Commit 1b14bdb55e8dd1bdbcc410f16a500802c741741c
authorMichel Pollet <buserror@gmail.com>
Wed, 6 Jun 2012 07:47:20 +0000 (08:47 +0100)
committerMichel Pollet <buserror@gmail.com>
Wed, 6 Jun 2012 07:47:20 +0000 (08:47 +0100)
Thanks to sebastien.besombes@gmail.com for the report

Signed-off-by: Michel Pollet <buserror@gmail.com>
2 files changed:
simavr/sim/avr_uart.c
simavr/sim/avr_uart.h

index 9fc5611c3df5f854117be8645a70b4e7ebc88f19..8adfe546f036cc6f417a04a2640e83968d974364 100644 (file)
@@ -34,6 +34,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <stdint.h>
+#include <stdlib.h>
 #include "avr_uart.h"
 #include "sim_hex.h"
 
@@ -156,13 +157,14 @@ static void avr_uart_write(struct avr_t * avr, avr_io_addr_t addr, uint8_t v, vo
                                p->usec_per_byte, avr_uart_txc_raise, p); // should be uart speed dependent
 
                if (p->flags & AVR_UART_FLAG_STDIO) {
-                       static char buf[128];
-                       static int l = 0;
-                       buf[l++] = v < ' ' ? '.' : v;
-                       buf[l] = 0;
-                       if (v == '\n' || l == 127) {
-                               l = 0;
-                               printf( FONT_GREEN "%s\n" FONT_DEFAULT, buf);
+                       const int maxsize = 256;
+                       if (!p->stdio_out)
+                               p->stdio_out = malloc(maxsize);
+                       p->stdio_out[p->stdio_len++] = v < ' ' ? '.' : v;
+                       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);
                        }
                }
                TRACE(printf("UDR%c(%02x) = %02x\n", p->name, addr, v);)
index dc9e8050973cedda45e5d2935b9a20c2f77b9aa9..933af1154f95be64acebdcc03e9922da402ff24d 100644 (file)
@@ -106,6 +106,9 @@ typedef struct avr_uart_t {
 
        uint32_t                flags;
        avr_cycle_count_t usec_per_byte;
+
+       uint8_t *               stdio_out;
+       int                             stdio_len;      // current size in the stdio output
 } avr_uart_t;
 
 /* takes a uint32_t* as parameter */