blob: 20cd06706eb4d2d6aa4ddb6bb09a4481cc24739d [file] [log] [blame]
Julien Massot80402f72021-02-26 09:22:16 +01001/*
2 * Copyright (c) 2021 IoT.bzh
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#include <ctype.h>
Gerard Marull-Paretas5113c142022-05-06 11:12:04 +02008#include <zephyr/kernel.h>
Julien Massot80402f72021-02-26 09:22:16 +01009#include <string.h>
10#include <tracing_core.h>
11#include <tracing_buffer.h>
12#include <tracing_backend.h>
13
14uint8_t ram_tracing[CONFIG_RAM_TRACING_BUFFER_SIZE];
15static uint32_t pos;
16static bool buffer_full;
17
18static 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
35static void tracing_backend_ram_init(void)
36{
37 memset(ram_tracing, 0, CONFIG_RAM_TRACING_BUFFER_SIZE);
Galen Krulce1cfe90d2024-04-03 14:39:51 -070038 pos = 0;
39 buffer_full = false;
Julien Massot80402f72021-02-26 09:22:16 +010040}
41
42const struct tracing_backend_api tracing_backend_ram_api = {
43 .init = tracing_backend_ram_init,
44 .output = tracing_backend_ram_output
45};
46
47TRACING_BACKEND_DEFINE(tracing_backend_ram, tracing_backend_ram_api);