diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/error.h | 42 | ||||
-rw-r--r-- | include/mcu/Kconfig | 11 | ||||
-rw-r--r-- | include/mcu/atmega328p.Kconfig | 11 | ||||
-rw-r--r-- | include/mcu/attiny4313.Kconfig | 2 | ||||
-rw-r--r-- | include/mcu/attiny85.Kconfig | 2 | ||||
-rw-r--r-- | include/mcu/mcu.h | 8 | ||||
-rw-r--r-- | include/timer.h | 11 | ||||
-rw-r--r-- | include/utils/buffer.h | 94 |
8 files changed, 116 insertions, 65 deletions
diff --git a/include/error.h b/include/error.h index 7b13bcd..6621633 100644 --- a/include/error.h +++ b/include/error.h @@ -1,3 +1,43 @@ +#include <stdlib.h> #include <stdint.h> -#include <ioport.h> +#ifndef _IOE_ERROR_H_ +#define _IOE_ERROR_H_ +#ifdef CONFIG_ERRORS + +enum ErrorCodes { + EC_OK = 0, // This is not really error code. It triggers error callback but the error function returns + EC_FUNC_ARG, // Invalid argument passed to function + EC_INVALID_PORT, // IO error, requested port is not on your CPU + EC_BUFFER_FULL, // If configured so, full buffer causes this error + _EC_LAST = 128 // Not really error code. This reserver error range for library. User can define its error codes by adding +}; + +#ifdef CONFIG_ERROR_MESSAGES + +void _error(enum ErrorCodes ec, const char *msg); +#define error(EC, MSG) _error(EC, MSG) + +#ifdef CONFIG_ERROR_CALLBACK +void error_callback(enum ErrorCodes ec, const char *msg); +#endif /* CONFIG_ERROR_CALLBACK */ + +#else /* CONFIG_ERROR_MESSAGES*/ + +void _error(enum ErrorCodes ec); +#define error(EC, MSG) _error(EC) + +#ifdef CONFIG_ERROR_CALLBACK +void error_callback(enum ErrorCodes ec); +#endif /* CONFIG_ERROR_CALLBACK */ + +#endif /* CONFIG_ERROR_MESSAGES */ + + +#else /* CONFIG_ERRORS */ + +// Just dummy definition to suppress all errors +#define error(EC, MSG) + +#endif /* CONFIG_ERRORS */ +#endif /* _IOE_ERROR_H_ */ diff --git a/include/mcu/Kconfig b/include/mcu/Kconfig index cecefdf..0468540 100644 --- a/include/mcu/Kconfig +++ b/include/mcu/Kconfig @@ -1,11 +1,12 @@ config MMCU - string - default "atmega328p" if ATMEGA328P - default "attiny85" if ATTINY85 - default "attiny4313" if ATTINY4313 + string + default "atmega328p" if ATMEGA328P + default "atmega168a" if ATMEGA168A + default "attiny85" if ATTINY85 + default "attiny4313" if ATTINY4313 choice MCU - prompt "Microcontroller (MMCU)" + prompt "Microcontroller (MMCU)" source "$IOEROOT/include/mcu/atmega328p.Kconfig" source "$IOEROOT/include/mcu/attiny85.Kconfig" diff --git a/include/mcu/atmega328p.Kconfig b/include/mcu/atmega328p.Kconfig index 5b4bf27..498887f 100644 --- a/include/mcu/atmega328p.Kconfig +++ b/include/mcu/atmega328p.Kconfig @@ -1,5 +1,14 @@ config ATMEGA328P - bool "atmega328p" + bool "ATmega328P" + select MCUSUPPORT_IOPORTS + select MCUSUPPORT_PCINT0 + select MCUSUPPORT_PCINT1 + select MCUSUPPORT_PCINT2 + select MCUSUPPORT_SPI + select MCUSUPPORT_USART + +config ATMEGA168A + bool "ATmega168A" select MCUSUPPORT_IOPORTS select MCUSUPPORT_PCINT0 select MCUSUPPORT_PCINT1 diff --git a/include/mcu/attiny4313.Kconfig b/include/mcu/attiny4313.Kconfig index f685793..bb56684 100644 --- a/include/mcu/attiny4313.Kconfig +++ b/include/mcu/attiny4313.Kconfig @@ -1,5 +1,5 @@ config ATTINY4313 - bool "attiny4313" + bool "ATtiny4313" select MCUSUPPORT_IOPORTS select MCUSUPPORT_PCINT0 select MCUSUPPORT_PCINT1 diff --git a/include/mcu/attiny85.Kconfig b/include/mcu/attiny85.Kconfig index d58c1d8..06d712f 100644 --- a/include/mcu/attiny85.Kconfig +++ b/include/mcu/attiny85.Kconfig @@ -1,4 +1,4 @@ config ATTINY85 - bool "attiny85" + bool "ATtiny85" select MCUSUPPORT_IOPORTS select MCUSUPPORT_PCINT0 diff --git a/include/mcu/mcu.h b/include/mcu/mcu.h index e1272b9..6038103 100644 --- a/include/mcu/mcu.h +++ b/include/mcu/mcu.h @@ -1,8 +1,8 @@ #define __MCU_ATmega328p__ \ ((defined __AVR_ATmega328P__ || defined __AVR_ATmega328__ || \ - defined __AVR_ATmega1688PA__ || defined __AVR_ATmega168A__ || \ - defined __AVR_ATmega88PA__ || defined __AVR_ATmega88A__ || \ - defined __AVR_ATmega48PA__ || defined AVR_ATmega48A__)) + defined __AVR_ATmega1688PA__ || defined __AVR_ATmega168A__ || \ + defined __AVR_ATmega88PA__ || defined __AVR_ATmega88A__ || \ + defined __AVR_ATmega48PA__ || defined AVR_ATmega48A__)) #define __MCU_ATmega32U4__ \ ((defined __AVR_ATmega32U4__ || defined __AVR_ATmega16U4)) @@ -15,4 +15,4 @@ #define __MCU_ATtiny85__ \ ((defined __AVR_ATtiny85__ || defined __AVR_ATtiny45__ || \ - defined __AVR_ATtiny25__)) + defined __AVR_ATtiny25__)) diff --git a/include/timer.h b/include/timer.h index 473110f..c0b9fe8 100644 --- a/include/timer.h +++ b/include/timer.h @@ -1,4 +1,3 @@ -// vim:ts=4:sw=4:sts=4:expandtab #include <avr/io.h> #include <avr/interrupt.h> #include <stdint.h> @@ -11,11 +10,11 @@ #ifdef CONFIG_IOE_TIMERS enum timerDivider { - TIMER_DIVIDER_1, - TIMER_DIVIDER_8, - TIMER_DIVIDER_64, - TIMER_DIVIDER_256, - TIMER_DIVIDER_1024 + TIMER_DIVIDER_1, + TIMER_DIVIDER_8, + TIMER_DIVIDER_64, + TIMER_DIVIDER_256, + TIMER_DIVIDER_1024 }; void timer_init(uint8_t timer, enum timerDivider div); diff --git a/include/utils/buffer.h b/include/utils/buffer.h index 66b68ad..35c281b 100644 --- a/include/utils/buffer.h +++ b/include/utils/buffer.h @@ -3,63 +3,64 @@ // Define new buffer #define IOEBUFFER(type, name, size) struct { \ - uint8_t rindex, windex; \ - type data[size]; \ - } name; + uint8_t rindex, windex; \ + type data[size]; \ + } name; #define IOEBUFFER_INIT(name, size) { \ - name.windex = size - 1; \ - name.rindex = size - 1; \ - } + name.windex = size - 1; \ + name.rindex = size - 1; \ + } #define IOEBUFFER_MODE_BLOCK 0 #define IOEBUFFER_MODE_OVERWRITE 1 #define IOEBUFFER_MODE_DROP 2 +#define IOEBUFFER_MODE_ERROR 3 // Add data to buffer. If buffer is full then behavior is defined by selected mode. -#define IOEBUFFER_PUT(name, size, idata, mode) \ - if (mode == IOEBUFFER_MODE_BLOCK) { \ - if (name.windex == 0) { \ - while (name.rindex == size - 1); \ - } else { \ - while (name.rindex == name.windex - 1); \ - } \ - } \ - name.data[name.windex] = idata; \ - if (mode != IOEBUFFER_MODE_DROP || \ - (name.windex == 0 && name.rindex == size - 1) || \ - (name.rindex + 1 == name.windex)) { \ - if (name.windex == 0) \ - name.windex = size - 1; \ - else \ - name.windex--; \ - } \ - if (mode == IOEBUFFER_MODE_OVERWRITE && name.windex == name.rindex) { \ - if (name.windex == size - 1) \ - name.windex = 0; \ - else \ - name.windex++; \ - } else; +#define IOEBUFFER_PUT(name, size, idata, mode) { \ + if (mode == IOEBUFFER_MODE_BLOCK) { \ + if (name.windex == 0) { \ + while (name.rindex == size - 1); \ + } else { \ + while (name.rindex == name.windex - 1); \ + } \ + } \ + name.data[name.windex] = idata; \ + if (mode != IOEBUFFER_MODE_DROP || \ + (name.windex == 0 && name.rindex == size - 1) || \ + (name.rindex + 1 == name.windex)) { \ + if (name.windex == 0) \ + name.windex = size - 1; \ + else \ + name.windex--; \ + } \ + if (mode == IOEBUFFER_MODE_OVERWRITE && name.windex == name.rindex) { \ + if (name.windex == size - 1) \ + name.windex = 0; \ + else \ + name.windex++; \ + } } // Get data from buffer and store it to variable #define IOEBUFFER_GET(name, size, variable) \ - if (name.rindex != name.windex) { \ - variable = name.data[name.rindex]; \ - if (name.rindex == 0) \ - name.rindex = size - 1; \ - else \ - name.rindex--; \ - } else { \ - variable = 0; \ - } + if (name.rindex != name.windex) { \ + variable = name.data[name.rindex]; \ + if (name.rindex == 0) \ + name.rindex = size - 1; \ + else \ + name.rindex--; \ + } else { \ + variable = 0; \ + } // Set count of buffered data to variable #define IOEBUFFER_CNT(name, size, variable) \ - if (name.windex < name.rindex) \ - variable = name.rindex - name.windex; \ - else if (name.windex > name.rindex) \ - variable = size - name.windex + name.rindex; \ - else \ - variable = 0; + if (name.windex < name.rindex) \ + variable = name.rindex - name.windex; \ + else if (name.windex > name.rindex) \ + variable = size - name.windex + name.rindex; \ + else \ + variable = 0; ///////////////////////////////////////////////////////////////////// @@ -69,10 +70,11 @@ #define IOEBUFFER_F_MODE_BLOCK 0x0 #define IOEBUFFER_F_MODE_OVERWRITE 0x1 #define IOEBUFFER_F_MODE_DROP 0x2 +#define IOEBUFFER_F_MODE_ERROR 0x3 typedef struct { - uint8_t rindex, windex, size, flags; - void **data; + uint8_t rindex, windex, size, flags; + void **data; } IOEBuffer; int8_t ioebuffer_init(IOEBuffer * buf, uint8_t size, uint8_t flags); |