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