while(true){ // Read LPC_USART->IIR if(is_break){ // handle_break // throwaway LPC_USART->RBR; }else if(has_data){ while(// LSR shows Read Data Ready in the RBR) { // Read byte from LPC_USART->RBR } } } |
while(true){ // Read LPC_USART->IIR if(is_break){ // handle_break // throwaway LPC_USART->RBR; }else if(has_data){ // Read one byte from LPC_USART->RBR } } |
void uart_receive_handler(void) { uint32_t interrupt_status = 0; uint32_t receive_status = 0; uint32_t interrupt_active = 0; uint32_t interrupt_type = 0; uint8_t trashcan = 0; while(TRUE) { interrupt_status = LPC_USART->IIR; interrupt_active = (interrupt_status & 1) == 0x0; // Funky because bit low means active if( interrupt_active == FALSE ) { break; } interrupt_type = (interrupt_status >> 1) & 0x7; // Grab bytes the three bytes, starting at bit 2 // If something other than a character // -- if(interrupt_type == 0x1) { // 0x1 == THRE //Send more data uart_transmit_next(); }else if(interrupt_type == 0x3) { // 0x3 == LSR receive_status = LPC_USART->LSR; // If break if(receive_status & UART_LSR_BI) { // Ship off what we have received receive_complete(); // throw away blank break value by reading from fifo trashcan = LPC_USART->RBR; trashcan = trashcan; // hide "never used" compiler warning. // Other errors } else if(receive_status & (UART_LSR_FE|UART_LSR_OE|UART_LSR_PE|UART_LSR_RXFE)) { // Throw away the rest of this packet. trashcan = LPC_USART->RBR; clean_packet = FALSE; }else{ } // If data ready // 0x2 = Data ready, 0x6 = leftover data ready (CTI) // -- } else if(interrupt_type == 0x2 || interrupt_type == 0x6) { dmx_buffer_add_byte(&receive_local_buffer, LPC_USART->RBR); if(dmx_buffer_is_full_rdm_packet(&receive_local_buffer)){ receive_complete(); } } } } |
if(receive_status & UART_LSR_BI) { // Ship off what we have received receive_complete(); // throw away blank break value by reading from fifo trashcan = LPC_USART->RBR; |
void uart_receive_handler(void) { uint32_t interrupt_status = 0; uint32_t receive_status = 0; uint32_t interrupt_active = 0; uint32_t interrupt_type = 0; uint8_t trashcan = 0; while(TRUE) { interrupt_status = LPC_USART->IIR; interrupt_active = (interrupt_status & 1) == 0x0; // Funky because bit low means active if( interrupt_active == FALSE ) { break; } interrupt_type = (interrupt_status >> 1) & 0x7; // Grab bytes the three bytes, starting at bit 2 receive_status = LPC_USART->LSR; if(interrupt_type == 0x1) { // 0x1 == THRE //Send more data uart_transmit_next(); }else if(interrupt_type == 0x3) { // 0x3 == LSR counters.interrupts +=1; if(receive_status & UART_LSR_OE){ counters.lsr_oe += 1; } if(receive_status & UART_LSR_PE){ counters.lsr_pe += 1; } if(receive_status & UART_LSR_FE){ counters.lsr_fe += 1; } if(receive_status & UART_LSR_BI){ counters.lsr_bi += 1; } if(receive_status & UART_LSR_RXFE){ counters.lsr_rxfe += 1; } // If break if(receive_status & UART_LSR_BI) { // Ship off what we have received recieve_complete(); // throw away blank break value by reading from fifo trashcan = LPC_USART->RBR; trashcan = trashcan; // hide "never used" compiler warning. // Other errors } else if(receive_status & (UART_LSR_FE|UART_LSR_OE|UART_LSR_PE|UART_LSR_RXFE)) { // Throw away the rest of this packet. trashcan = LPC_USART->RBR; clean_packet = FALSE; } // If also data ready if(receive_status & UART_LSR_RDR){ counters.lsr_rdr_alt += 1; trashcan = LPC_USART->RBR; } // If data ready // -- } else if(interrupt_type == 0x2 || interrupt_type == 0x6) { // 0x2 = Data ready, 0x6 = leftover data ready (CTI) while(LPC_USART->LSR & UART_LSR_RDR) { // LSR shows Read Data Ready in the RBR counters.lsr_rdr += 1; dmx_buffer_add_byte(&receive_local_buffer, LPC_USART->RBR); } if(dmx_buffer_is_full_rdm_packet(&receive_local_buffer)){ // Ship off what we have received recieve_complete(); } } } } |