📄 os_cpu_c.c
字号:
/*********************************************************************************************************\
* uC/OS-II *
* The Real-Time Kernel *
* *
* (c) Copyright 1992-1999, Jean J. Labrosse, Weston, FL *
* All Rights Reserved *
* *
* Intel 80C52 Specific code *
* LARGE MEMORY MODEL *
* *
* (IAR Systems Embedded Workbench 2.2 Compiler) *
* *
* File : OS_CPU_C.C *
* By : Jean J. Labrosse *
* *
* Ported to the IAR Systems compiler by: A. Fuentes (antonio_fuentes@msl-vlc.com) *
\*********************************************************************************************************/
#define OS_CPU_GLOBALS
#include "includes.h"
/*********************************************************************************************************\
* 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 *
* *
* pfdata 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. *
* *
\*********************************************************************************************************/
pOS_STK OSTaskStkInit(void (*task)(void *), void *pfdata, pOS_STK ptos, INT16U opt)
{
/*<---[ Variables used in this function: ]-------------------------------------------------------------->*/
pOS_STK stk; /* Used to access the task' stack in xdata memory */
INT8U *data_ptr; /* Pointer variable to convert 'pfdata' to a 16-bit value */
INT8U code *task_ptr; /* Pointer variable to convert 'task' to a 16-bit value */
INT16U xsp; /* 16-bit pointer to the base of the task'stack */
INT16U ptr; /* 16-bit pointer to the task parameter area passed at creation */
INT8U tsk_h; /* Upper 8-bits of the task pointer */
INT8U tsk_l; /* Lower 8-bits of the task pointer */
/*<---[ End of variable declaration ]------------------------------------------------------------------->*/
opt = opt; /* 'opt' is not used, prevent warning */
stk = ptos; /* Load stack pointer */
xsp = (INT16U)(stk + 1); /* Store the base of 'xstack' for later use */
task_ptr = (INT8U code *)task; /* ... Convert 'task' pointer to 16-bit value */
tsk_l = *task_ptr++; /* Get lower 8 bits of 'task' */
tsk_h = *task_ptr; /* Get upper 8 bits of 'task' */
*++stk = tsk_h; /* Place upper 8 bits of 'task' on stack */
*++stk = tsk_l; /* Place lower 8 bits of 'task' on stack */
*++stk = 0x00; /* Make room to store the PSW */
*++stk = 0xAC; /* Make room to store the ACC */
*++stk = 0x0B; /* Make room to store the B register */
*++stk = 0x00; /* Make room to store the R0 register */
*++stk = 0x01; /* Make room to store the R1 register */
*++stk = 0x02; /* Make room to store the R2 register */
*++stk = 0x03; /* Make room to store the R3 register */
*++stk = 0x04; /* Make room to store the R4 register */
data_ptr = (INT8U *)pfdata; /* Point to task parameter data */
ptr = (INT16U)data_ptr; /* ... Convert 'pfdata' pointer to 16-bit value */
*++stk = (INT8U)(ptr & 0x00FF); /* Place lower bits of 'pfdata' on stack (passed in R5) */
*++stk = (INT8U)((ptr >> 8) & 0x00FF); /* Place upper bits of 'pfdata' on stack (passed in R6) */
*++stk = 0x01; /* Place pointer type (always 01) (passed in R7) */
*++stk = 0x00; /* Make room to store DPH */
*++stk = 0x00; /* Make room to store DPL */
*++stk = (INT8U)((xsp >> 8) & 0x00FF); /* Place pointer high to base of 'xstack' */
*++stk = (INT8U)(xsp & 0x00FF); /* Place pointer low to base of 'xstack' */
*++stk = 0x11; /* Place number of bytes stacked (17) */
return((pOS_STK)stk); /* Return pointer to task's top-of-stack */
}
/*********************************************************************************************************\
* SYSTEM INITIALIZATION HOOK *
* *
* Description: This function kernel initialisation starts. *
* *
* Arguments : void. *
* *
* Note(s) : 1) Interrupts are disabled during this call. *
\*********************************************************************************************************/
void OSInitHookBegin(void)
{
/*<---[ Variables used in this function: ]-------------------------------------------------------------->*/
/*<---[ End of variable declaration ]------------------------------------------------------------------->*/
}
/*********************************************************************************************************\
* INITIALIZATION COMPLETE HOOK *
* *
* Description: This function is called when kernel initialisation is completed. *
* *
* Arguments : void *
* *
* Note(s) : 1) Interrupts are disabled during this call. *
\*********************************************************************************************************/
void OSInitHookEnd(void)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -