cores: Now duplicate the global structure
[simavr] / simavr / cores / sim_mega128.c
index bc5a22c..fd617ed 100644 (file)
@@ -43,7 +43,7 @@ void m128_reset(struct avr_t * avr);
 /*
  * 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;
@@ -107,6 +107,8 @@ struct mcu_t {
 
                .txen = AVR_IO_REGBIT(UCSR0B, TXEN0),
                .rxen = AVR_IO_REGBIT(UCSR0B, RXEN0),
+               .ucsz = AVR_IO_REGBITS(UCSR0C, UCSZ00, 0x3), // 2 bits
+               .ucsz2 = AVR_IO_REGBIT(UCSR0B, UCSZ02),         // 1 bits
 
                .r_ucsra = UCSR0A,
                .r_ucsrb = UCSR0B,
@@ -136,6 +138,8 @@ struct mcu_t {
 
                .txen = AVR_IO_REGBIT(UCSR1B, TXEN1),
                .rxen = AVR_IO_REGBIT(UCSR1B, RXEN1),
+               .ucsz = AVR_IO_REGBITS(UCSR1C, UCSZ10, 0x3), // 2 bits
+               .ucsz2 = AVR_IO_REGBIT(UCSR1B, UCSZ12),         // 1 bits
 
                .r_ucsra = UCSR1A,
                .r_ucsrb = UCSR1B,
@@ -251,9 +255,9 @@ struct mcu_t {
                                        AVR_IO_REGBIT(TCCR1B, WGM12), AVR_IO_REGBIT(TCCR1B, WGM13) },
                .wgm_op = {
                        [0] = AVR_TIMER_WGM_NORMAL16(),
-                       // TODO: 1 PWM phase corret 8bit
-                       //               2 PWM phase corret 9bit
-                       //       3 PWM phase corret 10bit
+                       // TODO: 1 PWM phase correct 8bit
+                       //               2 PWM phase correct 9bit
+                       //       3 PWM phase correct 10bit
                        [4] = AVR_TIMER_WGM_CTC(),
                        [5] = AVR_TIMER_WGM_FASTPWM8(),
                        [6] = AVR_TIMER_WGM_FASTPWM9(),
@@ -271,6 +275,9 @@ struct mcu_t {
                .r_icrh = ICR1H,
                .r_tcnth = TCNT1H,
 
+               .ices = AVR_IO_REGBIT(TCCR1B, ICES1),
+               .icp = AVR_IO_REGBIT(PORTD, 4),
+
                .overflow = {
                        .enable = AVR_IO_REGBIT(TIMSK, TOIE1),
                        .raised = AVR_IO_REGBIT(TIFR, TOV1),
@@ -356,15 +363,15 @@ struct mcu_t {
                                        AVR_IO_REGBIT(TCCR3B, WGM32), AVR_IO_REGBIT(TCCR3B, WGM33) },
                .wgm_op = {
                        [0] = AVR_TIMER_WGM_NORMAL16(),
-                       // TODO: 1 PWM phase corret 8bit
-                       //       2 PWM phase corret 9bit
-                       //       3 PWM phase corret 10bit
+                       // TODO: 1 PWM phase correct 8bit
+                       //       2 PWM phase correct 9bit
+                       //       3 PWM phase correct 10bit
                        [4] = AVR_TIMER_WGM_CTC(),
                        [5] = AVR_TIMER_WGM_FASTPWM8(),
                        [6] = AVR_TIMER_WGM_FASTPWM9(),
                        [7] = AVR_TIMER_WGM_FASTPWM10(),
-                       // TODO: 8 PWM phase and freq corret ICR
-                       //       9 PWM phase and freq corret OCR
+                       // TODO: 8 PWM phase and freq correct ICR
+                       //       9 PWM phase and freq correct OCR
                        //       10
                        //       11
                        [12] = AVR_TIMER_WGM_ICCTC(),
@@ -379,6 +386,9 @@ struct mcu_t {
                .r_icrh = ICR3H,
                .r_tcnth = TCNT3H,
 
+               .ices = AVR_IO_REGBIT(TCCR3B, ICES3),
+               .icp = AVR_IO_REGBIT(PORTE, 7),
+
                .overflow = {
                        .enable = AVR_IO_REGBIT(ETIMSK, TOIE3),
                        .raised = AVR_IO_REGBIT(ETIFR, TOV3),
@@ -462,7 +472,7 @@ struct mcu_t {
 
                .twi = {
                        .enable = AVR_IO_REGBIT(TWCR, TWIE),
-                       .raised = AVR_IO_REGBIT(TWSR, TWINT),
+                       .raised = AVR_IO_REGBIT(TWCR, TWINT),
                        .vector = TWI_vect,
                },
        },
@@ -471,7 +481,7 @@ struct mcu_t {
 
 static avr_t * make()
 {
-        return &mcu_mega128.core;
+       return avr_core_allocate(&mcu_mega128.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t mega128 = {