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