示例#1
0
/*FUNCTION**********************************************************************
 *
 * Function Name : DSPI_DRV_DmaMasterDeinit
 * Description   : Shuts down a DSPI instance with DMA support.
 *
 * This function resets the DSPI peripheral, gates its clock, disables any used interrupts to
 * the core, and releases any used DMA channels.
 *
 *END**************************************************************************/
dspi_status_t DSPI_DRV_DmaMasterDeinit(uint32_t instance)
{
    /* instantiate local variable of type dspi_dma_master_state_t and point to global state */
    dspi_dma_master_state_t * dspiDmaState = (dspi_dma_master_state_t *)g_dspiStatePtr[instance];
    SPI_Type *base = g_dspiBase[instance];

    /* First stop transfers */
    DSPI_HAL_StopTransfer(base);

    /* Restore the module to defaults then power it down. This also disables the DSPI module.*/
    DSPI_HAL_Init(base);

    /* destroy the interrupt sync object.*/
    OSA_SemaDestroy(&dspiDmaState->irqSync);

    /* disable the interrupt*/
    INT_SYS_DisableIRQ(g_dspiIrqId[instance]);

    /* Gate the clock for DSPI.*/
    CLOCK_SYS_DisableSpiClock(instance);

    /* Release all of the DMA channels used in the driver. DMA channel structures are stored in
     * the run-time state structure.
     */
    DMA_DRV_FreeChannel(&dspiDmaState->dmaTxDataChannel);
    DMA_DRV_FreeChannel(&dspiDmaState->dmaTxCmdChannel);
    DMA_DRV_FreeChannel(&dspiDmaState->dmaRxChannel);

    /* Clear state pointer. */
    g_dspiStatePtr[instance] = NULL;

    return kStatus_DSPI_Success;
}
/*FUNCTION**********************************************************************
 *
 * Function Name : SPI_DRV_DmaMasterDeinit
 * Description   : Shuts down a SPI instance with DMA support.
 *
 * This function resets the SPI peripheral, gates its clock, disables any used interrupts to
 * the core, and releases any used DMA channels.
 *
 *END**************************************************************************/
spi_status_t SPI_DRV_DmaMasterDeinit(uint32_t instance)
{
    /* 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_Type *base = g_spiBase[instance];

    /* Restore the module to defaults which includes disabling the SPI then power it down.*/
    SPI_HAL_Init(base);

    /* destroy the interrupt sync object.*/
    OSA_SemaDestroy(&spiDmaState->irqSync);

    /* Disable SPI interrupt.*/
    INT_SYS_DisableIRQ(g_spiIrqId[instance]);

    /* Gate the clock for SPI.*/
    CLOCK_SYS_DisableSpiClock(instance);

    /* Free DMA channels */
    DMA_DRV_FreeChannel(&spiDmaState->dmaReceive);
    DMA_DRV_FreeChannel(&spiDmaState->dmaTransmit);

    /* Clear state pointer. */
    g_spiStatePtr[instance] = NULL;

    return kStatus_SPI_Success;
}
示例#3
0
/*FUNCTION**********************************************************************
 *
 * Function Name : DMA_DRV_Deinit
 * Description   : Deinitilize DMA
 *
 *END**************************************************************************/
dma_status_t DMA_DRV_Deinit(void)
{
    uint8_t i;

    /* Disable DMA clock and free channel. */
    for (i = 0; i < FSL_FEATURE_DMA_DMAMUX_CHANNELS; i++)
    {
        /* Free all requested channels. */
        if (g_dma->dmaChan[i])
        {
            DMA_DRV_FreeChannel(g_dma->dmaChan[i]);
        }
    }

    /* Disable DMA clcok. */
    for (i = 0; i < DMA_INSTANCE_COUNT; i++)
    {
        CLOCK_SYS_DisableDmaClock(i);
    }

    /* Disable DMAMUX clock. */
    for (i = 0; i < DMAMUX_INSTANCE_COUNT; i++)
    {
        CLOCK_SYS_DisableDmaClock(i);
    }
#if USE_RTOS
    OSA_MutexDestroy(&g_dma->lock);
#endif

    return kStatus_DMA_Success;
}
/*FUNCTION**********************************************************************
 *
 * Function Name : UART_DRV_DmaDeinit
 * Description   : This function shuts down the UART by disabling UART DMA and
 *                 the transmitter/receiver.
 *
 *END**************************************************************************/
