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