Changeset 154 for uKadecot/trunk/pfatfs


Ignore:
Timestamp:
Feb 2, 2016, 9:54:35 PM (8 years ago)
Author:
coas-nagasima
Message:

SDカードの中身を/~/でアクセスできるよう変更

Location:
uKadecot/trunk/pfatfs
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • uKadecot/trunk/pfatfs/diskio.c

    r108 r154  
    2121#define RamDisk         ((unsigned char *)0xfff00000)
    2222#else
    23 #include <windows.h>
    24 #include <tchar.h>
    25 #include <winioctl.h>
    26 
    2723unsigned char RamDisk[SZ_RAMDISK * 1024];
     24extern void win_disk_initialize(void *ramDisk, int size);
    2825#endif
    2926
     
    3431        DWORD wip;
    3532        DWORD n_sectors;
    36 } STAT;
     33} RD_STAT;
    3734
    3835static volatile
    39 STAT Stat[MAX_DRIVES];
     36RD_STAT Stat[MAX_DRIVES];
    4037
    4138static
     
    4340
    4441static
    45 int get_status(volatile STAT *stat) {
     42int get_status(volatile RD_STAT *stat) {
    4643        stat->sz_sector = SS_RAMDISK;
    4744        if(stat->sz_sector < _MIN_SS || stat->sz_sector > _MAX_SS) return 0;
     
    5451/* Initialize Disk Drive                                                 */
    5552/*-----------------------------------------------------------------------*/
    56 DSTATUS disk_initialize (void)
     53DSTATUS ramdisk_initialize (void)
    5754{
    5855        DSTATUS sta;
    5956#ifdef _MSC_VER
    60         HANDLE h;
    61         DWORD br;
    62 
    63         h = CreateFile(_T("..\\..\\..\\..\\uip\\apps\\webserver\\httpd-fs.bin"), GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
    64         if (h != INVALID_HANDLE_VALUE) {
    65                 ReadFile(h, RamDisk, sizeof(RamDisk), &br, 0);
    66                 CloseHandle(h);
    67         }
     57        win_disk_initialize(RamDisk, sizeof(RamDisk));
    6858#endif
    6959        get_status(&Stat[0]);
     
    7767/* Get Disk Status                                                       */
    7868/*-----------------------------------------------------------------------*/
    79 DSTATUS disk_get_status (void)
     69DSTATUS ramdisk_get_status (void)
    8070{
    8171        return Stat[0].status;
     
    8575/* Read Partial Sector                                                   */
    8676/*-----------------------------------------------------------------------*/
    87 DRESULT disk_readp (
     77DRESULT ramdisk_readp (
    8878        BYTE* buff,             /* Data read buffer */
    8979        DWORD sector,   /* Sector number (LBA) */
     
    118108/* Write Partial Sector                                                  */
    119109/*-----------------------------------------------------------------------*/
    120 DRESULT disk_writep (
     110DRESULT ramdisk_writep (
    121111        const BYTE* buff,       /* Pointer to the write data */
    122112        DWORD sc                        /* Sector number (LBA), Number of bytes to send */
  • uKadecot/trunk/pfatfs/diskio.h

    r108 r154  
    1919/* Results of Disk Functions */
    2020typedef enum {
    21         RES_OK = 0,             /* 0: Function succeeded */
    22         RES_ERROR,              /* 1: Disk error */
    23         RES_NOTRDY,             /* 2: Not ready */
    24         RES_PARERR              /* 3: Invalid parameter */
     21        RES_OK = 0,             /* 0: Successful */
     22        RES_ERROR,              /* 1: R/W Error */
     23        RES_WRPRT,              /* 2: Write Protected */
     24        RES_NOTRDY,             /* 3: Not Ready */
     25        RES_PARERR              /* 4: Invalid Parameter */
    2526} DRESULT;
    2627
     
    2930/* Prototypes for disk control functions */
    3031
    31 DSTATUS disk_initialize (void);
    32 DSTATUS disk_get_status (void);
    33 DRESULT disk_readp (BYTE* buff, DWORD sector, UINT offset, UINT count);
    34 DRESULT disk_writep (const BYTE* buff, DWORD sc);
     32DSTATUS ramdisk_initialize (void);
     33DSTATUS ramdisk_get_status (void);
     34DRESULT ramdisk_readp (BYTE* buff, DWORD sector, UINT offset, UINT count);
     35DRESULT ramdisk_writep (const BYTE* buff, DWORD sc);
    3536
    3637#define STA_NOINIT              0x01    /* Drive not initialized */
    3738#define STA_NODISK              0x02    /* No medium in the drive */
     39#define STA_PROTECT             0x04    /* Write protected */
    3840
     41/* Generic command (Used by FatFs) */
     42#define CTRL_SYNC                       0       /* Complete pending write process (needed at _FS_READONLY == 0) */
     43#define GET_SECTOR_COUNT        1       /* Get media size (needed at _USE_MKFS == 1) */
     44#define GET_SECTOR_SIZE         2       /* Get sector size (needed at _MAX_SS != _MIN_SS) */
     45#define GET_BLOCK_SIZE          3       /* Get erase block size (needed at _USE_MKFS == 1) */
     46#define CTRL_TRIM                       4       /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */
     47
     48/* MMC/SDC specific command (Not used by FatFs) */
     49#define MMC_GET_TYPE            50      /* Get card type */
     50#define MMC_GET_CSD                     51      /* Get CSD */
     51#define MMC_GET_CID                     52      /* Get CID */
     52#define MMC_GET_OCR                     53      /* Get OCR */
     53#define MMC_GET_SDSTAT          54      /* Get SD status */
     54
     55/* MMC card type flags (MMC_GET_TYPE) */
     56#define CT_MMC          0x01            /* MMC ver 3 */
     57#define CT_SD1          0x02            /* SD ver 1 */
     58#define CT_SD2          0x04            /* SD ver 2 */
     59#define CT_SDC          (CT_SD1|CT_SD2) /* SD */
     60#define CT_BLOCK        0x08            /* Block addressing */
    3961
    4062#ifdef __cplusplus
  • uKadecot/trunk/pfatfs/pff.c

    r108 r154  
    5858#define ABORT(err)      {fs->flag = 0; return err;}
    5959
    60 #if _USE_LFN
    61 static WCHAR LfnBuf[_MAX_LFN+1];
    62 #endif
    63 
    6460/*--------------------------------------------------------*/
    6561/* DBCS code ranges and SBCS extend char conversion table */
     
    509505                ofs = bc % 512; bc /= 512;
    510506                if (ofs != 511) {
    511                         if (disk_readp(buf, fs->fatbase + bc, ofs, 2)) break;
     507                        if (fs->disk_readp(buf, fs->fatbase + bc, ofs, 2)) break;
    512508                } else {
    513                         if (disk_readp(buf, fs->fatbase + bc, 511, 1)) break;
    514                         if (disk_readp(buf+1, fs->fatbase + bc + 1, 0, 1)) break;
     509                        if (fs->disk_readp(buf, fs->fatbase + bc, 511, 1)) break;
     510                        if (fs->disk_readp(buf+1, fs->fatbase + bc + 1, 0, 1)) break;
    515511                }
    516512                wc = LD_WORD(buf);
     
    520516#if _FS_FAT16
    521517        case FS_FAT16 :
    522                 if (disk_readp(buf, fs->fatbase + clst / 256, ((UINT)clst % 256) * 2, 2)) break;
     518                if (fs->disk_readp(buf, fs->fatbase + clst / 256, ((UINT)clst % 256) * 2, 2)) break;
    523519                return LD_WORD(buf);
    524520#endif
    525521#if _FS_FAT32
    526522        case FS_FAT32 :
    527                 if (disk_readp(buf, fs->fatbase + clst / 128, ((UINT)clst % 128) * 4, 4)) break;
     523                if (fs->disk_readp(buf, fs->fatbase + clst / 128, ((UINT)clst % 128) * 4, 4)) break;
    528524                return LD_DWORD(buf) & 0x0FFFFFFF;
    529525#endif
     
    673669        BYTE a, ord, sum;
    674670#endif
     671        FATFS *fs = dj->fs;
    675672
    676673        res = dir_rewind(dj);                   /* Rewind directory object */
     
    681678#endif
    682679        do {
    683                 res = disk_readp(dir, dj->sect, (dj->index % 16) * 32, 32)      /* Read an entry */
     680                res = fs->disk_readp(dir, dj->sect, (dj->index % 16) * 32, 32)  /* Read an entry */
    684681                        ? FR_DISK_ERR : FR_OK;
    685682                if (res != FR_OK) break;
     
    735732        BYTE ord = 0xFF, sum = 0xFF;
    736733#endif
     734        FATFS *fs = dj->fs;
    737735
    738736        res = FR_NO_FILE;
    739737        while (dj->sect) {
    740                 res = disk_readp(dir, dj->sect, (dj->index % 16) * 32, 32)      /* Read an entry */
     738                res = fs->disk_readp(dir, dj->sect, (dj->index % 16) * 32, 32)  /* Read an entry */
    741739                        ? FR_DISK_ERR : FR_OK;
    742740                if (res != FR_OK) break;
     
    10721070)
    10731071{
    1074         if (disk_readp(buf, sect, 510, 2))              /* Read the boot record */
     1072        if (fs->disk_readp(buf, sect, 510, 2))          /* Read the boot record */
    10751073                return 3;
    10761074        if (LD_WORD(buf) != 0xAA55)                             /* Check record signature */
    10771075                return 2;
    10781076
    1079         if (!_FS_32ONLY && !disk_readp(buf, sect, BS_FilSysType, 2) && LD_WORD(buf) == 0x4146)  /* Check FAT12/16 */
     1077        if (!_FS_32ONLY && !fs->disk_readp(buf, sect, BS_FilSysType, 2) && LD_WORD(buf) == 0x4146)      /* Check FAT12/16 */
    10801078                return 0;
    1081         if (_FS_FAT32 && !disk_readp(buf, sect, BS_FilSysType32, 2) && LD_WORD(buf) == 0x4146)  /* Check FAT32 */
     1079        if (_FS_FAT32 && !fs->disk_readp(buf, sect, BS_FilSysType32, 2) && LD_WORD(buf) == 0x4146)      /* Check FAT32 */
    10821080                return 0;
    10831081        return 1;
     
    11061104        DWORD bsect, fsize, tsect, mclst;
    11071105
    1108         if (disk_get_status() & STA_NOINIT)     /* Check if the drive is ready or not */
     1106        if (fs->disk_get_status() & STA_NOINIT) /* Check if the drive is ready or not */
    11091107                return FR_NOT_READY;
    11101108
     
    11141112        if (fmt == 1) {                                         /* Not an FAT boot record, it may be FDISK format */
    11151113                /* Check a partition listed in top of the partition table */
    1116                 if (disk_readp(buf, bsect, MBR_Table, 16)) {    /* 1st partition entry */
     1114                if (fs->disk_readp(buf, bsect, MBR_Table, 16)) {        /* 1st partition entry */
    11171115                        fmt = 3;
    11181116                } else {
     
    11271125
    11281126        /* Initialize the file system object */
    1129         if (disk_readp(buf, bsect, 13, sizeof (buf))) return FR_DISK_ERR;
     1127        if (fs->disk_readp(buf, bsect, 13, sizeof (buf))) return FR_DISK_ERR;
    11301128
    11311129        fsize = LD_WORD(buf+BPB_FATSz16-13);                            /* Number of sectors per FAT */
     
    11871185        dj.fn = sp;
    11881186#if _USE_LFN
    1189         dj.lfn = LfnBuf;
     1187        dj.lfn = fs->LfnBuf;
    11901188#endif
    11911189        res = follow_path(&dj, dir, path);      /* Follow the file path */
     
    12491247                rcnt = 512 - (UINT)fs->fptr % 512;                      /* Get partial sector data from sector buffer */
    12501248                if (rcnt > btr) rcnt = btr;
    1251                 dr = disk_readp(!buff ? 0 : rbuff, fs->dsect, (UINT)fs->fptr % 512, rcnt);
     1249                dr = fs->disk_readp(!buff ? 0 : rbuff, fs->dsect, (UINT)fs->fptr % 512, rcnt);
    12521250                if (dr) ABORT(FR_DISK_ERR);
    12531251                fs->fptr += rcnt; rbuff += rcnt;                        /* Update pointers and counters */
     
    12861284
    12871285        if (!btw) {             /* Finalize request */
    1288                 if ((fs->flag & FA__WIP) && disk_writep(0, 0)) ABORT(FR_DISK_ERR);
     1286                if ((fs->flag & FA__WIP) && fs->disk_writep(0, 0)) ABORT(FR_DISK_ERR);
    12891287                fs->flag &= ~FA__WIP;
    12901288                return FR_OK;
     
    13101308                        if (!sect) ABORT(FR_DISK_ERR);
    13111309                        fs->dsect = sect + cs;
    1312                         if (disk_writep(0, fs->dsect)) ABORT(FR_DISK_ERR);      /* Initiate a sector write operation */
     1310                        if (fs->disk_writep(0, fs->dsect)) ABORT(FR_DISK_ERR);  /* Initiate a sector write operation */
    13131311                        fs->flag |= FA__WIP;
    13141312                }
    13151313                wcnt = 512 - (UINT)fs->fptr % 512;                      /* Number of bytes to write to the sector */
    13161314                if (wcnt > btw) wcnt = btw;
    1317                 if (disk_writep(p, wcnt)) ABORT(FR_DISK_ERR);   /* Send data to the sector */
     1315                if (fs->disk_writep(p, wcnt)) ABORT(FR_DISK_ERR);       /* Send data to the sector */
    13181316                fs->fptr += wcnt; p += wcnt;                            /* Update pointers and counters */
    13191317                btw -= wcnt; *bw += wcnt;
    13201318                if ((UINT)fs->fptr % 512 == 0) {
    1321                         if (disk_writep(0, 0)) ABORT(FR_DISK_ERR);      /* Finalize the currtent secter write operation */
     1319                        if (fs->disk_writep(0, 0)) ABORT(FR_DISK_ERR);  /* Finalize the currtent secter write operation */
    13221320                        fs->flag &= ~FA__WIP;
    13231321                }
     
    14011399                dj->fn = sp;
    14021400#if _USE_LFN
    1403                 dj->lfn = LfnBuf;
     1401                dj->lfn = fs->LfnBuf;
    14041402#endif
    14051403                res = follow_path(dj, dir, path);               /* Follow the path to the directory */
  • uKadecot/trunk/pfatfs/pff.h

    r108 r154  
    2424#include "integer.h"
    2525#include "pffconf.h"
     26#include "diskio.h"
    2627
    2728#if _PFATFS != _PFFCONF
     
    3940
    4041typedef struct {
     42        DSTATUS (* disk_get_status)(void);
     43        DRESULT (* disk_readp)(BYTE* buff, DWORD sector, UINT offset, UINT count);
     44        DRESULT (* disk_writep)(const BYTE* buff, DWORD sc);
    4145        BYTE    fs_type;        /* FAT sub type */
    4246        BYTE    flag;           /* File status flags */
     
    5357        CLUST   curr_clust;     /* File current cluster */
    5458        DWORD   dsect;          /* File current data sector */
     59#if _USE_LFN
     60        WCHAR LfnBuf[_MAX_LFN + 1];
     61#endif
    5562} FATFS;
    5663
  • uKadecot/trunk/pfatfs/pffconf.h

    r108 r154  
    1414#define _USE_LSEEK      1       /* Enable pf_lseek() function */
    1515#define _USE_WRITE      1       /* Enable pf_write() function */
     16#define _USE_IOCTL      1       /* Enable pf_ioctl() function */
    1617
    1718#define _FS_FAT12       1       /* Enable FAT12 */
Note: See TracChangeset for help on using the changeset viewer.