📄 os_cpu_c.c
字号:
{}
void OSTaskIdleHook(void)
{}
void OSTCBInitHook(OS_TCB *ptcb)
{
ptcb=ptcb;
}
#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.
*
* TASK STACK AREA (High Memory)
* 0
* -02 R[1 ..15] General Purpose registers of task
* -20 CP Context pointer of task
* -22 DPP3 Data page pointer 3 of task
* -24 DPP2 Data page pointer 1 of task
* -26 DPP0 Data page pointer 0 of task
* -28 MDC Multiply/Divide Control of task
* -2A MDH Multiply/Divide High register of task
* -2C MDL Multiply/Divide Low register of task (Low Memory)
* -2E PSW OF the interrupting task to preserve the MULIP flag
*
* 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 ; Get pointer to Task Stack
MOV R2,R10 ; Page pointer to passed parameter
MOV R3,R11 ; Offset pointer to passed parameter
; ADJUST THE TASK USER OFFSET POINTER
EXTP R8,#1
MOV R1,[R4+#0x0A] ; Get initial user offset pointer
SUB R1,#0x2E ; adjust user offset pointer to save task registers
EXTP R8,#1
MOV [R4+#0x0A],R1 ; Save true user offset pointer
; INITIALISE REGISTER VALUES
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 ; R10 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)
{
/// -----------------------------------------------------------------------
/// Configuration of Timer Block Prescaler 1:
/// -----------------------------------------------------------------------
/// - prescaler for timer block 1 is 8
/// -----------------------------------------------------------------------
/// Configuration of the GPT1 Core Timer 3:
/// -----------------------------------------------------------------------
/// - timer 3 works in timer mode
/// - external up/down control is disabled
/// - prescaler factor is 8
/// - up/down control bit is reset
/// - alternate output function T3OUT (P3.3) is disabled
/// - timer 3 output toggle latch (T3OTL) is set to 0
/// - timer 3 run bit is reset
GPT12E_T3CON = 0x0000; // load timer 3 control register
GPT12E_T3 = 0x0000; // load timer 3 register
/// -----------------------------------------------------------------------
/// Configuration of the GPT1 Auxiliary Timer 2:
/// -----------------------------------------------------------------------
/// - timer 2 works in timer mode
/// - external up/down control is disabled
/// - prescaler factor is 16
/// - up/down control bit is reset
GPT12E_T2CON = 0x0001; // load timer 2 control register
GPT12E_T2 = 0x0000; // load timer 2 register
/// -----------------------------------------------------------------------
/// Configuration of the GPT1 Auxiliary Timer 4:
/// -----------------------------------------------------------------------
/// - timer 4 works in timer mode
/// - external up/down control is disabled
/// - prescaler factor is 8
/// - up/down control bit is reset
/// - timer 4 run bit is reset
GPT12E_T4CON = 0x0000; // load timer 4 control register
GPT12E_T4 = 0x0000; // load timer 4 register
/// -----------------------------------------------------------------------
/// Configuration of the used GPT1 Port Pins:
/// -----------------------------------------------------------------------
/// -----------------------------------------------------------------------
/// Configuration of the used GPT1 Interrupts:
/// -----------------------------------------------------------------------
/// timer 2 service request node configuration:
/// - timer 2 interrupt priority level (ILVL) = 13
/// - timer 2 interrupt group level (GLVL) = 1
/// - timer 2 group priority extension (GPX) = 0
GPT12E_T2IC = 0x0075;
// USER CODE BEGIN (GPT1_Function,3)
// USER CODE END
GPT12E_T2CON_T2R = 1; // set timer 2 run bit
} // End of function GPT1_vInit
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -