diff options
| author | Lim-LinYuanbo <[email protected]> | 2021-09-08 22:45:31 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-09-08 22:45:31 +0800 |
| commit | b404f69f851817c62697074ffb363294b91585c6 (patch) | |
| tree | f5f31152993843a5e07559a6b7b0caddcc9ebd0a /components/drivers | |
| parent | 49fcf9f4cd436d30d2df8c4e24b751194c32f43b (diff) | |
| parent | 7fa1c819ee852937705d948a58f0218c422ea6b1 (diff) | |
Merge branch 'master' into master
Diffstat (limited to 'components/drivers')
| -rw-r--r-- | components/drivers/can/can.c | 3 | ||||
| -rw-r--r-- | components/drivers/include/ipc/ringblk_buf.h | 5 | ||||
| -rw-r--r-- | components/drivers/include/ipc/ringbuffer.h | 8 | ||||
| -rw-r--r-- | components/drivers/include/ipc/workqueue.h | 8 | ||||
| -rw-r--r-- | components/drivers/misc/adc.c | 4 | ||||
| -rw-r--r-- | components/drivers/misc/dac.c | 4 | ||||
| -rw-r--r-- | components/drivers/misc/rt_drv_pwm.c | 4 | ||||
| -rw-r--r-- | components/drivers/mtd/mtd_nand.c | 8 | ||||
| -rw-r--r-- | components/drivers/rtc/alarm.c | 2 | ||||
| -rw-r--r-- | components/drivers/rtc/rtc.c | 4 | ||||
| -rwxr-xr-x | components/drivers/sensors/sensor_cmd.c | 8 | ||||
| -rw-r--r-- | components/drivers/serial/serial.c | 85 | ||||
| -rw-r--r-- | components/drivers/spi/spi_flash_sfud.c | 5 | ||||
| -rw-r--r-- | components/drivers/src/completion.c | 27 | ||||
| -rw-r--r-- | components/drivers/src/ringblk_buf.c | 4 | ||||
| -rw-r--r-- | components/drivers/src/ringbuffer.c | 101 | ||||
| -rw-r--r-- | components/drivers/src/workqueue.c | 87 | ||||
| -rw-r--r-- | components/drivers/watchdog/watchdog.c | 2 | ||||
| -rw-r--r-- | components/drivers/wlan/wlan_cmd.c | 4 |
19 files changed, 324 insertions, 49 deletions
diff --git a/components/drivers/can/can.c b/components/drivers/can/can.c index 55444c3a0e..358220013f 100644 --- a/components/drivers/can/can.c +++ b/components/drivers/can/can.c @@ -966,6 +966,5 @@ int cmd_canstat(int argc, void **argv) } return 0; } -FINSH_FUNCTION_EXPORT_ALIAS(cmd_canstat, __cmd_canstat, Stat Can Device Status.); +MSH_CMD_EXPORT_ALIAS(cmd_canstat, canstat, stat can device status); #endif - 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/include/ipc/ringbuffer.h b/components/drivers/include/ipc/ringbuffer.h index 71c4801253..7da50225b3 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 comments for function interface. */ #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 the buffer size of the ring buffer object. + * + * @param rb A pointer to the ring buffer 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 03904d852e..776709a8ab 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 comments for rt_work_init() */ #ifndef WORKQUEUE_H__ #define WORKQUEUE_H__ @@ -67,6 +68,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 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) { diff --git a/components/drivers/misc/adc.c b/components/drivers/misc/adc.c index d8f79e058b..a73fcc54e3 100644 --- a/components/drivers/misc/adc.c +++ b/components/drivers/misc/adc.c @@ -144,7 +144,7 @@ rt_err_t rt_adc_disable(rt_adc_device_t dev, rt_uint32_t channel) return result; } -#ifdef FINSH_USING_MSH +#ifdef RT_USING_FINSH static int adc(int argc, char **argv) { @@ -232,4 +232,4 @@ static int adc(int argc, char **argv) } MSH_CMD_EXPORT(adc, adc function); -#endif /* FINSH_USING_MSH */ +#endif /* RT_USING_FINSH */ diff --git a/components/drivers/misc/dac.c b/components/drivers/misc/dac.c index 784a503888..45b90d2106 100644 --- a/components/drivers/misc/dac.c +++ b/components/drivers/misc/dac.c @@ -141,7 +141,7 @@ rt_err_t rt_dac_disabled(rt_dac_device_t dev, rt_uint32_t channel) return result; } -#ifdef FINSH_USING_MSH +#ifdef RT_USING_FINSH static int dac(int argc, char **argv) { @@ -228,4 +228,4 @@ static int dac(int argc, char **argv) } MSH_CMD_EXPORT(dac, dac function); -#endif /* FINSH_USING_MSH */ +#endif /* RT_USING_FINSH */ diff --git a/components/drivers/misc/rt_drv_pwm.c b/components/drivers/misc/rt_drv_pwm.c index f274f509e2..04895868e2 100644 --- a/components/drivers/misc/rt_drv_pwm.c +++ b/components/drivers/misc/rt_drv_pwm.c @@ -198,7 +198,7 @@ rt_err_t rt_pwm_get(struct rt_device_pwm *device, struct rt_pwm_configuration *c FINSH_FUNCTION_EXPORT_ALIAS(rt_pwm_enable, pwm_enable, enable pwm by channel.); FINSH_FUNCTION_EXPORT_ALIAS(rt_pwm_set, pwm_set, set pwm.); -#ifdef FINSH_USING_MSH +#ifdef RT_USING_FINSH static int pwm_enable(int argc, char **argv) { int result = 0; @@ -323,5 +323,5 @@ _exit: } MSH_CMD_EXPORT(pwm_get, pwm_get <pwm_dev> <channel>); -#endif /* FINSH_USING_MSH */ +#endif /* RT_USING_FINSH */ #endif /* RT_USING_FINSH */ diff --git a/components/drivers/mtd/mtd_nand.c b/components/drivers/mtd/mtd_nand.c index 646625ade5..f516f9b147 100644 --- a/components/drivers/mtd/mtd_nand.c +++ b/components/drivers/mtd/mtd_nand.c @@ -278,7 +278,7 @@ int mtd_nand_erase_all(const char *name) return 0; } -#ifdef FINSH_USING_MSH +#ifdef RT_USING_FINSH static void mtd_nand(int argc, char **argv) { /* If the number of arguments less than 2 */ @@ -346,16 +346,16 @@ help: } } MSH_CMD_EXPORT(mtd_nand, MTD nand device test function); -#endif /* FINSH_USING_MSH */ +#endif /* RT_USING_FINSH */ -#ifndef FINSH_USING_MSH_ONLY +#ifndef RT_USING_FINSH_ONLY FINSH_FUNCTION_EXPORT_ALIAS(mtd_nandid, nand_id, read ID - nandid(name)); FINSH_FUNCTION_EXPORT_ALIAS(mtd_nand_read, nand_read, read page in nand - nand_read(name, block, page)); FINSH_FUNCTION_EXPORT_ALIAS(mtd_nand_readoob, nand_readoob, read spare data in nand - nand_readoob(name, block, page)); FINSH_FUNCTION_EXPORT_ALIAS(mtd_nand_write, nand_write, write dump data to nand - nand_write(name, block, page)); FINSH_FUNCTION_EXPORT_ALIAS(mtd_nand_erase, nand_erase, nand_erase(name, block)); FINSH_FUNCTION_EXPORT_ALIAS(mtd_nand_erase_all, nand_erase_all, erase all of nand device - nand_erase_all(name, block)); -#endif /* FINSH_USING_MSH_ONLY */ +#endif /* RT_USING_FINSH_ONLY */ #endif /* defined(RT_MTD_NAND_DEBUG) && defined(RT_USING_FINSH) */ diff --git a/components/drivers/rtc/alarm.c b/components/drivers/rtc/alarm.c index cd0a976328..2bcc51f2ee 100644 --- a/components/drivers/rtc/alarm.c +++ b/components/drivers/rtc/alarm.c @@ -777,7 +777,7 @@ void rt_alarm_dump(void) rt_kprintf("+----+---------------------+------+------+----+\n"); } -FINSH_FUNCTION_EXPORT_ALIAS(rt_alarm_dump, __cmd_alarm_dump, dump alarm info); +MSH_CMD_EXPORT_ALIAS(rt_alarm_dump, rt_alarm_dump, dump alarm info); /** \brief initialize alarm service system * diff --git a/components/drivers/rtc/rtc.c b/components/drivers/rtc/rtc.c index 5eabeed2dd..35e7ddc3c4 100644 --- a/components/drivers/rtc/rtc.c +++ b/components/drivers/rtc/rtc.c @@ -218,7 +218,7 @@ rt_err_t set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second) return ret; } -#ifdef FINSH_USING_MSH +#ifdef RT_USING_FINSH #include <finsh.h> /** * get date and time or set (local timezone) [year month day hour min sec] @@ -283,6 +283,6 @@ static void date(uint8_t argc, char **argv) } } MSH_CMD_EXPORT(date, get date and time or set (local timezone) [year month day hour min sec]) -#endif /* FINSH_USING_MSH */ +#endif /* RT_USING_FINSH */ #endif /* RT_USING_RTC */ diff --git a/components/drivers/sensors/sensor_cmd.c b/components/drivers/sensors/sensor_cmd.c index 0f0ab66d63..14e53b1c22 100755 --- a/components/drivers/sensors/sensor_cmd.c +++ b/components/drivers/sensors/sensor_cmd.c @@ -155,7 +155,7 @@ static void sensor_fifo(int argc, char **argv) rt_device_control(dev, RT_SENSOR_CTRL_SET_ODR, (void *)20); } -#ifdef FINSH_USING_MSH +#ifdef RT_USING_FINSH MSH_CMD_EXPORT(sensor_fifo, Sensor fifo mode test function); #endif @@ -219,7 +219,7 @@ static void sensor_int(int argc, char **argv) } rt_device_control(dev, RT_SENSOR_CTRL_SET_ODR, (void *)20); } -#ifdef FINSH_USING_MSH +#ifdef RT_USING_FINSH MSH_CMD_EXPORT(sensor_int, Sensor interrupt mode test function); #endif @@ -268,7 +268,7 @@ static void sensor_polling(int argc, char **argv) } rt_device_close(dev); } -#ifdef FINSH_USING_MSH +#ifdef RT_USING_FINSH MSH_CMD_EXPORT(sensor_polling, Sensor polling mode test function); #endif @@ -496,6 +496,6 @@ static void sensor(int argc, char **argv) LOG_W("Unknown command, please enter 'sensor' get help information!"); } } -#ifdef FINSH_USING_MSH +#ifdef RT_USING_FINSH MSH_CMD_EXPORT(sensor, sensor test function); #endif diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c index 76298ea153..97068b30aa 100644 --- a/components/drivers/serial/serial.c +++ b/components/drivers/serial/serial.c @@ -24,7 +24,8 @@ * 2018-12-08 Ernest Chen add DMA choice * 2020-09-14 WillianChan add a line feed to the carriage return character * when using interrupt tx - * 2020-12-14 Meco Man add function of setting window's size(TIOCSWINSZ) + * 2020-12-14 Meco Man implement function of setting window's size(TIOCSWINSZ) + * 2021-08-22 Meco Man implement function of getting window's size(TIOCGWINSZ) */ #include <rthw.h> @@ -1122,13 +1123,83 @@ static rt_err_t rt_serial_control(struct rt_device *dev, case TIOCGWINSZ: { struct winsize* p_winsize; - p_winsize = (struct winsize*)args; - /* TODO: get windows size from console */ - p_winsize->ws_col = 80; - p_winsize->ws_row = 24; - p_winsize->ws_xpixel = 0;/*unused*/ - p_winsize->ws_ypixel = 0;/*unused*/ + + if(rt_thread_self() != rt_thread_find("tshell")) + { + /* only can be used in tshell thread; otherwise, return default size */ + p_winsize->ws_col = 80; + p_winsize->ws_row = 24; + } + else + { + #define _TIO_BUFLEN 20 + char _tio_buf[_TIO_BUFLEN]; + unsigned char cnt1, cnt2, cnt3, i; + char row_s[4], col_s[4]; + char *p; + + rt_memset(_tio_buf, 0, _TIO_BUFLEN); + + /* send the command to terminal for getting the window size of the terminal */ + rt_kprintf("\033[18t"); + + /* waiting for the response from the terminal */ + i = 0; + while(i < _TIO_BUFLEN) + { + _tio_buf[i] = getchar(); + if(_tio_buf[i] != 't') + { + i ++; + } + else + { + break; + } + } + if(i == _TIO_BUFLEN) + { + /* buffer overloaded, and return default size */ + p_winsize->ws_col = 80; + p_winsize->ws_row = 24; + break; + } + + /* interpreting data eg: "\033[8;1;15t" which means row is 1 and col is 15 (unit: size of ONE character) */ + rt_memset(row_s,0,4); + rt_memset(col_s,0,4); + cnt1 = 0; + while(_tio_buf[cnt1] != ';' && cnt1 < _TIO_BUFLEN) + { + cnt1++; + } + cnt2 = ++cnt1; + while(_tio_buf[cnt2] != ';' && cnt2 < _TIO_BUFLEN) + { + cnt2++; + } + p = row_s; + while(cnt1 < cnt2) + { + *p++ = _tio_buf[cnt1++]; + } + p = col_s; + cnt2++; + cnt3 = rt_strlen(_tio_buf) - 1; + while(cnt2 < cnt3) + { + *p++ = _tio_buf[cnt2++]; + } + + /* load the window size date */ + p_winsize->ws_col = atoi(col_s); + p_winsize->ws_row = atoi(row_s); + #undef _TIO_BUFLEN + } + + p_winsize->ws_xpixel = 0;/* unused */ + p_winsize->ws_ypixel = 0;/* unused */ } break; #endif /*RT_USING_POSIX_TERMIOS*/ diff --git a/components/drivers/spi/spi_flash_sfud.c b/components/drivers/spi/spi_flash_sfud.c index ba673edf62..bcc49e8df4 100644 --- a/components/drivers/spi/spi_flash_sfud.c +++ b/components/drivers/spi/spi_flash_sfud.c @@ -9,6 +9,7 @@ */ #include <stdint.h> +#include <string.h> #include <rtdevice.h> #include "spi_flash.h" #include "spi_flash_sfud.h" @@ -508,7 +509,7 @@ __error: return RT_NULL; } -#if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) +#if defined(RT_USING_FINSH) #include <finsh.h> @@ -773,6 +774,6 @@ static void sf(uint8_t argc, char **argv) { } } MSH_CMD_EXPORT(sf, SPI Flash operate.); -#endif /* defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) */ +#endif /* defined(RT_USING_FINSH) */ #endif /* RT_USING_SFUD */ diff --git a/components/drivers/src/completion.c b/components/drivers/src/completion.c index b91ae3d6dc..f13718f9b3 100644 --- a/components/drivers/src/completion.c +++ b/components/drivers/src/completion.c @@ -6,6 +6,7 @@ * Change Logs: * Date Author Notes * 2012-09-30 Bernard first version. + * 2021-08-18 chenyingchun add comments */ #include <rthw.h> @@ -15,6 +16,11 @@ #define RT_COMPLETED 1 #define RT_UNCOMPLETED 0 +/** + * @brief This function will initialize a completion object. + * + * @param completion is a pointer to a completion object. + */ void rt_completion_init(struct rt_completion *completion) { rt_base_t level; @@ -27,6 +33,22 @@ void rt_completion_init(struct rt_completion *completion) } RTM_EXPORT(rt_completion_init); +/** + * @brief This function will wait for a completion, if the completion is unavailable, the thread shall wait for + * the completion up to a specified time. + * + * @param completion is a pointer to a completion object. + * + * @param timeout is a timeout period (unit: OS ticks). If the completion is unavailable, the thread will wait for + * the completion done up to the amount of time specified by the argument. + * NOTE: Generally, we use the macro RT_WAITING_FOREVER to set this parameter, which means that when the + * completion is unavailable, the thread will be waitting forever. + * + * @return Return the operation status. ONLY when the return value is RT_EOK, the operation is successful. + * If the return value is any other values, it means that the completion wait failed. + * + * @warning This function can ONLY be called in the thread context. It MUST NOT be called in interrupt context. + */ rt_err_t rt_completion_wait(struct rt_completion *completion, rt_int32_t timeout) { @@ -94,6 +116,11 @@ __exit: } RTM_EXPORT(rt_completion_wait); +/** + * @brief This function indicates a completion has done. + * + * @param completion is a pointer to a completion object. + */ void rt_completion_done(struct rt_completion *completion) { rt_base_t level; 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; diff --git a/components/drivers/src/ringbuffer.c b/components/drivers/src/ringbuffer.c index f01a594609..3e76b1774a 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 comments for function interface. */ #include <rtthread.h> @@ -27,6 +28,13 @@ rt_inline enum rt_ringbuffer_state rt_ringbuffer_status(struct rt_ringbuffer *rb return RT_RINGBUFFER_HALFFULL; } +/** + * @brief Initialize the ring buffer object. + * + * @param rb A pointer to the ring buffer object. + * @param pool A pointer to the buffer. + * @param size The 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 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 data size we put into the ring buffer. */ 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 + * @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. * - * When the buffer is full, it will discard the old data. + * @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, @@ -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 data from the ring buffer. + * + * @param rb A pointer to the ring buffer. + * @param ptr A pointer to the data buffer. + * @param length The size of the data we want to 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, @@ -196,7 +220,14 @@ rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb, RTM_EXPORT(rt_ringbuffer_get); /** - * peak data from 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. + * + * @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) { @@ -230,7 +261,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 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 put into the ring buffer. + * + * @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) { @@ -258,9 +294,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 + * @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 put into the ring buffer. * - * When the buffer is full, it will discard one old data. + * @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) { @@ -295,7 +334,13 @@ 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 byte from the 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 The ring buffer is empty. + * @return 1 Success */ rt_size_t rt_ringbuffer_getchar(struct rt_ringbuffer *rb, rt_uint8_t *ch) { @@ -305,7 +350,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) @@ -323,7 +368,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 ring buffer in bytes. + * + * @param rb The pointer to the ring buffer object. + * + * @return Return the size of data in the ring buffer in bytes. */ rt_size_t rt_ringbuffer_data_len(struct rt_ringbuffer *rb) { @@ -335,16 +384,22 @@ rt_size_t rt_ringbuffer_data_len(struct rt_ringbuffer *rb) return rb->buffer_size; case RT_RINGBUFFER_HALFFULL: default: - if (rb->write_index > rb->read_index) - return rb->write_index - rb->read_index; + { + rt_size_t wi = rb->write_index, ri = rb->read_index; + + if (wi > ri) + return wi - ri; else - return rb->buffer_size - (rb->read_index - rb->write_index); - }; + return rb->buffer_size - (ri - wi); + } + } } RTM_EXPORT(rt_ringbuffer_data_len); /** - * empty the rb + * @brief Reset the ring buffer object, and clear all contents in the buffer. + * + * @param rb A pointer to the ring buffer object. */ void rt_ringbuffer_reset(struct rt_ringbuffer *rb) { @@ -359,7 +414,14 @@ RTM_EXPORT(rt_ringbuffer_reset); #ifdef RT_USING_HEAP -struct rt_ringbuffer* rt_ringbuffer_create(rt_uint16_t size) +/** + * @brief Create a ring buffer object with a given size. + * + * @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 this creation failed. + */ +struct rt_ringbuffer *rt_ringbuffer_create(rt_uint16_t size) { struct rt_ringbuffer *rb; rt_uint8_t *pool; @@ -386,6 +448,11 @@ exit: } RTM_EXPORT(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. + */ 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 8fcfd52688..b5d803472b 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 comments for function interface. */ #include <rthw.h> @@ -209,6 +210,15 @@ static void _delayed_work_timeout_handler(void *parameter) } } +/** + * @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. + * + * @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) { struct rt_workqueue *queue = RT_NULL; @@ -236,6 +246,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 the workqueue object. + * + * @return RT_EOK Success. + */ rt_err_t rt_workqueue_destroy(struct rt_workqueue *queue) { RT_ASSERT(queue != RT_NULL); @@ -248,6 +265,15 @@ rt_err_t rt_workqueue_destroy(struct rt_workqueue *queue) return RT_EOK; } +/** + * @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. + * + * @return RT_EOK Success. + * @return -RT_EBUSY This work item is executing. + */ rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work) { RT_ASSERT(queue != RT_NULL); @@ -256,6 +282,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. + * + * @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 The time parameter 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 +301,14 @@ rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *wo return _workqueue_submit_work(queue, work, time); } +/** + * @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. + * + * @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 +336,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 the workqueue object. + * @param work A pointer to the work item object. + * + * @return RT_EOK Success. + * @return -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); @@ -298,6 +352,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 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. + * + * @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 +378,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 items in work queue. + * + * @param queue A pointer to the workqueue object. + * + * @return RT_EOK Success. + */ rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue *queue) { struct rt_work *work; @@ -343,11 +412,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. + * + * @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 The time parameter 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 the system work queue. + * + * @param work A pointer to the work item object. + * + * @return RT_EOK Success. + * @return -RT_EBUSY This work item is executing. + */ rt_err_t rt_work_cancel(struct rt_work *work) { return rt_workqueue_cancel_work(sys_workq, work); diff --git a/components/drivers/watchdog/watchdog.c b/components/drivers/watchdog/watchdog.c index 9108d834c6..d26626863d 100644 --- a/components/drivers/watchdog/watchdog.c +++ b/components/drivers/watchdog/watchdog.c @@ -89,7 +89,7 @@ rt_err_t rt_hw_watchdog_register(struct rt_watchdog_device *wtd, device = &(wtd->parent); - device->type = RT_Device_Class_Miscellaneous; + device->type = RT_Device_Class_Security; device->rx_indicate = RT_NULL; device->tx_complete = RT_NULL; diff --git a/components/drivers/wlan/wlan_cmd.c b/components/drivers/wlan/wlan_cmd.c index fde9065428..52c25f6755 100644 --- a/components/drivers/wlan/wlan_cmd.c +++ b/components/drivers/wlan/wlan_cmd.c @@ -586,8 +586,8 @@ static int wifi_msh(int argc, char *argv[]) return 0; } -#if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) -FINSH_FUNCTION_EXPORT_ALIAS(wifi_msh, __cmd_wifi, wifi command.); +#if defined(RT_USING_FINSH) +MSH_CMD_EXPORT_ALIAS(wifi_msh, wifi, wifi command); #endif #endif |
