From: Michel Pollet Date: Thu, 5 Apr 2012 16:46:18 +0000 (+0100) Subject: UART: Added a trace macro X-Git-Url: http://git.rot13.org/?p=simavr;a=commitdiff_plain;h=10b26064e240ee44f238f277eb635b7acb0e1d19 UART: Added a trace macro Replaces the comments Signed-off-by: Michel Pollet --- diff --git a/examples/parts/uart_pty.c b/examples/parts/uart_pty.c index 2f95e60..0eb33f1 100644 --- a/examples/parts/uart_pty.c +++ b/examples/parts/uart_pty.c @@ -35,13 +35,18 @@ DEFINE_FIFO(uint8_t,uart_pty_fifo); +//#define TRACE(_w) _w +#ifndef TRACE +#define TRACE(_w) +#endif + /* * called when a byte is send via the uart on the AVR */ static void uart_pty_in_hook(struct avr_irq_t * irq, uint32_t value, void * param) { uart_pty_t * p = (uart_pty_t*)param; - //printf("uart_pty_in_hook %02x\n", value); + TRACE(printf("uart_pty_in_hook %02x\n", value);) uart_pty_fifo_write(&p->in, value); } @@ -51,7 +56,7 @@ static void uart_pty_flush_incoming(uart_pty_t * p) { while (p->xon && !uart_pty_fifo_isempty(&p->out)) { uint8_t byte = uart_pty_fifo_read(&p->out); - // printf("uart_pty_flush_incoming send %02x\n", byte); + TRACE(printf("uart_pty_flush_incoming send %02x\n", byte);) avr_raise_irq(p->irq + IRQ_UART_PTY_BYTE_OUT, byte); } } @@ -63,8 +68,7 @@ static void uart_pty_flush_incoming(uart_pty_t * p) static void uart_pty_xon_hook(struct avr_irq_t * irq, uint32_t value, void * param) { uart_pty_t * p = (uart_pty_t*)param; - if (!p->xon) - printf("uart_pty_xon_hook\n"); + TRACE(if (!p->xon) printf("uart_pty_xon_hook\n");) p->xon = 1; uart_pty_flush_incoming(p); } @@ -75,8 +79,7 @@ static void uart_pty_xon_hook(struct avr_irq_t * irq, uint32_t value, void * par static void uart_pty_xoff_hook(struct avr_irq_t * irq, uint32_t value, void * param) { uart_pty_t * p = (uart_pty_t*)param; - if (p->xon) - printf("uart_pty_xoff_hook\n"); + TRACE(if (p->xon) printf("uart_pty_xoff_hook\n");) p->xon = 0; } @@ -108,7 +111,7 @@ static void * uart_pty_thread(void * param) ssize_t r = read(p->s, p->buffer, sizeof(p->buffer)-1); p->buffer_len = r; p->buffer_done = 0; - // hdump("pty recv", p->buffer, r); + TRACE(hdump("pty recv", p->buffer, r);) } if (p->buffer_done < p->buffer_len) { // write them in fifo @@ -122,10 +125,10 @@ static void * uart_pty_thread(void * param) while (!uart_pty_fifo_isempty(&p->in) && dst < (buffer+sizeof(buffer))) *dst++ = uart_pty_fifo_read(&p->in); size_t len = dst - buffer; - size_t r = write(p->s, buffer, len); - // hdump("pty send", buffer, r); + TRACE(size_t r =) write(p->s, buffer, len); + TRACE(hdump("pty send", buffer, r);) } - // uart_pty_flush_incoming(p); + uart_pty_flush_incoming(p); } return NULL; } diff --git a/simavr/sim/avr_uart.c b/simavr/sim/avr_uart.c index cfc02d0..9fc5611 100644 --- a/simavr/sim/avr_uart.c +++ b/simavr/sim/avr_uart.c @@ -37,6 +37,11 @@ #include "avr_uart.h" #include "sim_hex.h" +//#define TRACE(_w) _w +#ifndef TRACE +#define TRACE(_w) +#endif + DEFINE_FIFO(uint8_t, uart_fifo); static avr_cycle_count_t avr_uart_txc_raise(struct avr_t * avr, avr_cycle_count_t when, void * param) @@ -103,7 +108,7 @@ static uint8_t avr_uart_read(struct avr_t * avr, avr_io_addr_t addr, void * para } uint8_t v = uart_fifo_read(&p->input); - //printf("UART read %02x %s\n", v, uart_fifo_isempty(&p->input) ? "EMPTY!" : ""); +// TRACE(printf("UART read %02x %s\n", v, uart_fifo_isempty(&p->input) ? "EMPTY!" : "");) avr->data[addr] = v; // made to trigger potential watchpoints v = avr_core_watch_read(avr, addr); @@ -160,7 +165,7 @@ static void avr_uart_write(struct avr_t * avr, avr_io_addr_t addr, uint8_t v, vo printf( FONT_GREEN "%s\n" FONT_DEFAULT, buf); } } - //printf("UDR%c(%02x) = %02x\n", p->name, addr, v); + TRACE(printf("UDR%c(%02x) = %02x\n", p->name, addr, v);) // tell other modules we are "outputing" a byte if (avr_regbit_get(avr, p->txen)) avr_raise_irq(p->io.irq + UART_IRQ_OUTPUT, v); @@ -207,7 +212,7 @@ static void avr_uart_irq_input(struct avr_irq_t * irq, uint32_t value, void * pa avr_cycle_timer_register_usec(avr, p->usec_per_byte, avr_uart_rxc_raise, p); // should be uart speed dependent uart_fifo_write(&p->input, value); // add to fifo - // printf("UART IRQ in %02x (%d/%d) %s\n", value, p->input.read, p->input.write, uart_fifo_isfull(&p->input) ? "FULL!!" : ""); + TRACE(printf("UART IRQ in %02x (%d/%d) %s\n", value, p->input.read, p->input.write, uart_fifo_isfull(&p->input) ? "FULL!!" : "");) if (uart_fifo_isfull(&p->input)) avr_raise_irq(p->io.irq + UART_IRQ_OUT_XOFF, 1);