⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os_task.lst

📁 实施操作系统的设计和开发
💻 LST
📖 第 1 页 / 共 4 页
字号:
C51 COMPILER V7.02b   OS_TASK                                                              11/29/2006 14:48:15 PAGE 1   


C51 COMPILER V7.02b, COMPILATION OF MODULE OS_TASK
OBJECT MODULE PLACED IN .\obj\OS_TASK.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE uCosii\OS_TASK.C LARGE BROWSE DEBUG OBJECTEXTEND PRINT(.\lst\OS_TASK.lst) O
                    -BJECT(.\obj\OS_TASK.obj)

stmt level    source

   1          /*
   2          *********************************************************************************************************
   3          *                                                uC/OS-II
   4          *                                          The Real-Time Kernel
   5          *                                            TASK MANAGEMENT
   6          *
   7          *                          (c) Copyright 1992-2001, Jean J. Labrosse, Weston, FL
   8          *                                           All Rights Reserved
   9          *
  10          * File : OS_TASK.C
  11          * By   : Jean J. Labrosse
  12          *********************************************************************************************************
  13          */
  14          
  15          #ifndef  OS_MASTER_FILE
  16          #include "source\includes.h"
  17          #endif
  18          
  19          /*
  20          *********************************************************************************************************
  21          *                                        CHANGE PRIORITY OF A TASK
  22          *
  23          * Description: This function allows you to change the priority of a task dynamically.  Note that the new
  24          *              priority MUST be available.
  25          *
  26          * Arguments  : oldp     is the old priority
  27          *
  28          *              newp     is the new priority
  29          *
  30          * Returns    : OS_NO_ERR        is the call was successful
  31          *              OS_PRIO_INVALID  if the priority you specify is higher that the maximum allowed
  32          *                               (i.e. >= OS_LOWEST_PRIO)
  33          *              OS_PRIO_EXIST    if the new priority already exist.
  34          *              OS_PRIO_ERR      there is no task with the specified OLD priority (i.e. the OLD task does
  35          *                               not exist.
  36          *********************************************************************************************************
  37          */
  38          
  39          #if OS_TASK_CHANGE_PRIO_EN > 0
              INT8U  OSTaskChangePrio (INT8U oldprio, INT8U newprio) reentrant
              {
              #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR    cpu_sr;
              #endif
              
              #if OS_EVENT_EN > 0
                  OS_EVENT    *pevent;
              #endif
              
                  OS_TCB      *ptcb;
                  INT8U        x;
                  INT8U        y;
                  INT8U        bitx;
                  INT8U        bity;
C51 COMPILER V7.02b   OS_TASK                                                              11/29/2006 14:48:15 PAGE 2   

              
              
              
              #if OS_ARG_CHK_EN > 0
                  if ((oldprio >= OS_LOWEST_PRIO && oldprio != OS_PRIO_SELF)  ||
                       newprio >= OS_LOWEST_PRIO) {
                      return (OS_PRIO_INVALID);
                  }
              #endif
                  OS_ENTER_CRITICAL();
                  if (OSTCBPrioTbl[newprio] != (OS_TCB *)0) {                 /* New priority must not already exist */
                      OS_EXIT_CRITICAL();
                      return (OS_PRIO_EXIST);
                  } else {
                      OSTCBPrioTbl[newprio] = (OS_TCB *)1;                    /* Reserve the entry to prevent others */
                      OS_EXIT_CRITICAL();
                      y    = newprio >> 3;                                    /* Precompute to reduce INT. latency   */
                      bity = OSMapTbl[y];
                      x    = newprio & 0x07;
                      bitx = OSMapTbl[x];
                      OS_ENTER_CRITICAL();
                      if (oldprio == OS_PRIO_SELF) {                          /* See if changing self                */
                          oldprio = OSTCBCur->OSTCBPrio;                      /* Yes, get priority                   */
                      }
                      if ((ptcb = OSTCBPrioTbl[oldprio]) != (OS_TCB *)0) {    /* Task to change must exist           */
                          OSTCBPrioTbl[oldprio] = (OS_TCB *)0;                /* Remove TCB from old priority        */
                          if ((OSRdyTbl[ptcb->OSTCBY] & ptcb->OSTCBBitX) != 0x00) {  /* If task is ready make it not */
                              if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0x00) {
                                  OSRdyGrp &= ~ptcb->OSTCBBitY;
                              }
                              OSRdyGrp    |= bity;                            /* Make new priority ready to run      */
                              OSRdyTbl[y] |= bitx;
              #if OS_EVENT_EN > 0
                          } else {
                              if ((pevent = ptcb->OSTCBEventPtr) != (OS_EVENT *)0) { /* Remove from event wait list  */
                                  if ((pevent->OSEventTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0) {
                                      pevent->OSEventGrp &= ~ptcb->OSTCBBitY;
                                  }
                                  pevent->OSEventGrp    |= bity;              /* Add new priority to wait list       */
                                  pevent->OSEventTbl[y] |= bitx;
                              }
              #endif
                          }
                          OSTCBPrioTbl[newprio] = ptcb;                       /* Place pointer to TCB @ new priority */
                          ptcb->OSTCBPrio       = newprio;                    /* Set new task priority               */
                          ptcb->OSTCBY          = y;
                          ptcb->OSTCBX          = x;
                          ptcb->OSTCBBitY       = bity;
                          ptcb->OSTCBBitX       = bitx;
                          OS_EXIT_CRITICAL();
                          OS_Sched();                                         /* Run highest priority task ready     */
                          return (OS_NO_ERR);
                      } else {
                          OSTCBPrioTbl[newprio] = (OS_TCB *)0;                /* Release the reserved prio.          */
                          OS_EXIT_CRITICAL();
                          return (OS_PRIO_ERR);                               /* Task to change didn't exist         */
                      }
                  }
              }
              #endif
 115          /*$PAGE*/
 116          /*
C51 COMPILER V7.02b   OS_TASK                                                              11/29/2006 14:48:15 PAGE 3   

 117          *********************************************************************************************************
 118          *                                            CREATE A TASK
 119          *
 120          * Description: This function is used to have uC/OS-II manage the execution of a task.  Tasks can either
 121          *              be created prior to the start of multitasking or by a running task.  A task cannot be
 122          *              created by an ISR.
 123          *
 124          * Arguments  : task     is a pointer to the task's code
 125          *
 126          *              ppdata   is a pointer to an optional data area which can be used to pass parameters to
 127          *                       the task when the task first executes.  Where the task is concerned it thinks
 128          *                       it was invoked and passed the argument 'ppdata' as follows:
 129          *
 130          *                           void Task (void *ppdata)
 131          *                           {
 132          *                               for (;;) {
 133          *                                   Task code;
 134          *                               }
 135          *                           }
 136          *
 137          *              ptos     is a pointer to the task's top of stack.  If the configuration constant
 138          *                       OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
 139          *                       memory to low memory).  'pstk' will thus point to the highest (valid) memory
 140          *                       location of the stack.  If OS_STK_GROWTH is set to 0, 'pstk' will point to the
 141          *                       lowest memory location of the stack and the stack will grow with increasing
 142          *                       memory locations.
 143          *
 144          *              prio     is the task's priority.  A unique priority MUST be assigned to each task and the
 145          *                       lower the number, the higher the priority.
 146          *
 147          * Returns    : OS_NO_ERR        if the function was successful.
 148          *              OS_PRIO_EXIT     if the task priority already exist
 149          *                               (each task MUST have a unique priority).
 150          *              OS_PRIO_INVALID  if the priority you specify is higher that the maximum allowed
 151          *                               (i.e. >= OS_LOWEST_PRIO)
 152          *********************************************************************************************************
 153          */
 154          
 155          #if OS_TASK_CREATE_EN > 0
 156          INT8U  OSTaskCreate (void (*task)(void *pd) reentrant, void *ppdata, OS_STK *ptos, INT8U prio) reentrant
 157          {
 158   1      #if OS_CRITICAL_METHOD == 3                  /* Allocate storage for CPU status register               */
                  OS_CPU_SR  cpu_sr;
              #endif
 161   1          OS_STK    *psp;
 162   1          INT8U      err;
 163   1      
 164   1      
 165   1      #if OS_ARG_CHK_EN > 0
 166   1          if (prio > OS_LOWEST_PRIO) {             /* Make sure priority is within allowable range           */
 167   2              return (OS_PRIO_INVALID);
 168   2          }
 169   1      #endif
 170   1          OS_ENTER_CRITICAL();
 171   1          if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority  */
 172   2              OSTCBPrioTbl[prio] = (OS_TCB *)1;    /* Reserve the priority to prevent others from doing ...  */
*** WARNING C196 IN LINE 172 OF UCOSII\OS_TASK.C: mspace probably invalid
 173   2                                                   /* ... the same thing until task is created.              */
 174   2              OS_EXIT_CRITICAL();
 175   2              psp = (OS_STK *)OSTaskStkInit(task, ppdata, ptos, 0);    /* Initialize the task's stack         */
 176   2              err = OS_TCBInit(prio, psp, (OS_STK *)0, 0, 0, (void *)0, 0);
 177   2              if (err == OS_NO_ERR) {
C51 COMPILER V7.02b   OS_TASK                                                              11/29/2006 14:48:15 PAGE 4   

 178   3                  OS_ENTER_CRITICAL();
 179   3                  OSTaskCtr++;                                        /* Increment the #tasks counter        */
 180   3                  OS_EXIT_CRITICAL();
 181   3                  if (OSRunning == TRUE) {         /* Find highest priority task if multitasking has started */
 182   4                      OS_Sched();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -