Skip to content

Commit

Permalink
Silabs: SPI
Browse files Browse the repository at this point in the history
Changed SPI implementation: #1 To avoid clearing data from buffers, during splitted DMA transfer
RX/TX buffer clear is done only when transfer is started.
USART transmit is completed instead of DMA/LDMA transfer completed.
  • Loading branch information
jhokajar authored and stevew817 committed Jan 12, 2016
1 parent a9f0fdb commit e48994e
Showing 1 changed file with 7 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -876,10 +876,7 @@ static void spi_activate_dma(spi_t *obj, void* rxdata, const void* txdata, int t
}

/* Save amount of TX done by DMA */

obj->tx_buff.pos += tx_length;
/* Clear TX registers */
obj->spi.spi->CMD = USART_CMD_CLEARTX;

LDMA_TransferCfg_t xferConf = LDMA_TRANSFER_CFG_PERIPHERAL(dma_periph);
LDMA_Descriptor_t desc = LDMA_DESCRIPTOR_SINGLE_M2P_BYTE(txdata, target_addr, tx_length);
Expand Down Expand Up @@ -925,9 +922,6 @@ static void spi_activate_dma(spi_t *obj, void* rxdata, const void* txdata, int t
break;
}

/* Clear RX registers */
obj->spi.spi->CMD = USART_CMD_CLEARRX;

LDMA_TransferCfg_t xferConf = LDMA_TRANSFER_CFG_PERIPHERAL(dma_periph);
LDMA_Descriptor_t desc = LDMA_DESCRIPTOR_SINGLE_P2M_BYTE(source_addr, rxdata, rx_length);
if(obj->spi.bits >= 9){
Expand Down Expand Up @@ -989,9 +983,6 @@ static void spi_activate_dma(spi_t *obj, void* rxdata, const void* txdata, int t
rxDescrCfg.hprot = 0;
DMA_CfgDescr(obj->spi.dmaOptionsRX.dmaChannel, true, &rxDescrCfg);

// Clear RX registers - Useful if previous command transfered don't
obj->spi.spi->CMD = USART_CMD_CLEARRX;

/* Activate RX channel */
DMA_ActivateBasic(obj->spi.dmaOptionsRX.dmaChannel, true, false, rxdata, (void *)&(obj->spi.spi->RXDATA),
rx_length - 1);
Expand All @@ -1006,9 +997,6 @@ static void spi_activate_dma(spi_t *obj, void* rxdata, const void* txdata, int t
txDescrCfg.hprot = 0;
DMA_CfgDescr(obj->spi.dmaOptionsTX.dmaChannel, true, &txDescrCfg);

/* Clear TX registers */
obj->spi.spi->CMD = USART_CMD_CLEARTX;

/* Activate TX channel */
DMA_ActivateBasic( obj->spi.dmaOptionsTX.dmaChannel,
true,
Expand All @@ -1028,9 +1016,6 @@ static void spi_activate_dma(spi_t *obj, void* rxdata, const void* txdata, int t
rxDescrCfg.hprot = 0;
DMA_CfgDescr(obj->spi.dmaOptionsRX.dmaChannel, true, &rxDescrCfg);

// Clear RX registers - Useful if previous command transfered don't
obj->spi.spi->CMD = USART_CMD_CLEARRX;

/* Activate RX channel */
DMA_ActivateBasic(obj->spi.dmaOptionsRX.dmaChannel, true, false, rxdata, (void *)&(obj->spi.spi->RXDATAX),
(rx_length / 2) - 1);
Expand All @@ -1044,9 +1029,6 @@ static void spi_activate_dma(spi_t *obj, void* rxdata, const void* txdata, int t
txDescrCfg.hprot = 0;
DMA_CfgDescr(obj->spi.dmaOptionsTX.dmaChannel, true, &txDescrCfg);

/* Clear TX registers */
obj->spi.spi->CMD = USART_CMD_CLEARTX;

/* Activate TX channel */
DMA_ActivateBasic( obj->spi.dmaOptionsTX.dmaChannel,
true,
Expand Down Expand Up @@ -1078,6 +1060,9 @@ void spi_master_transfer_dma(spi_t *obj, const void *txdata, void *rxdata, int t
{
/* Init DMA here to include it in the power figure */
dma_init();
/* Clear TX and RX registers */
obj->spi.spi->CMD = USART_CMD_CLEARTX;
obj->spi.spi->CMD = USART_CMD_CLEARRX;
/* If the DMA channels are already allocated, we can assume they have been setup already */
if (hint != DMA_USAGE_NEVER && obj->spi.dmaOptionsTX.dmaUsageState == DMA_USAGE_ALLOCATED) {
/* setup has already been done, so just activate the transfer */
Expand Down Expand Up @@ -1172,8 +1157,6 @@ uint32_t spi_irq_handler_asynch(spi_t* obj)
void* tx_pointer = (char*)obj->tx_buff.buffer + obj->tx_buff.pos;
uint32_t tx_length = obj->tx_buff.length - obj->tx_buff.pos;

/* Wait previous transmit to complete */
while(!(obj->spi.spi->STATUS & USART_STATUS_TXC));
/* Begin transfer. Rely on spi_activate_dma to split up the transfer further. */
spi_activate_dma(obj, obj->rx_buff.buffer, tx_pointer, tx_length, obj->rx_buff.length);

Expand All @@ -1200,6 +1183,8 @@ uint32_t spi_irq_handler_asynch(spi_t* obj)
obj->spi.dmaOptionsTX.dmaUsageState = DMA_USAGE_OPPORTUNISTIC;
}

/* Wait transmit to complete, before user code is indicated*/
while(!(obj->spi.spi->STATUS & USART_STATUS_TXC));
unblockSleepMode(SPI_LEAST_ACTIVE_SLEEPMODE);
/* return to CPP land to say we're finished */
return SPI_EVENT_COMPLETE;
Expand Down Expand Up @@ -1307,6 +1292,8 @@ uint32_t spi_irq_handler_asynch(spi_t* obj)
obj->spi.dmaOptionsTX.dmaUsageState = DMA_USAGE_OPPORTUNISTIC;
}

/* Wait transmit to complete, before user code is indicated*/
while(!(obj->spi.spi->STATUS & USART_STATUS_TXC));
unblockSleepMode(SPI_LEAST_ACTIVE_SLEEPMODE);

/* return to CPP land to say we're finished */
Expand Down

0 comments on commit e48994e

Please sign in to comment.