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_trace.h"
29 #include "tx_event_flags.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _tx_event_flags_create PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* William E. Lamie, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function creates a group of 32 event flags. All the flags are */
45 /* initially in a cleared state. */
46 /* */
47 /* INPUT */
48 /* */
49 /* group_ptr Pointer to event flags group */
50 /* control block */
51 /* name_ptr Pointer to event flags name */
52 /* */
53 /* OUTPUT */
54 /* */
55 /* TX_SUCCESS Successful completion status */
56 /* */
57 /* CALLS */
58 /* */
59 /* None */
60 /* */
61 /* CALLED BY */
62 /* */
63 /* Application Code */
64 /* */
65 /* RELEASE HISTORY */
66 /* */
67 /* DATE NAME DESCRIPTION */
68 /* */
69 /* 05-19-2020 William E. Lamie Initial Version 6.0 */
70 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
71 /* resulting in version 6.1 */
72 /* */
73 /**************************************************************************/
_tx_event_flags_create(TX_EVENT_FLAGS_GROUP * group_ptr,CHAR * name_ptr)74 UINT _tx_event_flags_create(TX_EVENT_FLAGS_GROUP *group_ptr, CHAR *name_ptr)
75 {
76
77 TX_INTERRUPT_SAVE_AREA
78
79 TX_EVENT_FLAGS_GROUP *next_group;
80 TX_EVENT_FLAGS_GROUP *previous_group;
81
82
83 /* Initialize event flags control block to all zeros. */
84 TX_MEMSET(group_ptr, 0, (sizeof(TX_EVENT_FLAGS_GROUP)));
85
86 /* Setup the basic event flags group fields. */
87 group_ptr -> tx_event_flags_group_name = name_ptr;
88
89 /* Disable interrupts to put the event flags group on the created list. */
90 TX_DISABLE
91
92 /* Setup the event flags ID to make it valid. */
93 group_ptr -> tx_event_flags_group_id = TX_EVENT_FLAGS_ID;
94
95 /* Place the group on the list of created event flag groups. First,
96 check for an empty list. */
97 if (_tx_event_flags_created_count == TX_EMPTY)
98 {
99
100 /* The created event flags list is empty. Add event flag group to empty list. */
101 _tx_event_flags_created_ptr = group_ptr;
102 group_ptr -> tx_event_flags_group_created_next = group_ptr;
103 group_ptr -> tx_event_flags_group_created_previous = group_ptr;
104 }
105 else
106 {
107
108 /* This list is not NULL, add to the end of the list. */
109 next_group = _tx_event_flags_created_ptr;
110 previous_group = next_group -> tx_event_flags_group_created_previous;
111
112 /* Place the new event flag group in the list. */
113 next_group -> tx_event_flags_group_created_previous = group_ptr;
114 previous_group -> tx_event_flags_group_created_next = group_ptr;
115
116 /* Setup this group's created links. */
117 group_ptr -> tx_event_flags_group_created_previous = previous_group;
118 group_ptr -> tx_event_flags_group_created_next = next_group;
119 }
120
121 /* Increment the number of created event flag groups. */
122 _tx_event_flags_created_count++;
123
124 /* Optional event flag group create extended processing. */
125 TX_EVENT_FLAGS_GROUP_CREATE_EXTENSION(group_ptr)
126
127 /* If trace is enabled, register this object. */
128 TX_TRACE_OBJECT_REGISTER(TX_TRACE_OBJECT_TYPE_EVENT_FLAGS, group_ptr, name_ptr, 0, 0)
129
130 /* If trace is enabled, insert this event into the trace buffer. */
131 TX_TRACE_IN_LINE_INSERT(TX_TRACE_EVENT_FLAGS_CREATE, group_ptr, TX_POINTER_TO_ULONG_CONVERT(&next_group), 0, 0, TX_TRACE_EVENT_FLAGS_EVENTS)
132
133 /* Log this kernel call. */
134 TX_EL_EVENT_FLAGS_CREATE_INSERT
135
136 /* Restore interrupts. */
137 TX_RESTORE
138
139 /* Return TX_SUCCESS. */
140 return(TX_SUCCESS);
141 }
142
143