diff options
author | Karel Kočí <cynerd@email.cz> | 2017-03-08 22:16:16 +0100 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2017-03-08 22:16:16 +0100 |
commit | 171e8e92686ac65e8f9a2962a975e6863c791a4f (patch) | |
tree | 42c8ba7caee8d1e6c67eca533350dd003d47d14f /src | |
parent | fbe0e4d00ba7e026b8b848cfcd0ed583a71f8069 (diff) | |
download | avr-ioe-171e8e92686ac65e8f9a2962a975e6863c791a4f.tar.gz avr-ioe-171e8e92686ac65e8f9a2962a975e6863c791a4f.tar.bz2 avr-ioe-171e8e92686ac65e8f9a2962a975e6863c791a4f.zip |
Shakeout of makefiles and Kconfigs
Diffstat (limited to 'src')
-rw-r--r-- | src/error.c | 2 | ||||
-rw-r--r-- | src/sources.mk | 19 | ||||
-rw-r--r-- | src/usart.c | 136 |
3 files changed, 88 insertions, 69 deletions
diff --git a/src/error.c b/src/error.c index 1c75382..9f4166b 100644 --- a/src/error.c +++ b/src/error.c @@ -24,7 +24,7 @@ void _error(enum ErrorCodes ec) { #ifdef CONFIG_EH_LED // Set led io_setout(CONFIG_EH_LED_IOPIN); - io_hight(CONFIG_EH_LED_IOPIN); + io_high(CONFIG_EH_LED_IOPIN); #endif /* CONFIG_EH_LED */ #ifdef CONFIG_EH_HANGS diff --git a/src/sources.mk b/src/sources.mk new file mode 100644 index 0000000..8616e46 --- /dev/null +++ b/src/sources.mk @@ -0,0 +1,19 @@ +# vim:ts=4:sw=4:sts=4:noexpandtab + +# Essential sources +SRC = base.c + +# IO ports +ifeq (y,$(CONFIG_IOPORTS)) +SRC += ioport.c +endif + +# SPI +ifeq (y,$(CONFIG_SPI)) +SRC += spi.c +endif + +# UART +ifeq (y,$(CONFIG_USART)) +SRC += usart.c +endif diff --git a/src/usart.c b/src/usart.c index 3da91ef..12c1fc7 100644 --- a/src/usart.c +++ b/src/usart.c @@ -11,126 +11,126 @@ volatile int8_t _usart_busy; void usart_init_async(void) { - _usart_busy = 0; + _usart_busy = 0; #define BAUD CONFIG_USART_BAUD #include <util/setbaud.h> - UBRR0H = UBRRH_VALUE; - UBRR0L = UBRRL_VALUE; + UBRR0H = UBRRH_VALUE; + UBRR0L = UBRRL_VALUE; #if USE_2X - UCSR0A |= _BV(U2X0); + UCSR0A |= _BV(U2X0); #else - UCSR0A &= ~_BV(U2X0); + UCSR0A &= ~_BV(U2X0); #endif - UCSR0C = 0 | + UCSR0C = 0 | // USART_PARITY_NONE are both UMP01 and UMP00 zero #if CONFIG_USART_PARITY == USART_PARITY_ODD - _BV(UPM01) | + _BV(UPM01) | #elif CONFIG_USART_PARITY == USART_PARITY_EVEN - _BV(UPM00) | _BV(UPM01) | + _BV(UPM00) | _BV(UPM01) | #endif // USART_STOPBIT_SINGLE is USBS0 zero #if CONFIG_USART_STOPBIT == USART_STOPBIT_DOUBLE - _BV(USBS0) | + _BV(USBS0) | #endif // For 5 databits are UCSZ00 and UCSZ01 zero #if CONFIG_USART_DATABITS == 6 - _BV(UCSZ00) + _BV(UCSZ00) #elif CONFIG_USART_DATABITS == 7 - _BV(UCSZ01) + _BV(UCSZ01) #elif CONFIG_USART_DATABITS == 8 - _BV(UCSZ00) | _BV(UCSZ01) + _BV(UCSZ00) | _BV(UCSZ01) #endif - ; - // Enable receiver, transmitter and RX complete, - // Data register empty interrupts - UCSR0B = _BV(RXEN0) | _BV(TXEN0) | _BV(RXCIE0) | _BV(UDRIE0); + ; + // Enable receiver, transmitter and RX complete, + // Data register empty interrupts + UCSR0B = _BV(RXEN0) | _BV(TXEN0) | _BV(RXCIE0) | _BV(UDRIE0); #ifdef CONFIG_USART_INPUT_BUFFER - IOEBUFFER_INIT(_ioe_usart_inbuffer, CONFIG_USART_INBUFFER_SIZE); + IOEBUFFER_INIT(_ioe_usart_inbuffer, CONFIG_USART_INBUFFER_SIZE); #endif #ifdef CONFIG_USART_OUTPUT_BUFFER - IOEBUFFER_INIT(_ioe_usart_outbuffer, CONFIG_USART_OUTBUFFER_SIZE); + IOEBUFFER_INIT(_ioe_usart_outbuffer, CONFIG_USART_OUTBUFFER_SIZE); #endif } inline void usart_send(uint8_t data) { #ifdef CONFIG_USART_OUTPUT_BUFFER - if (!_usart_busy) { - _usart_busy = 1; - UDR0 = data; - } else { - IOEBUFFER_PUT(_ioe_usart_outbuffer, - CONFIG_USART_OUTBUFFER_SIZE, data, - CONFIG_USART_OUTBUFFER_MODE); - } + if (!_usart_busy) { + _usart_busy = 1; + UDR0 = data; + } else { + IOEBUFFER_PUT(_ioe_usart_outbuffer, + CONFIG_USART_OUTBUFFER_SIZE, data, + CONFIG_USART_OUTBUFFER_MODE); + } #else - _usart_busy = 1; - UDR0 = data; + _usart_busy = 1; + UDR0 = data; #endif /* CONFIG_USART_OUTPUT_BUFFER */ } #ifdef CONFIG_USART_OUTPUT_BUFFER inline void usart_send_str(char *str) { - while (*str != '\0') { - usart_send((uint8_t) * str); - str++; - } + while (*str != '\0') { + usart_send((uint8_t) * str); + str++; + } } #endif /* CONFIG_USART_OUTPUT_BUFFER */ #ifdef CONFIG_USART_INPUT_BUFFER uint8_t usart_get(void) { - uint8_t rtn; - IOEBUFFER_GET(_ioe_usart_inbuffer, CONFIG_USART_INBUFFER_SIZE, - rtn); - return rtn; + uint8_t rtn; + IOEBUFFER_GET(_ioe_usart_inbuffer, CONFIG_USART_INBUFFER_SIZE, + rtn); + return rtn; } #endif #ifdef CONFIG_USART_INPUT_BUFFER uint8_t usart_inbuffered(void) { - uint8_t rtn; - IOEBUFFER_CNT(_ioe_usart_inbuffer, CONFIG_USART_INBUFFER_SIZE, - rtn); - return rtn; + uint8_t rtn; + IOEBUFFER_CNT(_ioe_usart_inbuffer, CONFIG_USART_INBUFFER_SIZE, + rtn); + return rtn; } #endif #ifdef CONFIG_USART_OUTPUT_BUFFER uint8_t usart_outbuffered(void) { - uint8_t rtn; - IOEBUFFER_CNT(_ioe_usart_outbuffer, CONFIG_USART_OUTBUFFER_SIZE, - rtn); - return rtn; + uint8_t rtn; + IOEBUFFER_CNT(_ioe_usart_outbuffer, CONFIG_USART_OUTBUFFER_SIZE, + rtn); + return rtn; } #endif #ifdef CONFIG_USART_OUTFILE static int usartput(char c, FILE * f) { - usart_send((uint8_t) c); - return 0; + usart_send((uint8_t) c); + return 0; } #endif #ifdef CONFIG_USART_INPUT_BUFFER static int usartget(FILE * f) { - uint8_t v; - while (!(v = usart_get())); - return v; + uint8_t v; + while (!(v = usart_get())); + return v; } #endif #if (defined CONFIG_USART_INFILE) || (defined CONFIG_USART_OUTFILE) FILE *usart_async_open(void) { - usart_init_async(); + usart_init_async(); #ifdef CONFIG_USART_OUTFILE #ifdef CONFIG_USART_INFILE - return fdevopen(usartput, usartget); + return fdevopen(usartput, usartget); #else - return fdevopen(usartput, 0); + return fdevopen(usartput, 0); #endif #else - return fdevopen(0, usartget); + return fdevopen(0, usartget); #endif } #endif @@ -141,28 +141,28 @@ void (*usart_sent) (void) = 0; SIGNAL(USART_RX_vect) { #ifdef CONFIG_USART_INPUT_BUFFER - uint8_t val = UDR0; - IOEBUFFER_PUT(_ioe_usart_inbuffer, CONFIG_USART_INBUFFER_SIZE, - val, CONFIG_USART_INBUFFER_MODE); + uint8_t val = UDR0; + IOEBUFFER_PUT(_ioe_usart_inbuffer, CONFIG_USART_INBUFFER_SIZE, + val, CONFIG_USART_INBUFFER_MODE); #endif /* CONFIG_USART_INPUT_BUFFER */ - if (usart_receive) - usart_receive(UDR0); + if (usart_receive) + usart_receive(UDR0); } SIGNAL(USART_UDRE_vect) { #ifdef CONFIG_USART_OUTPUT_BUFFER - uint8_t val; - IOEBUFFER_GET(_ioe_usart_outbuffer, CONFIG_USART_OUTBUFFER_SIZE, - val); - if (val) - UDR0 = val; - else - _usart_busy = 0; + uint8_t val; + IOEBUFFER_GET(_ioe_usart_outbuffer, CONFIG_USART_OUTBUFFER_SIZE, + val); + if (val) + UDR0 = val; + else + _usart_busy = 0; #else - _usart_busy = 0; + _usart_busy = 0; #endif /* CONFIG_USART_OUTPUT_BUFFER */ - if (usart_sent) - usart_sent(); + if (usart_sent) + usart_sent(); } #endif /* CONFIG_USART */ |