/*FUNCTION**********************************************************************
 *
 * Function Name : LPUART_DRV_Init
 * Description   : This function initializes a LPUART instance for operation.
 * This function will initialize the run-time state structure to keep track of
 * the on-going transfers, ungate the clock to the LPUART module, initialize the
 * module to user defined settings and default settings, configure the IRQ state
 * structure and enable the module-level interrupt to the core, and enable the
 * LPUART module transmitter and receiver.
 * The following is an example of how to set up the lpuart_state_t and the
 * lpuart_user_config_t parameters and how to call the LPUART_DRV_Init function
 * by passing in these parameters:
 *    lpuart_user_config_t lpuartConfig;
 *    lpuartConfig.clockSource = kClockLpuartSrcPllFllSel;
 *    lpuartConfig.baudRate = 9600;
 *    lpuartConfig.bitCountPerChar = klpuart8BitsPerChar;
 *    lpuartConfig.parityMode = klpuartParityDisabled;
 *    lpuartConfig.stopBitCount = klpuartOneStopBit;
 *    lpuart_state_t lpuartState;
 *    LPUART_DRV_Init(instance, &lpuartState, &lpuartConfig);
 *
 *END**************************************************************************/
lpuart_status_t LPUART_DRV_Init(uint32_t instance, lpuart_state_t * lpuartStatePtr,
                                const lpuart_user_config_t * lpuartUserConfig)
{
    assert(lpuartStatePtr && lpuartUserConfig);
    assert(instance < LPUART_INSTANCE_COUNT);

    uint32_t lpuartSourceClock;
    LPUART_Type * base = g_lpuartBase[instance];

    /* Exit if current instance is already initialized. */
    if (g_lpuartStatePtr[instance])
    {
        return kStatus_LPUART_Initialized;
    }

    /* Clear the state struct for this instance. */
    memset(lpuartStatePtr, 0, sizeof(lpuart_state_t));

    /* Save runtime structure pointer.*/
    g_lpuartStatePtr[instance] = lpuartStatePtr;

    /* Set LPUART clock source */
    CLOCK_SYS_SetLpuartSrc(instance, lpuartUserConfig->clockSource);

    /* ungate lpuart module clock */
    CLOCK_SYS_EnableLpuartClock(instance);

    /* initialize the LPUART instance */
    LPUART_HAL_Init(base);

    /* Init the interrupt sync object. */
    OSA_SemaCreate(&lpuartStatePtr->txIrqSync, 0);
    OSA_SemaCreate(&lpuartStatePtr->rxIrqSync, 0);

    /* LPUART clock source is either system clock or bus clock depending on the instance */
    lpuartSourceClock = CLOCK_SYS_GetLpuartFreq(instance);

    /* initialize the parameters of the LPUART config structure with desired data */
    LPUART_HAL_SetBaudRate(base, lpuartSourceClock, lpuartUserConfig->baudRate);
    LPUART_HAL_SetBitCountPerChar(base, lpuartUserConfig->bitCountPerChar);
    LPUART_HAL_SetParityMode(base, lpuartUserConfig->parityMode);
    LPUART_HAL_SetStopBitCount(base, lpuartUserConfig->stopBitCount);

    /* finally, enable the LPUART transmitter and receiver */
    LPUART_HAL_SetTransmitterCmd(base, true);
    LPUART_HAL_SetReceiverCmd(base, true);

    /* Enable LPUART interrupt. */
    INT_SYS_EnableIRQ(g_lpuartRxTxIrqId[instance]);

    return kStatus_LPUART_Success;
}
/* See fsl_debug_console.h for documentation of this function.*/
debug_console_status_t DbgConsole_Init(
        uint32_t uartInstance, uint32_t baudRate, debug_console_device_type_t device)
{
    if (s_debugConsole.type != kDebugConsoleNone)
    {
        return kStatus_DEBUGCONSOLE_Failed;
    }

    /* Set debug console to initialized to avoid duplicated init operation.*/
    s_debugConsole.type = device;
    s_debugConsole.instance = uartInstance;

    /* Switch between different device. */
    switch (device)
    {
#if defined(HW_UART_INSTANCE_COUNT)
        case kDebugConsoleUART:
            {
                uint32_t g_Addr[HW_UART_INSTANCE_COUNT] = UART_BASE_ADDRS;
                uint32_t baseAddr = g_Addr[uartInstance];
                uint32_t uartSourceClock;

                s_debugConsole.baseAddr = baseAddr;
                CLOCK_SYS_EnableUartClock(uartInstance);

                /* UART clock source is either system or bus clock depending on instance */
                uartSourceClock = CLOCK_SYS_GetUartFreq(uartInstance);

                /* Initialize UART baud rate, bit count, parity and stop bit. */
                UART_HAL_SetBaudRate(baseAddr, uartSourceClock, baudRate);
                UART_HAL_SetBitCountPerChar(baseAddr, kUart8BitsPerChar);
                UART_HAL_SetParityMode(baseAddr, kUartParityDisabled);
#if FSL_FEATURE_UART_HAS_STOP_BIT_CONFIG_SUPPORT
                UART_HAL_SetStopBitCount(baseAddr, kUartOneStopBit);
#endif

                /* Finally, enable the UART transmitter and receiver*/
                UART_HAL_EnableTransmitter(baseAddr);
                UART_HAL_EnableReceiver(baseAddr);

                /* Set the funciton pointer for send and receive for this kind of device. */
                s_debugConsole.ops.Send = UART_HAL_SendDataPolling;
                s_debugConsole.ops.rx_union.UART_Receive = UART_HAL_ReceiveDataPolling;
            }
            break;
#endif
#if defined(HW_UART0_INSTANCE_COUNT)
        case kDebugConsoleLPSCI:
            {
                /* Declare config sturcuture to initialize a uart instance. */
                uint32_t g_Addr[HW_UART0_INSTANCE_COUNT] = UART0_BASE_ADDRS;
                uint32_t baseAddr = g_Addr[uartInstance];
                uint32_t uartSourceClock;

                s_debugConsole.baseAddr = baseAddr;
                CLOCK_SYS_EnableLpsciClock(uartInstance);

                uartSourceClock = CLOCK_SYS_GetLpsciFreq(uartInstance);

                /* Initialize LPSCI baud rate, bit count, parity and stop bit. */
                LPSCI_HAL_SetBaudRate(baseAddr, uartSourceClock, baudRate);
                LPSCI_HAL_SetBitCountPerChar(baseAddr, kLpsci8BitsPerChar);
                LPSCI_HAL_SetParityMode(baseAddr, kLpsciParityDisabled);
#if FSL_FEATURE_LPSCI_HAS_STOP_BIT_CONFIG_SUPPORT
                LPSCI_HAL_SetStopBitCount(baseAddr, kLpsciOneStopBit);
#endif

                /* Finally, enable the LPSCI transmitter and receiver*/
                LPSCI_HAL_EnableTransmitter(baseAddr);
                LPSCI_HAL_EnableReceiver(baseAddr);

                /* Set the funciton pointer for send and receive for this kind of device. */
                s_debugConsole.ops.Send = LPSCI_HAL_SendDataPolling;
                s_debugConsole.ops.rx_union.UART0_Receive = LPSCI_HAL_ReceiveDataPolling;
            }     
            break;
#endif
#if defined(HW_LPUART_INSTANCE_COUNT)
        case kDebugConsoleLPUART:
            {
                uint32_t g_Addr[HW_LPUART_INSTANCE_COUNT] = LPUART_BASE_ADDRS;
                uint32_t baseAddr = g_Addr[uartInstance];
                uint32_t lpuartSourceClock;

                s_debugConsole.baseAddr = baseAddr;
                CLOCK_SYS_EnableLpuartClock(uartInstance);

                /* LPUART clock source is either system or bus clock depending on instance */
                lpuartSourceClock = CLOCK_SYS_GetLpuartFreq(uartInstance);

                /* initialize the parameters of the LPUART config structure with desired data */
                LPUART_HAL_SetBaudRate(baseAddr, lpuartSourceClock, baudRate);
                LPUART_HAL_SetBitCountPerChar(baseAddr, kLpuart8BitsPerChar);
                LPUART_HAL_SetParityMode(baseAddr, kLpuartParityDisabled);
                LPUART_HAL_SetStopBitCount(baseAddr, kLpuartOneStopBit);

                /* finally, enable the LPUART transmitter and receiver */
                LPUART_HAL_SetTransmitterCmd(baseAddr, true);
                LPUART_HAL_SetReceiverCmd(baseAddr, true);

                /* Set the funciton pointer for send and receive for this kind of device. */
                s_debugConsole.ops.Send = LPUART_HAL_SendDataPolling;
                s_debugConsole.ops.rx_union.LPUART_Receive = LPUART_HAL_ReceiveDataPolling;

            }
            break;
#endif
        /* If new device is requried as the low level device for debug console,
         * Add the case branch and add the preprocessor macro to judge whether
         * this kind of device exist in this SOC. */
        default:
            /* Device identified is invalid, return invalid device error code. */
            return kStatus_DEBUGCONSOLE_InvalidDevice;
    }

    /* Configure the s_debugConsole structure only when the inti operation is successful. */
    s_debugConsole.instance = uartInstance;

#if ((defined(__GNUC__)) && (!defined(FSL_RTOS_MQX))) && (!defined(__KSDK_STDLIB__))
    setvbuf(stdout, NULL, _IONBF, 0);
    setvbuf(stdin, NULL, _IONBF, 0);
    setvbuf(stderr, NULL, _IONBF, 0);
#endif

    return kStatus_DEBUGCONSOLE_Success;
}
/*FUNCTION**********************************************************************
 *
 * Function Name : LPUART_DRV_EdmaInit
 * Description   : This function initializes a LPUART instance for operation.
 * This function will initialize the run-time state structure to keep track of
 * the on-going transfers, ungate the clock to the LPUART module, initialize the
 * module to user defined settings and default settings, configure LPUART DMA
 * and enable the LPUART module transmitter and receiver.
 * The following is an example of how to set up the lpuart_edma_state_t and the
 * lpuart_user_config_t parameters and how to call the LPUART_DRV_EdmaInit function
 * by passing in these parameters:
 *    lpuart_user_config_t lpuartConfig;
 *    lpuartConfig.clockSource = kClockLpuartSrcPllFllSel;
 *    lpuartConfig.baudRate = 9600;
 *    lpuartConfig.bitCountPerChar = kLpuart8BitsPerChar;
 *    lpuartConfig.parityMode = kLpuartParityDisabled;
 *    lpuartConfig.stopBitCount = kLpuartOneStopBit;
 *    lpuart_edma_state_t lpuartEdmaState;
 *    LPUART_DRV_EdmaInit(instance, &lpuartEdmaState, &lpuartConfig);
 *
 *END**************************************************************************/
lpuart_status_t LPUART_DRV_EdmaInit(uint32_t instance,
                                    lpuart_edma_state_t * lpuartEdmaStatePtr,
                                    const lpuart_edma_user_config_t * lpuartUserConfig)
{
    assert(lpuartEdmaStatePtr && lpuartUserConfig);
    assert(instance < LPUART_INSTANCE_COUNT);
    /* This driver only support UART instances with separate DMA channels for
     * both Tx and Rx.*/
    assert(FSL_FEATURE_LPUART_HAS_SEPARATE_DMA_RX_TX_REQn(instance) == 1);

    LPUART_Type * base = g_lpuartBase[instance];
    uint32_t lpuartSourceClock = 0;
    dma_request_source_t lpuartTxEdmaRequest = kDmaRequestMux0Disable;
    dma_request_source_t lpuartRxEdmaRequest = kDmaRequestMux0Disable;

    /* Exit if current instance is already initialized. */
    if (g_lpuartStatePtr[instance])
    {
        return kStatus_LPUART_Initialized;
    }

    /* Clear the state structure for this instance. */
    memset(lpuartEdmaStatePtr, 0, sizeof(lpuart_edma_state_t));

    /* Save runtime structure pointer.*/
    g_lpuartStatePtr[instance] = lpuartEdmaStatePtr;

    /* Set LPUART clock source */
    CLOCK_SYS_SetLpuartSrc(instance, lpuartUserConfig->clockSource);

    /* Un-gate LPUART module clock */
    CLOCK_SYS_EnableLpuartClock(instance);

    /* Initialize LPUART to a known state. */
    LPUART_HAL_Init(base);

    /* Create Semaphore for txIrq and rxIrq. */
    OSA_SemaCreate(&lpuartEdmaStatePtr->txIrqSync, 0);
    OSA_SemaCreate(&lpuartEdmaStatePtr->rxIrqSync, 0);

    /* LPUART clock source is either system or bus clock depending on instance */
    lpuartSourceClock = CLOCK_SYS_GetLpuartFreq(instance);

    /* Initialize LPUART baud rate, bit count, parity and stop bit. */
    LPUART_HAL_SetBaudRate(base, lpuartSourceClock, lpuartUserConfig->baudRate);
    LPUART_HAL_SetBitCountPerChar(base, lpuartUserConfig->bitCountPerChar);
    LPUART_HAL_SetParityMode(base, lpuartUserConfig->parityMode);
    LPUART_HAL_SetStopBitCount(base, lpuartUserConfig->stopBitCount);

    switch (instance)
    {
#if (FSL_FEATURE_LPUART_HAS_SEPARATE_DMA_RX_TX_REQn(0) == 1)
        case 0:
            lpuartRxEdmaRequest = kDmaRequestMux0LPUART0Rx;
            lpuartTxEdmaRequest = kDmaRequestMux0LPUART0Tx;
            break;
#endif
#if (FSL_FEATURE_LPUART_HAS_SEPARATE_DMA_RX_TX_REQn(1) == 1)
        case 1:
            lpuartRxEdmaRequest = kDmaRequestMux0LPUART1Rx;
            lpuartTxEdmaRequest = kDmaRequestMux0LPUART1Tx;
            break;
#endif
#if (FSL_FEATURE_LPUART_HAS_SEPARATE_DMA_RX_TX_REQn(2) == 1)
        case 2:
            lpuartRxEdmaRequest = kDmaRequestMux0LPUART2Rx;
            lpuartTxEdmaRequest = kDmaRequestMux0LPUART2Tx;
            break;
#endif
#if (FSL_FEATURE_LPUART_HAS_SEPARATE_DMA_RX_TX_REQn(3) == 1)
        case 3:
            lpuartRxEdmaRequest = kDmaRequestMux0LPUART3Rx;
            lpuartTxEdmaRequest = kDmaRequestMux0LPUART3Tx;
            break;
#endif
#if (FSL_FEATURE_LPUART_HAS_SEPARATE_DMA_RX_TX_REQn(4) == 1)
        case 4:
            lpuartRxEdmaRequest = kDmaRequestMux0LPUART4Rx;
            lpuartTxEdmaRequest = kDmaRequestMux0LPUART4Tx;
            break;
#endif
        default :
            break;
    }

    /*--------------- Setup RX ------------------*/
    /* Request DMA channels for RX FIFO. */
    EDMA_DRV_RequestChannel(kEDMAAnyChannel, lpuartRxEdmaRequest,
                            &lpuartEdmaStatePtr->edmaLpuartRx);
    EDMA_DRV_InstallCallback(&lpuartEdmaStatePtr->edmaLpuartRx,
                    LPUART_DRV_EdmaRxCallback, (void *)instance);

    /*--------------- Setup TX ------------------*/
    /* Request DMA channels for TX FIFO. */
    EDMA_DRV_RequestChannel(kEDMAAnyChannel, lpuartTxEdmaRequest,
                            &lpuartEdmaStatePtr->edmaLpuartTx);
    EDMA_DRV_InstallCallback(&lpuartEdmaStatePtr->edmaLpuartTx,
                    LPUART_DRV_EdmaTxCallback, (void *)instance);

    /* Finally, enable the LPUART transmitter and receiver.
     * Enable DMA trigger when transmit data register empty,
     * and receive data register full. */
    LPUART_HAL_SetTxDmaCmd(base, true);
    LPUART_HAL_SetRxDmaCmd(base, true);
    LPUART_HAL_SetTransmitterCmd(base, true);
    LPUART_HAL_SetReceiverCmd(base, true);

    return kStatus_LPUART_Success;
}
/*FUNCTION**********************************************************************
 *
 * Function Name : LPUART_DRV_DmaInit
 * Description   : This function initializes a LPUART instance for operation.
 * This function will initialize the run-time state structure to keep track of
 * the on-going transfers, ungate the clock to the LPUART module, initialize the
 * module to user defined settings and default settings, configure LPUART DMA
 * and enable the LPUART module transmitter and receiver.
 * The following is an example of how to set up the lpuart_dma_state_t and the
 * lpuart_user_config_t parameters and how to call the LPUART_DRV_DmaInit function
 * by passing in these parameters:
 *    lpuart_user_config_t lpuartConfig;
 *    lpuartConfig.baudRate = 9600;
 *    lpuartConfig.bitCountPerChar = kLpuart8BitsPerChar;
 *    lpuartConfig.parityMode = kLpuartParityDisabled;
 *    lpuartConfig.stopBitCount = kLpuartOneStopBit;
 *    lpuart_dma_state_t lpuartDmaState;
 *    LPUART_DRV_DmaInit(instance, &lpuartDmaState, &lpuartConfig);
 *
 *END**************************************************************************/
lpuart_status_t LPUART_DRV_DmaInit(uint32_t instance,
                               lpuart_dma_state_t * lpuartDmaStatePtr,
                               const lpuart_dma_user_config_t * lpuartUserConfig)
{
    assert(lpuartDmaStatePtr && lpuartUserConfig);
    assert(instance < LPUART_INSTANCE_COUNT);

    LPUART_Type * base = g_lpuartBase[instance];
    uint32_t lpuartSourceClock = 0;
    dma_request_source_t lpuartTxDmaRequest = kDmaRequestMux0Disable;
    dma_request_source_t lpuartRxDmaRequest = kDmaRequestMux0Disable;

    /* Exit if current instance is already initialized. */
    if (g_lpuartStatePtr[instance])
    {
        return kStatus_LPUART_Initialized;
    }

    /* Clear the state structure for this instance. */
    memset(lpuartDmaStatePtr, 0, sizeof(lpuart_dma_state_t));

    /* Save runtime structure pointer.*/
    g_lpuartStatePtr[instance] = lpuartDmaStatePtr;

    /* Un-gate LPUART module clock */
    CLOCK_SYS_EnableLpuartClock(instance);

    /* Set LPUART clock source */
    CLOCK_SYS_SetLpuartSrc(instance, lpuartUserConfig->clockSource);

    /* Initialize LPUART to a known state. */
    LPUART_HAL_Init(base);

    /* Create Semaphore for txIrq and rxIrq. */
    OSA_SemaCreate(&lpuartDmaStatePtr->txIrqSync, 0);
    OSA_SemaCreate(&lpuartDmaStatePtr->rxIrqSync, 0);

    /* LPUART clock source is either system or bus clock depending on instance */
    lpuartSourceClock = CLOCK_SYS_GetLpuartFreq(instance);

    /* Initialize LPUART baud rate, bit count, parity and stop bit. */
    LPUART_HAL_SetBaudRate(base, lpuartSourceClock, lpuartUserConfig->baudRate);
    LPUART_HAL_SetBitCountPerChar(base, lpuartUserConfig->bitCountPerChar);
    LPUART_HAL_SetParityMode(base, lpuartUserConfig->parityMode);
#if FSL_FEATURE_LPUART_HAS_STOP_BIT_CONFIG_SUPPORT
    LPUART_HAL_SetStopBitCount(base, lpuartUserConfig->stopBitCount);
#endif

    /* Enable DMA trigger when transmit data register empty,
     * and receive data register full. */
    LPUART_HAL_SetTxDmaCmd(base, true);
    LPUART_HAL_SetRxDmaCmd(base, true);

    switch (instance)
    {
        case 0:
            lpuartRxDmaRequest = kDmaRequestMux0LPUART0Rx;
            lpuartTxDmaRequest = kDmaRequestMux0LPUART0Tx;
            break;
        default :
            break;
    }

    /* Request DMA channels for RX FIFO. */
    DMA_DRV_RequestChannel(kDmaAnyChannel, lpuartRxDmaRequest,
                            &lpuartDmaStatePtr->dmaLpuartRx);
    DMA_DRV_RegisterCallback(&lpuartDmaStatePtr->dmaLpuartRx,
                    LPUART_DRV_DmaRxCallback, (void *)instance);

    /* Request DMA channels for TX FIFO. */
    DMA_DRV_RequestChannel(kDmaAnyChannel, lpuartTxDmaRequest,
                            &lpuartDmaStatePtr->dmaLpuartTx);
    DMA_DRV_RegisterCallback(&lpuartDmaStatePtr->dmaLpuartTx,
                    LPUART_DRV_DmaTxCallback, (void *)instance);

    /* Finally, enable the LPUART transmitter and receiver*/
    LPUART_HAL_SetTransmitterCmd(base, true);
    LPUART_HAL_SetReceiverCmd(base, true);

    return kStatus_LPUART_Success;
}
示例#5
0
/* See fsl_debug_console.h for documentation of this function.*/
debug_console_status_t DbgConsole_Init(
        uint32_t uartInstance, uint32_t baudRate, debug_console_device_type_t device)
{
    if (s_debugConsole.type != kDebugConsoleNone)
    {
        return kStatus_DEBUGCONSOLE_Failed;
    }

    /* Set debug console to initialized to avoid duplicated init operation.*/
    s_debugConsole.type = device;
    s_debugConsole.instance = uartInstance;

    /* Switch between different device. */
    switch (device)
    {
#if (defined(USB_INSTANCE_COUNT) && defined(BOARD_USE_VIRTUALCOM))  /*&& defined()*/
       case kDebugConsoleUSBCDC:
         {
                VirtualCom_Init();
                s_debugConsole.base = (void*)g_app_handle;
                s_debugConsole.ops.tx_union.USB_Send = VirtualCom_SendDataBlocking;
                s_debugConsole.ops.rx_union.USB_Receive = VirtualCom_ReceiveDataBlocking;
         }
         break;
#endif
#if defined(UART_INSTANCE_COUNT)
        case kDebugConsoleUART:
            {
                UART_Type * g_Base[UART_INSTANCE_COUNT] = UART_BASE_PTRS;
                UART_Type * base = g_Base[uartInstance];
                uint32_t uartSourceClock;

                s_debugConsole.base = base;
                CLOCK_SYS_EnableUartClock(uartInstance);

                /* UART clock source is either system or bus clock depending on instance */
                uartSourceClock = CLOCK_SYS_GetUartFreq(uartInstance);

                /* Initialize UART baud rate, bit count, parity and stop bit. */
                UART_HAL_SetBaudRate(base, uartSourceClock, baudRate);
                UART_HAL_SetBitCountPerChar(base, kUart8BitsPerChar);
                UART_HAL_SetParityMode(base, kUartParityDisabled);
#if FSL_FEATURE_UART_HAS_STOP_BIT_CONFIG_SUPPORT
                UART_HAL_SetStopBitCount(base, kUartOneStopBit);
#endif

                /* Finally, enable the UART transmitter and receiver*/
                UART_HAL_EnableTransmitter(base);
                UART_HAL_EnableReceiver(base);

                /* Set the funciton pointer for send and receive for this kind of device. */
                s_debugConsole.ops.tx_union.UART_Send = UART_HAL_SendDataPolling;
                s_debugConsole.ops.rx_union.UART_Receive = UART_HAL_ReceiveDataPolling;
            }
            break;
#endif
#if defined(UART0_INSTANCE_COUNT)
        case kDebugConsoleLPSCI:
            {
                /* Declare config sturcuture to initialize a uart instance. */
                UART0_Type * g_Base[UART0_INSTANCE_COUNT] = UART0_BASE_PTRS;
                UART0_Type * base = g_Base[uartInstance];
                uint32_t uartSourceClock;

                s_debugConsole.base = base;
                CLOCK_SYS_EnableLpsciClock(uartInstance);

                uartSourceClock = CLOCK_SYS_GetLpsciFreq(uartInstance);

                /* Initialize LPSCI baud rate, bit count, parity and stop bit. */
                LPSCI_HAL_SetBaudRate(base, uartSourceClock, baudRate);
                LPSCI_HAL_SetBitCountPerChar(base, kLpsci8BitsPerChar);
                LPSCI_HAL_SetParityMode(base, kLpsciParityDisabled);
#if FSL_FEATURE_LPSCI_HAS_STOP_BIT_CONFIG_SUPPORT
                LPSCI_HAL_SetStopBitCount(base, kLpsciOneStopBit);
#endif

                /* Finally, enable the LPSCI transmitter and receiver*/
                LPSCI_HAL_EnableTransmitter(base);
                LPSCI_HAL_EnableReceiver(base);

                /* Set the funciton pointer for send and receive for this kind of device. */
                s_debugConsole.ops.tx_union.UART0_Send = LPSCI_HAL_SendDataPolling;
                s_debugConsole.ops.rx_union.UART0_Receive = LPSCI_HAL_ReceiveDataPolling;
            }
            break;
#endif
#if defined(LPUART_INSTANCE_COUNT)
        case kDebugConsoleLPUART:
            {
                LPUART_Type* g_Base[LPUART_INSTANCE_COUNT] = LPUART_BASE_PTRS;
                LPUART_Type* base = g_Base[uartInstance];
                uint32_t lpuartSourceClock;

                s_debugConsole.base = base;
                CLOCK_SYS_EnableLpuartClock(uartInstance);

                /* LPUART clock source is either system or bus clock depending on instance */
                lpuartSourceClock = CLOCK_SYS_GetLpuartFreq(uartInstance);

                /* initialize the parameters of the LPUART config structure with desired data */
                LPUART_HAL_SetBaudRate(base, lpuartSourceClock, baudRate);
                LPUART_HAL_SetBitCountPerChar(base, kLpuart8BitsPerChar);
                LPUART_HAL_SetParityMode(base, kLpuartParityDisabled);
                LPUART_HAL_SetStopBitCount(base, kLpuartOneStopBit);

                /* finally, enable the LPUART transmitter and receiver */
                LPUART_HAL_SetTransmitterCmd(base, true);
                LPUART_HAL_SetReceiverCmd(base, true);

                /* Set the funciton pointer for send and receive for this kind of device. */
                s_debugConsole.ops.tx_union.LPUART_Send = LPUART_HAL_SendDataPolling;
                s_debugConsole.ops.rx_union.LPUART_Receive = LPUART_HAL_ReceiveDataPolling;

            }
            break;
#endif
        /* If new device is requried as the low level device for debug console,
         * Add the case branch and add the preprocessor macro to judge whether
         * this kind of device exist in this SOC. */
        default:
            /* Device identified is invalid, return invalid device error code. */
            return kStatus_DEBUGCONSOLE_InvalidDevice;
    }

    /* Configure the s_debugConsole structure only when the inti operation is successful. */
    s_debugConsole.instance = uartInstance;

    return kStatus_DEBUGCONSOLE_Success;
}