Пример #1
0
/**
 * @brief	Main UART program body
 * @return	Always returns -1
 */
int main(void)
{
    FlagStatus exitflag;
    uint8_t buffer[10];
    int ret = 0;
    int len;

    SystemCoreClockUpdate();
    Board_Init();
    Board_UART_Init(LPC_UART);

#if !((defined(CHIP_LPC43XX) && defined(BOARD_KEIL_MCB_18574357) && UARTNum==3) || ((!(defined(CHIP_LPC43XX) && defined(BOARD_KEIL_MCB_18574357))) && UARTNum==0))
    Chip_UART_Init(LPC_UART);
    Chip_UART_SetBaud(LPC_UART, 115200);
    Chip_UART_ConfigData(LPC_UART, UART_LCR_WLEN8 | UART_LCR_SBS_1BIT); /* Default 8-N-1 */

    /* Enable UART Transmit */
    Chip_UART_TXEnable(LPC_UART);
#endif

    /* Reset FIFOs, Enable FIFOs and DMA mode in UART */
    Chip_UART_SetupFIFOS(LPC_UART, (UART_FCR_FIFO_EN | UART_FCR_RX_RS |
                                    UART_FCR_TX_RS | UART_FCR_DMAMODE_SEL | UART_FCR_TRG_LEV0));

    /* Enable UART End of Auto baudrate & Auto baudrate timeout interrupts */
    Chip_UART_IntEnable(LPC_UART, (UART_IER_ABEOINT | UART_IER_ABTOINT));

    /* preemption = 1, sub-priority = 1 */
    NVIC_SetPriority(UARTx_IRQn, 1);
    /* Enable Interrupt for UART0 channel */
    NVIC_EnableIRQ(UARTx_IRQn);

    /* Send UART Autobaud completed message */
    Chip_UART_SendBlocking(LPC_UART, uartABStart, sizeof(uartABStart));

    /* ---------------------- Auto baud rate section ----------------------- */
    /* Start auto baudrate mode */
    Chip_UART_ABCmd(LPC_UART, UART_ACR_MODE0, true, ENABLE);

    /* Loop until auto baudrate mode complete */
    while (Chip_UART_GetABEOStatus(LPC_UART) == RESET) {}

    /* Send UART Autobaud completed message */
    Chip_UART_SendBlocking(LPC_UART, uartABComplete, sizeof(uartABComplete));

    /* Disable UART Interrupt */
    NVIC_DisableIRQ(UARTx_IRQn);

    /* Print welcome screen */
    Print_Menu_Polling();

    exitflag = RESET;
    /* Read some data from the buffer */
    while (exitflag == RESET) {
        len = 0;
        while (len == 0) {
            len = Chip_UART_Read(LPC_UART, buffer, 1);
        }
        if (buffer[0] == 27) {
            /* ESC key, set exit flag */
            Chip_UART_SendBlocking(LPC_UART, uartPolling_menu3, sizeof(uartPolling_menu3));
            ret = -1;
            exitflag = SET;
        }
        else if (buffer[0] == 'c') {
            Chip_UART_SendBlocking(LPC_UART, uartPolling_menu4, sizeof(uartPolling_menu4));
            len = 0;
            while (len == 0) {
                len = Chip_UART_Read(LPC_UART, buffer, sizeof(buffer));
                if ((buffer[0] != '1') && (buffer[0] != '2') && (buffer[0] != '3')) {
                    len = 0;
                }
            }
            switch (buffer[0]) {
            case '1':		/* Polling Mode */
                Chip_UART_SendBlocking(LPC_UART, uartPolling_menu5, sizeof(uartPolling_menu5));
                break;

            case '2':		/* Interrupt Mode */
                ret = 2;
                /* Exitflag = SET; */
                App_Interrupt_Test();
                Print_Menu_Polling();
                break;

            case '3':		/* DMA mode */
                ret = 3;
                App_DMA_Test();
                Print_Menu_Polling();
                break;
            }
        }
    }

    /* Wait for current transmission complete - THR must be empty */
    while (Chip_UART_CheckBusy(LPC_UART) == SET) {}

    /* DeInitialize UART0 peripheral */
    Chip_UART_DeInit(LPC_UART);

    return ret;
}
Пример #2
0
/**
 * @brief	Main UART program body
 * @return	Always returns -1
 */
