src/occ_405/cmdh/cmdh_snapshot.c
// Function Specification
//
// Name: cmdh_snapshot_find_oldest_newest
//
// Description: Returns the index of the oldest and newest snapshot in the
//              g_cmdh_snapshot_array.
//
// End Function Specification
Function Specification
Name: cmdh_snapshot_find_oldest_newest

Returns the index of the oldest and newest snapshot in the
g_cmdh_snapshot_array.

End Function Specification
Function Specification Name : cmdh_snapshot_find_oldest_newest Returns the index of the oldest and newest snapshot in the g_cmdh_snapshot_array . End Function Specification
VOID cmdh_snapshot_find_oldest_newest(uint8_t  *o_oldest,
                                      uint8_t  *o_newest)
{
    uint8_t                 l_index = 0;
    do
    {
        if((g_cmdh_snapshot_cur_index == 0) &&
           (g_cmdh_snapshot_array[0].current_id == 0) &&
           (g_cmdh_snapshot_array[CMDH_SNAPSHOT_MAX_INDEX].current_id == 0))
        {
            *o_oldest = 0;
            *o_newest = 0;
            break;
        }
        *o_newest = g_cmdh_snapshot_cur_index;
        l_index = g_cmdh_snapshot_cur_index+1;
        if(l_index > CMDH_SNAPSHOT_MAX_INDEX)
        {
            l_index = 0;
        }
        else if((g_cmdh_snapshot_array[l_index].current_id == 0) &&
                (g_cmdh_snapshot_array[CMDH_SNAPSHOT_MAX_INDEX].current_id == 0))
        {
            l_index = 0;
        }
        *o_oldest = l_index;
    }while(FALSE);
    return;
}
VOID cmdh_snapshot_find_oldest_newest ( uint8_t * o_oldest , uint8_t * o_newest ) { uint8_t l_index = 0 ; do { if ( ( g_cmdh_snapshot_cur_index == 0 ) && ( g_cmdh_snapshot_array [ 0 ] . current_id == 0 ) && ( g_cmdh_snapshot_array [ CMDH_SNAPSHOT_MAX_INDEX ] . current_id == 0 ) ) { * o_oldest = 0 ; * o_newest = 0 ; break ; } * o_newest = g_cmdh_snapshot_cur_index ; l_index = g_cmdh_snapshot_cur_index + 1 ; if ( l_index > CMDH_SNAPSHOT_MAX_INDEX ) { l_index = 0 ; } else if ( ( g_cmdh_snapshot_array [ l_index ] . current_id == 0 ) && ( g_cmdh_snapshot_array [ CMDH_SNAPSHOT_MAX_INDEX ] . current_id == 0 ) ) { l_index = 0 ; } * o_oldest = l_index ; } while ( FALSE ) ; return ; }
Function Specification
Name: cmdh_snapshot_find_oldest_newest
Function Specification Name : cmdh_snapshot_find_oldest_newest
// We wont be called if no snapshots are available so we know at least // one is available // If our current index is 0, it's id is 0, and the last entry has // an id of 0 then we know we haven't wrapped yet since 2 entries // can not have the same current_id and 0 was what's written in // as an initializer // Newest will be g_cmdh_snapshot_cur_index // n = newest, o=oldest, x=used, _=empty //________________________________________ //|x|x|x|x|x|x|x|x|x|x|x|n|o|x|x|x|x|x|x|x| // Start by assuming that the oldest snapshot is right after the newest. //________________________________________ //|o|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|n| //Check on whether the newest was at the end of the array.  That would //mean that the oldest entry is at index 0. //________________________________________ //|o|x|x|x|x|x|x|x|x|x|x|n|_|_|_|_|_|_|_|_| //Check on whether the last entry in the array is empty and so is the one //right after the newest entry. If so, that means oldest is at index 0 since //we haven't wrapped yet. // else oldest is just equal to l_index