From 3780b775393ccc985c21c997598268e4e6585e5a Mon Sep 17 00:00:00 2001 From: Sympatron GmbH <35803463+Sympatron@users.noreply.github.com> Date: Wed, 30 Oct 2024 17:33:37 +0100 Subject: [PATCH 1/3] Optionally remove dependency on gettimeofday --- src/utils.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/utils.c b/src/utils.c index 272cd38..071ebe1 100644 --- a/src/utils.c +++ b/src/utils.c @@ -148,12 +148,26 @@ int add_iso8601_utc_datetime(char *buf, size_t size) return strftime(buf, size, "%Y-%m-%dT%H:%M:%SZ", &timeinfo); } +#elif defined(NO_OS) + +int add_iso8601_utc_datetime(char *buf, size_t size) +{ + //TODO: Timestamp Generation + ARG_UNUSED(buf); + ARG_UNUSED(size); + return 0; +} + +// Expect user to provide this function +extern int64_t usec_now(); + #else #error Platform test failed #endif +#if !defined(NO_OS) int64_t usec_now() { int64_t usec; @@ -173,6 +187,7 @@ void get_time(uint32_t *seconds, uint32_t *micro_seconds) *seconds = tv.tv_sec; *micro_seconds = tv.tv_usec; } +#endif int64_t usec_since(int64_t last) { @@ -205,6 +220,10 @@ void dump_trace(void) puts(""); free(strings); } +#elif defined(NO_OS) +void dump_trace(void) +{ +} #else void dump_trace(void) { From 631583cab025a79123040ca5796f65156aa942ba Mon Sep 17 00:00:00 2001 From: Sympatron GmbH <35803463+Sympatron@users.noreply.github.com> Date: Wed, 30 Oct 2024 17:34:55 +0100 Subject: [PATCH 2/3] Optionally remove logging to stdout for embedded platforms --- src/logger.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/logger.c b/src/logger.c index e2f8418..3becb45 100644 --- a/src/logger.c +++ b/src/logger.c @@ -42,7 +42,11 @@ logger_t default_logger = { .flags = LOGGER_FLAG_NONE, .log_level = LOG_INFO, .name = "GLOBAL", +#if defined(NO_OS) + .puts = NULL, +#else .puts = puts, +#endif .root_path = NULL, .cb = NULL, }; @@ -59,6 +63,10 @@ static const char *log_level_names[LOG_MAX_LEVEL] = { static inline void logger_log_set_color(logger_t *ctx, const char *color) { +#if defined(NO_OS) + ARG_UNUSED(ctx); + ARG_UNUSED(color); +#else size_t ret, len; if (ctx->flags & LOGGER_FLAG_NO_COLORS) @@ -70,6 +78,7 @@ static inline void logger_log_set_color(logger_t *ctx, const char *color) assert(ret == len); ARG_UNUSED(ret); /* squash warning in Release builds */ } +#endif } static const char *get_tstamp() @@ -134,10 +143,17 @@ int __logger_log(logger_t *ctx, int log_level, const char *file, unsigned long l ctx->cb(log_level, file, line, buf); } else { logger_log_set_color(ctx, log_level_colors[log_level]); +#if defined(NO_OS) + if (ctx->puts) + ctx->puts(buf); + else + return -1; +#else if (ctx->file) fputs(buf, ctx->file); else ctx->puts(buf); +#endif logger_log_set_color(ctx, RESET); } From 84aa08ed7acd2c05d99104039cec2215714959a2 Mon Sep 17 00:00:00 2001 From: Sympatron GmbH <35803463+Sympatron@users.noreply.github.com> Date: Wed, 30 Oct 2024 17:35:30 +0100 Subject: [PATCH 3/3] Use global logger for asserts rather than printf --- include/utils/assert.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/utils/assert.h b/include/utils/assert.h index aa10b90..cafc502 100644 --- a/include/utils/assert.h +++ b/include/utils/assert.h @@ -14,7 +14,7 @@ extern "C" { #endif -#define __ASSERT_PRINT(fmt, ...) printf(fmt, ##__VA_ARGS__) +#define __ASSERT_PRINT(fmt, ...) __logger_log(NULL, LOG_EMERG, __FILE__, __LINE__, fmt, ##__VA_ARGS__) #define __ASSERT_LOC(test) \ __ASSERT_PRINT("ASSERTION FAIL [%s] @ %s:%d\n", \