Hi all,
I have implemented a sort of circular buffer in C for embedded system the code is something like this
#define BUFFER_LENGTH 25
UINT8_T array[BUFFER_LENGTH];
UINT8_T increment_interrupt;
void interrupt(void)
{
increment_interrupt++;
array[increment_interrupt] = data;
if(increment_interrupt == 25)
increment_interrupt = 0;
}
UINT8_T g_old_Index_u8=0;
UINT8_T g_new_Index_u8=0;
void main()
{
g_old_Index_u8 = g_new_Index_u8;
g_new_Index_u8 = increment_interrupt;
if(g_new_Index_u8 > g_old_Index_u8)
{
fl_origianlcopy_u8 = g_new_Index_u8 - g_old_Index_u8;
fl_local_counter_u8 = fl_origianlcopy_u8;
}
else if(g_new_Index_u8 < g_old_Index_u8)
{
fl_origianlcopy_u8 = BUFFER_LENGTH + g_new_Index_u8 - g_old_Index_u8;
fl_local_counter_u8 = fl_origianlcopy_u8;
}
else
{
}
while(fl_local_counter_u8)
{
fl_sum_index = (g_old_Index_u8 + fl_index_three_u8) % (25);
fl_local_data_uA[fl_index_three_u8]=array[fl_sum_index];
fl_local_counter_u8--;
fl_index_three_u8++;
}
if(fl_origianlcopy_u8 > 0)
{
/* Do some procesing*/
}
}
The interrupt function and the main function are parallel processing. I could get the originalcopy_u8 correct for some test cases. But for some test cases it is failing. Please someone help me to correct the mistake. I have not exactly copy pasted the code here but the logic.