📄 os_core.lst
字号:
422 1 OS_EXIT_CRITICAL();
423 1 }
424 /*$PAGE*/
425 /*
426 *********************************************************************************************************
427 * SCHEDULER
428 *
429 * Description: This function is called by other uC/OS-II services to determine whether a new, high
430 * priority task has been made ready to run. This function is invoked by TASK level code
431 * and is not used to reschedule tasks from ISRs (see OSIntExit() for ISR rescheduling).
432 *
433 * Arguments : none
434 *
435 * Returns : none
436 *
437 * Notes : 1) This function is INTERNAL to uC/OS-II and your application should not call it.
438 * 2) Rescheduling is prevented when the scheduler is locked (see OSSchedLock())
439 *********************************************************************************************************
440 */
441
442 void OSSched (void) REENTRANT
443 {
444 1 INT8U y;
445 1
446 1
447 1 OS_ENTER_CRITICAL();
448 1 if ((OSLockNesting | OSIntNesting) == 0) { /* Task scheduling must be enabled and not ISR level */
449 2 y = OSUnMapTbl[OSRdyGrp]; /* Get pointer to highest priority task ready to run */
450 2 OSPrioHighRdy = (INT8U)((y << 3) + OSUnMapTbl[OSRdyTbl[y]]);
451 2 if (OSPrioHighRdy != OSPrioCur) { /* No context switch if current task is highest ready */
452 3 OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];
453 3 OSCtxSwCtr++; /* Increment context switch counter */
454 3 OS_TASK_SW(); /* Perform a context switch */
455 3 }
456 2 }
457 1 OS_EXIT_CRITICAL();
458 1 }
459 /*$PAGE*/
460 /*
461 *********************************************************************************************************
462 * PREVENT SCHEDULING
463 *
464 * Description: This function is used to prevent rescheduling to take place. This allows your application
465 * to prevent context switches until you are ready to permit context switching.
466 *
467 * Arguments : none
C51 COMPILER V7.06 OS_CORE 03/04/2005 14:28:17 PAGE 9
468 *
469 * Returns : none
470 *
471 * Notes : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair. In other words, for every
472 * call to OSSchedLock() you MUST have a call to OSSchedUnlock().
473 *********************************************************************************************************
474 */
475
476 void OSSchedLock (void) REENTRANT
477 {
478 1 if (OSRunning == TRUE) { /* Make sure multitasking is running */
479 2 OS_ENTER_CRITICAL();
480 2 OSLockNesting++; /* Increment lock nesting level */
481 2 OS_EXIT_CRITICAL();
482 2 }
483 1 }
484 /*$PAGE*/
485 /*
486 *********************************************************************************************************
487 * ENABLE SCHEDULING
488 *
489 * Description: This function is used to re-allow rescheduling.
490 *
491 * Arguments : none
492 *
493 * Returns : none
494 *
495 * Notes : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair. In other words, for every
496 * call to OSSchedLock() you MUST have a call to OSSchedUnlock().
497 *********************************************************************************************************
498 */
499
500 void OSSchedUnlock (void) REENTRANT
501 {
502 1 if (OSRunning == TRUE) { /* Make sure multitasking is running */
503 2 OS_ENTER_CRITICAL();
504 2 if (OSLockNesting > 0) { /* Do not decrement if already 0 */
505 3 OSLockNesting--; /* Decrement lock nesting level */
506 3 if ((OSLockNesting | OSIntNesting) == 0) { /* See if scheduling re-enabled and not an ISR */
507 4 OS_EXIT_CRITICAL();
508 4 OSSched(); /* See if a higher priority task is ready */
509 4 } else {
510 4 OS_EXIT_CRITICAL();
511 4 }
512 3 } else {
513 3 OS_EXIT_CRITICAL();
514 3 }
515 2 }
516 1 }
517 /*$PAGE*/
518 /*
519 *********************************************************************************************************
520 * START MULTITASKING
521 *
522 * Description: This function is used to start the multitasking process which lets uC/OS-II manages the
523 * task that you have created. Before you can call OSStart(), you MUST have called OSInit()
524 * and you MUST have created at least one task.
525 *
526 * Arguments : none
527 *
528 * Returns : none
529 *
C51 COMPILER V7.06 OS_CORE 03/04/2005 14:28:17 PAGE 10
530 * Note : OSStartHighRdy() MUST:
531 * a) Call OSTaskSwHook() then,
532 * b) Set OSRunning to TRUE.
533 *********************************************************************************************************
534 */
535
536 /* refer to book P96 */
537 void OSStart (void) REENTRANT
538 {
539 1 INT8U y;
540 1 INT8U x;
541 1
542 1
543 1 if (OSRunning == FALSE) {
544 2 y = OSUnMapTbl[OSRdyGrp]; /* Find highest priority's task priority number */
545 2 x = OSUnMapTbl[OSRdyTbl[y]];
546 2 OSPrioHighRdy = (INT8U)((y << 3) + x);
547 2 OSPrioCur = OSPrioHighRdy;
548 2 OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run */
549 2 OSTCBCur = OSTCBHighRdy;
550 2 OSStartHighRdy(); /* Execute target specific code to start task */
551 2 }
552 1 }
553 /*$PAGE*/
554 /*
555 *********************************************************************************************************
556 * STATISTICS INITIALIZATION
557 *
558 * Description: This function is called by your application to establish CPU usage by first determining
559 * how high a 32-bit counter would count to in 1 second if no other tasks were to execute
560 * during that time. CPU usage is then determined by a low priority task which keeps track
561 * of this 32-bit counter every second but this time, with other tasks running. CPU usage is
562 * determined by:
563 *
564 * OSIdleCtr
565 * CPU Usage (%) = 100 * (1 - ------------)
566 * OSIdleCtrMax
567 *
568 * Arguments : none
569 *
570 * Returns : none
571 *********************************************************************************************************
572 */
573
574 #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
588 /*$PAGE*/
589 /*
590 *********************************************************************************************************
591 * IDLE TASK
C51 COMPILER V7.06 OS_CORE 03/04/2005 14:28:17 PAGE 11
592 *
593 * Description: This task is internal to uC/OS-II and executes whenever no other higher priority tasks
594 * executes because they are waiting for event(s) to occur.
595 *
596 * Arguments : none
597 *
598 * Returns : none
599 *********************************************************************************************************
600 */
601
602 void OSTaskIdle (void DT_XDATA * ppdata) REENTRANT
603 {
604 1 ppdata = ppdata; /* Prevent compiler warning for not using 'ppdata'
-*/
605 1 for (;;) {
606 2 OS_ENTER_CRITICAL();
607 2 OSIdleCtr++;
608 2 OS_EXIT_CRITICAL();
609 2 }
610 1 }
611 /*$PAGE*/
612 /*
613 *********************************************************************************************************
614 * STATISTICS TASK
615 *
616 * Description: This task is internal to uC/OS-II and is used to compute some statistics about the
617 * multitasking environment. Specifically, OSTaskStat() computes the CPU usage.
618 * CPU usage is determined by:
619 *
620 * OSIdleCtr
621 * OSCPUUsage = 100 * (1 - ------------) (units are in %)
622 * OSIdleCtrMax
623 *
624 * Arguments : ppdata this pointer is not used at this time.
625 *
626 * Returns : none
627 *
628 * Notes : 1) This task runs at a priority level higher than the idle task. In fact, it runs at the
629 * next higher priority, OS_IDLE_PRIO-1.
630 * 2) You can disable this task by setting the configuration #define OS_TASK_STAT_EN to 0.
631 * 3) We delay for 5 seconds in the beginning to allow the system to reach steady state and
632 * have all other tasks created before we do statistics. You MUST have at least a delay
633 * of 2 seconds to allow for the system to establish the maximum value for the idle
634 * counter.
635 *********************************************************************************************************
636 */
637
638 #if OS_TASK_STAT_EN
void OSTaskStat (void DT_XDATA * ppdata) REENTRANT
{
INT32U run;
INT8S usage;
ppdata = ppdata; /* Prevent compiler warning for not using 'ppdata'
-*/
while (OSStatRdy == FALSE) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -