MCPcopy Create free account
hub / github.com/DISTORTEC/distortos / waitWhile

Function waitWhile

source/devices/memory/SdCardSpiBased.cpp:407–423  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

405
406template<typename Functor>
407std::pair<int, uint8_t> waitWhile(const SpiMasterHandle& spiMasterHandle, const distortos::TickClock::duration duration,
408 Functor functor)
409{
410 const auto deadline = distortos::TickClock::now() + duration;
411 while (distortos::TickClock::now() < deadline)
412 {
413 uint8_t byte;
414 const SpiMasterTransfer transfer {nullptr, &byte, sizeof(byte)};
415 const auto ret = spiMasterHandle.executeTransaction(SpiMasterTransfersRange{transfer});
416 if (ret != 0)
417 return {ret, {}};
418 if (functor(byte) == false)
419 return {{}, byte};
420 }
421
422 return {ETIMEDOUT, {}};
423}
424
425/**
426 * \brief Waits while SD card connected via SPI is busy.

Callers 2

waitWhileBusyFunction · 0.85
readDataBlockFunction · 0.85

Calls 1

executeTransactionMethod · 0.45

Tested by

no test coverage detected