📄 os_mutex.ls1
字号:
457 ; ptcb = (OS_TCB *)(pevent->OSEventPtr); /* Point to TCB of
mutex owner */
458 ; if (ptcb->OSTCBPrio != pip && mprio > OSTCBCur->OSTCBPrio) { /* Need to promote
prio of owner?*/
459 ; if ((OSRdyTbl[ptcb->OSTCBY] & ptcb->OSTCBBitX) != 0x00) { /* See if mutex own
er is ready */
460 ; /* Yes, Remove owne
r from Rdy ...*/
461 ; /* ... list at
current prio */
462 ; if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0x00) {
463 ; OSRdyGrp &= ~ptcb->OSTCBBitY;
464 ; }
465 ; rdy = TRUE;
466 ; } else {
467 ; rdy = FALSE; /* No
*/
A51 MACRO ASSEMBLER OS_MUTEX 05/17/2005 11:19:51 PAGE 10
468 ; }
469 ; ptcb->OSTCBPrio = pip; /* Change owner task prio to P
IP */
470 ; ptcb->OSTCBY = ptcb->OSTCBPrio >> 3;
471 ; ptcb->OSTCBBitY = OSMapTbl[ptcb->OSTCBY];
472 ; ptcb->OSTCBX = ptcb->OSTCBPrio & 0x07;
473 ; ptcb->OSTCBBitX = OSMapTbl[ptcb->OSTCBX];
474 ; if (rdy == TRUE) { /* If task was ready at owner'
s priority ...*/
475 ; OSRdyGrp |= ptcb->OSTCBBitY; /* ... make it ready at new pr
iority. */
476 ; OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
477 ; }
478 ; OSTCBPrioTbl[pip] = (OS_TCB *)ptcb;
479 ; }
480 ; OSTCBCur->OSTCBStat |= OS_STAT_MUTEX; /* Mutex not available, pend curren
t task */
481 ; OSTCBCur->OSTCBDly = timeout; /* Store timeout in current task's
TCB */
482 ; OS_EventTaskWait(pevent); /* Suspend task until event or time
out occurs */
483 ; OS_EXIT_CRITICAL();
484 ; OS_Sched(); /* Find next highest priority task
ready */
485 ; OS_ENTER_CRITICAL();
486 ; if (OSTCBCur->OSTCBStat & OS_STAT_MUTEX) { /* Must have timed out if still wai
ting for event*/
487 ; OS_EventTO(pevent);
488 ; OS_EXIT_CRITICAL();
489 ; *err = OS_TIMEOUT; /* Indicate that we didn't get mute
x within TO */
490 ; return;
491 ; }
492 ; OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;
493 ; OS_EXIT_CRITICAL();
494 ; *err = OS_NO_ERR;
495 ; }
496 ; /*$PAGE*/
497 ; /*
498 ; *****************************************************************************************
****************
499 ; * POST TO A MUTUAL EXCLUSION SEMAPHORE
500 ; *
501 ; * Description: This function signals a mutual exclusion semaphore
502 ; *
503 ; * Arguments : pevent is a pointer to the event control block associated wit
h the desired
504 ; * mutex.
505 ; *
506 ; * Returns : OS_NO_ERR The call was successful and the mutex was signaled
.
507 ; * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a mutex
508 ; * OS_ERR_PEVENT_NULL 'pevent' is a NULL pointer
509 ; * OS_ERR_POST_ISR Attempted to post from an ISR (not valid for MUTEX
es)
510 ; * OS_ERR_NOT_MUTEX_OWNER The task that did the post is NOT the owner of the
MUTEX.
511 ; *****************************************************************************************
****************
512 ; */
513 ;
514 ; INT8U OSMutexPost (OS_EVENT *pevent)LG_REENTRANT
515 ; {
516 ; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status
register */
517 ; OS_CPU_SR cpu_sr;
A51 MACRO ASSEMBLER OS_MUTEX 05/17/2005 11:19:51 PAGE 11
518 ; #endif
519 ; INT8U pip; /* Priority inheritance priority
*/
520 ; INT8U prio;
521 ;
522 ;
523 ; if (OSIntNesting > 0) { /* See if called from ISR ...
*/
524 ; return (OS_ERR_POST_ISR); /* ... can't POST mutex from an ISR
*/
525 ; }
526 ; #if OS_ARG_CHK_EN > 0
527 ; if (pevent == (OS_EVENT *)0) { /* Validate 'pevent'
*/
528 ; return (OS_ERR_PEVENT_NULL);
529 ; }
530 ; if (pevent->OSEventType != OS_EVENT_TYPE_MUTEX) { /* Validate event block type
*/
531 ; return (OS_ERR_EVENT_TYPE);
532 ; }
533 ; #endif
534 ; OS_ENTER_CRITICAL();
535 ; pip = (INT8U)(pevent->OSEventCnt >> 8); /* Get priority inheritance priorit
y of mutex */
536 ; prio = (INT8U)(pevent->OSEventCnt & OS_MUTEX_KEEP_LOWER_8); /* Get owner's original
priority */
537 ; if (OSTCBCur->OSTCBPrio != pip &&
538 ; OSTCBCur->OSTCBPrio != prio) { /* See if posting task owns the MUT
EX */
539 ; OS_EXIT_CRITICAL();
540 ; return (OS_ERR_NOT_MUTEX_OWNER);
541 ; }
542 ; if (OSTCBCur->OSTCBPrio == pip) { /* Did we have to raise current tas
k's priority? */
543 ; /* Yes, Return to original priority
*/
544 ; /* Remove owner from ready lis
t at 'pip' */
545 ; if ((OSRdyTbl[OSTCBCur->OSTCBY] &= ~OSTCBCur->OSTCBBitX) == 0) {
546 ; OSRdyGrp &= ~OSTCBCur->OSTCBBitY;
547 ; }
548 ; OSTCBCur->OSTCBPrio = prio;
549 ; OSTCBCur->OSTCBY = prio >> 3;
550 ; OSTCBCur->OSTCBBitY = OSMapTbl[OSTCBCur->OSTCBY];
551 ; OSTCBCur->OSTCBX = prio & 0x07;
552 ; OSTCBCur->OSTCBBitX = OSMapTbl[OSTCBCur->OSTCBX];
553 ; OSRdyGrp |= OSTCBCur->OSTCBBitY;
554 ; OSRdyTbl[OSTCBCur->OSTCBY] |= OSTCBCur->OSTCBBitX;
555 ; OSTCBPrioTbl[prio] = (OS_TCB *)OSTCBCur;
556 ; }
557 ; OSTCBPrioTbl[pip] = (OS_TCB *)1; /* Reserve table entry
*/
558 ; if (pevent->OSEventGrp != 0x00) { /* Any task waiting for the mutex?
*/
559 ; /* Yes, Make HPT waiting for mutex
ready */
560 ; prio = OS_EventTaskRdy(pevent, (void *)0, OS_STAT_MUTEX);
561 ; pevent->OSEventCnt &= OS_MUTEX_KEEP_UPPER_8; /* Save priority of mutex's ne
w owner */
562 ; pevent->OSEventCnt |= prio;
563 ; pevent->OSEventPtr = OSTCBPrioTbl[prio]; /* Link to mutex owner's OS_TC
B */
564 ; OS_EXIT_CRITICAL();
565 ; OS_Sched(); /* Find highest priority task
ready to run */
566 ; return (OS_NO_ERR);
A51 MACRO ASSEMBLER OS_MUTEX 05/17/2005 11:19:51 PAGE 12
567 ; }
568 ; pevent->OSEventCnt |= OS_MUTEX_AVAILABLE; /* No, Mutex is now available
*/
569 ; pevent->OSEventPtr = (void *)0;
570 ; OS_EXIT_CRITICAL();
571 ; return (OS_NO_ERR);
572 ; }
573 ; /*$PAGE*/
574 ; /*
575 ; *****************************************************************************************
****************
576 ; * QUERY A MUTUAL EXCLUSION SEMAPHORE
577 ; *
578 ; * Description: This function obtains information about a mutex
579 ; *
580 ; * Arguments : pevent is a pointer to the event control block associated with the
desired mutex
581 ; *
582 ; * pdata is a pointer to a structure that will contain information ab
out the mutex
583 ; *
584 ; * Returns : OS_NO_ERR The call was successful and the message was sent
585 ; * OS_ERR_QUERY_ISR If you called this function from an ISR
586 ; * OS_ERR_PEVENT_NULL 'pevent' is a NULL pointer
587 ; * OS_ERR_EVENT_TYPE If you are attempting to obtain data from a non mutex
.
588 ; *****************************************************************************************
****************
589 ; */
590 ;
591 ; #if OS_MUTEX_QUERY_EN > 0
592 ; INT8U OSMutexQuery (OS_EVENT *pevent, OS_MUTEX_DATA *os_pdata)LG_REENTRANT
593 ; {
594 ; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status regis
ter */
595 ; OS_CPU_SR cpu_sr;
596 ; #endif
597 ; INT8U *psrc;
598 ; INT8U *pdest;
599 ;
600 ;
601 ; if (OSIntNesting > 0) { /* See if called from ISR ...
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -