コード例 #1
0
ファイル: ciaaUART.c プロジェクト: mdarino/LSE_SistOper2
void ciaaUARTInit(void)
{
	/* UART0 (RS485/Profibus) */
	Chip_UART_Init(LPC_USART0);
	Chip_UART_SetBaud(LPC_USART0, 115200);

	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 */

	/* Restart FIFOS: set Enable, Reset content, set trigger level */
	Chip_UART_SetupFIFOS(LPC_USART0, UART_FCR_FIFO_EN | UART_FCR_TX_RS | UART_FCR_RX_RS | UART_FCR_TRG_LEV0);
	/* dummy read */
	Chip_UART_ReadByte(LPC_USART0);
	/* enable rx interrupt */
	Chip_UART_IntEnable(LPC_USART0, UART_IER_RBRINT);

	NVIC_EnableIRQ(USART0_IRQn);

	RingBuffer_Init(uarts[0].rrb, rxbuf[0], 1, UART_BUF_SIZE);
	RingBuffer_Init(uarts[0].trb, txbuf[0], 1, UART_BUF_SIZE);

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

	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 */

	Chip_UART_IntEnable(LPC_USART2, UART_IER_RBRINT);
	NVIC_EnableIRQ(USART2_IRQn);

	RingBuffer_Init(uarts[1].rrb, rxbuf[1], 1, UART_BUF_SIZE);
	RingBuffer_Init(uarts[1].trb, txbuf[1], 1, UART_BUF_SIZE);

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

	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_IntEnable(LPC_USART3, UART_IER_RBRINT);
	NVIC_EnableIRQ(USART3_IRQn);

	RingBuffer_Init(uarts[2].rrb, rxbuf[2], 1, UART_BUF_SIZE);
	RingBuffer_Init(uarts[2].trb, txbuf[2], 1, UART_BUF_SIZE);
}
コード例 #2
0
ファイル: board.c プロジェクト: ernesto-g/micropython
//================================================[UART Management]==========================================================
void Board_UART_Init(LPC_USART_T *pUART)
{
	if(pUART==LPC_USART0)
	{
		/* 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 */
		uart0RxBufferData.buffer = NULL;
		uart0RxBufferData.size=0;
		uart0RxBufferData.index=0;
		uart0RxBufferData.flagNewPacket=0;
		uart0RxBufferData.timeoutCounter=0;
        	//NVIC_SetPriority(USART0_IRQn, 1);
        	//NVIC_EnableIRQ(USART0_IRQn);

	}
	else if(pUART==LPC_USART3)
	{
		/* 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 */
		uart3RxBufferData.buffer = NULL;
                uart3RxBufferData.size=0;
                uart3RxBufferData.index=0;
		uart3RxBufferData.flagNewPacket=0;
                uart3RxBufferData.timeoutCounter=0;

                //NVIC_SetPriority(USART3_IRQn, 1);
                //NVIC_EnableIRQ(USART3_IRQn);
	}
	/* Restart FIFOS: set Enable, Reset content, set trigger level */
   	Chip_UART_SetupFIFOS(pUART, UART_FCR_FIFO_EN | UART_FCR_TX_RS | UART_FCR_RX_RS | UART_FCR_TRG_LEV0);
   	/* dummy read */
   	Chip_UART_ReadByte(pUART);
   	/* enable rx interrupt */
   	Chip_UART_IntEnable(pUART, UART_IER_RBRINT);
}
コード例 #3
0
ファイル: uart.c プロジェクト: LeoSf/postgraduate_course
/** \brief TODO init_UART_RS485_EDUCIAA Initialization method  */
uint8_t init_UART_RS485_EDUCIAA(void)
{
	/** \details
	 * TODO description init_UART_RS485_EDUCIAA
	 *
	 * \param none
	 *
	 * \return uint8_t: TBD (to support errors in the init function)
	 * */

	/*  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 */

	return TRUE;
}
コード例 #4
0
ファイル: uart.c プロジェクト: LeoSf/postgraduate_course
/** \brief TODO init_UART_RS232_EDUCIAA Initialization method  */
uint8_t init_UART_RS232_EDUCIAA(void)
{
	/** \details
	 * TODO description init_UART_RS232_EDUCIAA
	 *
	 * \param none
	 *
	 * \return uint8_t: TBD (to support errors in the init function)
	 * */

	/* UART initialization*/

	/** 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 */

	return TRUE;
}
コード例 #5
0
ファイル: cdc_uart.c プロジェクト: 0xBADCA7/lk
/* UART port init routine */
void UCOM_UartInit(void)
{
	/* Board specific muxing */
	Init_UART_PinMux();

	/* 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);

	/* Enable receive data and line status interrupt */
	Chip_UART_IntEnable(LPC_USART, UART_INTEN_RXRDY);

	/* Enable Interrupt for UART channel */
	/* Priority = 1 */
	NVIC_SetPriority(LPC_IRQNUM, 1);
	/* Enable Interrupt for UART channel */
	NVIC_EnableIRQ(LPC_IRQNUM);
}
コード例 #6
0
extern int32_t ciaaDriverUart_ioctl(ciaaDevices_deviceType const * const device, int32_t const request, void * param)
{
   int32_t ret = -1;

   if((device == ciaaDriverUartConst.devices[0]) ||
      (device == ciaaDriverUartConst.devices[1]) ||
      (device == ciaaDriverUartConst.devices[2]) )
   {
      switch(request)
      {
         case ciaaPOSIX_IOCTL_STARTTX:
            /* disable THRE irq (TX) */
            Chip_UART_IntDisable((LPC_USART_T *)device->loLayer, UART_IER_THREINT);
            /* this one calls write */
            ciaaDriverUart_txConfirmation(device);
            /* enable THRE irq (TX) */
            Chip_UART_IntEnable((LPC_USART_T *)device->loLayer, UART_IER_THREINT);
            ret = 0;
            break;

         case ciaaPOSIX_IOCTL_SET_BAUDRATE:
            ret = Chip_UART_SetBaud((LPC_USART_T *)device->loLayer,  (int32_t)param);
            break;

         case ciaaPOSIX_IOCTL_SET_FIFO_TRIGGER_LEVEL:
            Chip_UART_SetupFIFOS((LPC_USART_T *)device->loLayer,  UART_FCR_FIFO_EN | UART_FCR_TX_RS | UART_FCR_RX_RS | (int32_t)param);
            break;

         case ciaaPOSIX_IOCTL_SET_ENABLE_TX_INTERRUPT:
            if((bool)(intptr_t)param == false)
            {
               /* disable THRE irq (TX) */
               Chip_UART_IntDisable((LPC_USART_T *)device->loLayer, UART_IER_THREINT);
            }
            else
            {
               /* enable THRE irq (TX) */
               Chip_UART_IntEnable((LPC_USART_T *)device->loLayer, UART_IER_THREINT);
            }
            break;

         case ciaaPOSIX_IOCTL_SET_ENABLE_RX_INTERRUPT:
            if((bool)(intptr_t)param == false)
            {
               /* disable RBR irq (RX) */
               Chip_UART_IntDisable((LPC_USART_T *)device->loLayer, UART_IER_RBRINT);
            }
            else
            {
               /* enable RBR irq (RX) */
               Chip_UART_IntEnable((LPC_USART_T *)device->loLayer, UART_IER_RBRINT);
            }
            break;
      }
   }
   return ret;
}
コード例 #7
0
void initUSART_USB(uint32_t baud){
    /* Configuracion del Sistem Control Unit, para hacer uso de USB*/
	Chip_SCU_PinMux(UM_PORT7,PIN_RX_U2, MD_PLN | MD_EZI | MD_ZI, FUNC6);
    Chip_SCU_PinMux(UM_PORT7,PIN_TX_U2, MD_PLN, FUNC6);

    Chip_UART_Init(LPC_USART2);
    Chip_UART_SetBaud(LPC_USART2, baud);
    Chip_UART_SetupFIFOS(LPC_USART2, UART_FCR_FIFO_EN | UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_DIS | UART_FCR_TRG_LEV0);
    Chip_UART_TXEnable(LPC_USART2);
}
コード例 #8
0
void configurar_UART(void)
{

	Chip_SCU_PinMux(7,1,MD_PDN,FUNC6);
	Chip_SCU_PinMux(7,2,MD_PLN|MD_EZI|MD_ZI, FUNC6);
	Chip_UART_Init(LPC_USART2);
	Chip_UART_SetBaud(LPC_USART2, 9600);
	Chip_UART_SetupFIFOS(LPC_USART2, UART_FCR_FIFO_EN | UART_FCR_TRG_LEV0);
	Chip_UART_TXEnable(LPC_USART2);
}
コード例 #9
0
ファイル: board.c プロジェクト: pridolfi/workspace
/* Board Debug UART Initialisation function */
static void Board_UART_Init(void)
{
#if defined(DEBUG_UART)
	Chip_UART_Init(DEBUG_UART);
	Chip_UART_ConfigData(DEBUG_UART, UART_CFG_DATALEN_8 | UART_CFG_STOPLEN_1 | UART_CFG_PARITY_NONE);
	Chip_UART_Enable(DEBUG_UART);
	Chip_UART_TXEnable(DEBUG_UART);
	Chip_UART_SetBaud(DEBUG_UART, DEBUGBAUDRATE);
#endif
}
コード例 #10
0
void Board_UART_Init(uint32_t baudrate) {
    Chip_IOCON_PinMuxSet(LPC_IOCON, UART_RX_IOCON, (IOCON_FUNC1 | IOCON_MODE_INACT));	// Rx pin
    Chip_IOCON_PinMuxSet(LPC_IOCON, UART_TX_IOCON, (IOCON_FUNC1 | IOCON_MODE_INACT));	// Tx Pin

    Chip_UART_Init(LPC_USART);
    Chip_UART_SetBaud(LPC_USART, baudrate);
    Chip_UART_ConfigData(LPC_USART, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_DIS));
    Chip_UART_SetupFIFOS(LPC_USART, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2));
    Chip_UART_TXEnable(LPC_USART);
}
コード例 #11
0
ファイル: uart_rb.c プロジェクト: fcladera/ciaa_lpcopen_bare
/**
 * @brief	Main UART program body
 * @return	Always returns 1
 */
