📄 os_cpu_c.c
字号:
*stk-- = (INT16U)FP_OFF(task);
*stk-- = (INT16U)0x0202; /* SW = Interrupts enabled */
*stk-- = (INT16U)FP_SEG(task); /* Put pointer to task on top of stack */
*stk-- = (INT16U)FP_OFF(task);
*stk-- = (INT16U)0xAAAA; /* AX = 0xAAAA */
*stk-- = (INT16U)0xCCCC; /* CX = 0xCCCC */
*stk-- = (INT16U)0xDDDD; /* DX = 0xDDDD */
*stk-- = (INT16U)0xBBBB; /* BX = 0xBBBB */
*stk-- = (INT16U)0x0000; /* SP = 0x0000 */
*stk-- = (INT16U)0x1111; /* BP = 0x1111 */
*stk-- = (INT16U)0x2222; /* SI = 0x2222 */
*stk-- = (INT16U)0x3333; /* DI = 0x3333 */
*stk-- = (INT16U)0x4444; /* ES = 0x4444 */
*stk = _DS; /* DS = Current value of DS */
return ((OS_STK *)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
INT16U d=0;
INT16U d1=0;
void OSTimeTickHook (void)
{
char*s0="500";
char*s1="每";
char*s2="次中断的调度次数:";
char s[8];
if(d==500)
{
PC_DispStr(14,4,s1,DISP_BGND_BLACK+DISP_FGND_WHITE );
PC_DispStr(18,4,s0,DISP_BGND_BLACK+DISP_FGND_WHITE );
PC_DispStr(24,4,s2,DISP_BGND_BLACK+DISP_FGND_WHITE );
sprintf(s,"%d",OSCtxSwCtr);
PC_DispStr(20,d1+5,s,DISP_BGND_BLACK+DISP_FGND_WHITE );
d=0;
d1+=1;
}
d+=1;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -