aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Kconfig281
-rw-r--r--Makefile58
-rw-r--r--docs/references/ioport.md4
-rw-r--r--examples/blink/.config27
-rw-r--r--examples/blink/Kconfig9
-rw-r--r--examples/blink/Makefile69
-rw-r--r--examples/blink/blink.c2
-rw-r--r--examples/examples.mk74
-rw-r--r--examples/usartecho/.config42
-rw-r--r--examples/usartecho/Kconfig11
-rw-r--r--examples/usartecho/Makefile69
-rw-r--r--include/ioport.h34
-rw-r--r--include/usart.h5
-rw-r--r--ioe.Kconfig280
-rw-r--r--src/error.c2
-rw-r--r--src/sources.mk19
-rw-r--r--src/usart.c136
-rw-r--r--template/Makefile2
-rw-r--r--tools/kconfig.mk44
19 files changed, 542 insertions, 626 deletions
diff --git a/Kconfig b/Kconfig
index 5101d01..7330c85 100644
--- a/Kconfig
+++ b/Kconfig
@@ -1,280 +1,3 @@
-mainmenu "AVR-IOE configuration"
+mainmenu "AVR-IOE library configuration"
-config IOEROOT
- string
- option env="IOEROOT"
-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 CHOST
- string "AVR Compilation toolchain prefix (host)"
- default "avr-"
- ---help---
- Prefix used for all calls to compilation toolchain when compiling for AVR.
-
-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
-
-# Error handling ################################################################
-
-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
-
-menu "Errors handling"
-
-config CONFIG_EH_RESTART
- bool "Restart MCU on error detection"
- default n
- ---help---
- CPU is restarted when error is detected. This is suggested in production.
-
-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"
- depends on CONFIG_EH_LED
- default "IO_B0"
- ---help---
- Specifies IO pin which will be pulled up on error detection.
- 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)").
-
-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.
-
-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
-
-# IO Ports ######################################################################
-
-config MCUSUPPORT_IOPORTS
- bool
- default n
-
-config CONFIG_IOPORTS
- bool "Input/Output ports"
- default y
- depends on MCUSUPPORT_IOPORTS
-
-config MCUSUPPORT_PCINT0
- bool
- default n
-config MCUSUPPORT_PCINT1
- bool
- default n
-config MCUSUPPORT_PCINT2
- bool
- default n
-
-config CONFIG_IOPORTS_PCINT
- bool "Input/Output ports change interrupts"
- depends on CONFIG_IOPORTS
- depends on MCUSUPPORT_PCINT0 || MCUSUPPORT_PCINT1 || MCUSUPPORT_PCINT2
-
-# SPI ###########################################################################
-
-config MCUSUPPORT_SPI
- bool
- default n
-
-config CONFIG_SPI
- bool "SPI (Serial peripheral interface)"
- depends on MCUSUPPORT_SPI
-
-# USART #########################################################################
-config MCUSUPPORT_USART
- bool
- default n
-
-menuconfig CONFIG_USART
- bool "USART (Universal synchronous/asynchronous transceiver)"
- depends on MCUSUPPORT_USART
-
-if CONFIG_USART
-
-config CONFIG_USART_BAUD
- int "Baudrate"
- default 115200
-
-choice USART_PARITY_C
- prompt "Parity"
-config USART_PARITY_C_NONE
- bool "None"
-config USART_PARITY_C_ODD
- bool "Odd"
-config USART_PARITY_C_EVEN
- bool "Even"
-endchoice
-config CONFIG_USART_PARITY
- string
- default "USART_PARITY_NONE" if USART_PARITY_C_NONE
- default "USART_PARITY_ODD" if USART_PARITY_C_ODD
- default "USART_PARITY_EVEN" if USART_PARITY_C_EVEN
-
-config CONFIG_USART_DATABITS
- int "Data bits"
- default 8
- range 5 8
-
-choice USART_STOPBIT_C
- prompt "Stop bit"
-config USART_STOPBIT_C_SINGLE
- bool "Single"
-config USART_STOPBIT_C_DOUBLE
- bool "Double"
-endchoice
-config CONFIG_USART_STOPBIT
- string
- default "USART_STOPBIT_SINGLE" if USART_STOPBIT_C_SINGLE
- default "USART_STOPBIT_DOUBLE" if USART_STOPBIT_C_DOUBLE
-
-config CONFIG_USART_OUTPUT_BUFFER
- bool "Use output buffer"
- default n
-
-config CONFIG_USART_OUTBUFFER_SIZE
- int "Output buffer size in bytes." if CONFIG_USART_OUTPUT_BUFFER
- default 0 if ! CONFIG_USART_OUTPUT_BUFFER
- range 1 512000 if CONFIG_USART_OUTPUT_BUFFER
- default 32
-
-choice USART_OUTBUFFER_MODE_C
- prompt "Output buffer replacement policy" if CONFIG_USART_OUTPUT_BUFFER
-config USART_OUTBUFFER_MODE_C_BLOCK
- bool "Block"
-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
- default 1 if USART_OUTBUFFER_MODE_C_OVERWRITE
- default 2 if USART_OUTBUFFER_MODE_C_DROP
- default 0
-
-config CONFIG_USART_INPUT_BUFFER
- bool "Use input buffer"
-
-config CONFIG_USART_INBUFFER_SIZE
- int "Input buffer size in bytes." if CONFIG_USART_INPUT_BUFFER
- default 0 if ! CONFIG_USART_INPUT_BUFFER
- range 1 512000 if CONFIG_USART_INPUT_BUFFER
- default 32
-
-choice USART_INBUFFER_MODE_C
- prompt "Input buffer replacement policy" if CONFIG_USART_INPUT_BUFFER
-config USART_INBUFFER_MODE_C_BLOCK
- bool "Block"
-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
- default 1 if USART_INBUFFER_MODE_C_OVERWRITE
- default 2 if USART_INBUFFER_MODE_C_DROP
- default 0
-
-config CONFIG_USART_OUTFILE
- bool "STD FILE support for output"
- depends on CONFIG_USART_OUTPUT_BUFFER
-
-config CONFIG_USART_INFILE
- bool "STD FILE support for input"
- depends on CONFIG_USART_INPUT_BUFFER
-
-endif
-
-# Timers ########################################################################
-
-config CONFIG_TIMERS
- bool "Timers"
+source ioe.Kconfig
diff --git a/Makefile b/Makefile
index 13d281b..ea96319 100644
--- a/Makefile
+++ b/Makefile
@@ -24,19 +24,7 @@ ifeq (,$(filter clean help docs serve-docs clean-docs config oldconfig \
$(MAKECMDGOALS))) # Ignore build targets if goal is not building
include $(CONFIG) # include configuration
-
-### Source files list ###########################
-SRC = base.c
-ifeq (y,$(CONFIG_IOPORTS))
-SRC += ioport.c
-endif
-ifeq (y,$(CONFIG_SPI))
-SRC += spi.c
-endif
-ifeq (y,$(CONFIG_USART))
-SRC += usart.c
-endif
-### End of source files list ####################
+include src/sources.mk
OBJ = $(patsubst %.c,$(O)/build/%.o,$(SRC))
DEP = $(patsubst %.c,$(O)/build/%.d,$(SRC))
@@ -102,52 +90,20 @@ clean-docs:
.PHONY: proper
proper: clean clean-docs
@echo " CLEAN CONFIG"
- $(Q)$(RM) $(CONFIG) $(CONFIG).orig
+ $(Q)$(RM) $(CONFIG) $(CONFIG).orig .config.cmd
.PHONY: help
help:
@echo "all/libioe.a - Build library"
@echo "config - Start configuration program"
- @echo "menuconfig - NCurses based configuration program"
+ @echo "menuconfig - NCurses based configuration program (Kconfig)"
@echo "docs - Build documentation"
@echo "server-docs - Start temporally http server with documentation"
@echo "help - Prints this text"
@echo "clean - Removing all object files generated from source files"
@echo "clean-docs - Remove generated documentation"
+ @echo "proper - Cleans everything including configuration"
-$(CONFIG):
- @echo Please generate configuration first using config or menuconfig target
- @exit 1
-
-# We don't wont pass any variable to Kconfig. This is workaround for that.
-MAKEOVERRIDES =
-
-callconfig = $(Q)\
- [ ! -f "$(CONFIG)" ] || mv "$(CONFIG)" config; \
- IOEROOT=. $(MAKE) -f tools/kconfig/GNUmakefile --no-print-directory \
- TOPDIR=. SRCDIR=tools/kconfig $(1); \
- [ ! -f config ] || mv config "$(CONFIG)"; \
- [ ! -f config.old ] || mv config.old "$(CONFIG).old"
-# Note about this file moving madness:
-# avr-ioe is using Kconfig for configuration and it is not prepared too well for
-# nested projects (at least I don't know way). This unfortunately means that to
-# have configuration in parent project, We have to move it every time we are
-# generating it. Also upper projects can't use Kconfig for its self configuration.
-
--include .config.cmd
-
-.PHONY: oldconfig
-oldconfig: $(deps_config)
- $(call callconfig, oldconfig)
-
-.PHONY: config
-config: $(deps_config)
- $(call callconfig, config)
-
-.PHONY: menuconfig
-menuconfig: $(deps_config)
- $(call callconfig, menuconfig)
-
-.PHONY: allyesconfig
-allyesconfig: $(deps_config)
- $(call callconfig, allyesconfig)
+TOOL_PATH=tools
+IOEROOT=.
+include tools/kconfig.mk
diff --git a/docs/references/ioport.md b/docs/references/ioport.md
index 96a4b82..1f4b511 100644
--- a/docs/references/ioport.md
+++ b/docs/references/ioport.md
@@ -33,9 +33,9 @@ Parameters:
__group__ - Character specifying exact port group
__mask__ - Binary shifted 1. Shift is equal to port index in specified group.
-#### Function io_hight
+#### Function io_high
```C
-static inline void io_hight(uint8_t group, uint8_t mask)
+static inline void io_high(uint8_t group, uint8_t mask)
```
Sets output port to hight (also can be called as 1).
WARNING: Invoke this only if io_setout is called before.
diff --git a/examples/blink/.config b/examples/blink/.config
deleted file mode 100644
index 9023cfc..0000000
--- a/examples/blink/.config
+++ /dev/null
@@ -1,27 +0,0 @@
-#
-# Automatically generated file; DO NOT EDIT.
-# AVR-IOE configuration
-#
-MMCU="atmega328p"
-ATMEGA328P=y
-# ATTINY85 is not set
-# ATTINY4313 is not set
-F_CPU=16000
-
-#
-# Compilation options
-#
-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
-MCUSUPPORT_PCINT1=y
-MCUSUPPORT_PCINT2=y
-# CONFIG_IOPORTS_PCINT is not set
-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/Kconfig b/examples/blink/Kconfig
new file mode 100644
index 0000000..9c3a502
--- /dev/null
+++ b/examples/blink/Kconfig
@@ -0,0 +1,9 @@
+mainmenu "AVR-IOE blink configuration"
+
+# We need CONFIG_IOPORTS, but we don't care about anything else.
+config BLINK_DEFAULTS
+ bool
+ default y
+ select CONFIG_IOPORTS
+
+source "../../ioe.Kconfig"
diff --git a/examples/blink/Makefile b/examples/blink/Makefile
index f2cc133..c70ed33 100644
--- a/examples/blink/Makefile
+++ b/examples/blink/Makefile
@@ -1,69 +1,4 @@
-MAKEFLAGS += --no-builtin-rules
-PROJNAME = blink
-
+EXAMPLE_NAME = blink
SRC = blink.c
-OBJ = $(patsubst %.c,%.o,$(SRC)) # This creates list of *.o files from *.c
-Q ?= @ # This can be overwritten to show commands
-
-.PHONY: all
-ifneq ("$(wildcard .config)","") # Checking if configuration exists
-all: $(PROJNAME).hex
- @echo Now you can flash $< to your chip.
-else
-all: .config
-endif
-
-# Edit here help like you ever want
-.PHONY: help
-help:
- @echo "AVR-IOE blink example"
- @echo " all - Build example"
- @echo " config - Start configuration program"
- @echo " menuconfig - NCurses based configuration program"
- @echo " help - Prints this text"
- @echo " clean - Removing all object files generated from source files"
-
-.PHONY: clean
-clean:
- @echo " CLEAN OBJ"
- $(Q)$(RM) $(OBJ)
- @echo " CLEAN $(PROJNAME).elf $(PROJNAME).hex"
- $(Q)$(RM) $(PROJNAME).elf $(PROJNAME).hex
- $(Q)$(MAKE) -C ../.. clean O=examples/$(PROJNAME)
-
-# Building targets are available only if configuration is generated
-ifneq ("$(wildcard .config)","")
--include .config
-# 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 = -I../../include -mmcu=$(MMCU) -imacros build/config.h \
- $(shell echo $(CONFCFLAGS)) $(shell echo -DF_CPU=$(F_CPU)000L)
-
-$(PROJNAME).elf: libioe.a
-$(PROJNAME).elf: $(OBJ)
- @echo " LD $@"
- $(Q)avr-gcc -Os -mmcu=$(MMCU) $(filter %.o,$^) -o $@ -L. -lioe
-
-$(PROJNAME).hex: $(PROJNAME).elf
- @echo " OBJCOPY $@"
- $(Q)avr-objcopy -O ihex -R .eeprom $< $@
-
-$(OBJ): %.o: %.c libioe.a
- @echo " CC $@"
- $(Q)avr-gcc $(CFLAGS) -c -o $@ $<
-
-libioe.a: .config
- $(Q)$(MAKE) -C ../.. examples/$(PROJNAME)/libioe.a O=examples/$(PROJNAME)
-endif
-
-.config:
- @echo Configuration for this example is missing. Probably deleted...
- @exit 1
-
-config:
- $(Q)$(MAKE) -C ../.. config O=examples/$(PROJNAME)
-
-.PHONY: menuconfig
-menuconfig:
- $(Q)$(MAKE) -C ../.. menuconfig O=examples/$(PROJNAME)
+include ../examples.mk
diff --git a/examples/blink/blink.c b/examples/blink/blink.c
index 912ce80..a1411e6 100644
--- a/examples/blink/blink.c
+++ b/examples/blink/blink.c
@@ -6,7 +6,7 @@ int main() {
io_setout(IO_B0);
while (1) {
- io_hight(IO_B0);
+ io_high(IO_B0);
_delay_ms(500);
io_low(IO_B0);
_delay_ms(500);
diff --git a/examples/examples.mk b/examples/examples.mk
new file mode 100644
index 0000000..f6b0acb
--- /dev/null
+++ b/examples/examples.mk
@@ -0,0 +1,74 @@
+# vim:ts=4:sw=4:sts=4:noexpandtab
+MAKEFLAGS += --no-builtin-rules
+# Note this file is included to Makefiles in lower directories so all paths here
+# are like thy would be from lower directory.
+
+# You have to define EXAMPLE_NAME variable
+ifndef EXAMPLE_NAME
+$(error Before including examples.mk define EXAMPLE_NAME)
+endif
+ifndef SRC
+$(error Before including examples.mk define SRC)
+endif
+
+OBJ = $(patsubst %.c,%.o,$(SRC)) # This creates list of *.o files from *.c
+Q ?= @ # This can be overwritten to show commands
+
+CONFIG = .config
+
+.PHONY: all
+ifneq ("$(wildcard $(CONFIG))","") # Checking if configuration exists
+all: $(EXAMPLE_NAME).hex
+ @echo Now you can flash $< to your chip.
+else
+all: $(CONFIG)
+endif
+
+# Edit here help like you ever want
+.PHONY: help
+help:
+ @echo "AVR-IOE $(EXAMPLE_NAME) example"
+ @echo " all - Build example"
+ @echo " config - Start configuration program"
+ @echo " menuconfig - NCurses based configuration program"
+ @echo " help - Prints this text"
+ @echo " clean - Removing all object files generated from source files"
+
+.PHONY: clean
+clean:
+ @echo " CLEAN OBJ"
+ $(Q)$(RM) $(OBJ)
+ @echo " CLEAN $(EXAMPLE_NAME).elf $(EXAMPLE_NAME).hex"
+ $(Q)$(RM) $(EXAMPLE_NAME).elf $(EXAMPLE_NAME).hex
+ $(Q)$(MAKE) -C ../.. clean O=examples/$(EXAMPLE_NAME)
+
+# Building targets are available only if configuration is generated
+ifneq ("$(wildcard $(CONFIG))","")
+-include $(CONFIG)
+# 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 = -I../../include -mmcu=$(MMCU) -imacros build/config.h \
+ $(shell echo $(CCFLAGS)) $(shell echo -DF_CPU=$(F_CPU)000L)
+CC = $(CHOST)gcc
+OBJCOPY = $(CHOST)objcopy
+
+$(EXAMPLE_NAME).elf: libioe.a
+$(EXAMPLE_NAME).elf: $(OBJ)
+ @echo " LD $@"
+ $(Q)$(CC) -Os -mmcu=$(MMCU) $(filter %.o,$^) -o $@ -L. -lioe
+
+$(EXAMPLE_NAME).hex: $(EXAMPLE_NAME).elf
+ @echo " OBJCOPY $@"
+ $(Q)$(OBJCOPY) -O ihex -R .eeprom $< $@
+
+$(OBJ): %.o: %.c libioe.a
+ @echo " CC $@"
+ $(Q)$(CC) $(CFLAGS) -c -o $@ $<
+
+libioe.a: $(CONFIG)
+ $(Q)$(MAKE) -C ../.. examples/$(EXAMPLE_NAME)/libioe.a O=examples/$(EXAMPLE_NAME)
+endif
+
+TOOL_PATH=../../tools
+IOEROOT=../../
+include ../../tools/kconfig.mk
diff --git a/examples/usartecho/.config b/examples/usartecho/.config
deleted file mode 100644
index 48ae310..0000000
--- a/examples/usartecho/.config
+++ /dev/null
@@ -1,42 +0,0 @@
-#
-# Automatically generated file; DO NOT EDIT.
-# AVR-IOE configuration
-#
-MMCU="atmega328p"
-ATMEGA328P=y
-# ATTINY85 is not set
-# ATTINY4313 is not set
-F_CPU=16000
-
-#
-# Compilation options
-#
-GNUTOOLCHAIN_PREFIX="avr-"
-CONFCFLAGS="-Os -ffunction-sections -fdata-sections -fshort-enums -Wall"
-MCUSUPPORT_IOPORTS=y
-# CONFIG_IOPORTS is not set
-MCUSUPPORT_PCINT0=y
-MCUSUPPORT_PCINT1=y
-MCUSUPPORT_PCINT2=y
-MCUSUPPORT_SPI=y
-# CONFIG_SPI is not set
-MCUSUPPORT_USART=y
-CONFIG_USART=y
-CONFIG_USART_BAUD=115200
-USART_PARITY_C_NONE=y
-# USART_PARITY_C_ODD is not set
-# USART_PARITY_C_EVEN is not set
-CONFIG_USART_PARITY="USART_PARITY_NONE"
-CONFIG_USART_DATABITS=8
-USART_STOPBIT_C_SINGLE=y
-# USART_STOPBIT_C_DOUBLE is not set
-CONFIG_USART_STOPBIT="USART_STOPBIT_SINGLE"
-CONFIG_USART_OUTPUT_BUFFER=y
-CONFIG_USART_OUTBUFFER_SIZE=64
-USART_OUTBUFFER_MODE_C_BLOCK=y
-# USART_OUTBUFFER_MODE_C_OVERWRITE is not set
-# USART_OUTBUFFER_MODE_C_DROP is not set
-CONFIG_USART_OUTBUFFER_MODE=0
-# CONFIG_USART_INPUT_BUFFER is not set
-CONFIG_USART_INBUFFER_SIZE=32
-CONFIG_USART_INBUFFER_MODE=0
diff --git a/examples/usartecho/Kconfig b/examples/usartecho/Kconfig
new file mode 100644
index 0000000..3bfde28
--- /dev/null
+++ b/examples/usartecho/Kconfig
@@ -0,0 +1,11 @@
+mainmenu "AVR-IOE usartecho configuration"
+
+# We need CONFIG_IOPORTS, but we don't care about anything else.
+config USART_ECHO_DEFAULTS
+ bool
+ default y
+ select CONFIG_USART
+ select CONFIG_USART_OUTPUT_BUFFER
+ depends on ! CONFIG_USART_INPUT_BUFFER
+
+source "../../ioe.Kconfig"
diff --git a/examples/usartecho/Makefile b/examples/usartecho/Makefile
index 6e4e9d5..93a2783 100644
--- a/examples/usartecho/Makefile
+++ b/examples/usartecho/Makefile
@@ -1,69 +1,4 @@
-MAKEFLAGS += --no-builtin-rules
-PROJNAME = usartecho
-
+EXAMPLE_NAME = usartecho
SRC = echo.c
-OBJ = $(patsubst %.c,%.o,$(SRC)) # This creates list of *.o files from *.c
-Q ?= @ # This can be overwritten to show commands
-
-.PHONY: all
-ifneq ("$(wildcard .config)","") # Checking if configuration exists
-all: $(PROJNAME).hex
- @echo Now you can flash $< to your chip.
-else
-all: .config
-endif
-
-# Edit here help like you ever want
-.PHONY: help
-help:
- @echo "AVR-IOE USART echo example"
- @echo " all - Build example"
- @echo " config - Start configuration program"
- @echo " menuconfig - NCurses based configuration program"
- @echo " help - Prints this text"
- @echo " clean - Removing all object files generated from source files"
-
-.PHONY: clean
-clean:
- @echo " CLEAN OBJ"
- $(Q)$(RM) $(OBJ)
- @echo " CLEAN $(PROJNAME).elf $(PROJNAME).hex"
- $(Q)$(RM) $(PROJNAME).elf $(PROJNAME).hex
- $(Q)$(MAKE) -C ../.. clean O=examples/$(PROJNAME)
-
-# Building targets are available only if configuration is generated
-ifneq ("$(wildcard .config)","")
--include .config
-# 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 = -I../../include -mmcu=$(MMCU) -imacros build/config.h \
- $(shell echo $(CONFCFLAGS)) $(shell echo -DF_CPU=$(F_CPU)000L)
-
-$(PROJNAME).elf: libioe.a
-$(PROJNAME).elf: $(OBJ)
- @echo " LD $@"
- @avr-gcc -Os -mmcu=$(MMCU) $(filter %.o,$^) -o $@ -L. -lioe
-
-$(PROJNAME).hex: $(PROJNAME).elf
- @echo " OBJCOPY $@"
- $(Q)avr-objcopy -O ihex -R .eeprom $< $@
-
-$(OBJ): %.o: %.c libioe.a
- @echo " CC $@"
- $(Q)avr-gcc $(CFLAGS) -c -o $@ $<
-
-libioe.a: .config
- $(Q)$(MAKE) -C ../.. examples/$(PROJNAME)/libioe.a O=examples/$(PROJNAME)
-endif
-
-.config:
- @echo Configuration for this example is missing. Probably deleted...
- @exit 1
-
-config:
- $(Q)$(MAKE) -C ../.. config O=examples/$(PROJNAME)
-
-.PHONY: menuconfig
-menuconfig:
- $(Q)$(MAKE) -C ../.. menuconfig O=examples/$(PROJNAME)
+include ../examples.mk
diff --git a/include/ioport.h b/include/ioport.h
index 1022493..95b6205 100644
--- a/include/ioport.h
+++ b/include/ioport.h
@@ -9,36 +9,36 @@
#ifdef CONFIG_IOPORTS
enum ioInResistor {
- IO_PULLUP,
- IO_PULLDOWN
+ IO_PULLUP,
+ IO_PULLDOWN
};
static inline void io_setout(uint8_t group, uint8_t mask) {
- IO_DDR(group) |= mask;
+ IO_DDR(group) |= mask;
}
-static inline void io_hight(uint8_t group, uint8_t mask) {
- IO_PORT(group) |= mask;
+static inline void io_high(uint8_t group, uint8_t mask) {
+ IO_PORT(group) |= mask;
}
static inline void io_low(uint8_t group, uint8_t mask) {
- IO_PORT(group) &= ~mask;
+ IO_PORT(group) &= ~mask;
}
static inline void io_set(uint8_t group, uint8_t mask, int8_t val) {
- if (val)
- io_hight(group, mask);
- else
- io_low(group, mask);
+ if (val)
+ io_high(group, mask);
+ else
+ io_low(group, mask);
}
static inline void io_setin(uint8_t group, uint8_t mask,
enum ioInResistor resistor) {
- IO_DDR(group) &= ~mask;
- if (resistor == IO_PULLUP)
- IO_PORT(group) |= mask;
- else
- IO_PORT(group) &= ~mask;
+ IO_DDR(group) &= ~mask;
+ if (resistor == IO_PULLUP)
+ IO_PORT(group) |= mask;
+ else
+ IO_PORT(group) &= ~mask;
}
static inline int8_t io_get(uint8_t group, uint8_t mask) {
- return (int8_t) IO_PIN(group) & mask;
+ return (int8_t) IO_PIN(group) & mask;
}
#ifdef CONFIG_PCINT
@@ -46,7 +46,7 @@ static inline int8_t io_get(uint8_t group, uint8_t mask) {
#define IO_RISING (1 << 0)
#define IO_FALLING (1 << 1)
void io_change_sethook(uint8_t group, uint8_t mask, uint8_t edge,
- void (*change) (uint8_t group, uint8_t mask));
+ void (*change) (uint8_t group, uint8_t mask));
void io_change_remhook(void (*change) (uint8_t group, uint8_t mask));
void io_change_clearhooks(void);
diff --git a/include/usart.h b/include/usart.h
index 76e423d..bb80885 100644
--- a/include/usart.h
+++ b/include/usart.h
@@ -4,7 +4,6 @@
#include <stdio.h>
#include "mcu/mcu_def.h"
-#include "tasks.h"
#include "utils/buffer.h"
#ifndef _USART_H_
@@ -39,10 +38,10 @@ void usart_send_str(char *str);
uint8_t usart_get(void);
#endif
static inline uint8_t usart_queryerror(void) {
- return UCSR0A & (_BV(FE0) | _BV(DOR0) | _BV(UPE0));
+ return UCSR0A & (_BV(FE0) | _BV(DOR0) | _BV(UPE0));
}
static inline int8_t usart_busy(void) {
- return _usart_busy;
+ return _usart_busy;
}
#ifdef CONFIG_USART_INPUT_BUFFER
uint8_t usart_inbuffered(void);
diff --git a/ioe.Kconfig b/ioe.Kconfig
new file mode 100644
index 0000000..22dd75f
--- /dev/null
+++ b/ioe.Kconfig
@@ -0,0 +1,280 @@
+# vim:ft=kconfig
+
+config IOEROOT
+ string
+ option env="IOEROOT"
+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 CHOST
+ string "AVR Compilation toolchain prefix (host)"
+ default "avr-"
+ ---help---
+ Prefix used for all calls to compilation toolchain when compiling for AVR.
+
+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
+
+# Error handling ################################################################
+
+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
+
+menu "Errors handling"
+
+config CONFIG_EH_RESTART
+ bool "Restart MCU on error detection"
+ default n
+ ---help---
+ CPU is restarted when error is detected. This is suggested in production.
+
+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"
+ depends on CONFIG_EH_LED
+ default "IO_B0"
+ ---help---
+ Specifies IO pin which will be pulled up on error detection.
+ 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)").
+
+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.
+
+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
+
+# IO Ports ######################################################################
+
+config MCUSUPPORT_IOPORTS
+ bool
+ default n
+
+config CONFIG_IOPORTS
+ bool "Input/Output ports"
+ default y
+ depends on MCUSUPPORT_IOPORTS
+
+config MCUSUPPORT_PCINT0
+ bool
+ default n
+config MCUSUPPORT_PCINT1
+ bool
+ default n
+config MCUSUPPORT_PCINT2
+ bool
+ default n
+
+config CONFIG_IOPORTS_PCINT
+ bool "Input/Output ports change interrupts"
+ depends on CONFIG_IOPORTS
+ depends on MCUSUPPORT_PCINT0 || MCUSUPPORT_PCINT1 || MCUSUPPORT_PCINT2
+
+# SPI ###########################################################################
+
+config MCUSUPPORT_SPI
+ bool
+ default n
+
+config CONFIG_SPI
+ bool "SPI (Serial peripheral interface)"
+ depends on MCUSUPPORT_SPI
+
+# USART #########################################################################
+config MCUSUPPORT_USART
+ bool
+ default n
+
+menuconfig CONFIG_USART
+ bool "USART (Universal synchronous/asynchronous transceiver)"
+ depends on MCUSUPPORT_USART
+
+if CONFIG_USART
+
+config CONFIG_USART_BAUD
+ int "Baudrate"
+ default 115200
+
+choice USART_PARITY_C
+ prompt "Parity"
+config USART_PARITY_C_NONE
+ bool "None"
+config USART_PARITY_C_ODD
+ bool "Odd"
+config USART_PARITY_C_EVEN
+ bool "Even"
+endchoice
+config CONFIG_USART_PARITY
+ string
+ default "USART_PARITY_NONE" if USART_PARITY_C_NONE
+ default "USART_PARITY_ODD" if USART_PARITY_C_ODD
+ default "USART_PARITY_EVEN" if USART_PARITY_C_EVEN
+
+config CONFIG_USART_DATABITS
+ int "Data bits"
+ default 8
+ range 5 8
+
+choice USART_STOPBIT_C
+ prompt "Stop bit"
+config USART_STOPBIT_C_SINGLE
+ bool "Single"
+config USART_STOPBIT_C_DOUBLE
+ bool "Double"
+endchoice
+config CONFIG_USART_STOPBIT
+ string
+ default "USART_STOPBIT_SINGLE" if USART_STOPBIT_C_SINGLE
+ default "USART_STOPBIT_DOUBLE" if USART_STOPBIT_C_DOUBLE
+
+config CONFIG_USART_OUTPUT_BUFFER
+ bool "Use output buffer"
+ default n
+
+config CONFIG_USART_OUTBUFFER_SIZE
+ int "Output buffer size in bytes." if CONFIG_USART_OUTPUT_BUFFER
+ default 0 if ! CONFIG_USART_OUTPUT_BUFFER
+ range 1 512000 if CONFIG_USART_OUTPUT_BUFFER
+ default 32
+
+choice USART_OUTBUFFER_MODE_C
+ prompt "Output buffer replacement policy" if CONFIG_USART_OUTPUT_BUFFER
+config USART_OUTBUFFER_MODE_C_BLOCK
+ bool "Block"
+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
+ default 1 if USART_OUTBUFFER_MODE_C_OVERWRITE
+ default 2 if USART_OUTBUFFER_MODE_C_DROP
+ default 0
+
+config CONFIG_USART_INPUT_BUFFER
+ bool "Use input buffer"
+
+config CONFIG_USART_INBUFFER_SIZE
+ int "Input buffer size in bytes." if CONFIG_USART_INPUT_BUFFER
+ default 0 if ! CONFIG_USART_INPUT_BUFFER
+ range 1 512000 if CONFIG_USART_INPUT_BUFFER
+ default 32
+
+choice USART_INBUFFER_MODE_C
+ prompt "Input buffer replacement policy" if CONFIG_USART_INPUT_BUFFER
+config USART_INBUFFER_MODE_C_BLOCK
+ bool "Block"
+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
+ default 1 if USART_INBUFFER_MODE_C_OVERWRITE
+ default 2 if USART_INBUFFER_MODE_C_DROP
+ default 0
+
+config CONFIG_USART_OUTFILE
+ bool "STD FILE support for output"
+ depends on CONFIG_USART_OUTPUT_BUFFER
+
+config CONFIG_USART_INFILE
+ bool "STD FILE support for input"
+ depends on CONFIG_USART_INPUT_BUFFER
+
+endif
+
+# Timers ########################################################################
+
+config CONFIG_TIMERS
+ bool "Timers"
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 */
diff --git a/template/Makefile b/template/Makefile
index 59218a2..0661d7b 100644
--- a/template/Makefile
+++ b/template/Makefile
@@ -1,5 +1,5 @@
MAKEFLAGS += --no-builtin-rules
-# Change PROJNAME value to you project name
+# Change PROJNAME value to your project name
# Care to not make any space at the end!
PROJNAME = template
diff --git a/tools/kconfig.mk b/tools/kconfig.mk
new file mode 100644
index 0000000..c07bbfa
--- /dev/null
+++ b/tools/kconfig.mk
@@ -0,0 +1,44 @@
+# vim:ts=4:sw=4:sts=4:noexpandtab
+
+ifndef TOOL_PATH
+$(error Before including kconfig.mk you have to define path to tools in variable TOOL_PATH)
+endif
+ifndef CONFIG
+$(error Before including kconfig.mk you have to define variable CONFIG contaning name of configuration file)
+endif
+
+$(CONFIG):
+ @echo Please generate configuration first using config or menuconfig target
+ @exit 1
+
+# We don't wont pass any variable to Kconfig. This is workaround for that.
+# So include of this file should be last line in Makefile
+MAKEOVERRIDES =
+
+callconfig = $(Q)\
+ [ ! -f "$(CONFIG)" ] || mv "$(CONFIG)" config; \
+ IOEROOT="$(IOEROOT)" $(MAKE) -f "$(TOOL_PATH)/kconfig/GNUmakefile" --no-print-directory \
+ TOPDIR=. SRCDIR="$(TOOL_PATH)/kconfig" $(1); \
+ [ ! -f config ] || mv config "$(CONFIG)"; \
+ [ ! -f config.old ] || mv config.old "$(CONFIG).old"
+# Note about this file moving madness:
+# avr-ioe is using Kconfig for configuration and it is not prepared too well for
+# nested projects (at least I don't know way). This unfortunately means that to
+# have configuration in parent project, We have to move it every time we are
+# generating it. Also upper projects can't use Kconfig for its self configuration.
+
+.PHONY: oldconfig
+oldconfig: $(deps_config)
+ $(call callconfig, oldconfig)
+
+.PHONY: config
+config: $(deps_config)
+ $(call callconfig, config)
+
+.PHONY: menuconfig
+menuconfig: $(deps_config)
+ $(call callconfig, menuconfig)
+
+.PHONY: allyesconfig
+allyesconfig: $(deps_config)
+ $(call callconfig, allyesconfig)