uart_status_t UART_DRV_DmaDeinit(uint32_t instance)
{
    assert(instance < UART_INSTANCE_COUNT);
    assert(g_uartBase[instance]);

    /* Exit if current instance is already de-initialized or is gated.*/
    if ((!g_uartStatePtr[instance]) || (!CLOCK_SYS_GetUartGateCmd(instance)))
    {
        return kStatus_UART_Fail;
    }

    UART_Type * base = g_uartBase[instance];
    uart_dma_state_t * uartDmaState = (uart_dma_state_t *)g_uartStatePtr[instance];

    /* Wait until the data is completely shifted out of shift register */
    while(!(UART_BRD_S1_TC(base))) { }

    UART_HAL_SetTxDmaCmd(base, false);
    UART_HAL_SetRxDmaCmd(base, false);

    /* Release DMA channel. */
    DMA_DRV_FreeChannel(&uartDmaState->dmaUartRx);
    DMA_DRV_FreeChannel(&uartDmaState->dmaUartTx);

    /* Disable TX and RX */
    UART_HAL_DisableTransmitter(base);
    UART_HAL_DisableReceiver(base);

    /* Destroy TX and RX sema. */
    OSA_SemaDestroy(&uartDmaState->txIrqSync);
    OSA_SemaDestroy(&uartDmaState->rxIrqSync);

    /* Cleared state pointer. */
    g_uartStatePtr[instance] = NULL;

    /* Gate UART module clock */
    CLOCK_SYS_DisableUartClock(instance);

    return kStatus_UART_Success;
}
/*FUNCTION**********************************************************************
 *
 * Function Name : LPSCI_DRV_DmaDeinit
 * Description   : This function shuts down the LPSCI by disabling LPSCI DMA and
 *                 the transmitter/receiver.
 *
 *END**************************************************************************/
lpsci_status_t LPSCI_DRV_DmaDeinit(uint32_t instance)
{
    assert(instance < UART0_INSTANCE_COUNT);

    /* Exit if current instance is already de-initialized or is gated.*/
    if ((!g_lpsciStatePtr[instance]) || (!CLOCK_SYS_GetLpsciGateCmd(instance)))
    {
        return kStatus_LPSCI_Fail;
    }

    UART0_Type * base = g_lpsciBase[instance];
    lpsci_dma_state_t * lpsciDmaState = (lpsci_dma_state_t *)g_lpsciStatePtr[instance];

    /* Wait until the data is completely shifted out of shift register */
    while(!(UART0_BRD_S1_TC(base))) { }

    LPSCI_HAL_SetTxDmaCmd(base, false);
    LPSCI_HAL_SetRxDmaCmd(base, false);

    /* Release DMA channel. */
    DMA_DRV_FreeChannel(&lpsciDmaState->dmaLpsciRx);
    DMA_DRV_FreeChannel(&lpsciDmaState->dmaLpsciTx);

    /* Disable TX and RX */
    LPSCI_HAL_DisableTransmitter(base);
    LPSCI_HAL_DisableReceiver(base);

    /* Destroy TX and RX sema. */
    OSA_SemaDestroy(&lpsciDmaState->txIrqSync);
    OSA_SemaDestroy(&lpsciDmaState->rxIrqSync);

    /* Cleared state pointer. */
    g_lpsciStatePtr[instance] = NULL;

    /* Gate LPSCI module clock */
    CLOCK_SYS_DisableLpsciClock(instance);

    return kStatus_LPSCI_Success;
}
/*FUNCTION**********************************************************************
 *
 * Function Name : SPI_DRV_DmaSlaveDeinit
 * Description   : De-initializes the device.
 * Clears the control register and turns off the clock to the module.
 *
 *END**************************************************************************/
spi_status_t SPI_DRV_DmaSlaveDeinit(uint32_t instance)
{
    spi_dma_slave_state_t * spiState = (spi_dma_slave_state_t *)g_spiStatePtr[instance];
    SPI_Type *base = g_spiBase[instance];

    assert(instance < SPI_INSTANCE_COUNT);

    /* Disable SPI interrupt */
    INT_SYS_DisableIRQ(g_spiIrqId[instance]);

    /* Reset the SPI module to its default settings including disabling SPI and its interrupts */
    SPI_HAL_Init(base);

#if FSL_FEATURE_SPI_16BIT_TRANSFERS
    if (g_spiFifoSize[instance] != 0)
    {
        SPI_HAL_SetFifoIntCmd(base, kSpiRxFifoNearFullInt, false);
    }

    /* disable transmit interrupt */
    SPI_HAL_SetIntMode(base, kSpiTxEmptyInt, false);
#endif /* FSL_FEATURE_SPI_16BIT_TRANSFERS */

    /* Free DMA channels */
    DMA_DRV_FreeChannel(&spiState->dmaReceive);
    DMA_DRV_FreeChannel(&spiState->dmaTransmit);

    /* Disable clock for SPI */
    CLOCK_SYS_DisableSpiClock(instance);

    /* Destroy the event */
    OSA_EventDestroy(&spiState->event);

    /* Clear state pointer */
    g_spiStatePtr[instance] = NULL;

    return kStatus_SPI_Success;
}