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 /**   Trace                                                               */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define TX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "tx_api.h"
28 #include "tx_trace.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _tx_trace_user_event_insert                         PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    William E. Lamie, Microsoft Corporation                             */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function inserts a user-defined event into the trace buffer.   */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    event_id                              User Event ID                 */
48 /*    info_field_1                          First information field       */
49 /*    info_field_2                          First information field       */
50 /*    info_field_3                          First information field       */
51 /*    info_field_4                          First information field       */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    Completion Status                                                   */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    None                                                                */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    Application Code                                                    */
64 /*                                                                        */
65 /*  RELEASE HISTORY                                                       */
66 /*                                                                        */
67 /*    DATE              NAME                      DESCRIPTION             */
68 /*                                                                        */
69 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
70 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
71 /*                                            resulting in version 6.1    */
72 /*                                                                        */
73 /**************************************************************************/
_tx_trace_user_event_insert(ULONG event_id,ULONG info_field_1,ULONG info_field_2,ULONG info_field_3,ULONG info_field_4)74 UINT  _tx_trace_user_event_insert(ULONG event_id, ULONG info_field_1, ULONG info_field_2, ULONG info_field_3, ULONG info_field_4)
75 {
76 
77 #ifdef TX_ENABLE_EVENT_TRACE
78 
79 TX_INTERRUPT_SAVE_AREA
80 
81 UINT            status;
82 
83 
84     /* Disable interrupts.  */
85     TX_DISABLE
86 
87     /* Determine if trace is disabled.  */
88     if (_tx_trace_buffer_current_ptr == TX_NULL)
89     {
90 
91         /* Yes, trace is already disabled.  */
92         status =  TX_NOT_DONE;
93     }
94     else
95     {
96 
97         /* Insert this event into the trace buffer.  */
98 #ifdef TX_MISRA_ENABLE
99         TX_TRACE_IN_LINE_INSERT(event_id, TX_ULONG_TO_POINTER_CONVERT(info_field_1), info_field_2, info_field_3, info_field_4, ((ULONG) TX_TRACE_USER_EVENTS))
100 #else
101         TX_TRACE_IN_LINE_INSERT(event_id, info_field_1, info_field_2, info_field_3, info_field_4, TX_TRACE_USER_EVENTS)
102 #endif
103 
104         /* Return successful status.  */
105         status =  TX_SUCCESS;
106     }
107 
108     /* Restore interrupts.  */
109     TX_RESTORE
110 
111     /* Return completion status.  */
112     return(status);
113 
114 #else
115 
116 UINT        status;
117 
118 
119     /* Access input arguments just for the sake of lint, MISRA, etc.  */
120     if (event_id != ((ULONG) 0))
121     {
122 
123         /* Trace not enabled, return an error.  */
124         status =  TX_FEATURE_NOT_ENABLED;
125     }
126     else if (info_field_1 != ((ULONG) 0))
127     {
128 
129         /* Trace not enabled, return an error.  */
130         status =  TX_FEATURE_NOT_ENABLED;
131     }
132     else if (info_field_2 != ((ULONG) 0))
133     {
134 
135         /* Trace not enabled, return an error.  */
136         status =  TX_FEATURE_NOT_ENABLED;
137     }
138     else if (info_field_3 != ((ULONG) 0))
139     {
140 
141         /* Trace not enabled, return an error.  */
142         status =  TX_FEATURE_NOT_ENABLED;
143     }
144     else if (info_field_4 != ((ULONG) 0))
145     {
146 
147         /* Trace not enabled, return an error.  */
148         status =  TX_FEATURE_NOT_ENABLED;
149     }
150     else
151     {
152 
153         /* Trace not enabled, return an error.  */
154         status =  TX_FEATURE_NOT_ENABLED;
155     }
156 
157     /* Return completion status.  */
158     return(status);
159 #endif
160 }
161 
162