@@ -608,10 +608,11 @@ uint8_t Sd2Card::waitStartBlock(void) {
608
608
609
609
\param[in] blockNumber Logical block to be written.
610
610
\param[in] src Pointer to the location of the data to be written.
611
+ \param[in] sync If the write should be synchronous.
611
612
\return The value one, true, is returned for success and
612
613
the value zero, false, is returned for failure.
613
614
*/
614
- uint8_t Sd2Card::writeBlock (uint32_t blockNumber, const uint8_t * src) {
615
+ uint8_t Sd2Card::writeBlock (uint32_t blockNumber, const uint8_t * src, uint8_t sync ) {
615
616
#if SD_PROTECT_BLOCK_ZERO
616
617
// don't allow write to first block
617
618
if (blockNumber == 0 ) {
@@ -631,16 +632,17 @@ uint8_t Sd2Card::writeBlock(uint32_t blockNumber, const uint8_t* src) {
631
632
if (!writeData (DATA_START_BLOCK, src)) {
632
633
goto fail;
633
634
}
634
-
635
- // wait for flash programming to complete
636
- if (!waitNotBusy (SD_WRITE_TIMEOUT)) {
637
- error (SD_CARD_ERROR_WRITE_TIMEOUT);
638
- goto fail;
639
- }
640
- // response is r2 so get and check two bytes for nonzero
641
- if (cardCommand (CMD13, 0 ) || spiRec ()) {
642
- error (SD_CARD_ERROR_WRITE_PROGRAMMING);
643
- goto fail;
635
+ if (sync) {
636
+ // wait for flash programming to complete
637
+ if (!waitNotBusy (SD_WRITE_TIMEOUT)) {
638
+ error (SD_CARD_ERROR_WRITE_TIMEOUT);
639
+ goto fail;
640
+ }
641
+ // response is r2 so get and check two bytes for nonzero
642
+ if (cardCommand (CMD13, 0 ) || spiRec ()) {
643
+ error (SD_CARD_ERROR_WRITE_PROGRAMMING);
644
+ goto fail;
645
+ }
644
646
}
645
647
chipSelectHigh ();
646
648
return true ;
@@ -760,3 +762,16 @@ uint8_t Sd2Card::writeStop(void) {
760
762
chipSelectHigh ();
761
763
return false ;
762
764
}
765
+ // ------------------------------------------------------------------------------
766
+ /* * Check if the SD card is busy
767
+
768
+ \return The value one, true, is returned when is busy and
769
+ the value zero, false, is returned for when is NOT busy.
770
+ */
771
+ uint8_t Sd2Card::isBusy (void ) {
772
+ chipSelectLow ();
773
+ byte b = spiRec ();
774
+ chipSelectHigh ();
775
+
776
+ return (b != 0XFF );
777
+ }
0 commit comments