From: Doug Goldstein Date: Sun, 27 Apr 2014 20:30:41 +0000 (-0500) Subject: cores: Fix fuse support to handle proper byte size X-Git-Tag: v1.4~19 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=989158dbf2b4a843e0273c69ff7e3e6d1fbdc335;p=sx%2Fsimavr.git cores: Fix fuse support to handle proper byte size avr-libc specifies platforms with only 6, 3, 2, 1, and 0 bytes of fuses. Previously simavr only had 4 bytes available for fuses and assumed any platform using the CORE_DECLARE macro would have 3 fuses. This change allows the CORE_DECLARE macro to support any of the platforms supported by avr-libc with regard to fuses. Additionally add some defines to make it clear for users of simavr what order the fuses are in. --- diff --git a/simavr/cores/sim_core_declare.h b/simavr/cores/sim_core_declare.h index fa0b8c2..f69e5ca 100644 --- a/simavr/cores/sim_core_declare.h +++ b/simavr/cores/sim_core_declare.h @@ -39,13 +39,45 @@ * This declares a typical AVR core, using constants what appears * to be in every io*.h file... */ +#if FUSE_MEMORY_SIZE == 6 +# ifndef FUSE0_DEFAULT +# define FUSE0_DEFAULT 0xFF +# endif +# ifndef FUSE1_DEFAULT +# define FUSE1_DEFAULT 0xFF +# endif +# ifndef FUSE2_DEFAULT +# define FUSE2_DEFAULT 0xFF +# endif +# ifndef FUSE3_DEFAULT +# define FUSE3_DEFAULT 0xFF +# endif +# ifndef FUSE4_DEFAULT +# define FUSE4_DEFAULT 0xFF +# endif +# ifndef FUSE5_DEFAULT +# define FUSE5_DEFAULT 0xFF +# endif + +# define _FUSE_HELPER { FUSE1_DEFAULT, FUSE1_DEFAULT, FUSE2_DEFAULT, \ + FUSE3_DEFAULT, FUSE4_DEFAULT, FUSE5_DEFAULT } +#elif FUSE_MEMORY_SIZE == 3 +# define _FUSE_HELPER { LFUSE_DEFAULT, HFUSE_DEFAULT, EFUSE_DEFAULT } +#elif FUSE_MEMORY_SIZE == 2 +# define _FUSE_HELPER { LFUSE_DEFAULT, HFUSE_DEFAULT } +#elif FUSE_MEMORY_SIZE == 1 +# define _FUSE_HELPER { FUSE_DEFAULT } +#else +# define _FUSE_HELPER { 0 } +#endif + #ifdef SIGNATURE_0 #define DEFAULT_CORE(_vector_size) \ .ramend = RAMEND, \ .flashend = FLASHEND, \ .e2end = E2END, \ .vector_size = _vector_size, \ - .fuse = { LFUSE_DEFAULT, HFUSE_DEFAULT, EFUSE_DEFAULT }, \ + .fuse = _FUSE_HELPER, \ .signature = { SIGNATURE_0,SIGNATURE_1,SIGNATURE_2 } #else // Disable signature when using an old avr toolchain diff --git a/simavr/sim/sim_avr.h b/simavr/sim/sim_avr.h index 4c433f6..cb12166 100644 --- a/simavr/sim/sim_avr.h +++ b/simavr/sim/sim_avr.h @@ -135,6 +135,10 @@ struct avr_trace_data_t { typedef void (*avr_run_t)( struct avr_t * avr); +#define AVR_FUSE_LOW 0 +#define AVR_FUSE_HIGH 1 +#define AVR_FUSE_EXT 2 + /* * Main AVR instance. Some of these fields are set by the AVR "Core" definition files * the rest is runtime data (as little as possible) @@ -147,7 +151,7 @@ typedef struct avr_t { uint32_t e2end; uint8_t vector_size; uint8_t signature[3]; - uint8_t fuse[4]; + uint8_t fuse[6]; avr_io_addr_t rampz; // optional, only for ELPM/SPM on >64Kb cores avr_io_addr_t eind; // optional, only for EIJMP/EICALL on >64Kb cores uint8_t address_size; // 2, or 3 for cores >128KB in flash