simavr icon indicating copy to clipboard operation
simavr copied to clipboard

Add support for ATmega64.

Open melizasw opened this issue 3 years ago • 2 comments

Based on sim_mega128.c as the ATmega64 is essentially a smaller ATmega128. The few differences are show here: https://www.avrfreaks.net/sites/default/files/doc2539.pdf

melizasw avatar Oct 30 '20 02:10 melizasw

Could this had been done the same way as the other "series" instead of duplicating the whole file?

buserror avatar Apr 01 '21 18:04 buserror

Do you mean that I should use files like sim_megax4.h, sim_megax8.h and sim_megax.h? If so, only sim_megax.h is viable as it is the only one with AVR_EEPROM_DECLARE_NOEEPM in it.

However, I can't get it to compile as it sees redefinitions in sim_megax.h for the following that are defined in avr/iom64.h:

#define EICRA MCUCR
#define EIMSK GICR
#define EIFR GIFR 

And if I force my way past that issue I get many other compile errors such as these (this is a small sample):

cores/sim_megax.h:88:35: error: ‘EE_RDY_vect’ undeclared here (not in a function); did you mean ‘EE_READY_vect’?
   88 |         AVR_EEPROM_DECLARE_NOEEPM(EE_RDY_vect),
      |                                   ^~~~~~~~~~~
sim/avr_eeprom.h:101:35: note: in definition of macro ‘AVR_EEPROM_DECLARE_NOEEPM’
  101 |                         .vector = _vector,\
      |                                   ^~~~~~~
In file included from cores/sim_megax.h:27,
                 from cores/sim_mega64.c:32:
cores/sim_megax.h:89:44: error: ‘SPM_RDY_vect’ undeclared here (not in a function); did you mean ‘SPM_READY_vect’?
   89 |         AVR_SELFPROG_DECLARE(SPMCR, SPMEN, SPM_RDY_vect),
      |                                            ^~~~~~~~~~~~
sim/avr_flash.h:71:35: note: in definition of macro ‘AVR_SELFPROG_DECLARE_INTERNAL’
   71 |                         .vector = _vector,\
      |                                   ^~~~~~~

So either it can't be done this way with the existing files or I don't know how to do it this way.

#include "sim_avr.h"

#define SIM_VECTOR_SIZE	4
#define SIM_MMCU		"atmega64"
#define SIM_CORENAME	mcu_mega64

#define _AVR_IO_H_
#define __ASSEMBLER__
#include "avr/iom64.h"
// instantiate the new core
#include "sim_megax.h"

static avr_t * make()
{
	return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
}

avr_kind_t mega64 = {
	.names = { "atmega64" },
	.make = make
};

melizasw avatar Dec 23 '21 02:12 melizasw