-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiletest.c
159 lines (117 loc) · 2.33 KB
/
filetest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*********************************************************************
* Filename: spiflash.c
*
* Description: Used for file system test
*
*
* Author: wangzw <[email protected]>
* Created at: 2013-05-2 9:00:00
*
* Modify:
*
*
*
* Copyright (C) 2013 Yuettak Co.,Ltd
********************************************************************/
#include "filetest.h"
#include <dfs_init.h>
/* dfs filesystem:ELM filesystem init */
#include <dfs_elm.h>
/* dfs Filesystem APIs */
#include <dfs_fs.h>
#include "dfs_posix.h"
#define RING_BUFFER_LEN 20
const rt_uint8_t open_flie_cmd[] = "comopen";
const rt_uint8_t close_flie_cmd[] = "comclose";
const rt_uint8_t read_flie_cmd[] = "comread";
const rt_uint8_t remove_file_cmd[] = "commove";
struct ring_buffer
{
rt_uint8_t dat[RING_BUFFER_LEN];
rt_uint8_t head;
rt_uint8_t tail;
};
struct ring_buffer com2_ring_buffer;
int file_id = 0;
rt_bool_t get_buffer_data(rt_uint8_t *data)
{
if(com2_ring_buffer.head == com2_ring_buffer.tail)
{
return 0;
}
else
{
*data = com2_ring_buffer.dat[com2_ring_buffer.head++];
com2_ring_buffer.head %= RING_BUFFER_LEN;
}
return 1;
}
rt_bool_t com_cmd_flie_deal(rt_uint8_t* rec_data,const rt_uint8_t cmd[],rt_uint8_t *cnt)
{
rt_uint8_t* data = rec_data;
if(*data == cmd[*cnt])
{
data++;
(*cnt)++;
if(cmd[*cnt] == '\0')
{
data += *cnt;
*cnt = 0;
return 1;
}
}
else
{
*cnt = 0;
}
return 0;
}
void filesystem_test_thread(void *arg)
{
int file_id;
rt_uint8_t data[100];
while(1)
{
rt_thread_delay(500);
file_id = open("/photo/1.jpg",O_CREAT | O_RDWR,0);
read(file_id,data,100);
rt_kprintf("%s\n",data);
close(file_id);
}
}
void filesystem_test(void)
{
rt_thread_t id;
id = rt_thread_create("ftest",filesystem_test_thread,RT_NULL,1024*2,29,20);
if(id != RT_NULL)
{
rt_thread_startup(id);
}
}
#ifdef RT_USING_FINSH
#include <finsh.h>
FINSH_FUNCTION_EXPORT(unlink,unlink[path]);
void fileopen(const char *file, int flags)
{
int flag = 0;
if(flags & 0x01)
{
flag |= O_CREAT;
}
if(flags & 0x02)
{
flag |= O_RDWR;
}
if(flags & 0x04)
{
flag |= O_APPEND;
}
file_id = open(file,flag,0);
}
FINSH_FUNCTION_EXPORT(fileopen,fileopen[FileName ]);
void filecolse()
{
close(file_id);
}
FINSH_FUNCTION_EXPORT(filecolse,filecolse[ ]);
#endif