📄 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"
/*与CPU硬件及编译器相关的代码,在UCOS_II.H中声明*/
SYS_Stk sys_stk_info;
SYS_Stk *Sys_sp;
/*任务堆栈初始化*/
void *OSTaskStkInit (void (*task)(void *pd), void *pdata, void *ptos, INT16U opt)
{
unsigned int *stk;
opt = opt; /* 'opt' is not used, prevent warning */
stk = (unsigned int *)ptos; /* Load stack pointer 当前的栈底 */
/* build a context for the new task */
*--stk = opt;
*--stk = (unsigned int) task; /* opt maybe need pc */
*--stk = (unsigned int) task; /* pc */
*--stk = 0x0000; /* Y */
*--stk = 0x0000; /* X */
*--stk = 0; /* A,B */
((INT8U *)stk)--;
*(INT8U *)stk=(INT8U)(0x00);/*CCR*/
//((INT8U *)stk)--;
//*(INT8U *)stk=*(INT8U *)pdata;/*PPAGE*//*在建立任务时 需要利用pdata这个参数将PPAGE信息传入*/
return ((void *)stk);
}
/*优先级最高的就绪任务开始运行*/
void OSStartHighRdy(void){
OSRunning=1;
Sys_sp=&sys_stk_info;//指向SYS_Stk这个结构体
asm{
ldx Sys_sp
sts 0,x //save sp to Sys_sp
ldx OSTCBCur
lds 0,x
//pula /*出栈并赋值给A*/
//staa $30/*把A的值传递给 PPAGE(0x30)*/
//nop
rti/*出栈顺序CCR,B,A,X,Y,PC*/
}
}
/*任务级任务切换函数*/
void OSCtxSw(void){
asm{
pshy
pshx
pshd
pshc //模拟中断保存现场 PC在Call OSCtxSw()已经保存
//ldaa $30 //save PPAGE to A
//psha //save A to stack
ldx OSTCBCur
sts 0,x //save sp to OSTCBCur
}
OSTCBCur = OSTCBHighRdy;
OSPrioCur = OSPrioHighRdy;
asm{
ldx OSTCBCur //Get the new OSTCBCur to x
lds 0,x //load x to sp
//pula
//staa $30
rti
}
}
/*中断级任务切换函数*/
void OSIntCtxSw(void){
//从系统堆栈切换回任务堆栈
asm{
ldx Sys_sp
ins
ins
ins
ins //调整堆栈深度OSIntExit 2byte OSIntCtxSw 2byte
sts 0,x //save sp to Sys_sp
}
//进入中断时系统已经在被打断任务的堆栈中保存了信息
OSTCBCur = OSTCBHighRdy;
OSPrioCur = OSPrioHighRdy;
asm{
ldx OSTCBCur //Get the new OSTCBCur to x
lds 0,x //load x to sp
//pula //PPAGE 在中断调用时已经入栈
//staa $30
//nop
rti
}
}
/*$PAGE*/
#if OS_CPU_HOOKS_EN
/*
*********************************************************************************************************
* 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)
{
}
/*
*********************************************************************************************************
* 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)
{
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -