cores: Now duplicate the global structure
[simavr] / simavr / cores / sim_tiny13.c
index 3335c10..71a30a3 100644 (file)
@@ -24,6 +24,8 @@
 #include "sim_avr.h"
 #include "sim_core_declare.h"
 #include "avr_eeprom.h"
+#include "avr_watchdog.h"
+#include "avr_extint.h"
 #include "avr_ioport.h"
 #include "avr_timer.h"
 
@@ -35,9 +37,11 @@ static void init(struct avr_t * avr);
 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;
+       avr_extint_t    extint;
        avr_ioport_t    portb;
        avr_timer_t             timer0;
 } mcu = {
@@ -60,6 +64,13 @@ static struct mcu_t {
                .reset = reset,
        },
        AVR_EEPROM_DECLARE_8BIT(EE_RDY_vect),
+       // tiny13 has different names for these...
+       #define WDIF WDTIF
+       #define WDIE WDTIE
+       AVR_WATCHDOG_DECLARE(WDTCR, WDT_vect),
+       .extint = {
+               AVR_EXTINT_TINY_DECLARE(0, 'B', 1, GIFR),
+       },
        .portb = {
                .name = 'B',  .r_port = PORTB, .r_ddr = DDRB, .r_pin = PINB,
                .pcint = {
@@ -75,14 +86,12 @@ static struct mcu_t {
                .wgm_op = {
                        [0] = AVR_TIMER_WGM_NORMAL8(),
                        [2] = AVR_TIMER_WGM_CTC(),
-                       [3] = AVR_TIMER_WGM_FASTPWM(),
-                       [7] = AVR_TIMER_WGM_FASTPWM(),
+                       [3] = AVR_TIMER_WGM_FASTPWM8(),
+                       [7] = AVR_TIMER_WGM_OCPWM(),
                },
                .cs = { AVR_IO_REGBIT(TCCR0B, CS00), AVR_IO_REGBIT(TCCR0B, CS01), AVR_IO_REGBIT(TCCR0B, CS02) },
                .cs_div = { 0, 0, 3 /* 8 */, 6 /* 64 */, 8 /* 256 */, 10 /* 1024 */ },
 
-               .r_ocra = OCR0A,
-               .r_ocrb = OCR0B,
                .r_tcnt = TCNT0,
 
                .overflow = {
@@ -90,22 +99,30 @@ static struct mcu_t {
                        .raised = AVR_IO_REGBIT(TIFR0, TOV0),
                        .vector = TIM0_OVF_vect,
                },
-               .compa = {
-                       .enable = AVR_IO_REGBIT(TIMSK0, OCIE0A),
-                       .raised = AVR_IO_REGBIT(TIFR0, OCF0A),
-                       .vector = TIM0_COMPA_vect,
-               },
-               .compb = {
-                       .enable = AVR_IO_REGBIT(TIMSK0, OCIE0B),
-                       .raised = AVR_IO_REGBIT(TIFR0, OCF0B),
-                       .vector = TIM0_COMPB_vect,
-               },
-       },
+               .comp = {
+                       [AVR_TIMER_COMPA] = {
+                               .r_ocr = OCR0A,
+                               .interrupt = {
+                                       .enable = AVR_IO_REGBIT(TIMSK0, OCIE0A),
+                                       .raised = AVR_IO_REGBIT(TIFR0, OCF0A),
+                                       .vector = TIM0_COMPA_vect,
+                               }
+                       },
+                       [AVR_TIMER_COMPB] = {
+                               .r_ocr = OCR0B,
+                               .interrupt = {
+                                       .enable = AVR_IO_REGBIT(TIMSK0, OCIE0B),
+                                       .raised = AVR_IO_REGBIT(TIFR0, OCF0B),
+                                       .vector = TIM0_COMPB_vect,
+                               }
+                       }
+               }
+       }
 };
 
 static avr_t * make()
 {
-       return &mcu.core;
+       return avr_core_allocate(&mcu.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t tiny13 = {
@@ -120,6 +137,8 @@ static void init(struct avr_t * avr)
        printf("%s init\n", avr->mmcu);
 
        avr_eeprom_init(avr, &mcu->eeprom);
+       avr_watchdog_init(avr, &mcu->watchdog);
+       avr_extint_init(avr, &mcu->extint);
        avr_ioport_init(avr, &mcu->portb);
        avr_timer_init(avr, &mcu->timer0);
 }