📄 自己写的关于ucos-2在arm7上的移植代码.txt
字号:
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* ARM Specific code
*
* ADS1.2
*
*********************************************************************************************************
*/
#include "includes.h"
OS_STK *OSTaskStkInit (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT16U opt)
{
OS_STK *stk;
opt =opt; /* 'opt' is not used, prevent warning */
stk =ptos; /* Load stack pointer(获取堆栈指针) */
*stk =(OS_STK)task; /* pc */
*--stk=(OS_STK)task; /* lr */
*--stk=(unsigned int)0; /* r12 */
*--stk=(unsigned int)0; /* r11 */
*--stk=(unsigned int)0; /* r10 */
*--stk=(unsigned int)0; /* r9 */
*--stk=(unsigned int)0; /* r8 */
*--stk=(unsigned int)0; /* r7 */
*--stk=(unsigned int)0; /* r6 */
*--stk=(unsigned int)0; /* r5 */
*--stk=(unsigned int)0; /* r4 */
*--stk=(unsigned int)0; /* r3 */
*--stk=(unsigned int)0; /* r2 */
*--stk=(unsigned int)0; /* r1 */
*--stk=(unsigned int)pdata; /* r0,第一个参数使用r0传递 */
*--stk=(unsigned int)USR32Mode; /* spsr,任务运行在用户模式下 */
return (stk);
}
void SWI_Exception(int SWI_Num)
{
switch(SWI_Num)
{ /* OS_ENTER_CRITICAL()的代码段 */
case 0x02:
__asm
{
MRS R0,SPSR
ORR R0,R0,#NoInt
MSR SPSR_c,R0
}
break;
/* 宏 OS_EXIT_CRITICAL()的代码段 */
case 0x03:
__asm
{
MRS R0,SPSR
BIC R0,R0,#NoInt
MSR SPSR_c,R0
}
break;
/* 函数ChangeToSYSMode()的代码段 */
case 0x80:
__asm
{
MRS R0,SPSR
BIC R0,R0,#0X1F
ORR R0,R0,#USR32Mode
MSR SPSR_c,R0
}
break;
/* 函数ChangeToUSRMode */
case 0x81:
__asm
{
MRS R0,SPSR
BIC R0,R0,#0x1F
ORR R0,R0,#USR32Mode
MSR SPSR_c,R0
}
break;
default:
break;
}
}
/* 以下为一些钩子函数,全部为空函数。具体说明请看相关资料 */
#if OS_CPU_HOOKS_EN
/*
*********************************************************************************************************
* 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_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_VERSION > 203
void OSInitHookEnd (void)
{
}
#endif
/*
*********************************************************************************************************
* 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)
{
ptcb = ptcb; /* Prevent compiler warning */
}
/*
*********************************************************************************************************
* 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)
{
}
/*
*********************************************************************************************************
* 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)
{
}
/*
*********************************************************************************************************
* OSTCBInit() HOOK
*
* Description: This function is called by OSTCBInit() 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_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.
*********************************************************************************************************
*/
void OSTimeTickHook (void)
{
}
/*
*********************************************************************************************************
* 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_VERSION >= 251
void OSTaskIdleHook (void)
{
}
#endif
#endif
/*********************************************************************************************************
** End Of File
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -