#define __ASSEMBLER__
#include "avr/iousb162.h"
-struct mcu_t {
+const struct mcu_t {
avr_t core;
avr_eeprom_t eeprom;
avr_flash_t selfprog;
static avr_t * make()
{
- return &mcu_usb162.core;
+ return avr_core_allocate(&mcu_usb162.core, sizeof(struct mcu_t));
}
avr_kind_t usb162 = {
/*
* This is a template for all of the 128 devices, hopefuly
*/
-struct mcu_t {
+const struct mcu_t {
avr_t core;
avr_eeprom_t eeprom;
avr_flash_t selfprog;
static avr_t * make()
{
- return &mcu_mega128.core;
+ return avr_core_allocate(&mcu_mega128.core, sizeof(struct mcu_t));
}
avr_kind_t mega128 = {
/*
* This is a template for all of the 1280 devices, hopefully
*/
-struct mcu_t {
+const struct mcu_t {
avr_t core;
avr_eeprom_t eeprom;
avr_flash_t selfprog;
static avr_t * make()
{
- return &mcu_mega1280.core;
+ return avr_core_allocate(&mcu_mega1280.core, sizeof(struct mcu_t));
}
avr_kind_t mega1280 = {
/*
* This is a template for all of the 1281 devices, hopefully
*/
-struct mcu_t {
+const struct mcu_t {
avr_t core;
avr_eeprom_t eeprom;
avr_flash_t selfprog;
static avr_t * make()
{
- return &mcu_mega1281.core;
+ return avr_core_allocate(&mcu_mega1281.core, sizeof(struct mcu_t));
}
avr_kind_t mega1281 = {
static avr_t * make()
{
- return &SIM_CORENAME.core;
+ return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
}
avr_kind_t mega164 = {
static avr_t * make()
{
- return &SIM_CORENAME.core;
+ return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
}
avr_kind_t mega168 = {
static avr_t * make()
{
- return &SIM_CORENAME.core;
+ return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
}
avr_kind_t mega16m1 = {
static avr_t * make()
{
- return &SIM_CORENAME.core;
+ return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
}
avr_kind_t mega324 = {
static avr_t * make()
{
- return &SIM_CORENAME.core;
+ return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
}
avr_kind_t mega328 = {
static avr_t * make()
{
- return &SIM_CORENAME.core;
+ return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
}
avr_kind_t mega48 = {
static avr_t * make()
{
- return &SIM_CORENAME.core;
+ return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
}
avr_kind_t mega644 = {
static avr_t * make()
{
- return &SIM_CORENAME.core;
+ return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
}
avr_kind_t mega8 = {
static avr_t * make()
{
- return &SIM_CORENAME.core;
+ return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
}
avr_kind_t mega88 = {
#define EIMSK GICR
#define EIFR GIFR
-struct mcu_t SIM_CORENAME = {
+const struct mcu_t SIM_CORENAME = {
.core = {
.mmcu = SIM_MMCU,
DEFAULT_CORE(SIM_VECTOR_SIZE),
#error SIM_MMCU is not declared
#endif
-struct mcu_t SIM_CORENAME = {
+const struct mcu_t SIM_CORENAME = {
.core = {
.mmcu = SIM_MMCU,
DEFAULT_CORE(4),
#error SIM_MMCU is not declared
#endif
-struct mcu_t SIM_CORENAME = {
+const struct mcu_t SIM_CORENAME = {
.core = {
.mmcu = SIM_MMCU,
DEFAULT_CORE(SIM_VECTOR_SIZE),
#error SIM_MMCU is not declared
#endif
-struct mcu_t SIM_CORENAME = {
+const struct mcu_t SIM_CORENAME = {
.core = {
.mmcu = SIM_MMCU,
DEFAULT_CORE(SIM_VECTOR_SIZE),
static void reset(struct avr_t * avr);
-static struct mcu_t {
+const static struct mcu_t {
avr_t core;
avr_eeprom_t eeprom;
avr_watchdog_t watchdog;
static avr_t * make()
{
- return &mcu.core;
+ return avr_core_allocate(&mcu.core, sizeof(struct mcu_t));
}
avr_kind_t tiny13 = {
/*
* This is a template for all of the tinyx5 devices, hopefully
*/
-static struct mcu_t {
+const static struct mcu_t {
avr_t core;
avr_eeprom_t eeprom;
avr_watchdog_t watchdog;
static avr_t * make()
{
- return &mcu.core;
+ return avr_core_allocate(&mcu.core, sizeof(struct mcu_t));
}
avr_kind_t tiny2313 = {
static avr_t * make()
{
- return &SIM_CORENAME.core;
+ return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
}
avr_kind_t tiny24 = {
static avr_t * make()
{
- return &SIM_CORENAME.core;
+ return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
}
avr_kind_t tiny25 = {
static avr_t * make()
{
- return &SIM_CORENAME.core;
+ return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
}
avr_kind_t tiny44 = {
static avr_t * make()
{
- return &SIM_CORENAME.core;
+ return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
}
avr_kind_t tiny45 = {
static avr_t * make()
{
- return &SIM_CORENAME.core;
+ return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
}
avr_kind_t tiny84 = {
static avr_t * make()
{
- return &SIM_CORENAME.core;
+ return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
}
avr_kind_t tiny85 = {
#error SIM_MMCU is not declared
#endif
-struct mcu_t SIM_CORENAME = {
+const struct mcu_t SIM_CORENAME = {
.core = {
.mmcu = SIM_MMCU,
DEFAULT_CORE(SIM_VECTOR_SIZE),
#error SIM_MMCU is not declared
#endif
-struct mcu_t SIM_CORENAME = {
+const struct mcu_t SIM_CORENAME = {
.core = {
.mmcu = SIM_MMCU,
DEFAULT_CORE(SIM_VECTOR_SIZE),
return avr->state;
}
-#if 0
-extern avr_kind_t tiny13;
-extern avr_kind_t tiny2313;
-extern avr_kind_t tiny25,tiny45,tiny85;
-extern avr_kind_t tiny24,tiny44,tiny84;
-extern avr_kind_t mega8;
-extern avr_kind_t mega48,mega88,mega168,mega328;
-extern avr_kind_t mega164,mega324,mega644;
-extern avr_kind_t mega128;
-extern avr_kind_t mega1281;
-extern avr_kind_t mega16m1;
-extern avr_kind_t usb162;
-
-avr_kind_t * avr_kind[] = {
- &tiny13,
- &tiny2313,
- &tiny25, &tiny45, &tiny85,
- &tiny24, &tiny44, &tiny84,
- &mega8,
- &mega48, &mega88, &mega168, &mega328,
- &mega164, &mega324, &mega644,
- &mega128,
- &mega1281,
- &mega16m1,
- &usb162,
- NULL
-};
-#endif
+avr_t *
+avr_core_allocate(
+ const avr_t * core,
+ uint32_t coreLen)
+{
+ uint8_t * b = malloc(coreLen);
+ memcpy(b, core, coreLen);
+ return (avr_t *)b;
+}
-avr_t * avr_make_mcu_by_name(const char *name)
+avr_t *
+avr_make_mcu_by_name(
+ const char *name)
{
avr_kind_t * maker = NULL;
for (int i = 0; avr_kind[i] && !maker; i++) {
int
avr_init(
avr_t * avr);
+// Used by the cores, allocated a mutable avr_t from the const global
+avr_t *
+avr_core_allocate(
+ const avr_t * core,
+ uint32_t coreLen);
+
// resets the AVR, and the IO modules
void
avr_reset(