|
5 | 5 | * |
6 | 6 | * Change Logs: |
7 | 7 | * Date Author Notes |
| 8 | + * 2021-02-11 Meco Man remove _gettimeofday_r() and _times_r() |
8 | 9 | */ |
| 10 | + |
9 | 11 | #include <reent.h> |
10 | 12 | #include <sys/errno.h> |
11 | 13 | #include <sys/time.h> |
@@ -190,14 +192,6 @@ _stat_r(struct _reent *ptr, const char *file, struct stat *pstat) |
190 | 192 | #endif |
191 | 193 | } |
192 | 194 |
|
193 | | -_CLOCK_T_ |
194 | | -_times_r(struct _reent *ptr, struct tms *ptms) |
195 | | -{ |
196 | | - /* return "not supported" */ |
197 | | - ptr->_errno = ENOTSUP; |
198 | | - return -1; |
199 | | -} |
200 | | - |
201 | 195 | int |
202 | 196 | _unlink_r(struct _reent *ptr, const char *file) |
203 | 197 | { |
@@ -243,111 +237,6 @@ _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) |
243 | 237 | } |
244 | 238 | #endif |
245 | 239 |
|
246 | | -#ifdef RT_USING_PTHREADS |
247 | | - |
248 | | -#include <clock_time.h> |
249 | | -/* POSIX timer provides clock_gettime function */ |
250 | | -#include <time.h> |
251 | | -int |
252 | | -_gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp) |
253 | | -{ |
254 | | - struct timespec tp; |
255 | | - |
256 | | - if (clock_gettime(CLOCK_REALTIME, &tp) == 0) |
257 | | - { |
258 | | - if (__tp != RT_NULL) |
259 | | - { |
260 | | - __tp->tv_sec = tp.tv_sec; |
261 | | - __tp->tv_usec = tp.tv_nsec / 1000UL; |
262 | | - } |
263 | | - |
264 | | - return tp.tv_sec; |
265 | | - } |
266 | | - |
267 | | - /* return "not supported" */ |
268 | | - ptr->_errno = ENOTSUP; |
269 | | - return -1; |
270 | | -} |
271 | | - |
272 | | -#else |
273 | | - |
274 | | -#define MILLISECOND_PER_SECOND 1000UL |
275 | | -#define MICROSECOND_PER_SECOND 1000000UL |
276 | | -#define NANOSECOND_PER_SECOND 1000000000UL |
277 | | - |
278 | | -#define MILLISECOND_PER_TICK (MILLISECOND_PER_SECOND / RT_TICK_PER_SECOND) |
279 | | -#define MICROSECOND_PER_TICK (MICROSECOND_PER_SECOND / RT_TICK_PER_SECOND) |
280 | | -#define NANOSECOND_PER_TICK (NANOSECOND_PER_SECOND / RT_TICK_PER_SECOND) |
281 | | - |
282 | | -struct timeval _timevalue = {0}; |
283 | | -#ifdef RT_USING_DEVICE |
284 | | -static void libc_system_time_init(void) |
285 | | -{ |
286 | | - time_t time; |
287 | | - rt_tick_t tick; |
288 | | - rt_device_t device; |
289 | | - |
290 | | - time = 0; |
291 | | - device = rt_device_find("rtc"); |
292 | | - if (device != RT_NULL) |
293 | | - { |
294 | | - /* get realtime seconds */ |
295 | | - rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time); |
296 | | - } |
297 | | - |
298 | | - /* get tick */ |
299 | | - tick = rt_tick_get(); |
300 | | - |
301 | | - _timevalue.tv_usec = MICROSECOND_PER_SECOND - (tick%RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK; |
302 | | - _timevalue.tv_sec = time - tick/RT_TICK_PER_SECOND - 1; |
303 | | -} |
304 | | -#endif |
305 | | - |
306 | | -int libc_get_time(struct timespec *time) |
307 | | -{ |
308 | | - rt_tick_t tick; |
309 | | - static rt_bool_t inited = 0; |
310 | | - |
311 | | - RT_ASSERT(time != RT_NULL); |
312 | | - |
313 | | - /* initialize system time */ |
314 | | - if (inited == 0) |
315 | | - { |
316 | | - libc_system_time_init(); |
317 | | - inited = 1; |
318 | | - } |
319 | | - |
320 | | - /* get tick */ |
321 | | - tick = rt_tick_get(); |
322 | | - |
323 | | - time->tv_sec = _timevalue.tv_sec + tick / RT_TICK_PER_SECOND; |
324 | | - time->tv_nsec = (_timevalue.tv_usec + (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK) * 1000; |
325 | | - |
326 | | - return 0; |
327 | | -} |
328 | | - |
329 | | -int |
330 | | -_gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp) |
331 | | -{ |
332 | | - struct timespec tp; |
333 | | - |
334 | | - if (libc_get_time(&tp) == 0) |
335 | | - { |
336 | | - if (__tp != RT_NULL) |
337 | | - { |
338 | | - __tp->tv_sec = tp.tv_sec; |
339 | | - __tp->tv_usec = tp.tv_nsec / 1000UL; |
340 | | - } |
341 | | - |
342 | | - return tp.tv_sec; |
343 | | - } |
344 | | - |
345 | | - /* return "not supported" */ |
346 | | - ptr->_errno = ENOTSUP; |
347 | | - return -1; |
348 | | -} |
349 | | -#endif |
350 | | - |
351 | 240 | /* Memory routine */ |
352 | 241 | void * |
353 | 242 | _malloc_r (struct _reent *ptr, size_t size) |
@@ -453,3 +342,9 @@ int flock(int fd, int operation) |
453 | 342 | { |
454 | 343 | return 0; |
455 | 344 | } |
| 345 | + |
| 346 | +/* |
| 347 | +These functions will be implemented and replaced by the 'common/time.c' file |
| 348 | +int _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp); |
| 349 | +_CLOCK_T_ _times_r(struct _reent *ptr, struct tms *ptms); |
| 350 | +*/ |
0 commit comments