diff options
| author | iabdalkader <i.abdalkader@gmail.com> | 2024-03-21 12:02:24 +0100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2024-03-29 17:58:18 +1100 |
| commit | aa0f3ebe93b7e621a1852da21744d7763db27611 (patch) | |
| tree | aa4bc590b7194f370c1ca94ea8c50ff386459f5d | |
| parent | b82945035954e7f28c64f1f962e17b280cdf7ea5 (diff) | |
extmod/modopenamp: Set a default log handler for ports.
Use the existing metal log handling mechanism instead of overriding the
metal_log, which causes build issues when logging is enabled.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
| -rw-r--r-- | extmod/libmetal/metal/config.h | 7 | ||||
| -rw-r--r-- | extmod/modopenamp.c | 18 |
2 files changed, 17 insertions, 8 deletions
diff --git a/extmod/libmetal/metal/config.h b/extmod/libmetal/metal/config.h index 459a2f4ca..e553f1078 100644 --- a/extmod/libmetal/metal/config.h +++ b/extmod/libmetal/metal/config.h @@ -57,13 +57,6 @@ #define METAL_MAX_DEVICE_REGIONS 1 #endif -// generic/log.h -#if METAL_LOG_HANDLER_ENABLE -#include "py/mphal.h" -#undef metal_log -#define metal_log(level, ...) mp_printf(&mp_plat_print, __VA_ARGS__) -#endif - static inline void *__metal_allocate_memory(unsigned int size) { return m_tracked_calloc(1, size); } diff --git a/extmod/modopenamp.c b/extmod/modopenamp.c index eb19c4b73..1392f5427 100644 --- a/extmod/modopenamp.c +++ b/extmod/modopenamp.c @@ -28,9 +28,11 @@ #if MICROPY_PY_OPENAMP +#include <stdarg.h> #include "py/obj.h" #include "py/nlr.h" #include "py/runtime.h" +#include "py/mpprint.h" #include "metal/sys.h" #include "metal/alloc.h" @@ -315,6 +317,13 @@ static mp_obj_t openamp_new_service_callback(mp_obj_t ns_callback) { } static MP_DEFINE_CONST_FUN_OBJ_1(openamp_new_service_callback_obj, openamp_new_service_callback); +void openamp_metal_log_handler(enum metal_log_level level, const char *fmt, ...) { + va_list args; + va_start(args, fmt); + mp_vprintf(&mp_plat_print, fmt, args); + va_end(args); +} + void openamp_init(void) { if (MP_STATE_PORT(virtio_device) != NULL) { // Already initialized. @@ -322,7 +331,14 @@ void openamp_init(void) { } struct metal_device *device; - struct metal_init_params metal_params = METAL_INIT_DEFAULTS; + struct metal_init_params metal_params = { 0 }; + + #if METAL_LOG_HANDLER_ENABLE + // If logging is enabled, set the default log level and handler before + // calling metal_init, to allow ports to override them in metal_sys_init. + metal_params.log_level = METAL_LOG_DEBUG; + metal_params.log_handler = openamp_metal_log_handler; + #endif // Initialize libmetal. metal_init(&metal_params); |
