示例#1
0
/* Initialize debug output via UART for board */
void Board_Debug_Init(void)
{
#if defined(DEBUG_UART)
	Board_UART_Init();
	Chip_UART_Init(DEBUG_UART);
	Chip_UART_ConfigData(DEBUG_UART, UART_CFG_DATALEN_8 | UART_CFG_PARITY_NONE | UART_CFG_STOPLEN_1);
	Chip_UART_SetBaud(DEBUG_UART, 115200);
	Chip_UART_Enable(DEBUG_UART);
	Chip_UART_TXEnable(DEBUG_UART);
#endif
}
示例#2
0
/* Initialize debug output via UART for board */
void Board_Debug_Init(void)
{
#if defined(DEBUG_ENABLE)
    Board_UART_Init();
    /* Setup UART for 115.2K8N1 */
    Chip_UART_Init(LPC_USART);
    Chip_UART_SetBaud(LPC_USART, 115200);
    Chip_UART_ConfigData(LPC_USART, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT));
    Chip_UART_SetupFIFOS(LPC_USART, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2));
    Chip_UART_TXEnable(LPC_USART);
#endif
}
示例#3
0
/* Initialize debug output via UART for board */
void Board_Debug_Init(void)
{
#if defined(DEBUG_UART)
	Board_UART_Init();
	Chip_UART_Init(DEBUG_UART);
	Chip_UART_ConfigData(DEBUG_UART, UART_CFG_DATALEN_8 | UART_CFG_PARITY_NONE | UART_CFG_STOPLEN_1);
	Chip_Clock_SetUSARTNBaseClockRate((115200 * 16), true);
	Chip_UART_SetBaud(DEBUG_UART, 115200);
	Chip_UART_Enable(DEBUG_UART);
	Chip_UART_TXEnable(DEBUG_UART);
#endif
}
示例#4
0
/* Initialize debug output via UART for board */
void Board_Debug_Init(void)
{
#if defined(DEBUG_UART)
	Board_UART_Init(DEBUG_UART);

	Chip_UART_Init(DEBUG_UART);
	Chip_UART_SetBaudFDR(DEBUG_UART, 115200);
	Chip_UART_ConfigData(DEBUG_UART, UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_DIS);

	/* Enable UART Transmit */
	Chip_UART_TXEnable(DEBUG_UART);
#endif
}
static void ciaaDriverUart_hwInit(void)
{
   /* UART0 (RS485/Profibus) */
   Chip_UART_Init(LPC_USART0);
   Chip_UART_SetBaud(LPC_USART0, 115200);

   Chip_UART_SetupFIFOS(LPC_USART0, UART_FCR_FIFO_EN | UART_FCR_TRG_LEV0);

   Chip_UART_TXEnable(LPC_USART0);

   Chip_SCU_PinMux(9, 5, MD_PDN, FUNC7);              /* P9_5: UART0_TXD */
   Chip_SCU_PinMux(9, 6, MD_PLN|MD_EZI|MD_ZI, FUNC7); /* P9_6: UART0_RXD */

   Chip_UART_SetRS485Flags(LPC_USART0, UART_RS485CTRL_DCTRL_EN | UART_RS485CTRL_OINV_1);

   Chip_SCU_PinMux(6, 2, MD_PDN, FUNC2);              /* P6_2: UART0_DIR */

   /* UART2 (USB-UART) */
   Chip_UART_Init(LPC_USART2);
   Chip_UART_SetBaud(LPC_USART2, 115200);

   Chip_UART_SetupFIFOS(LPC_USART2, UART_FCR_FIFO_EN | UART_FCR_TRG_LEV0);

   Chip_UART_TXEnable(LPC_USART2);

   Chip_SCU_PinMux(7, 1, MD_PDN, FUNC6);              /* P7_1: UART2_TXD */
   Chip_SCU_PinMux(7, 2, MD_PLN|MD_EZI|MD_ZI, FUNC6); /* P7_2: UART2_RXD */

   /* UART3 (RS232) */
   Chip_UART_Init(LPC_USART3);
   Chip_UART_SetBaud(LPC_USART3, 115200);

   Chip_UART_SetupFIFOS(LPC_USART3, UART_FCR_FIFO_EN | UART_FCR_TRG_LEV0);

   Chip_UART_TXEnable(LPC_USART3);

   Chip_SCU_PinMux(2, 3, MD_PDN, FUNC2);              /* P2_3: UART3_TXD */
   Chip_SCU_PinMux(2, 4, MD_PLN|MD_EZI|MD_ZI, FUNC2); /* P2_4: UART3_RXD */
}
示例#6
0
int main(void)
{
	Board_Init();
	SystemCoreClockUpdate();

	Init_UART_PinMux();
	Chip_UART_Init(LPC_USART0);
	Board_LED_Set(0, false);

	/* Allocate UART handle, setup UART parameters, and initialize UART
	   clocking */
	setupUART();

	/* Transmit the welcome message and instructions using the
	   putline function */
	putLineUART("LP540xx USART API ROM polling Example\r\n");
	putLineUART("String receive (no echo): "
				"Enter a string and press enter to echo if back\r\n");

	/* Get a string for the UART and echo it back to the caller. Data is NOT
	   echoed back via the UART using this function. */
	getLineUART(recv_buf, sizeof(recv_buf));
	recv_buf[sizeof(recv_buf) - 1] = '\0';	/* Safety */
	if (strlen(recv_buf) == (sizeof(recv_buf) - 1)) {
		putLineUART("**String was truncated, input data longer than "
					"receive buffer***\r\n");
	}
	putLineUART(recv_buf);

	/* Transmit the message for byte/character part of the exampel */
	putLineUART("\r\nByte receive with echo: "
				"Press a key to echo it back. Press ESC to exit\r");

	/* Endless loop until ESC key is pressed */
	recv_buf[0] = '\n';
	while (recv_buf[0] != ESCKEY) {
		/* Echo it back */
		LPC_UARTD_API->uart_put_char(uartHandle, recv_buf[0]);

		/* uart_get_char will block until a character is received */
		recv_buf[0] = LPC_UARTD_API->uart_get_char(uartHandle);
	}

	/* Transmit the message for byte/character part of the exampel */
	putLineUART("\r\nESC key received, exiting\r\n");

	while (1) {
		__WFI();
	}
	return 0;
}
示例#7
0
文件: gps.c 项目: i7sid/SkyNet-Dongle
int skynetbase_gps_init(void) {
	DBG("begin init GPS...\n");

	NVIC_DisableIRQ(GPS_IRQn);
	Chip_UART_IntDisable(GPS_UART, (UART_IER_RBRINT | UART_IER_RLSINT));

	Chip_UART_Init(GPS_UART);
	Chip_UART_SetBaud(GPS_UART, 9600);
	Chip_UART_ConfigData(GPS_UART, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT));
	Chip_UART_SetupFIFOS(GPS_UART, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2));
	Chip_UART_TXEnable(GPS_UART);

	// Before using the ring buffers, initialize them using the ring buffer init function
	RingBuffer_Init(&rxring, rxbuff, 1, UART_RRB_SIZE);
	RingBuffer_Init(&txring, txbuff, 1, UART_SRB_SIZE);

	// Reset and enable FIFOs, FIFO trigger level 3 (14 chars)
	Chip_UART_SetupFIFOS(GPS_UART, (UART_FCR_FIFO_EN | UART_FCR_RX_RS |
			UART_FCR_TX_RS | UART_FCR_TRG_LEV3));

	/* Enable receive data and line status interrupt */
	Chip_UART_IntEnable(GPS_UART, (UART_IER_RBRINT | UART_IER_RLSINT));

	/* preemption = 1, sub-priority = 1 */
	NVIC_SetPriority(GPS_IRQn, 1);
	NVIC_EnableIRQ(GPS_IRQn);


	DBG("GPS up.\n");

	skynetbase_gps_config("$PUBX,40,GLL,0,0,0,0*5C\r\n");
	msDelayActive(250);
	skynetbase_gps_config("$PUBX,40,ZDA,0,0,0,0*44\r\n");
	msDelayActive(250);
	skynetbase_gps_config("$PUBX,40,VTG,0,0,0,0*5E\r\n");
	msDelayActive(250);
	skynetbase_gps_config("$PUBX,40,GSV,0,0,0,0*59\r\n");
	msDelayActive(250);
	skynetbase_gps_config("$PUBX,40,RMC,0,0,0,0*47\r\n");
	msDelayActive(250);
	skynetbase_gps_config("$PUBX,40,GSA,0,0,0,0*4E\r\n");
	msDelayActive(250);
	skynetbase_gps_config("$PUBX,40,GGA,0,0,0,0*5A\r\n");
	msDelayActive(250);

	DBG("GPS configured.\n");

	// TODO
	return 1;
}
/* Initialize debug output via UART for board */
void Board_Debug_Init(void)
{
#if defined(DEBUG_ENABLE)
	Board_UART_Init(DEBUG_UART);

	/* Setup UART for 115.2K8N1 */
	Chip_UART_Init(DEBUG_UART);
	Chip_UART_SetBaud(DEBUG_UART, 115200);
	Chip_UART_ConfigData(DEBUG_UART, UART_DATABIT_8, UART_PARITY_NONE, UART_STOPBIT_1);

	/* Enable UART Transmit */
	Chip_UART_TxCmd(DEBUG_UART, ENABLE);
#endif
}
示例#9
0
void Inicializar_UART(void)
{
//Configuramos la función del pint de la UART2 para que se conecte con la FTDI P7_1 (tx) y P7_2 (rx)
Chip_SCU_PinMux(_PAQUETE_PIN_UART2,_PIN_UART2_TX, MD_PDN, FUNC6);
Chip_SCU_PinMux(_PAQUETE_PIN_UART2,_PIN_UART2_RX, MD_PLN|MD_EZI|MD_ZI, FUNC6);

Chip_UART_Init(LPC_USART2);

Chip_UART_SetBaud(LPC_USART2,_BAUDRATE);

Chip_UART_SetupFIFOS(LPC_USART2, UART_FCR_FIFO_EN | UART_FCR_TRG_LEV0);
//El level 0 es para que cuando al fifo llegue un caracter lo mande, por ejemplo en lev3, esperaria 8 caracteres.

Chip_UART_TXEnable(LPC_USART2);
}
示例#10
0
void InitUART(uint32_t BAUD)
{
/*P7_1 UART2 TXD*/
Chip_SCU_PinMux(UART2_PUERTO, UART2_PIN_TXD, MD_PDN,FUNC6);
/*P7_2 UART RXD*/
Chip_SCU_PinMux(UART2_PUERTO, UART2_PIN_RXD, MD_PLN|MD_EZI|MD_ZI,FUNC6);

Chip_UART_Init(LPC_USART2);

Chip_UART_SetBaud(LPC_USART2, BAUD);

Chip_UART_SetupFIFOS(LPC_USART2, UART_FCR_FIFO_EN|UART_FCR_TRG_LEV0);

Chip_UART_TXEnable(LPC_USART2);

}
示例#11
0
/* UART port init routine */
static void UCOM_UartInit(void)
{
	/* Board specific muxing */
	Init_UART_PinMux();

	Chip_UART_Init(LPC_USART);
	Chip_UART_SetBaud(LPC_USART, 115200);
	Chip_UART_ConfigData(LPC_USART, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT));
	Chip_UART_SetupFIFOS(LPC_USART, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2));
	Chip_UART_TXEnable(LPC_USART);

	/* Enable receive data and line status interrupt */
	Chip_UART_IntEnable(LPC_USART, (UART_IER_RBRINT | UART_IER_RLSINT));

	/* Enable Interrupt for UART channel */
	/* Priority = 1 */
	NVIC_SetPriority(UART0_IRQn, 1);
	/* Enable Interrupt for UART channel */
	NVIC_EnableIRQ(UART0_IRQn);
}
示例#12
0
void UART_Init(void)
{
	struct __serial_info *serial = (struct __serial_info *)(get_S2E_Packet_pointer()->serial_info);

	/* Setup UART for 115.2K8N1 */
	Chip_UART_Init(LPC_USART);

	serial_info_init(serial);
	Chip_UART_SetupFIFOS(LPC_USART, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV3));
	Chip_UART_TXEnable(LPC_USART);

	/* Before using the ring buffers, initialize them using the ring
	   buffer init function */
	RingBuffer_Init(&rxring, rxbuff, 1, UART_RRB_SIZE);
	RingBuffer_Init(&txring, txbuff, 1, UART_SRB_SIZE);

	/* Enable receive data and line status interrupt */
	Chip_UART_IntEnable(LPC_USART, (UART_IER_RBRINT | UART_IER_RLSINT));

	/* preemption = 1, sub-priority = 1 */
	NVIC_SetPriority(UART0_IRQn, 1);
	NVIC_EnableIRQ(UART0_IRQn);
}
示例#13
0
void uart_init(void)
{
    /* Board specific muxing */
    uart_pinmux();

    Chip_UART_Init(LPC_USART);
    Chip_UART_SetBaudFDR(LPC_USART, 115200);
    Chip_UART_ConfigData(LPC_USART, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT));
    Chip_UART_SetupFIFOS(LPC_USART, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2));
    Chip_UART_TXEnable(LPC_USART);

    RingBuffer_Init(&uart_rxrb, uart_rxdata, 1, UART_RX_BUF_SZ);
    RingBuffer_Init(&uart_txrb, uart_txdata, 1, UART_TX_BUF_SZ);

    /* Enable receive data and line status interrupt */
    Chip_UART_IntEnable(LPC_USART, (UART_IER_RBRINT | UART_IER_RLSINT));

    /* Enable Interrupt for UART channel */
    /* Priority = 1 */
    NVIC_SetPriority(UART0_IRQn, 1);
    /* Enable Interrupt for UART channel */
    NVIC_EnableIRQ(UART0_IRQn);
}
示例#14
0
/** \brief TODO init_UART_FTDI_EDUCIAA Initialization method  */
uint8_t init_UART_FTDI_EDUCIAA(void)
{
	/** \details
	 * TODO description init_UART_FTDI_EDUCIAA
	 *
	 * \param none
	 *
	 * \return uint8_t: TBD (to support errors in the init function)
	 * */


	/** UART2 (USB-UART) */
	Chip_UART_Init(LPC_USART2);
	Chip_UART_SetBaud(LPC_USART2, 115200);

	Chip_UART_SetupFIFOS(LPC_USART2, UART_FCR_FIFO_EN | UART_FCR_TRG_LEV0);

	Chip_UART_TXEnable(LPC_USART2);

	Chip_SCU_PinMux(7, 1, MD_PDN, FUNC6);              /* P7_1: UART2_TXD */
	Chip_SCU_PinMux(7, 2, MD_PLN|MD_EZI|MD_ZI, FUNC6); /* P7_2: UART2_RXD */

	return TRUE;
}
示例#15
0
文件: uart_rb.c 项目: taphier/lk
/**
 * @brief	Main UART program body
 * @return	Always returns 1
 */
