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

📄 os_mutex.lst

📁 在51上运行的小的OS系统
💻 LST
📖 第 1 页 / 共 4 页
字号:
 439              OS_EXIT_CRITICAL();
 440              OS_Sched();                                       /* Find next highest priority task ready         */
 441              OS_ENTER_CRITICAL();
 442              if (OSTCBCur->OSTCBPendTO == TRUE) {              /* See if we timed out during the pend           */
 443                  OS_EventTO(pevent);
 444                  OS_EXIT_CRITICAL();
 445                  *err = OS_TIMEOUT;                            /* Indicate that we didn't get mutex within TO   */
 446                  return;
 447              }
 448              OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;
 449              OS_EXIT_CRITICAL();
 450              *err = OS_NO_ERR;
 451          }
 452          /*$PAGE*/
 453          /*
 454          *********************************************************************************************************
 455          *                                  POST TO A MUTUAL EXCLUSION SEMAPHORE
 456          *
 457          * Description: This function signals a mutual exclusion semaphore
 458          *
 459          * Arguments  : pevent              is a pointer to the event control block associated with the desired
 460          *                                  mutex.
 461          *
 462          * Returns    : OS_NO_ERR               The call was successful and the mutex was signaled.
 463          *              OS_ERR_EVENT_TYPE       If you didn't pass a pointer to a mutex
 464          *              OS_ERR_PEVENT_NULL      'pevent' is a NULL pointer
 465          *              OS_ERR_POST_ISR         Attempted to post from an ISR (not valid for MUTEXes)
 466          *              OS_ERR_NOT_MUTEX_OWNER  The task that did the post is NOT the owner of the MUTEX.
 467          *********************************************************************************************************
 468          */
 469          
 470          INT8U  OSMutexPost (OS_EVENT *pevent)
 471          {
 472              INT8U      pip;                                   /* Priority inheritance priority                 */
 473              INT8U      prio;
 474              INT8U      y;
 475          #if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 478          
 479          
 480          
 481              if (OSIntNesting > 0) {                           /* See if called from ISR ...                    */
 482                  return (OS_ERR_POST_ISR);                     /* ... can't POST mutex from an ISR              */
 483              }
 484          #if OS_ARG_CHK_EN > 0
 485              if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
 486                  return (OS_ERR_PEVENT_NULL);
 487              }
 488          #endif
 489              if (pevent->OSEventType != OS_EVENT_TYPE_MUTEX) { /* Validate event block type                     */
 490                  return (OS_ERR_EVENT_TYPE);
 491              }
 492              OS_ENTER_CRITICAL();
C51 COMPILER V8.08   OS_MUTEX                                                              08/04/2008 21:49:52 PAGE 10  

 493              pip  = (INT8U)(pevent->OSEventCnt >> 8);          /* Get priority inheritance priority of mutex    */
 494              prio = (INT8U)(pevent->OSEventCnt & OS_MUTEX_KEEP_LOWER_8);  /* Get owner's original priority      */
 495              if (OSTCBCur != (OS_TCB *)pevent->OSEventPtr) {   /* See if posting task owns the MUTEX            */
 496                  OS_EXIT_CRITICAL();
 497                  return (OS_ERR_NOT_MUTEX_OWNER);
 498              }
 499              if (OSTCBCur->OSTCBPrio == pip) {                 /* Did we have to raise current task's priority? */
 500                  y            = OSTCBCur->OSTCBY;              /* Yes, Return to original priority              */
 501                  OSRdyTbl[y] &= ~OSTCBCur->OSTCBBitX;          /*      Remove owner from ready list at 'pip'    */
 502                  if (OSRdyTbl[y] == 0) {
 503                      OSRdyGrp &= ~OSTCBCur->OSTCBBitY;
 504                  }
 505                  OSTCBCur->OSTCBPrio         = prio;
 506          #if OS_LOWEST_PRIO <= 63
 507                  OSTCBCur->OSTCBY            = prio >> 3;
 508                  OSTCBCur->OSTCBX            = prio & 0x07;
 509          #else
                      OSTCBCur->OSTCBY            = (prio >> 4) & 0xFF;
                      OSTCBCur->OSTCBX            = prio & 0x0F;
              #endif
 513                  OSTCBCur->OSTCBBitY         = 1 << OSTCBCur->OSTCBY;
 514                  OSTCBCur->OSTCBBitX         = 1 << OSTCBCur->OSTCBX;
 515                  OSRdyGrp                   |= OSTCBCur->OSTCBBitY;
 516                  OSRdyTbl[OSTCBCur->OSTCBY] |= OSTCBCur->OSTCBBitX;
 517                  OSTCBPrioTbl[prio]          = OSTCBCur;
 518              }
 519              OSTCBPrioTbl[pip] = (OS_TCB *)1;                  /* Reserve table entry                           */
 520              if (pevent->OSEventGrp != 0) {                    /* Any task waiting for the mutex?               */
 521                                                                /* Yes, Make HPT waiting for mutex ready         */
 522                  prio                = OS_EventTaskRdy(pevent, (void *)0, OS_STAT_MUTEX);
 523                  pevent->OSEventCnt &= OS_MUTEX_KEEP_UPPER_8;  /*      Save priority of mutex's new owner       */
 524                  pevent->OSEventCnt |= prio;
 525                  pevent->OSEventPtr  = OSTCBPrioTbl[prio];     /*      Link to mutex owner's OS_TCB             */
 526                  OS_EXIT_CRITICAL();
 527                  OS_Sched();                                   /*      Find highest priority task ready to run  */
 528                  return (OS_NO_ERR);
 529              }
 530              pevent->OSEventCnt |= OS_MUTEX_AVAILABLE;         /* No,  Mutex is now available                   */
 531              pevent->OSEventPtr  = (void *)0;
 532              OS_EXIT_CRITICAL();
 533              return (OS_NO_ERR);
 534          }
 535          /*$PAGE*/
 536          /*
 537          *********************************************************************************************************
 538          *                                     QUERY A MUTUAL EXCLUSION SEMAPHORE
 539          *
 540          * Description: This function obtains information about a mutex
 541          *
 542          * Arguments  : pevent          is a pointer to the event control block associated with the desired mutex
 543          *
 544          *              p_mutex_data    is a pointer to a structure that will contain information about the mutex
 545          *
 546          * Returns    : OS_NO_ERR            The call was successful and the message was sent
 547          *              OS_ERR_QUERY_ISR     If you called this function from an ISR
 548          *              OS_ERR_PEVENT_NULL   If 'pevent'       is a NULL pointer
 549          *              OS_ERR_PDATA_NULL    If 'p_mutex_data' is a NULL pointer
 550          *              OS_ERR_EVENT_TYPE    If you are attempting to obtain data from a non mutex.
 551          *********************************************************************************************************
 552          */
 553          
 554          #if OS_MUTEX_QUERY_EN > 0
