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

📄 os_task.lst

📁 这个是一个精简的在keil c51开发环境下移植uc/os-ii的一个源码。可以供很多初学者借鉴
💻 LST
📖 第 1 页 / 共 4 页
字号:
C51 COMPILER V7.06   OS_TASK                                                               01/08/2008 20:10:17 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE OS_TASK
OBJECT MODULE PLACED IN OS_TASK.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE OS_TASK.C LARGE BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          /*
   2          *********************************************************************************************************
   3          *                                                uC/OS-II
   4          *                                          The Real-Time Kernel
   5          *                                            TASK MANAGEMENT
   6          *
   7          *                        (c) Copyright 1992-1998, Jean J. Labrosse, Plantation, FL
   8          *                                           All Rights Reserved
   9          *
  10          *                                                  V2.00
  11          *
  12          * File : OS_TASK.C
  13          * By   : Jean J. Labrosse
  14          *********************************************************************************************************
  15          */
  16          
  17          #ifndef  OS_MASTER_FILE
  18          #include "includes.h"
  19          #endif
  20          
  21          /*
  22          *********************************************************************************************************
  23          *                                        LOCAL FUNCTION PROTOTYPES
  24          *********************************************************************************************************
  25          */
  26          
  27          
  28          static  void  OSDummy(void) reentrant;
  29          
  30          /*
  31          *********************************************************************************************************
  32          *                                            DUMMY FUNCTION
  33          *
  34          * Description: This function doesn't do anything.  It is called by OSTaskDel() to ensure that interrupts
  35          *              are disabled immediately after they are enabled.
  36          *
  37          * Arguments  : none
  38          *
  39          * Returns    : none
  40          *********************************************************************************************************
  41          */
  42          
  43          static void  OSDummy (void) reentrant
  44          {
  45   1      }
  46          
  47          /*$PAGE*/
  48          /*
  49          *********************************************************************************************************
  50          *                                        CHANGE PRIORITY OF A TASK
  51          *
  52          * Description: This function allows you to change the priority of a task dynamically.  Note that the new
  53          *              priority MUST be available.
  54          *
  55          * Arguments  : oldp     is the old priority
C51 COMPILER V7.06   OS_TASK                                                               01/08/2008 20:10:17 PAGE 2   

  56          *
  57          *              newp     is the new priority
  58          *
  59          * Returns    : OS_NO_ERR        is the call was successful
  60          *              OS_PRIO_INVALID  if the priority you specify is higher that the maximum allowed 
  61          *                               (i.e. >= OS_LOWEST_PRIO)
  62          *              OS_PRIO_EXIST    if the new priority already exist.
  63          *              OS_PRIO_ERR      there is no task with the specified OLD priority (i.e. the OLD task does
  64          *                               not exist.
  65          *********************************************************************************************************
  66          */
  67          
  68          #if OS_TASK_CHANGE_PRIO_EN
              INT8U OSTaskChangePrio (INT8U oldprio, INT8U newprio) reentrant
              {
                  OS_TCB   *ptcb;
                  OS_EVENT *pevent;
                  INT8U     x;
                  INT8U     y;
                  INT8U     bitx;
                  INT8U     bity;
              
              
                  if ((oldprio >= OS_LOWEST_PRIO && oldprio != OS_PRIO_SELF)  || 
                       newprio >= OS_LOWEST_PRIO) {
                      return (OS_PRIO_INVALID);
                  }
                  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) {     /* If task is ready make it not ready  */
                              if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0) {
                                  OSRdyGrp &= ~ptcb->OSTCBBitY;
                              }
                              OSRdyGrp    |= bity;                            /* Make new priority ready to run      */
                              OSRdyTbl[y] |= bitx;
                          } 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;
                              }
                          }
                          OSTCBPrioTbl[newprio] = ptcb;                       /* Place pointer to TCB @ new priority */
                          ptcb->OSTCBPrio       = newprio;                    /* Set new task priority               */
                          ptcb->OSTCBY          = y;
C51 COMPILER V7.06   OS_TASK                                                               01/08/2008 20:10:17 PAGE 3   

                          ptcb->OSTCBX          = x;
                          ptcb->OSTCBBitY       = bity;
                          ptcb->OSTCBBitX       = bitx;
                          OS_EXIT_CRITICAL();
                          OSSched();                                          /* 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
 132          /*$PAGE*/
 133          /*
 134          *********************************************************************************************************
 135          *                                            CREATE A TASK
 136          *
 137          * Description: This function is used to have uC/OS-II manage the execution of a task.  Tasks can either
 138          *              be created prior to the start of multitasking or by a running task.  A task cannot be
 139          *              created by an ISR.
 140          *
 141          * Arguments  : task     is a pointer to the task's code
 142          *
 143          *              pdata    is a pointer to an optional data area which can be used to pass parameters to
 144          *                       the task when the task first executes.  Where the task is concerned it thinks
 145          *                       it was invoked and passed the argument 'pdata' as follows:
 146          *
 147          *                           void Task (void *pdata)
 148          *                           {
 149          *                               for (;;) {
 150          *                                   Task code;
 151          *                               }
 152          *                           }
 153          *
 154          *              ptos     is a pointer to the task's top of stack.  If the configuration constant 
 155          *                       OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
 156          *                       memory to low memory).  'pstk' will thus point to the highest (valid) memory 
 157          *                       location of the stack.  If OS_STK_GROWTH is set to 0, 'pstk' will point to the 
 158          *                       lowest memory location of the stack and the stack will grow with increasing
 159          *                       memory locations.
 160          *
 161          *              prio     is the task's priority.  A unique priority MUST be assigned to each task and the
 162          *                       lower the number, the higher the priority.
 163          *
 164          * Returns    : OS_NO_ERR        if the function was successful.
 165          *              OS_PRIO_EXIT     if the task priority already exist 
 166          *                               (each task MUST have a unique priority).
 167          *              OS_PRIO_INVALID  if the priority you specify is higher that the maximum allowed 
 168          *                               (i.e. >= OS_LOWEST_PRIO)
 169          *********************************************************************************************************
 170          */
 171          
 172          #if OS_TASK_CREATE_EN
 173          INT8U OSTaskCreate (void (*task)(void *pd), void *ppdata, OS_STK *ptos, INT8U prio) reentrant
 174          {
 175   1          void   *psp;
 176   1          INT8U   err;
 177   1      
 178   1      
 179   1          if (prio > OS_LOWEST_PRIO) {             /* Make sure priority is within allowable range           */

⌨️ 快捷键说明

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