/* Helper function to sort the segments in the linked list in order of ascending base address. It uses a bubble sort algorithm.  */
static void FirmwareSortSegments(void)
/* Helper function to sort the segments in the linked list in order of ascending base address. It uses a bubble sort algorithm.  */
static void FirmwareSortSegments(void)
{
  tFirmwareSegment * currentSegment;
  uint32_t i;
  uint32_t tempBase;  
  uint32_t tempLength;                
  uint8_t *tempData;
  if (FirmwareGetSegmentCount() > 1)
  {
    for (i = 1; i < FirmwareGetSegmentCount(); i++)
    {
      currentSegment = segmentList;
      while ( (currentSegment != NULL) && (currentSegment->next != NULL) )
      {
        if (currentSegment->base > currentSegment->next->base) 
        {
          tempBase = currentSegment->next->base;
          tempLength = currentSegment->next->length;                
          tempData = currentSegment->next->data;
          currentSegment->next->base = currentSegment->base;
          currentSegment->next->length = currentSegment->length;
          currentSegment->next->data = currentSegment->data;
          currentSegment->base = tempBase;
          currentSegment->length = tempLength;
          currentSegment->data = tempData;
        }
        currentSegment = currentSegment->next;
      }
    }
  }
}