msg_t Mtd25::wait_op_complete(systime_t timeout) { systime_t start = chVTGetSystemTimeX(); systime_t end = start + timeout; osalThreadSleepMilliseconds(2); while (chVTIsSystemTimeWithinX(start, end)) { uint8_t tmp; #if SPI_USE_MUTUAL_EXCLUSION spiAcquireBus(this->spip); #endif spiSelect(spip); spiPolledExchange(spip, S25_CMD_RDSR1); tmp = spiPolledExchange(spip, 0); spiUnselect(spip); #if SPI_USE_MUTUAL_EXCLUSION spiReleaseBus(this->spip); #endif if (tmp & S25_SR1_WIP) { continue; } else { if (tmp & (S25_SR1_PERR | S25_SR1_EERR)) return MSG_RESET; else return MSG_OK; } osalThreadSleepMilliseconds(10); } /* time is out */ return MSG_RESET; }
bool System::isTimeWithin(systime_t start, systime_t end) { return chVTIsSystemTimeWithinX(start, end); }