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 25 #include "tx_api.h" 26 #include "tx_thread.h" 27 #include "tx_timer.h" 28 #include "txm_module.h" 29 30 31 /**************************************************************************/ 32 /* */ 33 /* FUNCTION RELEASE */ 34 /* */ 35 /* _txm_module_manager_timer_notify_trampoline PORTABLE C */ 36 /* 6.1 */ 37 /* AUTHOR */ 38 /* */ 39 /* Scott Larson, Microsoft Corporation */ 40 /* */ 41 /* DESCRIPTION */ 42 /* */ 43 /* This function processes the timer expirations from ThreadX. */ 44 /* */ 45 /* INPUT */ 46 /* */ 47 /* id Timer ID */ 48 /* */ 49 /* OUTPUT */ 50 /* */ 51 /* None */ 52 /* */ 53 /* CALLS */ 54 /* */ 55 /* _txm_module_manager_callback_request Send module callback request */ 56 /* */ 57 /* CALLED BY */ 58 /* */ 59 /* ThreadX */ 60 /* */ 61 /* RELEASE HISTORY */ 62 /* */ 63 /* DATE NAME DESCRIPTION */ 64 /* */ 65 /* 09-30-2020 Scott Larson Initial Version 6.1 */ 66 /* */ 67 /**************************************************************************/ _txm_module_manager_timer_notify_trampoline(ULONG id)68VOID _txm_module_manager_timer_notify_trampoline(ULONG id) 69 { 70 71 TX_INTERRUPT_SAVE_AREA 72 73 TXM_MODULE_INSTANCE *module_instance; 74 TXM_MODULE_CALLBACK_MESSAGE callback_message; 75 TX_QUEUE *module_callback_queue; 76 TX_TIMER *timer_ptr; 77 CHAR *internal_ptr; 78 79 80 /* We now know the callback is for a module. */ 81 82 /* Disable interrupts. */ 83 TX_DISABLE 84 85 /* Our expired timer pointer points to the internal timer, 86 * we need to get to the full timer pointer. */ 87 /* Pickup the current internal timer pointer. */ 88 internal_ptr = (CHAR *) _tx_timer_expired_timer_ptr; 89 90 /* Get the timer pointer from the internal pointer. */ 91 TX_USER_TIMER_POINTER_GET((TX_TIMER_INTERNAL *) internal_ptr, timer_ptr); 92 93 /* Pickup the module instance pointer. */ 94 module_instance = (TXM_MODULE_INSTANCE *) timer_ptr -> tx_timer_module_instance; 95 96 /* Determine if this module is still valid. */ 97 if ((module_instance) && (module_instance -> txm_module_instance_id == TXM_MODULE_ID) && 98 (module_instance -> txm_module_instance_state == TXM_MODULE_STARTED)) 99 { 100 101 /* Yes, the module is still valid. */ 102 103 /* Pickup the module's callback message queue. */ 104 module_callback_queue = &(module_instance -> txm_module_instance_callback_request_queue); 105 106 /* Build the queue notification message. */ 107 callback_message.txm_module_callback_message_type = TXM_TIMER_CALLBACK; 108 callback_message.txm_module_callback_message_activation_count = 1; 109 callback_message.txm_module_callback_message_application_function = (VOID (*)(VOID)) timer_ptr -> tx_timer_module_expiration_function; 110 callback_message.txm_module_callback_message_param_1 = (ULONG) id; 111 callback_message.txm_module_callback_message_param_2 = 0; 112 callback_message.txm_module_callback_message_param_3 = 0; 113 callback_message.txm_module_callback_message_param_4 = 0; 114 callback_message.txm_module_callback_message_param_5 = 0; 115 callback_message.txm_module_callback_message_param_6 = 0; 116 callback_message.txm_module_callback_message_param_7 = 0; 117 callback_message.txm_module_callback_message_param_8 = 0; 118 callback_message.txm_module_callback_message_reserved1 = 0; 119 callback_message.txm_module_callback_message_reserved2 = 0; 120 121 /* Restore interrupts. */ 122 TX_RESTORE 123 124 /* Call the general processing that will place the callback on the 125 module's callback request queue. */ 126 _txm_module_manager_callback_request(module_callback_queue, &callback_message); 127 } 128 else 129 { 130 131 /* Module no longer valid. */ 132 133 /* Error, increment the error counter and return. */ 134 _txm_module_manager_callback_error_count++; 135 136 /* Restore interrupts. */ 137 TX_RESTORE 138 } 139 } 140 141