summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-12-13 15:49:09 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-12-14 13:09:27 +0100
commit5dd02e95696bc573dbcb2df0afc0c2607bdd8f53 (patch)
tree88b51ea25ee976ba9dfba619e61fa14200bb558c
parentf74e2959ded6b0e1e750b539df27ba18eeceb46f (diff)
downloadrtems-5dd02e95696bc573dbcb2df0afc0c2607bdd8f53.tar.bz2
bsp/atsam: Avoid to power on/off the SPI module
-rw-r--r--c/src/lib/libbsp/arm/atsam/include/atsam-spi.h2
-rw-r--r--c/src/lib/libbsp/arm/atsam/spi/atsam_spi_bus.c29
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 c742e83337..968a947a7b 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 247f8869f5..82feebddbd 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);
}