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 /** Module Manager */ 18 /** */ 19 /**************************************************************************/ 20 /**************************************************************************/ 21 22 #define TX_SOURCE_CODE 23 24 #include "tx_api.h" 25 #include "tx_queue.h" 26 #include "tx_thread.h" 27 #include "txm_module.h" 28 29 #ifndef TX_DISABLE_NOTIFY_CALLBACKS 30 /**************************************************************************/ 31 /* */ 32 /* FUNCTION RELEASE */ 33 /* */ 34 /* _txm_module_manager_thread_notify_trampoline PORTABLE C */ 35 /* 6.1 */ 36 /* AUTHOR */ 37 /* */ 38 /* Scott Larson, Microsoft Corporation */ 39 /* */ 40 /* DESCRIPTION */ 41 /* */ 42 /* This function processes the thread entry/exit notification call */ 43 /* from ThreadX. */ 44 /* */ 45 /* INPUT */ 46 /* */ 47 /* thread_ptr Thread pointer */ 48 /* type Entry or exit type */ 49 /* */ 50 /* OUTPUT */ 51 /* */ 52 /* None */ 53 /* */ 54 /* CALLS */ 55 /* */ 56 /* _txm_module_manager_callback_request Send module callback request */ 57 /* */ 58 /* CALLED BY */ 59 /* */ 60 /* ThreadX */ 61 /* */ 62 /* RELEASE HISTORY */ 63 /* */ 64 /* DATE NAME DESCRIPTION */ 65 /* */ 66 /* 09-30-2020 Scott Larson Initial Version 6.1 */ 67 /* */ 68 /**************************************************************************/ _txm_module_manager_thread_notify_trampoline(TX_THREAD * thread_ptr,UINT type)69VOID _txm_module_manager_thread_notify_trampoline(TX_THREAD *thread_ptr, UINT type) 70 { 71 72 TX_INTERRUPT_SAVE_AREA 73 74 TXM_MODULE_INSTANCE *module_instance; 75 TXM_MODULE_CALLBACK_MESSAGE callback_message; 76 TX_QUEUE *module_callback_queue; 77 TXM_MODULE_THREAD_ENTRY_INFO *thread_info; 78 79 80 /* We now know the callback is for a module. */ 81 82 /* Disable interrupts. */ 83 TX_DISABLE 84 85 /* Determine if the thread is valid. */ 86 if ((thread_ptr) && (thread_ptr -> tx_thread_id == TX_THREAD_ID)) 87 { 88 89 /* Pickup the module instance pointer. */ 90 module_instance = (TXM_MODULE_INSTANCE *) thread_ptr -> tx_thread_module_instance_ptr; 91 92 /* Pickup the module's thread pointer. */ 93 thread_info = (TXM_MODULE_THREAD_ENTRY_INFO *) thread_ptr -> tx_thread_module_entry_info_ptr; 94 95 /* Determine if this module is still valid. */ 96 if ((module_instance) && (module_instance -> txm_module_instance_id == TXM_MODULE_ID) && 97 (module_instance -> txm_module_instance_state == TXM_MODULE_STARTED)) 98 { 99 100 /* Yes, the module is still valid. */ 101 102 /* Pickup the module's callback message queue. */ 103 module_callback_queue = &(module_instance -> txm_module_instance_callback_request_queue); 104 105 /* Build the queue notification message. */ 106 callback_message.txm_module_callback_message_type = TXM_THREAD_ENTRY_EXIT_CALLBACK; 107 callback_message.txm_module_callback_message_activation_count = 1; 108 callback_message.txm_module_callback_message_application_function = (VOID (*)(VOID)) thread_info -> txm_module_thread_entry_info_exit_notify; 109 callback_message.txm_module_callback_message_param_1 = (ALIGN_TYPE) thread_ptr; 110 callback_message.txm_module_callback_message_param_2 = (ALIGN_TYPE) type; 111 callback_message.txm_module_callback_message_param_3 = 0; 112 callback_message.txm_module_callback_message_param_4 = 0; 113 callback_message.txm_module_callback_message_param_5 = 0; 114 callback_message.txm_module_callback_message_param_6 = 0; 115 callback_message.txm_module_callback_message_param_7 = 0; 116 callback_message.txm_module_callback_message_param_8 = 0; 117 callback_message.txm_module_callback_message_reserved1 = 0; 118 callback_message.txm_module_callback_message_reserved2 = 0; 119 120 /* Restore interrupts. */ 121 TX_RESTORE 122 123 /* Call the general processing that will place the callback on the 124 module's callback request queue. */ 125 _txm_module_manager_callback_request(module_callback_queue, &callback_message); 126 } 127 else 128 { 129 130 /* Module no longer valid. */ 131 132 /* Error, increment the error counter and return. */ 133 _txm_module_manager_callback_error_count++; 134 135 /* Restore interrupts. */ 136 TX_RESTORE 137 } 138 } 139 else 140 { 141 142 /* Thread pointer is not valid. */ 143 144 /* Error, increment the error counter and return. */ 145 _txm_module_manager_callback_error_count++; 146 147 /* Restore interrupts. */ 148 TX_RESTORE 149 } 150 } 151 #endif 152 153