2009年3月21日 星期六

uc-os ii file system --about hardware mapping

FS__device_type ---- source insight can't index , why ??
FS__fsl_type 卻可以
先備份 ucfs_Source-0322.rar; 將 FS__device_type 拷貝於 FS__fsl_type 之下



記錄目的 : 軟體分層("pure algrithm for file system access" v.s "real hardware")

FS__pDevInfo
[idx].fs_ptr->fsl_fopen


& 一個簡易的操作系統下 -- 驅動程式如何編寫 (也不完全啦)??
應該說 file system 的資料結構......或說看到好多資料結構(於 linux 中) 內都帶有函數
(題外話 : C++ 函數封裝 ); 剛好 uc-os-ii FS 就有這樣的形式



// 原計畫由上層往下層找,但很像由下層找上去也不錯,看起來很像是由上往下找,但上面實際上十後面捕的 ---> 又重新編排,由下層往上層看,排版由上往下

// all project save in C:\test\ucfs_Source ;尚未歸檔於備份硬碟中

顏色管理 : 藍色 往下尋找的關鍵字, 紅色 為找到的結果

/*-------------------------------------------------*/
/*-------------------------------------------------*/
At91rm9200hdd.c (device\ide\hardware\at91rm9200):void AT91F_HDDOpen(void){
At91rm9200hdd.h (device\ide\hardware\at91rm9200):void AT91F_HDDOpen(void);
下列為出現 xx.h 內, **.c 內還有許多 intenal function
故 xx.h 才是開放給上層的


int AT91F_HDDRead(unsigned short *,int);
int AT91F_HDDWrite(unsigned short *,int);
int AT91F_HDDErase(int);
void AT91F_HDDOpen(void);
int AT91F_HDDSleep(void);
int AT91F_HDDRead_ID (unsigned short *);

/*-------------------------------------------------*/
// ide.c (device\ide\hardware\at91rm9200

//int FS__IDE_Init(FS_u32 Unit){
// AT91F_HDDOpen();
// return 0;
//}

//int FS__IDE_ReadSector(FS_u32 Unit,unsigned long Sector,unsigned char *pBuffer){
// AT91F_HDDRead((unsigned short *)pBuffer,Sector);
// return 0;
//}


//int FS__IDE_WriteSector(FS_u32 Unit,unsigned long Sector,unsigned char *pBuffer){
// AT91F_HDDWrite((unsigned short *)pBuffer,Sector);
// return 0;
//}

/*-------------------------------------------------*/
Ide_drv.c (device\ide): FS__IDE_Init(Unit);
_FS_IDE_DevStatus
_FS_IDE_DevIoCtl

/*-------------------------------------------------*/
Ide_drv.c (device\ide):static int _FS_IDE_DevIoCtl(FS_u32 Unit, FS_i32 Cmd, FS_i32 Aux, void *pBuffer)

const FS__device_type FS__idedevice_driver = {
"IDE device",
_FS_IDE_DevStatus,
_FS_IDE_DevRead,
_FS_IDE_DevWrite,
_FS_IDE_DevIoCtl
};

/*-------------------------------------------------*/
(key word seach : FS__idedevice_driver
Fs_info.c (api): extern const FS__device_type FS__idedevice_driver;
Fs_info.c (api): #define FS_DEVINFO_DEVIDE { "ide", &FS__fat_functable, &FS__idedevice_driver, FS_CACHEINFO_IDE_DRIVER 0 },

/*-------------------------------------------------*/
(key word search :FS_DEVINFO_DEVIDE)
Fs_info.c (api): #define FS_DEVINFO FS_DEVINFO_DEVSMC FS_DEVINFO_DEVMMC FS_DEVINFO_DEVIDE FS_DEVINFO_DEVFLASH FS_DEVINFO_DEVWINDRV FS_DEVINFO_DEVRAM

/*-------------------------------------------------*/
Fs_info.c (api):const FS__devinfo_type _FS__devinfo[] = { FS_DEVINFO };

_FS__devinfo -> can not find information to the other file
switch to FS_devinfo_type -->find FS_pDevinfo

/*-------------------------------------------------*/
Fs_int.h (api):extern const FS__devinfo_type *const FS__pDevInfo;
Fs_info.c (api):const FS__devinfo_type *const FS__pDevInfo = _FS__devinfo;

/*-------------------------------------------------*/
(keyword search : FS__pDevInfo
看樣子對應到上層了,因為許多檔案用到這個
Api_misc.c/Fat_dir.c / Fat_in.c / Fat_ioct.c /Fat_misc.c / Fat_open.c
Fat_out.c/Lb_misc.c

ex>FS_FILE *FS_FOpen(const char *pFileName, const char *pMode) {
FS_FARCHARPTR s;
FS_FILE *handle;
unsigned int i;
int idx;
int j;
int c;

/* Find correct FSL (device:unit:name) */
idx = FS__find_fsl(pFileName, &s);
if (idx < style="color: rgb(255, 0, 0);">FS__pDevInfo[idx].fs_ptr->fsl_fopen) {



/*-------------------------------------------------*
終於找到 main 了

Api_misc.c (api):* FS_FOpen
Api_misc.c (api):FS_FILE *FS_FOpen(const char *pFileName, const char *pMode) {
Fs_api.h (api): No open file bug when using FS_FOpen(name,"r+")
Fs_api.h (api):FS_FILE *FS_FOpen(const char *pFileName, const char *pMode);
Main.c (sample): myfile = FS_FOpen(name,"w");
Main.c (sample): myfile = FS_FOpen(name,"r");




// 補充說明 : 操作方法說明 FS__pDevInfo[idx].fs_ptr->fsl_fopen


--------------------------------簡易型式說明------------------------------
struct xxx
{
aaa
bbb
}

ex1>
struct xxx ccc;

if one access aaa/bbb
ccc.aaa / ccc.bbb //using "." dot to access

ex2>
struct xxx *ddd
if one access aaa/bbb
(*ddd).aaa/(*ddd)bbb ------ ddd -> aaa ; ddd -> bbb // using "->" to access
----------------------------正式說明---------------------------------
******FS__pDevInfo[idx].fs_ptr->fsl_fopen*******

typedef struct {
const char *const devname;
const FS__fsl_type *const fs_ptr;
const FS__device_type *const devdriver;
#if FS_USE_LB_READCACHE
FS__LB_CACHE *const pDevCacheInfo;
#endif /* FS_USE_LB_READCACHE */
const void *const data;
} FS__devinfo_type;



typedef struct {
FS_FARCHARPTR name;
FS_FILE * (*fsl_fopen)(const char *pFileName, const char *pMode, FS_FILE *pFile);
void (*fsl_fclose)(FS_FILE *pFile);
FS_size_t (*fsl_fread)(void *pData, FS_size_t Size, FS_size_t N, FS_FILE *pFile);
FS_size_t (*fsl_fwrite)(const void *pData, FS_size_t Size, FS_size_t N, FS_FILE *pFile);
long (*fsl_ftell)(FS_FILE *pFile);
int (*fsl_fseek)(FS_FILE *pFile, long int Offset, int Whence);
int (*fsl_ioctl)(int Idx, FS_u32 Id, FS_i32 Cmd, FS_i32 Aux, void *pBuffer);
#if FS_POSIX_DIR_SUPPORT
FS_DIR * (*fsl_opendir)(const char *pDirName, FS_DIR *pDir);
int (*fsl_closedir)(FS_DIR *pDir);
struct FS_DIRENT * (*fsl_readdir)(FS_DIR *pDir);
void (*fsl_rewinddir)(FS_DIR *pDir);
int (*fsl_mkdir)(const char *pDirName, int DevIndex, char Aux);
int (*fsl_rmdir)(const char *pDirName, int DevIndex, char Aux);
#endif /* FS_POSIX_DIR_SUPPORT */
} FS__fsl_type;
------------------------
FS__devinfo_type _FS__devinfo[] = { FS_DEVINFO };
宣告 裝置結構體"陣列";來表示存取的種類 (sd /mmc/ ide)
------------------------
Fs_int.h (api):extern const FS__devinfo_type *const FS__pDevInfo;
Fs_info.c (api):const FS__devinfo_type *const FS__pDevInfo = _FS__devinfo;
宣告 指針來存取上述 裝置結構體"陣列"

ps : C 語言中讓我困擾的地方 ?? 很像 C++ 有改了 const FS__devinfo_type *const FS__pDevInfo = _FS__devinfo; 正常應該這樣,一步應該分兩步 // step 1 : declare pointer variable // 宣告指針變數 FS__devinfo_type *const FS__pDevInfo; // step 2: assign array name without [] to pointer variable // 將陣列變數名(不帶[] ) 賦值給指針 FS__pDevInfo = _FS__devinfo;


------------------------
FS__pDevInfo[idx].fs_ptr->fsl_fopen
指針又以陣列形式存取內容


//--------------------------------------------
**** Fat_misc.c****
const FS__fsl_type FS__fat_functable = {
#if (FS_FAT_NOFAT32==0)
"FAT12/FAT16/FAT32",
#else
"FAT12/FAT16",
#endif /* FS_FAT_NOFAT32==0 */
FS__fat_fopen, /* open */
FS__fat_fclose, /* close */
FS__fat_fread, /* read */
FS__fat_fwrite, /* write */
0, /* tell */
0, /* seek */
FS__fat_ioctl, /* ioctl */
#if FS_POSIX_DIR_SUPPORT
FS__fat_opendir, /* opendir */
FS__fat_closedir, /* closedir */
FS__fat_readdir, /* readdir */
0, /* rewinddir */
FS__fat_MkRmDir, /* mkdir */
FS__fat_MkRmDir, /* rmdir */
#endif /* FS_POSIX_DIR_SUPPORT */
};

****fat_open.c*****
FS_FILE *FS__fat_fopen(const char *pFileName, const char *pMode, FS_FILE *pFile) {
xxx
FS__lb_ioctl(FS__pDevInfo[pFile->dev_index].devdriver, unit, FS_CMD_INC_BUSYCNT, 0, (void*)0); /* Turn on busy signal */
xxx


FS__pDevInfo[Idx].devdriver

沒有留言:

張貼留言