📄 fs_lib.c
字号:
/*----------------------------------------------------------------------------
* R T L - F l a s h F i l e S y s t e m
*----------------------------------------------------------------------------
* Name: FS_LIB.C
* Purpose: System Library Module
* Rev.: V3.22
*----------------------------------------------------------------------------
* This code is part of the RealView Run-Time Library.
* Copyright (c) 2004-2008 KEIL - An ARM Company. All rights reserved.
*---------------------------------------------------------------------------*/
#include "File_Config.h"
#include <string.h>
/*----------------------------------------------------------------------------
* Functions
*---------------------------------------------------------------------------*/
/*--------------------------- fn_cmp ----------------------------------------*/
BOOL fn_cmp (const S8 *sp, const S8 *fp) {
/* Compare flash filename string with provided filename. */
for ( ; *sp; sp++, fp++) {
if (*sp != *fp) {
return (__FALSE);
}
}
if (*fp != 0) {
return (__FALSE);
}
return (__TRUE);
} /* end of fn_cmp */
/*--------------------------- fs_strpos -------------------------------------*/
int fs_strpos (const S8 *sp, const S8 ch) {
/* Find a position of 'ch' in a string */
int i;
for (i = 0; *sp; sp++, i++) {
if (*sp == ch) {
return (i);
}
}
return (-1);
} /* end of fs_strpos */
/*--------------------------- fs_ReadData -----------------------------------*/
int fs_ReadData (U32 adr, U32 cnt, U8 *buf) {
/* Read Data from RAM memory to buffer. */
memcpy (buf, (void *)adr, cnt);
return (0);
} /* end of fs_ReadData */
/*--------------------------- fs_WriteData -----------------------------------*/
int fs_WriteData (U32 adr, U32 cnt, U8 *buf) {
/* Write Data from buffer to RAM memory. */
memcpy ((void *)adr, buf, cnt);
return (0);
} /* end of fs_WriteData */
/*--------------------------- fs_get_drive ----------------------------------*/
int fs_get_drive (const S8 *fn) {
/* Check if drive letter provided. */
if (*(fn+1) != ':') {
return (DRV_NONE);
}
switch (*fn) {
/* 'F:' - Flash device */
case 'F':
case 'f':
return (DRV_FLASH);
/* 'S:' - SPI Flash device. */
case 'S':
case 's':
return (DRV_SPI);
/* 'R:' - RAM device */
case 'R':
case 'r':
return (DRV_RAM);
/* 'M:' - SD Card device. */
case 'M':
case 'm':
return (DRV_MCARD);
}
return (DRV_NONE);
} /* end of fs_get_drive */
/*--------------------------- fs_find_iob -----------------------------------*/
int fs_find_iob (void) {
/* Find unused _iob[] structure. */
IOB *fcb;
U32 i,nfile = _NFILE;
for (i = 0, fcb = &_iob[0]; i < nfile; fcb++, i++) {
if (!(fcb->flags & (_IOREAD|_IOWRT))) {
/* Clear File Control Block, return '_iob' index. */
memset (fcb, 0, sizeof (struct iob));
return (i);
}
}
return (EOF);
} /* end of fs_find_iob */
/*--------------------------- fs_set_params ---------------------------------*/
BOOL fs_set_params (IOB *fcb) {
/* Set Flash/Ram drive Device parameters. */
switch (fcb->drive) {
case DRV_FLASH:
fcb->DevCfg = (DEVCONF *)&FlashDev[0];
fcb->InitVal = _BlockFREE;
fcb->NumSect = _FlashNumSect;
break;
case DRV_SPI:
fcb->DevCfg = (DEVCONF *)&SpiDev[0];
fcb->InitVal = _SpiBlFREE;
fcb->NumSect = _SpiNumSect;
break;
case DRV_RAM:
fcb->DevCfg = (DEVCONF *)&RamDev[0];
fcb->InitVal = 0x00000000;
fcb->NumSect = _RamNumSect;
break;
default:
return (__FALSE);
}
if (fcb->NumSect == 0) {
/* This device disabled from the configuration. */
return (__FALSE);
}
return (__TRUE);
} /* end of fs_set_params */
/*----------------------------------------------------------------------------
* end of file
*---------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -