NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
os_trace_api.h
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#ifndef OS_TRACE_API_H
21#define OS_TRACE_API_H
22
23#ifdef __ASSEMBLER__
24
25#define os_trace_isr_enter SEGGER_SYSVIEW_RecordEnterISR
26#define os_trace_isr_exit SEGGER_SYSVIEW_RecordExitISR
27#define os_trace_task_start_exec SEGGER_SYSVIEW_OnTaskStartExec
28
29#else
30
31#include <stdio.h>
32#include <string.h>
33#include "../syscfg/syscfg.h"
34#if MYNEWT_VAL(OS_SYSVIEW)
35#include "sysview/vendor/SEGGER_SYSVIEW.h"
36#endif
37#include "os.h"
38
39#define OS_TRACE_ID_EVENTQ_PUT (40)
40#define OS_TRACE_ID_EVENTQ_GET_NO_WAIT (41)
41#define OS_TRACE_ID_EVENTQ_GET (42)
42#define OS_TRACE_ID_EVENTQ_REMOVE (43)
43#define OS_TRACE_ID_EVENTQ_POLL_0TIMO (44)
44#define OS_TRACE_ID_EVENTQ_POLL (45)
45#define OS_TRACE_ID_MUTEX_INIT (50)
46#define OS_TRACE_ID_MUTEX_RELEASE (51)
47#define OS_TRACE_ID_MUTEX_PEND (52)
48#define OS_TRACE_ID_SEM_INIT (60)
49#define OS_TRACE_ID_SEM_RELEASE (61)
50#define OS_TRACE_ID_SEM_PEND (62)
51#define OS_TRACE_ID_CALLOUT_INIT (70)
52#define OS_TRACE_ID_CALLOUT_STOP (71)
53#define OS_TRACE_ID_CALLOUT_RESET (72)
54#define OS_TRACE_ID_CALLOUT_TICK (73)
55#define OS_TRACE_ID_MEMBLOCK_GET (80)
56#define OS_TRACE_ID_MEMBLOCK_PUT_FROM_CB (81)
57#define OS_TRACE_ID_MEMBLOCK_PUT (82)
58#define OS_TRACE_ID_MBUF_GET (90)
59#define OS_TRACE_ID_MBUF_GET_PKTHDR (91)
60#define OS_TRACE_ID_MBUF_FREE (92)
61#define OS_TRACE_ID_MBUF_FREE_CHAIN (93)
62
63#if MYNEWT_VAL(OS_SYSVIEW)
64
65typedef struct SEGGER_SYSVIEW_MODULE_STRUCT os_trace_module_t;
66
67static inline uint32_t
68os_trace_module_register(os_trace_module_t *m, const char *name,
69 uint32_t num_events, void (* send_desc_func)(void))
70{
71 char *desc = "M=???";
72
73 asprintf(&desc, "M=%s", name);
74
75 memset(m, 0, sizeof(*m));
76 m->sModule = desc;
77 m->NumEvents = num_events;
78 m->pfSendModuleDesc = send_desc_func;
79
80 SEGGER_SYSVIEW_RegisterModule(m);
81
82 return m->EventOffset;
83}
84
85static inline void
86os_trace_module_desc(const os_trace_module_t *m, const char *desc)
87{
88 SEGGER_SYSVIEW_RecordModuleDescription(m, desc);
89}
90
91static inline void
92os_trace_isr_enter(void)
93{
94 SEGGER_SYSVIEW_RecordEnterISR();
95}
96
97static inline void
98os_trace_isr_exit(void)
99{
100 SEGGER_SYSVIEW_RecordExitISR();
101}
102
103static inline void
104os_trace_task_info(const struct ble_npl_task *t)
105{
106 SEGGER_SYSVIEW_TASKINFO ti;
107
108 ti.TaskID = (uint32_t)t;
109 ti.sName = t->t_name;
110 ti.Prio = t->t_prio;
111 ti.StackSize = t->t_stacksize * sizeof(os_stack_t);
112 ti.StackBase = (uint32_t)&t->t_stackbottom + ti.StackSize;
113
114 SEGGER_SYSVIEW_SendTaskInfo(&ti);
115}
116
117static inline void
118os_trace_task_create(const struct ble_npl_task *t)
119{
120 SEGGER_SYSVIEW_OnTaskCreate((uint32_t)t);
121}
122
123static inline void
124os_trace_task_start_exec(const struct ble_npl_task *t)
125{
126 SEGGER_SYSVIEW_OnTaskStartExec((uint32_t)t);
127}
128
129static inline void
130os_trace_task_stop_exec(void)
131{
132 SEGGER_SYSVIEW_OnTaskStopExec();
133}
134
135static inline void
136os_trace_task_start_ready(const struct ble_npl_task *t)
137{
138 SEGGER_SYSVIEW_OnTaskStartReady((uint32_t)t);
139}
140
141static inline void
142os_trace_task_stop_ready(const struct ble_npl_task *t, unsigned reason)
143{
144 SEGGER_SYSVIEW_OnTaskStopReady((uint32_t)t, reason);
145}
146
147static inline void
148os_trace_idle(void)
149{
150 SEGGER_SYSVIEW_OnIdle();
151}
152
153static inline void
154os_trace_user_start(unsigned id)
155{
156 SEGGER_SYSVIEW_OnUserStart(id);
157}
158
159static inline void
160os_trace_user_stop(unsigned id)
161{
162 SEGGER_SYSVIEW_OnUserStop(id);
163}
164
165#endif /* MYNEWT_VAL(OS_SYSVIEW) */
166
167#if MYNEWT_VAL(OS_SYSVIEW) && !defined(OS_TRACE_DISABLE_FILE_API)
168
169static inline void
170os_trace_api_void(unsigned id)
171{
172 SEGGER_SYSVIEW_RecordVoid(id);
173}
174
175static inline void
176os_trace_api_u32(unsigned id, uint32_t p0)
177{
178 SEGGER_SYSVIEW_RecordU32(id, p0);
179}
180
181static inline void
182os_trace_api_u32x2(unsigned id, uint32_t p0, uint32_t p1)
183{
184 SEGGER_SYSVIEW_RecordU32x2(id, p0, p1);
185}
186
187static inline void
188os_trace_api_u32x3(unsigned id, uint32_t p0, uint32_t p1, uint32_t p2)
189{
190 SEGGER_SYSVIEW_RecordU32x3(id, p0, p1, p2);
191}
192
193static inline void
194os_trace_api_ret(unsigned id)
195{
196 SEGGER_SYSVIEW_RecordEndCall(id);
197}
198
199static inline void
200os_trace_api_ret_u32(unsigned id, uint32_t ret)
201{
202 SEGGER_SYSVIEW_RecordEndCallU32(id, ret);
203}
204
205#endif /* MYNEWT_VAL(OS_SYSVIEW) && !defined(OS_TRACE_DISABLE_FILE_API) */
206
207#if !MYNEWT_VAL(OS_SYSVIEW)
208
209static inline void
210os_trace_isr_enter(void)
211{
212}
213
214static inline void
215os_trace_isr_exit(void)
216{
217}
218
219static inline void
220os_trace_task_stop_exec(void)
221{
222}
223
224static inline void
225os_trace_idle(void)
226{
227}
228
229static inline void
230os_trace_user_start(unsigned id)
231{
232}
233
234static inline void
235os_trace_user_stop(unsigned id)
236{
237}
238
239#endif /* !MYNEWT_VAL(OS_SYSVIEW) */
240
241#if !MYNEWT_VAL(OS_SYSVIEW) || defined(OS_TRACE_DISABLE_FILE_API)
242
243static inline void
244os_trace_api_void(unsigned id)
245{
246}
247
248static inline void
249os_trace_api_u32(unsigned id, uint32_t p0)
250{
251}
252
253static inline void
254os_trace_api_u32x2(unsigned id, uint32_t p0, uint32_t p1)
255{
256}
257
258static inline void
259os_trace_api_u32x3(unsigned id, uint32_t p0, uint32_t p1, uint32_t p2)
260{
261}
262
263static inline void
264os_trace_api_ret(unsigned id)
265{
266}
267
268static inline void
269os_trace_api_ret_u32(unsigned id, uint32_t return_value)
270{
271}
272
273#endif /* !MYNEWT_VAL(OS_SYSVIEW) || defined(OS_TRACE_DISABLE_FILE_API) */
274
275#endif /* __ASSEMBLER__ */
276
277#endif /* OS_TRACE_API_H */