ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_esp_hosted_log.c
Go to the documentation of this file.
1
35
36#include <stdarg.h>
37#include <stddef.h>
38#include <stdint.h>
39
40#include "esp_log.h"
41#include "ra8_attributes.h"
44#include "ra8_esp_hosted_port.h"
46#include "ra8_log.h"
47
79
92
102static const char* const s_ra8_esp_hosted_log_tag = "C6LINK";
103
128static void internal_emit(int level, const char* tag, const char* line)
129{
130 if (level <= (int)ESP_LOG_ERROR) {
131 ra8_log_error(tag, line);
132 } else if (level == (int)ESP_LOG_WARN) {
133 ra8_log_warn(tag, line);
134 } else if (level == (int)ESP_LOG_INFO) {
135 ra8_log_info(tag, line);
136 } else {
137 ra8_log_debug(tag, line);
138 }
139}
140
145{
146 return (level > (int)ESP_LOG_NONE) && (level <= s_ra8_esp_hosted_log_level);
147}
148
152void priv_ra8_esp_hosted_log_vwrite(int level, const char* tag, const char* fmt, va_list ap)
153{
154 if (!priv_ra8_esp_hosted_log_accepts(level) || (fmt == nullptr)) {
155 return;
156 }
157
158 char line[(uint32_t)k_ra8_esp_hosted_log_line_max] = {};
159 (void)priv_ra8_esp_hosted_fmt_vformat(line, (uint32_t)sizeof(line), fmt, ap);
160 internal_emit(level, (tag == nullptr) ? s_ra8_esp_hosted_log_tag : tag, line);
161}
162
165void ra8_esp_hosted_log_write(int level, const char* tag, const char* fmt, ...)
166{
167 va_list ap;
168 va_start(ap, fmt);
169 priv_ra8_esp_hosted_log_vwrite(level, tag, fmt, ap);
170 va_end(ap);
171}
172
175void ra8_esp_hosted_log_hexdump(int level, const char* tag, const void* buf, uint32_t len)
176{
177 if (!priv_ra8_esp_hosted_log_accepts(level) || (buf == nullptr) || (len == 0U)) {
178 return;
179 }
180
181 const uint8_t* bytes = (const uint8_t*)buf;
182 uint32_t shown = len;
183 if (shown > (uint32_t)k_ra8_esp_hosted_log_dump_bytes) {
184 shown = (uint32_t)k_ra8_esp_hosted_log_dump_bytes;
185 }
186
187 char line[(uint32_t)k_ra8_esp_hosted_log_line_max] = {};
188 uint32_t pos = 0U;
189 for (uint32_t i = 0U; i < shown; i++) {
190 char nibbles[(uint32_t)k_ra8_esp_hosted_fmt_digits_max + 2U] = {};
191 const uint8_t digits = priv_ra8_esp_hosted_fmt_utoa(nibbles,
192 (uint64_t)bytes[i],
194 false);
195 if ((pos + (uint32_t)k_ra8_esp_hosted_log_dump_cost) >= sizeof(line)) {
196 break;
197 }
198 if (digits < (uint8_t)k_ra8_esp_hosted_log_dump_nibbles) {
199 line[pos] = '0';
200 pos++;
201 }
202 for (uint8_t d = 0U; d < digits; d++) {
203 line[pos] = nibbles[d];
204 pos++;
205 }
206 line[pos] = ' ';
207 pos++;
208 }
209 line[pos] = '\0';
210
211 internal_emit(level, (tag == nullptr) ? s_ra8_esp_hosted_log_tag : tag, line);
212}
213
217void ra8_esp_hosted_log_level_set(const char* tag, int level)
218{
219 (void)tag;
220 int clamped = level;
221 if (clamped < (int)ESP_LOG_NONE) {
222 clamped = (int)ESP_LOG_NONE;
223 }
224 if (clamped > (int)ESP_LOG_VERBOSE) {
225 clamped = (int)ESP_LOG_VERBOSE;
226 }
228}
229
237
240void ra8_esp_hosted_log_fatal(const char* tag, const char* expr, int code)
241{
242 const char* safe_tag = (tag == nullptr) ? s_ra8_esp_hosted_log_tag : tag;
244 safe_tag,
245 "fatal: %s -> %d",
246 (expr == nullptr) ? "(expr)" : expr,
247 code);
248 /* GCOVR_EXCL_START -- a park loop no host input can leave; entering it in
249 a unit test would hang the suite rather than report anything. */
250 while (true) {
251#ifndef RA8_OFF_TARGET
252 __asm__ volatile("wfi");
253#endif
254 }
255 /* GCOVR_EXCL_STOP */
256}
257
260void ra8_esp_hosted_mem_dump(const char* label)
261{
262 uint32_t available = 0U;
263 uint32_t fragments = 0U;
264 priv_ra8_esp_hosted_rtos_pool_stats(&available, &fragments);
267 "%s: pool free %u bytes in %u fragments",
268 (label == nullptr) ? "(unnamed)" : label,
269 (unsigned int)available,
270 (unsigned int)fragments);
271}
272
275void ra8_esp_hosted_alloc_failed(const char* func, size_t bytes)
276{
279 "%s: pool cannot serve %zu bytes",
280 (func == nullptr) ? "(unnamed)" : func,
281 bytes);
282}
ESP-IDF-compatible logging surface, implemented by this port.
@ ESP_LOG_NONE
Threshold only: suppress every line.
Definition esp_log.h:82
@ ESP_LOG_WARN
Something unexpected that was handled anyway.
Definition esp_log.h:84
@ ESP_LOG_VERBOSE
Per-frame and per-edge tracing.
Definition esp_log.h:87
@ ESP_LOG_INFO
Normal life-cycle milestones.
Definition esp_log.h:85
@ ESP_LOG_ERROR
A fault the caller cannot recover from itself.
Definition esp_log.h:83
Annotation-attribute framework macros for ra8-firmware.
#define RA8_PRIV
Module-private helper: shared across TUs but only inside one library.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
uint8_t priv_ra8_esp_hosted_fmt_utoa(char *buf, uint64_t value, uint8_t base, bool upper)
Implementation of priv_ra8_esp_hosted_fmt_utoa() – divides down and reverses in place,...
uint32_t priv_ra8_esp_hosted_fmt_vformat(char *out, uint32_t cap, const char *fmt, va_list ap)
Implementation of priv_ra8_esp_hosted_fmt_vformat() – single pass, every loop bounded,...
Bounded, heap-free printf-subset formatter for the esp-hosted port.
@ k_ra8_esp_hosted_fmt_digits_max
Widest digit run the supported bases produce, from UINT64_MAX in base ten.
void ra8_esp_hosted_log_fatal(const char *tag, const char *expr, int code)
Implementation of ra8_esp_hosted_log_fatal() – reports and parks; the caller's check already proved t...
void ra8_esp_hosted_log_level_set(const char *tag, int level)
Implementation of ra8_esp_hosted_log_level_set() – one global threshold rather than the per-tag table...
static int s_ra8_esp_hosted_log_level
Runtime verbosity threshold for the esp-hosted bridge.
int priv_ra8_esp_hosted_log_level_get(void)
Implementation of priv_ra8_esp_hosted_log_level_get() – reads the threshold the setter last clamped.
void ra8_esp_hosted_log_write(int level, const char *tag, const char *fmt,...)
Implementation of ra8_esp_hosted_log_write() – the varargs face of priv_ra8_esp_hosted_log_vwrite().
void ra8_esp_hosted_log_hexdump(int level, const char *tag, const void *buf, uint32_t len)
Implementation of ra8_esp_hosted_log_hexdump() – renders at most k_ra8_esp_hosted_log_dump_bytes byte...
void ra8_esp_hosted_mem_dump(const char *label)
Implementation of ra8_esp_hosted_mem_dump() – reads the live ThreadX byte-pool statistics,...
void priv_ra8_esp_hosted_log_vwrite(int level, const char *tag, const char *fmt, va_list ap)
Implementation of priv_ra8_esp_hosted_log_vwrite() – formats onto a bounded stack line,...
bool priv_ra8_esp_hosted_log_accepts(int level)
Implementation of priv_ra8_esp_hosted_log_accepts() – the single runtime level decision,...
static const char *const s_ra8_esp_hosted_log_tag
Fallback tag used when a caller passes none.
ra8_esp_hosted_log_bound_t
Fixed sizes the log bridge works within.
@ k_ra8_esp_hosted_log_dump_cost
Characters one dumped byte costs: two nibbles and a separator.
@ k_ra8_esp_hosted_log_dump_bytes
Bytes of a buffer a single hexdump line renders.
@ k_ra8_esp_hosted_log_line_max
Bytes of stack the formatted line may occupy, terminator included.
void ra8_esp_hosted_alloc_failed(const char *func, size_t bytes)
Implementation of ra8_esp_hosted_alloc_failed() – names the requester and the size,...
static void internal_emit(int level, const char *tag, const char *line)
Hand a finished line to the project logger at the mapped level.
Library-private surface of the esp-hosted logging bridge.
@ k_ra8_esp_hosted_log_dump_nibbles
Digits one byte renders as.
@ k_ra8_esp_hosted_log_dump_radix
Hexadecimal.
Public entry point of the RA8D2 + ThreadX port of esp-hosted.
Module-private contract of the esp-hosted RTOS abstraction slice.
void priv_ra8_esp_hosted_rtos_pool_stats(uint32_t *out_available, uint32_t *out_fragments)
Read live transport-pool occupancy.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_warn(tag, message)
RA8 log warn.
Definition ra8_log.h:347
#define ra8_log_info(tag, message)
RA8 log info.
Definition ra8_log.h:364
#define ra8_log_debug(tag, message)
RA8 log debug.
Definition ra8_log.h:376
#define ra8_log_error(tag, message)
RA8 log error.
Definition ra8_log.h:335