📄 os_core.lst
字号:
377 }
378 }
379 #endif
380
381 /*$PAGE*/
382 /*
383 *********************************************************************************************************
384 * ENABLE SCHEDULING
385 *
386 * Description: This function is used to re-allow rescheduling.
387 *
388 * Arguments : none
389 *
390 * Returns : none
391 *
392 * Notes : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair. In other words, for every
393 * call to OSSchedLock() you MUST have a call to OSSchedUnlock().
394 *********************************************************************************************************
395 */
396
397 #if OS_SCHED_LOCK_EN > 0
398 void OSSchedUnlock (void)
399 {
400 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
403
404
405
406 if (OSRunning == TRUE) { /* Make sure multitasking is running */
407 OS_ENTER_CRITICAL();
408 if (OSLockNesting > 0) { /* Do not decrement if already 0 */
409 OSLockNesting--; /* Decrement lock nesting level */
410 if (OSLockNesting == 0) { /* See if scheduler is enabled and ... */
411 if (OSIntNesting == 0) { /* ... not in an ISR */
412 OS_EXIT_CRITICAL();
413 OS_Sched(); /* See if a HPT is ready */
414 } else {
415 OS_EXIT_CRITICAL();
416 }
417 } else {
418 OS_EXIT_CRITICAL();
419 }
420 } else {
C51 COMPILER V8.08 OS_CORE 08/04/2008 21:49:51 PAGE 9
421 OS_EXIT_CRITICAL();
422 }
423 }
424 }
425 #endif
426
427 /*$PAGE*/
428 /*
429 *********************************************************************************************************
430 * START MULTITASKING
431 *
432 * Description: This function is used to start the multitasking process which lets uC/OS-II manages the
433 * task that you have created. Before you can call OSStart(), you MUST have called OSInit()
434 * and you MUST have created at least one task.
435 *
436 * Arguments : none
437 *
438 * Returns : none
439 *
440 * Note : OSStartHighRdy() MUST:
441 * a) Call OSTaskSwHook() then,
442 * b) Set OSRunning to TRUE.
443 * c) Load the context of the task pointed to by OSTCBHighRdy.
444 * d_ Execute the task.
445 *********************************************************************************************************
446 */
447
448 void OSStart (void)
449 {
450 if (OSRunning == FALSE) {
451 OS_SchedNew(); /* Find highest priority's task priority number */
452 OSPrioCur = OSPrioHighRdy;
453 OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run */
454 OSTCBCur = OSTCBHighRdy;
455 OSStartHighRdy(); /* Execute target specific code to start task */
456 }
457 }
458 /*$PAGE*/
459 /*
460 *********************************************************************************************************
461 * STATISTICS INITIALIZATION
462 *
463 * Description: This function is called by your application to establish CPU usage by first determining
464 * how high a 32-bit counter would count to in 1 second if no other tasks were to execute
465 * during that time. CPU usage is then determined by a low priority task which keeps track
466 * of this 32-bit counter every second but this time, with other tasks running. CPU usage is
467 * determined by:
468 *
469 * OSIdleCtr
470 * CPU Usage (%) = 100 * (1 - ------------)
471 * OSIdleCtrMax
472 *
473 * Arguments : none
474 *
475 * Returns : none
476 *********************************************************************************************************
477 */
478
479 #if OS_TASK_STAT_EN > 0
480 void OSStatInit (void)
481 {
482 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
C51 COMPILER V8.08 OS_CORE 08/04/2008 21:49:51 PAGE 10
OS_CPU_SR cpu_sr = 0;
#endif
485
486
487
488 OSTimeDly(2); /* Synchronize with clock tick */
489 OS_ENTER_CRITICAL();
490 OSIdleCtr = 0L; /* Clear idle counter */
491 OS_EXIT_CRITICAL();
492 OSTimeDly(OS_TICKS_PER_SEC / 10); /* Determine MAX. idle counter value for 1/10 second */
493 OS_ENTER_CRITICAL();
494 OSIdleCtrMax = OSIdleCtr; /* Store maximum idle counter count in 1/10 second */
495 OSStatRdy = TRUE;
496 OS_EXIT_CRITICAL();
497 }
498 #endif
499 /*$PAGE*/
500 /*
501 *********************************************************************************************************
502 * PROCESS SYSTEM TICK
503 *
504 * Description: This function is used to signal to uC/OS-II the occurrence of a 'system tick' (also known
505 * as a 'clock tick'). This function should be called by the ticker ISR but, can also be
506 * called by a high priority task.
507 *
508 * Arguments : none
509 *
510 * Returns : none
511 *********************************************************************************************************
512 */
513
514 void OSTimeTick (void)
515 {
516 OS_TCB *ptcb;
517 #if OS_TICK_STEP_EN > 0
518 BOOLEAN step;
519 #endif
520 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register
- */
OS_CPU_SR cpu_sr = 0;
#endif
523
524
525
526 #if OS_TIME_TICK_HOOK_EN > 0
527 OSTimeTickHook(); /* Call user definable hook
- */
528 #endif
529 #if OS_TIME_GET_SET_EN > 0
530 OS_ENTER_CRITICAL(); /* Update the 32-bit tick counter
- */
531 OSTime++;
532 OS_EXIT_CRITICAL();
533 #endif
534 if (OSRunning == TRUE) {
535 #if OS_TICK_STEP_EN > 0
536 switch (OSTickStepState) { /* Determine whether we need to process a tick
- */
537 case OS_TICK_STEP_DIS: /* Yes, stepping is disabled
- */
538 step = TRUE;
539 break;
C51 COMPILER V8.08 OS_CORE 08/04/2008 21:49:51 PAGE 11
540
541 case OS_TICK_STEP_WAIT: /* No, waiting for uC/OS-View to set ...
- */
542 step = FALSE; /* .. OSTickStepState to OS_TICK_STEP_ONCE
- */
543 break;
544
545 case OS_TICK_STEP_ONCE: /* Yes, process tick once and wait for next ...
- */
546 step = TRUE; /* ... step command from uC/OS-View
- */
547 OSTickStepState = OS_TICK_STEP_WAIT;
548 break;
549
550 default: /* Invalid case, correct situation
- */
551 step = TRUE;
552 OSTickStepState = OS_TICK_STEP_DIS;
553 break;
554 }
555 if (step == FALSE) { /* Return if waiting for step command
- */
556 return;
557 }
558 #endif
559 ptcb = OSTCBList; /* Point at first TCB in TCB list
- */
560 while (ptcb->OSTCBPrio != OS_IDLE_PRIO) { /* Go through all TCBs in TCB list
- */
561 OS_ENTER_CRITICAL();
562 if (ptcb->OSTCBDly != 0) { /* No, Delayed or waiting for event with TO
- */
563 if (--ptcb->OSTCBDly == 0) { /* Decrement nbr of ticks to end of delay
- */
564 /* Check for timeout
- */
565 if ((ptcb->OSTCBStat & OS_STAT_PEND_ANY) != OS_STAT_RDY) {
566 ptcb->OSTCBStat &= ~OS_STAT_PEND_ANY; /* Yes, Clear status flag
- */
567 ptcb->OSTCBPendTO = TRUE; /* Indicate PEND timeout
- */
568 } else {
569 ptcb->OSTCBPendTO = FALSE;
570 }
571
572 if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) == OS_STAT_RDY) { /* Is task suspended?
- */
573 OSRdyGrp |= ptcb->OSTCBBitY; /* No, Make ready
- */
574 OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
575 }
576 }
577 }
578 ptcb = ptcb->OSTCBNext; /* Point at next TCB in TCB list
- */
579 OS_EXIT_CRITICAL();
580 }
581 }
582 }
583 /*$PAGE*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -