/*FUNCTION********************************************************************** * * Function Name : LPUART_DRV_Deinit * Description : This function shuts down the UART by disabling interrupts and * transmitter/receiver. * *END**************************************************************************/ lpuart_status_t LPUART_DRV_Deinit(uint32_t instance) { assert(instance < LPUART_INSTANCE_COUNT); /* Exit if current instance is already de-initialized or is gated.*/ if ((!g_lpuartStatePtr[instance]) || (!CLOCK_SYS_GetLpuartGateCmd(instance))) { return kStatus_LPUART_Fail; } LPUART_Type * base = g_lpuartBase[instance]; lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance]; /* Wait until the data is completely shifted out of shift register */ while (!LPUART_BRD_STAT_TC(base)) {} /* Disable LPUART interrupt. */ INT_SYS_DisableIRQ(g_lpuartRxTxIrqId[instance]); /* disable tx and rx */ LPUART_HAL_SetTransmitterCmd(base, false); LPUART_HAL_SetReceiverCmd(base, false); /* Destroy TX and RX sema. */ OSA_SemaDestroy(&lpuartState->txIrqSync); OSA_SemaDestroy(&lpuartState->rxIrqSync); /* Clear our saved pointer to the state structure */ g_lpuartStatePtr[instance] = NULL; /* gate lpuart module clock */ CLOCK_SYS_DisableLpuartClock(instance); return kStatus_LPUART_Success; }
/*FUNCTION********************************************************************** * * Function Name : LPUART_DRV_DmaDeinit * Description : This function shuts down the LPUART by disabling LPUART DMA and * the transmitter/receiver. * *END**************************************************************************/ lpuart_status_t LPUART_DRV_DmaDeinit(uint32_t instance) { assert(instance < LPUART_INSTANCE_COUNT); /* Exit if current instance is already de-initialized or is gated.*/ if ((!g_lpuartStatePtr[instance]) || (!CLOCK_SYS_GetLpuartGateCmd(instance))) { return kStatus_LPUART_Fail; } LPUART_Type * base = g_lpuartBase[instance]; lpuart_dma_state_t * lpuartDmaState = (lpuart_dma_state_t *)g_lpuartStatePtr[instance]; /* Wait until the data is completely shifted out of shift register */ while(!(LPUART_BRD_STAT_TC(base))) { } LPUART_HAL_SetTxDmaCmd(base, false); LPUART_HAL_SetRxDmaCmd(base, false); /* Release DMA channel. */ DMA_DRV_FreeChannel(&lpuartDmaState->dmaLpuartRx); DMA_DRV_FreeChannel(&lpuartDmaState->dmaLpuartTx); /* Disable TX and RX */ LPUART_HAL_SetTransmitterCmd(base, false); LPUART_HAL_SetReceiverCmd(base, false); /* Destroy TX and RX sema. */ OSA_SemaDestroy(&lpuartDmaState->txIrqSync); OSA_SemaDestroy(&lpuartDmaState->rxIrqSync); /* Cleared state pointer. */ g_lpuartStatePtr[instance] = NULL; /* Gate LPUART module clock */ CLOCK_SYS_DisableLpuartClock(instance); return kStatus_LPUART_Success; }