[rtems commit] bsp/atsam: Avoid to power on/off the SPI module

Sebastian Huber sebh at rtems.org
Wed Dec 14 12:10:18 UTC 2016


Module:    rtems
Branch:    master
Commit:    5dd02e95696bc573dbcb2df0afc0c2607bdd8f53
Changeset: http://git.rtems.org/rtems/commit/?id=5dd02e95696bc573dbcb2df0afc0c2607bdd8f53

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Dec 13 15:49:09 2016 +0100

bsp/atsam: Avoid to power on/off the SPI module

---

 c/src/lib/libbsp/arm/atsam/include/atsam-spi.h |  2 +-
 c/src/lib/libbsp/arm/atsam/spi/atsam_spi_bus.c | 29 +++++++-------------------
 2 files changed, 9 insertions(+), 22 deletions(-)

diff --git a/c/src/lib/libbsp/arm/atsam/include/atsam-spi.h b/c/src/lib/libbsp/arm/atsam/include/atsam-spi.h
index c742e83..968a947 100644
--- a/c/src/lib/libbsp/arm/atsam/include/atsam-spi.h
+++ b/c/src/lib/libbsp/arm/atsam/include/atsam-spi.h
@@ -44,7 +44,7 @@ typedef struct {
 	uint32_t dma_rx_channel;
 	bool rx_transfer_done;
 	bool tx_transfer_done;
-	bool spi_switched_on;
+	bool chip_select_active;
 } atsam_spi_bus;
 
 int spi_bus_register_atsam(
diff --git a/c/src/lib/libbsp/arm/atsam/spi/atsam_spi_bus.c b/c/src/lib/libbsp/arm/atsam/spi/atsam_spi_bus.c
index 247f886..82feebd 100644
--- a/c/src/lib/libbsp/arm/atsam/spi/atsam_spi_bus.c
+++ b/c/src/lib/libbsp/arm/atsam/spi/atsam_spi_bus.c
@@ -34,15 +34,6 @@
 
 #define MAX_SPI_FREQUENCY 50000000
 
-static void atsam_finish_command(Spid *SpiDma)
-{
-  Spi *pSpiHw = SpiDma->pSpiHw;
-
-  SPI_Disable(pSpiHw);
-
-  PMC_DisablePeripheral(SpiDma->spiId);
-}
-
 static void atsam_interrupt_handler(void *arg)
 {
   atsam_spi_bus *bus = (atsam_spi_bus *)arg;
@@ -369,19 +360,13 @@ static uint32_t atsam_send_command(
     return SPID_ERROR_LOCK;
   }
 
-  if(!bus->spi_switched_on){
-    /* Enable the SPI Peripheral */
-    PMC_EnablePeripheral(spid->spiId);
+  if (!bus->chip_select_active){
+    bus->chip_select_active = true;
 
-    /* SPI chip select */
     SPI_ChipSelect(pSpiHw, 1 << msg->cs);
-
-    /* Enables the SPI to transfer and receive data. */
-    SPI_Enable (pSpiHw);
+    SPI_Enable(pSpiHw);
   }
 
-  bus->spi_switched_on = true;
-
   /* Start DMA */
   XDMAC_StartTransfer(pXdmac, bus->dma_rx_channel);
   XDMAC_StartTransfer(pXdmac, bus->dma_tx_channel);
@@ -443,9 +428,9 @@ static int atsam_spi_setup_transfer(atsam_spi_bus *bus)
     bus->tx_transfer_done = false;
 
     if (msgs[i].cs_change > 0) {
+      bus->chip_select_active = false;
       SPI_ReleaseCS(bus->SpiDma.pSpiHw);
-      atsam_finish_command(&bus->SpiDma);
-      bus->spi_switched_on = false;
+      SPI_Disable(bus->SpiDma.pSpiHw);
     }
   }
 
@@ -487,6 +472,9 @@ static void atsam_spi_destroy(spi_bus *base)
   sc = rtems_interrupt_handler_remove(bus->irq, atsam_spi_interrupt, bus);
   assert(sc == RTEMS_SUCCESSFUL);
 
+  SPI_Disable(bus->SpiDma.pSpiHw);
+  PMC_DisablePeripheral(bus->SpiDma.spiId);
+
   spi_bus_destroy_and_free(&bus->base);
 }
 
@@ -521,7 +509,6 @@ static void atsam_spi_init(
   bus->base.cs = 1;
 
   atsam_configure_spi(bus);
-
   atsam_set_dmac(bus);
 }
 



More information about the vc mailing list