aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitmodules3
-rw-r--r--Kconfig86
-rw-r--r--Makefile16
-rw-r--r--TODO.md7
-rw-r--r--examples/blink/.config2
-rw-r--r--examples/blink/README.md3
-rw-r--r--examples/blink/build/config.h1
-rw-r--r--include/error.h42
-rw-r--r--include/mcu/Kconfig11
-rw-r--r--include/mcu/atmega328p.Kconfig11
-rw-r--r--include/mcu/attiny4313.Kconfig2
-rw-r--r--include/mcu/attiny85.Kconfig2
-rw-r--r--include/mcu/mcu.h8
-rw-r--r--include/timer.h11
-rw-r--r--include/utils/buffer.h94
-rw-r--r--src/error.c40
-rw-r--r--src/ioport.c105
-rw-r--r--src/timer.c156
-rw-r--r--src/utils/buffer.c103
-rw-r--r--template/Makefile16
m---------tests/simavr0
21 files changed, 448 insertions, 271 deletions
diff --git a/.gitmodules b/.gitmodules
index a93346a..a020aca 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -2,6 +2,3 @@
path = tools/kconfig
url = https://github.com/guillon/kconfig.git
ignore = dirty
-[submodule "tests/simavr"]
- path = tests/simavr
- url = https://github.com/buserror/simavr.git
diff --git a/Kconfig b/Kconfig
index 83080bb..5101d01 100644
--- a/Kconfig
+++ b/Kconfig
@@ -8,18 +8,50 @@ source "$IOEROOT/include/mcu/Kconfig"
config F_CPU
int "CPU frequency in kHz (F_CPU)"
default 16000
+ ---help---
+ Frequency CPU is running on. This must be value in kHz.
# Toolchain #####################################################################
menu "Compilation options"
-config GNUTOOLCHAIN_PREFIX
- string "GNU Toolchain prefix"
+config CHOST
+ string "AVR Compilation toolchain prefix (host)"
default "avr-"
+ ---help---
+ Prefix used for all calls to compilation toolchain when compiling for AVR.
-config CONFCFLAGS
- string "Compilation CFlags"
+config CCFLAGS
+ string "AVR compilation flags"
default "-Os -ffunction-sections -fdata-sections -fshort-enums -Wall"
+ ---help---
+ C compilation flags for AVR host. Its suggested to not remove defaults unless
+ you know what they do.
+
+config CLDFLAGS
+ string "AVR linking flags"
+ default ""
+ ---help---
+ C linking flags for AVR host.
+
+config CBUILD
+ string "Building machine compilation toolchain prefix (build)"
+ default ""
+ ---help---
+ Prefix used for all calls to compilation toolchain when compiling applications
+ used for compilation or testing.
+
+config BUILD_CFLAGS
+ string "Bulding machine compilation flags"
+ default "-Wall"
+ ---help---
+ C compilation flags for build.
+
+config BUILD_LDFLAGS
+ string "Building machine linking flags"
+ default ""
+ ---help---
+ C linking flags for build.
endmenu
@@ -28,6 +60,10 @@ endmenu
config CONFIG_ERRORS
bool "Errors support"
default y
+ ---help---
+ This enables error handling. This enables some checks and allows both avr-ioe
+ and you program to react on errors. This doesn't handless hardware errors,
+ only software ones.
if CONFIG_ERRORS
@@ -35,16 +71,25 @@ menu "Errors handling"
config CONFIG_EH_RESTART
bool "Restart MCU on error detection"
- default y
+ default n
+ ---help---
+ CPU is restarted when error is detected. This is suggested in production.
-config CONFIG_EH_MEMORY
- bool "(TODO) Write error code and possible stack trase to EEPROM"
+config CONFIG_EH_HANG
+ bool "Hang execution until manual restart on error detection"
default n
+ ---help---
+ Program hangs execution when error is detected. This is suggested in
+ development.
config CONFIG_EH_LED
bool "Signal error detection by LED"
depends on CONFIG_IOPORTS
default n
+ ---help---
+ When error is detected, specified output is pulled up. This is handy with
+ CONFIG_EH_HANG. If you use this with CONFIG_EH_RESTART you will probably
+ miss led blink.
config CONFIG_EH_LED_IOPIN
string "Error detection led output pin"
@@ -55,16 +100,29 @@ config CONFIG_EH_LED_IOPIN
This string should be valid IO port (for example "IO_B0") or pair of group
mask divided by comma (for example "IO_B, _BV(0)").
-config CONFIG_EH_USART
- bool "Send error informations by UART"
- depends on CONFIG_USART && CONFIG_USART_OUTPUT_BUFFER
+endmenu
+
+config CONFIG_ERROR_MESSAGES
+ bool "Build with error messages"
default n
+ ---help---
+ If errors should support messages. Compiling error messages to code can be
+ handy to finding out errors, but also makes program unnecessary big.
-endmenu
+config CONFIG_ERROR_CALLBACK
+ bool "User program implements callback to be used to optionally resolve error"
+ default n
+ ---help---
+ This allows user program to define error callback to be called just after
+ error is detected. This also can suppress error, but that is dangerous and
+ should be used only with deep understanding of what it means.
config CONFIG_CHECK_ARGUMENTS
bool "Check arguments for all functions in library"
default n
+ ---help---
+ If arguments passed to functions in library should be checked and
+ possibly error should be risen.
endif
@@ -169,6 +227,9 @@ config USART_OUTBUFFER_MODE_C_OVERWRITE
bool "Overwrite"
config USART_OUTBUFFER_MODE_C_DROP
bool "Drop"
+config USART_OUTBUFFER_MODE_C_ERROR
+ depends on CONFIG_ERRORS
+ bool "Error"
endchoice
config CONFIG_USART_OUTBUFFER_MODE
int
@@ -193,6 +254,9 @@ config USART_INBUFFER_MODE_C_OVERWRITE
bool "Overwrite"
config USART_INBUFFER_MODE_C_DROP
bool "Drop"
+config USART_INBUFFER_MODE_C_ERROR
+ depends on CONFIG_ERRORS
+ bool "Error"
endchoice
config CONFIG_USART_INBUFFER_MODE
int
diff --git a/Makefile b/Makefile
index b71c4bf..13d281b 100644
--- a/Makefile
+++ b/Makefile
@@ -43,11 +43,11 @@ DEP = $(patsubst %.c,$(O)/build/%.d,$(SRC))
-include $(DEP)
-CFLAGS = $(shell echo $(CONFCFLAGS)) $(shell echo -DF_CPU=$(F_CPU)000L) \
+CFLAGS = $(shell echo $(CCFLAGS)) $(shell echo -DF_CPU=$(F_CPU)000L) \
-mmcu=$(MMCU) -Iinclude -imacros $(O)/build/config.h
-GCC = $(GNUTOOLCHAIN_PREFIX)gcc
-AR = $(GNUTOOLCHAIN_PREFIX)ar
-CPP = $(GNUTOOLCHAIN_PREFIX)cpp
+CC = $(CHOST)gcc
+AR = $(CHOST)ar
+CPP = $(CHOST)cpp
$(O)/libioe.a: $(OBJ)
@echo " AR $@"
@@ -56,7 +56,7 @@ $(O)/libioe.a: $(OBJ)
$(OBJ): $(O)/build/%.o: src/%.c
@mkdir -p "$(@D)"
@echo " CC $@"
- $(Q)$(GCC) $(CFLAGS) -c -o $@ $<
+ $(Q)$(CC) $(CFLAGS) -c -o $@ $<
$(DEP): $(O)/build/%.d: src/%.c $(O)/build/config.h
@mkdir -p "$(@D)"
@@ -97,10 +97,10 @@ serve-docs:
.PHONY: clean-docs
clean-docs:
@echo " CLEAN docs"
- $(Q)$(RM) -r site
+ $(Q)$(RM) -r html
-.PHONY: distclean
-distclean: clean clean-docs
+.PHONY: proper
+proper: clean clean-docs
@echo " CLEAN CONFIG"
$(Q)$(RM) $(CONFIG) $(CONFIG).orig
diff --git a/TODO.md b/TODO.md
new file mode 100644
index 0000000..6d0d095
--- /dev/null
+++ b/TODO.md
@@ -0,0 +1,7 @@
+### Error handling
+* Print error to UART
+* Save error to eeprom
+* Dump state to UART
+
+### Long term
+* Implement tasks and jobs
diff --git a/examples/blink/.config b/examples/blink/.config
index 52dfc53..9023cfc 100644
--- a/examples/blink/.config
+++ b/examples/blink/.config
@@ -13,6 +13,7 @@ F_CPU=16000
#
GNUTOOLCHAIN_PREFIX="avr-"
CONFCFLAGS="-Os -ffunction-sections -fdata-sections -fshort-enums -Wall"
+# CONFIG_ERRORS is not set
MCUSUPPORT_IOPORTS=y
CONFIG_IOPORTS=y
MCUSUPPORT_PCINT0=y
@@ -23,3 +24,4 @@ MCUSUPPORT_SPI=y
# CONFIG_SPI is not set
MCUSUPPORT_USART=y
# CONFIG_USART is not set
+# CONFIG_TIMERS is not set
diff --git a/examples/blink/README.md b/examples/blink/README.md
index e69de29..ed5ed86 100644
--- a/examples/blink/README.md
+++ b/examples/blink/README.md
@@ -0,0 +1,3 @@
+Blink example
+=============
+Very simple example where led B0 blinks periodically. Busy look is used.
diff --git a/examples/blink/build/config.h b/examples/blink/build/config.h
deleted file mode 100644
index 5fff870..0000000
--- a/examples/blink/build/config.h
+++ /dev/null
@@ -1 +0,0 @@
-#define CONFIG_IOPORTS y
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);
diff --git a/src/error.c b/src/error.c
new file mode 100644
index 0000000..1c75382
--- /dev/null
+++ b/src/error.c
@@ -0,0 +1,40 @@
+#include <error.h>
+#ifdef CONFIG_ERRORS
+
+#ifdef CONFIG_EH_LED
+#include "ioport.h"
+#endif /* CONFIG_EH_LED */
+
+#ifdef CONFIG_ERROR_MESSAGES
+void _error(enum ErrorCodes ec, const char *msg) {
+#ifdef CONFIG_ERROR_CALLBACK
+ error_callback(ec, msg);
+#endif
+#else /* CONFIG_ERROR_MESSAGES */
+void _error(enum ErrorCodes ec) {
+#ifdef CONFIG_ERROR_CALLBACK
+ error_callback(ec);
+#endif
+#endif /* CONFIG_ERROR_MESSAGES */
+
+ // OK error code means no error.
+ if (ec == EC_OK)
+ return;
+
+#ifdef CONFIG_EH_LED
+ // Set led
+ io_setout(CONFIG_EH_LED_IOPIN);
+ io_hight(CONFIG_EH_LED_IOPIN);
+#endif /* CONFIG_EH_LED */
+
+#ifdef CONFIG_EH_HANGS
+ // TODO
+#endif /* CONFIG_EH_HANGS */
+
+#ifdef CONFIG_EH_RESTART
+ // TODO
+#endif /* CONFIG_EH_RESTART */
+}
+
+
+#endif /* CONFIG_ERRORS */
diff --git a/src/ioport.c b/src/ioport.c
index a77e564..3cc9406 100644
--- a/src/ioport.c
+++ b/src/ioport.c
@@ -3,9 +3,9 @@
#ifdef CONFIG_PCINT
struct PCIW {
- uint8_t flags;
- uint8_t mask;
- void (*change) (uint8_t group, uint8_t mask);
+ uint8_t flags;
+ uint8_t mask;
+ void (*change) (uint8_t group, uint8_t mask);
};
// Exploiting implementation of libc malloc
@@ -14,8 +14,8 @@ struct PCIW {
#if (defined MCUSUPPORT_PCINT0 && defined MCUSUPPORT_PCINT1 && defined MCUSUPPORT_PCINT2)
#define PCI_COUNT 3
#elif (defined MCUSUPPORT_PCINT0 && defined MCUSUPPORT_PCINT1 || \
- defined MCUSUPPORT_PCINT1 && defined MCUSUPPORT_PCINT2 || \
- defined MCUSUPPORT_PCINT2 && defined MCUSUPPORT_PCINT0)
+ defined MCUSUPPORT_PCINT1 && defined MCUSUPPORT_PCINT2 || \
+ defined MCUSUPPORT_PCINT2 && defined MCUSUPPORT_PCINT0)
#define PCI_COUNT 2
#elif (defined MCUSUPPORT_PCINT0 || defined MCUSUPPORT_PCINT1 || defined MCUSUPPORT_PCINT2)
#define PCI_COUNT 1
@@ -28,84 +28,85 @@ struct PCIW {
static struct PCIW *pciw[PCI_COUNT];
static uint8_t pci_state[PCI_COUNT];
static void pci(int8_t group, int8_t pinmax) {
- int8_t i, y;
- int8_t index = GROUP2INDEX(group);
- int8_t len = (int8_t) PCIW_LEN(pciw[index]);
- // WARN Is possible that PCINT0 is not corresponding with B group and so on?
- uint8_t state = IOE_IO_PIN(group);
- for (i = len; i >= 0; i--) {
- uint8_t stA = state & pciw[index][i].mask;
- uint8_t stB = pci_state[index] & pciw[index][i].mask;
- if (((~stA & stB) && pciw[index][i].flags & IOE_IO_RISING) ||
- ((stA & ~stB) && pciw[index][i].flags & IOE_IO_FALLING)) {
- pciw[index][i].change(IOE_IO_B, mask);
- }
- }
- pci_state[index] = state;
+ int8_t i, y;
+ int8_t index = GROUP2INDEX(group);
+ int8_t len = (int8_t) PCIW_LEN(pciw[index]);
+ // WARN Is possible that PCINT0 is not corresponding with B group and so on?
+ uint8_t state = IOE_IO_PIN(group);
+ for (i = len; i >= 0; i--) {
+ uint8_t stA = state & pciw[index][i].mask;
+ uint8_t stB = pci_state[index] & pciw[index][i].mask;
+ if (((~stA & stB) && pciw[index][i].flags & IOE_IO_RISING) ||
+ ((stA & ~stB) && pciw[index][i].flags & IOE_IO_FALLING)) {
+ pciw[index][i].change(IOE_IO_B, mask);
+ }
+ }
+ pci_state[index] = state;
}
void io_change_sethook(uint8_t group, uint8_t mask, uint8_t edge,
- void (*change) (uint8_t group, uint8_t mask)) {
- int8_t index = (int8_t) GROUP2INDEX(group);
- int8_t len = (int8_t) PCIW_LEN(pciw[index]);
- pciw[index] = realloc(pciw[index], len + 1);
- pciw[index][len].flags = edge;
- pciw[index][len].mask = mask;
- pciw[index][len].change = change;
- switch (group) {
+ void (*change) (uint8_t group, uint8_t mask)) {
+ int8_t index = (int8_t) GROUP2INDEX(group);
+ int8_t len = (int8_t) PCIW_LEN(pciw[index]);
+ pciw[index] = realloc(pciw[index], len + 1);
+ pciw[index][len].flags = edge;
+ pciw[index][len].mask = mask;
+ pciw[index][len].change = change;
+ switch (group) {
#ifdef MCUSUPPORT_PCINT0 // TODO this wont work with attiny4313 and meaby others
- case IO_B:
- PCICR |= (1<<0);
- PCMSK0 |= mask;
- break;
+ case IO_B:
+ PCICR |= (1<<0);
+ PCMSK0 |= mask;
+ break;
#endif
#ifdef MCUSUPPORT_PCINT1
- case IO_C:
- PCICR |= (1<<1);
- PCMSK1 |= mask;
- break;
+ case IO_C:
+ PCICR |= (1<<1);
+ PCMSK1 |= mask;
+ break;
#endif
#ifdef MCUSUPPORT_PCINT2
- case IO_D:
- PCICR |= (1<<2);
- PCMSK2 |= mask;
- break
+ case IO_D:
+ PCICR |= (1<<2);
+ PCMSK2 |= mask;
+ break
#endif
- }
+ }
}
void io_change_remhook(void (*change) (uint8_t group, uint8_t mask)) {
- int8_t i, y;
- int8_t len;
- for (i = PCI_COUNT - 1; i >= 0; i--) {
- len = (int8_t)PCIW_LEN(pciw[index]);
- for (y = len - 1; y >= 0; y--) {
- if (pciw[i][y].change == change) {
+ int8_t i, y;
+ int8_t len;
+ for (i = PCI_COUNT - 1; i >= 0; i--) {
+ len = (int8_t)PCIW_LEN(pciw[index]);
+ for (y = len - 1; y >= 0; y--) {
+ if (pciw[i][y].change == change) {
- }
- }
- }
+ }
+ }
+ }
}
void io_change_clearhooks(void) {
+ // TODO
}
// WARN This will work only if C is only defined on MCU with also B defined.
#ifdef MCUSUPPORT_PCINT0
ISR(PCINT0_vect, ISR_BLOCK) {
- pci(IO_B, MCUSUPPORT_PCINT0);
+ pci(IO_B, MCUSUPPORT_PCINT0);
}
#endif /* MCUSUPPORT_PCINT0 */
#ifdef MCUSUPPORT_PCINT1
ISR(PCINT1_vect, ISR_BLOCK) {
- pci(IO_C, MCUSUPPORT_PCINT1);
+ pci(IO_C, MCUSUPPORT_PCINT1);
}
#endif /* MCUSUPPORT_PCINT1 */
#ifdef MCUSUPPORT_PCINT2
ISR(PCINT2_vect, ISR_BLOCK) {
- pci(IO_D, MCUSUPPORT_PCINT2);
+ pci(IO_D, MCUSUPPORT_PCINT2);
}
#endif /* MCUSUPPORT_PCINT2 */
diff --git a/src/timer.c b/src/timer.c
index 1175bad..967a2fa 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -2,100 +2,100 @@
#ifdef CONFIG_IOE_TIMERS
void timer_init(uint8_t timer, enum timerDivider div) {
- switch (timer) {
+ switch (timer) {
#ifdef COUNTER0_PWM
- case COUNTER0_PWM:
- // Null counting register
- TCNT0 = 0;
- // Set interrupt flag
- TIMSK0 = _BV(TOIE0);
- // Set division and start counting
- switch (div) {
- case TIMER_DIVIDER_1:
- TCCR0B = _BV(CS00);
- break;
- case TIMER_DIVIDER_8:
- TCCR0B = _BV(CS01);
- break;
- case TIMER_DIVIDER_64:
- TCCR0B = _BV(CS01) | _BV(CS00);
- break;
- case TIMER_DIVIDER_256:
- TCCR0B = _BV(CS02);
- break;
- case TIMER_DIVIDER_1024:
- TCCR0B = _BV(CS02) | _BV(CS01);
- break;
- default:
- return;
- }
- break;
+ case COUNTER0_PWM:
+ // Null counting register
+ TCNT0 = 0;
+ // Set interrupt flag
+ TIMSK0 = _BV(TOIE0);
+ // Set division and start counting
+ switch (div) {
+ case TIMER_DIVIDER_1:
+ TCCR0B = _BV(CS00);
+ break;
+ case TIMER_DIVIDER_8:
+ TCCR0B = _BV(CS01);
+ break;
+ case TIMER_DIVIDER_64:
+ TCCR0B = _BV(CS01) | _BV(CS00);
+ break;
+ case TIMER_DIVIDER_256:
+ TCCR0B = _BV(CS02);
+ break;
+ case TIMER_DIVIDER_1024:
+ TCCR0B = _BV(CS02) | _BV(CS01);
+ break;
+ default:
+ return;
+ }
+ break;
#endif /* COUNTER0_PWM */
#ifdef COUNTER1_16PWM
- case COUNTER1_16PWM:
- break;
+ case COUNTER1_16PWM:
+ break;
#endif /* COUNTER1_16PWM */
#ifdef COUNTER2_PWM_ASYNC
- case COUNTER2_PWM_ASYNC:
- break;
+ case COUNTER2_PWM_ASYNC:
+ break;
#endif /* COUNTER2_PWM_ASYNC */
- }
+ }
}
void timer_disable(uint8_t timer) {
- switch (timer) {
+ switch (timer) {
#ifdef COUNTER0_PWM
- case COUNTER0_PWM:
- TCCR0B = 0;
- break;
+ case COUNTER0_PWM:
+ TCCR0B = 0;
+ break;
#endif /* COUNTER0_PWM */
#ifdef COUNTER1_16PWM
- case COUNTER1_16PWM:
- break;
+ case COUNTER1_16PWM:
+ break;
#endif /* COUNTER1_16PWM */
#ifdef COUNTER2_PWM_ASYNC
- case COUNTER2_PWM_ASYNC:
- break;
+ case COUNTER2_PWM_ASYNC:
+ break;
#endif /* COUNTER2_PWM_ASYNC */
- }
+ }
}
void timer_reset(uint8_t timer) {
- switch (timer) {
+ switch (timer) {
#ifdef COUNTER0_PWM
- case COUNTER0_PWM:
- TCNT0 = 0;
- break;
+ case COUNTER0_PWM:
+ TCNT0 = 0;
+ break;
#endif /* COUNTER0_PWM */
#ifdef COUNTER1_16PWM
- case COUNTER1_16PWM:
- break;
+ case COUNTER1_16PWM:
+ break;
#endif /* COUNTER1_16PWM */
#ifdef COUNTER2_PWM_ASYNC
- case COUNTER2_PWM_ASYNC:
- break;
+ case COUNTER2_PWM_ASYNC:
+ break;
#endif /* COUNTER2_PWM_ASYNC */
- }
+ }
}
uint16_t timer_value(uint8_t timer) {
- switch (timer) {
+ switch (timer) {
#ifdef COUNTER0_PWM
- case COUNTER0_PWM:
- return TCNT0;
- break;
+ case COUNTER0_PWM:
+ return TCNT0;
+ break;
#endif /* COUNTER0_PWM */
#ifdef COUNTER1_16PWM
- case COUNTER1_16PWM:
- break;
+ case COUNTER1_16PWM:
+ break;
#endif /* COUNTER1_16PWM */
#ifdef COUNTER2_PWM_ASYNC
- case COUNTER2_PWM_ASYNC:
- break;
+ case COUNTER2_PWM_ASYNC:
+ break;
#endif /* COUNTER2_PWM_ASYNC */
- default:
- return 0;
- }
+ default:
+ return 0;
+ }
}
#ifdef COUNTER0_PWM
@@ -109,43 +109,43 @@ static void (*timer_2_pwm_overflow) (void);
#endif /* COUNTER2_PWM_ASYNC */
void timer_sethook(uint8_t timer, void (*fnc) (void)) {
- switch (timer) {
+ switch (timer) {
#ifdef COUNTER0_PWM
- case COUNTER0_PWM:
- timer_0_pwm_overflow = fnc;
- break;
+ case COUNTER0_PWM:
+ timer_0_pwm_overflow = fnc;
+ break;
#endif /* COUNTER0_PWM */
#ifdef COUNTER1_16PWM
- case COUNTER1_16PWM:
- timer_1_16pwm_overflow = fnc;
- break;
+ case COUNTER1_16PWM:
+ timer_1_16pwm_overflow = fnc;
+ break;
#endif /* COUNTER1_16PWM */
#ifdef COUNTER2_PWM_ASYNC
- case COUNTER2_PWM_ASYNC:
- timer_2_pwm_overflow = fnc;
- break;
+ case COUNTER2_PWM_ASYNC:
+ timer_2_pwm_overflow = fnc;
+ break;
#endif /* COUNTER2_PWM_ASYNC */
- }
+ }
}
#ifdef COUNTER0_PWM
ISR(TIMER0_OVF_vect, ISR_BLOCK) {
- if (timer_0_pwm_overflow)
- timer_0_pwm_overflow();
+ if (timer_0_pwm_overflow)
+ timer_0_pwm_overflow();
}
#endif /* COUNTER0_PWM */
#ifdef COUNTER0_PWM
ISR(TIMER1_OVF_vect, ISR_BLOCK) {
- if (timer_1_16pwm_overflow)
- timer_1_16pwm_overflow();
+ if (timer_1_16pwm_overflow)
+ timer_1_16pwm_overflow();
}
#endif /* COUNTER0_PWM */
#ifdef COUNTER0_PWM
ISR(TIMER2_OVF_vect, ISR_BLOCK) {
- if (timer_2_pwm_overflow)
- timer_2_pwm_overflow();
+ if (timer_2_pwm_overflow)
+ timer_2_pwm_overflow();
}
#endif /* COUNTER0_PWM */
diff --git a/src/utils/buffer.c b/src/utils/buffer.c
index 3a5c15e..644a599 100644
--- a/src/utils/buffer.c
+++ b/src/utils/buffer.c
@@ -1,70 +1,79 @@
#include <utils/buffer.h>
+#include <error.h>
#ifdef CONFIG_IOE_BUFFER
int8_t ioebuffer_init(IOEBuffer * buf, uint8_t size, uint8_t flags) {
- buf->windex = 0;
- buf->rindex = 0;
- buf->size = size;
- buf->flags = flags;
- buf->data = malloc(size * sizeof(void *));
+ buf->windex = 0;
+ buf->rindex = 0;
+ buf->size = size;
+ buf->flags = flags;
+ buf->data = malloc(size * sizeof(void *));
}
void ioebuffer_uninit(IOEBuffer * buf) {
- free(buf->data);
+ free(buf->data);
}
int8_t ioebuffer_put(IOEBuffer * buf, void *data) {
- uint8_t mode = buf->flags & 0x3;
- if (mode == IOEBUFFER_F_MODE_BLOCK) {
- if (bud->windex == 0) {
- while (bud->rindex == size - 1);
- } else {
- while (bud->rindex == bud->windex - 1);
- }
- }
- bud->data[bud->windex] = data;
- if (mode != IOEBUFFER_F_MODE_DROP ||
- (bud->windex == 0 && bud->rindex == size - 1) ||
- (bud->rindex + 1 == bud->windex)) {
- if (bud->windex == 0)
- bud->windex = size - 1;
- else
- bud->windex--;
- }
- if (mode == IOEBUFFER_F_MODE_OVERWRITE && bud->windex == bud->rindex) {
- if (bud->windex == size - 1)
- bud->windex = 0;
- else
- bud->windex++;
- } else
- return -1;
- return 0;
+ uint8_t mode = buf->flags & 0x3;
+#ifdef CONFIG_CHECK_ARGUMENTS
+ switch(mode) {
+ case IOEBUFFER_F_MODE_BLOCK:
+
+ }
+#endif /* CONFIG_CHECK_ARGUMENTS */
+ // First we check if we shouldn't block
+ if (mode == IOEBUFFER_F_MODE_BLOCK) {
+ if (bud->windex == 0) {
+ while (bud->rindex == size - 1);
+ } else {
+ while (bud->rindex == bud->windex - 1);
+ }
+ }
+ bud->data[bud->windex] = data;
+ if (mode != IOEBUFFER_F_MODE_DROP ||
+ (bud->windex == 0 && bud->rindex == size - 1) ||
+ (bud->rindex + 1 == bud->windex)) {
+ if (bud->windex == 0)
+ bud->windex = size - 1;
+ else
+ bud->windex--;
+ }
+ if (mode == IOEBUFFER_F_MODE_OVERWRITE && bud->windex == bud->rindex) {
+ if (bud->windex == size - 1)
+ bud->windex = 0;
+ else
+ bud->windex++;
+ } else
+ return -1;
+
+ return 0;
}
int8_t ioebuffer_get(IOEBuffer * buf, void **data) {
- if (buf->rindex != buf->windex) {
- *data = buf->data[buf->rindex];
- if (buf->rindex == 0)
- buf->rindex = buf->size - 1;
- else
- buf->rindex--;
- } else
- *data = NULL;
+ if (buf->rindex != buf->windex) {
+ *data = buf->data[buf->rindex];
+ if (buf->rindex == 0)
+ buf->rindex = buf->size - 1;
+ else
+ buf->rindex--;
+ } else
+ *data = NULL;
}
void ioebuffer_clean(IOEBuffer * buf) {
- buf->windex = 0;
- bud->rindex = 0;
+ buf->windex = 0;
+ bud->rindex = 0;
}
uint8_t ioebuffer_cnt(IOEBuffer * buf) {
- if (buf->windex < buf->rindex)
- return buf->rindex - buf->windex;
- else if (buf->windex > buf->rindex)
- return buf->size - buf->windex + buf->rindex;
- else
- return 0;
+ if (buf->windex < buf->rindex)
+ return buf->rindex - buf->windex;
+ else if (buf->windex > buf->rindex)
+ return buf->size - buf->windex + buf->rindex;
+ else
+ return 0;
}
#endif /* CONFIG_IOE_BUFFER */
diff --git a/template/Makefile b/template/Makefile
index bc0643f..59218a2 100644
--- a/template/Makefile
+++ b/template/Makefile
@@ -41,25 +41,29 @@ include ioeconfig
# If you want change some standard CFLAGS, change them in configuration not here.
# Add here only options that should not be applied to avr-ioe also.
CFLAGS = -Iavr-ioe/include -mmcu=$(MMCU) -imacros avr-ioe/build/config.h \
- $(shell echo $(CONFCFLAGS)) $(shell echo -DF_CPU=$(F_CPU)000L)
+ $(shell echo $(CCFLAGS)) $(shell echo -DF_CPU=$(F_CPU)000L)
+CC = $(CHOST)gcc
+AR = $(CHOST)ar
+CPP = $(CHOST)cpp
+OBJCOPY = $(CHOST)objcopy
$(PROJNAME).elf: avr-ioe/libioe.a
$(PROJNAME).elf: $(OBJ)
@echo " LD $@"
- $(Q)avr-gcc -Os -mmcu=$(MMCU) $^ -o $@ -Lavr-ioe -lioe
+ $(Q)$(CC) -Os -mmcu=$(MMCU) $^ -o $@ -Lavr-ioe -lioe
$(PROJNAME).hex: $(PROJNAME).elf
@echo " OBJCOPY $@"
- $(Q)avr-objcopy -O ihex -R .eeprom $< $@
+ $(Q)$(OBJCOPY) -O ihex -R .eeprom $< $@
$(OBJ): %.o: %.c avr-ioe/build/config.h
@echo " CC $@"
- $(Q)avr-gcc $(CFLAGS) -c -o $@ $<
+ $(Q)$(CC) $(CFLAGS) -c -o $@ $<
avr-ioe/libioe.a: ioeconfig
- $(Q)$(MAKE) -C avr-ioe libioe.a CONFIG="$$( readlink -f ioeconfig )"
+ $(Q)+$(MAKE) -C avr-ioe libioe.a CONFIG="$$( readlink -f ioeconfig )"
avr-ioe/build/config.h: ioeconfig
- $(Q)$(MAKE) -C avr-ioe build/config.h CONFIG="$$( readlink -f ioeconfig )"
+ $(Q)+$(MAKE) -C avr-ioe build/config.h CONFIG="$$( readlink -f ioeconfig )"
endif
.config:
diff --git a/tests/simavr b/tests/simavr
deleted file mode 160000
-Subproject dc222b5ec86bfaeadd6a32f58c51859ac13454c