Skip to content

Commit ff9ef1a

Browse files
authored
Merge pull request #4331 from mysterywolf/syscall
[libc][newlib]remove _gettimeofday_r() and _times_r()
2 parents acda6bb + dbe1a9c commit ff9ef1a

File tree

2 files changed

+9
-131
lines changed

2 files changed

+9
-131
lines changed

components/libc/compilers/newlib/libc.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,17 @@
1010
#ifndef __RTT_LIBC_H__
1111
#define __RTT_LIBC_H__
1212

13-
#include <stdio.h>
14-
#include <stdint.h>
15-
#include <string.h>
16-
#include <sys/time.h>
17-
1813
#ifndef _EXFUN
19-
#define _EXFUN(name, proto) name proto
14+
#define _EXFUN(name, proto) name proto
2015
#endif
2116

22-
#define MILLISECOND_PER_SECOND 1000UL
23-
#define MICROSECOND_PER_SECOND 1000000UL
24-
#define NANOSECOND_PER_SECOND 1000000000UL
25-
26-
#define MILLISECOND_PER_TICK (MILLISECOND_PER_SECOND / RT_TICK_PER_SECOND)
27-
#define MICROSECOND_PER_TICK (MICROSECOND_PER_SECOND / RT_TICK_PER_SECOND)
28-
#define NANOSECOND_PER_TICK (NANOSECOND_PER_SECOND / RT_TICK_PER_SECOND)
29-
3017
#ifdef __cplusplus
3118
extern "C" {
3219
#endif
3320
int libc_system_init(void);
3421
int libc_stdio_set_console(const char* device_name, int mode);
3522
int libc_stdio_get_console(void);
3623

37-
/* some time related function */
38-
int libc_set_time(const struct timespec* time);
39-
int libc_get_time(struct timespec* time);
40-
int libc_time_to_tick(const struct timespec* time);
4124
#ifdef __cplusplus
4225
}
4326
#endif

components/libc/compilers/newlib/syscalls.c

Lines changed: 8 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
*
66
* Change Logs:
77
* Date Author Notes
8+
* 2021-02-11 Meco Man remove _gettimeofday_r() and _times_r()
89
*/
10+
911
#include <reent.h>
1012
#include <sys/errno.h>
1113
#include <sys/time.h>
@@ -190,14 +192,6 @@ _stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
190192
#endif
191193
}
192194

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-
201195
int
202196
_unlink_r(struct _reent *ptr, const char *file)
203197
{
@@ -243,111 +237,6 @@ _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
243237
}
244238
#endif
245239

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-
351240
/* Memory routine */
352241
void *
353242
_malloc_r (struct _reent *ptr, size_t size)
@@ -453,3 +342,9 @@ int flock(int fd, int operation)
453342
{
454343
return 0;
455344
}
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

Comments
 (0)