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

📄 os_q.lst

📁 在51上运行的小的OS系统
💻 LST
📖 第 1 页 / 共 4 页
字号:
 353          *                            wait for a message to arrive at the queue up to the amount of time
 354          *                            specified by this argument.  If you specify 0, however, your task will wait
 355          *                            forever at the specified queue or, until a message arrives.
 356          *
 357          *              err           is a pointer to where an error message will be deposited.  Possible error
 358          *                            messages are:
 359          *
 360          *                            OS_NO_ERR           The call was successful and your task received a
 361          *                                                message.
 362          *                            OS_TIMEOUT          A message was not received within the specified timeout
 363          *                            OS_ERR_EVENT_TYPE   You didn't pass a pointer to a queue
 364          *                            OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer
 365          *                            OS_ERR_PEND_ISR     If you called this function from an ISR and the result
 366          *                                                would lead to a suspension.
 367          *
 368          * Returns    : != (void *)0  is a pointer to the message received
 369          *              == (void *)0  if you received a NULL pointer message or,
 370          *                            if no message was received or,
C51 COMPILER V8.08   OS_Q                                                                  08/04/2008 21:49:52 PAGE 8   

 371          *                            if 'pevent' is a NULL pointer or,
 372          *                            if you didn't pass a pointer to a queue.
 373          *
 374          * Note(s)    : As of V2.60, this function allows you to receive NULL pointer messages.
 375          *********************************************************************************************************
 376          */
 377          
 378          void  *OSQPend (OS_EVENT *pevent, INT16U timeout, INT8U *err)
 379          {
 380              void      *msg;
 381              OS_Q      *pq;
 382          #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 385          
 386          
 387          
 388          #if OS_ARG_CHK_EN > 0
 389              if (err == (INT8U *)0) {                     /* Validate 'err'                                     */
 390                  return ((void *)0);
 391              }
 392              if (pevent == (OS_EVENT *)0) {               /* Validate 'pevent'                                  */
 393                  *err = OS_ERR_PEVENT_NULL;
 394                  return ((void *)0);
 395              }
 396              if (pevent->OSEventType != OS_EVENT_TYPE_Q) {/* Validate event block type                          */
 397                  *err = OS_ERR_EVENT_TYPE;
 398                  return ((void *)0);
 399              }
 400          #endif
 401              if (OSIntNesting > 0) {                      /* See if called from ISR ...                         */
 402                  *err = OS_ERR_PEND_ISR;                  /* ... can't PEND from an ISR                         */
 403                  return ((void *)0);
 404              }
 405              OS_ENTER_CRITICAL();
 406              pq = (OS_Q *)pevent->OSEventPtr;             /* Point at queue control block                       */
 407              if (pq->OSQEntries > 0) {                    /* See if any messages in the queue                   */
 408                  msg = *pq->OSQOut++;                     /* Yes, extract oldest message from the queue         */
 409                  pq->OSQEntries--;                        /* Update the number of entries in the queue          */
 410                  if (pq->OSQOut == pq->OSQEnd) {          /* Wrap OUT pointer if we are at the end of the queue */
 411                      pq->OSQOut = pq->OSQStart;
 412                  }
 413                  OS_EXIT_CRITICAL();
 414                  *err = OS_NO_ERR;
 415                  return (msg);                            /* Return message received                            */
 416              }
 417              OSTCBCur->OSTCBStat   |= OS_STAT_Q;          /* Task will have to pend for a message to be posted  */
 418              OSTCBCur->OSTCBPendTO  = FALSE;
 419              OSTCBCur->OSTCBDly     = timeout;            /* Load timeout into TCB                              */
 420              OS_EventTaskWait(pevent);                    /* Suspend task until event or timeout occurs         */
 421              OS_EXIT_CRITICAL();
 422              OS_Sched();                                  /* Find next highest priority task ready to run       */
 423              OS_ENTER_CRITICAL();
 424              if (OSTCBCur->OSTCBPendTO == TRUE) {         /* Was task readied because of a timeout?             */
 425                  OS_EventTO(pevent);                      /* Yes                                                */
 426                  OS_EXIT_CRITICAL();
 427                  *err = OS_TIMEOUT;                       /*     Indicate a timeout occured                     */
 428                  return ((void *)0);                      /*     No message received                            */
 429              }
 430              msg                     = OSTCBCur->OSTCBMsg;/* No, Extract message from TCB (Put there by QPost)  */
 431              OSTCBCur->OSTCBMsg      = (void *)0;
 432              OSTCBCur->OSTCBStat     = OS_STAT_RDY;
C51 COMPILER V8.08   OS_Q                                                                  08/04/2008 21:49:52 PAGE 9   

 433              OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;     /*     No longer waiting for event                    */
 434              OS_EXIT_CRITICAL();
 435              *err                    = OS_NO_ERR;
 436              return (msg);                                /*     Return message received                        */
 437          }
 438          /*$PAGE*/
 439          /*
 440          *********************************************************************************************************
 441          *                                        POST MESSAGE TO A QUEUE
 442          *
 443          * Description: This function sends a message to a queue
 444          *
 445          * Arguments  : pevent        is a pointer to the event control block associated with the desired queue
 446          *
 447          *              msg           is a pointer to the message to send.
 448          *
 449          * Returns    : OS_NO_ERR             The call was successful and the message was sent
 450          *              OS_Q_FULL             If the queue cannot accept any more messages because it is full.
 451          *              OS_ERR_EVENT_TYPE     If you didn't pass a pointer to a queue.
 452          *              OS_ERR_PEVENT_NULL    If 'pevent' is a NULL pointer
 453          *
 454          * Note(s)    : As of V2.60, this function allows you to send NULL pointer messages.
 455          *********************************************************************************************************
 456          */
 457          
 458          #if OS_Q_POST_EN > 0
 459          INT8U  OSQPost (OS_EVENT *pevent, void *msg)
 460          {
 461              OS_Q      *pq;
 462          #if OS_CRITICAL_METHOD == 3                            /* Allocate storage for CPU status register     */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 465          
 466          
 467          
 468          #if OS_ARG_CHK_EN > 0
 469              if (pevent == (OS_EVENT *)0) {                     /* Validate 'pevent'                            */
 470                  return (OS_ERR_PEVENT_NULL);
 471              }
 472          #endif
 473              if (pevent->OSEventType != OS_EVENT_TYPE_Q) {      /* Validate event block type                    */
 474                  return (OS_ERR_EVENT_TYPE);
 475              }
 476              OS_ENTER_CRITICAL();
 477              if (pevent->OSEventGrp != 0) {                     /* See if any task pending on queue             */
 478                  (void)OS_EventTaskRdy(pevent, msg, OS_STAT_Q); /* Ready highest priority task waiting on event */
 479                  OS_EXIT_CRITICAL();
 480                  OS_Sched();                                    /* Find highest priority task ready to run      */
 481                  return (OS_NO_ERR);
 482              }
 483              pq = (OS_Q *)pevent->OSEventPtr;                   /* Point to queue control block                 */
 484              if (pq->OSQEntries >= pq->OSQSize) {               /* Make sure queue is not full                  */
 485                  OS_EXIT_CRITICAL();
 486                  return (OS_Q_FULL);
 487              }
 488              *pq->OSQIn++ = msg;                                /* Insert message into queue                    */
 489              pq->OSQEntries++;                                  /* Update the nbr of entries in the queue       */
 490              if (pq->OSQIn == pq->OSQEnd) {                     /* Wrap IN ptr if we are at end of queue        */
 491                  pq->OSQIn = pq->OSQStart;
 492              }
 493              OS_EXIT_CRITICAL();
 494              return (OS_NO_ERR);
C51 COMPILER V8.08   OS_Q                                                                  08/04/2008 21:49:52 PAGE 10  

 495          }
 496          #endif
 497          /*$PAGE*/
 498          /*
 499          *********************************************************************************************************
 500          *                                   POST MESSAGE TO THE FRONT OF A QUEUE
 501          *
 502          * Description: This function sends a message to a queue but unlike OSQPost(), the message is posted at
 503          *              the front instead of the end of the queue.  Using OSQPostFront() allows you to send
 504          *              'priority' messages.
 505          *
 506          * Arguments  : pevent        is a pointer to the event control block associated with the desired queue
 507          *
 508          *              msg           is a pointer to the message to send.
 509          *
 510          * Returns    : OS_NO_ERR             The call was successful and the message was sent
 511          *              OS_Q_FULL             If the queue cannot accept any more messages because it is full.
 512          *              OS_ERR_EVENT_TYPE     If you didn't pass a pointer to a queue.
 513          *              OS_ERR_PEVENT_NULL    If 'pevent' is a NULL pointer
 514          *
 515          * Note(s)    : As of V2.60, this function allows you to send NULL pointer messages.
 516          *********************************************************************************************************
 517          */
 518          
 519          #if OS_Q_POST_FRONT_EN > 0
 520          INT8U  OSQPostFront (OS_EVENT *pevent, void *msg)
 521          {
 522              OS_Q      *pq;
 523          #if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 526          
 527          
 528          
 529          #if OS_ARG_CHK_EN > 0
 530              if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
 531                  return (OS_ERR_PEVENT_NULL);
 532              }
 533          #endif
 534              if (pevent->OSEventType != OS_EVENT_TYPE_Q) {     /* Validate event block type                     */
 535                  return (OS_ERR_EVENT_TYPE);
 536              }
 537              OS_ENTER_CRITICAL();
 538              if (pevent->OSEventGrp != 0) {                    /* See if any task pending on queue              */
 539                  (void)OS_EventTaskRdy(pevent, msg, OS_STAT_Q);/* Ready highest priority task waiting on event  */
 540                  OS_EXIT_CRITICAL();
 541                  OS_Sched();                                   /* Find highest priority task ready to run       */
 542                  return (OS_NO_ERR);
 543              }
 544              pq = (OS_Q *)pevent->OSEventPtr;                  /* Point to queue control block                  */
 545              if (pq->OSQEntries >= pq->OSQSize) {              /* Make sure queue is not full                   */
 546                  OS_EXIT_CRITICAL();
 547                  return (OS_Q_FULL);
 548              }
 549              if (pq->OSQOut == pq->OSQStart) {                 /* Wrap OUT ptr if we are at the 1st queue entry */
 550                  pq->OSQOut = pq->OSQEnd;
 551              }
 552              pq->OSQOut--;
 553              *pq->OSQOut = msg;                                /* Insert message into queue                     */
 554              pq->OSQEntries++;                                 /* Update the nbr of entries in the queue        */
 555              OS_EXIT_CRITICAL();
 556              return (OS_NO_ERR);
C51 COMPILER V8.08   OS_Q                                                                  08/04/2008 21:49:52 PAGE 11  

 557          }
 558          #endif
 559          /*$PAGE*/

⌨️ 快捷键说明

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