diff --git a/fusee/fusee-secondary/src/exception_handlers.c b/fusee/fusee-secondary/src/exception_handlers.c index 16e8c74..42a4651 100644 --- a/fusee/fusee-secondary/src/exception_handlers.c +++ b/fusee/fusee-secondary/src/exception_handlers.c @@ -17,10 +17,9 @@ #include #include "exception_handlers.h" -#include "lib/driver_utils.h" #include "utils.h" #include "display/video_fb.h" -#include "log.h" +#include "lib/log.h" #define CODE_DUMP_SIZE 0x30 #define STACK_DUMP_SIZE 0x60 diff --git a/fusee/fusee-secondary/src/lib/driver_utils.h b/fusee/fusee-secondary/src/lib/driver_utils.h deleted file mode 100644 index 9ea0008..0000000 --- a/fusee/fusee-secondary/src/lib/driver_utils.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2018 Atmosphère-NX - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef FUSEE_DRIVER_UTILS_H -#define FUSEE_DRIVER_UTILS_H - -#include -#include - -#endif diff --git a/fusee/fusee-secondary/src/lib/log.c b/fusee/fusee-secondary/src/lib/log.c new file mode 100644 index 0000000..b4e8782 --- /dev/null +++ b/fusee/fusee-secondary/src/lib/log.c @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2018 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "log.h" + +#include + +/* default log level for screen output */ +ScreenLogLevel g_screen_log_level = SCREEN_LOG_LEVEL_MANDATORY; + +void log_set_log_level(ScreenLogLevel log_level) { + g_screen_log_level = log_level; +} + +void log_to_uart(const char *message) { + /* TODO: add UART logging */ +} + +void print_to_screen(ScreenLogLevel screen_log_level, char *message) { + /* don't print to screen if below log level */ + if(screen_log_level > g_screen_log_level) return; + + printf(message); +} + +/** + * vprintk - logs a message and prints it to screen based on its screen_log_level + * + * If the level is below g_screen_log_level it will not be shown but logged to UART + * This text will not be colored or prefixed + * UART is TODO + */ +void vprint(ScreenLogLevel screen_log_level, const char *fmt, va_list args) +{ + char buf[PRINT_MESSAGE_MAX_LENGTH]; + vsnprintf(buf, PRINT_MESSAGE_MAX_LENGTH, fmt, args); + + /* log to UART */ + log_to_uart(buf); + + print_to_screen(screen_log_level, buf); +} + +void add_prefix(ScreenLogLevel screen_log_level, const char *fmt, char *buf) { + char typebuf[] = "[%s] %s"; + + /* apply prefix and append message format */ + /* TODO: add coloring to the output */ + switch(screen_log_level) + { + case SCREEN_LOG_LEVEL_ERROR: + snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, typebuf, "ERROR", fmt); + break; + case SCREEN_LOG_LEVEL_WARNING: + snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, typebuf, "WARNING", fmt); + break; + case SCREEN_LOG_LEVEL_MANDATORY: + snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, "%s", fmt); + break; + case SCREEN_LOG_LEVEL_INFO: + snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, typebuf, "INFO", fmt); + break; + case SCREEN_LOG_LEVEL_DEBUG: + snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, typebuf, "DEBUG", fmt); + break; + default: + break; + } +} + +/** + * print - logs a message and prints it to screen based on its screen_log_level + * + * If the level is below g_screen_log_level it will not be shown but logged to UART + * Use SCREEN_LOG_LEVEL_NO_PREFIX if you don't want a prefix to be added + * UART is TODO + */ +void print(ScreenLogLevel screen_log_level, const char * fmt, ...) +{ + char buf[PRINT_MESSAGE_MAX_LENGTH] = {}; + char message[PRINT_MESSAGE_MAX_LENGTH] = {}; + + /* TODO: make splash disappear if level > MANDATORY */ + + /* make prefix free messages with log_level possible */ + if(screen_log_level & SCREEN_LOG_LEVEL_NO_PREFIX) { + /* remove the NO_PREFIX flag so the enum can be recognized later on */ + screen_log_level &= ~SCREEN_LOG_LEVEL_NO_PREFIX; + + snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, "%s", fmt); + } + else { + add_prefix(screen_log_level, fmt, buf); + } + + /* input arguments */ + va_list args; + va_start(args, fmt); + vsnprintf(message, PRINT_MESSAGE_MAX_LENGTH, buf, args); + va_end(args); + + /* log to UART */ + log_to_uart(message); + + print_to_screen(screen_log_level, message); +} \ No newline at end of file diff --git a/fusee/fusee-secondary/src/lib/log.h b/fusee/fusee-secondary/src/lib/log.h new file mode 100644 index 0000000..080f34b --- /dev/null +++ b/fusee/fusee-secondary/src/lib/log.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2018 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef FUSEE_SECONDARY_PRINT_H +#define FUSEE_SECONDARY_PRINT_H + +#define PRINT_MESSAGE_MAX_LENGTH 512 + +#include + +typedef enum { + SCREEN_LOG_LEVEL_NONE = 0, + SCREEN_LOG_LEVEL_ERROR = 1, + SCREEN_LOG_LEVEL_WARNING = 2, + SCREEN_LOG_LEVEL_MANDATORY = 3, /* no log prefix */ + SCREEN_LOG_LEVEL_INFO = 4, + SCREEN_LOG_LEVEL_DEBUG = 5, + + SCREEN_LOG_LEVEL_NO_PREFIX = 0x100 /* OR this to your LOG_LEVEL to prevent prefix creation */ +} ScreenLogLevel; + +/* TODO: make this configurable by BCT.ini */ +extern ScreenLogLevel g_screen_log_level; + +void log_set_log_level(ScreenLogLevel screen_log_level); +void log_to_uart(const char *message); +void vprint(ScreenLogLevel screen_log_level, const char *fmt, va_list args); +void print(ScreenLogLevel screen_log_level, const char* fmt, ...); + +#endif \ No newline at end of file diff --git a/fusee/fusee-secondary/src/loader.c b/fusee/fusee-secondary/src/loader.c index 1fc5420..f9a2a7a 100644 --- a/fusee/fusee-secondary/src/loader.c +++ b/fusee/fusee-secondary/src/loader.c @@ -24,7 +24,7 @@ #include "fs_utils.h" #include "stage2.h" #include "lib/ini.h" -#include "log.h" +#include "lib/log.h" static loader_ctx_t g_loader_ctx = {0}; diff --git a/fusee/fusee-secondary/src/log.c b/fusee/fusee-secondary/src/log.c deleted file mode 100644 index 49e9895..0000000 --- a/fusee/fusee-secondary/src/log.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2018 Atmosphère-NX - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include - -#include "log.h" -#include "display/video_fb.h" - -/* default log level for screen output */ -ScreenLogLevel g_screen_log_level = SCREEN_LOG_LEVEL_MANDATORY; - -void log_set_log_level(ScreenLogLevel log_level) { - g_screen_log_level = log_level; -} - -void log_to_uart(const char *message) { - /* TODO: add UART logging */ -} - -void print_to_screen(ScreenLogLevel screen_log_level, char *message) { - /* don't print to screen if below log level */ - if(screen_log_level > g_screen_log_level) return; - - //video_puts(buf); - printf(message); -} - -/** - * vprintk - logs a message and prints it to screen based on its screen_log_level - * - * If the level is below g_screen_log_level it will not be shown but logged to UART - * This text will not be colored or prefixed - * UART is TODO - */ -void vprint(ScreenLogLevel screen_log_level, const char *fmt, va_list args) -{ - char buf[PRINT_MESSAGE_MAX_LENGTH]; - vsnprintf(buf, PRINT_MESSAGE_MAX_LENGTH, fmt, args); - - /* log to UART */ - log_to_uart(buf); - - print_to_screen(screen_log_level, buf); -} - -void add_prefix(ScreenLogLevel screen_log_level, const char *fmt, char *buf) { - char typebuf[] = "[%s] %s"; - - /* apply prefix and append message format */ - /* TODO: add coloring to the output */ - switch(screen_log_level) - { - case SCREEN_LOG_LEVEL_ERROR: - snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, typebuf, "ERROR", fmt); - break; - case SCREEN_LOG_LEVEL_WARNING: - snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, typebuf, "WARNING", fmt); - break; - case SCREEN_LOG_LEVEL_MANDATORY: - snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, "%s", fmt); - break; - case SCREEN_LOG_LEVEL_INFO: - snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, typebuf, "INFO", fmt); - break; - case SCREEN_LOG_LEVEL_DEBUG: - snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, typebuf, "DEBUG", fmt); - break; - default: - break; - } -} - -/** - * print - logs a message and prints it to screen based on its screen_log_level - * - * If the level is below g_screen_log_level it will not be shown but logged to UART - * Use SCREEN_LOG_LEVEL_NO_PREFIX if you don't want a prefix to be added - * UART is TODO - */ -void print(ScreenLogLevel screen_log_level, const char * fmt, ...) -{ - char buf[PRINT_MESSAGE_MAX_LENGTH] = {}; - char message[PRINT_MESSAGE_MAX_LENGTH] = {}; - - /* TODO: make splash disappear if level > MANDATORY */ - - /* make prefix free messages with log_level possible */ - if(screen_log_level & SCREEN_LOG_LEVEL_NO_PREFIX) { - /* remove the NO_PREFIX flag so the enum can be recognized later on */ - screen_log_level &= ~SCREEN_LOG_LEVEL_NO_PREFIX; - - snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, "%s", fmt); - } - else { - add_prefix(screen_log_level, fmt, buf); - } - - /* input arguments */ - va_list args; - va_start(args, fmt); - vsnprintf(message, PRINT_MESSAGE_MAX_LENGTH, buf, args); - va_end(args); - - /* log to UART */ - log_to_uart(message); - - print_to_screen(screen_log_level, message); -} \ No newline at end of file diff --git a/fusee/fusee-secondary/src/log.h b/fusee/fusee-secondary/src/log.h deleted file mode 100644 index 73b7d86..0000000 --- a/fusee/fusee-secondary/src/log.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2018 Atmosphère-NX - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef FUSEE_PRINT_H -#define FUSEE_PRINT_H - -#define PRINT_MESSAGE_MAX_LENGTH 512 - -#include - -typedef enum { - SCREEN_LOG_LEVEL_NONE = 0, - SCREEN_LOG_LEVEL_ERROR = 1, - SCREEN_LOG_LEVEL_WARNING = 2, - SCREEN_LOG_LEVEL_MANDATORY = 3, /* no log prefix */ - SCREEN_LOG_LEVEL_INFO = 4, - SCREEN_LOG_LEVEL_DEBUG = 5, - - SCREEN_LOG_LEVEL_NO_PREFIX = 0x100 /* OR this to your LOG_LEVEL to prevent prefix creation */ -} ScreenLogLevel; - -/* TODO: make this configurable by BCT.ini */ -extern ScreenLogLevel g_screen_log_level; - -void log_set_log_level(ScreenLogLevel screen_log_level); -void log_to_uart(const char *message); -void vprint(ScreenLogLevel screen_log_level, const char *fmt, va_list args); -void print(ScreenLogLevel screen_log_level, const char* fmt, ...); - -#endif \ No newline at end of file diff --git a/fusee/fusee-secondary/src/main.c b/fusee/fusee-secondary/src/main.c index b598093..ec2ea8b 100644 --- a/fusee/fusee-secondary/src/main.c +++ b/fusee/fusee-secondary/src/main.c @@ -33,7 +33,7 @@ #include "gpt.h" #include "display/video_fb.h" #include "sdmmc/sdmmc.h" -#include "log.h" +#include "lib/log.h" extern void (*__program_exit_callback)(int rc); diff --git a/fusee/fusee-secondary/src/nxboot.c b/fusee/fusee-secondary/src/nxboot.c index 3c21786..83fb6ca 100644 --- a/fusee/fusee-secondary/src/nxboot.c +++ b/fusee/fusee-secondary/src/nxboot.c @@ -45,7 +45,7 @@ #define u8 uint8_t #define u32 uint32_t #include "exosphere_bin.h" -#include "log.h" +#include "lib/log.h" #undef u8 #undef u32 diff --git a/fusee/fusee-secondary/src/package2.c b/fusee/fusee-secondary/src/package2.c index 51ec914..7decd95 100644 --- a/fusee/fusee-secondary/src/package2.c +++ b/fusee/fusee-secondary/src/package2.c @@ -27,7 +27,7 @@ #define u8 uint8_t #define u32 uint32_t #include "thermosphere_bin.h" -#include "log.h" +#include "lib/log.h" #undef u8 #undef u32 diff --git a/fusee/fusee-secondary/src/sdmmc/sdmmc.c b/fusee/fusee-secondary/src/sdmmc/sdmmc.c index e4a59c0..3aeb59f 100644 --- a/fusee/fusee-secondary/src/sdmmc/sdmmc.c +++ b/fusee/fusee-secondary/src/sdmmc/sdmmc.c @@ -26,7 +26,6 @@ #include "mmc.h" #include "sd.h" #include "../timers.h" -#include "../lib/driver_utils.h" #define UNSTUFF_BITS(resp,start,size) \ ({ \ diff --git a/fusee/fusee-secondary/src/sdmmc/sdmmc_core.c b/fusee/fusee-secondary/src/sdmmc/sdmmc_core.c index 4a19dc7..56602bc 100644 --- a/fusee/fusee-secondary/src/sdmmc/sdmmc_core.c +++ b/fusee/fusee-secondary/src/sdmmc/sdmmc_core.c @@ -30,8 +30,7 @@ #include "../gpio.h" #include "../pmc.h" #include "../max7762x.h" -#include "../lib/driver_utils.h" -#include "../log.h" +#include "../lib/log.h" static SdmmcLogLevel g_sdmmc_log_level = SDMMC_LOG_NONE; diff --git a/fusee/fusee-secondary/src/utils.c b/fusee/fusee-secondary/src/utils.c index 60bf639..b74e016 100644 --- a/fusee/fusee-secondary/src/utils.c +++ b/fusee/fusee-secondary/src/utils.c @@ -24,7 +24,7 @@ #include "timers.h" #include "btn.h" #include "panic.h" -#include "log.h" +#include "lib/log.h" #include #include