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 /** Module */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 #ifndef TXM_MODULE 24 #define TXM_MODULE 25 #endif 26 27 #ifndef TX_SOURCE_CODE 28 #define TX_SOURCE_CODE 29 #endif 30 31 32 /* Include necessary system files. */ 33 34 #include "txm_module.h" 35 #include "tx_queue.h" 36 37 38 /* Define the global module entry pointer from the start thread of the module. 39 This structure contains the pointer to the request queue as well as the 40 pointer to the callback response queue. */ 41 42 extern TXM_MODULE_THREAD_ENTRY_INFO *_txm_module_entry_info; 43 44 /**************************************************************************/ 45 /* */ 46 /* FUNCTION RELEASE */ 47 /* */ 48 /* _txm_module_callback_request_thread_entry PORTABLE C */ 49 /* 6.1.10 */ 50 /* AUTHOR */ 51 /* */ 52 /* Scott Larson, Microsoft Corporation */ 53 /* */ 54 /* DESCRIPTION */ 55 /* */ 56 /* This function processes all module callback requests, transferred */ 57 /* by the resident code via the callback queue. When the callback is */ 58 /* complete, the response is sent back to the resident code to */ 59 /* acknowledge it. */ 60 /* */ 61 /* INPUT */ 62 /* */ 63 /* id Module thread ID */ 64 /* */ 65 /* OUTPUT */ 66 /* */ 67 /* None */ 68 /* */ 69 /* CALLS */ 70 /* */ 71 /* tx_queue_receive Receive callback request */ 72 /* */ 73 /* CALLED BY */ 74 /* */ 75 /* Initial thread stack frame */ 76 /* */ 77 /* RELEASE HISTORY */ 78 /* */ 79 /* DATE NAME DESCRIPTION */ 80 /* */ 81 /* 09-30-2020 Scott Larson Initial Version 6.1 */ 82 /* 01-31-2022 Scott Larson Modified comments and added */ 83 /* CALL_NOT_USED option, */ 84 /* resulting in version 6.1.10 */ 85 /* */ 86 /**************************************************************************/ _txm_module_callback_request_thread_entry(ULONG id)87VOID _txm_module_callback_request_thread_entry(ULONG id) 88 { 89 90 TX_QUEUE *request_queue; 91 TXM_MODULE_CALLBACK_MESSAGE callback_message; 92 ULONG activation_count; 93 VOID (*timer_callback)(ULONG); 94 VOID (*events_set_notify)(TX_EVENT_FLAGS_GROUP *); 95 VOID (*semaphore_put_notify)(TX_SEMAPHORE *); 96 VOID (*queue_send_notify)(TX_QUEUE *); 97 VOID (*thread_entry_exit_notify)(TX_THREAD *, UINT); 98 UINT status; 99 100 /* Disable warning of parameter not used. */ 101 TX_PARAMETER_NOT_USED(id); 102 103 /* Pickup pointer to the request queue. */ 104 request_queue = _txm_module_entry_info -> txm_module_thread_entry_info_callback_request_queue; 105 106 /* Loop to process callback messages from the module manager. */ 107 while(1) 108 { 109 110 /* Wait for the callback request for the module. */ 111 status = _txe_queue_receive(request_queue, (VOID *) &callback_message, TX_WAIT_FOREVER); 112 113 /* Check to see if a request was received. */ 114 if (status != TX_SUCCESS) 115 { 116 117 /* This should not happen - get out of the loop. */ 118 break; 119 } 120 121 /* Pickup the activation count in the message. */ 122 activation_count = callback_message.txm_module_callback_message_activation_count; 123 124 /* Loop to call the callback function the correct number of times. */ 125 while (activation_count) 126 { 127 128 /* Decrement the activation count. */ 129 activation_count--; 130 131 /* Now dispatch the callback function. */ 132 switch (callback_message.txm_module_callback_message_type) 133 { 134 135 case TXM_TIMER_CALLBACK: 136 137 /* Setup timer callback pointer. */ 138 timer_callback = (void (*)(ULONG)) callback_message.txm_module_callback_message_application_function; 139 140 /* Call application's timer callback. */ 141 (timer_callback)((ULONG) callback_message.txm_module_callback_message_param_1); 142 143 break; 144 145 case TXM_EVENTS_SET_CALLBACK: 146 147 /* Setup events set callback pointer. */ 148 events_set_notify = (void (*)(TX_EVENT_FLAGS_GROUP *)) callback_message.txm_module_callback_message_application_function; 149 150 /* Call events set notify callback. */ 151 (events_set_notify)((TX_EVENT_FLAGS_GROUP *) callback_message.txm_module_callback_message_param_1); 152 153 break; 154 155 case TXM_QUEUE_SEND_CALLBACK: 156 157 /* Setup queue send callback pointer. */ 158 queue_send_notify = (void (*)(TX_QUEUE *)) callback_message.txm_module_callback_message_application_function; 159 160 /* Call queue send notify callback. */ 161 (queue_send_notify)((TX_QUEUE *) callback_message.txm_module_callback_message_param_1); 162 163 break; 164 165 case TXM_SEMAPHORE_PUT_CALLBACK: 166 167 /* Setup semaphore put callback pointer. */ 168 semaphore_put_notify = (void (*)(TX_SEMAPHORE *)) callback_message.txm_module_callback_message_application_function; 169 170 /* Call semaphore put notify callback. */ 171 (semaphore_put_notify)((TX_SEMAPHORE *) callback_message.txm_module_callback_message_param_1); 172 173 break; 174 175 case TXM_THREAD_ENTRY_EXIT_CALLBACK: 176 177 /* Setup thread entry/exit callback pointer. */ 178 thread_entry_exit_notify = (void (*)(TX_THREAD *, UINT)) callback_message.txm_module_callback_message_application_function; 179 180 /* Call thread entry/exit notify callback. */ 181 (thread_entry_exit_notify)((TX_THREAD *) callback_message.txm_module_callback_message_param_1, (UINT) callback_message.txm_module_callback_message_param_2); 182 183 break; 184 185 default: 186 187 #ifdef TXM_MODULE_ENABLE_NETX 188 189 /* Determine if there is a NetX callback. */ 190 if ((callback_message.txm_module_callback_message_type >= TXM_NETX_CALLBACKS_START) && (callback_message.txm_module_callback_message_type < TXM_NETX_CALLBACKS_END)) 191 { 192 193 /* Call the NetX module callback function. */ 194 _txm_module_netx_callback_request(&callback_message); 195 } 196 #endif 197 198 #ifdef TXM_MODULE_ENABLE_NETXDUO 199 200 /* Determine if there is a NetX Duo callback. */ 201 if ((callback_message.txm_module_callback_message_type >= TXM_NETXDUO_CALLBACKS_START) && (callback_message.txm_module_callback_message_type < TXM_NETXDUO_CALLBACKS_END)) 202 { 203 204 /* Call the NetX Duo module callback function. */ 205 _txm_module_netxduo_callback_request(&callback_message); 206 } 207 #endif 208 209 #ifdef TXM_MODULE_ENABLE_FILEX 210 211 /* Determine if there is a FileX callback. */ 212 if ((callback_message.txm_module_callback_message_type >= TXM_FILEX_CALLBACKS_START) && (callback_message.txm_module_callback_message_type < TXM_FILEX_CALLBACKS_END)) 213 { 214 215 /* Call the FileX module callback function. */ 216 _txm_module_filex_callback_request(&callback_message); 217 } 218 #endif 219 220 #ifdef TXM_MODULE_ENABLE_GUIX 221 222 /* Determine if there is a GUIX callback. */ 223 if ((callback_message.txm_module_callback_message_type >= TXM_GUIX_CALLBACKS_START) && (callback_message.txm_module_callback_message_type < TXM_GUIX_CALLBACKS_END)) 224 { 225 226 /* Call the GUIX module callback function. */ 227 _txm_module_guix_callback_request(&callback_message); 228 } 229 #endif 230 231 #ifdef TXM_MODULE_ENABLE_USBX 232 233 /* Determine if there is a USBX callback. */ 234 if ((callback_message.txm_module_callback_message_type >= TXM_USBX_CALLBACKS_START) && (callback_message.txm_module_callback_message_type < TXM_USBX_CALLBACKS_END)) 235 { 236 237 /* Call the USBX callback function. */ 238 _txm_module_usbx_callback_request(&callback_message); 239 } 240 #endif 241 242 break; 243 } 244 } 245 } 246 } 247