?? start.c
字號:
/*
**********************************************************************
* Micrium, Inc.
* 949 Crestview Circle
* Weston, FL 33327-1848
*
* uC/FS
*
* (c) Copyright 2001 - 2003, Micrium, Inc.
* All rights reserved.
*
***********************************************************************
----------------------------------------------------------------------
File : Start.c
Purpose : Sample program for using the file system
---------------------------END-OF-HEADER------------------------------
*/
#include "stl_ucfs.h"
#include "fs_api.h"
#include "fs_fat.h"
#include <string.h>
#define FS_X_Log(x) printf(x)
/*********************************************************************
*
* Global variables
*
**********************************************************************
*/
static FS_FILE * _pFile;
static char _acBuffer[0x100];
static const char _sDefaultText[] = "現在寫入數據到你的磁盤.\n";
#if FS_USE_RAMDISK_DRIVER
static const char _sRAMText[] = "This text was written on your RAM disk.\n";
#endif
/*********************************************************************
*
* Local functions
*
**********************************************************************
*/
/*********************************************************************
*
* _WriteFile
*
* This routine demonstrates, how to create and write to a file
* using the file system.
*/
void _WriteFile(const char *pName, const char *pTxt) {
int x;
/* create file */
FS_X_Log("Writing file ");
FS_X_Log("\r\n");
_pFile = FS_FOpen(pName, "w");
if (_pFile) {
/* write to file */
x = FS_FWrite(pTxt,1, strlen(pTxt), _pFile);
/* all data written ? */
if (x != (int)strlen(pTxt)) {
/* check, why not all data was written */
x = FS_FError(_pFile);
printf("Not all bytes written");
}
/* close file */
FS_FClose(_pFile);
}
else {
printf("Unable to create file\n");
}
printf("Writed.\r\n");
}
/*********************************************************************
*
* _DumpFile
*
* This routine demonstrates, how to open and read from a file using
* the file system.
*/
void _DumpFile(const char *pName) {
int x;
unsigned char FileName[20];
unsigned char Count;
/* open file */
printf("please input file name for read:");
Count = 0;
while(1){
unsigned char key;
key = getchar();
if(key){
unsigned char string[2];
string[0] = key;
string[1] = 0;
putchar((char*)string);
if(key==0x0d){
break;
}
if((key<='z')&&(key>='!')){;
if(key==0x08){
if(Count>0)
Count -= 1;
}
FileName [Count++] = key;
}
}
}
_pFile = FS_FOpen((char*)FileName,"r");
printf("Contents of file ");
printf((char*)FileName);
FS_X_Log("\r\n");
if (_pFile) {
/* read until EOF has been reached */
do {
x = FS_FRead(_acBuffer, 1, sizeof(_acBuffer) - 1, _pFile);
_acBuffer[x]=0;
if (x) {
printf(_acBuffer);
}
} while (x);
/* check, if there is no more data, because of EOF */
x = FS_FError(_pFile);
if (x != FS_ERR_EOF) {
/* there was a problem during read operation */
printf("Error during read operation\n");
}
/* close file */
FS_FClose(_pFile);
}
else {
printf("Unable to open file");
}
printf("dummp finash.\r\n");
}
/***********************************************************/
/*名稱: UintToStr */
/*功能: 無符號數據轉換為字符串 */
/*參數: value:要轉換的數據,轉換后數據的緩沖地址 */
/***********************************************************/
void UintToStr(unsigned int value,char *p){
*(p+0) = value/10000 + '0';
*(p+1) = (value%10000)/1000 + '0';
*(p+2) = ((value%10000)%1000)/100 + '0';
*(p+3) = (((value%10000)%1000)%100)/10 + '0';
*(p+4) = (((value%10000)%1000)%100)%10 + '0';
*(p+5) = 0;
}
void _ShowDirectory(const char * pName) {
FS_DIR *pDir;
struct FS_DIRENT *pDirEnt;
printf("start show directory.\r\n");
pDir = FS_OpenDir(pName); /* Open root directory of default device */
if(pDir) {
do {
char acName[20];
FS_u8 Attr;
pDirEnt = FS_ReadDir(pDir);
//FS_DirEnt2Name(pDirEnt, acName);
//FS_DirEnt2Attr(pDirEnt, &Attr);
if ((void*)pDirEnt == NULL) {
break; /* No more files */
}
printf(pDirEnt->d_name);
printf(" ");
Attr = pDirEnt->FAT_DirAttr;
if(Attr & FS_ATTR_DIRECTORY) { printf("(Dir) ");}
else { printf(" ");};
if(Attr & FS_ATTR_ARCHIVE) { printf("A ");}
else { printf("_ ");};
if(Attr & FS_ATTR_READ_ONLY) { printf("R ");}
else { printf("_ ");};
if(Attr & FS_ATTR_HIDDEN) { printf("H ");}
else { printf("_ ");};
if(Attr & FS_ATTR_SYSTEM) { printf("S ");}
else { printf("_ ");};
UintToStr(pDir->size,acName);
printf(acName);
printf("\r\n");
} while (1);
FS_CloseDir(pDir);
} else {
printf("Unable to open directory\r\n");
}
printf("finashed show directory.\r\n");
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -