How to cut interrupt code to minimum?
I have some interrupt lets say from UART to make real example:
void USART2_IRQHandler(void)
{
int i = 0;
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
{
static uint8_t cnt = 0;
char t = USART_ReceiveData(USART2);
if((t!='!')&&(cnt < MAX_STRLEN))
{
received_string[cnt] = t;
cnt++;
}
else
{
cnt = 0;
if(strncmp(received_string,"connection",10) == 0)
{
USART2_SendText("connection ok");
}
else if(strncmp(received_string,"sine",4) == 0)
{
DAC_DeInit();
DAC_Ch2SineWaveConfig();
USART2_SendText("generating sine");
}
else
{
USART2_SendText("unknown commmand: ");
USART2_SendText(received_string);
}
for (i = 0; i <= MAX_STRLEN+1; i++) // flush buffer
received_string[i] = '\0';
}
}
}
But interrupt code should run as fast as possible. And here we have some time consuming functions inside.
The question is: What is the correct way to implement interrupts which calls time consuming functions?
One of my ideas is to create flags buffer add flags in interrupt. And process flag buffer in main loop calling approperiate functions. Is it correct?
I have some interrupt lets say from UART to make real example:
void USART2_IRQHandler(void)
{
int i = 0;
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
{
static uint8_t cnt = 0;
char t = USART_ReceiveData(USART2);
if((t!='!')&&(cnt < MAX_STRLEN))
{
received_string[cnt] = t;
cnt++;
}
else
{
cnt = 0;
if(strncmp(received_string,"connection",10) == 0)
{
USART2_SendText("connection ok");
}
else if(strncmp(received_string,"sine",4) == 0)
{
DAC_DeInit();
DAC_Ch2SineWaveConfig();
USART2_SendText("generating sine");
}
else
{
USART2_SendText("unknown commmand: ");
USART2_SendText(received_string);
}
for (i = 0; i <= MAX_STRLEN+1; i++) // flush buffer
received_string[i] = '\0';
}
}
}
But interrupt code should run as fast as possible. And here we have some time consuming functions inside.
The question is: What is the correct way to implement interrupts which calls time consuming functions?
One of my ideas is to create flags buffer add flags in interrupt. And process flag buffer in main loop calling approperiate functions. Is it correct?
No comments:
Post a Comment