diff options
-rw-r--r-- | src/usart.c | 32 | ||||
-rw-r--r-- | usart.h | 11 |
2 files changed, 42 insertions, 1 deletions
diff --git a/src/usart.c b/src/usart.c index 0e17aff..745d75c 100644 --- a/src/usart.c +++ b/src/usart.c @@ -117,7 +117,7 @@ void usart_send_str(char *str) { #ifdef _IOE_USART_INBUFFER uint8_t usart_get(void) { - uint8_t rtn = 0; + uint8_t rtn; IOEBUFFER_GET(_ioe_usart_inbuffer, CONFIG_IOE_USART_INBUFFER_SIZE, rtn); return rtn; @@ -150,6 +150,36 @@ uint8_t usart_outbuffered(void) { } #endif +#ifdef CONFIG_IOE_USART_OUTFILE +static int usartput(char c, FILE * f) { + usart_send((uint8_t) c); + return 0; +} +#endif + +#ifdef CONFIG_IOE_USART_INBUFFER +static int usartget(FILE * f) { + uint8_t v; + while (!(v = usart_get())); + return v; +} +#endif + +#if (defined CONFIG_IOE_USART_INFILE) || (defined CONFIG_IOE_USART_OUTFILE) +FILE *usart_async_open(void) { + usart_init_async(); +#ifdef CONFIG_IOE_USART_OUTFILE +#ifdef CONFIG_IOE_USART_INFILE + return fdevopen(spiput, spiget); +#else + return fdevopen(spiput, 0); +#endif +#else + return fdevopen(0, spiget); +#endif +} +#endif + ////// Interrupts //////////////////////////////// void (*usart_receive) (uint8_t data) = 0; void (*usart_sent) (void) = 0; @@ -1,6 +1,7 @@ #include <avr/io.h> #include <avr/interrupt.h> #include <stdint.h> +#include <stdio.h> #include "mcu/mcu_def.h" #include "buffers.h" @@ -51,6 +52,13 @@ enum usartDataBits { #define USART_DATAOVERRUN _BV(DOR0) #define USART_PARITYERROR _BV(UPE0) +#if (defined CONFIG_IOE_USART_INFILE) && (CONFIG_IOE_USART_INBUFFER_SIZE <= 0) +#error "USART Input file can't be enabled without input buffer" +#endif +#if (defined CONFIG_IOE_USART_OUTFILE) && (CONFIG_IOE_USART_OUTBUFFER_SIZE <= 0) +#error "USART Input file can't be enabled without output buffer" +#endif + #if CONFIG_IOE_USART_INBUFFER_SIZE > 0 #define _IOE_USART_INBUFFER volatile IOEBUFFER(_ioe_usart_inbuffer, CONFIG_IOE_USART_INBUFFER_SIZE); @@ -85,6 +93,9 @@ uint8_t usart_inbuffered(void); #ifdef _IOE_USART_OUTBUFFER uint8_t usart_outbuffered(void); #endif +#if (defined CONFIG_IOE_USART_INFILE) || (defined CONFIG_IOE_USART_OUTFILE) +FILE *spi_open(void); +#endif // Following function must be user defined if relevant buffers not used. extern void (*usart_receive)(uint8_t data); |