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_queue_notify_trampoline         PORTABLE C      */
35 /*                                                           6.1          */
36 /*  AUTHOR                                                                */
37 /*                                                                        */
38 /*    Scott Larson, Microsoft Corporation                                 */
39 /*                                                                        */
40 /*  DESCRIPTION                                                           */
41 /*                                                                        */
42 /*    This function processes the queue notification call from ThreadX.   */
43 /*                                                                        */
44 /*  INPUT                                                                 */
45 /*                                                                        */
46 /*    queue_ptr                         Queue pointer                     */
47 /*                                                                        */
48 /*  OUTPUT                                                                */
49 /*                                                                        */
50 /*    None                                                                */
51 /*                                                                        */
52 /*  CALLS                                                                 */
53 /*                                                                        */
54 /*    _txm_module_manager_callback_request  Send module callback request  */
55 /*                                                                        */
56 /*  CALLED BY                                                             */
57 /*                                                                        */
58 /*    ThreadX                                                             */
59 /*                                                                        */
60 /*  RELEASE HISTORY                                                       */
61 /*                                                                        */
62 /*    DATE              NAME                      DESCRIPTION             */
63 /*                                                                        */
64 /*  09-30-2020      Scott Larson            Initial Version 6.1           */
65 /*                                                                        */
66 /**************************************************************************/
_txm_module_manager_queue_notify_trampoline(TX_QUEUE * queue_ptr)67 VOID  _txm_module_manager_queue_notify_trampoline(TX_QUEUE *queue_ptr)
68 {
69 
70 TX_INTERRUPT_SAVE_AREA
71 
72 TXM_MODULE_INSTANCE         *module_instance;
73 TXM_MODULE_CALLBACK_MESSAGE  callback_message;
74 TX_QUEUE                    *module_callback_queue;
75 
76 
77     /* We now know the callback is for a module.  */
78 
79     /* Disable interrupts.  */
80     TX_DISABLE
81 
82     /* Pickup the module instance pointer.  */
83     module_instance =  (TXM_MODULE_INSTANCE *) queue_ptr -> tx_queue_module_instance;
84 
85     /* Determine if this module is still valid.  */
86     if ((module_instance) && (module_instance -> txm_module_instance_id == TXM_MODULE_ID) &&
87         (module_instance -> txm_module_instance_state == TXM_MODULE_STARTED))
88     {
89 
90         /* Yes, the module is still valid.  */
91 
92         /* Pickup the module's callback message queue.  */
93         module_callback_queue =  &(module_instance -> txm_module_instance_callback_request_queue);
94 
95         /* Build the queue notification message.  */
96         callback_message.txm_module_callback_message_type =                  TXM_QUEUE_SEND_CALLBACK;
97         callback_message.txm_module_callback_message_activation_count =      1;
98         callback_message.txm_module_callback_message_application_function =  (VOID (*)(VOID)) queue_ptr -> tx_queue_send_module_notify;
99         callback_message.txm_module_callback_message_param_1 =               (ALIGN_TYPE) queue_ptr;
100         callback_message.txm_module_callback_message_param_2 =               0;
101         callback_message.txm_module_callback_message_param_3 =               0;
102         callback_message.txm_module_callback_message_param_4 =               0;
103         callback_message.txm_module_callback_message_param_5 =               0;
104         callback_message.txm_module_callback_message_param_6 =               0;
105         callback_message.txm_module_callback_message_param_7 =               0;
106         callback_message.txm_module_callback_message_param_8 =               0;
107         callback_message.txm_module_callback_message_reserved1 =             0;
108         callback_message.txm_module_callback_message_reserved2 =             0;
109 
110         /* Restore interrupts.  */
111         TX_RESTORE
112 
113         /* Call the general processing that will place the callback on the
114            module's callback request queue.  */
115         _txm_module_manager_callback_request(module_callback_queue, &callback_message);
116     }
117     else
118     {
119 
120         /* Module no longer valid.  */
121 
122         /* Error, increment the error counter and return.  */
123         _txm_module_manager_callback_error_count++;
124 
125         /* Restore interrupts.  */
126         TX_RESTORE
127     }
128 }
129 #endif
130 
131 
132