int main(void)
{
	FlagStatus exitflag;
	uint8_t buffer[10];
	int ret = 0;
	uint32_t len;

	/* UART FIFO configuration Struct variable */
	UART_FIFO_CFG_T UARTFIFOConfigStruct;
	/* Auto baudrate configuration structure */
	UART_AB_CFG_T ABConfig;

	Board_Init();
	Board_UART_Init(LPC_UART);

#if (UARTNum != 0)
	Chip_UART_Init(LPC_UART);
	Chip_UART_SetBaud(LPC_UART, 115200);
	Chip_UART_ConfigData(LPC_UART, UART_DATABIT_8, UART_PARITY_NONE, UART_STOPBIT_1);	/* Default 8-N-1 */

	/* Enable UART Transmit */
	Chip_UART_TxCmd(LPC_UART, ENABLE);
#endif

	Chip_UART_FIFOConfigStructInit(LPC_UART, &UARTFIFOConfigStruct);

	/* Enable DMA mode in UART */
	UARTFIFOConfigStruct.FIFO_DMAMode = ENABLE;
	/* Initialize FIFO for UART0 peripheral */
	Chip_UART_FIFOConfig(LPC_UART, &UARTFIFOConfigStruct);

	/* Enable UART End of Auto baudrate interrupt */
	Chip_UART_IntConfig(LPC_UART, UART_INTCFG_ABEO, ENABLE);
	/* Enable UART Auto baudrate timeout interrupt */
	Chip_UART_IntConfig(LPC_UART, UART_INTCFG_ABTO, ENABLE);

	/* preemption = 1, sub-priority = 1 */
	NVIC_SetPriority(UARTx_IRQn, 1);
	/* Enable Interrupt for UART0 channel */
	NVIC_EnableIRQ(UARTx_IRQn);

	/* ---------------------- Auto baud rate section ----------------------- */
	/* Configure Auto baud rate mode */
	ABConfig.ABMode = UART_AUTOBAUD_MODE0;
	ABConfig.AutoRestart = ENABLE;

	/* Start auto baudrate mode */
	Chip_UART_ABCmd(LPC_UART, &ABConfig, ENABLE);

	/* Loop until auto baudrate mode complete */
	while (Chip_UART_GetABEOStatus(LPC_UART) == RESET) {}

	Chip_UART_Send(LPC_UART, uartABComplete, sizeof(uartABComplete), BLOCKING);

	/* Disable UART Interrupt */
	NVIC_DisableIRQ(UARTx_IRQn);

	/* Print welcome screen */
	Print_Menu_Polling();

	exitflag = RESET;
	/* Read some data from the buffer */
	while (exitflag == RESET) {
		len = 0;
		while (len == 0) {
			len = Chip_UART_Receive(LPC_UART, buffer, 1, NONE_BLOCKING);
		}
		if (buffer[0] == 27) {
			/* ESC key, set exit flag */
			Chip_UART_Send(LPC_UART, uartPolling_menu3, sizeof(uartPolling_menu3), BLOCKING);
			ret = -1;
			exitflag = SET;
		}
		else if (buffer[0] == 'c') {
			Chip_UART_Send(LPC_UART, uartPolling_menu4, sizeof(uartPolling_menu4), BLOCKING);
			len = 0;
			while (len == 0) {
				len = Chip_UART_Receive(LPC_UART, buffer, sizeof(buffer), NONE_BLOCKING);
				if ((buffer[0] != '1') && (buffer[0] != '2') && (buffer[0] != '3')) {
					len = 0;
				}
			}
			switch (buffer[0]) {
			case '1':		/* Polling Mode */
				Chip_UART_Send(LPC_UART, uartPolling_menu5, sizeof(uartPolling_menu5), BLOCKING);
				break;

			case '2':		/* Interrupt Mode */
				ret = 2;
				/* Exitflag = SET; */
				App_Interrupt_Test();
				Print_Menu_Polling();
				break;

			case '3':		/* DMA mode */
				ret = 3;
				App_DMA_Test();
				Print_Menu_Polling();
				break;
			}
		}
	}

	/* Wait for current transmission complete - THR must be empty */
	while (Chip_UART_CheckBusy(LPC_UART) == SET) {}

	/* DeInitialize UART0 peripheral */
	Chip_UART_DeInit(LPC_UART);

	return ret;
}