summaryrefslogtreecommitdiff
path: root/components/drivers
diff options
context:
space:
mode:
authorjonas <[email protected]>2021-09-02 10:36:07 +0800
committerjonas <[email protected]>2021-09-02 10:36:07 +0800
commitd72ee7b6cc19e3b0d5721b2b5fa047ed1a5fc7c4 (patch)
treeab7034a4df4cb5171a68c2236f9f831c8cd27ed0 /components/drivers
parentab43390fe2c0e672771b73cf610e739a419aa06f (diff)
parent8d175ab3d237dccc25450a8e12808fc87318eb2f (diff)
Merge branch 'master' of [email protected]:RT-Thread/rt-thread.git into bsp_hk32
# Conflicts: # .ignore_format.yml
Diffstat (limited to 'components/drivers')
-rw-r--r--components/drivers/misc/adc.c4
-rw-r--r--components/drivers/misc/dac.c4
-rw-r--r--components/drivers/misc/rt_drv_pwm.c4
-rw-r--r--components/drivers/mtd/mtd_nand.c8
-rw-r--r--components/drivers/rtc/rtc.c4
-rwxr-xr-xcomponents/drivers/sensors/sensor_cmd.c8
-rw-r--r--components/drivers/serial/serial.c85
-rw-r--r--components/drivers/spi/spi_flash_sfud.c5
-rw-r--r--components/drivers/src/completion.c27
-rw-r--r--components/drivers/wlan/wlan_cmd.c2
10 files changed, 125 insertions, 26 deletions
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/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/wlan/wlan_cmd.c b/components/drivers/wlan/wlan_cmd.c
index fde9065428..3b8a119784 100644
--- a/components/drivers/wlan/wlan_cmd.c
+++ b/components/drivers/wlan/wlan_cmd.c
@@ -586,7 +586,7 @@ static int wifi_msh(int argc, char *argv[])
return 0;
}
-#if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH)
+#if defined(RT_USING_FINSH)
FINSH_FUNCTION_EXPORT_ALIAS(wifi_msh, __cmd_wifi, wifi command.);
#endif