Commit 6a1a04a0a02467797ae7dbecc04b3ffe9452e7b0
authorAndreas Schultes <andreasschultes@users.noreply.github.com>
Mon, 9 Oct 2017 07:59:08 +0000 (09:59 +0200)
committerMichel Pollet <github.com@pollet.net>
Mon, 9 Oct 2017 07:59:08 +0000 (08:59 +0100)
* use only 12 bits for ubrr

* use bitmask for ubrr

* remove r_ubrr_h and r_ubrr_l

3 files changed:
simavr/cores/sim_megaxm1.h
simavr/sim/avr_uart.c
simavr/sim/avr_uart.h

index 6890fb50850cf0d5a1ac2e18676a4cecd5520df2..6af2c1cde9f4a8909d3278eadd3429713952b167 100644 (file)
@@ -137,8 +137,7 @@ const struct mcu_t SIM_CORENAME = {
                        .r_ucsra = 0,
                        .r_ucsrb = 0,
                        .r_ucsrc = 0,
-                       .r_ubrrl = 0,
-                       .r_ubrrh = 0,
+
 
                        .rxc = {
                                .enable = AVR_IO_REGBIT(LINENIR, LENRXOK),
index bde5cc03f8739d0fc3ccd8fb395c6e3f26018a34..4e3db86c610fdbf544fdec79ce16be85867e87eb 100644 (file)
@@ -240,7 +240,7 @@ avr_uart_baud_write(
 {
        avr_uart_t * p = (avr_uart_t *)param;
        avr_core_watch_write(avr, addr, v);
-       uint32_t val = avr->data[p->r_ubrrl] | (avr->data[p->r_ubrrh] << 8);
+       uint32_t val = avr_regbit_get(avr,p->ubrrl) | (avr_regbit_get(avr,p->ubrrh) << 8);
 
        const int databits[] = { 5,6,7,8,  /* 'reserved', assume 8 */8,8,8, 9 };
        int db = databits[avr_regbit_get(avr, p->ucsz) | (avr_regbit_get(avr, p->ucsz2) << 2)];
@@ -548,8 +548,8 @@ avr_uart_init(
                avr_register_io_write(avr, p->udrc.enable.reg, avr_uart_write, p);
        if (p->r_ucsra)
                avr_register_io_write(avr, p->r_ucsra, avr_uart_write, p);
-       if (p->r_ubrrl)
-               avr_register_io_write(avr, p->r_ubrrl, avr_uart_baud_write, p);
+       if (p->ubrrl.reg)
+               avr_register_io_write(avr, p->ubrrl.reg, avr_uart_baud_write, p);
        avr_register_io_write(avr, p->rxen.reg, avr_uart_write, p);
 }
 
index f4803853916e78237e1d16310dc38c13e16c2c53..107359e3a22c05716dfa64646f813a051e845f95 100644 (file)
@@ -111,7 +111,8 @@ typedef struct avr_uart_t {
        avr_regbit_t    upe;            // parity error bit
        avr_regbit_t    rxb8;           // receive data bit 8
 
-       avr_io_addr_t r_ubrrl,r_ubrrh;
+       avr_regbit_t    ubrrl;
+       avr_regbit_t    ubrrh;
 
        avr_int_vector_t rxc;
        avr_int_vector_t txc;
@@ -152,12 +153,13 @@ void avr_uart_init(avr_t * avr, avr_uart_t * port);
                .usbs = AVR_IO_REGBIT(UCSR ## _name ## C, USBS ## _name), \
                .ucsz = AVR_IO_REGBITS(UCSR ## _name ## C, UCSZ ## _name ## 0, 0x3), \
                .ucsz2 = AVR_IO_REGBIT(UCSR ## _name ## B, UCSZ ## _name ## 2), \
-       \
+               .ubrrl = AVR_IO_REGBITS(UBRR ## _name ## L, 0,0xFF), \
+               .ubrrh = AVR_IO_REGBITS(UBRR ## _name ## H, 0,0xF), \
+               \
                .r_ucsra = UCSR ## _name ## A, \
                .r_ucsrb = UCSR ## _name ## B, \
                .r_ucsrc = UCSR ## _name ## C, \
-               .r_ubrrl = UBRR ## _name ## L, \
-               .r_ubrrh = UBRR ## _name ## H, \
+       \
                .rxc = { \
                        .enable = AVR_IO_REGBIT(UCSR ## _name ## B, RXCIE ## _name), \
                        .raised = AVR_IO_REGBIT(UCSR ## _name ## A, RXC ## _name), \
@@ -194,12 +196,13 @@ void avr_uart_init(avr_t * avr, avr_uart_t * port);
                .usbs = AVR_IO_REGBIT(UCSR ## _rname_ix ## C, USBS ## _rname_ix), \
                .ucsz = AVR_IO_REGBITS(UCSR ## _rname_ix ## C, UCSZ ## _rname_ix ## 0, 0x3), \
                .ucsz2 = AVR_IO_REGBIT(UCSR ## _rname_ix ## B, UCSZ ## _rname_ix ## 2), \
+               .ubrrl = AVR_IO_REGBITS(UBRR ## _rname_ix ## L, 0,0xFF), \
+               .ubrrh = AVR_IO_REGBITS(UBRR ## _rname_ix ## H, 0,0xF), \
        \
                .r_ucsra = UCSR ## _rname_ix ## A, \
                .r_ucsrb = UCSR ## _rname_ix ## B, \
                .r_ucsrc = UCSR ## _rname_ix ## C, \
-               .r_ubrrl = UBRR ## _rname_ix ## L, \
-               .r_ubrrh = UBRR ## _rname_ix ## H, \
+       \
                .rxc = { \
                        .enable = AVR_IO_REGBIT(UCSR ## _rname_ix ## B, RXCIE ## _rname_ix), \
                        .raised = AVR_IO_REGBIT(UCSR ## _rname_ix ## A, RXC ## _rname_ix), \