int main(void)
{
    uint8_t key;
    int bytes;

    SystemCoreClockUpdate();
    Board_Init();
    Init_UART_PinMux();
    Board_LED_Set(0, false);

    /* Before setting up the UART, the global UART clock for USARTS 1-4
       must first be setup. This requires setting the UART divider and
       the UART base clock rate to 16x the maximum UART rate for all
       UARTs. */
#if defined(USE_INTEGER_CLOCK)
    /* Use main clock rate as base for UART baud rate divider */
    Chip_Clock_SetUARTBaseClockRate(Chip_Clock_GetMainClockRate(), false);

#else
    /* Use 128x expected UART baud rate for fractional baud mode. */
    Chip_Clock_SetUARTBaseClockRate((115200 * 128), true);
#endif

    /* Setup UART */
    Chip_UART_Init(LPC_USART);
    Chip_UART_ConfigData(LPC_USART, UART_CFG_DATALEN_8 | UART_CFG_PARITY_NONE | UART_CFG_STOPLEN_1);
    Chip_UART_SetBaud(LPC_USART, UART_TEST_DEFAULT_BAUDRATE);
    /* Optional for low clock rates only: Chip_UART_SetBaudWithRTC32K(LPC_USART, 300); */
    Chip_UART_Enable(LPC_USART);
    Chip_UART_TXEnable(LPC_USART);

    /* Before using the ring buffers, initialize them using the ring
       buffer init function */
    RingBuffer_Init(&rxring, rxbuff, 1, UART_RB_SIZE);
    RingBuffer_Init(&txring, txbuff, 1, UART_RB_SIZE);

    /* Enable receive data and line status interrupt */
    Chip_UART_IntEnable(LPC_USART, UART_INTEN_RXRDY);
    Chip_UART_IntDisable(LPC_USART, UART_INTEN_TXRDY);	/* May not be needed */

    /* Enable UART interrupt */
    NVIC_EnableIRQ(LPC_IRQNUM);

    /* Initial message sent using blocking method to prevent ring
       buffer overflow */
    Chip_UART_SendBlocking(LPC_USART, inst1, sizeof(inst1) - 1);
    Chip_UART_SendRB(LPC_USART, &txring, inst2, sizeof(inst2) - 1);

    /* Poll the receive ring buffer for the ESC (ASCII 27) key */
    key = 0;
    while (key != 27) {
        bytes = Chip_UART_ReadRB(LPC_USART, &rxring, &key, 1);
        if (bytes > 0) {
            /* Wrap value back around */
            if (Chip_UART_SendRB(LPC_USART, &txring, (const uint8_t *) &key, 1) != 1) {
                Board_LED_Toggle(0);/* Toggle LED if the TX FIFO is full */
            }
        }
    }

    /* DeInitialize UART peripheral */
    NVIC_DisableIRQ(LPC_IRQNUM);
    Chip_UART_DeInit(LPC_USART);

    return 1;
}
示例#16
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_Send(LPC_UART,  "F**K OFF\n",10, BLOCKING);

	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;
}
示例#17
0
/**
 * @brief	Main UART/DMA program body
 * @return	Does not exit
 */
