📄 os_core.src
字号:
; * Description: This function is used to prevent rescheduling to take place. This allows your application
; * to prevent context switches until you are ready to permit context switching.
; *
; * Arguments : none
; *
; * Returns : none
; *
; * Notes : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair. In other words, for every
; * call to OSSchedLock() you MUST have a call to OSSchedUnlock().
; *********************************************************************************************************
; */
;
; void OSSchedLock (void) reentrant
RSEG ?PR?_?OSSchedLock?OS_CORE
_?OSSchedLock:
USING 0
; SOURCE LINE # 463
; {
; if (OSRunning == TRUE) { /* Make sure multitasking is running */
; SOURCE LINE # 465
MOV R0,#LOW (OSRunning)
MOV A,@R0
CJNE A,#01H,?C0022
; OS_ENTER_CRITICAL();
; SOURCE LINE # 466
CLR EA
; OSLockNesting++; /* Increment lock nesting level */
; SOURCE LINE # 467
MOV DPTR,#OSLockNesting
MOVX A,@DPTR
INC A
MOVX @DPTR,A
; OS_EXIT_CRITICAL();
; SOURCE LINE # 468
SETB EA
; }
; SOURCE LINE # 469
; }
; SOURCE LINE # 470
?C0022:
RET
; END OF _?OSSchedLock
; /*$PAGE*/
; /*
; *********************************************************************************************************
; * ENABLE SCHEDULING
; *
; * Description: This function is used to re-allow rescheduling.
; *
; * Arguments : none
; *
; * Returns : none
; *
; * Notes : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair. In other words, for every
; * call to OSSchedLock() you MUST have a call to OSSchedUnlock().
; *********************************************************************************************************
; */
;
; void OSSchedUnlock (void) reentrant
RSEG ?PR?_?OSSchedUnlock?OS_CORE
_?OSSchedUnlock:
USING 0
; SOURCE LINE # 487
; {
; if (OSRunning == TRUE) { /* Make sure multitasking is running */
; SOURCE LINE # 489
MOV R0,#LOW (OSRunning)
MOV A,@R0
XRL A,#01H
JNZ ?C0028
; OS_ENTER_CRITICAL();
; SOURCE LINE # 490
CLR EA
; if (OSLockNesting > 0) { /* Do not decrement if already 0 */
; SOURCE LINE # 491
MOV DPTR,#OSLockNesting
MOVX A,@DPTR
SETB C
SUBB A,#00H
JC ?C0024
; OSLockNesting--; /* Decrement lock nesting level */
; SOURCE LINE # 492
MOVX A,@DPTR
DEC A
MOVX @DPTR,A
; if ((OSLockNesting | OSIntNesting) == 0) { /* See if scheduling re-enabled and not an ISR */
; SOURCE LINE # 493
MOV DPTR,#OSIntNesting
MOVX A,@DPTR
MOV R7,A
MOV DPTR,#OSLockNesting
MOVX A,@DPTR
ORL A,R7
JNZ ?C0025
; OS_EXIT_CRITICAL();
; SOURCE LINE # 494
SETB EA
; OSSched(); /* See if a higher priority task is ready */
; SOURCE LINE # 495
LJMP _?OSSched
; } else {
; SOURCE LINE # 496
?C0025:
; OS_EXIT_CRITICAL();
; SOURCE LINE # 497
SETB EA
; }
; SOURCE LINE # 498
; } else {
; SOURCE LINE # 499
RET
?C0024:
; OS_EXIT_CRITICAL();
; SOURCE LINE # 500
SETB EA
; }
; SOURCE LINE # 501
; }
; SOURCE LINE # 502
; }
; SOURCE LINE # 503
?C0028:
RET
; END OF _?OSSchedUnlock
; /*$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) reentrant
RSEG ?PR?_?OSStart?OS_CORE
_?OSStart:
USING 0
; SOURCE LINE # 523
MOV DPTR,#0FFFEH
LCALL ?C?ADDXBP
; {
; INT8U y;
; INT8U x;
;
;
; if (OSRunning == FALSE) {
; SOURCE LINE # 529
MOV R0,#LOW (OSRunning)
MOV A,@R0
JNZ ?C0030
; y = OSUnMapTbl[OSRdyGrp]; /* Find highest priority's task priority number */
; SOURCE LINE # 530
MOV DPTR,#OSRdyGrp
MOVX A,@DPTR
MOV DPTR,#OSUnMapTbl
MOVC A,@A+DPTR
MOV DPH,?C_XBP
MOV DPL,?C_XBP+01H
MOVX @DPTR,A
; x = OSUnMapTbl[OSRdyTbl[y]];
; SOURCE LINE # 531
MOVX A,@DPTR
MOV R7,A
ADD A,#LOW (OSRdyTbl)
MOV DPL,A
CLR A
ADDC A,#HIGH (OSRdyTbl)
MOV DPH,A
MOVX A,@DPTR
MOV DPTR,#OSUnMapTbl
MOVC A,@A+DPTR
MOV DPH,?C_XBP
MOV DPL,?C_XBP+01H
INC DPTR
MOVX @DPTR,A
; OSPrioHighRdy = (INT8U)((y << 3) + x);
; SOURCE LINE # 532
MOV A,R7
RLC A
RLC A
RLC A
ANL A,#0F8H
MOV R7,A
MOV DPH,?C_XBP
MOV DPL,?C_XBP+01H
INC DPTR
MOVX A,@DPTR
ADD A,R7
MOV R0,#LOW (OSPrioHighRdy)
MOV @R0,A
; OSPrioCur = OSPrioHighRdy;
; SOURCE LINE # 533
DEC R0
MOV @R0,A
; OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run */
; SOURCE LINE # 534
MOV B,#03H
MUL AB
ADD A,#LOW (OSTCBPrioTbl)
MOV DPL,A
CLR A
ADDC A,#HIGH (OSTCBPrioTbl)
MOV DPH,A
MOVX A,@DPTR
MOV R3,A
INC DPTR
MOVX A,@DPTR
MOV R2,A
INC DPTR
MOVX A,@DPTR
MOV R0,#LOW (OSTCBHighRdy)
MOV @R0,AR3
INC R0
MOV @R0,AR2
INC R0
MOV @R0,A
; OSTCBCur = OSTCBHighRdy;
; SOURCE LINE # 535
MOV R0,#LOW (OSTCBCur)
MOV @R0,AR3
INC R0
MOV @R0,AR2
INC R0
MOV @R0,A
; OSStartHighRdy(); /* Execute target specific code to start task */
; SOURCE LINE # 536
LCALL OSStartHighRdy
; }
; SOURCE LINE # 537
; }
; SOURCE LINE # 538
?C0030:
MOV DPTR,#02H
LJMP ?C?ADDXBP
; END OF _?OSStart
; /*$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
; void OSStatInit (void) reentrant
; {
; OSTimeDly(2); /* Synchronize with clock tick */
; OS_ENTER_CRITICAL();
; OSIdleCtr = 0L; /* Clear idle counter */
; OS_EXIT_CRITICAL();
; OSTimeDly(OS_TICKS_PER_SEC); /* Determine MAX. idle counter value for 1 second */
; OS_ENTER_CRITICAL();
; OSIdleCtrMax = OSIdleCtr; /* Store maximum idle counter count in 1 second */
; OSStatRdy = TRUE;
; OS_EXIT_CRITICAL();
; }
; #endif
; /*$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 *ppdata) reentrant
RSEG ?PR?_?OSTaskIdle?OS_CORE
_?OSTaskIdle:
USING 0
; SOURCE LINE # 588
MOV DPTR,#0FFFDH
LCALL ?C?ADDXBP
MOV A,R3
MOVX @DPTR,A
INC DPTR
MOV A,R2
MOVX @DPTR,A
INC DPTR
MOV A,R1
MOVX @DPTR,A
; {
; ppdata = ppdata; /* Prevent compiler warning for not using 'pdata' */
; SOURCE LINE # 590
MOV DPH,?C_XBP
MOV DPL,?C_XBP+01H
MOVX A,@DPTR
MOV R1,A
INC DPTR
MOVX A,@DPTR
MOV R2,A
INC DPTR
MOVX A,@DPTR
MOV DPH,?C_XBP
MOV DPL,?C_XBP+01H
XCH A,R1
MOVX @DPTR,A
INC DPTR
MOV A,R2
MOVX @DPTR,A
INC DPTR
MOV A,R1
MOVX @DPTR,A
; for (;;) {
; SOURCE LINE # 591
?C0031:
; OS_ENTER_CRITICAL();
; SOURCE LINE # 592
CLR EA
; OSIdleCtr++;
; SOURCE LINE # 593
MOV DPTR,#OSIdleCtr
MOVX A,@DPTR
MOV R4,A
INC DPTR
MOVX A,@DPTR
MOV R5,A
INC DPTR
MOVX A,@DPTR
MOV R6,A
INC DPTR
MOVX A,@DPTR
ADD A,#01H
MOV R7,A
CLR A
ADDC A,R6
MOV R6,A
CLR A
ADDC A,R5
MOV R5,A
CLR A
ADDC A,R4
MOV R4,A
MOV DPTR,#OSIdleCtr
LCALL ?C?LSTXDATA
; OS_EXIT_CRITICAL();
; SOURCE LINE # 594
SETB EA
; }
; SOURCE LINE # 595
SJMP ?C0031
; END OF _?OSTaskIdle
; }
; /*$PAGE*/
; /*
; *********************************************************************************************************
; * STATISTICS TASK
; *
; * Description: This task is internal to uC/OS-II and is used to compute some statistics about the
; * multitasking environment. Specifically, OSTaskStat() computes the CPU usage.
; * CPU usage is determined by:
; *
; * OSIdleCtr
; * OSCPUUsage = 100 * (1 - ------------) (units are in %)
; * OSIdleCtrMax
; *
; * Arguments : pdata this pointer is not used at this time.
; *
; * Returns : none
; *
; * Notes : 1) This task runs at a priority level higher than the idle task. In fact, it runs at the
; * next higher priority, OS_IDLE_PRIO-1.
; * 2) You can disable this task by setting the configuration #define OS_TASK_STAT_EN to 0.
; * 3) We delay for 5 seconds in the beginning to allow the system to reach steady state and
; * have all other tasks created before we do statistics. You MUST have at least a delay
; * of 2 seconds to allow for the system to establish the maximum value for the idle
; * counter.
; *********************************************************************************************************
; */
;
; #if OS_TASK_STAT_EN
; void OSTaskStat (void *ppdata) reentrant
; {
; INT32U run;
; INT8S usage;
;
;
; ppdata = ppdata; /* Prevent compiler warning for not using 'pdata' */
; while (OSStatRdy == FALSE) {
; OSTimeDly(2 * OS_TICKS_PER_SEC); /* Wait until statistic task is ready */
; }
; for (;;) {
; OS_ENTER_CRITICAL();
; OSIdleCtrRun = OSIdleCtr; /* Obtain the of the idle counter for the past second */
; run = OSIdleCtr;
; OSIdleCtr = 0L; /* Reset the idle counter for the next second */
; OS_EXIT_CRITICAL();
; if (OSIdleCtrMax > 0L) {
; usage = (INT8S)(100L - 100L * run / OSIdleCtrMax);
; if (usage > 100) {
; OSCPUUsage = 100;
; } else if (usage < 0) {
; OSCPUUsage = 0;
; } else {
; OSCPUUsage = usage;
; }
; } else {
; OSCPUUsage = 0;
; }
; OSTaskStatHook(); /* Invoke user definable hook */
; OSTimeDly(OS_TICKS_PER_SEC); /* Accumulate OSIdleCtr for the next second */
; }
; }
; #endif
; /*$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()'.
; *
; * id is the task's ID (0..65535)
; *
; * stk_size is the size of the stack (in 'stack units'). If the stack units are INT8Us
; * then, 'stk_size' contains the number of bytes for the stack. If the stack
; * units are INT32Us then, the stack contains '4 * stk_size' bytes. The stack
; * units are established by the #define constant OS_STK which is CPU
; * specific. 'stk_size' is 0 if called by 'OSTaskCreate()'.
; *
; * pext is a pointer to a user supplied memory area that is used to extend the task
; * control block. This allows you to store the contents of floating-point
; * registers, MMU registers or anything else you could find useful during a
; * context switch. You can even assign a name to each task and store this name
; * in this TCB extension. A NULL pointer is passed if called by OSTaskCreate().
; *
; * opt options as passed to 'OSTaskCreateExt()' or,
; * 0 if called from 'OSTaskCreate()'.
; *
; * Returns : OS_NO_ERR if the call was successful
; * OS_NO_MORE_TCB if there are no more free TCBs to be allocated and thus, the task cannot
; * be created.
; *
; * Note : This function is INTERNAL to uC/OS-II and your application should not call it.
; *********************************************************************************************************
; */
;
; INT8U OSTCBInit (INT8U prio, OS_STK *ptos, OS_STK *pbos, INT16U id, INT16U stk_size, void *pext, INT16U opt) reentrant
RSEG ?PR?_?OSTCBInit?OS_CORE
_?OSTCBInit:
USING 0
; SOURCE LINE # 702
MOV DPTR,#0FFFDH
LCALL ?C?ADDXBP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -