📄 os_flag.lst
字号:
737 *
738 * 0x31 (note, bit 0 is least significant bit)
739 *
740 * If 'opt' (see below) is OS_FLAG_CLR, each bit that is set in 'flags' will
C51 COMPILER V8.08 OS_FLAG 08/04/2008 21:49:51 PAGE 14
741 * CLEAR the corresponding bit in the event flag group. e.g. to clear bits 0,
742 * 4 and 5 you would specify 'flags' as:
743 *
744 * 0x31 (note, bit 0 is least significant bit)
745 *
746 * opt indicates whether the flags will be:
747 * set (OS_FLAG_SET) or
748 * cleared (OS_FLAG_CLR)
749 *
750 * err is a pointer to an error code and can be:
751 * OS_NO_ERR The call was successfull
752 * OS_FLAG_INVALID_PGRP You passed a NULL pointer
753 * OS_ERR_EVENT_TYPE You are not pointing to an event flag group
754 * OS_FLAG_INVALID_OPT You specified an invalid option
755 *
756 * Returns : the new value of the event flags bits that are still set.
757 *
758 * Called From: Task or ISR
759 *
760 * WARNING(s) : 1) The execution time of this function depends on the number of tasks waiting on the event
761 * flag group.
762 * 2) The amount of time interrupts are DISABLED depends on the number of tasks waiting on
763 * the event flag group.
764 *********************************************************************************************************
765 */
766 OS_FLAGS OSFlagPost (OS_FLAG_GRP *pgrp, OS_FLAGS flags, INT8U opt, INT8U *err)
767 {
768 OS_FLAG_NODE *pnode;
769 BOOLEAN sched;
770 OS_FLAGS flags_cur;
771 OS_FLAGS flags_rdy;
772 BOOLEAN rdy;
773 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
776
777
778
779 #if OS_ARG_CHK_EN > 0
780 if (err == (INT8U *)0) { /* Validate 'err' */
781 return ((OS_FLAGS)0);
782 }
783 if (pgrp == (OS_FLAG_GRP *)0) { /* Validate 'pgrp' */
784 *err = OS_FLAG_INVALID_PGRP;
785 return ((OS_FLAGS)0);
786 }
787 #endif
788 if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) { /* Make sure we are pointing to an event flag grp */
789 *err = OS_ERR_EVENT_TYPE;
790 return ((OS_FLAGS)0);
791 }
792 /*$PAGE*/
793 OS_ENTER_CRITICAL();
794 switch (opt) {
795 case OS_FLAG_CLR:
796 pgrp->OSFlagFlags &= ~flags; /* Clear the flags specified in the group */
797 break;
798
799 case OS_FLAG_SET:
800 pgrp->OSFlagFlags |= flags; /* Set the flags specified in the group */
801 break;
802
C51 COMPILER V8.08 OS_FLAG 08/04/2008 21:49:51 PAGE 15
803 default:
804 OS_EXIT_CRITICAL(); /* INVALID option */
805 *err = OS_FLAG_INVALID_OPT;
806 return ((OS_FLAGS)0);
807 }
808 sched = FALSE; /* Indicate that we don't need rescheduling */
809 pnode = (OS_FLAG_NODE *)pgrp->OSFlagWaitList;
810 while (pnode != (OS_FLAG_NODE *)0) { /* Go through all tasks waiting on event flag(s) */
811 switch (pnode->OSFlagNodeWaitType) {
812 case OS_FLAG_WAIT_SET_ALL: /* See if all req. flags are set for current node */
813 flags_rdy = pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
814 if (flags_rdy == pnode->OSFlagNodeFlags) {
815 rdy = OS_FlagTaskRdy(pnode, flags_rdy); /* Make task RTR, event(s) Rx'd */
816 if (rdy == TRUE) {
817 sched = TRUE; /* When done we will reschedule */
818 }
819 }
820 break;
821
822 case OS_FLAG_WAIT_SET_ANY: /* See if any flag set */
823 flags_rdy = pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
824 if (flags_rdy != (OS_FLAGS)0) {
825 rdy = OS_FlagTaskRdy(pnode, flags_rdy); /* Make task RTR, event(s) Rx'd */
826 if (rdy == TRUE) {
827 sched = TRUE; /* When done we will reschedule */
828 }
829 }
830 break;
831
832 #if OS_FLAG_WAIT_CLR_EN > 0
833 case OS_FLAG_WAIT_CLR_ALL: /* See if all req. flags are set for current node */
834 flags_rdy = (OS_FLAGS)~pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
835 if (flags_rdy == pnode->OSFlagNodeFlags) {
836 rdy = OS_FlagTaskRdy(pnode, flags_rdy); /* Make task RTR, event(s) Rx'd */
837 if (rdy == TRUE) {
838 sched = TRUE; /* When done we will reschedule */
839 }
840 }
841 break;
842
843 case OS_FLAG_WAIT_CLR_ANY: /* See if any flag set */
844 flags_rdy = (OS_FLAGS)~pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
845 if (flags_rdy != (OS_FLAGS)0) {
846 rdy = OS_FlagTaskRdy(pnode, flags_rdy); /* Make task RTR, event(s) Rx'd */
847 if (rdy == TRUE) {
848 sched = TRUE; /* When done we will reschedule */
849 }
850 }
851 break;
852 #endif
853 default:
854 OS_EXIT_CRITICAL();
855 *err = OS_FLAG_ERR_WAIT_TYPE;
856 return ((OS_FLAGS)0);
857 }
858 pnode = (OS_FLAG_NODE *)pnode->OSFlagNodeNext; /* Point to next task waiting for event flag(s) */
859 }
860 OS_EXIT_CRITICAL();
861 if (sched == TRUE) {
862 OS_Sched();
863 }
864 OS_ENTER_CRITICAL();
C51 COMPILER V8.08 OS_FLAG 08/04/2008 21:49:51 PAGE 16
865 flags_cur = pgrp->OSFlagFlags;
866 OS_EXIT_CRITICAL();
867 *err = OS_NO_ERR;
868 return (flags_cur);
869 }
870 /*$PAGE*/
871 /*
872 *********************************************************************************************************
873 * QUERY EVENT FLAG
874 *
875 * Description: This function is used to check the value of the event flag group.
876 *
877 * Arguments : pgrp is a pointer to the desired event flag group.
878 *
879 * err is a pointer to an error code returned to the called:
880 * OS_NO_ERR The call was successfull
881 * OS_FLAG_INVALID_PGRP You passed a NULL pointer
882 * OS_ERR_EVENT_TYPE You are not pointing to an event flag group
883 *
884 * Returns : The current value of the event flag group.
885 *
886 * Called From: Task or ISR
887 *********************************************************************************************************
888 */
889
890 #if OS_FLAG_QUERY_EN > 0
891 OS_FLAGS OSFlagQuery (OS_FLAG_GRP *pgrp, INT8U *err)
892 {
893 OS_FLAGS flags;
894 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
897
898
899
900 #if OS_ARG_CHK_EN > 0
901 if (err == (INT8U *)0) { /* Validate 'err' */
902 return ((OS_FLAGS)0);
903 }
904 if (pgrp == (OS_FLAG_GRP *)0) { /* Validate 'pgrp' */
905 *err = OS_FLAG_INVALID_PGRP;
906 return ((OS_FLAGS)0);
907 }
908 #endif
909 if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) { /* Validate event block type */
910 *err = OS_ERR_EVENT_TYPE;
911 return ((OS_FLAGS)0);
912 }
913 OS_ENTER_CRITICAL();
914 flags = pgrp->OSFlagFlags;
915 OS_EXIT_CRITICAL();
916 *err = OS_NO_ERR;
917 return (flags); /* Return the current value of the event flags */
918 }
919 #endif
920
921 /*$PAGE*/
922 /*
923 *********************************************************************************************************
924 * SUSPEND TASK UNTIL EVENT FLAG(s) RECEIVED OR TIMEOUT OCCURS
925 *
926 * Description: This function is internal to uC/OS-II and is used to put a task to sleep until the desired
C51 COMPILER V8.08 OS_FLAG 08/04/2008 21:49:51 PAGE 17
927 * event flag bit(s) are set.
928 *
929 * Arguments : pgrp is a pointer to the desired event flag group.
930 *
931 * pnode is a pointer to a structure which contains data about the task waiting for
932 * event flag bit(s) to be set.
933 *
934 * flags Is a bit pattern indicating which bit(s) (i.e. flags) you wish to check.
935 * The
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -