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

📄 os_q.lst

📁 在51上运行的小的OS系统
💻 LST
📖 第 1 页 / 共 4 页
字号:
 144                      pevent->OSEventType    = OS_EVENT_TYPE_Q;
 145                      pevent->OSEventCnt     = 0;
 146                      pevent->OSEventPtr     = pq;
 147          #if OS_EVENT_NAME_SIZE > 1
 148                      pevent->OSEventName[0] = '?';                  /* Unknown name                             */
 149                      pevent->OSEventName[1] = OS_ASCII_NUL;
 150          #endif
 151                      OS_EventWaitListInit(pevent);                 /*      Initalize the wait list              */
 152                  } else {
 153                      pevent->OSEventPtr = (void *)OSEventFreeList; /* No,  Return event control block on error  */
 154                      OSEventFreeList    = pevent;
 155                      OS_EXIT_CRITICAL();
 156                      pevent = (OS_EVENT *)0;
 157                  }
 158              }
 159              return (pevent);
 160          }
 161          /*$PAGE*/
 162          /*
 163          *********************************************************************************************************
 164          *                                        DELETE A MESSAGE QUEUE
 165          *
 166          * Description: This function deletes a message queue and readies all tasks pending on the queue.
 167          *
 168          * Arguments  : pevent        is a pointer to the event control block associated with the desired
 169          *                            queue.
 170          *
 171          *              opt           determines delete options as follows:
 172          *                            opt == OS_DEL_NO_PEND   Delete the queue ONLY if no task pending
 173          *                            opt == OS_DEL_ALWAYS    Deletes the queue even if tasks are waiting.
 174          *                                                    In this case, all the tasks pending will be readied.
 175          *
 176          *              err           is a pointer to an error code that can contain one of the following values:
 177          *                            OS_NO_ERR               The call was successful and the queue was deleted
 178          *                            OS_ERR_DEL_ISR          If you tried to delete the queue from an ISR
 179          *                            OS_ERR_INVALID_OPT      An invalid option was specified
 180          *                            OS_ERR_TASK_WAITING     One or more tasks were waiting on the queue
 181          *                            OS_ERR_EVENT_TYPE       If you didn't pass a pointer to a queue
 182          *                            OS_ERR_PEVENT_NULL      If 'pevent' is a NULL pointer.
 183          *
 184          * Returns    : pevent        upon error
C51 COMPILER V8.08   OS_Q                                                                  08/04/2008 21:49:52 PAGE 5   

 185          *              (OS_EVENT *)0 if the queue was successfully deleted.
 186          *
 187          * Note(s)    : 1) This function must be used with care.  Tasks that would normally expect the presence of
 188          *                 the queue MUST check the return code of OSQPend().
 189          *              2) OSQAccept() callers will not know that the intended queue has been deleted unless
 190          *                 they check 'pevent' to see that it's a NULL pointer.
 191          *              3) This call can potentially disable interrupts for a long time.  The interrupt disable
 192          *                 time is directly proportional to the number of tasks waiting on the queue.
 193          *              4) Because ALL tasks pending on the queue will be readied, you MUST be careful in
 194          *                 applications where the queue is used for mutual exclusion because the resource(s)
 195          *                 will no longer be guarded by the queue.
 196          *              5) If the storage for the message queue was allocated dynamically (i.e. using a malloc()
 197          *                 type call) then your application MUST release the memory storage by call the counterpart
 198          *                 call of the dynamic allocation scheme used.  If the queue storage was created statically
 199          *                 then, the storage can be reused.
 200          *********************************************************************************************************
 201          */
 202          
 203          #if OS_Q_DEL_EN > 0
 204          OS_EVENT  *OSQDel (OS_EVENT *pevent, INT8U opt, INT8U *err)
 205          {
 206              BOOLEAN    tasks_waiting;
 207              OS_EVENT  *pevent_return;
 208              OS_Q      *pq;
 209          #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 212          
 213          
 214          
 215          #if OS_ARG_CHK_EN > 0
 216              if (err == (INT8U *)0) {                               /* Validate 'err'                           */
 217                  return (pevent);
 218              }
 219              if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
 220                  *err = OS_ERR_PEVENT_NULL;
 221                  return (pevent);
 222              }
 223          #endif
 224              if (pevent->OSEventType != OS_EVENT_TYPE_Q) {          /* Validate event block type                */
 225                  *err = OS_ERR_EVENT_TYPE;
 226                  return (pevent);
 227              }
 228              if (OSIntNesting > 0) {                                /* See if called from ISR ...               */
 229                  *err = OS_ERR_DEL_ISR;                             /* ... can't DELETE from an ISR             */
 230                  return (pevent);
 231              }
 232              OS_ENTER_CRITICAL();
 233              if (pevent->OSEventGrp != 0) {                         /* See if any tasks waiting on queue        */
 234                  tasks_waiting = TRUE;                              /* Yes                                      */
 235              } else {
 236                  tasks_waiting = FALSE;                             /* No                                       */
 237              }
 238              switch (opt) {
 239                  case OS_DEL_NO_PEND:                               /* Delete queue only if no task waiting     */
 240                       if (tasks_waiting == FALSE) {
 241          #if OS_EVENT_NAME_SIZE > 1
 242                           pevent->OSEventName[0] = '?';             /* Unknown name                             */
 243                           pevent->OSEventName[1] = OS_ASCII_NUL;
 244          #endif
 245                           pq                     = (OS_Q *)pevent->OSEventPtr;  /* Return OS_Q to free list     */
 246                           pq->OSQPtr             = OSQFreeList;
C51 COMPILER V8.08   OS_Q                                                                  08/04/2008 21:49:52 PAGE 6   

 247                           OSQFreeList            = pq;
 248                           pevent->OSEventType    = OS_EVENT_TYPE_UNUSED;
 249                           pevent->OSEventPtr     = OSEventFreeList; /* Return Event Control Block to free list  */
 250                           pevent->OSEventCnt     = 0;
 251                           OSEventFreeList        = pevent;          /* Get next free event control block        */
 252                           OS_EXIT_CRITICAL();
 253                           *err                   = OS_NO_ERR;
 254                           pevent_return          = (OS_EVENT *)0;   /* Queue has been deleted                   */
 255                       } else {
 256                           OS_EXIT_CRITICAL();
 257                           *err                   = OS_ERR_TASK_WAITING;
 258                           pevent_return          = pevent;
 259                       }
 260                       break;
 261          
 262                  case OS_DEL_ALWAYS:                                /* Always delete the queue                  */
 263                       while (pevent->OSEventGrp != 0) {             /* Ready ALL tasks waiting for queue        */
 264                           (void)OS_EventTaskRdy(pevent, (void *)0, OS_STAT_Q);
 265                       }
 266          #if OS_EVENT_NAME_SIZE > 1
 267                       pevent->OSEventName[0] = '?';                 /* Unknown name                             */
 268                       pevent->OSEventName[1] = OS_ASCII_NUL;
 269          #endif
 270                       pq                     = (OS_Q *)pevent->OSEventPtr;   /* Return OS_Q to free list        */
 271                       pq->OSQPtr             = OSQFreeList;
 272                       OSQFreeList            = pq;
 273                       pevent->OSEventType    = OS_EVENT_TYPE_UNUSED;
 274                       pevent->OSEventPtr     = OSEventFreeList;     /* Return Event Control Block to free list  */
 275                       pevent->OSEventCnt     = 0;
 276                       OSEventFreeList        = pevent;              /* Get next free event control block        */
 277                       OS_EXIT_CRITICAL();
 278                       if (tasks_waiting == TRUE) {                  /* Reschedule only if task(s) were waiting  */
 279                           OS_Sched();                               /* Find highest priority task ready to run  */
 280                       }
 281                       *err                   = OS_NO_ERR;
 282                       pevent_return          = (OS_EVENT *)0;       /* Queue has been deleted                   */
 283                       break;
 284          
 285                  default:
 286                       OS_EXIT_CRITICAL();
 287                       *err                   = OS_ERR_INVALID_OPT;
 288                       pevent_return          = pevent;
 289                       break;
 290              }
 291              return (pevent_return);
 292          }
 293          #endif
 294          
 295          /*$PAGE*/
 296          /*
 297          *********************************************************************************************************
 298          *                                             FLUSH QUEUE
 299          *
 300          * Description : This function is used to flush the contents of the message queue.
 301          *
 302          * Arguments   : none
 303          *
 304          * Returns     : OS_NO_ERR           upon success
 305          *               OS_ERR_EVENT_TYPE   If you didn't pass a pointer to a queue
 306          *               OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer
 307          *
 308          * WARNING     : You should use this function with great care because, when to flush the queue, you LOOSE
C51 COMPILER V8.08   OS_Q                                                                  08/04/2008 21:49:52 PAGE 7   

 309          *               the references to what the queue entries are pointing to and thus, you could cause
 310          *               'memory leaks'.  In other words, the data you are pointing to that's being referenced
 311          *               by the queue entries should, most likely, need to be de-allocated (i.e. freed).
 312          *********************************************************************************************************
 313          */
 314          
 315          #if OS_Q_FLUSH_EN > 0
 316          INT8U  OSQFlush (OS_EVENT *pevent)
 317          {
 318              OS_Q      *pq;
 319          #if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 322          
 323          
 324          
 325          #if OS_ARG_CHK_EN > 0
 326              if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
 327                  return (OS_ERR_PEVENT_NULL);
 328              }
 329              if (pevent->OSEventType != OS_EVENT_TYPE_Q) {     /* Validate event block type                     */
 330                  return (OS_ERR_EVENT_TYPE);
 331              }
 332          #endif
 333              OS_ENTER_CRITICAL();
 334              pq             = (OS_Q *)pevent->OSEventPtr;      /* Point to queue storage structure              */
 335              pq->OSQIn      = pq->OSQStart;
 336              pq->OSQOut     = pq->OSQStart;
 337              pq->OSQEntries = 0;
 338              OS_EXIT_CRITICAL();
 339              return (OS_NO_ERR);
 340          }
 341          #endif
 342          
 343          /*$PAGE*/
 344          /*
 345          *********************************************************************************************************
 346          *                                     PEND ON A QUEUE FOR A MESSAGE
 347          *
 348          * Description: This function waits for a message to be sent to a queue
 349          *
 350          * Arguments  : pevent        is a pointer to the event control block associated with the desired queue
 351          *
 352          *              timeout       is an optional timeout period (in clock ticks).  If non-zero, your task will

⌨️ 快捷键说明

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