📄 os_cpu_c.c
字号:
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1992-1998, Jean J. Labrosse, Plantation, FL
* All Rights Reserved
*
*
* KeilC51 Specific code
* SMALL MEMORY MODEL
*
* File : OS_CPU_C.C
* By : Jean J. Labrosse
* Refer to Code Written By : Yang Yi (http://www.zlgmcu.com/philips/philips-embedsys.asp)
* Port to KeilC51 Small Mode By : Li Zhanglin (wzzlin@nankai.edu.cn)
*********************************************************************************************************
*/
#define OS_CPU_GLOBALS
#define UCOS51_GLOBALS
#include "..\uc_os_II\includes.h"
#include "..\Ex1_Keil\ucos51_bl.h"
/*
*********************************************************************************************************
* OSTaskStkInit
*
* Description: Init stack before task running.
*
* Arguments : task is a pointer to the task code
*
* 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 bottom of stack.
*
* Note(s) : 1) stack stored as following format
; CONTENT START POSITION IN OSTCBStk
; ---------- ----------------------
; AR7
; AR6
; AR5
; AR4
; AR3
; AR2
; AR1
; AR0
; PSW
; DPL
; DPH
; B
; ACC
; HARDWARE STACK CONTENT(NOT INCLUDE REGISTERS) 2+SmltStkSize
; HARDWARE STACK SIZE(INCLUDE REGISTERS) 1+SmltStkSize
; SIMULATED STACK CONTENT 1
; ?C_IBP 0
*********************************************************************************************************
*/
/*
因为uC/OS-II在设计时无法知道当前处理器在进行进程调度时需要保存那些信息.
OSTaskStkInit就是初始化堆栈,让Task看起来就好像刚刚进入中断并保存好寄存器的值一样.
当OS_Sched调度到该Task时,只需切换到该堆栈中,将寄存器值Pop出来,然后执行一个中断返回指令IRET即可。
*/
void DT_XDATA *OSTaskStkInit (void (DT_CODE *task)(void DT_XDATA *pd), void DT_XDATA *ppdata, void DT_XDATA *ptos, INT16U opt) REENTRANT
{
/*一般是将pdata入栈,flag入栈,task入栈,然后将各寄存器依次入栈。*/
OS_STK DT_XDATA *stk;
ppdata = ppdata;
opt = opt; /* 保留此句防止警告产生 */
/*每个任务传过来一个堆栈栈顶(增长型TOP为最低,减少型TOP为最高).从这个TOP堆栈起分别压入2+13个寄存器的内容.
当调用这个任务的TCB的就好象刚刚发生中断一样.从TOP起还原2+13个寄存器.使程序从这个任务重新开始*/
stk = (OS_STK DT_XDATA *)ptos; /* 用户堆栈最低地址 */
*stk++ = (0xFF + 1); /* C_IBP */
/* simulated stack size == 0 */
*stk++ = 2 + 13; /* tow bytes of return address and 13 byte registers */
*stk++ = (INT16U)task & 0xFF; /* 保存返回的地址--低地址 */
*stk++ = (INT16U)task >> 8; /* 保存返回的地址--高地址 */
*stk++ = 0x0A; /* ACC */
*stk++ = 0x0B; /* B */
*stk++ = 0xD1; /* DPH */
*stk++ = 0xD0; /* DPL */
*stk++ = 0x00; /* PSW */
*stk++ = 0x00; /* R0 */
*stk++ = 0x01; /* R1 */
*stk++ = 0x02; /* R2 */
*stk++ = 0x03; /* R3 */
*stk++ = 0x04; /* R4 */
*stk++ = 0x05; /* R5 */
*stk++ = 0x06; /* R6 */
*stk++ = 0x07; /* R7 */
return ((void DT_XDATA *)ptos); /* note return ptos, not stk */
}
/*
*********************************************************************************************************
* OS Time ISR
*
* Description: use T0.
*
* Arguments :
*
* Note(s) : in default, OSTickISR using register bank 0. Register pushing code will added by keilC.
*********************************************************************************************************
*/
//2ms
void OSTickISR() interrupt 1
{
TH0 = TIMER_24M_25MS_H;
TL0 = TIMER_24M_25MS_L;
OSIntEnter();
OSMboxPost (LEDSM,(void*)1);
if(++time0>=5) //10MS
{
time0=0;
OSTimeTick();
}
OSIntExit();
}
/*$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 DT_XDATA *ptcb) REENTRANT
{
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 DT_XDATA *ptcb) REENTRANT
{
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) REENTRANT
{
}
/*
*********************************************************************************************************
* 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) REENTRANT
{
}
/*
*********************************************************************************************************
* 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) REENTRANT
{
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -