port log.c log.h for fusee-primary

refactor printing
remove lib/printk as it is replaced with log
remove lib/driver_utils.h
added log levels as they seem right, might need adjustments
This commit is contained in:
Resaec 2018-09-26 02:18:50 +02:00
parent d67a7c0a87
commit 81355415d0
No known key found for this signature in database
GPG key ID: 5E890BD898EA9064
12 changed files with 212 additions and 135 deletions

View file

@ -25,7 +25,7 @@
#include "car.h"
#include "btn.h"
#include "lib/printk.h"
#include "lib/log.h"
#include <inttypes.h>
@ -84,11 +84,11 @@ __attribute__ ((noreturn)) void generic_panic(void) {
__attribute__((noreturn)) void fatal_error(const char *fmt, ...) {
va_list args;
printk("Fatal error: ");
print(SCREEN_LOG_LEVEL_ERROR, "Fatal error: ");
va_start(args, fmt);
vprintk(fmt, args);
vprint(SCREEN_LOG_LEVEL_ERROR, fmt, args);
va_end(args);
printk("\nPress POWER to reboot\n");
print(SCREEN_LOG_LEVEL_ERROR | SCREEN_LOG_LEVEL_NO_PREFIX,"\nPress POWER to reboot\n");
wait_for_button_and_reboot();
}
@ -109,27 +109,27 @@ void hexdump(const void* data, size_t size, uintptr_t addrbase) {
for (size_t i = 0; i < size; i++) {
if (i % 16 == 0) {
printk("%0*" PRIXPTR ": | ", 2 * sizeof(addrbase), addrbase + i);
print(SCREEN_LOG_LEVEL_ERROR | SCREEN_LOG_LEVEL_NO_PREFIX, "%0*" PRIXPTR ": | ", 2 * sizeof(addrbase), addrbase + i);
}
printk("%02X ", d[i]);
print(SCREEN_LOG_LEVEL_ERROR | SCREEN_LOG_LEVEL_NO_PREFIX, "%02X ", d[i]);
if (d[i] >= ' ' && d[i] <= '~') {
ascii[i % 16] = d[i];
} else {
ascii[i % 16] = '.';
}
if ((i+1) % 8 == 0 || i+1 == size) {
printk(" ");
print(SCREEN_LOG_LEVEL_ERROR | SCREEN_LOG_LEVEL_NO_PREFIX, " ");
if ((i+1) % 16 == 0) {
printk("| %s \n", ascii);
print(SCREEN_LOG_LEVEL_ERROR | SCREEN_LOG_LEVEL_NO_PREFIX, "| %s \n", ascii);
} else if (i+1 == size) {
ascii[(i+1) % 16] = '\0';
if ((i+1) % 16 <= 8) {
printk(" ");
print(SCREEN_LOG_LEVEL_ERROR | SCREEN_LOG_LEVEL_NO_PREFIX, " ");
}
for (size_t j = (i+1) % 16; j < 16; j++) {
printk(" ");
print(SCREEN_LOG_LEVEL_ERROR | SCREEN_LOG_LEVEL_NO_PREFIX, " ");
}
printk("| %s \n", ascii);
print(SCREEN_LOG_LEVEL_ERROR | SCREEN_LOG_LEVEL_NO_PREFIX, "| %s \n", ascii);
}
}
}