📄 os_core.lst
字号:
362 *
363 * Notes : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair. In other words, for every
364 * call to OSSchedLock() you MUST have a call to OSSchedUnlock().
365 *********************************************************************************************************
366 */
367
368 #if OS_SCHED_LOCK_EN > 0
void OSSchedUnlock (void) reentrant
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
C51 COMPILER V8.02 OS_CORE 06/22/2006 11:44:34 PAGE 8
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 == 0) && (OSIntNesting == 0)) { /* See if sched. enabled and not an ISR */
OS_EXIT_CRITICAL();
OS_Sched(); /* See if a HPT is ready */
} else {
OS_EXIT_CRITICAL();
}
} else {
OS_EXIT_CRITICAL();
}
}
}
#endif
392
393 /*$PAGE*/
394 /*
395 *********************************************************************************************************
396 * START MULTITASKING
397 *
398 * Description: This function is used to start the multitasking process which lets uC/OS-II manages the
399 * task that you have created. Before you can call OSStart(), you MUST have called OSInit()
400 * and you MUST have created at least one task.
401 *
402 * Arguments : none
403 *
404 * Returns : none
405 *
406 * Note : OSStartHighRdy() MUST:
407 * a) Call OSTaskSwHook() then,
408 * b) Set OSRunning to TRUE.
409 *********************************************************************************************************
410 */
411
412 void OSStart (void) reentrant
413 {
414 1 INT8U y;
415 1 INT8U x;
416 1
417 1
418 1 if (OSRunning == FALSE) {
419 2 y = OSUnMapTbl[OSRdyGrp]; /* Find highest priority's task priority number */
420 2 x = OSUnMapTbl[OSRdyTbl[y]];
421 2 OSPrioHighRdy = (INT8U)((y << 3) + x);
422 2 OSPrioCur = OSPrioHighRdy;
423 2 OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run */
424 2 OSTCBCur = OSTCBHighRdy;
425 2 OSStartHighRdy(); /* Execute target specific code to start task */
426 2 }
427 1 }
428 /*$PAGE*/
429 /*
430 *********************************************************************************************************
431 * STATISTICS INITIALIZATION
432 *
433 * Description: This function is called by your application to establish CPU usage by first determining
434 * how high a 32-bit counter would count to in 1 second if no other tasks were to execute
435 * during that time. CPU usage is then determined by a low priority task which keeps track
436 * of this 32-bit counter every second but this time, with other tasks running. CPU usage is
437 * determined by:
C51 COMPILER V8.02 OS_CORE 06/22/2006 11:44:34 PAGE 9
438 *
439 * OSIdleCtr
440 * CPU Usage (%) = 100 * (1 - ------------)
441 * OSIdleCtrMax
442 *
443 * Arguments : none
444 *
445 * Returns : none
446 *********************************************************************************************************
447 */
448
449 #if OS_TASK_STAT_EN > 0
void OSStatInit (void) reentrant
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
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
468 /*$PAGE*/
469 /*
470 *********************************************************************************************************
471 * PROCESS SYSTEM TICK
472 *
473 * Description: This function is used to signal to uC/OS-II the occurrence of a 'system tick' (also known
474 * as a 'clock tick'). This function should be called by the ticker ISR but, can also be
475 * called by a high priority task.
476 *
477 * Arguments : none
478 *
479 * Returns : none
480 *********************************************************************************************************
481 */
482
483 void OSTimeTick (void) reentrant
484 {
485 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
488 1 OS_TCB *ptcb;
489 1
490 1
491 1 OSTimeTickHook(); /* Call user definable hook */
492 1 #if OS_TIME_GET_SET_EN > 0
493 1 OS_ENTER_CRITICAL(); /* Update the 32-bit tick counter */
494 1 OSTime++;
495 1 OS_EXIT_CRITICAL();
496 1 #endif
497 1 ptcb = OSTCBList; /* Point at first TCB in TCB list */
498 1 while (ptcb->OSTCBPrio != OS_IDLE_PRIO) { /* Go through all TCBs in TCB list */
499 2 OS_ENTER_CRITICAL();
C51 COMPILER V8.02 OS_CORE 06/22/2006 11:44:34 PAGE 10
500 2 if (ptcb->OSTCBDly != 0) { /* Delayed or waiting for event with TO */
501 3 if (--ptcb->OSTCBDly == 0) { /* Decrement nbr of ticks to end of delay */
502 4 if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) == 0x00) { /* Is task suspended? */
503 5 OSRdyGrp |= ptcb->OSTCBBitY; /* No, Make task Rdy to Run (timed out)*/
504 5 OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
505 5 } else { /* Yes, Leave 1 tick to prevent ... */
506 5 ptcb->OSTCBDly = 1; /* ... loosing the task when the ... */
507 5 } /* ... suspension is removed. */
508 4 }
509 3 }
510 2 ptcb = ptcb->OSTCBNext; /* Point at next TCB in TCB list */
511 2 OS_EXIT_CRITICAL();
512 2 }
513 1 }
514 /*$PAGE*/
515 /*
516 *********************************************************************************************************
517 * GET VERSION
518 *
519 * Description: This function is used to return the version number of uC/OS-II. The returned value
520 * corresponds to uC/OS-II's version number multiplied by 100. In other words, version 2.00
521 * would be returned as 200.
522 *
523 * Arguments : none
524 *
525 * Returns : the version number of uC/OS-II multiplied by 100.
526 *********************************************************************************************************
527 */
528
529 INT16U OSVersion (void) reentrant
530 {
531 1 return (OS_VERSION);
532 1 }
533
534 /*$PAGE*/
535 /*
536 *********************************************************************************************************
537 * DUMMY FUNCTION
538 *
539 * Description: This function doesn't do anything. It is called by OSTaskDel().
540 *
541 * Arguments : none
542 *
543 * Returns : none
544 *********************************************************************************************************
545 */
546
547 #if OS_TASK_DEL_EN > 0
void OS_Dummy (void) reentrant
{
}
#endif
552
553 /*$PAGE*/
554 /*
555 *********************************************************************************************************
556 * MAKE TASK READY TO RUN BASED ON EVENT OCCURING
557 *
558 * Description: This function is called by other uC/OS-II services and is used to ready a task that was
559 * waiting for an event to occur.
560 *
561 * Arguments : pevent is a pointer to the event control block corresponding to the event.
C51 COMPILER V8.02 OS_CORE 06/22/2006 11:44:34 PAGE 11
562 *
563 * msg is a pointer to a message. This pointer is used by message oriented services
564 * such as MAILBOXEs and QUEUEs. The pointer is not used when called by other
565 * service functions.
566 *
567 * msk is a mask that is used to clear the status byte of the TCB. For example,
568 * OSSemPost() will pass OS_STAT_SEM, OSMboxPost() will pass OS_STAT_MBOX etc.
569 *
570 * Returns : none
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -