📄 os_core.lst
字号:
429 void OSSched (void)reentrant
430 {
431 1 INT8U y;
432 1
433 1
434 1 OS_ENTER_CRITICAL();
435 1 if ((OSLockNesting | OSIntNesting) == 0)
436 1 { /* Task scheduling must be enabled and not ISR level */
437 2 y = OSUnMapTbl[OSRdyGrp]; /* Get pointer to highest priority task ready to run */
438 2 OSPrioHighRdy = (INT8U)((y << 3) + OSUnMapTbl[OSRdyTbl[y]]);
439 2 if (OSPrioHighRdy != OSPrioCur)
440 2 { /* No context switch if current task is highest ready */
441 3 OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];
442 3 OSCtxSwCtr++; /* Increment context switch counter */
443 3 OSCtxSw(); /* Perform a context switch */
444 3 }
445 2 }
446 1 OS_EXIT_CRITICAL();
447 1 }
448 /*$PAGE*/
449 /*
450 *********************************************************************************************************
451 * PREVENT SCHEDULING
452 *
453 * Description: This function is used to prevent rescheduling to take place. This allows your application
454 * to prevent context switches until you are ready to permit context switching.
455 *
456 * Arguments : none
457 *
458 * Returns : none
459 *
460 * Notes : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair. In other words, for every
461 * call to OSSchedLock() you MUST have a call to OSSchedUnlock().
462 *********************************************************************************************************
463 */
464 #if OSSCHED_LOCK_EN
void OSSchedLock (void)reentrant
{
if (OSRunning == TRUE) { /* Make sure multitasking is running */
OS_ENTER_CRITICAL();
OSLockNesting++; /* Increment lock nesting level */
OS_EXIT_CRITICAL();
}
}
/*$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().
*********************************************************************************************************
C51 COMPILER V7.06 OS_CORE 02/21/2006 13:52:52 PAGE 9
*/
void OSSchedUnlock (void)reentrant
{
if (OSRunning == TRUE) { /* Make sure multitasking is running */
OS_ENTER_CRITICAL();
if (OSLockNesting > 0) { /* Do not decrement if already 0 */
OSLockNesting--; /* Decrement lock nesting level */
if ((OSLockNesting | OSIntNesting) == 0) { /* See if scheduling re-enabled and not an ISR */
OS_EXIT_CRITICAL();
OSSched(); /* See if a higher priority task is ready */
} else {
OS_EXIT_CRITICAL();
}
} else {
OS_EXIT_CRITICAL();
}
}
}
#endif
507 /*$PAGE*/
508 /*
509 *********************************************************************************************************
510 * START MULTITASKING
511 *
512 * Description: This function is used to start the multitasking process which lets uC/OS-II manages the
513 * task that you have created. Before you can call OSStart(), you MUST have called OSInit()
514 * and you MUST have created at least one task.
515 *
516 * Arguments : none
517 *
518 * Returns : none
519 *
520 * Note : OSStartHighRdy() MUST:
521 * a) Call OSTaskSwHook() then,
522 * b) Set OSRunning to TRUE.
523 *********************************************************************************************************
524 */
525
526 void OSStart (void)
527 {
528 1 INT8U y;
529 1 INT8U x;
530 1
531 1
532 1 if (OSRunning == FALSE) {
533 2 y = OSUnMapTbl[OSRdyGrp]; /* Find highest priority's task priority number */
534 2 x = OSUnMapTbl[OSRdyTbl[y]];
535 2 OSPrioHighRdy = (INT8U)((y << 3) + x);
536 2 OSPrioCur = OSPrioHighRdy;
537 2 OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run */
538 2 OSTCBCur = OSTCBHighRdy;
539 2 OSStartHighRdy(); /* Execute target specific code to start task */
540 2 }
541 1 }
542 /*$PAGE*/
543 /*
544 *********************************************************************************************************
545 * STATISTICS INITIALIZATION
546 *
547 * Description: This function is called by your application to establish CPU usage by first determining
548 * how high a 32-bit counter would count to in 1 second if no other tasks were to execute
C51 COMPILER V7.06 OS_CORE 02/21/2006 13:52:52 PAGE 10
549 * during that time. CPU usage is then determined by a low priority task which keeps track
550 * of this 32-bit counter every second but this time, with other tasks running. CPU usage is
551 * determined by:
552 *
553 * OSIdleCtr
554 * CPU Usage (%) = 100 * (1 - ------------)
555 * OSIdleCtrMax
556 *
557 * Arguments : none
558 *
559 * Returns : none
560 *********************************************************************************************************
561 */
562
563 #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
577 /*$PAGE*/
578 /*
579 *********************************************************************************************************
580 * IDLE TASK
581 *
582 * Description: This task is internal to uC/OS-II and executes whenever no other higher priority tasks
583 * executes because they are waiting for event(s) to occur.
584 *
585 * Arguments : none
586 *
587 * Returns : none
588 *********************************************************************************************************
589 */
590 void OSTaskIdle (void *dataptr)reentrant
591 {
592 1 //sendstring("\r\n空闲任务:");sendbyte(EA);
593 1 INT8U i;
594 1 dataptr = dataptr; /* Prevent compiler warning for not using 'dataptr' */
595 1 //sendstring("\r\n空闲任务:");sendbyte(EA);
596 1 OS_ENTER_CRITICAL();
597 1 OSIdleCtr++; //空闲任务计数器(每执行一次空闲任务,计数器加1)
598 1 OS_EXIT_CRITICAL();
599 1 for(i=0;i<1;i++)
600 1 {
601 2 ;
602 2 }
603 1 }
604 /*$PAGE*/
605 /*
606 *********************************************************************************************************
607 * STATISTICS TASK
608 *
609 * Description: This task is internal to uC/OS-II and is used to compute some statistics about the
610 * multitasking environment. Specifically, OSTaskStat() computes the CPU usage.
C51 COMPILER V7.06 OS_CORE 02/21/2006 13:52:52 PAGE 11
611 * CPU usage is determined by:
612 *
613 * OSIdleCtr
614 * OSCPUUsage = 100 * (1 - ------------) (units are in %)
615 * OSIdleCtrMax
616 *
617 * Arguments : dataptr this pointer is not used at this time.
618 *
619 * Returns : none
620 *
621 * Notes : 1) This task runs at a priority level higher than the idle task. In fact, it runs at the
622 * next higher priority, OS_IDLE_PRIO-1.
623 * 2) You can disable this task by setting the configuration #define OS_TASK_STAT_EN to 0.
624 * 3) We delay for 5 seconds in the beginning to allow the system to reach steady state and
625 * have all other tasks created before we do statistics. You MUST have at least a delay
626 * of 2 seconds to allow for the system to establish the maximum value for the idle
627 * counter.
628 *********************************************************************************************************
629 */
630
631 #if OS_TASK_STAT_EN
void OSTaskStat (void *dataptr)reentrant
{
INT32U run;
INT8S usage;
dataptr = dataptr; /* Prevent compiler warning for not using 'dataptr'
- */
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();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -