MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / fsrw1_thread_entry

Function fsrw1_thread_entry

examples/test/fs_test.c:26–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24#define fsrw1_fn "/test1.dat"
25#define fsrw1_data_len 120 /* Less than 256 */
26static void fsrw1_thread_entry(void* parameter)
27{
28 int fd;
29 int index,length;
30 rt_uint32_t round;
31 rt_uint32_t tick_start,tick_end,read_speed,write_speed;
32
33 static rt_uint8_t write_data1[fsrw1_data_len];
34 static rt_uint8_t read_data1[fsrw1_data_len];
35
36 round = 1;
37
38 while(1)
39 {
40 if( stop_flag )
41 {
42 rt_kprintf("thread fsrw2 error,thread fsrw1 quit!\r\n");
43 fsrw1_thread = RT_NULL;
44 stop_flag = 0;
45 return;
46 }
47
48 /* creat file */
49 fd = open(fsrw1_fn, O_WRONLY | O_CREAT | O_TRUNC, 0);
50 if (fd < 0)
51 {
52 rt_kprintf("fsrw1 open file for write failed\n");
53 stop_flag = 1;
54 fsrw1_thread = RT_NULL;
55 return;
56 }
57
58 /* plan write data */
59 for (index = 0; index < fsrw1_data_len; index ++)
60 {
61 write_data1[index] = index;
62 }
63
64 /* write 8000 times */
65 tick_start = rt_tick_get();
66 for(index=0; index<8000; index++)
67 {
68 length = write(fd, write_data1, fsrw1_data_len);
69 if (length != fsrw1_data_len)
70 {
71 rt_kprintf("fsrw1 write data failed\n");
72 close(fd);
73 fsrw1_thread = RT_NULL;
74 stop_flag = 1;
75 return;
76 }
77 }
78 tick_end = rt_tick_get();
79 write_speed = fsrw1_data_len*8000UL*RT_TICK_PER_SECOND/(tick_end-tick_start);
80
81 /* close file */
82 close(fd);
83

Callers

nothing calls this directly

Calls 6

rt_kprintfFunction · 0.85
rt_tick_getFunction · 0.85
openFunction · 0.50
writeFunction · 0.50
closeFunction · 0.50
readFunction · 0.50

Tested by

no test coverage detected