Commit 9903ca718a19106ac341f28e377cd0ba7f6fbb0e
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>
4 files changed:
include/avr_mcu_section.h
simavr/sim/sim_avr.h
simavr/sim/sim_elf.c
simavr/sim/sim_elf.h

index 01118ca73c8202bbe66a976cfffb02e56e2c4c12..bce65e87898775b8e1a6be1788ff953ddec5d991 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 9ef4fcf2c7b0091a109f7fc3fec8771968aed836..8904dfdef53a6409fe0503b581acda8b3e000a4a 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 c6dbca6889ae47d7f83a69c1d6479d7d50b07dbf..6cfa3c49206c55a13818562fbfe0959264b69960 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 085193a99c9ae53299d602be805f136c29cc1c42..53edaebe504ccdb9b8d2dc826a07f1f47ad74b19 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;