From: Michel Pollet Date: Wed, 14 Apr 2010 17:11:49 +0000 (+0100) Subject: core+elf: Add fields for the MCU voltages X-Git-Tag: v1.0a3~9 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=9903ca718a19106ac341f28e377cd0ba7f6fbb0e;p=sx%2Fsimavr.git core+elf: Add fields for the MCU voltages You can now specify AVR_MCU_VOLTAGES(vcc, avcc, aref) in millivolts in your firmware to set them into the simavr core. Prerequisite for ADC VREF support. Signed-off-by: Michel Pollet --- diff --git a/include/avr_mcu_section.h b/include/avr_mcu_section.h index 01118ca..bce65e8 100644 --- a/include/avr_mcu_section.h +++ b/include/avr_mcu_section.h @@ -44,6 +44,9 @@ enum { AVR_MMCU_TAG = 0, AVR_MMCU_TAG_NAME, AVR_MMCU_TAG_FREQUENCY, + AVR_MMCU_TAG_VCC, + AVR_MMCU_TAG_AVCC, + AVR_MMCU_TAG_AREF, AVR_MMCU_TAG_LFUSE, AVR_MMCU_TAG_HFUSE, AVR_MMCU_TAG_EFUSE, @@ -140,6 +143,11 @@ const uint8_t _##_tag _MMCU_ = { _tag, 1, _val } AVR_MCU_STRING(AVR_MMCU_TAG_NAME, _name);\ AVR_MCU_LONG(AVR_MMCU_TAG_FREQUENCY, _speed) +#define AVR_MCU_VOLTAGES(_vcc, _avcc, _aref) \ + AVR_MCU_LONG(AVR_MMCU_TAG_VCC, (_vcc));\ + AVR_MCU_LONG(AVR_MMCU_TAG_AVCC, (_avcc));\ + AVR_MCU_LONG(AVR_MMCU_TAG_AREF, (_aref)); + #endif /* __AVR__ */ diff --git a/simavr/sim/sim_avr.h b/simavr/sim/sim_avr.h index 9ef4fcf..8904dfd 100644 --- a/simavr/sim/sim_avr.h +++ b/simavr/sim/sim_avr.h @@ -86,6 +86,8 @@ typedef struct avr_t { int state; // stopped, running, sleeping uint32_t frequency; // frequency we are running at + // mostly used by the ADC for now + uint32_t vcc,avcc,aref; // (optional) voltages // cycles gets incremented when sleeping and when running; it corresponds // not only to "cycles that runs" but also "cycles that might have run" diff --git a/simavr/sim/sim_elf.c b/simavr/sim/sim_elf.c index c6dbca6..6cfa3c4 100644 --- a/simavr/sim/sim_elf.c +++ b/simavr/sim/sim_elf.c @@ -39,6 +39,9 @@ void avr_load_firmware(avr_t * avr, elf_firmware_t * firmware) { avr->frequency = firmware->frequency; + avr->vcc = firmware->vcc; + avr->avcc = firmware->avcc; + avr->aref = firmware->aref; #if CONFIG_SIMAVR_TRACE avr->codeline = firmware->codeline; #endif @@ -48,6 +51,7 @@ void avr_load_firmware(avr_t * avr, elf_firmware_t * firmware) avr_eeprom_desc_t d = { .ee = firmware->eeprom, .offset = 0, .size = firmware->eesize }; avr_ioctl(avr, AVR_IOCTL_EEPROM_SET, &d); } + avr_set_command_register(avr, firmware->command_register_addr); if (firmware->tracecount == 0) return; @@ -114,6 +118,18 @@ static void elf_parse_mmcu_section(elf_firmware_t * firmware, uint8_t * src, uin case AVR_MMCU_TAG_NAME: strcpy(firmware->mmcu, (char*)src); break; + case AVR_MMCU_TAG_VCC: + firmware->vcc = + src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24); + break; + case AVR_MMCU_TAG_AVCC: + firmware->avcc = + src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24); + break; + case AVR_MMCU_TAG_AREF: + firmware->aref = + src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24); + break; case AVR_MMCU_TAG_VCD_TRACE: { uint8_t mask = src[0]; uint16_t addr = src[1] | (src[2] << 8); diff --git a/simavr/sim/sim_elf.h b/simavr/sim/sim_elf.h index 085193a..53edaeb 100644 --- a/simavr/sim/sim_elf.h +++ b/simavr/sim/sim_elf.h @@ -39,6 +39,7 @@ typedef struct elf_firmware_t { char mmcu[64]; uint32_t frequency; + uint32_t vcc,avcc,aref; char tracename[128]; // trace filename uint32_t traceperiod;