1 /*
2 * Copyright (c) 2021 IoT.bzh
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <ctype.h>
8 #include <kernel.h>
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
tracing_backend_ram_output(const struct tracing_backend * backend,uint8_t * data,uint32_t length)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
tracing_backend_ram_init(void)35 static void tracing_backend_ram_init(void)
36 {
37 memset(ram_tracing, 0, CONFIG_RAM_TRACING_BUFFER_SIZE);
38 }
39
40 const struct tracing_backend_api tracing_backend_ram_api = {
41 .init = tracing_backend_ram_init,
42 .output = tracing_backend_ram_output
43 };
44
45 TRACING_BACKEND_DEFINE(tracing_backend_ram, tracing_backend_ram_api);
46