diff options
Diffstat (limited to 'include')
-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 |
13 files changed, 157 insertions, 106 deletions
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 |