summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorchen zx <[email protected]>2021-08-06 17:05:50 +0800
committerGitHub <[email protected]>2021-08-06 17:05:50 +0800
commitb104bbc4f9d978209e898a6dfced53248e27e3d7 (patch)
treec6852a2c6500e7d7e2902d8a63eac4e1774ae50a /components
parenteb29bb5318b2d4b0a3ff48ed906b72c074bcc17d (diff)
parent054f6db3e651cb6e7340913e969f5656626b9e9a (diff)
Merge branch 'RT-Thread:master' into master
Diffstat (limited to 'components')
-rw-r--r--components/dfs/include/dfs_select.h2
-rw-r--r--components/drivers/include/drivers/mmcsd_core.h1
-rw-r--r--components/drivers/include/drivers/rtc.h34
-rw-r--r--components/drivers/include/drivers/rtc_core.h45
-rw-r--r--components/drivers/include/ipc/workqueue.h5
-rw-r--r--components/drivers/rtc/SConscript2
-rw-r--r--components/drivers/rtc/rtc.c132
-rw-r--r--components/drivers/rtc/rtc_core.c123
-rw-r--r--components/drivers/sdio/block_dev.c12
-rw-r--r--components/drivers/src/ringbuffer.c4
-rw-r--r--components/drivers/src/workqueue.c6
-rw-r--r--components/libc/Kconfig4
-rw-r--r--components/libc/aio/posix_aio.c6
-rw-r--r--components/libc/aio/posix_aio.h4
-rw-r--r--components/libc/compilers/common/none-gcc/sys/errno.h4
-rw-r--r--components/libc/compilers/common/none-gcc/sys/stat.h5
-rw-r--r--components/libc/compilers/common/none-gcc/sys/types.h4
-rw-r--r--components/libc/compilers/common/none-gcc/sys/unistd.h4
-rw-r--r--components/libc/compilers/common/sys/select.h49
-rw-r--r--components/libc/compilers/common/sys/signal.h194
-rw-r--r--components/libc/compilers/common/sys/time.h37
-rw-r--r--components/libc/compilers/common/time.c126
-rw-r--r--components/libc/pthreads/mqueue.c3
-rw-r--r--components/libc/pthreads/pthread_cond.c2
-rw-r--r--components/libc/pthreads/semaphore.c2
-rw-r--r--components/libc/signal/posix_signal.c7
-rw-r--r--components/libc/signal/posix_signal.h1
-rw-r--r--components/net/at/at_socket/at_socket.c17
-rw-r--r--components/net/at/src/at_client.c20
-rw-r--r--components/net/lwip-1.4.1/src/lwipopts.h7
-rw-r--r--components/net/lwip-1.4.1/src/netif/ethernetif.c8
-rw-r--r--components/net/lwip-2.0.2/src/lwipopts.h11
-rw-r--r--components/net/lwip-2.0.2/src/netif/ethernetif.c8
-rw-r--r--components/net/lwip-2.0.3/src/lwipopts.h11
-rw-r--r--components/net/lwip-2.0.3/src/netif/ethernetif.c8
-rw-r--r--components/net/lwip-2.1.2/src/lwipopts.h11
-rw-r--r--components/net/lwip-2.1.2/src/netif/ethernetif.c8
-rw-r--r--components/net/sal_socket/include/socket/netdb.h2
38 files changed, 598 insertions, 331 deletions
diff --git a/components/dfs/include/dfs_select.h b/components/dfs/include/dfs_select.h
index 458691df20..e0572c5059 100644
--- a/components/dfs/include/dfs_select.h
+++ b/components/dfs/include/dfs_select.h
@@ -10,7 +10,7 @@
#ifndef DFS_SELECT_H__
#define DFS_SELECT_H__
-#include <libc/libc_fdset.h>
+#include <sys/select.h>
#ifdef __cplusplus
extern "C" {
diff --git a/components/drivers/include/drivers/mmcsd_core.h b/components/drivers/include/drivers/mmcsd_core.h
index 11b1386b23..51263d35f2 100644
--- a/components/drivers/include/drivers/mmcsd_core.h
+++ b/components/drivers/include/drivers/mmcsd_core.h
@@ -234,7 +234,6 @@ struct rt_mmcsd_host *mmcsd_alloc_host(void);
void mmcsd_free_host(struct rt_mmcsd_host *host);
int rt_mmcsd_core_init(void);
-int rt_mmcsd_blk_init(void);
rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card);
void rt_mmcsd_blk_remove(struct rt_mmcsd_card *card);
diff --git a/components/drivers/include/drivers/rtc.h b/components/drivers/include/drivers/rtc.h
index 9eddf801b7..0bafbad7ad 100644
--- a/components/drivers/include/drivers/rtc.h
+++ b/components/drivers/include/drivers/rtc.h
@@ -6,13 +6,43 @@
* Change Logs:
* Date Author Notes
* 2012-10-10 aozima first version.
+ * 2021-06-11 iysheng implement RTC framework V2.0
+ * 2021-07-30 Meco Man move rtc_core.h to rtc.h
*/
#ifndef __RTC_H__
#define __RTC_H__
-#include <rtconfig.h>
-#include <drivers/rtc_core.h>
+#include <rtdef.h>
+
+#define RT_DEVICE_CTRL_RTC_GET_TIME 0x10 /**< get second time */
+#define RT_DEVICE_CTRL_RTC_SET_TIME 0x11 /**< set second time */
+#define RT_DEVICE_CTRL_RTC_GET_TIME_US 0x12 /**< get microsecond time */
+#define RT_DEVICE_CTRL_RTC_SET_TIME_US 0x13 /**< set microsecond time */
+#define RT_DEVICE_CTRL_RTC_GET_ALARM 0x14 /**< get alarm */
+#define RT_DEVICE_CTRL_RTC_SET_ALARM 0x15 /**< set alarm */
+
+struct rt_rtc_ops
+{
+ rt_err_t (*init)(void);
+ rt_err_t (*get_secs)(void *arg);
+ rt_err_t (*set_secs)(void *arg);
+ rt_err_t (*get_alarm)(void *arg);
+ rt_err_t (*set_alarm)(void *arg);
+ rt_err_t (*get_usecs)(void *arg);
+ rt_err_t (*set_usecs)(void *arg);
+};
+
+typedef struct rt_rtc_device
+{
+ struct rt_device parent;
+ const struct rt_rtc_ops *ops;
+} rt_rtc_dev_t;
+
+rt_err_t rt_hw_rtc_register(rt_rtc_dev_t *rtc,
+ const char *name,
+ rt_uint32_t flag,
+ void *data);
rt_err_t set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day);
rt_err_t set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second);
diff --git a/components/drivers/include/drivers/rtc_core.h b/components/drivers/include/drivers/rtc_core.h
deleted file mode 100644
index f0c7b64e94..0000000000
--- a/components/drivers/include/drivers/rtc_core.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2021-06-11 iysheng first version.
- */
-
-#ifndef __RTC_CORE_H__
-#define __RTC_CORE_H__
-
-#include <rtthread.h>
-
-#define RT_DEVICE_CTRL_RTC_GET_TIME 0x10 /**< get second time */
-#define RT_DEVICE_CTRL_RTC_SET_TIME 0x11 /**< set second time */
-#define RT_DEVICE_CTRL_RTC_GET_TIME_US 0x12 /**< get microsecond time */
-#define RT_DEVICE_CTRL_RTC_SET_TIME_US 0x13 /**< set microsecond time */
-#define RT_DEVICE_CTRL_RTC_GET_ALARM 0x14 /**< get alarm */
-#define RT_DEVICE_CTRL_RTC_SET_ALARM 0x15 /**< set alarm */
-
-struct rt_rtc_ops
-{
- rt_err_t (*init)(void);
- rt_err_t (*get_secs)(void *arg);
- rt_err_t (*set_secs)(void *arg);
- rt_err_t (*get_alarm)(void *arg);
- rt_err_t (*set_alarm)(void *arg);
- rt_err_t (*get_usecs)(void *arg);
- rt_err_t (*set_usecs)(void *arg);
-};
-
-typedef struct rt_rtc_device
-{
- struct rt_device parent;
- const struct rt_rtc_ops *ops;
-} rt_rtc_dev_t;
-
-rt_err_t rt_rtc_dev_register(rt_rtc_dev_t *rtc,
- const char *name,
- rt_uint32_t flag,
- void *data);
-
-#endif /* __RTC_CORE_H__ */
diff --git a/components/drivers/include/ipc/workqueue.h b/components/drivers/include/ipc/workqueue.h
index 03d38b2f4d..a156145641 100644
--- a/components/drivers/include/ipc/workqueue.h
+++ b/components/drivers/include/ipc/workqueue.h
@@ -69,7 +69,7 @@ rt_err_t rt_workqueue_critical_work(struct rt_workqueue *queue, struct rt_work *
#ifdef RT_USING_SYSTEM_WORKQUEUE
rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t time);
rt_err_t rt_work_cancel(struct rt_work *work);
-#endif
+#endif /* RT_USING_SYSTEM_WORKQUEUE */
rt_inline void rt_work_init(struct rt_work *work, void (*work_func)(struct rt_work *work, void *work_data),
void *work_data)
@@ -85,7 +85,6 @@ rt_inline void rt_work_init(struct rt_work *work, void (*work_func)(struct rt_wo
void rt_delayed_work_init(struct rt_delayed_work *work, void (*work_func)(struct rt_work *work,
void *work_data), void *work_data);
-int rt_work_sys_workqueue_init(void);
-#endif
+#endif /* RT_USING_HEAP */
#endif
diff --git a/components/drivers/rtc/SConscript b/components/drivers/rtc/SConscript
index c3252fe7f9..6ec8bcb3c5 100644
--- a/components/drivers/rtc/SConscript
+++ b/components/drivers/rtc/SConscript
@@ -7,7 +7,7 @@ CPPPATH = [cwd + '/../include']
group = []
if GetDepend(['RT_USING_RTC']):
- src = src + ['rtc.c', 'rtc_core.c']
+ src = src + ['rtc.c']
if GetDepend(['RT_USING_ALARM']):
src = src + ['alarm.c']
if GetDepend(['RT_USING_SOFT_RTC']):
diff --git a/components/drivers/rtc/rtc.c b/components/drivers/rtc/rtc.c
index 3a843e2e0c..5eabeed2dd 100644
--- a/components/drivers/rtc/rtc.c
+++ b/components/drivers/rtc/rtc.c
@@ -10,6 +10,8 @@
* 2012-04-16 aozima add scheduler lock for set_date and set_time.
* 2018-02-16 armink add auto sync time by NTP
* 2021-05-09 Meco Man remove NTP
+ * 2021-06-11 iysheng implement RTC framework V2.0
+ * 2021-07-30 Meco Man move rtc_core.c to rtc.c
*/
#include <time.h>
@@ -20,7 +22,117 @@
#ifdef RT_USING_RTC
+/*
+ * This function initializes rtc_core
+ */
+static rt_err_t rt_rtc_init(struct rt_device *dev)
+{
+ rt_rtc_dev_t *rtc_core;
+
+ RT_ASSERT(dev != RT_NULL);
+ rtc_core = (rt_rtc_dev_t *)dev;
+ if (rtc_core->ops->init)
+ {
+ return (rtc_core->ops->init());
+ }
+
+ return -RT_ENOSYS;
+}
+
+static rt_err_t rt_rtc_open(struct rt_device *dev, rt_uint16_t oflag)
+{
+ return RT_EOK;
+}
+static rt_err_t rt_rtc_close(struct rt_device *dev)
+{
+ /* Add close member function in rt_rtc_ops when need,
+ * then call that function here.
+ * */
+ return RT_EOK;
+}
+
+static rt_err_t rt_rtc_control(struct rt_device *dev, int cmd, void *args)
+{
+#define TRY_DO_RTC_FUNC(rt_rtc_dev, func_name, args) \
+ rt_rtc_dev->ops->func_name ? rt_rtc_dev->ops->func_name(args) : -RT_EINVAL;
+
+ rt_rtc_dev_t *rtc_device;
+ rt_err_t ret = -RT_EINVAL;
+
+ RT_ASSERT(dev != RT_NULL);
+ rtc_device = (rt_rtc_dev_t *)dev;
+
+ switch (cmd)
+ {
+ case RT_DEVICE_CTRL_RTC_GET_TIME:
+ ret = TRY_DO_RTC_FUNC(rtc_device, get_secs, args);
+ break;
+ case RT_DEVICE_CTRL_RTC_SET_TIME:
+ ret = TRY_DO_RTC_FUNC(rtc_device, set_secs, args);
+ break;
+ case RT_DEVICE_CTRL_RTC_GET_TIME_US:
+ ret = TRY_DO_RTC_FUNC(rtc_device, get_usecs, args);
+ break;
+ case RT_DEVICE_CTRL_RTC_SET_TIME_US:
+ ret = TRY_DO_RTC_FUNC(rtc_device, set_usecs, args);
+ break;
+ case RT_DEVICE_CTRL_RTC_GET_ALARM:
+ ret = TRY_DO_RTC_FUNC(rtc_device, get_alarm, args);
+ break;
+ case RT_DEVICE_CTRL_RTC_SET_ALARM:
+ ret = TRY_DO_RTC_FUNC(rtc_device, set_alarm, args);
+ break;
+ default:
+ break;
+ }
+
+ return ret;
+
+#undef TRY_DO_RTC_FUNC
+}
+
+#ifdef RT_USING_DEVICE_OPS
+const static struct rt_device_ops rtc_core_ops =
+{
+ rt_rtc_init,
+ rt_rtc_open,
+ rt_rtc_close,
+ RT_NULL,
+ RT_NULL,
+ rt_rtc_control,
+};
+#endif /* RT_USING_DEVICE_OPS */
+
+rt_err_t rt_hw_rtc_register(rt_rtc_dev_t *rtc,
+ const char *name,
+ rt_uint32_t flag,
+ void *data)
+{
+ struct rt_device *device;
+ RT_ASSERT(rtc != RT_NULL);
+
+ device = &(rtc->parent);
+
+ device->type = RT_Device_Class_RTC;
+ device->rx_indicate = RT_NULL;
+ device->tx_complete = RT_NULL;
+
+#ifdef RT_USING_DEVICE_OPS
+ device->ops = &rtc_core_ops;
+#else
+ device->init = rt_rtc_init;
+ device->open = rt_rtc_open;
+ device->close = rt_rtc_close;
+ device->read = RT_NULL;
+ device->write = RT_NULL;
+ device->control = rt_rtc_control;
+#endif /* RT_USING_DEVICE_OPS */
+ device->user_data = data;
+
+ /* register a character device */
+ return rt_device_register(device, name, flag);
+}
/**
* Set system date(time not modify, local timezone).
@@ -30,12 +142,10 @@
* @param rt_uint32_t day e.g: 31.
*
* @return rt_err_t if set success, return RT_EOK.
- *
*/
rt_err_t set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day)
{
time_t now;
- struct tm *p_tm;
struct tm tm_new;
rt_device_t device;
rt_err_t ret = -RT_ERROR;
@@ -43,14 +153,8 @@ rt_err_t set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day)
/* get current time */
now = time(RT_NULL);
- /* lock scheduler. */
- rt_enter_critical();
/* converts calendar time into local time. */
- p_tm = localtime(&now);
- /* copy the statically located variable */
- rt_memcpy(&tm_new, p_tm, sizeof(struct tm));
- /* unlock scheduler. */
- rt_exit_critical();
+ localtime_r(&now, &tm_new);
/* update date. */
tm_new.tm_year = year - 1900;
@@ -80,12 +184,10 @@ rt_err_t set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day)
* @param rt_uint32_t second e.g: 0~59.
*
* @return rt_err_t if set success, return RT_EOK.
- *
*/
rt_err_t set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second)
{
time_t now;
- struct tm *p_tm;
struct tm tm_new;
rt_device_t device;
rt_err_t ret = -RT_ERROR;
@@ -93,14 +195,8 @@ rt_err_t set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second)
/* get current time */
now = time(RT_NULL);
- /* lock scheduler. */
- rt_enter_critical();
/* converts calendar time into local time. */
- p_tm = localtime(&now);
- /* copy the statically located variable */
- rt_memcpy(&tm_new, p_tm, sizeof(struct tm));
- /* unlock scheduler. */
- rt_exit_critical();
+ localtime_r(&now, &tm_new);
/* update time. */
tm_new.tm_hour = hour;
diff --git a/components/drivers/rtc/rtc_core.c b/components/drivers/rtc/rtc_core.c
deleted file mode 100644
index 80bb61c8aa..0000000000
--- a/components/drivers/rtc/rtc_core.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * COPYRIGHT (C) 2011-2021, Real-Thread Information Technology Ltd
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2021-06-11 iysheng first version.
- */
-
-#include <drivers/rtc_core.h>
-
-#define TRY_DO_RTC_FUNC(rt_rtc_dev, func_name, args) \
- rt_rtc_dev->ops->func_name ? rt_rtc_dev->ops->func_name(args) : -RT_EINVAL;
-
-/*
- * This function initializes rtc_core
- */
-static rt_err_t rt_rtc_core_init(struct rt_device *dev)
-{
- rt_rtc_dev_t *rtc_core;
-
- RT_ASSERT(dev != RT_NULL);
- rtc_core = (rt_rtc_dev_t *)dev;
- if (rtc_core->ops->init)
- {
- return (rtc_core->ops->init());
- }
-
- return (-RT_ENOSYS);
-}
-
-static rt_err_t rt_rtc_core_open(struct rt_device *dev, rt_uint16_t oflag)
-{
- return (RT_EOK);
-}
-
-static rt_err_t rt_rtc_core_close(struct rt_device *dev)
-{
- /* Add close member function in rt_rtc_ops when need,
- * then call that function here.
- * */
- return (RT_EOK);
-}
-
-static rt_err_t rt_rtc_core_control(struct rt_device *dev,
- int cmd,
- void *args)
-{
- rt_rtc_dev_t *rtc_core;
- rt_err_t ret = -RT_EINVAL;
-
- RT_ASSERT(dev != RT_NULL);
- rtc_core = (rt_rtc_dev_t *)dev;
-
- switch (cmd)
- {
- case RT_DEVICE_CTRL_RTC_GET_TIME:
- ret = TRY_DO_RTC_FUNC(rtc_core, get_secs, args);
- break;
- case RT_DEVICE_CTRL_RTC_SET_TIME:
- ret = TRY_DO_RTC_FUNC(rtc_core, set_secs, args);
- break;
- case RT_DEVICE_CTRL_RTC_GET_TIME_US:
- ret = TRY_DO_RTC_FUNC(rtc_core, get_usecs, args);
- break;
- case RT_DEVICE_CTRL_RTC_SET_TIME_US:
- ret = TRY_DO_RTC_FUNC(rtc_core, set_usecs, args);
- break;
- case RT_DEVICE_CTRL_RTC_GET_ALARM:
- ret = TRY_DO_RTC_FUNC(rtc_core, get_alarm, args);
- break;
- case RT_DEVICE_CTRL_RTC_SET_ALARM:
- ret = TRY_DO_RTC_FUNC(rtc_core, set_alarm, args);
- break;
- default:
- break;
- }
-
- return ret;
-}
-#ifdef RT_USING_DEVICE_OPS
-const static struct rt_device_ops rtc_core_ops =
-{
- rt_rtc_core_init,
- rt_rtc_core_open,
- rt_rtc_core_close,
- RT_NULL,
- RT_NULL,
- rt_rtc_core_control,
-};
-#endif
-
-rt_err_t rt_rtc_dev_register(rt_rtc_dev_t *rtc,
- const char *name,
- rt_uint32_t flag,
- void *data)
-{
- struct rt_device *device;
- RT_ASSERT(rtc != RT_NULL);
-
- device = &(rtc->parent);
-
- device->type = RT_Device_Class_RTC;
- device->rx_indicate = RT_NULL;
- device->tx_complete = RT_NULL;
-
-#ifdef RT_USING_DEVICE_OPS
- device->ops = &rtc_core_ops;
-#else
- device->init = rt_rtc_core_init;
- device->open = rt_rtc_core_open;
- device->close = rt_rtc_core_close;
- device->read = RT_NULL;
- device->write = RT_NULL;
- device->control = rt_rtc_core_control;
-#endif
- device->user_data = data;
-
- /* register a character device */
- return rt_device_register(device, name, flag);
-}
-
diff --git a/components/drivers/sdio/block_dev.c b/components/drivers/sdio/block_dev.c
index f2ce09a83f..2acbc44fa3 100644
--- a/components/drivers/sdio/block_dev.c
+++ b/components/drivers/sdio/block_dev.c
@@ -515,15 +515,3 @@ void rt_mmcsd_blk_remove(struct rt_mmcsd_card *card)
}
}
}
-
-/*
- * This function will initialize block device on the mmc/sd.
- *
- * @deprecated since 2.1.0, this function does not need to be invoked
- * in the system initialization.
- */
-int rt_mmcsd_blk_init(void)
-{
- /* nothing */
- return 0;
-}
diff --git a/components/drivers/src/ringbuffer.c b/components/drivers/src/ringbuffer.c
index 29de20b087..f01a594609 100644
--- a/components/drivers/src/ringbuffer.c
+++ b/components/drivers/src/ringbuffer.c
@@ -8,6 +8,7 @@
* 2012-09-30 Bernard first version.
* 2013-05-08 Grissiom reimplement
* 2016-08-18 heyuanjie add interface
+ * 2021-07-20 arminker fix write_index bug in function rt_ringbuffer_put_force
*/
#include <rtthread.h>
@@ -138,7 +139,8 @@ rt_size_t rt_ringbuffer_put_force(struct rt_ringbuffer *rb,
if (length > space_length)
{
- rb->read_mirror = ~rb->read_mirror;
+ if (rb->write_index <= rb->read_index)
+ rb->read_mirror = ~rb->read_mirror;
rb->read_index = rb->write_index;
}
diff --git a/components/drivers/src/workqueue.c b/components/drivers/src/workqueue.c
index f195dad927..065c505015 100644
--- a/components/drivers/src/workqueue.c
+++ b/components/drivers/src/workqueue.c
@@ -358,7 +358,7 @@ rt_err_t rt_work_cancel(struct rt_work *work)
return rt_workqueue_cancel_work(sys_workq, work);
}
-int rt_work_sys_workqueue_init(void)
+static int rt_work_sys_workqueue_init(void)
{
if (sys_workq != RT_NULL)
return RT_EOK;
@@ -370,5 +370,5 @@ int rt_work_sys_workqueue_init(void)
return RT_EOK;
}
INIT_PREV_EXPORT(rt_work_sys_workqueue_init);
-#endif
-#endif
+#endif /* RT_USING_SYSTEM_WORKQUEUE */
+#endif /* RT_USING_HEAP */
diff --git a/components/libc/Kconfig b/components/libc/Kconfig
index a89b252caa..37a98ba836 100644
--- a/components/libc/Kconfig
+++ b/components/libc/Kconfig
@@ -59,9 +59,9 @@ if RT_USING_LIBC != y
default y
endif
-config RT_LIBC_FIXED_TIMEZONE
+config RT_LIBC_DEFAULT_TIMEZONE
depends on (RT_LIBC_USING_TIME || RT_USING_LIBC)
- int "Manually set a fixed time zone (UTC+)"
+ int "Set the default time zone (UTC+)"
range -12 12
default 8
diff --git a/components/libc/aio/posix_aio.c b/components/libc/aio/posix_aio.c
index 66f15e4c57..66cced8687 100644
--- a/components/libc/aio/posix_aio.c
+++ b/components/libc/aio/posix_aio.c
@@ -9,14 +9,8 @@
*/
#include <stdint.h>
-#include <stdio.h>
-
#include <rthw.h>
-#include <rtdevice.h>
-#include <rtthread.h>
-
#include <dfs_posix.h>
-
#include "posix_aio.h"
struct rt_workqueue* aio_queue = NULL;
diff --git a/components/libc/aio/posix_aio.h b/components/libc/aio/posix_aio.h
index de11738515..4e25e1d15b 100644
--- a/components/libc/aio/posix_aio.h
+++ b/components/libc/aio/posix_aio.h
@@ -11,6 +11,10 @@
#ifndef POSIX_AIO_H__
#define POSIX_AIO_H__
+#include <stdio.h>
+#include <sys/signal.h>
+#include <rtdevice.h>
+
struct aiocb
{
int aio_fildes; /* File descriptor. */
diff --git a/components/libc/compilers/common/none-gcc/sys/errno.h b/components/libc/compilers/common/none-gcc/sys/errno.h
index ad3614024d..ff1abca387 100644
--- a/components/libc/compilers/common/none-gcc/sys/errno.h
+++ b/components/libc/compilers/common/none-gcc/sys/errno.h
@@ -7,8 +7,8 @@
* Date Author Notes
* 2021-05-22 Meco Man The first version.
*/
-#ifndef _SYS_ERRNO_H
-#define _SYS_ERRNO_H
+#ifndef __SYS_ERRNO_H__
+#define __SYS_ERRNO_H__
#if defined(__ARMCC_VERSION)
/*
diff --git a/components/libc/compilers/common/none-gcc/sys/stat.h b/components/libc/compilers/common/none-gcc/sys/stat.h
index c4b42083c4..c8f65df435 100644
--- a/components/libc/compilers/common/none-gcc/sys/stat.h
+++ b/components/libc/compilers/common/none-gcc/sys/stat.h
@@ -6,3 +6,8 @@
* Change Logs:
* Date Author Notes
*/
+
+ #ifndef __SYS_STAT_H__
+ #define __SYS_STAT_H__
+
+ #endif
diff --git a/components/libc/compilers/common/none-gcc/sys/types.h b/components/libc/compilers/common/none-gcc/sys/types.h
index 7222326a2a..e9f44f7762 100644
--- a/components/libc/compilers/common/none-gcc/sys/types.h
+++ b/components/libc/compilers/common/none-gcc/sys/types.h
@@ -8,8 +8,8 @@
* 2020-09-05 Meco Man fix bugs
* 2020-12-16 Meco Man add useconds_t
*/
-#ifndef __TYPES_H__
-#define __TYPES_H__
+#ifndef __SYS_TYPES_H__
+#define __SYS_TYPES_H__
#include <stdint.h>
diff --git a/components/libc/compilers/common/none-gcc/sys/unistd.h b/components/libc/compilers/common/none-gcc/sys/unistd.h
index 2f01f660b3..ea2d674b0f 100644
--- a/components/libc/compilers/common/none-gcc/sys/unistd.h
+++ b/components/libc/compilers/common/none-gcc/sys/unistd.h
@@ -7,8 +7,8 @@
* Date Author Notes
* 2020-12-16 Meco Man add usleep
*/
-#ifndef _SYS_UNISTD_H
-#define _SYS_UNISTD_H
+#ifndef __SYS_UNISTD_H__
+#define __SYS_UNISTD_H__
#include <rtconfig.h>
#include "types.h"
diff --git a/components/libc/compilers/common/sys/select.h b/components/libc/compilers/common/sys/select.h
new file mode 100644
index 0000000000..db42b6ebcc
--- /dev/null
+++ b/components/libc/compilers/common/sys/select.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-07-21 Meco Man The first version
+ */
+
+#ifndef __SYS_SELECT_H__
+#define __SYS_SELECT_H__
+
+#include <rtconfig.h>
+#include <sys/types.h>
+
+#ifndef FD_SETSIZE
+#define FD_SETSIZE 32
+#endif
+
+#ifdef SAL_USING_POSIX
+#ifdef FD_SETSIZE
+#undef FD_SETSIZE
+#endif
+#define FD_SETSIZE DFS_FD_MAX
+#endif /* SAL_USING_POSIX */
+
+#define NBBY 8 /* number of bits in a byte */
+
+typedef long fd_mask;
+
+#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */
+#ifndef howmany
+#define howmany(x,y) (((x)+((y)-1))/(y))
+#endif
+
+#ifndef _SYS_TYPES_FD_SET /* MIPS */
+typedef struct _types_fd_set {
+ fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
+} _types_fd_set;
+#define fd_set _types_fd_set
+
+#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS)))
+#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS)))
+#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS)))
+#define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p)))
+#endif /* _SYS_TYPES_FD_SET */
+
+#endif /* __SYS_SELECT_H__ */
diff --git a/components/libc/compilers/common/sys/signal.h b/components/libc/compilers/common/sys/signal.h
new file mode 100644
index 0000000000..9787958a37
--- /dev/null
+++ b/components/libc/compilers/common/sys/signal.h
@@ -0,0 +1,194 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2017-09-12 Bernard The first version
+ * 2021-07-21 Meco Man move to libc/common
+ */
+
+#ifndef __SYS_SIGNAL_H__
+#define __SYS_SIGNAL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+
+/* Signal Generation and Delivery, P1003.1b-1993, p. 63
+ NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and
+ sigev_notify_attributes to the sigevent structure. */
+union sigval
+{
+ int sival_int; /* Integer signal value */
+ void *sival_ptr; /* Pointer signal value */
+};
+
+struct sigevent
+{
+ int sigev_notify; /* Notification type */
+ int sigev_signo; /* Signal number */
+ union sigval sigev_value; /* Signal value */
+ void (*sigev_notify_function)( union sigval );
+ /* Notification function */
+ void *sigev_notify_attributes; /* Notification Attributes, really pthread_attr_t */
+};
+
+struct siginfo
+{
+ uint16_t si_signo;
+ uint16_t si_code;
+
+ union sigval si_value;
+};
+typedef struct siginfo siginfo_t;
+
+#define SI_USER 0x01 /* Signal sent by kill(). */
+#define SI_QUEUE 0x02 /* Signal sent by sigqueue(). */
+#define SI_TIMER 0x03 /* Signal generated by expiration of a timer set by timer_settime(). */
+#define SI_ASYNCIO 0x04 /* Signal generated by completion of an asynchronous I/O request. */
+#define SI_MESGQ 0x05 /* Signal generated by arrival of a message on an empty message queue. */
+
+typedef void (*_sig_func_ptr)(int);
+typedef unsigned long sigset_t;
+
+struct sigaction
+{
+ _sig_func_ptr sa_handler;
+ sigset_t sa_mask;
+ int sa_flags;
+};
+
+#define SIG_SETMASK 0 /* set mask with sigprocmask() */
+#define SIG_BLOCK 1 /* set of signals to block */
+#define SIG_UNBLOCK 2 /* set of signals to, well, unblock */
+
+#define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0)
+#define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0)
+#define sigemptyset(what) (*(what) = 0, 0)
+#define sigfillset(what) (*(what) = ~(0), 0)
+#define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0)
+
+int sigprocmask (int how, const sigset_t *set, sigset_t *oset);
+int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
+
+#ifdef __ARMCC_VERSION
+#define SIGHUP 1
+/* #define SIGINT 2 */
+#define SIGQUIT 3
+/* #define SIGILL 4 */
+#define SIGTRAP 5
+/* #define SIGABRT 6 */
+#define SIGEMT 7
+/* #define SIGFPE 8 */
+#define SIGKILL 9
+#define SIGBUS 10
+/* #define SIGSEGV 11 */
+#define SIGSYS 12
+#define SIGPIPE 13
+#define SIGALRM 14
+/* #define SIGTERM 15 */
+#define SIGURG 16
+#define SIGSTOP 17
+#define SIGTSTP 18
+#define SIGCONT 19
+#define SIGCHLD 20
+#define SIGTTIN 21
+#define SIGTTOU 22
+#define SIGPOLL 23
+#define SIGWINCH 24
+/* #define SIGUSR1 25 */
+/* #define SIGUSR2 26 */
+#define SIGRTMIN 27
+#define SIGRTMAX 31
+#define NSIG 32
+
+#include <signal.h>
+
+#elif defined(__IAR_SYSTEMS_ICC__)
+#define SIGHUP 1
+#define SIGINT 2
+#define SIGQUIT 3
+#define SIGILL 4
+#define SIGTRAP 5
+/* #define SIGABRT 6 */
+#define SIGEMT 7
+#define SIGFPE 8
+#define SIGKILL 9
+#define SIGBUS 10
+#define SIGSEGV 11
+#define SIGSYS 12
+#define SIGPIPE 13
+#define SIGALRM 14
+#define SIGTERM 15
+#define SIGURG 16
+#define SIGSTOP 17
+#define SIGTSTP 18
+#define SIGCONT 19
+#define SIGCHLD 20
+#define SIGTTIN 21
+#define SIGTTOU 22
+#define SIGPOLL 23
+#define SIGWINCH 24
+#define SIGUSR1 25
+#define SIGUSR2 26
+#define SIGRTMIN 27
+#define SIGRTMAX 31
+#define NSIG 32
+
+#include <signal.h>
+
+#elif defined(__GNUC__)
+#define SIGHUP 1 /* hangup */
+#define SIGINT 2 /* interrupt */
+#define SIGQUIT 3 /* quit */
+#define SIGILL 4 /* illegal instruction (not reset when caught) */
+#define SIGTRAP 5 /* trace trap (not reset when caught) */
+#define SIGIOT 6 /* IOT instruction */
+#define SIGABRT 6 /* used by abort, replace SIGIOT in the future */
+#define SIGEMT 7 /* EMT instruction */
+#define SIGFPE 8 /* floating point exception */
+#define SIGKILL 9 /* kill (cannot be caught or ignored) */
+#define SIGBUS 10 /* bus error */
+#define SIGSEGV 11 /* segmentation violation */
+#define SIGSYS 12 /* bad argument to system call */
+#define SIGPIPE 13 /* write on a pipe with no one to read it */
+#define SIGALRM 14 /* alarm clock */
+#define SIGTERM 15 /* software termination signal from kill */
+#define SIGURG 16 /* urgent condition on IO channel */
+#define SIGSTOP 17 /* sendable stop signal not from tty */
+#define SIGTSTP 18 /* stop signal from tty */
+#define SIGCONT 19 /* continue a stopped process */
+#define SIGCHLD 20 /* to parent on child stop or exit */
+#define SIGCLD 20 /* System V name for SIGCHLD */
+#define SIGTTIN 21 /* to readers pgrp upon background tty read */
+#define SIGTTOU 22 /* like TTIN for output if (tp->t_local&LTOSTOP) */
+#define SIGIO 23 /* input/output possible signal */
+#define SIGPOLL SIGIO /* System V name for SIGIO */
+#define SIGXCPU 24 /* exceeded CPU time limit */
+#define SIGXFSZ 25 /* exceeded file size limit */
+#define SIGVTALRM 26 /* virtual time alarm */
+#define SIGPROF 27 /* profiling time alarm */
+#define SIGWINCH 28 /* window changed */
+#define SIGLOST 29 /* resource lost (eg, record-lock lost) */
+#define SIGUSR1 30 /* user defined signal 1 */
+#define SIGUSR2 31 /* user defined signal 2 */
+#define NSIG 32 /* signal 0 implied */
+
+#ifndef _SIGNAL_H_
+/* Some applications take advantage of the fact that <sys/signal.h>
+ * and <signal.h> are equivalent in glibc. Allow for that here. */
+#include <signal.h>
+#endif
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h
index bb1a9c96fd..c2320429e0 100644
--- a/components/libc/compilers/common/sys/time.h
+++ b/components/libc/compilers/common/sys/time.h
@@ -12,12 +12,14 @@
#define _SYS_TIME_H_
#include <rtconfig.h>
+#include <rtdef.h>
#include <time.h>
#ifdef __cplusplus
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 */
@@ -30,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 */
@@ -44,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);
@@ -66,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
@@ -95,7 +102,7 @@ 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 */
#ifdef __cplusplus
diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c
index e79a22b9db..50f6d4c71e 100644
--- a/components/libc/compilers/common/time.c
+++ b/components/libc/compilers/common/time.c
@@ -18,12 +18,13 @@
* 2021-02-12 Meco Man move all of the functions located in <clock_time.c> to this file
* 2021-03-15 Meco Man fixed a bug of leaking memory in asctime()
* 2021-05-01 Meco Man support fixed timezone
+ * 2021-07-21 Meco Man implement that change/set timezone APIs
*/
#include "sys/time.h"
#include <sys/errno.h>
#include <rtthread.h>
-
+#include <rthw.h>
#ifdef RT_USING_DEVICE
#include <rtdevice.h>
#endif
@@ -32,10 +33,6 @@
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
-#ifndef RT_LIBC_FIXED_TIMEZONE
-#define RT_LIBC_FIXED_TIMEZONE 8 /* UTC+8 */
-#endif
-
/* seconds per day */
#define SPD 24*60*60
@@ -202,7 +199,7 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r)
r->tm_mon = i;
r->tm_mday += work - __spm[i];
- r->tm_isdst = 0;
+ r->tm_isdst = rt_tz_is_dst();
return r;
}
RTM_EXPORT(gmtime_r);
@@ -218,7 +215,7 @@ struct tm* localtime_r(const time_t* t, struct tm* r)
{
time_t local_tz;
- local_tz = *t + RT_LIBC_FIXED_TIMEZONE * 3600;
+ local_tz = *t + rt_tz_get() * 3600;
return gmtime_r(&local_tz, r);
}
RTM_EXPORT(localtime_r);
@@ -235,7 +232,7 @@ time_t mktime(struct tm * const t)
time_t timestamp;
timestamp = timegm(t);
- timestamp = timestamp - 3600 * RT_LIBC_FIXED_TIMEZONE;
+ timestamp = timestamp - 3600 * rt_tz_get();
return timestamp;
}
RTM_EXPORT(mktime);
@@ -426,7 +423,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
if(tz != RT_NULL)
{
tz->tz_dsttime = DST_NONE;
- tz->tz_minuteswest = -(RT_LIBC_FIXED_TIMEZONE * 60);
+ tz->tz_minuteswest = -(rt_tz_get() * 60);
}
if (tv != RT_NULL && get_timeval(tv) == RT_EOK)
@@ -468,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();
+ level = rt_hw_interrupt_disable();
+ _timevalue.tv_usec = 0;
+ _timevalue.tv_sec = 0;
+ rt_hw_interrupt_enable(level);
- _timevalue.tv_usec = (tick%RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK;
- _timevalue.tv_sec = time - tick/RT_TICK_PER_SECOND - 1;
-
- 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)
@@ -529,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)
@@ -546,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;
@@ -574,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;
@@ -586,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;
@@ -648,6 +666,32 @@ 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 */
+#ifndef RT_LIBC_DEFAULT_TIMEZONE
+#define RT_LIBC_DEFAULT_TIMEZONE 8
+#endif
+
+static volatile rt_int8_t rt_current_timezone = RT_LIBC_DEFAULT_TIMEZONE;
+
+void rt_tz_set(rt_int8_t tz)
+{
+ register rt_base_t level;
+ level = rt_hw_interrupt_disable();
+ rt_current_timezone = tz;
+ rt_hw_interrupt_enable(level);
+}
+
+rt_int8_t rt_tz_get(void)
+{
+ return rt_current_timezone;
+}
+
+rt_int8_t rt_tz_is_dst(void)
+{
+ return 0;
+}
diff --git a/components/libc/pthreads/mqueue.c b/components/libc/pthreads/mqueue.c
index 1af0ab2919..6840164a68 100644
--- a/components/libc/pthreads/mqueue.c
+++ b/components/libc/pthreads/mqueue.c
@@ -8,6 +8,7 @@
*/
#include <string.h>
+#include <sys/signal.h>
#include "mqueue.h"
#include "pthread_internal.h"
@@ -243,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)
diff --git a/components/libc/pthreads/pthread_cond.c b/components/libc/pthreads/pthread_cond.c
index 59c271bf6e..9bf49704ed 100644
--- a/components/libc/pthreads/pthread_cond.c
+++ b/components/libc/pthreads/pthread_cond.c
@@ -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;
diff --git a/components/libc/pthreads/semaphore.c b/components/libc/pthreads/semaphore.c
index 199b33bfe8..5e59ae850f 100644
--- a/components/libc/pthreads/semaphore.c
+++ b/components/libc/pthreads/semaphore.c
@@ -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)
diff --git a/components/libc/signal/posix_signal.c b/components/libc/signal/posix_signal.c
index 1cb561d428..ac8d2b1eef 100644
--- a/components/libc/signal/posix_signal.c
+++ b/components/libc/signal/posix_signal.c
@@ -7,6 +7,7 @@
* Date Author Notes
* 2017/10/1 Bernard The first version
*/
+
#include <rthw.h>
#include <rtthread.h>
@@ -14,6 +15,7 @@
#include <sys/errno.h>
#include "posix_signal.h"
+
#define sig_valid(sig_no) (sig_no >= 0 && sig_no < RT_SIG_MAX)
void (*signal(int sig, void (*func)(int))) (int)
@@ -79,13 +81,10 @@ int sigtimedwait(const sigset_t *set, siginfo_t *info,
int ret = 0;
int tick = RT_WAITING_FOREVER;
-#ifdef RT_USING_PTHREADS
if (timeout)
{
- extern int clock_time_to_tick(const struct timespec *time);
- tick = clock_time_to_tick(timeout);
+ tick = rt_timespec_to_tick(timeout);
}
-#endif
ret = rt_signal_wait(set, info, tick);
if (ret == 0) return 0;
diff --git a/components/libc/signal/posix_signal.h b/components/libc/signal/posix_signal.h
index fa8ad38fa6..f04b54c5f8 100644
--- a/components/libc/signal/posix_signal.h
+++ b/components/libc/signal/posix_signal.h
@@ -15,7 +15,6 @@
extern "C" {
#endif
-#include <rtthread.h>
#include <sys/signal.h>
enum rt_signal_value{
diff --git a/components/net/at/at_socket/at_socket.c b/components/net/at/at_socket/at_socket.c
index 973be0acf4..8215dd4417 100644
--- a/components/net/at/at_socket/at_socket.c
+++ b/components/net/at/at_socket/at_socket.c
@@ -13,6 +13,7 @@
#include <string.h>
#include <ctype.h>
#include <sys/time.h>
+#include <sys/errno.h>
#include <at_socket.h>
#include <at_device.h>
@@ -78,7 +79,7 @@ struct at_socket *at_get_socket(int socket)
}
/* get a block to the AT socket receive list*/
-static size_t at_recvpkt_put(rt_slist_t *rlist, const char *ptr, size_t length)
+static rt_err_t at_recvpkt_put(rt_slist_t *rlist, const char *ptr, size_t length)
{
at_recv_pkt_t pkt = RT_NULL;
@@ -86,7 +87,7 @@ static size_t at_recvpkt_put(rt_slist_t *rlist, const char *ptr, size_t length)
if (pkt == RT_NULL)
{
LOG_E("No memory for receive packet table!");
- return 0;
+ return -RT_ENOMEM;
}
pkt->bfsz_totle = length;
@@ -95,7 +96,7 @@ static size_t at_recvpkt_put(rt_slist_t *rlist, const char *ptr, size_t length)
rt_slist_append(rlist, &pkt->list);
- return length;
+ return RT_EOK;
}
/* delete and free all receive buffer list */
@@ -651,14 +652,20 @@ static void at_recv_notice_cb(struct at_socket *sock, at_socket_evt_t event, con
RT_ASSERT(event == AT_SOCKET_EVT_RECV);
/* check the socket object status */
- if (sock->magic != AT_SOCKET_MAGIC)
+ if (sock->magic != AT_SOCKET_MAGIC || sock->state == AT_SOCKET_CLOSED)
{
+ rt_free((void *)buff);
return;
}
/* put receive buffer to receiver packet list */
rt_mutex_take(sock->recv_lock, RT_WAITING_FOREVER);
- at_recvpkt_put(&(sock->recvpkt_list), buff, bfsz);
+ if (at_recvpkt_put(&(sock->recvpkt_list), buff, bfsz) != RT_EOK)
+ {
+ rt_free((void *)buff);
+ rt_mutex_release(sock->recv_lock);
+ return;
+ }
rt_mutex_release(sock->recv_lock);
rt_sem_release(sock->recv_notice);
diff --git a/components/net/at/src/at_client.c b/components/net/at/src/at_client.c
index 7904c24d92..948020f4cf 100644
--- a/components/net/at/src/at_client.c
+++ b/components/net/at/src/at_client.c
@@ -9,6 +9,7 @@
* 2018-04-12 chenyong add client implement
* 2018-08-17 chenyong multiple client support
* 2021-03-17 Meco Man fix a buf of leaking memory
+ * 2021-07-14 Sszl fix a buf of leaking memory
*/
#include <at.h>
@@ -571,30 +572,19 @@ int at_obj_set_urc_table(at_client_t client, const struct at_urc *urc_table, rt_
}
else
{
- struct at_urc_table *old_urc_table = RT_NULL;
- size_t old_table_size = client->urc_table_size * sizeof(struct at_urc_table);
-
- old_urc_table = (struct at_urc_table *) rt_malloc(old_table_size);
- if (old_urc_table == RT_NULL)
- {
- return -RT_ENOMEM;
- }
- rt_memcpy(old_urc_table, client->urc_table, old_table_size);
+ struct at_urc_table *new_urc_table = RT_NULL;
/* realloc urc table space */
- client->urc_table = (struct at_urc_table *) rt_realloc(client->urc_table,
- old_table_size + sizeof(struct at_urc_table));
- if (client->urc_table == RT_NULL)
+ new_urc_table = (struct at_urc_table *) rt_realloc(client->urc_table,client->urc_table_size * sizeof(struct at_urc_table) + sizeof(struct at_urc_table));
+ if (new_urc_table == RT_NULL)
{
- rt_free(old_urc_table);
return -RT_ENOMEM;
}
- rt_memcpy(client->urc_table, old_urc_table, old_table_size);
+ client->urc_table = new_urc_table;
client->urc_table[client->urc_table_size].urc = urc_table;
client->urc_table[client->urc_table_size].urc_size = table_sz;
client->urc_table_size++;
- rt_free(old_urc_table);
}
return RT_EOK;
diff --git a/components/net/lwip-1.4.1/src/lwipopts.h b/components/net/lwip-1.4.1/src/lwipopts.h
index 0b7e092d6c..9148066d50 100644
--- a/components/net/lwip-1.4.1/src/lwipopts.h
+++ b/components/net/lwip-1.4.1/src/lwipopts.h
@@ -222,6 +222,13 @@
#define LWIP_DBG_TYPES_ON (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT)
/* ---------- Memory options ---------- */
+#ifdef RT_USING_ASM_MEMCPY
+#define MEMCPY(dst,src,len) rt_memcpy(dst,src,len)
+#else
+#define MEMCPY(dst,src,len) memcpy(dst,src,len)
+#endif /* RT_USING_ASM_MEMCPY */
+#define SMEMCPY(dst,src,len) MEMCPY(dst,src,len)
+
#define MEM_ALIGNMENT 4
#define MEM_LIBC_MALLOC 1
diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c
index 4565f5e528..40cd8fb6ef 100644
--- a/components/net/lwip-1.4.1/src/netif/ethernetif.c
+++ b/components/net/lwip-1.4.1/src/netif/ethernetif.c
@@ -201,14 +201,14 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len,
{
return -RT_ERROR;
}
- rt_memcpy(&h, &res->ai_addr, sizeof(struct sockaddr_in *));
- rt_memcpy(&ina, &h->sin_addr, sizeof(ina));
+ SMEMCPY(&h, &res->ai_addr, sizeof(struct sockaddr_in *));
+ SMEMCPY(&ina, &h->sin_addr, sizeof(ina));
lwip_freeaddrinfo(res);
if (inet_aton(inet_ntoa(ina), &target_addr) == 0)
{
return -RT_ERROR;
}
- rt_memcpy(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t));
+ SMEMCPY(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t));
/* new a socket */
if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0)
@@ -331,7 +331,7 @@ static int netdev_add(struct netif *lwip_netif)
netdev->mtu = lwip_netif->mtu;
netdev->ops = &lwip_netdev_ops;
netdev->hwaddr_len = lwip_netif->hwaddr_len;
- rt_memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
+ SMEMCPY(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
netdev->ip_addr = lwip_netif->ip_addr;
netdev->gw = lwip_netif->gw;
netdev->netmask = lwip_netif->netmask;
diff --git a/components/net/lwip-2.0.2/src/lwipopts.h b/components/net/lwip-2.0.2/src/lwipopts.h
index d559684c02..fdfe1437b2 100644
--- a/components/net/lwip-2.0.2/src/lwipopts.h
+++ b/components/net/lwip-2.0.2/src/lwipopts.h
@@ -230,14 +230,21 @@
#define LWIP_DBG_TYPES_ON (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT)
/* ---------- Memory options ---------- */
+#ifdef RT_USING_ASM_MEMCPY
+#define MEMCPY(dst,src,len) rt_memcpy(dst,src,len)
+#else
+#define MEMCPY(dst,src,len) memcpy(dst,src,len)
+#endif /* RT_USING_ASM_MEMCPY */
+#define SMEMCPY(dst,src,len) MEMCPY(dst,src,len)
+
#ifdef RT_LWIP_MEM_ALIGNMENT
#define MEM_ALIGNMENT RT_LWIP_MEM_ALIGNMENT
#else
#define MEM_ALIGNMENT 4
#endif
-#define MEMP_OVERFLOW_CHECK 1 ////
-#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1 ////
+#define MEMP_OVERFLOW_CHECK 1
+#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1
//#define MEM_LIBC_MALLOC 1
//#define MEM_USE_POOLS 1
//#define MEMP_USE_CUSTOM_POOLS 1
diff --git a/components/net/lwip-2.0.2/src/netif/ethernetif.c b/components/net/lwip-2.0.2/src/netif/ethernetif.c
index 1c0f3ca9b2..0b1943fdff 100644
--- a/components/net/lwip-2.0.2/src/netif/ethernetif.c
+++ b/components/net/lwip-2.0.2/src/netif/ethernetif.c
@@ -210,14 +210,14 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len,
{
return -RT_ERROR;
}
- rt_memcpy(&h, &res->ai_addr, sizeof(struct sockaddr_in *));
- rt_memcpy(&ina, &h->sin_addr, sizeof(ina));
+ SMEMCPY(&h, &res->ai_addr, sizeof(struct sockaddr_in *));
+ SMEMCPY(&ina, &h->sin_addr, sizeof(ina));
lwip_freeaddrinfo(res);
if (inet_aton(inet_ntoa(ina), &target_addr) == 0)
{
return -RT_ERROR;
}
- rt_memcpy(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t));
+ SMEMCPY(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t));
/* new a socket */
if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0)
@@ -340,7 +340,7 @@ static int netdev_add(struct netif *lwip_netif)
netdev->mtu = lwip_netif->mtu;
netdev->ops = &lwip_netdev_ops;
netdev->hwaddr_len = lwip_netif->hwaddr_len;
- rt_memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
+ SMEMCPY(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
netdev->ip_addr = lwip_netif->ip_addr;
netdev->gw = lwip_netif->gw;
netdev->netmask = lwip_netif->netmask;
diff --git a/components/net/lwip-2.0.3/src/lwipopts.h b/components/net/lwip-2.0.3/src/lwipopts.h
index d559684c02..fdfe1437b2 100644
--- a/components/net/lwip-2.0.3/src/lwipopts.h
+++ b/components/net/lwip-2.0.3/src/lwipopts.h
@@ -230,14 +230,21 @@
#define LWIP_DBG_TYPES_ON (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT)
/* ---------- Memory options ---------- */
+#ifdef RT_USING_ASM_MEMCPY
+#define MEMCPY(dst,src,len) rt_memcpy(dst,src,len)
+#else
+#define MEMCPY(dst,src,len) memcpy(dst,src,len)
+#endif /* RT_USING_ASM_MEMCPY */
+#define SMEMCPY(dst,src,len) MEMCPY(dst,src,len)
+
#ifdef RT_LWIP_MEM_ALIGNMENT
#define MEM_ALIGNMENT RT_LWIP_MEM_ALIGNMENT
#else
#define MEM_ALIGNMENT 4
#endif
-#define MEMP_OVERFLOW_CHECK 1 ////
-#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1 ////
+#define MEMP_OVERFLOW_CHECK 1
+#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1
//#define MEM_LIBC_MALLOC 1
//#define MEM_USE_POOLS 1
//#define MEMP_USE_CUSTOM_POOLS 1
diff --git a/components/net/lwip-2.0.3/src/netif/ethernetif.c b/components/net/lwip-2.0.3/src/netif/ethernetif.c
index 1c0f3ca9b2..0b1943fdff 100644
--- a/components/net/lwip-2.0.3/src/netif/ethernetif.c
+++ b/components/net/lwip-2.0.3/src/netif/ethernetif.c
@@ -210,14 +210,14 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len,
{
return -RT_ERROR;
}
- rt_memcpy(&h, &res->ai_addr, sizeof(struct sockaddr_in *));
- rt_memcpy(&ina, &h->sin_addr, sizeof(ina));
+ SMEMCPY(&h, &res->ai_addr, sizeof(struct sockaddr_in *));
+ SMEMCPY(&ina, &h->sin_addr, sizeof(ina));
lwip_freeaddrinfo(res);
if (inet_aton(inet_ntoa(ina), &target_addr) == 0)
{
return -RT_ERROR;
}
- rt_memcpy(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t));
+ SMEMCPY(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t));
/* new a socket */
if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0)
@@ -340,7 +340,7 @@ static int netdev_add(struct netif *lwip_netif)
netdev->mtu = lwip_netif->mtu;
netdev->ops = &lwip_netdev_ops;
netdev->hwaddr_len = lwip_netif->hwaddr_len;
- rt_memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
+ SMEMCPY(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
netdev->ip_addr = lwip_netif->ip_addr;
netdev->gw = lwip_netif->gw;
netdev->netmask = lwip_netif->netmask;
diff --git a/components/net/lwip-2.1.2/src/lwipopts.h b/components/net/lwip-2.1.2/src/lwipopts.h
index 2cd7cb023a..a964ab13ac 100644
--- a/components/net/lwip-2.1.2/src/lwipopts.h
+++ b/components/net/lwip-2.1.2/src/lwipopts.h
@@ -242,9 +242,16 @@
#endif
/* ---------- Memory options ---------- */
+#ifdef RT_USING_ASM_MEMCPY
+#define MEMCPY(dst,src,len) rt_memcpy(dst,src,len)
+#else
+#define MEMCPY(dst,src,len) memcpy(dst,src,len)
+#endif /* RT_USING_ASM_MEMCPY */
+#define SMEMCPY(dst,src,len) MEMCPY(dst,src,len)
+
#define MEM_ALIGNMENT 4
-#define MEMP_OVERFLOW_CHECK 1 ////
-#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1 ////
+#define MEMP_OVERFLOW_CHECK 1
+#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1
//#define MEM_LIBC_MALLOC 1
//#define MEM_USE_POOLS 1
//#define MEMP_USE_CUSTOM_POOLS 1
diff --git a/components/net/lwip-2.1.2/src/netif/ethernetif.c b/components/net/lwip-2.1.2/src/netif/ethernetif.c
index 81dd792f29..bd4db225ee 100644
--- a/components/net/lwip-2.1.2/src/netif/ethernetif.c
+++ b/components/net/lwip-2.1.2/src/netif/ethernetif.c
@@ -208,14 +208,14 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len,
{
return -RT_ERROR;
}
- rt_memcpy(&h, &res->ai_addr, sizeof(struct sockaddr_in *));
- rt_memcpy(&ina, &h->sin_addr, sizeof(ina));
+ SMEMCPY(&h, &res->ai_addr, sizeof(struct sockaddr_in *));
+ SMEMCPY(&ina, &h->sin_addr, sizeof(ina));
lwip_freeaddrinfo(res);
if (inet_aton(inet_ntoa(ina), &target_addr) == 0)
{
return -RT_ERROR;
}
- rt_memcpy(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t));
+ SMEMCPY(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t));
/* new a socket */
if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0)
@@ -338,7 +338,7 @@ static int netdev_add(struct netif *lwip_netif)
netdev->mtu = lwip_netif->mtu;
netdev->ops = &lwip_netdev_ops;
netdev->hwaddr_len = lwip_netif->hwaddr_len;
- rt_memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
+ SMEMCPY(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
netdev->ip_addr = lwip_netif->ip_addr;
netdev->gw = lwip_netif->gw;
netdev->netmask = lwip_netif->netmask;
diff --git a/components/net/sal_socket/include/socket/netdb.h b/components/net/sal_socket/include/socket/netdb.h
index 4783405022..9d54953681 100644
--- a/components/net/sal_socket/include/socket/netdb.h
+++ b/components/net/sal_socket/include/socket/netdb.h
@@ -6,7 +6,7 @@
* Change Logs:
* Date Author Notes
* 2015-02-17 Bernard First version
- * 2108-05-24 ChenYong Add socket abstraction layer
+ * 2018-05-24 ChenYong Add socket abstraction layer
*/
#ifndef NETDB_H__