diff options
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | docs/index.md | 10 | ||||
-rw-r--r-- | docs/miscelaneous/jobs_vs_tasks.md (renamed from docs/miscellanoues/jobs_vs_tasks.md) | 0 | ||||
-rw-r--r-- | docs/references/ioport.md (renamed from docs/parts/ioport.md) | 0 | ||||
-rw-r--r-- | docs/references/jobs.md (renamed from docs/parts/jobs.md) | 0 | ||||
-rw-r--r-- | docs/references/spi.md (renamed from docs/parts/spi.md) | 0 | ||||
-rw-r--r-- | docs/references/tasks.md (renamed from docs/parts/tasks.md) | 0 | ||||
-rw-r--r-- | docs/references/timer.md (renamed from docs/parts/timer.md) | 0 | ||||
-rw-r--r-- | docs/references/usart.md (renamed from docs/parts/usart.md) | 0 | ||||
-rw-r--r-- | docs/references/utils/buffer.md (renamed from docs/parts/utils/buffer.md) | 0 | ||||
-rw-r--r-- | docs/references/utils/narray.md (renamed from docs/parts/utils/narray.md) | 0 | ||||
-rw-r--r-- | examples/blink/blink.c | 6 | ||||
-rw-r--r-- | examples/blink/build/config.h | 1 | ||||
-rw-r--r-- | examples/dht22usart/dht22.c | 26 | ||||
-rw-r--r-- | examples/dht22usart/makefile | 40 | ||||
-rw-r--r-- | include/adc.h | 1 | ||||
-rw-r--r-- | include/eeprom.h | 2 | ||||
-rw-r--r-- | include/error.h | 3 | ||||
-rw-r--r-- | include/jobs.h | 8 | ||||
-rw-r--r-- | include/sensors/dht22.h | 42 | ||||
-rw-r--r-- | include/spi.h | 10 | ||||
-rw-r--r-- | include/sys/mutex.h | 32 | ||||
-rw-r--r-- | include/sys/semaphore.h | 31 | ||||
-rw-r--r-- | include/tasks.h | 56 | ||||
-rw-r--r-- | include/timer.h | 1 | ||||
-rw-r--r-- | include/usi-spi.h | 66 | ||||
-rw-r--r-- | include/usi-twi.h (renamed from include/wireless/nrf24l01p.h) | 0 | ||||
-rw-r--r-- | include/utils/timers_div.h | 11 | ||||
-rw-r--r-- | mkdocs.yml | 20 | ||||
-rw-r--r-- | src/can/mcp2515.c | 52 | ||||
-rw-r--r-- | src/sensors/dht22.c | 117 | ||||
-rw-r--r-- | src/tasks.c | 9 |
34 files changed, 186 insertions, 373 deletions
@@ -8,5 +8,9 @@ *.d *.hex *.elf +*.old +html +build trash libioe.a +install.sh @@ -1,3 +1,4 @@ +# vim:ts=4:sw=4:sts=4:noexpandtab MAKEFLAGS += --no-builtin-rules # Default output path. Can be changed by enviroment to compile to different folder @@ -53,17 +54,17 @@ $(O)/libioe.a: $(OBJ) $(Q)$(AR) -crs $@ $^ $(OBJ): $(O)/build/%.o: src/%.c - $(Q)mkdir -p "$(@D)" + @mkdir -p "$(@D)" @echo " CC $@" $(Q)$(GCC) $(CFLAGS) -c -o $@ $< $(DEP): $(O)/build/%.d: src/%.c $(O)/build/config.h - $(Q)mkdir -p "$(@D)" + @mkdir -p "$(@D)" @echo " DEP $@" $(Q)$(CPP) -MM -MG -MT '$(O)/build/$*.o $@' $(CFLAGS) -o $@ $< $(O)/build/config.h: $(CONFIG) - $(Q)mkdir -p "$(@D)" + @mkdir -p "$(@D)" @echo " GEN $@" $(Q)grep -v "^#" $(CONFIG) | grep "CONFIG_" | sed -e 's/="\(.*\)"/=\1/;s/=/ /;s/^/#define /' > $@ @@ -1,6 +1,6 @@ -#AVR-IOE +# AVR-IOE [![Build Status](https://travis-ci.com/Cynerd/avr-ioe.svg?token=j1mJhmD5jiZyJQGyPUkt&branch=master)](https://travis-ci.com/Cynerd/avr-ioe) -##AVR input/output expansion +## AVR input/output expansion This is library that implements different input/output interfaces and other utilities. Its target is to create simple and highly configurable pack of code for diff --git a/docs/index.md b/docs/index.md index c39df46..23b6cb9 100644 --- a/docs/index.md +++ b/docs/index.md @@ -6,8 +6,8 @@ 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 | +| Parts | Header | Description | +|----------------------------------|----------|--------------------------------------------------------| +| [IO Ports](references/ioport.md) | ioport.h | Simple input/output port access | +| [SPI](references/spi.md) | spi.h | Serial peripheral interface | +| [USART](references/usart.md) | usart.h | Universal synchronous/asynchronous receive/transmitter | diff --git a/docs/miscellanoues/jobs_vs_tasks.md b/docs/miscelaneous/jobs_vs_tasks.md index 17d7fdd..17d7fdd 100644 --- a/docs/miscellanoues/jobs_vs_tasks.md +++ b/docs/miscelaneous/jobs_vs_tasks.md diff --git a/docs/parts/ioport.md b/docs/references/ioport.md index 96a4b82..96a4b82 100644 --- a/docs/parts/ioport.md +++ b/docs/references/ioport.md diff --git a/docs/parts/jobs.md b/docs/references/jobs.md index 878a557..878a557 100644 --- a/docs/parts/jobs.md +++ b/docs/references/jobs.md diff --git a/docs/parts/spi.md b/docs/references/spi.md index f63d304..f63d304 100644 --- a/docs/parts/spi.md +++ b/docs/references/spi.md diff --git a/docs/parts/tasks.md b/docs/references/tasks.md index e4f71df..e4f71df 100644 --- a/docs/parts/tasks.md +++ b/docs/references/tasks.md diff --git a/docs/parts/timer.md b/docs/references/timer.md index e69de29..e69de29 100644 --- a/docs/parts/timer.md +++ b/docs/references/timer.md diff --git a/docs/parts/usart.md b/docs/references/usart.md index 22e54ab..22e54ab 100644 --- a/docs/parts/usart.md +++ b/docs/references/usart.md diff --git a/docs/parts/utils/buffer.md b/docs/references/utils/buffer.md index 4365c25..4365c25 100644 --- a/docs/parts/utils/buffer.md +++ b/docs/references/utils/buffer.md diff --git a/docs/parts/utils/narray.md b/docs/references/utils/narray.md index 3e64f67..3e64f67 100644 --- a/docs/parts/utils/narray.md +++ b/docs/references/utils/narray.md diff --git a/examples/blink/blink.c b/examples/blink/blink.c index 8386d4b..6a81aee 100644 --- a/examples/blink/blink.c +++ b/examples/blink/blink.c @@ -3,12 +3,12 @@ #include <ioport.h> int main() { - io_setout(IO_B3); + io_setout(IO_B0); while (1) { - io_hight(IO_B3); + io_hight(IO_B0); _delay_ms(500); - io_low(IO_B3); + io_low(IO_B0); _delay_ms(500); } } diff --git a/examples/blink/build/config.h b/examples/blink/build/config.h new file mode 100644 index 0000000..5fff870 --- /dev/null +++ b/examples/blink/build/config.h @@ -0,0 +1 @@ +#define CONFIG_IOPORTS y diff --git a/examples/dht22usart/dht22.c b/examples/dht22usart/dht22.c deleted file mode 100644 index ec643aa..0000000 --- a/examples/dht22usart/dht22.c +++ /dev/null @@ -1,26 +0,0 @@ -#include <avr/io.h> -#include <avr/interrupt.h> -#include <util/delay.h> -#include <string.h> -#include "../../usart.h" -//#include "../../sensor_dht22.h" - -void rec(uint8_t data) { - if (data == '\r') { - // TODO read sensor and send data - } -} - -const struct dht22_port dht22_ports[] = { - {&DDRC, &PORTC, &PINC, _BV(PORTC4), NULL, 0} -}; - -int main() { - //usart_async_open(); - //sei(); - //usart_receive = rec; - //dht22_init(0); - - timer_init(COUNTER0_PWM); - while (1); -} diff --git a/examples/dht22usart/makefile b/examples/dht22usart/makefile deleted file mode 100644 index fb69068..0000000 --- a/examples/dht22usart/makefile +++ /dev/null @@ -1,40 +0,0 @@ -MAKEFLAGS += --no-builtin-rules - -MMCU = atmega328p -F_CPU = 16000000L -IOE_PREFIX = ../.. -IOE_SHORTOUTPUT=y -IOE_CFLAGS = -Os -ffunction-sections -fdata-sections -fshort-enums -Wall \ - -DF_CPU=$(F_CPU) -mmcu=$(MMCU) \ - -DCONFIG_IOE_USART \ - -DCONFIG_IOE_USART_OUTBUFFER_SIZE=64 \ - -DCONFIG_IOE_USART_OUTBUFFER_MODE=0 \ - -DCONFIG_IOE_USART_OUTFILE \ - -DCONFIG_IOE_USART_BAUD=115200 \ - -DCONFIG_IOE_USART_PARITY=USART_PARITY_NONE \ - -DCONFIG_IOE_USART_STOPBIT=USART_STOPBIT_SINGLE \ - -DCONFIG_IOE_USART_DATABITS=8 \ - -DCONFIG_IOE_TIMERS \ - -DCONFIG_IOE_SENSOR_DHT22 \ - -DCONFIG_IOE_SENSOR_DHT22_TIMER=COUNTER0_PWM - -all: dht22.hex - @echo Now you can flash dht22.hex to your chip. - -clean: ioeclean - $(RM) dht22.o - $(RM) dht22.elf dht22.hex - -include ../../avr-ioe.mk - -dht22.elf: %.elf: $(IOE_OBJ) dht22.o - @echo " LD $@" - @avr-gcc -Os -mmcu=$(MMCU) $^ -o $@ - -dht22.hex: %.hex: %.elf - @echo " OBJCOPY $@" - @avr-objcopy -O ihex -R .eeprom $< $@ - -dht22.o: %.o: %.c - @echo " CC $@" - @avr-gcc $(IOE_CFLAGS) -c -o $@ $< diff --git a/include/adc.h b/include/adc.h index 86429a1..f865b99 100644 --- a/include/adc.h +++ b/include/adc.h @@ -1,3 +1,4 @@ +// vim:ts=4:sw=4:sts=4:expandtab #include <avr/io.h> #include <avr/interrupt.h> #include <stdint.h> diff --git a/include/eeprom.h b/include/eeprom.h new file mode 100644 index 0000000..31da039 --- /dev/null +++ b/include/eeprom.h @@ -0,0 +1,2 @@ +#include <stdint.h> + diff --git a/include/error.h b/include/error.h new file mode 100644 index 0000000..7b13bcd --- /dev/null +++ b/include/error.h @@ -0,0 +1,3 @@ +#include <stdint.h> + +#include <ioport.h> diff --git a/include/jobs.h b/include/jobs.h new file mode 100644 index 0000000..d2abbdc --- /dev/null +++ b/include/jobs.h @@ -0,0 +1,8 @@ +#include <stdint.h> + +#ifndef _IOE_JOBS_H_ +#define _IOE_JOBS_H_ + + + +#endif /* _IOE_JOBS_H_ */ diff --git a/include/sensors/dht22.h b/include/sensors/dht22.h deleted file mode 100644 index aabb442..0000000 --- a/include/sensors/dht22.h +++ /dev/null @@ -1,42 +0,0 @@ -#include <avr/io.h> -#include <util/delay.h> -#include <stdint.h> - -#include "../tasks.h" -#include "../timer.h" - -#ifndef _IOE_SENSOR_DHT22_H_ -#define _IOE_SENSOR_DHT22_H_ -#ifdef CONFIG_IOE_SENSOR_DHT22 - -struct dht22_value { - uint8_t integral; - uint8_t decimal; -}; - -struct dht22_port { - volatile uint8_t *DDR; // Address of DDR register - volatile uint8_t *PORT; // Address of PORT register - volatile uint8_t *PIN; // Address of PIN register - uint8_t MASK; // _BV() of index of port - volatile uint8_t *PCMSK; // Address of relevant PCMSK register - uint8_t PCMSK_MASK; // _BV() of index of PCMSK -}; - -extern const struct dht22_port dht22_ports[]; - -/* - * Initialize port for sensor - */ -void dht22_init(uint8_t port); - -/* - * Read values from dht22 - * rh - relative - * t - temperature - */ -int8_t dht22_read(uint8_t portindex, struct dht22_value *rh, - struct dht22_value *t); - -#endif /* CONFIG_IOE_SENSOR_DHT22 */ -#endif /* _IOE_SENSOR_DHT22_H_ */ diff --git a/include/spi.h b/include/spi.h index bdfce25..c4c003b 100644 --- a/include/spi.h +++ b/include/spi.h @@ -1,3 +1,4 @@ +// vim:ts=4:sw=4:sts=4:expandtab #include <avr/io.h> #include <avr/interrupt.h> #include <stdint.h> @@ -9,11 +10,6 @@ #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 @@ -22,10 +18,6 @@ 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) { diff --git a/include/sys/mutex.h b/include/sys/mutex.h new file mode 100644 index 0000000..f682e02 --- /dev/null +++ b/include/sys/mutex.h @@ -0,0 +1,32 @@ +#include <avr/io.h> +#include <stdint.h> +#include <stdlib.h> + +#include "../tasks.h" + +#ifndef _IOE_SYS_MUTEX_H_ +#define _IOE_SYS_MUTEX_H_ +#ifdef CONFIG_IOE_MUTEX + +#define MUTEX_F_TIMED (1<<0) +#define MUTEX_F_TAKEN (1<<7) +#define mutex_t volatile struct Mutex +struct Mutex { + uint8_t flags; + Task *_task_took; +}; +int8_t mutex_init(struct Mutex * mtx); +int8_t mutex_free(struct Mutex * mtx); +int8_t mutex_take(struct Mutex * mtx, uint16_t timeout); +int8_t mutex_give(struct Mutex * mtx); + +#else /* CONFIG_IOE_MUTEX */ + +#define mutex_t struct { } +#define mutex_init(MTX, FLAGS) +#define mutex_free(MTX) +#define mutex_take(MTX, TIMEOUT) +#define mutex_give(MTX); + +#endif /* CONFIG_IOE_MUTEX */ +#endif /* _IOE_SYS_MUTEX_H_ */ diff --git a/include/sys/semaphore.h b/include/sys/semaphore.h new file mode 100644 index 0000000..0a25af3 --- /dev/null +++ b/include/sys/semaphore.h @@ -0,0 +1,31 @@ +#include <avr/io.h> +#include <stdint.h> +#include <stdlib.h> + +#ifndef _IOE_SYS_SEMAPHORE_H_ +#define _IOE_SYS_SEMAPHORE_H_ +#ifdef CONFIG_IOE_SEMAPHORE + +#define semaphore_t volatile struct Semaphore +struct Semaphore { + uint8_t flags; + uint8_t _count; + Task **_tasks; + uint8_t _tasks_len; +}; +int8_t semaphore_init(struct Semaphore * sem, uint8_t count); +int8_t semaphore_free(struct Semaphore * sem); +int8_t semaphore_take(struct Semaphore * sem, uint16_t timeout); +int8_t semaphore_give(Semaphore * sem); + +#else /* CONFIG_IOE_SEMAPHORE */ + +#define semaphore_t struct { } +// TODO implement for single processor +#define semaphore_init(SEM, FLAGS, COUNT) +#define semaphore_free(SEM) +#define semaphore_take(SEM, TIMEOUT) +#define semaphore_give(SEM) + +#endif /* CONFIG_IOE_SEMAPHORE */ +#endif /* _IOE_SYS_SEMAPHORE_H_ */ diff --git a/include/tasks.h b/include/tasks.h index 27bd968..b62b093 100644 --- a/include/tasks.h +++ b/include/tasks.h @@ -22,17 +22,21 @@ union StackPointer { uint8_t lh8[2]; uint16_t lh16; }; -typedef struct { + +struct Task { uint8_t flags; void (*func) (void *data); void *data; uint8_t _rflags; uint8_t _stack_size; union StackPointer _sp; -} Task; -int8_t task_spawn(Task * t, uint8_t stack_size); +}; +typedef task_t volatile struct Task; + +int8_t task_spawn(struct Task * t, uint8_t stack_size); +Task *tasks_self(void); void taks_exit(void); -int8_t task_kill(Task * t); +int8_t task_kill(struct Task * t); int8_t task_safe(void); int8_t task_unsafe(void); @@ -40,55 +44,13 @@ int8_t task_delay(uint16_t cycles); int8_t task_delay_ms(uint16_t ms); int8_t task_delay_till(volatile int8_t * boolean, uint16_t ms); -#define MUTEX_F_TIMED (1<<0) -#define MUTEX_F_TAKEN (1<<7) -typedef struct { - uint8_t flags; - Task *_task_took; -} Mutex; -int8_t mutex_init(Mutex * mtx); -int8_t mutex_free(Mutex * mtx); -int8_t mutex_take(Mutex * mtx, uint16_t timeout); -int8_t mutex_give(Mutex * mtx); - -typedef struct { - uint8_t flags; - uint8_t _count; - Task **_tasks; - uint8_t _tasks_len; -} Semaphore; -int8_t semaphore_init(Semaphore * sem, uint8_t count); -int8_t semaphore_free(Semaphore * sem); -int8_t semaphore_take(Semaphore * sem, uint16_t timeout); -int8_t semaphore_give(Semaphore * sem); - #else /* CONFIG_IOE_TASKS */ -typedef struct { -} Task; -#define task_spawn(T, STACK_SIZE) -#define task_exit() -#define task_kill(T) #define task_safe() #define task_unsafe() - -#define task_delay(US) _delay_us(US) // TODO this should be cycles +#define task_delay(CC) _delay_us(CC) // TODO this should be cycles #define task_delay_ms(MS) _delay_ms(MS) int8_t task_delay_till(volatile int8_t * boolean, uint16_t ms); -typedef struct { -} Mutex; -#define mutex_init(MTX, FLAGS) -#define mutex_free(MTX) -#define mutex_take(MTX, TIMEOUT) -#define mutex_give(MTX); - -typedef struct { -} Semaphore; -#define semaphore_init(SEM, FLAGS, COUNT) -#define semaphore_free(SEM) -#define semaphore_take(SEM, TIMEOUT) -#define semaphore_give(SEM) - #endif /* CONFIG_IOE_TASKS */ #endif /* _IOE_TASKS_H_ */ diff --git a/include/timer.h b/include/timer.h index 4fef95c..473110f 100644 --- a/include/timer.h +++ b/include/timer.h @@ -1,3 +1,4 @@ +// vim:ts=4:sw=4:sts=4:expandtab #include <avr/io.h> #include <avr/interrupt.h> #include <stdint.h> diff --git a/include/usi-spi.h b/include/usi-spi.h new file mode 100644 index 0000000..18534ab --- /dev/null +++ b/include/usi-spi.h @@ -0,0 +1,66 @@ +#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/include/wireless/nrf24l01p.h b/include/usi-twi.h index e69de29..e69de29 100644 --- a/include/wireless/nrf24l01p.h +++ b/include/usi-twi.h diff --git a/include/utils/timers_div.h b/include/utils/timers_div.h index 9077aac..c63c8eb 100644 --- a/include/utils/timers_div.h +++ b/include/utils/timers_div.h @@ -1,11 +1,6 @@ -//#include "../timer.h" -enum timerDivider { - TIMER_DIVIDER_1, - TIMER_DIVIDER_8, - TIMER_DIVIDER_64, - TIMER_DIVIDER_256, - TIMER_DIVIDER_1024 -}; +#ifndef _IOE_TIMER_H_ +#error Please include time.h before timers_div.h +#endif #ifndef TIMER_DIV_RESTIME #error Please define minimal time (us) before include timers_div.h in TIMER_DIV_RESTIME @@ -5,19 +5,19 @@ copyright: GNU General Public License, version 2.0 pages: - Home: index.md - Usage: usage.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 +- References: + - IO Ports: references/ioport.md + - SPI: references/spi.md + - Tasks: references/tasks.md + - Jobs: references/jobs.md + - Timer: references/timer.md + - USART: references/usart.md - Utils: - - Buffer: parts/utils/buffer.md - - NArray: parts/utils/narray.md + - Buffer: references/utils/buffer.md + - NArray: references/utils/narray.md - Adding MCU support: add_support.md - Miscellanoues: - - Jobs vs. Tasks: miscellanoues/jobs_vs_tasks.md + - Jobs vs. Tasks: miscelaneous/jobs_vs_tasks.md theme: readthedocs site_dir: html diff --git a/src/can/mcp2515.c b/src/can/mcp2515.c deleted file mode 100644 index 8c9915c..0000000 --- a/src/can/mcp2515.c +++ /dev/null @@ -1,52 +0,0 @@ -#include <can/mcp2515.h> - -#ifdef CONFIG_IOE_CAN_MCP2515 -// TODO check -#define CAN_MCP2515_RESET 0xC0 -#define CAN_MCP2515_READ 0x03 -#define CAN_MCP2515_READRX 0x90 -#define CAN_MCP2515_WRITE 0x02 -#define CAN_MCP2515_LOADTX 0x40 -#define CAN_MCP2515_RTS 0x80 -#define CAN_MCP2515_RDSTAT 0xA0 -#define CAN_MCP2515_RXSTAT 0xB0 -#define CAN_MCP2515_BITMOD 0x05 - -inline void can_mcp2515_init(canMcp2515 * can, uint8_t group, uint8_t mask) { - can->group = group; - can->mask = mask; - can_mcp2515_reset(can); - // TODO - return 0; -}; - -inline void can_mcp2515_reset(canMcp2515 * can) { - take_mutex(spi_mutex); - spi_join(); - - release_mutex(spi_mutex); -}; - -inline uint8_t can_mcp2515_read(canMcp2515 * can, uint8_t address) { -}; - -inline uint8_t can_mcp2515_readrx(canMcp2515 * can, uint8_t buffer) { -}; - -inline void can_mcp2515_write(canMcp2515 * can, uint8_t address, uint8_t data) { -}; - -inline void can_mcp2515_loadrx(canMcp2515 * can, uint8_t buffer, uint8_t data) { -}; - -inline uint8_t can_mcp2515_rdstat(canMcp2515 * can) { -}; - -inline uint8_t can_mcp2515_rxstat(canMcp2515 * can) { -}; - -inline void can_mcp2515_bitmod(canMcp2515 * can, uint8_t address, uint8_t mask, - uint8_t data) { -}; - -#endif /* CONFIG_IOE_CAN_MCP2515 */ diff --git a/src/sensors/dht22.c b/src/sensors/dht22.c deleted file mode 100644 index 9653ba5..0000000 --- a/src/sensors/dht22.c +++ /dev/null @@ -1,117 +0,0 @@ -#include <sensors/dht22.h> - -#ifdef CONFIG_IOE_SENSOR_DHT22 - -#define PP dht22_ports[pi] -#define PPP dht22_ports[dht22_measurement.pi] - -#define TIMEOUT F_CPU/40000 - -#define STATUS_NONE 0 -#define STATUS_COMPLETE 1 -#define STATUS_TIMEOUT 2 - -#define PORT_SENSORW 4 -#define PORT_SENSORRESP_L 3 -#define PORT_SENSORRESP_H 2 -#define PORT_H 1 -#define PORT_L 0 - -struct { - uint8_t index; - uint8_t data[5]; - volatile uint8_t status; - uint8_t pi; - uint8_t port_status; -} dht22_measurement; - -inline void dht22_init(uint8_t pi) { - // Set port as output and set level hight - *(PP.DDR) |= PP.MASK; - *(PP.PORT) |= PP.MASK; - // Enable all pin change interrupts - PCIFR = 0xff; -} - - -inline void dht22_read_deac(uint8_t status) { - dht22_measurement.status = status; - // Disable pin change interrupt - *(PPP.PCMSK) &= ~PPP.PCMSK_MASK; - timer_disable(CONFIG_IOE_SENSOR_DHT22_TIMER); -} - -// This is called from pcint.c -void dht22_read_pcint(void) { - switch (dht22_measurement.port_status) { - case PORT_L: - if (!(*(PPP.PIN) & PPP.MASK)) - return; - dht22_measurement.port_status = PORT_H; - break; - case PORT_H: - if (*(PPP.PIN) & PPP.MASK) - return; - dht22_measurement.port_status = PORT_L; - register uint16_t val; - val = timer_value(CONFIG_IOE_SENSOR_DHT22_TIMER); - // TODO compare value - if (val < 1) { - dht22_measurement.data[dht22_measurement.index / 8] - } - if (++(dht22_measurement.index) == 40) { - dht22_read_deac(STATUS_COMPLETE); - return; - } - break; - default: - if (((*(PPP.PIN) & PPP.MASK) && dht22_measurement.port_status == 3) - || !(*(PPP.PIN & PPP.MASK))) - return; - dht22_measurement.port_status--; - } - timer_reset(CONFIG_IOE_SENSOR_DHT22_TIMER); -} - -void dht22_read_timer_overflow(void) { - dht22_read_deac(STATUS_TIMEOUT); -} - -int8_t dht22_read(uint8_t pi, struct dht22_value *rh, - struct dht22_value *t) { - dht22_measurement.index = 0; - dht22_measurement.status = STATUS_NONE; - dht22_measurement.pi = pi; - dht22_measurement.port_status = PORT_SENSORW; - - // Pull port down for 500us - *(PP.PORT) &= ~PP.MASK; - _delay_us(500); - // Initialize timer - timer_init(CONFIG_IOE_SENSOR_DHT22_TIMER, TIMER_DIVIDER_64); - timer_sethook(CONFIG_IOE_SENSOR_DHT22_TIMER, - dht22_read_timer_overflow); - // Set pin change interrupt - *(PP.PCMSK) |= PP.PCMSK_MASK; - // Set port as output and pull-up resistor - *(PP.DDR) &= ~PP.MASK; - *(PP.PORT) |= PP.MASK; - // Delay till reading is done - taskDelayTill(&(dht22_measurement.status)); - - // Copy data - rh->integral = dht22_measurement.data[0]; - rh->decimal = dht22_measurement.data[1]; - t->integral = dht22_measurement.data[2]; - t->decimal = dht22_measurement.data[3]; - // Check sum - uint8_t sum = dht22_measurement.data[0]; - sum += dht22_measurement.data[1]; - sum += dht22_measurement.data[2]; - sum += dht22_measurement.data[3]; - if (sum != dht22_measurement.data[4]) - return 1; - return dht22_measurement.status - 1; -} - -#endif /* CONFIG_IOE_SENSOR_SHT22 */ diff --git a/src/tasks.c b/src/tasks.c index abc2add..27f8fb4 100644 --- a/src/tasks.c +++ b/src/tasks.c @@ -33,15 +33,6 @@ void task_stack_reg(TaskStack * ts, Task * t) { void task_stack_unreg(TaskStack * ts, Task * t) { } -void init_mutex(Mutex * mtx, uint8_t flags) { -}; -void take_mutex(Mutex * mtx) { -}; -int8_t take_mutex_t(Mutex * mtx, uint16_t timeout) { -}; -void give_mutex(Mutex * mtx) { -}; - #else /* CONFIG_IOE_TASKS */ int8_t task_delay_till(volatile int8_t * boolean, uint16_t timeout) { |