Exemple #1
0
/*FUNCTION**********************************************************************
 *
 * Function Name : LPSCI_DRV_Deinit
 * Description   : This function shuts down the LPSCI by disabling interrupts
 * and the transmitter/receiver.
 *
 *END**************************************************************************/
void LPSCI_DRV_Deinit(uint32_t instance)
{
    assert(instance < HW_UART0_INSTANCE_COUNT);

    uint32_t baseAddr = g_lpsciBaseAddr[instance];
    lpsci_state_t * lpsciState = (lpsci_state_t *)g_lpsciStatePtr[instance];

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

    /* Disable the interrupt */
    INT_SYS_DisableIRQ(g_lpsciRxTxIrqId[instance]);

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

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

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

    /* Gate LPSCI module clock */
    CLOCK_SYS_DisableUartClock(instance);
}
/*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;
}