00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <stdio.h>
00011 #include <avr/io.h>
00012 #include <cio.h>
00013 #include "ff.h"
00014 #include "FatFSDev.h"
00015 #include "fcntl.h"
00016 #include "Xmmc.h"
00017
00018 static int DOpen(IOCB *pIOCB) __attribute__((section(".lowtext")));
00019 static int DClose(IOCB *pIOCB) __attribute__((section(".lowtext")));
00020 static int DGetC(IOCB *pIOCB) __attribute__((section(".lowtext")));
00021 static int DRead(IOCB *pIOCB,char *b, int n) __attribute__((section(".lowtext")));
00022 static int DPutC(IOCB *pIOCB,int c) __attribute__((section(".lowtext")));
00023 static int DWrite(IOCB *pIOCB,char *b, int n) __attribute__((section(".lowtext")));
00024 static int DStatus(IOCB *pIOCB,int m) __attribute__((section(".lowtext")));
00025 static int DXio(IOCB *pIOCB,int cmd,void *pP) __attribute__((section(".lowtext")));
00026 static int DInit(void) __attribute__((section(".lowtext")));
00027
00028 static H_JVEC DJump = {
00029 DOpen,
00030 DClose,
00031 DGetC,
00032 DRead,
00033 DPutC,
00034 DWrite,
00035 DStatus,
00036 DXio,
00037 DInit
00038 };
00039
00040 static FATFS *FSYS;
00041
00042 static int Dmode(int mode)
00043 {
00044 int retval = 0;
00045
00046 if(mode & FCNTL_RDONLY)
00047 retval |= FA_READ;
00048 if(mode & FCNTL_WRONLY)
00049 retval |= FA_WRITE;
00050 return retval;
00051 }
00052
00053 static int DOpen(IOCB *pIOCB)
00054 {
00055 FF_DCB *pD = malloc(sizeof(FF_DCB));
00056 pIOCB->p = pD;
00057 pD->pF = malloc(sizeof(FIL));
00058 pIOCB->dev_name++;
00059 pD->mode = Dmode(pIOCB->mode);
00060 return f_open(pD->pF,pIOCB->dev_name,pD->mode);
00061 }
00062
00063 static int DClose(IOCB *pIOCB)
00064 {
00065 f_close ((FIL *)pIOCB->p);
00066 free(pIOCB->p);
00067 return 0;
00068 }
00069
00070 static int DGetC(IOCB *pIOCB)
00071 {
00072 return 0;
00073 }
00074
00075 static int DRead(IOCB *pIOCB,char *b, int n)
00076 {
00077 unsigned nread;
00078
00079 f_read (((FF_DCB *)pIOCB->p)->pF,b,n,&nread);
00080 return (int)nread;
00081 }
00082
00083 static int DPutC(IOCB *pIOCB,int c)
00084 {
00085 return 0;
00086 }
00087
00088 static int DWrite(IOCB *pIOCB,char *b, int n)
00089 {
00090 return 0;
00091 }
00092
00093 static int DStatus(IOCB *pIOCB,int m)
00094 {
00095 return 0;
00096 }
00097
00098 static int DXio(IOCB *pIOCB,int cmd,void *pP)
00099 {
00100 return 0;
00101 }
00102
00103 static int DInit(void)
00104 {
00105 int retval = 0;
00106
00107 FSYS = (FATFS *)malloc(sizeof(FATFS));
00108 if(FSYS)
00109 {
00110 if(f_mount(1,FSYS))
00111 {
00112 free(FSYS);
00113 FSYS = 0;
00114 }
00115 }
00116 CioAddHandler("D",&DJump);
00117 return retval;
00118 }
00119
00120 void FatFSInit(void)
00121 {
00122
00123
00124
00125
00126
00127 DInit();
00128 }