From a8ed7b776995598c7d4443735ed7dbdcb8bd967e Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 22 Jul 2021 17:00:21 +0800 Subject: [workqueue] 将rt_work_sys_workqueue_init函数私有化 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/include/ipc/workqueue.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'components/drivers/include') 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 -- cgit v1.3.1 From 9e47b95e61b09ddbec2bc9f8a2c2cbb970b1f54e Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Fri, 30 Jul 2021 02:31:15 +0800 Subject: rt_rtc_dev_register -> rt_hw_rtc_register --- bsp/stm32/libraries/HAL_Drivers/drv_rtc.c | 2 +- components/drivers/include/drivers/rtc_core.h | 2 +- components/drivers/rtc/rtc_core.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'components/drivers/include') diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_rtc.c b/bsp/stm32/libraries/HAL_Drivers/drv_rtc.c index 15968a178c..fb0680dfb2 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_rtc.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_rtc.c @@ -280,7 +280,7 @@ static int rt_hw_rtc_init(void) rt_err_t result; stm32_rtc_dev.ops = &stm32_rtc_ops; - result = rt_rtc_dev_register(&stm32_rtc_dev, "rtc", RT_DEVICE_FLAG_RDWR, RT_NULL); + result = rt_hw_rtc_register(&stm32_rtc_dev, "rtc", RT_DEVICE_FLAG_RDWR, RT_NULL); if (result != RT_EOK) { LOG_E("rtc register err code: %d", result); diff --git a/components/drivers/include/drivers/rtc_core.h b/components/drivers/include/drivers/rtc_core.h index f0c7b64e94..e858e9ee28 100644 --- a/components/drivers/include/drivers/rtc_core.h +++ b/components/drivers/include/drivers/rtc_core.h @@ -37,7 +37,7 @@ typedef struct rt_rtc_device const struct rt_rtc_ops *ops; } rt_rtc_dev_t; -rt_err_t rt_rtc_dev_register(rt_rtc_dev_t *rtc, +rt_err_t rt_hw_rtc_register(rt_rtc_dev_t *rtc, const char *name, rt_uint32_t flag, void *data); diff --git a/components/drivers/rtc/rtc_core.c b/components/drivers/rtc/rtc_core.c index 80bb61c8aa..8edec43095 100644 --- a/components/drivers/rtc/rtc_core.c +++ b/components/drivers/rtc/rtc_core.c @@ -91,7 +91,7 @@ const static struct rt_device_ops rtc_core_ops = }; #endif -rt_err_t rt_rtc_dev_register(rt_rtc_dev_t *rtc, +rt_err_t rt_hw_rtc_register(rt_rtc_dev_t *rtc, const char *name, rt_uint32_t flag, void *data) -- cgit v1.3.1 From 94a9332915fe971277ed6aa86f544c8dd3f459ea Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Fri, 30 Jul 2021 02:42:57 +0800 Subject: [rtc] 移除rtc_core.c/.h 将内容转移到rtc.c/.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/efm32/drv_rtc.c | 56 +++--------- components/drivers/include/drivers/rtc.h | 33 ++++++- components/drivers/include/drivers/rtc_core.h | 45 ---------- components/drivers/rtc/SConscript | 2 +- components/drivers/rtc/rtc.c | 112 +++++++++++++++++++++++ components/drivers/rtc/rtc_core.c | 123 -------------------------- 6 files changed, 156 insertions(+), 215 deletions(-) delete mode 100644 components/drivers/include/drivers/rtc_core.h delete mode 100644 components/drivers/rtc/rtc_core.c (limited to 'components/drivers/include') diff --git a/bsp/efm32/drv_rtc.c b/bsp/efm32/drv_rtc.c index 9972d3c631..3e842a8e4c 100644 --- a/bsp/efm32/drv_rtc.c +++ b/bsp/efm32/drv_rtc.c @@ -128,49 +128,6 @@ void rt_hw_rtc_isr(rt_device_t device) RTC->IFC = _RTC_IFC_MASK; } -/***************************************************************************//** - * @brief - * Register RTC device - * - * @details - * - * @note - * - * @param[in] device - * Pointer to device descriptor - * - * @param[in] name - * Device name - * - * @param[in] flag - * Configuration flags - * - * @return - * Error code - ******************************************************************************/ -rt_err_t rt_hw_rtc_register( - rt_device_t device, - const char *name, - rt_uint32_t flag) -{ - RT_ASSERT(device != RT_NULL); - - device->type = RT_Device_Class_RTC; - device->rx_indicate = RT_NULL; - device->tx_complete = RT_NULL; - device->init = RT_NULL; - device->open = rt_rtc_open; - device->close = RT_NULL; - device->read = rt_rtc_read; - device->write = RT_NULL; - device->control = rt_rtc_control; - device->user_data = RT_NULL; /* no private */ - - /* register a character device */ - return rt_device_register(device, name, RT_DEVICE_FLAG_RDWR | flag); -} - - /***************************************************************************//** * @brief * Initialize all RTC module related hardware and register RTC device to kernel @@ -224,7 +181,18 @@ void rt_hw_rtc_init(void) } /* register rtc device */ - rt_hw_rtc_register(&rtc, RT_RTC_NAME, EFM32_NO_DATA); + rtc.type = RT_Device_Class_RTC; + rtc.rx_indicate = RT_NULL; + rtc.tx_complete = RT_NULL; + rtc.init = RT_NULL; + rtc.open = rt_rtc_open; + rtc.close = RT_NULL; + rtc.read = rt_rtc_read; + rtc.write = RT_NULL; + rtc.control = rt_rtc_control; + rtc.user_data = RT_NULL; /* no private */ + + rt_device_register(&rtc, RT_RTC_NAME, RT_DEVICE_FLAG_RDWR | EFM32_NO_DATA); } #endif diff --git a/components/drivers/include/drivers/rtc.h b/components/drivers/include/drivers/rtc.h index 9eddf801b7..ab64dd8ec9 100644 --- a/components/drivers/include/drivers/rtc.h +++ b/components/drivers/include/drivers/rtc.h @@ -6,13 +6,42 @@ * Change Logs: * Date Author Notes * 2012-10-10 aozima first version. + * 2021-06-11 iysheng implement RTC v2.0 */ #ifndef __RTC_H__ #define __RTC_H__ -#include -#include +#include + +#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 e858e9ee28..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 - -#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); - -#endif /* __RTC_CORE_H__ */ 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 9e1305cdd7..8d61129bf8 100644 --- a/components/drivers/rtc/rtc.c +++ b/components/drivers/rtc/rtc.c @@ -10,6 +10,7 @@ * 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 v2.0 */ #include @@ -20,6 +21,117 @@ #ifdef RT_USING_RTC +#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_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_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); +} + /** * Set system date(time not modify, local timezone). * diff --git a/components/drivers/rtc/rtc_core.c b/components/drivers/rtc/rtc_core.c deleted file mode 100644 index 8edec43095..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 - -#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_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_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); -} - -- cgit v1.3.1 From a25667a7e5fa449d8554a4589744eeca26a615c0 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Fri, 30 Jul 2021 03:55:18 +0800 Subject: [rtc] add comments --- bsp/stm32/libraries/HAL_Drivers/drv_rtc.c | 4 +- components/drivers/include/drivers/rtc.h | 5 ++- components/drivers/rtc/rtc.c | 66 ++++++++++++++++--------------- 3 files changed, 39 insertions(+), 36 deletions(-) (limited to 'components/drivers/include') diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_rtc.c b/bsp/stm32/libraries/HAL_Drivers/drv_rtc.c index fb0680dfb2..278fce140b 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_rtc.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_rtc.c @@ -265,8 +265,8 @@ static rt_err_t stm32_rtc_set_secs(void *args) static const struct rt_rtc_ops stm32_rtc_ops = { stm32_rtc_init, - stm32_rtc_get_secs, /* get_secs */ - stm32_rtc_set_secs, /* set secs */ + stm32_rtc_get_secs, + stm32_rtc_set_secs, RT_NULL, RT_NULL, RT_NULL, diff --git a/components/drivers/include/drivers/rtc.h b/components/drivers/include/drivers/rtc.h index ab64dd8ec9..0bafbad7ad 100644 --- a/components/drivers/include/drivers/rtc.h +++ b/components/drivers/include/drivers/rtc.h @@ -6,7 +6,8 @@ * Change Logs: * Date Author Notes * 2012-10-10 aozima first version. - * 2021-06-11 iysheng implement RTC v2.0 + * 2021-06-11 iysheng implement RTC framework V2.0 + * 2021-07-30 Meco Man move rtc_core.h to rtc.h */ #ifndef __RTC_H__ @@ -38,7 +39,7 @@ typedef struct rt_rtc_device const struct rt_rtc_ops *ops; } rt_rtc_dev_t; -rt_err_t rt_hw_rtc_register(rt_rtc_dev_t *rtc, +rt_err_t rt_hw_rtc_register(rt_rtc_dev_t *rtc, const char *name, rt_uint32_t flag, void *data); diff --git a/components/drivers/rtc/rtc.c b/components/drivers/rtc/rtc.c index 8d61129bf8..5eabeed2dd 100644 --- a/components/drivers/rtc/rtc.c +++ b/components/drivers/rtc/rtc.c @@ -10,7 +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 v2.0 + * 2021-06-11 iysheng implement RTC framework V2.0 + * 2021-07-30 Meco Man move rtc_core.c to rtc.c */ #include @@ -21,13 +22,10 @@ #ifdef RT_USING_RTC -#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) +static rt_err_t rt_rtc_init(struct rt_device *dev) { rt_rtc_dev_t *rtc_core; @@ -38,71 +36,75 @@ static rt_err_t rt_rtc_core_init(struct rt_device *dev) return (rtc_core->ops->init()); } - return (-RT_ENOSYS); + return -RT_ENOSYS; } -static rt_err_t rt_rtc_core_open(struct rt_device *dev, rt_uint16_t oflag) +static rt_err_t rt_rtc_open(struct rt_device *dev, rt_uint16_t oflag) { - return (RT_EOK); + return RT_EOK; } -static rt_err_t rt_rtc_core_close(struct rt_device *dev) +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); + return RT_EOK; } -static rt_err_t rt_rtc_core_control(struct rt_device *dev, - int cmd, - void *args) +static rt_err_t rt_rtc_control(struct rt_device *dev, int cmd, void *args) { - rt_rtc_dev_t *rtc_core; +#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_core = (rt_rtc_dev_t *)dev; + rtc_device = (rt_rtc_dev_t *)dev; switch (cmd) { case RT_DEVICE_CTRL_RTC_GET_TIME: - ret = TRY_DO_RTC_FUNC(rtc_core, get_secs, args); + ret = TRY_DO_RTC_FUNC(rtc_device, get_secs, args); break; case RT_DEVICE_CTRL_RTC_SET_TIME: - ret = TRY_DO_RTC_FUNC(rtc_core, set_secs, args); + 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_core, get_usecs, args); + 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_core, set_usecs, args); + ret = TRY_DO_RTC_FUNC(rtc_device, set_usecs, args); break; case RT_DEVICE_CTRL_RTC_GET_ALARM: - ret = TRY_DO_RTC_FUNC(rtc_core, get_alarm, args); + ret = TRY_DO_RTC_FUNC(rtc_device, get_alarm, args); break; case RT_DEVICE_CTRL_RTC_SET_ALARM: - ret = TRY_DO_RTC_FUNC(rtc_core, set_alarm, args); + 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_core_init, - rt_rtc_core_open, - rt_rtc_core_close, + rt_rtc_init, + rt_rtc_open, + rt_rtc_close, RT_NULL, RT_NULL, - rt_rtc_core_control, + rt_rtc_control, }; -#endif +#endif /* RT_USING_DEVICE_OPS */ -rt_err_t rt_hw_rtc_register(rt_rtc_dev_t *rtc, +rt_err_t rt_hw_rtc_register(rt_rtc_dev_t *rtc, const char *name, rt_uint32_t flag, void *data) @@ -119,13 +121,13 @@ rt_err_t rt_hw_rtc_register(rt_rtc_dev_t *rtc, #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->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_core_control; -#endif + device->control = rt_rtc_control; +#endif /* RT_USING_DEVICE_OPS */ device->user_data = data; /* register a character device */ -- cgit v1.3.1 From 84db60ecfa18956840245cedc140fdec1a20e56c Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 1 Aug 2021 00:11:37 +0800 Subject: [sdio] remove rt_mmcsd_blk_init --- components/drivers/include/drivers/mmcsd_core.h | 1 - components/drivers/sdio/block_dev.c | 12 ------------ 2 files changed, 13 deletions(-) (limited to 'components/drivers/include') 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/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; -} -- cgit v1.3.1 From 94ed55f34d5f0fb6f086e84eecfe4ce3b635056f Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 1 Aug 2021 16:53:26 +0800 Subject: [workqueue] remove rt_delayed_work_init() --- components/drivers/include/ipc/workqueue.h | 9 +-------- components/drivers/src/workqueue.c | 9 ++------- components/net/sal_socket/src/sal_socket.c | 14 ++++++-------- 3 files changed, 9 insertions(+), 23 deletions(-) (limited to 'components/drivers/include') diff --git a/components/drivers/include/ipc/workqueue.h b/components/drivers/include/ipc/workqueue.h index a156145641..03904d852e 100644 --- a/components/drivers/include/ipc/workqueue.h +++ b/components/drivers/include/ipc/workqueue.h @@ -5,6 +5,7 @@ * * Change Logs: * Date Author Notes + * 2021-08-01 Meco Man remove rt_delayed_work_init() and rt_delayed_work structure */ #ifndef WORKQUEUE_H__ #define WORKQUEUE_H__ @@ -48,11 +49,6 @@ struct rt_work struct rt_workqueue *workqueue; }; -struct rt_delayed_work -{ - struct rt_work work; -}; - #ifdef RT_USING_HEAP /** * WorkQueue for DeviceDriver @@ -82,9 +78,6 @@ rt_inline void rt_work_init(struct rt_work *work, void (*work_func)(struct rt_wo work->type = 0; } -void rt_delayed_work_init(struct rt_delayed_work *work, void (*work_func)(struct rt_work *work, - void *work_data), void *work_data); - #endif /* RT_USING_HEAP */ #endif diff --git a/components/drivers/src/workqueue.c b/components/drivers/src/workqueue.c index 065c505015..8fcfd52688 100644 --- a/components/drivers/src/workqueue.c +++ b/components/drivers/src/workqueue.c @@ -5,7 +5,8 @@ * * Change Logs: * Date Author Notes - * 2017-02-27 bernard fix the re-work issue. + * 2017-02-27 Bernard fix the re-work issue. + * 2021-08-01 Meco Man remove rt_delayed_work_init() */ #include @@ -339,12 +340,6 @@ rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue *queue) return RT_EOK; } -void rt_delayed_work_init(struct rt_delayed_work *work, void (*work_func)(struct rt_work *work, - void *work_data), void *work_data) -{ - rt_work_init(&work->work, work_func, work_data); -} - #ifdef RT_USING_SYSTEM_WORKQUEUE static struct rt_workqueue *sys_workq; diff --git a/components/net/sal_socket/src/sal_socket.c b/components/net/sal_socket/src/sal_socket.c index dd3c5d3dc2..7b33038d17 100644 --- a/components/net/sal_socket/src/sal_socket.c +++ b/components/net/sal_socket/src/sal_socket.c @@ -165,7 +165,6 @@ static void check_netdev_internet_up_work(struct rt_work *work, void *work_data) struct netdev *netdev = (struct netdev *)work_data; socklen_t addr_len = sizeof(struct sockaddr_in); char send_data[SAL_INTERNET_BUFF_LEN], recv_data = 0; - struct rt_delayed_work *delay_work = (struct rt_delayed_work *)work; const char month[][SAL_INTERNET_MONTH_LEN] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; char date[SAL_INTERNET_DATE_LEN]; @@ -176,7 +175,7 @@ static void check_netdev_internet_up_work(struct rt_work *work, void *work_data) if (work) { - rt_free(delay_work); + rt_free(work); } /* get network interface socket operations */ @@ -287,18 +286,18 @@ int sal_check_netdev_internet_up(struct netdev *netdev) #ifdef SAL_INTERNET_CHECK /* workqueue for network connect */ - struct rt_delayed_work *net_work = RT_NULL; + struct rt_work *net_work = RT_NULL; - net_work = (struct rt_delayed_work *)rt_calloc(1, sizeof(struct rt_delayed_work)); + net_work = (struct rt_work *)rt_calloc(1, sizeof(struct rt_work)); if (net_work == RT_NULL) { LOG_W("No memory for network interface device(%s) delay work.", netdev->name); return -1; } - rt_delayed_work_init(net_work, check_netdev_internet_up_work, (void *)netdev); - rt_work_submit(&(net_work->work), RT_TICK_PER_SECOND); + rt_work_init(net_work, check_netdev_internet_up_work, (void *)netdev); + rt_work_submit(net_work, RT_TICK_PER_SECOND); #endif /* SAL_INTERNET_CHECK */ return 0; } @@ -619,7 +618,7 @@ int sal_accept(int socket, struct sockaddr *addr, socklen_t *addrlen) LOG_E("New socket registered failed, return error %d.", retval); return -1; } - + /* new socket create by accept should have the same netdev with server*/ new_sock->netdev = sock->netdev; /* socket structure user_data used to store the acquired new socket */ @@ -1176,4 +1175,3 @@ void sal_freeaddrinfo(struct addrinfo *ai) pf->netdb_ops->freeaddrinfo(ai); } } - -- cgit v1.3.1 From 0b4603d581f5d9f16666f0ebc1a28f2db11c70db Mon Sep 17 00:00:00 2001 From: Jackistang Date: Sat, 14 Aug 2021 11:10:43 +0800 Subject: [workqueue] 添加了 workqueue 接口的注释 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/include/ipc/workqueue.h | 7 +++ components/drivers/src/workqueue.c | 86 ++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) (limited to 'components/drivers/include') diff --git a/components/drivers/include/ipc/workqueue.h b/components/drivers/include/ipc/workqueue.h index 03904d852e..8cd86896d0 100644 --- a/components/drivers/include/ipc/workqueue.h +++ b/components/drivers/include/ipc/workqueue.h @@ -67,6 +67,13 @@ 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 /* RT_USING_SYSTEM_WORKQUEUE */ +/** + * @brief Init a work item, and bind it with a callback function. + * + * @param work A pointer to work item object. + * @param work_func A callback function will be called when this work item is being executed. + * @param work_data A user data passed to the callback function as it's second parameter. + */ rt_inline void rt_work_init(struct rt_work *work, void (*work_func)(struct rt_work *work, void *work_data), void *work_data) { diff --git a/components/drivers/src/workqueue.c b/components/drivers/src/workqueue.c index 8fcfd52688..897ee7af0b 100644 --- a/components/drivers/src/workqueue.c +++ b/components/drivers/src/workqueue.c @@ -209,6 +209,15 @@ static void _delayed_work_timeout_handler(void *parameter) } } +/** + * @brief Create a work queue, which contains a thread. + * + * @param name The name for work queue thread. + * @param stack_size The stack size for work queue thread. + * @param priority The priority for work queue thread. + * + * @return Return a pointer to workqueue object. When the return value is RT_NULL, it means the creation failed. + */ struct rt_workqueue *rt_workqueue_create(const char *name, rt_uint16_t stack_size, rt_uint8_t priority) { struct rt_workqueue *queue = RT_NULL; @@ -236,6 +245,13 @@ struct rt_workqueue *rt_workqueue_create(const char *name, rt_uint16_t stack_siz return queue; } +/** + * @brief Destroy a work queue. + * + * @param queue A pointer to workqueue object. + * + * @return RT_EOK Success. + */ rt_err_t rt_workqueue_destroy(struct rt_workqueue *queue) { RT_ASSERT(queue != RT_NULL); @@ -248,6 +264,15 @@ rt_err_t rt_workqueue_destroy(struct rt_workqueue *queue) return RT_EOK; } +/** + * @brief Submit a work item to the work queue immediately. + * + * @param queue A pointer to workqueue object. + * @param work A pointer to work item object. + * + * @return RT_EOK Success. + * @return -RT_EBUSY This work item is been executing now. + */ rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work) { RT_ASSERT(queue != RT_NULL); @@ -256,6 +281,17 @@ rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work) return _workqueue_submit_work(queue, work, 0); } +/** + * @brief Submit a work item to the work queue with a delay of time. + * + * @param queue A pointer to workqueue object. + * @param work A pointer to work item object. + * @param time This work item will be delayed by time (unit: an OS tick) before it's been submitted to the work queue. + * + * @return RT_EOK Success. + * @return -RT_EBUSY This work item is been executing now. + * @return -RT_ERROR Time is invalid. + */ rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work, rt_tick_t time) { RT_ASSERT(queue != RT_NULL); @@ -264,6 +300,14 @@ rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *wo return _workqueue_submit_work(queue, work, time); } +/** + * @brief This function submit a work item to the work queue. This work item will be executed immediately after the current work item is executed. + * + * @param queue A pointer to workqueue object. + * @param work A pointer to work item object. + * + * @return RT_EOK Success. + */ rt_err_t rt_workqueue_critical_work(struct rt_workqueue *queue, struct rt_work *work) { rt_base_t level; @@ -291,6 +335,15 @@ rt_err_t rt_workqueue_critical_work(struct rt_workqueue *queue, struct rt_work * return RT_EOK; } +/** + * @brief Cancel a work item in the work queue. + * + * @param queue A pointer to workqueue object. + * @param work A pointer to work item object. + * + * @return RT_EOK Success. + * @return -RT_EBUSY This work item is been executing now. + */ rt_err_t rt_workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *work) { RT_ASSERT(work != RT_NULL); @@ -298,6 +351,14 @@ rt_err_t rt_workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *wo return _workqueue_cancel_work(queue, work); } +/** + * @brief Cancel a work item in the work queue. If the work item is been executing now, this function will block until it is done. + * + * @param queue A pointer to workqueue object. + * @param work A pointer to work item object. + * + * @return RT_EOK Success. + */ rt_err_t rt_workqueue_cancel_work_sync(struct rt_workqueue *queue, struct rt_work *work) { RT_ASSERT(queue != RT_NULL); @@ -316,6 +377,13 @@ rt_err_t rt_workqueue_cancel_work_sync(struct rt_workqueue *queue, struct rt_wor return RT_EOK; } +/** + * @brief This function will cancel all work item in work queue. + * + * @param queue A pointer to workqueue object. + * + * @return RT_EOK Success. + */ rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue *queue) { struct rt_work *work; @@ -343,11 +411,29 @@ rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue *queue) #ifdef RT_USING_SYSTEM_WORKQUEUE static struct rt_workqueue *sys_workq; +/** + * @brief Submit a work item to the system work queue with a delay of time. + * + * @param work A pointer to work item object. + * @param time This work item will be delayed by time (unit: an OS tick) before it's been submitted to system work queue. + * + * @return RT_EOK Success. + * @return -RT_EBUSY This work item is been executing now. + * @return -RT_ERROR Time is invalid. + */ rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t time) { return rt_workqueue_submit_work(sys_workq, work, time); } +/** + * @brief Cancel a work item in system work queue. + * + * @param work A pointer to work item object. + * + * @return RT_EOK Success. + * @return -RT_EBUSY This work item is been executing now. + */ rt_err_t rt_work_cancel(struct rt_work *work) { return rt_workqueue_cancel_work(sys_workq, work); -- cgit v1.3.1 From 1b7468979f7b697dcbff49dfa5f7f5e92acded75 Mon Sep 17 00:00:00 2001 From: Jackistang Date: Sat, 14 Aug 2021 13:47:05 +0800 Subject: [ringbuffer] 添加 ringbuffer 的接口注释 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/include/ipc/ringbuffer.h | 8 +++ components/drivers/include/ipc/workqueue.h | 1 + components/drivers/src/ringbuffer.c | 91 +++++++++++++++++++++++++---- components/drivers/src/workqueue.c | 1 + 4 files changed, 90 insertions(+), 11 deletions(-) (limited to 'components/drivers/include') diff --git a/components/drivers/include/ipc/ringbuffer.h b/components/drivers/include/ipc/ringbuffer.h index 71c4801253..324d87b9b9 100644 --- a/components/drivers/include/ipc/ringbuffer.h +++ b/components/drivers/include/ipc/ringbuffer.h @@ -5,6 +5,7 @@ * * Change Logs: * Date Author Notes + * 2021-08-14 Jackistang add commets for function inferface. */ #ifndef RINGBUFFER_H__ #define RINGBUFFER_H__ @@ -80,6 +81,13 @@ struct rt_ringbuffer* rt_ringbuffer_create(rt_uint16_t length); void rt_ringbuffer_destroy(struct rt_ringbuffer *rb); #endif +/** + * @brief Get buffer size of the ringbuffer object. + * + * @param rb A pointer to the ringbuffer object. + * + * @return Buffer size. + */ rt_inline rt_uint16_t rt_ringbuffer_get_size(struct rt_ringbuffer *rb) { RT_ASSERT(rb != RT_NULL); diff --git a/components/drivers/include/ipc/workqueue.h b/components/drivers/include/ipc/workqueue.h index 8cd86896d0..31295c29be 100644 --- a/components/drivers/include/ipc/workqueue.h +++ b/components/drivers/include/ipc/workqueue.h @@ -6,6 +6,7 @@ * Change Logs: * Date Author Notes * 2021-08-01 Meco Man remove rt_delayed_work_init() and rt_delayed_work structure + * 2021-08-14 Jackistang add commets for rt_work_init() */ #ifndef WORKQUEUE_H__ #define WORKQUEUE_H__ diff --git a/components/drivers/src/ringbuffer.c b/components/drivers/src/ringbuffer.c index f01a594609..099d48691e 100644 --- a/components/drivers/src/ringbuffer.c +++ b/components/drivers/src/ringbuffer.c @@ -9,6 +9,7 @@ * 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 + * 2021-08-14 Jackistang add commets for function inferface. */ #include @@ -27,6 +28,13 @@ rt_inline enum rt_ringbuffer_state rt_ringbuffer_status(struct rt_ringbuffer *rb return RT_RINGBUFFER_HALFFULL; } +/** + * @brief Init a ringbuffer object with a given buffer. + * + * @param rb A pointer to the ringbuffer object. + * @param pool A pointer to the buffer. + * @param size Size of the buffer in bytes. + */ void rt_ringbuffer_init(struct rt_ringbuffer *rb, rt_uint8_t *pool, rt_int16_t size) @@ -45,7 +53,13 @@ void rt_ringbuffer_init(struct rt_ringbuffer *rb, RTM_EXPORT(rt_ringbuffer_init); /** - * put a block of data into ring buffer + * @brief Put a block of data into the ringbuffer. If the size of ringbuffer is not enough, it will discard out-of-range data. + * + * @param rb A pointer to the ringbuffer object. + * @param ptr A pointer to the data buffer. + * @param length The size of data in bytes. + * + * @return Return the size in bytes put into the ringbuffer actually. */ rt_size_t rt_ringbuffer_put(struct rt_ringbuffer *rb, const rt_uint8_t *ptr, @@ -92,9 +106,13 @@ rt_size_t rt_ringbuffer_put(struct rt_ringbuffer *rb, RTM_EXPORT(rt_ringbuffer_put); /** - * put a block of data into ring buffer - * - * When the buffer is full, it will discard the old data. + * @brief Put a block of data into the ringbuffer. If the size of ringbuffer is not enough, it will overwrite the existing data in the ringbuffer. + * + * @param rb A pointer to the ringbuffer object. + * @param ptr A pointer to the data buffer. + * @param length The size of data in bytes. + * + * @return Return the size in bytes put into the ringbuffer actually. */ rt_size_t rt_ringbuffer_put_force(struct rt_ringbuffer *rb, const rt_uint8_t *ptr, @@ -149,7 +167,13 @@ rt_size_t rt_ringbuffer_put_force(struct rt_ringbuffer *rb, RTM_EXPORT(rt_ringbuffer_put_force); /** - * get data from ring buffer + * @brief Get a block of data from the ringbuffer. + * + * @param rb A pointer to the ringbuffer. + * @param ptr A pointer to the data buffer. + * @param length The size of data we want to read from the ringbuffer. + * + * @return Return the size of data we read from the ringbuffer actually. */ rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb, rt_uint8_t *ptr, @@ -198,6 +222,15 @@ RTM_EXPORT(rt_ringbuffer_get); /** * peak data from ring buffer */ + +/** + * @brief Peak data from the ringbuffer. + * + * @param rb A pointer to the ringbuffer. + * @param ptr When this function return, *ptr is a pointer to the first character of ringbuffer. + * + * @return Return the size of ringbuffer. + */ rt_size_t rt_ringbuffer_peak(struct rt_ringbuffer *rb, rt_uint8_t **ptr) { RT_ASSERT(rb != RT_NULL); @@ -230,7 +263,12 @@ rt_size_t rt_ringbuffer_peak(struct rt_ringbuffer *rb, rt_uint8_t **ptr) RTM_EXPORT(rt_ringbuffer_peak); /** - * put a character into ring buffer + * @brief Put a character into the ringbuffer. If ringbuffer is full, This operation will fail. + * + * @param rb A pointer to the ringbuffer object. + * @param ch A character to be put into the ringbuffer. + * + * @return Return the size in bytes put into the ringbuffer. If return 0, it means the ringbuffer if full. If return 1, it means success. */ rt_size_t rt_ringbuffer_putchar(struct rt_ringbuffer *rb, const rt_uint8_t ch) { @@ -258,9 +296,12 @@ rt_size_t rt_ringbuffer_putchar(struct rt_ringbuffer *rb, const rt_uint8_t ch) RTM_EXPORT(rt_ringbuffer_putchar); /** - * put a character into ring buffer - * - * When the buffer is full, it will discard one old data. + * @brief Put a character into the ringbuffer. If ringbuffer is full, it will discard one old data and put into a new data. + * + * @param rb A pointer to the ringbuffer object. + * @param ch A character to be put into the ringbuffer. + * + * @return Return the size in bytes put into the ringbuffer. Always return 1. */ rt_size_t rt_ringbuffer_putchar_force(struct rt_ringbuffer *rb, const rt_uint8_t ch) { @@ -297,6 +338,16 @@ RTM_EXPORT(rt_ringbuffer_putchar_force); /** * get a character from a ringbuffer */ + +/** + * @brief Get a character from the ringbuffer. + * + * @param rb The pointer to ringbuffer object. + * @param ch The buffer to store character read from ringbuffer. + * + * @return 0 Ringbuffer is empty. + * @return 1 Success + */ rt_size_t rt_ringbuffer_getchar(struct rt_ringbuffer *rb, rt_uint8_t *ch) { RT_ASSERT(rb != RT_NULL); @@ -323,7 +374,11 @@ rt_size_t rt_ringbuffer_getchar(struct rt_ringbuffer *rb, rt_uint8_t *ch) RTM_EXPORT(rt_ringbuffer_getchar); /** - * get the size of data in rb + * @brief Get the size of data in the ringbuffer in bytes. + * + * @param rb The pointer to ringbuffer object. + * + * @return Return the size of data in the ringbuffer in bytes. */ rt_size_t rt_ringbuffer_data_len(struct rt_ringbuffer *rb) { @@ -344,7 +399,9 @@ rt_size_t rt_ringbuffer_data_len(struct rt_ringbuffer *rb) RTM_EXPORT(rt_ringbuffer_data_len); /** - * empty the rb + * @brief Reset the ringbuffer object, and clear all contents in the buffer. + * + * @param rb A pointer to the ringbuffer object. */ void rt_ringbuffer_reset(struct rt_ringbuffer *rb) { @@ -359,6 +416,13 @@ RTM_EXPORT(rt_ringbuffer_reset); #ifdef RT_USING_HEAP +/** + * @brief Create a ringbuffer object with a given size. + * + * @param size Size of the buffer in bytes. + * + * @return Return a pointer to ringbuffer object. When the return value is RT_NULL, it means the creation failed. + */ struct rt_ringbuffer* rt_ringbuffer_create(rt_uint16_t size) { struct rt_ringbuffer *rb; @@ -386,6 +450,11 @@ exit: } RTM_EXPORT(rt_ringbuffer_create); +/** + * @brief Destroy a ringbuffer object, which is created by rt_ringbuffer_create() . + * + * @param rb A pointer to the ringbuffer object. + */ void rt_ringbuffer_destroy(struct rt_ringbuffer *rb) { RT_ASSERT(rb != RT_NULL); diff --git a/components/drivers/src/workqueue.c b/components/drivers/src/workqueue.c index 897ee7af0b..e37af37658 100644 --- a/components/drivers/src/workqueue.c +++ b/components/drivers/src/workqueue.c @@ -7,6 +7,7 @@ * Date Author Notes * 2017-02-27 Bernard fix the re-work issue. * 2021-08-01 Meco Man remove rt_delayed_work_init() + * 2021-08-14 Jackistang add commets for function interface. */ #include -- cgit v1.3.1 From 99de1a622003d100c29abc084669cfc1263b1614 Mon Sep 17 00:00:00 2001 From: Jackistang Date: Sat, 14 Aug 2021 14:32:58 +0800 Subject: format code --- components/drivers/include/ipc/ringbuffer.h | 4 +-- components/drivers/include/ipc/workqueue.h | 2 +- components/drivers/src/ringbuffer.c | 44 ++++++++++++++--------------- components/drivers/src/workqueue.c | 44 ++++++++++++++--------------- 4 files changed, 47 insertions(+), 47 deletions(-) (limited to 'components/drivers/include') diff --git a/components/drivers/include/ipc/ringbuffer.h b/components/drivers/include/ipc/ringbuffer.h index 324d87b9b9..a9d74b064d 100644 --- a/components/drivers/include/ipc/ringbuffer.h +++ b/components/drivers/include/ipc/ringbuffer.h @@ -83,9 +83,9 @@ void rt_ringbuffer_destroy(struct rt_ringbuffer *rb); /** * @brief Get buffer size of the ringbuffer object. - * + * * @param rb A pointer to the ringbuffer object. - * + * * @return Buffer size. */ rt_inline rt_uint16_t rt_ringbuffer_get_size(struct rt_ringbuffer *rb) diff --git a/components/drivers/include/ipc/workqueue.h b/components/drivers/include/ipc/workqueue.h index 31295c29be..d479d0ec95 100644 --- a/components/drivers/include/ipc/workqueue.h +++ b/components/drivers/include/ipc/workqueue.h @@ -70,7 +70,7 @@ rt_err_t rt_work_cancel(struct rt_work *work); /** * @brief Init a work item, and bind it with a callback function. - * + * * @param work A pointer to work item object. * @param work_func A callback function will be called when this work item is being executed. * @param work_data A user data passed to the callback function as it's second parameter. diff --git a/components/drivers/src/ringbuffer.c b/components/drivers/src/ringbuffer.c index 099d48691e..b42c2ecefc 100644 --- a/components/drivers/src/ringbuffer.c +++ b/components/drivers/src/ringbuffer.c @@ -30,7 +30,7 @@ rt_inline enum rt_ringbuffer_state rt_ringbuffer_status(struct rt_ringbuffer *rb /** * @brief Init a ringbuffer object with a given buffer. - * + * * @param rb A pointer to the ringbuffer object. * @param pool A pointer to the buffer. * @param size Size of the buffer in bytes. @@ -54,11 +54,11 @@ RTM_EXPORT(rt_ringbuffer_init); /** * @brief Put a block of data into the ringbuffer. If the size of ringbuffer is not enough, it will discard out-of-range data. - * + * * @param rb A pointer to the ringbuffer object. * @param ptr A pointer to the data buffer. * @param length The size of data in bytes. - * + * * @return Return the size in bytes put into the ringbuffer actually. */ rt_size_t rt_ringbuffer_put(struct rt_ringbuffer *rb, @@ -107,11 +107,11 @@ RTM_EXPORT(rt_ringbuffer_put); /** * @brief Put a block of data into the ringbuffer. If the size of ringbuffer is not enough, it will overwrite the existing data in the ringbuffer. - * + * * @param rb A pointer to the ringbuffer object. * @param ptr A pointer to the data buffer. * @param length The size of data in bytes. - * + * * @return Return the size in bytes put into the ringbuffer actually. */ rt_size_t rt_ringbuffer_put_force(struct rt_ringbuffer *rb, @@ -168,11 +168,11 @@ RTM_EXPORT(rt_ringbuffer_put_force); /** * @brief Get a block of data from the ringbuffer. - * + * * @param rb A pointer to the ringbuffer. * @param ptr A pointer to the data buffer. * @param length The size of data we want to read from the ringbuffer. - * + * * @return Return the size of data we read from the ringbuffer actually. */ rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb, @@ -225,10 +225,10 @@ RTM_EXPORT(rt_ringbuffer_get); /** * @brief Peak data from the ringbuffer. - * + * * @param rb A pointer to the ringbuffer. * @param ptr When this function return, *ptr is a pointer to the first character of ringbuffer. - * + * * @return Return the size of ringbuffer. */ rt_size_t rt_ringbuffer_peak(struct rt_ringbuffer *rb, rt_uint8_t **ptr) @@ -264,10 +264,10 @@ RTM_EXPORT(rt_ringbuffer_peak); /** * @brief Put a character into the ringbuffer. If ringbuffer is full, This operation will fail. - * + * * @param rb A pointer to the ringbuffer object. * @param ch A character to be put into the ringbuffer. - * + * * @return Return the size in bytes put into the ringbuffer. If return 0, it means the ringbuffer if full. If return 1, it means success. */ rt_size_t rt_ringbuffer_putchar(struct rt_ringbuffer *rb, const rt_uint8_t ch) @@ -297,10 +297,10 @@ RTM_EXPORT(rt_ringbuffer_putchar); /** * @brief Put a character into the ringbuffer. If ringbuffer is full, it will discard one old data and put into a new data. - * + * * @param rb A pointer to the ringbuffer object. * @param ch A character to be put into the ringbuffer. - * + * * @return Return the size in bytes put into the ringbuffer. Always return 1. */ rt_size_t rt_ringbuffer_putchar_force(struct rt_ringbuffer *rb, const rt_uint8_t ch) @@ -341,10 +341,10 @@ RTM_EXPORT(rt_ringbuffer_putchar_force); /** * @brief Get a character from the ringbuffer. - * + * * @param rb The pointer to ringbuffer object. * @param ch The buffer to store character read from ringbuffer. - * + * * @return 0 Ringbuffer is empty. * @return 1 Success */ @@ -375,9 +375,9 @@ RTM_EXPORT(rt_ringbuffer_getchar); /** * @brief Get the size of data in the ringbuffer in bytes. - * + * * @param rb The pointer to ringbuffer object. - * + * * @return Return the size of data in the ringbuffer in bytes. */ rt_size_t rt_ringbuffer_data_len(struct rt_ringbuffer *rb) @@ -400,7 +400,7 @@ RTM_EXPORT(rt_ringbuffer_data_len); /** * @brief Reset the ringbuffer object, and clear all contents in the buffer. - * + * * @param rb A pointer to the ringbuffer object. */ void rt_ringbuffer_reset(struct rt_ringbuffer *rb) @@ -418,12 +418,12 @@ RTM_EXPORT(rt_ringbuffer_reset); /** * @brief Create a ringbuffer object with a given size. - * + * * @param size Size of the buffer in bytes. - * + * * @return Return a pointer to ringbuffer object. When the return value is RT_NULL, it means the creation failed. */ -struct rt_ringbuffer* rt_ringbuffer_create(rt_uint16_t size) +struct rt_ringbuffer *rt_ringbuffer_create(rt_uint16_t size) { struct rt_ringbuffer *rb; rt_uint8_t *pool; @@ -452,7 +452,7 @@ RTM_EXPORT(rt_ringbuffer_create); /** * @brief Destroy a ringbuffer object, which is created by rt_ringbuffer_create() . - * + * * @param rb A pointer to the ringbuffer object. */ void rt_ringbuffer_destroy(struct rt_ringbuffer *rb) diff --git a/components/drivers/src/workqueue.c b/components/drivers/src/workqueue.c index e37af37658..37733a1f65 100644 --- a/components/drivers/src/workqueue.c +++ b/components/drivers/src/workqueue.c @@ -212,11 +212,11 @@ static void _delayed_work_timeout_handler(void *parameter) /** * @brief Create a work queue, which contains a thread. - * + * * @param name The name for work queue thread. * @param stack_size The stack size for work queue thread. * @param priority The priority for work queue thread. - * + * * @return Return a pointer to workqueue object. When the return value is RT_NULL, it means the creation failed. */ struct rt_workqueue *rt_workqueue_create(const char *name, rt_uint16_t stack_size, rt_uint8_t priority) @@ -248,10 +248,10 @@ struct rt_workqueue *rt_workqueue_create(const char *name, rt_uint16_t stack_siz /** * @brief Destroy a work queue. - * + * * @param queue A pointer to workqueue object. - * - * @return RT_EOK Success. + * + * @return RT_EOK Success. */ rt_err_t rt_workqueue_destroy(struct rt_workqueue *queue) { @@ -267,10 +267,10 @@ rt_err_t rt_workqueue_destroy(struct rt_workqueue *queue) /** * @brief Submit a work item to the work queue immediately. - * + * * @param queue A pointer to workqueue object. * @param work A pointer to work item object. - * + * * @return RT_EOK Success. * @return -RT_EBUSY This work item is been executing now. */ @@ -284,11 +284,11 @@ rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work) /** * @brief Submit a work item to the work queue with a delay of time. - * + * * @param queue A pointer to workqueue object. * @param work A pointer to work item object. * @param time This work item will be delayed by time (unit: an OS tick) before it's been submitted to the work queue. - * + * * @return RT_EOK Success. * @return -RT_EBUSY This work item is been executing now. * @return -RT_ERROR Time is invalid. @@ -303,11 +303,11 @@ rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *wo /** * @brief This function submit a work item to the work queue. This work item will be executed immediately after the current work item is executed. - * + * * @param queue A pointer to workqueue object. * @param work A pointer to work item object. - * - * @return RT_EOK Success. + * + * @return RT_EOK Success. */ rt_err_t rt_workqueue_critical_work(struct rt_workqueue *queue, struct rt_work *work) { @@ -338,10 +338,10 @@ rt_err_t rt_workqueue_critical_work(struct rt_workqueue *queue, struct rt_work * /** * @brief Cancel a work item in the work queue. - * + * * @param queue A pointer to workqueue object. * @param work A pointer to work item object. - * + * * @return RT_EOK Success. * @return -RT_EBUSY This work item is been executing now. */ @@ -354,10 +354,10 @@ rt_err_t rt_workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *wo /** * @brief Cancel a work item in the work queue. If the work item is been executing now, this function will block until it is done. - * + * * @param queue A pointer to workqueue object. * @param work A pointer to work item object. - * + * * @return RT_EOK Success. */ rt_err_t rt_workqueue_cancel_work_sync(struct rt_workqueue *queue, struct rt_work *work) @@ -380,9 +380,9 @@ rt_err_t rt_workqueue_cancel_work_sync(struct rt_workqueue *queue, struct rt_wor /** * @brief This function will cancel all work item in work queue. - * + * * @param queue A pointer to workqueue object. - * + * * @return RT_EOK Success. */ rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue *queue) @@ -414,10 +414,10 @@ static struct rt_workqueue *sys_workq; /** * @brief Submit a work item to the system work queue with a delay of time. - * + * * @param work A pointer to work item object. * @param time This work item will be delayed by time (unit: an OS tick) before it's been submitted to system work queue. - * + * * @return RT_EOK Success. * @return -RT_EBUSY This work item is been executing now. * @return -RT_ERROR Time is invalid. @@ -429,9 +429,9 @@ rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t time) /** * @brief Cancel a work item in system work queue. - * + * * @param work A pointer to work item object. - * + * * @return RT_EOK Success. * @return -RT_EBUSY This work item is been executing now. */ -- cgit v1.3.1 From 6173c9d7d5933adbf2ed374034d34608bbdd3c58 Mon Sep 17 00:00:00 2001 From: Jackistang Date: Tue, 17 Aug 2021 22:44:29 +0800 Subject: fix comments error in ringbuffer and workqueue. --- components/drivers/include/ipc/ringbuffer.h | 6 +-- components/drivers/include/ipc/workqueue.h | 8 +-- components/drivers/src/ringbuffer.c | 84 +++++++++++++---------------- components/drivers/src/workqueue.c | 16 +++--- 4 files changed, 53 insertions(+), 61 deletions(-) (limited to 'components/drivers/include') diff --git a/components/drivers/include/ipc/ringbuffer.h b/components/drivers/include/ipc/ringbuffer.h index a9d74b064d..da68c5c1fa 100644 --- a/components/drivers/include/ipc/ringbuffer.h +++ b/components/drivers/include/ipc/ringbuffer.h @@ -5,7 +5,7 @@ * * Change Logs: * Date Author Notes - * 2021-08-14 Jackistang add commets for function inferface. + * 2021-08-14 Jackistang add comments for function interface. */ #ifndef RINGBUFFER_H__ #define RINGBUFFER_H__ @@ -82,9 +82,9 @@ void rt_ringbuffer_destroy(struct rt_ringbuffer *rb); #endif /** - * @brief Get buffer size of the ringbuffer object. + * @brief Get buffer size of the ring buffer object. * - * @param rb A pointer to the ringbuffer object. + * @param rb A pointer to the ring buffer object. * * @return Buffer size. */ diff --git a/components/drivers/include/ipc/workqueue.h b/components/drivers/include/ipc/workqueue.h index d479d0ec95..70744ad668 100644 --- a/components/drivers/include/ipc/workqueue.h +++ b/components/drivers/include/ipc/workqueue.h @@ -6,7 +6,7 @@ * Change Logs: * Date Author Notes * 2021-08-01 Meco Man remove rt_delayed_work_init() and rt_delayed_work structure - * 2021-08-14 Jackistang add commets for rt_work_init() + * 2021-08-14 Jackistang add comments for rt_work_init() */ #ifndef WORKQUEUE_H__ #define WORKQUEUE_H__ @@ -69,10 +69,10 @@ rt_err_t rt_work_cancel(struct rt_work *work); #endif /* RT_USING_SYSTEM_WORKQUEUE */ /** - * @brief Init a work item, and bind it with a callback function. + * @brief Initialize a work item, binding with a callback function. * - * @param work A pointer to work item object. - * @param work_func A callback function will be called when this work item is being executed. + * @param work A pointer to the work item object. + * @param work_func A callback function will be called when this work item is executed. * @param work_data A user data passed to the callback function as it's second parameter. */ rt_inline void rt_work_init(struct rt_work *work, void (*work_func)(struct rt_work *work, void *work_data), diff --git a/components/drivers/src/ringbuffer.c b/components/drivers/src/ringbuffer.c index b42c2ecefc..417982a1b7 100644 --- a/components/drivers/src/ringbuffer.c +++ b/components/drivers/src/ringbuffer.c @@ -9,7 +9,7 @@ * 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 - * 2021-08-14 Jackistang add commets for function inferface. + * 2021-08-14 Jackistang add comments for function interface. */ #include @@ -29,9 +29,9 @@ rt_inline enum rt_ringbuffer_state rt_ringbuffer_status(struct rt_ringbuffer *rb } /** - * @brief Init a ringbuffer object with a given buffer. + * @brief Initialize a ring buffer object with a given buffer. * - * @param rb A pointer to the ringbuffer object. + * @param rb A pointer to the ring buffer object. * @param pool A pointer to the buffer. * @param size Size of the buffer in bytes. */ @@ -53,13 +53,13 @@ void rt_ringbuffer_init(struct rt_ringbuffer *rb, RTM_EXPORT(rt_ringbuffer_init); /** - * @brief Put a block of data into the ringbuffer. If the size of ringbuffer is not enough, it will discard out-of-range data. + * @brief Put a block of data into the ring buffer. If the size of ring buffer is not enough, it will discard out-of-range data. * - * @param rb A pointer to the ringbuffer object. + * @param rb A pointer to the ring buffer object. * @param ptr A pointer to the data buffer. * @param length The size of data in bytes. * - * @return Return the size in bytes put into the ringbuffer actually. + * @return Return the size in bytes put into the ring buffer actually. */ rt_size_t rt_ringbuffer_put(struct rt_ringbuffer *rb, const rt_uint8_t *ptr, @@ -106,13 +106,13 @@ rt_size_t rt_ringbuffer_put(struct rt_ringbuffer *rb, RTM_EXPORT(rt_ringbuffer_put); /** - * @brief Put a block of data into the ringbuffer. If the size of ringbuffer is not enough, it will overwrite the existing data in the ringbuffer. + * @brief Put a block of data into the ring buffer. If the size of ring buffer is not enough, it will overwrite the existing data in the ring buffer. * - * @param rb A pointer to the ringbuffer object. + * @param rb A pointer to the ring buffer object. * @param ptr A pointer to the data buffer. * @param length The size of data in bytes. * - * @return Return the size in bytes put into the ringbuffer actually. + * @return Return the byte size of the data actually put into the ring buffer. */ rt_size_t rt_ringbuffer_put_force(struct rt_ringbuffer *rb, const rt_uint8_t *ptr, @@ -167,13 +167,13 @@ rt_size_t rt_ringbuffer_put_force(struct rt_ringbuffer *rb, RTM_EXPORT(rt_ringbuffer_put_force); /** - * @brief Get a block of data from the ringbuffer. + * @brief Get data from the ring buffer. * - * @param rb A pointer to the ringbuffer. + * @param rb A pointer to the ring buffer. * @param ptr A pointer to the data buffer. - * @param length The size of data we want to read from the ringbuffer. + * @param length The size of data we want to read from the ring buffer. * - * @return Return the size of data we read from the ringbuffer actually. + * @return Return the data size that we read from the ring buffer. */ rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb, rt_uint8_t *ptr, @@ -220,16 +220,12 @@ rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb, RTM_EXPORT(rt_ringbuffer_get); /** - * peak data from ring buffer - */ - -/** - * @brief Peak data from the ringbuffer. + * @brief Peak data from the ring buffer. * * @param rb A pointer to the ringbuffer. - * @param ptr When this function return, *ptr is a pointer to the first character of ringbuffer. + * @param ptr When this function return, *ptr is a pointer to the first readable byte of the ring buffer. * - * @return Return the size of ringbuffer. + * @return Return the size of ring buffer. */ rt_size_t rt_ringbuffer_peak(struct rt_ringbuffer *rb, rt_uint8_t **ptr) { @@ -263,12 +259,12 @@ rt_size_t rt_ringbuffer_peak(struct rt_ringbuffer *rb, rt_uint8_t **ptr) RTM_EXPORT(rt_ringbuffer_peak); /** - * @brief Put a character into the ringbuffer. If ringbuffer is full, This operation will fail. + * @brief Put a byte into the ring buffer. If ring buffer is full, this operation will fail. * - * @param rb A pointer to the ringbuffer object. - * @param ch A character to be put into the ringbuffer. + * @param rb A pointer to the ring buffer object. + * @param ch A byte to be put into the ring buffer. * - * @return Return the size in bytes put into the ringbuffer. If return 0, it means the ringbuffer if full. If return 1, it means success. + * @return Return the size in bytes put into the ring buffer. The ring buffer is full if returns 0. Otherwise, it will return 1. */ rt_size_t rt_ringbuffer_putchar(struct rt_ringbuffer *rb, const rt_uint8_t ch) { @@ -296,12 +292,12 @@ rt_size_t rt_ringbuffer_putchar(struct rt_ringbuffer *rb, const rt_uint8_t ch) RTM_EXPORT(rt_ringbuffer_putchar); /** - * @brief Put a character into the ringbuffer. If ringbuffer is full, it will discard one old data and put into a new data. + * @brief Put a byte into the ring buffer. If ring buffer is full, it will discard one old data and put into a new data. * - * @param rb A pointer to the ringbuffer object. - * @param ch A character to be put into the ringbuffer. + * @param rb A pointer to the ring buffer object. + * @param ch A byte to be put into the ring buffer. * - * @return Return the size in bytes put into the ringbuffer. Always return 1. + * @return Return the size in bytes put into the ring buffer. Always return 1. */ rt_size_t rt_ringbuffer_putchar_force(struct rt_ringbuffer *rb, const rt_uint8_t ch) { @@ -336,16 +332,12 @@ rt_size_t rt_ringbuffer_putchar_force(struct rt_ringbuffer *rb, const rt_uint8_t RTM_EXPORT(rt_ringbuffer_putchar_force); /** - * get a character from a ringbuffer - */ - -/** - * @brief Get a character from the ringbuffer. + * @brief Get a byte from the ring buffer. * - * @param rb The pointer to ringbuffer object. - * @param ch The buffer to store character read from ringbuffer. + * @param rb The pointer to ring buffer object. + * @param ch The buffer to store byte read from ring buffer. * - * @return 0 Ringbuffer is empty. + * @return 0 ring buffer is empty. * @return 1 Success */ rt_size_t rt_ringbuffer_getchar(struct rt_ringbuffer *rb, rt_uint8_t *ch) @@ -356,7 +348,7 @@ rt_size_t rt_ringbuffer_getchar(struct rt_ringbuffer *rb, rt_uint8_t *ch) if (!rt_ringbuffer_data_len(rb)) return 0; - /* put character */ + /* put byte */ *ch = rb->buffer_ptr[rb->read_index]; if (rb->read_index == rb->buffer_size-1) @@ -374,11 +366,11 @@ rt_size_t rt_ringbuffer_getchar(struct rt_ringbuffer *rb, rt_uint8_t *ch) RTM_EXPORT(rt_ringbuffer_getchar); /** - * @brief Get the size of data in the ringbuffer in bytes. + * @brief Get the size of data in the ring buffer in bytes. * - * @param rb The pointer to ringbuffer object. + * @param rb The pointer to ring buffer object. * - * @return Return the size of data in the ringbuffer in bytes. + * @return Return the size of data in the ring buffer in bytes. */ rt_size_t rt_ringbuffer_data_len(struct rt_ringbuffer *rb) { @@ -399,9 +391,9 @@ rt_size_t rt_ringbuffer_data_len(struct rt_ringbuffer *rb) RTM_EXPORT(rt_ringbuffer_data_len); /** - * @brief Reset the ringbuffer object, and clear all contents in the buffer. + * @brief Reset the ring buffer object, and clear all contents in the buffer. * - * @param rb A pointer to the ringbuffer object. + * @param rb A pointer to the ring buffer object. */ void rt_ringbuffer_reset(struct rt_ringbuffer *rb) { @@ -417,11 +409,11 @@ RTM_EXPORT(rt_ringbuffer_reset); #ifdef RT_USING_HEAP /** - * @brief Create a ringbuffer object with a given size. + * @brief Create a ring buffer object with a given size. * * @param size Size of the buffer in bytes. * - * @return Return a pointer to ringbuffer object. When the return value is RT_NULL, it means the creation failed. + * @return Return a pointer to ring buffer object. When the return value is RT_NULL, it means the creation failed. */ struct rt_ringbuffer *rt_ringbuffer_create(rt_uint16_t size) { @@ -451,9 +443,9 @@ exit: RTM_EXPORT(rt_ringbuffer_create); /** - * @brief Destroy a ringbuffer object, which is created by rt_ringbuffer_create() . + * @brief Destroy a ring buffer object, which is created by rt_ringbuffer_create() . * - * @param rb A pointer to the ringbuffer object. + * @param rb A pointer to the ring buffer object. */ void rt_ringbuffer_destroy(struct rt_ringbuffer *rb) { diff --git a/components/drivers/src/workqueue.c b/components/drivers/src/workqueue.c index 37733a1f65..60472d9ca4 100644 --- a/components/drivers/src/workqueue.c +++ b/components/drivers/src/workqueue.c @@ -7,7 +7,7 @@ * Date Author Notes * 2017-02-27 Bernard fix the re-work issue. * 2021-08-01 Meco Man remove rt_delayed_work_init() - * 2021-08-14 Jackistang add commets for function interface. + * 2021-08-14 Jackistang add comments for function interface. */ #include @@ -217,7 +217,7 @@ static void _delayed_work_timeout_handler(void *parameter) * @param stack_size The stack size for work queue thread. * @param priority The priority for work queue thread. * - * @return Return a pointer to workqueue object. When the return value is RT_NULL, it means the creation failed. + * @return Return a pointer to workqueue object. It will return RT_NULL if failed. */ struct rt_workqueue *rt_workqueue_create(const char *name, rt_uint16_t stack_size, rt_uint8_t priority) { @@ -272,7 +272,7 @@ rt_err_t rt_workqueue_destroy(struct rt_workqueue *queue) * @param work A pointer to work item object. * * @return RT_EOK Success. - * @return -RT_EBUSY This work item is been executing now. + * @return -RT_EBUSY This work item is executing. */ rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work) { @@ -287,10 +287,10 @@ rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work) * * @param queue A pointer to workqueue object. * @param work A pointer to work item object. - * @param time This work item will be delayed by time (unit: an OS tick) before it's been submitted to the work queue. + * @param time This work item will be delayed by time (unit: an OS ticks) before it's been submitted to the work queue. * * @return RT_EOK Success. - * @return -RT_EBUSY This work item is been executing now. + * @return -RT_EBUSY This work item is executing. * @return -RT_ERROR Time is invalid. */ rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work, rt_tick_t time) @@ -343,7 +343,7 @@ rt_err_t rt_workqueue_critical_work(struct rt_workqueue *queue, struct rt_work * * @param work A pointer to work item object. * * @return RT_EOK Success. - * @return -RT_EBUSY This work item is been executing now. + * @return -RT_EBUSY This work item is executing. */ rt_err_t rt_workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *work) { @@ -419,7 +419,7 @@ static struct rt_workqueue *sys_workq; * @param time This work item will be delayed by time (unit: an OS tick) before it's been submitted to system work queue. * * @return RT_EOK Success. - * @return -RT_EBUSY This work item is been executing now. + * @return -RT_EBUSY This work item is executing. * @return -RT_ERROR Time is invalid. */ rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t time) @@ -433,7 +433,7 @@ rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t time) * @param work A pointer to work item object. * * @return RT_EOK Success. - * @return -RT_EBUSY This work item is been executing now. + * @return -RT_EBUSY This work item is executing. */ rt_err_t rt_work_cancel(struct rt_work *work) { -- cgit v1.3.1 From 3de03a072e3145522546b46117e51e9e444e1b4e Mon Sep 17 00:00:00 2001 From: Jackistang Date: Wed, 18 Aug 2021 09:44:52 +0800 Subject: 修改 ringbuffer 和 workqueue 注释的语法 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/include/ipc/ringbuffer.h | 2 +- components/drivers/include/ipc/workqueue.h | 4 +- components/drivers/src/ringbuffer.c | 44 +++++++++++---------- components/drivers/src/workqueue.c | 60 ++++++++++++++--------------- 4 files changed, 56 insertions(+), 54 deletions(-) (limited to 'components/drivers/include') diff --git a/components/drivers/include/ipc/ringbuffer.h b/components/drivers/include/ipc/ringbuffer.h index da68c5c1fa..7da50225b3 100644 --- a/components/drivers/include/ipc/ringbuffer.h +++ b/components/drivers/include/ipc/ringbuffer.h @@ -82,7 +82,7 @@ void rt_ringbuffer_destroy(struct rt_ringbuffer *rb); #endif /** - * @brief Get buffer size of the ring buffer object. + * @brief Get the buffer size of the ring buffer object. * * @param rb A pointer to the ring buffer object. * diff --git a/components/drivers/include/ipc/workqueue.h b/components/drivers/include/ipc/workqueue.h index 70744ad668..776709a8ab 100644 --- a/components/drivers/include/ipc/workqueue.h +++ b/components/drivers/include/ipc/workqueue.h @@ -72,8 +72,8 @@ rt_err_t rt_work_cancel(struct rt_work *work); * @brief Initialize a work item, binding with a callback function. * * @param work A pointer to the work item object. - * @param work_func A callback function will be called when this work item is executed. - * @param work_data A user data passed to the callback function as it's second parameter. + * @param work_func A callback function that will be called when this work item is executed. + * @param work_data A user data passed to the callback function as the second parameter. */ rt_inline void rt_work_init(struct rt_work *work, void (*work_func)(struct rt_work *work, void *work_data), void *work_data) diff --git a/components/drivers/src/ringbuffer.c b/components/drivers/src/ringbuffer.c index 417982a1b7..a8233a7555 100644 --- a/components/drivers/src/ringbuffer.c +++ b/components/drivers/src/ringbuffer.c @@ -29,11 +29,11 @@ rt_inline enum rt_ringbuffer_state rt_ringbuffer_status(struct rt_ringbuffer *rb } /** - * @brief Initialize a ring buffer object with a given buffer. + * @brief Initialize the ring buffer object with the given buffer. * * @param rb A pointer to the ring buffer object. * @param pool A pointer to the buffer. - * @param size Size of the buffer in bytes. + * @param size The size of the buffer in bytes. */ void rt_ringbuffer_init(struct rt_ringbuffer *rb, rt_uint8_t *pool, @@ -53,13 +53,13 @@ void rt_ringbuffer_init(struct rt_ringbuffer *rb, RTM_EXPORT(rt_ringbuffer_init); /** - * @brief Put a block of data into the ring buffer. If the size of ring buffer is not enough, it will discard out-of-range data. + * @brief Put a block of data into the ring buffer. If the capacity of ring buffer is insufficient, it will discard out-of-range data. * * @param rb A pointer to the ring buffer object. * @param ptr A pointer to the data buffer. * @param length The size of data in bytes. * - * @return Return the size in bytes put into the ring buffer actually. + * @return Return the data size we put into the ring buffer. */ rt_size_t rt_ringbuffer_put(struct rt_ringbuffer *rb, const rt_uint8_t *ptr, @@ -106,13 +106,13 @@ rt_size_t rt_ringbuffer_put(struct rt_ringbuffer *rb, RTM_EXPORT(rt_ringbuffer_put); /** - * @brief Put a block of data into the ring buffer. If the size of ring buffer is not enough, it will overwrite the existing data in the ring buffer. + * @brief Put a block of data into the ring buffer. If the capacity of ring buffer is insufficient, it will overwrite the existing data in the ring buffer. * * @param rb A pointer to the ring buffer object. * @param ptr A pointer to the data buffer. * @param length The size of data in bytes. * - * @return Return the byte size of the data actually put into the ring buffer. + * @return Return the data size we put into the ring buffer. */ rt_size_t rt_ringbuffer_put_force(struct rt_ringbuffer *rb, const rt_uint8_t *ptr, @@ -171,9 +171,9 @@ RTM_EXPORT(rt_ringbuffer_put_force); * * @param rb A pointer to the ring buffer. * @param ptr A pointer to the data buffer. - * @param length The size of data we want to read from the ring buffer. + * @param length The size of the data we want to read from the ring buffer. * - * @return Return the data size that we read from the ring buffer. + * @return Return the data size we read from the ring buffer. */ rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb, rt_uint8_t *ptr, @@ -220,12 +220,14 @@ rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb, RTM_EXPORT(rt_ringbuffer_get); /** - * @brief Peak data from the ring buffer. + * @brief Get the first readable byte of the ring buffer. * * @param rb A pointer to the ringbuffer. * @param ptr When this function return, *ptr is a pointer to the first readable byte of the ring buffer. * - * @return Return the size of ring buffer. + * @note It is recommended to read only one byte, otherwise it may cause buffer overflow. + * + * @return Return the size of the ring buffer. */ rt_size_t rt_ringbuffer_peak(struct rt_ringbuffer *rb, rt_uint8_t **ptr) { @@ -262,9 +264,9 @@ RTM_EXPORT(rt_ringbuffer_peak); * @brief Put a byte into the ring buffer. If ring buffer is full, this operation will fail. * * @param rb A pointer to the ring buffer object. - * @param ch A byte to be put into the ring buffer. + * @param ch A byte put into the ring buffer. * - * @return Return the size in bytes put into the ring buffer. The ring buffer is full if returns 0. Otherwise, it will return 1. + * @return Return the data size we put into the ring buffer. The ring buffer is full if returns 0. Otherwise, it will return 1. */ rt_size_t rt_ringbuffer_putchar(struct rt_ringbuffer *rb, const rt_uint8_t ch) { @@ -292,12 +294,12 @@ rt_size_t rt_ringbuffer_putchar(struct rt_ringbuffer *rb, const rt_uint8_t ch) RTM_EXPORT(rt_ringbuffer_putchar); /** - * @brief Put a byte into the ring buffer. If ring buffer is full, it will discard one old data and put into a new data. + * @brief Put a byte into the ring buffer. If ring buffer is full, it will discard an old data and put into a new data. * * @param rb A pointer to the ring buffer object. - * @param ch A byte to be put into the ring buffer. + * @param ch A byte put into the ring buffer. * - * @return Return the size in bytes put into the ring buffer. Always return 1. + * @return Return the data size we put into the ring buffer. Always return 1. */ rt_size_t rt_ringbuffer_putchar_force(struct rt_ringbuffer *rb, const rt_uint8_t ch) { @@ -334,10 +336,10 @@ RTM_EXPORT(rt_ringbuffer_putchar_force); /** * @brief Get a byte from the ring buffer. * - * @param rb The pointer to ring buffer object. - * @param ch The buffer to store byte read from ring buffer. + * @param rb The pointer to the ring buffer object. + * @param ch A pointer to the buffer, used to store one byte. * - * @return 0 ring buffer is empty. + * @return 0 The ring buffer is empty. * @return 1 Success */ rt_size_t rt_ringbuffer_getchar(struct rt_ringbuffer *rb, rt_uint8_t *ch) @@ -368,7 +370,7 @@ RTM_EXPORT(rt_ringbuffer_getchar); /** * @brief Get the size of data in the ring buffer in bytes. * - * @param rb The pointer to ring buffer object. + * @param rb The pointer to the ring buffer object. * * @return Return the size of data in the ring buffer in bytes. */ @@ -411,7 +413,7 @@ RTM_EXPORT(rt_ringbuffer_reset); /** * @brief Create a ring buffer object with a given size. * - * @param size Size of the buffer in bytes. + * @param size The size of the buffer in bytes. * * @return Return a pointer to ring buffer object. When the return value is RT_NULL, it means the creation failed. */ @@ -443,7 +445,7 @@ exit: RTM_EXPORT(rt_ringbuffer_create); /** - * @brief Destroy a ring buffer object, which is created by rt_ringbuffer_create() . + * @brief Destroy the ring buffer object, which is created by rt_ringbuffer_create() . * * @param rb A pointer to the ring buffer object. */ diff --git a/components/drivers/src/workqueue.c b/components/drivers/src/workqueue.c index 60472d9ca4..4a776ca485 100644 --- a/components/drivers/src/workqueue.c +++ b/components/drivers/src/workqueue.c @@ -211,13 +211,13 @@ static void _delayed_work_timeout_handler(void *parameter) } /** - * @brief Create a work queue, which contains a thread. + * @brief Create a work queue with a thread inside. * - * @param name The name for work queue thread. - * @param stack_size The stack size for work queue thread. - * @param priority The priority for work queue thread. + * @param name The name of the work queue thread. + * @param stack_size The stack size of the work queue thread. + * @param priority The priority of the work queue thread. * - * @return Return a pointer to workqueue object. It will return RT_NULL if failed. + * @return Return A pointer to the workqueue object. It will return RT_NULL if failed. */ struct rt_workqueue *rt_workqueue_create(const char *name, rt_uint16_t stack_size, rt_uint8_t priority) { @@ -249,7 +249,7 @@ struct rt_workqueue *rt_workqueue_create(const char *name, rt_uint16_t stack_siz /** * @brief Destroy a work queue. * - * @param queue A pointer to workqueue object. + * @param queue A pointer to the workqueue object. * * @return RT_EOK Success. */ @@ -266,10 +266,10 @@ rt_err_t rt_workqueue_destroy(struct rt_workqueue *queue) } /** - * @brief Submit a work item to the work queue immediately. + * @brief Submit a work item to the work queue without delay. * - * @param queue A pointer to workqueue object. - * @param work A pointer to work item object. + * @param queue A pointer to the workqueue object. + * @param work A pointer to the work item object. * * @return RT_EOK Success. * @return -RT_EBUSY This work item is executing. @@ -283,15 +283,15 @@ rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work) } /** - * @brief Submit a work item to the work queue with a delay of time. + * @brief Submit a work item to the work queue with a delay. * - * @param queue A pointer to workqueue object. - * @param work A pointer to work item object. - * @param time This work item will be delayed by time (unit: an OS ticks) before it's been submitted to the work queue. + * @param queue A pointer to the workqueue object. + * @param work A pointer to the work item object. + * @param time The delay time (unit: OS ticks) for the work item to be submitted to the work queue. * * @return RT_EOK Success. * @return -RT_EBUSY This work item is executing. - * @return -RT_ERROR Time is invalid. + * @return -RT_ERROR The time parameter is invalid. */ rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work, rt_tick_t time) { @@ -302,10 +302,10 @@ rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *wo } /** - * @brief This function submit a work item to the work queue. This work item will be executed immediately after the current work item is executed. + * @brief Submit a work item to the work queue without delay. This work item will be executed after the current work item is executed. * - * @param queue A pointer to workqueue object. - * @param work A pointer to work item object. + * @param queue A pointer to the workqueue object. + * @param work A pointer to the work item object. * * @return RT_EOK Success. */ @@ -339,8 +339,8 @@ rt_err_t rt_workqueue_critical_work(struct rt_workqueue *queue, struct rt_work * /** * @brief Cancel a work item in the work queue. * - * @param queue A pointer to workqueue object. - * @param work A pointer to work item object. + * @param queue A pointer to the workqueue object. + * @param work A pointer to the work item object. * * @return RT_EOK Success. * @return -RT_EBUSY This work item is executing. @@ -353,10 +353,10 @@ rt_err_t rt_workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *wo } /** - * @brief Cancel a work item in the work queue. If the work item is been executing now, this function will block until it is done. + * @brief Cancel a work item in the work queue. If the work item is executing, this function will block until it is done. * - * @param queue A pointer to workqueue object. - * @param work A pointer to work item object. + * @param queue A pointer to the workqueue object. + * @param work A pointer to the work item object. * * @return RT_EOK Success. */ @@ -379,9 +379,9 @@ rt_err_t rt_workqueue_cancel_work_sync(struct rt_workqueue *queue, struct rt_wor } /** - * @brief This function will cancel all work item in work queue. + * @brief This function will cancel all work items in work queue. * - * @param queue A pointer to workqueue object. + * @param queue A pointer to the workqueue object. * * @return RT_EOK Success. */ @@ -413,14 +413,14 @@ rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue *queue) static struct rt_workqueue *sys_workq; /** - * @brief Submit a work item to the system work queue with a delay of time. + * @brief Submit a work item to the system work queue with a delay. * - * @param work A pointer to work item object. - * @param time This work item will be delayed by time (unit: an OS tick) before it's been submitted to system work queue. + * @param work A pointer to the work item object. + * @param time The delay time (unit: OS ticks) for the work item to be submitted to the work queue. * * @return RT_EOK Success. * @return -RT_EBUSY This work item is executing. - * @return -RT_ERROR Time is invalid. + * @return -RT_ERROR The time parameter is invalid. */ rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t time) { @@ -428,9 +428,9 @@ rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t time) } /** - * @brief Cancel a work item in system work queue. + * @brief Cancel a work item in the system work queue. * - * @param work A pointer to work item object. + * @param work A pointer to the work item object. * * @return RT_EOK Success. * @return -RT_EBUSY This work item is executing. -- cgit v1.3.1 From 5fb6cb8b4159d8913e2b6dcd6d61f3a005204ddc Mon Sep 17 00:00:00 2001 From: malongwei <2544047213@qq.com> Date: Wed, 1 Sep 2021 19:58:23 +0800 Subject: 修复ringblk_buf在不使用动态内存时报错的问题 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/include/ipc/ringblk_buf.h | 5 ++++- components/drivers/src/ringblk_buf.c | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'components/drivers/include') diff --git a/components/drivers/include/ipc/ringblk_buf.h b/components/drivers/include/ipc/ringblk_buf.h index 5b2971b800..df05659f3e 100644 --- a/components/drivers/include/ipc/ringblk_buf.h +++ b/components/drivers/include/ipc/ringblk_buf.h @@ -76,9 +76,12 @@ typedef struct rt_rbb *rt_rbb_t; /* rbb (ring block buffer) API */ void rt_rbb_init(rt_rbb_t rbb, rt_uint8_t *buf, rt_size_t buf_size, rt_rbb_blk_t block_set, rt_size_t blk_max_num); +rt_size_t rt_rbb_get_buf_size(rt_rbb_t rbb); + +#ifdef RT_USING_HEAP rt_rbb_t rt_rbb_create(rt_size_t buf_size, rt_size_t blk_max_num); void rt_rbb_destroy(rt_rbb_t rbb); -rt_size_t rt_rbb_get_buf_size(rt_rbb_t rbb); +#endif /* rbb block API */ rt_rbb_blk_t rt_rbb_blk_alloc(rt_rbb_t rbb, rt_size_t blk_size); diff --git a/components/drivers/src/ringblk_buf.c b/components/drivers/src/ringblk_buf.c index c6688b3d2b..b966da3d36 100644 --- a/components/drivers/src/ringblk_buf.c +++ b/components/drivers/src/ringblk_buf.c @@ -44,6 +44,8 @@ void rt_rbb_init(rt_rbb_t rbb, rt_uint8_t *buf, rt_size_t buf_size, rt_rbb_blk_t } RTM_EXPORT(rt_rbb_init); +#ifdef RT_USING_HEAP + /** * ring block buffer object create * @@ -102,6 +104,8 @@ void rt_rbb_destroy(rt_rbb_t rbb) } RTM_EXPORT(rt_rbb_destroy); +#endif + static rt_rbb_blk_t find_empty_blk_in_set(rt_rbb_t rbb) { rt_size_t i; -- cgit v1.3.1 From fca920751761da33a58fb9565fea31f7099f826d Mon Sep 17 00:00:00 2001 From: Jackistang Date: Mon, 6 Sep 2021 13:27:40 +0800 Subject: serial: add CTS/RTS flowcontrol. --- bsp/stm32/libraries/HAL_Drivers/drv_usart.c | 14 +++++++++++++- components/drivers/include/drivers/serial.h | 7 ++++++- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'components/drivers/include') diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_usart.c b/bsp/stm32/libraries/HAL_Drivers/drv_usart.c index be8b50bba1..06c1d81dfd 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_usart.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_usart.c @@ -107,10 +107,22 @@ static rt_err_t stm32_configure(struct rt_serial_device *serial, struct serial_c uart = rt_container_of(serial, struct stm32_uart, serial); uart->handle.Instance = uart->config->Instance; uart->handle.Init.BaudRate = cfg->baud_rate; - uart->handle.Init.HwFlowCtl = UART_HWCONTROL_NONE; uart->handle.Init.Mode = UART_MODE_TX_RX; uart->handle.Init.OverSampling = UART_OVERSAMPLING_16; + switch (cfg->flowcontrol) + { + case RT_SERIAL_FLOWCONTROL_NONE: + uart->handle.Init.HwFlowCtl = UART_HWCONTROL_NONE; + break; + case RT_SERIAL_FLOWCONTROL_CTSRTS: + uart->handle.Init.HwFlowCtl = UART_HWCONTROL_RTS_CTS; + break; + default: + uart->handle.Init.HwFlowCtl = UART_HWCONTROL_NONE; + break; + } + switch (cfg->data_bits) { case DATA_BITS_8: diff --git a/components/drivers/include/drivers/serial.h b/components/drivers/include/drivers/serial.h index c2e951e9b1..f0d0edbfad 100644 --- a/components/drivers/include/drivers/serial.h +++ b/components/drivers/include/drivers/serial.h @@ -77,6 +77,9 @@ #define RT_SERIAL_TX_DATAQUEUE_SIZE 2048 #define RT_SERIAL_TX_DATAQUEUE_LWM 30 +#define RT_SERIAL_FLOWCONTROL_CTSRTS 1 +#define RT_SERIAL_FLOWCONTROL_NONE 0 + /* Default config for serial_configure structure */ #define RT_SERIAL_CONFIG_DEFAULT \ { \ @@ -87,6 +90,7 @@ BIT_ORDER_LSB, /* LSB first sent */ \ NRZ_NORMAL, /* Normal mode */ \ RT_SERIAL_RB_BUFSZ, /* Buffer size */ \ + RT_SERIAL_FLOWCONTROL_NONE, /* Off flowcontrol */ \ 0 \ } @@ -100,7 +104,8 @@ struct serial_configure rt_uint32_t bit_order :1; rt_uint32_t invert :1; rt_uint32_t bufsz :16; - rt_uint32_t reserved :6; + rt_uint32_t flowcontrol :1; + rt_uint32_t reserved :5; }; /* -- cgit v1.3.1 From 3dc820b3717637c4b2a54f12ab09f64037e97e9f Mon Sep 17 00:00:00 2001 From: BernardXiong Date: Sat, 11 Sep 2021 16:00:00 +0800 Subject: [drivers] fix stdint issue in cputime --- components/drivers/include/drivers/cputime.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'components/drivers/include') diff --git a/components/drivers/include/drivers/cputime.h b/components/drivers/include/drivers/cputime.h index 0141f24805..26a1e40f8e 100644 --- a/components/drivers/include/drivers/cputime.h +++ b/components/drivers/include/drivers/cputime.h @@ -11,6 +11,8 @@ #ifndef CPUTIME_H__ #define CPUTIME_H__ +#include + struct rt_clock_cputime_ops { float (*cputime_getres) (void); -- cgit v1.3.1 From 0b13409c16326f142597570b50bdea8e138da606 Mon Sep 17 00:00:00 2001 From: BernardXiong Date: Sat, 11 Sep 2021 18:09:22 +0800 Subject: [BSP] fix compiling issue with libc --- bsp/gd32vf103v-eval/board/board.c | 2 +- bsp/gd32vf103v-eval/libraries/SConscript | 1 - bsp/lpc1114/driver/drv_uart.c | 2 +- bsp/mini2440/drivers/uart.c | 140 +++++++++++++++------------- bsp/raspberry-pi/raspi4-32/driver/drv_eth.c | 40 ++++---- bsp/raspberry-pi/raspi4-32/driver/mbox.h | 1 + bsp/tm4c123bsp/libraries/Drivers/drv_pwm.h | 1 + bsp/tm4c123bsp/libraries/Drivers/drv_spi.h | 1 + components/drivers/include/drivers/pm.h | 1 + components/drivers/phy/phy.c | 2 +- components/net/netdev/src/netdev.c | 1 + libcpu/arm/zynqmp-r5/cache.c | 68 ++++++++------ 12 files changed, 146 insertions(+), 114 deletions(-) (limited to 'components/drivers/include') diff --git a/bsp/gd32vf103v-eval/board/board.c b/bsp/gd32vf103v-eval/board/board.c index 5df6fa722f..3c03e3fc83 100644 --- a/bsp/gd32vf103v-eval/board/board.c +++ b/bsp/gd32vf103v-eval/board/board.c @@ -8,7 +8,7 @@ * 2019-07-23 tyustli first version * */ - +#include #include #include #include "board.h" diff --git a/bsp/gd32vf103v-eval/libraries/SConscript b/bsp/gd32vf103v-eval/libraries/SConscript index e7a4f5c3eb..932d0eef17 100644 --- a/bsp/gd32vf103v-eval/libraries/SConscript +++ b/bsp/gd32vf103v-eval/libraries/SConscript @@ -8,7 +8,6 @@ cwd = GetCurrentDir() src = Glob('GD32VF103_standard_peripheral/Source/*.c') src += Glob('n22/env_Eclipse/*.c') -src += Glob('n22/stubs/*.c') src += ['GD32VF103_standard_peripheral/system_gd32vf103.c', 'n22/drivers/n22_func.c', 'n22/env_Eclipse/start.S', diff --git a/bsp/lpc1114/driver/drv_uart.c b/bsp/lpc1114/driver/drv_uart.c index 10956140c1..515310ed5f 100644 --- a/bsp/lpc1114/driver/drv_uart.c +++ b/bsp/lpc1114/driver/drv_uart.c @@ -8,7 +8,7 @@ * 2013-05-18 Bernard The first version for LPC40xx * 2019-05-05 jg1uaa port to LPC1114 */ - +#include #include #include #include diff --git a/bsp/mini2440/drivers/uart.c b/bsp/mini2440/drivers/uart.c index 6226a3cb17..9a9db5a76b 100644 --- a/bsp/mini2440/drivers/uart.c +++ b/bsp/mini2440/drivers/uart.c @@ -1,29 +1,32 @@ /* - * File : uart.c - * Drivers for s3c2440 uarts. + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * * Change Logs: * Date Author Notes * 2020-04-09 Jonne Code refactoring for new bsp */ +#include #include #include #include -#define ULCON_OFS 0x00 -#define UCON_OFS 0x04 -#define UFCON_OFS 0x08 -#define UMCON_OFS 0x0c -#define UTRSTAT_OFS 0x10 -#define UERSTAT_OFS 0x14 -#define UFSTAT_OFS 0x18 -#define UMSTAT_OFS 0x1c -#define UTXH_OFS 0x20 -#define URXH_OFS 0x24 -#define UBRDIV_OFS 0x28 +#define ULCON_OFS 0x00 +#define UCON_OFS 0x04 +#define UFCON_OFS 0x08 +#define UMCON_OFS 0x0c +#define UTRSTAT_OFS 0x10 +#define UERSTAT_OFS 0x14 +#define UFSTAT_OFS 0x18 +#define UMSTAT_OFS 0x1c +#define UTXH_OFS 0x20 +#define URXH_OFS 0x24 +#define UBRDIV_OFS 0x28 #define readl(addr) (*(volatile unsigned long *)(addr)) -#define writel(addr, value) (*(volatile unsigned long *)(addr) = value) +#define writel(addr, value) (*(volatile unsigned long *)(addr) = value) #define PCLK_HZ 50000000 @@ -33,9 +36,9 @@ struct hw_uart_device rt_uint32_t irqno; }; -static rt_err_t s3c2440_serial_configure(struct rt_serial_device *serial, struct serial_configure *cfg) +static rt_err_t s3c2440_serial_configure(struct rt_serial_device *serial, struct serial_configure *cfg) { - struct hw_uart_device* uart = serial->parent.user_data; + struct hw_uart_device *uart = serial->parent.user_data; writel(uart->hw_base + UBRDIV_OFS, PCLK_HZ / (cfg->baud_rate * 16)); @@ -44,22 +47,22 @@ static rt_err_t s3c2440_serial_configure(struct rt_serial_device *serial, struct writel(uart->hw_base + UFCON_OFS, 0x00); writel(uart->hw_base + UMCON_OFS, 0x00); - return RT_EOK; + return RT_EOK; } static rt_err_t s3c2440_serial_control(struct rt_serial_device *serial, int cmd, void *arg) { - struct hw_uart_device *uart; + struct hw_uart_device *uart; int mask; - RT_ASSERT(serial != RT_NULL); + RT_ASSERT(serial != RT_NULL); uart = (struct hw_uart_device *)serial->parent.user_data; - if(uart->irqno == INTUART0) + if (uart->irqno == INTUART0) { mask = BIT_SUB_RXD0; } - else if(uart->irqno == INTUART1) + else if (uart->irqno == INTUART1) { mask = BIT_SUB_RXD1; } @@ -73,7 +76,7 @@ static rt_err_t s3c2440_serial_control(struct rt_serial_device *serial, int cmd, case RT_DEVICE_CTRL_CLR_INT: /* disable rx irq */ INTSUBMSK |= mask; - + break; case RT_DEVICE_CTRL_SET_INT: @@ -86,28 +89,28 @@ static rt_err_t s3c2440_serial_control(struct rt_serial_device *serial, int cmd, } static int s3c2440_putc(struct rt_serial_device *serial, char c) { - struct hw_uart_device* uart = serial->parent.user_data; + struct hw_uart_device *uart = serial->parent.user_data; - while(!(readl(uart->hw_base + UTRSTAT_OFS) & (1<<2))) + while (!(readl(uart->hw_base + UTRSTAT_OFS) & (1 << 2))) { } writel(uart->hw_base + UTXH_OFS, c); - + return 0; - + } static int s3c2440_getc(struct rt_serial_device *serial) { - struct hw_uart_device* uart = serial->parent.user_data; + struct hw_uart_device *uart = serial->parent.user_data; int ch = -1; - if(readl(uart->hw_base + UTRSTAT_OFS) & (1<<0)) + if (readl(uart->hw_base + UTRSTAT_OFS) & (1 << 0)) { ch = readl(uart->hw_base + URXH_OFS) & 0x000000FF; } - + return ch; } @@ -116,61 +119,68 @@ static void rt_hw_uart_isr(int irqno, void *param) struct rt_serial_device *serial = (struct rt_serial_device *)param; rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND); - - /*clear SUBSRCPND*/ - if(irqno == INTUART0) + + /*clear SUBSRCPND*/ + if (irqno == INTUART0) { SUBSRCPND = BIT_SUB_RXD0; - } - else if(irqno == INTUART1) + } + else if (irqno == INTUART1) { SUBSRCPND = BIT_SUB_RXD1; } - else + else { SUBSRCPND = BIT_SUB_RXD2; } } -static struct rt_uart_ops s3c2440_uart_ops = { - .configure = s3c2440_serial_configure, - .control = s3c2440_serial_control, - .putc = s3c2440_putc, - .getc = s3c2440_getc +static struct rt_uart_ops s3c2440_uart_ops = +{ + .configure = s3c2440_serial_configure, + .control = s3c2440_serial_control, + .putc = s3c2440_putc, + .getc = s3c2440_getc }; -static struct rt_serial_device _serial0 = { - .ops = &s3c2440_uart_ops, - .config = RT_SERIAL_CONFIG_DEFAULT, - .serial_rx = NULL, - .serial_tx = NULL +static struct rt_serial_device _serial0 = +{ + .ops = &s3c2440_uart_ops, + .config = RT_SERIAL_CONFIG_DEFAULT, + .serial_rx = NULL, + .serial_tx = NULL }; -static struct hw_uart_device _hwserial0 = { - .hw_base = 0x50000000, - .irqno = INTUART0 +static struct hw_uart_device _hwserial0 = +{ + .hw_base = 0x50000000, + .irqno = INTUART0 }; -static struct rt_serial_device _serial1 = { - .ops = &s3c2440_uart_ops, - .config = RT_SERIAL_CONFIG_DEFAULT, - .serial_rx = NULL, - .serial_tx = NULL +static struct rt_serial_device _serial1 = +{ + .ops = &s3c2440_uart_ops, + .config = RT_SERIAL_CONFIG_DEFAULT, + .serial_rx = NULL, + .serial_tx = NULL }; -static struct hw_uart_device _hwserial1 = { - .hw_base = 0x50004000, - .irqno = INTUART1 +static struct hw_uart_device _hwserial1 = +{ + .hw_base = 0x50004000, + .irqno = INTUART1 }; -static struct rt_serial_device _serial2 = { - .ops = &s3c2440_uart_ops, - .config = RT_SERIAL_CONFIG_DEFAULT, - .serial_rx = NULL, - .serial_tx = NULL +static struct rt_serial_device _serial2 = +{ + .ops = &s3c2440_uart_ops, + .config = RT_SERIAL_CONFIG_DEFAULT, + .serial_rx = NULL, + .serial_tx = NULL }; -static struct hw_uart_device _hwserial2 = { - .hw_base = 0x50008000, - .irqno = INTUART2 +static struct hw_uart_device _hwserial2 = +{ + .hw_base = 0x50008000, + .irqno = INTUART2 }; @@ -185,7 +195,7 @@ int rt_hw_uart_init(void) rt_hw_serial_register(&_serial0, "uart0", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX, &_hwserial0); rt_hw_interrupt_install(_hwserial0.irqno, rt_hw_uart_isr, &_serial0, "uart0"); rt_hw_interrupt_umask(INTUART0); - + /* register UART1 device */ rt_hw_serial_register(&_serial1, "uart1", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX, &_hwserial1); rt_hw_interrupt_install(_hwserial1.irqno, rt_hw_uart_isr, &_serial1, "uart1"); diff --git a/bsp/raspberry-pi/raspi4-32/driver/drv_eth.c b/bsp/raspberry-pi/raspi4-32/driver/drv_eth.c index a11707f7a2..5375955086 100644 --- a/bsp/raspberry-pi/raspi4-32/driver/drv_eth.c +++ b/bsp/raspberry-pi/raspi4-32/driver/drv_eth.c @@ -9,9 +9,12 @@ * 2020-10-30 bigmagic first version */ -#include #include + +#include #include +#include "board.h" + #include #include @@ -72,12 +75,12 @@ static struct rt_semaphore link_ack; static inline rt_uint32_t read32(void *addr) { - return (*((volatile unsigned int*)(addr))); + return (*((volatile unsigned int *)(addr))); } static inline void write32(void *addr, rt_uint32_t value) { - (*((volatile unsigned int*)(addr))) = value; + (*((volatile unsigned int *)(addr))) = value; } static void eth_rx_irq(int irq, void *param) @@ -380,7 +383,7 @@ static int bcmgenet_gmac_eth_start(void) /* Update MAC registers based on PHY property */ ret = bcmgenet_adjust_link(); - if(ret) + if (ret) { rt_kprintf("bcmgenet: adjust PHY link failed: %d\n", ret); return ret; @@ -416,10 +419,10 @@ static rt_uint32_t prev_recv_cnt = 0; static rt_uint32_t cur_recv_cnt = 0; static rt_uint32_t bcmgenet_gmac_eth_recv(rt_uint8_t **packetp) { - void* desc_base; + void *desc_base; rt_uint32_t length = 0, addr = 0; rt_uint32_t prod_index = read32(MAC_REG + RDMA_PROD_INDEX); - if(prod_index == index_flag) + if (prod_index == index_flag) { cur_recv_cnt = index_flag; index_flag = 0x7fffffff; @@ -428,7 +431,7 @@ static rt_uint32_t bcmgenet_gmac_eth_recv(rt_uint8_t **packetp) } else { - if(prev_recv_cnt == prod_index & 0xffff) + if (prev_recv_cnt == (prod_index & 0xffff)) { return 0; } @@ -437,15 +440,16 @@ static rt_uint32_t bcmgenet_gmac_eth_recv(rt_uint8_t **packetp) length = read32(desc_base + DMA_DESC_LENGTH_STATUS); length = (length >> DMA_BUFLENGTH_SHIFT) & DMA_BUFLENGTH_MASK; addr = read32(desc_base + DMA_DESC_ADDRESS_LO); + /* To cater for the IP headepr alignment the hardware does. - * This would actually not be needed if we don't program - * RBUF_ALIGN_2B - */ - rt_hw_cpu_dcache_invalidate(addr,length); + * This would actually not be needed if we don't program + * RBUF_ALIGN_2B + */ + rt_hw_cpu_dcache_ops(RT_HW_CACHE_INVALIDATE, (void *) addr, length); *packetp = (rt_uint8_t *)(addr + RX_BUF_OFFSET); rx_index = rx_index + 1; - if(rx_index >= RX_DESCS) + if (rx_index >= RX_DESCS) { rx_index = 0; } @@ -453,7 +457,7 @@ static rt_uint32_t bcmgenet_gmac_eth_recv(rt_uint8_t **packetp) cur_recv_cnt = cur_recv_cnt + 1; - if(cur_recv_cnt > 0xffff) + if (cur_recv_cnt > 0xffff) { cur_recv_cnt = 0; } @@ -468,16 +472,16 @@ static int bcmgenet_gmac_eth_send(void *packet, int length) void *desc_base = (TX_DESC_BASE + tx_index * DMA_DESC_SIZE); rt_uint32_t len_stat = length << DMA_BUFLENGTH_SHIFT; - rt_uint32_t prod_index, cons; - rt_uint32_t tries = 100; + rt_uint32_t prod_index; prod_index = read32(MAC_REG + TDMA_PROD_INDEX); len_stat |= 0x3F << DMA_TX_QTAG_SHIFT; len_stat |= DMA_TX_APPEND_CRC | DMA_SOP | DMA_EOP; - rt_hw_cpu_dcache_clean((void*)packet, length); - write32((desc_base + DMA_DESC_ADDRESS_LO), packet); + rt_hw_cpu_dcache_ops(RT_HW_CACHE_FLUSH, (void *)packet, length); + + write32((desc_base + DMA_DESC_ADDRESS_LO), (rt_uint32_t)packet); write32((desc_base + DMA_DESC_ADDRESS_HI), 0); write32((desc_base + DMA_DESC_LENGTH_STATUS), len_stat); @@ -631,7 +635,7 @@ struct pbuf *rt_eth_rx(rt_device_t device) if (recv_len > 0) { pbuf = pbuf_alloc(PBUF_LINK, recv_len, PBUF_RAM); - if(pbuf) + if (pbuf) { rt_memcpy(pbuf->payload, addr_point, recv_len); } diff --git a/bsp/raspberry-pi/raspi4-32/driver/mbox.h b/bsp/raspberry-pi/raspi4-32/driver/mbox.h index 2c69bcf55a..7d59add27f 100644 --- a/bsp/raspberry-pi/raspi4-32/driver/mbox.h +++ b/bsp/raspberry-pi/raspi4-32/driver/mbox.h @@ -12,6 +12,7 @@ #define __MBOX_H__ #include +#include "board.h" //https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface //https://github.com/hermanhermitage/videocoreiv diff --git a/bsp/tm4c123bsp/libraries/Drivers/drv_pwm.h b/bsp/tm4c123bsp/libraries/Drivers/drv_pwm.h index 906680fe3d..dfbd655188 100644 --- a/bsp/tm4c123bsp/libraries/Drivers/drv_pwm.h +++ b/bsp/tm4c123bsp/libraries/Drivers/drv_pwm.h @@ -11,6 +11,7 @@ #ifndef __DRV_PWM_H__ #define __DRV_PWM_H__ +#include #include #include diff --git a/bsp/tm4c123bsp/libraries/Drivers/drv_spi.h b/bsp/tm4c123bsp/libraries/Drivers/drv_spi.h index 33b28146bc..f657f304b6 100644 --- a/bsp/tm4c123bsp/libraries/Drivers/drv_spi.h +++ b/bsp/tm4c123bsp/libraries/Drivers/drv_spi.h @@ -11,6 +11,7 @@ #ifndef __DRV_SPI_H__ #define __DRV_SPI_H__ +#include #include #include #include "drivers/spi.h" diff --git a/components/drivers/include/drivers/pm.h b/components/drivers/include/drivers/pm.h index 51bff54ebb..d38c0a4e2a 100644 --- a/components/drivers/include/drivers/pm.h +++ b/components/drivers/include/drivers/pm.h @@ -15,6 +15,7 @@ #ifndef __PM_H__ #define __PM_H__ +#include #include #ifndef PM_HAS_CUSTOM_CONFIG diff --git a/components/drivers/phy/phy.c b/components/drivers/phy/phy.c index 6d408ce612..87152a306e 100644 --- a/components/drivers/phy/phy.c +++ b/components/drivers/phy/phy.c @@ -8,7 +8,7 @@ * Date Author Notes * 2020-09-27 wangqiang first version */ - +#include #include #include #include diff --git a/components/net/netdev/src/netdev.c b/components/net/netdev/src/netdev.c index 26451cb007..4c5d524510 100644 --- a/components/net/netdev/src/netdev.c +++ b/components/net/netdev/src/netdev.c @@ -10,6 +10,7 @@ #include #include +#include #include #include diff --git a/libcpu/arm/zynqmp-r5/cache.c b/libcpu/arm/zynqmp-r5/cache.c index 6053b2fe47..a6ee643271 100644 --- a/libcpu/arm/zynqmp-r5/cache.c +++ b/libcpu/arm/zynqmp-r5/cache.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2021, RT-Thread Development Team + * Copyright (c) 2006 - 2021, RT-Thread Development Team * Copyright (c) 2014 - 2020 Xilinx, Inc. All rights reserved. * Copyright (c) 2021 WangHuachen. All rights reserved. * SPDX-License-Identifier: MIT @@ -9,6 +9,8 @@ * 2020-03-19 WangHuachen first version * 2021-05-10 WangHuachen add more functions */ + +#include #include #include @@ -69,9 +71,10 @@ void Xil_DCacheEnable(void) #if defined (__GNUC__) CtrlReg = mfcp(XREG_CP15_SYS_CONTROL); #elif defined (__ICCARM__) - mfcp(XREG_CP15_SYS_CONTROL,CtrlReg); + mfcp(XREG_CP15_SYS_CONTROL, CtrlReg); #endif - if ((CtrlReg & XREG_CP15_CONTROL_C_BIT)==0x00000000U) { + if ((CtrlReg & XREG_CP15_CONTROL_C_BIT) == 0x00000000U) + { /* invalidate the Data cache */ Xil_DCacheInvalidate(); @@ -93,7 +96,7 @@ void Xil_DCacheDisable(void) #if defined (__GNUC__) CtrlReg = mfcp(XREG_CP15_SYS_CONTROL); #elif defined (__ICCARM__) - mfcp(XREG_CP15_SYS_CONTROL,CtrlReg); + mfcp(XREG_CP15_SYS_CONTROL, CtrlReg); #endif CtrlReg &= ~(XREG_CP15_CONTROL_C_BIT); @@ -126,7 +129,7 @@ void Xil_DCacheInvalidateLine(INTPTR adr) mtcp(XREG_CP15_CACHE_SIZE_SEL, 0); mtcp(XREG_CP15_INVAL_DC_LINE_MVA_POC, (adr & (~0x1F))); - /* Wait for invalidate to complete */ + /* Wait for invalidate to complete */ dsb(); mtcpsr(currmask); @@ -143,29 +146,33 @@ void Xil_DCacheInvalidateRange(INTPTR adr, u32 len) currmask = mfcpsr(); mtcpsr(currmask | IRQ_FIQ_MASK); - if (len != 0U) { + if (len != 0U) + { end = tempadr + len; tempend = end; /* Select L1 Data cache in CSSR */ mtcp(XREG_CP15_CACHE_SIZE_SEL, 0U); - if ((tempadr & (cacheline-1U)) != 0U) { + if ((tempadr & (cacheline - 1U)) != 0U) + { tempadr &= (~(cacheline - 1U)); Xil_DCacheFlushLine(tempadr); } - if ((tempend & (cacheline-1U)) != 0U) { + if ((tempend & (cacheline - 1U)) != 0U) + { tempend &= (~(cacheline - 1U)); Xil_DCacheFlushLine(tempend); } - while (tempadr < tempend) { + while (tempadr < tempend) + { - /* Invalidate Data cache line */ - asm_inval_dc_line_mva_poc(tempadr); + /* Invalidate Data cache line */ + asm_inval_dc_line_mva_poc(tempadr); - tempadr += cacheline; + tempadr += cacheline; } } @@ -189,7 +196,7 @@ void Xil_DCacheFlush(void) #if defined (__GNUC__) CsidReg = mfcp(XREG_CP15_CACHE_SIZE_ID); #elif defined (__ICCARM__) - mfcp(XREG_CP15_CACHE_SIZE_ID,CsidReg); + mfcp(XREG_CP15_CACHE_SIZE_ID, CsidReg); #endif /* Determine Cache Size */ @@ -204,15 +211,17 @@ void Xil_DCacheFlush(void) /* Get the cacheline size, way size, index size from csidr */ LineSize = (CsidReg & 0x00000007U) + 0x00000004U; - NumSet = CacheSize/NumWays; + NumSet = CacheSize / NumWays; NumSet /= (0x00000001U << LineSize); Way = 0U; Set = 0U; /* Invalidate all the cachelines */ - for (WayIndex = 0U; WayIndex < NumWays; WayIndex++) { - for (SetIndex = 0U; SetIndex < NumSet; SetIndex++) { + for (WayIndex = 0U; WayIndex < NumWays; WayIndex++) + { + for (SetIndex = 0U; SetIndex < NumSet; SetIndex++) + { C7Reg = Way | Set; /* Flush by Set/Way */ asm_clean_inval_dc_line_sw(C7Reg); @@ -241,7 +250,7 @@ void Xil_DCacheFlushLine(INTPTR adr) mtcp(XREG_CP15_CLEAN_INVAL_DC_LINE_MVA_POC, (adr & (~0x1F))); - /* Wait for flush to complete */ + /* Wait for flush to complete */ dsb(); mtcpsr(currmask); } @@ -256,14 +265,16 @@ void Xil_DCacheFlushRange(INTPTR adr, u32 len) currmask = mfcpsr(); mtcpsr(currmask | IRQ_FIQ_MASK); - if (len != 0x00000000U) { + if (len != 0x00000000U) + { /* Back the starting address up to the start of a cache line * perform cache operations until adr+len */ end = LocalAddr + len; LocalAddr &= ~(cacheline - 1U); - while (LocalAddr < end) { + while (LocalAddr < end) + { /* Flush Data cache line */ asm_clean_inval_dc_line_mva_poc(LocalAddr); @@ -301,7 +312,8 @@ void Xil_ICacheEnable(void) #elif defined (__ICCARM__) mfcp(XREG_CP15_SYS_CONTROL, CtrlReg); #endif - if ((CtrlReg & XREG_CP15_CONTROL_I_BIT)==0x00000000U) { + if ((CtrlReg & XREG_CP15_CONTROL_I_BIT) == 0x00000000U) + { /* invalidate the instruction cache */ mtcp(XREG_CP15_INVAL_IC_POU, 0); @@ -321,11 +333,11 @@ void Xil_ICacheDisable(void) /* invalidate the instruction cache */ mtcp(XREG_CP15_INVAL_IC_POU, 0); - /* disable the instruction cache */ + /* disable the instruction cache */ #if defined (__GNUC__) CtrlReg = mfcp(XREG_CP15_SYS_CONTROL); #elif defined (__ICCARM__) - mfcp(XREG_CP15_SYS_CONTROL,CtrlReg); + mfcp(XREG_CP15_SYS_CONTROL, CtrlReg); #endif CtrlReg &= ~(XREG_CP15_CONTROL_I_BIT); @@ -360,7 +372,7 @@ void Xil_ICacheInvalidateLine(INTPTR adr) mtcp(XREG_CP15_CACHE_SIZE_SEL, 1); mtcp(XREG_CP15_INVAL_IC_LINE_MVA_POU, (adr & (~0x1F))); - /* Wait for invalidate to complete */ + /* Wait for invalidate to complete */ dsb(); mtcpsr(currmask); } @@ -374,7 +386,8 @@ void Xil_ICacheInvalidateRange(INTPTR adr, u32 len) currmask = mfcpsr(); mtcpsr(currmask | IRQ_FIQ_MASK); - if (len != 0x00000000U) { + if (len != 0x00000000U) + { /* Back the starting address up to the start of a cache line * perform cache operations until adr+len */ @@ -384,7 +397,8 @@ void Xil_ICacheInvalidateRange(INTPTR adr, u32 len) /* Select cache L0 I-cache in CSSR */ mtcp(XREG_CP15_CACHE_SIZE_SEL, 1U); - while (LocalAddr < end) { + while (LocalAddr < end) + { /* Invalidate L1 I-cache line */ asm_inval_ic_line_mva_pou(LocalAddr); @@ -418,7 +432,7 @@ rt_base_t rt_hw_cpu_icache_status(void) #if defined (__GNUC__) CtrlReg = mfcp(XREG_CP15_SYS_CONTROL); #elif defined (__ICCARM__) - mfcp(XREG_CP15_SYS_CONTROL,CtrlReg); + mfcp(XREG_CP15_SYS_CONTROL, CtrlReg); #endif return CtrlReg & XREG_CP15_CONTROL_I_BIT; } @@ -429,7 +443,7 @@ rt_base_t rt_hw_cpu_dcache_status(void) #if defined (__GNUC__) CtrlReg = mfcp(XREG_CP15_SYS_CONTROL); #elif defined (__ICCARM__) - mfcp(XREG_CP15_SYS_CONTROL,CtrlReg); + mfcp(XREG_CP15_SYS_CONTROL, CtrlReg); #endif return CtrlReg & XREG_CP15_CONTROL_C_BIT; } -- cgit v1.3.1 From ff0b6d241beafd99b41d5ea91e29b4869ecbcfc0 Mon Sep 17 00:00:00 2001 From: armink Date: Wed, 29 Sep 2021 17:12:27 +0800 Subject: [DeviceDriver][RTC] Remove RT_DEVICE_CTRL_RTC_GET_TIME_US and RT_DEVICE_CTRL_RTC_SET_TIME_US. Add RT_DEVICE_CTRL_RTC_GET_TIMEVAL and RT_DEVICE_CTRL_RTC_SET_TIMEVAL. The RT_DEVICE_CTRL_RTC_GET_TIMEVAL cmd can get second time and microsecond time. --- components/drivers/include/drivers/rtc.h | 12 +-- components/libc/compilers/common/time.c | 148 ++++++++----------------------- 2 files changed, 42 insertions(+), 118 deletions(-) (limited to 'components/drivers/include') diff --git a/components/drivers/include/drivers/rtc.h b/components/drivers/include/drivers/rtc.h index 0bafbad7ad..f8702a2e99 100644 --- a/components/drivers/include/drivers/rtc.h +++ b/components/drivers/include/drivers/rtc.h @@ -15,12 +15,12 @@ #include -#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 */ +#define RT_DEVICE_CTRL_RTC_GET_TIME 0x20 /**< get second time */ +#define RT_DEVICE_CTRL_RTC_SET_TIME 0x21 /**< set second time */ +#define RT_DEVICE_CTRL_RTC_GET_TIMEVAL 0x22 /**< get timeval for gettimeofday */ +#define RT_DEVICE_CTRL_RTC_SET_TIMEVAL 0x23 /**< set timeval for gettimeofday */ +#define RT_DEVICE_CTRL_RTC_GET_ALARM 0x24 /**< get alarm */ +#define RT_DEVICE_CTRL_RTC_SET_ALARM 0x25 /**< set alarm */ struct rt_rtc_ops { diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index f81844f8e9..6395d789fa 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -18,21 +18,23 @@ * 2021-02-12 Meco Man move all of the functions located in 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 #include -#include + #ifdef RT_USING_DEVICE #include #endif -#define DBG_TAG "time" +#define DBG_TAG "TIME" #define DBG_LVL DBG_INFO #include +#ifndef RT_LIBC_FIXED_TIMEZONE +#define RT_LIBC_FIXED_TIMEZONE 8 /* UTC+8 */ +#endif + /* seconds per day */ #define SPD 24*60*60 @@ -101,7 +103,7 @@ static rt_err_t get_timeval(struct timeval *tv) if (rt_device_open(device, 0) == RT_EOK) { rst = rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &tv->tv_sec); - rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME_US, &tv->tv_usec); + rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIMEVAL, tv); rt_device_close(device); } } @@ -147,7 +149,7 @@ static int set_timeval(struct timeval *tv) if (rt_device_open(device, 0) == RT_EOK) { rst = rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &tv->tv_sec); - rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME_US, &tv->tv_usec); + rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIMEVAL, tv); rt_device_close(device); } } @@ -199,7 +201,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 = tz_is_dst(); + r->tm_isdst = 0; return r; } RTM_EXPORT(gmtime_r); @@ -215,7 +217,7 @@ struct tm* localtime_r(const time_t* t, struct tm* r) { time_t local_tz; - local_tz = *t + tz_get() * 3600; + local_tz = *t + RT_LIBC_FIXED_TIMEZONE * 3600; return gmtime_r(&local_tz, r); } RTM_EXPORT(localtime_r); @@ -232,36 +234,13 @@ time_t mktime(struct tm * const t) time_t timestamp; timestamp = timegm(t); - timestamp = timestamp - 3600 * tz_get(); + timestamp = timestamp - 3600 * RT_LIBC_FIXED_TIMEZONE; return timestamp; } RTM_EXPORT(mktime); char* asctime_r(const struct tm *t, char *buf) { - /* Checking input validity */ - if (rt_strlen(days) <= (t->tm_wday << 2) || rt_strlen(months) <= (t->tm_mon << 2)) - { - LOG_W("asctime_r: the input parameters exceeded the limit, please check it."); - *(int*) buf = *(int*) days; - *(int*) (buf + 4) = *(int*) months; - num2str(buf + 8, t->tm_mday); - if (buf[8] == '0') - buf[8] = ' '; - buf[10] = ' '; - num2str(buf + 11, t->tm_hour); - buf[13] = ':'; - num2str(buf + 14, t->tm_min); - buf[16] = ':'; - num2str(buf + 17, t->tm_sec); - buf[19] = ' '; - num2str(buf + 20, 2000 / 100); - num2str(buf + 22, 2000 % 100); - buf[24] = '\n'; - buf[25] = '\0'; - return buf; - } - /* "Wed Jun 30 21:49:08 1993\n" */ *(int*) buf = *(int*) (days + (t->tm_wday << 2)); *(int*) (buf + 4) = *(int*) (months + (t->tm_mon << 2)); @@ -446,7 +425,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz) if(tz != RT_NULL) { tz->tz_dsttime = DST_NONE; - tz->tz_minuteswest = -(tz_get() * 60); + tz->tz_minuteswest = -(RT_LIBC_FIXED_TIMEZONE * 60); } if (tv != RT_NULL && get_timeval(tv) == RT_EOK) @@ -469,6 +448,7 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz) * Thus, the following is purely of historic interest. */ if (tv != RT_NULL + && tv->tv_sec >= 0 && tv->tv_usec >= 0 && set_timeval((struct timeval *)tv) == RT_EOK) { @@ -487,47 +467,33 @@ RTM_EXPORT(difftime); RTM_EXPORT(strftime); #ifdef RT_USING_POSIX - -#ifdef RT_USING_RTC -static volatile struct timeval _timevalue; -static int _rt_clock_time_system_init() +static struct timeval _timevalue; +static int clock_time_system_init() { - register rt_base_t level; - time_t time = 0; + time_t time; rt_tick_t tick; rt_device_t device; + time = 0; device = rt_device_find("rtc"); if (device != RT_NULL) { /* get realtime seconds */ - 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; - } + rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time); } - level = rt_hw_interrupt_disable(); - _timevalue.tv_usec = 0; - _timevalue.tv_sec = 0; - rt_hw_interrupt_enable(level); + /* 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; - return -1; + return 0; } -INIT_COMPONENT_EXPORT(_rt_clock_time_system_init); -#endif /* RT_USING_RTC */ +INIT_COMPONENT_EXPORT(clock_time_system_init); 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) @@ -557,16 +523,11 @@ 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) @@ -579,14 +540,11 @@ int clock_gettime(clockid_t clockid, struct timespec *tp) { case CLOCK_REALTIME: { - int tick; - register rt_base_t level; + /* get tick */ + int tick = rt_tick_get(); - 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; @@ -610,17 +568,11 @@ 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; @@ -628,36 +580,34 @@ 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); /* update for RTC device */ device = rt_device_find("rtc"); if (device != RT_NULL) { /* set realtime seconds */ - if(rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &second) == RT_EOK) - { - return 0; - } + rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &second); } + else + return -1; - return -1; -#endif /* RT_USING_RTC */ + return 0; } RTM_EXPORT(clock_settime); -int rt_timespec_to_tick(const struct timespec *time) +int clock_time_to_tick(const struct timespec *time) { int tick; int nsecond, second; @@ -688,32 +638,6 @@ int rt_timespec_to_tick(const struct timespec *time) return tick; } -RTM_EXPORT(rt_timespec_to_tick); +RTM_EXPORT(clock_time_to_tick); #endif /* RT_USING_POSIX */ - - -/* timezone */ -#ifndef RT_LIBC_DEFAULT_TIMEZONE -#define RT_LIBC_DEFAULT_TIMEZONE 8 -#endif - -static volatile int8_t _current_timezone = RT_LIBC_DEFAULT_TIMEZONE; - -void tz_set(int8_t tz) -{ - register rt_base_t level; - level = rt_hw_interrupt_disable(); - _current_timezone = tz; - rt_hw_interrupt_enable(level); -} - -int8_t tz_get(void) -{ - return _current_timezone; -} - -int8_t tz_is_dst(void) -{ - return 0; -} -- cgit v1.3.1 From 816a99d88e5f42ceb846f587235281a1a1414750 Mon Sep 17 00:00:00 2001 From: armink Date: Wed, 29 Sep 2021 17:52:10 +0800 Subject: [DeviceDriver][RTC] Add RT_DEVICE_CTRL_RTC_GET_TIMEVAL and RT_DEVICE_CTRL_RTC_SET_TIMEVAL ops --- components/drivers/include/drivers/rtc.h | 4 ++-- components/drivers/rtc/rtc.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'components/drivers/include') diff --git a/components/drivers/include/drivers/rtc.h b/components/drivers/include/drivers/rtc.h index f8702a2e99..5b333161f8 100644 --- a/components/drivers/include/drivers/rtc.h +++ b/components/drivers/include/drivers/rtc.h @@ -29,8 +29,8 @@ struct rt_rtc_ops 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); + rt_err_t (*get_timeval)(void *arg); + rt_err_t (*set_timeval)(void *arg); }; typedef struct rt_rtc_device diff --git a/components/drivers/rtc/rtc.c b/components/drivers/rtc/rtc.c index bc75c83e7d..0658d2aaf4 100644 --- a/components/drivers/rtc/rtc.c +++ b/components/drivers/rtc/rtc.c @@ -71,11 +71,11 @@ static rt_err_t rt_rtc_control(struct rt_device *dev, int cmd, void *args) 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); + case RT_DEVICE_CTRL_RTC_GET_TIMEVAL: + ret = TRY_DO_RTC_FUNC(rtc_device, get_timeval, args); break; - case RT_DEVICE_CTRL_RTC_SET_TIME_US: - ret = TRY_DO_RTC_FUNC(rtc_device, set_usecs, args); + case RT_DEVICE_CTRL_RTC_SET_TIMEVAL: + ret = TRY_DO_RTC_FUNC(rtc_device, set_timeval, args); break; case RT_DEVICE_CTRL_RTC_GET_ALARM: ret = TRY_DO_RTC_FUNC(rtc_device, get_alarm, args); -- cgit v1.3.1 From e538c5aa70d3200240086043ded2428abe36816c Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 20 Oct 2021 15:48:07 -0400 Subject: [workqueue] rename rt_workqueue_critical_work as rt_workqueue_urgent_work --- components/drivers/include/ipc/workqueue.h | 2 +- components/drivers/src/workqueue.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'components/drivers/include') diff --git a/components/drivers/include/ipc/workqueue.h b/components/drivers/include/ipc/workqueue.h index 776709a8ab..edefb0933e 100644 --- a/components/drivers/include/ipc/workqueue.h +++ b/components/drivers/include/ipc/workqueue.h @@ -61,7 +61,7 @@ rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *wo rt_err_t rt_workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *work); rt_err_t rt_workqueue_cancel_work_sync(struct rt_workqueue *queue, struct rt_work *work); rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue *queue); -rt_err_t rt_workqueue_critical_work(struct rt_workqueue *queue, struct rt_work *work); +rt_err_t rt_workqueue_urgent_work(struct rt_workqueue *queue, struct rt_work *work); #ifdef RT_USING_SYSTEM_WORKQUEUE rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t time); diff --git a/components/drivers/src/workqueue.c b/components/drivers/src/workqueue.c index b5d803472b..6dbb0da627 100644 --- a/components/drivers/src/workqueue.c +++ b/components/drivers/src/workqueue.c @@ -309,7 +309,7 @@ rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *wo * * @return RT_EOK Success. */ -rt_err_t rt_workqueue_critical_work(struct rt_workqueue *queue, struct rt_work *work) +rt_err_t rt_workqueue_urgent_work(struct rt_workqueue *queue, struct rt_work *work) { rt_base_t level; RT_ASSERT(queue != RT_NULL); -- cgit v1.3.1