Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
AdRainty
rt-thread
提交
c3dab994
R
rt-thread
项目概览
AdRainty
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
c3dab994
编写于
7月 31, 2021
作者:
B
Bernard Xiong
提交者:
GitHub
7月 31, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4880 from mysterywolf/tz
[libc][time] 修复若干问题
上级
7de647c7
2589d245
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
81 addition
and
62 deletion
+81
-62
components/libc/compilers/common/sys/time.h
components/libc/compilers/common/sys/time.h
+21
-21
components/libc/compilers/common/time.c
components/libc/compilers/common/time.c
+56
-37
components/libc/pthreads/mqueue.c
components/libc/pthreads/mqueue.c
+1
-1
components/libc/pthreads/pthread_cond.c
components/libc/pthreads/pthread_cond.c
+1
-1
components/libc/pthreads/semaphore.c
components/libc/pthreads/semaphore.c
+1
-1
components/libc/signal/posix_signal.c
components/libc/signal/posix_signal.c
+1
-1
未找到文件。
components/libc/compilers/common/sys/time.h
浏览文件 @
c3dab994
...
...
@@ -19,6 +19,7 @@
extern
"C"
{
#endif
/* timezone */
#define DST_NONE 0
/* not on dst */
#define DST_USA 1
/* USA style dst */
#define DST_AUST 2
/* Australian style dst */
...
...
@@ -31,12 +32,21 @@ extern "C" {
#define DST_TUR 9
/* Turkey */
#define DST_AUSTALT 10
/* Australian style with shift in 1986 */
#ifndef _TIMEVAL_DEFINED
#define _TIMEVAL_DEFINED
struct
timezone
{
int
tz_minuteswest
;
/* minutes west of Greenwich */
int
tz_dsttime
;
/* type of dst correction */
};
void
rt_tz_set
(
rt_int8_t
tz
);
rt_int8_t
rt_tz_get
(
void
);
rt_int8_t
rt_tz_is_dst
(
void
);
/*
* Structure returned by gettimeofday(2) system call,
* and used in other calls.
*/
#ifndef _TIMEVAL_DEFINED
#define _TIMEVAL_DEFINED
#if !(defined(_WIN32))
struct
timeval
{
long
tv_sec
;
/* seconds */
...
...
@@ -45,18 +55,6 @@ struct timeval {
#endif
#endif
/* _TIMEVAL_DEFINED */
#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)
/*GCC*/
) && !(defined(__ICCARM__) && (__VER__ >= 8010001)) && !defined(_WIN32)
struct
timespec
{
time_t
tv_sec
;
/* seconds */
long
tv_nsec
;
/* and nanoseconds */
};
#endif
struct
timezone
{
int
tz_minuteswest
;
/* minutes west of Greenwich */
int
tz_dsttime
;
/* type of dst correction */
};
int
stime
(
const
time_t
*
t
);
time_t
timegm
(
struct
tm
*
const
t
);
int
gettimeofday
(
struct
timeval
*
tv
,
struct
timezone
*
tz
);
...
...
@@ -67,6 +65,14 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r);
#ifdef RT_USING_POSIX
#include <sys/types.h>
#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)
/*GCC*/
) && !(defined(__ICCARM__) && (__VER__ >= 8010001)) && !defined(_WIN32)
struct
timespec
{
time_t
tv_sec
;
/* seconds */
long
tv_nsec
;
/* and nanoseconds */
};
#endif
/* posix clock and timer */
#define MILLISECOND_PER_SECOND 1000UL
#define MICROSECOND_PER_SECOND 1000000UL
...
...
@@ -96,15 +102,9 @@ 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_time
_to_tick
(
const
struct
timespec
*
time
);
int
rt_timespec
_to_tick
(
const
struct
timespec
*
time
);
#endif
/* RT_USING_POSIX */
/* timezone APIs (Not standard LIBC APIs) */
void
rt_tz_set
(
rt_int8_t
tz
);
rt_int8_t
rt_tz_get
(
void
);
rt_int8_t
rt_tz_is_dst
(
void
);
#ifdef __cplusplus
}
#endif
...
...
components/libc/compilers/common/time.c
浏览文件 @
c3dab994
...
...
@@ -24,7 +24,7 @@
#include "sys/time.h"
#include <sys/errno.h>
#include <rtthread.h>
#include <rthw.h>
#ifdef RT_USING_DEVICE
#include <rtdevice.h>
#endif
...
...
@@ -465,38 +465,47 @@ RTM_EXPORT(difftime);
RTM_EXPORT
(
strftime
);
#ifdef RT_USING_POSIX
static
struct
timeval
_timevalue
;
static
int
clock_time_system_init
()
#ifdef RT_USING_RTC
static
volatile
struct
timeval
_timevalue
;
static
int
_rt_clock_time_system_init
()
{
time_t
time
;
register
rt_base_t
level
;
time_t
time
=
0
;
rt_tick_t
tick
;
rt_device_t
device
;
time
=
0
;
#ifdef RT_USING_RTC
device
=
rt_device_find
(
"rtc"
);
if
(
device
!=
RT_NULL
)
{
/* get realtime seconds */
rt_device_control
(
device
,
RT_DEVICE_CTRL_RTC_GET_TIME
,
&
time
);
if
(
rt_device_control
(
device
,
RT_DEVICE_CTRL_RTC_GET_TIME
,
&
time
)
==
RT_EOK
)
{
level
=
rt_hw_interrupt_disable
();
tick
=
rt_tick_get
();
/* get tick */
_timevalue
.
tv_usec
=
(
tick
%
RT_TICK_PER_SECOND
)
*
MICROSECOND_PER_TICK
;
_timevalue
.
tv_sec
=
time
-
tick
/
RT_TICK_PER_SECOND
-
1
;
rt_hw_interrupt_enable
(
level
);
return
0
;
}
}
#else
LOG_W
(
"Cannot find a RTC device to provide time!"
);
#endif
/* get tick */
tick
=
rt_tick_get
();
_timevalue
.
tv_usec
=
(
tick
%
RT_TICK_PER_SECOND
)
*
MICROSECOND_PER_TICK
;
_timevalue
.
tv_sec
=
time
-
tick
/
RT_TICK_PER_SECOND
-
1
;
level
=
rt_hw_interrupt_disable
();
_timevalue
.
tv_usec
=
0
;
_timevalue
.
tv_sec
=
0
;
rt_hw_interrupt_enable
(
level
);
return
0
;
return
-
1
;
}
INIT_COMPONENT_EXPORT
(
clock_time_system_init
);
INIT_COMPONENT_EXPORT
(
_rt_clock_time_system_init
);
#endif
/* RT_USING_RTC */
int
clock_getres
(
clockid_t
clockid
,
struct
timespec
*
res
)
{
#ifndef RT_USING_RTC
LOG_W
(
"Cannot find a RTC device to save time!"
);
return
-
1
;
#else
int
ret
=
0
;
if
(
res
==
RT_NULL
)
...
...
@@ -526,11 +535,16 @@ int clock_getres(clockid_t clockid, struct timespec *res)
}
return
ret
;
#endif
/* RT_USING_RTC */
}
RTM_EXPORT
(
clock_getres
);
int
clock_gettime
(
clockid_t
clockid
,
struct
timespec
*
tp
)
{
#ifndef RT_USING_RTC
LOG_W
(
"Cannot find a RTC device to save time!"
);
return
-
1
;
#else
int
ret
=
0
;
if
(
tp
==
RT_NULL
)
...
...
@@ -543,11 +557,14 @@ int clock_gettime(clockid_t clockid, struct timespec *tp)
{
case
CLOCK_REALTIME
:
{
/* get tick */
int
tick
=
rt_tick_get
()
;
int
tick
;
register
rt_base_t
level
;
level
=
rt_hw_interrupt_disable
();
tick
=
rt_tick_get
();
/* get tick */
tp
->
tv_sec
=
_timevalue
.
tv_sec
+
tick
/
RT_TICK_PER_SECOND
;
tp
->
tv_nsec
=
(
_timevalue
.
tv_usec
+
(
tick
%
RT_TICK_PER_SECOND
)
*
MICROSECOND_PER_TICK
)
*
1000
;
rt_hw_interrupt_enable
(
level
);
}
break
;
...
...
@@ -571,11 +588,17 @@ int clock_gettime(clockid_t clockid, struct timespec *tp)
}
return
ret
;
#endif
/* RT_USING_RTC */
}
RTM_EXPORT
(
clock_gettime
);
int
clock_settime
(
clockid_t
clockid
,
const
struct
timespec
*
tp
)
{
#ifndef RT_USING_RTC
LOG_W
(
"Cannot find a RTC device to save time!"
);
return
-
1
;
#else
register
rt_base_t
level
;
int
second
;
rt_tick_t
tick
;
rt_device_t
device
;
...
...
@@ -583,38 +606,36 @@ int clock_settime(clockid_t clockid, const struct timespec *tp)
if
((
clockid
!=
CLOCK_REALTIME
)
||
(
tp
==
RT_NULL
))
{
rt_set_errno
(
EINVAL
);
return
-
1
;
}
/* get second */
second
=
tp
->
tv_sec
;
/* get tick */
tick
=
rt_tick_get
();
level
=
rt_hw_interrupt_disable
();
tick
=
rt_tick_get
();
/* get tick */
/* update timevalue */
_timevalue
.
tv_usec
=
MICROSECOND_PER_SECOND
-
(
tick
%
RT_TICK_PER_SECOND
)
*
MICROSECOND_PER_TICK
;
_timevalue
.
tv_sec
=
second
-
tick
/
RT_TICK_PER_SECOND
-
1
;
rt_hw_interrupt_enable
(
level
);
#ifdef RT_USING_RTC
/* update for RTC device */
device
=
rt_device_find
(
"rtc"
);
if
(
device
!=
RT_NULL
)
{
/* set realtime seconds */
rt_device_control
(
device
,
RT_DEVICE_CTRL_RTC_SET_TIME
,
&
second
);
if
(
rt_device_control
(
device
,
RT_DEVICE_CTRL_RTC_SET_TIME
,
&
second
)
==
RT_EOK
)
{
return
0
;
}
}
else
#else
LOG_W
(
"Cannot find a RTC device to save time!"
);
#endif
return
-
1
;
return
0
;
return
-
1
;
#endif
/* RT_USING_RTC */
}
RTM_EXPORT
(
clock_settime
);
int
clock_time
_to_tick
(
const
struct
timespec
*
time
)
int
rt_timespec
_to_tick
(
const
struct
timespec
*
time
)
{
int
tick
;
int
nsecond
,
second
;
...
...
@@ -645,19 +666,17 @@ int clock_time_to_tick(const struct timespec *time)
return
tick
;
}
RTM_EXPORT
(
clock_time
_to_tick
);
RTM_EXPORT
(
rt_timespec
_to_tick
);
#endif
/* RT_USING_POSIX */
/* timezone
APIs (Not standard LIBC APIs)
*/
/* timezone */
#ifndef RT_LIBC_DEFAULT_TIMEZONE
#define RT_LIBC_DEFAULT_TIMEZONE 8
#endif
#include <rthw.h>
volatile
static
rt_int8_t
rt_current_timezone
=
RT_LIBC_DEFAULT_TIMEZONE
;
static
volatile
rt_int8_t
rt_current_timezone
=
RT_LIBC_DEFAULT_TIMEZONE
;
void
rt_tz_set
(
rt_int8_t
tz
)
{
...
...
components/libc/pthreads/mqueue.c
浏览文件 @
c3dab994
...
...
@@ -244,7 +244,7 @@ ssize_t mq_timedreceive(mqd_t mqdes,
return
-
1
;
}
tick
=
clock_time
_to_tick
(
abs_timeout
);
tick
=
rt_timespec
_to_tick
(
abs_timeout
);
result
=
rt_mq_recv
(
mqdes
->
mq
,
msg_ptr
,
msg_len
,
tick
);
if
(
result
==
RT_EOK
)
...
...
components/libc/pthreads/pthread_cond.c
浏览文件 @
c3dab994
...
...
@@ -222,7 +222,7 @@ int pthread_cond_timedwait(pthread_cond_t *cond,
int
timeout
;
rt_err_t
result
;
timeout
=
clock_time
_to_tick
(
abstime
);
timeout
=
rt_timespec
_to_tick
(
abstime
);
result
=
_pthread_cond_timedwait
(
cond
,
mutex
,
timeout
);
if
(
result
==
RT_EOK
)
return
0
;
...
...
components/libc/pthreads/semaphore.c
浏览文件 @
c3dab994
...
...
@@ -319,7 +319,7 @@ int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout)
return
EINVAL
;
/* calculate os tick */
tick
=
clock_time
_to_tick
(
abs_timeout
);
tick
=
rt_timespec
_to_tick
(
abs_timeout
);
result
=
rt_sem_take
(
sem
->
sem
,
tick
);
if
(
result
==
-
RT_ETIMEOUT
)
...
...
components/libc/signal/posix_signal.c
浏览文件 @
c3dab994
...
...
@@ -83,7 +83,7 @@ int sigtimedwait(const sigset_t *set, siginfo_t *info,
if
(
timeout
)
{
tick
=
clock_time
_to_tick
(
timeout
);
tick
=
rt_timespec
_to_tick
(
timeout
);
}
ret
=
rt_signal_wait
(
set
,
info
,
tick
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录