📄 os_core.lst
字号:
383 *
384 * Returns : none
385 *
386 * Notes : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair. In other words, for every
387 * call to OSSchedLock() you MUST have a call to OSSchedUnlock().
388 *********************************************************************************************************
389 */
390 #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().
*********************************************************************************************************
*/
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();
}
C51 COMPILER V7.20 OS_CORE 12/29/2004 11:50:53 PAGE 8
} else {
OS_EXIT_CRITICAL();
}
}
}
#endif
433 /*$PAGE*/
434 /*
435 *********************************************************************************************************
436 * START MULTITASKING
437 *
438 * Description: This function is used to start the multitasking process which lets uC/OS-II manages the
439 * task that you have created. Before you can call OSStart(), you MUST have called OSInit()
440 * and you MUST have created at least one task.
441 *
442 * Arguments : none
443 *
444 * Returns : none
445 *
446 * Note : OSStartHighRdy() MUST:
447 * a) Call OSTaskSwHook() then,
448 * b) Set OSRunning to TRUE.
449 *********************************************************************************************************
450 */
451
452 void OSStart (void)
453 {
454 1 INT8U y;
455 1 INT8U x;
456 1
457 1
458 1 if (OSRunning == FALSE) {
459 2 y = OSUnMapTbl[OSRdyGrp]; /* Find highest priority's task priority number */
460 2 x = OSUnMapTbl[OSRdyTbl[y]];
461 2 OSPrioHighRdy = (INT8U)((y << 3) + x);
462 2 OSPrioCur = OSPrioHighRdy;
463 2 OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run */
464 2 OSTCBCur = OSTCBHighRdy;
465 2 OSStartHighRdy(); /* Execute target specific code to start task */
466 2 }
467 1 }
468 /*$PAGE*/
469 /*
470 *********************************************************************************************************
471 * STATISTICS INITIALIZATION
472 *
473 * Description: This function is called by your application to establish CPU usage by first determining
474 * how high a 32-bit counter would count to in 1 second if no other tasks were to execute
475 * during that time. CPU usage is then determined by a low priority task which keeps track
476 * of this 32-bit counter every second but this time, with other tasks running. CPU usage is
477 * determined by:
478 *
479 * OSIdleCtr
480 * CPU Usage (%) = 100 * (1 - ------------)
481 * OSIdleCtrMax
482 *
483 * Arguments : none
484 *
485 * Returns : none
486 *********************************************************************************************************
487 */
488
C51 COMPILER V7.20 OS_CORE 12/29/2004 11:50:53 PAGE 9
489 #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
503 /*$PAGE*/
504 /*
505 *********************************************************************************************************
506 * IDLE TASK
507 *
508 * Description: This task is internal to uC/OS-II and executes whenever no other higher priority tasks
509 * executes because they are waiting for event(s) to occur.
510 *
511 * Arguments : none
512 *
513 * Returns : none
514 *********************************************************************************************************
515 */
516 void OSTaskIdle (void *dataptr)reentrant
517 {
518 1 //sendstring("\r\n空闲任务:");sendbyte(EA);
519 1 INT8U i;
520 1 dataptr = dataptr; /* Prevent compiler warning for not using 'dataptr' */
521 1 //sendstring("\r\n空闲任务:");sendbyte(EA);
522 1 OS_ENTER_CRITICAL();
523 1 OSIdleCtr++;
524 1 OS_EXIT_CRITICAL();
525 1 for(i=0;i<1;i++)
526 1 {
527 2 ;
528 2 }
529 1 }
530 /*$PAGE*/
531 /*
532 *********************************************************************************************************
533 * STATISTICS TASK
534 *
535 * Description: This task is internal to uC/OS-II and is used to compute some statistics about the
536 * multitasking environment. Specifically, OSTaskStat() computes the CPU usage.
537 * CPU usage is determined by:
538 *
539 * OSIdleCtr
540 * OSCPUUsage = 100 * (1 - ------------) (units are in %)
541 * OSIdleCtrMax
542 *
543 * Arguments : dataptr this pointer is not used at this time.
544 *
545 * Returns : none
546 *
547 * Notes : 1) This task runs at a priority level higher than the idle task. In fact, it runs at the
548 * next higher priority, OS_IDLE_PRIO-1.
549 * 2) You can disable this task by setting the configuration #define OS_TASK_STAT_EN to 0.
550 * 3) We delay for 5 seconds in the beginning to allow the system to reach steady state and
C51 COMPILER V7.20 OS_CORE 12/29/2004 11:50:53 PAGE 10
551 * have all other tasks created before we do statistics. You MUST have at least a delay
552 * of 2 seconds to allow for the system to establish the maximum value for the idle
553 * counter.
554 *********************************************************************************************************
555 */
556
557 #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();
if (OSIdleCtrMax > 0L) {
usage = (INT8S)(100L - 100L * run / OSIdleCtrMax);
if (usage > 100) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -