From 1b5e2fdb36d8176418f0b6fb00aca235c298b003 Mon Sep 17 00:00:00 2001 From: Jakob Gruber Date: Fri, 14 Jun 2013 20:50:31 +0200 Subject: [PATCH] Revert "Merge pull request #12 from ponty/logger2" This reverts commit 4a345c29fe62858693a226a3f6adbef1021236b1, reversing changes made to 77c0525fa53ac81daaf277593767cc5659e2e43e. --- simavr/sim/avr_uart.c | 2 +- simavr/sim/sim_avr.c | 37 +++++++++++-------------------------- simavr/sim/sim_avr.h | 32 ++++++++++++++------------------ simavr/sim/sim_elf.c | 12 ++++++------ 4 files changed, 32 insertions(+), 51 deletions(-) diff --git a/simavr/sim/avr_uart.c b/simavr/sim/avr_uart.c index 149d8b9..f723ee4 100644 --- a/simavr/sim/avr_uart.c +++ b/simavr/sim/avr_uart.c @@ -164,7 +164,7 @@ static void avr_uart_write(struct avr_t * avr, avr_io_addr_t addr, uint8_t v, vo p->stdio_out[p->stdio_len] = 0; if (v == '\n' || p->stdio_len == maxsize) { p->stdio_len = 0; - AVR_LOG(avr, LOG_TRACE, FONT_GREEN "%s\n" FONT_DEFAULT, p->stdio_out); + printf( FONT_GREEN "%s\n" FONT_DEFAULT, p->stdio_out); } } TRACE(printf("UDR%c(%02x) = %02x\n", p->name, addr, v);) diff --git a/simavr/sim/sim_avr.c b/simavr/sim/sim_avr.c index 79560d9..0eb7c9e 100644 --- a/simavr/sim/sim_avr.c +++ b/simavr/sim/sim_avr.c @@ -23,7 +23,6 @@ #include #include #include -#include #include "sim_avr.h" #include "sim_core.h" #include "sim_time.h" @@ -35,9 +34,6 @@ #define AVR_KIND_DECL #include "sim_core_decl.h" -void std_logger(avr_t* avr, const int level, const char * format, ... ); -logger_t global_logger = std_logger; - int avr_init(avr_t * avr) { avr->flash = malloc(avr->flashend + 1); @@ -48,7 +44,7 @@ int avr_init(avr_t * avr) avr->trace_data = calloc(1, sizeof(struct avr_trace_data_t)); #endif - AVR_LOG(avr, LOG_TRACE, "%s init\n", avr->mmcu); + printf("%s init\n", avr->mmcu); // cpu is in limbo before init is finished. avr->state = cpu_Limbo; @@ -87,7 +83,7 @@ void avr_terminate(avr_t * avr) void avr_reset(avr_t * avr) { - AVR_LOG(avr, LOG_TRACE, "%s reset\n", avr->mmcu); + printf("%s reset\n", avr->mmcu); memset(avr->data, 0x0, avr->ramend + 1); _avr_sp_set(avr, avr->ramend); @@ -108,7 +104,7 @@ void avr_reset(avr_t * avr) void avr_sadly_crashed(avr_t *avr, uint8_t signal) { - AVR_LOG(avr, LOG_ERROR, "%s\n", __FUNCTION__); + printf("%s\n", __FUNCTION__); avr->state = cpu_Stopped; if (avr->gdb_port) { // enable gdb server, and wait @@ -121,7 +117,7 @@ void avr_sadly_crashed(avr_t *avr, uint8_t signal) static void _avr_io_command_write(struct avr_t * avr, avr_io_addr_t addr, uint8_t v, void * param) { - AVR_LOG(avr, LOG_TRACE, "%s %02x\n", __FUNCTION__, v); + printf("%s %02x\n", __FUNCTION__, v); switch (v) { case SIMAVR_CMD_VCD_START_TRACE: if (avr->vcd) @@ -135,7 +131,7 @@ static void _avr_io_command_write(struct avr_t * avr, avr_io_addr_t addr, uint8_ avr_irq_t * src = avr_io_getirq(avr, AVR_IOCTL_UART_GETIRQ('0'), UART_IRQ_OUTPUT); avr_irq_t * dst = avr_io_getirq(avr, AVR_IOCTL_UART_GETIRQ('0'), UART_IRQ_INPUT); if (src && dst) { - AVR_LOG(avr, LOG_TRACE, "%s activating uart local echo IRQ src %p dst %p\n", __FUNCTION__, src, dst); + printf("%s activating uart local echo IRQ src %p dst %p\n", __FUNCTION__, src, dst); avr_connect_irq(src, dst); } } break; @@ -156,7 +152,7 @@ static void _avr_io_console_write(struct avr_t * avr, avr_io_addr_t addr, uint8_ if (v == '\r' && buf) { buf[len] = 0; - AVR_LOG(avr, LOG_TRACE, "O:" "%s" "" "\n", buf); + printf("O:" "%s" "" "\n", buf); fflush(stdout); len = 0; return; @@ -178,7 +174,7 @@ void avr_set_console_register(avr_t * avr, avr_io_addr_t addr) void avr_loadcode(avr_t * avr, uint8_t * code, uint32_t size, avr_flashaddr_t address) { if (size > avr->flashend+1) { - AVR_LOG(avr, LOG_ERROR, "avr_loadcode(): Attempted to load code of size %d but flash size is only %d.\n", + fprintf(stderr, "avr_loadcode(): Attempted to load code of size %d but flash size is only %d.\n", size, avr->flashend+1); abort(); } @@ -244,7 +240,7 @@ void avr_callback_run_gdb(avr_t * avr) if (avr->state == cpu_Sleeping) { if (!avr->sreg[S_I]) { if (avr->log) - AVR_LOG(avr, LOG_TRACE, "simavr: sleeping with interrupts off, quitting gracefully\n"); + printf("simavr: sleeping with interrupts off, quitting gracefully\n"); avr->state = cpu_Done; return; } @@ -298,7 +294,7 @@ void avr_callback_run_raw(avr_t * avr) if (avr->state == cpu_Sleeping) { if (!avr->sreg[S_I]) { if (avr->log) - AVR_LOG(avr, LOG_TRACE, "simavr: sleeping with interrupts off, quitting gracefully\n"); + printf("simavr: sleeping with interrupts off, quitting gracefully\n"); avr->state = cpu_Done; return; } @@ -343,23 +339,12 @@ avr_make_mcu_by_name( } } if (!maker) { - AVR_LOG(((avr_t*)0), LOG_ERROR, "%s: AVR '%s' not known\n", __FUNCTION__, name); + fprintf(stderr, "%s: AVR '%s' not known\n", __FUNCTION__, name); return NULL; } avr_t * avr = maker->make(); - AVR_LOG(avr, LOG_TRACE, "Starting %s - flashend %04x ramend %04x e2end %04x\n", avr->mmcu, avr->flashend, avr->ramend, avr->e2end); + printf("Starting %s - flashend %04x ramend %04x e2end %04x\n", avr->mmcu, avr->flashend, avr->ramend, avr->e2end); return avr; } -void std_logger(avr_t* avr, const int level, const char * format, ... ) { - if (!avr || avr->log >= level) - { - va_list args; - va_start(args, format); - vfprintf((level > LOG_ERROR) ? stdout : stderr , format, args); - va_end(args); - } -} - - diff --git a/simavr/sim/sim_avr.h b/simavr/sim/sim_avr.h index 80f7341..db41e41 100644 --- a/simavr/sim/sim_avr.h +++ b/simavr/sim/sim_avr.h @@ -61,6 +61,20 @@ enum { #define AVR_DATA_TO_IO(v) ((v) - 32) #define AVR_IO_TO_DATA(v) ((v) + 32) +/** + * Logging macros and associated log levels. + * The current log level is kept in avr->log. + */ +enum { + LOG_ERROR = 1, + LOG_WARNING, + LOG_TRACE, +}; +#define AVR_LOG(avr, level, ...) \ + do { \ + if (avr->log >= level) \ + fprintf(stdout, __VA_ARGS__); \ + } while(0) /* * Core states. @@ -361,24 +375,6 @@ void avr_callback_run_gdb(avr_t * avr); void avr_callback_sleep_raw(avr_t * avr, avr_cycle_count_t howLong); void avr_callback_run_raw(avr_t * avr); -/** - * Logging macros and associated log levels. - * The current log level is kept in avr->log. - */ -enum { - LOG_ERROR = 1, - LOG_WARNING, - LOG_TRACE, -}; -typedef void (*logger_t)(avr_t* avr, const int level, const char * format, ... ); -extern logger_t global_logger; -#ifndef AVR_LOG -#define AVR_LOG(avr, level, ...) \ - do { \ - global_logger( avr, level, __VA_ARGS__); \ - } while(0) -#endif - #ifdef __cplusplus }; #endif diff --git a/simavr/sim/sim_elf.c b/simavr/sim/sim_elf.c index af4ab2d..3f58825 100644 --- a/simavr/sim/sim_elf.c +++ b/simavr/sim/sim_elf.c @@ -75,7 +75,7 @@ void avr_load_firmware(avr_t * avr, elf_firmware_t * firmware) avr->vcd, firmware->traceperiod >= 1000 ? firmware->traceperiod : 1000); - AVR_LOG(avr, LOG_TRACE, "Creating VCD trace file '%s'\n", avr->vcd->filename); + printf("Creating VCD trace file '%s'\n", avr->vcd->filename); for (int ti = 0; ti < firmware->tracecount; ti++) { if (firmware->trace[ti].mask == 0xff || firmware->trace[ti].mask == 0) { // easy one @@ -153,7 +153,7 @@ static void elf_parse_mmcu_section(elf_firmware_t * firmware, uint8_t * src, uin uint8_t mask = src[0]; uint16_t addr = src[1] | (src[2] << 8); char * name = (char*)src + 3; - AVR_LOG(NULL, LOG_TRACE, "AVR_MMCU_TAG_VCD_TRACE %04x:%02x - %s\n", addr, mask, name); + printf("AVR_MMCU_TAG_VCD_TRACE %04x:%02x - %s\n", addr, mask, name); firmware->trace[firmware->tracecount].mask = mask; firmware->trace[firmware->tracecount].addr = addr; strncpy(firmware->trace[firmware->tracecount].name, name, @@ -187,7 +187,7 @@ int elf_read_firmware(const char * file, elf_firmware_t * firmware) if ((fd = open(file, O_RDONLY | O_BINARY)) == -1 || (read(fd, &elf_header, sizeof(elf_header))) < sizeof(elf_header)) { - AVR_LOG(NULL, LOG_ERROR, "could not read %s\n", file); + printf("could not read %s\n", file); perror(file); close(fd); return -1; @@ -296,12 +296,12 @@ int elf_read_firmware(const char * file, elf_firmware_t * firmware) // hdump("code", data_text->d_buf, data_text->d_size); memcpy(firmware->flash + offset, data_text->d_buf, data_text->d_size); offset += data_text->d_size; - AVR_LOG(NULL, LOG_TRACE, "Loaded %u .text\n", (unsigned int)data_text->d_size); + printf("Loaded %u .text\n", (unsigned int)data_text->d_size); } if (data_data) { // hdump("data", data_data->d_buf, data_data->d_size); memcpy(firmware->flash + offset, data_data->d_buf, data_data->d_size); - AVR_LOG(NULL, LOG_TRACE, "Loaded %u .data\n", (unsigned int)data_data->d_size); + printf("Loaded %u .data\n", (unsigned int)data_data->d_size); offset += data_data->d_size; firmware->datasize = data_data->d_size; } @@ -309,7 +309,7 @@ int elf_read_firmware(const char * file, elf_firmware_t * firmware) // hdump("eeprom", data_ee->d_buf, data_ee->d_size); firmware->eeprom = malloc(data_ee->d_size); memcpy(firmware->eeprom, data_ee->d_buf, data_ee->d_size); - AVR_LOG(NULL, LOG_TRACE, "Loaded %u .eeprom\n", (unsigned int)data_ee->d_size); + printf("Loaded %u .eeprom\n", (unsigned int)data_ee->d_size); firmware->eesize = data_ee->d_size; } // hdump("flash", avr->flash, offset); -- 2.39.5