Julien Massot | 80402f7 | 2021-02-26 09:22:16 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021 IoT.bzh |
| 3 | * |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
| 5 | */ |
| 6 | |
| 7 | #include <ctype.h> |
Gerard Marull-Paretas | 5113c14 | 2022-05-06 11:12:04 +0200 | [diff] [blame] | 8 | #include <zephyr/kernel.h> |
Julien Massot | 80402f7 | 2021-02-26 09:22:16 +0100 | [diff] [blame] | 9 | #include <string.h> |
| 10 | #include <tracing_core.h> |
| 11 | #include <tracing_buffer.h> |
| 12 | #include <tracing_backend.h> |
| 13 | |
| 14 | uint8_t ram_tracing[CONFIG_RAM_TRACING_BUFFER_SIZE]; |
| 15 | static uint32_t pos; |
| 16 | static bool buffer_full; |
| 17 | |
| 18 | static void tracing_backend_ram_output( |
| 19 | const struct tracing_backend *backend, |
| 20 | uint8_t *data, uint32_t length) |
| 21 | { |
| 22 | if (buffer_full) { |
| 23 | return; |
| 24 | } |
| 25 | |
| 26 | if ((pos + length) > CONFIG_RAM_TRACING_BUFFER_SIZE) { |
| 27 | buffer_full = true; |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | memcpy(ram_tracing + pos, data, length); |
| 32 | pos += length; |
| 33 | } |
| 34 | |
| 35 | static void tracing_backend_ram_init(void) |
| 36 | { |
| 37 | memset(ram_tracing, 0, CONFIG_RAM_TRACING_BUFFER_SIZE); |
Galen Krulce | 1cfe90d | 2024-04-03 14:39:51 -0700 | [diff] [blame] | 38 | pos = 0; |
| 39 | buffer_full = false; |
Julien Massot | 80402f7 | 2021-02-26 09:22:16 +0100 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | const struct tracing_backend_api tracing_backend_ram_api = { |
| 43 | .init = tracing_backend_ram_init, |
| 44 | .output = tracing_backend_ram_output |
| 45 | }; |
| 46 | |
| 47 | TRACING_BACKEND_DEFINE(tracing_backend_ram, tracing_backend_ram_api); |