mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-12-26 01:07:21 +00:00
[posix] POSIX standard implementation for PSE51 (#5384)
* [posix] POSIX standard implementation for PSE51 - add some posix's interfaces that we haven't before. - these PR have passed the interface definition test across gcc platfrom; - have tested base on qemu-a9 and stm32h750-art-pi. * [newlib] only enable POSIX.1-1990 * update projects
This commit is contained in:
committed by
GitHub
parent
417efc370f
commit
6369e89502
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-05-07 Meco Man first Version
|
||||
*/
|
||||
#ifndef __DELAY_H__
|
||||
#define __DELAY_H__
|
||||
|
||||
void msleep(unsigned int msecs);
|
||||
void ssleep(unsigned int seconds);
|
||||
void mdelay(unsigned long msecs);
|
||||
void udelay(unsigned long usecs);
|
||||
void ndelay(unsigned long nsecs);
|
||||
|
||||
#endif
|
||||
@@ -72,6 +72,7 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz);
|
||||
struct tm *gmtime_r(const time_t *timep, struct tm *r);
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_POSIX_CLOCK
|
||||
/* POSIX clock and timer */
|
||||
#define MILLISECOND_PER_SECOND 1000UL
|
||||
#define MICROSECOND_PER_SECOND 1000000UL
|
||||
@@ -101,7 +102,10 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r);
|
||||
int clock_getres (clockid_t clockid, struct timespec *res);
|
||||
int clock_gettime (clockid_t clockid, struct timespec *tp);
|
||||
int clock_settime (clockid_t clockid, const struct timespec *tp);
|
||||
int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, struct timespec *rmtp);
|
||||
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
|
||||
int rt_timespec_to_tick(const struct timespec *time);
|
||||
#endif /* RT_USING_POSIX_CLOCK */
|
||||
|
||||
/* timezone */
|
||||
void tz_set(int8_t tz);
|
||||
|
||||
@@ -486,6 +486,8 @@ RTM_EXPORT(settimeofday);
|
||||
RTM_EXPORT(difftime);
|
||||
RTM_EXPORT(strftime);
|
||||
|
||||
#ifdef RT_USING_POSIX_CLOCK
|
||||
#include <delay.h>
|
||||
#ifdef RT_USING_RTC
|
||||
static volatile struct timeval _timevalue;
|
||||
static int _rt_clock_time_system_init()
|
||||
@@ -612,6 +614,17 @@ int clock_gettime(clockid_t clockid, struct timespec *tp)
|
||||
}
|
||||
RTM_EXPORT(clock_gettime);
|
||||
|
||||
int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, struct timespec *rmtp)
|
||||
{
|
||||
if ((clockid != CLOCK_REALTIME) || (rqtp == RT_NULL))
|
||||
{
|
||||
rt_set_errno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return nanosleep(rqtp, rmtp);
|
||||
}
|
||||
|
||||
int clock_settime(clockid_t clockid, const struct timespec *tp)
|
||||
{
|
||||
#ifndef RT_USING_RTC
|
||||
@@ -655,6 +668,33 @@ int clock_settime(clockid_t clockid, const struct timespec *tp)
|
||||
}
|
||||
RTM_EXPORT(clock_settime);
|
||||
|
||||
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
|
||||
{
|
||||
uint32_t time_ms = rqtp->tv_sec * 1000;
|
||||
uint32_t time_us = rqtp->tv_nsec / 1000;
|
||||
|
||||
time_ms += time_us / 1000 ;
|
||||
time_us = time_us % 1000;
|
||||
|
||||
if (rt_thread_self() != RT_NULL)
|
||||
{
|
||||
rt_thread_mdelay(time_ms);
|
||||
}
|
||||
else /* scheduler has not run yet */
|
||||
{
|
||||
while(time_ms > 0)
|
||||
{
|
||||
udelay(1000u);
|
||||
time_ms -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
udelay(time_us);
|
||||
|
||||
return 0;
|
||||
}
|
||||
RTM_EXPORT(nanosleep);
|
||||
|
||||
int rt_timespec_to_tick(const struct timespec *time)
|
||||
{
|
||||
int tick;
|
||||
@@ -688,6 +728,8 @@ int rt_timespec_to_tick(const struct timespec *time)
|
||||
}
|
||||
RTM_EXPORT(rt_timespec_to_tick);
|
||||
|
||||
#endif /* RT_USING_POSIX_CLOCK */
|
||||
|
||||
/* timezone */
|
||||
#ifndef RT_LIBC_DEFAULT_TIMEZONE
|
||||
#define RT_LIBC_DEFAULT_TIMEZONE 8
|
||||
|
||||
Reference in New Issue
Block a user