/* Wait execution cycle to complete on the SPI interface. */
BOOLEAN WaitForSpiCycleComplete(IN UINT32 ScSpiBar0, IN BOOLEAN ErrorCheck)
/* Wait execution cycle to complete on the SPI interface. */
BOOLEAN WaitForSpiCycleComplete(IN UINT32 ScSpiBar0, IN BOOLEAN ErrorCheck)
{
  UINT64  WaitTicks;
  UINT64  WaitCount;
  UINT32  Data32;
  WaitCount = WAIT_TIME / WAIT_PERIOD;
  for (WaitTicks = 0; WaitTicks < WaitCount; WaitTicks++) {
    Data32 = MmioRead32 (ScSpiBar0 + R_SPI_HSFS);
    if ((Data32 & B_SPI_HSFS_SCIP) == 0) {
      MmioWrite32 (ScSpiBar0 + R_SPI_HSFS, B_SPI_HSFS_FCERR | B_SPI_HSFS_FDONE);
      if (((Data32 & B_SPI_HSFS_FCERR) != 0) && ErrorCheck) {
        return FALSE;
      } else {
        return TRUE;
      }
    }
    MicroSecondDelay (WAIT_PERIOD);
  }
  return FALSE;
}