diff options
| author | Wayne Lin <[email protected]> | 2022-01-25 18:53:52 +0800 |
|---|---|---|
| committer | Wayne Lin <[email protected]> | 2022-01-25 18:53:52 +0800 |
| commit | c95c296e9915a38a666ae1a2575c2a4d0ba1d376 (patch) | |
| tree | c6e5a1ffe4ceb997e853ba0c3daffc9dc60c8b79 /components/drivers | |
| parent | f7ba146a01fcf23a2b06a141d1b1a56cb27b878c (diff) | |
| parent | 32a5668593c578b85560338c29d76f3a252c8dbc (diff) | |
Merge branch 'master' of https://github.com/RT-Thread/rt-thread into nuvoton
# Conflicts:
# bsp/gd32/gd32107c-eval/rtconfig.h
Diffstat (limited to 'components/drivers')
| -rw-r--r-- | components/drivers/include/ipc/workqueue.h | 26 | ||||
| -rw-r--r-- | components/drivers/ipc/SConscript (renamed from components/drivers/src/SConscript) | 0 | ||||
| -rw-r--r-- | components/drivers/ipc/completion.c (renamed from components/drivers/src/completion.c) | 0 | ||||
| -rw-r--r-- | components/drivers/ipc/dataqueue.c (renamed from components/drivers/src/dataqueue.c) | 0 | ||||
| -rw-r--r-- | components/drivers/ipc/pipe.c (renamed from components/drivers/src/pipe.c) | 4 | ||||
| -rw-r--r-- | components/drivers/ipc/ringblk_buf.c (renamed from components/drivers/src/ringblk_buf.c) | 0 | ||||
| -rw-r--r-- | components/drivers/ipc/ringbuffer.c (renamed from components/drivers/src/ringbuffer.c) | 0 | ||||
| -rw-r--r-- | components/drivers/ipc/waitqueue.c (renamed from components/drivers/src/waitqueue.c) | 7 | ||||
| -rw-r--r-- | components/drivers/ipc/workqueue.c (renamed from components/drivers/src/workqueue.c) | 128 | ||||
| -rw-r--r-- | components/drivers/serial/serial.c | 4 | ||||
| -rw-r--r-- | components/drivers/serial/serial_v2.c | 3 | ||||
| -rw-r--r-- | components/drivers/spi/SConscript | 18 |
12 files changed, 119 insertions, 71 deletions
diff --git a/components/drivers/include/ipc/workqueue.h b/components/drivers/include/ipc/workqueue.h index edefb0933e..b2224bdcf4 100644 --- a/components/drivers/include/ipc/workqueue.h +++ b/components/drivers/include/ipc/workqueue.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2021, RT-Thread Development Team + * Copyright (c) 2006-2022, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -54,37 +54,23 @@ struct rt_work /** * WorkQueue for DeviceDriver */ +void rt_work_init(struct rt_work *work, void (*work_func)(struct rt_work *work, void *work_data), void *work_data); struct rt_workqueue *rt_workqueue_create(const char *name, rt_uint16_t stack_size, rt_uint8_t priority); rt_err_t rt_workqueue_destroy(struct rt_workqueue *queue); rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work); -rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work, rt_tick_t time); +rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work, rt_tick_t ticks); 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_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); +rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t ticks); +rt_err_t rt_work_urgent(struct rt_work *work); rt_err_t rt_work_cancel(struct rt_work *work); #endif /* RT_USING_SYSTEM_WORKQUEUE */ -/** - * @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 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) -{ - rt_list_init(&(work->list)); - work->work_func = work_func; - work->work_data = work_data; - work->workqueue = RT_NULL; - work->flags = 0; - work->type = 0; -} + #endif /* RT_USING_HEAP */ diff --git a/components/drivers/src/SConscript b/components/drivers/ipc/SConscript index 9f921ec509..9f921ec509 100644 --- a/components/drivers/src/SConscript +++ b/components/drivers/ipc/SConscript diff --git a/components/drivers/src/completion.c b/components/drivers/ipc/completion.c index f13718f9b3..f13718f9b3 100644 --- a/components/drivers/src/completion.c +++ b/components/drivers/ipc/completion.c diff --git a/components/drivers/src/dataqueue.c b/components/drivers/ipc/dataqueue.c index 4e52662c44..4e52662c44 100644 --- a/components/drivers/src/dataqueue.c +++ b/components/drivers/ipc/dataqueue.c diff --git a/components/drivers/src/pipe.c b/components/drivers/ipc/pipe.c index 7e1f569b62..3a2ad4104d 100644 --- a/components/drivers/src/pipe.c +++ b/components/drivers/ipc/pipe.c @@ -14,8 +14,8 @@ #include <sys/errno.h> #if defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE) -#include <dfs_file.h> -#include <dfs_posix.h> +#include <unistd.h> +#include <fcntl.h> #include <poll.h> #include <sys/ioctl.h> diff --git a/components/drivers/src/ringblk_buf.c b/components/drivers/ipc/ringblk_buf.c index 5b7a5f9c96..5b7a5f9c96 100644 --- a/components/drivers/src/ringblk_buf.c +++ b/components/drivers/ipc/ringblk_buf.c diff --git a/components/drivers/src/ringbuffer.c b/components/drivers/ipc/ringbuffer.c index deb8979930..deb8979930 100644 --- a/components/drivers/src/ringbuffer.c +++ b/components/drivers/ipc/ringbuffer.c diff --git a/components/drivers/src/waitqueue.c b/components/drivers/ipc/waitqueue.c index 4c6bb7e97f..6a26604617 100644 --- a/components/drivers/src/waitqueue.c +++ b/components/drivers/ipc/waitqueue.c @@ -7,6 +7,7 @@ * Date Author Notes * 2018/06/26 Bernard Fix the wait queue issue when wakeup a soon * to blocked thread. + * 2022-01-24 THEWON let rt_wqueue_wait return thread->error when using signal */ #include <stdint.h> @@ -141,6 +142,10 @@ int rt_wqueue_wait(rt_wqueue_t *queue, int condition, int msec) rt_list_init(&__wait.list); level = rt_hw_interrupt_disable(); + + /* reset thread error */ + tid->error = RT_EOK; + if (queue->flag == RT_WQ_FLAG_WAKEUP) { /* already wakeup */ @@ -171,5 +176,5 @@ __exit_wakeup: rt_wqueue_remove(&__wait); - return 0; + return tid->error; } diff --git a/components/drivers/src/workqueue.c b/components/drivers/ipc/workqueue.c index 6dbb0da627..58cb0ddf56 100644 --- a/components/drivers/src/workqueue.c +++ b/components/drivers/ipc/workqueue.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2021, RT-Thread Development Team + * Copyright (c) 2006-2022, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -7,7 +7,8 @@ * 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 comments for function interface. + * 2021-08-14 Jackistang add comments for function interface + * 2022-01-16 Meco Man add rt_work_urgent() */ #include <rthw.h> @@ -98,7 +99,7 @@ static rt_err_t _workqueue_submit_work(struct rt_workqueue *queue, /* remove list */ rt_list_remove(&(work->list)); work->flags &= ~RT_WORK_STATE_PENDING; - /* */ + if (ticks == 0) { if (queue->work_current != work) @@ -211,13 +212,39 @@ static void _delayed_work_timeout_handler(void *parameter) } /** + * @brief Initialize a work item, binding with a callback function. + * + * @param work is a pointer to the work item object. + * + * @param work_func is a callback function that will be called when this work item is executed. + * + * @param work_data is a user data passed to the callback function as the second parameter. + */ +void rt_work_init(struct rt_work *work, + void (*work_func)(struct rt_work *work, void *work_data), + void *work_data) +{ + RT_ASSERT(work != RT_NULL); + RT_ASSERT(work_func != RT_NULL); + + rt_list_init(&(work->list)); + work->work_func = work_func; + work->work_data = work_data; + work->workqueue = RT_NULL; + work->flags = 0; + work->type = 0; +} + +/** * @brief Create a work queue with a thread inside. * - * @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. + * @param name is a name of the work queue thread. + * + * @param stack_size is stack size of the work queue thread. + * + * @param priority is a priority of the work queue thread. * - * @return Return A pointer to the 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,9 +276,9 @@ struct rt_workqueue *rt_workqueue_create(const char *name, rt_uint16_t stack_siz /** * @brief Destroy a work queue. * - * @param queue A pointer to the workqueue object. + * @param queue is a pointer to the workqueue object. * - * @return RT_EOK Success. + * @return RT_EOK Success. */ rt_err_t rt_workqueue_destroy(struct rt_workqueue *queue) { @@ -268,11 +295,12 @@ rt_err_t rt_workqueue_destroy(struct rt_workqueue *queue) /** * @brief Submit a work item to the work queue without delay. * - * @param queue A pointer to the workqueue object. - * @param work A pointer to the work item object. + * @param queue is a pointer to the workqueue object. + * + * @param work is a pointer to the work item object. * * @return RT_EOK Success. - * @return -RT_EBUSY This work item is executing. + * -RT_EBUSY This work item is executing. */ rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work) { @@ -285,33 +313,40 @@ 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. * - * @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. + * @param queue is a pointer to the workqueue object. + * + * @param work is a pointer to the work item object. + * + * @param ticks is the delay ticks for the work item to be submitted to the work queue. + * + * NOTE: The max timeout tick should be no more than (RT_TICK_MAX/2 - 1) * * @return RT_EOK Success. - * @return -RT_EBUSY This work item is executing. - * @return -RT_ERROR The time parameter is invalid. + * -RT_EBUSY This work item is executing. + * -RT_ERROR The ticks parameter is invalid. */ -rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work, rt_tick_t time) +rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work, rt_tick_t ticks) { RT_ASSERT(queue != RT_NULL); RT_ASSERT(work != RT_NULL); + RT_ASSERT(ticks < RT_TICK_MAX / 2); - return _workqueue_submit_work(queue, work, time); + return _workqueue_submit_work(queue, work, ticks); } /** * @brief Submit a work item to the work queue without delay. This work item will be executed after the current work item. * - * @param queue A pointer to the workqueue object. - * @param work A pointer to the work item object. + * @param queue is a pointer to the workqueue object. + * + * @param work is a pointer to the work item object. * * @return RT_EOK Success. */ rt_err_t rt_workqueue_urgent_work(struct rt_workqueue *queue, struct rt_work *work) { rt_base_t level; + RT_ASSERT(queue != RT_NULL); RT_ASSERT(work != RT_NULL); @@ -339,24 +374,27 @@ rt_err_t rt_workqueue_urgent_work(struct rt_workqueue *queue, struct rt_work *wo /** * @brief Cancel a work item in the work queue. * - * @param queue A pointer to the workqueue object. - * @param work A pointer to the work item object. + * @param queue is a pointer to the workqueue object. + * + * @param work is a pointer to the work item object. * * @return RT_EOK Success. - * @return -RT_EBUSY This work item is executing. + * -RT_EBUSY This work item is executing. */ rt_err_t rt_workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *work) { RT_ASSERT(work != RT_NULL); RT_ASSERT(queue != RT_NULL); + return _workqueue_cancel_work(queue, work); } /** * @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 the workqueue object. - * @param work A pointer to the work item object. + * @param queue is a pointer to the workqueue object. + * + * @param work is a pointer to the work item object. * * @return RT_EOK Success. */ @@ -381,7 +419,7 @@ rt_err_t rt_workqueue_cancel_work_sync(struct rt_workqueue *queue, struct rt_wor /** * @brief This function will cancel all work items in work queue. * - * @param queue A pointer to the workqueue object. + * @param queue is a pointer to the workqueue object. * * @return RT_EOK Success. */ @@ -410,30 +448,46 @@ rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue *queue) } #ifdef RT_USING_SYSTEM_WORKQUEUE -static struct rt_workqueue *sys_workq; + +static struct rt_workqueue *sys_workq; /* system work queue */ /** * @brief Submit a work item to the system work queue with a delay. * - * @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. + * @param work is a pointer to the work item object. + * + * @param ticks is the delay OS ticks for the work item to be submitted to the work queue. + * + * NOTE: The max timeout tick should be no more than (RT_TICK_MAX/2 - 1) * * @return RT_EOK Success. - * @return -RT_EBUSY This work item is executing. - * @return -RT_ERROR The time parameter is invalid. + * -RT_EBUSY This work item is executing. + * -RT_ERROR The ticks parameter is invalid. + */ +rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t ticks) +{ + return rt_workqueue_submit_work(sys_workq, work, ticks); +} + +/** + * @brief Submit a work item to the system work queue without delay. This work item will be executed after the current work item. + * + * @param work is a pointer to the work item object. + * + * @return RT_EOK Success. */ -rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t time) +rt_err_t rt_work_urgent(struct rt_work *work) { - return rt_workqueue_submit_work(sys_workq, work, time); + return rt_workqueue_urgent_work(sys_workq, work); } /** * @brief Cancel a work item in the system work queue. * - * @param work A pointer to the work item object. + * @param work is a pointer to the work item object. * * @return RT_EOK Success. - * @return -RT_EBUSY This work item is executing. + * -RT_EBUSY This work item is executing. */ rt_err_t rt_work_cancel(struct rt_work *work) { @@ -445,7 +499,7 @@ static int rt_work_sys_workqueue_init(void) if (sys_workq != RT_NULL) return RT_EOK; - sys_workq = rt_workqueue_create("sys_work", RT_SYSTEM_WORKQUEUE_STACKSIZE, + sys_workq = rt_workqueue_create("sys workq", RT_SYSTEM_WORKQUEUE_STACKSIZE, RT_SYSTEM_WORKQUEUE_PRIORITY); RT_ASSERT(sys_workq != RT_NULL); diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c index da330b5e9c..c749897a08 100644 --- a/components/drivers/serial/serial.c +++ b/components/drivers/serial/serial.c @@ -37,7 +37,9 @@ #include <rtdbg.h> #ifdef RT_USING_POSIX_STDIO -#include <dfs_posix.h> +#include <dfs_file.h> +#include <fcntl.h> +#include <unistd.h> #include <poll.h> #include <sys/ioctl.h> diff --git a/components/drivers/serial/serial_v2.c b/components/drivers/serial/serial_v2.c index 16d376eeb9..3e0b057df5 100644 --- a/components/drivers/serial/serial_v2.c +++ b/components/drivers/serial/serial_v2.c @@ -17,7 +17,8 @@ #include <rtdbg.h> #ifdef RT_USING_POSIX_STDIO -#include <dfs_posix.h> +#include <unistd.h> +#include <fcntl.h> #include <poll.h> #include <sys/ioctl.h> diff --git a/components/drivers/spi/SConscript b/components/drivers/spi/SConscript index d6cb93f7f1..81d2c4c8a0 100644 --- a/components/drivers/spi/SConscript +++ b/components/drivers/spi/SConscript @@ -4,7 +4,7 @@ import rtconfig cwd = GetCurrentDir() src = ['spi_core.c', 'spi_dev.c'] CPPPATH = [cwd, cwd + '/../include'] -LOCAL_CCFLAGS = '' +LOCAL_CFLAGS = '' if GetDepend('RT_USING_QSPI'): src += ['qspi_core.c'] @@ -25,16 +25,16 @@ if GetDepend('RT_USING_SFUD'): CPPPATH += [cwd + '/sfud/inc'] if GetDepend('RT_SFUD_USING_SFDP'): src_device += ['sfud/src/sfud_sfdp.c'] - if rtconfig.CROSS_TOOL == 'gcc': - LOCAL_CCFLAGS += ' -std=c99' - elif rtconfig.CROSS_TOOL == 'keil': - if rtconfig.PLATFORM == 'armcc': - LOCAL_CCFLAGS += ' --c99' - elif rtconfig.PLATFORM == 'armclang': - LOCAL_CCFLAGS += ' -std=c99' + + if rtconfig.PLATFORM == 'gcc': + LOCAL_CFLAGS += ' -std=c99' + elif rtconfig.PLATFORM == 'armcc': + LOCAL_CFLAGS += ' --c99' + elif rtconfig.PLATFORM == 'armclang': + LOCAL_CFLAGS += ' -std=c99' src += src_device -group = DefineGroup('DeviceDrivers', src, depend = ['RT_USING_SPI'], CPPPATH = CPPPATH, LOCAL_CCFLAGS = LOCAL_CCFLAGS) +group = DefineGroup('DeviceDrivers', src, depend = ['RT_USING_SPI'], CPPPATH = CPPPATH, LOCAL_CFLAGS = LOCAL_CFLAGS) Return('group') |
