Beispiel #1
0
//================================================[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);
}
Beispiel #2
0
/**
 * @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;
}
/* 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);

}
Beispiel #4
0
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;
}
Beispiel #5
0
/** \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;
}
Beispiel #6
0
/** \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;
}
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;
}
Beispiel #8
0
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);
}
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);
}
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);
}
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);
}
Beispiel #12
0
/* 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 */

	}

}
/*==================[external functions definition]==========================*/
extern ciaaDevices_deviceType * ciaaDriverUart_open(char const * path, ciaaDevices_deviceType * device, uint8_t const oflag)
{
   /* Restart FIFOS: set Enable, Reset content, set trigger level */
   Chip_UART_SetupFIFOS((LPC_USART_T *)device->loLayer, UART_FCR_FIFO_EN | UART_FCR_TX_RS | UART_FCR_RX_RS | UART_FCR_TRG_LEV0);
   /* dummy read */
   Chip_UART_ReadByte((LPC_USART_T *)device->loLayer);
   /* enable rx interrupt */
   Chip_UART_IntEnable((LPC_USART_T *)device->loLayer, UART_IER_RBRINT);

   return device;
}
Beispiel #14
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
}
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 */
}
Beispiel #16
0
/* Initializes the pUART peripheral */
void Chip_UART_Init(LPC_USART_T *pUART)
{
	Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_UART0);
	Chip_Clock_SetUARTClockDiv(1);

	/* Enable FIFOs by default, reset them */
	Chip_UART_SetupFIFOS(pUART, (UART_FCR_FIFO_EN | UART_FCR_RX_RS | UART_FCR_TX_RS));

	/* Default 8N1, with DLAB disabled */
	Chip_UART_ConfigData(pUART, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_DIS));

	/* Disable fractional divider */
	pUART->FDR = 0x10;
}
Beispiel #17
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);
}
Beispiel #18
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);

}
Beispiel #19
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);
}
Beispiel #20
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);
}
Beispiel #21
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);
}
Beispiel #22
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;
}
/** \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;
}
/* clear UART rx ringbuffer */
void UART_FlushRxRB(void)
{
	Chip_UART_SetupFIFOS(LPC_USART, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2 | UART_FCR_RX_RS));
	RingBuffer_Flush(&uart_rxrb);
}
/**
 * @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;
}
Beispiel #26
0
/* clear UART tx ringbuffer */
void uart_flush_txrb(void)
{
    Chip_UART_SetupFIFOS(LPC_USART, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2 | UART_FCR_TX_RS));
    RingBuffer_Flush(&uart_txrb);
}