📄 os_flag.lst
字号:
OS_EXIT_CRITICAL(); /* Yes, condition met, return to caller */
*err = OS_NO_ERR;
return (flags_cur);
} else { /* Block task until events occur or timeout */
OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
OS_EXIT_CRITICAL();
}
break;
case OS_FLAG_WAIT_CLR_ANY:
flags_rdy = ~pgrp->OSFlagFlags & flags; /* Extract only the bits we want */
if (flags_rdy != (OS_FLAGS)0) { /* See if any flag cleared */
if (consume == TRUE) { /* See if we need to consume the flags */
pgrp->OSFlagFlags |= flags_rdy; /* Set ONLY the flags that we got */
}
flags_cur = pgrp->OSFlagFlags; /* Will return the state of the group */
OS_EXIT_CRITICAL(); /* Yes, condition met, return to caller */
*err = OS_NO_ERR;
return (flags_cur);
} else { /* Block task until events occur or timeout */
OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
OS_EXIT_CRITICAL();
}
break;
#endif
477 2
478 2 default:
479 2 OS_EXIT_CRITICAL();
480 2 flags_cur = (OS_FLAGS)0;
481 2 *err = OS_FLAG_ERR_WAIT_TYPE;
482 2 return (flags_cur);
483 2 }
484 1 OS_Sched(); /* Find next HPT ready to run */
485 1 OS_ENTER_CRITICAL();
C51 COMPILER V8.08 OS_FLAG 08/19/2008 10:59:08 PAGE 9
486 1 if (OSTCBCur->OSTCBStat & OS_STAT_FLAG) { /* Have we timed-out? */
487 2 OS_FlagUnlink(&node);
488 2 OSTCBCur->OSTCBStat = OS_STAT_RDY; /* Yes, make task ready-to-run */
489 2 OS_EXIT_CRITICAL();
490 2 flags_cur = (OS_FLAGS)0;
491 2 *err = OS_TIMEOUT; /* Indicate that we timed-out waiting */
492 2 } else {
493 2 if (consume == TRUE) { /* See if we need to consume the flags */
494 3 switch (wait_type) {
495 4 case OS_FLAG_WAIT_SET_ALL:
496 4 case OS_FLAG_WAIT_SET_ANY: /* Clear ONLY the flags we got */
497 4 pgrp->OSFlagFlags &= ~OSTCBCur->OSTCBFlagsRdy;
498 4 break;
499 4
500 4 #if OS_FLAG_WAIT_CLR_EN > 0
case OS_FLAG_WAIT_CLR_ALL:
case OS_FLAG_WAIT_CLR_ANY: /* Set ONLY the flags we got */
pgrp->OSFlagFlags |= OSTCBCur->OSTCBFlagsRdy;
break;
#endif
506 4 }
507 3 }
508 2 flags_cur = pgrp->OSFlagFlags;
509 2 OS_EXIT_CRITICAL();
510 2 *err = OS_NO_ERR; /* Event(s) must have occurred */
511 2 }
512 1 return (flags_cur);
513 1 }
514 /*$PAGE*/
515 /*
516 *********************************************************************************************************
517 * POST EVENT FLAG BIT(S)
518 *
519 * Description: This function is called to set or clear some bits in an event flag group. The bits to
520 * set or clear are specified by a 'bit mask'.
521 *
522 * Arguments : pgrp is a pointer to the desired event flag group.
523 *
524 * flags If 'opt' (see below) is OS_FLAG_SET, each bit that is set in 'flags' will
525 * set the corresponding bit in the event flag group. e.g. to set bits 0, 4
526 * and 5 you would set 'flags' to:
527 *
528 * 0x31 (note, bit 0 is least significant bit)
529 *
530 * If 'opt' (see below) is OS_FLAG_CLR, each bit that is set in 'flags' will
531 * CLEAR the corresponding bit in the event flag group. e.g. to clear bits 0,
532 * 4 and 5 you would specify 'flags' as:
533 *
534 * 0x31 (note, bit 0 is least significant bit)
535 *
536 * opt indicates whether the flags will be:
537 * set (OS_FLAG_SET) or
538 * cleared (OS_FLAG_CLR)
539 *
540 * err is a pointer to an error code and can be:
541 * OS_NO_ERR The call was successfull
542 * OS_FLAG_INVALID_PGRP You passed a NULL pointer
543 * OS_ERR_EVENT_TYPE You are not pointing to an event flag group
544 * OS_FLAG_INVALID_OPT You specified an invalid option
545 *
546 * Returns : the new value of the event flags bits that are still set.
547 *
C51 COMPILER V8.08 OS_FLAG 08/19/2008 10:59:08 PAGE 10
548 * Called From: Task or ISR
549 *
550 * WARNING(s) : 1) The execution time of this function depends on the number of tasks waiting on the event
551 * flag group.
552 * 2) The amount of time interrupts are DISABLED depends on the number of tasks waiting on
553 * the event flag group.
554 *********************************************************************************************************
555 */
556 OS_FLAGS OSFlagPost (OS_FLAG_GRP *pgrp, OS_FLAGS flags, INT8U opt, INT8U *err) reentrant
557 {
558 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
561 1 OS_FLAG_NODE *pnode;
562 1 BOOLEAN sched;
563 1 OS_FLAGS flags_cur;
564 1 OS_FLAGS flags_rdy;
565 1
566 1
567 1 #if OS_ARG_CHK_EN > 0
568 1 if (pgrp == (OS_FLAG_GRP *)0) { /* Validate 'pgrp' */
569 2 *err = OS_FLAG_INVALID_PGRP;
570 2 return ((OS_FLAGS)0);
571 2 }
572 1 if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) { /* Make sure we are pointing to an event flag grp */
573 2 *err = OS_ERR_EVENT_TYPE;
574 2 return ((OS_FLAGS)0);
575 2 }
576 1 #endif
577 1 /*$PAGE*/
578 1 OS_ENTER_CRITICAL();
579 1 switch (opt) {
580 2 case OS_FLAG_CLR:
581 2 pgrp->OSFlagFlags &= ~flags; /* Clear the flags specified in the group */
582 2 break;
583 2
584 2 case OS_FLAG_SET:
585 2 pgrp->OSFlagFlags |= flags; /* Set the flags specified in the group */
586 2 break;
587 2
588 2 default:
589 2 OS_EXIT_CRITICAL(); /* INVALID option */
590 2 *err = OS_FLAG_INVALID_OPT;
591 2 return ((OS_FLAGS)0);
592 2 }
593 1 sched = FALSE; /* Indicate that we don't need rescheduling */
594 1 pnode = pgrp->OSFlagWaitList;
595 1 while (pnode != (OS_FLAG_NODE *)0) { /* Go through all tasks waiting on event flag(s) */
596 2 switch (pnode->OSFlagNodeWaitType) {
597 3 case OS_FLAG_WAIT_SET_ALL: /* See if all req. flags are set for current node */
598 3 flags_rdy = pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
599 3 if (flags_rdy == pnode->OSFlagNodeFlags) {
600 4 if (OS_FlagTaskRdy(pnode, flags_rdy) == TRUE) { /* Make task RTR, event(s) Rx'd */
601 5 sched = TRUE; /* When done we will reschedule */
602 5 }
603 4 }
604 3 break;
605 3
606 3 case OS_FLAG_WAIT_SET_ANY: /* See if any flag set */
607 3 flags_rdy = pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
608 3 if (flags_rdy != (OS_FLAGS)0) {
609 4 if (OS_FlagTaskRdy(pnode, flags_rdy) == TRUE) { /* Make task RTR, event(s) Rx'd */
C51 COMPILER V8.08 OS_FLAG 08/19/2008 10:59:08 PAGE 11
610 5 sched = TRUE; /* When done we will reschedule */
611 5 }
612 4 }
613 3 break;
614 3
615 3 #if OS_FLAG_WAIT_CLR_EN > 0
case OS_FLAG_WAIT_CLR_ALL: /* See if all req. flags are set for current node */
flags_rdy = ~pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
if (flags_rdy == pnode->OSFlagNodeFlags) {
if (OS_FlagTaskRdy(pnode, flags_rdy) == TRUE) { /* Make task RTR, event(s) Rx'd */
sched = TRUE; /* When done we will reschedule */
}
}
break;
case OS_FLAG_WAIT_CLR_ANY: /* See if any flag set */
flags_rdy = ~pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
if (flags_rdy != (OS_FLAGS)0) {
if (OS_FlagTaskRdy(pnode, flags_rdy) == TRUE) { /* Make task RTR, event(s) Rx'd */
sched = TRUE; /* When done we will reschedule */
}
}
break;
#endif
634 3 }
635 2 pnode = pnode->OSFlagNodeNext; /* Point to next task waiting for event flag(s) */
636 2 }
637 1 OS_EXIT_CRITICAL();
638 1 if (sched == TRUE) {
639 2 OS_Sched();
640 2 }
641 1 OS_ENTER_CRITICAL();
642 1 flags_cur = pgrp->OSFlagFlags;
643 1 OS_EXIT_CRITICAL();
644 1 *err = OS_NO_ERR;
645 1 return (flags_cur);
646 1 }
647 /*$PAGE*/
648 /*
649 *********************************************************************************************************
650 * QUERY EVENT FLAG
651 *
652 * Description: This function is used to check the value of the event flag group.
653 *
654 * Arguments : pgrp is a pointer to the desired event flag group.
655 *
656 * err is a pointer to an error code returned to the called:
657 * OS_NO_ERR The call was successfull
658 * OS_FLAG_INVALID_PGRP You passed a NULL pointer
659 * OS_ERR_EVENT_TYPE You are not pointing to an event flag group
660 *
661 * Returns : The current value of the event flag group.
662 *
663 * Called From: Task or ISR
664 *********************************************************************************************************
665 */
666
667 #if OS_FLAG_QUERY_EN > 0
OS_FLAGS OSFlagQuery (OS_FLAG_GRP *pgrp, INT8U *err) reentrant
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
C51 COMPILER V8.08 OS_FLAG 08/19/2008 10:59:08 PAGE 12
#endif
OS_FLAGS flags;
#if OS_ARG_CHK_EN > 0
if (pgrp == (OS_FLAG_GRP *)0) { /* Validate 'pgrp' */
*err = OS_FLAG_INVALID_PGRP;
return ((OS_FLAGS)0);
}
if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) { /* Validate event block type */
*err = OS_ERR_EVENT_TYPE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -