📄 os_core.s
字号:
; #else
; OSTaskCreate(OSTaskIdle, (void *)0, &OSTaskIdleStk[0], OS_IDLE_PRIO);
; #endif
;
; }
; /*$PAGE*/
; /*
; *********************************************************************************************************
; * EXIT ISR
; *
; * Description: This function is used to notify uC/OS-II that you have completed serviving an ISR. When
; * the last nested ISR has completed, uC/OS-II will call the scheduler to determine whether
; * a new, high-priority task, is ready to run.
; *
; * Arguments : none
; *
; * Returns : none
; *
; * Notes : 1) You MUST invoke OSIntEnter() and OSIntExit() in pair. In other words, for every call
; * to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
; * end of the ISR.
; * 2) Rescheduling is prevented when the scheduler is locked (see OSSchedLock())
; *********************************************************************************************************
; */
;
; void OSIntExit (void)
; {
.dbline 147
; OS_ENTER_CRITICAL();
st -y,r16
in r16,0x3F
cli
push r16
ld r16,y+
.dbline 147
.dbline 148
; if ((--OSIntNesting | OSLockNesting) == 0) { /* Reschedule only if all ISRs completed & not locked */
lds R24,_OSIntNesting
subi R24,1
mov R2,R24
sts _OSIntNesting,R2
lds R4,_OSLockNesting
or R2,R4
breq X0
rjmp L25
X0:
.dbline 148
.dbline 149
; OSIntExitY = OSUnMapTbl[OSRdyGrp];
ldi R24,<_OSUnMapTbl
ldi R25,>_OSUnMapTbl
lds R30,_OSRdyGrp
clr R31
add R30,R24
adc R31,R25
lpm R30,Z
sts _OSIntExitY,R30
.dbline 150
; OSPrioHighRdy = (INT8U)((OSIntExitY << 3) + OSUnMapTbl[OSRdyTbl[OSIntExitY]]);
ldi R24,<_OSRdyTbl
ldi R25,>_OSRdyTbl
clr R31
add R30,R24
adc R31,R25
ldd R30,z+0
clr R31
ldi R24,<_OSUnMapTbl
ldi R25,>_OSUnMapTbl
add R30,R24
adc R31,R25
lpm R2,Z
clr R3
lds R4,_OSIntExitY
clr R5
lsl R4
rol R5
lsl R4
rol R5
lsl R4
rol R5
add R4,R2
adc R5,R3
sts _OSPrioHighRdy,R4
.dbline 151
; if (OSPrioHighRdy != OSPrioCur) { /* No context switch if current task is highest ready */
lds R2,_OSPrioCur
cp R4,R2
breq L27
.dbline 151
.dbline 152
; OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];
mov R2,R4
ldi R24,2
mul R24,R2
movw R30,R0
ldi R24,<_OSTCBPrioTbl
ldi R25,>_OSTCBPrioTbl
add R30,R24
adc R31,R25
ldd R2,z+0
ldd R3,z+1
sts _OSTCBHighRdy+1,R3
sts _OSTCBHighRdy,R2
.dbline 153
; OSCtxSwCtr++; /* Keep track of the number of context switches */
ldi R24,1
ldi R25,0
ldi R26,0
ldi R27,0
lds R4,_OSCtxSwCtr+2
lds R5,_OSCtxSwCtr+2+1
lds R2,_OSCtxSwCtr
lds R3,_OSCtxSwCtr+1
add R2,R24
adc R3,R25
adc R4,R26
adc R5,R27
sts _OSCtxSwCtr+1,R3
sts _OSCtxSwCtr,R2
sts _OSCtxSwCtr+2+1,R5
sts _OSCtxSwCtr+2,R4
.dbline 154
; OSIntCtxSw(); /* Perform interrupt level context switch */
rcall _OSIntCtxSw
.dbline 155
; }
L27:
.dbline 156
; }
L25:
.dbline 157
; OS_EXIT_CRITICAL();
st -y,r16
pop r16
out 0x3F,r16
ld r16,y+
.dbline 157
.dbline -2
L24:
.dbline 0 ; func end
ret
.dbend
.dbfunc e OSSched _OSSched fV
; y -> R10
.even
_OSSched::
rcall push_gset3x
.dbline -1
.dbline 178
; }
; /*$PAGE*/
; /*
; *********************************************************************************************************
; * SCHEDULER
; *
; * Description: This function is called by other uC/OS-II services to determine whether a new, high
; * priority task has been made ready to run. This function is invoked by TASK level code
; * and is not used to reschedule tasks from ISRs (see OSIntExit() for ISR rescheduling).
; *
; * Arguments : none
; *
; * Returns : none
; *
; * Notes : 1) This function is INTERNAL to uC/OS-II and your application should not call it.
; * 2) Rescheduling is prevented when the scheduler is locked (see OSSchedLock())
; *********************************************************************************************************
; */
;
; void OSSched (void)
; {
.dbline 182
; INT8U y;
;
;
; OS_ENTER_CRITICAL();
st -y,r16
in r16,0x3F
cli
push r16
ld r16,y+
.dbline 182
.dbline 183
; if ((OSLockNesting | OSIntNesting) == 0) { /* Task scheduling must be enabled and not ISR level */
lds R2,_OSIntNesting
lds R3,_OSLockNesting
or R3,R2
breq X1
rjmp L30
X1:
.dbline 183
.dbline 184
; y = OSUnMapTbl[OSRdyGrp]; /* Get pointer to highest priority task ready to run */
ldi R24,<_OSUnMapTbl
ldi R25,>_OSUnMapTbl
lds R30,_OSRdyGrp
clr R31
add R30,R24
adc R31,R25
lpm R10,Z
.dbline 185
; OSPrioHighRdy = (INT8U)((y << 3) + OSUnMapTbl[OSRdyTbl[y]]);
ldi R24,<_OSRdyTbl
ldi R25,>_OSRdyTbl
mov R30,R10
clr R31
add R30,R24
adc R31,R25
ldd R30,z+0
clr R31
ldi R24,<_OSUnMapTbl
ldi R25,>_OSUnMapTbl
add R30,R24
adc R31,R25
lpm R2,Z
clr R3
mov R4,R10
clr R5
lsl R4
rol R5
lsl R4
rol R5
lsl R4
rol R5
add R4,R2
adc R5,R3
sts _OSPrioHighRdy,R4
.dbline 186
; if (OSPrioHighRdy != OSPrioCur) { /* No context switch if current task is highest ready */
lds R2,_OSPrioCur
cp R4,R2
breq L32
.dbline 186
.dbline 187
; OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];
mov R2,R4
ldi R24,2
mul R24,R2
movw R30,R0
ldi R24,<_OSTCBPrioTbl
ldi R25,>_OSTCBPrioTbl
add R30,R24
adc R31,R25
ldd R2,z+0
ldd R3,z+1
sts _OSTCBHighRdy+1,R3
sts _OSTCBHighRdy,R2
.dbline 188
; OSCtxSwCtr++; /* Increment context switch counter */
ldi R24,1
ldi R25,0
ldi R26,0
ldi R27,0
lds R4,_OSCtxSwCtr+2
lds R5,_OSCtxSwCtr+2+1
lds R2,_OSCtxSwCtr
lds R3,_OSCtxSwCtr+1
add R2,R24
adc R3,R25
adc R4,R26
adc R5,R27
sts _OSCtxSwCtr+1,R3
sts _OSCtxSwCtr,R2
sts _OSCtxSwCtr+2+1,R5
sts _OSCtxSwCtr+2,R4
.dbline 189
; OS_TASK_SW(); /* Perform a context switch */
rcall _OSCtxSw
.dbline 190
; }
L32:
.dbline 191
; }
L30:
.dbline 192
; OS_EXIT_CRITICAL();
st -y,r16
pop r16
out 0x3F,r16
ld r16,y+
.dbline 192
.dbline -2
L29:
rcall pop_gset3x
.dbline 0 ; func end
ret
.dbsym r y 10 c
.dbend
.dbfunc e OSStart _OSStart fV
; x -> R12
; y -> R10
.even
_OSStart::
rcall push_gset4x
.dbline -1
.dbline 214
.dbline 219
lds R2,_OSRunning
tst R2
breq X2
rjmp L35
X2:
.dbline 219
.dbline 220
ldi R24,<_OSUnMapTbl
ldi R25,>_OSUnMapTbl
lds R30,_OSRdyGrp
clr R31
add R30,R24
adc R31,R25
lpm R10,Z
.dbline 221
ldi R24,<_OSRdyTbl
ldi R25,>_OSRdyTbl
mov R30,R10
clr R31
add R30,R24
adc R31,R25
ldd R30,z+0
clr R31
ldi R24,<_OSUnMapTbl
ldi R25,>_OSUnMapTbl
add R30,R24
adc R31,R25
lpm R12,Z
.dbline 222
mov R2,R12
clr R3
mov R4,R10
clr R5
lsl R4
rol R5
lsl R4
rol R5
lsl R4
rol R5
add R4,R2
adc R5,R3
sts _OSPrioHighRdy,R4
.dbline 223
mov R2,R4
sts _OSPrioCur,R2
.dbline 224
ldi R24,2
mul R24,R2
movw R30,R0
ldi R24,<_OSTCBPrioTbl
ldi R25,>_OSTCBPrioTbl
add R30,R24
adc R31,R25
ldd R2,z+0
ldd R3,z+1
sts _OSTCBHighRdy+1,R3
sts _OSTCBHighRdy,R2
.dbline 225
sts _OSTCBCur+1,R3
sts _OSTCBCur,R2
.dbline 226
rcall _OSStartHighRdy
.dbline 227
L35:
.dbline -2
L34:
rcall pop_gset4x
.dbline 0 ; func end
ret
.dbsym r x 12 c
.dbsym r y 10 c
.dbend
.dbfunc e OSTaskIdle _OSTaskIdle fV
; pdata -> R16,R17
.even
_OSTaskIdle::
.dbline -1
.dbline 244
; }
; /*$PAGE*/
; /*
; *********************************************************************************************************
; * START MULTITASKING
; *
; * Description: This function is used to start the multitasking process which lets uC/OS-II manages the
; * task that you have created. Before you can call OSStart(), you MUST have called OSInit()
; * and you MUST have created at least one task.
; *
; * Arguments : none
; *
; * Returns : none
; *
; * Note : OSStartHighRdy() MUST:
; * a) Call OSTaskSwHook() then,
; * b) Set OSRunning to TRUE.
; *********************************************************************************************************
; */
;
; void OSStart (void)
; {
; INT8U y;
; INT8U x;
;
;
; if (OSRunning == FALSE) {
; y = OSUnMapTbl[OSRdyGrp]; /* Find highest priority's task priority number */
; x = OSUnMapTbl[OSRdyTbl[y]];
; OSPrioHighRdy = (INT8U)((y << 3) + x);
; OSPrioCur = OSPrioHighRdy;
; OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run */
; OSTCBCur = OSTCBHighRdy;
; OSStartHighRdy(); /* Execute target specific code to start task */
; }
; }
; /*$PAGE*/
; /*
; *********************************************************************************************************
; * IDLE TASK
; *
; * Description: This task is internal to uC/OS-II and executes whenever no other higher priority tasks
; * executes because they are waiting for event(s) to occur.
; *
; * Arguments : none
; *
; * Returns : none
; *********************************************************************************************************
; */
;
; void OSTaskIdle (void *pdata)
; {
.dbline 245
; pdata = pdata; /* Prevent compiler warning for not using 'pdata' */
.dbline 246
L38:
.dbline 246
.dbline 247
st -y,r16
in r16,0x3F
cli
push r16
ld r16,y+
.dbline 247
.dbline 248
ldi R24,1
ldi R25,0
ldi R26,0
ldi R27,0
lds R4,_OSIdleCtr+2
lds R5,_OSIdleCtr+2+1
lds R2,_OSIdleCtr
lds R3,_OSIdleCtr+1
add R2,R24
adc R3,R25
adc R4,R26
adc R5,R27
sts _OSIdleCtr+1,R3
sts _OSIdleCtr,R2
sts _OSIdleCtr+2+1,R5
sts _OSIdleCtr+2,R4
.dbline 249
st -y,r16
pop r16
out 0x3F,r16
ld r16,y+
.dbline 249
.dbline 250
.dbline 246
.dbline 246
rjmp L38
X3:
.dbline -2
L37:
.dbline 0 ; func end
ret
.dbsym r pdata 16 pV
.dbend
.dbfunc e OSTCBInit _OSTCBInit fc
; ptcb -> R10,R11
; opt -> y+10
; pext -> y+8
; stk_size -> y+6
; id -> y+4
; pbos -> y+2
; ptos -> R18,R19
; prio -> R16
.even
_OSTCBInit::
rcall push_gset3x
.dbline -1
.dbline 297
; for (;;) {
; OS_ENTER_CRITICAL();
; OSIdleCtr++;
; OS_EXIT_CRITICAL();
; }
; }
; /*$PAGE*/
; /*
; *********************************************************************************************************
; * INITIALIZE TCB
; *
; * Description: This function is internal to uC/OS-II and is used to initialize a Task Control Block when
; * a task is created (see OSTaskCreate() and OSTaskCreateExt()).
; *
; * Arguments : prio is the priority of the task being created
; *
; * ptos is a pointer to the task's top-of-stack assuming that the CPU registers
; * have been placed on the stack. Note that the top-of-stack corresponds to a
; * 'high' memory location is OS_STK_GROWTH is set to 1 and a 'low' memory
; * location if OS_STK_GROWTH is set to 0. Note that stack growth is CPU
; * specific.
; *
; * pbos is a pointer to the bottom of stack. A NULL pointer is passed if called by
; * 'OSTaskCreate()'.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -