1 /* 2 * Copyright (c) 2023 Sebastian Bedin <sebabedin@gmail.com>. 3 * Copyright (c) 2026 Martin Javier Klöckner <mklockner@fi.uba.ar> 4 * 5 * See file `LICENSE` for full details 6 */ 7 8 #ifndef INC_LOGGER_H_ 9 #define INC_LOGGER_H_ 10 11 #ifdef __cplusplus 12 extern "C" { 13 #endif 14 15 #include <stdio.h> 16 #include <stdint.h> 17 #include <stdbool.h> 18 #include <string.h> 19 20 #define LOGGER_CONFIG_ENABLE (1) 21 #define LOGGER_CONFIG_MAXLEN (64) 22 #define LOGGER_CONFIG_USE_SEMIHOSTING (1) 23 24 #if 1 == LOGGER_CONFIG_ENABLE 25 #define LOGGER_LOG(...)\ 26 __asm("CPSID i"); /* disable interrupts*/\ 27 {\ 28 logger_msg_len = snprintf(logger_msg, (LOGGER_CONFIG_MAXLEN - 1), __VA_ARGS__);\ 29 logger_log_print_(logger_msg);\ 30 }\ 31 __asm("CPSIE i"); /* enable interrupts*/ 32 #else 33 #define LOGGER_LOG(...) 34 #endif 35 36 #define LOGGER_INFO(...)\ 37 LOGGER_LOG("[INFO] ");\ 38 LOGGER_LOG(__VA_ARGS__);\ 39 LOGGER_LOG("\n"); 40 41 #define LOGGER_ERROR(...)\ 42 LOGGER_LOG("[ERROR] ");\ 43 LOGGER_LOG(__VA_ARGS__);\ 44 LOGGER_LOG("\n"); 45 46 #define GET_NAME(var) #var 47 48 extern char* const logger_msg; 49 extern int logger_msg_len; // only for debug information 50 51 void logger_log_print_(char* const msg); 52 53 #ifdef __cplusplus 54 } 55 #endif 56 57 #endif /* INC_LOGGER_H_ */
