[Tinyos-contrib-commits] CVS: tinyos-1.x/contrib/handhelds/tos/lib/SD SD_M.nc, 1.3, 1.4

steve ayer ayer1 at users.sourceforge.net
Thu Mar 27 12:13:37 PDT 2008


Update of /cvsroot/tinyos/tinyos-1.x/contrib/handhelds/tos/lib/SD
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv13524

Modified Files:
	SD_M.nc 
Log Message:

added wrappers forceInit() -- calls init -- and deSelect() -- it calls
CS_HIGH() -- to enforce compliance with updated interface.  the
interface was changed to align with new driver SD_DMA_M.

read/writeSector were deprecated in favor of the sd-centric block
specifier that the other driver uses; the new calls are
read/writeBlock, and use the same arguments.


Index: SD_M.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/handhelds/tos/lib/SD/SD_M.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** SD_M.nc	22 Jan 2008 20:20:46 -0000	1.3
--- SD_M.nc	27 Mar 2008 19:13:35 -0000	1.4
***************
*** 147,150 ****
--- 147,151 ----
    command result_t StdControl.stop(){
      TOSH_SET_SW_SD_PWR_N_PIN();    // powers down module
+     // tbd    TOSH_CLR_SD_CS_N_PIN();
  
      call DockInterrupt.disable();
***************
*** 273,293 ****
    }
  
-   command result_t SD.init(){
-     register uint8_t i;
-     uint8_t r;
- 
-     initSPI();
- 
-     CS_HIGH();
- 
-     for(i = 0; i < 10; i++)
-       spiSendByte(0xff);
-     
-     if((r = call SD.setIdle()) == MMC_SUCCESS)
-       initialization = TRUE;
- 
-     return r;
-   }
- 
    command result_t SD.setIdle(){
      char response;
--- 274,277 ----
***************
*** 314,322 ****
    }
  
    // we don't have pin for this one yet; it uses cd pin, which we don't have wired in mock-up
    //  command result_t detect();
  
    // change block length to 2^len bytes; default is 512
!   command result_t SD.setBlockLength (const uint16_t len) {
      CS_LOW ();
  
--- 298,335 ----
    }
  
+   command void SD.deSelect(){
+     CS_HIGH();
+   }
+ 
+   /* 
+    * this is here to comply with a merged SD interface between 
+    * someone else's driver using dma and this one
+    */
+   async command result_t SD.forceInit(){
+     return call SD.init();
+   }
+ 
+   command result_t SD.init(){
+     register uint8_t i;
+     uint8_t r;
+ 
+     initSPI();
+ 
+     CS_HIGH();
+ 
+     for(i = 0; i < 10; i++)
+       spiSendByte(0xff);
+     
+     if((r = call SD.setIdle()) == MMC_SUCCESS)
+       initialization = TRUE;
+ 
+     return r;
+   }
+ 
    // we don't have pin for this one yet; it uses cd pin, which we don't have wired in mock-up
    //  command result_t detect();
  
    // change block length to 2^len bytes; default is 512
!   result_t setBlockLength (const uint16_t len) {
      CS_LOW ();
  
***************
*** 338,361 ****
    }
      
