📄 os_cpu_c.c
字号:
/*********************************************************************
*File: OS_CPU_C.c - V2.52 port for C6416
*Author: Jean J. Labrosse
*Data:
*modification history:
* 2006.04.20 rongjie revised OSTaskStkInit() for porting to C6416
*DESCRIPTION:
little endian, C code in relation to processor.
*********************************************************************/
/* includes */
#define OS_CPU_GLOBALS
#include "..\includes.h"
int intCount = 0;
/*
*********************************************************************************************************
* 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.
*
* 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.
*
* Note(s) : Interrupts are enabled when your task starts executing.
*********************************************************************************************************
*/
OS_STK * OSTaskStkInit(void (*task)(void *pd), void *pdata, OS_STK *ptos, INT16U opt)
{
int *stk;
opt = opt; /* 'opt' is not used, prevent warning */
/* THE SP MUST BE ALIGNED ON AN 8-BYTE BOUNDARY.*/
stk = (int *)( (int)ptos & ~7 );
*stk-- = (int)task; /* Put pointer to task */
stk--;
*stk-- = 0xA0;
*stk-- = 0xA1;
*stk-- = 0xA2;
*stk-- = 0xA3;
*stk-- = (int)pdata; /* the first argument of C function here*/
*stk-- = 0xA5;
*stk-- = 0xA6;
*stk-- = 0xA7;
*stk-- = 0xA8;
*stk-- = 0xA9;
*stk-- = 0xA10;
*stk-- = 0xA11;
*stk-- = 0xA12;
*stk-- = 0xA13;
*stk-- = 0xA14;
*stk-- = 0xA15;
*stk-- = 0xA16;
*stk-- = 0xA17;
*stk-- = 0xA18;
*stk-- = 0xA19;
*stk-- = 0xA20;
*stk-- = 0xA21;
*stk-- = 0xA22;
*stk-- = 0xA23;
*stk-- = 0xA24;
*stk-- = 0xA25;
*stk-- = 0xA26;
*stk-- = 0xA27;
*stk-- = 0xA28;
*stk-- = 0xA29;
*stk-- = 0xA30;
*stk-- = 0xA31;
*stk-- = 0xB0;
*stk-- = 0xB1;
*stk-- = 0xB2;
//B3 has been saved at the beginning
*stk-- = 0xB4;
*stk-- = 0xB5;
*stk-- = 0xB6;
*stk-- = 0xB7;
*stk-- = 0xB8;
*stk-- = 0xB9;
*stk-- = 0xB10;
*stk-- = 0xB11;
*stk-- = 0xB12;
*stk-- = 0xB13;
*stk-- = DSP_C6x_GetCurrentDP(); /* Save current data pointer */
//b15 is saved in TCB
*stk-- = 0xB16;
*stk-- = 0xB17;
*stk-- = 0xB18;
*stk-- = 0xB19;
*stk-- = 0xB20;
*stk-- = 0xB21;
*stk-- = 0xB22;
*stk-- = 0xB23;
*stk-- = 0xB24;
*stk-- = 0xB25;
*stk-- = 0xB26;
*stk-- = 0xB27;
*stk-- = 0xB28;
*stk-- = 0xB29;
*stk-- = 0xB30;
*stk-- = 0xB31;
*stk-- = 0x0; /* AMR default value as it was after reset*/
*stk-- = 0x0102; /* CSR Little Endian(bit8 = 1); PGIE set 1;
GIE set 0 to prevent interrupt when call OSStartHighRdy in OS_Start*/
//*stk-- = 0x02; /* IER Just set the NMIF bit */
*stk-- = (int)task; /* IRP Put pointer to task */
*stk-- = 0xAA; /* make SP on an 8-bytes boundary */
//stk--; make SP on an 8-bytes boundary
return ( (OS_STK *)stk );
}
/*
*********************************************************************************************************
* OS INITIALIZATION HOOK
* (BEGINNING)
*
* Description: This function is called by OSInit() at the beginning of OSInit().
*
* Arguments : none
*
* Note(s) : 1) Interrupts should be disabled during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION > 203
void OSInitHookBegin (void)
{
}
#endif
/*
*********************************************************************************************************
* OS INITIALIZATION HOOK
* (END)
*
* Description: This function is called by OSInit() at the end of OSInit().
*
* Arguments : none
*
* Note(s) : 1) Interrupts should be disabled during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION > 203
void OSInitHookEnd (void)
{
}
#endif
/*$PAGE*//*
*********************************************************************************************************
* 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.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
void OSTaskCreateHook (OS_TCB *ptcb)
{
ptcb = ptcb; /* Prevent compiler warning */
}
#endif
/*
*********************************************************************************************************
* 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.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
void OSTaskDelHook (OS_TCB *ptcb)
{
ptcb = ptcb; /* Prevent compiler warning */
}
#endif
/*
*********************************************************************************************************
* 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) : 1) Interrupts are enabled during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION >= 251
void OSTaskIdleHook (void)
{
}
#endif
/*
*********************************************************************************************************
* 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
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
void OSTaskStatHook (void)
{
}
#endif
/*
*********************************************************************************************************
* 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).
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
void OSTaskSwHook (void)
{
}
#endif
/*
*********************************************************************************************************
* OSTCBInit() HOOK
*
* Description: This function is called by OS_TCBInit() after setting up most of the TCB.
*
* Arguments : ptcb is a pointer to the TCB of the task being created.
*
* Note(s) : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION > 203
void OSTCBInitHook (OS_TCB *ptcb)
{
ptcb = ptcb; /* Prevent Compiler warning */
}
#endif
/*
*********************************************************************************************************
* TICK HOOK
*
* Description: This function is called every tick.
*
* Arguments : none
*
* Note(s) : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
void OSTimeTickHook (void)
{
}
#endif
/*********************************************************************************************************
* HANDLE TIMER TICK ISR
* - void OSTickISR(void) -
*
* Description: This function is the C6x-DSP Timer0 ISR. And the timer tick should be 10~100 /sec.
* It also offers the time tick to uC/OS-II.
**********************************************************************************************************
*/
void OSTickISR(void)
{
intCount++;
ctwSave();
OSIntEnter();
if (OSIntNesting == 1)
{
OSTCBCur->OSTCBStkPtr = (OS_STK *) DSP_C6x_GetCurrentSP();
}
/* You can enable Interrupt again here,
if want to use nested interrupt..... */
OSTimeTick();
OSIntExit();
ctwRest();
//asm (" nop 5"); //important!
// this can avoid a stack error when compile with the optimization!
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -