Add write block function.
authorasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Fri, 2 Sep 2011 16:16:34 +0000 (16:16 +0000)
committerasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Fri, 2 Sep 2011 16:16:34 +0000 (16:16 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@5013 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/drv/sd.c
bertos/drv/sd.h

index a16e729957df79e61dcd8f500848656a2af5df91..02ec965329646b549729b6ff4aa69b254b76935d 100644 (file)
@@ -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);
 }
 
index 813e65a7124c15416be948b25f15d1533cf285b3..3316a81c0a491f968d3499b4ab825fa66e11f7e4 100644 (file)
@@ -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)