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);
}
{
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);
}
}
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);
}
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;
}
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
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;
}
#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)
}
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);
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);
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);