int main(void)
{
	int bytes = 0, idx;
	uint8_t buff[UARTRXBUFFSIZE];

	SystemCoreClockUpdate();
	Board_Init();
	Init_UART_PinMux();
	Board_LED_Set(0, false);

#if defined(USE_INTEGER_CLOCK)
	/* Use main clock rate as base for UART baud rate divider */
	Chip_Clock_SetUARTBaseClockRate(Chip_Clock_GetMainClockRate(), false);

#else
	/* Use 128x expected UART baud rate for fractional baud mode. */
	Chip_Clock_SetUARTBaseClockRate((115200 * 128), true);
#endif
	/* Setup UART */
	Chip_UART_Init(LPC_USART0);
	Chip_UART_ConfigData(LPC_USART0, UART_CFG_DATALEN_8 | UART_CFG_PARITY_NONE | UART_CFG_STOPLEN_1);
	Chip_UART_SetBaud(LPC_USART0, 115200);
	/* Optional for low clock rates only: Chip_UART_SetBaudWithRTC32K(LPC_USART, 300); */
	Chip_UART_Enable(LPC_USART0);
	Chip_UART_TXEnable(LPC_USART0);

	/* DMA initialization - enable DMA clocking and reset DMA if needed */
	Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_DMA);
	Chip_SYSCTL_PeriphReset(RESET_DMA);
	/* Initialize ROM API pointer */
	pDMAApi = LPC_DMAD_API;
	size_in_bytes = pDMAApi->dma_get_mem_size();
	if (size_in_bytes > RAMBLOCK) {
		/* Adjust RAMBLOCK size in this case */
		return 1;
	}
	/* Setup DMA ROM driver, provided RAM blocks for DMA Handle */
	dma_handle = pDMAApi->dma_setup(LPC_DMA_BASE, dma_ram_block);

	/* Init UART 0 TX descriptor */
	countTXDescUsed = 0;

	/* Enable the DMA IRQ */
	NVIC_EnableIRQ(DMA_IRQn);

	/* Enqueue a bunch of strings in DMA transmit descriptors and start
	   transmit. In this use of DMA, the descriptors aren't chained, so
	     the DMA restarts the next queued descriptor in the DMA interrupt
	     handler. */
	for (idx = 0; idx < DMASENDSTRCNT; idx++) {
		sprintf(dmaSendStr[idx], "DMA send string (unlinked) #%d\r\n", idx);
		dmaTXSend((uint8_t *) dmaSendStr[idx], strlen(dmaSendStr[idx]));
	}

	/* Wait for UART TX DMA channel to go inactive */
	while (1) {
		__WFI();
		if (countTXDescUsed == 0) {
			break;
		}
	}

	/* Receive buffers are queued. The DMA interrupt will only trigger on a
	   full DMA buffer receive, so if the UART is idle, but the DMA is only
	   partially complete, the DMA interrupt won't fire. For UART data
	   receive where data is not continuous, a timeout method will be
	   required to flush the DMA when the DMA has pending data and no
	   data has been received on the UART in a specified timeout */
	dmaRXQueue();

	/* Get RX data via DMA and send it out on TX via DMA */
	while (1) {
		/* Sleep until something happens */
		__WFI();

		/* Did any data come in? */
		bytes = checkRxData(buff);
		if (bytes > 0) {
			/* RX data received, send it via TX DMA */
			dmaTXSend(buff, bytes);
		}
	}

	return 1;
}
示例#18
0
/** \brief Main function
 *
 * This is the main entry point of the software.
 *
 * \returns 0
 *
 * \remarks This function never returns. Return value is only to avoid compiler
 *          warnings or errors.
 */
