forked from Imagelibrary/rtems
bsp/atsam: Simplify SPI transfer status
This commit is contained in:
@@ -36,6 +36,10 @@
|
|||||||
|
|
||||||
#define MAX_SPI_FREQUENCY 50000000
|
#define MAX_SPI_FREQUENCY 50000000
|
||||||
|
|
||||||
|
#define TX_IN_PROGRESS 0x1
|
||||||
|
|
||||||
|
#define RX_IN_PROGRESS 0x2
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
spi_bus base;
|
spi_bus base;
|
||||||
bool msg_cs_change;
|
bool msg_cs_change;
|
||||||
@@ -47,8 +51,7 @@ typedef struct {
|
|||||||
Spid SpiDma;
|
Spid SpiDma;
|
||||||
uint32_t dma_tx_channel;
|
uint32_t dma_tx_channel;
|
||||||
uint32_t dma_rx_channel;
|
uint32_t dma_rx_channel;
|
||||||
bool rx_transfer_done;
|
int transfer_status;
|
||||||
bool tx_transfer_done;
|
|
||||||
bool chip_select_active;
|
bool chip_select_active;
|
||||||
} atsam_spi_bus;
|
} atsam_spi_bus;
|
||||||
|
|
||||||
@@ -269,8 +272,7 @@ static void atsam_spi_setup_transfer(atsam_spi_bus *bus)
|
|||||||
{
|
{
|
||||||
uint32_t msg_todo = bus->msg_todo;
|
uint32_t msg_todo = bus->msg_todo;
|
||||||
|
|
||||||
bus->rx_transfer_done = false;
|
bus->transfer_status = RX_IN_PROGRESS | TX_IN_PROGRESS;
|
||||||
bus->tx_transfer_done = false;
|
|
||||||
|
|
||||||
if (bus->msg_cs_change) {
|
if (bus->msg_cs_change) {
|
||||||
bus->chip_select_active = false;
|
bus->chip_select_active = false;
|
||||||
@@ -355,14 +357,14 @@ static void atsam_spi_interrupt(void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bExec == 1 && (channel == bus->dma_rx_channel)) {
|
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);
|
XDMAC_DisableGIt(spid->pXdmad->pXdmacs, bus->dma_rx_channel);
|
||||||
} else if (bExec == 1 && (channel == bus->dma_tx_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);
|
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);
|
atsam_spi_setup_transfer(bus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user