1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** ThreadX Component                                                     */
17 /**                                                                       */
18 /**   Event Flags                                                         */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 #define TX_SOURCE_CODE
24 
25 
26 /* Include necessary system files.  */
27 
28 #include "tx_api.h"
29 #include "tx_event_flags.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _txe_event_flags_set                                PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    William E. Lamie, Microsoft Corporation                             */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function checks for errors in the set event flags function     */
45 /*    call.                                                               */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    group_ptr                         Pointer to group control block    */
50 /*    flags_to_set                      Event flags to set                */
51 /*    set_option                        Specified either AND or OR        */
52 /*                                        operation on the event flags    */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    TX_GROUP_ERROR                    Invalid event flags group pointer */
57 /*    TX_OPTION_ERROR                   Invalid set option                */
58 /*    status                            Actual completion status          */
59 /*                                                                        */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*    _tx_event_flags_set               Actual set event flags function   */
63 /*                                                                        */
64 /*  CALLED BY                                                             */
65 /*                                                                        */
66 /*    Application Code                                                    */
67 /*                                                                        */
68 /*  RELEASE HISTORY                                                       */
69 /*                                                                        */
70 /*    DATE              NAME                      DESCRIPTION             */
71 /*                                                                        */
72 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
73 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
74 /*                                            resulting in version 6.1    */
75 /*                                                                        */
76 /**************************************************************************/
_txe_event_flags_set(TX_EVENT_FLAGS_GROUP * group_ptr,ULONG flags_to_set,UINT set_option)77 UINT  _txe_event_flags_set(TX_EVENT_FLAGS_GROUP *group_ptr, ULONG flags_to_set, UINT set_option)
78 {
79 
80 UINT        status;
81 
82 
83     /* Default status to success.  */
84     status =  TX_SUCCESS;
85 
86     /* Check for an invalid event flag group pointer.  */
87     if (group_ptr == TX_NULL)
88     {
89 
90         /* Event flags group pointer is invalid, return appropriate error code.  */
91         status =  TX_GROUP_ERROR;
92     }
93 
94     /* Now check for invalid event flag group ID.  */
95     else if (group_ptr -> tx_event_flags_group_id != TX_EVENT_FLAGS_ID)
96     {
97 
98         /* Event flags group pointer is invalid, return appropriate error code.  */
99         status =  TX_GROUP_ERROR;
100     }
101     else
102     {
103 
104         /* Check for invalid set option.  */
105         if (set_option != TX_AND)
106         {
107 
108             if (set_option != TX_OR)
109             {
110 
111                 /* Invalid set events option, return appropriate error.  */
112                 status =  TX_OPTION_ERROR;
113             }
114         }
115     }
116 
117     /* Determine if everything is okay.  */
118     if (status == TX_SUCCESS)
119     {
120 
121         /* Call actual event flags set function.  */
122         status =  _tx_event_flags_set(group_ptr, flags_to_set, set_option);
123     }
124 
125     /* Return completion status.  */
126     return(status);
127 }
128 
129