OS_CPU_C.C源程序:
关键是堆栈初始化的函数OSTaskStkInit()和OSTickISR(),其他的函数只声明一下就可以了
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1992-1998, Jean J. Labrosse, Plantation, FL
* All Rights Reserved
*
* TI C6414 DSP Specific code
* Little Endian Mode*
* Code Composer Studio V3.1
*
* File : OS_CPU_C.C
*********************************************************************************************************
*/
#define OS_CPU_GLOBALS
#include "..\..\..\Project\includes.h"
/*
*********************************************************************************************************
* 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)
{
INIT_STACK_FRAME *StkFrame, *StackBottom;
int * StackFreePointer ;
/* THE SP MUST BE ALIGNED ON AN 8-BYTE BOUNDARY.*/
StkFrame = (INIT_STACK_FRAME *) ((int)ptos &~7 );
StackBottom = StkFrame ;
StkFrame-- ; /* to the bottom of the frame, to init the struct. */
StkFrame->Start_Address = task ;
StkFrame->A0 = 0x0A00 ;
StkFrame->A1 = 0x0A01 ;
StkFrame->A2 = 0x0A02 ;
StkFrame->A3 = 0x0A03 ;
StkFrame->A4 = (int) pdata ; /* the first argument of C function here*/
StkFrame->A5 = 0x0A05 ;
StkFrame->A6 = 0x0A06 ;
StkFrame->A7 = 0x0A07 ;
StkFrame->A8 = 0x0A08 ;
StkFrame->A9 = 0x0A09 ;
StkFrame->A10 = 0x0A10 ;
StkFrame->A11 = 0x0A11 ;
StkFrame->A12 = 0x0A12 ;
StkFrame->A13 = 0x0A13 ;
StkFrame->A14 = 0x0A14 ;
StkFrame->A15 = 0x0A15 ;
StkFrame->A16 = 0x0A16 ;
StkFrame->A17 = 0x0A17 ;
StkFrame->A18 = 0x0A18 ;
StkFrame->A19 = 0x0A19 ;
StkFrame->A20 = 0x0A20 ;
StkFrame->A21 = 0x0A21 ;
StkFrame->A22 = 0x0A22 ;
StkFrame->A23 = 0x0A23 ;
StkFrame->A24 = 0x0A24 ;
StkFrame->A25 = 0x0A25 ;
StkFrame->A26 = 0x0A26 ;
StkFrame->A27 = 0x0A27 ;
StkFrame->A28 = 0x0A28 ;
StkFrame->A29 = 0x0A29 ;
StkFrame->A30 = 0x0A30 ;
StkFrame->A31 = 0x0A31 ;
StkFrame->B0 = 0x0B00 ;
StkFrame->B1 = 0x0B01 ;
StkFrame->B2 = 0x0B02 ;
StkFrame->B3 = (int) task ; //for cosmetic reason
StkFrame->B4 = 0x0B04 ;
StkFrame->B5 = 0x0B05 ;
StkFrame->B6 = 0x0B06 ;
StkFrame->B7 = 0x0B07 ;
StkFrame->B8 = 0x0B08 ;
StkFrame->B9 = 0x0B09 ;
StkFrame->B10 = 0x0B10 ;
StkFrame->B11 = 0x0B11 ;
StkFrame->B12 = 0x0B12 ;
StkFrame->B13 = 0x0B13 ;
StkFrame->B14 = DSP_C6x_GetCurrentDP() ; /* Save current data pointer */
StkFrame->B15 = (int) StackBottom ; /* Save the SP */
StkFrame->B16 = 0x0B16 ;
StkFrame->B17 = 0x0B17 ;
StkFrame->B18 = 0x0B18 ;
StkFrame->B19 = 0x0B19 ;
StkFrame->B20 = 0x0B20 ;
StkFrame->B21 = 0x0B21 ;
StkFrame->B22 = 0x0B22 ;
StkFrame->B23 = 0x0B23 ;
StkFrame->B24 = 0x0B24 ;
StkFrame->B25 = 0x0B25 ;
StkFrame->B26 = 0x0B26 ;
StkFrame->B27 = 0x0B27 ;
StkFrame->B28 = 0x0B28 ;
StkFrame->B29 = 0x0B29 ;
StkFrame->B30 = 0x0B30 ;
StkFrame->B31 = 0x0B31 ;
StkFrame->AMR = 0 ; /*default value as it was after reset*/
StkFrame->CSR = 0x0103 ; /* Little Endian(bit8 = 1); PGIE set 1; GIE set 1 */
StkFrame->IER = 0x02 ; /* Just set the NMIF bit */
StkFrame->IRP = 0xabcdabcd ; /* never return, so any value could used here. */
StackFreePointer = (int *) StkFrame ;
StackFreePointer-- ; /* Jusr move 4-BYTE(int) to the next free position */
return ((OS_STK *) StackFreePointer);
}
/*$PAGE*/ /*
*********************************************************************************************************
* 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)
{
DSP_C6x_Save();
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();
DSP_C6x_Resume();
asm (" nop 5"); //important!
// this can avoid a stack error when compile with the optimization!
}
/*$PAGE*/
/*
*********************************************************************************************************
* 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