PageRenderTime 638ms CodeModel.GetById 221ms app.highlight 191ms RepoModel.GetById 211ms app.codeStats 1ms

/src/compiler/ucos-vs2008/UCOS_SIM/src/ucosii/os_core.c

http://ftk.googlecode.com/
C | 1522 lines | 819 code | 131 blank | 572 comment | 145 complexity | dc9b969887c73e9e3445928058ba2774 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/*
   2*********************************************************************************************************
   3*                                                uC/OS-II
   4*                                          The Real-Time Kernel
   5*                                             CORE FUNCTIONS
   6*
   7*                          (c) Copyright 1992-2005, Jean J. Labrosse, Weston, FL
   8*                                           All Rights Reserved
   9*
  10* File    : OS_CORE.C
  11* By      : Jean J. Labrosse
  12* Version : V2.80
  13*********************************************************************************************************
  14*/
  15
  16#ifndef  OS_MASTER_FILE

  17#define  OS_GLOBALS

  18#include <ucos_ii.h>

  19#endif

  20
  21/*
  22*********************************************************************************************************
  23*                                       PRIORITY RESOLUTION TABLE
  24*
  25* Note: Index into table is bit pattern to resolve highest priority
  26*       Indexed value corresponds to highest priority bit position (i.e. 0..7)
  27*********************************************************************************************************
  28*/
  29
  30INT8U  const  OSUnMapTbl[256] = {
  31    0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x00 to 0x0F                             */
  32    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x10 to 0x1F                             */
  33    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x20 to 0x2F                             */
  34    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x30 to 0x3F                             */
  35    6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x40 to 0x4F                             */
  36    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x50 to 0x5F                             */
  37    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x60 to 0x6F                             */
  38    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x70 to 0x7F                             */
  39    7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x80 to 0x8F                             */
  40    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x90 to 0x9F                             */
  41    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0xA0 to 0xAF                             */
  42    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0xB0 to 0xBF                             */
  43    6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0xC0 to 0xCF                             */
  44    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0xD0 to 0xDF                             */
  45    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0xE0 to 0xEF                             */
  46    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0        /* 0xF0 to 0xFF                             */
  47};
  48
  49/*$PAGE*/
  50/*
  51*********************************************************************************************************
  52*                                       FUNCTION PROTOTYPES
  53*********************************************************************************************************
  54*/
  55static  void  OS_InitEventList(void);
  56static  void  OS_InitMisc(void);
  57static  void  OS_InitRdyList(void);
  58static  void  OS_InitTaskIdle(void);
  59#if OS_TASK_STAT_EN > 0

  60static  void  OS_InitTaskStat(void);
  61#endif

  62static  void  OS_InitTCBList(void);
  63
  64static  void  OS_SchedNew(void);
  65
  66/*$PAGE*/
  67/*
  68*********************************************************************************************************
  69*                         GET THE NAME OF A SEMAPHORE, MUTEX, MAILBOX or QUEUE
  70*
  71* Description: This function is used to obtain the name assigned to a semaphore, mutex, mailbox or queue.
  72*
  73* Arguments  : pevent    is a pointer to the event group.  'pevent' can point either to a semaphore,
  74*                        a mutex, a mailbox or a queue.  Where this function is concerned, the actual
  75*                        type is irrelevant.
  76*
  77*              pname     is a pointer to an ASCII string that will receive the name of the semaphore,
  78*                        mutex, mailbox or queue.  The string must be able to hold at least
  79*                        OS_EVENT_NAME_SIZE characters.
  80*
  81*              err       is a pointer to an error code that can contain one of the following values:
  82*
  83*                        OS_NO_ERR                  if the name was copied to 'pname'
  84*                        OS_ERR_EVENT_TYPE          if 'pevent' is not pointing to the proper event
  85*                                                   control block type.
  86*                        OS_ERR_PNAME_NULL          You passed a NULL pointer for 'pname'
  87*                        OS_ERR_PEVENT_NULL         if you passed a NULL pointer for 'pevent'
  88*
  89* Returns    : The length of the string or 0 if the 'pevent' is a NULL pointer.
  90*********************************************************************************************************
  91*/
  92
  93#if OS_EVENT_EN && (OS_EVENT_NAME_SIZE > 1)

  94INT8U  OSEventNameGet (OS_EVENT *pevent, INT8U *pname, INT8U *err)
  95{
  96    INT8U      len;
  97#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */

  98    OS_CPU_SR  cpu_sr = 0;
  99#endif

 100
 101
 102
 103#if OS_ARG_CHK_EN > 0

 104    if (err == (INT8U *)0) {                     /* Validate 'err'                                     */
 105        return (0);
 106    }
 107    if (pevent == (OS_EVENT *)0) {               /* Is 'pevent' a NULL pointer?                        */
 108        *err = OS_ERR_PEVENT_NULL;
 109        return (0);
 110    }
 111    if (pname == (INT8U *)0) {                   /* Is 'pname' a NULL pointer?                         */
 112        *err = OS_ERR_PNAME_NULL;
 113        return (0);
 114    }
 115#endif

 116    switch (pevent->OSEventType) {
 117        case OS_EVENT_TYPE_SEM:
 118        case OS_EVENT_TYPE_MUTEX:
 119        case OS_EVENT_TYPE_MBOX:
 120        case OS_EVENT_TYPE_Q:
 121             break;
 122
 123        default:
 124             *err = OS_ERR_EVENT_TYPE;
 125             return (0);
 126    }
 127    OS_ENTER_CRITICAL();
 128    len  = OS_StrCopy(pname, pevent->OSEventName);    /* Copy name from OS_EVENT                       */
 129    OS_EXIT_CRITICAL();
 130    *err = OS_NO_ERR;
 131    return (len);
 132}
 133#endif

 134
 135/*$PAGE*/
 136/*
 137*********************************************************************************************************
 138*                         ASSIGN A NAME TO A SEMAPHORE, MUTEX, MAILBOX or QUEUE
 139*
 140* Description: This function assigns a name to a semaphore, mutex, mailbox or queue.
 141*
 142* Arguments  : pevent    is a pointer to the event group.  'pevent' can point either to a semaphore,
 143*                        a mutex, a mailbox or a queue.  Where this function is concerned, it doesn't
 144*                        matter the actual type.
 145*
 146*              pname     is a pointer to an ASCII string that will be used as the name of the semaphore,
 147*                        mutex, mailbox or queue.  The string must be able to hold at least
 148*                        OS_EVENT_NAME_SIZE characters.
 149*
 150*              err       is a pointer to an error code that can contain one of the following values:
 151*
 152*                        OS_NO_ERR                  if the requested task is resumed
 153*                        OS_ERR_EVENT_TYPE          if 'pevent' is not pointing to the proper event
 154*                                                   control block type.
 155*                        OS_ERR_PNAME_NULL          You passed a NULL pointer for 'pname'
 156*                        OS_ERR_PEVENT_NULL         if you passed a NULL pointer for 'pevent'
 157*
 158* Returns    : None
 159*********************************************************************************************************
 160*/
 161
 162#if OS_EVENT_EN && (OS_EVENT_NAME_SIZE > 1)

 163void  OSEventNameSet (OS_EVENT *pevent, INT8U *pname, INT8U *err)
 164{
 165    INT8U      len;
 166#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */

 167    OS_CPU_SR  cpu_sr = 0;
 168#endif

 169
 170
 171
 172#if OS_ARG_CHK_EN > 0

 173    if (err == (INT8U *)0) {                     /* Validate 'err'                                     */
 174        return;
 175    }
 176    if (pevent == (OS_EVENT *)0) {               /* Is 'pevent' a NULL pointer?                        */
 177        *err = OS_ERR_PEVENT_NULL;
 178        return;
 179    }
 180    if (pname == (INT8U *)0) {                    /* Is 'pname' a NULL pointer?                         */
 181        *err = OS_ERR_PNAME_NULL;
 182        return;
 183    }
 184#endif

 185    switch (pevent->OSEventType) {
 186        case OS_EVENT_TYPE_SEM:
 187        case OS_EVENT_TYPE_MUTEX:
 188        case OS_EVENT_TYPE_MBOX:
 189        case OS_EVENT_TYPE_Q:
 190             break;
 191
 192        default:
 193             *err = OS_ERR_EVENT_TYPE;
 194             return;
 195    }
 196    OS_ENTER_CRITICAL();
 197    len = OS_StrLen(pname);                           /* Can we fit the string in the storage area?    */
 198    if (len > (OS_EVENT_NAME_SIZE - 1)) {             /* No                                            */
 199        OS_EXIT_CRITICAL();
 200        *err = OS_ERR_EVENT_NAME_TOO_LONG;
 201        return;
 202    }
 203    (void)OS_StrCopy(pevent->OSEventName, pname);     /* Yes, copy name to the event control block     */
 204    OS_EXIT_CRITICAL();
 205    *err = OS_NO_ERR;
 206}
 207#endif

 208
 209/*$PAGE*/
 210/*
 211*********************************************************************************************************
 212*                                             INITIALIZATION
 213*
 214* Description: This function is used to initialize the internals of uC/OS-II and MUST be called prior to
 215*              creating any uC/OS-II object and, prior to calling OSStart().
 216*
 217* Arguments  : none
 218*
 219* Returns    : none
 220*********************************************************************************************************
 221*/
 222
 223void  OSInit (void)
 224{
 225#if OS_VERSION >= 204

 226    OSInitHookBegin();                                           /* Call port specific initialization code   */
 227#endif

 228
 229    OS_InitMisc();                                               /* Initialize miscellaneous variables       */
 230
 231    OS_InitRdyList();                                            /* Initialize the Ready List                */
 232
 233    OS_InitTCBList();                                            /* Initialize the free list of OS_TCBs      */
 234
 235    OS_InitEventList();                                          /* Initialize the free list of OS_EVENTs    */
 236
 237#if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)

 238    OS_FlagInit();                                               /* Initialize the event flag structures     */
 239#endif

 240
 241#if (OS_MEM_EN > 0) && (OS_MAX_MEM_PART > 0)

 242    OS_MemInit();                                                /* Initialize the memory manager            */
 243#endif

 244
 245#if (OS_Q_EN > 0) && (OS_MAX_QS > 0)

 246    OS_QInit();                                                  /* Initialize the message queue structures  */
 247#endif

 248
 249    OS_InitTaskIdle();                                           /* Create the Idle Task                     */
 250#if OS_TASK_STAT_EN > 0

 251    OS_InitTaskStat();                                           /* Create the Statistic Task                */
 252#endif

 253
 254#if OS_VERSION >= 204

 255    OSInitHookEnd();                                             /* Call port specific init. code            */
 256#endif

 257
 258#if OS_VERSION >= 270 && OS_DEBUG_EN > 0

 259    OSDebugInit();
 260#endif

 261}
 262/*$PAGE*/
 263/*
 264*********************************************************************************************************
 265*                                              ENTER ISR
 266*
 267* Description: This function is used to notify uC/OS-II that you are about to service an interrupt
 268*              service routine (ISR).  This allows uC/OS-II to keep track of interrupt nesting and thus
 269*              only perform rescheduling at the last nested ISR.
 270*
 271* Arguments  : none
 272*
 273* Returns    : none
 274*
 275* Notes      : 1) This function should be called ith interrupts already disabled
 276*              2) Your ISR can directly increment OSIntNesting without calling this function because
 277*                 OSIntNesting has been declared 'global'.
 278*              3) You MUST still call OSIntExit() even though you increment OSIntNesting directly.
 279*              4) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
 280*                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
 281*                 end of the ISR.
 282*              5) You are allowed to nest interrupts up to 255 levels deep.
 283*              6) I removed the OS_ENTER_CRITICAL() and OS_EXIT_CRITICAL() around the increment because
 284*                 OSIntEnter() is always called with interrupts disabled.
 285*********************************************************************************************************
 286*/
 287
 288void  OSIntEnter (void)
 289{
 290    if (OSRunning == TRUE) {
 291        if (OSIntNesting < 255u) {
 292            OSIntNesting++;                      /* Increment ISR nesting level                        */
 293        }
 294    }
 295}
 296/*$PAGE*/
 297/*
 298*********************************************************************************************************
 299*                                               EXIT ISR
 300*
 301* Description: This function is used to notify uC/OS-II that you have completed serviving an ISR.  When
 302*              the last nested ISR has completed, uC/OS-II will call the scheduler to determine whether
 303*              a new, high-priority task, is ready to run.
 304*
 305* Arguments  : none
 306*
 307* Returns    : none
 308*
 309* Notes      : 1) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
 310*                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
 311*                 end of the ISR.
 312*              2) Rescheduling is prevented when the scheduler is locked (see OS_SchedLock())
 313*********************************************************************************************************
 314*/
 315
 316void  OSIntExit (void)
 317{
 318#if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */

 319    OS_CPU_SR  cpu_sr = 0;
 320#endif

 321
 322
 323
 324    if (OSRunning == TRUE) {
 325        OS_ENTER_CRITICAL();
 326        if (OSIntNesting > 0) {                            /* Prevent OSIntNesting from wrapping       */
 327            OSIntNesting--;
 328        }
 329        if (OSIntNesting == 0) {                           /* Reschedule only if all ISRs complete ... */
 330            if (OSLockNesting == 0) {                      /* ... and not locked.                      */
 331                OS_SchedNew();
 332                if (OSPrioHighRdy != OSPrioCur) {          /* No Ctx Sw if current task is highest rdy */
 333                    OSTCBHighRdy  = OSTCBPrioTbl[OSPrioHighRdy];
 334#if OS_TASK_PROFILE_EN > 0

 335                    OSTCBHighRdy->OSTCBCtxSwCtr++;         /* Inc. # of context switches to this task  */
 336#endif

 337                    OSCtxSwCtr++;                          /* Keep track of the number of ctx switches */
 338                    OSIntCtxSw();                          /* Perform interrupt level ctx switch       */
 339                }
 340            }
 341        }
 342        OS_EXIT_CRITICAL();
 343    }
 344}
 345/*$PAGE*/
 346/*
 347*********************************************************************************************************
 348*                                          PREVENT SCHEDULING
 349*
 350* Description: This function is used to prevent rescheduling to take place.  This allows your application
 351*              to prevent context switches until you are ready to permit context switching.
 352*
 353* Arguments  : none
 354*
 355* Returns    : none
 356*
 357* Notes      : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair.  In other words, for every
 358*                 call to OSSchedLock() you MUST have a call to OSSchedUnlock().
 359*********************************************************************************************************
 360*/
 361
 362#if OS_SCHED_LOCK_EN > 0

 363void  OSSchedLock (void)
 364{
 365#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */

 366    OS_CPU_SR  cpu_sr = 0;
 367#endif

 368
 369
 370
 371    if (OSRunning == TRUE) {                     /* Make sure multitasking is running                  */
 372        OS_ENTER_CRITICAL();
 373        if (OSLockNesting < 255u) {              /* Prevent OSLockNesting from wrapping back to 0      */
 374            OSLockNesting++;                     /* Increment lock nesting level                       */
 375        }
 376        OS_EXIT_CRITICAL();
 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

 398void  OSSchedUnlock (void)
 399{
 400#if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */

 401    OS_CPU_SR  cpu_sr = 0;
 402#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 {
 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
 448void  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

 480void  OSStatInit (void)
 481{
 482#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */

 483    OS_CPU_SR  cpu_sr = 0;
 484#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
 514void  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     */

 521    OS_CPU_SR  cpu_sr = 0;
 522#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;
 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*/
 584/*
 585*********************************************************************************************************
 586*                                             GET VERSION
 587*
 588* Description: This function is used to return the version number of uC/OS-II.  The returned value
 589*              corresponds to uC/OS-II's version number multiplied by 100.  In other words, version 2.00
 590*              would be returned as 200.
 591*
 592* Arguments  : none
 593*
 594* Returns    : the version number of uC/OS-II multiplied by 100.
 595*********************************************************************************************************
 596*/
 597
 598INT16U  OSVersion (void)
 599{
 600    return (OS_VERSION);
 601}
 602
 603/*$PAGE*/
 604/*
 605*********************************************************************************************************
 606*                                            DUMMY FUNCTION
 607*
 608* Description: This function doesn't do anything.  It is called by OSTaskDel().
 609*
 610* Arguments  : none
 611*
 612* Returns    : none
 613*********************************************************************************************************
 614*/
 615
 616#if OS_TASK_DEL_EN > 0

 617void  OS_Dummy (void)
 618{
 619}
 620#endif

 621
 622/*$PAGE*/
 623/*
 624*********************************************************************************************************
 625*                             MAKE TASK READY TO RUN BASED ON EVENT OCCURING
 626*
 627* Description: This function is called by other uC/OS-II services and is used to ready a task that was
 628*              waiting for an event to occur.
 629*
 630* Arguments  : pevent    is a pointer to the event control block corresponding to the event.
 631*
 632*              msg       is a pointer to a message.  This pointer is used by message oriented services
 633*                        such as MAILBOXEs and QUEUEs.  The pointer is not used when called by other
 634*                        service functions.
 635*
 636*              msk       is a mask that is used to clear the status byte of the TCB.  For example,
 637*                        OSSemPost() will pass OS_STAT_SEM, OSMboxPost() will pass OS_STAT_MBOX etc.
 638*
 639* Returns    : none
 640*
 641* Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
 642*********************************************************************************************************
 643*/
 644#if OS_EVENT_EN

 645INT8U  OS_EventTaskRdy (OS_EVENT *pevent, void *msg, INT8U msk)
 646{
 647    OS_TCB  *ptcb;
 648    INT8U    x;
 649    INT8U    y;
 650    INT8U    prio;
 651#if OS_LOWEST_PRIO <= 63

 652    INT8U    bitx;
 653    INT8U    bity;
 654#else

 655    INT16U   bitx;
 656    INT16U   bity;
 657    INT16U  *ptbl;
 658#endif

 659
 660
 661#if OS_LOWEST_PRIO <= 63

 662    y     = OSUnMapTbl[pevent->OSEventGrp];             /* Find HPT waiting for message                */
 663    bity  = 1 << y;
 664    x     = OSUnMapTbl[pevent->OSEventTbl[y]];
 665    bitx  = 1 << x;
 666    prio  = (INT8U)((y << 3) + x);                      /* Find priority of task getting the msg       */
 667#else

 668    if ((pevent->OSEventGrp & 0xFF) != 0) {             /* Find HPT waiting for message                */
 669        y = OSUnMapTbl[pevent->OSEventGrp & 0xFF];
 670    } else {
 671        y = OSUnMapTbl[(pevent->OSEventGrp >> 8) & 0xFF] + 8;
 672    }
 673    bity = 1 << y;
 674    ptbl = &pevent->OSEventTbl[y];
 675    if ((*ptbl & 0xFF) != 0) {
 676        x = OSUnMapTbl[*ptbl & 0xFF];
 677    } else {
 678        x = OSUnMapTbl[(*ptbl >> 8) & 0xFF] + 8;
 679    }
 680    bitx = 1 << x;
 681    prio = (INT8U)((y << 4) + x);                       /* Find priority of task getting the msg       */
 682#endif

 683
 684    pevent->OSEventTbl[y] &= ~bitx;                     /* Remove this task from the waiting list      */
 685    if (pevent->OSEventTbl[y] == 0) {
 686        pevent->OSEventGrp &= ~bity;                    /* Clr group bit if this was only task pending */
 687    }
 688    ptcb                 =  OSTCBPrioTbl[prio];         /* Point to this task's OS_TCB                 */
 689    ptcb->OSTCBDly       =  0;                          /* Prevent OSTimeTick() from readying task     */
 690    ptcb->OSTCBEventPtr  = (OS_EVENT *)0;               /* Unlink ECB from this task                   */
 691#if ((OS_Q_EN > 0) && (OS_MAX_QS > 0)) || (OS_MBOX_EN > 0)

 692    ptcb->OSTCBMsg       = msg;                         /* Send message directly to waiting task       */
 693#else

 694    msg                  = msg;                         /* Prevent compiler warning if not used        */
 695#endif

 696    ptcb->OSTCBPendTO    = FALSE;                       /* Cancel 'any' timeout because of post        */
 697    ptcb->OSTCBStat     &= ~msk;                        /* Clear bit associated with event type        */
 698    if (ptcb->OSTCBStat == OS_STAT_RDY) {               /* See if task is ready (could be susp'd)      */
 699        OSRdyGrp        |=  bity;                       /* Put task in the ready to run list           */
 700        OSRdyTbl[y]     |=  bitx;
 701    }
 702    return (prio);
 703}
 704#endif

 705/*$PAGE*/
 706/*
 707*********************************************************************************************************
 708*                                   MAKE TASK WAIT FOR EVENT TO OCCUR
 709*
 710* Description: This function is called by other uC/OS-II services to suspend a task because an event has
 711*              not occurred.
 712*
 713* Arguments  : pevent   is a pointer to the event control block for which the task will be waiting for.
 714*
 715* Returns    : none
 716*
 717* Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
 718*********************************************************************************************************
 719*/
 720#if OS_EVENT_EN

 721void  OS_EventTaskWait (OS_EVENT *pevent)
 722{
 723    INT8U  y;
 724
 725
 726    OSTCBCur->OSTCBEventPtr = pevent;             /* Store pointer to event control block in TCB       */
 727    y                       = OSTCBCur->OSTCBY;   /* Task no longer ready                              */
 728    OSRdyTbl[y]            &= ~OSTCBCur->OSTCBBitX;
 729    if (OSRdyTbl[y] == 0) {
 730        OSRdyGrp &= ~OSTCBCur->OSTCBBitY;         /* Clear event grp bit if this was only task pending */
 731    }
 732    pevent->OSEventTbl[OSTCBCur->OSTCBY] |= OSTCBCur->OSTCBBitX;          /* Put task in waiting list  */
 733    pevent->OSEventGrp                   |= OSTCBCur->OSTCBBitY;
 734}
 735#endif

 736/*$PAGE*/
 737/*
 738*********************************************************************************************************
 739*                              MAKE TASK READY TO RUN BASED ON EVENT TIMEOUT
 740*
 741* Description: This function is called by other uC/OS-II services to make a task ready to run because a
 742*              timeout occurred.
 743*
 744* Arguments  : pevent   is a pointer to the event control block which is readying a task.
 745*
 746* Returns    : none
 747*
 748* Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
 749*********************************************************************************************************
 750*/
 751#if OS_EVENT_EN

 752void  OS_EventTO (OS_EVENT *pevent)
 753{
 754    INT8U  y;
 755
 756
 757    y                      = OSTCBCur->OSTCBY;
 758    pevent->OSEventTbl[y] &= ~OSTCBCur->OSTCBBitX;     /* Remove task from wait list                   */
 759    if (pevent->OSEventTbl[y] == 0x00) {
 760        pevent->OSEventGrp &= ~OSTCBCur->OSTCBBitY;
 761    }
 762    OSTCBCur->OSTCBPendTO   = FALSE;                   /* Clear the Pend Timeout flag                  */
 763    OSTCBCur->OSTCBStat     = OS_STAT_RDY;             /* Set status to ready                          */
 764    OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;           /* No longer waiting for event                  */
 765}
 766#endif

 767/*$PAGE*/
 768/*
 769*********************************************************************************************************
 770*                                 INITIALIZE EVENT CONTROL BLOCK'S WAIT LIST
 771*
 772* Description: This function is called by other uC/OS-II services to initialize the event wait list.
 773*
 774* Arguments  : pevent    is a pointer to the event control block allocated to the event.
 775*
 776* Returns    : none
 777*
 778* Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
 779*********************************************************************************************************
 780*/
 781#if OS_EVENT_EN

 782void  OS_EventWaitListInit (OS_EVENT *pevent)
 783{
 784#if OS_LOWEST_PRIO <= 63

 785    INT8U  *ptbl;
 786#else

 787    INT16U *ptbl;
 788#endif

 789    INT8U   i;
 790
 791
 792    pevent->OSEventGrp = 0;                      /* No task waiting on event                           */
 793    ptbl               = &pevent->OSEventTbl[0];
 794
 795    for (i = 0; i < OS_EVENT_TBL_SIZE; i++) {
 796        *ptbl++ = 0;
 797    }
 798}
 799#endif

 800/*$PAGE*/
 801/*
 802*********************************************************************************************************
 803*                                             INITIALIZATION
 804*                           INITIALIZE THE FREE LIST OF EVENT CONTROL BLOCKS
 805*
 806* Description: This function is called by OSInit() to initialize the free list of event control blocks.
 807*
 808* Arguments  : none
 809*
 810* Returns    : none
 811*********************************************************************************************************
 812*/
 813
 814static  void  OS_InitEventList (void)
 815{
 816#if OS_EVENT_EN && (OS_MAX_EVENTS > 0)

 817#if (OS_MAX_EVENTS > 1)

 818    INT16U     i;
 819    OS_EVENT  *pevent1;
 820    OS_EVENT  *pevent2;
 821
 822
 823    OS_MemClr((INT8U *)&OSEventTbl[0], sizeof(OSEventTbl)); /* Clear the event table                   */
 824    pevent1 = &OSEventTbl[0];
 825    pevent2 = &OSEventTbl[1];
 826    for (i = 0; i < (OS_MAX_EVENTS - 1); i++) {             /* Init. list of free EVENT control blocks */
 827        pevent1->OSEventType    = OS_EVENT_TYPE_UNUSED;
 828        pevent1->OSEventPtr     = pevent2;
 829#if OS_EVENT_NAME_SIZE > 1

 830        pevent1->OSEventName[0] = '?';                      /* Unknown name                            */
 831        pevent1->OSEventName[1] = OS_ASCII_NUL;
 832#endif

 833        pevent1++;
 834        pevent2++;
 835    }
 836    pevent1->OSEventType            = OS_EVENT_TYPE_UNUSED;
 837    pevent1->OSEventPtr             = (OS_EVENT *)0;
 838#if OS_EVENT_NAME_SIZE > 1

 839    pevent1->OSEventName[0]         = '?';
 840    pevent1->OSEventName[1]         = OS_ASCII_NUL;
 841#endif

 842    OSEventFreeList                 = &OSEventTbl[0];
 843#else

 844    OSEventFreeList                 = &OSEventTbl[0];       /* Only have ONE event control block       */
 845    OSEventFreeList->OSEventType    = OS_EVENT_TYPE_UNUSED;
 846    OSEventFreeList->OSEventPtr     = (OS_EVENT *)0;
 847#if OS_EVENT_NAME_SIZE > 1

 848    OSEventFreeList->OSEventName[0] = '?';                  /* Unknown name                            */
 849    OSEventFreeList->OSEventName[1] = OS_ASCII_NUL;
 850#endif

 851#endif

 852#endif

 853}
 854/*$PAGE*/
 855/*
 856*********************************************************************************************************
 857*                                             INITIALIZATION
 858*                                    INITIALIZE MISCELLANEOUS VARIABLES
 859*
 860* Description: This function is called by OSInit() to initialize miscellaneous variables.
 861*
 862* Arguments  : none
 863*
 864* Returns    : none
 865*********************************************************************************************************
 866*/
 867
 868static  void  OS_InitMisc (void)
 869{
 870#if OS_TIME_GET_SET_EN > 0

 871    OSTime        = 0L;                                    /* Clear the 32-bit system clock            */
 872#endif

 873
 874    OSIntNesting  = 0;                                     /* Clear the interrupt nesting counter      */
 875    OSLockNesting = 0;                                     /* Clear the scheduling lock counter        */
 876
 877    OSTaskCtr     = 0;                                     /* Clear the number of tasks                */
 878
 879    OSRunning     = FALSE;                                 /* Indicate that multitasking not started   */
 880
 881    OSCtxSwCtr    = 0;                                     /* Clear the context switch counter         */
 882    OSIdleCtr     = 0L;                                    /* Clear the 32-bit idle counter            */
 883
 884#if OS_TASK_STAT_EN > 0

 885    OSIdleCtrRun  = 0L;
 886    OSIdleCtrMax  = 0L;
 887    OSStatRdy     = FALSE;                                 /* Statistic task is not ready              */
 888#endif

 889}
 890/*$PAGE*/
 891/*
 892*********************************************************************************************************
 893*                                             INITIALIZATION
 894*                                       INITIALIZE THE READY LIST
 895*
 896* Description: This function is called by OSInit() to initialize the Ready List.
 897*
 898* Arguments  : none
 899*
 900* Returns    : none
 901*********************************************************************************************************
 902*/
 903
 904static  void  OS_InitRdyList (void)
 905{
 906    INT8U    i;
 907#if OS_LOWEST_PRIO <= 63

 908    INT8U   *prdytbl;
 909#else

 910    INT16U  *prdytbl;
 911#endif

 912
 913
 914    OSRdyGrp      = 0;                                     /* Clear the ready list                     */
 915    prdytbl       = &OSRdyTbl[0];
 916    for (i = 0; i < OS_RDY_TBL_SIZE; i++) {
 917        *prdytbl++ = 0;
 918    }
 919
 920    OSPrioCur     = 0;
 921    OSPrioHighRdy = 0;
 922
 923    OSTCBHighRdy  = (OS_TCB *)0;
 924    OSTCBCur      = (OS_TCB *)0;
 925}
 926
 927/*$PAGE*/
 928/*
 929*********************************************************************************************************
 930*                                             INITIALIZATION
 931*                                         CREATING THE IDLE TASK
 932*
 933* Description: This function creates the Idle Task.
 934*
 935* Arguments  : none
 936*
 937* Returns    : none
 938*********************************************************************************************************
 939*/
 940
 941static  void  OS_InitTaskIdle (void)
 942{
 943#if OS_TASK_NAME_SIZE > 14

 944    INT8U  err;
 945#endif

 946
 947
 948#if OS_TASK_CREATE_EXT_EN > 0

 949    #if OS_STK_GROWTH == 1

 950    (void)OSTaskCreateExt(OS_TaskIdle,
 951                          (void *)0,                                 /* No arguments passed to OS_TaskIdle() */
 952                          &OSTaskIdleStk[OS_TASK_IDLE_STK_SIZE - 1], /* Set Top-Of-Stack                     */
 953                          OS_IDLE_PRIO,                              /* Lowest priority level                */
 954                          OS_TASK_IDLE_ID,
 955                          &OSTaskIdleStk[0],                         /* Set Bottom-Of-Stack                  */
 956                          OS_TASK_IDLE_STK_SIZE,
 957                          (void *)0,                                 /* No TCB extension                     */
 958                          OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);/* Enable stack checking + clear stack  */
 959    #else
 960    (void)OSTaskCreateExt(OS_TaskIdle,
 961                          (void *)0,                                 /* No arguments passed to OS_TaskIdle() */
 962                          &OSTaskIdleStk[0],                         /* Set Top-Of-Stack                     */
 963                          OS_IDLE_PRIO,                              /* Lowest priority level                */
 964                          OS_TASK_IDLE_ID,
 965                          &OSTaskIdleStk[OS_TASK_IDLE_STK_SIZE - 1], /* Set Bottom-Of-Stack                  */
 966                          OS_TASK_IDLE_STK_SIZE,
 967                          (void *)0,                                 /* No TCB extension                     */
 968                          OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);/* Enable stack checking + clear stack  */
 969    #endif
 970#else

 971    #if OS_STK_GROWTH == 1

 972    (void)OSTaskCreate(OS_TaskIdle,
 973                       (void *)0,
 974                       &OSTaskIdleStk[OS_TASK_IDLE_STK_SIZE - 1],
 975                       OS_IDLE_PRIO);
 976    #else
 977    (void)OSTaskCreate(OS_TaskIdle,
 978                       (void *)0,
 979                       &OSTaskIdleStk[0],
 980                       OS_IDLE_PRIO);
 981    #endif
 982#endif

 983
 984#if OS_TASK_NAME_SIZE > 14

 985    OSTaskNameSet(OS_IDLE_PRIO, (INT8U *)"uC/OS-II Idle", &err);
 986#endif

 987}
 988/*$PAGE*/
 989/*
 990*********************************************************************************************************
 991*                                             INITIALIZATION
 992*                                      CREATING THE STATISTIC TASK
 993*
 994* Description: This function creates the Statistic Task.
 995*
 996* Arguments  : none
 997*
 998* Returns    : none
 999*********************************************************************************************************
1000*/
1001
1002#if OS_TASK_STAT_EN > 0

1003static  void  OS_InitTaskStat (void)
1004{
1005#if OS_TASK_NAME_SIZE > 14

1006    INT8U  err;
1007#endif

1008
1009
1010#if OS_TASK_CREATE_EXT_EN > 0

1011    #if OS_STK_GROWTH == 1

1012    (void)OSTaskCreateExt(OS_TaskStat,
1013                          (void *)0,                                   /* No args passed to OS_TaskStat()*/
1014                          &OSTaskStatStk[OS_TASK_STAT_STK_SIZE - 1],   /* Set Top-Of-Stack               */
1015                          OS_STAT_PRIO,                                /* One higher than the idle task  */
1016                          OS_TASK_STAT_ID,
1017                          &OSTaskStatStk[0],                           /* Set Bottom-Of-Stack            */
1018                          OS_TASK_STAT_STK_SIZE,
1019                          (void *)0,                                   /* No TCB extension               */
1020                          OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);  /* Enable stack checking + clear  */
1021    #else
1022    (void)OSTaskCreateExt(OS_TaskStat,
1023                          (void *)0,                                   /* No args passed to OS_TaskStat()*/
1024                          &OSTaskStatStk[0],                           /* Set Top-Of-Stack               */
1025                          OS_STAT_PRIO,                                /* One higher than the idle task  */
1026                          OS_TASK_STAT_ID,
1027                          &OSTaskStatStk[OS_TASK_STAT_STK_SIZE - 1],   /* Set Bottom-Of-Stack            */
1028                          OS_TASK_STAT_STK_SIZE,
1029                          (void *)0,                                   /* No TCB extension               */
1030                          OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);  /* Enable stack checking + clear  */
1031    #endif
1032#else

1033    #if OS_STK_GROWTH == 1

1034    (void)OSTaskCreate(OS_TaskStat,
1035                       (void *)0,                                      /* No args passed to OS_TaskStat()*/
1036                       &OSTaskStatStk[OS_TASK_STAT_STK_SIZE - 1],      /* Set Top-Of-Stack               */
1037                       OS_STAT_PRIO);                                  /* One higher than the idle task  */
1038    #else
1039    (void)OSTaskCreate(OS_TaskStat,
1040                       (void *)0,                                      /* No args passed to OS_TaskStat()*/
1041                       &OSTaskStatStk[0],                              /* Set Top-Of-Stack               */
1042                       OS_STAT_PRIO);                                  /* One higher than the idle task  */
1043    #endif
1044#endif

1045
1046#if OS_TASK_NAME_SIZE > 14

1047    OSTaskNameSet(OS_STAT_PRIO, (INT8U *)"uC/OS-II Stat", &err);
1048#endif

1049}
1050#endif

1051/*$PAGE*/
1052/*
1053*********************************************************************************************************
1054*                                             INITIALIZATION
1055*                            INITIALIZE THE FREE LIST OF TASK CONTROL BLOCKS
1056*
1057* Description: This function is called by OSInit() to initialize the free list of OS_TCBs.
1058*
1059* Arguments  : none
1060*
1061* Returns    : none
1062*********************************************************************************************************
1063*/
1064
1065static  void  OS_InitTCBList (void)
1066{
1067    INT8U    i;
1068    OS_TCB  *ptcb1;
1069    OS_TCB  *ptcb2;
1070
1071
1072    OS_MemClr((INT8U *)&OSTCBTbl[0],     sizeof(OSTCBTbl));      /* Clear all the TCBs                 */
1073    OS_MemClr((INT8U *)&OSTCBPrioTbl[0], sizeof(OSTCBPrioTbl));  /* Clear the priority table           */
1074    ptcb1 = &OSTCBTbl[0];
1075    ptcb2 = &OSTCBTbl[1];
1076    for (i = 0; i < (OS_MAX_TASKS + OS_N_SYS_TASKS - 1); i++) {  /* Init. list of free TCBs            */
1077        ptcb1->OSTCBNext = ptcb2;
1078#if OS_TASK_NAME_SIZE > 1

1079        ptcb1->OSTCBTaskName[0] = '?';                           /* Unknown name                       */
1080        ptcb1->OSTCBTaskName[1] = OS_ASCII_NUL;
1081#endif

1082        ptcb1++;
1083        ptcb2++;
1084    }
1085    ptcb1->OSTCBNext = (OS_TCB *)0;                              /* Last OS_TCB                        */
1086#if OS_TASK_NAME_SIZE > 1

1087    ptcb1->OSTCBTaskName[0] = '?';                               /* Unknown name                       */
1088    ptcb1->OSTCBTaskName[1] = OS_ASCII_NUL;
1089#endif

1090    OSTCBList               = (OS_TCB *)0;                       /* TCB lists initializations          */
1091    OSTCBFreeList           = &OSTCBTbl[0];
1092}
1093/*$PAGE*/
1094/*
1095*********************************************************************************************************
1096*                                        CLEAR A SECTION OF MEMORY
1097*
1098* Description: This function is called by other uC/OS-II services to clear a contiguous block of RAM.
1099*
1100* Arguments  : pdest    is the start of the RAM to clear (i.e. write 0x00 to)
1101*
1102*              size     is the number of bytes to clear.
1103*
1104* Returns    : none
1105*
1106* Notes      : 1) This function is INTERNAL to uC/OS-II and your application should not call it.
1107*              2) Note that we can only clear up to 64K bytes of RAM.  This is not an issue because none
1108*                 of the uses of this function gets close to this limit.
1109*              3) The clear is done one byte at a time since this will work on any processor irrespective
1110*                 of the alignment of the destination.
1111*********************************************************************************************************
1112*/
1113
1114void  OS_MemClr (INT8U *pdest, INT16U size)
1115{
1116    while (size > 0) {
1117        *pdest++ = (INT8U)0;
1118        size--;
1119    }
1120}
1121/*$PAGE*/
1122/*
1123*********************************************************************************************************
1124*                                        COPY A BLOCK OF MEMORY
1125*
1126* Description: This function is called by other uC/OS-II services to copy a block of memory from one
1127*              location to another.
1128*
1129* Arguments  : pdest    is a pointer to the 'destination' memory block
1130*
1131*              psrc     is a pointer to the 'source'      memory block
1132*
1133*              size     is the number of bytes to copy.
1134*
1135* Returns    : none
1136*
1137* Notes      : 1) This function is INTERNAL to uC/OS-II and your application should not call it.  There is
1138*                 no provision to handle overlapping memory copy.  However, that's not a problem since this
1139*                 is not a situation that will happen.
1140*              2) Note that we can only copy up to 64K bytes of RAM
1141*              3) The copy is done one byte at a time since this will work on any processor irrespective
1142*                 of the alignment of the source and destination.
1143*********************************************************************************************************
1144*/
1145
1146void  OS_MemCopy (INT8U *pdest, INT8U *psrc, INT16U size)
1147{
1148    while (size > 0) {
1149        *pdest++ = *psrc++;
1150        size--;
1151    }
1152}
1153/*$PAGE*/
1154/*
1155*********************************************************************************************************
1156*                                              SCHEDULER
1157*
1158* Description: This function is called by other uC/OS-II services to determine whether a new, high
1159*              priority task has been made ready to run.  This function is invoked by TASK level code
1160*              and is not used to reschedule tasks from ISRs (see OSIntExit() for ISR rescheduling).
1161*
1162* Arguments  : none
1163*
1164* Returns    : none
1165*
1166* Notes      : 1) This function is INTERNAL to uC/OS-II and your application should not call it.
1167*              2) Rescheduling is prevented when the scheduler is locked (see OS_SchedLock())
1168*********************************************************************************************************
1169*/
1170
1171void  OS_Sched (void)
1172{
1173#if OS_CRITICAL_METHOD == 3                            …

Large files files are truncated, but you can click here to view the full file