int main(void)
{
	uint8_t key;
	int bytes;

	SystemCoreClockUpdate();
	Board_Init();
	Board_UART_Init(LPC_UARTX);
	Board_LED_Set(0, false);

	/* Setup UART for 115.2K8N1 */
	Chip_UART_Init(LPC_UARTX);
	Chip_UART_SetBaud(LPC_UARTX, 115200);
	Chip_UART_ConfigData(LPC_UARTX, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT));
	Chip_UART_SetupFIFOS(LPC_UARTX, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2));
	Chip_UART_TXEnable(LPC_UARTX);

	/* 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(LPC_UARTX, (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(LPC_UARTX, (UART_IER_RBRINT | UART_IER_RLSINT));

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

	/* Send initial messages */
	Chip_UART_SendRB(LPC_UARTX, &txring, inst1, sizeof(inst1) - 1);
	Chip_UART_SendRB(LPC_UARTX, &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_UARTX, &rxring, &key, 1);
		if (bytes > 0) {
			/* Wrap value back around */
			if (Chip_UART_SendRB(LPC_UARTX, &txring, (const uint8_t *) &key, 1) != 1) {
				Board_LED_Toggle(0);/* Toggle LED if the TX FIFO is full */
			}
		}
	}

	/* DeInitialize UART0 peripheral */
	NVIC_DisableIRQ(UARTx_IRQn);
	Chip_UART_DeInit(LPC_UARTX);

	return 1;
}
コード例 #12
0
ファイル: target_uart.c プロジェクト: TWilmer/targetboard
/* UART port init routine */
static void UCOM_UartInit(int i)
{

	/* Pin-muxing done in board init. */
	//Init_UART_PinMux();
	if(i==1)
	{
		Chip_UART_Init(LPC_UART0);
		Chip_UART_SetBaud(LPC_UART0, 115200);
		Chip_UART_ConfigData(LPC_UART0, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT));
		Chip_UART_SetupFIFOS(LPC_UART0, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2));
		Chip_UART_TXEnable(LPC_UART0);

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

		/* Enable Interrupt for UART channel */
		/* Priority = 1 */
		NVIC_SetPriority(UART0_IRQn, 1);
		/* Enable Interrupt for UART channel */

	}

	if(i==2)
	{
		Chip_UART_Init(LPC_UART2);
		Chip_UART_SetBaud(LPC_UART2, 115200);
		Chip_UART_ConfigData(LPC_UART2, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT));
		Chip_UART_SetupFIFOS(LPC_UART2, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2));
		Chip_UART_TXEnable(LPC_UART2);

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

		/* Enable Interrupt for UART channel */
		/* Priority = 1 */
		NVIC_SetPriority(UART2_IRQn, 1);
		/* Enable Interrupt for UART channel */

	}

}
コード例 #13
0
ファイル: board.c プロジェクト: glocklueng/ac_charging
/* 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
}
コード例 #14
0
ファイル: board.c プロジェクト: Strongc/Earphone-Code
/* 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
}
コード例 #15
0
ファイル: board.c プロジェクト: FEDEVEL/openrex-lpc
/* 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
}
コード例 #16
0
/* Init seriové linky a pinů určených k přenosu dat
 * Nastavení UARTu: 115.2K8N1.
 *  FIFO lvl3 - 14 znaků.
 *  */
