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