[Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/handhelds/tos/lib/SD SD_M.nc, 1.1, 1.2
steve ayer
ayer1 at users.sourceforge.net
Wed Oct 25 06:26:44 PDT 2006
Update of /cvsroot/tinyos/tinyos-1.x/contrib/handhelds/tos/lib/SD
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv11368
Modified Files:
SD_M.nc
Log Message:
mismatched readCardSize function since replacement with card size
estimation hack. now matches prototype in SD.nc interface.
Index: SD_M.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/handhelds/tos/lib/SD/SD_M.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** SD_M.nc 3 Aug 2006 19:16:50 -0000 1.1
--- SD_M.nc 25 Oct 2006 13:26:42 -0000 1.2
***************
*** 296,300 ****
}
-
command result_t SD.readSector(uint32_t sector, uint8_t * pBuffer) {
return call SD.readBlock(sector * 512, 512, pBuffer);
--- 296,299 ----
***************
*** 432,438 ****
}
// Read the Card Size from the CSD Register
// this command is unsupported on sdio-only, like sandisk micro sd cards
! command uint16_t SD.readCardSize(){
// Read contents of Card Specific Data (CSD)
--- 431,465 ----
}
+ /*
+ * feel our way out over the cliff of the card to estimate the size
+ * turns out cmd9 is not supported on sdio, as there's no csd register
+ */
+ uint32_t hackGetCardSize() {
+ uint32_t howbig = 0;
+ uint8_t b[512];
+ result_t failed;
+
+ /* we'll estimate based upon popular sizes of cards, e.g. 128mb, 256 mb, 512mb, 1gb, 2gb
+ * experimentally, we find that 512mb == ~990900 sectors, 1gb == ~1983000 sectors
+ * extrapolating down, we'll say that 247700 should be readable on a 128mb
+ * reading beyond that returns an error
+ */
+
+ failed = call SD.readSector(0, b);
+ failed = call SD.readSector(200000, b);
+ // if we can't get this far, we're toast anyway
+ if(!failed){
+ howbig = 247000;
+ while(!call SD.readSector(howbig, b)){
+ howbig = howbig * 2;
+ }
+ howbig = howbig / 2;
+ }
+ return howbig;
+ }
+
// Read the Card Size from the CSD Register
// this command is unsupported on sdio-only, like sandisk micro sd cards
! command uint32_t SD.readCardSize(){
// Read contents of Card Specific Data (CSD)
***************
*** 441,444 ****
--- 468,473 ----
uint8_t mmc_READ_BL_LEN, mmc_C_SIZE_MULT;
+ return hackGetCardSize();
+
CS_LOW ();
More information about the Tinyos-contrib-commits
mailing list