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 /** USBX Component                                                        */
16 /**                                                                       */
17 /**   Trace                                                               */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #ifndef UX_SOURCE_CODE
23 #define UX_SOURCE_CODE
24 #endif
25 
26 
27 /* Include necessary system files.  */
28 
29 #include "ux_api.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_trace_event_insert                              PORTABLE C      */
37 /*                                                           6.1.9        */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function inserts a USBX event into the current trace buffer.   */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    event_id                              User Event ID                 */
49 /*    info_field_1                          First information field       */
50 /*    info_field_2                          First information field       */
51 /*    info_field_3                          First information field       */
52 /*    info_field_4                          First information field       */
53 /*    current_event                         Current event pointer for     */
54 /*                                            post event update           */
55 /*    current_timestamp                     Timestamp for post event      */
56 /*                                            update                      */
57 /*                                                                        */
58 /*  OUTPUT                                                                */
59 /*                                                                        */
60 /*    None                                                                */
61 /*                                                                        */
62 /*  CALLS                                                                 */
63 /*                                                                        */
64 /*    None                                                                */
65 /*                                                                        */
66 /*  CALLED BY                                                             */
67 /*                                                                        */
68 /*    Internal USBX Functions                                             */
69 /*                                                                        */
70 /*  RELEASE HISTORY                                                       */
71 /*                                                                        */
72 /*    DATE              NAME                      DESCRIPTION             */
73 /*                                                                        */
74 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
75 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
76 /*                                            used UX prefix to refer to  */
77 /*                                            TX symbols instead of using */
78 /*                                            them directly,              */
79 /*                                            resulting in version 6.1    */
80 /*  10-15-2021     Chaoqiong Xiao           Modified comment(s),          */
81 /*                                            improved traceX support,    */
82 /*                                            resulting in version 6.1.9  */
83 /*                                                                        */
84 /**************************************************************************/
85 #ifdef UX_ENABLE_EVENT_TRACE
_ux_trace_event_insert(ULONG event_id,ULONG info_field_1,ULONG info_field_2,ULONG info_field_3,ULONG info_field_4,ULONG filter,TX_TRACE_BUFFER_ENTRY ** current_event,ULONG * current_timestamp)86 VOID  _ux_trace_event_insert(ULONG event_id, ULONG info_field_1, ULONG info_field_2, ULONG info_field_3, ULONG info_field_4,
87                              ULONG filter, TX_TRACE_BUFFER_ENTRY **current_event, ULONG *current_timestamp)
88 {
89 
90 UX_INTERRUPT_SAVE_AREA
91 
92 TX_TRACE_BUFFER_ENTRY  *event;
93 ULONG                   timestamp;
94 
95 
96     /* Disable interrupts.  */
97     UX_DISABLE
98 
99     /* Pickup the current event.  */
100     event =  _tx_trace_buffer_current_ptr;
101 
102     /* Insert this event into the trace buffer.  */
103     TX_TRACE_IN_LINE_INSERT(event_id, info_field_1, info_field_2, info_field_3, info_field_4, filter)
104 
105     /* Initialize the timestamp to 0.  */
106     timestamp =  0;
107 
108     /* Determine if the event was inserted.  */
109     if (event)
110     {
111 
112         /* Was the event inserted?  */
113         if (event -> tx_trace_buffer_entry_event_id == event_id)
114         {
115 
116             /* Yes, the event was inserted in the event trace so pickup the timestamp.  */
117             timestamp =  event -> tx_trace_buffer_entry_time_stamp;
118         }
119         else
120         {
121 
122             /* Event was not inserted, simply set the event pointer to NULL.  */
123             event =  UX_NULL;
124         }
125     }
126 
127     /* Now determine if the caller requested the current event.  */
128     if (current_event)
129     {
130 
131         /* Yes, return the event pointer of potential subsequent update.  */
132         *current_event =  event;
133     }
134 
135     /* Now determine if the current timestamp was requested.  */
136     if (current_timestamp)
137     {
138 
139         /* Yes, return the current timestamp.  */
140         *current_timestamp =  timestamp;
141     }
142 
143     /* Restore interrupts.  */
144     UX_RESTORE
145 }
146 #endif
147 
148