コード例 #1
0
/*FUNCTION**********************************************************************
 *
 * Function Name : SPI_DRV_DmaMasterTransfer
 * Description   : Performs a non-blocking SPI master mode transfer with DMA support.
 *
 * This function returns immediately. It is the user's responsibility to check back to
 * ascertain if the transfer is complete (using the SPI_DRV_DmaMasterGetTransferStatus function).
 * This function simultaneously sends and receives data on the SPI bus, as SPI is naturally
 * a full-duplex bus. The function does return until the transfer is complete.
 *
 *END**************************************************************************/
spi_status_t SPI_DRV_DmaMasterTransfer(uint32_t instance,
                                       const spi_dma_master_user_config_t * device,
                                       const uint8_t * sendBuffer,
                                       uint8_t * receiveBuffer,
                                       size_t transferByteCount)
{
    /* instantiate local variable of type spi_dma_master_state_t and point to global state */
    spi_dma_master_state_t * spiDmaState = (spi_dma_master_state_t *)g_spiStatePtr[instance];
    spi_status_t errorStatus = kStatus_SPI_Success;

    /* fill in members of the run-time state struct*/
    spiDmaState->isTransferBlocking = false; /* Indicates this is a non-blocking transfer */
    spiDmaState->sendBuffer = sendBuffer;
    spiDmaState->receiveBuffer = (uint8_t *)receiveBuffer;
    spiDmaState->remainingSendByteCount = transferByteCount;
    spiDmaState->remainingReceiveByteCount = transferByteCount;

    errorStatus = SPI_DRV_DmaMasterStartTransfer(instance, device);
    if (errorStatus != kStatus_SPI_Success)
    {
        return errorStatus;
    }

    /* Else, return immediately as this is an async transfer */
    return kStatus_SPI_Success;
}
コード例 #2
0
/*FUNCTION**********************************************************************
 *
 * Function Name : SPI_DRV_DmaMasterTransferBlocking
 * Description   : Performs a blocking SPI master mode transfer with DMA support.
 *
 * This function simultaneously sends and receives data on the SPI bus, as SPI is naturally
 * a full-duplex bus. The function does return until the transfer is complete.
 *
 *END**************************************************************************/
spi_status_t SPI_DRV_DmaMasterTransferBlocking(uint32_t instance,
                                               const spi_dma_master_user_config_t * device,
                                               const uint8_t * sendBuffer,
                                               uint8_t * receiveBuffer,
                                               size_t transferByteCount,
                                               uint32_t timeout)
{
    /* instantiate local variable of type spi_dma_master_state_t and point to global state */
    spi_dma_master_state_t * spiDmaState = (spi_dma_master_state_t *)g_spiStatePtr[instance];
    spi_status_t errorStatus = kStatus_SPI_Success;
    SPI_Type *base = g_spiBase[instance];

    /* fill in members of the run-time state struct*/
    spiDmaState->isTransferBlocking = true; /* Indicates this is a blocking transfer */
    spiDmaState->sendBuffer = (const uint8_t *)sendBuffer;
    spiDmaState->receiveBuffer = (uint8_t *)receiveBuffer;
    spiDmaState->remainingSendByteCount = transferByteCount;
    spiDmaState->remainingReceiveByteCount = transferByteCount;

    /* start the transfer process*/
    errorStatus = SPI_DRV_DmaMasterStartTransfer(instance, device);
    if (errorStatus != kStatus_SPI_Success)
    {
        return errorStatus;
    }

    /* As this is a synchronous transfer, wait until the transfer is complete.*/
    osa_status_t syncStatus;

    do
    {
        syncStatus = OSA_SemaWait(&spiDmaState->irqSync, timeout);
    }while(syncStatus == kStatus_OSA_Idle);

    /* If a timeout occurs, stop the transfer by setting the isTransferInProgress to false and
     * disabling DMA requests and interrupts, then return the timeout error status.
     */
    if (syncStatus != kStatus_OSA_Success)
    {
        /* The transfer is complete.*/
        spiDmaState->isTransferInProgress = false;

        /* Disable DMA requests and interrupts. */
        SPI_HAL_SetRxDmaCmd(base, false);
        SPI_HAL_SetTxDmaCmd(base, false);
        SPI_HAL_SetIntMode(base, kSpiTxEmptyInt, false);

        errorStatus = kStatus_SPI_Timeout;
    }

    return errorStatus;
}
コード例 #3
0
                                               size_t transferByteCount,
                                               uint32_t timeout)
{
    /* instantiate local variable of type spi_dma_master_state_t and point to global state */
    spi_dma_master_state_t * spiDmaState = (spi_dma_master_state_t *)g_spiStatePtr[instance];
    spi_status_t errorStatus = kStatus_SPI_Success;

    /* fill in members of the run-time state struct*/
    spiDmaState->isTransferBlocking = true; /* Indicates this is a blocking transfer */
    spiDmaState->sendBuffer = (const uint8_t *)sendBuffer;
    spiDmaState->receiveBuffer = (uint8_t *)receiveBuffer;
    spiDmaState->remainingSendByteCount = transferByteCount;
    spiDmaState->remainingReceiveByteCount = transferByteCount;

    /* start the transfer process*/
    errorStatus = SPI_DRV_DmaMasterStartTransfer(instance, device);
    if (errorStatus != kStatus_SPI_Success)
    {
        return errorStatus;
    }

    /* As this is a synchronous transfer, wait until the transfer is complete.*/
    osa_status_t syncStatus;

    do
    {
        syncStatus = OSA_SemaWait(&spiDmaState->irqSync, timeout);
    }while(syncStatus == kStatus_OSA_Idle);

    if (syncStatus != kStatus_OSA_Success)
    {