!   command result_t SD.readSector(uint32_t sector, uint8_t * pBuffer) {
!     /*
!      * need to test dock pin for some platforms
!      * on others this will be attached to a pullup
!      */
!     if(!TOSH_READ_DOCK_N_PIN())
!       return MMC_INIT_ERROR;
! 
!     return call SD.readBlock(sector * 512, 512, pBuffer);
!   }
! 
!   // see macro in module for writing to a sector instead of an address
!   command result_t SD.readBlock(const uint32_t address, const uint16_t count, uint8_t * buffer){
      register uint16_t i = 0;
      uint8_t rvalue = MMC_RESPONSE_ERROR;
! 
      // Set the block length to read
!     if(call SD.setBlockLength(count) == MMC_SUCCESS){   // block length can be set
        CS_LOW ();
! 
        sendCmd(MMC_READ_SINGLE_BLOCK, address, 0xff);
        // Send 8 Clock pulses of delay, check if the MMC acknowledged the read block command
--- 351,367 ----
    }
      
!   /* 
!    * renamed to clear the way for renaming what was readSector -- which called this -- 
!    * to be renamed readBlock.  --sma
!    */
!   
!   result_t read_block(const uint32_t address, const uint16_t count, uint8_t * buffer){
      register uint16_t i = 0;
      uint8_t rvalue = MMC_RESPONSE_ERROR;
!     
      // Set the block length to read
!     if(setBlockLength(count) == MMC_SUCCESS){   // block length can be set
        CS_LOW ();
!       
        sendCmd(MMC_READ_SINGLE_BLOCK, address, 0xff);
        // Send 8 Clock pulses of delay, check if the MMC acknowledged the read block command
***************
*** 365,373 ****
  	// now look for the data token to signify the start of the data
  	if(getXXResponse(MMC_START_DATA_BLOCK_TOKEN) == MMC_START_DATA_BLOCK_TOKEN){
! 
  	  // clock the actual data transfer and receive the bytes; spi_read automatically finds the Data Block
  	  for (i = 0; i < count; i++)
  	    buffer[i] = spiSendByte(0xff);   // is executed with card inserted
! 
  	  // get CRC bytes (not really needed by us, but required by MMC)
  	  spiSendByte(0xff);
--- 371,379 ----
  	// now look for the data token to signify the start of the data
  	if(getXXResponse(MMC_START_DATA_BLOCK_TOKEN) == MMC_START_DATA_BLOCK_TOKEN){
! 	  
  	  // clock the actual data transfer and receive the bytes; spi_read automatically finds the Data Block
  	  for (i = 0; i < count; i++)
  	    buffer[i] = spiSendByte(0xff);   // is executed with card inserted
! 	  
  	  // get CRC bytes (not really needed by us, but required by MMC)
  	  spiSendByte(0xff);
***************
*** 388,416 ****
        rvalue = MMC_BLOCK_SET_ERROR;           // 1
      }
! 
      CS_HIGH ();
      spiSendByte(0xff);
! 
      return rvalue;
    }
  
!   command result_t SD.writeSector(uint32_t sector, uint8_t * pBuffer){
!     /*
!      * need to test dock pin for some platforms
!      * on others this will be attached to a pullup
!      */
      if(!TOSH_READ_DOCK_N_PIN())
        return MMC_INIT_ERROR;
  
!     return call SD.writeBlock(sector * 512, 512, pBuffer);
    }
  
! 
!   command result_t SD.writeBlock(const uint32_t address, const uint16_t count, uint8_t * buffer){
      register uint16_t i;
      uint8_t rvalue = MMC_RESPONSE_ERROR;         // MMC_SUCCESS;
  
      // Set the block length to write
!     if(call SD.setBlockLength (count) == MMC_SUCCESS){   // block length could be set
        //      call Leds.yellowOn();
        CS_LOW ();
--- 394,421 ----
        rvalue = MMC_BLOCK_SET_ERROR;           // 1
      }
!     
      CS_HIGH ();
      spiSendByte(0xff);
!     
      return rvalue;
    }
  
!   /*
!    * need to test dock pin for some platforms
!    * on others this will be attached to a pullup
!    */
!   command result_t SD.readBlock(const uint32_t sector, uint8_t * buffer) {
      if(!TOSH_READ_DOCK_N_PIN())
        return MMC_INIT_ERROR;
  
!     return read_block(sector * 512, 512, buffer);
    }
  
!   result_t write_block(const uint32_t address, const uint16_t count, uint8_t * buffer){
      register uint16_t i;
      uint8_t rvalue = MMC_RESPONSE_ERROR;         // MMC_SUCCESS;
  
      // Set the block length to write
!     if(setBlockLength (count) == MMC_SUCCESS){   // block length could be set
        //      call Leds.yellowOn();
        CS_LOW ();
***************
*** 454,461 ****
  
    // register read of length len into buffer
!   command result_t SD.readRegister(const uint8_t reg, const uint8_t len, uint8_t * buffer){
      uint8_t uc, rvalue = MMC_TIMEOUT_ERROR;
  
!     if((call SD.setBlockLength (len)) == MMC_SUCCESS){
        CS_LOW ();
        // CRC not used: 0xff as last byte
--- 459,466 ----
  
    // register read of length len into buffer
!   result_t readRegister(const uint8_t reg, const uint8_t len, uint8_t * buffer){
      uint8_t uc, rvalue = MMC_TIMEOUT_ERROR;
  
!     if(setBlockLength (len) == MMC_SUCCESS){
        CS_LOW ();
        // CRC not used: 0xff as last byte
***************
*** 487,490 ****
--- 492,506 ----
    } 
  
+   command result_t SD.writeBlock(const uint32_t sector, uint8_t * buffer){
+     /*
+      * need to test dock pin for some platforms
+      * on others this will be attached to a pullup
+      */
+     if(!TOSH_READ_DOCK_N_PIN())
+       return MMC_INIT_ERROR;
+ 
+     return write_block(sector * 512, 512, buffer);
+   }
+ 
    /*
     * feel our way out over the cliff of the card to estimate the size
***************
*** 502,511 ****
       */
  
!     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;
        }
--- 518,527 ----
       */
  
!     failed = call SD.readBlock(0, b);
!     failed = call SD.readBlock(200000, b);
      // if we can't get this far, we're toast anyway
      if(!failed){
        howbig = 247000;
!       while(!call SD.readBlock(howbig, b)){
  	howbig = howbig * 2;
        }



More information about the Tinyos-contrib-commits mailing list