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