if (IIRValue == IIR_RLS) /* Receive Line Status */ { LSRValue = LPC_UART->LSR; /* Receive Line Status */ if (LSRValue & (LSR_OE | LSR_PE | LSR_FE | LSR_RXFE | LSR_BI)) { /* There are errors or break interrupt */ /* Read LSR will clear the interrupt */ UARTStatus = LSRValue; Dummy = LPC_UART->RBR; /* Dummy read on RX to clear interrupt, then bail out */ return; } if (LSRValue & LSR_RDR) /* Receive Data Ready */ { /* If no error on RLS, normal ready, save into the data buffer. */ /* Note: read RBR will clear the interrupt */ UARTBuffer[UARTCount++] = LPC_UART->RBR; if (UARTCount == BUFSIZE) { UARTCount = 0; /* buffer overflow */ } } } |
volatile uint32_t UARTStatus; volatile uint8_t UARTTxEmpty = 1; volatile uint8_t UARTBuffer[BUFSIZE]; volatile uint32_t UARTCount = 0; uint8_t Buf_var[PKGSIZE], Parsable=0, First_char=1, Pos_in_message=0, Write1_personal=0;//za_char; uint8_t za_char,var_i, message[30]; uint8_t mes_fin[]="\n\rString totally evaluated.\n\r",mes_start[]="\n\rHit the { char.\n\r", mes_stop[]="\n\rHit the end } char.\n\r",mes_char[]="\n\rJust another useful char.\n\r" ; #if CONFIG_UART_DEFAULT_UART_IRQHANDLER==1 /***************************************************************************** ** Function name: UART_IRQHandler ** ** Descriptions: UART interrupt handler ** ** parameters: None ** Returned value: None ** *****************************************************************************/ void UART_IRQHandler(void) { //LPC_UART->IER = IER_THRE | IER_RLS; /* Disable RBR */ uint8_t IIRValue, LSRValue; uint8_t Dummy = Dummy; uint8_t Error=0; IIRValue = LPC_UART->IIR; IIRValue >>= 1; /* skip pending bit in IIR */ IIRValue &= 0x07; /* check bit 1~3, interrupt identification */ if (IIRValue == IIR_RLS) /* Receive Line Status */ { LSRValue = LPC_UART->LSR; /* Receive Line Status */ if (LSRValue & (LSR_OE | LSR_PE | LSR_FE | LSR_RXFE | LSR_BI)) { /* There are errors or break interrupt */ /* Read LSR will clear the interrupt */ UARTStatus = LSRValue; Dummy = LPC_UART->RBR; /* Dummy read on RX to clear interrupt, then bail out */ Error=1; //LPC_UART->IER = IER_THRE | IER_RLS | IER_RBR; /* Re-enable RBR */ return; } if (LSRValue & LSR_RDR) /* Receive Data Ready */ { Error=0; /* If no error on RLS, normal ready, save into the data buffer. */ /* Note: read RBR will clear the interrupt */ //UARTBuffer[UARTCount++] = LPC_UART->RBR; za_char= LPC_UART->RBR; // if (UARTCount == BUFSIZE) // { // UARTCount = 0; /* buffer overflow */ // } } } else if (IIRValue == IIR_RDA) /* Receive Data Available */ { Error=0; /* Receive Data Available */ za_char = LPC_UART->RBR; // if ( (LPC_UART->LSR & LSR_THRE) ); //LPC_UART->THR = za_char; // UARTBuffer[UARTCount++] = LPC_UART->RBR; // if (UARTCount == BUFSIZE) //{ // UARTCount = 0; /* buffer overflow */ //} } else if (IIRValue == IIR_CTI) /* Character timeout indicator */ {Error=1; /* Character Time-out indicator */ UARTStatus |= 0x100; /* Bit 9 as the CTI error */ } else if (IIRValue == IIR_THRE) /* THRE, transmit holding register empty */ {Error=1; /* THRE interrupt */ LSRValue = LPC_UART->LSR; /* Check status in the LSR to see if valid data in U0THR or not */ if (LSRValue & LSR_THRE) { UARTTxEmpty = 1; } else { UARTTxEmpty = 0; } } if(!Error) { if(!Parsable) { switch (za_char){ case '{': { UARTSend((uint8_t *)mes_start,(int)strlen((const char *)mes_start)); if(First_char==1) { First_char=0; Write1_personal=1; Pos_in_message=0; // LPC_UART->THR = '#'; UARTSend((uint8_t * )Buf_var, (int)strlen((const char *)Buf_var)); //LPC_UART->THR = '\n'; for( var_i=0;var_i<=PKGSIZE;var_i++) { Buf_var[var_i]=0; } } break; } case '}': { UARTSend((uint8_t *)mes_stop,(int)strlen((const char *)mes_stop)); if (First_char==0 ) { if (Pos_in_message == 5) { Parsable=1; } else { for( var_i=0;var_i<=PKGSIZE;var_i++) { Buf_var[var_i]=0; } First_char=1; Write1_personal=0; Pos_in_message=0; } } break; } default: { UARTSend((uint8_t *)mes_char,(int)strlen((const char *)mes_char)); if(First_char==0 && Write1_personal && Pos_in_message<=4 ) { Buf_var[Pos_in_message++]=za_char; UARTSend((uint8_t * )Buf_var, (int)strlen((const char *)Buf_var)); } } } } } // LPC_UART->IER = IER_THRE | IER_RLS | IER_RBR; /* Re-enable RBR */ UARTSend((uint8_t *)mes_fin,(int)strlen((const char *)mes_fin)); return; } #endif |