[rtems commit] bsp/atsam: Simplify SPI transfer status

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


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Dec 14 11:42:28 2016 +0100

bsp/atsam: Simplify SPI transfer status

---

 c/src/lib/libbsp/arm/atsam/spi/atsam_spi_bus.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

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 7dee4d5..7c3855d 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
@@ -36,6 +36,10 @@
 
 #define MAX_SPI_FREQUENCY 50000000
 
+#define TX_IN_PROGRESS 0x1
+
+#define RX_IN_PROGRESS 0x2
+
 typedef struct {
   spi_bus base;
   bool msg_cs_change;
@@ -47,8 +51,7 @@ typedef struct {
   Spid SpiDma;
   uint32_t dma_tx_channel;
   uint32_t dma_rx_channel;
-  bool rx_transfer_done;
-  bool tx_transfer_done;
+  int transfer_status;
   bool chip_select_active;
 } atsam_spi_bus;
 
@@ -269,8 +272,7 @@ static void atsam_spi_setup_transfer(atsam_spi_bus *bus)
 {
   uint32_t msg_todo = bus->msg_todo;
 
-  bus->rx_transfer_done = false;
-  bus->tx_transfer_done = false;
+  bus->transfer_status = RX_IN_PROGRESS | TX_IN_PROGRESS;
 
   if (bus->msg_cs_change) {
     bus->chip_select_active = false;
@@ -355,14 +357,14 @@ static void atsam_spi_interrupt(void *arg)
       }
 
       if (bExec == 1 && (channel == bus->dma_rx_channel)) {
-        bus->rx_transfer_done = true;
+        bus->transfer_status &= ~RX_IN_PROGRESS;
         XDMAC_DisableGIt(spid->pXdmad->pXdmacs, bus->dma_rx_channel);
       } else if (bExec == 1 && (channel == bus->dma_tx_channel)) {
-        bus->tx_transfer_done = true;
+        bus->transfer_status &= ~TX_IN_PROGRESS;
         XDMAC_DisableGIt(spid->pXdmad->pXdmacs, bus->dma_tx_channel);
       }
 
-      if (bus->rx_transfer_done && bus->tx_transfer_done) {
+      if (bus->transfer_status == 0) {
         atsam_spi_setup_transfer(bus);
       }
     }



More information about the vc mailing list