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 /** GUIX Component */
17 /** */
18 /** System Management (System) */
19 /** */
20 /**************************************************************************/
21
22 #define GX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "gx_api.h"
28 #include "gx_system.h"
29
30 #if !defined(GX_THREAD_SLEEPING)
31 #define GX_THREAD_SLEEPING
32 #endif
33
34 #if !defined(GX_THREAD_AWAKE)
35 #define GX_THREAD_AWAKE
36 #endif
37
38 /**************************************************************************/
39 /* */
40 /* FUNCTION RELEASE */
41 /* */
42 /* _gx_system_thread_entry PORTABLE C */
43 /* 6.1 */
44 /* AUTHOR */
45 /* */
46 /* Kenneth Maxwell, Microsoft Corporation */
47 /* */
48 /* DESCRIPTION */
49 /* */
50 /* This is the main processing thread for GUIX. All events and drawing */
51 /* are done from the context of this thread. */
52 /* */
53 /* INPUT */
54 /* */
55 /* id Thread ID */
56 /* */
57 /* OUTPUT */
58 /* */
59 /* None */
60 /* */
61 /* CALLS */
62 /* */
63 /* tx_mutex_get Get protection mutex */
64 /* tx_mutex_put Release protection mutex */
65 /* tx_queue_receive Receive GUIX events from queue*/
66 /* _gx_system_dirty_mark Mark a widget as dirty */
67 /* _gx_system_error_process Process system errors */
68 /* _gx_system_event_dispatch Dispatch GUIX events */
69 /* _gx_system_canvas_refresh Refresh the canvas */
70 /* _gx_system_timer_update Update active system timers */
71 /* */
72 /* CALLED BY */
73 /* */
74 /* ThreadX */
75 /* */
76 /* RELEASE HISTORY */
77 /* */
78 /* DATE NAME DESCRIPTION */
79 /* */
80 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
81 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */
82 /* resulting in version 6.1 */
83 /* */
84 /**************************************************************************/
_gx_system_thread_entry(ULONG id)85 VOID _gx_system_thread_entry(ULONG id)
86 {
87
88 UINT status = GX_FAILURE;
89
90 #ifdef GX_THREADX_BINDING
91 ULONG event_memory[GX_EVENT_ULONGS];
92 #else
93 GX_EVENT event_memory;
94 #endif
95
96 GX_EVENT *event_ptr;
97 GX_WIDGET *widget;
98
99 GX_PARAMETER_NOT_USED(id);
100
101 /* Loop to process GUIX events. */
102 while (1)
103 {
104 #ifdef GX_THREADX_BINDING
105 /* Pickup event from event queue. */
106 status = tx_queue_receive(&_gx_system_event_queue, &event_memory[0], TX_NO_WAIT);
107
108 /* Was there an event? */
109 if (status == TX_QUEUE_EMPTY)
110 {
111 /* No event to process, so re-draw dirty widgets */
112 _gx_system_canvas_refresh();
113
114 /* Now block this thread until an event is received. */
115 GX_THREAD_SLEEPING
116 status = tx_queue_receive(&_gx_system_event_queue, &event_memory[0], TX_WAIT_FOREVER);
117 if (status == TX_SUCCESS)
118 {
119 status = GX_SUCCESS;
120 }
121 }
122 #else
123 /* here for generic RTOS binding */
124 status = GX_EVENT_POP(&event_memory, GX_FALSE);
125 if (status == GX_FAILURE)
126 {
127 _gx_system_canvas_refresh();
128 GX_THREAD_SLEEPING
129 status = GX_EVENT_POP(&event_memory, GX_TRUE);
130 }
131 #endif
132
133 /* Check for a successful status. */
134 if (status == GX_SUCCESS)
135 {
136 GX_THREAD_AWAKE
137 /* Setup a pointer to the event. */
138 event_ptr = (GX_EVENT *)(&event_memory);
139
140 switch (event_ptr -> gx_event_type)
141 {
142 /* Determine if a redraw event is present. */
143 case GX_EVENT_REDRAW:
144 /* Yes, a redraw event is present, detect and process the dirty area(s). */
145 widget = (GX_WIDGET *)_gx_system_root_window_created_list;
146 while (widget)
147 {
148 _gx_system_dirty_mark(widget);
149 widget = widget -> gx_widget_next;
150 }
151 break;
152
153 case GX_EVENT_TERMINATE:
154 return;
155
156 case GX_EVENT_TIMER:
157 if (event_ptr ->gx_event_target == GX_NULL)
158 {
159 /* the event is from gx_system_timer_expiration */
160 _gx_system_timer_update(event_ptr -> gx_event_payload.gx_event_ulongdata);
161 }
162 else
163 {
164 _gx_system_event_dispatch(event_ptr);
165 }
166 break;
167
168 case 0:
169 /* the event has been purged */
170 break;
171
172 default:
173 /* Dispatch the event to GUIX proper window/widget. */
174 _gx_system_event_dispatch(event_ptr);
175 break;
176 }
177 }
178 else
179 {
180 /* Error receiving event - call system error handler. */
181 _gx_system_error_process(GX_SYSTEM_EVENT_RECEIVE_ERROR);
182
183 /* Return to exit the system thread. */
184 return;
185 }
186 }
187 }
188
189