From 5d29fe79d30f430ae326d9dc57ccfaed6fe61328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Tue, 8 Mar 2016 16:10:33 +0100 Subject: Another full update of current work --- src/usart.c | 131 +++++++++++++++++++++++++++++------------------------------- 1 file changed, 64 insertions(+), 67 deletions(-) (limited to 'src/usart.c') diff --git a/src/usart.c b/src/usart.c index bba83ac..6cfbc20 100644 --- a/src/usart.c +++ b/src/usart.c @@ -1,7 +1,5 @@ -#include "../usart.h" - -#ifdef CONFIG_IOE_USART -#ifdef MCUSUPPORT_USART +#include +#ifdef CONFIG_USART #define USART_PARITY_NONE 0 #define USART_PARITY_ODD 1 @@ -10,46 +8,46 @@ #define USART_STOPBIT_SINGLE 1 #define USART_STOPBIT_DOUBLE 2 -#ifndef CONFIG_IOE_USART_BAUD -#warning "CONFIG_IOE_USART_BAUD not defined. Setting default 9600." -#define CONFIG_IOE_USART_BAUD 9600 +#ifndef CONFIG_USART_BAUD +#warning "CONFIG_USART_BAUD not defined. Setting default 9600." +#define CONFIG_USART_BAUD 9600 #endif -#ifndef CONFIG_IOE_USART_PARITY -#warning "CONFIG_IOE_USART_PARITY not defined. Using default USART_PARITY_NONE." -#define CONFIG_IOE_USART_PARITY USART_PARITY_NONE +#ifndef CONFIG_USART_PARITY +#warning "CONFIG_USART_PARITY not defined. Using default USART_PARITY_NONE." +#define CONFIG_USART_PARITY USART_PARITY_NONE #endif -#ifndef CONFIG_IOE_USART_STOPBIT -#warning "CONFIG_IOE_USART_STOPBIT not defined. Using default USART_STOPBIT_SINGLE." -#define CONFIG_IOE_USART_STOPBIT USART_STOPBIT_SINGLE +#ifndef CONFIG_USART_STOPBIT +#warning "CONFIG_USART_STOPBIT not defined. Using default USART_STOPBIT_SINGLE." +#define CONFIG_USART_STOPBIT USART_STOPBIT_SINGLE #endif -#ifndef CONFIG_IOE_USART_DATABITS -#warning "CONFIG_IOE_USART_DATABITS not defined. Using default 8." -#define CONFIG_IOE_USART_DATABITS 8 +#ifndef CONFIG_USART_DATABITS +#warning "CONFIG_USART_DATABITS not defined. Using default 8." +#define CONFIG_USART_DATABITS 8 #endif -#if !((CONFIG_IOE_USART_PARITY == USART_PARITY_NONE) || \ - (CONFIG_IOE_USART_PARITY == USART_PARITY_ODD) || \ - (CONFIG_IOE_USART_PARITY == USART_PARITY_EVEN)) -#error "CONFIG_IOE_USART_PARITY has value, that is not allowed." +#if !((CONFIG_USART_PARITY == USART_PARITY_NONE) || \ + (CONFIG_USART_PARITY == USART_PARITY_ODD) || \ + (CONFIG_USART_PARITY == USART_PARITY_EVEN)) +#error "CONFIG_USART_PARITY has value, that is not allowed." #endif -#if !((CONFIG_IOE_USART_STOPBIT == USART_STOPBIT_SINGLE) || \ - (CONFIG_IOE_USART_STOPBIT == USART_STOPBIT_DOUBLE)) -#error "CONFIG_IOE_USART_STOPBIT has value, that is not allowed." +#if !((CONFIG_USART_STOPBIT == USART_STOPBIT_SINGLE) || \ + (CONFIG_USART_STOPBIT == USART_STOPBIT_DOUBLE)) +#error "CONFIG_USART_STOPBIT has value, that is not allowed." #endif -#if !((CONFIG_IOE_USART_DATABITS == 5) || \ - (CONFIG_IOE_USART_DATABITS == 6) || \ - (CONFIG_IOE_USART_DATABITS == 7) || \ - (CONFIG_IOE_USART_DATABITS == 8)) +#if !((CONFIG_USART_DATABITS == 5) || \ + (CONFIG_USART_DATABITS == 6) || \ + (CONFIG_USART_DATABITS == 7) || \ + (CONFIG_USART_DATABITS == 8)) // TODO DATABITS 9 is not supported -#error "CONFIG_IOE_USART_DATABITS has value, that is not allowed." +#error "CONFIG_USART_DATABITS has value, that is not allowed." #endif -#if (defined CONFIG_IOE_USART_INFILE) && (CONFIG_IOE_USART_INBUFFER_SIZE <= 0) +#if (defined CONFIG_USART_INFILE) && (CONFIG_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) +#if (defined CONFIG_USART_OUTFILE) && (CONFIG_USART_OUTBUFFER_SIZE <= 0) #error "USART Input file can't be enabled without output buffer" #endif @@ -58,7 +56,7 @@ volatile int8_t _usart_busy; void usart_init_async(void) { _usart_busy = 0; -#define BAUD CONFIG_IOE_USART_BAUD +#define BAUD CONFIG_USART_BAUD #include UBRR0H = UBRRH_VALUE; UBRR0L = UBRRL_VALUE; @@ -70,95 +68,95 @@ void usart_init_async(void) { UCSR0C = 0 | // USART_PARITY_NONE are both UMP01 and UMP00 zero -#if CONFIG_IOE_USART_PARITY == USART_PARITY_ODD +#if CONFIG_USART_PARITY == USART_PARITY_ODD _BV(UPM01) | -#elif CONFIG_IOE_USART_PARITY == USART_PARITY_EVEN +#elif CONFIG_USART_PARITY == USART_PARITY_EVEN _BV(UPM00) | _BV(UPM01) | #endif // USART_STOPBIT_SINGLE is USBS0 zero -#if CONFIG_IOE_USART_STOPBIT == USART_STOPBIT_DOUBLE +#if CONFIG_USART_STOPBIT == USART_STOPBIT_DOUBLE _BV(USBS0) | #endif // For 5 databits are UCSZ00 and UCSZ01 zero -#if CONFIG_IOE_USART_DATABITS == 6 +#if CONFIG_USART_DATABITS == 6 _BV(UCSZ00) -#elif CONFIG_IOE_USART_DATABITS == 7 +#elif CONFIG_USART_DATABITS == 7 _BV(UCSZ01) -#elif CONFIG_IOE_USART_DATABITS == 8 +#elif CONFIG_USART_DATABITS == 8 _BV(UCSZ00) | _BV(UCSZ01) #endif ; // Enable receiver, transmitter and RX complete, // Data register empty interrupts UCSR0B = _BV(RXEN0) | _BV(TXEN0) | _BV(RXCIE0) | _BV(UDRIE0); -#ifdef _IOE_USART_INBUFFER - IOEBUFFER_INIT(_ioe_usart_inbuffer, CONFIG_IOE_USART_INBUFFER_SIZE); +#ifdef _USART_INBUFFER + IOEBUFFER_INIT(_ioe_usart_inbuffer, CONFIG_USART_INBUFFER_SIZE); #endif -#ifdef _IOE_USART_OUTBUFFER - IOEBUFFER_INIT(_ioe_usart_outbuffer, CONFIG_IOE_USART_OUTBUFFER_SIZE); +#ifdef _USART_OUTBUFFER + IOEBUFFER_INIT(_ioe_usart_outbuffer, CONFIG_USART_OUTBUFFER_SIZE); #endif } inline void usart_send(uint8_t data) { -#ifdef _IOE_USART_OUTBUFFER +#ifdef _USART_OUTBUFFER if (!_usart_busy) { _usart_busy = 1; UDR0 = data; } else { IOEBUFFER_PUT(_ioe_usart_outbuffer, - CONFIG_IOE_USART_OUTBUFFER_SIZE, data, - CONFIG_IOE_USART_OUTBUFFER_MODE); + CONFIG_USART_OUTBUFFER_SIZE, data, + CONFIG_USART_OUTBUFFER_MODE); } #else _usart_busy = 1; UDR0 = data; -#endif /* _IOE_USART_OUTBUFFER */ +#endif /* _USART_OUTBUFFER */ } -#ifdef _IOE_USART_OUTBUFFER +#ifdef _USART_OUTBUFFER inline void usart_send_str(char *str) { while (*str != '\0') { usart_send((uint8_t) * str); str++; } } -#endif /* _IOE_USART_OUTBUFFER */ +#endif /* _USART_OUTBUFFER */ -#ifdef _IOE_USART_INBUFFER +#ifdef _USART_INBUFFER uint8_t usart_get(void) { uint8_t rtn; - IOEBUFFER_GET(_ioe_usart_inbuffer, CONFIG_IOE_USART_INBUFFER_SIZE, + IOEBUFFER_GET(_ioe_usart_inbuffer, CONFIG_USART_INBUFFER_SIZE, rtn); return rtn; } #endif -#ifdef _IOE_USART_INBUFFER +#ifdef _USART_INBUFFER uint8_t usart_inbuffered(void) { uint8_t rtn; - IOEBUFFER_CNT(_ioe_usart_inbuffer, CONFIG_IOE_USART_INBUFFER_SIZE, + IOEBUFFER_CNT(_ioe_usart_inbuffer, CONFIG_USART_INBUFFER_SIZE, rtn); return rtn; } #endif -#ifdef _IOE_USART_OUTBUFFER +#ifdef _USART_OUTBUFFER uint8_t usart_outbuffered(void) { uint8_t rtn; - IOEBUFFER_CNT(_ioe_usart_outbuffer, CONFIG_IOE_USART_OUTBUFFER_SIZE, + IOEBUFFER_CNT(_ioe_usart_outbuffer, CONFIG_USART_OUTBUFFER_SIZE, rtn); return rtn; } #endif -#ifdef CONFIG_IOE_USART_OUTFILE +#ifdef CONFIG_USART_OUTFILE static int usartput(char c, FILE * f) { usart_send((uint8_t) c); return 0; } #endif -#ifdef CONFIG_IOE_USART_INBUFFER +#ifdef CONFIG_USART_INBUFFER static int usartget(FILE * f) { uint8_t v; while (!(v = usart_get())); @@ -166,11 +164,11 @@ static int usartget(FILE * f) { } #endif -#if (defined CONFIG_IOE_USART_INFILE) || (defined CONFIG_IOE_USART_OUTFILE) +#if (defined CONFIG_USART_INFILE) || (defined CONFIG_USART_OUTFILE) FILE *usart_async_open(void) { usart_init_async(); -#ifdef CONFIG_IOE_USART_OUTFILE -#ifdef CONFIG_IOE_USART_INFILE +#ifdef CONFIG_USART_OUTFILE +#ifdef CONFIG_USART_INFILE return fdevopen(usartput, usartget); #else return fdevopen(usartput, 0); @@ -186,19 +184,19 @@ void (*usart_receive) (uint8_t data) = 0; void (*usart_sent) (void) = 0; SIGNAL(USART_RX_vect) { -#ifdef _IOE_USART_INBUFFER +#ifdef _USART_INBUFFER uint8_t val = UDR0; - IOEBUFFER_PUT(_ioe_usart_inbuffer, CONFIG_IOE_USART_INBUFFER_SIZE, - val, CONFIG_IOE_USART_INBUFFER_MODE); -#endif /* _IOE_USART_INBUFFER */ + IOEBUFFER_PUT(_ioe_usart_inbuffer, CONFIG_USART_INBUFFER_SIZE, + val, CONFIG_USART_INBUFFER_MODE); +#endif /* _USART_INBUFFER */ if (usart_receive) usart_receive(UDR0); } SIGNAL(USART_UDRE_vect) { -#ifdef _IOE_USART_OUTBUFFER +#ifdef _USART_OUTBUFFER uint8_t val; - IOEBUFFER_GET(_ioe_usart_outbuffer, CONFIG_IOE_USART_OUTBUFFER_SIZE, + IOEBUFFER_GET(_ioe_usart_outbuffer, CONFIG_USART_OUTBUFFER_SIZE, val); if (val) UDR0 = val; @@ -206,10 +204,9 @@ SIGNAL(USART_UDRE_vect) { _usart_busy = 0; #else _usart_busy = 0; -#endif /* _IOE_USART_OUTBUFFER */ +#endif /* _USART_OUTBUFFER */ if (usart_sent) usart_sent(); } -#endif /* MCUSUPPORT_USART */ -#endif /* CONFIG_IOE_USART */ +#endif /* CONFIG_USART */ -- cgit v1.2.3