| 495 | */ |
| 496 | |
| 497 | int writeDataBlock(const SpiMasterHandle& spiMasterHandle, const uint8_t token, const void* const buffer, |
| 498 | const size_t size, const distortos::TickClock::duration duration) |
| 499 | { |
| 500 | uint8_t footer[3]; // crc + data response token |
| 501 | { |
| 502 | const uint8_t header[] {0xff, token}; |
| 503 | const SpiMasterTransfer transfers[] |
| 504 | { |
| 505 | {&header, nullptr, sizeof(header)}, |
| 506 | {buffer, nullptr, size}, |
| 507 | {nullptr, footer, sizeof(footer)}, |
| 508 | }; |
| 509 | const auto ret = spiMasterHandle.executeTransaction(SpiMasterTransfersRange{transfers}); |
| 510 | if (ret != 0) |
| 511 | return ret; |
| 512 | } |
| 513 | { |
| 514 | const auto ret = waitWhileBusy(spiMasterHandle, duration); |
| 515 | if (ret != 0) |
| 516 | return ret; |
| 517 | } |
| 518 | |
| 519 | const auto dataResponseToken = footer[2]; |
| 520 | if ((dataResponseToken & dataResponseTokenMask) != dataResponseTokenDataAccepted) |
| 521 | return EIO; |
| 522 | |
| 523 | return {}; |
| 524 | } |
| 525 | |
| 526 | /** |
| 527 | * \brief Reads response from SD card connected via SPI. |
no test coverage detected