Subversion Repositories Code-Repo

Rev

Blame | Last modification | View Log | RSS feed

/*-----------------------------------------------------------------------*/
/* Low level disk I/O module skeleton for Petit FatFs (C)ChaN, 2009      */
/*-----------------------------------------------------------------------*/

#include "diskio.h"
#include "mmc.h"


/*-----------------------------------------------------------------------*/
/* Initialize Disk Drive                                                 */
/*-----------------------------------------------------------------------*/

DSTATUS disk_initialize (void)
{
    int i;

    // Try the initialization sequence up to four times
    for (i = 0; i < 4; i++) {
        if (mmcInit() == MMC_SUCCESS)
            return STA_OK;
    }

    return STA_NOINIT;
}



/*-----------------------------------------------------------------------*/
/* Read Partial Sector                                                   */
/*-----------------------------------------------------------------------*/

DRESULT disk_readp (
    BYTE* dest,         /* Pointer to the destination object */
    DWORD sector,       /* Sector number (LBA) */
    WORD sofs,          /* Offset in the sector */
    WORD count          /* Byte count (bit15:destination) */
)
{
    DRESULT res;
    DWORD address = (sector * MMC_SECTOR_SIZE) + sofs;

    if (mmcReadBlock(address, count, dest) == MMC_SUCCESS) {
        res = RES_OK;
    } else {
        res = RES_ERROR;
    }

    return res;
}



/*-----------------------------------------------------------------------*/
/* Write Partial Sector                                                  */
/*-----------------------------------------------------------------------*/

//DRESULT disk_writep (
//  BYTE* buff,     /* Pointer to the data to be written, NULL:Initiate/Finalize write operation */
//  DWORD sc        /* Sector number (LBA) or Number of bytes to send */
//)
//{
//  DRESULT res;
//
//
//  if (!buff) {
//      if (sc) {
//
//          // Initiate write process
//
//      } else {
//
//          // Finalize write process
//
//      }
//  } else {
//
//      // Send data to the disk
//
//  }
//
//  return res;
//}