I am trying to implement message timeout for UART message, is it possible without global variables.
Two timeout detections i want to do, one is the complete message frame timeout within 10ms and another inter message byte timeout.
The frame format is
Start of Frame: 0x3A, Address, Data (this is variable but there is max limit of 10 Bytes), CRC, EOF.
As a starting point i want to detect the timeout of continuous messages, but the number of global variables are more, can i optimize or use some other method to avoid global variables.
Two timeout detections i want to do, one is the complete message frame timeout within 10ms and another inter message byte timeout.
The frame format is
Start of Frame: 0x3A, Address, Data (this is variable but there is max limit of 10 Bytes), CRC, EOF.
As a starting point i want to detect the timeout of continuous messages, but the number of global variables are more, can i optimize or use some other method to avoid global variables.
Code:
uint8_t messagerxed = FALSE;
uint16_t msgcounter=0;
uint8_t msgtimeout = FALSE;
int main(void)
{
while(1);
}
/********* UART Interrupt ********/
UartInterrupt(void) {
messagerxed = TRUE;
msgcounter = 0;
msgtimeout = FALSE;
array[count++] = data;
}
/****** 1 ms Time Interrupt ********/
OnemsTimerInterrupt(void) {
if(messagerxed == TRUE) {
msgcounter++;
if(msgcounter == FIVEMS) {
msgtimeout = TRUE;
messagerxed = FALSE; // reset the msgrxed flag
msgcounter = 0; // reset the msgcouter
}
}