/*FUNCTION**********************************************************************
 *
 * Function Name : SPI_DRV_DmaSlaveTransferBlocking
 * Description   : Transfer data with the master, using blocking call and DMA
 * driven.
 *
 *END**************************************************************************/
spi_status_t SPI_DRV_DmaSlaveTransferBlocking(uint32_t instance,
                                           const uint8_t *sendBuffer,
                                           uint8_t *receiveBuffer,
                                           uint32_t transferByteCount,
                                           uint32_t timeout)
{
    spi_dma_slave_state_t * spiState = (spi_dma_slave_state_t *)g_spiStatePtr[instance];
    spi_status_t errorStatus = kStatus_SPI_Success;
    event_flags_t setFlags = 0;

    /* fill in members of the run-time state struct */
    spiState->isSync = true;
    spiState->sendBuffer = (const uint8_t *)sendBuffer;
    spiState->receiveBuffer = (uint8_t *)receiveBuffer;
    spiState->remainingSendByteCount = transferByteCount;
    spiState->remainingReceiveByteCount = transferByteCount;

    /* Clear the event flags */
    OSA_EventClear(&spiState->event, kSpiDmaTransferDone);

    errorStatus = SPI_DRV_DmaSlaveStartTransfer(instance);
    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_EventWait(&spiState->event, kSpiDmaTransferDone, true, timeout, &setFlags);
    }while(syncStatus == kStatus_OSA_Idle);

    if (syncStatus != kStatus_OSA_Success)
    {
        /* Abort the transfer so it doesn't continue unexpectedly. */
        SPI_DRV_DmaSlaveAbortTransfer(instance);

        errorStatus = kStatus_SPI_Timeout;
    }

    return errorStatus;
}
uint32_t OS_Event_clear(os_event_handle handle, uint32_t bitmask)
{
    return ((kStatus_OSA_Success == OSA_EventClear((event_t*) (handle), (bitmask))) ? OS_EVENT_OK : OS_EVENT_ERROR);
}