From ae3acc651a459500bc11ba938607875c6ae21f3a Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 31 Aug 2020 15:24:50 +0200 Subject: msp430fr: rename spi_b to spi to be consistent with other architectures --- src/app/sharp96test/Makefile.inc | 2 +- src/app/sharp96test/main.cc | 2 +- src/app/transactiontest/main.cc | 11 ++--- src/app/transactiontest/util.S | 9 ++-- src/arch/msp430fr5969lp/Kconfig | 2 +- src/arch/msp430fr5969lp/Makefile.inc | 16 ++----- src/arch/msp430fr5969lp/driver/spi.cc | 75 +++++++++++++++++++++++++++++++++ src/arch/msp430fr5969lp/driver/spi_b.cc | 75 --------------------------------- src/arch/msp430fr5994lp/Kconfig | 2 +- src/arch/msp430fr5994lp/Makefile.inc | 16 ++----- src/arch/msp430fr5994lp/driver/spi.cc | 75 +++++++++++++++++++++++++++++++++ src/arch/msp430fr5994lp/driver/spi_b.cc | 75 --------------------------------- src/driver/nrf24l01.cc | 8 ---- src/driver/sharp96.cc | 2 +- 14 files changed, 172 insertions(+), 198 deletions(-) create mode 100644 src/arch/msp430fr5969lp/driver/spi.cc delete mode 100644 src/arch/msp430fr5969lp/driver/spi_b.cc create mode 100644 src/arch/msp430fr5994lp/driver/spi.cc delete mode 100644 src/arch/msp430fr5994lp/driver/spi_b.cc (limited to 'src') diff --git a/src/app/sharp96test/Makefile.inc b/src/app/sharp96test/Makefile.inc index 37bb857..a63136a 100644 --- a/src/app/sharp96test/Makefile.inc +++ b/src/app/sharp96test/Makefile.inc @@ -1,5 +1,5 @@ ifdef app override loop = 1 - override arch_drivers += spi_b + override arch_drivers += spi override drivers += sharp96 endif diff --git a/src/app/sharp96test/main.cc b/src/app/sharp96test/main.cc index bbf9258..38a8a3d 100644 --- a/src/app/sharp96test/main.cc +++ b/src/app/sharp96test/main.cc @@ -1,7 +1,7 @@ #include "arch.h" #include "driver/gpio.h" #include "driver/stdout.h" -#include "driver/spi_b.h" +#include "driver/spi.h" #include "driver/sharp96.h" unsigned char const lynx[12 * 96] = { diff --git a/src/app/transactiontest/main.cc b/src/app/transactiontest/main.cc index 1ca7f67..12d995f 100644 --- a/src/app/transactiontest/main.cc +++ b/src/app/transactiontest/main.cc @@ -2,13 +2,9 @@ #include "driver/gpio.h" #include "driver/stdout.h" #include "driver/uptime.h" -#include "driver/spi_b.h" +#include "driver/spi.h" #include "driver/sharp96.h" -#ifndef TIMER_CYCLES -#error makeflag timer_cycles=1 required -#endif - unsigned char const lynx[12 * 96] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -117,6 +113,9 @@ extern "C" { uint16_t i = 0; class Transaction { + /** + * Transactions objects must not be nested. + */ public: inline Transaction() { asm_save_all(); } inline ~Transaction() {} @@ -126,7 +125,6 @@ class Transaction { void loop(void) { - gpio.led_toggle(1); { Transaction tx; kout << dec << i << endl; @@ -153,7 +151,6 @@ int main(void) sharp96.setup(); sharp96.powerOn(); - gpio.led_on(0); gpio.input(GPIO::p4_5, 1); asm_load_all(); diff --git a/src/app/transactiontest/util.S b/src/app/transactiontest/util.S index 1a12736..ea298b6 100644 --- a/src/app/transactiontest/util.S +++ b/src/app/transactiontest/util.S @@ -6,6 +6,7 @@ #define SRAM_SIZE 4096 ; SRAM and stack pointer backup space +; two backup areas allow for consistency in case of a power loss during backup sp_backup1: .space 2 sram_backup1: @@ -20,7 +21,8 @@ sram_backup2: backup_cookie: .space 2 -; save entire SRAM and CPU register state to persistent FRAM +; save entire SRAM and CPU register state to persistent FRAM. +; Must be called with interrupts disabled asm_save_all: ; r4 to r11 are callee saved -> push them to the stack. @@ -65,9 +67,8 @@ save_sram_word: ; load entire SRAM and CPU register state from persistent FRAM, ; if it contains valid backup data. Execution will resume at the -; last place where asm_save_all() was called is if nothing in between -; had happened. Does not take possible the state of hardware peripherals -; into account. +; last place where asm_save_all() was called as if nothing in between +; had happened. Does not take the state of hardware peripherals into account. asm_load_all: ; check if we have backup data diff --git a/src/arch/msp430fr5969lp/Kconfig b/src/arch/msp430fr5969lp/Kconfig index 549c54f..6b085ae 100644 --- a/src/arch/msp430fr5969lp/Kconfig +++ b/src/arch/msp430fr5969lp/Kconfig @@ -16,7 +16,7 @@ select meta_driver_i2c #bool "SPI on eUSCI_A1" #select meta_driver_spi -config arch_msp430fr5969lp_driver_spi_b +config arch_msp430fr5969lp_driver_spi bool "SPI on eUSCI_B0" select meta_driver_spi diff --git a/src/arch/msp430fr5969lp/Makefile.inc b/src/arch/msp430fr5969lp/Makefile.inc index 8a48859..af285ac 100644 --- a/src/arch/msp430fr5969lp/Makefile.inc +++ b/src/arch/msp430fr5969lp/Makefile.inc @@ -47,12 +47,8 @@ else ifneq ($(findstring i2c,${arch_drivers}), ) CONFIG_arch_msp430fr5969lp_driver_i2c = y endif -ifneq ($(findstring spi_a1,${arch_drivers}), ) - CONFIG_arch_msp430fr5969lp_driver_spi_a1 = y -endif - -ifneq ($(findstring spi_b,${arch_drivers}), ) - CONFIG_arch_msp430fr5969lp_driver_spi_b = y +ifneq ($(findstring spi,${arch_drivers}), ) + CONFIG_arch_msp430fr5969lp_driver_spi = y endif ifneq ($(findstring timer,${arch_drivers}), ) @@ -82,12 +78,8 @@ ifdef CONFIG_arch_msp430fr5969lp_driver_i2c COMMON_FLAGS += -DDRIVER_I2C endif -ifdef CONFIG_arch_msp430fr5969lp_driver_spi_a1 - CXX_TARGETS += src/arch/msp430fr5969lp/driver/spi_a1.cc -endif - -ifdef CONFIG_arch_msp430fr5969lp_driver_spi_b - CXX_TARGETS += src/arch/msp430fr5969lp/driver/spi_b.cc +ifdef CONFIG_arch_msp430fr5969lp_driver_spi + CXX_TARGETS += src/arch/msp430fr5969lp/driver/spi.cc endif ifdef CONFIG_arch_msp430fr5969lp_driver_timer diff --git a/src/arch/msp430fr5969lp/driver/spi.cc b/src/arch/msp430fr5969lp/driver/spi.cc new file mode 100644 index 0000000..f34a76b --- /dev/null +++ b/src/arch/msp430fr5969lp/driver/spi.cc @@ -0,0 +1,75 @@ +#include "driver/spi.h" +#include + +#ifndef F_I2C +#define F_I2C 1000000UL +#endif + +void SPI::setup() +{ + UCB0CTLW0 |= UCSWRST; + + /* UCB0CLK Pin 2.2 */ + P2SEL0 &= ~BIT2; + P2SEL1 |= BIT2; + P2DIR |= BIT2; + + /* UCB0SIMO Pin 1.6 */ + P1SEL0 &= ~BIT6; + P1SEL1 |= BIT6; + P1DIR |= BIT6; + + /* UCB0SOMI Pin 1.7 */ + P1SEL0 &= ~BIT7; + P1SEL1 |= BIT7; + P1DIR &= ~BIT7; + //P1REN |= BIT6; + + UCB0CTLW0 = UCCKPH | UCMSB | UCMST | UCSYNC | UCMODE_0 | UCSSEL__SMCLK | UCSWRST; + UCB0BRW = (F_CPU/F_I2C)-1; // /16 -> 1MHz + // UCB0BRW = (F_CPU / F_I2C) - 1 + 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) +{ + if (tx_len < 1) { + return -1; + } + + while (UCB0STATW & UCBUSY) ; + + if (!(UCB0IFG & UCTXIFG)) { + return -1; + } + + UCB0IFG &= ~UCRXIFG; + UCB0TXBUF = 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) && (UCB0IFG & UCTXIFG)) { + UCB0TXBUF = tx_buf[tx_pos++]; + } + if (UCB0IFG & UCRXIFG) { + if (rx_pos < rx_len) { + rx_buf[rx_pos] = UCB0RXBUF; + } else { + UCB0IFG &= ~UCRXIFG; + } + rx_pos++; + } + } + while (UCB0STATW & UCBUSY) ; + return 0; +} + +SPI spi; diff --git a/src/arch/msp430fr5969lp/driver/spi_b.cc b/src/arch/msp430fr5969lp/driver/spi_b.cc deleted file mode 100644 index 0fa71da..0000000 --- a/src/arch/msp430fr5969lp/driver/spi_b.cc +++ /dev/null @@ -1,75 +0,0 @@ -#include "driver/spi_b.h" -#include - -#ifndef F_I2C -#define F_I2C 1000000UL -#endif - -void SPI::setup() -{ - UCB0CTLW0 |= UCSWRST; - - /* UCB0CLK Pin 2.2 */ - P2SEL0 &= ~BIT2; - P2SEL1 |= BIT2; - P2DIR |= BIT2; - - /* UCB0SIMO Pin 1.6 */ - P1SEL0 &= ~BIT6; - P1SEL1 |= BIT6; - P1DIR |= BIT6; - - /* UCB0SOMI Pin 1.7 */ - P1SEL0 &= ~BIT7; - P1SEL1 |= BIT7; - P1DIR &= ~BIT7; - //P1REN |= BIT6; - - UCB0CTLW0 = UCCKPH | UCMSB | UCMST | UCSYNC | UCMODE_0 | UCSSEL__SMCLK | UCSWRST; - UCB0BRW = (F_CPU/F_I2C)-1; // /16 -> 1MHz - // UCB0BRW = (F_CPU / F_I2C) - 1 - 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) -{ - if (tx_len < 1) { - return -1; - } - - while (UCB0STATW & UCBUSY) ; - - if (!(UCB0IFG & UCTXIFG)) { - return -1; - } - - UCB0IFG &= ~UCRXIFG; - UCB0TXBUF = 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) && (UCB0IFG & UCTXIFG)) { - UCB0TXBUF = tx_buf[tx_pos++]; - } - if (UCB0IFG & UCRXIFG) { - if (rx_pos < rx_len) { - rx_buf[rx_pos] = UCB0RXBUF; - } else { - UCB0IFG &= ~UCRXIFG; - } - rx_pos++; - } - } - while (UCB0STATW & UCBUSY) ; - return 0; -} - -SPI spi; diff --git a/src/arch/msp430fr5994lp/Kconfig b/src/arch/msp430fr5994lp/Kconfig index 385b59c..e240c2b 100644 --- a/src/arch/msp430fr5994lp/Kconfig +++ b/src/arch/msp430fr5994lp/Kconfig @@ -16,7 +16,7 @@ select meta_driver_i2c #bool "SPI on eUSCI_A1" #select meta_driver_spi -config arch_msp430fr5994lp_driver_spi_b +config arch_msp430fr5994lp_driver_spi bool "SPI on eUSCI_B1" select meta_driver_spi diff --git a/src/arch/msp430fr5994lp/Makefile.inc b/src/arch/msp430fr5994lp/Makefile.inc index 9446aeb..68d3894 100644 --- a/src/arch/msp430fr5994lp/Makefile.inc +++ b/src/arch/msp430fr5994lp/Makefile.inc @@ -58,12 +58,8 @@ else ifneq ($(findstring i2c,${arch_drivers}), ) CONFIG_arch_msp430fr5994lp_driver_i2c = y endif -ifneq ($(findstring spi_a1,${arch_drivers}), ) - CONFIG_arch_msp430fr5994lp_driver_spi_a1 = y -endif - -ifneq ($(findstring spi_b,${arch_drivers}), ) - CONFIG_arch_msp430fr5994lp_driver_spi_b = y +ifneq ($(findstring spi,${arch_drivers}), ) + CONFIG_arch_msp430fr5994lp_driver_spi = y endif ifneq ($(findstring timer,${arch_drivers}), ) @@ -93,12 +89,8 @@ ifdef CONFIG_arch_msp430fr5994lp_driver_i2c COMMON_FLAGS += -DDRIVER_I2C endif -ifdef CONFIG_arch_msp430fr5994lp_driver_spi_a1 - CXX_TARGETS += src/arch/msp430fr5994lp/driver/spi_a1.cc -endif - -ifdef CONFIG_arch_msp430fr5994lp_driver_spi_b - CXX_TARGETS += src/arch/msp430fr5994lp/driver/spi_b.cc +ifdef CONFIG_arch_msp430fr5994lp_driver_spi + CXX_TARGETS += src/arch/msp430fr5994lp/driver/spi.cc endif ifdef CONFIG_arch_msp430fr5994lp_driver_timer diff --git a/src/arch/msp430fr5994lp/driver/spi.cc b/src/arch/msp430fr5994lp/driver/spi.cc new file mode 100644 index 0000000..543987d --- /dev/null +++ b/src/arch/msp430fr5994lp/driver/spi.cc @@ -0,0 +1,75 @@ +#include "driver/spi.h" +#include + +#ifndef F_I2C +#define F_I2C 1000000UL +#endif + +void SPI::setup() +{ + UCB1CTLW0 |= UCSWRST; + + /* UCB1CLK Pin 5.2 */ + P5SEL1 &= ~BIT2; + P5SEL0 |= BIT2; + P5DIR |= BIT2; + + /* UCB1SIMO Pin 5.0 */ + P5SEL1 &= ~BIT0; + P5SEL0 |= BIT0; + P5DIR |= BIT0; + + /* UCB1SOMI Pin 5.1 */ + P5SEL1 &= ~BIT1; + P5SEL0 |= BIT1; + P5DIR &= ~BIT1; + //P1REN |= BIT6; + + UCB1CTLW0 = UCCKPH | UCMSB | UCMST | UCSYNC | UCMODE_0 | UCSSEL__SMCLK | UCSWRST; + UCB1BRW = (F_CPU/F_I2C)-1; // /16 -> 1MHz + // UCB1BRW = (F_CPU / F_I2C) - 1 + UCB1CTLW0 &= ~UCSWRST; +} + +static inline unsigned char clean_rxbuf() +{ + return UCB1RXBUF; +} + +signed char SPI::xmit(unsigned char tx_len, unsigned char *tx_buf, + unsigned char rx_len, unsigned char *rx_buf) +{ + if (tx_len < 1) { + return -1; + } + + while (UCB1STATW & UCBUSY) ; + + if (!(UCB1IFG & UCTXIFG)) { + return -1; + } + + UCB1IFG &= ~UCRXIFG; + UCB1TXBUF = 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) && (UCB1IFG & UCTXIFG)) { + UCB1TXBUF = tx_buf[tx_pos++]; + } + if (UCB1IFG & UCRXIFG) { + if (rx_pos < rx_len) { + rx_buf[rx_pos] = UCB1RXBUF; + } else { + UCB1IFG &= ~UCRXIFG; + } + rx_pos++; + } + } + while (UCB1STATW & UCBUSY) ; + return 0; +} + +SPI spi; diff --git a/src/arch/msp430fr5994lp/driver/spi_b.cc b/src/arch/msp430fr5994lp/driver/spi_b.cc deleted file mode 100644 index 8624a40..0000000 --- a/src/arch/msp430fr5994lp/driver/spi_b.cc +++ /dev/null @@ -1,75 +0,0 @@ -#include "driver/spi_b.h" -#include - -#ifndef F_I2C -#define F_I2C 1000000UL -#endif - -void SPI::setup() -{ - UCB1CTLW0 |= UCSWRST; - - /* UCB1CLK Pin 5.2 */ - P5SEL1 &= ~BIT2; - P5SEL0 |= BIT2; - P5DIR |= BIT2; - - /* UCB1SIMO Pin 5.0 */ - P5SEL1 &= ~BIT0; - P5SEL0 |= BIT0; - P5DIR |= BIT0; - - /* UCB1SOMI Pin 5.1 */ - P5SEL1 &= ~BIT1; - P5SEL0 |= BIT1; - P5DIR &= ~BIT1; - //P1REN |= BIT6; - - UCB1CTLW0 = UCCKPH | UCMSB | UCMST | UCSYNC | UCMODE_0 | UCSSEL__SMCLK | UCSWRST; - UCB1BRW = (F_CPU/F_I2C)-1; // /16 -> 1MHz - // UCB1BRW = (F_CPU / F_I2C) - 1 - UCB1CTLW0 &= ~UCSWRST; -} - -static inline unsigned char clean_rxbuf() -{ - return UCB1RXBUF; -} - -signed char SPI::xmit(unsigned char tx_len, unsigned char *tx_buf, - unsigned char rx_len, unsigned char *rx_buf) -{ - if (tx_len < 1) { - return -1; - } - - while (UCB1STATW & UCBUSY) ; - - if (!(UCB1IFG & UCTXIFG)) { - return -1; - } - - UCB1IFG &= ~UCRXIFG; - UCB1TXBUF = 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) && (UCB1IFG & UCTXIFG)) { - UCB1TXBUF = tx_buf[tx_pos++]; - } - if (UCB1IFG & UCRXIFG) { - if (rx_pos < rx_len) { - rx_buf[rx_pos] = UCB1RXBUF; - } else { - UCB1IFG &= ~UCRXIFG; - } - rx_pos++; - } - } - while (UCB1STATW & UCBUSY) ; - return 0; -} - -SPI spi; diff --git a/src/driver/nrf24l01.cc b/src/driver/nrf24l01.cc index a381fd0..1cde2ba 100644 --- a/src/driver/nrf24l01.cc +++ b/src/driver/nrf24l01.cc @@ -6,15 +6,7 @@ #include "driver/nrf24l01.h" #include "driver/nrf24l01/registers.h" -#ifdef MULTIPASS_ARCH_arduino_nano #include "driver/spi.h" -#endif -#ifdef MULTIPASS_ARCH_msp430fr5969lp -#include "driver/spi_b.h" -#endif -#ifdef MULTIPASS_ARCH_msp430fr5994lp -#include "driver/spi_b.h" -#endif #include "driver/gpio.h" #include "arch.h" diff --git a/src/driver/sharp96.cc b/src/driver/sharp96.cc index 1e9a2ec..2bd46d7 100644 --- a/src/driver/sharp96.cc +++ b/src/driver/sharp96.cc @@ -1,5 +1,5 @@ #include "driver/sharp96.h" -#include "driver/spi_b.h" +#include "driver/spi.h" #include "driver/gpio.h" #ifndef SHARP96_POWER_PIN -- cgit v1.2.3