core+elf: Add fields for the MCU voltages
authorMichel Pollet <buserror@gmail.com>
Wed, 14 Apr 2010 17:11:49 +0000 (18:11 +0100)
committerMichel Pollet <buserror@gmail.com>
Wed, 14 Apr 2010 17:11:49 +0000 (18:11 +0100)
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 <buserror@gmail.com>
include/avr_mcu_section.h
simavr/sim/sim_avr.h
simavr/sim/sim_elf.c
simavr/sim/sim_elf.h

index 01118ca..bce65e8 100644 (file)
@@ -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__ */
 
 
index 9ef4fcf..8904dfd 100644 (file)
@@ -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"
index c6dbca6..6cfa3c4 100644 (file)
@@ -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);
index 085193a..53edaeb 100644 (file)
@@ -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;