Code for autonomous ground vehicle, Data Bus, 3rd place winner in 2012 Sparkfun AVC.

Dependencies:   Watchdog mbed Schedule SimpleFilter LSM303DLM PinDetect DebounceIn Servo

SDFileSystem/FATFileSystem/Core/diskio.c

Committer:
shimniok
Date:
2012-06-20
Revision:
0:826c6171fc1b

File content as of revision 0:826c6171fc1b:

/*-----------------------------------------------------------------------*/
/* Low level disk I/O module skeleton for FatFs     (C)ChaN, 2007        */
/*-----------------------------------------------------------------------*/
/* This is a stub disk I/O module that acts as front end of the existing */
/* disk I/O modules and attach it to FatFs module with common interface. */
/*-----------------------------------------------------------------------*/

//Modified by Thomas Hamilton, Copyright 2010

#include "diskio.h"

DSTATUS disk_initialize(BYTE drv) 
{
    if (FATFileSystem::DriveArray[drv])
    {
        return (DSTATUS)FATFileSystem::DriveArray[drv]->disk_initialize();
    }
    else
    {
        return STA_NOINIT;
    }
}

DSTATUS disk_status(BYTE drv) 
{
    if (FATFileSystem::DriveArray[drv])
    {
        return (DSTATUS)FATFileSystem::DriveArray[drv]->disk_status();
    }
    else
    {
        return STA_NOINIT;
    }
}

DRESULT disk_read(BYTE drv, BYTE* buff, DWORD sector, BYTE count)
{
    if (FATFileSystem::DriveArray[drv])
    {
        return (DRESULT)FATFileSystem::DriveArray[drv]->disk_read((unsigned char*)buff,
            (unsigned long)sector, (unsigned char)count);
    }
    else
    {
        return RES_NOTRDY;
    }
}

#if _READONLY == 0
DRESULT disk_write(BYTE drv, const BYTE* buff, DWORD sector, BYTE count)
{
    if (FATFileSystem::DriveArray[drv])
    {
        return (DRESULT)FATFileSystem::DriveArray[drv]->disk_write((const unsigned char*)buff,
            (unsigned long)sector, (unsigned char)count);
    }
    else
    {
        return RES_NOTRDY;
    }
}
#endif

DRESULT disk_ioctl(BYTE drv, BYTE ctrl, void* buff)
{
    switch (ctrl)
    {
        case CTRL_SYNC:
            if (FATFileSystem::DriveArray[drv])
            {
                return (DRESULT)FATFileSystem::DriveArray[drv]->disk_sync();
            }
            else
            {
                return RES_NOTRDY;
            } 

        case GET_SECTOR_SIZE:
            if (FATFileSystem::DriveArray[drv])
            {
                WORD Result = FATFileSystem::DriveArray[drv]->disk_sector_size();
                if (Result > 0)
                {
                    *((WORD*)buff) = Result;
                    return RES_OK;
                }
                else
                {
                    return RES_ERROR;
                }
            }
            else
            {
                return RES_NOTRDY;
            }

        case GET_SECTOR_COUNT:
            if (FATFileSystem::DriveArray[drv])
            {
                DWORD Result = FATFileSystem::DriveArray[drv]->disk_sector_count();
                if (Result > 0)
                {
                    *((DWORD*)buff) = Result;
                    return RES_OK;
                }
                else
                {
                    return RES_ERROR;
                }
            }
            else
            {
                return RES_NOTRDY;
            }

        case GET_BLOCK_SIZE:
            if (FATFileSystem::DriveArray[drv])
            {
                DWORD Result = FATFileSystem::DriveArray[drv]->disk_block_size();
                if (Result > 0)
                {
                    *((DWORD*)buff) = Result;
                    return RES_OK;
                }
                else
                {
                    return RES_ERROR;
                }
            }
            else
            {
                return RES_NOTRDY;
            }

        default:
            return RES_PARERR;
    }
}