Altera_Forum
Honored Contributor
11 years agoSerial communication and interval timer integration problems
I'm required to build a Nios based fpga firmware for a specific system, which includes UART RS-232 communication. The communication itself based on packets of 20 bytes, with time outs between bytes receive. For example: if data receive process started if the next byte is not received within 1ms, discard, the received data, until 20 bytes are received. I've written in Nios IDE functions for communication and timer control: uart interrupt handling, enable/disable interrupts, checksum check, start timer, stop timer, restart timer, time out handling, set period and etc.
All the functions are working fine except there is a problem with some nesting: If I get to uart interrupt handling due to received byte, and within those interrupt routine I'm calling some timer control functions, I miss some of received bytes. It makes it look like those timer control functions take more than 100,000 CPU cycles, which is of course not true. UART baud rate is 115200, the whole system frequency is 50MHz. I can't copy for you the code, but here is the pseudo code of UART interrupt handling: int index = 0; unsigned char rx_packet[20]; void timer_interrupt_handling(){ if time out occurred { timer_stop(); index = 0; clear_timeout(); } } void uart_interrupt_handling(){ if byte is received { restart_timer(); rx_packet[index] = read_uart_rx(); index++; if index > 19 { timer_stop(); index = 0; packet_handling(); } } clear_uart_interrupt(); } If I run this code rx_packet ={rx[0], rx[5], rx[10], rx[15], non_valid, non_valid, ........} If I remove the timer functions calling, everything works fine.