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 Manager                                                      */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 #define TX_SOURCE_CODE
24 
25 #include "tx_api.h"
26 #include "tx_queue.h"
27 #include "tx_thread.h"
28 #include "txm_module.h"
29 
30 #ifndef TX_DISABLE_NOTIFY_CALLBACKS
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _txm_module_manager_queue_notify_trampoline         PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Scott Larson, Microsoft Corporation                                 */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function processes the queue notification call from ThreadX.   */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    queue_ptr                         Queue pointer                     */
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_queue_notify_trampoline(TX_QUEUE * queue_ptr)68 VOID  _txm_module_manager_queue_notify_trampoline(TX_QUEUE *queue_ptr)
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 
77 
78     /* We now know the callback is for a module.  */
79 
80     /* Disable interrupts.  */
81     TX_DISABLE
82 
83     /* Pickup the module instance pointer.  */
84     module_instance =  (TXM_MODULE_INSTANCE *) queue_ptr -> tx_queue_module_instance;
85 
86     /* Determine if this module is still valid.  */
87     if ((module_instance) && (module_instance -> txm_module_instance_id == TXM_MODULE_ID) &&
88         (module_instance -> txm_module_instance_state == TXM_MODULE_STARTED))
89     {
90 
91         /* Yes, the module is still valid.  */
92 
93         /* Pickup the module's callback message queue.  */
94         module_callback_queue =  &(module_instance -> txm_module_instance_callback_request_queue);
95 
96         /* Build the queue notification message.  */
97         callback_message.txm_module_callback_message_type =                  TXM_QUEUE_SEND_CALLBACK;
98         callback_message.txm_module_callback_message_activation_count =      1;
99         callback_message.txm_module_callback_message_application_function =  (VOID (*)(VOID)) queue_ptr -> tx_queue_send_module_notify;
100         callback_message.txm_module_callback_message_param_1 =               (ALIGN_TYPE) queue_ptr;
101         callback_message.txm_module_callback_message_param_2 =               0;
102         callback_message.txm_module_callback_message_param_3 =               0;
103         callback_message.txm_module_callback_message_param_4 =               0;
104         callback_message.txm_module_callback_message_param_5 =               0;
105         callback_message.txm_module_callback_message_param_6 =               0;
106         callback_message.txm_module_callback_message_param_7 =               0;
107         callback_message.txm_module_callback_message_param_8 =               0;
108         callback_message.txm_module_callback_message_reserved1 =             0;
109         callback_message.txm_module_callback_message_reserved2 =             0;
110 
111         /* Restore interrupts.  */
112         TX_RESTORE
113 
114         /* Call the general processing that will place the callback on the
115            module's callback request queue.  */
116         _txm_module_manager_callback_request(module_callback_queue, &callback_message);
117     }
118     else
119     {
120 
121         /* Module no longer valid.  */
122 
123         /* Error, increment the error counter and return.  */
124         _txm_module_manager_callback_error_count++;
125 
126         /* Restore interrupts.  */
127         TX_RESTORE
128     }
129 }
130 #endif
131 
132 
133