summaryrefslogtreecommitdiff
path: root/common_modules/module_manager/src/txm_module_manager_thread_notify_trampoline.c
blob: b7f2d5521839ee29b55388dfa70d776bde35c2e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/***************************************************************************
 * Copyright (c) 2024 Microsoft Corporation
 * Copyright (c) 2026-present Eclipse ThreadX contributors
 *
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 *
 * SPDX-License-Identifier: MIT
 **************************************************************************/


/**************************************************************************/
/**************************************************************************/
/**                                                                       */
/** ThreadX Component                                                     */
/**                                                                       */
/**   Module Manager                                                      */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/

#define TX_SOURCE_CODE

#include "tx_api.h"
#include "tx_queue.h"
#include "tx_thread.h"
#include "txm_module.h"

#ifndef TX_DISABLE_NOTIFY_CALLBACKS
/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _txm_module_manager_thread_notify_trampoline        PORTABLE C      */
/*                                                           6.1          */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Scott Larson, Microsoft Corporation                                 */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This function processes the thread entry/exit notification call     */
/*    from ThreadX.                                                       */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    thread_ptr                        Thread pointer                    */
/*    type                              Entry or exit type                */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    None                                                                */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*    _txm_module_manager_callback_request  Send module callback request  */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    ThreadX                                                             */
/*                                                                        */
/**************************************************************************/
VOID  _txm_module_manager_thread_notify_trampoline(TX_THREAD *thread_ptr, UINT type)
{

TX_INTERRUPT_SAVE_AREA

TXM_MODULE_INSTANCE             *module_instance;
TXM_MODULE_CALLBACK_MESSAGE     callback_message;
TX_QUEUE                        *module_callback_queue;
TXM_MODULE_THREAD_ENTRY_INFO    *thread_info;


    /* We now know the callback is for a module.  */

    /* Disable interrupts.  */
    TX_DISABLE

    /* Determine if the thread is valid.  */
    if ((thread_ptr) && (thread_ptr -> tx_thread_id == TX_THREAD_ID))
    {

        /* Pickup the module instance pointer.  */
        module_instance =  (TXM_MODULE_INSTANCE *) thread_ptr -> tx_thread_module_instance_ptr;

        /* Pickup the module's thread pointer.  */
        thread_info =  (TXM_MODULE_THREAD_ENTRY_INFO *) thread_ptr -> tx_thread_module_entry_info_ptr;

        /* Determine if this module is still valid.  */
        if ((module_instance) && (module_instance -> txm_module_instance_id == TXM_MODULE_ID) &&
            (module_instance -> txm_module_instance_state == TXM_MODULE_STARTED))
        {

            /* Yes, the module is still valid.  */

            /* Pickup the module's callback message queue.  */
            module_callback_queue =  &(module_instance -> txm_module_instance_callback_request_queue);

            /* Build the queue notification message.  */
            callback_message.txm_module_callback_message_type =                  TXM_THREAD_ENTRY_EXIT_CALLBACK;
            callback_message.txm_module_callback_message_activation_count =      1;
            callback_message.txm_module_callback_message_application_function =  (VOID (*)(VOID)) thread_info -> txm_module_thread_entry_info_exit_notify;
            callback_message.txm_module_callback_message_param_1 =               (ALIGN_TYPE) thread_ptr;
            callback_message.txm_module_callback_message_param_2 =               (ALIGN_TYPE) type;
            callback_message.txm_module_callback_message_param_3 =               0;
            callback_message.txm_module_callback_message_param_4 =               0;
            callback_message.txm_module_callback_message_param_5 =               0;
            callback_message.txm_module_callback_message_param_6 =               0;
            callback_message.txm_module_callback_message_param_7 =               0;
            callback_message.txm_module_callback_message_param_8 =               0;
            callback_message.txm_module_callback_message_reserved1 =             0;
            callback_message.txm_module_callback_message_reserved2 =             0;

            /* Restore interrupts.  */
            TX_RESTORE

            /* Call the general processing that will place the callback on the
               module's callback request queue.  */
            _txm_module_manager_callback_request(module_callback_queue, &callback_message);
        }
        else
        {

            /* Module no longer valid.  */

            /* Error, increment the error counter and return.  */
            _txm_module_manager_callback_error_count++;

            /* Restore interrupts.  */
            TX_RESTORE
        }
    }
    else
    {

        /* Thread pointer is not valid.  */

        /* Error, increment the error counter and return.  */
        _txm_module_manager_callback_error_count++;

        /* Restore interrupts.  */
        TX_RESTORE
    }
}
#endif