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

Function fsrw2_thread_entry

examples/test/fs_test.c:134–238  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132#define fsrw2_fn "/test2.dat"
133#define fsrw2_data_len 180 /* Less than 256 */
134static void fsrw2_thread_entry(void* parameter)
135{
136 int fd;
137 int index,length;
138 rt_uint32_t round;
139 rt_uint32_t tick_start,tick_end,read_speed,write_speed;
140
141 static rt_uint8_t write_data2[fsrw2_data_len];
142 static rt_uint8_t read_data2[fsrw2_data_len];
143
144 round = 1;
145
146 while(1)
147 {
148 if( stop_flag )
149 {
150 rt_kprintf("thread fsrw1 error,thread fsrw2 quit!\r\n");
151 fsrw2_thread = RT_NULL;
152 stop_flag = 0;
153 return;
154 }
155
156 /* creat file */
157 fd = open(fsrw2_fn, O_WRONLY | O_CREAT | O_TRUNC, 0);
158 if (fd < 0)
159 {
160 rt_kprintf("fsrw2 open file for write failed\n");
161 stop_flag = 1;
162 fsrw2_thread = RT_NULL;
163 return;
164 }
165
166 /* plan write data */
167 for (index = 0; index < fsrw2_data_len; index ++)
168 {
169 write_data2[index] = index;
170 }
171
172 /* write 5000 times */
173 tick_start = rt_tick_get();
174 for(index=0; index<5000; index++)
175 {
176 length = write(fd, write_data2, fsrw2_data_len);
177 if (length != fsrw2_data_len)
178 {
179 rt_kprintf("fsrw2 write data failed\n");
180 close(fd);
181 stop_flag = 1;
182 fsrw2_thread = RT_NULL;
183 return;
184 }
185 }
186 tick_end = rt_tick_get();
187 write_speed = fsrw2_data_len*5000UL*RT_TICK_PER_SECOND/(tick_end-tick_start);
188
189 /* close file */
190 close(fd);
191

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