/*********************************************************************************************** * uC/OS-II * The Real-Time Kernel * File : os_cpu_c.c * For : uC/OS Real-time multitasking kernel for the Nios2 SoftCore Processor * Written by : IS * Based on : Nios port done by JS * * Functions defined in this module: * ***********************************************************************************************/ #include #include #define OS_CPU_GLOBALS #include "includes.h" // Standard includes for uC/OS-II extern void OSStartTsk; // The entry point for all tasks. /*********************************************************************************************** * INITIALIZE A TASK'S STACK * * Description: This function is called by either OSTaskCreate() or OSTaskCreateExt() to * initialize the stack frame of the task being created. This function is * highly processor specific. * * What it does: It builds up initial stack for a task. * * Arguments : task is a pointer to the task code * * pdata is a pointer to a user supplied data area that will be passed to the task * when the task first executes. * * ptos is a pointer to the top of stack. It is assumed that 'ptos' points to * a 'free' entry on the task stack. If OS_STK_GROWTH is set to 1 then * 'ptos' will contain the HIGHEST valid address of the stack. Similarly, if * OS_STK_GROWTH is set to 0, the 'ptos' will contains the LOWEST valid address * of the stack. * * opt specifies options that can be used to alter the behavior of OSTaskStkInit(). * (see uCOS_II.H for OS_TASK_OPT_???). * * 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. * ***********************************************************************************************/ OS_STK *OSTaskStkInit(void (*task)(void *pd), void *pdata, OS_STK *pstk, INT16U opt) { INT32U *frame_pointer; INT32U *stk; struct _reent* impure_ptr; /* * create and initialise the impure pointer used for Newlib thread local storage. */ impure_ptr = (struct _reent*)((((INT32U)(pstk)) & ~0x3) - sizeof(struct _reent)); _REENT_INIT_PTR (impure_ptr); /* * create a stack frame at the top of the stack (leaving space for the * reentrant data structure). */ frame_pointer = (INT32U*) impure_ptr; stk = frame_pointer - DEFAULT_STACK_FRAME; /* Now fill the stack frame. */ *(stk + 13) = (INT32U)task; /* return address (ra) */ *(stk + 12) = (INT32U) pdata; /* first register argument (r4) */ *(stk + 11) = (INT32U) impure_ptr; /* value of _impure_ptr for this thread */ *(stk + 10) = 1; /* disable interrupts */ *(stk + 1) = (INT32U) frame_pointer; /* frame pointer (fp) */ *(stk) = (INT32U) &OSStartTsk; /* exception return address (ea) */ return((OS_STK *)stk); } #if OS_CPU_HOOKS_EN /* ********************************************************************************************************* * TASK CREATION HOOK * * Description: This function is called when a task is created. * * Arguments : ptcb is a pointer to the task control block of the task being created. * * Note(s) : 1) Interrupts are disabled during this call. ********************************************************************************************************* */ void OSTaskCreateHook (OS_TCB *ptcb) { OSView_TaskCreateHook(ptcb); } /* ********************************************************************************************************* * TASK DELETION HOOK * * Description: This function is called when a task is deleted. * * Arguments : ptcb is a pointer to the task control block of the task being deleted. * * Note(s) : 1) Interrupts are disabled during this call. ********************************************************************************************************* */ void OSTaskDelHook (OS_TCB *ptcb) { ptcb = ptcb; /* Prevent compiler warning */ } /* ********************************************************************************************************* * 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 'OSTCBHighRdy' points to the TCB of the task that * will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the * task being switched out (i.e. the preempted task). ********************************************************************************************************* */ void OSTaskSwHook (void) { OSView_TaskSwHook(); } /* ********************************************************************************************************* * STATISTIC TASK HOOK * * Description: This function is called every second by uC/OS-II's statistics task. This allows your * application to add functionality to the statistics task. * * Arguments : none ********************************************************************************************************* */ void OSTaskStatHook (void) { } /* ********************************************************************************************************* * TICK HOOK * * Description: This function is called every tick. * * Arguments : none * * Note(s) : 1) Interrupts may or may not be ENABLED during this call. ********************************************************************************************************* */ void OSTimeTickHook (void) { OSView_TickHook(); } void OSInitHookBegin(void) { } void OSInitHookEnd(void) { } void OSTaskIdleHook(void) { } void OSTCBInitHook(OS_TCB *ptcb) { } #endif