summaryrefslogtreecommitdiff
path: root/src/arch
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch')
-rw-r--r--src/arch/msp430fr5969lp/Makefile.inc4
-rw-r--r--src/arch/msp430fr5969lp/driver/spi.cc61
-rw-r--r--src/arch/msp430fr5969lp/driver/spi_b.cc26
3 files changed, 21 insertions, 70 deletions
diff --git a/src/arch/msp430fr5969lp/Makefile.inc b/src/arch/msp430fr5969lp/Makefile.inc
index 8480b71..1581c2d 100644
--- a/src/arch/msp430fr5969lp/Makefile.inc
+++ b/src/arch/msp430fr5969lp/Makefile.inc
@@ -24,8 +24,8 @@ ifneq ($(findstring i2c,${arch_drivers}), )
TARGETS += src/arch/msp430fr5969lp/driver/i2c.cc
endif
-ifneq ($(findstring spi,${arch_drivers}), )
- TARGETS += src/arch/msp430fr5969lp/driver/spi.cc
+ifneq ($(findstring spi_a1,${arch_drivers}), )
+ TARGETS += src/arch/msp430fr5969lp/driver/spi_a1.cc
endif
ifneq ($(findstring spi_b,${arch_drivers}), )
diff --git a/src/arch/msp430fr5969lp/driver/spi.cc b/src/arch/msp430fr5969lp/driver/spi.cc
deleted file mode 100644
index 981bc53..0000000
--- a/src/arch/msp430fr5969lp/driver/spi.cc
+++ /dev/null
@@ -1,61 +0,0 @@
-#include "driver/spi.h"
-#include <msp430.h>
-
-signed char SPI::setup()
-{
- /* UCA1CLK Pin 2.4 */
- P2SEL0 &= ~BIT4;
- P2SEL1 |= BIT4;
- P2DIR |= BIT4;
-
- /* UCA1SIMO Pin 2.5 */
- P2SEL0 &= ~BIT5;
- P2SEL1 |= BIT5;
- P2DIR |= BIT5;
-
- /* UCA1SOMI Pin 2.6 */
- P2SEL0 &= ~BIT6;
- P2SEL1 |= BIT6;
- P2DIR &= ~BIT6;
- //P2REN |= BIT6;
-
- UCA1CTLW0 |= UCSWRST;
- UCA1MCTLW = 0; // no modulation
-
- UCA1CTLW0 = UCCKPH | UCMSB | UCMST | UCSYNC | UCMODE_0 | UCSSEL__SMCLK | UCSWRST;
- UCA1BRW = 15; // /16 -> 1MHz
- UCA1CTLW0 &= ~UCSWRST;
-}
-
-signed char SPI::xmit(unsigned char tx_len, unsigned char *tx_buf,
- unsigned char rx_len, unsigned char *rx_buf)
-{
- volatile char rxbuf_cache;
- if (tx_len < 1) {
- return -1;
- }
-
- UCA1IE &= ~(UCTXIE | UCRXIE);
-
- while (UCA1STATW & UCBUSY) ;
-
- rxbuf_cache = UCA1RXBUF;
- UCA1TXBUF = tx_buf[0];
-
- unsigned char tx_pos = 1;
- unsigned char rx_pos = 0;
-
- while (tx_pos < tx_len || rx_pos < rx_len) {
- if ((tx_pos < tx_len) && (UCA1IF & UCTXIFG)) {
- UCBA1TXBUF = tx_buf[tx_pos++];
- }
- if (UCA1IFG & UCRXIFG) {
- if (rx_pos < rx_len) {
- rx_buf[rx_pos] = UCA1RXBUF;
- } else {
- rxbuf_cache = UCA1RXBUF;
- }
- }
- rx_pos++;
- }
-}
diff --git a/src/arch/msp430fr5969lp/driver/spi_b.cc b/src/arch/msp430fr5969lp/driver/spi_b.cc
index eafb94e..2eb3a79 100644
--- a/src/arch/msp430fr5969lp/driver/spi_b.cc
+++ b/src/arch/msp430fr5969lp/driver/spi_b.cc
@@ -1,8 +1,10 @@
-#include "driver/spi.h"
+#include "driver/spi_b.h"
#include <msp430.h>
-signed char SPI::setup()
+void SPI::setup()
{
+ UCB0CTLW0 |= UCSWRST;
+
/* UCB0CLK Pin 2.2 */
P2SEL0 &= ~BIT2;
P2SEL1 |= BIT2;
@@ -24,19 +26,25 @@ signed char SPI::setup()
UCB0CTLW0 &= ~UCSWRST;
}
+static inline unsigned char clean_rxbuf()
+{
+ return UCB0RXBUF;
+}
+
signed char SPI::xmit(unsigned char tx_len, unsigned char *tx_buf,
unsigned char rx_len, unsigned char *rx_buf)
{
- volatile char rxbuf_cache;
if (tx_len < 1) {
return -1;
}
- UCB0IE &= ~(UCTXIE | UCRXIE);
-
while (UCB0STATW & UCBUSY) ;
- rxbuf_cache = UCB0RXBUF;
+ if (!(UCB0IFG & UCTXIFG)) {
+ return -1;
+ }
+
+ UCB0IFG &= ~UCRXIFG;
UCB0TXBUF = tx_buf[0];
unsigned char tx_pos = 1;
@@ -50,9 +58,13 @@ signed char SPI::xmit(unsigned char tx_len, unsigned char *tx_buf,
if (rx_pos < rx_len) {
rx_buf[rx_pos] = UCB0RXBUF;
} else {
- rxbuf_cache = UCB0RXBUF;
+ UCB0IFG &= ~UCRXIFG;
}
rx_pos++;
}
}
+ while (UCB0STATW & UCBUSY) ;
+ return 0;
}
+
+SPI spi;