►Disk related functions

The only file you need to modify is diskio.c, and the functions within it. This module is the interface for Chan’s library to your SD card. If the functions within this file are written as wrappers to your fundamental functions, Chan’s library will work without any problems.

The functions in this module are as follows: disk_initialize, disk_status, disk_read, disk_write, and disk_ioctl. Also note that the only feature within disk_ioctl that is used is CTRL_SYNC. These functions, along with all of the previous functions, will do the job.

DSTATUS disk_initialize( BYTE drv )
{
   /* Supports only single drive */
   if( drv != 0)
      return STA_NOINIT;
   
   /* if initialization succeeds... */
   if( !SD_Init() )
   {   
      /* Clear STA_NOINIT */
      Stat &= ~STA_NOINIT;
   } 
   
   /* return current status */
   return( Stat );
}

DSTATUS disk_status( BYTE drv	)
{
   /* Supports only single drive */
   if( drv != 0)
      return STA_NOINIT;

   /* return current status */
   return( Stat );
}

DRESULT disk_read ( BYTE drv, BYTE *buff, DWORD sector, BYTE count )
{
   /* Supports only single drive and must have a size of 1 sector */
   if( drv || !count || (count>
1) ) 
      return( RES_PARERR );

   /* if we haven't initialized the card yet... */
   if( Stat & STA_NOINIT ) 
      return( RES_NOTRDY );
   
   /* Single block read */
   if( SD_ReadSector( sector, buff ) )
      return( RES_ERROR );
   
   /* return successful result: OK */
   return( RES_OK );
}

#if _READONLY == 0 
DRESULT disk_write( BYTE drv, const BYTE *buff, DWORD sector, BYTE count )
{
   /* Supports only single drive and must have a size of 1 sector */
   if( drv || !count || (count>
1) ) 
      return( RES_PARERR );

   /* if we haven't initialized the card yet... */
   if( Stat & STA_NOINIT ) 
      return( RES_NOTRDY );
      
   /* Single block write */
   if( SD_WriteSector( sector, buff ) )
      return( RES_ERROR );
      
   /* return successful result: OK */
   return( RES_OK );
}
#endif // _READONLY

DRESULT disk_ioctl ( BYTE drv, BYTE ctrl, void *buff )
{
   DRESULT res;
   BYTE  *ptr = buff;

   /* Supports only single drive */
   if( drv != 0)
      return RES_PARERR;
   
   /* if we haven't initialized the card yet... */
   if( Stat & STA_NOINIT ) 
      return RES_NOTRDY;
   
   res = RES_ERROR;
   
   switch( ctrl ) 
   {
      /* Flush dirty buffer if present */
      case CTRL_SYNC :	
         SPI_EnableCS();
         if( SD_WaitForReady() == 0xFF )
            res = RES_OK;
         break;
   
      default:
         res = RES_PARERR;
         break;
   }
   
   SPI_DisableCS();
   SPI_Byte( 0xFF );
   return res;
}



Tutorial Index
Interface to Chan’s Library of functions SD Card Initialization
Target development platform Reading and Writing a single sector
Setting up the SPI port during startup.A51 Working with diskio.c
Global type definitions and variables Pulling it all together
Basic SPI function Index Page

Conversation

Thu May 13 2021, 07:18 PM
Rufus
Pretty section of content. I just stumbled upon your weblog and in accession capital to assert that I get actually enjoyed account your blog posts. Any way I will be subscribing to your augment and even I achievement you access consistently quickly. https://mkfinstitute.com Trisha Trisha
Wed May 12 2021, 01:23 PM
Jed Roan
Now you can promote your site all over the internet for FREE: http://www3.listofsitesthatacceptfreeads.club
Wed May 12 2021, 08:20 AM
Edgardo
If some one wants to be updated with most recent technologies afterward he must be visit this web page and be up to date every day. annual credit report https://creditscoresetf.com
Wed May 12 2021, 06:11 AM
Laurinda
Great website. A lot of useful information here. I'm sending it to some pals ans also sharing in delicious. And of course, thanks on your effort! annual credit report https://creditscorecheckn.com
Wed May 12 2021, 05:37 AM
Joann
Does your site have a contact page? I'm having problems locating it but, I'd like to shoot you an email. I've got some recommendations for your blog you might be interested in hearing. Either way, great website and I look forward to seeing it improve over time. get credit report https://freecreditreportww.com

Downloads

Comments

Mirza123
Thu Jun 25 2020, 03:46 PM
eunicelove124
Mon Jun 22 2020, 03:03 PM
cerouno
Tue Jun 16 2020, 05:10 PM
Marce
Sat Jun 13 2020, 09:43 PM
Davidthils
Thu May 21 2020, 12:44 PM
Jakeror
Thu May 21 2020, 01:28 AM
motorCar
Wed May 20 2020, 07:05 PM
Vordrync
Wed May 20 2020, 11:52 AM

Online

Guests: 110, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38215
Newest member: Mirza123