📄 os_cpu_c.c
字号:
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1992-1998, Jean J. Labrosse, Plantation, FL
* All Rights Reserved
* (c) Copyright ARM Limited 1999. All rights reserved.
*
* ARM Specific code
*
*
* File : OS_CPU_C.C
*********************************************************************************************************
*/
#define OS_CPU_GLOBALS
#include "includes.h"
/*********************************************************************************************************
** 函数名称: OSTaskStkInit
** 功能描述: 任务堆栈初始化代码,本函数调用失败会使系统崩溃
** 输 入: task : 任务开始执行的地址
** pdata :传递给任务的参数
** ptos :任务的堆栈开始位置
** opt :附加参数,当前版本对于本函数无用,具体意义参见OSTaskCreateExt()的opt参数
** 输 出: 栈顶指针位置
** 全局变量:
** 调用模块:
********************************************************************************************************/
OS_STK *OSTaskStkInit(
void (*task)(void *pd),
void *pdata,
OS_STK *ptos,
INT16U opt)
{
OS_STK *stk;
opt = opt; /* 'opt' 没有使用。作用是避免编译器警告 */
stk = ptos; /* 获取堆栈指针 */
/* 建立任务环境,ADS1.2使用满递减堆栈 */
*stk = (OS_STK) task; /* pc */
*--stk = (OS_STK) task; /* lr */
*--stk = 0xCCCCCCCC; /* r12 */
*--stk = 0xBBBBBBBB; /* r11 */
*--stk = 0xAAAAAAAA; /* r10 */
*--stk = 0x99999999; /* r9 */
*--stk = 0x88888888; /* r8 */
*--stk = 0x77777777; /* r7 */
*--stk = 0x00000077; /* double r7 保证压堆偶数个寄存器,RVDS的特点 */
*--stk = 0x66666666; /* r6 */
*--stk = 0x55555555; /* r5 */
*--stk = 0x44444444; /* r4 */
*--stk = 0x33333333; /* r3 */
*--stk = 0x22222222; /* r2 */
*--stk = 0x11111111; /* r1 */
*--stk = (unsigned int) pdata; /* r0,第一个参数使用R0传递 */
*--stk = (USER_USING_MODE|0x00); /* spsr,允许 IRQ, FIQ 中断 */
*--stk = 0; /* 关中断计数器OsEnterSum */
return (stk);
}
void SWI_Exception(int SWI_Num, int *Regs)
{
OS_TCB *ptcb;
int R0;
switch(SWI_Num)
{
#if 1
case 0x02:
{/* 宏OS_ENTER_CRITICAL()的代码段 */
__asm
{
MRS R0,SPSR
ORR R0,R0,#NoInt
MSR SPSR_c,R0
}
OsEnterSum++;
break;
}
case 0x03:
{/* 宏OS_EXIT_CRITICAL()的代码段 */
if(--OsEnterSum == 0)
{
__asm
{
MRS R0,SPSR
BIC R0,R0,#NoInt
MSR SPSR_c,R0
}
}
break;
}
case 0x80:
{/* 函数ChangeToSYSMode()的代码段 */
__asm
{
MRS R0,SPSR
BIC R0,R0,#0x1F
ORR R0,R0,#SYS32MODE
MSR SPSR_c,R0
}
break;
}
case 0x81:
{/* 函数ChangeToUSRMode()的代码段 */
__asm
{
MRS R0,SPSR
BIC R0,R0,#0x1F
ORR R0,R0,#USR32MODE
MSR SPSR_c,R0
}
break;
}
case 0x82:
{/* 函数TaskIsARM()的代码段 */
if(Regs[0]<=OS_LOWEST_PRIO)
{
ptcb = OSTCBPrioTbl[Regs[0]];
if(ptcb != NULL)
{
ptcb->OSTCBStkPtr[1] &= ~(1<<5);
}
}
break;
}
case 0x83:
{/* 函数TaskIsTHUMB()的代码段 */
if(Regs[0]<=OS_LOWEST_PRIO)
{
ptcb = OSTCBPrioTbl[Regs[0]];
if(ptcb != NULL)
{
ptcb->OSTCBStkPtr[1] |= (1<<5);
}
}
break;
}
#endif
default :
{
break;
}
}
return;
}
/*********************************************************************************************************
** 函数名称: OSStartHighRdy
** 功能描述: uC/OS-II启动时使用OSStartHighRdy运行第一个任务,
** 实质是产生swi 1指令
** 输 入: 无
** 输 出 : 无
** 全局变量: 无
** 调用模块: 无
**-------------------------------------------------------------------------------------------------------
** 修 改:
** 日 期:
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void OSStartHighRdy(void)
{
_OSStartHighRdy();
}
/* 以下为一些钩子函数,全部为空函数。具体说明请看相关资料 */
#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 + -