From 53781ed66c2b281138a978951e75f2d8dcb7f076 Mon Sep 17 00:00:00 2001 From: KSMehta11 Date: Sat, 31 Jan 2026 14:50:29 -0800 Subject: [PATCH 1/4] Add TraceX support --- threadX/traceX/inc/traceout.h | 41 ++++++++++++++++++++++++++++ threadX/traceX/inc/tracex.h | 51 +++++++++++++++++++++++++++++++++++ threadX/traceX/src/traceout.c | 49 +++++++++++++++++++++++++++++++++ threadX/traceX/src/tracex.c | 51 +++++++++++++++++++++++++++++++++++ 4 files changed, 192 insertions(+) create mode 100644 threadX/traceX/inc/traceout.h create mode 100644 threadX/traceX/inc/tracex.h create mode 100644 threadX/traceX/src/traceout.c create mode 100644 threadX/traceX/src/tracex.c diff --git a/threadX/traceX/inc/traceout.h b/threadX/traceX/inc/traceout.h new file mode 100644 index 00000000..25efcfd8 --- /dev/null +++ b/threadX/traceX/inc/traceout.h @@ -0,0 +1,41 @@ +/** + * @file traceout.h + * @brief TraceX data output interface. + */ + +#ifndef TRACEOUT_H +#define TRACEOUT_H + +#include + +/* Size of each transmitted chunk */ +#define TRACEOUT_CHUNK_BYTES (1024U) + +/** + * @brief Platform transmit callback. + * + * Must initiate a non-blocking transmit (DMA / IT). + * + * @param data Pointer to data buffer. + * @param len Number of bytes to transmit. + */ +typedef void (*traceout_tx_fn_t)(const uint8_t *data, uint16_t len); + +/** + * @brief Initialize trace output streaming. + * + * @param tx_fn Platform transmit callback. + */ +void traceout_init(traceout_tx_fn_t tx_fn); + +/** + * @brief Start trace output from ISR context. + */ +void traceout_start_from_isr(void); + +/** + * @brief Notify trace output that transmit completed (ISR context). + */ +void traceout_on_tx_complete_from_isr(void); + +#endif /* TRACEOUT_H */ \ No newline at end of file diff --git a/threadX/traceX/inc/tracex.h b/threadX/traceX/inc/tracex.h new file mode 100644 index 00000000..b472c16d --- /dev/null +++ b/threadX/traceX/inc/tracex.h @@ -0,0 +1,51 @@ +/** + * @file tracex.h + * @brief TraceX control interface. + * + */ + +#ifndef TRACEX_H +#define TRACEX_H + +#include "tx_api.h" +#include + +/** + * @brief Initialize TraceX with a user-provided buffer. + * + * This must be called once before starting TraceX. + * + * @param buffer Pointer to trace buffer. + * @param size Size of trace buffer in bytes. + */ +void tracex_init(UCHAR *buffer, uint32_t size); + +/** + * @brief Start TraceX recording. + * + * Safe to call multiple times. + */ +void tracex_start(void); + +/** + * @brief Stop TraceX recording. + * + * Safe to call multiple times. + */ +void tracex_stop(void); + +/** + * @brief Get the TraceX buffer pointer. + * + * @return Pointer to trace buffer. + */ +UCHAR *tracex_get_buffer(void); + +/** + * @brief Get the TraceX buffer size. + * + * @return Buffer size in bytes. + */ +uint32_t tracex_get_buffer_size(void); + +#endif /* TRACEX_H */ \ No newline at end of file diff --git a/threadX/traceX/src/traceout.c b/threadX/traceX/src/traceout.c new file mode 100644 index 00000000..b6393e4e --- /dev/null +++ b/threadX/traceX/src/traceout.c @@ -0,0 +1,49 @@ +/** + * @file traceout.c + * @brief TraceX data output interface. + */ + +#include "traceout.h" +#include "tracex.h" + +static traceout_tx_fn_t s_tx_fn = NULL; +static volatile uint8_t s_output_active = 0U; +static const uint8_t *s_dp = NULL; +static uint32_t s_remaining = 0U; + +static void start_next_chunk(void) { + if (s_remaining == 0U) { + s_output_active = 0U; + tracex_start(); + return; + } + + uint32_t n = + (s_remaining > TRACEOUT_CHUNK_BYTES) ? TRACEOUT_CHUNK_BYTES : s_remaining; + + s_tx_fn(s_dp, (uint16_t)n); + s_dp += n; + s_remaining -= n; +} + +void traceout_init(traceout_tx_fn_t tx_fn) { s_tx_fn = tx_fn; } + +void traceout_start_from_isr(void) { + if ((s_tx_fn == NULL) || (s_output_active != 0U)) { + return; + } + + tracex_stop(); + + s_dp = tracex_get_buffer(); + s_remaining = tracex_get_buffer_size(); + s_output_active = 1U; + + start_next_chunk(); +} + +void traceout_on_tx_complete_from_isr(void) { + if (s_output_active != 0U) { + start_next_chunk(); + } +} \ No newline at end of file diff --git a/threadX/traceX/src/tracex.c b/threadX/traceX/src/tracex.c new file mode 100644 index 00000000..773bf10e --- /dev/null +++ b/threadX/traceX/src/tracex.c @@ -0,0 +1,51 @@ +/** + * @file tracex.c + * @brief TraceX control interface. + * + */ + +#include "tracex.h" +#include + +/** + * @brief Enable the CPU cycle counter used by TraceX timestamps. + * + * This function is implemented by the application or platform layer. + * It must enable a free-running CPU cycle counter before TraceX is started. + * + * It is called once from tracex_start(). + */ +void tracex_enable_cycle_counter(void); + +static UCHAR *s_trace_buffer = NULL; +static uint32_t s_trace_size = 0U; +static bool s_tracex_started = false; + +void tracex_init(UCHAR *buffer, uint32_t size) { + s_trace_buffer = buffer; + s_trace_size = size; +} + +UCHAR *tracex_get_buffer(void) { return s_trace_buffer; } + +uint32_t tracex_get_buffer_size(void) { return s_trace_size; } + +void tracex_start(void) { + if ((s_tracex_started == true) || (s_trace_buffer == NULL) || + (s_trace_size == 0U)) { + return; + } + + tracex_enable_cycle_counter(); + tx_trace_enable(s_trace_buffer, s_trace_size, 32U); + s_tracex_started = true; +} + +void tracex_stop(void) { + if (s_tracex_started == false) { + return; + } + + tx_trace_disable(); + s_tracex_started = false; +} \ No newline at end of file From 625e5d888bb9a49861a8669b986a32712f0d07d3 Mon Sep 17 00:00:00 2001 From: KSMehta11 Date: Sat, 31 Jan 2026 14:55:37 -0800 Subject: [PATCH 2/4] Fixed Format --- threadX/traceX/src/traceout.c | 61 +++++++++++++++++++---------------- threadX/traceX/src/tracex.c | 47 ++++++++++++++++----------- 2 files changed, 62 insertions(+), 46 deletions(-) diff --git a/threadX/traceX/src/traceout.c b/threadX/traceX/src/traceout.c index b6393e4e..d7dab394 100644 --- a/threadX/traceX/src/traceout.c +++ b/threadX/traceX/src/traceout.c @@ -11,39 +11,46 @@ static volatile uint8_t s_output_active = 0U; static const uint8_t *s_dp = NULL; static uint32_t s_remaining = 0U; -static void start_next_chunk(void) { - if (s_remaining == 0U) { - s_output_active = 0U; - tracex_start(); - return; - } - - uint32_t n = - (s_remaining > TRACEOUT_CHUNK_BYTES) ? TRACEOUT_CHUNK_BYTES : s_remaining; - - s_tx_fn(s_dp, (uint16_t)n); - s_dp += n; - s_remaining -= n; +static void start_next_chunk(void) +{ + if (s_remaining == 0U) { + s_output_active = 0U; + tracex_start(); + return; + } + + uint32_t n = (s_remaining > TRACEOUT_CHUNK_BYTES) ? + TRACEOUT_CHUNK_BYTES : + s_remaining; + + s_tx_fn(s_dp, (uint16_t)n); + s_dp += n; + s_remaining -= n; } -void traceout_init(traceout_tx_fn_t tx_fn) { s_tx_fn = tx_fn; } +void traceout_init(traceout_tx_fn_t tx_fn) +{ + s_tx_fn = tx_fn; +} -void traceout_start_from_isr(void) { - if ((s_tx_fn == NULL) || (s_output_active != 0U)) { - return; - } +void traceout_start_from_isr(void) +{ + if ((s_tx_fn == NULL) || (s_output_active != 0U)) { + return; + } - tracex_stop(); + tracex_stop(); - s_dp = tracex_get_buffer(); - s_remaining = tracex_get_buffer_size(); - s_output_active = 1U; + s_dp = tracex_get_buffer(); + s_remaining = tracex_get_buffer_size(); + s_output_active = 1U; - start_next_chunk(); + start_next_chunk(); } -void traceout_on_tx_complete_from_isr(void) { - if (s_output_active != 0U) { - start_next_chunk(); - } +void traceout_on_tx_complete_from_isr(void) +{ + if (s_output_active != 0U) { + start_next_chunk(); + } } \ No newline at end of file diff --git a/threadX/traceX/src/tracex.c b/threadX/traceX/src/tracex.c index 773bf10e..223a7890 100644 --- a/threadX/traceX/src/tracex.c +++ b/threadX/traceX/src/tracex.c @@ -21,31 +21,40 @@ static UCHAR *s_trace_buffer = NULL; static uint32_t s_trace_size = 0U; static bool s_tracex_started = false; -void tracex_init(UCHAR *buffer, uint32_t size) { - s_trace_buffer = buffer; - s_trace_size = size; +void tracex_init(UCHAR *buffer, uint32_t size) +{ + s_trace_buffer = buffer; + s_trace_size = size; } -UCHAR *tracex_get_buffer(void) { return s_trace_buffer; } +UCHAR *tracex_get_buffer(void) +{ + return s_trace_buffer; +} -uint32_t tracex_get_buffer_size(void) { return s_trace_size; } +uint32_t tracex_get_buffer_size(void) +{ + return s_trace_size; +} -void tracex_start(void) { - if ((s_tracex_started == true) || (s_trace_buffer == NULL) || - (s_trace_size == 0U)) { - return; - } +void tracex_start(void) +{ + if ((s_tracex_started == true) || (s_trace_buffer == NULL) || + (s_trace_size == 0U)) { + return; + } - tracex_enable_cycle_counter(); - tx_trace_enable(s_trace_buffer, s_trace_size, 32U); - s_tracex_started = true; + tracex_enable_cycle_counter(); + tx_trace_enable(s_trace_buffer, s_trace_size, 32U); + s_tracex_started = true; } -void tracex_stop(void) { - if (s_tracex_started == false) { - return; - } +void tracex_stop(void) +{ + if (s_tracex_started == false) { + return; + } - tx_trace_disable(); - s_tracex_started = false; + tx_trace_disable(); + s_tracex_started = false; } \ No newline at end of file From a51ce433fb8ab527d7464f4d0acda0fba0938912 Mon Sep 17 00:00:00 2001 From: KSMehta11 Date: Sat, 31 Jan 2026 17:04:52 -0800 Subject: [PATCH 3/4] Add comments --- {threadX/traceX => traceX}/inc/traceout.h | 0 {threadX/traceX => traceX}/inc/tracex.h | 0 {threadX/traceX => traceX}/src/traceout.c | 0 {threadX/traceX => traceX}/src/tracex.c | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename {threadX/traceX => traceX}/inc/traceout.h (100%) rename {threadX/traceX => traceX}/inc/tracex.h (100%) rename {threadX/traceX => traceX}/src/traceout.c (100%) rename {threadX/traceX => traceX}/src/tracex.c (100%) diff --git a/threadX/traceX/inc/traceout.h b/traceX/inc/traceout.h similarity index 100% rename from threadX/traceX/inc/traceout.h rename to traceX/inc/traceout.h diff --git a/threadX/traceX/inc/tracex.h b/traceX/inc/tracex.h similarity index 100% rename from threadX/traceX/inc/tracex.h rename to traceX/inc/tracex.h diff --git a/threadX/traceX/src/traceout.c b/traceX/src/traceout.c similarity index 100% rename from threadX/traceX/src/traceout.c rename to traceX/src/traceout.c diff --git a/threadX/traceX/src/tracex.c b/traceX/src/tracex.c similarity index 100% rename from threadX/traceX/src/tracex.c rename to traceX/src/tracex.c From 6e88d203d6092dae748c6a45d94b078dce8ceada Mon Sep 17 00:00:00 2001 From: KSMehta11 Date: Sun, 1 Feb 2026 13:12:00 -0800 Subject: [PATCH 4/4] Remove cycle counter --- traceX/src/tracex.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/traceX/src/tracex.c b/traceX/src/tracex.c index 223a7890..08732ced 100644 --- a/traceX/src/tracex.c +++ b/traceX/src/tracex.c @@ -7,16 +7,6 @@ #include "tracex.h" #include -/** - * @brief Enable the CPU cycle counter used by TraceX timestamps. - * - * This function is implemented by the application or platform layer. - * It must enable a free-running CPU cycle counter before TraceX is started. - * - * It is called once from tracex_start(). - */ -void tracex_enable_cycle_counter(void); - static UCHAR *s_trace_buffer = NULL; static uint32_t s_trace_size = 0U; static bool s_tracex_started = false; @@ -44,7 +34,6 @@ void tracex_start(void) return; } - tracex_enable_cycle_counter(); tx_trace_enable(s_trace_buffer, s_trace_size, 32U); s_tracex_started = true; }