📄 os_cpu_c.c
字号:
// SCISend1(*(INT8U *)pdata);
stk = (INT16U *)ptos; //加载堆栈指针,空两个字节
*--stk = opt; //该一个字节为特殊选项,存用户参数
*--stk = (INT16U)task; //PC入栈
*--stk = (INT16U)(0x1122); //Y
*--stk = (INT16U)(0x3344); //X
((INT8U *)stk)--;
*(INT8U *)stk = (INT8U)(((INT16U)pdata)>>8); //A
((INT8U *)stk)--;
*(INT8U *)stk = (INT8U)(pdata); //B
((INT8U *)stk)--;
*(INT8U *)stk = (INT8U)(0x00); //CCR
((INT8U *)stk)--;
*(INT8U *)stk = *(INT8U *)pdata; //只有PPAGE一个内容
return ((void *)stk);
}
/*$PAGE*/
/*
*********************************************************************************************************
* INITIALIZE A TASK'S STACK FOR FLOATING POINT EMULATION
*
* Description: This function MUST be called BEFORE calling either OSTaskCreate() or OSTaskCreateExt() in
* order to initialize the task's stack to allow the task to use the Borland floating-point
* emulation. The returned pointer MUST be used in the task creation call.
*
* Ex.: OS_STK TaskStk[1000];
*
*
* void main (void)
* {
* OS_STK *ptos;
* OS_STK *pbos;
* INT32U size;
*
*
* OSInit();
* .
* .
* ptos = &TaskStk[999];
* pbos = &TaskStk[0];
* psize = 1000;
* OSTaskStkInit_FPE_x86(&ptos, &pbos, &size);
* OSTaskCreate(Task, (void *)0, ptos, 10);
* .
* .
* OSStart();
* }
*
* Arguments : pptos is the pointer to the task's top-of-stack pointer which would be passed to
* OSTaskCreate() or OSTaskCreateExt().
*
* ppbos is the pointer to the new bottom of stack pointer which would be passed to
* OSTaskCreateExt().
*
* psize is a pointer to the size of the stack (in number of stack elements). You
* MUST allocate sufficient stack space to leave at least 384 bytes for the
* floating-point emulation.
*
* Returns : The new size of the stack once memory is allocated to the floating-point emulation.
*
* Note(s) : 1) _SS is a Borland 'pseudo-register' and returns the contents of the Stack Segment (SS)
* 2) The pointer to the top-of-stack (pptos) will be modified so that it points to the new
* top-of-stack.
* 3) The pointer to the bottom-of-stack (ppbos) will be modified so that it points to the new
* bottom-of-stack.
* 4) The new size of the stack is adjusted to reflect the fact that memory was reserved on
* the stack for the floating-point emulation.
*********************************************************************************************************
*/
/*$PAGE*/
//void OSTaskStkInit_FPE_x86 (OS_STK **pptos, OS_STK **ppbos, INT32U *psize)
//{
// INT32U lin_tos; /* 'Linear' version of top-of-stack address */
// INT32U lin_bos; /* 'Linear' version of bottom-of-stack address */
// INT16U seg;
// INT16U off;
// INT32U bytes;
// seg = FP_SEG(*pptos); /* Decompose top-of-stack pointer into seg:off */
// off = FP_OFF(*pptos);
// lin_tos = ((INT32U)seg << 4) + (INT32U)off; /* Convert seg:off to linear address */
// bytes = *psize * sizeof(OS_STK); /* Determine how many bytes for the stack */
// lin_bos = (lin_tos - bytes + 15) & 0xFFFFFFF0L; /* Ensure paragraph alignment for BOS */
// seg = (INT16U)(lin_bos >> 4); /* Get new 'normalized' segment */
// *ppbos = (OS_STK *)MK_FP(seg, 0x0000); /* Create 'normalized' BOS pointer */
// memcpy(*ppbos, MK_FP(_SS, 0), 384); /* Copy FP emulation memory to task's stack */
// bytes = bytes - 16; /* Loose 16 bytes because of alignment */
// *pptos = (OS_STK *)MK_FP(seg, (INT16U)bytes); /* Determine new top-of-stack */
// *ppbos = (OS_STK *)MK_FP(seg, 384); /* Determine new bottom-of-stack */
// bytes = bytes - 384;
// *psize = bytes / sizeof(OS_STK); /* Determine new stack size */
//}
/*$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)
{
}
#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)
{
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)
{
}
#endif
//OSStartHighRdy:让优先级最高的任务运行函数--------------------------------*
//功 能:让优先级最高的就绪态任务开始运行 *
//参 数:无 *
//返 回:无 *
//-------------------------------------------------------------------------*
void OSStartHighRdy(void)
{
OSTaskSwHook();
OSRunning = 1;
asm{
ldx OSTCBCur //将TCB的地址给X
lds 0,X //将值给SP
pula
staa $30 //恢复页面寄存器
nop //延时
rti
}
}
//OSIntCtxSw:中断级任务切换函数--------------------------------------------*
//功 能:如果在中断服务结束时,中断中激活了更高优先级的任务,则调用该函数 *
//参 数:无 *
//返 回:无 *
//-------------------------------------------------------------------------*
void OSIntCtxSw(void)
{
OSTaskSwHook();
OSTCBCur = OSTCBHighRdy; //Change OSTCBCur and OSPrioCur
OSPrioCur = OSPrioHighRdy;
asm{
ldx OSTCBCur //get the new task's TCB's address
lds 0,x
pula
staa $30
nop //retore ppage from stack
rti
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -