#define AVR_KIND_DECL
#include "sim_core_decl.h"
-void std_logger(const int level, const char * format, ... );
+void std_logger(avr_t* avr, const int level, const char * format, ... );
logger_t global_logger = std_logger;
int avr_init(avr_t * avr)
return avr;
}
-void std_logger(const int level, const char * format, ... ) {
- va_list args;
- va_start(args, format);
- vfprintf((level > LOG_ERROR) ? stdout : stderr , format, args);
- va_end(args);
+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);
+ }
}
#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,
-};
-typedef void (*logger_t)(const int level, const char * format, ... );
-extern logger_t global_logger;
-#ifndef AVR_LOG
-#define AVR_LOG(avr, level, ...) \
- do { \
- if (!avr || avr->log >= level) \
- global_logger( level, __VA_ARGS__); \
- } while(0)
-#endif
/*
* Core states.
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
uint8_t mask = src[0];
uint16_t addr = src[1] | (src[2] << 8);
char * name = (char*)src + 3;
- AVR_LOG(((avr_t*)0), LOG_TRACE, "AVR_MMCU_TAG_VCD_TRACE %04x:%02x - %s\n", addr, mask, name);
+ AVR_LOG(NULL, LOG_TRACE, "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,
if ((fd = open(file, O_RDONLY | O_BINARY)) == -1 ||
(read(fd, &elf_header, sizeof(elf_header))) < sizeof(elf_header)) {
- AVR_LOG(((avr_t*)0), LOG_ERROR, "could not read %s\n", file);
+ AVR_LOG(NULL, LOG_ERROR, "could not read %s\n", file);
perror(file);
close(fd);
return -1;
// 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(((avr_t*)0), LOG_TRACE, "Loaded %u .text\n", (unsigned int)data_text->d_size);
+ AVR_LOG(NULL, LOG_TRACE, "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(((avr_t*)0), LOG_TRACE, "Loaded %u .data\n", (unsigned int)data_data->d_size);
+ AVR_LOG(NULL, LOG_TRACE, "Loaded %u .data\n", (unsigned int)data_data->d_size);
offset += data_data->d_size;
firmware->datasize = data_data->d_size;
}
// 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(((avr_t*)0), LOG_TRACE, "Loaded %u .eeprom\n", (unsigned int)data_ee->d_size);
+ AVR_LOG(NULL, LOG_TRACE, "Loaded %u .eeprom\n", (unsigned int)data_ee->d_size);
firmware->eesize = data_ee->d_size;
}
// hdump("flash", avr->flash, offset);