From 3abeb3ef6c421232e9c74b294f474298ac5b61dd Mon Sep 17 00:00:00 2001 From: Yuguo Zou Date: Thu, 9 Apr 2020 14:37:08 +0800 Subject: [PATCH 1/3] embARC: add support Signed-off-by: Yuguo Zou --- Ports/ARC/embARC/MetaWare/os_cpu.h | 109 ++++++ Ports/ARC/embARC/MetaWare/os_cpu_a.s | 549 +++++++++++++++++++++++++++ Ports/ARC/embARC/MetaWare/os_cpu_c.c | 422 ++++++++++++++++++++ 3 files changed, 1080 insertions(+) create mode 100644 Ports/ARC/embARC/MetaWare/os_cpu.h create mode 100644 Ports/ARC/embARC/MetaWare/os_cpu_a.s create mode 100644 Ports/ARC/embARC/MetaWare/os_cpu_c.c diff --git a/Ports/ARC/embARC/MetaWare/os_cpu.h b/Ports/ARC/embARC/MetaWare/os_cpu.h new file mode 100644 index 0000000..8d24a35 --- /dev/null +++ b/Ports/ARC/embARC/MetaWare/os_cpu.h @@ -0,0 +1,109 @@ +/* +********************************************************************************************************* +* uC/OS-III +* The Real-Time Kernel +* +* (c) Copyright 2009-2018; Silicon Laboratories Inc., +* 400 W. Cesar Chavez, Austin, TX 78701 +* +* All rights reserved. Protected by international copyright laws. +* +* Your use of this software is subject to your acceptance of the terms +* of a Silicon Labs Micrium software license, which can be obtained by +* contacting info@micrium.com. If you do not agree to the terms of this +* license, you may not use this software. +* +* Please help us continue to provide the Embedded community with the finest +* software available. Your honesty is greatly appreciated. +* +* You can find our product's documentation at: doc.micrium.com +* +* For more information visit us at: www.micrium.com +********************************************************************************************************* +*/ + +/* +********************************************************************************************************* +* +* ARC +* MetaWare +* +* Filename : os_cpu.h +* Version : V3.07.03 +********************************************************************************************************* +*/ + +#ifndef _OS_CPU_H +#define _OS_CPU_H + +#ifdef OS_CPU_GLOBALS +#define OS_CPU_EXT +#else +#define OS_CPU_EXT extern +#endif + +#include "embARC.h" +#ifdef __cplusplus +extern "C" { +#endif + +/* +********************************************************************************************************* +* MACROS +* +* Note(s): OS_TASK_SW() invokes the task level context switch. +* +* (1) On some processors, this corresponds to a call to OSCtxSw() which is an assemply language +* function that performs the context switch. +* +* (2) On some processors, you need to simulate an interrupt using a 'sowfate interrupt' or a +* TRAP instruction. Some compilers allow you to add in-line assembly language as shown. +********************************************************************************************************* +*/ + +#define OS_TASK_SW() OSCtxSw() /* Simulate interrupt */ + +/* +********************************************************************************************************* +* TIMESTAMP CONFIGURATION +* +* Note(s) : (1) OS_TS_GET() is generally defined as CPU_TS_Get32() to allow CPU timestamp timer to be of +* any data type size. +* +* (2) For architectures that provide 32-bit or higher precision free running counters +* (i.e. cycle count registers): +* +* (a) OS_TS_GET() may be defined as CPU_TS_TmrRd() to improve performance when retrieving +* the timestamp. You would use CPU_TS_TmrRd() if this function returned the value of +* a 32-bit free running timer 0x00000000 to 0xFFFFFFFF then roll over to 0x00000000. +* +* (b) CPU_TS_TmrRd() MUST be configured to be greater or equal to 32-bits to avoid +* truncation of TS. +* +* (c) The Timer must be an up counter. +********************************************************************************************************* +*/ + +#if OS_CFG_TS_EN == 1u +#define OS_TS_GET() (CPU_TS)CPU_TS_Get32() /* See Note #2a. CPU_TS_TmrRd() */ +#else +#define OS_TS_GET() (CPU_TS)0u +#endif + + +/* +********************************************************************************************************* +* FUNCTION PROTOTYPES +********************************************************************************************************* +*/ + +void OSCtxSw (void); +void OSIntCtxSw (void); +void OSStartHighRdy (void); +int OS_SysTickInit (void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Ports/ARC/embARC/MetaWare/os_cpu_a.s b/Ports/ARC/embARC/MetaWare/os_cpu_a.s new file mode 100644 index 0000000..c94e21d --- /dev/null +++ b/Ports/ARC/embARC/MetaWare/os_cpu_a.s @@ -0,0 +1,549 @@ +;******************************************************************************************************** +; uC/OS-III +; The Real-Time Kernel +; +; (c) Copyright 2009-2018; Silicon Laboratories Inc., +; 400 W. Cesar Chavez, Austin, TX 78701 +; +; All rights reserved. Protected by international copyright laws. +; +; Your use of this software is subject to your acceptance of the terms +; of a Silicon Labs Micrium software license, which can be obtained by +; contacting info@micrium.com. If you do not agree to the terms of this +; license, you may not use this software. +; +; Please help us continue to provide the Embedded community with the finest +; software available. Your honesty is greatly appreciated. +; +; You can find our product's documentation at: doc.micrium.com +; +; For more information visit us at: www.micrium.com +;******************************************************************************************************** + +;******************************************************************************************************** +; +; ASSEMBLY LANGUAGE PORT +; +; ARC +; MetaWare +; +; Filename : os_cpu_a.asm +; Version : V3.07.03 +;******************************************************************************************************** + +#define __ASSEMBLY__ +#include "arc/arc.h" +#include "arc/arc_asm_common.h" + + .text + .align 4 +;******************************************************************************************************** +; PUBLIC FUNCTIONS +;******************************************************************************************************** + + .global task_startup_routine + .global dispatch + .global OSStartHighRdy ; Public functions + + .extern OSTCBCurPtr ; Declared as OS_TCB * , 32-bit long + .extern OSTCBHighRdyPtr ; Declared as OS_TCB * , 32-bit long + .extern OSPrioCur ; Declared as INT8U , 8-bit long + .extern OSPrioHighRdy ; Declared as INT8U , 8-bit long + .extern OSTaskSwHook + .extern OS_Set_StackCheck + +;******************************************************************************************************** +; CODE GENERATION DIRECTIVES +;******************************************************************************************************** + + .text + .align 4 +/* + * task startup routine + * + */ +task_startup_routine: + seti /* unlock cpu */ + mov blink, OS_TaskReturn /* set return address, in normal cases a task should not return */ + POP r1 /* get task function body */ + POP r0 /* get task parameters */ + j [r1] + +;/*$PAGE*/ +;********************************************************************************************************* +; TASK LEVEL CONTEXT SWITCH +; +; Description : This function is called when a task makes a higher priority task ready-to-run. +; The pseudo code is: +; +; OS_CTX_SAVE +; OSTCBCurPtr->SP = SP; +; OSTaskSwHook(); +; OSPrioCur = OSPrioHighRdy; +; OSTCBCurPtr = OSTCBHighRdyPtr; +; SP = OSTCBCurPtr->StkPtr; +; OS_CTX_RESTORE +; Return from interrupt/exception +;********************************************************************************************************* + + .text + .align 4 +dispatch: +/* + * the pre-conditions of this routine are task context, CPU is + * locked, dispatch is enabled. + */ + SAVE_NONSCRATCH_REGS /* save callee save registers */ + mov r1, dispatch_r + PUSH r1 /* save return address */ + ld r0, [OSTCBCurPtr] + bl dispatcher + +/* return routine when task dispatch happened in task context */ +dispatch_r: + RESTORE_NONSCRATCH_REGS /* recover registers */ + j [blink] + +;/*$PAGE*/ +;********************************************************************************************************* +; START MULTITASKING +; +; Description : This function is called by OSStart() to start the highest priority task that was created +; by your application before calling OSStart(). +; +; Arguments : none +; +; Note(s) : 1) The stack frame is assumed to look as follows: +; +; OSTCBHighRdy->OSTCBStkPtr + 0 ----> +; +; 2) OSStartHighRdy() MUST: +; a) Call OSTaskSwHook() then, +; b) Switch to the highest priority task. +;********************************************************************************************************* + +OSStartHighRdy: + clri + mov r0, 0 + st r0, [exc_nest_count] + b dispatcher_0 +dispatcher: + ld r1, [ulCriticalNesting] + PUSH r1 /* save critical nesting */ + st sp, [r0] /* save stack pointer of current task, r0->OSTCBCurPtr */ +dispatcher_0: + jl OSTaskSwHook ; Call OSTaskSwHook() + mov r1, OSPrioHighRdy ; OSPrioCur = OSPrioHighRdy + mov r0, OSPrioCur + ldb r2, [r1] + stb r2, [r0] + ld r1, [OSTCBHighRdyPtr] ; OSTCBCurPtr = OSTCBHighRdyPtr + st r1, [OSTCBCurPtr] + ld r1, [OSTCBCurPtr] ; SP = OSTCBCurPtr->StkPtr + ld sp, [r1] +#if ARC_FEATURE_STACK_CHECK +#if ARC_FEATURE_SEC_PRESENT + lr r0, [AUX_SEC_STAT] + bclr r0, r0, AUX_SEC_STAT_BIT_SSC + sflag r0 +#else + lr r0, [AUX_STATUS32] + bclr r0, r0, AUX_STATUS_BIT_SC + kflag r0 +#endif + jl OS_Set_StackCheck +#if ARC_FEATURE_SEC_PRESENT + lr r0, [AUX_SEC_STAT] + bset r0, r0, AUX_SEC_STAT_BIT_SSC + sflag r0 +#else + lr r0, [AUX_STATUS32] + bset r0, r0, AUX_STATUS_BIT_SC + kflag r0 +#endif +#endif + POP r0 ;get critical nesting + st r0, [ulCriticalNesting] + POP r0 ;return address + j [r0] + + + +/****** exceptions and interrupts handing ******/ +/****** entry for exception handling ******/ + .global exc_entry_cpu + .align 4 +exc_entry_cpu: + + EXCEPTION_PROLOGUE + + mov blink, sp + mov r3, sp /* as exception handler's para(p_excinfo) */ + + ld r0, [exc_nest_count] + add r1, r0, 1 + st r1, [exc_nest_count] + brne r0, 0, exc_handler_1 +/* change to exception stack if interrupt happened in task context */ + mov sp, _e_stack +exc_handler_1: + PUSH blink + + lr r0, [AUX_ECR] + lsr r0, r0, 16 + mov r1, exc_int_handler_table + ld.as r2, [r1, r0] + + mov r0, r3 + jl [r2] /* !!!!jump to exception handler where interrupts are not allowed! */ + +/* interrupts are not allowed */ +ret_exc: + POP sp + mov r1, exc_nest_count + ld r0, [r1] + sub r0, r0, 1 + st r0, [r1] + brne r0, 0, ret_exc_1 /* nest exception case */ + lr r1, [AUX_IRQ_ACT] /* nest interrupt case */ + brne r1, 0, ret_exc_1 + + ld r0, [context_switch_reqflg] + brne r0, 0, ret_exc_2 +ret_exc_1: /* return from non-task context, interrupts or exceptions are nested */ + + EXCEPTION_EPILOGUE + rtie + +/* there is a dispatch request */ +ret_exc_2: + /* clear dispatch request */ + mov r0, 0 + st r0, [context_switch_reqflg] + + ld r0, [OSTCBCurPtr] + breq r0, 0, ret_exc_1 + + SAVE_CALLEE_REGS /* save callee save registers */ + + lr r0, [AUX_STATUS32] + bclr r0, r0, AUX_STATUS_BIT_AE /* clear exception bit */ + kflag r0 + + mov r1, ret_exc_r /* save return address */ + PUSH r1 + + bl dispatcher /* r0->OSTCBCurPtr */ + +ret_exc_r: + /* recover exception status */ + lr r0, [AUX_STATUS32] + bset r0, r0, AUX_STATUS_BIT_AE + kflag r0 + + RESTORE_CALLEE_REGS /* recover registers */ + EXCEPTION_EPILOGUE + rtie + +/****** entry for normal interrupt exception handling ******/ + .global exc_entry_int /* entry for interrupt handling */ + .align 4 +exc_entry_int: +#if ARC_FEATURE_FIRQ == 1 +#if ARC_FEATURE_RGF_NUM_BANKS > 1 + lr r0, [AUX_IRQ_ACT] /* check whether it is P0 interrupt */ + btst r0, 0 + jnz exc_entry_firq +#else + PUSH r10 + lr r10, [AUX_IRQ_ACT] + btst r10, 0 + POP r10 + jnz exc_entry_firq +#endif +#endif + INTERRUPT_PROLOGUE + + mov blink, sp + + clri /* disable interrupt */ + ld r3, [exc_nest_count] + add r2, r3, 1 + st r2, [exc_nest_count] + seti /* enable higher priority interrupt */ + + brne r3, 0, irq_handler_1 +/* change to exception stack if interrupt happened in task context */ + mov sp, _e_stack +#if ARC_FEATURE_STACK_CHECK +#if ARC_FEATURE_SEC_PRESENT + lr r0, [AUX_SEC_STAT] + bclr r0, r0, AUX_SEC_STAT_BIT_SSC + sflag r0 +#else + lr r0, [AUX_STATUS32] + bclr r0, r0, AUX_STATUS_BIT_SC + kflag r0 +#endif +#endif +irq_handler_1: + PUSH blink + + lr r0, [AUX_IRQ_CAUSE] + mov r1, exc_int_handler_table + ld.as r2, [r1, r0] /* r2 = exc_int_handler_table + irqno *4 */ +/* handle software triggered interrupt */ + lr r3, [AUX_IRQ_HINT] + cmp r3, r0 + bne.d irq_hint_handled + xor r3, r3, r3 + sr r3, [AUX_IRQ_HINT] +irq_hint_handled: + + jl [r2] /* jump to interrupt handler */ +/* no interrupts are allowed from here */ +ret_int: + clri /* disable interrupt */ + + POP sp + mov r1, exc_nest_count + ld r0, [r1] + sub r0, r0, 1 + st r0, [r1] +/* if there are multi-bits set in IRQ_ACT, it's still in nest interrupt */ + lr r0, [AUX_IRQ_CAUSE] + sr r0, [AUX_IRQ_SELECT] + lr r3, [AUX_IRQ_PRIORITY] + lr r1, [AUX_IRQ_ACT] + bclr r2, r1, r3 + brne r2, 0, ret_int_1 + + ld r0, [context_switch_reqflg] + brne r0, 0, ret_int_2 +ret_int_1: /* return from non-task context */ + INTERRUPT_EPILOGUE + rtie +/* there is a dispatch request */ +ret_int_2: + /* clear dispatch request */ + mov r0, 0 + st r0, [context_switch_reqflg] + + ld r0, [OSTCBCurPtr] + breq r0, 0, ret_int_1 + +/* r1 has old AUX_IRQ_ACT */ + PUSH r1 +/* clear related bits in IRQ_ACT manually to simulate a irq return */ + sr r2, [AUX_IRQ_ACT] + + SAVE_CALLEE_REGS /* save callee save registers */ + mov r1, ret_int_r /* save return address */ + PUSH r1 + + bl dispatcher /* r0->OSTCBCurPtr */ + +ret_int_r: + RESTORE_CALLEE_REGS /* recover registers */ + POPAX AUX_IRQ_ACT + INTERRUPT_EPILOGUE + rtie + +#if ARC_FEATURE_FIRQ == 1 + .global exc_entry_firq + .align 4 +exc_entry_firq: +#if ARC_FEATURE_STACK_CHECK && ARC_FEATURE_RGF_NUM_BANKS > 1 +#if ARC_FEATURE_SEC_PRESENT + lr r0, [AUX_SEC_STAT] + bclr r0, r0, AUX_SEC_STAT_BIT_SSC + sflag r0 +#else + lr r0, [AUX_STATUS32] + bclr r0, r0, AUX_STATUS_BIT_SC + kflag r0 +#endif +#endif + SAVE_FIQ_EXC_REGS + + mov blink, sp + + ld r3, [exc_nest_count] + add r2, r3, 1 + st r2, [exc_nest_count] + + brne r3, 0, firq_handler_1 +#if ARC_FEATURE_STACK_CHECK && ARC_FEATURE_RGF_NUM_BANKS == 1 +#if ARC_FEATURE_SEC_PRESENT + lr r0, [AUX_SEC_STAT] + bclr r0, r0, AUX_SEC_STAT_BIT_SSC + sflag r0 +#else + lr r0, [AUX_STATUS32] + bclr r0, r0, AUX_STATUS_BIT_SC + kflag r0 +#endif +#endif +/* change to exception stack if interrupt happened in task context */ + mov sp, _e_stack +firq_handler_1: + PUSH blink + + lr r0, [AUX_IRQ_CAUSE] + mov r1, exc_int_handler_table + ld.as r2, [r1, r0] /* r2 = exc_int_handler_table + irqno *4 */ +/* handle software triggered interrupt */ + lr r3, [AUX_IRQ_HINT] + brne r3, r0, firq_hint_handled + xor r3, r3, r3 + sr r3, [AUX_IRQ_HINT] +firq_hint_handled: + + jl [r2] /* jump to interrupt handler */ +/* no interrupts are allowed from here */ +ret_firq: + clri + POP sp + + mov r1, exc_nest_count + ld r0, [r1] + sub r0, r0, 1 + st r0, [r1] +/* if there are multi-bits set in IRQ_ACT, it's still in nest interrupt */ + lr r1, [AUX_IRQ_ACT] + bclr r1, r1, 0 + brne r1, 0, ret_firq_1 + + ld r0, [context_switch_reqflg] + brne r0, 0, ret_firq_2 +ret_firq_1: /* return from non-task context */ + RESTORE_FIQ_EXC_REGS + rtie +/* there is a dispatch request */ +ret_firq_2: + /* clear dispatch request */ + mov r0, 0 + st r0, [context_switch_reqflg] + + ld r0, [OSTCBCurPtr] + breq r0, 0, ret_firq_1 + +/* reconstruct the interruptted context + * When ARC_FEATURE_RGF_BANKED_REGS >= 16 (16, 32), sp is banked + * so need to restore the fast irq stack. + */ +#if ARC_FEATURE_RGF_BANKED_REGS >= 16 + RESTORE_LP_REGS +#if ARC_FEATURE_CODE_DENSITY + RESTORE_CODE_DENSITY +#endif + RESTORE_R58_R59 +#endif + +/* when BANKED_REGS == 16, r4-r9 wiil be also saved in fast irq stack + * so pop them out + */ +#if ARC_FEATURE_RGF_BANKED_REGS == 16 && !defined(ARC_FEATURE_RF16) + POP r9 + POP r8 + POP r7 + POP r6 + POP r5 + POP r4 +#endif + +/* for other cases, unbanked regs are already in interrupted context's stack, + * so just need to save and pop the banked regs + */ + +/* save the interruptted context */ +#if ARC_FEATURE_RGF_BANKED_REGS > 0 +/* switch back to bank0 */ + lr r0, [AUX_STATUS32] + bic r0, r0, 0x70000 + kflag r0 +#endif + +#if ARC_FEATURE_RGF_BANKED_REGS == 4 +/* r4 - r12, gp, fp, r30, blink already saved */ + PUSH r0 + PUSH r1 + PUSH r2 + PUSH r3 +#elif ARC_FEATURE_RGF_BANKED_REGS == 8 +/* r4 - r9, r0, r11 gp, fp, r30, blink already saved */ + PUSH r0 + PUSH r1 + PUSH r2 + PUSH r3 + PUSH r12 +#elif ARC_FEATURE_RGF_BANKED_REGS >= 16 +/* nothing is saved, */ + SAVE_R0_TO_R12 + + SAVE_R58_R59 + PUSH gp + PUSH fp + PUSH r30 /* general purpose */ + PUSH blink + +#if ARC_FEATURE_CODE_DENSITY + SAVE_CODE_DENSITY +#endif + SAVE_LP_REGS +#endif + PUSH ilink + lr r0, [AUX_STATUS32_P0] + PUSH r0 + lr r0, [AUX_IRQ_ACT] + PUSH r0 + bclr r0, r0, 0 + sr r0, [AUX_IRQ_ACT] + + SAVE_CALLEE_REGS /* save callee save registers */ + + mov r1, ret_firq_r /* save return address */ + PUSH r1 + ld r0, [OSTCBCurPtr] + bl dispatcher /* r0->OSTCBCurPtr */ + +ret_firq_r: + RESTORE_CALLEE_REGS /* recover registers */ + POPAX AUX_IRQ_ACT + POPAX AUX_STATUS32_P0 + POP ilink + +#if ARC_FEATURE_RGF_NUM_BANKS > 1 +#if ARC_FEATURE_RGF_BANKED_REGS == 4 +/* r4 - r12, gp, fp, r30, blink already saved */ + POP r3 + POP r2 + POP r1 + POP r0 + RESTORE_FIQ_EXC_REGS +#elif ARC_FEATURE_RGF_BANKED_REGS == 8 +/* r4 - r9, gp, fp, r30, blink already saved */ + POP r12 + POP r3 + POP r2 + POP r1 + POP r0 + RESTORE_FIQ_EXC_REGS +#elif ARC_FEATURE_RGF_BANKED_REGS >= 16 + RESTORE_LP_REGS +#if ARC_FEATURE_CODE_DENSITY + RESTORE_CODE_DENSITY +#endif + POP blink + POP r30 + POP fp + POP gp + + RESTORE_R58_R59 + RESTORE_R0_TO_R12 +#endif /* ARC_FEATURE_RGF_BANKED_REGS */ +#else + RESTORE_FIQ_EXC_REGS +#endif /* ARC_FEATURE_RGF_NUM_BANKS */ + rtie +#endif diff --git a/Ports/ARC/embARC/MetaWare/os_cpu_c.c b/Ports/ARC/embARC/MetaWare/os_cpu_c.c new file mode 100644 index 0000000..c84cabf --- /dev/null +++ b/Ports/ARC/embARC/MetaWare/os_cpu_c.c @@ -0,0 +1,422 @@ +/* +********************************************************************************************************* +* uC/OS-III +* The Real-Time Kernel +* +* (c) Copyright 2009-2018; Silicon Laboratories Inc., +* 400 W. Cesar Chavez, Austin, TX 78701 +* +* All rights reserved. Protected by international copyright laws. +* +* Your use of this software is subject to your acceptance of the terms +* of a Silicon Labs Micrium software license, which can be obtained by +* contacting info@micrium.com. If you do not agree to the terms of this +* license, you may not use this software. +* +* Please help us continue to provide the Embedded community with the finest +* software available. Your honesty is greatly appreciated. +* +* You can find our product's documentation at: doc.micrium.com +* +* For more information visit us at: www.micrium.com +********************************************************************************************************* +*/ + +/* +********************************************************************************************************* +* +* ARC +* MetaWare +* +* Filename : os_cpu_c.c +* Version : V3.07.03 +********************************************************************************************************* + +*/ + +#define OS_CPU_GLOBALS + +#ifdef VSC_INCLUDE_SOURCE_FILE_NAMES +const CPU_CHAR *os_cpu_c__c = "$Id: $"; +#endif + +/* +********************************************************************************************************* +* INCLUDE FILES +********************************************************************************************************* +*/ + +#include "os.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern void task_startup_routine(void); +extern void dispatch(void); +uint32_t exc_nest_count; +volatile uint32_t ulCriticalNesting = 999UL; +volatile unsigned int context_switch_reqflg; +/* +********************************************************************************************************* +* LOCAL DEFINES +********************************************************************************************************* +*/ + +/* +********************************************************************************************************* +* IDLE TASK HOOK +* +* Description: This function is called by the idle task. This hook has been added to allow you to do +* such things as STOP the CPU to conserve power. +* +* Arguments : None. +* +* Note(s) : None. +********************************************************************************************************* +*/ + +void OSIdleTaskHook (void) +{ +#if OS_CFG_APP_HOOKS_EN > 0u + if (OS_AppIdleTaskHookPtr != (OS_APP_HOOK_VOID)0) { + (*OS_AppIdleTaskHookPtr)(); + } +#endif +} + + +/* +********************************************************************************************************* +* OS INITIALIZATION HOOK +* +* Description: This function is called by OSInit() at the beginning of OSInit(). +* +* Arguments : None. +* +* Note(s) : None. +********************************************************************************************************* +*/ + +void OSInitHook (void) +{ + OS_SysTickInit(); +} + + +/* +********************************************************************************************************* +* REDZONE HIT HOOK +* +* Description: This function is called when a task's stack overflowed. +* +* Arguments : p_tcb Pointer to the task control block of the offending task. +* +* Note(s) : None. +********************************************************************************************************* +*/ +#if (OS_CFG_TASK_STK_REDZONE_EN == DEF_ENABLED) +void OSRedzoneHitHook (OS_TCB *p_tcb) +{ +#if OS_CFG_APP_HOOKS_EN > 0u + if (OS_AppRedzoneHitHookPtr != (OS_APP_HOOK_TCB)0) { + (*OS_AppRedzoneHitHookPtr)(p_tcb); + } +#endif + (void)p_tcb; /* Prevent compiler warning */ + CPU_SW_EXCEPTION(;); +} +#endif + + +/* +********************************************************************************************************* +* STATISTIC TASK HOOK +* +* Description: This function is called periodically by uC/OS-III's statistics task. This allows your +* application to add functionality to the statistics task. +* +* Arguments : None. +* +* Note(s) : None. +********************************************************************************************************* +*/ + +void OSStatTaskHook (void) +{ +#if OS_CFG_APP_HOOKS_EN > 0u + if (OS_AppStatTaskHookPtr != (OS_APP_HOOK_VOID)0) { + (*OS_AppStatTaskHookPtr)(); + } +#endif +} + + +/* +********************************************************************************************************* +* TASK CREATION HOOK +* +* Description: This function is called when a task is created. +* +* Arguments : p_tcb Pointer to the task control block of the task being created. +* +* Note(s) : None. +********************************************************************************************************* +*/ + +void OSTaskCreateHook (OS_TCB *p_tcb) +{ +#if OS_CFG_APP_HOOKS_EN > 0u + if (OS_AppTaskCreateHookPtr != (OS_APP_HOOK_TCB)0) { + (*OS_AppTaskCreateHookPtr)(p_tcb); + } +#else + (void)p_tcb; /* Prevent compiler warning */ +#endif +} + + +/* +********************************************************************************************************* +* TASK DELETION HOOK +* +* Description: This function is called when a task is deleted. +* +* Arguments : p_tcb Pointer to the task control block of the task being deleted. +* +* Note(s) : None. +********************************************************************************************************* +*/ + +void OSTaskDelHook (OS_TCB *p_tcb) +{ +#if OS_CFG_APP_HOOKS_EN > 0u + if (OS_AppTaskDelHookPtr != (OS_APP_HOOK_TCB)0) { + (*OS_AppTaskDelHookPtr)(p_tcb); + } +#else + (void)p_tcb; /* Prevent compiler warning */ +#endif +} + + +/* +********************************************************************************************************* +* TASK RETURN HOOK +* +* Description: This function is called if a task accidentally returns. In other words, a task should +* either be an infinite loop or delete itself when done. +* +* Arguments : p_tcb Pointer to the task control block of the task that is returning. +* +* Note(s) : None. +********************************************************************************************************* +*/ + +void OSTaskReturnHook (OS_TCB *p_tcb) +{ +#if OS_CFG_APP_HOOKS_EN > 0u + if (OS_AppTaskReturnHookPtr != (OS_APP_HOOK_TCB)0) { + (*OS_AppTaskReturnHookPtr)(p_tcb); + } +#else + (void)p_tcb; /* Prevent compiler warning */ +#endif +} + + +/* +********************************************************************************************************** +* INITIALIZE A TASK'S STACK +* +* Description: This function is called by OS_Task_Create() or OSTaskCreateExt() to initialize the stack +* frame of the task being created. This function is highly processor specific. +* +* Arguments : p_task Pointer to the task entry point address. +* +* p_arg Pointer to a user supplied data area that will be passed to the task +* when the task first executes. +* +* p_stk_base Pointer to the base address of the stack. +* +* stk_size Size of the stack, in number of CPU_STK elements. +* +* opt Options used to alter the behavior of OS_Task_StkInit(). +* (see OS.H for OS_TASK_OPT_xxx). +* +* Returns : Always returns the location of the new top-of-stack' once the processor registers have +* been placed on the stack in the proper order. +* +* Note(s) : 1) Interrupts are enabled when task starts executing. +********************************************************************************************************** +*/ + +CPU_STK *OSTaskStkInit (OS_TASK_PTR p_task, + void *p_arg, + CPU_STK *p_stk_base, + CPU_STK *p_stk_limit, + CPU_STK_SIZE stk_size, + OS_OPT opt) +{ + CPU_STK *p_stk; + + + (void)p_stk_limit; /* Prevent compiler warning */ + (void)opt; + + p_stk = &p_stk_base[stk_size]; /* Load stack pointer */ + /* Put CPU register values onto the stack */ + + *(--p_stk) = (CPU_STK) p_arg; + *(--p_stk) = (CPU_STK) p_task; + *(--p_stk) = (CPU_STK) task_startup_routine; //dispatch return address + *(--p_stk) = (CPU_STK) 0u; //preserve a place for critical nesting counter + return (p_stk); +} + + +void OSCtxSw(void) +{ + CPU_SR_ALLOC(); + CPU_CRITICAL_ENTER(); + dispatch(); + CPU_CRITICAL_EXIT(); +} + +void OSIntCtxSw(void) +{ + CPU_SR_ALLOC(); + CPU_CRITICAL_ENTER(); + context_switch_reqflg = true; + CPU_CRITICAL_EXIT(); +} + +/* +********************************************************************************************************* +* TASK SWITCH HOOK +* +* Description: This function is called when a task switch is performed. This allows you to perform other +* operations during a context switch. +* +* Arguments : None. +* +* Note(s) : 1) Interrupts are disabled during this call. +* 2) It is assumed that the global pointer 'OSTCBHighRdyPtr' points to the TCB of the task +* that will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCurPtr' points +* to the task being switched out (i.e. the preempted task). +********************************************************************************************************* +*/ + +void OSTaskSwHook (void) +{ +#if OS_CFG_TASK_PROFILE_EN > 0u + CPU_TS ts; +#endif +#ifdef CPU_CFG_INT_DIS_MEAS_EN + CPU_TS int_dis_time; +#endif +#if (OS_CFG_TASK_STK_REDZONE_EN == DEF_ENABLED) + CPU_BOOLEAN stk_status; +#endif + + +#if OS_CFG_APP_HOOKS_EN > 0u + if (OS_AppTaskSwHookPtr != (OS_APP_HOOK_VOID)0) { + (*OS_AppTaskSwHookPtr)(); + } +#endif + +#if OS_CFG_TASK_PROFILE_EN > 0u + ts = OS_TS_GET(); + if (OSTCBCurPtr != OSTCBHighRdyPtr) { + OSTCBCurPtr->CyclesDelta = ts - OSTCBCurPtr->CyclesStart; + OSTCBCurPtr->CyclesTotal += (OS_CYCLES)OSTCBCurPtr->CyclesDelta; + } + + OSTCBHighRdyPtr->CyclesStart = ts; +#endif + +#ifdef CPU_CFG_INT_DIS_MEAS_EN + int_dis_time = CPU_IntDisMeasMaxCurReset(); /* Keep track of per-task interrupt disable time */ + if (OSTCBCurPtr->IntDisTimeMax < int_dis_time) { + OSTCBCurPtr->IntDisTimeMax = int_dis_time; + } +#endif + +#if OS_CFG_SCHED_LOCK_TIME_MEAS_EN > 0u + /* Keep track of per-task scheduler lock time */ + if (OSTCBCurPtr->SchedLockTimeMax < OSSchedLockTimeMaxCur) { + OSTCBCurPtr->SchedLockTimeMax = OSSchedLockTimeMaxCur; + } + OSSchedLockTimeMaxCur = (CPU_TS)0; /* Reset the per-task value */ +#endif + +#if (OS_CFG_TASK_STK_REDZONE_EN == DEF_ENABLED) + /* Check if stack overflowed. */ + stk_status = OSTaskStkRedzoneChk(DEF_NULL); + if (stk_status != DEF_OK) { + CPU_SW_EXCEPTION(;); + } +#endif +} + + +/* +********************************************************************************************************* +* TICK HOOK +* +* Description: This function is called every tick. +* +* Arguments : None. +* +* Note(s) : 1) This function is assumed to be called from the Tick ISR. +********************************************************************************************************* +*/ + +void OSTimeTickHook (void) +{ +#if OS_CFG_APP_HOOKS_EN > 0u + if (OS_AppTimeTickHookPtr != (OS_APP_HOOK_VOID)0) { + (*OS_AppTimeTickHookPtr)(); + } +#endif +#if (CPU_CFG_TS_EN == DEF_ENABLED) + CPU_TS_Update(); +#endif +} + +static void OS_CPU_SysTickHandler (void) +{ + CPU_SR_ALLOC(); + + + CPU_CRITICAL_ENTER(); + OSIntEnter(); /* Tell uC/OS-III that we are starting an ISR */ + CPU_CRITICAL_EXIT(); + + OSTimeTick(); /* Call uC/OS-III's OSTimeTick() */ + + OSIntExit(); /* Tell uC/OS-III that we are leaving the ISR */ +} + +extern EMBARC_HOOK_VOID board_timer_isr_hook; + +int OS_SysTickInit(void) +{ + board_timer_isr_hook = OS_CPU_SysTickHandler; + + return 0; +} + +void OS_Set_StackCheck(OS_TCB *old, OS_TCB *new) +{ + (void)old; + if (new != NULL) { + arc_kernel_stack_check_configure((uint32_t)(new->StkBasePtr), (uint32_t)(new->StkSize + new->StkBasePtr)); + } +} + +#ifdef __cplusplus +} +#endif + From a459cc980c313106a6d8c37c03f034ed7829ae28 Mon Sep 17 00:00:00 2001 From: Yuguo Zou Date: Thu, 17 Jun 2021 10:24:15 +0800 Subject: [PATCH 2/3] embARC: fix licenses and version Signed-off-by: Yuguo Zou --- Ports/ARC/embARC/MetaWare/os_cpu.h | 24 ++++++------------ Ports/ARC/embARC/MetaWare/os_cpu_a.s | 38 +++++++++++----------------- Ports/ARC/embARC/MetaWare/os_cpu_c.c | 24 ++++++------------ 3 files changed, 31 insertions(+), 55 deletions(-) diff --git a/Ports/ARC/embARC/MetaWare/os_cpu.h b/Ports/ARC/embARC/MetaWare/os_cpu.h index 8d24a35..f274cd3 100644 --- a/Ports/ARC/embARC/MetaWare/os_cpu.h +++ b/Ports/ARC/embARC/MetaWare/os_cpu.h @@ -1,24 +1,16 @@ /* ********************************************************************************************************* -* uC/OS-III -* The Real-Time Kernel +* uC/OS-III +* The Real-Time Kernel * -* (c) Copyright 2009-2018; Silicon Laboratories Inc., -* 400 W. Cesar Chavez, Austin, TX 78701 +* Copyright 2009-2021 Silicon Laboratories Inc. www.silabs.com * -* All rights reserved. Protected by international copyright laws. +* SPDX-License-Identifier: APACHE-2.0 * -* Your use of this software is subject to your acceptance of the terms -* of a Silicon Labs Micrium software license, which can be obtained by -* contacting info@micrium.com. If you do not agree to the terms of this -* license, you may not use this software. +* This software is subject to an open source license and is distributed by +* Silicon Laboratories Inc. pursuant to the terms of the Apache License, +* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0. * -* Please help us continue to provide the Embedded community with the finest -* software available. Your honesty is greatly appreciated. -* -* You can find our product's documentation at: doc.micrium.com -* -* For more information visit us at: www.micrium.com ********************************************************************************************************* */ @@ -29,7 +21,7 @@ * MetaWare * * Filename : os_cpu.h -* Version : V3.07.03 +* Version : V3.08.01 ********************************************************************************************************* */ diff --git a/Ports/ARC/embARC/MetaWare/os_cpu_a.s b/Ports/ARC/embARC/MetaWare/os_cpu_a.s index c94e21d..c5188f4 100644 --- a/Ports/ARC/embARC/MetaWare/os_cpu_a.s +++ b/Ports/ARC/embARC/MetaWare/os_cpu_a.s @@ -1,24 +1,17 @@ -;******************************************************************************************************** -; uC/OS-III -; The Real-Time Kernel -; -; (c) Copyright 2009-2018; Silicon Laboratories Inc., -; 400 W. Cesar Chavez, Austin, TX 78701 -; -; All rights reserved. Protected by international copyright laws. -; -; Your use of this software is subject to your acceptance of the terms -; of a Silicon Labs Micrium software license, which can be obtained by -; contacting info@micrium.com. If you do not agree to the terms of this -; license, you may not use this software. -; -; Please help us continue to provide the Embedded community with the finest -; software available. Your honesty is greatly appreciated. -; -; You can find our product's documentation at: doc.micrium.com -; -; For more information visit us at: www.micrium.com -;******************************************************************************************************** +/* +********************************************************************************************************* +* uC/OS-III +* The Real-Time Kernel +* +* Copyright 2009-2021 Silicon Laboratories Inc. www.silabs.com +* +* SPDX-License-Identifier: APACHE-2.0 +* +* This software is subject to an open source license and is distributed by +* Silicon Laboratories Inc. pursuant to the terms of the Apache License, +* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0. +* +********************************************************************************************************* ;******************************************************************************************************** ; @@ -28,7 +21,7 @@ ; MetaWare ; ; Filename : os_cpu_a.asm -; Version : V3.07.03 +; Version : V3.08.01 ;******************************************************************************************************** #define __ASSEMBLY__ @@ -69,7 +62,6 @@ task_startup_routine: POP r0 /* get task parameters */ j [r1] -;/*$PAGE*/ ;********************************************************************************************************* ; TASK LEVEL CONTEXT SWITCH ; diff --git a/Ports/ARC/embARC/MetaWare/os_cpu_c.c b/Ports/ARC/embARC/MetaWare/os_cpu_c.c index c84cabf..fa89f83 100644 --- a/Ports/ARC/embARC/MetaWare/os_cpu_c.c +++ b/Ports/ARC/embARC/MetaWare/os_cpu_c.c @@ -1,24 +1,16 @@ /* ********************************************************************************************************* -* uC/OS-III -* The Real-Time Kernel +* uC/OS-III +* The Real-Time Kernel * -* (c) Copyright 2009-2018; Silicon Laboratories Inc., -* 400 W. Cesar Chavez, Austin, TX 78701 +* Copyright 2009-2021 Silicon Laboratories Inc. www.silabs.com * -* All rights reserved. Protected by international copyright laws. +* SPDX-License-Identifier: APACHE-2.0 * -* Your use of this software is subject to your acceptance of the terms -* of a Silicon Labs Micrium software license, which can be obtained by -* contacting info@micrium.com. If you do not agree to the terms of this -* license, you may not use this software. +* This software is subject to an open source license and is distributed by +* Silicon Laboratories Inc. pursuant to the terms of the Apache License, +* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0. * -* Please help us continue to provide the Embedded community with the finest -* software available. Your honesty is greatly appreciated. -* -* You can find our product's documentation at: doc.micrium.com -* -* For more information visit us at: www.micrium.com ********************************************************************************************************* */ @@ -29,7 +21,7 @@ * MetaWare * * Filename : os_cpu_c.c -* Version : V3.07.03 +* Version : V3.08.01 ********************************************************************************************************* */ From 1e9c9ec7eddeb043195c31a28c87c2e33c574c5f Mon Sep 17 00:00:00 2001 From: Sharbel Bousemaan Date: Thu, 17 Jun 2021 14:28:52 -0400 Subject: [PATCH 3/3] Cleaned up file headers. --- Ports/ARC/embARC/MetaWare/os_cpu.h | 8 +++---- Ports/ARC/embARC/MetaWare/os_cpu_a.s | 35 ++++++++++++++-------------- Ports/ARC/embARC/MetaWare/os_cpu_c.c | 8 +++---- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/Ports/ARC/embARC/MetaWare/os_cpu.h b/Ports/ARC/embARC/MetaWare/os_cpu.h index f274cd3..491a570 100644 --- a/Ports/ARC/embARC/MetaWare/os_cpu.h +++ b/Ports/ARC/embARC/MetaWare/os_cpu.h @@ -17,11 +17,11 @@ /* ********************************************************************************************************* * -* ARC -* MetaWare +* ARC +* MetaWare * -* Filename : os_cpu.h -* Version : V3.08.01 +* Filename : os_cpu.h +* Version : V3.08.01 ********************************************************************************************************* */ diff --git a/Ports/ARC/embARC/MetaWare/os_cpu_a.s b/Ports/ARC/embARC/MetaWare/os_cpu_a.s index c5188f4..098e400 100644 --- a/Ports/ARC/embARC/MetaWare/os_cpu_a.s +++ b/Ports/ARC/embARC/MetaWare/os_cpu_a.s @@ -1,27 +1,26 @@ -/* -********************************************************************************************************* -* uC/OS-III -* The Real-Time Kernel -* -* Copyright 2009-2021 Silicon Laboratories Inc. www.silabs.com -* -* SPDX-License-Identifier: APACHE-2.0 -* -* This software is subject to an open source license and is distributed by -* Silicon Laboratories Inc. pursuant to the terms of the Apache License, -* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0. -* -********************************************************************************************************* +;******************************************************************************************************** +; uC/OS-III +; The Real-Time Kernel +; +; Copyright 2009-2021 Silicon Laboratories Inc. www.silabs.com +; +; SPDX-License-Identifier: APACHE-2.0 +; +; This software is subject to an open source license and is distributed by +; Silicon Laboratories Inc. pursuant to the terms of the Apache License, +; Version 2.0 available at www.apache.org/licenses/LICENSE-2.0. +; +;******************************************************************************************************** ;******************************************************************************************************** ; ; ASSEMBLY LANGUAGE PORT ; -; ARC -; MetaWare +; ARC +; MetaWare ; -; Filename : os_cpu_a.asm -; Version : V3.08.01 +; Filename : os_cpu_a.asm +; Version : V3.08.01 ;******************************************************************************************************** #define __ASSEMBLY__ diff --git a/Ports/ARC/embARC/MetaWare/os_cpu_c.c b/Ports/ARC/embARC/MetaWare/os_cpu_c.c index fa89f83..844a0c3 100644 --- a/Ports/ARC/embARC/MetaWare/os_cpu_c.c +++ b/Ports/ARC/embARC/MetaWare/os_cpu_c.c @@ -17,11 +17,11 @@ /* ********************************************************************************************************* * -* ARC -* MetaWare +* ARC +* MetaWare * -* Filename : os_cpu_c.c -* Version : V3.08.01 +* Filename : os_cpu_c.c +* Version : V3.08.01 ********************************************************************************************************* */