aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2015-03-14 11:36:26 +0100
committerKarel Kočí <cynerd@email.cz>2015-03-14 11:36:26 +0100
commit8a115123eee5b9e294ff86ec4e41e6112dc47774 (patch)
tree23e864f9fafb91a77ca6b57956dcfa69dc5209b1
parentd7a7c97220ab9660722a3602cc74549b0c82d3d0 (diff)
downloadavr-ioe-8a115123eee5b9e294ff86ec4e41e6112dc47774.tar.gz
avr-ioe-8a115123eee5b9e294ff86ec4e41e6112dc47774.tar.bz2
avr-ioe-8a115123eee5b9e294ff86ec4e41e6112dc47774.zip
SPI USI implementation !NOT TESTED!
SPI on USI implemented. But not tested yet.
-rw-r--r--spi_usi.h25
-rw-r--r--src/avr25/spi_usi.c56
2 files changed, 81 insertions, 0 deletions
diff --git a/spi_usi.h b/spi_usi.h
new file mode 100644
index 0000000..2e603ac
--- /dev/null
+++ b/spi_usi.h
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <inttypes.h>
+
+#include "mcu/mcu.h"
+
+#ifndef _IOE_SPI_USI_H_
+#define _IOE_SPI_USI_H_
+
+inline void ioe_spi_usi_init(void);
+#ifdef IOE_SPI_USI_MASTER
+inline int8_t ioe_spi_usi_transfer(int8_t data);
+#else
+inline void ioe_spi_usi_expose(int8_t data);
+inline void ioe_spi_usi_expect(void);
+inline int ioe_spi_usi_ready(void);
+inline void ioe_spi_usi_join(void);
+
+// Following function must be user defined
+inline void ioe_spi_usi_retrieve(int8_t data);
+#endif /* IOE_SPI_USI_MASTER */
+
+
+#endif /* _IOE_SPI_USI_H_ */
diff --git a/src/avr25/spi_usi.c b/src/avr25/spi_usi.c
new file mode 100644
index 0000000..e63721a
--- /dev/null
+++ b/src/avr25/spi_usi.c
@@ -0,0 +1,56 @@
+#include "../../spi_usi.h"
+
+#if __AVR_ARCH__ == 25
+
+#ifdef IOE_SPI_USI_MASTER
+
+// TODO counter settings with interups
+inline void ioe_spi_usi_init(void) {
+ USI_DIR_REG |= _BV(USI_USCK_PIN) | _BV(USI_DO_PIN);
+ USI_OUT_REG |= _BV(USI_DI_PIN);
+
+ USICR |= _BV(USIWM0) | _BV(USICS1) | _BV(USICLK);
+}
+
+inline int8_t ioe_spi_usi_transfer(int8_t d) {
+ USISR |= _BV(USIOIF);
+ USIDR = d;
+ do {
+ USICR |= _BV(USITC);
+ } while (!(USISR & _BV(USIOIF)));
+ return USIDR;
+}
+
+#else /* IOE_SPI_USI_MASTER */
+
+inline void ioe_spi_usi_init(void) {
+ USI_DIR_REG |= _BV(USI_DO_PIN);
+ USI_OUT_REG |= _BV(USI_USCK_PIN) | _BV(USI_DI_PIN);
+
+ USICR |= _BV(USIWM0) | _BV(USICS1) | _BV(USIOIE);
+}
+
+inline void ioe_spi_usi_expose(int8_t data) {
+ USIDR = data;
+}
+
+inline void ioe_spi_usi_expect(void) {
+ USISR |= _BV(USIOIF);
+}
+
+inline int ioe_spi_usi_busy(void) {
+ return USISR & 0x0F;
+}
+
+inline void ioe_spi_usi_join(void) {
+ while (ioe_spi_usi_busy()) {
+ }
+}
+
+SIGNAL(USI_OVF_vect) {
+ ioe_spi_usi_retrieve(USIDR);
+}
+
+#endif /* IOE_SPI_USI_MASTER */
+
+#endif /* __AVR_ARCH__ == 25 */