MCPcopy Create free account
hub / github.com/SmingHub/Sming / disk_write

Function disk_write

Sming/Libraries/SDCard/SDCard.cpp:481–522  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

479/*-----------------------------------------------------------------------*/
480
481DRESULT disk_write(BYTE drv, /* Physical drive nmuber (0) */
482 const BYTE* buff, /* Pointer to the data to be written */
483 DWORD sector, /* Start sector number (LBA) */
484 UINT count /* Sector count (1..128) */
485)
486{
487 if(disk_status(drv) & STA_NOINIT) {
488 return RES_NOTRDY;
489 }
490 if(!(CardType & CT_BLOCK)) {
491 sector *= 512; /* Convert LBA to byte address if needed */
492 }
493
494 if(count == 1) { /* Single block write */
495 if((send_cmd(CMD24, sector) == 0) /* WRITE_BLOCK */
496 && xmit_datablock(buff, 0xFE)) {
497 count = 0;
498 } else {
499 debug_e("[SDCard] CMD24 error");
500 }
501 } else { /* Multiple block write */
502 if(CardType & CT_SDC) {
503 send_cmd(ACMD23, count);
504 }
505 if(send_cmd(CMD25, sector) == 0) { /* WRITE_MULTIPLE_BLOCK */
506 do {
507 if(!xmit_datablock(buff, 0xFC)) {
508 debug_e("[SDCard] xmit error");
509 break;
510 }
511 buff += 512;
512 } while(--count);
513 if(!xmit_datablock(0, 0xFD)) { /* STOP_TRAN token */
514 debug_e("[SDCard] STOP_TRAN error");
515 count = 1;
516 }
517 }
518 }
519 deselect();
520
521 return count ? RES_ERROR : RES_OK;
522}
523
524/*-----------------------------------------------------------------------*/
525/* Miscellaneous Functions */

Callers 9

sync_windowFunction · 0.85
sync_fsFunction · 0.85
f_readFunction · 0.85
f_writeFunction · 0.85
f_syncFunction · 0.85
f_lseekFunction · 0.85
f_truncateFunction · 0.85
f_mkfsFunction · 0.85
f_fdiskFunction · 0.85

Calls 4

disk_statusFunction · 0.85
send_cmdFunction · 0.85
xmit_datablockFunction · 0.85
deselectFunction · 0.85

Tested by

no test coverage detected