aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Kconfig127
-rw-r--r--Makefile13
-rw-r--r--conffile65
-rw-r--r--docs/index.md17
-rw-r--r--docs/miscellanoues/jobs_vs_tasks.md17
-rw-r--r--docs/parts/ioport.md (renamed from docs/modules/ioport.md)82
-rw-r--r--docs/parts/jobs.md15
-rw-r--r--docs/parts/spi.md (renamed from docs/modules/spi.md)31
-rw-r--r--docs/parts/tasks.md (renamed from docs/modules/tasks.md)3
-rw-r--r--docs/parts/timer.md (renamed from docs/modules/timer.md)0
-rw-r--r--docs/parts/usart.md23
-rw-r--r--docs/parts/utils/buffer.md (renamed from docs/modules/utils/buffer.md)0
-rw-r--r--docs/parts/utils/narray.md (renamed from docs/modules/utils/narray.md)0
-rw-r--r--docs/usage.md1
-rw-r--r--examples/blink/Makefile8
-rw-r--r--include/can/global.h20
-rw-r--r--include/can/mcp2515.h36
-rw-r--r--include/can/software.h9
-rw-r--r--include/spi.h10
-rw-r--r--include/usart.h10
-rw-r--r--include/usi_spi.h66
-rw-r--r--mkdocs.yml19
-rw-r--r--src/base.c (renamed from docs/modules/usart.md)0
-rw-r--r--src/spi.c4
-rw-r--r--src/usart.c76
25 files changed, 311 insertions, 341 deletions
diff --git a/Kconfig b/Kconfig
index b748514..ebafb5b 100644
--- a/Kconfig
+++ b/Kconfig
@@ -23,6 +23,59 @@ config CONFCFLAGS
endmenu
+# Tracing and error handling ####################################################
+
+menu "Tracing and error handling"
+
+config CONFIG_ERRORS
+ bool "Errors support"
+
+if CONFIG_ERRORS
+
+menu "Errors handling"
+
+config CONFIG_EH_RESTART
+ bool "Restart MCU on error detection"
+
+config CONFIG_EH_MEMORY
+ bool "TODO: Write error code and possible stack trase to EEPROM"
+
+config CONFIG_EH_LED
+ bool "Signal error detection by LED"
+ depends on CONFIG_IOPORTS
+
+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)").
+
+config CONFIG_EH_USART
+ bool "Send error informations by UART"
+ depends on CONFIG_USART && CONFIG_USART_OUTPUT_BUFFER
+
+endmenu
+
+config CONFIG_CHECK_ARGUMENTS
+ bool "Check arguments for all functions in library"
+
+endif
+
+config CONFIG_TRACING
+ bool "TODO: Tracing support"
+
+if CONFIG_TRACING
+
+config CONFIG_TRACE_FUNCTIONCALL
+ bool "TODO: Trace all function calls in library"
+
+endif
+
+endmenu
+
# IO Ports ######################################################################
config MCUSUPPORT_IOPORTS
@@ -92,6 +145,7 @@ config CONFIG_USART_PARITY
config CONFIG_USART_DATABITS
int "Data bits"
default 8
+ range 5 8
choice USART_STOPBIT_C
prompt "Stop bit"
@@ -111,7 +165,8 @@ config CONFIG_USART_OUTPUT_BUFFER
config CONFIG_USART_OUTBUFFER_SIZE
int "Output buffer size in bytes." if CONFIG_USART_OUTPUT_BUFFER
- default 0 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
@@ -134,7 +189,8 @@ config CONFIG_USART_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
+ default 0 if ! CONFIG_USART_INPUT_BUFFER
+ range 1 512000 if CONFIG_USART_INPUT_BUFFER
default 32
choice USART_INBUFFER_MODE_C
@@ -152,4 +208,71 @@ config CONFIG_USART_INBUFFER_MODE
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"
+
+# Tasks #########################################################################
+
+menuconfig CONFIG_TASKS
+ bool "Taks support"
+ depends on CONFIG_TIMERS
+
+if CONFIG_TASKS
+
+config CONFIG_TASKS_TIME
+ bool "Measure approximate real time"
+
+choice TASKS_TIMER
+ prompt "Timer used for tasks planning and interrupts"
+ default TASKS_TIMER_2
+
+config TASKS_TIMER_0
+ bool "Timer0 (8-bit)"
+
+config TASKS_TIMER_1
+ bool "Timer1 (16-bit)"
+
+config TASKS_TIMER_2
+ bool "Timer2 (8-bit asynchronous)"
+
+endchoice
+
+endif
+
+# Jobs ##########################################################################
+
+menuconfig CONFIG_JOBS
+ bool "Jobs support"
+ ---help---
+ Job support allows you to plan and execute functions periodically. This is
+ designed for realtime control.
+
+if CONFIG_JOBS
+
+choice JOBS_DURATION
+ prompt "Jobs duration source"
+
+config JOBS_DURATION_CONSTANT
+ bool "Predefined constants"
+
+config JOBS_DURATION_PREV
+ bool "Previous execution time"
+
+config JOBS_DURATION_MAX
+ bool "Maximum previous time"
+
+endchoice
+
+endif
diff --git a/Makefile b/Makefile
index 0ddb6d8..67aaf49 100644
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,7 @@ ifeq (,$(filter clean help docs serve-docs clean-docs config oldconfig \
allyesconfig menuconfig, \
$(MAKECMDGOALS))) # Ignore build targets if goal is not building
--include $(O)/build/config.mk # include configuration
+include $(CONFIG) # include configuration
### Source files list ###########################
SRC = base.c
@@ -56,20 +56,15 @@ $(OBJ): $(O)/build/%.o: src/%.c
@echo " CC $@"
$(Q)$(GCC) $(CFLAGS) -c -o $@ $<
-$(DEP): $(O)/build/%.d: src/%.c $(O)/build/config.mk
+$(DEP): $(O)/build/%.d: src/%.c
$(Q)mkdir -p "$(@D)"
@echo " DEP $@"
$(Q)$(GCC) -MM -MG -MT '$*.o $@' $(CFLAGS) -c -o $@ $<
-$(O)/build/config.mk: $(CONFIG)
- $(Q)mkdir -p "$(@D)"
- @echo " GEN $(CONFIG).mk"
- $(Q)sed 's/="\(.*\)"/=\1/' $(CONFIG) > "$@"
-
$(O)/build/config.h: $(CONFIG)
$(Q)mkdir -p "$(@D)"
- @echo " GEN $(CONFIG).h"
- $(Q)grep -v "^#" $(CONFIG) | grep "CONFIG_" | sed 's/=/ /;s/^/#define /' > $@
+ @echo " GEN $@"
+ $(Q)grep -v "^#" $(CONFIG) | grep "CONFIG_" | sed 's/="\(.*\)"/=\1/;s/=/ /;s/^/#define /' > $@
# This is not optimal because configuration change results to complete project
# rebuild instead of only rebuilding required files.
diff --git a/conffile b/conffile
deleted file mode 100644
index 6342804..0000000
--- a/conffile
+++ /dev/null
@@ -1,65 +0,0 @@
-MCU::
- type string
- default "atmega328p"
- menu "MCU name"
-
-F_CPU::
- type float
- default 16
- menu "CPU frequency"
-#################################################################################
-
-if MCU == "atmega328p"
-MCUSUPPORT_SPI:
-MCUSUPPORT_USART:
-endif
-
-#################################################################################
-
-IOE_SPI: MCUSUPPORT_USART
- menu "SPI interface"
-
-group IOE_USART: MCUSUPPORT_SPI
- type bool
- menu "USART interface"
-
-IOE_USART_BAUD:
- type int<0,>
- menu "Baud"
-
-IOE_USART_PARITY:
- type {!None("USART_PARITY_NONE"), Odd("USART_PARITY_ODD"), Even("USART_PARITY_EVEN")}
- menu "Parity"
-
-IOE_USART_STOPBIT:
- type {!Single("USART_STOPBIT_SINGLE"), Double("USART_STOPBIT_DOUBLE")}
- menu "Number of stop bits"
-
-IOE_USART_DATABITS:
- type int<5,8>
- default 8
- menu "Number of data bits"
-
-IOE_USART_INBUFFER_SIZE:
- type int<0,>
- menu "USART input buffer size"
- help "Defines size of input buffer for USART interface."
- " If size is set to 0, no buffer is used."
-
-IOE_USART_OUTBUFFER_SIZE:
- type int<0,>
- menu "USART output buffer size"
- help "Defines size of output buffer for USART interface."
- " If size is set to 0, no buffer is used."
-endgroup # IOE_USART
-
-IOE_CAN_MCP2515: IOE_SPI
- menu "MCP2515 CAN controller"
-
-group SENSORS:
- menu "Sensors"
-
-IOE_SENSOR_DHT22:
- menu "DHT22 temperature and humidity sensor"
-
-endgroup # SENSORS
diff --git a/docs/index.md b/docs/index.md
index 4c261ff..c39df46 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -1,10 +1,13 @@
AVR Input/Output expansion
==========================
-Modules
--------
-| Module | Header | Enable Config | Description |
-|-------------------------------|----------|-------------------------------------------|--------------------------------------------------------|
-| [IO Ports](modules/ioport.md) | ioport.h | CONFIG_IOPORTS and CONFIG_IOE_PCINTERRUPT | Simple input/output port access |
-| [SPI](modules/spi.md) | spi.h | CONFIG_SPI | Serial peripheral interface |
-| [USART](modules/usart.md) | usart.h | CONFIG_USART | Universal synchronous/asynchronous receive/transmitter |
+Parts
+-----
+Whole library consists from set of parts. You can use any part directly or
+only trough other part. Every part can be enabled or disabled.
+
+| Parts | Header | Description |
+|-------------------------------|----------|--------------------------------------------------------|
+| [IO Ports](parts/ioport.md) | ioport.h | Simple input/output port access |
+| [SPI](parts/spi.md) | spi.h | Serial peripheral interface |
+| [USART](parts/usart.md) | usart.h | Universal synchronous/asynchronous receive/transmitter |
diff --git a/docs/miscellanoues/jobs_vs_tasks.md b/docs/miscellanoues/jobs_vs_tasks.md
new file mode 100644
index 0000000..17d7fdd
--- /dev/null
+++ b/docs/miscellanoues/jobs_vs_tasks.md
@@ -0,0 +1,17 @@
+Jobs vs. Tasks
+==============
+This document refers to [Jobs](/parts/jobs.md) and [Tasks](/parts/tasks.md).
+
+You should be familiar with threads from other platforms. Tasks are from usability
+point of view almost same. They are switched according their priority and
+availability. Jobs are different. They are designed to execute single function at
+the time and when this function exits it executes another. It cant interrupt
+execution when more important task come. So why use jobs instead of tasks? Task
+requires for their run stack memory and during whole live of task is this memory
+taken. This limits number of tasks running. Jobs are sharing same stack and only
+one function has data on it at the time. This results in less memory consumption.
+Another huge difference is how planing works. Tasks are planned based on priority.
+Task with higher priority will run unless it isn't suspended. Jobs don't have
+priority, but they have to specify time until they should be finished (deadline)
+and duration of execution. With these two parameters jobs planner can plan their
+execution.
diff --git a/docs/modules/ioport.md b/docs/parts/ioport.md
index e777e0c..96a4b82 100644
--- a/docs/modules/ioport.md
+++ b/docs/parts/ioport.md
@@ -1,6 +1,5 @@
IO port
=======
-To use include: `ioport.md`
And define: `CONFIG_IOE_IOPORT`
Defines simple access to io ports. This allows runtime access to any pin with just
@@ -16,36 +15,45 @@ command.
WARNING: No check is implemented for right group number. Usage of unsupported
value is undefined (write to other parts of memory can happen).
-## References
+Configuration
+-------------
+To use this part, you must enable `CONFIG_IOPORTS` option.
+This part also handles pin change interrupts. Enable it using
+`CONFIG_IOPORTS_PCINT` option.
+
+References
+----------
### For output
#### Function io_setout
```C
static inline void io_setout(uint8_t group, uint8_t mask)
```
Configures port of `group` with `mask` as output.
-Parameters:
- group - Character specifying exact port group
- mask - Binary shifted 1. Shift is equal to port index in specified group.
+Parameters:
+__group__ - Character specifying exact port group
+__mask__ - Binary shifted 1. Shift is equal to port index in specified group.
#### Function io_hight
```C
static inline void io_hight(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.
-Parameters:
- group - Character specifying exact port group
- mask - Binary shifted 1. Shift is equal to port index in specified group.
+WARNING: Invoke this only if io_setout is called before.
+
+Parameters:
+__group__ - Character specifying exact port group
+__mask__ - Binary shifted 1. Shift is equal to port index in specified group.
#### Function io_low
```C
static inline void io_low(uint8_t group, uint8_t mask)
```
Sets output port to low (also called as 0).
-WARNING: Invoke this only if io_setout is called before.
-Parameters:
- group - Number specifying exact port group
- mask - Binary shifted 1. Shift is equal to port index in specified group.
+WARNING: Invoke this only if io_setout is called before.
+
+Parameters:
+__group__ - Number specifying exact port group
+__mask__ - Binary shifted 1. Shift is equal to port index in specified group.
#### Function io_set
```C
@@ -53,9 +61,9 @@ static inline void io_set(uint8_t group, uint8_t mask, int8_t val)
```
Sets output port to value passed as argument.
WARNING: Invoke this only if io_setout is called before.
-Parameters:
- group - Number specifying exact port group
- mask - Binary shifted 1. Shift is equal to port index in specified group.
+Parameters:
+__group__ - Number specifying exact port group
+__mask__ - Binary shifted 1. Shift is equal to port index in specified group.
### For input
#### Function io_setin
@@ -64,20 +72,22 @@ static inline void io_setin(uint8_t group, uint8_t mask,
enum ioeIOInResistor resistor)
```
Configures port of `group` with `mask` as input with specified pull-up/down
-resistor.
-Parameters:
- group - Number specifying exact port group
- mask - Binary shifted 1. Shift is equal to port index in specified group.
+resistor.
+
+Parameters:
+__group__ - Number specifying exact port group
+__mask__ - Binary shifted 1. Shift is equal to port index in specified group.
#### Function io_get
```C
static inline int8_t io_get(uint8_t group, uint8_t mask)
```
Returns current value of port. Note that you can use this also if port is
-configured as output.
-Parameters:
- group - Number specifying exact port group
- mask - Binary shifted 1. Shift is equal to port index in specified group.
+configured as output.
+
+Parameters:
+__group__ - Number specifying exact port group
+__mask__ - Binary shifted 1. Shift is equal to port index in specified group.
#### Enum ioeIOInResistor
```C
@@ -100,20 +110,22 @@ specifies port and edge specifies on what edge should hook be called. `edge` can
be IO_RISING or IO_FALLING or their binary combination with operator
`|`.
WARNING: `change` call is call during interrupt handling. You shouldn't be
-blocking execution for long time.
+blocking execution for long time.
+
Parameters:
- group - Number specifying exact port group
- mask - Binary shifted 1. Shift is equal to port index in specified group.
- edge - Signals on what edge should be hook called.
- change - Pointer to function used as interupt hook
+__group__ - Number specifying exact port group.
+__mask__ - Binary shifted 1. Shift is equal to port index in specified group.
+__edge__ - Signals on what edge should be hook called.
+__change__ - Pointer to function used as interupt hook.
#### Function io_change_remhook
```C
int8_t io_change_remhook(void (*change) (uint8_t group, uint8_t mask))
```
-Removes `change` hook.
+Removes `change` hook.
+
Parameters:
- change - Pointer to function used as hook
+__change__ - Pointer to function used as hook
### Others
#### Definitions IO_{GROUP}
@@ -126,12 +138,14 @@ mcu support file should define all ports in form of single line definition in
format `IOE_IO_{GROUP}{INDEX}`. Disadvantage is that with these definitions you
can't use binary conjunction and so only one pin can be controlled with it.
-## Relevant examples
+Relevant examples
+-----------------
* blink
* pcinterrupt
-## Adding support
-For more information on how add support, see `doc/add_support.md`.
+Adding support
+--------------
+For more information on how add support, see [Adding MCU support](/add_support.md).
Main definition is `MCUSUPPORT_IOPORT`. Define it to enable support.
### IO_{GROUP}
diff --git a/docs/parts/jobs.md b/docs/parts/jobs.md
new file mode 100644
index 0000000..878a557
--- /dev/null
+++ b/docs/parts/jobs.md
@@ -0,0 +1,15 @@
+Jobs
+====
+Jobs allows periodic execution of different short functions. It is designed to host
+control loops. So called functions should be short.
+
+Every job must specify deadline and if not set otherwise also its duration.
+
+If tasks support is enabled jobs can be also executed on multiple tasks, which is
+handy if you divide sensor reading and control algorithm, because control
+algorithm can than run when for example mcu waiting for response from sensor.
+Always be sure that jobs are running on tasks with highest priority, otherwise
+deadlines might not be fulfilled every time.
+
+Be aware of taking mutexes and semaphores. It can sometime result in long task
+suspension and that would result to deadline misses.
diff --git a/docs/modules/spi.md b/docs/parts/spi.md
index 3ae730c..f63d304 100644
--- a/docs/modules/spi.md
+++ b/docs/parts/spi.md
@@ -1,9 +1,16 @@
Serial peripheral interface
===========================
-This interface is link to MOSI and MISO pins. Also SS pin is used when slave mode initialized.
+To use include: `spi.h`
+This interface is link to MOSI and MISO pins. Also SS pin is used when slave mode
+initialized.
-## References
-### spi\_init
+Configuration
+-------------
+To use SPI you must enable `CONFIG_SPI` configuration symbol.
+
+References
+----------
+### Function spi\_init
```C
static inline void spi_init(enum spiMode mode)
```
@@ -13,20 +20,20 @@ Parameters:
NOTE: Global interrupts must be enabled for right function of SPI.
-### spi\_busy
+### Function spi\_busy
```C
static inline int8_t spi_busy(void)
```
Returns NULL when device is not busy.
When device is busy return values in non-zero.
-### spi\_join
+### Function spi\_join
```C
static inline void spi_join(void)
```
Blocks processor until device is not busy.
-### spi\_send
+### Function spi\_send
```C
static inline uint8_t spi_send(uint8_t data)
```
@@ -34,7 +41,7 @@ Swap bytes with slave over SPI.
This function blocks execution until device isn't busy (transfer completed).
WARNING: Invoke this only when interface is initialized in MASTER mode.
-### spi\_transfer
+### Function spi\_transfer
```C
static inline void spi_transfer(uint8_t data)
```
@@ -43,7 +50,7 @@ This function isn't blocking execution until transfer is complete.
Always call spi\_join before this function when called outside of spi\_receive().
WARNING: Invoke this only when interface is initialized in MASTER mode.
-### spi\_expose
+### Function spi\_expose
```C
static inline void spi_expose(uint8_t data)
```
@@ -52,14 +59,14 @@ Please don't use this when device is busy.
Best place to call this is spi\_receive().
WARNING: Invoke this only when interface is initialized in SLAVE mode.
-## Function pointer spi\_receive
+### Function pointer spi\_receive
```C
extern void (*spi_receive)(uint8_t data)
```
This function is called every time transfer is finished.
And until return from this function interrupts are disabled.
-## Enum spiMode
+### Enum spiMode
```C
enum spiMode {
SPI_MODE_MASTER,
@@ -67,3 +74,7 @@ enum spiMode {
};
```
This is used as parameter for spi\_init function.
+
+Relevant examples
+-----------------
+* spiblink
diff --git a/docs/modules/tasks.md b/docs/parts/tasks.md
index 0078f00..e4f71df 100644
--- a/docs/modules/tasks.md
+++ b/docs/parts/tasks.md
@@ -1,6 +1,7 @@
Tasks
=====
-Tasks allows separate jobs.
+Tasks can be used for sharing processor for example during period of waiting for
+interrupt. Planing is based on priority.
## Functions
### tasks_run
diff --git a/docs/modules/timer.md b/docs/parts/timer.md
index e69de29..e69de29 100644
--- a/docs/modules/timer.md
+++ b/docs/parts/timer.md
diff --git a/docs/parts/usart.md b/docs/parts/usart.md
new file mode 100644
index 0000000..22e54ab
--- /dev/null
+++ b/docs/parts/usart.md
@@ -0,0 +1,23 @@
+Universal synchronous/asynchronous receive/transmitter
+======================================================
+This part acts as UART intended as text base interface with computer. It is
+using hardware termed as USART by Atmel. This hardware also supports synchronous
+communication and can behave as SPI master, but this is not supported by this
+library (I don't require this feature, but implementation is welcomed).
+
+This part implements, if enabled, whole stack for binding input and output to
+stdin and stdout. This is handy during development. You can use `printf` and
+`scanf` directly.
+
+This part can be enabled by `CONFIG_USART` configuration option. This enables
+more detailed configuration in sub-menu.
+
+## Usage
+
+
+## References
+### usart_init_async
+```C
+void usart_init_async(void)
+```
+
diff --git a/docs/modules/utils/buffer.md b/docs/parts/utils/buffer.md
index 4365c25..4365c25 100644
--- a/docs/modules/utils/buffer.md
+++ b/docs/parts/utils/buffer.md
diff --git a/docs/modules/utils/narray.md b/docs/parts/utils/narray.md
index 3e64f67..3e64f67 100644
--- a/docs/modules/utils/narray.md
+++ b/docs/parts/utils/narray.md
diff --git a/docs/usage.md b/docs/usage.md
index e69de29..b96c601 100644
--- a/docs/usage.md
+++ b/docs/usage.md
@@ -0,0 +1 @@
+Sorry this documentation is not finished yet. To start you can look to examples.
diff --git a/examples/blink/Makefile b/examples/blink/Makefile
index ef7e205..f2cc133 100644
--- a/examples/blink/Makefile
+++ b/examples/blink/Makefile
@@ -30,7 +30,7 @@ clean:
$(Q)$(RM) $(OBJ)
@echo " CLEAN $(PROJNAME).elf $(PROJNAME).hex"
$(Q)$(RM) $(PROJNAME).elf $(PROJNAME).hex
- $(Q)$(MAKE) -C ../.. clean O=examples/blink
+ $(Q)$(MAKE) -C ../.. clean O=examples/$(PROJNAME)
# Building targets are available only if configuration is generated
ifneq ("$(wildcard .config)","")
@@ -54,7 +54,7 @@ $(OBJ): %.o: %.c libioe.a
$(Q)avr-gcc $(CFLAGS) -c -o $@ $<
libioe.a: .config
- $(Q)$(MAKE) -C ../.. examples/blink/libioe.a O=examples/blink
+ $(Q)$(MAKE) -C ../.. examples/$(PROJNAME)/libioe.a O=examples/$(PROJNAME)
endif
.config:
@@ -62,8 +62,8 @@ endif
@exit 1
config:
- $(Q)$(MAKE) -C ../.. config O=examples/blink
+ $(Q)$(MAKE) -C ../.. config O=examples/$(PROJNAME)
.PHONY: menuconfig
menuconfig:
- $(Q)$(MAKE) -C ../.. menuconfig O=examples/blink
+ $(Q)$(MAKE) -C ../.. menuconfig O=examples/$(PROJNAME)
diff --git a/include/can/global.h b/include/can/global.h
deleted file mode 100644
index 5d88fe6..0000000
--- a/include/can/global.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#include <stdint.h>
-
-#ifndef _IOE_CAN_GLOBAL_
-#define _IOE_CAN_GLOBAL_
-
-typedef struct {
- uint16_t id;
- uint8_t length;
- uint8_t data[8];
-} CanFrame;
-
-typedef struct {
- CanFrame **buffer;
- void *udata;
-} Can;
-
-
-void can_send(Can *can, CanFrame *frame);
-
-#endif /* _IOE_CAN_GLOBAL_ */
diff --git a/include/can/mcp2515.h b/include/can/mcp2515.h
deleted file mode 100644
index 59376f7..0000000
--- a/include/can/mcp2515.h
+++ /dev/null
@@ -1,36 +0,0 @@
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <stdint.h>
-
-#include "spi.h"
-#include "global.h"
-
-#ifndef _IOE_CAN_MCP2515_H_
-#define _IOE_CAN_MCP2515_H_
-#ifdef CONFIG_IOE_CAN_MCP2515
-#ifndef CONFIG_IOE_SPI
-#error "Please define CONFIG_IOE_SPI. MCP2515 requires SPI."
-#endif
-
-// TODO registers
-#define CAN_MCP2515_CANCTL
-// TODO buffers
-
-typedef struct {
- uint8_t group, mask;
-} CanMcp2515;
-
-int8_t can_mcp2515_init(CanMcp2515 * can, uint8_t group, uint8_t mask);
-
-void can_mcp2515_reset(CanMcp2515 * can);
-uint8_t can_mcp2515_read(CanMcp2515 * can, uint8_t address);
-uint8_t can_mcp2515_readrx(CanMcp2515 * can, uint8_t buffer);
-void can_mcp2515_write(CanMcp2515 * can, uint8_t address, uint8_t data);
-void can_mcp2515_loadrx(CanMcp2515 * can, uint8_t buffer, uint8_t data);
-uint8_t can_mcp2515_rdstat(CanMcp2515 * can);
-uint8_t can_mcp2515_rxstat(CanMcp2515 * can);
-void can_mcp2515_bitmod(CanMcp2515 * can, uint8_t address, uint8_t mask,
- uint8_t data);
-
-#endif /* CONFIG_IOE_CAN_MCP2515 */
-#endif /* _IOE_CAN_MCP2515_H_ */
diff --git a/include/can/software.h b/include/can/software.h
deleted file mode 100644
index b443e42..0000000
--- a/include/can/software.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <avr/io.h>
-#include <util/delay.h>
-#include <stdint.h>
-
-#ifndef _IOE_CAN_SOFTWARE_H_
-#define _IOE_CAN_SOFTWARE_H_
-
-
-#endif /* _IOE_CAN_SOFTWARE_H_ */
diff --git a/include/spi.h b/include/spi.h
index 8d51eb9..bdfce25 100644
--- a/include/spi.h
+++ b/include/spi.h
@@ -9,6 +9,11 @@
#define _IOE_SPI_H_
#ifdef CONFIG_SPI
+/*! \brief Modes definition for spi_init
+ *
+ * This enum is used by spi_init to define if SPI should be initialized as master
+ * or slave.
+ */
enum spiMode {
SPI_MODE_MASTER,
SPI_MODE_SLAVE
@@ -17,6 +22,10 @@ enum spiMode {
volatile extern int8_t _spi_busy;
volatile extern Mutex spi_mutex;
+/*! \brief Initializes SPI interface.
+ *
+ * \param mode Specify mode of SPI interface
+ */
static inline void spi_init(enum spiMode mode) {
_spi_busy = 0;
if (mode == SPI_MODE_MASTER) {
@@ -59,7 +68,6 @@ static inline void spi_expose(uint8_t data) {
SPDR = data;
}
-// Null terminated array
extern void (*spi_receive)(uint8_t data);
#endif /* CONFIG_SPI */
diff --git a/include/usart.h b/include/usart.h
index 3ba5382..a3f585a 100644
--- a/include/usart.h
+++ b/include/usart.h
@@ -17,12 +17,10 @@
#define USART_DATAOVERRUN _BV(DOR0)
#define USART_PARITYERROR _BV(UPE0)
-#if CONFIG_USART_INBUFFER_SIZE > 0
-#define _USART_INBUFFER
+#ifdef CONFIG_USART_INPUT_BUFFER
volatile IOEBUFFER(uint8_t, _ioe_usart_inbuffer, CONFIG_USART_INBUFFER_SIZE);
#endif
-#if CONFIG_USART_OUTBUFFER_SIZE > 0
-#define _USART_OUTBUFFER
+#ifdef CONFIG_USART_OUTPUT_BUFFER
volatile IOEBUFFER(uint8_t, _ioe_usart_outbuffer, CONFIG_USART_OUTBUFFER_SIZE);
#endif
@@ -46,10 +44,10 @@ static inline uint8_t usart_queryerror(void) {
static inline int8_t usart_busy(void) {
return _usart_busy;
}
-#ifdef _USART_INBUFFER
+#ifdef CONFIG_USART_INPUT_BUFFER
uint8_t usart_inbuffered(void);
#endif
-#ifdef _USART_OUTBUFFER
+#ifdef CONFIG_USART_OUTPUT_BUFFER
uint8_t usart_outbuffered(void);
#endif
#if (defined CONFIG_USART_INFILE) || (defined CONFIG_USART_OUTFILE)
diff --git a/include/usi_spi.h b/include/usi_spi.h
deleted file mode 100644
index 18534ab..0000000
--- a/include/usi_spi.h
+++ /dev/null
@@ -1,66 +0,0 @@
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <stdint.h>
-
-#include "mcu/mcu_def.h"
-
-#ifndef _IOE_USI_SPI_H_
-#define _IOE_USI_SPI_H_
-
-#ifndef MCUSUPPORT_USI
-#error "No USI interface is known on your mcu."
-#endif
-
-enum usiSpiMode {
- // Device is initialized as master
- USI_SPI_MODE_MASTER,
- // Device is initialized as slave
- USI_SPI_MODE_SLAVE,
-};
-
-/*
- * Initialize SPI on USI device
- *
- * Parameters:
- * mode - Specify mode of SPI interface
- */
-void usi_spi_init(enum usiSpiMode mode);
-/*
- * Returns NULL when device is not busy.
- * When device is busy return values in non-zero.
- */
-int8_t usi_spi_busy(void);
-/*
- * Blocks processor until device is not busy.
- */
-void usi_spi_join(void);
-/*
- * Swap bytes with slave over SPI.
- * This function blocks execution until device isn't busy.
- * WARNING: Invoke this only when interface is initialized in MASTER mode.
- */
-uint8_t usi_spi_send(uint8_t data);
-/*
- * Swaps byte with slave over SPI.
- * This function isn't checking if device is busy, but it's not blocking execution.
- * WARNING: Invoke this only when interface is initialized in MASTER mode.
- */
-uint8_t usi_spi_transfer(uint8_t data);
-/*
- * Expose data for next master request.
- * Please don't use this when device is busy.
- * Best place to call this is usi_spi_retrieve().
- * WARNING: Invoke this only when interface is initialized in SLAVE mode.
- */
-void usi_spi_expose(uint8_t data);
-
-/*
- * This function must be defined by user.
- * This function is called every time transfer is finished.
- * And until return from this function interrupts are disabled.
- * WARNING: Please define this function in your code.
- */
-void usi_spi_receive(uint8_t data);
-
-
-#endif /* _IOE_USI_SPI_H_ */
diff --git a/mkdocs.yml b/mkdocs.yml
index a0724b4..83ec683 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -5,16 +5,19 @@ copyright: GNU General Public License, version 2.0
pages:
- Home: index.md
- Usage: usage.md
-- Modules:
- - IO Ports: modules/ioport.md
- - SPI: modules/spi.md
- - Tasks: modules/tasks.md
- - Timer: modules/timer.md
- - USART: modules/usart.md
+- Parts:
+ - IO Ports: parts/ioport.md
+ - SPI: parts/spi.md
+ - Tasks: parts/tasks.md
+ - Jobs: parts/jobs.md
+ - Timer: parts/timer.md
+ - USART: parts/usart.md
- Utils:
- - Buffer: modules/utils/buffer.md
- - NArray: modules/utils/narray.md
+ - Buffer: parts/utils/buffer.md
+ - NArray: parts/utils/narray.md
- Adding MCU support: add_support.md
+- Miscellanoues:
+ - Jobs vs. Tasks: miscellanoues/jobs_vs_tasks.md
theme: readthedocs
site_dir: html
diff --git a/docs/modules/usart.md b/src/base.c
index e69de29..e69de29 100644
--- a/docs/modules/usart.md
+++ b/src/base.c
diff --git a/src/spi.c b/src/spi.c
index 69012fa..adf858d 100644
--- a/src/spi.c
+++ b/src/spi.c
@@ -8,11 +8,9 @@ volatile Mutex spi_mutex;
void (*spi_receive) (uint8_t data) = 0;
ISR(SPI_STC_vect, ISR_BLOCK) {
- void (*spir_w) (uint8_t data) = spi_receive;
_spi_busy = 0;
- while (spir_w != NULL) {
+ if (spi_receive != NULL) {
spir_w(SPDR);
- spir_w++;
}
}
diff --git a/src/usart.c b/src/usart.c
index 6cfbc20..12528f9 100644
--- a/src/usart.c
+++ b/src/usart.c
@@ -8,50 +8,6 @@
#define USART_STOPBIT_SINGLE 1
#define USART_STOPBIT_DOUBLE 2
-#ifndef CONFIG_USART_BAUD
-#warning "CONFIG_USART_BAUD not defined. Setting default 9600."
-#define CONFIG_USART_BAUD 9600
-#endif
-#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_USART_STOPBIT
-#warning "CONFIG_USART_STOPBIT not defined. Using default USART_STOPBIT_SINGLE."
-#define CONFIG_USART_STOPBIT USART_STOPBIT_SINGLE
-#endif
-#ifndef CONFIG_USART_DATABITS
-#warning "CONFIG_USART_DATABITS not defined. Using default 8."
-#define CONFIG_USART_DATABITS 8
-#endif
-
-#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_USART_STOPBIT == USART_STOPBIT_SINGLE) || \
- (CONFIG_USART_STOPBIT == USART_STOPBIT_DOUBLE))
-#error "CONFIG_USART_STOPBIT has value, that is not allowed."
-#endif
-
-#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_USART_DATABITS has value, that is not allowed."
-#endif
-
-#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_USART_OUTFILE) && (CONFIG_USART_OUTBUFFER_SIZE <= 0)
-#error "USART Input file can't be enabled without output buffer"
-#endif
-
-
volatile int8_t _usart_busy;
void usart_init_async(void) {
@@ -89,40 +45,40 @@ void usart_init_async(void) {
// Enable receiver, transmitter and RX complete,
// Data register empty interrupts
UCSR0B = _BV(RXEN0) | _BV(TXEN0) | _BV(RXCIE0) | _BV(UDRIE0);
-#ifdef _USART_INBUFFER
+#ifdef CONFIG_USART_INPUT_BUFFER
IOEBUFFER_INIT(_ioe_usart_inbuffer, CONFIG_USART_INBUFFER_SIZE);
#endif
-#ifdef _USART_OUTBUFFER
+#ifdef CONFIG_USART_OUTPUT_BUFFER
IOEBUFFER_INIT(_ioe_usart_outbuffer, CONFIG_USART_OUTBUFFER_SIZE);
#endif
}
inline void usart_send(uint8_t data) {
-#ifdef _USART_OUTBUFFER
+#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);
+ CONFIGCONFIG_USART_OUTPUT_BUFFER_MODE);
}
#else
_usart_busy = 1;
UDR0 = data;
-#endif /* _USART_OUTBUFFER */
+#endif /* CONFIG_USART_OUTPUT_BUFFER */
}
-#ifdef _USART_OUTBUFFER
+#ifdef CONFIG_USART_OUTPUT_BUFFER
inline void usart_send_str(char *str) {
while (*str != '\0') {
usart_send((uint8_t) * str);
str++;
}
}
-#endif /* _USART_OUTBUFFER */
+#endif /* CONFIG_USART_OUTPUT_BUFFER */
-#ifdef _USART_INBUFFER
+#ifdef CONFIG_USART_INPUT_BUFFER
uint8_t usart_get(void) {
uint8_t rtn;
IOEBUFFER_GET(_ioe_usart_inbuffer, CONFIG_USART_INBUFFER_SIZE,
@@ -131,7 +87,7 @@ uint8_t usart_get(void) {
}
#endif
-#ifdef _USART_INBUFFER
+#ifdef CONFIG_USART_INPUT_BUFFER
uint8_t usart_inbuffered(void) {
uint8_t rtn;
IOEBUFFER_CNT(_ioe_usart_inbuffer, CONFIG_USART_INBUFFER_SIZE,
@@ -140,7 +96,7 @@ uint8_t usart_inbuffered(void) {
}
#endif
-#ifdef _USART_OUTBUFFER
+#ifdef CONFIG_USART_OUTPUT_BUFFER
uint8_t usart_outbuffered(void) {
uint8_t rtn;
IOEBUFFER_CNT(_ioe_usart_outbuffer, CONFIG_USART_OUTBUFFER_SIZE,
@@ -156,7 +112,7 @@ static int usartput(char c, FILE * f) {
}
#endif
-#ifdef CONFIG_USART_INBUFFER
+#ifdef CONFIGCONFIG_USART_INPUT_BUFFER
static int usartget(FILE * f) {
uint8_t v;
while (!(v = usart_get()));
@@ -184,17 +140,17 @@ void (*usart_receive) (uint8_t data) = 0;
void (*usart_sent) (void) = 0;
SIGNAL(USART_RX_vect) {
-#ifdef _USART_INBUFFER
+#ifdef CONFIG_USART_INPUT_BUFFER
uint8_t val = UDR0;
IOEBUFFER_PUT(_ioe_usart_inbuffer, CONFIG_USART_INBUFFER_SIZE,
- val, CONFIG_USART_INBUFFER_MODE);
-#endif /* _USART_INBUFFER */
+ val, CONFIGCONFIG_USART_INPUT_BUFFER_MODE);
+#endif /* CONFIG_USART_INPUT_BUFFER */
if (usart_receive)
usart_receive(UDR0);
}
SIGNAL(USART_UDRE_vect) {
-#ifdef _USART_OUTBUFFER
+#ifdef CONFIG_USART_OUTPUT_BUFFER
uint8_t val;
IOEBUFFER_GET(_ioe_usart_outbuffer, CONFIG_USART_OUTBUFFER_SIZE,
val);
@@ -204,7 +160,7 @@ SIGNAL(USART_UDRE_vect) {
_usart_busy = 0;
#else
_usart_busy = 0;
-#endif /* _USART_OUTBUFFER */
+#endif /* CONFIG_USART_OUTPUT_BUFFER */
if (usart_sent)
usart_sent();
}