int32_t Board_UART_getChar(LPC_USART_T *pUART) { if (Chip_UART_ReadLineStatus(pUART) & UART_LSR_RDR) { return (int32_t)Chip_UART_ReadByte(pUART); } return -1; }
void UART0_IRQHandler (void) { uint8_t status = Chip_UART_ReadLineStatus(LPC_USART0); if(status & UART_LSR_RDR) { if(uart0RxBufferData.index<uart0RxBufferData.size) { uart0RxBufferData.buffer[uart0RxBufferData.index] = Chip_UART_ReadByte(LPC_USART0); if(uart0RxBufferData.timeout==0) { if(uart0RxBufferData.buffer[uart0RxBufferData.index]==uart0RxBufferData.finalByte) { uart0RxBufferData.flagNewPacket=1; //Board_UARTPutSTR("entro paquete por byte final!:"); //Board_UARTPutSTR(uart0RxBufferData.buffer); } } else { uart3RxBufferData.timeoutCounter=uart3RxBufferData.timeout; } uart3RxBufferData.index++; } else uart3RxBufferData.flagNewPacket=1; } }
/* Sends a character on the UART */ void Board_UARTPutChar(char ch) { #if defined(DEBUG_ENABLE) while ((Chip_UART_ReadLineStatus(DEBUG_UART) & UART_LSR_THRE) == 0) {} Chip_UART_SendByte(DEBUG_UART, (uint8_t) ch); #endif }
void __lpc1788_isr_uart4(void) { while (UART_LSR_RDR & Chip_UART_ReadLineStatus(LPC_UART4)) { read_byte = Chip_UART_ReadByte(LPC_UART4); buf_uart.buffer[buf_uart.producer] = read_byte; BUF_PRODUCER_PLUS1; } }
/* UART receive-only interrupt handler for ring buffers */ void Chip_UART_RXIntHandlerRB(LPC_USART_T *pUART, RINGBUFF_T *pRB) { /* New data will be ignored if data not popped in time */ while (Chip_UART_ReadLineStatus(pUART) & UART_LSR_RDR) { uint8_t ch = Chip_UART_ReadByte(pUART); RingBuffer_Insert(pRB, &ch); } }
/* Sends a character on the UART */ void Board_UARTPutChar(char ch) { #if defined(DEBUG_UART) /* Wait for space in FIFO */ while ((Chip_UART_ReadLineStatus(DEBUG_UART) & UART_LSR_THRE) == 0) {} Chip_UART_SendByte(DEBUG_UART, (uint8_t) ch); #endif }
/* Gets a character from the UART, returns EOF if no character is ready */ int Board_UARTGetChar(void) { #if defined(DEBUG_UART) if (Chip_UART_ReadLineStatus(DEBUG_UART) & UART_LSR_RDR) { return (int) Chip_UART_ReadByte(DEBUG_UART); } #endif return EOF; }
/* UART transmit-only interrupt handler for ring buffers */ void Chip_UART_TXIntHandlerRB(LPC_USART_T *pUART, RINGBUFF_T *pRB) { uint8_t ch; /* Fill FIFO until full or until TX ring buffer is empty */ while ((Chip_UART_ReadLineStatus(pUART) & UART_LSR_THRE) != 0 && RingBuffer_Pop(pRB, &ch)) { Chip_UART_SendByte(pUART, ch); } }
uint32_t Board_UART_Write(LPC_USART_T *pUART, uint8_t const * const buffer, uint32_t const size) { uint32_t ret = 0; while(ret<size) { while((Chip_UART_ReadLineStatus(pUART) & UART_LSR_THRE) == 0){} Chip_UART_SendByte(pUART, buffer[ret]); /* bytes written */ ret++; } return ret; }
/* Transmit a byte array through the UART peripheral (non-blocking) */ int Chip_UART_Send(LPC_USART_T *pUART, const void *data, int numBytes) { int sent = 0; uint8_t *p8 = (uint8_t *) data; /* Send until the transmit FIFO is full or out of bytes */ while ((sent < numBytes) && ((Chip_UART_ReadLineStatus(pUART) & UART_LSR_THRE) != 0)) { Chip_UART_SendByte(pUART, *p8); p8++; sent++; } return sent; }
/* Read data through the UART peripheral (non-blocking) */ int Chip_UART_Read(LPC_USART_T *pUART, void *data, int numBytes) { int readBytes = 0; uint8_t *p8 = (uint8_t *) data; /* Send until the transmit FIFO is full or out of bytes */ while ((readBytes < numBytes) && ((Chip_UART_ReadLineStatus(pUART) & UART_LSR_RDR) != 0)) { *p8 = Chip_UART_ReadByte(pUART); p8++; readBytes++; } return readBytes; }
extern ssize_t ciaaDriverUart_write(ciaaDevices_deviceType const * const device, uint8_t const * const buffer, size_t const size) { ssize_t ret = 0; if((device == ciaaDriverUartConst.devices[0]) || (device == ciaaDriverUartConst.devices[1]) || (device == ciaaDriverUartConst.devices[2]) ) { while((Chip_UART_ReadLineStatus((LPC_USART_T *)device->loLayer) & UART_LSR_THRE) && (ret < size)) { /* send first byte */ Chip_UART_SendByte((LPC_USART_T *)device->loLayer, buffer[ret]); /* bytes written */ ret++; } } return ret; }
uint32_t readStatus_UART_USB_EDUCIAA() { return (Chip_UART_ReadLineStatus((LPC_USART_T *)LPC_USART2) & UART_LSR_THRE); }
/** \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; }
int32_t Board_UART_charAvailable(LPC_USART_T *pUART) { return Chip_UART_ReadLineStatus(pUART) & UART_LSR_RDR; }
/* Přerušení.. * UART0 - Konfigurace mac/ip adresy * UART2 - Pro konektory J4 - 5 na desce * UART4 - Pro debug test (konektory J6 - 7) * * Přijímání dat po bajtu od zařízení JN5148 a ukládání * do kruhového bufferu. */ void __lpc1788_isr_uart0(void) { while (UART_LSR_RDR & Chip_UART_ReadLineStatus(UART0)) { eeprom_buffer[eeprom_lenght] = Chip_UART_ReadByte(UART0); eeprom_lenght++; } }