C51 COMPILER V8.08   OS_MUTEX                                                              08/04/2008 21:49:52 PAGE 11  

 555          INT8U  OSMutexQuery (OS_EVENT *pevent, OS_MUTEX_DATA *p_mutex_data)
 556          {
 557              INT8U      i;
 558          #if OS_LOWEST_PRIO <= 63
 559              INT8U     *psrc;
 560              INT8U     *pdest;
 561          #else
                  INT16U    *psrc;
                  INT16U    *pdest;
              #endif
 565          #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 568          
 569          
 570          
 571              if (OSIntNesting > 0) {                                /* See if called from ISR ...               */
 572                  return (OS_ERR_QUERY_ISR);                         /* ... can't QUERY mutex from an ISR        */
 573              }
 574          #if OS_ARG_CHK_EN > 0
 575              if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
 576                  return (OS_ERR_PEVENT_NULL);
 577              }
 578              if (p_mutex_data == (OS_MUTEX_DATA *)0) {              /* Validate 'p_mutex_data'                  */
 579                  return (OS_ERR_PDATA_NULL);
 580              }
 581          #endif
 582              if (pevent->OSEventType != OS_EVENT_TYPE_MUTEX) {      /* Validate event block type                */
 583                  return (OS_ERR_EVENT_TYPE);
 584              }
 585              OS_ENTER_CRITICAL();
 586              p_mutex_data->OSMutexPIP  = (INT8U)(pevent->OSEventCnt >> 8);
 587              p_mutex_data->OSOwnerPrio = (INT8U)(pevent->OSEventCnt & OS_MUTEX_KEEP_LOWER_8);
 588              if (p_mutex_data->OSOwnerPrio == 0xFF) {
 589                  p_mutex_data->OSValue = 1;
 590              } else {
 591                  p_mutex_data->OSValue = 0;
 592              }
 593              p_mutex_data->OSEventGrp  = pevent->OSEventGrp;        /* Copy wait list                           */
 594              psrc                      = &pevent->OSEventTbl[0];
 595              pdest                     = &p_mutex_data->OSEventTbl[0];
 596              for (i = 0; i < OS_EVENT_TBL_SIZE; i++) {
 597                  *pdest++ = *psrc++;
 598              }
 599              OS_EXIT_CRITICAL();
 600              return (OS_NO_ERR);
 601          }
 602          #endif                                                     /* OS_MUTEX_QUERY_EN                        */
 603          #endif                                                     /* OS_MUTEX_EN                              */

C51 COMPILATION COMPLETE.  0 WARNING(S),  57 ERROR(S)

⌨️ 快捷键说明

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