/* Waits for the SPI flash to indicate that it is ready (not busy) or until a timeout occurs.  */
spiflashError_e w25q16bvWaitForReady()
/* Waits for the SPI flash to indicate that it is ready (not busy) or until a timeout occurs.  */
spiflashError_e w25q16bvWaitForReady()
{
  uint32_t timeout = 0;
  uint8_t status;
  while ( timeout < SSP_MAX_TIMEOUT )
  {
    status = w25q16bvGetStatus() & W25Q16BV_STAT1_BUSY;
    if (status == 0)
    {
      break;
    }
    timeout++;
  }
  if ( timeout == SSP_MAX_TIMEOUT )
  {
    return SPIFLASH_ERROR_TIMEOUT_READY;
  }
  return SPIFLASH_ERROR_OK;
}