1 /* 2 * Copyright (c) 2018 Intel Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 #ifndef ZEPHYR_TRACE_SYSVIEW_H 7 #define ZEPHYR_TRACE_SYSVIEW_H 8 #include <string.h> 9 #include <zephyr/kernel.h> 10 #include <zephyr/init.h> 11 #include <tracing_sysview_ids.h> 12 13 #include <SEGGER_SYSVIEW.h> 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 void sys_trace_thread_info(struct k_thread *thread); 20 21 #define sys_port_trace_k_thread_foreach_enter() SEGGER_SYSVIEW_RecordVoid(TID_THREAD_FOREACH) 22 23 #define sys_port_trace_k_thread_foreach_exit() SEGGER_SYSVIEW_RecordEndCall(TID_THREAD_FOREACH) 24 25 #define sys_port_trace_k_thread_foreach_unlocked_enter() \ 26 SEGGER_SYSVIEW_RecordVoid(TID_THREAD_FOREACH_UNLOCKED) 27 28 #define sys_port_trace_k_thread_foreach_unlocked_exit() \ 29 SEGGER_SYSVIEW_RecordEndCall(TID_THREAD_FOREACH_UNLOCKED) 30 31 #define sys_port_trace_k_thread_create(new_thread) \ 32 do { \ 33 SEGGER_SYSVIEW_OnTaskCreate((uint32_t)(uintptr_t)new_thread); \ 34 sys_trace_thread_info(new_thread); \ 35 } while (0) 36 37 #define sys_port_trace_k_thread_user_mode_enter() \ 38 SEGGER_SYSVIEW_RecordVoid(TID_THREAD_USERMODE_ENTER) 39 40 #define sys_port_trace_k_thread_heap_assign(thread, heap) 41 #define sys_port_trace_k_thread_join_enter(thread, timeout) \ 42 SEGGER_SYSVIEW_RecordU32x2(TID_THREAD_JOIN, (uint32_t)(uintptr_t)thread, \ 43 (uint32_t)timeout.ticks) 44 #define sys_port_trace_k_thread_join_blocking(thread, timeout) 45 #define sys_port_trace_k_thread_join_exit(thread, timeout, ret) \ 46 SEGGER_SYSVIEW_RecordEndCallU32(TID_THREAD_JOIN, (int32_t)ret) 47 48 #define sys_port_trace_k_thread_sleep_enter(timeout) \ 49 SEGGER_SYSVIEW_RecordU32(TID_SLEEP, (uint32_t)k_ticks_to_ms_floor32(timeout.ticks)) 50 51 #define sys_port_trace_k_thread_sleep_exit(timeout, ret) \ 52 SEGGER_SYSVIEW_RecordEndCallU32(TID_SLEEP, (int32_t)ret) 53 54 #define sys_port_trace_k_thread_msleep_enter(ms) SEGGER_SYSVIEW_RecordU32(TID_MSLEEP, (uint32_t)ms) 55 56 #define sys_port_trace_k_thread_msleep_exit(ms, ret) \ 57 SEGGER_SYSVIEW_RecordEndCallU32(TID_MSLEEP, (int32_t)ret) 58 59 #define sys_port_trace_k_thread_usleep_enter(us) SEGGER_SYSVIEW_RecordU32(TID_USLEEP, (uint32_t)us) 60 61 #define sys_port_trace_k_thread_usleep_exit(us, ret) \ 62 SEGGER_SYSVIEW_RecordEndCallU32(TID_USLEEP, (int32_t)ret) 63 64 #define sys_port_trace_k_thread_busy_wait_enter(usec_to_wait) \ 65 SEGGER_SYSVIEW_RecordU32(TID_BUSYWAIT, (uint32_t)usec_to_wait) 66 67 #define sys_port_trace_k_thread_busy_wait_exit(usec_to_wait) \ 68 SEGGER_SYSVIEW_RecordEndCall(TID_BUSYWAIT) 69 70 #define sys_port_trace_k_thread_yield() SEGGER_SYSVIEW_RecordVoid(TID_THREAD_YIELD) 71 72 #define sys_port_trace_k_thread_wakeup(thread) \ 73 SEGGER_SYSVIEW_RecordU32(TID_THREAD_WAKEUP, (uint32_t)(uintptr_t)thread) 74 75 #define sys_port_trace_k_thread_start(thread) \ 76 SEGGER_SYSVIEW_RecordU32(TID_THREAD_START, (uint32_t)(uintptr_t)thread) 77 78 #define sys_port_trace_k_thread_abort(thread) \ 79 SEGGER_SYSVIEW_RecordU32(TID_THREAD_ABORT, (uint32_t)(uintptr_t)thread) 80 81 #define sys_port_trace_k_thread_suspend_enter(thread) \ 82 SEGGER_SYSVIEW_RecordU32(TID_THREAD_SUSPEND, (uint32_t)(uintptr_t)thread) 83 84 #define sys_port_trace_k_thread_suspend_exit(thread) \ 85 SEGGER_SYSVIEW_RecordEndCall(TID_THREAD_SUSPEND) 86 87 #define sys_port_trace_k_thread_resume_enter(thread) \ 88 SEGGER_SYSVIEW_RecordU32(TID_THREAD_RESUME, (uint32_t)(uintptr_t)thread) 89 90 #define sys_port_trace_k_thread_resume_exit(thread) SEGGER_SYSVIEW_RecordEndCall(TID_THREAD_RESUME) 91 92 #define sys_port_trace_k_thread_sched_lock() 93 94 #define sys_port_trace_k_thread_sched_unlock() 95 96 #define sys_port_trace_k_thread_name_set(thread, ret) do { \ 97 SEGGER_SYSVIEW_RecordU32(TID_THREAD_NAME_SET, (uint32_t)(uintptr_t)thread); \ 98 sys_trace_thread_info(thread); \ 99 } while (0) 100 101 #define sys_port_trace_k_thread_switched_out() sys_trace_k_thread_switched_out() 102 103 #define sys_port_trace_k_thread_switched_in() sys_trace_k_thread_switched_in() 104 105 #define sys_port_trace_k_thread_info(thread) sys_trace_k_thread_info(thread) 106 107 #define sys_port_trace_k_thread_sched_wakeup(thread) \ 108 SEGGER_SYSVIEW_RecordU32(TID_THREAD_WAKEUP, (uint32_t)(uintptr_t)thread) 109 110 #define sys_port_trace_k_thread_sched_abort(thread) \ 111 SEGGER_SYSVIEW_RecordU32(TID_THREAD_ABORT, (uint32_t)(uintptr_t)thread) 112 113 #define sys_port_trace_k_thread_sched_priority_set(thread, prio) \ 114 SEGGER_SYSVIEW_RecordU32x2(TID_THREAD_PRIORITY_SET, \ 115 SEGGER_SYSVIEW_ShrinkId((uint32_t)thread), prio); 116 117 #define sys_port_trace_k_thread_sched_ready(thread) \ 118 SEGGER_SYSVIEW_OnTaskStartReady((uint32_t)(uintptr_t)thread) 119 120 #define sys_port_trace_k_thread_sched_pend(thread) \ 121 SEGGER_SYSVIEW_OnTaskStopReady((uint32_t)(uintptr_t)thread, 3 << 3) 122 123 #define sys_port_trace_k_thread_sched_resume(thread) 124 125 #define sys_port_trace_k_thread_sched_suspend(thread) \ 126 SEGGER_SYSVIEW_OnTaskStopReady((uint32_t)(uintptr_t)thread, 3 << 3) 127 128 #define sys_port_trace_k_work_init(work) \ 129 SEGGER_SYSVIEW_RecordU32(TID_WORK_INIT, (uint32_t)(uintptr_t)work) 130 131 #define sys_port_trace_k_work_submit_to_queue_enter(queue, work) \ 132 SEGGER_SYSVIEW_RecordU32x2(TID_WORK_SUBMIT_TO_QUEUE, (uint32_t)(uintptr_t)queue, \ 133 (uint32_t)(uintptr_t)work) 134 135 #define sys_port_trace_k_work_submit_to_queue_exit(queue, work, ret) \ 136 SEGGER_SYSVIEW_RecordEndCallU32(TID_WORK_SUBMIT_TO_QUEUE, (uint32_t)ret) 137 138 #define sys_port_trace_k_work_submit_enter(work) \ 139 SEGGER_SYSVIEW_RecordU32(TID_WORK_SUBMIT, (uint32_t)(uintptr_t)work) 140 141 #define sys_port_trace_k_work_submit_exit(work, ret) \ 142 SEGGER_SYSVIEW_RecordEndCallU32(TID_WORK_SUBMIT, (uint32_t)ret) 143 144 #define sys_port_trace_k_work_flush_enter(work) \ 145 SEGGER_SYSVIEW_RecordU32(TID_WORK_FLUSH, (uint32_t)(uintptr_t)work) 146 147 #define sys_port_trace_k_work_flush_blocking(work, timeout) 148 149 #define sys_port_trace_k_work_flush_exit(work, ret) \ 150 SEGGER_SYSVIEW_RecordEndCallU32(TID_WORK_FLUSH, (uint32_t)ret) 151 152 #define sys_port_trace_k_work_cancel_enter(work) \ 153 SEGGER_SYSVIEW_RecordU32(TID_WORK_CANCEL, (uint32_t)(uintptr_t)work) 154 155 #define sys_port_trace_k_work_cancel_exit(work, ret) \ 156 SEGGER_SYSVIEW_RecordEndCallU32(TID_WORK_CANCEL, (uint32_t)ret) 157 158 #define sys_port_trace_k_work_cancel_sync_enter(work, sync) \ 159 SEGGER_SYSVIEW_RecordU32x2(TID_WORK_CANCEL_SYNC, (uint32_t)(uintptr_t)work, \ 160 (uint32_t)(uintptr_t)sync) 161 162 #define sys_port_trace_k_work_cancel_sync_blocking(work, sync) 163 164 #define sys_port_trace_k_work_cancel_sync_exit(work, sync, ret) \ 165 SEGGER_SYSVIEW_RecordEndCallU32(TID_WORK_CANCEL_SYNC, (uint32_t)ret) 166 167 #define sys_port_trace_k_work_queue_init(queue) \ 168 SEGGER_SYSVIEW_RecordU32(TID_WORK_QUEUE_INIT, \ 169 (uint32_t)(uintptr_t)queue) 170 171 #define sys_port_trace_k_work_queue_start_enter(queue) \ 172 SEGGER_SYSVIEW_RecordU32(TID_WORK_QUEUE_START, (uint32_t)(uintptr_t)queue) 173 174 #define sys_port_trace_k_work_queue_start_exit(queue) \ 175 SEGGER_SYSVIEW_RecordEndCall(TID_WORK_QUEUE_START) 176 177 #define sys_port_trace_k_work_queue_drain_enter(queue) \ 178 SEGGER_SYSVIEW_RecordU32(TID_WORK_QUEUE_DRAIN, (uint32_t)(uintptr_t)queue) 179 180 #define sys_port_trace_k_work_queue_drain_exit(queue, ret) \ 181 SEGGER_SYSVIEW_RecordEndCallU32(TID_WORK_QUEUE_DRAIN, (uint32_t)ret) 182 183 #define sys_port_trace_k_work_queue_unplug_enter(queue) \ 184 SEGGER_SYSVIEW_RecordU32(TID_WORK_QUEUE_UNPLUG, (uint32_t)(uintptr_t)queue) 185 186 #define sys_port_trace_k_work_queue_unplug_exit(queue, ret) \ 187 SEGGER_SYSVIEW_RecordEndCallU32(TID_WORK_QUEUE_UNPLUG, (uint32_t)ret) 188 189 #define sys_port_trace_k_work_delayable_init(dwork) \ 190 SEGGER_SYSVIEW_RecordU32(TID_WORK_DELAYABLE_INIT, (uint32_t)(uintptr_t)dwork) 191 192 #define sys_port_trace_k_work_schedule_for_queue_enter(queue, dwork, delay) \ 193 SEGGER_SYSVIEW_RecordU32x3(TID_WORK_SCHEDULE_FOR_QUEUE, (uint32_t)(uintptr_t)queue, \ 194 (uint32_t)(uintptr_t)dwork, (uint32_t)delay.ticks) 195 196 #define sys_port_trace_k_work_schedule_for_queue_exit(queue, dwork, delay, ret) \ 197 SEGGER_SYSVIEW_RecordEndCallU32(TID_WORK_SCHEDULE_FOR_QUEUE, (uint32_t)ret) 198 199 #define sys_port_trace_k_work_schedule_enter(dwork, delay) \ 200 SEGGER_SYSVIEW_RecordU32x2(TID_WORK_SCHEDULE, (uint32_t)(uintptr_t)dwork, \ 201 (uint32_t)delay.ticks) 202 203 #define sys_port_trace_k_work_schedule_exit(dwork, delay, ret) \ 204 SEGGER_SYSVIEW_RecordEndCallU32(TID_WORK_SCHEDULE, (uint32_t)ret) 205 206 #define sys_port_trace_k_work_reschedule_for_queue_enter(queue, dwork, delay) \ 207 SEGGER_SYSVIEW_RecordU32x3(TID_WORK_RESCHEDULE_FOR_QUEUE, (uint32_t)(uintptr_t)queue, \ 208 (uint32_t)(uintptr_t)dwork, (uint32_t)delay.ticks) 209 210 #define sys_port_trace_k_work_reschedule_for_queue_exit(queue, dwork, delay, ret) \ 211 SEGGER_SYSVIEW_RecordEndCallU32(TID_WORK_RESCHEDULE_FOR_QUEUE, (uint32_t)ret) 212 213 #define sys_port_trace_k_work_reschedule_enter(dwork, delay) \ 214 SEGGER_SYSVIEW_RecordU32x2(TID_WORK_RESCHEDULE, (uint32_t)(uintptr_t)dwork, \ 215 (uint32_t)delay.ticks) 216 217 #define sys_port_trace_k_work_reschedule_exit(dwork, delay, ret) \ 218 SEGGER_SYSVIEW_RecordEndCallU32(TID_WORK_RESCHEDULE, (uint32_t)ret) 219 220 #define sys_port_trace_k_work_flush_delayable_enter(dwork, sync) \ 221 SEGGER_SYSVIEW_RecordU32x2(TID_WORK_FLUSH_DELAYABLE, (uint32_t)(uintptr_t)dwork, \ 222 (uint32_t)(uintptr_t)sync) 223 224 #define sys_port_trace_k_work_flush_delayable_exit(dwork, sync, ret) \ 225 SEGGER_SYSVIEW_RecordEndCallU32(TID_WORK_FLUSH_DELAYABLE, (uint32_t)ret) 226 227 #define sys_port_trace_k_work_cancel_delayable_enter(dwork) \ 228 SEGGER_SYSVIEW_RecordU32(TID_WORK_CANCEL_DELAYABLE, (uint32_t)(uintptr_t)dwork) 229 230 #define sys_port_trace_k_work_cancel_delayable_exit(dwork, ret) \ 231 SEGGER_SYSVIEW_RecordEndCallU32(TID_WORK_CANCEL_DELAYABLE, (uint32_t)ret) 232 233 #define sys_port_trace_k_work_cancel_delayable_sync_enter(dwork, sync) \ 234 SEGGER_SYSVIEW_RecordU32x2(TID_WORK_CANCEL_DELAYABLE_SYNC, (uint32_t)(uintptr_t)dwork, \ 235 (uint32_t)(uintptr_t)sync) 236 237 #define sys_port_trace_k_work_cancel_delayable_sync_exit(dwork, sync, ret) \ 238 SEGGER_SYSVIEW_RecordEndCallU32(TID_WORK_CANCEL_DELAYABLE_SYNC, (uint32_t)ret) 239 240 #define sys_port_trace_k_work_poll_init_enter(work) \ 241 SEGGER_SYSVIEW_RecordU32(TID_WORK_POLL_INIT, (uint32_t)(uintptr_t)work) 242 243 #define sys_port_trace_k_work_poll_init_exit(work) SEGGER_SYSVIEW_RecordEndCall(TID_WORK_POLL_INIT) 244 245 #define sys_port_trace_k_work_poll_submit_to_queue_enter(work_q, work, timeout) \ 246 SEGGER_SYSVIEW_RecordU32x3(TID_WORK_POLL_SUBMIT_TO_QUEUE, (uint32_t)(uintptr_t)work_q, \ 247 (uint32_t)(uintptr_t)work, (uint32_t)timeout.ticks) 248 249 #define sys_port_trace_k_work_poll_submit_to_queue_blocking(work_q, work, timeout) 250 251 #define sys_port_trace_k_work_poll_submit_to_queue_exit(work_q, work, timeout, ret) \ 252 SEGGER_SYSVIEW_RecordEndCallU32(TID_WORK_POLL_SUBMIT_TO_QUEUE, (uint32_t)ret) 253 254 #define sys_port_trace_k_work_poll_submit_enter(work, timeout) \ 255 SEGGER_SYSVIEW_RecordU32x2(TID_WORK_POLL_SUBMIT, (uint32_t)(uintptr_t)work, \ 256 (uint32_t)timeout.ticks) 257 258 #define sys_port_trace_k_work_poll_submit_exit(work, timeout, ret) \ 259 SEGGER_SYSVIEW_RecordEndCallU32(TID_WORK_POLL_SUBMIT, (uint32_t)ret) 260 261 #define sys_port_trace_k_work_poll_cancel_enter(work) \ 262 SEGGER_SYSVIEW_RecordU32(TID_WORK_POLL_CANCEL, (uint32_t)(uintptr_t)work) 263 264 #define sys_port_trace_k_work_poll_cancel_exit(work, ret) \ 265 SEGGER_SYSVIEW_RecordEndCallU32(TID_WORK_POLL_CANCEL, (uint32_t)ret) 266 267 #define sys_port_trace_k_poll_api_event_init(event) 268 #define sys_port_trace_k_poll_api_poll_enter(events) 269 #define sys_port_trace_k_poll_api_poll_exit(events, ret) 270 #define sys_port_trace_k_poll_api_signal_init(signal) 271 #define sys_port_trace_k_poll_api_signal_reset(signal) 272 #define sys_port_trace_k_poll_api_signal_check(signal) 273 #define sys_port_trace_k_poll_api_signal_raise(signal, ret) 274 275 #define sys_port_trace_k_sem_init(sem, ret) \ 276 SEGGER_SYSVIEW_RecordU32x2(TID_SEMA_INIT, (uint32_t)(uintptr_t)sem, (int32_t)ret) 277 278 #define sys_port_trace_k_sem_give_enter(sem) \ 279 SEGGER_SYSVIEW_RecordU32(TID_SEMA_GIVE, (uint32_t)(uintptr_t)sem) 280 281 #define sys_port_trace_k_sem_give_exit(sem) SEGGER_SYSVIEW_RecordEndCall(TID_SEMA_GIVE) 282 283 #define sys_port_trace_k_sem_take_enter(sem, timeout) \ 284 SEGGER_SYSVIEW_RecordU32x2(TID_SEMA_TAKE, (uint32_t)(uintptr_t)sem, (uint32_t)timeout.ticks) 285 286 #define sys_port_trace_k_sem_take_blocking(sem, timeout) 287 288 #define sys_port_trace_k_sem_take_exit(sem, timeout, ret) \ 289 SEGGER_SYSVIEW_RecordEndCallU32(TID_SEMA_TAKE, (int32_t)ret) 290 291 #define sys_port_trace_k_sem_reset(sem) \ 292 SEGGER_SYSVIEW_RecordU32(TID_SEMA_RESET, (uint32_t)(uintptr_t)sem) 293 294 #define sys_port_trace_k_mutex_init(mutex, ret) \ 295 SEGGER_SYSVIEW_RecordU32x2(TID_MUTEX_INIT, (uint32_t)(uintptr_t)mutex, (int32_t)ret) 296 297 #define sys_port_trace_k_mutex_lock_enter(mutex, timeout) \ 298 SEGGER_SYSVIEW_RecordU32x2(TID_MUTEX_LOCK, (uint32_t)(uintptr_t)mutex, \ 299 (uint32_t)timeout.ticks) 300 301 #define sys_port_trace_k_mutex_lock_blocking(mutex, timeout) 302 303 #define sys_port_trace_k_mutex_lock_exit(mutex, timeout, ret) \ 304 SEGGER_SYSVIEW_RecordEndCallU32(TID_MUTEX_LOCK, (int32_t)ret) 305 306 #define sys_port_trace_k_mutex_unlock_enter(mutex) \ 307 SEGGER_SYSVIEW_RecordU32(TID_MUTEX_UNLOCK, (uint32_t)(uintptr_t)mutex) 308 309 #define sys_port_trace_k_mutex_unlock_exit(mutex, ret) \ 310 SEGGER_SYSVIEW_RecordEndCallU32(TID_MUTEX_UNLOCK, (uint32_t)ret) 311 312 #define sys_port_trace_k_condvar_init(condvar, ret) \ 313 SEGGER_SYSVIEW_RecordU32(TID_CONDVAR_INIT, (uint32_t)(uintptr_t)condvar) 314 315 #define sys_port_trace_k_condvar_signal_enter(condvar) \ 316 SEGGER_SYSVIEW_RecordU32(TID_CONDVAR_SIGNAL, (uint32_t)(uintptr_t)condvar) 317 318 #define sys_port_trace_k_condvar_signal_blocking(condvar, timeout) 319 320 #define sys_port_trace_k_condvar_signal_exit(condvar, ret) \ 321 SEGGER_SYSVIEW_RecordEndCallU32(TID_CONDVAR_SIGNAL, (uint32_t)ret) 322 323 #define sys_port_trace_k_condvar_broadcast_enter(condvar) \ 324 SEGGER_SYSVIEW_RecordU32(TID_CONDVAR_BROADCAST, (uint32_t)(uintptr_t)condvar) 325 326 #define sys_port_trace_k_condvar_broadcast_exit(condvar, ret) \ 327 SEGGER_SYSVIEW_RecordEndCallU32(TID_CONDVAR_BROADCAST, (uint32_t)ret) 328 329 #define sys_port_trace_k_condvar_wait_enter(condvar) \ 330 SEGGER_SYSVIEW_RecordU32(TID_CONDVAR_WAIT, (uint32_t)(uintptr_t)condvar) 331 332 #define sys_port_trace_k_condvar_wait_exit(condvar, ret) \ 333 SEGGER_SYSVIEW_RecordEndCallU32(TID_CONDVAR_WAIT, (uint32_t)ret) 334 335 #define sys_port_trace_k_queue_init(queue) \ 336 SEGGER_SYSVIEW_RecordU32(TID_QUEUE_INIT, (uint32_t)(uintptr_t)queue) 337 338 #define sys_port_trace_k_queue_cancel_wait(queue) \ 339 SEGGER_SYSVIEW_RecordU32(TID_QUEUE_CANCEL_WAIT, (uint32_t)(uintptr_t)queue) 340 341 #define sys_port_trace_k_queue_queue_insert_enter(queue, alloc) 342 #define sys_port_trace_k_queue_queue_insert_blocking(queue, alloc, timeout) 343 #define sys_port_trace_k_queue_queue_insert_exit(queue, alloc, ret) 344 345 #define sys_port_trace_k_queue_append_enter(queue) \ 346 SEGGER_SYSVIEW_RecordU32(TID_QUEUE_APPEND, (uint32_t)(uintptr_t)queue) 347 348 #define sys_port_trace_k_queue_append_exit(queue) SEGGER_SYSVIEW_RecordEndCall(TID_QUEUE_APPEND) 349 350 #define sys_port_trace_k_queue_alloc_append_enter(queue) \ 351 SEGGER_SYSVIEW_RecordU32(TID_QUEUE_ALLOC_APPEND, (uint32_t)(uintptr_t)queue) 352 353 #define sys_port_trace_k_queue_alloc_append_exit(queue, ret) \ 354 SEGGER_SYSVIEW_RecordEndCallU32(TID_QUEUE_ALLOC_APPEND, (uint32_t)ret) 355 356 #define sys_port_trace_k_queue_prepend_enter(queue) \ 357 SEGGER_SYSVIEW_RecordU32(TID_QUEUE_PREPEND, (uint32_t)(uintptr_t)queue) 358 359 #define sys_port_trace_k_queue_prepend_exit(queue) SEGGER_SYSVIEW_RecordEndCall(TID_QUEUE_PREPEND) 360 361 #define sys_port_trace_k_queue_alloc_prepend_enter(queue) \ 362 SEGGER_SYSVIEW_RecordU32(TID_QUEUE_ALLOC_PREPEND, (uint32_t)(uintptr_t)queue) 363 364 #define sys_port_trace_k_queue_alloc_prepend_exit(queue, ret) \ 365 SEGGER_SYSVIEW_RecordEndCallU32(TID_QUEUE_ALLOC_PREPEND, (uint32_t)ret) 366 367 #define sys_port_trace_k_queue_insert_enter(queue) \ 368 SEGGER_SYSVIEW_RecordU32(TID_QUEUE_INSERT, (uint32_t)(uintptr_t)queue) 369 370 #define sys_port_trace_k_queue_insert_blocking(queue, timeout) 371 372 #define sys_port_trace_k_queue_insert_exit(queue) SEGGER_SYSVIEW_RecordEndCall(TID_QUEUE_INSERT) 373 374 #define sys_port_trace_k_queue_append_list_enter(queue) \ 375 SEGGER_SYSVIEW_RecordU32(TID_QUEUE_APPEND_LIST, (uint32_t)(uintptr_t)queue) 376 377 #define sys_port_trace_k_queue_append_list_exit(queue, ret) \ 378 SEGGER_SYSVIEW_RecordEndCallU32(TID_QUEUE_APPEND_LIST, (uint32_t)ret) 379 380 #define sys_port_trace_k_queue_merge_slist_enter(queue) 381 #define sys_port_trace_k_queue_merge_slist_exit(queue, ret) 382 383 #define sys_port_trace_k_queue_get_enter(queue, timeout) \ 384 SEGGER_SYSVIEW_RecordU32x2(TID_QUEUE_GET, (uint32_t)(uintptr_t)queue, \ 385 (uint32_t)timeout.ticks) 386 387 #define sys_port_trace_k_queue_get_blocking(queue, timeout) 388 389 #define sys_port_trace_k_queue_get_exit(queue, timeout, data) \ 390 SEGGER_SYSVIEW_RecordEndCall(TID_QUEUE_GET) 391 392 #define sys_port_trace_k_queue_remove_enter(queue) \ 393 SEGGER_SYSVIEW_RecordU32(TID_QUEUE_REMOVE, (uint32_t)(uintptr_t)queue) 394 395 #define sys_port_trace_k_queue_remove_exit(queue, ret) \ 396 SEGGER_SYSVIEW_RecordEndCallU32(TID_QUEUE_REMOVE, (uint32_t)ret) 397 398 #define sys_port_trace_k_queue_unique_append_enter(queue) 399 #define sys_port_trace_k_queue_unique_append_exit(queue, ret) 400 401 #define sys_port_trace_k_queue_peek_head(queue, ret) \ 402 SEGGER_SYSVIEW_RecordU32x2(TID_QUEUE_PEAK_HEAD, (uint32_t)(uintptr_t)queue, (int32_t)ret) 403 404 #define sys_port_trace_k_queue_peek_tail(queue, ret) \ 405 SEGGER_SYSVIEW_RecordU32x2(TID_QUEUE_PEAK_TAIL, (uint32_t)(uintptr_t)queue, (int32_t)ret) 406 407 #define sys_port_trace_k_fifo_init_enter(fifo) \ 408 SEGGER_SYSVIEW_RecordU32(TID_FIFO_INIT, (uint32_t)(uintptr_t)fifo) 409 #define sys_port_trace_k_fifo_init_exit(fifo) SEGGER_SYSVIEW_RecordEndCall(TID_FIFO_INIT) 410 411 #define sys_port_trace_k_fifo_cancel_wait_enter(fifo) \ 412 SEGGER_SYSVIEW_RecordU32(TID_FIFO_CANCEL_WAIT, (uint32_t)(uintptr_t)fifo) 413 #define sys_port_trace_k_fifo_cancel_wait_exit(fifo) \ 414 SEGGER_SYSVIEW_RecordEndCall(TID_FIFO_CANCEL_WAIT) 415 416 #define sys_port_trace_k_fifo_put_enter(fifo, data) \ 417 SEGGER_SYSVIEW_RecordU32x2(TID_FIFO_PUT, (uint32_t)(uintptr_t)fifo, \ 418 (uint32_t)(uintptr_t)data) 419 420 #define sys_port_trace_k_fifo_put_exit(fifo, data) SEGGER_SYSVIEW_RecordEndCall(TID_FIFO_PUT) 421 422 #define sys_port_trace_k_fifo_alloc_put_enter(fifo, data) \ 423 SEGGER_SYSVIEW_RecordU32x2(TID_FIFO_ALLOC_PUT, (uint32_t)(uintptr_t)fifo, \ 424 (uint32_t)(uintptr_t)data) 425 #define sys_port_trace_k_fifo_alloc_put_exit(fifo, data, ret) \ 426 SEGGER_SYSVIEW_RecordEndCall(TID_FIFO_ALLOC_PUT) 427 428 #define sys_port_trace_k_fifo_put_list_enter(fifo, head, tail) \ 429 SEGGER_SYSVIEW_RecordU32x3(TID_FIFO_PUT_LIST, (uint32_t)(uintptr_t)fifo, \ 430 (uint32_t)(uintptr_t)head, (uint32_t)(uintptr_t)tail) 431 432 #define sys_port_trace_k_fifo_put_list_exit(fifo, head, tail) \ 433 SEGGER_SYSVIEW_RecordEndCall(TID_FIFO_PUT_LIST) 434 435 #define sys_port_trace_k_fifo_put_slist_enter(fifo, list) \ 436 SEGGER_SYSVIEW_RecordU32x2(TID_FIFO_PUT_SLIST, (uint32_t)(uintptr_t)fifo, \ 437 (uint32_t)(uintptr_t)list) 438 #define sys_port_trace_k_fifo_put_slist_exit(fifo, list) \ 439 SEGGER_SYSVIEW_RecordEndCall(TID_FIFO_PUT_SLIST) 440 441 #define sys_port_trace_k_fifo_get_enter(fifo, timeout) \ 442 SEGGER_SYSVIEW_RecordU32x2(TID_FIFO_GET, (uint32_t)(uintptr_t)fifo, (uint32_t)timeout.ticks) 443 444 #define sys_port_trace_k_fifo_get_exit(fifo, timeout, ret) \ 445 SEGGER_SYSVIEW_RecordEndCall(TID_FIFO_GET) 446 447 #define sys_port_trace_k_fifo_peek_head_enter(fifo) \ 448 SEGGER_SYSVIEW_RecordU32(TID_FIFO_PEAK_HEAD, (uint32_t)(uintptr_t)fifo) 449 450 #define sys_port_trace_k_fifo_peek_head_exit(fifo, ret) \ 451 SEGGER_SYSVIEW_RecordEndCall(TID_FIFO_PEAK_HEAD) 452 453 #define sys_port_trace_k_fifo_peek_tail_enter(fifo) \ 454 SEGGER_SYSVIEW_RecordU32(TID_FIFO_PEAK_TAIL, (uint32_t)(uintptr_t)fifo) 455 #define sys_port_trace_k_fifo_peek_tail_exit(fifo, ret) \ 456 SEGGER_SYSVIEW_RecordEndCall(TID_FIFO_PEAK_TAIL) 457 458 #define sys_port_trace_k_lifo_init_enter(lifo) \ 459 SEGGER_SYSVIEW_RecordU32(TID_LIFO_INIT, (uint32_t)(uintptr_t)lifo) 460 461 #define sys_port_trace_k_lifo_init_exit(lifo) SEGGER_SYSVIEW_RecordEndCall(TID_LIFO_INIT) 462 463 #define sys_port_trace_k_lifo_put_enter(lifo, data) \ 464 SEGGER_SYSVIEW_RecordU32x2(TID_LIFO_PUT, (uint32_t)(uintptr_t)lifo, \ 465 (uint32_t)(uintptr_t)data) 466 467 #define sys_port_trace_k_lifo_put_exit(lifo, data) SEGGER_SYSVIEW_RecordEndCall(TID_LIFO_PUT) 468 469 #define sys_port_trace_k_lifo_alloc_put_enter(lifo, data) \ 470 SEGGER_SYSVIEW_RecordU32x2(TID_LIFO_ALLOC_PUT, (uint32_t)(uintptr_t)lifo, \ 471 (uint32_t)(uintptr_t)data) 472 #define sys_port_trace_k_lifo_alloc_put_exit(lifo, data, ret) \ 473 SEGGER_SYSVIEW_RecordEndCall(TID_LIFO_ALLOC_PUT) 474 475 #define sys_port_trace_k_lifo_get_enter(lifo, timeout) \ 476 SEGGER_SYSVIEW_RecordU32x2(TID_LIFO_GET, (uint32_t)(uintptr_t)lifo, (uint32_t)timeout.ticks) 477 #define sys_port_trace_k_lifo_get_exit(lifo, timeout, ret) \ 478 SEGGER_SYSVIEW_RecordEndCall(TID_LIFO_GET) 479 480 #define sys_port_trace_k_stack_init(stack) 481 #define sys_port_trace_k_stack_alloc_init_enter(stack) 482 #define sys_port_trace_k_stack_alloc_init_exit(stack, ret) 483 #define sys_port_trace_k_stack_cleanup_enter(stack) 484 #define sys_port_trace_k_stack_cleanup_exit(stack, ret) 485 #define sys_port_trace_k_stack_push_enter(stack) 486 #define sys_port_trace_k_stack_push_exit(stack, ret) 487 #define sys_port_trace_k_stack_pop_enter(stack, timeout) 488 #define sys_port_trace_k_stack_pop_blocking(stack, timeout) 489 #define sys_port_trace_k_stack_pop_exit(stack, timeout, ret) 490 491 #define sys_port_trace_k_msgq_init(msgq) 492 #define sys_port_trace_k_msgq_alloc_init_enter(msgq) 493 #define sys_port_trace_k_msgq_alloc_init_exit(msgq, ret) 494 #define sys_port_trace_k_msgq_cleanup_enter(msgq) 495 #define sys_port_trace_k_msgq_cleanup_exit(msgq, ret) 496 #define sys_port_trace_k_msgq_put_enter(msgq, timeout) 497 #define sys_port_trace_k_msgq_put_blocking(msgq, timeout) 498 #define sys_port_trace_k_msgq_put_exit(msgq, timeout, ret) 499 #define sys_port_trace_k_msgq_get_enter(msgq, timeout) 500 #define sys_port_trace_k_msgq_get_blocking(msgq, timeout) 501 #define sys_port_trace_k_msgq_get_exit(msgq, timeout, ret) 502 #define sys_port_trace_k_msgq_peek(msgq, ret) 503 #define sys_port_trace_k_msgq_purge(msgq) 504 505 #define sys_port_trace_k_mbox_init(mbox) 506 #define sys_port_trace_k_mbox_message_put_enter(mbox, timeout) 507 #define sys_port_trace_k_mbox_message_put_blocking(mbox, timeout) 508 #define sys_port_trace_k_mbox_message_put_exit(mbox, timeout, ret) 509 #define sys_port_trace_k_mbox_put_enter(mbox, timeout) 510 #define sys_port_trace_k_mbox_put_exit(mbox, timeout, ret) 511 #define sys_port_trace_k_mbox_async_put_enter(mbox, sem) 512 #define sys_port_trace_k_mbox_async_put_exit(mbox, sem) 513 #define sys_port_trace_k_mbox_get_enter(mbox, timeout) 514 #define sys_port_trace_k_mbox_get_blocking(mbox, timeout) 515 #define sys_port_trace_k_mbox_get_exit(mbox, timeout, ret) 516 #define sys_port_trace_k_mbox_data_get(rx_msg) 517 518 #define sys_port_trace_k_pipe_init(pipe) 519 #define sys_port_trace_k_pipe_cleanup_enter(pipe) 520 #define sys_port_trace_k_pipe_cleanup_exit(pipe, ret) 521 #define sys_port_trace_k_pipe_alloc_init_enter(pipe) 522 #define sys_port_trace_k_pipe_alloc_init_exit(pipe, ret) 523 #define sys_port_trace_k_pipe_flush_enter(pipe) 524 #define sys_port_trace_k_pipe_flush_exit(pipe) 525 #define sys_port_trace_k_pipe_buffer_flush_enter(pipe) 526 #define sys_port_trace_k_pipe_buffer_flush_exit(pipe) 527 #define sys_port_trace_k_pipe_put_enter(pipe, timeout) 528 #define sys_port_trace_k_pipe_put_blocking(pipe, timeout) 529 #define sys_port_trace_k_pipe_put_exit(pipe, timeout, ret) 530 #define sys_port_trace_k_pipe_get_enter(pipe, timeout) 531 #define sys_port_trace_k_pipe_get_blocking(pipe, timeout) 532 #define sys_port_trace_k_pipe_get_exit(pipe, timeout, ret) 533 #define sys_port_trace_k_pipe_block_put_enter(pipe, sem) 534 #define sys_port_trace_k_pipe_block_put_exit(pipe, sem) 535 536 #define sys_port_trace_k_event_init(event) 537 #define sys_port_trace_k_event_post_enter(event, events, events_mask) 538 #define sys_port_trace_k_event_post_exit(event, events, events_mask) 539 #define sys_port_trace_k_event_wait_enter(event, events, options, timeout) 540 #define sys_port_trace_k_event_wait_blocking(event, events, options, timeout) 541 #define sys_port_trace_k_event_wait_exit(event, events, ret) 542 543 #define sys_port_trace_k_heap_init(heap) \ 544 SEGGER_SYSVIEW_RecordU32(TID_HEAP_INIT, (uint32_t)(uintptr_t)heap) 545 546 #define sys_port_trace_k_heap_aligned_alloc_enter(heap, timeout) \ 547 SEGGER_SYSVIEW_RecordU32x2(TID_HEAP_ALIGNED_ALLOC, (uint32_t)(uintptr_t)heap, \ 548 (uint32_t)timeout.ticks) 549 550 #define sys_port_trace_k_heap_aligned_alloc_blocking(heap, timeout) 551 552 #define sys_port_trace_k_heap_aligned_alloc_exit(heap, timeout, ret) \ 553 SEGGER_SYSVIEW_RecordEndCallU32(TID_HEAP_ALIGNED_ALLOC, (uint32_t)ret) 554 555 #define sys_port_trace_k_heap_alloc_enter(heap, timeout) \ 556 SEGGER_SYSVIEW_RecordU32x2(TID_HEAP_ALLOC, (uint32_t)(uintptr_t)heap, \ 557 (uint32_t)timeout.ticks) 558 559 #define sys_port_trace_k_heap_alloc_exit(heap, timeout, ret) \ 560 SEGGER_SYSVIEW_RecordEndCallU32(TID_HEAP_ALLOC, (uint32_t)ret) 561 562 #define sys_port_trace_k_heap_free(heap) \ 563 SEGGER_SYSVIEW_RecordU32(TID_HEAP_FREE, (uint32_t)(uintptr_t)heap) 564 565 #define sys_port_trace_k_heap_sys_k_aligned_alloc_enter(heap) 566 #define sys_port_trace_k_heap_sys_k_aligned_alloc_exit(heap, ret) 567 #define sys_port_trace_k_heap_sys_k_malloc_enter(heap) 568 #define sys_port_trace_k_heap_sys_k_malloc_exit(heap, ret) 569 #define sys_port_trace_k_heap_sys_k_free_enter(heap, heap_ref) 570 #define sys_port_trace_k_heap_sys_k_free_exit(heap, heap_ref) 571 #define sys_port_trace_k_heap_sys_k_calloc_enter(heap) 572 #define sys_port_trace_k_heap_sys_k_calloc_exit(heap, ret) 573 574 #define sys_port_trace_k_mem_slab_init(slab, rc) \ 575 SEGGER_SYSVIEW_RecordU32(TID_MSLAB_INIT, (uint32_t)(uintptr_t)slab) 576 577 #define sys_port_trace_k_mem_slab_alloc_enter(slab, timeout) \ 578 SEGGER_SYSVIEW_RecordU32x2(TID_MSLAB_ALLOC, (uint32_t)(uintptr_t)slab, \ 579 (uint32_t)timeout.ticks) 580 581 #define sys_port_trace_k_mem_slab_alloc_blocking(slab, timeout) 582 #define sys_port_trace_k_mem_slab_alloc_exit(slab, timeout, ret) \ 583 SEGGER_SYSVIEW_RecordEndCallU32(TID_MSLAB_ALLOC, (uint32_t)ret) 584 585 #define sys_port_trace_k_mem_slab_free_enter(slab) \ 586 SEGGER_SYSVIEW_RecordU32(TID_MSLAB_FREE, (uint32_t)(uintptr_t)slab) 587 588 #define sys_port_trace_k_mem_slab_free_exit(slab) SEGGER_SYSVIEW_RecordEndCall(TID_MSLAB_ALLOC) 589 590 #define sys_port_trace_k_timer_init(timer) \ 591 SEGGER_SYSVIEW_RecordU32(TID_TIMER_INIT, (uint32_t)(uintptr_t)timer) 592 593 #define sys_port_trace_k_timer_start(timer, duration, period) \ 594 SEGGER_SYSVIEW_RecordU32x3(TID_TIMER_START, (uint32_t)(uintptr_t)timer, \ 595 (uint32_t)duration.ticks, (uint32_t)period.ticks) 596 597 #define sys_port_trace_k_timer_stop(timer) \ 598 SEGGER_SYSVIEW_RecordU32(TID_TIMER_STOP, (uint32_t)(uintptr_t)timer) 599 600 #define sys_port_trace_k_timer_status_sync_enter(timer) \ 601 SEGGER_SYSVIEW_RecordU32(TID_TIMER_STATUS_SYNC, (uint32_t)(uintptr_t)timer) 602 603 #define sys_port_trace_k_timer_status_sync_blocking(timer, timeout) 604 605 #define sys_port_trace_k_timer_status_sync_exit(timer, result) \ 606 SEGGER_SYSVIEW_RecordEndCallU32(TID_TIMER_STATUS_SYNC, (uint32_t)result) 607 608 #define sys_port_trace_syscall_enter(id, name, ...) \ 609 SEGGER_SYSVIEW_RecordU32(TID_SYSCALL, (uint32_t)id) 610 611 #define sys_port_trace_syscall_exit(id, name, ...) \ 612 SEGGER_SYSVIEW_RecordEndCallU32(TID_SYSCALL, (uint32_t)id) 613 614 void sys_trace_idle(void); 615 616 void sys_trace_k_thread_create(struct k_thread *new_thread, size_t stack_size, int prio); 617 void sys_trace_k_thread_user_mode_enter(k_thread_entry_t entry, void *p1, void *p2, void *p3); 618 619 void sys_trace_k_thread_join_blocking(struct k_thread *thread, k_timeout_t timeout); 620 void sys_trace_k_thread_join_exit(struct k_thread *thread, k_timeout_t timeout, int ret); 621 622 void sys_trace_k_thread_switched_out(void); 623 void sys_trace_k_thread_switched_in(void); 624 void sys_trace_k_thread_ready(struct k_thread *thread); 625 void sys_trace_k_thread_pend(struct k_thread *thread); 626 void sys_trace_k_thread_info(struct k_thread *thread); 627 628 #define sys_port_trace_pm_system_suspend_enter(ticks) \ 629 SEGGER_SYSVIEW_RecordU32(TID_PM_SYSTEM_SUSPEND, (uint32_t)ticks) 630 #define sys_port_trace_pm_system_suspend_exit(ticks, state) \ 631 SEGGER_SYSVIEW_RecordEndCallU32(TID_PM_SYSTEM_SUSPEND, (uint32_t)state) 632 633 #define sys_port_trace_pm_device_runtime_get_enter(dev) \ 634 SEGGER_SYSVIEW_RecordU32(TID_PM_DEVICE_RUNTIME_GET, \ 635 (uint32_t)(uintptr_t)dev) 636 #define sys_port_trace_pm_device_runtime_get_exit(dev, ret) \ 637 SEGGER_SYSVIEW_RecordEndCallU32(TID_PM_DEVICE_RUNTIME_GET, \ 638 (uint32_t)ret) 639 #define sys_port_trace_pm_device_runtime_put_enter(dev) \ 640 SEGGER_SYSVIEW_RecordU32(TID_PM_DEVICE_RUNTIME_PUT, \ 641 (uint32_t)(uintptr_t)dev) 642 #define sys_port_trace_pm_device_runtime_put_exit(dev, ret) \ 643 SEGGER_SYSVIEW_RecordEndCallU32(TID_PM_DEVICE_RUNTIME_PUT, \ 644 (uint32_t)ret) 645 #define sys_port_trace_pm_device_runtime_put_async_enter(dev) \ 646 SEGGER_SYSVIEW_RecordU32(TID_PM_DEVICE_RUNTIME_PUT_ASYNC, \ 647 (uint32_t)(uintptr_t)dev) 648 #define sys_port_trace_pm_device_runtime_put_async_exit(dev, ret) \ 649 SEGGER_SYSVIEW_RecordEndCallU32(TID_PM_DEVICE_RUNTIME_PUT_ASYNC, \ 650 (uint32_t)ret) 651 #define sys_port_trace_pm_device_runtime_enable_enter(dev) \ 652 SEGGER_SYSVIEW_RecordU32(TID_PM_DEVICE_RUNTIME_ENABLE, \ 653 (uint32_t)(uintptr_t)dev) 654 #define sys_port_trace_pm_device_runtime_enable_exit(dev, ret) \ 655 SEGGER_SYSVIEW_RecordEndCallU32(TID_PM_DEVICE_RUNTIME_ENABLE, \ 656 (uint32_t)ret) 657 #define sys_port_trace_pm_device_runtime_disable_enter(dev) \ 658 SEGGER_SYSVIEW_RecordU32(TID_PM_DEVICE_RUNTIME_DISABLE, \ 659 (uint32_t)(uintptr_t)dev) 660 #define sys_port_trace_pm_device_runtime_disable_exit(dev, ret) \ 661 SEGGER_SYSVIEW_RecordEndCallU32(TID_PM_DEVICE_RUNTIME_DISABLE, \ 662 (uint32_t)ret) 663 664 #ifdef __cplusplus 665 } 666 #endif 667 668 #endif /* ZEPHYR_TRACE_SYSVIEW_H */ 669