void setup_uarts(){

	/* UART0 set up */
	Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 2, (IOCON_FUNC1 | IOCON_MODE_INACT));
	Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 3, (IOCON_FUNC1 | IOCON_MODE_INACT));

	/* Setup UART0 for 115.2K8N1 */
	Chip_UART_Init(LPC_UART0);
	Chip_UART_SetBaud(LPC_UART0, 115200);
	Chip_UART_ConfigData(LPC_UART0, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT));
	Chip_UART_SetupFIFOS(LPC_UART0, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2));
	Chip_UART_TXEnable(LPC_UART0);
	Chip_UART_IntEnable(UART0, (UART_IER_RBRINT));
	Chip_UART_SetupFIFOS(LPC_UART0, (UART_FCR_FIFO_EN | UART_FCR_RX_RS |
	UART_FCR_TX_RS | UART_FCR_TRG_LEV3));

	NVIC_EnableIRQ(UART0_IRQn);

	/* UART2 set up */
	Chip_IOCON_PinMuxSet(LPC_IOCON, 2, 8, (IOCON_FUNC2 | IOCON_MODE_INACT));
	Chip_IOCON_PinMuxSet(LPC_IOCON, 2, 9, (IOCON_FUNC2 | IOCON_MODE_INACT));

	/* Setup UART4 for 115.2K8N1 */
	Chip_UART_Init(UART2);
	Chip_UART_SetBaudFDR(UART2, 115200);
	Chip_UART_ConfigData(UART2, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_DIS));
	Chip_UART_TXEnable(UART2);
	Chip_UART_IntEnable(UART2, (UART_IER_RBRINT));
	Chip_UART_SetupFIFOS(UART2, (UART_FCR_FIFO_EN | UART_FCR_RX_RS |
	UART_FCR_TX_RS | UART_FCR_TRG_LEV3));

	NVIC_EnableIRQ(UART2_IRQn);

	/* UART4 set up */
	Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 22, (IOCON_FUNC3 | IOCON_MODE_INACT));
	Chip_IOCON_PinMuxSet(LPC_IOCON, 5, 3, (IOCON_FUNC4 | IOCON_MODE_INACT));


	/* Setup UART4 for 115.2K8N1 */
	Chip_UART_Init(LPC_UART4);
	Chip_UART_SetBaudFDR(LPC_UART4, 115200);
	Chip_UART_ConfigData(LPC_UART4, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_DIS));
	Chip_UART_TXEnable(LPC_UART4);
	Chip_UART_IntEnable(LPC_UART4, (UART_IER_RBRINT));
	Chip_UART_SetupFIFOS(LPC_UART4, (UART_FCR_FIFO_EN | UART_FCR_RX_RS |
	UART_FCR_TX_RS | UART_FCR_TRG_LEV3));

	//Chip_UART_SetAutoBaudReg(LPC_UART4,UART_ACR_START | UART_ACR_MODE);

	NVIC_EnableIRQ(UART4_IRQn);

}
コード例 #17
0
ファイル: cdc_uart.c プロジェクト: 0xBADCA7/lk
/* Set line coding call back routine */
static ErrorCode_t UCOM_SetLineCode(USBD_HANDLE_T hCDC, CDC_LINE_CODING *line_coding)
{
	uint32_t config_data = 0;

	switch (line_coding->bDataBits) {
	case 7:
		config_data |= UART_CFG_DATALEN_7;
		break;

	case 9:
		config_data |= UART_CFG_DATALEN_9;
		break;

	case 8:
	default:
		config_data |= UART_CFG_DATALEN_8;
		break;
	}

	switch (line_coding->bCharFormat) {
	case 2:	/* 2 Stop Bits */
		config_data |= UART_CFG_STOPLEN_2;
		break;

	default:
	case 1:	/* 1 Stop Bit */
		config_data |= UART_CFG_STOPLEN_1;
		break;
	}

	switch (line_coding->bParityType) {
	case 1:
		config_data |= (UART_CFG_PARITY_ODD);
		break;

	case 2:
		config_data |= (UART_CFG_PARITY_EVEN);
		break;

	default:
	case 0:
		config_data |= UART_CFG_PARITY_NONE;
		break;
	}

	if (line_coding->dwDTERate < 3125000) {
		Chip_UART_SetBaud(LPC_USART, line_coding->dwDTERate);
	}
	Chip_UART_ConfigData(LPC_USART, config_data);

	return LPC_OK;
}
コード例 #18
0
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 */
}
コード例 #19
0
ファイル: board.c プロジェクト: dlang9159/MCU_Test_MCore
/* 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_SetBaud(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
}
コード例 #20
0
/* 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
}
コード例 #21
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;
}
コード例 #22
0
ファイル: UART.c プロジェクト: lgescher/baremetal_edu_ciaa
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);
}
コード例 #23
0
ファイル: UART.c プロジェクト: RafaPoos/baremetal_edu_ciaa
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);

}
コード例 #24
0
ファイル: cdc_uart.c プロジェクト: jack77er/ledstriper
/* 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);
}
コード例 #25
0
ファイル: board.c プロジェクト: ernesto-g/micropython
void Board_UART_setConfig(LPC_USART_T *pUART,int32_t baud,int32_t stopBits,int32_t parity)
{
	Chip_UART_SetBaud(pUART, baud);

	uint32_t config=UART_LCR_WLEN8;
	if(stopBits==2)
		config|=UART_LCR_SBS_2BIT;
	else
		config|=UART_LCR_SBS_1BIT;

	switch(parity)
	{
		case 1: config|=UART_LCR_PARITY_ODD; break;
		case 2: config|=UART_LCR_PARITY_EVEN; break;
		case 3: config|=UART_LCR_PARITY_F_0; break;
		case 4: config|=UART_LCR_PARITY_F_1; break;
		default: config|=UART_LCR_PARITY_DIS;
	}
	Chip_UART_ConfigData(pUART, config);

}
コード例 #26
0
ファイル: uart.c プロジェクト: LeoSf/postgraduate_course
/** \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;
}
コード例 #27
0
ファイル: uartHandler.c プロジェクト: Wiznet/WIZ550S2E
void serial_info_init(struct __serial_info *serial)
{
	uint32_t config = 0;

	/* Set Baud Rate */
	Chip_UART_SetBaud(LPC_USART, serial->baud_rate);

	/* Set Data Bits */
	switch(serial->data_bits) {
		case word_len5:
			config |= UART_LCR_WLEN5;
			break;
		case word_len6:
			config |= UART_LCR_WLEN6;
			break;
		case word_len7:
			config |= UART_LCR_WLEN7;
			break;
		case word_len8:
			config |= UART_LCR_WLEN8;
			break;
		default:
			config |= UART_LCR_WLEN8;
			serial->data_bits = word_len8;
			break;
	}

	/* Set Stop Bits */
	switch(serial->stop_bits) {
		case stop_bit1:
			config |= UART_LCR_SBS_1BIT;
			break;
		case stop_bit2:
			config |= UART_LCR_SBS_2BIT;
			break;
		default:
			config |= UART_LCR_SBS_1BIT;
			serial->stop_bits = stop_bit1;
			break;
	}

	/* Set Parity Bits */
	switch(serial->parity) {
		case parity_none:
			config |= UART_LCR_PARITY_DIS;
			break;
		case parity_odd:
			config |= (UART_LCR_PARITY_EN | UART_LCR_PARITY_ODD);
			break;
		case parity_even:
			config |= (UART_LCR_PARITY_EN | UART_LCR_PARITY_EVEN);
			break;
		default:
			config |= UART_LCR_PARITY_DIS;
			serial->parity = parity_none;
			break;
	}
	Chip_UART_ConfigData(LPC_USART, config);

	Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 7, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));		// CTS
	Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 17, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));	// RTS 
	switch(serial->flow_control) {
		case flow_none:
			Chip_UART_ClearModemControl(LPC_USART, UART_MCR_RTS_CTRL | UART_MCR_AUTO_RTS_EN | UART_MCR_AUTO_CTS_EN);
			Chip_UART_ClearRS485Flags(LPC_USART, UART_RS485CTRL_DCTRL_EN | UART_RS485CTRL_NMM_EN | UART_RS485CTRL_OINV_1);
			break;
		case flow_rts_cts:
			Chip_UART_ClearRS485Flags(LPC_USART, UART_RS485CTRL_DCTRL_EN | UART_RS485CTRL_NMM_EN | UART_RS485CTRL_OINV_1);
			Chip_UART_SetModemControl(LPC_USART, UART_MCR_AUTO_RTS_EN | UART_MCR_AUTO_CTS_EN);
			break;
		case flow_rs422:
			Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 17, (IOCON_FUNC0 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));	// RTS 
			Chip_GPIO_SetPinState(LPC_GPIO, 0, 17, 0);
			Chip_UART_ClearModemControl(LPC_USART, UART_MCR_RTS_CTRL | UART_MCR_AUTO_RTS_EN | UART_MCR_AUTO_CTS_EN);
			Chip_UART_ClearRS485Flags(LPC_USART, UART_RS485CTRL_DCTRL_EN | UART_RS485CTRL_NMM_EN | UART_RS485CTRL_OINV_1);
			break;
		case flow_rs485:
			Chip_UART_ClearModemControl(LPC_USART, UART_MCR_RTS_CTRL | UART_MCR_AUTO_RTS_EN | UART_MCR_AUTO_CTS_EN);
			Chip_UART_SetRS485Flags(LPC_USART, UART_RS485CTRL_DCTRL_EN | UART_RS485CTRL_NMM_EN | UART_RS485CTRL_OINV_1);
			break;
		default:
			break;
	}
}
コード例 #28
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;
}
コード例 #29
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;
}
コード例 #30
0
ファイル: uart_test.c プロジェクト: nopodige/bike_tire_video
/**
 * @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;
}