ctf tracing: native/host backend: Refactor to support embedded C libraries
Split this tracing backend in a top and bottom to enable building it with embedded libCs with the native simulator. Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This commit is contained in:
parent
df7749129f
commit
9be7b59b4a
5 changed files with 73 additions and 15 deletions
|
@ -124,5 +124,5 @@ host libC (:kconfig:option:`CONFIG_EXTERNAL_LIBC`).
|
||||||
serial, uart native TTY, :kconfig:option:`CONFIG_UART_NATIVE_TTY`, host libC
|
serial, uart native TTY, :kconfig:option:`CONFIG_UART_NATIVE_TTY`, host libC
|
||||||
spi, SPI emul, :kconfig:option:`CONFIG_SPI_EMUL`, all
|
spi, SPI emul, :kconfig:option:`CONFIG_SPI_EMUL`, all
|
||||||
system tick, native_posix timer, :kconfig:option:`CONFIG_NATIVE_POSIX_TIMER`, all
|
system tick, native_posix timer, :kconfig:option:`CONFIG_NATIVE_POSIX_TIMER`, all
|
||||||
tracing, Posix tracing backend, :kconfig:option:`CONFIG_TRACING_BACKEND_POSIX`, host libC
|
tracing, Posix tracing backend, :kconfig:option:`CONFIG_TRACING_BACKEND_POSIX`, all
|
||||||
usb, USB native posix, :kconfig:option:`CONFIG_USB_NATIVE_POSIX`, host libC
|
usb, USB native posix, :kconfig:option:`CONFIG_USB_NATIVE_POSIX`, host libC
|
||||||
|
|
|
@ -27,10 +27,14 @@ zephyr_sources_ifdef(
|
||||||
tracing_backend_uart.c
|
tracing_backend_uart.c
|
||||||
)
|
)
|
||||||
|
|
||||||
zephyr_sources_ifdef(
|
if (CONFIG_TRACING_BACKEND_POSIX)
|
||||||
CONFIG_TRACING_BACKEND_POSIX
|
zephyr_sources(tracing_backend_posix.c)
|
||||||
tracing_backend_posix.c
|
if (CONFIG_NATIVE_APPLICATION)
|
||||||
)
|
zephyr_library_sources(tracing_backend_posix_bottom.c)
|
||||||
|
else()
|
||||||
|
target_sources(native_simulator INTERFACE tracing_backend_posix_bottom.c)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
zephyr_sources_ifdef(
|
zephyr_sources_ifdef(
|
||||||
CONFIG_TRACING_BACKEND_RAM
|
CONFIG_TRACING_BACKEND_RAM
|
||||||
|
|
|
@ -5,11 +5,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <soc.h>
|
#include <soc.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <zephyr/kernel.h>
|
|
||||||
#include <cmdline.h>
|
#include <cmdline.h>
|
||||||
#include <zephyr/sys/__assert.h>
|
|
||||||
#include <tracing_backend.h>
|
#include <tracing_backend.h>
|
||||||
|
#include "tracing_backend_posix_bottom.h"
|
||||||
|
|
||||||
static void *out_stream;
|
static void *out_stream;
|
||||||
static const char *file_name;
|
static const char *file_name;
|
||||||
|
@ -20,20 +18,16 @@ static void tracing_backend_posix_init(void)
|
||||||
file_name = "channel0_0";
|
file_name = "channel0_0";
|
||||||
}
|
}
|
||||||
|
|
||||||
out_stream = (void *)fopen(file_name, "wb");
|
out_stream = tracing_backend_posix_init_bottom(file_name);
|
||||||
|
|
||||||
__ASSERT(out_stream != NULL, "posix backend init failed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tracing_backend_posix_output(
|
static void tracing_backend_posix_output(
|
||||||
const struct tracing_backend *backend,
|
const struct tracing_backend *backend,
|
||||||
uint8_t *data, uint32_t length)
|
uint8_t *data, uint32_t length)
|
||||||
{
|
{
|
||||||
fwrite(data, length, 1, (FILE *)out_stream);
|
ARG_UNUSED(backend);
|
||||||
|
|
||||||
if (!k_is_in_isr()) {
|
tracing_backend_posix_output_bottom(data, length, out_stream);
|
||||||
fflush((FILE *)out_stream);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct tracing_backend_api tracing_backend_posix_api = {
|
const struct tracing_backend_api tracing_backend_posix_api = {
|
||||||
|
|
33
subsys/tracing/tracing_backend_posix_bottom.c
Normal file
33
subsys/tracing/tracing_backend_posix_bottom.c
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018 Oticon A/S
|
||||||
|
* Copyright (c) 2023 Nordic Semiconductor ASA
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "nsi_tracing.h"
|
||||||
|
|
||||||
|
void *tracing_backend_posix_init_bottom(const char *file_name)
|
||||||
|
{
|
||||||
|
FILE *f;
|
||||||
|
|
||||||
|
f = fopen(file_name, "wb");
|
||||||
|
if (f == NULL) {
|
||||||
|
nsi_print_error_and_exit("%s: Could not open CTF backend file %s\n",
|
||||||
|
__func__, file_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (void *)f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tracing_backend_posix_output_bottom(const void *data, unsigned long length, void *out_stream)
|
||||||
|
{
|
||||||
|
int rc = fwrite(data, length, 1, (FILE *)out_stream);
|
||||||
|
|
||||||
|
if (rc != 1) {
|
||||||
|
nsi_print_warning("%s: Failure writing to CTF backend file\n", __func__);
|
||||||
|
}
|
||||||
|
|
||||||
|
fflush((FILE *)out_stream);
|
||||||
|
}
|
27
subsys/tracing/tracing_backend_posix_bottom.h
Normal file
27
subsys/tracing/tracing_backend_posix_bottom.h
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Nordic Semiconductor ASA
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* "Bottom" of the CTF tracing backend for the native/hosted targets.
|
||||||
|
* When built with the native_simulator this will be built in the runner context,
|
||||||
|
* that is, with the host C library, and with the host include paths.
|
||||||
|
*
|
||||||
|
* Note: None of these functions are public interfaces. But internal to this CTF backend.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DRIVERS_FLASH_FLASH_SIMULATOR_NATIVE_H
|
||||||
|
#define DRIVERS_FLASH_FLASH_SIMULATOR_NATIVE_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void *tracing_backend_posix_init_bottom(const char *file_name);
|
||||||
|
void tracing_backend_posix_output_bottom(const void *data, unsigned long length, void *out_stream);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* DRIVERS_FLASH_FLASH_SIMULATOR_NATIVE_H */
|
Loading…
Add table
Add a link
Reference in a new issue