I'm using an Atmega168 in a project that involve using the ISRs from multiple sources. I have an ISR hooked up to an external button and a timer, to use it as a reset button after a predetermined hold time.
I'm also using an ISR hooked upto UART. The UART is connected to an external Linux based SoC. Upon receiving specific commands from the linux machine, the atmel will perform certain functions.
In very rare occasions, the linux hangs up during tranmission and is always sending out the UART commands. This saturates the ISR and it also prevents the reset button ISR to function.
Although this happens rarely, I would like to take measures for this. As far as I know, there are no way to set priority in avr ISRs. So what can I do if the UART ISR is always called and prevents the rest of the board from functioning?
EDIT:
I think the problem arises when the linux machine sends an empty string to the atmel.
the UART_receive() on the atmel gets stuck at: while ( !(UCSR0A & (1<<RXC0)) );
Any way I can avoid this?
unsigned char USART_Receive_string(unsigned char *x, unsigned char size)
{
unsigned char i = 0;
if (size == 0) return 0; // return 0 if no space
while (i < size - 1) { // check space is available (including additional null char at end)
unsigned char c;
while ( !(UCSR0A & (1<<RXC0)) ); // wait for another char - WARNING this will wait forever if nothing is received
c = UDR0;
if (c == '\0') break; // break on NULL character
x[i] = c; // write into the supplied buffer
i++;
}
x[i] = 0; // ensure string is null terminated
return i + 1; // return number of characters written
}