📄 os_cpu_c.c
字号:
//******************************************************************
// 单位: 福建三明学院物理与机械工程系
// 作者: 林峰彬 (一水寒)
// QQ: 364700581
// 文件: OS_CPU_C.c for unsp
//******************************************************************
#define OS_CPU_GLOBALS
#include <ucos_ii.h>
#include "spce061v004.h"
/*******************************************************************
堆栈初始化函数
该函数在创建任务时调用,用于对个寄存器初始化
********************************************************************/
OS_STK *OSTaskStkInit(void (*task)(void *pd), void *p_arg, OS_STK *ptos, INT16U opt)
{
OS_STK* stk;
stk=(OS_STK*)ptos;
*stk--=(OS_STK)p_arg;
*stk--=*((INT16U*)task+1);
*stk--=0x0000; /* SR */
*stk--=*((INT16U*)task+1);/* pc */
*stk--=0x0000; /* SR */
*stk--=0x0000; /* R1 */
*stk--=0x0000; /* R2 */
*stk--=0x0000; /* R3 */
*stk--=0x0000; /* R4 */
*stk--=0x0000; /* R5 */
return ((void *)stk);
}
void OSStartHighRdy()
{
OS_STK *SaveSp;
OSTaskSwHook();
SaveSp=OSTCBHighRdy->OSTCBStkPtr;
asm("SP =%0 " : :"r"(SaveSp));
OSRunning = TRUE;
asm("POP BP,R1 from [sp] \n\t"
"INT FIQ\n\t"
"INT IRQ\n\t"
"RETI\n\t");
}
//********************************************************************
// 打开SPACE061A的时间基准信号中断
//********************************************************************
void OSTickISR()
{
*P_INT_Ctrl=0x0001;
}
//********************************************************************
// 该中断采用SPACE061A的时间基准信号产生调度信号
// 注意要 在程序开始前对该中断初始化
//********************************************************************
//********************************************************************
void BREAK(void)__attribute__((ISR));
void BREAK()
{
OS_STK *SaveSp;
asm("%0 = SP" : "=r"(SaveSp));
SaveSp+=2;
OSTCBCur->OSTCBStkPtr=SaveSp;
OSTaskSwHook();
OSTCBCur = OSTCBHighRdy;
OSPrioCur = OSPrioHighRdy;
SaveSp=OSTCBHighRdy->OSTCBStkPtr;
SaveSp-=2;
asm("SP = %0" : : "r"(SaveSp));
}
void IRQ6(void)__attribute__((ISR));
void IRQ6(void)
{
OSIntEnter();
if (OSIntNesting == 1)
{
asm("%0 = SP" : "=r"(OSTCBCur->OSTCBStkPtr));
(OSTCBCur->OSTCBStkPtr)++;
}
OSTimeTick();
*P_INT_Clear=0x0001;
OSIntExit();
}
//*********************************************************************
// 仅需调整SP指针,然后进行任务切换
//*********************************************************************
void OSIntCtxSw()
{
OS_STK *Save_Sp;
OSTaskSwHook();
OSTCBCur = OSTCBHighRdy;
OSPrioCur = OSPrioHighRdy;
Save_Sp=OSTCBHighRdy->OSTCBStkPtr ;
asm("SP = %0" : : "r"(Save_Sp));
asm("POP BP,R1 from [sp] \n\t"
"INT FIQ\n\t"
"INT IRQ\n\t"
"RETI\n\t");
}
//********************************************************************
// 该中断采用SPACE061A的时间基准信号产生调度信号
// 注意要 在程序开始前对该中断初始化
//********************************************************************
//************************************************************************
#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.
*********************************************************************************************************
*/
#if OS_TASK_DEL_EN > 0
void OSTaskDelHook (OS_TCB *ptcb)
{
ptcb = ptcb; /* Prevent compiler warning */
}
#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).
*********************************************************************************************************
*/
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -