From: asterix Date: Fri, 2 Sep 2011 16:16:34 +0000 (+0000) Subject: Add write block function. X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=fd1ea54bc72a87329ef7e729e9753b328772192d;p=bertos.git Add write block function. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@5013 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/drv/sd.c b/bertos/drv/sd.c index a16e7299..02ec9653 100644 --- a/bertos/drv/sd.c +++ b/bertos/drv/sd.c @@ -1090,9 +1090,40 @@ int sd_readSingleBlock(Sd *sd, size_t index, uint32_t *buf, size_t words) } +int sd_writeSingleBlock(Sd *sd, size_t index, uint32_t *buf, size_t words) +{ + ASSERT(sd); + ASSERT(buf); + + hsmci_prgTxDMA(buf, words, sd->csd.blk_len); + + if (hsmci_sendCmd(24, index * sd->csd.blk_len, HSMCI_CMDR_RSPTYP_48_BIT | + HSMCI_CMDR_TRCMD_START_DATA | HSMCI_CMDR_TRTYP_SINGLE)) + { + LOG_ERR("SIGLE_BLK_WRITE: %lx\n", HSMCI_SR); + return -1; + } + hsmci_readResp(&(sd->status), 1); + + LOG_INFOB(dump("SIGLE_BLK_WR", &(sd->status), 1);); + LOG_INFO("State[%d]\n", SD_GET_STATE(sd->status)); + + if (sd->status & SD_STATUS_READY) + { + hsmci_waitTransfer(); + LOG_INFOB(dump("BLK", buf, words);); + + return words; + } + + return -1; +} + + void sd_setHightSpeed(Sd *sd) { + (void)sd; hsmci_setSpeed(2100000, true); } diff --git a/bertos/drv/sd.h b/bertos/drv/sd.h index 813e65a7..3316a81c 100644 --- a/bertos/drv/sd.h +++ b/bertos/drv/sd.h @@ -153,6 +153,7 @@ int sd_setBusWidth(Sd *sd, size_t len); int sd_set_BlockLen(Sd *sd, size_t len); void sd_setHightSpeed(Sd *sd); int sd_readSingleBlock(Sd *sd, size_t index, uint32_t *buf, size_t words); +int sd_writeSingleBlock(Sd *sd, size_t index, uint32_t *buf, size_t words); INLINE int sd_setBus4bit(Sd *sd)