📄 os_mutex.lst
字号:
370 1 OS_ENTER_CRITICAL();
371 1 if (OSTCBCur->OSTCBStat & OS_STAT_MUTEX) { /* Must have timed out if still waiting for event*/
372 2 OS_EventTO(pevent);
373 2 OS_EXIT_CRITICAL();
374 2 *err = OS_TIMEOUT; /* Indicate that we didn't get mutex within TO */
375 2 return;
376 2 }
377 1 OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;
378 1 OS_EXIT_CRITICAL();
379 1 *err = OS_NO_ERR;
380 1 }
381 /*$PAGE*/
382 /*
383 *********************************************************************************************************
384 * POST TO A MUTUAL EXCLUSION SEMAPHORE
385 *
386 * Description: This function signals a mutual exclusion semaphore
387 *
388 * Arguments : pevent is a pointer to the event control block associated with the desired
389 * mutex.
390 *
391 * Returns : OS_NO_ERR The call was successful and the mutex was signaled.
392 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a mutex
393 * OS_ERR_PEVENT_NULL 'pevent' is a NULL pointer
394 * OS_ERR_POST_ISR Attempted to post from an ISR (not valid for MUTEXes)
395 * OS_ERR_NOT_MUTEX_OWNER The task that did the post is NOT the owner of the MUTEX.
396 *********************************************************************************************************
397 */
398
399 INT8U OSMutexPost (OS_EVENT *pevent) KCREENTRANT
400 {
401 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
404 1 INT8U pip; /* Priority inheritance priority */
405 1 INT8U prio;
406 1
407 1
408 1 if (OSIntNesting > 0) { /* See if called from ISR ... */
409 2 return (OS_ERR_POST_ISR); /* ... can't POST mutex from an ISR */
410 2 }
411 1 #if OS_ARG_CHK_EN > 0
412 1 if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
413 2 return (OS_ERR_PEVENT_NULL);
414 2 }
415 1 if (pevent->OSEventType != OS_EVENT_TYPE_MUTEX) { /* Validate event block type */
416 2 return (OS_ERR_EVENT_TYPE);
417 2 }
418 1 #endif
419 1 OS_ENTER_CRITICAL();
420 1 pip = (INT8U)(pevent->OSEventCnt >> 8); /* Get priority inheritance priority of mutex */
421 1 prio = (INT8U)(pevent->OSEventCnt & OS_MUTEX_KEEP_LOWER_8); /* Get owner's original priority */
422 1 if (OSTCBCur->OSTCBPrio != pip &&
423 1 OSTCBCur->OSTCBPrio != prio) { /* See if posting task owns the MUTEX */
424 2 OS_EXIT_CRITICAL();
425 2 return (OS_ERR_NOT_MUTEX_OWNER);
426 2 }
427 1 if (OSTCBCur->OSTCBPrio == pip) { /* Did we have to raise current task's priority? */
C51 COMPILER V6.23a OS_MUTEX 12/09/2004 16:50:26 PAGE 8
428 2 /* Yes, Return to original priority */
429 2 /* Remove owner from ready list at 'pip' */
430 2 if ((OSRdyTbl[OSTCBCur->OSTCBY] &= ~OSTCBCur->OSTCBBitX) == 0) {
431 3 OSRdyGrp &= ~OSTCBCur->OSTCBBitY;
432 3 }
433 2 OSTCBCur->OSTCBPrio = prio;
434 2 OSTCBCur->OSTCBY = prio >> 3;
435 2 OSTCBCur->OSTCBBitY = OSMapTbl[OSTCBCur->OSTCBY];
436 2 OSTCBCur->OSTCBX = prio & 0x07;
437 2 OSTCBCur->OSTCBBitX = OSMapTbl[OSTCBCur->OSTCBX];
438 2 OSRdyGrp |= OSTCBCur->OSTCBBitY;
439 2 OSRdyTbl[OSTCBCur->OSTCBY] |= OSTCBCur->OSTCBBitX;
440 2 OSTCBPrioTbl[prio] = (OS_TCB *)OSTCBCur;
441 2 }
442 1 OSTCBPrioTbl[pip] = (OS_TCB *)1; /* Reserve table entry */
443 1 if (pevent->OSEventGrp != 0x00) { /* Any task waiting for the mutex? */
444 2 /* Yes, Make HPT waiting for mutex ready */
445 2 prio = OS_EventTaskRdy(pevent, (void *)0, OS_STAT_MUTEX);
446 2 pevent->OSEventCnt &= OS_MUTEX_KEEP_UPPER_8; /* Save priority of mutex's new owner */
447 2 pevent->OSEventCnt |= prio;
448 2 pevent->OSEventPtr = OSTCBPrioTbl[prio]; /* Link to mutex owner's OS_TCB */
449 2 OS_EXIT_CRITICAL();
450 2 OS_Sched(); /* Find highest priority task ready to run */
451 2 return (OS_NO_ERR);
452 2 }
453 1 pevent->OSEventCnt |= OS_MUTEX_AVAILABLE; /* No, Mutex is now available */
454 1 pevent->OSEventPtr = (void *)0;
455 1 OS_EXIT_CRITICAL();
456 1 return (OS_NO_ERR);
457 1 }
458 /*$PAGE*/
459 /*
460 *********************************************************************************************************
461 * QUERY A MUTUAL EXCLUSION SEMAPHORE
462 *
463 * Description: This function obtains information about a mutex
464 *
465 * Arguments : pevent is a pointer to the event control block associated with the desired mutex
466 *
467 * pdata is a pointer to a structure that will contain information about the mutex
468 *
469 * Returns : OS_NO_ERR The call was successful and the message was sent
470 * OS_ERR_QUERY_ISR If you called this function from an ISR
471 * OS_ERR_PEVENT_NULL 'pevent' is a NULL pointer
472 * OS_ERR_EVENT_TYPE If you are attempting to obtain data from a non mutex.
473 *********************************************************************************************************
474 */
475
476 #if OS_MUTEX_QUERY_EN > 0
477 INT8U OSMutexQuery (OS_EVENT *pevent, OS_MUTEX_DATA *pdata) KCREENTRANT
478 {
479 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
482 1 INT8U *psrc;
483 1 INT8U *pdest;
484 1
485 1
486 1 if (OSIntNesting > 0) { /* See if called from ISR ... */
487 2 return (OS_ERR_QUERY_ISR); /* ... can't QUERY mutex from an ISR */
488 2 }
489 1 #if OS_ARG_CHK_EN > 0
C51 COMPILER V6.23a OS_MUTEX 12/09/2004 16:50:26 PAGE 9
490 1 if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
491 2 return (OS_ERR_PEVENT_NULL);
492 2 }
493 1 if (pevent->OSEventType != OS_EVENT_TYPE_MUTEX) { /* Validate event block type */
494 2 return (OS_ERR_EVENT_TYPE);
495 2 }
496 1 #endif
497 1 OS_ENTER_CRITICAL();
498 1 pdata->OSMutexPIP = (INT8U)(pevent->OSEventCnt >> 8);
499 1 pdata->OSOwnerPrio = (INT8U)(pevent->OSEventCnt & OS_MUTEX_KEEP_LOWER_8);
500 1 if (pdata->OSOwnerPrio == 0xFF) {
501 2 pdata->OSValue = 1;
502 2 } else {
503 2 pdata->OSValue = 0;
504 2 }
505 1 pdata->OSEventGrp = pevent->OSEventGrp; /* Copy wait list */
506 1 psrc = &pevent->OSEventTbl[0];
507 1 pdest = &pdata->OSEventTbl[0];
508 1 #if OS_EVENT_TBL_SIZE > 0
509 1 *pdest++ = *psrc++;
510 1 #endif
511 1
512 1 #if OS_EVENT_TBL_SIZE > 1
513 1 *pdest++ = *psrc++;
514 1 #endif
515 1
516 1 #if OS_EVENT_TBL_SIZE > 2
*pdest++ = *psrc++;
#endif
519 1
520 1 #if OS_EVENT_TBL_SIZE > 3
*pdest++ = *psrc++;
#endif
523 1
524 1 #if OS_EVENT_TBL_SIZE > 4
*pdest++ = *psrc++;
#endif
527 1
528 1 #if OS_EVENT_TBL_SIZE > 5
*pdest++ = *psrc++;
#endif
531 1
532 1 #if OS_EVENT_TBL_SIZE > 6
*pdest++ = *psrc++;
#endif
535 1
536 1 #if OS_EVENT_TBL_SIZE > 7
*pdest = *psrc;
#endif
539 1 OS_EXIT_CRITICAL();
540 1 return (OS_NO_ERR);
541 1 }
542 #endif /* OS_MUTEX_QUERY_EN */
543 #endif /* OS_MUTEX_EN */
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 3527 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
C51 COMPILER V6.23a OS_MUTEX 12/09/2004 16:50:26 PAGE 10
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -