[core] Add macros for wrapping and disabling SDK printf()
This commit is contained in:
@@ -25,7 +25,12 @@ void entry_set_world_flag(void) {
|
||||
#endif // CFG_SUPPORT_BOOTLOADER
|
||||
|
||||
extern void main(void);
|
||||
extern unsigned char __disable_bk_printf;
|
||||
|
||||
#ifdef LIBRETUYA
|
||||
// beken-72xx has printf_port.h
|
||||
extern void __wrap_bk_printf_disable();
|
||||
extern void __wrap_bk_printf_enable();
|
||||
#endif
|
||||
|
||||
void entry_main(void) {
|
||||
// compatibility with BK7231S_1.0.5
|
||||
@@ -33,7 +38,9 @@ void entry_main(void) {
|
||||
entry_set_world_flag();
|
||||
#endif
|
||||
// suppress all output during initialization
|
||||
__disable_bk_printf = 1;
|
||||
#if LIBRETUYA
|
||||
__wrap_bk_printf_disable();
|
||||
#endif
|
||||
// read reboot cause into bk_misc_get_start_type()
|
||||
bk_misc_init_start_type();
|
||||
// clear driver registration arrays
|
||||
@@ -50,7 +57,9 @@ void entry_main(void) {
|
||||
bk_wdg_reload();
|
||||
#endif
|
||||
// enable bk_printf output again
|
||||
__disable_bk_printf = 0;
|
||||
#if LIBRETUYA
|
||||
__wrap_bk_printf_enable();
|
||||
#endif
|
||||
// run the app
|
||||
main();
|
||||
}
|
||||
|
||||
18
platform/beken-72xx/fixups/inc/uart_pub.h
Normal file
18
platform/beken-72xx/fixups/inc/uart_pub.h
Normal file
@@ -0,0 +1,18 @@
|
||||
/* Copyright (c) Kuba Szczodrzyński 2022-06-20. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include_next "uart_pub.h"
|
||||
|
||||
#ifdef LIBRETUYA
|
||||
// make uart.c call __wrap_bk_printf() instead of bk_printf()
|
||||
// standard wrapping does not work in this case, as bk_printf()
|
||||
// is implemented in the same translation unit
|
||||
extern void __wrap_bk_printf(const char *fmt, ...);
|
||||
#undef bk_printf
|
||||
#undef os_printf
|
||||
#undef as_printf
|
||||
// not defining bk_printf() again, as this would just change the impl name
|
||||
#define os_printf __wrap_bk_printf
|
||||
#define as_printf (__wrap_bk_printf("%s:%d\r\n", __FUNCTION__, __LINE__))
|
||||
#endif
|
||||
@@ -1,22 +0,0 @@
|
||||
/* Copyright (c) Kuba Szczodrzyński 2022-06-14. */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
|
||||
extern int __wrap_vsnprintf(char *str, size_t size, const char *format, va_list args);
|
||||
extern void bk_send_string(unsigned char uport, const char *string);
|
||||
extern int uart_print_port;
|
||||
|
||||
unsigned char __disable_bk_printf = 0;
|
||||
|
||||
void __wrap_bk_printf(const char *fmt, ...) {
|
||||
if (__disable_bk_printf)
|
||||
return;
|
||||
va_list ap;
|
||||
char string[128];
|
||||
va_start(ap, fmt);
|
||||
__wrap_vsnprintf(string, sizeof(string) - 1, fmt, ap);
|
||||
string[127] = 0;
|
||||
bk_send_string(uart_print_port, string);
|
||||
va_end(ap);
|
||||
}
|
||||
Reference in New Issue
Block a user