?? os_flag.lst
字號:
600 3 *err = OS_NO_ERR;
601 3 return (flags_cur);
602 3 } else { /* Block task until events occur or timeout */
603 3 OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
604 3 OS_EXIT_CRITICAL();
605 3 }
606 2 break;
607 2 #endif
608 2
609 2 default:
C51 COMPILER V7.06 OS_FLAG 07/18/2003 11:05:57 PAGE 11
610 2 OS_EXIT_CRITICAL();
611 2 flags_cur = (OS_FLAGS)0;
612 2 *err = OS_FLAG_ERR_WAIT_TYPE;
613 2 return (flags_cur);
614 2 }
615 1 OS_Sched(); /* Find next HPT ready to run */
616 1 OS_ENTER_CRITICAL();
617 1 if (OSTCBCur->OSTCBStat & OS_STAT_FLAG) { /* Have we timed-out? */
618 2 OS_FlagUnlink(&node);
619 2 OSTCBCur->OSTCBStat = OS_STAT_RDY; /* Yes, make task ready-to-run */
620 2 OS_EXIT_CRITICAL();
621 2 flags_cur = (OS_FLAGS)0;
622 2 *err = OS_TIMEOUT; /* Indicate that we timed-out waiting */
623 2 } else {
624 2 if (consume == TRUE) { /* See if we need to consume the flags */
625 3 switch (wait_type) {
626 4 case OS_FLAG_WAIT_SET_ALL:
627 4 case OS_FLAG_WAIT_SET_ANY: /* Clear ONLY the flags we got */
628 4 pgrp->OSFlagFlags &= ~OSTCBCur->OSTCBFlagsRdy;
629 4 break;
630 4
631 4 #if OS_FLAG_WAIT_CLR_EN > 0
632 4 case OS_FLAG_WAIT_CLR_ALL:
633 4 case OS_FLAG_WAIT_CLR_ANY: /* Set ONLY the flags we got */
634 4 pgrp->OSFlagFlags |= OSTCBCur->OSTCBFlagsRdy;
635 4 break;
636 4 #endif
637 4 default:
638 4 OS_EXIT_CRITICAL();
639 4 *err = OS_FLAG_ERR_WAIT_TYPE;
640 4 return ((OS_FLAGS)0);
641 4 }
642 3 }
643 2 flags_cur = pgrp->OSFlagFlags;
644 2 OS_EXIT_CRITICAL();
645 2 *err = OS_NO_ERR; /* Event(s) must have occurred */
646 2 }
647 1 return (flags_cur);
648 1 }
649 /*$PAGE*/
650 /*
651 *********************************************************************************************************
652 * GET FLAGS WHO CAUSED TASK TO BECOME READY
653 *
654 * Description: This function is called to obtain the flags that caused the task to become ready to run.
655 * In other words, this function allows you to tell "Who done it!".
656 *
657 * Arguments : None
658 *
659 * Returns : The flags that caused the task to be ready.
660 *
661 * Called from: Task ONLY
662 *********************************************************************************************************
663 */
664
665 OS_FLAGS OSFlagPendGetFlagsRdy (void) reentrant //using 0
666 {
667 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
668 1 OS_CPU_SR cpu_sr;
669 1 #endif
670 1 OS_FLAGS flags;
671 1
C51 COMPILER V7.06 OS_FLAG 07/18/2003 11:05:57 PAGE 12
672 1
673 1 OS_ENTER_CRITICAL();
674 1 flags = OSTCBCur->OSTCBFlagsRdy;
675 1 //OS_ENTER_CRITICAL();//#Lin@20030714
676 1 OS_EXIT_CRITICAL();
677 1 return (flags);
678 1 }
679
680 /*$PAGE*/
681 /*
682 *********************************************************************************************************
683 * POST EVENT FLAG BIT(S)
684 *
685 * Description: This function is called to set or clear some bits in an event flag group. The bits to
686 * set or clear are specified by a 'bit mask'.
687 *
688 * Arguments : pgrp is a pointer to the desired event flag group.
689 *
690 * flags If 'opt' (see below) is OS_FLAG_SET, each bit that is set in 'flags' will
691 * set the corresponding bit in the event flag group. e.g. to set bits 0, 4
692 * and 5 you would set 'flags' to:
693 *
694 * 0x31 (note, bit 0 is least significant bit)
695 *
696 * If 'opt' (see below) is OS_FLAG_CLR, each bit that is set in 'flags' will
697 * CLEAR the corresponding bit in the event flag group. e.g. to clear bits 0,
698 * 4 and 5 you would specify 'flags' as:
699 *
700 * 0x31 (note, bit 0 is least significant bit)
701 *
702 * opt indicates whether the flags will be:
703 * set (OS_FLAG_SET) or
704 * cleared (OS_FLAG_CLR)
705 *
706 * err is a pointer to an error code and can be:
707 * OS_NO_ERR The call was successfull
708 * OS_FLAG_INVALID_PGRP You passed a NULL pointer
709 * OS_ERR_EVENT_TYPE You are not pointing to an event flag group
710 * OS_FLAG_INVALID_OPT You specified an invalid option
711 *
712 * Returns : the new value of the event flags bits that are still set.
713 *
714 * Called From: Task or ISR
715 *
716 * WARNING(s) : 1) The execution time of this function depends on the number of tasks waiting on the event
717 * flag group.
718 * 2) The amount of time interrupts are DISABLED depends on the number of tasks waiting on
719 * the event flag group.
720 *********************************************************************************************************
721 */
722 OS_FLAGS OSFlagPost (OS_FLAG_GRP *pgrp, OS_FLAGS flags, INT8U opt, INT8U *err) reentrant //using 0
723 {
724 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
725 1 OS_CPU_SR cpu_sr;
726 1 #endif
727 1 OS_FLAG_NODE *pnode;
728 1 BOOLEAN sched;
729 1 OS_FLAGS flags_cur;
730 1 OS_FLAGS flags_rdy;
731 1 BOOLEAN rdy;
732 1
733 1
C51 COMPILER V7.06 OS_FLAG 07/18/2003 11:05:57 PAGE 13
734 1 #if OS_ARG_CHK_EN > 0
735 1 if (pgrp == (OS_FLAG_GRP *)0) { /* Validate 'pgrp' */
736 2 *err = OS_FLAG_INVALID_PGRP;
737 2 return ((OS_FLAGS)0);
738 2 }
739 1 #endif
740 1 if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) { /* Make sure we are pointing to an event flag grp */
741 2 *err = OS_ERR_EVENT_TYPE;
742 2 return ((OS_FLAGS)0);
743 2 }
744 1 /*$PAGE*/
745 1 OS_ENTER_CRITICAL();
746 1 switch (opt) {
747 2 case OS_FLAG_CLR:
748 2 pgrp->OSFlagFlags &= ~flags; /* Clear the flags specified in the group */
749 2 break;
750 2
751 2 case OS_FLAG_SET:
752 2 pgrp->OSFlagFlags |= flags; /* Set the flags specified in the group */
753 2 break;
754 2
755 2 default:
756 2 OS_EXIT_CRITICAL(); /* INVALID option */
757 2 *err = OS_FLAG_INVALID_OPT;
758 2 return ((OS_FLAGS)0);
759 2 }
760 1 sched = FALSE; /* Indicate that we don't need rescheduling */
761 1 pnode = (OS_FLAG_NODE *)pgrp->OSFlagWaitList;
762 1 while (pnode != (OS_FLAG_NODE *)0) { /* Go through all tasks waiting on event flag(s) */
763 2 switch (pnode->OSFlagNodeWaitType) {
764 3 case OS_FLAG_WAIT_SET_ALL: /* See if all req. flags are set for current node */
765 3 flags_rdy = pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
766 3 if (flags_rdy == pnode->OSFlagNodeFlags) {
767 4 rdy = OS_FlagTaskRdy(pnode, flags_rdy); /* Make task RTR, event(s) Rx'd */
768 4 if (rdy == TRUE) {
769 5 sched = TRUE; /* When done we will reschedule */
770 5 }
771 4 }
772 3 break;
773 3
774 3 case OS_FLAG_WAIT_SET_ANY: /* See if any flag set */
775 3 flags_rdy = pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
776 3 if (flags_rdy != (OS_FLAGS)0) {
777 4 rdy = OS_FlagTaskRdy(pnode, flags_rdy); /* Make task RTR, event(s) Rx'd */
778 4 if (rdy == TRUE) {
779 5 sched = TRUE; /* When done we will reschedule */
780 5 }
781 4 }
782 3 break;
783 3
784 3 #if OS_FLAG_WAIT_CLR_EN > 0
785 3 case OS_FLAG_WAIT_CLR_ALL: /* See if all req. flags are set for current node */
786 3 flags_rdy = ~pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
787 3 if (flags_rdy == pnode->OSFlagNodeFlags) {
788 4 rdy = OS_FlagTaskRdy(pnode, flags_rdy); /* Make task RTR, event(s) Rx'd */
789 4 if (rdy == TRUE) {
790 5 sched = TRUE; /* When done we will reschedule */
791 5 }
792 4 }
793 3 break;
794 3
795 3 case OS_FLAG_WAIT_CLR_ANY: /* See if any flag set */
C51 COMPILER V7.06 OS_FLAG 07/18/2003 11:05:57 PAGE 14
796 3 flags_rdy = ~pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
797 3 if (flags_rdy != (OS_FLAGS)0) {
798 4 rdy = OS_FlagTaskRdy(pnode, flags_rdy); /* Make task RTR, event(s) Rx'd */
799 4 if (rdy == TRUE) {
800 5 sched = TRUE; /* When done we will reschedule */
801 5 }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -