new global_logger, used in AVR_LOG(), default is stdout/stderr
[simavr] / simavr / sim / avr_uart.c
index 5510c02..149d8b9 100644 (file)
@@ -137,11 +137,11 @@ static void avr_uart_baud_write(struct avr_t * avr, avr_io_addr_t addr, uint8_t
        int sb = 1 + avr_regbit_get(avr, p->usbs);
        int word_size = 1 /* start */ + db /* data bits */ + 1 /* parity */ + sb /* stops */;
 
-       printf("UART-%c configured to %04x = %d bps (x%d), %d data %d stop\n",
+       AVR_LOG(avr, LOG_TRACE, "UART: %c configured to %04x = %d bps (x%d), %d data %d stop\n",
                        p->name, val, baud, avr_regbit_get(avr, p->u2x)?2:1, db, sb);
        // TODO: Use the divider value and calculate the straight number of cycles
        p->usec_per_byte = 1000000 / (baud / word_size);
-       printf("Roughly %d usec per bytes\n", (int)p->usec_per_byte);
+       AVR_LOG(avr, LOG_TRACE, "UART: Roughly %d usec per bytes\n", (int)p->usec_per_byte);
 }
 
 static void avr_uart_write(struct avr_t * avr, avr_io_addr_t addr, uint8_t v, void * param)
@@ -164,7 +164,7 @@ static void avr_uart_write(struct avr_t * avr, avr_io_addr_t addr, uint8_t v, vo
                        p->stdio_out[p->stdio_len] = 0;
                        if (v == '\n' || p->stdio_len == maxsize) {
                                p->stdio_len = 0;
-                               printf( FONT_GREEN "%s\n" FONT_DEFAULT, p->stdio_out);
+                               AVR_LOG(avr, LOG_TRACE, FONT_GREEN "%s\n" FONT_DEFAULT, p->stdio_out);
                        }
                }
                TRACE(printf("UDR%c(%02x) = %02x\n", p->name, addr, v);)
@@ -192,9 +192,8 @@ static void avr_uart_write(struct avr_t * avr, avr_io_addr_t addr, uint8_t v, vo
                //uint8_t udre = avr_regbit_get(avr, p->udrc.raised);
                uint8_t txc = avr_regbit_get(avr, p->txc.raised);
 
-               // no need to write this value in here, only the
-               // interrupt flags need clearing!
-               // avr_core_watch_write(avr, addr, v);
+                // required for u2x (double uart transmission speed)
+               avr_core_watch_write(avr, addr, v);
 
                //avr_clear_interrupt_if(avr, &p->udrc, udre);
                avr_clear_interrupt_if(avr, &p->txc, txc);
@@ -232,6 +231,9 @@ void avr_uart_reset(struct avr_io_t *io)
        avr_cycle_timer_cancel(avr, avr_uart_txc_raise, p);
        uart_fifo_reset(&p->input);
 
+        avr_regbit_set(avr, p->ucsz);
+        avr_regbit_clear(avr, p->ucsz2);
+
        // DEBUG allow printf without fiddling with enabling the uart
        avr_regbit_set(avr, p->txen);
        p->usec_per_byte = 100;