📄 os_cpu_c.c
字号:
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
* All Rights Reserved
*
*
* at89c55wd Specific code
* LARGE MEMORY MODEL
*
* keil C/C++ V7.2
*
* File : OS_CPU_C.C
* By : Jean J. Labrosse
* Port by : NiuYi(牛毅)
* 修补 : 2005-05-02-01:30 (增加了中断管理)
*********************************************************************************************************
*/
#define OS_CPU_GLOBALS
#include "includes.h"
/*
*********************************************************************************************************
* 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) LG_REENTRANT
{
}
#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) LG_REENTRANT
{
}
#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) LG_REENTRANT
{
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) LG_REENTRANT
{
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) LG_REENTRANT
{
// SBUF='i';
// while(TI==0);TI=0;
//printf ("idle task");
}
#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) LG_REENTRANT
{
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* 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
*
* os_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. You can change this by setting the
* PSW to 0x0002 instead. In this case, interrupts would be disabled upon task startup. The
* application code would be responsible for enabling interrupts at the beginning of the task
* code. You will need to modify OSTaskIdle() and OSTaskStat() so that they enable
* interrupts. Failure to do this will make your system crash!
*********************************************************************************************************
*/
/*
at89c55wd PDL(sp form LOW to HIGH): (堆栈指针所指的栈顶数据为有效数据)
装入堆栈指针ptos到stk
stk--> 入栈:task底\高 (高内存)
入 || 入栈:ACC
栈 || 入栈:B
顺 || 入栈:DPH //暂时忽略第二指针
序 || 入栈:DPL
| \/ | 入栈:PSW
| | 入栈:R7-R4
|______| 入栈:os_pdata(R3,R2,R1)用寄存器传递os_pdata
入栈:R0 (底内存)
// 入栈:DPS?? //双数据指针选择寄存器??
// 入栈:PC
自己应该参照编译器定义入栈/出栈顺序,写出来备以后查阅
*/
OS_STK *OSTaskStkInit (void (*task)(void *pd)LG_REENTRANT, void *os_pdata, OS_STK *ptos, INT16U opt) LG_REENTRANT
{
//INT16U *stk;
OS_STK *stk;
opt = opt; /* 'opt' is not used, prevent warning */
stk = (OS_STK *)ptos; /* Load stack pointer */
//装入堆栈指针ptos到stk
*stk = 0; //入栈:R0
stk -= sizeof(void *);
*(void **)stk = (void *)os_pdata; //用寄存器传递os_pdata
*--stk = 4; //入栈:R4-R7
*--stk = 5;
*--stk = 6;
*--stk = 7;
*--stk = PSW; //入栈:PSW
*--stk = 'L'; //入栈:DPL
*--stk = 'H'; //入栈:DPH //暂时忽略第二指针
*--stk = 'B'; //入栈:B
*--stk = 'A'; //入栈:ACC
*--stk = ((INT16U)task & 0xff00) >> 8; //保存任务地址
*--stk = (INT16U)task & 0x00ff;
*--stk = 15; //入栈个数
//END
return ((OS_STK *)stk);
}
/*$PAGE*/
/*
*********************************************************************************************************
* INITIALIZE A TASK'S STACK FOR FLOATING POINT EMULATION
*
*********************************************************************************************************
*/
/*$PAGE*/
//void OSTaskStkInit_FPE_x86 (OS_STK **pptos, OS_STK **ppbos, INT32U *psize)
//{
//}
/*$PAGE*/
/*
*********************************************************************************************************
* 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) LG_REENTRANT
{
}
#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) LG_REENTRANT
{
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) LG_REENTRANT
{
}
#endif
/*
*********************************************************************************************************
* 中断服务程序外挂
* NOTE : 注意:所有中断外挂都在临界区之外,用户可以自行控制进/退临界区
*********************************************************************************************************
*/
#if OS_ISR_T1_EN > 0
void OSISR_T1HOOK (void) LG_REENTRANT
{
/* 请在这里输入中断服务程序 */
}
#endif
#if OS_ISR_INT0_EN > 0
void OSISR_INT0HOOK (void) LG_REENTRANT
{
/* 请在这里输入中断服务程序 */
}
#endif
#if OS_ISR_INT1_EN > 0
void OSISR_INT1HOOK (void) LG_REENTRANT
{
/* 请在这里输入中断服务程序 */
}
#endif
#if OS_ISR_S0_EN > 0
void OSISR_S0HOOK (void) LG_REENTRANT
{
/* 请在这里输入中断服务程序 */
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -