From f3ee2dd186582715fb0d9bfca5edf8594f9a0d79 Mon Sep 17 00:00:00 2001 From: Fanming Date: Tue, 17 Dec 2019 17:53:16 +0800 Subject: [drivers/sensor]disable irq only when the sensor and module sensors are all cloesed. --- components/drivers/sensors/sensor.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'components') diff --git a/components/drivers/sensors/sensor.c b/components/drivers/sensors/sensor.c index 91b256bd66..0539ffd90d 100644 --- a/components/drivers/sensors/sensor.c +++ b/components/drivers/sensors/sensor.c @@ -211,12 +211,6 @@ static rt_err_t rt_sensor_close(rt_device_t dev) sensor->config.power = RT_SENSOR_POWER_DOWN; } - /* Sensor disable interrupt */ - if (sensor->config.irq_pin.pin != RT_PIN_NONE) - { - rt_pin_irq_enable(sensor->config.irq_pin.pin, RT_FALSE); - } - if (sensor->module != RT_NULL && sensor->info.fifo_max > 0 && sensor->data_buf != RT_NULL) { for (i = 0; i < sensor->module->sen_num; i ++) @@ -235,6 +229,11 @@ static rt_err_t rt_sensor_close(rt_device_t dev) } } } + /* Sensor disable interrupt */ + if (sensor->config.irq_pin.pin != RT_PIN_NONE) + { + rt_pin_irq_enable(sensor->config.irq_pin.pin, RT_FALSE); + } __exit: if (sensor->module) -- cgit v1.3.1 From 3ac86d08cbcd3e603850ab6ac6058f7fa6287b3d Mon Sep 17 00:00:00 2001 From: redoc <619675912@qq.com> Date: Thu, 7 Jan 2021 16:28:54 +0800 Subject: 解决添加RT_USING_MTD_NOR编译报错的问题。 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/spi/spi_flash.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'components') diff --git a/components/drivers/spi/spi_flash.h b/components/drivers/spi/spi_flash.h index 30db32474a..19adefaba6 100644 --- a/components/drivers/spi/spi_flash.h +++ b/components/drivers/spi/spi_flash.h @@ -6,11 +6,18 @@ * Change Logs: * Date Author Notes * 2016/5/20 bernard the first version + * 2020/1/7 redoc add include */ #ifndef SPI_FLASH_H__ #define SPI_FLASH_H__ +#include + +#ifdef RT_USING_MTD_NOR +#include "drivers/mtd_nor.h" +#endif + struct spi_flash_device { struct rt_device flash_device; -- cgit v1.3.1 From aed3cc162fa83971c9cd1afe42809746de4246b0 Mon Sep 17 00:00:00 2001 From: Trisuborn <553070703@qq.com> Date: Tue, 19 Jan 2021 17:14:32 +0800 Subject: 为stm32的PWM驱动添加对STM32H7的支持、添加互补PWM功能的支持,补全pwm_get命令 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/stm32/libraries/HAL_Drivers/drv_pwm.c | 38 +++++++++--- components/drivers/include/drivers/rt_drv_pwm.h | 16 +++-- components/drivers/misc/rt_drv_pwm.c | 82 +++++++++++++++++++++---- 3 files changed, 111 insertions(+), 25 deletions(-) (limited to 'components') diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c b/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c index 64f283dabd..ab3897c569 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c @@ -9,8 +9,10 @@ */ #include + #ifdef RT_USING_PWM #include "drv_config.h" +#include //#define DRV_DEBUG #define LOG_TAG "drv.pwm" @@ -167,13 +169,27 @@ static rt_err_t drv_pwm_enable(TIM_HandleTypeDef *htim, struct rt_pwm_configurat /* Converts the channel number to the channel number of Hal library */ rt_uint32_t channel = 0x04 * (configuration->channel - 1); - if (!enable) + if (!configuration->complementary) { - HAL_TIM_PWM_Stop(htim, channel); + if (!enable) + { + HAL_TIM_PWM_Stop(htim, channel); + } + else + { + HAL_TIM_PWM_Start(htim, channel); + } } - else + else if (configuration->complementary) { - HAL_TIM_PWM_Start(htim, channel); + if (!enable) + { + HAL_TIMEx_PWMN_Stop(htim, channel); + } + else + { + HAL_TIMEx_PWMN_Start(htim, channel); + } } return RT_EOK; @@ -187,21 +203,23 @@ static rt_err_t drv_pwm_get(TIM_HandleTypeDef *htim, struct rt_pwm_configuration #if defined(SOC_SERIES_STM32F2) || defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) if (htim->Instance == TIM9 || htim->Instance == TIM10 || htim->Instance == TIM11) -#elif defined(SOC_SERIES_STM32L4) +#elif defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32H7) if (htim->Instance == TIM15 || htim->Instance == TIM16 || htim->Instance == TIM17) #elif defined(SOC_SERIES_STM32MP1) - if (htim->Instance == TIM4) + if (htim->Instance == TIM4) #elif defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32G0) if (0) #endif { #if !defined(SOC_SERIES_STM32F0) && !defined(SOC_SERIES_STM32G0) tim_clock = HAL_RCC_GetPCLK2Freq() * 2; +#else + tim_clock = HAL_RCC_GetPCLK2Freq(); #endif } else { -#if defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32G0) +#if defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32H7) tim_clock = HAL_RCC_GetPCLK1Freq(); #else tim_clock = HAL_RCC_GetPCLK1Freq() * 2; @@ -234,7 +252,7 @@ static rt_err_t drv_pwm_set(TIM_HandleTypeDef *htim, struct rt_pwm_configuration #if defined(SOC_SERIES_STM32F2) || defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) if (htim->Instance == TIM9 || htim->Instance == TIM10 || htim->Instance == TIM11) -#elif defined(SOC_SERIES_STM32L4) +#elif defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32H7) if (htim->Instance == TIM15 || htim->Instance == TIM16 || htim->Instance == TIM17) #elif defined(SOC_SERIES_STM32MP1) if (htim->Instance == TIM4) @@ -244,11 +262,13 @@ static rt_err_t drv_pwm_set(TIM_HandleTypeDef *htim, struct rt_pwm_configuration { #if !defined(SOC_SERIES_STM32F0) && !defined(SOC_SERIES_STM32G0) tim_clock = HAL_RCC_GetPCLK2Freq() * 2; +#else + tim_clock = HAL_RCC_GetPCLK2Freq(); #endif } else { -#if defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32G0) +#if defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32H7) tim_clock = HAL_RCC_GetPCLK1Freq(); #else tim_clock = HAL_RCC_GetPCLK1Freq() * 2; diff --git a/components/drivers/include/drivers/rt_drv_pwm.h b/components/drivers/include/drivers/rt_drv_pwm.h index 16de4c6ab8..4b436758d9 100644 --- a/components/drivers/include/drivers/rt_drv_pwm.h +++ b/components/drivers/include/drivers/rt_drv_pwm.h @@ -21,9 +21,15 @@ struct rt_pwm_configuration { - rt_uint32_t channel; /* 0-n */ - rt_uint32_t period; /* unit:ns 1ns~4.29s:1Ghz~0.23hz */ - rt_uint32_t pulse; /* unit:ns (pulse<=period) */ + rt_uint32_t channel; /* 0-n */ + rt_uint32_t period; /* unit:ns 1ns~4.29s:1Ghz~0.23hz */ + rt_uint32_t pulse; /* unit:ns (pulse<=period) */ + + /* + * RT_TRUE : The channel of pwm is complememtary. + * RT_FALSE : The channel of pwm is nomal. + */ + rt_bool_t complementary; }; struct rt_device_pwm; @@ -40,8 +46,8 @@ struct rt_device_pwm rt_err_t rt_device_pwm_register(struct rt_device_pwm *device, const char *name, const struct rt_pwm_ops *ops, const void *user_data); -rt_err_t rt_pwm_enable(struct rt_device_pwm *device, int channel); -rt_err_t rt_pwm_disable(struct rt_device_pwm *device, int channel); +rt_err_t rt_pwm_enable(struct rt_device_pwm *device, int channel, rt_uint8_t complementary); +rt_err_t rt_pwm_disable(struct rt_device_pwm *device, int channel, rt_uint8_t complementary); rt_err_t rt_pwm_set(struct rt_device_pwm *device, int channel, rt_uint32_t period, rt_uint32_t pulse); #endif /* __DRV_PWM_H_INCLUDE__ */ diff --git a/components/drivers/misc/rt_drv_pwm.c b/components/drivers/misc/rt_drv_pwm.c index 97d38d51b3..03ef3353a3 100644 --- a/components/drivers/misc/rt_drv_pwm.c +++ b/components/drivers/misc/rt_drv_pwm.c @@ -126,7 +126,7 @@ rt_err_t rt_device_pwm_register(struct rt_device_pwm *device, const char *name, return result; } -rt_err_t rt_pwm_enable(struct rt_device_pwm *device, int channel) +rt_err_t rt_pwm_enable(struct rt_device_pwm *device, int channel, rt_uint8_t complementary) { rt_err_t result = RT_EOK; struct rt_pwm_configuration configuration = {0}; @@ -137,12 +137,13 @@ rt_err_t rt_pwm_enable(struct rt_device_pwm *device, int channel) } configuration.channel = channel; + configuration.complementary = complementary ? (RT_TRUE) : (RT_FALSE); result = rt_device_control(&device->parent, PWM_CMD_ENABLE, &configuration); return result; } -rt_err_t rt_pwm_disable(struct rt_device_pwm *device, int channel) +rt_err_t rt_pwm_disable(struct rt_device_pwm *device, int channel, rt_uint8_t complementary) { rt_err_t result = RT_EOK; struct rt_pwm_configuration configuration = {0}; @@ -153,6 +154,7 @@ rt_err_t rt_pwm_disable(struct rt_device_pwm *device, int channel) } configuration.channel = channel; + configuration.complementary = complementary ? (RT_TRUE) : (RT_FALSE); result = rt_device_control(&device->parent, PWM_CMD_DISABLE, &configuration); return result; @@ -176,6 +178,20 @@ rt_err_t rt_pwm_set(struct rt_device_pwm *device, int channel, rt_uint32_t perio return result; } +rt_err_t rt_pwm_get(struct rt_device_pwm *device, struct rt_pwm_configuration *cfg) +{ + rt_err_t result = RT_EOK; + + if (!device) + { + return -RT_EIO; + } + + result = rt_device_control(&device->parent, PWM_CMD_GET, cfg); + + return result; +} + #ifdef RT_USING_FINSH #include @@ -188,9 +204,10 @@ static int pwm_enable(int argc, char **argv) int result = 0; struct rt_device_pwm *device = RT_NULL; - if (argc != 3) + if (argc != 4) { - rt_kprintf("Usage: pwm_enable pwm1 1\n"); + rt_kprintf("Usage: pwm_enable pwm1 1 1\n"); + rt_kprintf(" pwm_enable \n"); result = -RT_ERROR; goto _exit; } @@ -202,21 +219,22 @@ static int pwm_enable(int argc, char **argv) goto _exit; } - result = rt_pwm_enable(device, atoi(argv[2])); + result = rt_pwm_enable(device, atoi(argv[2]), atoi(argv[3])); _exit: return result; } -MSH_CMD_EXPORT(pwm_enable, pwm_enable pwm1 1); +MSH_CMD_EXPORT(pwm_enable, pwm_enable ); static int pwm_disable(int argc, char **argv) { int result = 0; struct rt_device_pwm *device = RT_NULL; - if (argc != 3) + if (argc != 4) { - rt_kprintf("Usage: pwm_enable pwm1 1\n"); + rt_kprintf("Usage: pwm_enable pwm1 1 1\n"); + rt_kprintf(" pwm_disable \n"); result = -RT_ERROR; goto _exit; } @@ -228,12 +246,12 @@ static int pwm_disable(int argc, char **argv) goto _exit; } - result = rt_pwm_disable(device, atoi(argv[2])); + result = rt_pwm_disable(device, atoi(argv[2]), atoi(argv[3])); _exit: return result; } -MSH_CMD_EXPORT(pwm_disable, pwm_disable pwm1 1); +MSH_CMD_EXPORT(pwm_disable, pwm_disable ); static int pwm_set(int argc, char **argv) { @@ -243,6 +261,7 @@ static int pwm_set(int argc, char **argv) if (argc != 5) { rt_kprintf("Usage: pwm_set pwm1 1 100 50\n"); + rt_kprintf("Usage: pwm_set \n"); result = -RT_ERROR; goto _exit; } @@ -259,7 +278,48 @@ static int pwm_set(int argc, char **argv) _exit: return result; } -MSH_CMD_EXPORT(pwm_set, pwm_set pwm1 1 100 50); +MSH_CMD_EXPORT(pwm_set, pwm_set ); + + +static int pwm_get(int argc, char **argv) +{ + int result = 0; + struct rt_device_pwm *device = RT_NULL; + struct rt_pwm_configuration cfg = {0}; + + if (argc != 3) + { + rt_kprintf("Usage: pwm_get pwm1 1\n"); + rt_kprintf(" pwm_get \n"); + result = -RT_ERROR; + goto _exit; + } + + device = (struct rt_device_pwm *)rt_device_find(argv[1]); + if (!device) + { + result = -RT_EIO; + goto _exit; + } + + cfg.channel = atoi(argv[2]); + result = rt_pwm_get(device, &cfg); + if (result != RT_EOK) + { + rt_kprintf("Get info of device: [%s] error.\n", argv[1]); + } + else + { + rt_kprintf("Get info of device: [%s]:\n", argv[1]); + rt_kprintf("period : %d\n", cfg.period); + rt_kprintf("pulse : %d\n", cfg.pulse); + rt_kprintf("Duty cycle : %d%%\n", (int)(((double)(cfg.pulse)/(cfg.period)) * 100)); + } + +_exit: + return result; +} +MSH_CMD_EXPORT(pwm_get, pwm_get ); #endif /* FINSH_USING_MSH */ #endif /* RT_USING_FINSH */ -- cgit v1.3.1 From 74691ea7831fe155a54d5784939ad523cca1c3c7 Mon Sep 17 00:00:00 2001 From: zhouji92 <956133287@qq.com> Date: Mon, 18 Jan 2021 15:02:28 +0800 Subject: [fix] 修复使用lwip 2.1.2作为协议栈,并使能dhcp server选项时,编译报错问题。 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/net/lwip_dhcpd/SConscript | 2 +- components/net/lwip_dhcpd/dhcp_server.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'components') diff --git a/components/net/lwip_dhcpd/SConscript b/components/net/lwip_dhcpd/SConscript index 16c673036a..837eb043e4 100644 --- a/components/net/lwip_dhcpd/SConscript +++ b/components/net/lwip_dhcpd/SConscript @@ -2,7 +2,7 @@ from building import * cwd = GetCurrentDir() -if GetDepend('RT_USING_LWIP202') or GetDepend('RT_USING_LWIP210') : +if GetDepend('RT_USING_LWIP202') or GetDepend('RT_USING_LWIP212') : src = ['dhcp_server_raw.c'] else: src = ['dhcp_server.c'] diff --git a/components/net/lwip_dhcpd/dhcp_server.c b/components/net/lwip_dhcpd/dhcp_server.c index 93b4ad16f0..b37d038b86 100644 --- a/components/net/lwip_dhcpd/dhcp_server.c +++ b/components/net/lwip_dhcpd/dhcp_server.c @@ -80,6 +80,22 @@ #define LWIP_DHCP 1 #include +#ifndef DHCP_CLIENT_PORT +#define DHCP_CLIENT_PORT 68 +#endif + +#ifndef DHCP_SERVER_PORT +#define DHCP_SERVER_PORT 67 +#endif + +#ifndef ETHADDR32_COPY +#define ETHADDR32_COPY(dst, src) SMEMCPY(dst, src, ETH_HWADDR_LEN) +#endif + +#ifndef ETHADDR16_COPY +#define ETHADDR16_COPY(dst, src) SMEMCPY(dst, src, ETH_HWADDR_LEN) +#endif + /* buffer size for receive DHCP packet */ #define BUFSZ 1024 -- cgit v1.3.1 From 87b5f3f51e86cb858e8e728cfffb76c7dd34d652 Mon Sep 17 00:00:00 2001 From: chenyong Date: Wed, 20 Jan 2021 11:20:30 +0800 Subject: [components][utilities][ulog] Add backend filtering interface, add async log output control interface, ulog mutex change to semaphore Signed-off-by: chenyong --- components/utilities/ulog/ulog.c | 183 +++++++++++++++++++++++++---------- components/utilities/ulog/ulog.h | 2 + components/utilities/ulog/ulog_def.h | 1 + 3 files changed, 133 insertions(+), 53 deletions(-) (limited to 'components') diff --git a/components/utilities/ulog/ulog.c b/components/utilities/ulog/ulog.c index 7610089298..8be20ae115 100644 --- a/components/utilities/ulog/ulog.c +++ b/components/utilities/ulog/ulog.c @@ -77,7 +77,7 @@ struct rt_ulog { rt_bool_t init_ok; - struct rt_mutex output_locker; + struct rt_semaphore output_locker; /* all backends */ rt_slist_t backend_list; /* the thread log's line buffer */ @@ -90,6 +90,7 @@ struct rt_ulog #endif /* ULOG_USING_ISR_LOG */ #ifdef ULOG_USING_ASYNC_OUTPUT + rt_bool_t async_enabled; rt_rbb_t async_rbb; rt_thread_t async_th; struct rt_semaphore async_notice; @@ -186,7 +187,7 @@ static void output_unlock(void) /* is in thread context */ if (rt_interrupt_get_nest() == 0) { - rt_mutex_release(&ulog.output_locker); + rt_sem_release(&ulog.output_locker); } else { @@ -201,7 +202,7 @@ static void output_lock(void) /* is in thread context */ if (rt_interrupt_get_nest() == 0) { - rt_mutex_take(&ulog.output_locker, RT_WAITING_FOREVER); + rt_sem_take(&ulog.output_locker, RT_WAITING_FOREVER); } else { @@ -393,6 +394,10 @@ void ulog_output_to_all_backend(rt_uint32_t level, const char *tag, rt_bool_t is for (node = rt_slist_first(&ulog.backend_list); node; node = rt_slist_next(node)) { backend = rt_slist_entry(node, struct ulog_backend, list); + if (backend->out_level < level) + { + continue; + } #if !defined(ULOG_USING_COLOR) || defined(ULOG_USING_SYSLOG) backend->output(backend, level, tag, is_raw, log, size); #else @@ -738,6 +743,42 @@ void ulog_hexdump(const char *tag, rt_size_t width, rt_uint8_t *buf, rt_size_t s } #ifdef ULOG_USING_FILTER +/** + * Set the filter's level by different backend. + * The log on this backend which level is less than it will stop output. + * + * @param be_name backend name + * @param level The filter level. When the level is LOG_FILTER_LVL_SILENT, the log enter silent mode. + * When the level is LOG_FILTER_LVL_ALL, it will remove this tag's level filer. + * Then all level log will resume output. + * + * @return 0 : success + * -10: level is out of range + */ +int ulog_be_lvl_filter_set(const char *be_name, rt_uint32_t level) +{ + rt_slist_t *node = RT_NULL; + ulog_backend_t backend; + int result = RT_EOK; + + if (level > LOG_FILTER_LVL_ALL) + return -RT_EINVAL; + + if (!ulog.init_ok) + return result; + + for (node = rt_slist_first(&ulog.backend_list); node; node = rt_slist_next(node)) + { + backend = rt_slist_entry(node, struct ulog_backend, list); + if (rt_strncmp(backend->name, be_name, RT_NAME_MAX) == 0) + { + backend->out_level = level; + } + } + + return result; +} + /** * Set the filter's level by different tag. * The log on this tag which level is less than it will stop output. @@ -945,6 +986,47 @@ const char *ulog_global_filter_kw_get(void) #if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) #include +static void _print_lvl_info(void) +{ +#ifndef ULOG_USING_SYSLOG + rt_kprintf("Assert : 0\n"); + rt_kprintf("Error : 3\n"); + rt_kprintf("Warning : 4\n"); + rt_kprintf("Info : 6\n"); + rt_kprintf("Debug : 7\n"); +#else + rt_kprintf("EMERG : 1 (1 << 0)\n"); + rt_kprintf("ALERT : 2 (1 << 1)\n"); + rt_kprintf("CRIT : 4 (1 << 2)\n"); + rt_kprintf("ERR : 8 (1 << 3)\n"); + rt_kprintf("WARNING : 16 (1 << 4)\n"); + rt_kprintf("NOTICE : 32 (1 << 5)\n"); + rt_kprintf("INFO : 64 (1 << 6)\n"); + rt_kprintf("DEBUG : 128 (1 << 7)\n"); +#endif /* ULOG_USING_SYSLOG */ +} + +static void ulog_be_lvl(uint8_t argc, char **argv) +{ + if (argc > 2) + { + if ((atoi(argv[2]) <= LOG_FILTER_LVL_ALL) && (atoi(argv[2]) >= 0)) + { + ulog_be_lvl_filter_set(argv[1], atoi(argv[2])); + } + else + { + rt_kprintf("Please input correct level (0-%d).\n", LOG_FILTER_LVL_ALL); + } + } + else + { + rt_kprintf("Please input: ulog_be_lvl .\n"); + _print_lvl_info(); + } +} +MSH_CMD_EXPORT(ulog_be_lvl, Set ulog filter level by different backend.); + static void ulog_tag_lvl(uint8_t argc, char **argv) { if (argc > 2) @@ -961,22 +1043,7 @@ static void ulog_tag_lvl(uint8_t argc, char **argv) else { rt_kprintf("Please input: ulog_tag_lvl .\n"); -#ifndef ULOG_USING_SYSLOG - rt_kprintf("Assert : 0\n"); - rt_kprintf("Error : 3\n"); - rt_kprintf("Warning : 4\n"); - rt_kprintf("Info : 6\n"); - rt_kprintf("Debug : 7\n"); -#else - rt_kprintf("EMERG : 1 (1 << 0)\n"); - rt_kprintf("ALERT : 2 (1 << 1)\n"); - rt_kprintf("CRIT : 4 (1 << 2)\n"); - rt_kprintf("ERR : 8 (1 << 3)\n"); - rt_kprintf("WARNING : 16 (1 << 4)\n"); - rt_kprintf("NOTICE : 32 (1 << 5)\n"); - rt_kprintf("INFO : 64 (1 << 6)\n"); - rt_kprintf("DEBUG : 128 (1 << 7)\n"); -#endif /* ULOG_USING_SYSLOG */ + _print_lvl_info(); } } MSH_CMD_EXPORT(ulog_tag_lvl, Set ulog filter level by different tag.); @@ -997,22 +1064,7 @@ static void ulog_lvl(uint8_t argc, char **argv) else { rt_kprintf("Please input: ulog_lvl .\n"); -#ifndef ULOG_USING_SYSLOG - rt_kprintf("Assert : 0\n"); - rt_kprintf("Error : 3\n"); - rt_kprintf("Warning : 4\n"); - rt_kprintf("Info : 6\n"); - rt_kprintf("Debug : 7\n"); -#else - rt_kprintf("EMERG : 1 (1 << 0)\n"); - rt_kprintf("ALERT : 2 (1 << 1)\n"); - rt_kprintf("CRIT : 4 (1 << 2)\n"); - rt_kprintf("ERR : 8 (1 << 3)\n"); - rt_kprintf("WARNING : 16 (1 << 4)\n"); - rt_kprintf("NOTICE : 32 (1 << 5)\n"); - rt_kprintf("INFO : 64 (1 << 6)\n"); - rt_kprintf("DEBUG : 128 (1 << 7)\n"); -#endif /* ULOG_USING_SYSLOG */ + _print_lvl_info(); } } MSH_CMD_EXPORT(ulog_lvl, Set ulog global filter level.); @@ -1124,6 +1176,7 @@ rt_err_t ulog_backend_register(ulog_backend_t backend, const char *name, rt_bool } backend->support_color = support_color; + backend->out_level = LOG_FILTER_LVL_ALL; rt_memcpy(backend->name, name, RT_NAME_MAX); level = rt_hw_interrupt_disable(); @@ -1163,6 +1216,11 @@ void ulog_async_output(void) rt_rbb_blk_t log_blk; ulog_frame_t log_frame; + if (!ulog.async_enabled) + { + return; + } + while ((log_blk = rt_rbb_blk_get(ulog.async_rbb)) != NULL) { log_frame = (ulog_frame_t) log_blk->buf; @@ -1176,6 +1234,17 @@ void ulog_async_output(void) } } +/** + * enable or disable asynchronous output mode + * the log will be output directly when mode is disabled + * + * @param enabled RT_TRUE: enabled, RT_FALSE: disabled + */ +void ulog_async_output_enabled(rt_bool_t enabled) +{ + ulog.async_enabled = enabled; +} + /** * waiting for get asynchronous output log * @@ -1230,7 +1299,7 @@ int ulog_init(void) if (ulog.init_ok) return 0; - rt_mutex_init(&ulog.output_locker, "ulog lock", RT_IPC_FLAG_FIFO); + rt_sem_init(&ulog.output_locker, "ulog lock", 1, RT_IPC_FLAG_FIFO); rt_slist_init(&ulog.backend_list); #ifdef ULOG_USING_FILTER @@ -1239,29 +1308,16 @@ int ulog_init(void) #ifdef ULOG_USING_ASYNC_OUTPUT RT_ASSERT(ULOG_ASYNC_OUTPUT_STORE_LINES >= 2); + ulog.async_enabled = RT_TRUE; /* async output ring block buffer */ ulog.async_rbb = rt_rbb_create(RT_ALIGN(ULOG_ASYNC_OUTPUT_BUF_SIZE, RT_ALIGN_SIZE), ULOG_ASYNC_OUTPUT_STORE_LINES); if (ulog.async_rbb == NULL) { rt_kprintf("Error: ulog init failed! No memory for async rbb.\n"); - rt_mutex_detach(&ulog.output_locker); + rt_sem_detach(&ulog.output_locker); return -RT_ENOMEM; } - /* async output thread */ - ulog.async_th = rt_thread_create("ulog_async", async_output_thread_entry, &ulog, ULOG_ASYNC_OUTPUT_THREAD_STACK, - ULOG_ASYNC_OUTPUT_THREAD_PRIORITY, 20); - if (ulog.async_th == NULL) - { - rt_kprintf("Error: ulog init failed! No memory for async output thread.\n"); - rt_mutex_detach(&ulog.output_locker); - rt_rbb_destroy(ulog.async_rbb); - return -RT_ENOMEM; - } - rt_sem_init(&ulog.async_notice, "ulog", 0, RT_IPC_FLAG_FIFO); - /* async output thread startup */ - rt_thread_startup(ulog.async_th); - #endif /* ULOG_USING_ASYNC_OUTPUT */ #ifdef ULOG_USING_FILTER @@ -1272,7 +1328,28 @@ int ulog_init(void) return 0; } -INIT_PREV_EXPORT(ulog_init); +INIT_BOARD_EXPORT(ulog_init); + +#ifdef ULOG_USING_ASYNC_OUTPUT +int ulog_async_init(void) +{ + if (ulog.async_th == NULL) + { + /* async output thread */ + ulog.async_th = rt_thread_create("ulog_async", async_output_thread_entry, &ulog, ULOG_ASYNC_OUTPUT_THREAD_STACK, + ULOG_ASYNC_OUTPUT_THREAD_PRIORITY, 20); + if (ulog.async_th == NULL) + { + rt_kprintf("Error: ulog init failed! No memory for async output thread.\n"); + return -RT_ENOMEM; + } + /* async output thread startup */ + rt_thread_startup(ulog.async_th); + } + return 0; +} +INIT_PREV_EXPORT(ulog_async_init); +#endif /* ULOG_USING_ASYNC_OUTPUT */ void ulog_deinit(void) { @@ -1304,7 +1381,7 @@ void ulog_deinit(void) } #endif /* ULOG_USING_FILTER */ - rt_mutex_detach(&ulog.output_locker); + rt_sem_detach(&ulog.output_locker); #ifdef ULOG_USING_ASYNC_OUTPUT rt_rbb_destroy(ulog.async_rbb); diff --git a/components/utilities/ulog/ulog.h b/components/utilities/ulog/ulog.h index c78d72eda5..670644bb30 100644 --- a/components/utilities/ulog/ulog.h +++ b/components/utilities/ulog/ulog.h @@ -24,6 +24,7 @@ extern "C" { * ulog init and deint */ int ulog_init(void); +int ulog_async_init(void); void ulog_deinit(void); /* @@ -78,6 +79,7 @@ void ulog_flush(void); * asynchronous output API */ void ulog_async_output(void); +void ulog_async_output_enabled(rt_bool_t enabled); void ulog_async_waiting_log(rt_int32_t time); #endif diff --git a/components/utilities/ulog/ulog_def.h b/components/utilities/ulog/ulog_def.h index de5e82fcc5..771e76a601 100644 --- a/components/utilities/ulog/ulog_def.h +++ b/components/utilities/ulog/ulog_def.h @@ -201,6 +201,7 @@ struct ulog_backend { char name[RT_NAME_MAX]; rt_bool_t support_color; + rt_uint32_t out_level; void (*init) (struct ulog_backend *backend); void (*output)(struct ulog_backend *backend, rt_uint32_t level, const char *tag, rt_bool_t is_raw, const char *log, size_t len); void (*flush) (struct ulog_backend *backend); -- cgit v1.3.1 From 63239801d9a2abe1b210faf6cd9f3b126924f7e0 Mon Sep 17 00:00:00 2001 From: Trisuborn <553070703@qq.com> Date: Wed, 20 Jan 2021 11:24:00 +0800 Subject: 修改无意义代码 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/stm32/libraries/HAL_Drivers/drv_pwm.c | 4 ---- components/drivers/include/drivers/rt_drv_pwm.h | 6 +++--- 2 files changed, 3 insertions(+), 7 deletions(-) (limited to 'components') diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c b/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c index ab3897c569..38958dddd4 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c @@ -213,8 +213,6 @@ static rt_err_t drv_pwm_get(TIM_HandleTypeDef *htim, struct rt_pwm_configuration { #if !defined(SOC_SERIES_STM32F0) && !defined(SOC_SERIES_STM32G0) tim_clock = HAL_RCC_GetPCLK2Freq() * 2; -#else - tim_clock = HAL_RCC_GetPCLK2Freq(); #endif } else @@ -262,8 +260,6 @@ static rt_err_t drv_pwm_set(TIM_HandleTypeDef *htim, struct rt_pwm_configuration { #if !defined(SOC_SERIES_STM32F0) && !defined(SOC_SERIES_STM32G0) tim_clock = HAL_RCC_GetPCLK2Freq() * 2; -#else - tim_clock = HAL_RCC_GetPCLK2Freq(); #endif } else diff --git a/components/drivers/include/drivers/rt_drv_pwm.h b/components/drivers/include/drivers/rt_drv_pwm.h index 4b436758d9..a4d64fbc12 100644 --- a/components/drivers/include/drivers/rt_drv_pwm.h +++ b/components/drivers/include/drivers/rt_drv_pwm.h @@ -21,9 +21,9 @@ struct rt_pwm_configuration { - rt_uint32_t channel; /* 0-n */ - rt_uint32_t period; /* unit:ns 1ns~4.29s:1Ghz~0.23hz */ - rt_uint32_t pulse; /* unit:ns (pulse<=period) */ + rt_uint32_t channel; /* 0-n */ + rt_uint32_t period; /* unit:ns 1ns~4.29s:1Ghz~0.23hz */ + rt_uint32_t pulse; /* unit:ns (pulse<=period) */ /* * RT_TRUE : The channel of pwm is complememtary. -- cgit v1.3.1 From 55402e19db41f6c8a706782572a177f61b4e93ef Mon Sep 17 00:00:00 2001 From: Trisuborn <553070703@qq.com> Date: Wed, 20 Jan 2021 23:47:18 +0800 Subject: 优化互补PWM输出功能的实现逻辑,兼容原本API,增加互补PWM使能/失能命令 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/stm32/libraries/HAL_Drivers/drv_pwm.c | 4 +++ components/drivers/include/drivers/rt_drv_pwm.h | 6 +++-- components/drivers/misc/rt_drv_pwm.c | 34 +++++++++++++------------ 3 files changed, 26 insertions(+), 18 deletions(-) (limited to 'components') diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c b/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c index 38958dddd4..b6caafe05c 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c @@ -309,8 +309,12 @@ static rt_err_t drv_pwm_control(struct rt_device_pwm *device, int cmd, void *arg switch (cmd) { + case PWMN_CMD_ENABLE: + configuration->complementary = RT_TRUE; case PWM_CMD_ENABLE: return drv_pwm_enable(htim, configuration, RT_TRUE); + case PWMN_CMD_DISABLE: + configuration->complementary = RT_FALSE; case PWM_CMD_DISABLE: return drv_pwm_enable(htim, configuration, RT_FALSE); case PWM_CMD_SET: diff --git a/components/drivers/include/drivers/rt_drv_pwm.h b/components/drivers/include/drivers/rt_drv_pwm.h index a4d64fbc12..59d670714d 100644 --- a/components/drivers/include/drivers/rt_drv_pwm.h +++ b/components/drivers/include/drivers/rt_drv_pwm.h @@ -18,6 +18,8 @@ #define PWM_CMD_DISABLE (128 + 1) #define PWM_CMD_SET (128 + 2) #define PWM_CMD_GET (128 + 3) +#define PWMN_CMD_ENABLE (128 + 4) +#define PWMN_CMD_DISABLE (128 + 5)/ struct rt_pwm_configuration { @@ -46,8 +48,8 @@ struct rt_device_pwm rt_err_t rt_device_pwm_register(struct rt_device_pwm *device, const char *name, const struct rt_pwm_ops *ops, const void *user_data); -rt_err_t rt_pwm_enable(struct rt_device_pwm *device, int channel, rt_uint8_t complementary); -rt_err_t rt_pwm_disable(struct rt_device_pwm *device, int channel, rt_uint8_t complementary); +rt_err_t rt_pwm_enable(struct rt_device_pwm *device, int channel); +rt_err_t rt_pwm_disable(struct rt_device_pwm *device, int channel); rt_err_t rt_pwm_set(struct rt_device_pwm *device, int channel, rt_uint32_t period, rt_uint32_t pulse); #endif /* __DRV_PWM_H_INCLUDE__ */ diff --git a/components/drivers/misc/rt_drv_pwm.c b/components/drivers/misc/rt_drv_pwm.c index 03ef3353a3..572580c45c 100644 --- a/components/drivers/misc/rt_drv_pwm.c +++ b/components/drivers/misc/rt_drv_pwm.c @@ -126,7 +126,7 @@ rt_err_t rt_device_pwm_register(struct rt_device_pwm *device, const char *name, return result; } -rt_err_t rt_pwm_enable(struct rt_device_pwm *device, int channel, rt_uint8_t complementary) +rt_err_t rt_pwm_enable(struct rt_device_pwm *device, int channel) { rt_err_t result = RT_EOK; struct rt_pwm_configuration configuration = {0}; @@ -136,14 +136,14 @@ rt_err_t rt_pwm_enable(struct rt_device_pwm *device, int channel, rt_uint8_t com return -RT_EIO; } - configuration.channel = channel; - configuration.complementary = complementary ? (RT_TRUE) : (RT_FALSE); + configuration.channel = (channel > 0) ? (channel) : (-channel); /* Make it is positive num forever */ + configuration.complementary = (channel > 0) ? (RT_FALSE) : (RT_TRUE); /* If nagetive, it's complementary */ result = rt_device_control(&device->parent, PWM_CMD_ENABLE, &configuration); return result; } -rt_err_t rt_pwm_disable(struct rt_device_pwm *device, int channel, rt_uint8_t complementary) +rt_err_t rt_pwm_disable(struct rt_device_pwm *device, int channel) { rt_err_t result = RT_EOK; struct rt_pwm_configuration configuration = {0}; @@ -153,8 +153,8 @@ rt_err_t rt_pwm_disable(struct rt_device_pwm *device, int channel, rt_uint8_t co return -RT_EIO; } - configuration.channel = channel; - configuration.complementary = complementary ? (RT_TRUE) : (RT_FALSE); + configuration.channel = (channel > 0) ? (channel) : (-channel); /* Make it is positive num forever */ + configuration.complementary = (channel > 0) ? (RT_FALSE) : (RT_TRUE); /* If nagetive, it's complementary */ result = rt_device_control(&device->parent, PWM_CMD_DISABLE, &configuration); return result; @@ -204,10 +204,10 @@ static int pwm_enable(int argc, char **argv) int result = 0; struct rt_device_pwm *device = RT_NULL; - if (argc != 4) + if (argc != 3) { - rt_kprintf("Usage: pwm_enable pwm1 1 1\n"); - rt_kprintf(" pwm_enable \n"); + rt_kprintf("Usage: pwm_enable pwm1 1\n"); + rt_kprintf(" pwm_enable \n"); result = -RT_ERROR; goto _exit; } @@ -219,22 +219,23 @@ static int pwm_enable(int argc, char **argv) goto _exit; } - result = rt_pwm_enable(device, atoi(argv[2]), atoi(argv[3])); + /* If channel is complementary(1), make the channel number to nagetive */ + result = rt_pwm_enable(device, atoi(argv[2])); _exit: return result; } -MSH_CMD_EXPORT(pwm_enable, pwm_enable ); +MSH_CMD_EXPORT(pwm_enable, pwm_enable ); static int pwm_disable(int argc, char **argv) { int result = 0; struct rt_device_pwm *device = RT_NULL; - if (argc != 4) + if (argc != 3) { - rt_kprintf("Usage: pwm_enable pwm1 1 1\n"); - rt_kprintf(" pwm_disable \n"); + rt_kprintf("Usage: pwm_disable pwm1 1\n"); + rt_kprintf(" pwm_disable \n"); result = -RT_ERROR; goto _exit; } @@ -246,12 +247,13 @@ static int pwm_disable(int argc, char **argv) goto _exit; } - result = rt_pwm_disable(device, atoi(argv[2]), atoi(argv[3])); + /* If channel is complementary(1), make the channel number to nagetive */ + result = rt_pwm_disable(device, atoi(argv[2])); _exit: return result; } -MSH_CMD_EXPORT(pwm_disable, pwm_disable ); +MSH_CMD_EXPORT(pwm_disable, pwm_disable ); static int pwm_set(int argc, char **argv) { -- cgit v1.3.1 From 3bf767dfe125d6de8394b8cd7a401a013a555906 Mon Sep 17 00:00:00 2001 From: Trisuborn <553070703@qq.com> Date: Wed, 20 Jan 2021 23:55:57 +0800 Subject: 文本错误 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/include/drivers/rt_drv_pwm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components') diff --git a/components/drivers/include/drivers/rt_drv_pwm.h b/components/drivers/include/drivers/rt_drv_pwm.h index 59d670714d..7a8e17b916 100644 --- a/components/drivers/include/drivers/rt_drv_pwm.h +++ b/components/drivers/include/drivers/rt_drv_pwm.h @@ -19,7 +19,7 @@ #define PWM_CMD_SET (128 + 2) #define PWM_CMD_GET (128 + 3) #define PWMN_CMD_ENABLE (128 + 4) -#define PWMN_CMD_DISABLE (128 + 5)/ +#define PWMN_CMD_DISABLE (128 + 5) struct rt_pwm_configuration { -- cgit v1.3.1 From 43b1daf325a44c400dcc989a5560d4f93e8df202 Mon Sep 17 00:00:00 2001 From: chenyong Date: Thu, 21 Jan 2021 18:58:57 +0800 Subject: [utilities][ulog] fix ulog backend color log length calculation error Signed-off-by: chenyong --- components/utilities/ulog/ulog.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'components') diff --git a/components/utilities/ulog/ulog.c b/components/utilities/ulog/ulog.c index 8be20ae115..5fcc40ac07 100644 --- a/components/utilities/ulog/ulog.c +++ b/components/utilities/ulog/ulog.c @@ -408,7 +408,11 @@ void ulog_output_to_all_backend(rt_uint32_t level, const char *tag, rt_bool_t is else { /* recalculate the log start address and log size when backend not supported color */ - rt_size_t color_info_len = rt_strlen(color_output_info[level]), output_size = size; + rt_size_t color_info_len = 0, output_size = size; + + if (color_output_info[level] != RT_NULL) + color_info_len = rt_strlen(color_output_info[level]); + if (color_info_len) { rt_size_t color_hdr_len = rt_strlen(CSI_START) + color_info_len; -- cgit v1.3.1 From d0743d6090de62ec21f1db976f88b5a94af1bca9 Mon Sep 17 00:00:00 2001 From: redoc <619675912@qq.com> Date: Fri, 22 Jan 2021 13:44:15 +0800 Subject: 1、【删除】多余语句 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/spi/spi_flash.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'components') diff --git a/components/drivers/spi/spi_flash.h b/components/drivers/spi/spi_flash.h index 19adefaba6..eed65e2f38 100644 --- a/components/drivers/spi/spi_flash.h +++ b/components/drivers/spi/spi_flash.h @@ -14,9 +14,6 @@ #include -#ifdef RT_USING_MTD_NOR -#include "drivers/mtd_nor.h" -#endif struct spi_flash_device { -- cgit v1.3.1 From a04bb0be3ad92256f47ddc747c6e09e2eec094db Mon Sep 17 00:00:00 2001 From: redoc <619675912@qq.com> Date: Fri, 22 Jan 2021 13:45:41 +0800 Subject: 删除换行 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/spi/spi_flash.h | 1 - 1 file changed, 1 deletion(-) (limited to 'components') diff --git a/components/drivers/spi/spi_flash.h b/components/drivers/spi/spi_flash.h index eed65e2f38..82b1ab2ecd 100644 --- a/components/drivers/spi/spi_flash.h +++ b/components/drivers/spi/spi_flash.h @@ -14,7 +14,6 @@ #include - struct spi_flash_device { struct rt_device flash_device; -- cgit v1.3.1 From 998e370ae1ac647922abf7251b6c9363fc6d80c0 Mon Sep 17 00:00:00 2001 From: Wayne Lin Date: Tue, 26 Jan 2021 10:44:00 +0800 Subject: Append RT_WEAK to override various ECC layout. --- components/dfs/filesystems/uffs/uffs_nandif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components') diff --git a/components/dfs/filesystems/uffs/uffs_nandif.c b/components/dfs/filesystems/uffs/uffs_nandif.c index 2e1a981fba..00e1bee8d5 100644 --- a/components/dfs/filesystems/uffs/uffs_nandif.c +++ b/components/dfs/filesystems/uffs/uffs_nandif.c @@ -324,7 +324,7 @@ static rt_uint8_t hw_flash_ecc_layout[UFFS_SPARE_LAYOUT_SIZE] = 0x00, 0x04, 0xFF, 0x00 }; -void uffs_setup_storage(struct uffs_StorageAttrSt *attr, +RT_WEAK void uffs_setup_storage(struct uffs_StorageAttrSt *attr, struct rt_mtd_nand_device *nand) { rt_memset(attr, 0, sizeof(struct uffs_StorageAttrSt)); -- cgit v1.3.1 From 44e9a48f1d4f5e564478048dd63e6c0f50fb4e41 Mon Sep 17 00:00:00 2001 From: Wayne Lin Date: Tue, 26 Jan 2021 17:04:47 +0800 Subject: Enlarge ECC/DATA layout array size. --- components/dfs/filesystems/uffs/src/inc/uffs/uffs_flash.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components') diff --git a/components/dfs/filesystems/uffs/src/inc/uffs/uffs_flash.h b/components/dfs/filesystems/uffs/src/inc/uffs/uffs_flash.h index 1d0344ff8b..844d8ea231 100644 --- a/components/dfs/filesystems/uffs/src/inc/uffs/uffs_flash.h +++ b/components/dfs/filesystems/uffs/src/inc/uffs/uffs_flash.h @@ -62,7 +62,7 @@ extern "C"{ #define UFFS_LAYOUT_UFFS 0 //!< do layout by dev->attr information #define UFFS_LAYOUT_FLASH 1 //!< flash driver do the layout -#define UFFS_SPARE_LAYOUT_SIZE 6 //!< maximum spare layout array size, 2 segments +#define UFFS_SPARE_LAYOUT_SIZE 16 //!< maximum spare layout array size, 2 segments /** flash operation return code */ #define UFFS_FLASH_NO_ERR 0 //!< no error -- cgit v1.3.1