/* Switches blocks by programming the current one and initializing the next.  */
static tFlashBlockInfo * FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_addr)
/* Switches blocks by programming the current one and initializing the next.  */
static tFlashBlockInfo * FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_addr)
{
  blt_addr last_block_base_addr;
  last_block_base_addr = flashLayout[FLASH_LAST_SECTOR_IDX].sector_start + \
                         flashLayout[FLASH_LAST_SECTOR_IDX].sector_size -  \
                         FLASH_WRITE_BLOCK_SIZE;
  if (block == &bootBlockInfo)
  {
    block = &blockInfo;
  }
  else if (base_addr == last_block_base_addr)
  {
    block = &bootBlockInfo;
  }
  else
  {
    if (FlashWriteBlock(block) == BLT_FALSE)
    {
      return BLT_NULL;
    }
  }
  if (FlashInitBlock(block, base_addr) == BLT_FALSE)
  {
    return BLT_NULL;
  }
  return block;
}