X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=simavr%2Fsim%2Favr_uart.h;h=8db33a074c48a4a1b1d1fdbc83696013849b97b7;hb=26689f832a6bf077f7412d301f60ba615bbc7d50;hp=283f7e062e6c8dd1c09e145f6d1b7b619c828294;hpb=741c561aa23730f12c93e420f80be00072a732cd;p=simavr diff --git a/simavr/sim/avr_uart.h b/simavr/sim/avr_uart.h index 283f7e0..8db33a0 100644 --- a/simavr/sim/avr_uart.h +++ b/simavr/sim/avr_uart.h @@ -19,8 +19,12 @@ along with simavr. If not, see . */ -#ifndef AVR_UART_H_ -#define AVR_UART_H_ +#ifndef __AVR_UART_H__ +#define __AVR_UART_H__ + +#ifdef __cplusplus +extern "C" { +#endif #include "sim_avr.h" @@ -30,15 +34,15 @@ DECLARE_FIFO(uint8_t, uart_fifo, 64); /* * The method of "connecting" the the UART from external code is to use 4 IRQS. - * The easy one is UART->YOU, where you will be called with the byte everytime + * The easy one is UART->YOU, where you will be called with the byte every time * the AVR firmware sends one. Do whatever you like with it. * * The slightly more tricky one is the INPUT part. Since the AVR is quite a bit * slower than your code most likely, there is a way for the AVR UART to tell - * you to "pause" sending it bytes when it's own input buffer is full. - * So, the UART will send XON to you when it's fifo is empty, XON means you can - * send as many bytes as you have until XOFF is send. Note that these are two - * IRQs because you /will/ be caused with XOFF when sending a byte in INPUT... + * you to "pause" sending it bytes when its own input buffer is full. + * So, the UART will send XON to you when its fifo is empty, XON means you can + * send as many bytes as you have until XOFF is sent. Note that these are two + * IRQs because you /will/ be called with XOFF when sending a byte in INPUT... * So it's a reentrant process. * * When XOFF has been called, do not send any new bytes, they would be dropped. @@ -50,13 +54,13 @@ DECLARE_FIFO(uint8_t, uart_fifo, 64); * volatile int off = 0; * void irq_xon() * { - * off = 0; - * while (!off && bytes_lefts) + * off = 0; + * while (!off && bytes_left) * avr_raise_irq(UART_IRQ_INPUT, a_byte); * } * void irq_xoff() * { - * off = 1; + * off = 1; * } * */ @@ -92,6 +96,9 @@ typedef struct avr_uart_t { avr_regbit_t rxen; // receive enabled avr_regbit_t txen; // transmit enable avr_regbit_t u2x; // double UART speed + avr_regbit_t usbs; // stop bits + avr_regbit_t ucsz; // data bits + avr_regbit_t ucsz2; // data bits, continued avr_io_addr_t r_ubrrl,r_ubrrh; @@ -102,6 +109,10 @@ typedef struct avr_uart_t { uart_fifo_t input; 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 */ @@ -110,4 +121,8 @@ typedef struct avr_uart_t { void avr_uart_init(avr_t * avr, avr_uart_t * port); -#endif /* AVR_UART_H_ */ +#ifdef __cplusplus +}; +#endif + +#endif /*__AVR_UART_H__*/