int main(void)
{


	   /*Put initializations in a separate function hw_init(void) or something like that...*/

	   Chip_SCU_PinMux(1,0,MD_PUP|MD_EZI|MD_ZI,FUNC0); /* GPIO0[4], SW1 */
	   Chip_SCU_PinMux(1,1,MD_PUP|MD_EZI|MD_ZI,FUNC0); /* GPIO0[8], SW2 */
	   Chip_SCU_PinMux(1,2,MD_PUP|MD_EZI|MD_ZI,FUNC0); /* GPIO0[9], SW3 */
	   Chip_SCU_PinMux(1,6,MD_PUP|MD_EZI|MD_ZI,FUNC0); /* GPIO1[9], SW4 */

	   Chip_GPIO_SetDir(LPC_GPIO_PORT, 0,(1<<4)|(1<<8)|(1<<9),0);
	   Chip_GPIO_SetDir(LPC_GPIO_PORT, 1,(1<<9),0);

	   /* LEDs */
	   Chip_SCU_PinMux(2,0,MD_PUP,FUNC4);  /* GPIO5[0], LED0R */
	   Chip_SCU_PinMux(2,1,MD_PUP,FUNC4);  /* GPIO5[1], LED0G */
	   Chip_SCU_PinMux(2,2,MD_PUP,FUNC4);  /* GPIO5[2], LED0B */
	   Chip_SCU_PinMux(2,10,MD_PUP,FUNC0); /* GPIO0[14], LED1 */
	   Chip_SCU_PinMux(2,11,MD_PUP,FUNC0); /* GPIO1[11], LED2 */
	   Chip_SCU_PinMux(2,12,MD_PUP,FUNC0); /* GPIO1[12], LED3 */

	   Chip_GPIO_SetDir(LPC_GPIO_PORT, 5,(1<<0)|(1<<1)|(1<<2),1);
	   Chip_GPIO_SetDir(LPC_GPIO_PORT, 0,(1<<14),1);
	   Chip_GPIO_SetDir(LPC_GPIO_PORT, 1,(1<<11)|(1<<12),1);

	   Chip_GPIO_ClearValue(LPC_GPIO_PORT, 5,(1<<0)|(1<<1)|(1<<2));
	   Chip_GPIO_ClearValue(LPC_GPIO_PORT, 0,(1<<14));
	   Chip_GPIO_ClearValue(LPC_GPIO_PORT, 1,(1<<11)|(1<<12));

	/*Hardware GPIO initialization (leds, buttons ...)*/


	   /*UART initialization*/

	   /* UART0 (RS485/Profibus) */
	   Chip_UART_Init(LPC_USART0);
	   Chip_UART_SetBaud(LPC_USART0, 115200);

	   Chip_UART_SetupFIFOS(LPC_USART0, UART_FCR_FIFO_EN | UART_FCR_TRG_LEV0);

	   Chip_UART_TXEnable(LPC_USART0);

	   Chip_SCU_PinMux(9, 5, MD_PDN, FUNC7);              /* P9_5: UART0_TXD */
	   Chip_SCU_PinMux(9, 6, MD_PLN|MD_EZI|MD_ZI, FUNC7); /* P9_6: UART0_RXD */

	   Chip_UART_SetRS485Flags(LPC_USART0, UART_RS485CTRL_DCTRL_EN | UART_RS485CTRL_OINV_1);

	   Chip_SCU_PinMux(6, 2, MD_PDN, FUNC2);              /* P6_2: UART0_DIR */

	   /* UART2 (USB-UART) */
	   Chip_UART_Init(LPC_USART2);
	   Chip_UART_SetBaud(LPC_USART2, 115200);

	   Chip_UART_SetupFIFOS(LPC_USART2, UART_FCR_FIFO_EN | UART_FCR_TRG_LEV0);

	   Chip_UART_TXEnable(LPC_USART2);

	   Chip_SCU_PinMux(7, 1, MD_PDN, FUNC6);              /* P7_1: UART2_TXD */
	   Chip_SCU_PinMux(7, 2, MD_PLN|MD_EZI|MD_ZI, FUNC6); /* P7_2: UART2_RXD */

	   /* UART3 (RS232) */
	   Chip_UART_Init(LPC_USART3);
	   Chip_UART_SetBaud(LPC_USART3, 115200);

	   Chip_UART_SetupFIFOS(LPC_USART3, UART_FCR_FIFO_EN | UART_FCR_TRG_LEV0);

	   Chip_UART_TXEnable(LPC_USART3);

	   Chip_SCU_PinMux(2, 3, MD_PDN, FUNC2);              /* P2_3: UART3_TXD */
	   Chip_SCU_PinMux(2, 4, MD_PLN|MD_EZI|MD_ZI, FUNC2); /* P2_4: UART3_RXD */



       /*Chip_UART_IntDisable((LPC_USART_T *)LPC_USART2, UART_IER_THREINT);*/
       /* this one calls write */
       /*ciaaDriverUart_txConfirmation(device);*/
       /* enable THRE irq (TX) */
/*       Chip_UART_IntEnable((LPC_USART_T *)LPC_USART2, UART_IER_THREINT);*/

      uint64_t j;
	  uint8_t size = 28;
	  uint8_t i = 0;
	  uint8_t data = 0;

	  char message[] = "Follow the white rabbit...\n\r";

	  /*	  just send the F  ...! */
	 /*	   Chip_UART_Send((LPC_USART_T *) LPC_USART2, message, index); */

	  /*looking for a 'a' character*/
   /* perform the needed initialization here */
   while(1) {
      /* do nothing */
		  data = i = 0;

		  /*wait for keyboard character*/

		  while (data == 0)
		  {
			  data = Chip_UART_ReadByte((LPC_USART_T *)LPC_USART2);

			switch (data){
			case 'r':
				  /*Toggle Red Led*/
			 	  Chip_GPIO_SetPortToggle(LPC_GPIO_PORT,LED2_PORT,LED_2);
				break;
			case 'v':
				  /*Toggle Green Led*/
			 	  Chip_GPIO_SetPortToggle(LPC_GPIO_PORT,LED3_PORT,LED_3);
				break;
			case 'a':
				  /*Toggle Yellow Led*/
			 	  Chip_GPIO_SetPortToggle(LPC_GPIO_PORT,LED1_PORT,LED_1);
				break;
			default:
				data = 0;
			}
		  }

 	     /*Send string*/
		 while(((Chip_UART_ReadLineStatus((LPC_USART_T *)LPC_USART2) & UART_LSR_THRE) != 0) && (i < size))
	      {
	         /* send first byte */
	         Chip_UART_SendByte((LPC_USART_T *)LPC_USART2, message[i]);
	         /* bytes written */

	         /*delay*/
	         for (j=0;j<50000;j++){
	           asm  ("nop");
	           }
	         i++;
	      }
   }
   return 0;
}
示例#19
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;
}
示例#20
0
platform_result_t platform_uart_init( platform_uart_driver_t* driver, const platform_uart_t* interface, const platform_uart_config_t* config, wiced_ring_buffer_t* optional_ring_buffer )
{
    uint32_t           uart_number;
    UART_FIFO_CFG_T    UARTFIFOConfigStruct;
    config_uart_data_t config_uart_data;

    wiced_assert( "bad argument", ( driver != NULL ) && ( interface != NULL ) && ( config != NULL ) );
    Chip_Clock_EnablePeriphClock( SYSCTL_CLOCK_UART0 );

    uart_number = platform_uart_get_port_number(interface->uart_base);
    driver->rx_size              = 0;
    driver->tx_size              = 0;
    driver->last_transmit_result = PLATFORM_SUCCESS;
    driver->last_receive_result  = PLATFORM_SUCCESS;
    driver->interface            = (platform_uart_t*)interface;
    host_rtos_init_semaphore( &driver->tx_complete );
    host_rtos_init_semaphore( &driver->rx_complete );

    platform_gpio_set_alternate_function( &driver->interface->tx_pin);
    platform_gpio_set_alternate_function( &driver->interface->rx_pin);

    /* Initialise USART peripheral */
    Chip_UART_FIFOConfigStructInit( driver->interface->uart_base, &UARTFIFOConfigStruct );
    Chip_UART_Init( driver->interface->uart_base );
    Chip_UART_SetBaud( driver->interface->uart_base, config->baud_rate );
    config_uart_data.databits = ( ( config->data_width == DATA_WIDTH_8BIT ) || ( ( config->data_width == DATA_WIDTH_7BIT ) && ( config->parity != NO_PARITY ) ) ) ? UART_DATABIT_8 : UART_DATABIT_7;
    config_uart_data.stopbits = ( config->stop_bits == STOP_BITS_1 ) ? UART_STOPBIT_1 : UART_STOPBIT_2;
    switch ( config->parity )
    {
        case NO_PARITY:
            config_uart_data.parity = UART_PARITY_NONE;
            break;

        case EVEN_PARITY:
            config_uart_data.parity = UART_PARITY_EVEN;
            break;

        case ODD_PARITY:
            config_uart_data.parity = UART_PARITY_ODD;
            break;

        default:
            return WICED_BADARG;
    }

    Chip_UART_ConfigData( driver->interface->uart_base, config_uart_data.databits, config_uart_data.parity, config_uart_data.stopbits );
    Chip_UART_TxCmd( driver->interface->uart_base, ENABLE );
    /* Enable receive data and line status interrupt */
    /* Initialize FIFO for UART0 peripheral */
    Chip_UART_FIFOConfig( driver->interface->uart_base, &UARTFIFOConfigStruct );
    /* Enable UART Rx interrupt */
    Chip_UART_IntConfig( driver->interface->uart_base, UART_INTCFG_RBR, ENABLE );
    /* Enable UART line status interrupt */
    Chip_UART_IntConfig( driver->interface->uart_base, UART_INTCFG_RLS, ENABLE );

    /* Enable Interrupt for UART channel */
    NVIC_DisableIRQ( uart_irq_vectors[ uart_number ] );
    NVIC_ClearPendingIRQ( uart_irq_vectors[ uart_number ] );
    /*Note the LPC uses 5 bits for interrupt priority levels*/
    NVIC_EnableIRQ( uart_irq_vectors[ uart_number ] );
    if ( optional_ring_buffer != NULL )
    {
        /* Note that the ring_buffer should've been initialised first */
        driver->rx_buffer = optional_ring_buffer;
        driver->rx_size = 0;
    }

    return PLATFORM_SUCCESS;
}