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_semaphore_notify_trampoline     PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Scott Larson, Microsoft Corporation                                 */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function processes the semaphore put notification call from    */
44 /*    ThreadX.                                                            */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    semaphore_ptr                     Semaphore pointer                 */
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_semaphore_notify_trampoline(TX_SEMAPHORE * semaphore_ptr)69 VOID  _txm_module_manager_semaphore_notify_trampoline(TX_SEMAPHORE *semaphore_ptr)
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 
78 
79     /* We now know the callback is for a module.  */
80 
81     /* Disable interrupts.  */
82     TX_DISABLE
83 
84     /* Pickup the module instance pointer.  */
85     module_instance =  (TXM_MODULE_INSTANCE *) semaphore_ptr -> tx_semaphore_module_instance;
86 
87     /* Determine if this module is still valid.  */
88     if ((module_instance) && (module_instance -> txm_module_instance_id == TXM_MODULE_ID) &&
89         (module_instance -> txm_module_instance_state == TXM_MODULE_STARTED))
90     {
91 
92         /* Yes, the module is still valid.  */
93 
94         /* Pickup the module's callback message queue.  */
95         module_callback_queue =  &(module_instance -> txm_module_instance_callback_request_queue);
96 
97         /* Build the queue notification message.  */
98         callback_message.txm_module_callback_message_type =                  TXM_SEMAPHORE_PUT_CALLBACK;
99         callback_message.txm_module_callback_message_activation_count =      1;
100         callback_message.txm_module_callback_message_application_function =  (VOID (*)(VOID)) semaphore_ptr -> tx_semaphore_put_module_notify;
101         callback_message.txm_module_callback_message_param_1 =               (ALIGN_TYPE) semaphore_ptr;
102         callback_message.txm_module_callback_message_param_2 =               0;
103         callback_message.txm_module_callback_message_param_3 =               0;
104         callback_message.txm_module_callback_message_param_4 =               0;
105         callback_message.txm_module_callback_message_param_5 =               0;
106         callback_message.txm_module_callback_message_param_6 =               0;
107         callback_message.txm_module_callback_message_param_7 =               0;
108         callback_message.txm_module_callback_message_param_8 =               0;
109         callback_message.txm_module_callback_message_reserved1 =             0;
110         callback_message.txm_module_callback_message_reserved2 =             0;
111 
112         /* Restore interrupts.  */
113         TX_RESTORE
114 
115         /* Call the general processing that will place the callback on the
116            module's callback request queue.  */
117         _txm_module_manager_callback_request(module_callback_queue, &callback_message);
118     }
119     else
120     {
121 
122         /* Module no longer valid.  */
123 
124         /* Error, increment the error counter and return.  */
125         _txm_module_manager_callback_error_count++;
126 
127         /* Restore interrupts.  */
128         TX_RESTORE
129     }
130 }
131 #endif
132