📄 os_core.s
字号:
;
; void OSStart (void)
; {
; if (OSRunning == FALSE) {
; OS_SchedNew(); /* Find highest priority's task priority number */
; OSPrioCur = OSPrioHighRdy;
; OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run */
; OSTCBCur = OSTCBHighRdy;
; OSStartHighRdy(); /* Execute target specific code to start task */
; }
; }
; /*$PAGE*/
; /*
; *********************************************************************************************************
; * STATISTICS INITIALIZATION
; *
; * Description: This function is called by your application to establish CPU usage by first determining
; * how high a 32-bit counter would count to in 1 second if no other tasks were to execute
; * during that time. CPU usage is then determined by a low priority task which keeps track
; * of this 32-bit counter every second but this time, with other tasks running. CPU usage is
; * determined by:
; *
; * OSIdleCtr
; * CPU Usage (%) = 100 * (1 - ------------)
; * OSIdleCtrMax
; *
; * Arguments : none
; *
; * Returns : none
; *********************************************************************************************************
; */
;
; #if OS_TASK_STAT_EN > 0
; void OSStatInit (void)
; {
; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
; OS_CPU_SR cpu_sr = 0;
; #endif
;
;
;
; OSTimeDly(2); /* Synchronize with clock tick */
; OS_ENTER_CRITICAL();
; OSIdleCtr = 0L; /* Clear idle counter */
; OS_EXIT_CRITICAL();
; OSTimeDly(OS_TICKS_PER_SEC / 10); /* Determine MAX. idle counter value for 1/10 second */
; OS_ENTER_CRITICAL();
; OSIdleCtrMax = OSIdleCtr; /* Store maximum idle counter count in 1/10 second */
; OSStatRdy = TRUE;
; OS_EXIT_CRITICAL();
; }
; #endif
; /*$PAGE*/
; /*
; *********************************************************************************************************
; * PROCESS SYSTEM TICK
; *
; * Description: This function is used to signal to uC/OS-II the occurrence of a 'system tick' (also known
; * as a 'clock tick'). This function should be called by the ticker ISR but, can also be
; * called by a high priority task.
; *
; * Arguments : none
; *
; * Returns : none
; *********************************************************************************************************
; */
;
; void OSTimeTick (void)
; {
.dbline 521
; OS_TCB *ptcb;
; #if OS_TICK_STEP_EN > 0
; BOOLEAN step;
; #endif
; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
; OS_CPU_SR cpu_sr = 0;
clr R22
.dbline 534
; #endif
;
;
;
; #if OS_TIME_TICK_HOOK_EN > 0
; OSTimeTickHook(); /* Call user definable hook */
; #endif
; #if OS_TIME_GET_SET_EN > 0
; OS_ENTER_CRITICAL(); /* Update the 32-bit tick counter */
; OSTime++;
; OS_EXIT_CRITICAL();
; #endif
; if (OSRunning == TRUE) {
lds R24,_OSRunning
cpi R24,1
breq X5
xjmp L36
X5:
.dbline 534
.dbline 536
lds R20,_OSTickStepState
clr R21
cpi R20,0
cpc R20,R21
breq L41
X1:
cpi R20,1
ldi R30,0
cpc R21,R30
breq L42
cpi R20,2
ldi R30,0
cpc R21,R30
breq L43
xjmp L38
X2:
.dbline 536
; #if OS_TICK_STEP_EN > 0
; switch (OSTickStepState) { /* Determine whether we need to process a tick */
L41:
.dbline 538
; case OS_TICK_STEP_DIS: /* Yes, stepping is disabled */
; step = TRUE;
ldi R20,1
.dbline 539
; break;
xjmp L39
L42:
.dbline 542
;
; case OS_TICK_STEP_WAIT: /* No, waiting for uC/OS-View to set ... */
; step = FALSE; /* .. OSTickStepState to OS_TICK_STEP_ONCE */
clr R20
.dbline 543
; break;
xjmp L39
L43:
.dbline 546
;
; case OS_TICK_STEP_ONCE: /* Yes, process tick once and wait for next ... */
; step = TRUE; /* ... step command from uC/OS-View */
ldi R20,1
.dbline 547
; OSTickStepState = OS_TICK_STEP_WAIT;
ldi R24,1
sts _OSTickStepState,R24
.dbline 548
; break;
xjmp L39
L38:
.dbline 551
;
; default: /* Invalid case, correct situation */
; step = TRUE;
ldi R20,1
.dbline 552
; OSTickStepState = OS_TICK_STEP_DIS;
clr R2
sts _OSTickStepState,R2
.dbline 553
; break;
L39:
.dbline 555
; }
; if (step == FALSE) { /* Return if waiting for step command */
tst R20
brne L44
.dbline 555
.dbline 556
; return;
xjmp L35
L44:
.dbline 559
; }
; #endif
; ptcb = OSTCBList; /* Point at first TCB in TCB list */
lds R20,_OSTCBList
lds R21,_OSTCBList+1
xjmp L47
L46:
.dbline 560
; while (ptcb->OSTCBPrio != OS_IDLE_PRIO) { /* Go through all TCBs in TCB list */
.dbline 561
; OS_ENTER_CRITICAL();
xcall _OS_CPU_SR_Save
mov R22,R16
.dbline 562
; if (ptcb->OSTCBDly != 0) { /* No, Delayed or waiting for event with TO */
movw R30,R20
ldd R2,z+8
ldd R3,z+9
tst R2
brne X3
tst R3
brne X6
xjmp L49
X6:
X3:
.dbline 562
.dbline 563
; if (--ptcb->OSTCBDly == 0) { /* Decrement nbr of ticks to end of delay */
movw R24,R20
adiw R24,8
movw R30,R24
ldd R24,z+0
ldd R25,z+1
sbiw R24,1
movw R4,R24
std z+1,R5
std z+0,R4
cpi R24,0
cpc R24,R25
breq X7
xjmp L51
X7:
X4:
.dbline 563
.dbline 565
; /* Check for timeout */
; if ((ptcb->OSTCBStat & OS_STAT_PEND_ANY) != OS_STAT_RDY) {
movw R30,R20
ldd R24,z+10
andi R24,55
breq L53
.dbline 565
.dbline 566
; ptcb->OSTCBStat &= ~OS_STAT_PEND_ANY; /* Yes, Clear status flag */
movw R24,R20
adiw R24,10
movw R30,R24
ldd R24,z+0
andi R24,200
std z+0,R24
.dbline 567
; ptcb->OSTCBPendTO = TRUE; /* Indicate PEND timeout */
ldi R24,1
movw R30,R20
std z+11,R24
.dbline 568
xjmp L54
L53:
.dbline 568
; } else {
.dbline 569
; ptcb->OSTCBPendTO = FALSE;
clr R2
movw R30,R20
std z+11,R2
.dbline 570
; }
L54:
.dbline 572
;
; if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) == OS_STAT_RDY) { /* Is task suspended? */
movw R30,R20
ldd R2,z+10
clr R3
sbrc R2,3
rjmp L55
.dbline 572
.dbline 573
; OSRdyGrp |= ptcb->OSTCBBitY; /* No, Make ready */
movw R30,R20
ldd R2,z+16
lds R3,_OSRdyGrp
or R3,R2
sts _OSRdyGrp,R3
.dbline 574
; OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
ldi R24,<_OSRdyTbl
ldi R25,>_OSRdyTbl
movw R30,R20
ldd R2,z+14
clr R3
add R2,R24
adc R3,R25
movw R30,R20
ldd R4,z+15
movw R30,R2
ldd R5,z+0
or R5,R4
std z+0,R5
.dbline 575
; }
L55:
.dbline 576
; }
L51:
.dbline 577
; }
L49:
.dbline 578
movw R30,R20
ldd R20,z+2
ldd R21,z+3
.dbline 579
mov R16,R22
xcall _OS_CPU_SR_Restore
.dbline 580
L47:
.dbline 560
movw R30,R20
ldd R24,z+12
cpi R24,8
breq X8
xjmp L46
X8:
.dbline 581
L36:
.dbline -2
L35:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r step 20 c
.dbsym r cpu_sr 22 c
.dbsym r ptcb 20 pS[os_tcb]
.dbend
.dbfunc e OSVersion _OSVersion fi
.even
_OSVersion::
.dbline -1
.dbline 599
; ptcb = ptcb->OSTCBNext; /* Point at next TCB in TCB list */
; OS_EXIT_CRITICAL();
; }
; }
; }
; /*$PAGE*/
; /*
; *********************************************************************************************************
; * GET VERSION
; *
; * Description: This function is used to return the version number of uC/OS-II. The returned value
; * corresponds to uC/OS-II's version number multiplied by 100. In other words, version 2.00
; * would be returned as 200.
; *
; * Arguments : none
; *
; * Returns : the version number of uC/OS-II multiplied by 100.
; *********************************************************************************************************
; */
;
; INT16U OSVersion (void)
; {
.dbline 600
; return (OS_VERSION);
ldi R16,280
ldi R17,1
.dbline -2
L57:
.dbline 0 ; func end
ret
.dbend
.dbfunc e OS_Dummy _OS_Dummy fV
.even
_OS_Dummy::
.dbline -1
.dbline 618
; }
;
; /*$PAGE*/
; /*
; *********************************************************************************************************
; * DUMMY FUNCTION
; *
; * Description: This function doesn't do anything. It is called by OSTaskDel().
; *
; * Arguments : none
; *
; * Returns : none
; *********************************************************************************************************
; */
;
; #if OS_TASK_DEL_EN > 0
; void OS_Dummy (void)
; {
.dbline -2
L58:
.dbline 0 ; func end
ret
.dbend
.dbfunc e OS_EventTaskRdy _OS_EventTaskRdy fc
; bity -> R12
; bitx -> R22
; prio -> R20
; x -> R20
; ptcb -> R14,R15
; y -> R10
; msk -> y+10
; msg -> R20,R21
; pevent -> R14,R15
.even
_OS_EventTaskRdy::
xcall push_gset5
movw R20,R18
movw R14,R16
.dbline -1
.dbline 646
; }
; #endif
;
; /*$PAGE*/
; /*
; *********************************************************************************************************
; * MAKE TASK READY TO RUN BASED ON EVENT OCCURING
; *
; * Description: This function is called by other uC/OS-II services and is used to ready a task that was
; * waiting for an event to occur.
; *
; * Arguments : pevent is a pointer to the event control block corresponding to the event.
; *
; * msg is a pointer to a message. This pointer is used by message oriented services
; * such as MAILBOXEs and QUEUEs. The pointer is not used when called by other
; * service functions.
; *
; * msk is a mask that is used to clear the status byte of the TCB. For example,
; * OSSemPost() will pass OS_STAT_SEM, OSMboxPost() will pass OS_STAT_MBOX etc.
; *
; * Returns : none
; *
; * Note : This function is INTERNAL to uC/OS-II and your application should not call it.
; *********************************************************************************************************
; */
; #if OS_EVENT_EN
; INT8U OS_EventTaskRdy (OS_EVENT *pevent, void *msg, INT8U msk)
; {
.dbline 662
; OS_TCB *ptcb;
; INT8U x;
; INT8U y;
; INT8U prio;
; #if OS_LOWEST_PRIO <= 63
; INT8U bitx;
; INT8U bity;
; #else
; INT16U bitx;
; INT16U bity;
; INT16U *ptbl;
; #endif
;
;
; #if OS_LOWEST_PRIO <= 63
; y = OSUnMapTbl[pevent->OSEventGrp]; /* Find HPT waiting for message */
ldi R24,<_OSUnMapTbl
ldi R25,>_OSUnMapTbl
movw R30,R14
ldd R30,z+5
clr R31
add R30,R24
adc R31,R25
lpm R10,Z
.dbline 663
; bity = 1 << y;
ldi R16,1
mov R17,R10
xcall lsl8
mov R12,R16
.dbline 664
; x = OSUnMapTbl[pevent->OSEventTbl[y]];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -