📄 os_cpu_c.c
字号:
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1992-1999, Jean J. Labrosse, Weston, FL
* All Rights Reserved
*
*
* C164CI Specific code
* LARGE MEMORY MODEL
*
* File : OS_CPU_C.C
* By : Jean J. Labrosse
* Michael Awosika
*********************************************************************************************************
*/
#define OS_CPU_GLOBALS
#include "MAIN.H"
/*
*********************************************************************************************************
* INITIALISE A TASK'S STACK
*
* Description: This function is called by either OSTaskCreate() or OSTaskCreateExt() to initialise the
* stack frame of the task being created. This function is highly processor specific.
*
* 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().
*
* 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 0x0800 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!
*
*********************************************************************************************************
*/
OS_STK *OSTaskStkInit (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT16U opt)
{
INT16U *stk;
INT32U usr;
INT16U page;
INT16U offset;
INT16U data_pag;
INT16U data_pof;
opt = opt; /* 'opt' is not used, prevent warning */
data_pag = (INT16U)((INT32U)pdata >> 16);
data_pof = ((INT16U) pdata & 0xFFFF);
stk = (INT16U *)ptos; /* Load stack pointer */
*stk-- = data_pag;
*stk-- = data_pof;
*stk-- = (INT16U)((INT32U)task >> 16); /* 任务函数段开始地址 */
*stk-- = ((INT16U)task & 0xFFFF); /* 任务函数段内偏移量 */
*stk-- = (INT16U)0xFBFE; /* 任务的系统堆栈指针 */
usr = (INT32U)stk;
offset = (INT16U)((((usr) & 0x3FFF) - 10) | 0x4000); /* Task user stack offset */
*stk-- = offset;
page = (INT16U)(usr >> 0x000E); /* Task user stack page */
*stk-- = page;
*stk-- = (INT16U)0x0800; /* Task PSW = Interrupts enabled */
*stk-- = ((INT16U)task & 0xFFFF); /* Task offset return address */
*stk-- = (INT16U)((INT32U)task >> 16); /* Task segment return address */
OSTaskBuildStk(page, offset, data_pag, data_pof);
return ((OS_STK *)stk);
}
/*$PAGE*/
/*$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 *ptcb)
{
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 *ptcb)
{
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)
{
}
/*
*********************************************************************************************************
* 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)
{
}
/*
*********************************************************************************************************
* 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)
{
}
#endif
/*
*********************************************************************************************************
* BUILD A TASK'S STACK AREA
*
* Description: This function is called by OSTaskStkInit to initialise the
* stack frame of the task being created.
*
* Arguments : page is a pointer to the current task user stack page.
*
* offset is a pointer to the current task user stack offset.
*
* datapag is a pointer to a user supplied data area page when the task first executes.
*
* datapof is a pointer to a user supplied data area offset when the task first executes.
*
* Returns : None
*********************************************************************************************************
*/
void OSTaskBuildStk (INT16U page, INT16U offset, INT16U datapag, INT16U datapof)
{
page = page; // The compiler assign page to R8
offset = offset; // The compiler assign offset to R9
datapag = datapag; // The compiler assign datapag to R10
datapof = datapof; // The compiler assign datapof to R11
#pragma asm
; ; SAVE USED REGISTERS
PUSH R1
PUSH R2
PUSH R3
PUSH R4
PUSH R10
PUSH R11
PUSH R12
; ; LOAD INITIAL TASK STACK.
MOV R4,R9 ; //任务堆栈偏移量
MOV R2,R10 ; //参数页号
MOV R3,R11 ; //参数偏移量
EXTP R8,#1 ; //调整任务堆栈偏移指针
MOV R1,[R4+#0x0A] ; Get initial user offset pointer
SUB R1,#2Eh ; adjust user offset pointer to save task registers
EXTP R8,#1
MOV [R4+#0x0A],R1 ; //保存用户堆栈偏移量指针
MOV R9 ,#0x1111 ; R1 initialised to 1111
MOV R10,#0x2222 ; R2 initialised to 2222
MOV R11,#0x3333 ; R3 initialised to 3333
MOV R12,#0x4444 ; R4 initialised to 4444
EXTP R8,#4
MOV [-R4],R9
MOV [-R4],R10
MOV [-R4],R11
MOV [-R4],R12
MOV R9, #0x5555 ; R5 initialised to 5555
MOV R10,#0x6666 ; R6 initialised to 6666
MOV R11,#0x7777 ; R7 initialised to 7777
MOV R12,R3 ; R8 initialised to point @ POF of pdata
EXTP R8,#4
MOV [-R4],R9
MOV [-R4],R10
MOV [-R4],R11
MOV [-R4],R12
MOV R9 ,R2 ; R9 initialised to point @ PAG of pdata
MOV R10,#0xAAAA ; R10 initialised to AAAA
MOV R11,#0xBBBB ; R11 initialised to BBBB
MOV R12,#0xCCCC ; R12 initialised to CCCC
EXTP R8,#4
MOV [-R4],R9
MOV [-R4],R10
MOV [-R4],R11
MOV [-R4],R12
MOV R9 ,#0xDDDD ; R13 initialised to DDDD
MOV R10,#0xEEEE ; R14 initialised to EEEE
MOV R11,#0xFFFF ; R15 initialised to FFFF
MOV R12,CP ; Get the Context Pointer (CP)
EXTP R8,#4
MOV [-R4],R9
MOV [-R4],R10
MOV [-R4],R11
MOV [-R4],R12
MOV R9 ,DPP3 ; Get Data Page Pointer 3 (DPP3)
MOV R10,DPP2 ; Get Data Page Pointer 2 (DPP2)
MOV R11,DPP0 ; Get Data Page Pointer 0 (DPP0)
EXTP R8,#3
MOV [-R4],R9 ; Put it on the user stack
MOV [-R4],R10 ; Put it on the user stack
MOV [-R4],R11 ; Put it on the user stack
MOV R9,#0x00 ; PSW initialised to 0
EXTP R8,#4
MOV [-R4],R9 ; Set Multiply/Divide Control (MDC)
MOV [-R4],R9 ; Set Multiply/Divide High (MDH)
MOV [-R4],R9 ; Set Multiply/Divide Low (MDL)
MOV [-R4],R9 ; Set Temporary PSW (Cleared)
; ; RESTORE USED REGISTERS
POP R12
POP R11
POP R10
POP R4
POP R3
POP R2
POP R1
#pragma endasm
}
/*$PAGE*/
/*
*********************************************************************************************************
* INITIALIZE SYSTEM TICK
*
* Description: This function is called to initialize and configure the system interrupt tick.
*
* Arguments : none
*********************************************************************************************************
*/
/*
void OSTickISRInit (void)
{
// Configure RTC interrupt Priority Level (ILVL) = 1, //
// Group Level (GLVL) = 1 //
XP3IC = 0x006F; // and start the RTC interrupt operation //
RTCIE = 1; // Enable RTC interrupt in sub-node register //
T14REL = 0xFC2F; // ----- Timer 14 reload register ---- //
T14 = 0xFC2F; // time base = 25 ms //
}
*/
#define MS_OF_ONE_TIMER 10; //每个时钟节怕的毫秒数
int GetTickCnt(INT32U ms)
{
return ms / MS_OF_ONE_TIMER;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -