forked from xuos/xiuos
gpio test sample for edu-riscv64
This commit is contained in:
@@ -5,27 +5,58 @@
|
||||
#define MAX_READ_LENGTH 1000
|
||||
|
||||
// sd card here is loaded as "/"
|
||||
void TestSD(void)
|
||||
void TestFs(void)
|
||||
{
|
||||
//open the file in sdcard
|
||||
int fd = open(SD_FPATH,O_RDWR|O_CREAT);
|
||||
if(fd<0){
|
||||
printf("fs fd open error:%d\n",fd);
|
||||
return;
|
||||
}
|
||||
|
||||
char filewords[MAX_READ_LENGTH];
|
||||
memset(filewords,0,MAX_READ_LENGTH);
|
||||
const char *input_words = "these words are going to write in fs\n";
|
||||
|
||||
//read and write then close file
|
||||
read(fd,filewords,MAX_READ_LENGTH);
|
||||
int err_flag = read(fd,filewords,MAX_READ_LENGTH);
|
||||
if(err_flag<0){
|
||||
printf("read failed,error:%d\n",err_flag);
|
||||
return;
|
||||
}
|
||||
printf("read data is \n%s\n",filewords);
|
||||
const char *input_words = "these words are going to write in fs\n";
|
||||
write(fd,input_words,strlen(input_words));
|
||||
close(fd);
|
||||
|
||||
err_flag = write(fd,input_words,strlen(input_words));
|
||||
if(err_flag<0){
|
||||
printf("write failed,error:%d\n",err_flag);
|
||||
return;
|
||||
}
|
||||
err_flag = close(fd);
|
||||
if(err_flag<0){
|
||||
printf("close failed,error %d\n",err_flag);
|
||||
return ;
|
||||
}
|
||||
|
||||
//re-open the file and re-read the file
|
||||
fd = open(SD_FPATH,O_RDWR);
|
||||
read(fd,filewords,MAX_READ_LENGTH);
|
||||
if(fd<0){
|
||||
printf("fs fd open error:%d\n",fd);
|
||||
return;
|
||||
}
|
||||
err_flag = read(fd,filewords,MAX_READ_LENGTH);
|
||||
if(err_flag<0){
|
||||
printf("read failed,error:%d\n",err_flag);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("read data is \n%s\n",filewords);
|
||||
close(fd);
|
||||
err_flag = close(fd);
|
||||
if(err_flag<0){
|
||||
printf("close failed,error:%d\n",err_flag);
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
PRIV_SHELL_CMD_FUNCTION(TestSD, a sdcard test sample, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
PRIV_SHELL_CMD_FUNCTION(TestFs, a sd or usb filesystem test sample, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
Reference in New Issue
Block a user