From d59acc2e033c707535a0790354cc4b28e177511c Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Tue, 28 Dec 2021 16:45:44 +0800 Subject: [PATCH] add hs300x and ps5308 sensor support Nuttx on stm32f407-discovery --- APP_Framework/Applications/Make.defs | 7 + APP_Framework/Applications/Makefile | 45 +- APP_Framework/Applications/framework_init.c | 10 +- .../general_functions/list/Makefile | 12 +- .../general_functions/list/list.h | 4 +- APP_Framework/Applications/sensor_app/Kconfig | 49 +- .../Applications/sensor_app/Make.defs | 6 + .../Applications/sensor_app/Makefile | 120 +- .../Applications/sensor_app/humidity_hs300x.c | 5 +- .../Applications/sensor_app/pm10_0_ps5308.c | 38 + .../Applications/sensor_app/pm1_0_ps5308.c | 5 +- .../Applications/sensor_app/pm2_5_ps5308.c | 38 + .../sensor_app/temperature_hs300x.c | 6 +- APP_Framework/Framework/Make.defs | 5 + APP_Framework/Framework/sensor/Make.defs | 7 + APP_Framework/Framework/sensor/Makefile | 66 +- .../Framework/sensor/humidity/Kconfig | 14 +- .../Framework/sensor/humidity/Make.defs | 4 + .../Framework/sensor/humidity/Makefile | 2 +- .../sensor/humidity/hs300x_humi/Make.defs | 6 + .../sensor/humidity/hs300x_humi/Makefile | 14 +- .../sensor/humidity/hs300x_humi/hs300x_humi.c | 18 + APP_Framework/Framework/sensor/pm/Kconfig | 45 +- APP_Framework/Framework/sensor/pm/Make.defs | 4 + .../Framework/sensor/pm/ps5308/Make.defs | 6 + .../Framework/sensor/pm/ps5308/Makefile | 12 +- .../Framework/sensor/pm/ps5308/ps5308.c | 29 +- APP_Framework/Framework/sensor/sensor.c | 11 +- .../Framework/sensor/temperature/Kconfig | 13 +- .../Framework/sensor/temperature/Make.defs | 4 + .../Framework/sensor/temperature/Makefile | 2 +- .../sensor/temperature/hs300x_temp/Make.defs | 6 + .../sensor/temperature/hs300x_temp/Makefile | 13 +- .../temperature/hs300x_temp/hs300x_temp.c | 18 + .../Framework/transform_layer/nuttx/Makefile | 5 + .../transform_layer/nuttx/transform.c | 177 + .../transform_layer/nuttx/transform.h | 214 ++ APP_Framework/Make.defs | 5 + APP_Framework/Makefile | 11 +- .../Nuttx/app_match_nuttx/apps/Makefile | 224 ++ .../Nuttx/app_match_nuttx/apps/nshlib/Kconfig | 1304 +++++++ .../app_match_nuttx/apps/nshlib/Makefile | 131 + .../Nuttx/app_match_nuttx/apps/nshlib/nsh.h | 1426 +++++++ .../apps/nshlib/nsh_Applicationscmd.c | 128 + .../app_match_nuttx/apps/nshlib/nsh_command.c | 1153 ++++++ Ubiquitous/Nuttx/app_match_nuttx/build.sh | 13 + .../Nuttx/app_match_nuttx/nuttx/Kconfig | 1911 +++++++++ .../Nuttx/app_match_nuttx/nuttx/Makefile | 48 + .../nuttx/arch/arm/src/stm32/stm32_serial.c | 3404 +++++++++++++++++ .../arm/stm32/common/include/stm32_hs300x.h | 80 + .../boards/arm/stm32/common/src/Make.defs | 131 + .../arm/stm32/common/src/stm32_hs300x.c | 102 + .../stm32/stm32f4discovery/scripts/Make.defs | 99 + .../stm32f4discovery/src/stm32_bringup.c | 552 +++ .../nuttx/drivers/sensors/Kconfig | 993 +++++ .../nuttx/drivers/sensors/Make.defs | 315 ++ .../nuttx/drivers/sensors/hs300x.c | 253 ++ .../nuttx/include/nuttx/sensors/hs300x.h | 88 + .../app_match_nuttx/nuttx/tools/Makefile.unix | 618 +++ .../app_match_nuttx/nuttx/tools/cfgdefine.c | 360 ++ readme.md | 315 ++ 61 files changed, 14578 insertions(+), 126 deletions(-) create mode 100644 APP_Framework/Applications/Make.defs create mode 100644 APP_Framework/Applications/sensor_app/Make.defs create mode 100644 APP_Framework/Applications/sensor_app/pm10_0_ps5308.c create mode 100644 APP_Framework/Applications/sensor_app/pm2_5_ps5308.c create mode 100644 APP_Framework/Framework/Make.defs create mode 100644 APP_Framework/Framework/sensor/Make.defs create mode 100644 APP_Framework/Framework/sensor/humidity/Make.defs create mode 100644 APP_Framework/Framework/sensor/humidity/hs300x_humi/Make.defs create mode 100644 APP_Framework/Framework/sensor/pm/Make.defs create mode 100644 APP_Framework/Framework/sensor/pm/ps5308/Make.defs create mode 100644 APP_Framework/Framework/sensor/temperature/Make.defs create mode 100644 APP_Framework/Framework/sensor/temperature/hs300x_temp/Make.defs create mode 100644 APP_Framework/Framework/transform_layer/nuttx/Makefile create mode 100644 APP_Framework/Framework/transform_layer/nuttx/transform.c create mode 100644 APP_Framework/Framework/transform_layer/nuttx/transform.h create mode 100644 APP_Framework/Make.defs create mode 100644 Ubiquitous/Nuttx/app_match_nuttx/apps/Makefile create mode 100644 Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/Kconfig create mode 100644 Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/Makefile create mode 100644 Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/nsh.h create mode 100644 Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c create mode 100644 Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/nsh_command.c create mode 100644 Ubiquitous/Nuttx/app_match_nuttx/build.sh create mode 100644 Ubiquitous/Nuttx/app_match_nuttx/nuttx/Kconfig create mode 100644 Ubiquitous/Nuttx/app_match_nuttx/nuttx/Makefile create mode 100644 Ubiquitous/Nuttx/app_match_nuttx/nuttx/arch/arm/src/stm32/stm32_serial.c create mode 100644 Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/common/include/stm32_hs300x.h create mode 100644 Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/common/src/Make.defs create mode 100644 Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/common/src/stm32_hs300x.c create mode 100644 Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/stm32f4discovery/scripts/Make.defs create mode 100644 Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/stm32f4discovery/src/stm32_bringup.c create mode 100644 Ubiquitous/Nuttx/app_match_nuttx/nuttx/drivers/sensors/Kconfig create mode 100644 Ubiquitous/Nuttx/app_match_nuttx/nuttx/drivers/sensors/Make.defs create mode 100644 Ubiquitous/Nuttx/app_match_nuttx/nuttx/drivers/sensors/hs300x.c create mode 100644 Ubiquitous/Nuttx/app_match_nuttx/nuttx/include/nuttx/sensors/hs300x.h create mode 100644 Ubiquitous/Nuttx/app_match_nuttx/nuttx/tools/Makefile.unix create mode 100644 Ubiquitous/Nuttx/app_match_nuttx/nuttx/tools/cfgdefine.c create mode 100644 readme.md diff --git a/APP_Framework/Applications/Make.defs b/APP_Framework/Applications/Make.defs new file mode 100644 index 000000000..581c8c124 --- /dev/null +++ b/APP_Framework/Applications/Make.defs @@ -0,0 +1,7 @@ +############################################################################ +# APP_Framework/Applications/Make.defs +############################################################################ +CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Applications +CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Applications/general_functions/list + +include $(wildcard $(APPDIR)/../../../APP_Framework/Applications/*/Make.defs) diff --git a/APP_Framework/Applications/Makefile b/APP_Framework/Applications/Makefile index af2f86d2c..775dc4c26 100644 --- a/APP_Framework/Applications/Makefile +++ b/APP_Framework/Applications/Makefile @@ -1,25 +1,36 @@ -SRC_DIR := general_functions app_test +include $(KERNEL_ROOT)/.config -SRC_FILES := main.c framework_init.c +ifeq ($(CONFIG_ADD_NUTTX_FETURES),y) + include $(APPDIR)/Make.defs + CSRCS += framework_init.c + include $(APPDIR)/Application.mk -ifeq ($(CONFIG_APPLICATION_OTA),y) - SRC_DIR += ota endif -ifeq ($(CONFIG_APPLICATION_SENSOR),y) - SRC_DIR += sensor_app -endif +ifeq ($(CONFIG_ADD_XIUOS_FETURES),y) + SRC_DIR := general_functions app_test -ifeq ($(CONFIG_APPLICATION_CONNECTION),y) - SRC_DIR += connection_app -endif + SRC_FILES := main.c framework_init.c -ifeq ($(CONFIG_APPLICATION_KNOWING),y) - SRC_DIR += knowing_app -endif + ifeq ($(CONFIG_APPLICATION_OTA),y) + SRC_DIR += ota + endif -ifeq ($(CONFIG_APPLICATION_CONTROL),y) - SRC_DIR += control_app -endif + ifeq ($(CONFIG_APPLICATION_SENSOR),y) + SRC_DIR += sensor_app + endif -include $(KERNEL_ROOT)/compiler.mk + ifeq ($(CONFIG_APPLICATION_CONNECTION),y) + SRC_DIR += connection_app + endif + + ifeq ($(CONFIG_APPLICATION_KNOWING),y) + SRC_DIR += knowing_app + endif + + ifeq ($(CONFIG_APPLICATION_CONTROL),y) + SRC_DIR += control_app + endif + + include $(KERNEL_ROOT)/compiler.mk +endif \ No newline at end of file diff --git a/APP_Framework/Applications/framework_init.c b/APP_Framework/Applications/framework_init.c index 603af2fac..07e7299f5 100644 --- a/APP_Framework/Applications/framework_init.c +++ b/APP_Framework/Applications/framework_init.c @@ -28,6 +28,8 @@ extern int D124VoiceInit(void); extern int Hs300xTemperatureInit(void); extern int Hs300xHumidityInit(void); extern int Ps5308Pm1_0Init(void); +extern int Ps5308Pm2_5Init(void); +extern int Ps5308Pm10Init(void); extern int Zg09Co2Init(void); extern int As830Ch4Init(void); extern int Tb600bIaq10IaqInit(void); @@ -87,6 +89,12 @@ static struct InitDesc sensor_desc[] = #ifdef SENSOR_QUANTITY_PS5308_PM1_0 { "ps5308_pm1_0", Ps5308Pm1_0Init }, #endif +#ifdef SENSOR_QUANTITY_PS5308_PM2_5 + { "ps5308_pm2_5", Ps5308Pm2_5Init }, +#endif +#ifdef SENSOR_QUANTITY_PS5308_PM10 + { "ps5308_pm10", Ps5308Pm10Init }, +#endif #endif #ifdef SENSOR_ZG09 @@ -190,7 +198,7 @@ static int ConnectionDeviceFrameworkInit(struct InitDesc sub_desc[]) * This function will init system framework * */ -int FrameworkInit() +int FrameworkInit(void) { #ifdef SUPPORT_SENSOR_FRAMEWORK SensorDeviceFrameworkInit(framework); diff --git a/APP_Framework/Applications/general_functions/list/Makefile b/APP_Framework/Applications/general_functions/list/Makefile index 6a4f6e414..89ca52441 100644 --- a/APP_Framework/Applications/general_functions/list/Makefile +++ b/APP_Framework/Applications/general_functions/list/Makefile @@ -1,3 +1,11 @@ -SRC_FILES := double_list.c single_list.c +include $(KERNEL_ROOT)/.config +ifeq ($(CONFIG_ADD_NUTTX_FETURES),y) + include $(APPDIR)/Make.defs + CSRCS += double_list.c single_list.c + include $(APPDIR)/Application.mk +endif -include $(KERNEL_ROOT)/compiler.mk \ No newline at end of file +ifeq ($(CONFIG_ADD_XIUOS_FETURES),y) + SRC_FILES := double_list.c single_list.c + include $(KERNEL_ROOT)/compiler.mk +endif \ No newline at end of file diff --git a/APP_Framework/Applications/general_functions/list/list.h b/APP_Framework/Applications/general_functions/list/list.h index 3eeca2372..98ed2cb08 100644 --- a/APP_Framework/Applications/general_functions/list/list.h +++ b/APP_Framework/Applications/general_functions/list/list.h @@ -22,7 +22,9 @@ #ifndef __LIST_H__ #define __LIST_H__ -#include "libc.h" +#include +#include +#include #include #ifdef __cplusplus extern "C" { diff --git a/APP_Framework/Applications/sensor_app/Kconfig b/APP_Framework/Applications/sensor_app/Kconfig index 67474d37c..7046f66e4 100755 --- a/APP_Framework/Applications/sensor_app/Kconfig +++ b/APP_Framework/Applications/sensor_app/Kconfig @@ -65,6 +65,26 @@ menu "sensor app" default n endif + menuconfig APPLICATION_SENSOR_PM2_5 + bool "Using sensor PM2.5 apps" + default n + + if APPLICATION_SENSOR_PM2_5 + config APPLICATION_SENSOR_PM2_5_PS5308 + bool "Using sensor PS5308 apps" + default n + endif + + menuconfig APPLICATION_SENSOR_PM10 + bool "Using sensor PM10 apps" + default n + + if APPLICATION_SENSOR_PM10 + config APPLICATION_SENSOR_PM10_PS5308 + bool "Using sensor PS5308 apps" + default n + endif + menuconfig APPLICATION_SENSOR_VOICE bool "Using sensor voice apps" default n @@ -75,16 +95,6 @@ menu "sensor app" default n endif - menuconfig APPLICATION_SENSOR_HUMIDITY - bool "Using sensor humidity apps" - default n - - if APPLICATION_SENSOR_HUMIDITY - config APPLICATION_SENSOR_HUMIDITY_HS300X - bool "Using sensor HS300x apps" - default n - endif - menuconfig APPLICATION_SENSOR_TEMPERATURE bool "Using sensor temperature apps" default n @@ -93,7 +103,26 @@ menu "sensor app" config APPLICATION_SENSOR_TEMPERATURE_HS300X bool "Using sensor HS300x apps" default n + + if ADD_NUTTX_FETURES + endif + endif + + menuconfig APPLICATION_SENSOR_HUMIDITY + bool "Using sensor humidity apps" + default n + + if APPLICATION_SENSOR_HUMIDITY + config APPLICATION_SENSOR_HUMIDITY_HS300X + bool "Using sensor HS300x apps" + default n + + if ADD_NUTTX_FETURES + endif + + endif + endif endmenu diff --git a/APP_Framework/Applications/sensor_app/Make.defs b/APP_Framework/Applications/sensor_app/Make.defs new file mode 100644 index 000000000..be73b4746 --- /dev/null +++ b/APP_Framework/Applications/sensor_app/Make.defs @@ -0,0 +1,6 @@ +############################################################################ +# APP_Framework/Applications/sensor_app/Make.defs +############################################################################ +ifneq ($(CONFIG_APPLICATION_SENSOR),) +CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Applications/sensor_app +endif diff --git a/APP_Framework/Applications/sensor_app/Makefile b/APP_Framework/Applications/sensor_app/Makefile index 7a067414b..4cc02859f 100644 --- a/APP_Framework/Applications/sensor_app/Makefile +++ b/APP_Framework/Applications/sensor_app/Makefile @@ -1,39 +1,103 @@ -SRC_FILES := +include $(KERNEL_ROOT)/.config + +ifeq ($(CONFIG_ADD_NUTTX_FETURES),y) + include $(APPDIR)/Make.defs + + ifeq ($(CONFIG_APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS), y) + CSRCS += hcho_tb600b_wq_hcho1os.c + endif + + ifeq ($(CONFIG_APPLICATION_SENSOR_TVOC_TB600B_TVOC10), y) + CSRCS += tvoc_tb600b_tvoc10.c + endif + + ifeq ($(CONFIG_APPLICATION_SENSOR_IAQ_TB600B_IAQ10), y) + CSRCS += iaq_tb600b_iaq10.c + endif + + ifeq ($(CONFIG_APPLICATION_SENSOR_CH4_AS830), y) + CSRCS += ch4_as830.c + endif + + ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_ZG09), y) + CSRCS += co2_zg09.c + endif + + ifeq ($(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308), y) + CSRCS += pm1_0_ps5308.c + endif + + ifeq ($(CONFIG_APPLICATION_SENSOR_PM2_5_PS5308), y) + CSRCS += pm2_5_ps5308.c + endif + + ifeq ($(CONFIG_APPLICATION_SENSOR_PM10_PS5308), y) + CSRCS += pm10_0_ps5308.c + endif + + ifeq ($(CONFIG_APPLICATION_SENSOR_VOICE_D124), y) + CSRCS += voice_d124.c + endif + + ifeq ($(CONFIG_APPLICATION_SENSOR_HUMIDITY_HS300X), y) + CSRCS += humidity_hs300x.c + endif + + ifeq ($(CONFIG_APPLICATION_SENSOR_TEMPERATURE_HS300X), y) + CSRCS += temperature_hs300x.c + endif + + include $(APPDIR)/Application.mk -ifeq ($(CONFIG_APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS), y) - SRC_FILES += hcho_tb600b_wq_hcho1os.c endif -ifeq ($(CONFIG_APPLICATION_SENSOR_TVOC_TB600B_TVOC10), y) - SRC_FILES += tvoc_tb600b_tvoc10.c -endif +ifeq ($(CONFIG_ADD_XIUOS_FETURES),y) + SRC_FILES := -ifeq ($(CONFIG_APPLICATION_SENSOR_IAQ_TB600B_IAQ10), y) - SRC_FILES += iaq_tb600b_iaq10.c -endif + ifeq ($(CONFIG_APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS), y) + SRC_FILES += hcho_tb600b_wq_hcho1os.c + endif -ifeq ($(CONFIG_APPLICATION_SENSOR_CH4_AS830), y) - SRC_FILES += ch4_as830.c -endif + ifeq ($(CONFIG_APPLICATION_SENSOR_TVOC_TB600B_TVOC10), y) + SRC_FILES += tvoc_tb600b_tvoc10.c + endif -ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_ZG09), y) - SRC_FILES += co2_zg09.c -endif + ifeq ($(CONFIG_APPLICATION_SENSOR_IAQ_TB600B_IAQ10), y) + SRC_FILES += iaq_tb600b_iaq10.c + endif -ifeq ($(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308), y) - SRC_FILES += pm1_0_ps5308.c -endif + ifeq ($(CONFIG_APPLICATION_SENSOR_CH4_AS830), y) + SRC_FILES += ch4_as830.c + endif -ifeq ($(CONFIG_APPLICATION_SENSOR_VOICE_D124), y) - SRC_FILES += voice_d124.c -endif + ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_ZG09), y) + SRC_FILES += co2_zg09.c + endif -ifeq ($(CONFIG_APPLICATION_SENSOR_HUMIDITY_HS300X), y) - SRC_FILES += humidity_hs300x.c -endif + ifeq ($(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308), y) + SRC_FILES += pm1_0_ps5308.c + endif -ifeq ($(CONFIG_APPLICATION_SENSOR_TEMPERATURE_HS300X), y) - SRC_FILES += temperature_hs300x.c -endif + ifeq ($(CONFIG_APPLICATION_SENSOR_PM2_5_PS5308), y) + SRC_FILES += pm2_5_ps5308.c + endif -include $(KERNEL_ROOT)/compiler.mk + ifeq ($(CONFIG_APPLICATION_SENSOR_PM10_PS5308), y) + SRC_FILES += pm10_0_ps5308.c + endif + + ifeq ($(CONFIG_APPLICATION_SENSOR_VOICE_D124), y) + SRC_FILES += voice_d124.c + endif + + ifeq ($(CONFIG_APPLICATION_SENSOR_HUMIDITY_HS300X), y) + SRC_FILES += humidity_hs300x.c + endif + + ifeq ($(CONFIG_APPLICATION_SENSOR_TEMPERATURE_HS300X), y) + SRC_FILES += temperature_hs300x.c + endif + + include $(KERNEL_ROOT)/compiler.mk + +endif diff --git a/APP_Framework/Applications/sensor_app/humidity_hs300x.c b/APP_Framework/Applications/sensor_app/humidity_hs300x.c index 451d2c3c1..c9958cbe4 100644 --- a/APP_Framework/Applications/sensor_app/humidity_hs300x.c +++ b/APP_Framework/Applications/sensor_app/humidity_hs300x.c @@ -18,7 +18,10 @@ * @date 2021.04.23 */ -#include +#ifdef ADD_XIUOS_FETURES +# include +#endif + #include /** diff --git a/APP_Framework/Applications/sensor_app/pm10_0_ps5308.c b/APP_Framework/Applications/sensor_app/pm10_0_ps5308.c new file mode 100644 index 000000000..e4b57a2a5 --- /dev/null +++ b/APP_Framework/Applications/sensor_app/pm10_0_ps5308.c @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** + * @file pm1_0_ps5308.c + * @brief PS5308 PM1.0 example + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2021.04.23 + */ + +#ifdef ADD_XIUOS_FETURES +# include +#endif + +#include + +/** + * @description: Read a PM10 + * @return 0 + */ +void Pm100Ps5308(void) +{ + struct SensorQuantity *pm10_0 = SensorQuantityFind(SENSOR_QUANTITY_PS5308_PM10, SENSOR_QUANTITY_PM); + SensorQuantityOpen(pm10_0); + PrivTaskDelay(2000); + printf("PM10 : %d ug/m³\n", SensorQuantityRead(pm10_0)); + SensorQuantityClose(pm10_0); +} \ No newline at end of file diff --git a/APP_Framework/Applications/sensor_app/pm1_0_ps5308.c b/APP_Framework/Applications/sensor_app/pm1_0_ps5308.c index 4f6bda856..1e169be94 100644 --- a/APP_Framework/Applications/sensor_app/pm1_0_ps5308.c +++ b/APP_Framework/Applications/sensor_app/pm1_0_ps5308.c @@ -18,7 +18,10 @@ * @date 2021.04.23 */ -#include +#ifdef ADD_XIUOS_FETURES +# include +#endif + #include /** diff --git a/APP_Framework/Applications/sensor_app/pm2_5_ps5308.c b/APP_Framework/Applications/sensor_app/pm2_5_ps5308.c new file mode 100644 index 000000000..e4343f4c4 --- /dev/null +++ b/APP_Framework/Applications/sensor_app/pm2_5_ps5308.c @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** + * @file pm1_0_ps5308.c + * @brief PS5308 PM1.0 example + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2021.04.23 + */ + +#ifdef ADD_XIUOS_FETURES +# include +#endif + +#include + +/** + * @description: Read a PM2.5 + * @return 0 + */ +void Pm25Ps5308(void) +{ + struct SensorQuantity *pm2_5 = SensorQuantityFind(SENSOR_QUANTITY_PS5308_PM2_5, SENSOR_QUANTITY_PM); + SensorQuantityOpen(pm2_5); + PrivTaskDelay(2000); + printf("PM2.5 : %d ug/m³\n", SensorQuantityRead(pm2_5)); + SensorQuantityClose(pm2_5); +} \ No newline at end of file diff --git a/APP_Framework/Applications/sensor_app/temperature_hs300x.c b/APP_Framework/Applications/sensor_app/temperature_hs300x.c index c945040e7..6ce2a3531 100644 --- a/APP_Framework/Applications/sensor_app/temperature_hs300x.c +++ b/APP_Framework/Applications/sensor_app/temperature_hs300x.c @@ -18,7 +18,10 @@ * @date 2021.04.23 */ -#include +#ifdef ADD_XIUOS_FETURES +# include +#endif + #include /** @@ -43,4 +46,3 @@ void TempHs300x(void) SensorQuantityClose(temp); } -SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, TempHs300x, TempHs300x, TempHs300x function); diff --git a/APP_Framework/Framework/Make.defs b/APP_Framework/Framework/Make.defs new file mode 100644 index 000000000..40d65f37f --- /dev/null +++ b/APP_Framework/Framework/Make.defs @@ -0,0 +1,5 @@ +############################################################################ +# APP_Framework/Framework/Make.defs +############################################################################ +CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/transform_layer/nuttx +include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/*/Make.defs) diff --git a/APP_Framework/Framework/sensor/Make.defs b/APP_Framework/Framework/sensor/Make.defs new file mode 100644 index 000000000..c06e310db --- /dev/null +++ b/APP_Framework/Framework/sensor/Make.defs @@ -0,0 +1,7 @@ +############################################################################ +# APP_Framework/Framework/sensor/Make.defs +############################################################################ +ifneq ($(CONFIG_SUPPORT_SENSOR_FRAMEWORK),) +CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/sensor +endif +include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/sensor/*/Make.defs) diff --git a/APP_Framework/Framework/sensor/Makefile b/APP_Framework/Framework/sensor/Makefile index 9f19136de..6b34db9f0 100644 --- a/APP_Framework/Framework/sensor/Makefile +++ b/APP_Framework/Framework/sensor/Makefile @@ -1,39 +1,49 @@ -SRC_FILES := sensor.c +include $(KERNEL_ROOT)/.config +ifeq ($(CONFIG_ADD_NUTTX_FETURES),y) + include $(APPDIR)/Make.defs + CSRCS += sensor.c + include $(APPDIR)/Application.mk -ifeq ($(CONFIG_SENSOR_HCHO),y) - SRC_DIR += hcho endif -ifeq ($(CONFIG_SENSOR_TVOC),y) - SRC_DIR += tvoc -endif +ifeq ($(CONFIG_ADD_XIUOS_FETURES),y) + SRC_FILES := sensor.c -ifeq ($(CONFIG_SENSOR_IAQ),y) - SRC_DIR += iaq -endif + ifeq ($(CONFIG_SENSOR_HCHO),y) + SRC_DIR += hcho + endif -ifeq ($(CONFIG_SENSOR_CH4),y) - SRC_DIR += ch4 -endif + ifeq ($(CONFIG_SENSOR_TVOC),y) + SRC_DIR += tvoc + endif -ifeq ($(CONFIG_SENSOR_CO2),y) - SRC_DIR += co2 -endif + ifeq ($(CONFIG_SENSOR_IAQ),y) + SRC_DIR += iaq + endif -ifeq ($(CONFIG_SENSOR_PM),y) - SRC_DIR += pm -endif + ifeq ($(CONFIG_SENSOR_CH4),y) + SRC_DIR += ch4 + endif -ifeq ($(CONFIG_SENSOR_VOICE),y) - SRC_DIR += voice -endif + ifeq ($(CONFIG_SENSOR_CO2),y) + SRC_DIR += co2 + endif -ifeq ($(CONFIG_SENSOR_TEMPERATURE),y) - SRC_DIR += temperature -endif + ifeq ($(CONFIG_SENSOR_PM),y) + SRC_DIR += pm + endif -ifeq ($(CONFIG_SENSOR_HUMIDITY),y) - SRC_DIR += humidity -endif + ifeq ($(CONFIG_SENSOR_VOICE),y) + SRC_DIR += voice + endif -include $(KERNEL_ROOT)/compiler.mk + ifeq ($(CONFIG_SENSOR_TEMPERATURE),y) + SRC_DIR += temperature + endif + + ifeq ($(CONFIG_SENSOR_HUMIDITY),y) + SRC_DIR += humidity + endif + + include $(KERNEL_ROOT)/compiler.mk +endif diff --git a/APP_Framework/Framework/sensor/humidity/Kconfig b/APP_Framework/Framework/sensor/humidity/Kconfig index 624edf34c..be535c039 100644 --- a/APP_Framework/Framework/sensor/humidity/Kconfig +++ b/APP_Framework/Framework/sensor/humidity/Kconfig @@ -1,9 +1,9 @@ -config SENSOR_HS300X - bool "Using HS300x" +config SENSOR_HS300X_HUMIDITY + bool "Using HS300x for humidity" default n - if SENSOR_HS300X + if SENSOR_HS300X_HUMIDITY config SENSOR_DEVICE_HS300X string "HS300x sensor name" default "hs300x_1" @@ -22,7 +22,15 @@ config SENSOR_HS300X default 0x44 endif + if ADD_NUTTX_FETURES + config SENSOR_DEVICE_HS300X_DEV + string "HS300x device name" + default "/dev/i2c1" + + config SENSOR_DEVICE_HS300X_I2C_ADDR + hex "HS300x device i2c address" + default 0x44 endif diff --git a/APP_Framework/Framework/sensor/humidity/Make.defs b/APP_Framework/Framework/sensor/humidity/Make.defs new file mode 100644 index 000000000..affd5dbaf --- /dev/null +++ b/APP_Framework/Framework/sensor/humidity/Make.defs @@ -0,0 +1,4 @@ +############################################################################ +# APP_Framework/Framework/sensor/humidity/Make.defs +############################################################################ +include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/sensor/humidity/*/Make.defs) diff --git a/APP_Framework/Framework/sensor/humidity/Makefile b/APP_Framework/Framework/sensor/humidity/Makefile index 5e89f9cf9..979a42404 100644 --- a/APP_Framework/Framework/sensor/humidity/Makefile +++ b/APP_Framework/Framework/sensor/humidity/Makefile @@ -1,4 +1,4 @@ -ifeq ($(CONFIG_SENSOR_HS300X),y) +ifeq ($(CONFIG_SENSOR_HS300X_HUMIDITY),y) SRC_DIR += hs300x_humi endif diff --git a/APP_Framework/Framework/sensor/humidity/hs300x_humi/Make.defs b/APP_Framework/Framework/sensor/humidity/hs300x_humi/Make.defs new file mode 100644 index 000000000..76a42c621 --- /dev/null +++ b/APP_Framework/Framework/sensor/humidity/hs300x_humi/Make.defs @@ -0,0 +1,6 @@ +############################################################################ +# APP_Framework/Framework/sensor/humidity/hs300x_humi/Make.defs +############################################################################ +ifneq ($(CONFIG_SENSOR_HS300X_HUMIDITY),) +CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/sensor/humidity/hs300x_humi +endif diff --git a/APP_Framework/Framework/sensor/humidity/hs300x_humi/Makefile b/APP_Framework/Framework/sensor/humidity/hs300x_humi/Makefile index 860898f3c..00f8c897d 100644 --- a/APP_Framework/Framework/sensor/humidity/hs300x_humi/Makefile +++ b/APP_Framework/Framework/sensor/humidity/hs300x_humi/Makefile @@ -1,3 +1,13 @@ -SRC_FILES := hs300x_humi.c +include $(KERNEL_ROOT)/.config +ifeq ($(CONFIG_ADD_NUTTX_FETURES),y) + include $(APPDIR)/Make.defs + CSRCS += hs300x_humi.c + include $(APPDIR)/Application.mk -include $(KERNEL_ROOT)/compiler.mk +endif + +ifeq ($(CONFIG_ADD_XIUOS_FETURES),y) + SRC_FILES := hs300x_humi.c + include $(KERNEL_ROOT)/compiler.mk + +endif \ No newline at end of file diff --git a/APP_Framework/Framework/sensor/humidity/hs300x_humi/hs300x_humi.c b/APP_Framework/Framework/sensor/humidity/hs300x_humi/hs300x_humi.c index 880ccaf1d..706c8958a 100644 --- a/APP_Framework/Framework/sensor/humidity/hs300x_humi/hs300x_humi.c +++ b/APP_Framework/Framework/sensor/humidity/hs300x_humi/hs300x_humi.c @@ -36,6 +36,12 @@ static struct SensorProductInfo info = */ static int SensorDeviceOpen(struct SensorDevice *sdev) { +#ifdef ADD_NUTTX_FETURES + sdev->fd = PrivOpen(SENSOR_DEVICE_HS300X_DEV, O_RDWR); + + return sdev->fd; + +#else int result; uint16_t i2c_dev_addr = SENSOR_DEVICE_HS300X_I2C_ADDR; @@ -52,6 +58,7 @@ static int SensorDeviceOpen(struct SensorDevice *sdev) result = PrivIoctl(sdev->fd, OPE_INT, &ioctl_cfg); return result; +#endif } /** @@ -62,6 +69,16 @@ static int SensorDeviceOpen(struct SensorDevice *sdev) */ static int SensorDeviceRead(struct SensorDevice *sdev, size_t len) { +#ifdef ADD_NUTTX_FETURES + int ret; + ret = PrivRead(sdev->fd, sdev->buffer, len); + if (ret != len ){ + perror("Failed to read data!\n"); + return -1; + } + + return 0; +#else //send i2c device start signal and address, need to implemente in OS i2c driver if (PrivWrite(sdev->fd, NULL, 0) != 1) return -1; @@ -73,6 +90,7 @@ static int SensorDeviceRead(struct SensorDevice *sdev, size_t len) return -1; return 0; +#endif } static struct SensorDone done = diff --git a/APP_Framework/Framework/sensor/pm/Kconfig b/APP_Framework/Framework/sensor/pm/Kconfig index bfda3639a..e9ec52939 100644 --- a/APP_Framework/Framework/sensor/pm/Kconfig +++ b/APP_Framework/Framework/sensor/pm/Kconfig @@ -8,18 +8,36 @@ config SENSOR_PS5308 string "PS5308 sensor name" default "ps5308_1" - config SENSOR_QUANTITY_PS5308_PM1_0 - string "PS5308 quantity PM1.0 name" - default "pm1_0_1" + config PS5308_PM1_0 + bool "Using pm1.0 function" + default n + + if PS5308_PM1_0 + config SENSOR_QUANTITY_PS5308_PM1_0 + string "PS5308 quantity PM1.0 name" + default "pm1_0_1" + endif + + config PS5308_PM2_5 + bool "Using pm2.5 function" + default n + + if PS5308_PM2_5 + config SENSOR_QUANTITY_PS5308_PM2_5 + string "PS5308 quantity PM2.5 name" + default "pm2_5_1" + endif + + config PS5308_PM10 + bool "Using pm10 function" + default n + + if PS5308_PM10 + config SENSOR_QUANTITY_PS5308_PM10 + string "PS5308 quantity PM10 name" + default "pm10_1" + endif - config SENSOR_QUANTITY_PS5308_PM2_5 - string "PS5308 quantity PM2.5 name" - default "pm2_5_1" - - config SENSOR_QUANTITY_PS5308_PM10 - string "PS5308 quantity PM10 name" - default "pm10_1" - if ADD_XIUOS_FETURES config SENSOR_PS5308_DRIVER_EXTUART bool "Using extra uart to support PS5308" @@ -42,6 +60,11 @@ config SENSOR_PS5308 endif if ADD_NUTTX_FETURES + config SENSOR_DEVICE_PS5308_DEV + string "PS5308 device name" + default "/dev/ttyS1" + ---help--- + If USART1 is selected, then fill in /dev/ttyS1 here. endif diff --git a/APP_Framework/Framework/sensor/pm/Make.defs b/APP_Framework/Framework/sensor/pm/Make.defs new file mode 100644 index 000000000..c26342446 --- /dev/null +++ b/APP_Framework/Framework/sensor/pm/Make.defs @@ -0,0 +1,4 @@ +############################################################################ +# APP_Framework/Framework/sensor/pm/Make.defs +############################################################################ +include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/sensor/pm/*/Make.defs) diff --git a/APP_Framework/Framework/sensor/pm/ps5308/Make.defs b/APP_Framework/Framework/sensor/pm/ps5308/Make.defs new file mode 100644 index 000000000..1f1c1b77e --- /dev/null +++ b/APP_Framework/Framework/sensor/pm/ps5308/Make.defs @@ -0,0 +1,6 @@ +############################################################################ +# APP_Framework/Framework/sensor/pm/ps5308//Make.defs +############################################################################ +ifneq ($(CONFIG_SENSOR_PS5308),) +CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/sensor/pm/ps5308 +endif diff --git a/APP_Framework/Framework/sensor/pm/ps5308/Makefile b/APP_Framework/Framework/sensor/pm/ps5308/Makefile index 0e907f8c7..89e586656 100644 --- a/APP_Framework/Framework/sensor/pm/ps5308/Makefile +++ b/APP_Framework/Framework/sensor/pm/ps5308/Makefile @@ -1,3 +1,11 @@ -SRC_FILES := ps5308.c +include $(KERNEL_ROOT)/.config +ifeq ($(CONFIG_ADD_NUTTX_FETURES),y) + include $(APPDIR)/Make.defs + CSRCS += ps5308.c + include $(APPDIR)/Application.mk +endif -include $(KERNEL_ROOT)/compiler.mk +ifeq ($(CONFIG_ADD_XIUOS_FETURES),y) + SRC_FILES := ps5308.c + include $(KERNEL_ROOT)/compiler.mk +endif diff --git a/APP_Framework/Framework/sensor/pm/ps5308/ps5308.c b/APP_Framework/Framework/sensor/pm/ps5308/ps5308.c index f287d97da..57d1754df 100644 --- a/APP_Framework/Framework/sensor/pm/ps5308/ps5308.c +++ b/APP_Framework/Framework/sensor/pm/ps5308/ps5308.c @@ -51,6 +51,32 @@ static void *ReadTask(void *parameter) * @param sdev - sensor device pointer * @return success: 1 , failure: other */ +#ifdef ADD_NUTTX_FETURES +static int SensorDeviceOpen(struct SensorDevice *sdev) +{ + int result = 0; + + result = PrivMutexCreate(&buff_lock, 0); + if (result != 0){ + printf("SensorDeviceOpen:mutex create failed, status=%d\n", result); + } + + sdev->fd = open(SENSOR_DEVICE_PS5308_DEV, O_RDWR); + if (sdev->fd < 0) { + printf("SensorDeviceOpen:open %s error\n", SENSOR_DEVICE_PS5308_DEV); + return -1; + } + + result = PrivTaskCreate(&active_task_id, NULL, &ReadTask, sdev); + if (result != 0){ + printf("SensorDeviceOpen:task create failed, status=%d\n", result); + } + + PrivTaskStartup(&active_task_id); + + return result; +} +#else static int SensorDeviceOpen(struct SensorDevice *sdev) { int result = 0; @@ -76,13 +102,14 @@ static int SensorDeviceOpen(struct SensorDevice *sdev) cfg.port_configure = PORT_CFG_INIT; #endif - result = ioctl(sdev->fd, OPE_INT, &cfg); + //result = PrivIoctl(sdev->fd, OPE_INT, &cfg); PrivTaskCreate(&active_task_id, NULL, &ReadTask, sdev); PrivTaskStartup(&active_task_id); return result; } +#endif /** * @description: Close PS5308 sensor device diff --git a/APP_Framework/Framework/sensor/sensor.c b/APP_Framework/Framework/sensor/sensor.c index f3bd3a2c7..372acb74d 100644 --- a/APP_Framework/Framework/sensor/sensor.c +++ b/APP_Framework/Framework/sensor/sensor.c @@ -151,12 +151,9 @@ static int SensorDeviceOpen(struct SensorDevice *sdev) if (sdev->done->open != NULL) result = sdev->done->open(sdev); - if (result == 0) { + if (result >= 0) { printf("Device %s open success.\n", sdev->name); }else{ - if (sdev->fd) - PrivClose(sdev->fd); - printf("Device %s open failed(%d).\n", sdev->name, result); memset(sdev, 0, sizeof(struct SensorDevice)); } @@ -173,13 +170,13 @@ static int SensorDeviceClose(struct SensorDevice *sdev) { int result = 0; - if (sdev->fd) + if (sdev->fd >= 0) PrivClose(sdev->fd); if (sdev->done->close != NULL) result = sdev->done->close(sdev); - if (result == 0) + if (result >= 0) printf("%s successfully closed.\n", sdev->name); else printf("Closed %s failure.\n", sdev->name); @@ -276,7 +273,7 @@ int SensorQuantityOpen(struct SensorQuantity *quant) if (sdev->ref_cnt == 0) { ret = SensorDeviceOpen(sdev); - if (ret != 0) { + if (ret < 0) { printf("%s: open sensor device failed\n", __func__); return ret; } diff --git a/APP_Framework/Framework/sensor/temperature/Kconfig b/APP_Framework/Framework/sensor/temperature/Kconfig index 0817643e4..42c91303e 100644 --- a/APP_Framework/Framework/sensor/temperature/Kconfig +++ b/APP_Framework/Framework/sensor/temperature/Kconfig @@ -1,9 +1,9 @@ -config SENSOR_HS300X - bool "Using HS300x" +config SENSOR_HS300X_TEMPERATURE + bool "Using HS300x for temperature" default n - if SENSOR_HS300X + if SENSOR_HS300X_TEMPERATURE config SENSOR_DEVICE_HS300X string "HS300x sensor name" default "hs300x_1" @@ -23,6 +23,13 @@ config SENSOR_HS300X endif if ADD_NUTTX_FETURES + config SENSOR_DEVICE_HS300X_DEV + string "HS300x device name" + default "/dev/i2c1" + + config SENSOR_DEVICE_HS300X_I2C_ADDR + hex "HS300x device i2c address" + default 0x44 endif diff --git a/APP_Framework/Framework/sensor/temperature/Make.defs b/APP_Framework/Framework/sensor/temperature/Make.defs new file mode 100644 index 000000000..1b5456350 --- /dev/null +++ b/APP_Framework/Framework/sensor/temperature/Make.defs @@ -0,0 +1,4 @@ +############################################################################ +# APP_Framework/Framework/sensor/temperature//Make.defs +############################################################################ +include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/sensor/temperature/*/Make.defs) diff --git a/APP_Framework/Framework/sensor/temperature/Makefile b/APP_Framework/Framework/sensor/temperature/Makefile index b7e113e30..361a8718c 100644 --- a/APP_Framework/Framework/sensor/temperature/Makefile +++ b/APP_Framework/Framework/sensor/temperature/Makefile @@ -1,4 +1,4 @@ -ifeq ($(CONFIG_SENSOR_HS300X),y) +ifeq ($(CONFIG_SENSOR_HS300X_TEMPERATURE),y) SRC_DIR += hs300x_temp endif diff --git a/APP_Framework/Framework/sensor/temperature/hs300x_temp/Make.defs b/APP_Framework/Framework/sensor/temperature/hs300x_temp/Make.defs new file mode 100644 index 000000000..013b46253 --- /dev/null +++ b/APP_Framework/Framework/sensor/temperature/hs300x_temp/Make.defs @@ -0,0 +1,6 @@ +############################################################################ +# APP_Framework/Framework/sensor/temperature/hs300x_temp//Make.defs +############################################################################ +ifneq ($(CONFIG_SENSOR_HS300X_TEMPERATURE),) +CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/sensor/temperature/hs300x_temp +endif diff --git a/APP_Framework/Framework/sensor/temperature/hs300x_temp/Makefile b/APP_Framework/Framework/sensor/temperature/hs300x_temp/Makefile index 3d0aa62ef..fe3a526c7 100644 --- a/APP_Framework/Framework/sensor/temperature/hs300x_temp/Makefile +++ b/APP_Framework/Framework/sensor/temperature/hs300x_temp/Makefile @@ -1,3 +1,12 @@ -SRC_FILES := hs300x_temp.c +include $(KERNEL_ROOT)/.config +ifeq ($(CONFIG_ADD_NUTTX_FETURES),y) + include $(APPDIR)/Make.defs + CSRCS += hs300x_temp.c + include $(APPDIR)/Application.mk -include $(KERNEL_ROOT)/compiler.mk +endif + +ifeq ($(CONFIG_ADD_XIUOS_FETURES),y) + SRC_FILES := hs300x_temp.c + include $(KERNEL_ROOT)/compiler.mk +endif diff --git a/APP_Framework/Framework/sensor/temperature/hs300x_temp/hs300x_temp.c b/APP_Framework/Framework/sensor/temperature/hs300x_temp/hs300x_temp.c index 7ffb43478..a3a80acbd 100644 --- a/APP_Framework/Framework/sensor/temperature/hs300x_temp/hs300x_temp.c +++ b/APP_Framework/Framework/sensor/temperature/hs300x_temp/hs300x_temp.c @@ -36,6 +36,12 @@ static struct SensorProductInfo info = */ static int SensorDeviceOpen(struct SensorDevice *sdev) { +#ifdef ADD_NUTTX_FETURES + sdev->fd = PrivOpen(SENSOR_DEVICE_HS300X_DEV, O_RDWR); + + return sdev->fd; + +#else int result; uint16_t i2c_dev_addr = SENSOR_DEVICE_HS300X_I2C_ADDR; @@ -51,6 +57,7 @@ static int SensorDeviceOpen(struct SensorDevice *sdev) result = PrivIoctl(sdev->fd, OPE_INT, &ioctl_cfg); return result; +#endif } /** @@ -61,6 +68,16 @@ static int SensorDeviceOpen(struct SensorDevice *sdev) */ static int SensorDeviceRead(struct SensorDevice *sdev, size_t len) { +#ifdef ADD_NUTTX_FETURES + int ret; + ret = PrivRead(sdev->fd, sdev->buffer, len); + if (ret != len ){ + perror("Failed to read data!\n"); + return -1; + } + + return 0; +#else //send i2c device start signal and address, need to implemente in OS i2c driver if (PrivWrite(sdev->fd, NULL, 0) != 1) return -1; @@ -72,6 +89,7 @@ static int SensorDeviceRead(struct SensorDevice *sdev, size_t len) return -1; return 0; +#endif } static struct SensorDone done = diff --git a/APP_Framework/Framework/transform_layer/nuttx/Makefile b/APP_Framework/Framework/transform_layer/nuttx/Makefile new file mode 100644 index 000000000..1b72ae240 --- /dev/null +++ b/APP_Framework/Framework/transform_layer/nuttx/Makefile @@ -0,0 +1,5 @@ +include $(KERNEL_ROOT)/.config +include $(APPDIR)/Make.defs +CSRCS = transform.c + +include $(APPDIR)/Application.mk \ No newline at end of file diff --git a/APP_Framework/Framework/transform_layer/nuttx/transform.c b/APP_Framework/Framework/transform_layer/nuttx/transform.c new file mode 100644 index 000000000..b31989482 --- /dev/null +++ b/APP_Framework/Framework/transform_layer/nuttx/transform.c @@ -0,0 +1,177 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** + * @file xiuos.c + * @brief Converts the framework interface to an operating system interface + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2021.06.07 + */ + +#include "transform.h" + +/**************************mutex***************************/ +/* private mutex API */ +int PrivMutexCreate(pthread_mutex_t *p_mutex, const pthread_mutexattr_t *attr) +{ + return pthread_mutex_init(p_mutex, attr); +} + +int PrivMutexDelete(pthread_mutex_t *p_mutex) +{ + return pthread_mutex_destroy(p_mutex); +} + +int PrivMutexObtain(pthread_mutex_t *p_mutex) +{ + return pthread_mutex_lock(p_mutex); +} + +int PrivMutexAbandon(pthread_mutex_t *p_mutex) +{ + return pthread_mutex_unlock(p_mutex); +} + +/**********************semaphore****************************/ +int PrivSemaphoreCreate(sem_t *sem, int pshared, unsigned int value) +{ + return sem_init(sem, pshared, value); +} + +int PrivSemaphoreDelete(sem_t *sem) +{ + return sem_destroy(sem); +} + +int PrivSemaphoreObtainWait(sem_t *sem, const struct timespec *abstime) +{ + return sem_timedwait(sem, abstime); +} + +int PrivSemaphoreObtainNoWait(sem_t *sem) +{ + return sem_trywait(sem); +} + +int PrivSemaphoreAbandon(sem_t *sem) +{ + return sem_post(sem); +} + +/**************************task*************************/ +int PrivTaskCreate(pthread_t *thread, const pthread_attr_t *attr, + void *(*start_routine)(void *), void *arg) +{ + return pthread_create(thread, attr, start_routine, arg); +} + +int PrivTaskStartup(pthread_t *thread) +{ + return 0; +} + +int PrivTaskDelete(pthread_t thread, int sig) +{ + return pthread_kill(thread, sig); +} + +void PrivTaskQuit(void *value_ptr) +{ + pthread_exit(value_ptr); +} + +int PrivTaskDelay(int32_t ms) +{ + return usleep(ms); +} + +/*********************fs**************************/ + +/************************Driver Posix Transform***********************/ +int PrivOpen(const char *path, int flags) +{ + return open(path, flags); +} + +int PrivClose(int fd) +{ + return close(fd); +} + +int PrivRead(int fd, void *buf, size_t len) +{ + return read(fd, buf, len); +} + +int PrivWrite(int fd, const void *buf, size_t len) +{ + return write(fd, buf, len); +} + +static int PrivSerialIoctl(int fd, int cmd, void *args) +{ + struct SerialDataCfg *serial_cfg = (struct SerialDataCfg *)args; + return ioctl(fd, cmd, serial_cfg); +} + +static int PrivPinIoctl(int fd, int cmd, void *args) +{ + struct PinParam *pin_cfg = (struct PinParam *)args; + + return ioctl(fd, cmd, pin_cfg); +} + +int PrivIoctl(int fd, int cmd, void *args) +{ + int ret = 0; + struct PrivIoctlCfg *ioctl_cfg = (struct PrivIoctlCfg *)args; + + switch (ioctl_cfg->ioctl_driver_type) + { + case SERIAL_TYPE: + ret = PrivSerialIoctl(fd, cmd, ioctl_cfg->args); + break; + case PIN_TYPE: + ret = PrivPinIoctl(fd, cmd, ioctl_cfg->args); + break; + case I2C_TYPE: + ret = ioctl(fd, cmd, ioctl_cfg->args); + break; + default: + break; + } + + return ret; +} + +/********************memory api************/ +void *PrivMalloc(size_t size) +{ + return malloc(size); +} + +void *PrivRealloc(void *pointer, size_t size) +{ + return realloc(pointer, size); +} + +void *PrivCalloc(size_t count, size_t size) +{ + return calloc(count, size); +} + +void PrivFree(void *pointer) +{ + free(pointer); +} + diff --git a/APP_Framework/Framework/transform_layer/nuttx/transform.h b/APP_Framework/Framework/transform_layer/nuttx/transform.h new file mode 100644 index 000000000..f50dd4075 --- /dev/null +++ b/APP_Framework/Framework/transform_layer/nuttx/transform.h @@ -0,0 +1,214 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** + * @file transform.h + * @brief Interface function declarations required by the framework + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2021.06.04 + */ + +#ifndef TRANSFORM_H +#define TRANSFORM_H + +#include +#include +#include +#include +#include + +typedef uint8_t uint8; +typedef uint16_t uint16; +typedef uint32_t uint32; +typedef uint64_t uint64; + +typedef int8_t int8; +typedef int16_t int16; +typedef int32_t int32; +typedef int64_t int64; + +#ifdef __cplusplus +extern "C" { +#endif + +#define OPE_INT 0x0000 +#define OPE_CFG 0x0001 + +#define NAME_NUM_MAX 32 + +/*********************GPIO define*********************/ +#define GPIO_LOW 0x00 +#define GPIO_HIGH 0x01 + +#define GPIO_CFG_OUTPUT 0x00 +#define GPIO_CFG_INPUT 0x01 +#define GPIO_CFG_INPUT_PULLUP 0x02 +#define GPIO_CFG_INPUT_PULLDOWN 0x03 +#define GPIO_CFG_OUTPUT_OD 0x04 + +#define GPIO_CONFIG_MODE 0xffffffff + +/********************SERIAL define*******************/ +#define BAUD_RATE_2400 2400 +#define BAUD_RATE_4800 4800 +#define BAUD_RATE_9600 9600 +#define BAUD_RATE_19200 19200 +#define BAUD_RATE_38400 38400 +#define BAUD_RATE_57600 57600 +#define BAUD_RATE_115200 115200 +#define BAUD_RATE_230400 230400 +#define BAUD_RATE_460800 460800 +#define BAUD_RATE_921600 921600 +#define BAUD_RATE_2000000 2000000 +#define BAUD_RATE_3000000 3000000 + +#define DATA_BITS_5 5 +#define DATA_BITS_6 6 +#define DATA_BITS_7 7 +#define DATA_BITS_8 8 +#define DATA_BITS_9 9 + +#define STOP_BITS_1 1 +#define STOP_BITS_2 2 +#define STOP_BITS_3 3 +#define STOP_BITS_4 4 + +#define PARITY_NONE 1 +#define PARITY_ODD 2 +#define PARITY_EVEN 3 + +#define BIT_ORDER_LSB 1 +#define BIT_ORDER_MSB 2 + +#define NRZ_NORMAL 1 +#define NRZ_INVERTED 2 + +#ifndef SERIAL_RB_BUFSZ +#define SERIAL_RB_BUFSZ 128 +#endif + +struct PinDevIrq +{ + int irq_mode;//< RISING/FALLING/HIGH/LOW + void (*hdr) (void *args);//< callback function + void *args;//< the params of callback function +}; + +struct PinParam +{ + int cmd;//< cmd:GPIO_CONFIG_MODE/GPIO_IRQ_REGISTER/GPIO_IRQ_FREE/GPIO_IRQ_DISABLE/GPIO_IRQ_ENABLE + long pin;//< pin number + int mode;//< pin mode: input/output + struct PinDevIrq irq_set;//< pin irq set + uint64 arg; +}; + +struct PinStat +{ + long pin;//< pin number + uint16_t val;//< pin level +}; + +enum ExtSerialPortConfigure +{ + PORT_CFG_INIT = 0, + PORT_CFG_PARITY_CHECK, + PORT_CFG_DISABLE, + PORT_CFG_DIV, +}; + +struct SerialDataCfg +{ + uint32_t serial_baud_rate; + uint8_t serial_data_bits; + uint8_t serial_stop_bits; + uint8_t serial_parity_mode; + uint8_t serial_bit_order; + uint8_t serial_invert_mode; + uint16_t serial_buffer_size; + + uint8 ext_uart_no; + enum ExtSerialPortConfigure port_configure; +}; + +enum IoctlDriverType +{ + SERIAL_TYPE = 0, + SPI_TYPE, + I2C_TYPE, + PIN_TYPE, + DEFAULT_TYPE, +}; + +struct PrivIoctlCfg +{ + enum IoctlDriverType ioctl_driver_type; + void *args; +}; + +int open(FAR const char *path, int oflags, ...); +int ioctl(int fd, int req, ...); +FAR void *malloc(size_t size); +FAR void *realloc(FAR void *oldmem, size_t size); +FAR void *calloc(size_t n, size_t elem_size); +void free(FAR void *mem); + +/**********************mutex**************************/ + +int PrivMutexCreate(pthread_mutex_t *p_mutex, const pthread_mutexattr_t *attr); +int PrivMutexDelete(pthread_mutex_t *p_mutex); +int PrivMutexObtain(pthread_mutex_t *p_mutex); +int PrivMutexAbandon(pthread_mutex_t *p_mutex); + + + + +/*********************semaphore**********************/ + +int PrivSemaphoreCreate(sem_t *sem, int pshared, unsigned int value); +int PrivSemaphoreDelete(sem_t *sem); +int PrivSemaphoreObtainWait(sem_t *sem, const struct timespec *abstime); +int PrivSemaphoreObtainNoWait(sem_t *sem); +int PrivSemaphoreAbandon(sem_t *sem); +int32_t PrivSemaphoreSetValue(int32_t sem, uint16_t val); + +/*********************task**************************/ + +int PrivTaskCreate(pthread_t *thread, const pthread_attr_t *attr, + void *(*start_routine)(void *), void *arg); +int PrivTaskStartup(pthread_t *thread); +int PrivTaskDelete(pthread_t thread, int sig); +void PrivTaskQuit(void *value_ptr); +int PrivTaskDelay(int32_t ms); + +/*********************driver*************************/ + +int PrivOpen(const char *path, int flags); +int PrivRead(int fd, void *buf, size_t len); +int PrivWrite(int fd, const void *buf, size_t len); +int PrivClose(int fd); +int PrivIoctl(int fd, int cmd, void *args); + +/*********************memory***********************/ + +void *PrivMalloc(size_t size); +void *PrivRealloc(void *pointer, size_t size); +void *PrivCalloc(size_t count, size_t size); +void PrivFree(void *pointer); + + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/APP_Framework/Make.defs b/APP_Framework/Make.defs new file mode 100644 index 000000000..7f23f14d0 --- /dev/null +++ b/APP_Framework/Make.defs @@ -0,0 +1,5 @@ +############################################################################ +# APP_Framework/Make.defs +############################################################################ +CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework +include $(wildcard $(APPDIR)/../../../APP_Framework/*/Make.defs) diff --git a/APP_Framework/Makefile b/APP_Framework/Makefile index e6778c79a..665f21fb8 100644 --- a/APP_Framework/Makefile +++ b/APP_Framework/Makefile @@ -1,4 +1,11 @@ -SRC_DIR := Applications Framework lib +include $(KERNEL_ROOT)/.config +ifeq ($(CONFIG_ADD_NUTTX_FETURES),y) + include $(APPDIR)/Make.defs + include $(APPDIR)/Application.mk +endif -include $(KERNEL_ROOT)/compiler.mk +ifeq ($(CONFIG_ADD_XIUOS_FETURES),y) + SRC_DIR := Applications Framework lib + include $(KERNEL_ROOT)/compiler.mk +endif diff --git a/Ubiquitous/Nuttx/app_match_nuttx/apps/Makefile b/Ubiquitous/Nuttx/app_match_nuttx/apps/Makefile new file mode 100644 index 000000000..08cabda67 --- /dev/null +++ b/Ubiquitous/Nuttx/app_match_nuttx/apps/Makefile @@ -0,0 +1,224 @@ +############################################################################ +# apps/Makefile +# +# Copyright (C) 2011 Uros Platise. All rights reserved. +# Copyright (C) 2011-2014, 2018-2019 Gregory Nutt. All rights reserved. +# Authors: Uros Platise +# Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +export APPDIR = $(CURDIR) +include $(APPDIR)/Make.defs + +include $(APPDIR)/../../../APP_Framework/Make.defs + +# Symbol table for loadable apps. + +SYMTABSRC = symtab_apps.c +SYMTABOBJ = $(SYMTABSRC:.c=$(OBJEXT)) + +# Build targets + +# We first remove libapps.a before letting the other rules add objects to it +# so that we ensure libapps.a does not contain objects from prior build + +all: + $(RM) $(BIN) + $(MAKE) $(BIN) + +.PHONY: import install dirlinks export .depdirs preconfig depend clean distclean +.PHONY: context clean_context context_all register register_all +.PRECIOUS: $(BIN) + +$(foreach SDIR, $(CONFIGURED_APPS), $(eval $(call SDIR_template,$(SDIR),all))) +$(foreach SDIR, $(CONFIGURED_APPS), $(eval $(call SDIR_template,$(SDIR),install))) +$(foreach SDIR, $(CONFIGURED_APPS), $(eval $(call SDIR_template,$(SDIR),context))) +$(foreach SDIR, $(CONFIGURED_APPS), $(eval $(call SDIR_template,$(SDIR),register))) +$(foreach SDIR, $(CONFIGURED_APPS), $(eval $(call SDIR_template,$(SDIR),depend))) +$(foreach SDIR, $(CLEANDIRS), $(eval $(call SDIR_template,$(SDIR),clean))) +$(foreach SDIR, $(CLEANDIRS), $(eval $(call SDIR_template,$(SDIR),distclean))) + +$(MKDEP): $(TOPDIR)/tools/mkdeps.c + $(HOSTCC) $(HOSTINCLUDES) $(HOSTCFLAGS) $< -o $@ + +$(INCDIR): $(TOPDIR)/tools/incdir.c + $(HOSTCC) $(HOSTINCLUDES) $(HOSTCFLAGS) $< -o $@ + +IMPORT_TOOLS = $(MKDEP) $(INCDIR) + +# In the KERNEL build, we must build and install all of the modules. No +# symbol table is needed + +ifeq ($(CONFIG_BUILD_KERNEL),y) + +install: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_install) + +.import: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all) + $(Q) $(MAKE) install + +import: $(IMPORT_TOOLS) + $(Q) $(MAKE) context TOPDIR="$(APPDIR)$(DELIM)import" + $(Q) $(MAKE) register TOPDIR="$(APPDIR)$(DELIM)import" + $(Q) $(MAKE) depend TOPDIR="$(APPDIR)$(DELIM)import" + $(Q) $(MAKE) .import TOPDIR="$(APPDIR)$(DELIM)import" + +else + +# In FLAT and protected modes, the modules have already been created. A +# symbol table is required. + +ifeq ($(CONFIG_BUILD_LOADABLE),) + +$(BIN): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all) + $(Q) for app in ${CONFIGURED_APPS}; do \ + $(MAKE) -C "$${app}" archive ; \ + done + +else + +$(SYMTABSRC): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all) + $(Q) for app in ${CONFIGURED_APPS}; do \ + $(MAKE) -C "$${app}" archive ; \ + done + $(Q) $(MAKE) install + $(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(BINDIR) >$@.tmp + $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) + +$(SYMTABOBJ): %$(OBJEXT): %.c + $(call COMPILE, -fno-lto $<, $@) + +$(BIN): $(SYMTABOBJ) +ifeq ($(CONFIG_CYGWIN_WINTOOL),y) + $(call ARCHIVE_ADD, "${shell cygpath -w $(BIN)}", $^) +else + $(call ARCHIVE_ADD, $(BIN), $^) +endif + +endif # !CONFIG_BUILD_LOADABLE + +install: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_install) + +# Link nuttx + +HEAD_OBJ += $(wildcard $(APPDIR)$(DELIM)import$(DELIM)startup$(DELIM)*$(OBJEXT)) +HEAD_OBJ += $(wildcard $(APPDIR)$(DELIM)builtin$(DELIM)*$(OBJEXT)) + +.import: $(BIN) install + $(Q) echo "LD: nuttx" + $(Q) $(LD) --entry=__start $(LDFLAGS) $(LDLIBPATH) $(EXTRA_LIBPATHS) \ + -L$(APPDIR)$(DELIM)import$(DELIM)scripts -T$(LDNAME) \ + -o nuttx$(EXEEXT) $(HEAD_OBJ) $(EXTRA_OBJS) $(LDSTARTGROUP) \ + $(BIN) $(LDLIBS) $(EXTRA_LIBS) $(LDENDGROUP) +ifeq ($(CONFIG_INTELHEX_BINARY),y) + $(Q) echo "CP: nuttx.hex" + $(Q) $(OBJCOPY) $(OBJCOPYARGS) -O ihex nuttx$(EXEEXT) nuttx.hex +endif +ifeq ($(CONFIG_RAW_BINARY),y) + $(Q) echo "CP: nuttx.bin" + $(Q) $(OBJCOPY) $(OBJCOPYARGS) -O binary nuttx$(EXEEXT) nuttx.bin +endif + $(call POSTBUILD, $(APPDIR)) + +import: $(IMPORT_TOOLS) + $(Q) $(MAKE) context TOPDIR="$(APPDIR)$(DELIM)import" + $(Q) $(MAKE) register TOPDIR="$(APPDIR)$(DELIM)import" + $(Q) $(MAKE) depend TOPDIR="$(APPDIR)$(DELIM)import" + $(Q) $(MAKE) .import TOPDIR="$(APPDIR)$(DELIM)import" + +endif # CONFIG_BUILD_KERNEL + +dirlinks: + $(Q) $(MAKE) -C platform dirlinks + +context_all: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_context) +register_all: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_register) + +context: + $(Q) $(MAKE) context_all + $(Q) $(MAKE) register_all + +Kconfig: + $(foreach SDIR, $(CONFIGDIRS), $(call MAKE_template,$(SDIR),preconfig)) + $(Q) $(MKKCONFIG) + +preconfig: Kconfig + +export: +ifneq ($(EXPORTDIR),) +ifneq ($(BUILTIN_REGISTRY),) + $(Q) mkdir -p "${EXPORTDIR}"/registry || exit 1; \ + for f in "${BUILTIN_REGISTRY}"/*.bdat "${BUILTIN_REGISTRY}"/*.pdat ; do \ + [ -f "$${f}" ] && cp -f "$${f}" "${EXPORTDIR}"/registry ; \ + done +endif +endif + +.depdirs: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_depend) + +.depend: Makefile .depdirs + $(Q) touch $@ + +depend: .depend + +clean_context: + $(Q) $(MAKE) -C platform clean_context + $(Q) $(MAKE) -C builtin clean_context + +clean: $(foreach SDIR, $(CLEANDIRS), $(SDIR)_clean) + $(call DELFILE, $(SYMTABSRC)) + $(call DELFILE, $(SYMTABOBJ)) + $(call DELFILE, $(BIN)) + $(call DELFILE, Kconfig) + $(call DELDIR, $(BINDIR)) + $(call CLEAN) + +distclean: $(foreach SDIR, $(CLEANDIRS), $(SDIR)_distclean) +ifeq ($(CONFIG_WINDOWS_NATIVE),y) + $(Q) ( if exist external ( \ + echo ********************************************************" \ + echo * The external directory/link must be removed manually *" \ + echo ********************************************************" \ + ) +else + $(Q) ( if [ -e external ]; then \ + echo "********************************************************"; \ + echo "* The external directory/link must be removed manually *"; \ + echo "********************************************************"; \ + fi; \ + ) +endif + $(call DELFILE, .depend) + $(call DELFILE, $(SYMTABSRC)) + $(call DELFILE, $(SYMTABOBJ)) + $(call DELFILE, $(BIN)) + $(call DELFILE, Kconfig) + $(call DELDIR, $(BINDIR)) + $(call CLEAN) diff --git a/Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/Kconfig b/Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/Kconfig new file mode 100644 index 000000000..80c5c5988 --- /dev/null +++ b/Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/Kconfig @@ -0,0 +1,1304 @@ +# +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +menu "NSH Library" + +config NSH_LIBRARY + bool "NSH Library" + default n + select NETUTILS_NETLIB if NET + select LIBC_NETDB if NET + select READLINE_HAVE_EXTMATCH + select LIB_BOARDCTL if (!NSH_DISABLE_MKRD && !DISABLE_MOUNTPOINT) || NSH_ARCHINIT || NSH_ROMFSETC + select BOARDCTL_MKRD if !NSH_DISABLE_MKRD && !DISABLE_MOUNTPOINT + select BOARDCTL_ROMDISK if NSH_ROMFSETC + ---help--- + Build the NSH support library. This is used, for example, by + system/nsh in order to implement the full NuttShell (NSH). + +if NSH_LIBRARY + +menuconfig NSH_MOTD + bool "Message of the Day (MOTD)" + default n + ---help--- + Support a user-provided Message of the Day (MOTD) that will be + presented each time new NSH session is opened. + +if NSH_MOTD + +config NSH_PLATFORM_MOTD + bool "Platform MOTD" + default n + ---help--- + If this option is selected, the NSH will call into platform-specific + logic in order to get the MOTD. The function prototype for this + call is: + + void platform_motd(FAR char *buffer, size_t buflen); + + Where buffer is the location to return the MOTD and buflen is the + length of that buffer. The maximum size of the buffer is determined + by NSH_FILEIOSIZE. An appropriate location for the + implementation of platform_motd would be within apps/platform/. + + One newline will be inserted after the platform-supplied message. + + platform_motd() is prototyped and described in apps/include/nshlib/nshlib.h + which may be included like: + + #include "nshlib/nshlib.h" + +config NSH_MOTD_STRING + string "MOTD String" + default "No MOTD string provided" + depends on !NSH_PLATFORM_MOTD + ---help--- + If NSH_MOTD is selected, but NSH_PLATFORM_MOTD is not, then a fixed + MOTD string will be used. That string is provided by this selection. + + One newline will be inserted after supplied MOTD message. + +endif # NSH_MOTD + +menu "Command Line Configuration" + +config NSH_PROMPT_STRING + string "Prompt String" + default "nsh> " + ---help--- + Provide the shell prompt string, default is "nsh> ". + +choice + prompt "Command Line Editor" + default NSH_READLINE if DEFAULT_SMALL + default NSH_CLE if !DEFAULT_SMALL + +config NSH_READLINE + bool "Minimal readline()" + select SYSTEM_READLINE + ---help--- + Selects the minimal implementation of readline(). This minimal + implementation provides on backspace for command line editing. + +config NSH_CLE + bool "Command Line Editor" + select SYSTEM_CLE + ---help--- + Selects the more extensive, EMACS-like command line editor. + Select this option only if (1) you don't mind a modest increase + in the FLASH footprint, and (2) you work with a terminal that + supports extensive VT100 editing commands. + + Selecting this option will add probably 1.5-2KB to the FLASH + footprint. + +endchoice + +config NSH_LINELEN + int "Max command line length" + default 64 if DEFAULT_SMALL + default 80 if !DEFAULT_SMALL + ---help--- + The maximum length of one command line and of one output line. + Default: 64/80 + +config NSH_DISABLE_SEMICOLON + bool "Disable multiple commands per line" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + ---help--- + By default, you can enter multiple NSH commands on a line with each + command separated by a semicolon. You can disable this feature to + save a little memory on FLASH challenged platforms. + +config NSH_QUOTE + bool "Enable back-slash quoting of characters" + default n if DEFAULT_SMALL || !NSH_ARGCAT + default y if !DEFAULT_SMALL && NSH_ARGCAT + ---help--- + Force special characters like back-quotes, quotation marks, and the + back-slash character itself to be treat like normal text. + + This feature is only implemented properly for the case where + CONFIG_NSH_ARGCAT is also selected. + +config NSH_CMDPARMS + bool "Enable commands as parameters" + default n if DEFAULT_SMALL + default y if !DEFAULT_SMALL + depends on !DISABLE_MOUNTPOINT + ---help--- + If selected, then the output from commands, from file applications, and + from NSH built-in commands can be used as arguments to other + commands. The entity to be executed is identified by enclosing the + command line in back quotes. For example, + + set FOO `myprogram $BAR` + + Will execute the program named myprogram passing it the value of the + environment variable BAR. The value of the environment variable FOO + is then set output of myprogram on stdout. + + Because this feature commits significant resources, it is disabled by + default. + +config NSH_MAXARGUMENTS + int "Maximum number of command arguments" + default 7 + ---help--- + The maximum number of NSH command arguments. + Default: 7 + +config NSH_ARGCAT + bool "Concatenation of argument strings" + default n if DEFAULT_SMALL + default y if !DEFAULT_SMALL + ---help--- + Support concatenation of strings with environment variables or command + output. For example: + + set FOO XYZ + set BAR 123 + set FOOBAR ABC_${FOO}_${BAR} + + would set the environment variable FOO to XYZ, BAR to 123 and FOOBAR + to ABC_XYZ_123. If NSH_ARGCAT is not selected, then a slightly small + FLASH footprint results but then also only simple environment + variables like $FOO can be used on the command line. + +config NSH_NESTDEPTH + int "Maximum command nesting" + default 3 + ---help--- + The maximum number of nested if-then[-else]-fi sequences that + are permissible. Default: 3 + +config NSH_DISABLEBG + bool "Disable background commands" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + ---help--- + This can be set to 'y' to suppress support for background + commands. This setting disables the 'nice' command prefix and + the '&' command suffix. This would only be set on systems + where a minimal footprint is a necessity and background command + execution is not. + +endmenu # Command Line Configuration + +config NSH_BUILTIN_APPS + bool "Enable built-in applications" + default n + depends on BUILTIN + ---help--- + Support external registered, "built-in" applications that can be + executed from the NSH command line (see apps/README.txt for + more information). This options requires support for builtin + applications (BUILTIN). + +config NSH_FILE_APPS + bool "Enable execution of program files" + default n + depends on LIBC_EXECFUNCS + ---help--- + Support execution of program files residing within a file + system. This options requires support for the posix_spawn() + interface (LIBC_EXECFUNCS). + +menu "Disable Individual commands" + +config NSH_DISABLE_ADDROUTE + bool "Disable addroute" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + depends on NET_ROUTE + +config NSH_DISABLE_ARP + bool "Disable arp" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + depends on NET_ARP + +config NSH_DISABLE_BASE64DEC + bool "Disable base64dec" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + depends on NETUTILS_CODECS && CODECS_BASE64 + +config NSH_DISABLE_BASE64ENC + bool "Disable base64enc" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + depends on NETUTILS_CODECS && CODECS_BASE64 + +config NSH_DISABLE_BASENAME + bool "Disable basename" + default y if DEFAULT_SMALL || NSH_DISABLESCRIPT + default n if !DEFAULT_SMALL && !NSH_DISABLESCRIPT + +config NSH_DISABLE_CAT + bool "Disable cat" + default n + +config NSH_DISABLE_CD + bool "Disable cd" + default n + +config NSH_DISABLE_CP + bool "Disable cp" + default n + +config NSH_DISABLE_CMP + bool "Disable cmp" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + +config NSH_DISABLE_DATE + bool "Disable date" + default n if RTC + default y if !RTC + +config NSH_DISABLE_DD + bool "Disable dd" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + +config NSH_DISABLE_DF + bool "Disable df" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + +config NSH_DISABLE_DELROUTE + bool "Disable delroute" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + depends on NET_ROUTE + +config NSH_DISABLE_DIRNAME + bool "Disable dirname" + default y if DEFAULT_SMALL || NSH_DISABLESCRIPT + default n if !DEFAULT_SMALL && !NSH_DISABLESCRIPT + +config NSH_DISABLE_DMESG + bool "Disable dmesg" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + depends on RAMLOG_SYSLOG + +config NSH_DISABLE_ECHO + bool "Disable echo" + default n + +config NSH_DISABLE_ENV + bool "Disable env" + default n + +config NSH_DISABLE_EXEC + bool "Disable exec" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + +config NSH_DISABLE_EXIT + bool "Disable exit" + default y if DEFAULT_SMALL && !NSH_TELNET + default n if !DEFAULT_SMALL || NSH_TELNET + +config NSH_DISABLE_EXPORT + bool "Disable export" + default n + +config NSH_DISABLE_FREE + bool "Disable free" + default n + +config NSH_DISABLE_GET + bool "Disable get" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + +config NSH_DISABLE_HELP + bool "Disable help" + default n + +config NSH_DISABLE_HEXDUMP + bool "Disable hexdump" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + +config NSH_DISABLE_IFCONFIG + bool "Disable ifconfig" + default y if !FS_PROCFS || FS_PROCFS_EXCLUDE_NET + default n if FS_PROCFS && !FS_PROCFS_EXCLUDE_NET + +config NSH_DISABLE_IFUPDOWN + bool "Disable ifup/down" + default y if !FS_PROCFS || FS_PROCFS_EXCLUDE_NET + default n if FS_PROCFS && !FS_PROCFS_EXCLUDE_NET + +config NSH_DISABLE_KILL + bool "Disable kill" + default n + +config NSH_DISABLE_LOSETUP + bool "Disable losetup" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + +config NSH_DISABLE_LOSMART + bool "Disable losmart" + default y if DEFAULT_SMALL || !MTD_SMART + default n if !DEFAULT_SMALL && MTD_SMART + +config NSH_DISABLE_LN + bool "Disable ln" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + depends on PSEUDOFS_SOFTLINKS + +config NSH_DISABLE_LS + bool "Disable ls" + default n + +config NSH_DISABLE_MB + bool "Disable mb" + default y + +config NSH_DISABLE_MD5 + bool "Disable md5" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + depends on NETUTILS_CODECS && CODECS_HASH_MD5 + +config NSH_DISABLE_MKDIR + bool "Disable mkdir" + default n + +config NSH_DISABLE_MKFATFS + bool "Disable mkfatfs" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + depends on FSUTILS_MKFATFS + +config NSH_DISABLE_MKFIFO + bool "Disable mkfifo" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + depends on PIPES + +config NSH_DISABLE_MKRD + bool "Disable mkrd" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + +config NSH_DISABLE_MKSMARTFS + bool "Disable mksmartfs" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + depends on FS_SMARTFS && FSUTILS_MKSMARTFS + +config NSH_DISABLE_MH + bool "Disable mh" + default y + +config NSH_DISABLE_MODCMDS + bool "Disable modules commands (insmod, rmmod, lsmod)" + default n + depends on MODULE + +config NSH_DISABLE_MOUNT + bool "Disable mount" + default n + +config NSH_DISABLE_MV + bool "Disable mv" + default n + +config NSH_DISABLE_MW + bool "Disable mw" + default y + +config NSH_DISABLE_NSFMOUNT + bool "Disable nfsmount" + default n + depends on NFS + +config NSH_DISABLE_NSLOOKUP + bool "Disable nslookup" + default n + depends on LIBC_NETDB && NETDB_DNSCLIENT + +config NSH_DISABLE_PASSWD + bool "Disable passwd" + default y + depends on NSH_LOGIN_PASSWD && !FSUTILS_PASSWD_READONLY + +config NSH_DISABLE_PMCONFIG + bool "Disable pmconfig" + default n + depends on PM + +config NSH_DISABLE_POWEROFF + bool "Disable poweroff" + default n if !DEFAULT_SMALL + default y if DEFAULT_SMALL + depends on BOARDCTL_POWEROFF + +config NSH_DISABLE_PRINTF + bool "Disable printf" + default y + +config NSH_DISABLE_PS + bool "Disable ps" + default y if !FS_PROCFS || FS_PROCFS_EXCLUDE_PROCESS + default n if FS_PROCFS && !FS_PROCFS_EXCLUDE_PROCESS + +config NSH_DISABLE_PSSTACKUSAGE + bool "Disable ps stack usage" + depends on STACK_COLORATION && !NSH_DISABLE_PS + default n + ---help--- + Disable to save space and not pull in floating point routines + +config NSH_DISABLE_PUT + bool "Disable put" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + +config NSH_DISABLE_PWD + bool "Disable pwd" + default n + +config NSH_DISABLE_READLINK + bool "Disable readlink" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + depends on PSEUDOFS_SOFTLINKS + +config NSH_DISABLE_REBOOT + bool "Disable reboot" + default n if !DEFAULT_SMALL + default y if DEFAULT_SMALL + depends on BOARDCTL_RESET + +config NSH_DISABLE_RM + bool "Disable rm" + default n + +config NSH_DISABLE_RMDIR + bool "Disable rmdir" + default n + +config NSH_DISABLE_ROUTE + bool "Disable delroute" + depends on FS_PROCFS && NET_ROUTE && !FS_PROCFS_EXCLUDE_NET && !FS_PROCFS_EXCLUDE_ROUTE + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + +config NSH_DISABLE_RPTUN + bool "Disable rptun" + default n + depends on RPTUN + +config NSH_DISABLE_SET + bool "Disable set" + default n + +config NSH_DISABLE_SOURCE + bool "Disable source" + default n + +config NSH_DISABLE_SHUTDOWN + bool "Disable shutdown" + default n if !DEFAULT_SMALL && BOARD_POWEROFF && BOARD_RESET + default y if DEFAULT_SMALL || !BOARD_POWEROFF || !BOARD_RESET + depends on BOARDCTL_POWEROFF || BOARDCTL_RESET + +config NSH_DISABLE_SLEEP + bool "Disable sleep" + default n + +config NSH_DISABLE_TIME + bool "Disable time" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + +config NSH_DISABLE_TEST + bool "Disable test" + default n + +config NSH_DISABLE_TELNETD + bool "Disable telnetd" + default n if !NSH_NETLOCAL + default y if NSH_NETLOCAL + +config NSH_DISABLE_TRUNCATE + bool "Disable truncate" + default y + +config NSH_DISABLE_UMOUNT + bool "Disable umount" + default n + +config NSH_DISABLE_UNAME + bool "Disable uname" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + +config NSH_DISABLE_UNSET + bool "Disable unset" + default n + +config NSH_DISABLE_URLDECODE + bool "Disable urldecode" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + depends on NETUTILS_CODECS && CODECS_URLCODE + +config NSH_DISABLE_URLENCODE + bool "Disable urlencode" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + depends on NETUTILS_CODECS && CODECS_URLCODE + +config NSH_DISABLE_USERADD + bool "Disable useradd" + default y + depends on NSH_LOGIN_PASSWD && !FSUTILS_PASSWD_READONLY + +config NSH_DISABLE_USERDEL + bool "Disable userdel" + default y + depends on NSH_LOGIN_PASSWD && !FSUTILS_PASSWD_READONLY + +config NSH_DISABLE_USLEEP + bool "Disable usleep" + default n + +config NSH_DISABLE_WGET + bool "Disable wget" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + +config NSH_DISABLE_XD + bool "Disable xd" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + +config NSH_DISABLE_PM1_0PS5308 + bool "Disable the pm1.0 function of the sensor ps5308" + default n + +config NSH_DISABLE_PM2_5PS5308 + bool "Disable the pm2.5 function of the sensor ps5308" + default n + +config NSH_DISABLE_PM10PS5308 + bool "Disable the pm10 function of the sensor ps5308" + default n + +config NSH_DISABLE_TEMPHS300X + bool "Disable the temperature function of the sensor Hs300x" + default n + +config NSH_DISABLE_HUMIHS300X + bool "Disable the humidity function of the sensor Hs300x" + default n + +endmenu + +if MMCSD + +config NSH_MMCSDMINOR + int "MMC/SD minor number" + default 0 + ---help--- + If board-specific NSH start-up logic needs to mount an MMC/SD device, then the + setting should be provided to identify the MMC/SD minor device number (i.e., the N ini + /dev/mmcsdN). Default 0 + +config NSH_MMCSDSLOTNO + int "MMC/SD slot number" + default 0 + ---help--- + If board-specific NSH start-up supports more than one MMC/SD slot, then this setting + should be provided to indicate which slot should be used. Default: 0. + +config NSH_MMCSDSPIPORTNO + int "MMC/SD SPI device number" + default 0 + depends on MMCSD_SPI + ---help--- + If board-specif NSH start-up logic will mount an SPI-based MMC/SD volume, then this + setting may be needed to tell the board logic which SPI bus to use. Default: 0 + (meaning is board-specific). + +endif # MMCSD + +menu "Configure Command Options" + +config NSH_VARS + bool "NSH variables" + default n + ---help--- + By default, there are no internal NSH variables. NSH will use OS + environment variables for all variable storage. If this option, NSH + will also support local NSH variables. These variables are, for the + most part, transparent and work just like the OS environment + variables. The difference is that when you create new tasks, all of + environment variables are inherited by the created tasks. NSH local + variables are not. + + If this option is enabled (and CONFIG_DISABLE_ENVIRON is not), then a + new command called 'export' is enabled. The export command works very + must like the set command except that is operates on environment + variables. When CONFIG_NSH_VARS is enabled, there are changes in the + behavior of certains commands + + ============== =========================== =========================== + CMD w/o CONFIG_NSH_VARS w/CONFIG_NSH_VARS + ============== =========================== =========================== + set Set environment var a to b Set NSH var a to b + unset Unsets environment var a Unsets both environment var + and NSH var a + export Causes an error Unsets NSH var a. Sets + environment var a to b. + export Causes an error Sets environment var a to + NSH var b (or ""). Unsets + local var a. + env Lists all environment Lists all environment + variables variables + ============== =========================== =========================== + +config NSH_CMDOPT_DD_STATS + bool "dd: Support transfer statistics" + default n + depends on !NSH_DISABLE_DD + +config NSH_CODECS_BUFSIZE + int "File buffer size used by CODEC commands" + default 128 + +config NSH_CMDOPT_HEXDUMP + bool "hexdump: Enable 'skip' and 'count' parameters" + default n if DEFAULT_SMALL + default y if !DEFAULT_SMALL + depends on !NSH_DISABLE_HEXDUMP + +config NSH_PROC_MOUNTPOINT + string "procfs mountpoint" + default "/proc" + depends on FS_PROCFS + +endmenu + +config NSH_FILEIOSIZE + int "NSH I/O buffer size" + default 512 if DEFAULT_SMALL + default 1024 if !DEFAULT_SMALL + ---help--- + Size of a static I/O buffer used for file access (ignored if + there is no filesystem). Default is 512/1024. + +config NSH_STRERROR + bool "Use strerror()" + default n + depends on LIBC_STRERROR + ---help--- + strerror(errno) makes more readable output but strerror() is + very large and will not be used unless this setting is 'y' + This setting depends upon the strerror() having been enabled + with LIBC_STRERROR. + +menu "Scripting Support" + +config NSH_DISABLESCRIPT + bool "Disable script support" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + ---help--- + This can be set to 'y' to suppress support for scripting. This + setting disables the 'sh', 'test', and '[' commands and the + if-then[-else]-fi construct. This would only be set on systems + where a minimal footprint is a necessity and scripting is not. + +if !NSH_DISABLESCRIPT + +config NSH_DISABLE_ITEF + bool "Disable if-then-else-fi" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + ---help--- + This can be set to 'y' to suppress support for if-then-else-fi + sequences in scripts. This would only be set on systems where + some minimal scripting is required but if-then-else-fi is not. + +config NSH_DISABLE_LOOPS + bool "Disable loops" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + ---help--- + This can be set to 'y' to suppress support for while-do-done and + until-do-done sequences in scripts. This would only be set on + systems where some minimal scripting is required but looping + is not. + +endif # !NSH_DISABLESCRIPT + +config NSH_MMCSDMINOR + int "MMC/SD minor device number" + default 0 + ---help--- + If the architecture supports an MMC/SD slot and if the NSH + architecture specific logic is present, this option will provide + the MMC/SD minor number, i.e., the MMC/SD block driver will + be registered as /dev/mmcsdN where N is the minor number. + Default is zero. + +config NSH_ROMFSETC + bool "Support ROMFS start-up script" + default n + depends on FS_ROMFS + ---help--- + Mount a ROMFS filesystem at /etc and provide a startup script + at /etc/init.d/rcS. The default startup script will mount + a FAT FS RAMDISK at /tmp but the logic is easily extensible. + +if NSH_ROMFSETC + +config NSH_CROMFSETC + bool "Support CROMFS (compressed) start-up script" + default n + depends on NSH_ROMFSETC && FS_CROMFS + ---help--- + Mount a CROMFS filesystem at /etc and provide a compressed startup + script at /etc/init.d/rcS. + +config NSH_ROMFSRC + bool "Support ROMFS login script" + default n + ---help--- + The ROMFS start-up script will be executed exactly once. For + simple, persistence consoles (like a serial console). But with + other other kinds of consoles, there may be multiple, transient + sessions (such as Telnet and USB consoles). In these cases, you + may need another script that is executed at the beginning of each + session. Selecting this option enables support for such a login + script + +config NSH_ROMFSMOUNTPT + string "ROMFS mount point" + default "/etc" + ---help--- + The default mountpoint for the ROMFS volume is /etc, but that + can be changed with this setting. This must be a absolute path + beginning with '/'. + +config NSH_INITSCRIPT + string "Relative path to startup script" + default "init.d/rcS" + ---help--- + This is the relative path to the startup script within the mountpoint. + The default is init.d/rcS. This is a relative path and must not + start with '/'. + +config NSH_RCSCRIPT + string "Relative path to login script" + default ".nshrc" + depends on NSH_ROMFSRC + ---help--- + This is the relative path to the login script within the mountpoint. + The default is .nshrc. This is a relative path and must not + start with '/'. + +config NSH_ROMFSDEVNO + int "ROMFS block device minor number" + default 0 + ---help--- + This is the minor number of the ROMFS block device. The default is + '0' corresponding to /dev/ram0. + +config NSH_ROMFSSECTSIZE + int "ROMFS sector size" + default 64 + ---help--- + This is the sector size to use with the ROMFS volume. Since the + default volume is very small, this defaults to 64 but should be + increased if the ROMFS volume were to be become large. Any value + selected must be a power of 2. + +choice + prompt "ROMFS header location" + default NSH_DEFAULTROMFS + +config NSH_DEFAULTROMFS + bool "Default ROMFS header path" + ---help--- + Selects the default header located in the source directory of the + NSH library. + +config NSH_ARCHROMFS + bool "Architecture-specific ROMFS path" + ---help--- + Enable this option to provide an architecture-specific ROMFS + header at arch//nsh_romfsimg.h. Note that this header + will be linked (or copied) from nuttx/boards////include + and should be stored at that location in the nuttx boards/ + sub-directory. + +config NSH_CUSTOMROMFS + bool "Custom ROMFS header path" + ---help--- + Enable this option to provide a custom ROMFS header. The path to + the header file can be specified in the option "Custom ROMFS header + file". + +endchoice + +if NSH_CUSTOMROMFS + +config NSH_CUSTOMROMFS_HEADER + string "Custom ROMFS header file path" + default "" + ---help--- + Specifies the path to the custom ROMFS header file. This must be + either a full path or a path relative to one of the include file + search paths provided in your CFLAGS. + +endif #NSH_CUSTOMROMFS + +config NSH_FATDEVNO + int "FAT block device minor number" + default 1 + depends on FS_FAT + ---help--- + When the default rcS file used when NSH_ROMFSETC is selected, it + will mount a FAT FS under /tmp. This is the minor number of the FAT + FS block device. The default is '1' corresponding to /dev/ram1. + +config NSH_FATSECTSIZE + int "FAT sector size" + default 512 + depends on FS_FAT + ---help--- + When the default rcS file used when NSH_ROMFSETC is selected, it + will mount a FAT FS under /tmp. This is the sector size use with the + FAT FS. Default is 512. + +config NSH_FATNSECTORS + int "FAT number of sectors" + default 1024 + depends on FS_FAT + ---help--- + When the default rcS file used when NSH_ROMFSETC is selected, it + will mount a FAT FS under /tmp. This is the number of sectors to use + with the FAT FS. Default is 1024. The amount of memory used by the + FAT FS will be NSH_FATSECTSIZE * NSH_FATNSECTORS bytes. + +config NSH_FATMOUNTPT + string "FAT mount point" + default "/tmp" + depends on FS_FAT + ---help--- + When the default rcS file used when NSH_ROMFSETC is selected, it + will mount a FAT FS under /tmp. This is the location where the FAT + FS will be mounted. Default is "/tmp". + +endif # NSH_ROMFSETC +endmenu # Scripting Support + +menu "Console Configuration" + +config NSH_CONSOLE + bool "Use console" + default y + ---help--- + If NSH_CONSOLE is set to 'y', then a character driver + console front-end is selected (/dev/console). + + Normally, the serial console device is a UART and RS-232 + interface. However, if USBDEV is defined, then a USB + serial device may, instead, be used if the one of + the following are defined: + + PL2303 and PL2303_CONSOLE - Set up the Prolifics PL2303 + emulation as a console device at /dev/console. + + CDCACM and CDCACM_CONSOLE - Set up the CDC/ACM serial + device as a console device at dev/console. + + NSH_USBCONSOLE and NSH_USBCONDEV - Sets up some other USB + serial device as the NSH console (not necessarily dev/console). + +config NSH_USBCONSOLE + bool "Use a USB serial console" + default n + depends on LIB_BOARDCTL && NSH_CONSOLE && USBDEV && (CDCACM || PL2303) + select BOARDCTL_USBDEVCTRL + ---help--- + If defined, then the an arbitrary USB serial device may be used + to as the NSH console. In this case, NSH_USBCONDEV must be defined + to indicate which USB serial device to use as the console. + +if NSH_USBCONSOLE + +config NSH_USBCONDEV + string "USB serial console device" + default "/dev/ttyACM0" if CDCACM + default "/dev/ttyUSB0" if !CDCACM + ---help--- + If NSH_USBCONSOLE is set to 'y', then NSH_USBCONDEV must + also be set to select the USB device used to support the + NSH console. This should be set to the quoted name of a + read-/write-able USB driver. Default: "/dev/ttyACM0". + +config USBDEV_MINOR + int "USB serial console device minor number" + default 0 + ---help--- + If there are more than one USB devices, then a USB device + minor number may also need to be provided. Default: 0 + +endif # NSH_USBCONSOLE + +config NSH_ALTCONDEV + bool "Alternative console device" + default n + depends on NSH_CONSOLE && !NSH_USBCONSOLE && !NSH_TELNET + ---help--- + If CONFIG_NSH_CONSOLE is set to y, then CONFIG_NSH_ALTCONDEV may + also be selected to enable use of an alternate character device + to support the NSH console. If CONFIG_NSH_ALTCONDEV is selected, + then NSH_ALTSTDIN, NSH_ALTSTDOUT and NSH_ALTSTDERR must be set + to select the serial devices used to support the NSH console. + This may be useful, for example, to separate the NSH command + line from the system console when the system console is used to + provide debug output. + + Default: stdin, stderr and stdout (probably "/dev/console") + + NOTE 1: When any other device other than /dev/console is used + for a user interface, (1) linefeeds (\n) will not be expanded to + carriage return / linefeeds (\r\n). You will need to set + your terminal program to account for this. And (2) input is + not automatically echoed so you will have to turn local echo on. + + NOTE 2: This option forces the console of all sessions to use + NSH_ALTSTD(IN/OUT/ERR). Hence, this option only makes sense for + a system that supports only a single session. This option is, + in particular, incompatible with Telnet sessions because each + Telnet session must use a different console device. + +if NSH_ALTCONDEV + +config NSH_ALTSTDIN + string "Alternative console \"stdin\" device name" + default "/dev/console" + ---help--- + If CONFIG_NSH_CONSOLE is set to y, then CONFIG_NSH_ALTCONDEV may + also be selected to enable use of an alternate character device + to support the NSH console. If CONFIG_NSH_ALTCONDEV is selected, + then NSH_ALTSTDIN must be set to select the "stdin" device to + support the NSH console. This should be set to the quoted name + of a readable character driver such as: + + NSH_ALTSTDIN="/dev/ttyS1". + + This way the input will come from "/dev/ttyS1". + +config NSH_ALTSTDOUT + string "Alternative console \"stdout\" device name" + default "/dev/console" if !SLCD_CONSOLE + default "/dev/slcd0" if SLCD_CONSOLE + ---help--- + If CONFIG_NSH_CONSOLE is set to y, then CONFIG_NSH_ALTCONDEV may + also be selected to enable use of an alternate character device + to support the NSH console. If CONFIG_NSH_ALTCONDEV is selected, + then NSH_ALTSTDOUT must be set to select the "stdout" device to + support the NSH console. This should be set to the quoted name + of a write-able character driver such as: + + NSH_ALTSTDIN="/dev/ttyS1". + + This way the standard output will go to "/dev/ttyS1". + +config NSH_ALTSTDERR + string "Alternative console \"stderr\" device name" + default "/dev/console" if !SLCD_CONSOLE + default "/dev/slcd0" if SLCD_CONSOLE + ---help--- + If CONFIG_NSH_CONSOLE is set to y, then CONFIG_NSH_ALTCONDEV may + also be selected to enable use of an alternate character device + to support the NSH console. If CONFIG_NSH_ALTCONDEV is selected, + then NSH_ALTSTDERR must be set to select the "stderr" device to + support the NSH console. This should be set to the quoted name + of a write-able character driver such as: + + NSH_ALTSTDIN="/dev/ttyS1". + + This way the standard error output will go to "/dev/ttyS1". + +endif # NSH_ALTCONDEV + +config NSH_USBKBD + bool "Use USB keyboard input" + default n + depends on NSH_CONSOLE && USBHOST_HIDKBD && !NSH_USBCONSOLE + ---help--- + Normally NSH uses the same device for stdin, stdout, and stderr. By + default, that device is /dev/console. If this option is selected, + then NSH will use a USB HID keyboard for stdin. In this case, the + keyboard is connected directly to the target (via a USB host + interface) and the data from the keyboard will drive NSH. NSH + output (stdout and stderr) will still go to /dev/console. + +if NSH_USBKBD + +config NSH_USBKBD_DEVNAME + string "USB keyboard device" + default "/dev/kbda" + ---help--- + If NSH_USBKBD is set to 'y', then NSH_USBKBD_DEVNAME must also be + set to select the USB keyboard device used to support the NSH + console input. This should be set to the quoted name of a read- + able keyboard driver. Default: "/dev/kbda". + +endif #NSH_USBKBD +endmenu # Console Configuration + +menu "USB Device Trace Support" + depends on USBDEV && (DEBUG_FEATURES || USBDEV_TRACE) + +config NSH_USBDEV_TRACE + bool "Enable Builtin USB Trace Support" + default n + ---help--- + Enable builtin USB trace support in NSH. If selected, buffered USB + trace data will be presented each time a command is provided to NSH. + The USB trace data will be sent to the console unless CONFIG_DEBUG_FEATURES + set or unless you are using a USB console. In those cases, the trace + data will go to the SYSLOG device. + + If not enabled, the USB trace support can be provided by external + logic such as nuttx/drivers/usbmonitor. + +if NSH_USBDEV_TRACE + +config NSH_USBDEV_TRACEINIT + bool "Show initialization events" + default n + ---help--- + Show initialization events + +config NSH_USBDEV_TRACECLASS + bool "Show class driver events" + default n + ---help--- + Show class driver events + +config NSH_USBDEV_TRACETRANSFERS + bool "Show data transfer events" + default n + ---help--- + Show data transfer events + +config NSH_USBDEV_TRACECONTROLLER + bool "Show controller events" + default n + ---help--- + Show controller events + +config NSH_USBDEV_TRACEINTERRUPTS + bool "Show interrupt-related events" + default n + ---help--- + Show interrupt-related events + +endif # NSH_USBDEV_TRACE +endmenu # USB Device Trace Support + +config NSH_ARCHINIT + bool "Have architecture-specific initialization" + default n + select LIB_BOARDCTL + ---help--- + Set if your board provides architecture specific initialization + via the board-interface function boardctl(). The boardctl() + function will be called early in NSH initialization to allow + board logic to do such things as configure MMC/SD slots. + +menu "Networking Configuration" + depends on NET + +config NSH_NETINIT + bool "Network initialization" + default y + depends on NET + select NETUTILS_NETINIT + ---help--- + This option enables/disables all network initialization in NSH. + +if !NSH_DISABLE_WGET +config NSH_WGET_BUFF_SIZE + int "wget buffer size" + default 512 + ---help--- + Buffer size for wget command +endif # NSH_DISABLE_WGET + +endmenu # Networking Configuration" + +menu "Telnet Configuration" + depends on NETUTILS_TELNETD + +config NSH_TELNET + bool "Use Telnet console" + default n if DEFAULT_SMALL + default y if !DEFAULT_SMALL + depends on NETUTILS_TELNETD + ---help--- + If NSH_TELNET is set to 'y', then a TELENET + server front-end is selected. When this option is provided, + you may log into NuttX remotely using telnet in order to + access NSH. + +if NSH_TELNET + +config NSH_TELNETD_PORT + int "Telnet port number" + default 23 + ---help--- + The telnet daemon will listen on this TCP port number for connections. + Default: 23 + +config NSH_TELNETD_DAEMONPRIO + int "Telnet daemon priority" + default 100 + ---help--- + Priority of the Telnet daemon. Default: 100 + +config NSH_TELNETD_DAEMONSTACKSIZE + int "Telnet daemon stack size" + default DEFAULT_TASK_STACKSIZE + ---help--- + Stack size allocated for the Telnet daemon. Default: 2048 + +config NSH_TELNETD_CLIENTPRIO + int "Telnet client priority" + default 100 + ---help--- + Priority of the Telnet client. Default: 100 + +config NSH_TELNETD_CLIENTSTACKSIZE + int "Telnet client stack size" + default DEFAULT_TASK_STACKSIZE + ---help--- + Stack size allocated for the Telnet client. Default: 2048 + +config NSH_IOBUFFER_SIZE + int "Telnet I/O buffer size" + default 512 + ---help--- + Determines the size of the I/O buffer to use for sending/ + receiving TELNET commands/responses. Default: 512 + +endif # NSH_TELNET +endmenu # Telnet Configuration + +config NSH_LOGIN + bool + default n + +config NSH_CONSOLE_LOGIN + bool "Console Login" + default n + select NSH_LOGIN + ---help--- + If defined, then the console user will be required to provide a + username and password to start the NSH shell. + +config NSH_TELNET_LOGIN + bool "Telnet Login" + default n + depends on NSH_TELNET + select NSH_LOGIN + ---help--- + If defined, then the Telnet user will be required to provide a + username and password to start the NSH shell. + +if NSH_LOGIN + +choice + prompt "Verification method" + default NSH_LOGIN_PASSWD if FSUTILS_PASSWD + default NSH_LOGIN_FIXED if !FSUTILS_PASSWD + +config NSH_LOGIN_FIXED + bool "Fixed username/password" + ---help--- + Verify user credentials by matching to fixed username and password + strings + +config NSH_LOGIN_PLATFORM + bool "Platform username/password" + ---help--- + Call a platform-specific function to perform the verification of + user credentials. In this case, the platform-specific logic must + provide a function with the following prototype: + + int platform_user_verify(FAR const char *username, FAR const char *password); + + which is prototyped an described in apps/include/nshlib/nshlib.h and + which may be included like: + + #include "nshlib/nshlib.h" + + An appropriate place to implement this function might be in the + directory apps/platform/. + +config NSH_LOGIN_PASSWD + bool "Encrypted password file" + depends on FSUTILS_PASSWD + ---help--- + Use the content of an encrypted password file to verify user + credentials. This option requires that you have selected + CONFIG_FSUTILS_PASSWD to enable the access methods of + apps/fsutils/passwd. + +endchoice # Verification method + +config NSH_LOGIN_USERNAME + string "Login username" + default "admin" + depends on !NSH_LOGIN_PASSWD + ---help--- + Login user name. Default: "admin" + +config NSH_LOGIN_PASSWORD + string "Login password" + default "Administrator" + depends on !NSH_LOGIN_PASSWD + ---help--- + Login password: Default: "Administrator" + +config NSH_LOGIN_FAILDELAY + int "Login failure delay" + default 0 + ---help--- + Login failure delay in milliseconds. The system will pause this + amount of time after each failed login attempt in order to + discourage people from cracking the password by brute force. The + value zero may be supplied to disable the delay. + +config NSH_LOGIN_FAILCOUNT + int "Login retry count" + default 3 + ---help--- + Number of login retry attempts. + +endif # NSH_LOGIN +endif # NSH_LIBRARY +endmenu # NSH Library diff --git a/Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/Makefile b/Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/Makefile new file mode 100644 index 000000000..0fbd57dc7 --- /dev/null +++ b/Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/Makefile @@ -0,0 +1,131 @@ +############################################################################ +# apps/nshlib/Makefile +# +# Copyright (C) 2011-2013, 2016 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +include $(APPDIR)/Make.defs + +# NSH Library + +CSRCS = nsh_init.c nsh_parse.c nsh_console.c nsh_script.c nsh_system.c +CSRCS += nsh_command.c nsh_fscmds.c nsh_ddcmd.c nsh_proccmds.c nsh_mmcmds.c +CSRCS += nsh_timcmds.c nsh_envcmds.c nsh_syscmds.c nsh_dbgcmds.c nsh_Applicationscmd.c + +ifeq ($(CONFIG_FILE_STREAM),y) +CSRCS += nsh_session.c +ifeq ($(CONFIG_NSH_CONSOLE_LOGIN),y) +CSRCS += nsh_login.c +endif +else +CSRCS += nsh_stdsession.c +ifeq ($(CONFIG_NSH_CONSOLE_LOGIN),y) +CSRCS += nsh_stdlogin.c +endif +endif + +CSRCS += nsh_fsutils.c + +ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) +CSRCS += nsh_builtin.c +endif + +ifeq ($(CONFIG_NSH_FILE_APPS),y) +CSRCS += nsh_fileapps.c +endif + +ifeq ($(CONFIG_NSH_VARS),y) +CSRCS += nsh_vars.c +endif + +ifeq ($(CONFIG_NSH_ROMFSETC),y) +CSRCS += nsh_romfsetc.c +endif + +ifeq ($(CONFIG_NET),y) +CSRCS += nsh_netcmds.c + +ifeq ($(CONFIG_NET_ROUTE),y) +CSRCS += nsh_routecmds.c +endif +endif + +ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y) +CSRCS += nsh_mntcmds.c +endif + +ifeq ($(CONFIG_MODULE),y) +ifneq ($(CONFIG_NSH_DISABLE_MODCMDS),y) +CSRCS += nsh_modcmds.c +endif +endif + +ifeq ($(CONFIG_NSH_CONSOLE),y) +CSRCS += nsh_consolemain.c +endif + +ifneq ($(CONFIG_NSH_DISABLE_PRINTF),y) +CSRCS += nsh_printf.c +endif + +ifeq ($(CONFIG_NSH_TELNET),y) +CSRCS += nsh_telnetd.c +ifeq ($(CONFIG_NSH_TELNET_LOGIN),y) +CSRCS += nsh_telnetlogin.c +endif +endif + +ifneq ($(CONFIG_NSH_DISABLESCRIPT),y) +CSRCS += nsh_test.c +endif + +ifeq ($(CONFIG_USBDEV),y) +CSRCS += nsh_usbconsole.c +endif + +ifeq ($(CONFIG_NSH_ALTCONDEV),y) +CSRCS += nsh_altconsole.c +endif + +ifeq ($(CONFIG_NSH_USBDEV_TRACE),y) +CSRCS += nsh_usbtrace.c +endif + +ifeq ($(CONFIG_NETUTILS_CODECS),y) +CSRCS += nsh_codeccmd.c +endif + +ifeq ($(CONFIG_NSH_LOGIN_PASSWD),y) +CSRCS += nsh_passwdcmds.c +endif + +include $(APPDIR)/Application.mk diff --git a/Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/nsh.h b/Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/nsh.h new file mode 100644 index 000000000..e8b63b79a --- /dev/null +++ b/Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/nsh.h @@ -0,0 +1,1426 @@ +/**************************************************************************** + * apps/nshlib/nsh.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __APPS_NSHLIB_NSH_H +#define __APPS_NSHLIB_NSH_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include +#include +#include +#include + +#ifdef CONFIG_NSH_STRERROR +# include +#endif + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +/* The background commands require pthread support */ + +#ifdef CONFIG_DISABLE_PTHREAD +# ifndef CONFIG_NSH_DISABLEBG +# define CONFIG_NSH_DISABLEBG 1 +# endif +#endif + +#ifndef CONFIG_FILE_STREAM +# undef CONFIG_NSH_TELNET +# undef CONFIG_NSH_FILE_APPS +# undef CONFIG_NSH_TELNET +# undef CONFIG_NSH_CMDPARMS +#endif + +/* rmdir, mkdir, rm, and mv are only available if mountpoints are enabled + * AND there is a writeable file system OR if these operations on the + * pseudo-filesystem are not disabled. + */ + +#undef NSH_HAVE_DIROPTS +#if !defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_DISABLE_PSEUDOFS_OPERATIONS) +# define NSH_HAVE_DIROPTS 1 +#endif + +/* If CONFIG_NSH_CMDPARMS is selected, then the path to a directory to + * hold temporary files must be provided. + */ + +#if defined(CONFIG_NSH_CMDPARMS) && !defined(CONFIG_LIBC_TMPDIR) +# define CONFIG_LIBC_TMPDIR "/tmp" +#endif + +/* Some networking commands do not make sense unless there is a network + * device. There might not be a network device if, for example, only Unix + * domain sockets were enable. + */ + +/* Telnetd requires networking support */ + +#ifndef CONFIG_NET +# undef CONFIG_NSH_TELNET +#endif + +/* get and put require TFTP client support */ + +#ifndef CONFIG_NETUTILS_TFTPC +# undef CONFIG_NSH_DISABLE_PUT +# undef CONFIG_NSH_DISABLE_GET +# define CONFIG_NSH_DISABLE_PUT 1 +# define CONFIG_NSH_DISABLE_GET 1 +#endif + +/* Route depends on routing table support and procfs support */ + +#if !defined(CONFIG_FS_PROCFS) || defined(CONFIG_FS_PROCFS_EXCLUDE_NET) || \ + defined(CONFIG_FS_PROCFS_EXCLUDE_ROUTE) || !defined(CONFIG_NET_ROUTE) || \ + (!defined(CONFIG_NET_IPv4) && !defined(CONFIG_NET_IPv6)) +# ifndef CONFIG_NSH_DISABLE_ROUTE +# define CONFIG_NSH_DISABLE_ROUTE 1 +# endif +#endif + +/* wget depends on web client support */ + +#ifndef CONFIG_NETUTILS_WEBCLIENT +# undef CONFIG_NSH_DISABLE_WGET +# define CONFIG_NSH_DISABLE_WGET 1 +#endif + +/* mksmartfs depends on smartfs and mksmartfs support */ + +#if !defined(CONFIG_FS_SMARTFS) || !defined(CONFIG_FSUTILS_MKSMARTFS) +# undef CONFIG_NSH_DISABLE_MKSMARTFS +# define CONFIG_NSH_DISABLE_MKSMARTFS 1 +#endif + +/* One front end must be defined */ + +#if !defined(CONFIG_NSH_CONSOLE) && !defined(CONFIG_NSH_TELNET) +# error "No NSH front end defined" +#endif + +/* If a USB device is selected for the NSH console then we need to handle + * some special start-up conditions. + */ + +#undef HAVE_USB_CONSOLE +#if defined(CONFIG_USBDEV) + +/* Check for a PL2303 serial console. Use console device "/dev/console". */ + +# if defined(CONFIG_PL2303) && defined(CONFIG_PL2303_CONSOLE) +# define HAVE_USB_CONSOLE 1 + +/* Check for a CDC/ACM serial console. Use console device "/dev/console". */ + +# elif defined(CONFIG_CDCACM) && defined(CONFIG_CDCACM_CONSOLE) +# define HAVE_USB_CONSOLE 1 + +/* Check for a generic USB console. In this case, the USB console device + * must be provided in CONFIG_NSH_USBCONDEV. + */ + +# elif defined(CONFIG_NSH_USBCONSOLE) +# define HAVE_USB_CONSOLE 1 +# endif +#endif + +/* Defaults for the USB console */ + +#ifdef HAVE_USB_CONSOLE + +/* The default USB console device minor number is 0 */ + +# ifndef CONFIG_NSH_USBDEV_MINOR +# define CONFIG_NSH_USBDEV_MINOR 0 +# endif + +/* The default USB serial console device */ + +# ifndef CONFIG_NSH_USBCONDEV +# if defined(CONFIG_CDCACM) +# define CONFIG_NSH_USBCONDEV "/dev/ttyACM0" +# elif defined(CONFIG_PL2303) +# define CONFIG_NSH_USBCONDEV "/dev/ttyUSB0" +# else +# define CONFIG_NSH_USBCONDEV "/dev/console" +# endif +# endif + +#endif /* HAVE_USB_CONSOLE */ + +/* If a USB keyboard device is selected for NSH input then we need to handle + * some special start-up conditions. + */ + +#undef HAVE_USB_KEYBOARD + +/* Check pre-requisites */ + +#if !defined(CONFIG_USBHOST) || !defined(CONFIG_USBHOST_HIDKBD) || \ + defined(HAVE_USB_CONSOLE) +# undef CONFIG_NSH_USBKBD +#endif + +/* Check default settings */ + +#if defined(CONFIG_NSH_USBKBD) + +/* Check for a USB HID keyboard in the configuration */ + +# define HAVE_USB_KEYBOARD 1 + +/* The default keyboard device is /dev/kbda */ + +# ifndef NSH_USBKBD_DEVNAME +# define NSH_USBKBD_DEVNAME "/dev/kbda" +# endif + +/* In this case NSH_ALTSTDIN should be "/dev/kbda" */ + +# undef CONFIG_NSH_ALTSTDIN +# define CONFIG_NSH_ALTSTDIN NSH_USBKBD_DEVNAME + +#endif /* HAVE_USB_KEYBOARD */ + +/* USB trace settings */ + +#ifndef CONFIG_USBDEV_TRACE +# undef CONFIG_NSH_USBDEV_TRACE +#endif + +#ifdef CONFIG_NSH_USBDEV_TRACE +# ifdef CONFIG_NSH_USBDEV_TRACEINIT +# define TRACE_INIT_BITS (TRACE_INIT_BIT) +# else +# define TRACE_INIT_BITS (0) +# endif + +# define TRACE_ERROR_BITS (TRACE_DEVERROR_BIT|TRACE_CLSERROR_BIT) + +# ifdef CONFIG_NSH_USBDEV_TRACECLASS +# define TRACE_CLASS_BITS (TRACE_CLASS_BIT|TRACE_CLASSAPI_BIT|\ + TRACE_CLASSSTATE_BIT) +# else +# define TRACE_CLASS_BITS (0) +# endif + +# ifdef CONFIG_NSH_USBDEV_TRACETRANSFERS +# define TRACE_TRANSFER_BITS (TRACE_OUTREQQUEUED_BIT|TRACE_INREQQUEUED_BIT|\ + TRACE_READ_BIT|TRACE_WRITE_BIT|\ + TRACE_COMPLETE_BIT) +# else +# define TRACE_TRANSFER_BITS (0) +# endif + +# ifdef CONFIG_NSH_USBDEV_TRACECONTROLLER +# define TRACE_CONTROLLER_BITS (TRACE_EP_BIT|TRACE_DEV_BIT) +# else +# define TRACE_CONTROLLER_BITS (0) +# endif + +# ifdef CONFIG_NSH_USBDEV_TRACEINTERRUPTS +# define TRACE_INTERRUPT_BITS (TRACE_INTENTRY_BIT|TRACE_INTDECODE_BIT|\ + TRACE_INTEXIT_BIT) +# else +# define TRACE_INTERRUPT_BITS (0) +# endif + +# define TRACE_BITSET (TRACE_INIT_BITS|TRACE_ERROR_BITS|\ + TRACE_CLASS_BITS|TRACE_TRANSFER_BITS|\ + TRACE_CONTROLLER_BITS|TRACE_INTERRUPT_BITS) + +#endif /* CONFIG_NSH_USBDEV_TRACE */ + +/* If Telnet is selected for the NSH console, then we must configure + * the resources used by the Telnet daemon and by the Telnet clients. + * + * CONFIG_NSH_TELNETD_PORT - The telnet daemon will listen on this. + * port. Default: 23 + * CONFIG_NSH_TELNETD_DAEMONPRIO - Priority of the Telnet daemon. + * Default: SCHED_PRIORITY_DEFAULT + * CONFIG_NSH_TELNETD_DAEMONSTACKSIZE - Stack size allocated for the + * Telnet daemon. Default: 2048 + * CONFIG_NSH_TELNETD_CLIENTPRIO - Priority of the Telnet client. + * Default: SCHED_PRIORITY_DEFAULT + * CONFIG_NSH_TELNETD_CLIENTSTACKSIZE - Stack size allocated for the + * Telnet client. Default: 2048 + * CONFIG_NSH_TELNET_LOGIN - Support a simple Telnet login. + * + * If CONFIG_NSH_TELNET_LOGIN is defined, then these additional + * options may be specified: + * + * CONFIG_NSH_LOGIN_USERNAME - Login user name. Default: "admin" + * CONFIG_NSH_LOGIN_PASSWORD - Login password: Default: "Administrator" + * CONFIG_NSH_LOGIN_FAILCOUNT - Number of login retry attempts. + * Default 3. + */ + +#ifndef CONFIG_NSH_TELNETD_PORT +# define CONFIG_NSH_TELNETD_PORT 23 +#endif + +#ifndef CONFIG_NSH_TELNETD_DAEMONPRIO +# define CONFIG_NSH_TELNETD_DAEMONPRIO SCHED_PRIORITY_DEFAULT +#endif + +#ifndef CONFIG_NSH_TELNETD_DAEMONSTACKSIZE +# define CONFIG_NSH_TELNETD_DAEMONSTACKSIZE 2048 +#endif + +#ifndef CONFIG_NSH_TELNETD_CLIENTPRIO +# define CONFIG_NSH_TELNETD_CLIENTPRIO SCHED_PRIORITY_DEFAULT +#endif + +#ifndef CONFIG_NSH_TELNETD_CLIENTSTACKSIZE +# define CONFIG_NSH_TELNETD_CLIENTSTACKSIZE 2048 +#endif + +#ifdef CONFIG_NSH_TELNET_LOGIN + +# ifndef CONFIG_NSH_LOGIN_USERNAME +# define CONFIG_NSH_LOGIN_USERNAME "admin" +# endif + +# ifndef CONFIG_NSH_LOGIN_PASSWORD +# define CONFIG_NSH_LOGIN_PASSWORD "nuttx" +# endif + +# ifndef CONFIG_NSH_LOGIN_FAILCOUNT +# define CONFIG_NSH_LOGIN_FAILCOUNT 3 +# endif + +#endif /* CONFIG_NSH_TELNET_LOGIN */ + +/* Verify support for ROMFS /etc directory support options */ + +#ifdef CONFIG_NSH_ROMFSETC +# ifdef CONFIG_DISABLE_MOUNTPOINT +# error "Mountpoint support is disabled" +# undef CONFIG_NSH_ROMFSETC +# endif + +# ifndef CONFIG_FS_ROMFS +# error "ROMFS support not enabled" +# undef CONFIG_NSH_ROMFSETC +# endif + +# ifndef CONFIG_NSH_ROMFSMOUNTPT +# define CONFIG_NSH_ROMFSMOUNTPT "/etc" +# endif + +# ifndef CONFIG_NSH_INITSCRIPT +# define CONFIG_NSH_INITSCRIPT "init.d/rcS" +# endif + +# undef NSH_INITPATH +# define NSH_INITPATH CONFIG_NSH_ROMFSMOUNTPT "/" CONFIG_NSH_INITSCRIPT + +# ifdef CONFIG_NSH_ROMFSRC +# ifndef CONFIG_NSH_RCSCRIPT +# define CONFIG_NSH_RCSCRIPT ".nshrc" +# endif + +# undef NSH_RCPATH +# define NSH_RCPATH CONFIG_NSH_ROMFSMOUNTPT "/" CONFIG_NSH_RCSCRIPT +# endif + +# ifndef CONFIG_NSH_ROMFSDEVNO +# define CONFIG_NSH_ROMFSDEVNO 0 +# endif + +# ifndef CONFIG_NSH_ROMFSSECTSIZE +# define CONFIG_NSH_ROMFSSECTSIZE 64 +# endif + +# define NSECTORS(b) (((b)+CONFIG_NSH_ROMFSSECTSIZE-1)/CONFIG_NSH_ROMFSSECTSIZE) +# define STR_RAMDEVNO(m) #m +# define MKMOUNT_DEVNAME(m) "/dev/ram" STR_RAMDEVNO(m) +# define MOUNT_DEVNAME MKMOUNT_DEVNAME(CONFIG_NSH_ROMFSDEVNO) + +#else + +# undef CONFIG_NSH_ROMFSRC +# undef CONFIG_NSH_ROMFSMOUNTPT +# undef CONFIG_NSH_INITSCRIPT +# undef CONFIG_NSH_RCSCRIPT +# undef CONFIG_NSH_ROMFSDEVNO +# undef CONFIG_NSH_ROMFSSECTSIZE + +#endif + +/* This is the maximum number of arguments that will be accepted for a + * command. Here we attempt to select the smallest number possible depending + * upon the of commands that are available. Most commands use seven or fewer + * arguments, but there are a few that require more. + * + * This value is also configurable with CONFIG_NSH_MAXARGUMENTS. This + * configurability is necessary since there may also be external, "built-in" + * commands that require more commands than NSH is aware of. + */ + +#if CONFIG_NSH_MAXARGUMENTS < 11 +# if defined(CONFIG_NET) && !defined(CONFIG_NSH_DISABLE_IFCONFIG) +# undef CONFIG_NSH_MAXARGUMENTS +# define CONFIG_NSH_MAXARGUMENTS 11 +# endif +#endif + +/* Argument list size + * + * argv[0]: The command name. + * argv[1]: The beginning of argument (up to CONFIG_NSH_MAXARGUMENTS) + * argv[argc-3]: Possibly '>' or '>>' + * argv[argc-2]: Possibly + * argv[argc-1]: Possibly '&' (if pthreads are enabled) + * argv[argc]: NULL terminating pointer + * + * Maximum size is CONFIG_NSH_MAXARGUMENTS+5 + */ + +#ifndef CONFIG_NSH_DISABLEBG +# define MAX_ARGV_ENTRIES (CONFIG_NSH_MAXARGUMENTS+5) +#else +# define MAX_ARGV_ENTRIES (CONFIG_NSH_MAXARGUMENTS+4) +#endif + +/* strerror() produces much nicer output but is, however, quite large and + * will only be used if CONFIG_NSH_STRERROR is defined. Note that the + * strerror interface must also have been enabled with CONFIG_LIBC_STRERROR. + */ + +#ifndef CONFIG_LIBC_STRERROR +# undef CONFIG_NSH_STRERROR +#endif + +#ifdef CONFIG_NSH_STRERROR +# define NSH_ERRNO strerror(errno) +# define NSH_ERRNO_OF(err) strerror(err) +# define NSH_HERRNO gai_strerror(h_errno) +# define NSH_HERRNO_OF(err) gai_strerror(err) +#else +# define NSH_ERRNO (errno) +# define NSH_ERRNO_OF(err) (err) +# define NSH_HERRNO (h_errno) +# define NSH_HERRNO_OF(err) (err) +#endif + +/* Maximum size of one command line (telnet or serial) */ + +#ifndef CONFIG_NSH_LINELEN +# define CONFIG_NSH_LINELEN 80 +#endif + +/* The following two settings are used only in the telnetd interface */ + +#ifndef CONFIG_NSH_IOBUFFER_SIZE +# define CONFIG_NSH_IOBUFFER_SIZE 512 +#endif + +/* The maximum number of nested if-then[-else]-fi sequences that + * are permissible. + */ + +#ifndef CONFIG_NSH_NESTDEPTH +# define CONFIG_NSH_NESTDEPTH 3 +#endif + +/* Define to enable dumping of all input/output buffers */ + +#undef CONFIG_NSH_TELNETD_DUMPBUFFER + +/* Make sure that the home directory is defined */ + +#ifndef CONFIG_LIB_HOMEDIR +# define CONFIG_LIB_HOMEDIR "/" +#endif + +#undef NSH_HAVE_VARS +#if defined(CONFIG_NSH_VARS) || !defined(CONFIG_DISABLE_ENVIRON) +# define NSH_HAVE_VARS +#endif + +/* Stubs used when working directory is not supported */ + +#ifdef CONFIG_DISABLE_ENVIRON +# define nsh_getfullpath(v,p) ((FAR char*)(p)) +# define nsh_freefullpath(p) +#endif + +/* The size of the I/O buffer may be specified in the + * boards////configs/defconfig file -- provided + * that it is at least as large as PATH_MAX. + */ + +#define NSH_HAVE_IOBUFFER 1 + +/* The I/O buffer is needed for the ls, cp, and ps commands. It is also + * needed if the platform supplied MOTD is configured. + */ + +#if defined(CONFIG_NSH_DISABLE_LS) && defined(CONFIG_NSH_DISABLE_CP) && \ + defined(CONFIG_NSH_DISABLE_PS) && !defined(CONFIG_NSH_PLATFORM_MOTD) +# undef NSH_HAVE_IOBUFFER +#endif + +#ifdef NSH_HAVE_IOBUFFER +# ifdef CONFIG_NSH_FILEIOSIZE +# if CONFIG_NSH_FILEIOSIZE > (PATH_MAX + 1) +# define IOBUFFERSIZE CONFIG_NSH_FILEIOSIZE +# else +# define IOBUFFERSIZE (PATH_MAX + 1) +# endif +# else +# define IOBUFFERSIZE 1024 +# endif +#else +# define IOBUFFERSIZE (PATH_MAX + 1) +#endif + +/* Certain commands/features are only available if the procfs file system is + * enabled. + */ + +#if !defined(CONFIG_FS_PROCFS) || defined(CONFIG_FS_PROCFS_EXCLUDE_NET) +# undef CONFIG_NSH_DISABLE_IFCONFIG /* 'ifconfig' depends on network procfs */ +# define CONFIG_NSH_DISABLE_IFCONFIG 1 + +# undef CONFIG_NSH_DISABLE_IFUPDOWN /* 'ifup/down' depend on network procfs */ +# define CONFIG_NSH_DISABLE_IFUPDOWN 1 +#endif + +#if !defined(CONFIG_FS_PROCFS) || defined(CONFIG_FS_PROCFS_EXCLUDE_PROCESS) +# undef CONFIG_NSH_DISABLE_PS /* 'ps' depends on process procfs */ +# define CONFIG_NSH_DISABLE_PS 1 +#endif + +#define NSH_HAVE_CPULOAD 1 +#if !defined(CONFIG_FS_PROCFS) || defined(CONFIG_FS_PROCFS_EXCLUDE_CPULOAD) || \ + !defined(CONFIG_SCHED_CPULOAD) || defined(CONFIG_NSH_DISABLE_PS) +# undef NSH_HAVE_CPULOAD +#endif + +#if !defined(CONFIG_FS_PROCFS) || (defined(CONFIG_FS_PROCFS_EXCLUDE_BLOCKS) && \ + defined(CONFIG_FS_PROCFS_EXCLUDE_USAGE)) +# undef CONFIG_NSH_DISABLE_DF /* 'df' depends on fs procfs */ +# define CONFIG_NSH_DISABLE_DF 1 +#endif + +#if defined(CONFIG_FS_PROCFS) || !defined(CONFIG_NSH_DISABLE_DF) +# define HAVE_DF_HUMANREADBLE 1 +# define HAVE_DF_BLOCKOUTPUT 1 +# if defined(CONFIG_FS_PROCFS_EXCLUDE_USAGE) +# undef HAVE_DF_HUMANREADBLE +# endif +# if defined(CONFIG_FS_PROCFS_EXCLUDE_BLOCKS) +# undef HAVE_DF_BLOCKOUTPUT +# endif +#endif + +#undef HAVE_IRQINFO +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS) && \ + defined(CONFIG_SCHED_IRQMONITOR) +# define HAVE_IRQINFO 1 +#endif + +#undef HAVE_MOUNT_LIST +#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_NSH_DISABLE_MOUNT) && \ + !defined(CONFIG_FS_PROCFS_EXCLUDE_MOUNT) +# define HAVE_MOUNT_LIST 1 +#endif + +#if !defined(CONFIG_FS_PROCFS) || defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO) +# undef CONFIG_NSH_DISABLE_FREE +# define CONFIG_NSH_DISABLE_FREE 1 +#endif + +/* Suppress unused file utilities */ + +#define NSH_HAVE_CATFILE 1 +#define NSH_HAVE_READFILE 1 +#define NSH_HAVE_FOREACH_DIRENTRY 1 +#define NSH_HAVE_TRIMDIR 1 +#define NSH_HAVE_TRIMSPACES 1 + +#if !defined(CONFIG_FS_PROCFS) || defined(CONFIG_DISABLE_ENVIRON) || \ + defined(CONFIG_FS_PROCFS_EXCLUDE_ENVIRON) || !defined(NSH_HAVE_CATFILE) +# undef CONFIG_NSH_DISABLE_ENV +# define CONFIG_NSH_DISABLE_ENV 1 +#endif + +#if !defined(CONFIG_NSH_VARS) || defined(CONFIG_DISABLE_ENVIRON) +# undef CONFIG_NSH_DISABLE_EXPORT +# define CONFIG_NSH_DISABLE_EXPORT 1 +#endif + +/* nsh_catfile used by cat, ifconfig, ifup/down, df, free, env, irqinfo, and + * mount (with no arguments). + */ + +#if !defined(CONFIG_NSH_DISABLE_CAT) && !defined(CONFIG_NSH_DISABLE_IFCONFIG) && \ + !defined(CONFIG_NSH_DISABLE_IFUPDOWN) && !defined(CONFIG_NSH_DISABLE_DF) && \ + !defined(CONFIG_NSH_DISABLE_FREE) && !defined(CONFIG_NSH_DISABLE_ENV) && \ + !defined(HAVE_IRQINFO) && !defined(HAVE_MOUNT_LIST) +# undef NSH_HAVE_CATFILE +#endif + +/* nsh_readfile used by ps command */ + +#if defined(CONFIG_NSH_DISABLE_PS) +# undef NSH_HAVE_READFILE +#endif + +/* nsh_foreach_direntry used by the ls and ps commands */ + +#if defined(CONFIG_NSH_DISABLE_LS) && defined(CONFIG_NSH_DISABLE_PS) +# undef NSH_HAVE_FOREACH_DIRENTRY +#endif + +#if defined(CONFIG_NSH_DISABLE_CP) +# undef NSH_HAVE_TRIMDIR +#endif + +/* nsh_trimspaces used by the set and ps commands */ + +#if defined(CONFIG_NSH_DISABLE_SET) && defined(CONFIG_NSH_DISABLE_PS) +# undef NSH_HAVE_TRIMSPACES +#endif + +#ifndef CONFIG_NSH_DISABLESCRIPT +# define NSH_NP_SET_OPTIONS "ex" /* Maintain order see nsh_npflags_e */ +# define NSH_NP_SET_OPTIONS_INIT (NSH_PFLAG_SILENT) +#endif + +#if !defined(NSH_HAVE_VARS) && defined(CONFIG_NSH_DISABLESCRIPT) +# undef CONFIG_NSH_DISABLE_SET +# define CONFIG_NSH_DISABLE_SET 1 +# undef CONFIG_NSH_DISABLE_UNSET +# define CONFIG_NSH_DISABLE_UNSET 1 +#endif + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +#ifndef CONFIG_NSH_DISABLE_ITEF +/* State when parsing and if-then-else sequence */ + +enum nsh_itef_e +{ + NSH_ITEF_NORMAL = 0, /* Not in an if-then-else sequence */ + NSH_ITEF_IF, /* Just parsed 'if', expect condition */ + NSH_ITEF_THEN, /* Just parsed 'then', looking for 'else' or 'fi' */ + NSH_ITEF_ELSE /* Just parsed 'else', look for 'fi' */ +}; + +/* All state data for parsing one if-then-else sequence */ + +struct nsh_itef_s +{ + uint8_t ie_ifcond : 1; /* Value of command in 'if' statement */ + uint8_t ie_disabled : 1; /* TRUE: Unconditionally disabled */ + uint8_t ie_inverted : 1; /* TRUE: inverted logic ('if ! ') */ + uint8_t ie_unused : 3; + uint8_t ie_state : 2; /* If-then-else state (see enum nsh_itef_e) */ +}; +#endif + +#ifndef CONFIG_NSH_DISABLE_LOOPS +/* State when parsing and while-do-done or until-do-done sequence */ + +enum nsh_lp_e +{ + NSH_LOOP_NORMAL = 0, /* Not in a while-do-done or until-do-done sequence */ + NSH_LOOP_WHILE, /* Just parsed 'while', expect condition */ + NSH_LOOP_UNTIL, /* Just parsed 'until', expect condition */ + NSH_LOOP_DO /* Just parsed 'do', looking for 'done' */ +}; + +/* All state data for parsing one while-do-done or until-do-done sequence */ + +struct nsh_loop_s +{ + uint8_t lp_enable : 1; /* Loop command processing is enabled */ + uint8_t lp_unused : 5; + uint8_t lp_state : 2; /* Loop state (see enume nsh_lp_e) */ +#ifndef CONFIG_NSH_DISABLE_ITEF + uint8_t lp_iendx; /* Saved if-then-else-fi index */ +#endif + long lp_topoffs; /* Top of loop file offset */ +}; +#endif + +#ifndef CONFIG_NSH_DISABLESCRIPT +/* Define the bits that correspond to the option defined in + * NSH_NP_SET_OPTIONS. The bit value is 1 shifted left the offset + * of the char in NSH_NP_SET_OPTIONS string. + */ + +enum nsh_npflags_e +{ + NSH_PFLAG_IGNORE = 1, /* set for +e no exit on errors, + * cleared -e exit on error */ + NSH_PFLAG_SILENT = 2, /* cleared -x print a trace of commands + * when parsing. + * set +x no print a trace of commands */ +}; +#endif + +/* These structure provides the overall state of the parser */ + +struct nsh_parser_s +{ +#ifndef CONFIG_NSH_DISABLEBG + bool np_bg; /* true: The last command executed in background */ +#endif +#ifdef CONFIG_FILE_STREAM + bool np_redirect; /* true: Output from the last command was re-directed */ +#endif + bool np_fail; /* true: The last command failed */ +#ifndef CONFIG_NSH_DISABLESCRIPT + uint8_t np_flags; /* See nsh_npflags_e above */ +#endif +#ifndef CONFIG_NSH_DISABLEBG + int np_nice; /* "nice" value applied to last background cmd */ +#endif + +#ifndef CONFIG_NSH_DISABLESCRIPT + FILE *np_stream; /* Stream of current script */ +#ifndef CONFIG_NSH_DISABLE_LOOPS + long np_foffs; /* File offset to the beginning of a line */ +#ifndef NSH_DISABLE_SEMICOLON + uint16_t np_loffs; /* Byte offset to the beginning of a command */ + bool np_jump; /* "Jump" to the top of the loop */ +#endif + uint8_t np_lpndx; /* Current index into np_lpstate[] */ +#endif +#ifndef CONFIG_NSH_DISABLE_ITEF + uint8_t np_iendx; /* Current index into np_iestate[] */ +#endif + + /* This is a stack of parser state information. */ + +#ifndef CONFIG_NSH_DISABLE_ITEF + struct nsh_itef_s np_iestate[CONFIG_NSH_NESTDEPTH]; +#endif +#ifndef CONFIG_NSH_DISABLE_LOOPS + struct nsh_loop_s np_lpstate[CONFIG_NSH_NESTDEPTH]; +#endif +#endif +}; + +/* This is the general form of a command handler */ + +struct nsh_vtbl_s; /* Defined in nsh_console.h */ +typedef CODE int (*nsh_cmd_t)(FAR struct nsh_vtbl_s *vtbl, int argc, + FAR char **argv); + +/* This is the form of a callback from nsh_foreach_direntry() */ + +struct dirent; /* Defined in dirent.h */ +typedef CODE int (*nsh_direntry_handler_t)(FAR struct nsh_vtbl_s *vtbl, + FAR const char *dirpath, + FAR struct dirent *entryp, + FAR void *pvarg); + +#if defined(CONFIG_NSH_VARS) && !defined(CONFIG_NSH_DISABLE_SET) +/* Used with nsh_foreach_var() */ + +typedef int (*nsh_foreach_var_t)(FAR struct nsh_vtbl_s *vtbl, FAR void *arg, + FAR const char *pair); +#endif + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +extern const char g_nshgreeting[]; +#if defined(CONFIG_NSH_MOTD) && !defined(CONFIG_NSH_PLATFORM_MOTD) +extern const char g_nshmotd[]; +#endif +#ifdef CONFIG_NSH_LOGIN +#if defined(CONFIG_NSH_TELNET_LOGIN) && defined(CONFIG_NSH_TELNET) +extern const char g_telnetgreeting[]; +#endif +extern const char g_userprompt[]; +extern const char g_passwordprompt[]; +extern const char g_loginsuccess[]; +extern const char g_badcredentials[]; +extern const char g_loginfailure[]; +#endif +extern const char g_nshprompt[]; +extern const char g_fmtsyntax[]; +extern const char g_fmtargrequired[]; +extern const char g_fmtnomatching[]; +extern const char g_fmtarginvalid[]; +extern const char g_fmtargrange[]; +extern const char g_fmtcmdnotfound[]; +extern const char g_fmtnosuch[]; +extern const char g_fmttoomanyargs[]; +extern const char g_fmtdeepnesting[]; +extern const char g_fmtcontext[]; +extern const char g_fmtcmdfailed[]; +extern const char g_fmtcmdoutofmemory[]; +extern const char g_fmtinternalerror[]; +extern const char g_fmtsignalrecvd[]; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/* Initialization */ + +#ifdef CONFIG_NSH_ROMFSETC +int nsh_romfsetc(void); +#else +# define nsh_romfsetc() (-ENOSYS) +#endif + +#ifdef HAVE_USB_CONSOLE +int nsh_usbconsole(void); +#else +# define nsh_usbconsole() (-ENOSYS) +#endif + +#if defined(CONFIG_FILE_STREAM) && !defined(CONFIG_NSH_DISABLESCRIPT) +int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, + FAR const char *path); +#ifdef CONFIG_NSH_ROMFSETC +int nsh_initscript(FAR struct nsh_vtbl_s *vtbl); +#ifdef CONFIG_NSH_ROMFSRC +int nsh_loginscript(FAR struct nsh_vtbl_s *vtbl); +#endif +#endif +#endif + +/* Certain commands are only available if the boardctl() interface is + * available: + */ + +/* Architecture-specific initialization depends on boardctl(BOARDIOC_INIT) */ + +#if defined(CONFIG_NSH_ARCHINIT) && !defined(CONFIG_LIB_BOARDCTL) +# warning CONFIG_NSH_ARCHINIT is set, but CONFIG_LIB_BOARDCTL is not +# undef CONFIG_NSH_ARCHINIT +#endif + +/* The mkrd command depends on boardctl(BOARDIOC_MKRD) */ + +#if !defined(CONFIG_LIB_BOARDCTL) || !defined(CONFIG_BOARDCTL_MKRD) +# undef CONFIG_NSH_DISABLE_MKRD +# define CONFIG_NSH_DISABLE_MKRD 1 +#endif + +/* Basic session and message handling */ + +struct console_stdio_s; +int nsh_session(FAR struct console_stdio_s *pstate, + bool login, int argc, FAR char *argv[]); +int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline); + +/**************************************************************************** + * Name: nsh_login + * + * Description: + * Prompt the user for a username and password. Return a failure if valid + * credentials are not returned (after some retries. + * + ****************************************************************************/ + +#ifdef CONFIG_NSH_CONSOLE_LOGIN +int nsh_login(FAR struct console_stdio_s *pstate); +#endif + +#ifdef CONFIG_NSH_TELNET_LOGIN +int nsh_telnetlogin(FAR struct console_stdio_s *pstate); +#endif + +/* Application interface */ + +int nsh_command(FAR struct nsh_vtbl_s *vtbl, int argc, char *argv[]); + +#ifdef CONFIG_NSH_BUILTIN_APPS +int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, + FAR char **argv, FAR const char *redirfile, int oflags); +#endif + +#ifdef CONFIG_NSH_FILE_APPS +int nsh_fileapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, + FAR char **argv, FAR const char *redirfile, int oflags); +#endif + +#ifndef CONFIG_DISABLE_ENVIRON +/* Working directory support */ + +FAR const char *nsh_getcwd(void); +FAR char *nsh_getfullpath(FAR struct nsh_vtbl_s *vtbl, + FAR const char *relpath); +void nsh_freefullpath(FAR char *fullpath); +#endif + +/* Debug */ + +void nsh_dumpbuffer(FAR struct nsh_vtbl_s *vtbl, const char *msg, + const uint8_t *buffer, ssize_t nbytes); + +#ifdef CONFIG_NSH_USBDEV_TRACE +/* USB debug support */ + +void nsh_usbtrace(void); +#endif + +/* Shell command handlers */ + +#ifndef CONFIG_NSH_DISABLE_BASENAME + int cmd_basename(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_LOOPS) + int cmd_break(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#ifndef CONFIG_NSH_DISABLE_DIRNAME + int cmd_dirname(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#ifndef CONFIG_NSH_DISABLE_ECHO + int cmd_echo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#ifndef CONFIG_NSH_DISABLE_PRINTF + int cmd_printf(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#ifndef CONFIG_NSH_DISABLE_EXEC + int cmd_exec(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#ifndef CONFIG_NSH_DISABLE_EXPORT + int cmd_export(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#ifndef CONFIG_NSH_DISABLE_MB + int cmd_mb(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#ifndef CONFIG_NSH_DISABLE_MH + int cmd_mh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#ifndef CONFIG_NSH_DISABLE_MW + int cmd_mw(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#ifndef CONFIG_NSH_DISABLE_FREE + int cmd_free(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#ifndef CONFIG_NSH_DISABLE_TIME + int cmd_time(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#ifndef CONFIG_NSH_DISABLE_PS + int cmd_ps(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#ifndef CONFIG_NSH_DISABLE_XD + int cmd_xd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#if defined(CONFIG_MODULE) && !defined(CONFIG_NSH_DISABLE_MODCMDS) +int cmd_insmod(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +int cmd_rmmod(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE) +int cmd_lsmod(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#endif + +#ifdef HAVE_IRQINFO +int cmd_irqinfo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST) + int cmd_test(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); + int cmd_lbracket(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#ifndef CONFIG_NSH_DISABLE_DATE + int cmd_date(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#ifndef CONFIG_NSH_DISABLE_CAT + int cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#ifndef CONFIG_NSH_DISABLE_CP + int cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#ifndef CONFIG_NSH_DISABLE_CMP + int cmd_cmp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#ifndef CONFIG_NSH_DISABLE_DD + int cmd_dd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#ifndef CONFIG_NSH_DISABLE_HEXDUMP + int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#if !defined(CONFIG_NSH_DISABLE_LN) && defined(CONFIG_PSEUDOFS_SOFTLINKS) + int cmd_ln(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#ifndef CONFIG_NSH_DISABLE_LS + int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#if defined(CONFIG_RAMLOG_SYSLOG) && !defined(CONFIG_NSH_DISABLE_DMESG) + int cmd_dmesg(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#if !defined(CONFIG_NSH_DISABLE_READLINK) && defined(CONFIG_PSEUDOFS_SOFTLINKS) + int cmd_readlink(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#if defined(CONFIG_FILE_STREAM) && !defined(CONFIG_NSH_DISABLESCRIPT) +# ifndef CONFIG_NSH_DISABLE_SOURCE + int cmd_source(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +#endif /* CONFIG_FILE_STREAM && !CONFIG_NSH_DISABLESCRIPT */ + +#ifdef NSH_HAVE_DIROPTS +# ifndef CONFIG_NSH_DISABLE_MKDIR + int cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# ifndef CONFIG_NSH_DISABLE_MV + int cmd_mv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# ifndef CONFIG_NSH_DISABLE_RM + int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# ifndef CONFIG_NSH_DISABLE_RMDIR + int cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# endif /* NSH_HAVE_DIROPTS */ + +#ifndef CONFIG_DISABLE_MOUNTPOINT +# if defined(CONFIG_DEV_LOOP) && !defined(CONFIG_NSH_DISABLE_LOSETUP) + int cmd_losetup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# if defined(CONFIG_SMART_DEV_LOOP) && !defined(CONFIG_NSH_DISABLE_LOSMART) + int cmd_losmart(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# if defined(CONFIG_PIPES) && CONFIG_DEV_FIFO_SIZE > 0 && \ + !defined(CONFIG_NSH_DISABLE_MKFIFO) + int cmd_mkfifo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# ifdef NSH_HAVE_CATFILE +# ifndef CONFIG_NSH_DISABLE_DF + int cmd_df(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# ifndef CONFIG_NSH_DISABLE_MOUNT + int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# endif +# ifndef CONFIG_NSH_DISABLE_UMOUNT + int cmd_umount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# ifndef CONFIG_NSH_DISABLE_MKRD + int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# ifdef CONFIG_FSUTILS_MKFATFS +# ifndef CONFIG_NSH_DISABLE_MKFATFS + int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# endif /* CONFIG_FSUTILS_MKFATFS */ +# if defined(CONFIG_FS_SMARTFS) && defined(CONFIG_FSUTILS_MKSMARTFS) +# ifndef CONFIG_NSH_DISABLE_MKSMARTFS + int cmd_mksmartfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# endif /* CONFIG_FS_SMARTFS */ +# ifndef CONFIG_NSH_DISABLE_TRUNCATE + int cmd_truncate(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# if defined(CONFIG_NSH_LOGIN_PASSWD) && \ + !defined(CONFIG_FSUTILS_PASSWD_READONLY) +# ifndef CONFIG_NSH_DISABLE_USERADD + int cmd_useradd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# ifndef CONFIG_NSH_DISABLE_USERDEL + int cmd_userdel(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# ifndef CONFIG_NSH_DISABLE_PASSWD + int cmd_passwd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# endif +#endif /* !CONFIG_DISABLE_MOUNTPOINT */ + +#if !defined(CONFIG_DISABLE_ENVIRON) +# ifndef CONFIG_NSH_DISABLE_CD + int cmd_cd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# ifndef CONFIG_NSH_DISABLE_PWD + int cmd_pwd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +#endif /* !CONFIG_DISABLE_MOUNTPOINT */ + +#ifndef CONFIG_NSH_DISABLE_ENV + int cmd_env(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#if defined(CONFIG_NET) +# if defined(CONFIG_NET_ARP) && !defined(CONFIG_NSH_DISABLE_ARP) + int cmd_arp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# if defined(CONFIG_NET_ROUTE) && !defined(CONFIG_NSH_DISABLE_ADDROUTE) + int cmd_addroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# if defined(CONFIG_NET_ROUTE) && !defined(CONFIG_NSH_DISABLE_DELROUTE) + int cmd_delroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# ifdef CONFIG_NET_UDP +# ifndef CONFIG_NSH_DISABLE_GET + int cmd_get(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# endif +# ifndef CONFIG_NSH_DISABLE_IFCONFIG + int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# ifndef CONFIG_NSH_DISABLE_IFUPDOWN + int cmd_ifup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); + int cmd_ifdown(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_NFS) +# ifndef CONFIG_NSH_DISABLE_NFSMOUNT + int cmd_nfsmount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# endif +# ifdef CONFIG_NET_UDP +# ifndef CONFIG_NSH_DISABLE_PUT + int cmd_put(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# endif +# ifdef CONFIG_NET_TCP +# ifndef CONFIG_NSH_DISABLE_WGET + int cmd_wget(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# endif +# ifndef CONFIG_NSH_DISABLE_ROUTE + int cmd_route(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# if defined(CONFIG_NSH_TELNET) +# ifndef CONFIG_NSH_DISABLE_TELNETD + int cmd_telnetd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# endif +#endif /* CONFIG_NET */ + +#if defined(CONFIG_LIBC_NETDB) && !defined(CONFIG_NSH_DISABLE_NSLOOKUP) + int cmd_nslookup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#if defined(CONFIG_BOARDCTL_POWEROFF) && !defined(CONFIG_NSH_DISABLE_POWEROFF) + int cmd_poweroff(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#if defined(CONFIG_PM) && !defined(CONFIG_NSH_DISABLE_PMCONFIG) +int cmd_pmconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#if defined(CONFIG_BOARDCTL_RESET) && !defined(CONFIG_NSH_DISABLE_REBOOT) + int cmd_reboot(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN) + int cmd_rptun(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#if (defined(CONFIG_BOARDCTL_POWEROFF) || defined(CONFIG_BOARDCTL_RESET)) && \ + !defined(CONFIG_NSH_DISABLE_SHUTDOWN) + int cmd_shutdown(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#ifndef CONFIG_NSH_DISABLE_UNAME + int cmd_uname(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#ifndef CONFIG_NSH_DISABLE_SET + int cmd_set(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#ifndef CONFIG_NSH_DISABLE_UNSET + int cmd_unset(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#ifndef CONFIG_NSH_DISABLE_KILL + int cmd_kill(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#ifndef CONFIG_NSH_DISABLE_SLEEP + int cmd_sleep(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +#ifndef CONFIG_NSH_DISABLE_USLEEP + int cmd_usleep(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_BASE64) +# ifndef CONFIG_NSH_DISABLE_BASE64DEC + int cmd_base64decode(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# ifndef CONFIG_NSH_DISABLE_BASE64ENC + int cmd_base64encode(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +#endif + +#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_HASH_MD5) +# ifndef CONFIG_NSH_DISABLE_MD5 + int cmd_md5(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +#endif + +#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_URLCODE) +# ifndef CONFIG_NSH_DISABLE_URLDECODE + int cmd_urlencode(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# ifndef CONFIG_NSH_DISABLE_URLENCODE + int cmd_urldecode(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +#endif + +/**************************************************************************** + * Name: nsh_extmatch_count + * + * Description: + * This support function is used to provide support for realine tab- + * completion logic nsh_extmatch_count() counts the number of matching + * nsh command names + * + * Input Parameters: + * name - A point to the name containing the name to be matched. + * matches - A table is size CONFIG_READLINE_MAX_EXTCMDS that can + * be used to remember matching name indices. + * namelen - The length of the name to match + * + * Returned Values: + * The number commands that match to the first namelen characters. + * + ****************************************************************************/ + +#if defined(CONFIG_NSH_READLINE) && defined(CONFIG_READLINE_TABCOMPLETION) && \ + defined(CONFIG_READLINE_HAVE_EXTMATCH) +int nsh_extmatch_count(FAR char *name, FAR int *matches, int namelen); +#endif + +/**************************************************************************** + * Name: nsh_extmatch_getname + * + * Description: + * This support function is used to provide support for realine tab- + * completion logic nsh_extmatch_getname() will return the full command + * string from an index that was previously saved by nsh_exmatch_count(). + * + * Input Parameters: + * index - The index of the command name to be returned. + * + * Returned Values: + * The numb + * + ****************************************************************************/ + +#if defined(CONFIG_NSH_READLINE) && defined(CONFIG_READLINE_TABCOMPLETION) && \ + defined(CONFIG_READLINE_HAVE_EXTMATCH) +FAR const char *nsh_extmatch_getname(int index); +#endif + +/**************************************************************************** + * Name: nsh_catfile + * + * Description: + * Dump the contents of a file to the current NSH terminal. + * + * Input Paratemets: + * vtbl - The console vtable + * cmd - NSH command name to use in error reporting + * filepath - The full path to the file to be dumped + * + * Returned Value: + * Zero (OK) on success; -1 (ERROR) on failure. + * + ****************************************************************************/ + +#ifdef NSH_HAVE_CATFILE +int nsh_catfile(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, + FAR const char *filepath); +#endif + +/**************************************************************************** + * Name: nsh_readfile + * + * Description: + * Read a small file into a user-provided buffer. The data is assumed to + * be a string and is guaranteed to be NUL-termined. An error occurs if + * the file content (+terminator) will not fit into the provided 'buffer'. + * + * Input Parameters: + * vtbl - The console vtable + * cmd - NSH command name to use in error reporting + * filepath - The full path to the file to be read + * buffer - The user-provided buffer into which the file is read. + * buflen - The size of the user provided buffer + * + * Returned Value: + * Zero (OK) is returned on success; -1 (ERROR) is returned on any + * failure to read the fil into the buffer. + * + ****************************************************************************/ + +#ifdef NSH_HAVE_READFILE +int nsh_readfile(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, + FAR const char *filepath, FAR char *buffer, size_t buflen); +#endif + +/**************************************************************************** + * Name: nsh_foreach_direntry + * + * Description: + * Call the provided 'handler' for each entry found in the directory at + * 'dirpath'. + * + * Input Parameters + * vtbl - The console vtable + * cmd - NSH command name to use in error reporting + * dirpath - The full path to the directory to be traversed + * handler - The handler to be called for each entry of the directory + * pvarg - User provided argument to be passed to the 'handler' + * + * Returned Value: + * Zero (OK) returned on success; -1 (ERROR) returned on failure. + * + ****************************************************************************/ + +#ifdef NSH_HAVE_FOREACH_DIRENTRY +int nsh_foreach_direntry(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, + FAR const char *dirpath, + nsh_direntry_handler_t handler, void *pvarg); +#endif + +/**************************************************************************** + * Name: nsh_trimdir + * + * Description: + * Skip any trailing '/' characters (unless it is also the leading '/') + * + * Input Parameters: + * dirpath - The directory path to be trimmed. May be modified! + * + * Returned value: + * None + * + ****************************************************************************/ + +#ifdef NSH_HAVE_TRIMDIR +void nsh_trimdir(FAR char *dirpath); +#endif + +/**************************************************************************** + * Name: nsh_trimspaces + * + * Description: + * Trim any leading or trailing spaces from a string. + * + * Input Parameters: + * str - The string to be trimmed. May be modified! + * + * Returned value: + * The new string pointer. + * + ****************************************************************************/ + +#ifdef NSH_HAVE_TRIMSPACES +FAR char *nsh_trimspaces(FAR char *str); +#endif + +/**************************************************************************** + * Name: nsh_getvar, nsh_setvar, and nsh_setvar + * + * Description: + * Get, set, or unset an NSH variable. + * + * Input Parameters: + * vtbl - NSH session data + * name - The name of the variable to get or set + * value - The value to use with nsh_setvar() + * + * Returned value: + * nsh_getvar() returns a read-only reference to the variable value on + * success or NULL on failure. + * nset_unsetvar() returns OK on success or an negated errno value on + * failure. + * + ****************************************************************************/ + +#ifdef CONFIG_NSH_VARS +FAR char *nsh_getvar(FAR struct nsh_vtbl_s *vtbl, FAR const char *name); +#ifndef CONFIG_NSH_DISABLE_SET +int nsh_setvar(FAR struct nsh_vtbl_s *vtbl, FAR const char *name, + FAR const char *value); +#endif +#if !defined(CONFIG_NSH_DISABLE_UNSET) || !defined(CONFIG_NSH_DISABLE_EXPORT) +int nsh_unsetvar(FAR struct nsh_vtbl_s *vtbl, FAR const char *name); +#endif +#endif + +/**************************************************************************** + * Name: nsh_foreach_var + * + * Description: + * Visit each name-value pair in the environment. + * + * Input Parameters: + * vtbl - NSH session data + * cb - The callback function to be invoked for each environment + * variable. + * + * Returned Value: + * Zero if the all NSH variables have been traversed. A non-zero value + * means that the callback function requested early termination by + * returning a nonzero value. + * + ****************************************************************************/ + +#if defined(CONFIG_NSH_VARS) && !defined(CONFIG_NSH_DISABLE_SET) +int nsh_foreach_var(FAR struct nsh_vtbl_s *vtbl, nsh_foreach_var_t cb, + FAR void *arg); +#endif + +#if defined(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308) && !defined(CONFIG_NSH_DISABLE_PM1_0PS5308) + int cmd_Pm10Ps5308(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#if defined(CONFIG_APPLICATION_SENSOR_PM2_5_PS5308) && !defined(CONFIG_NSH_DISABLE_PM2_5PS5308) + int cmd_Pm25Ps5308(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#if defined(CONFIG_APPLICATION_SENSOR_PM10_PS5308) && !defined(CONFIG_NSH_DISABLE_PM10PS5308) + int cmd_Pm100Ps5308(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#if defined(CONFIG_APPLICATION_SENSOR_TEMPERATURE_HS300X) && !defined(CONFIG_NSH_DISABLE_TEMPHS300X) + int cmd_TempHs300x(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#if defined(CONFIG_APPLICATION_SENSOR_HUMIDITY_HS300X) && !defined(CONFIG_NSH_DISABLE_HUMIHS300X) + int cmd_HumiHs300x(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#endif /* __APPS_NSHLIB_NSH_H */ diff --git a/Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c b/Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c new file mode 100644 index 000000000..79538c1c5 --- /dev/null +++ b/Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c @@ -0,0 +1,128 @@ +/**************************************************************************** + * apps/nshlib/nsh_Applicationscmd.c + * + * Copyright (C) 2016 Alan Carvalho de Assis. All rights reserved. + * Author: Alan Carvalho de Assis + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "nsh.h" +#include "nsh_console.h" + +extern int FrameworkInit(void); + +/**************************************************************************** + * Name: cmd_Pm10Ps5308 + ****************************************************************************/ + +#if defined(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308) && !defined(CONFIG_NSH_DISABLE_PM1_0PS5308) +extern void Pm10Ps5308(void); +int cmd_Pm10Ps5308(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + printf("Hello, world!\n"); + FrameworkInit(); + Pm10Ps5308(); + return 0; +} +#endif + +/**************************************************************************** + * Name: cmd_Pm25Ps5308 + ****************************************************************************/ + +#if defined(CONFIG_APPLICATION_SENSOR_PM2_5_PS5308) && !defined(CONFIG_NSH_DISABLE_PM2_5PS5308) +extern void Pm25Ps5308(void); +int cmd_Pm25Ps5308(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + printf("Hello, world!\n"); + FrameworkInit(); + Pm25Ps5308(); + return 0; +} +#endif + +/**************************************************************************** + * Name: cmd_Pm10Ps5308 + ****************************************************************************/ + +#if defined(CONFIG_APPLICATION_SENSOR_PM10_PS5308) && !defined(CONFIG_NSH_DISABLE_PM10PS5308) +extern void Pm100Ps5308(void); +int cmd_Pm100Ps5308(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + printf("Hello, world!\n"); + FrameworkInit(); + Pm100Ps5308(); + return 0; +} +#endif + +/**************************************************************************** + * Name: cmd_TempHs300x + ****************************************************************************/ + +#if defined(CONFIG_APPLICATION_SENSOR_TEMPERATURE_HS300X) && !defined(CONFIG_NSH_DISABLE_TEMPHS300X) +extern void TempHs300x(void); +int cmd_TempHs300x(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + printf("Hello, world!\n"); + FrameworkInit(); + TempHs300x(); + return 0; +} +#endif + +/**************************************************************************** + * Name: cmd_HumiHs300x + ****************************************************************************/ + +#if defined(CONFIG_APPLICATION_SENSOR_HUMIDITY_HS300X) && !defined(CONFIG_NSH_DISABLE_HUMIHS300X) +extern void HumiHs300x(void); +int cmd_HumiHs300x(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + printf("Hello, world!\n"); + FrameworkInit(); + HumiHs300x(); + return 0; +} +#endif diff --git a/Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/nsh_command.c b/Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/nsh_command.c new file mode 100644 index 000000000..6156a40c8 --- /dev/null +++ b/Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/nsh_command.c @@ -0,0 +1,1153 @@ +/**************************************************************************** + * apps/nshlib/nsh_command.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#ifdef CONFIG_NSH_BUILTIN_APPS +# include +#endif + +#if defined(CONFIG_SYSTEM_READLINE) && defined(CONFIG_READLINE_HAVE_EXTMATCH) +# include "system/readline.h" +#endif + +#include "nsh.h" +#include "nsh_console.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Help command summary layout */ + +#define HELP_LINELEN 80 +#define NUM_CMDS ((sizeof(g_cmdmap)/sizeof(struct cmdmap_s)) - 1) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct cmdmap_s +{ + FAR const char *cmd; /* Name of the command */ + nsh_cmd_t handler; /* Function that handles the command */ + uint8_t minargs; /* Minimum number of arguments (including command) */ + uint8_t maxargs; /* Maximum number of arguments (including command) */ + FAR const char *usage; /* Usage instructions for 'help' command */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +#ifndef CONFIG_NSH_DISABLE_HELP +static int cmd_help(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#ifndef CONFIG_NSH_DISABLESCRIPT +static int cmd_true(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +static int cmd_false(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#ifndef CONFIG_NSH_DISABLE_EXIT +static int cmd_exit(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +static int cmd_unrecognized(FAR struct nsh_vtbl_s *vtbl, int argc, + char **argv); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct cmdmap_s g_cmdmap[] = +{ +#if defined(CONFIG_FILE_STREAM) && !defined(CONFIG_NSH_DISABLESCRIPT) +# ifndef CONFIG_NSH_DISABLE_SOURCE + { ".", cmd_source, 2, 2, "" }, +# endif +#endif + +#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST) + { "[", cmd_lbracket, 4, CONFIG_NSH_MAXARGUMENTS, " ]" }, +#endif + +#ifndef CONFIG_NSH_DISABLE_HELP + { "?", cmd_help, 1, 1, NULL }, +#endif + +#if defined(CONFIG_NET) && defined(CONFIG_NET_ROUTE) && !defined(CONFIG_NSH_DISABLE_ADDROUTE) + { "addroute", cmd_addroute, 3, 4, " [] " }, +#endif + +#if defined(CONFIG_NET) && defined(CONFIG_NET_ARP) && !defined(CONFIG_NSH_DISABLE_ARP) +#ifdef CONFIG_NETLINK_ROUTE + { "arp", cmd_arp, 2, 4, + "[-t|-a |-d |-s ]" }, +#else + { "arp", cmd_arp, 3, 4, + "[-a |-d |-s ]" }, +#endif +#endif + +#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_BASE64) +# ifndef CONFIG_NSH_DISABLE_BASE64DEC + { "base64dec", cmd_base64decode, 2, 4, "[-w] [-f] " }, +# endif +# ifndef CONFIG_NSH_DISABLE_BASE64ENC + { "base64enc", cmd_base64encode, 2, 4, "[-w] [-f] " }, +# endif +#endif + +#ifndef CONFIG_NSH_DISABLE_BASENAME + { "basename", cmd_basename, 2, 3, " []" }, +#endif + +#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_LOOPS) + { "break", cmd_break, 1, 1, NULL }, +#endif + +#ifndef CONFIG_NSH_DISABLE_CAT + { "cat", cmd_cat, 2, CONFIG_NSH_MAXARGUMENTS, + " [ [ ...]]" }, +#endif + +#ifndef CONFIG_DISABLE_ENVIRON +# ifndef CONFIG_NSH_DISABLE_CD + { "cd", cmd_cd, 1, 2, "[|-|~|..]" }, +# endif +#endif + +#ifndef CONFIG_NSH_DISABLE_CP + { "cp", cmd_cp, 3, 3, " " }, +#endif + +#ifndef CONFIG_NSH_DISABLE_CMP + { "cmp", cmd_cmp, 3, 3, " " }, +#endif + +#ifndef CONFIG_NSH_DISABLE_DIRNAME + { "dirname", cmd_dirname, 2, 2, "" }, +#endif + +#ifndef CONFIG_NSH_DISABLE_DATE + { "date", cmd_date, 1, 3, "[-s \"MMM DD HH:MM:SS YYYY\"]" }, +#endif + +#ifndef CONFIG_NSH_DISABLE_DD + { "dd", cmd_dd, 3, 6, + "if= of= [bs=] [count=] " + "[skip=]" }, +# endif + +#if defined(CONFIG_NET) && defined(CONFIG_NET_ROUTE) && !defined(CONFIG_NSH_DISABLE_DELROUTE) + { "delroute", cmd_delroute, 2, 3, " []" }, +#endif + +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && !defined(CONFIG_NSH_DISABLE_DF) +#ifdef NSH_HAVE_CATFILE +#if defined(HAVE_DF_HUMANREADBLE) && defined(HAVE_DF_BLOCKOUTPUT) + { "df", cmd_df, 1, 2, "[-h]" }, +#else + { "df", cmd_df, 1, 1, NULL }, +#endif +#endif +#endif + +#if defined(CONFIG_RAMLOG_SYSLOG) && !defined(CONFIG_NSH_DISABLE_DMESG) + { "dmesg", cmd_dmesg, 1, 1, NULL }, +#endif + +#ifndef CONFIG_NSH_DISABLE_ECHO +# ifndef CONFIG_DISABLE_ENVIRON + { "echo", cmd_echo, 1, CONFIG_NSH_MAXARGUMENTS, + "[-n] [ [...]]" }, +# else + { "echo", cmd_echo, 1, CONFIG_NSH_MAXARGUMENTS, + "[-n] [ [...]]" }, +# endif +#endif + +#ifndef CONFIG_NSH_DISABLE_ENV + { "env", cmd_env, 1, 1, NULL }, +#endif + +#ifndef CONFIG_NSH_DISABLE_EXEC + { "exec", cmd_exec, 2, 3, "" }, +#endif + +#ifndef CONFIG_NSH_DISABLE_EXIT + { "exit", cmd_exit, 1, 1, NULL }, +#endif + +#ifndef CONFIG_NSH_DISABLE_EXPORT + { "export", cmd_export, 2, 3, "[ []]" }, +#endif + +#ifndef CONFIG_NSH_DISABLESCRIPT + { "false", cmd_false, 1, 1, NULL }, +#endif + +#ifndef CONFIG_NSH_DISABLE_FREE + { "free", cmd_free, 1, 1, NULL }, +#endif + +#ifdef CONFIG_NET_UDP +# ifndef CONFIG_NSH_DISABLE_GET + { "get", cmd_get, 4, 7, + "[-b|-n] [-f ] -h " }, +# endif +#endif + +#ifndef CONFIG_NSH_DISABLE_HELP +# ifdef CONFIG_NSH_HELP_TERSE + { "help", cmd_help, 1, 2, "[]" }, +#else + { "help", cmd_help, 1, 3, "[-v] []" }, +# endif +#endif + +#ifndef CONFIG_NSH_DISABLE_HEXDUMP +#ifndef CONFIG_NSH_CMDOPT_HEXDUMP + { "hexdump", cmd_hexdump, 2, 2, "" }, +#else + { "hexdump", cmd_hexdump, 2, 4, + " [skip=] [count=]" }, +#endif +#endif + +#ifdef CONFIG_NET +# ifndef CONFIG_NSH_DISABLE_IFCONFIG + { "ifconfig", cmd_ifconfig, 1, 11, + "[interface [|dhcp]] [dr|gw|gateway ] " + "[netmask ] [dns ] [hw ]" }, +# endif +# ifndef CONFIG_NSH_DISABLE_IFUPDOWN + { "ifdown", cmd_ifdown, 2, 2, "" }, + { "ifup", cmd_ifup, 2, 2, "" }, +# endif +#endif + +#if defined(CONFIG_MODULE) && !defined(CONFIG_NSH_DISABLE_MODCMDS) + { "insmod", cmd_insmod, 3, 3, " " }, +#endif + +#ifdef HAVE_IRQINFO + { "irqinfo", cmd_irqinfo, 1, 1, NULL }, +#endif + +#ifndef CONFIG_NSH_DISABLE_KILL + { "kill", cmd_kill, 3, 3, "- " }, +#endif + +#ifndef CONFIG_DISABLE_MOUNTPOINT +# if defined(CONFIG_DEV_LOOP) && !defined(CONFIG_NSH_DISABLE_LOSETUP) + { "losetup", cmd_losetup, 3, 6, + "[-d ] | [[-o ] [-r] ]" }, +# endif +#endif + +#ifndef CONFIG_DISABLE_MOUNTPOINT +# if defined(CONFIG_SMART_DEV_LOOP) && !defined(CONFIG_NSH_DISABLE_LOSMART) + { "losmart", cmd_losmart, 2, 11, + "[-d ] | [[-m ] [-o ] [-e ] " + "[-s ] [-r] ]" }, +# endif +#endif + +#if !defined(CONFIG_NSH_DISABLE_LN) && defined(CONFIG_PSEUDOFS_SOFTLINKS) + { "ln", cmd_ln, 3, 4, "[-s] " }, +#endif + +#ifndef CONFIG_NSH_DISABLE_LS + { "ls", cmd_ls, 1, 5, "[-lRs] " }, +#endif + +#if defined(CONFIG_MODULE) && !defined(CONFIG_NSH_DISABLE_MODCMDS) +#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE) + { "lsmod", cmd_lsmod, 1, 1, NULL }, +#endif +#endif + +#ifndef CONFIG_NSH_DISABLE_MB + { "mb", cmd_mb, 2, 3, + "[=] []" }, +#endif + +#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_HASH_MD5) +# ifndef CONFIG_NSH_DISABLE_MD5 + { "md5", cmd_md5, 2, 3, "[-f] " }, +# endif +#endif + +#ifdef NSH_HAVE_DIROPTS +# ifndef CONFIG_NSH_DISABLE_MKDIR + { "mkdir", cmd_mkdir, 2, 2, "" }, +# endif +#endif + +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FSUTILS_MKFATFS) +# ifndef CONFIG_NSH_DISABLE_MKFATFS + { "mkfatfs", cmd_mkfatfs, 2, 6, + "[-F ] [-r ] " }, +# endif +#endif + +#ifndef CONFIG_DISABLE_MOUNTPOINT +# if defined(CONFIG_PIPES) && CONFIG_DEV_FIFO_SIZE > 0 && \ + !defined(CONFIG_NSH_DISABLE_MKFIFO) + { "mkfifo", cmd_mkfifo, 2, 2, "" }, +# endif +#endif + +#ifndef CONFIG_NSH_DISABLE_MKRD + { "mkrd", cmd_mkrd, 2, 6, + "[-m ] [-s ] " }, +#endif + +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_SMARTFS) && \ + defined(CONFIG_FSUTILS_MKSMARTFS) +# ifndef CONFIG_NSH_DISABLE_MKSMARTFS +# ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS + { "mksmartfs", cmd_mksmartfs, 2, 6, + "[-s ] [-f] []" }, +# else + { "mksmartfs", cmd_mksmartfs, 2, 5, "[-s ] [-f] " }, +# endif +# endif +#endif + +#ifndef CONFIG_NSH_DISABLE_MH + { "mh", cmd_mh, 2, 3, + "[=] []" }, +#endif + +#if !defined(CONFIG_DISABLE_MOUNTPOINT) +#ifndef CONFIG_NSH_DISABLE_MOUNT +#if defined(NSH_HAVE_CATFILE) && defined(HAVE_MOUNT_LIST) + { "mount", cmd_mount, 1, 7, + "[-t [-o ] [] ]" }, +#else + { "mount", cmd_mount, 4, 7, + "-t [-o ] [] " }, +#endif +#endif +#endif + +#ifdef NSH_HAVE_DIROPTS +# ifndef CONFIG_NSH_DISABLE_MV + { "mv", cmd_mv, 3, 3, " " }, +# endif +#endif + +#ifndef CONFIG_NSH_DISABLE_MW + { "mw", cmd_mw, 2, 3, + "[=] []" }, +#endif + +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_NET) && \ + defined(CONFIG_NFS) +# ifndef CONFIG_NSH_DISABLE_NFSMOUNT + { "nfsmount", cmd_nfsmount, 4, 5, + " [udp]" }, +# endif +#endif + +#if defined(CONFIG_LIBC_NETDB) && !defined(CONFIG_NSH_DISABLE_NSLOOKUP) + { "nslookup", cmd_nslookup, 2, 2, "" }, +#endif + +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && \ + defined(CONFIG_NSH_LOGIN_PASSWD) && \ + !defined(CONFIG_FSUTILS_PASSWD_READONLY) +# ifndef CONFIG_NSH_DISABLE_PASSWD + { "passwd", cmd_passwd, 3, 3, " " }, +# endif +#endif + +#if defined(CONFIG_PM) && !defined(CONFIG_NSH_DISABLE_PMCONFIG) + { "pmconfig", cmd_pmconfig, 1, 3, + "[stay|relax] [normal|idle|standby|sleep]" }, +#endif + +#if defined(CONFIG_BOARDCTL_POWEROFF) && !defined(CONFIG_NSH_DISABLE_POWEROFF) + { "poweroff", cmd_poweroff, 1, 2, NULL }, +#endif + +#ifndef CONFIG_NSH_DISABLE_PRINTF +# ifndef CONFIG_DISABLE_ENVIRON + { "printf", cmd_printf, 1, CONFIG_NSH_MAXARGUMENTS, + "[\\xNN] [\\n\\r\\t] [ [...]]" }, +# else + { "printf", cmd_printf, 1, CONFIG_NSH_MAXARGUMENTS, + "[\\xNN] [\\n\\r\\t] [ [...]]" }, +# endif +#endif + +#ifndef CONFIG_NSH_DISABLE_PS + { "ps", cmd_ps, 1, 1, NULL }, +#endif + +#ifdef CONFIG_NET_UDP +# ifndef CONFIG_NSH_DISABLE_PUT + { "put", cmd_put, 4, 7, + "[-b|-n] [-f ] -h " }, +# endif +#endif + +#ifndef CONFIG_DISABLE_ENVIRON +# ifndef CONFIG_NSH_DISABLE_PWD + { "pwd", cmd_pwd, 1, 1, NULL }, +# endif +#endif + +#if !defined(CONFIG_NSH_DISABLE_READLINK) && defined(CONFIG_PSEUDOFS_SOFTLINKS) + { "readlink", cmd_readlink, 2, 2, "" }, +#endif + +#if defined(CONFIG_BOARDCTL_RESET) && !defined(CONFIG_NSH_DISABLE_REBOOT) + { "reboot", cmd_reboot, 1, 2, NULL }, +#endif + +#ifdef NSH_HAVE_DIROPTS +# ifndef CONFIG_NSH_DISABLE_RM + { "rm", cmd_rm, 2, 2, "" }, +# endif +#endif + +#ifdef NSH_HAVE_DIROPTS +# ifndef CONFIG_NSH_DISABLE_RMDIR + { "rmdir", cmd_rmdir, 2, 2, "" }, +# endif +#endif + +#if defined(CONFIG_MODULE) && !defined(CONFIG_NSH_DISABLE_MODCMDS) + { "rmmod", cmd_rmmod, 2, 2, "" }, +#endif + +#ifndef CONFIG_NSH_DISABLE_ROUTE +#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6) + { "route", cmd_route, 2, 2, "ipv4|ipv6" }, +#elif defined(CONFIG_NET_IPv4) + { "route", cmd_route, 1, 2, "[ipv4]" }, +#elif defined(CONFIG_NET_IPv6) + { "route", cmd_route, 1, 2, "[ipv6]" }, +#endif +#endif + +#if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN) + { "rptun", cmd_rptun, 3, 3, "start|stop " }, +#endif + +#ifndef CONFIG_NSH_DISABLE_SET +#ifdef CONFIG_NSH_VARS +# if !defined(CONFIG_DISABLE_ENVIRON) && !defined(CONFIG_NSH_DISABLESCRIPT) + { "set", cmd_set, 1, 4, "[{+|-}{e|x|xe|ex}] [ ]" }, +# elif !defined(CONFIG_DISABLE_ENVIRON) && defined(CONFIG_NSH_DISABLESCRIPT) + { "set", cmd_set, 1, 3, "[ ]" }, +# elif defined(CONFIG_DISABLE_ENVIRON) && !defined(CONFIG_NSH_DISABLESCRIPT) + { "set", cmd_set, 1, 2, "[{+|-}{e|x|xe|ex}]" }, +# endif +#else +# if !defined(CONFIG_DISABLE_ENVIRON) && !defined(CONFIG_NSH_DISABLESCRIPT) + { "set", cmd_set, 2, 4, "[{+|-}{e|x|xe|ex}] [ ]" }, +# elif !defined(CONFIG_DISABLE_ENVIRON) && defined(CONFIG_NSH_DISABLESCRIPT) + { "set", cmd_set, 3, 3, " " }, +# elif defined(CONFIG_DISABLE_ENVIRON) && !defined(CONFIG_NSH_DISABLESCRIPT) + { "set", cmd_set, 2, 2, "{+|-}{e|x|xe|ex}" }, +# endif +#endif +#endif /* CONFIG_NSH_DISABLE_SET */ + +#ifndef CONFIG_NSH_DISABLE_SHUTDOWN +#if defined(CONFIG_BOARDCTL_POWEROFF) && defined(CONFIG_BOARDCTL_RESET) + { "shutdown", cmd_shutdown, 1, 2, "[--reboot]" }, +#elif defined(CONFIG_BOARDCTL_POWEROFF) + { "shutdown", cmd_shutdown, 1, 1, NULL }, +#elif defined(CONFIG_BOARDCTL_RESET) + { "shutdown", cmd_shutdown, 2, 2, "--reboot" }, +#endif +#endif + +#ifndef CONFIG_NSH_DISABLE_SLEEP + { "sleep", cmd_sleep, 2, 2, "" }, +#endif + +#if defined(CONFIG_FILE_STREAM) && !defined(CONFIG_NSH_DISABLESCRIPT) +# ifndef CONFIG_NSH_DISABLE_SOURCE + { "source", cmd_source, 2, 2, "" }, +# endif +#endif + +#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST) + { "test", cmd_test, 3, CONFIG_NSH_MAXARGUMENTS, "" }, +#endif + +#if defined(CONFIG_NSH_TELNET) && !defined(CONFIG_NSH_DISABLE_TELNETD) +#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6) + {"telnetd", cmd_telnetd, 2, 2, "[ipv4|ipv6]" }, +#else + {"telnetd", cmd_telnetd, 1, 1, NULL }, +#endif +#endif + +#ifndef CONFIG_NSH_DISABLE_TIME + { "time", cmd_time, 2, 2, "\"\"" }, +#endif + +#ifndef CONFIG_NSH_DISABLESCRIPT + { "true", cmd_true, 1, 1, NULL }, +#endif + +#ifndef CONFIG_DISABLE_MOUNTPOINT +# ifndef CONFIG_NSH_DISABLE_TRUNCATE + { "truncate", cmd_truncate, 4, 4, "-s " }, +# endif +#endif + +#ifndef CONFIG_NSH_DISABLE_UNAME +#ifdef CONFIG_NET + { "uname", cmd_uname, 1, 7, "[-a | -imnoprsv]" }, +#else + { "uname", cmd_uname, 1, 7, "[-a | -imoprsv]" }, +#endif +#endif + +#if !defined(CONFIG_DISABLE_MOUNTPOINT) +# ifndef CONFIG_NSH_DISABLE_UMOUNT + { "umount", cmd_umount, 2, 2, "" }, +# endif +#endif + +#ifndef CONFIG_NSH_DISABLE_UNSET + { "unset", cmd_unset, 2, 2, "" }, +#endif + +#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_URLCODE) +# ifndef CONFIG_NSH_DISABLE_URLDECODE + { "urldecode", cmd_urldecode, 2, 3, "[-f] " }, +# endif +# ifndef CONFIG_NSH_DISABLE_URLENCODE + { "urlencode", cmd_urlencode, 2, 3, "[-f] " }, +# endif +#endif + +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && \ + defined(CONFIG_NSH_LOGIN_PASSWD) && \ + !defined(CONFIG_FSUTILS_PASSWD_READONLY) +# ifndef CONFIG_NSH_DISABLE_USERADD + { "useradd", cmd_useradd, 3, 3, " " }, +# endif +# ifndef CONFIG_NSH_DISABLE_USERDEL + { "userdel", cmd_userdel, 2, 2, "" }, +# endif +#endif + +#ifndef CONFIG_NSH_DISABLE_USLEEP + { "usleep", cmd_usleep, 2, 2, "" }, +#endif + +#ifdef CONFIG_NET_TCP +# ifndef CONFIG_NSH_DISABLE_WGET + { "wget", cmd_wget, 2, 4, "[-o ] " }, +# endif +#endif + +#ifndef CONFIG_NSH_DISABLE_XD + { "xd", cmd_xd, 3, 3, " " }, +#endif + +#if defined(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308) && !defined(CONFIG_NSH_DISABLE_PM1_0PS5308) + { "pm1.0", cmd_Pm10Ps5308, 1, 1, "[get pm1.0 with sensor Ps5308]" }, +#endif + +#if defined(CONFIG_APPLICATION_SENSOR_PM2_5_PS5308) && !defined(CONFIG_NSH_DISABLE_PM2_5PS5308) + { "pm2.5", cmd_Pm25Ps5308, 1, 1, "[get pm2.5with sensor Ps5308]" }, +#endif + +#if defined(CONFIG_APPLICATION_SENSOR_PM10_PS5308) && !defined(CONFIG_NSH_DISABLE_PM10PS5308) + { "pm10", cmd_Pm100Ps5308, 1, 1, "[get pm10 with sensor Ps5308]" }, +#endif + +#if defined(CONFIG_APPLICATION_SENSOR_TEMPERATURE_HS300X) && !defined(CONFIG_NSH_DISABLE_TEMPHS300X) + { "temp", cmd_TempHs300x, 1, 1, "[Get humidity with sensor HS300x]" }, +#endif + +#if defined(CONFIG_APPLICATION_SENSOR_HUMIDITY_HS300X) && !defined(CONFIG_NSH_DISABLE_HUMIHS300X) + { "humi", cmd_HumiHs300x, 1, 1, "[Get temperature with sensor HS300x]" }, +#endif + + { NULL, NULL, 1, 1, NULL } +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: help_cmdlist + ****************************************************************************/ + +#ifndef CONFIG_NSH_DISABLE_HELP +static inline void help_cmdlist(FAR struct nsh_vtbl_s *vtbl) +{ + unsigned int colwidth; + unsigned int cmdwidth; + unsigned int cmdsperline; + unsigned int ncmdrows; + unsigned int i; + unsigned int j; + unsigned int k; + + /* Pick an optimal column width */ + + for (k = 0, colwidth = 0; k < NUM_CMDS; k++) + { + cmdwidth = strlen(g_cmdmap[k].cmd); + if (cmdwidth > colwidth) + { + colwidth = cmdwidth; + } + } + + colwidth += 2; + + /* Determine the number of commands to put on one line */ + + if (colwidth > HELP_LINELEN) + { + cmdsperline = 1; + } + else + { + cmdsperline = HELP_LINELEN / colwidth; + } + + /* Determine the total number of lines to output */ + + ncmdrows = (NUM_CMDS + (cmdsperline - 1)) / cmdsperline; + + /* Print the command name in 'ncmdrows' rows with 'cmdsperline' commands + * on each line. + */ + + for (i = 0; i < ncmdrows; i++) + { + nsh_output(vtbl, " "); + for (j = 0, k = i; + j < cmdsperline && k < NUM_CMDS; + j++, k += ncmdrows) + { + nsh_output(vtbl, "%s", g_cmdmap[k].cmd); + + for (cmdwidth = strlen(g_cmdmap[k].cmd); + cmdwidth < colwidth; + cmdwidth++) + { + nsh_output(vtbl, " "); + } + } + + nsh_output(vtbl, "\n"); + } +} +#endif + +/**************************************************************************** + * Name: help_usage + ****************************************************************************/ + +#if !defined(CONFIG_NSH_DISABLE_HELP) && !defined(CONFIG_NSH_HELP_TERSE) +static inline void help_usage(FAR struct nsh_vtbl_s *vtbl) +{ + nsh_output(vtbl, "NSH command forms:\n"); +#ifndef CONFIG_NSH_DISABLEBG + nsh_output(vtbl, " [nice [-d >]] " + "[> |>> ] [&]\n\n"); +#else + nsh_output(vtbl, " [> |>> ]\n\n"); +#endif +#ifndef CONFIG_NSH_DISABLESCRIPT +#ifndef CONFIG_NSH_DISABLE_ITEF + nsh_output(vtbl, "OR\n"); + nsh_output(vtbl, " if \n"); + nsh_output(vtbl, " then\n"); + nsh_output(vtbl, " [sequence of ]\n"); + nsh_output(vtbl, " else\n"); + nsh_output(vtbl, " [sequence of ]\n"); + nsh_output(vtbl, " fi\n\n"); +#endif +#ifndef CONFIG_NSH_DISABLE_LOOPS + nsh_output(vtbl, "OR\n"); + nsh_output(vtbl, " while \n"); + nsh_output(vtbl, " do\n"); + nsh_output(vtbl, " [sequence of ]\n"); + nsh_output(vtbl, " done\n\n"); + nsh_output(vtbl, "OR\n"); + nsh_output(vtbl, " until \n"); + nsh_output(vtbl, " do\n"); + nsh_output(vtbl, " [sequence of ]\n"); + nsh_output(vtbl, " done\n\n"); +#endif +#endif +} +#endif + +/**************************************************************************** + * Name: help_showcmd + ****************************************************************************/ + +#ifndef CONFIG_NSH_DISABLE_HELP +static void help_showcmd(FAR struct nsh_vtbl_s *vtbl, + FAR const struct cmdmap_s *cmdmap) +{ + if (cmdmap->usage) + { + nsh_output(vtbl, " %s %s\n", cmdmap->cmd, cmdmap->usage); + } + else + { + nsh_output(vtbl, " %s\n", cmdmap->cmd); + } +} +#endif + +/**************************************************************************** + * Name: help_cmd + ****************************************************************************/ + +#ifndef CONFIG_NSH_DISABLE_HELP +static int help_cmd(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd) +{ + FAR const struct cmdmap_s *cmdmap; + + /* Find the command in the command table */ + + for (cmdmap = g_cmdmap; cmdmap->cmd; cmdmap++) + { + /* Is this the one we are looking for? */ + + if (strcmp(cmdmap->cmd, cmd) == 0) + { + /* Yes... show it */ + + nsh_output(vtbl, "%s usage:", cmd); + help_showcmd(vtbl, cmdmap); + return OK; + } + } + + nsh_error(vtbl, g_fmtcmdnotfound, cmd); + return ERROR; +} +#endif + +/**************************************************************************** + * Name: help_allcmds + ****************************************************************************/ + +#if !defined(CONFIG_NSH_DISABLE_HELP) && !defined(CONFIG_NSH_HELP_TERSE) +static inline void help_allcmds(FAR struct nsh_vtbl_s *vtbl) +{ + FAR const struct cmdmap_s *cmdmap; + + /* Show all of the commands in the command table */ + + for (cmdmap = g_cmdmap; cmdmap->cmd; cmdmap++) + { + help_showcmd(vtbl, cmdmap); + } +} +#endif + +/**************************************************************************** + * Name: help_builtins + ****************************************************************************/ + +#ifndef CONFIG_NSH_DISABLE_HELP +static inline void help_builtins(FAR struct nsh_vtbl_s *vtbl) +{ +#ifdef CONFIG_NSH_BUILTIN_APPS + FAR const struct builtin_s *builtin; + unsigned int builtins_per_line; + unsigned int num_builtin_rows; + unsigned int builtin_width; + unsigned int num_builtins; + unsigned int column_width; + unsigned int i; + unsigned int j; + unsigned int k; + + /* Count the number of built-in commands and get the optimal column width */ + + num_builtins = 0; + column_width = 0; + + for (i = 0; (builtin = builtin_for_index(i)) != NULL; i++) + { + if (builtin->main == NULL) + { + continue; + } + + num_builtins++; + + builtin_width = strlen(builtin->name); + if (builtin_width > column_width) + { + column_width = builtin_width; + } + } + + /* Skip the printing if no available built-in commands */ + + if (num_builtins == 0) + { + return; + } + + column_width += 2; + + /* Determine the number of commands to put on one line */ + + if (column_width > HELP_LINELEN) + { + builtins_per_line = 1; + } + else + { + builtins_per_line = HELP_LINELEN / column_width; + } + + /* Determine the total number of lines to output */ + + num_builtin_rows = ((num_builtins + (builtins_per_line - 1)) / + builtins_per_line); + + /* List the set of available built-in commands */ + + nsh_output(vtbl, "\nBuiltin Apps:\n"); + for (i = 0; i < num_builtin_rows; i++) + { + nsh_output(vtbl, " "); + for (j = 0, k = i; + j < builtins_per_line && + (builtin = builtin_for_index(k)); + j++, k += num_builtin_rows) + { + if (builtin->main == NULL) + { + continue; + } + + nsh_output(vtbl, "%s", builtin->name); + + for (builtin_width = strlen(builtin->name); + builtin_width < column_width; + builtin_width++) + { + nsh_output(vtbl, " "); + } + } + + nsh_output(vtbl, "\n"); + } +#endif +} +#endif + +/**************************************************************************** + * Name: cmd_help + ****************************************************************************/ + +#ifndef CONFIG_NSH_DISABLE_HELP +static int cmd_help(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + FAR const char *cmd = NULL; +#ifndef CONFIG_NSH_HELP_TERSE + bool verbose = false; + int i; +#endif + + /* The command may be followed by a verbose option */ + +#ifndef CONFIG_NSH_HELP_TERSE + i = 1; + if (argc > i) + { + if (strcmp(argv[i], "-v") == 0) + { + verbose = true; + i++; + } + } + + /* The command line may end with a command name */ + + if (argc > i) + { + cmd = argv[i]; + } + + /* Show the generic usage if verbose is requested */ + + if (verbose) + { + help_usage(vtbl); + } +#else + if (argc > 1) + { + cmd = argv[1]; + } +#endif + + /* Are we showing help on a single command? */ + + if (cmd) + { + /* Yes.. show the single command */ + + help_cmd(vtbl, cmd); + } + else + { + /* In verbose mode, show detailed help for all commands */ + +#ifndef CONFIG_NSH_HELP_TERSE + if (verbose) + { + nsh_output(vtbl, "Where is one of:\n"); + help_allcmds(vtbl); + } + + /* Otherwise, just show the list of command names */ + + else +#endif + { + help_cmd(vtbl, "help"); + nsh_output(vtbl, "\n"); + help_cmdlist(vtbl); + } + + /* And show the list of built-in applications */ + + help_builtins(vtbl); + } + + return OK; +} +#endif + +/**************************************************************************** + * Name: cmd_unrecognized + ****************************************************************************/ + +static int cmd_unrecognized(FAR struct nsh_vtbl_s *vtbl, int argc, + char **argv) +{ + nsh_error(vtbl, g_fmtcmdnotfound, argv[0]); + return ERROR; +} + +/**************************************************************************** + * Name: cmd_true + ****************************************************************************/ + +#ifndef CONFIG_NSH_DISABLESCRIPT +static int cmd_true(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + return OK; +} + +#endif + +/**************************************************************************** + * Name: cmd_false + ****************************************************************************/ + +#ifndef CONFIG_NSH_DISABLESCRIPT +static int cmd_false(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + return ERROR; +} +#endif + +/**************************************************************************** + * Name: cmd_exit + ****************************************************************************/ + +#ifndef CONFIG_NSH_DISABLE_EXIT +static int cmd_exit(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + nsh_exit(vtbl, 0); + return OK; +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nsh_command + * + * Description: + * Execute the command in argv[0] + * + * Returned Value: + * -1 (ERROR) if the command was unsuccessful + * 0 (OK) if the command was successful + * + ****************************************************************************/ + +int nsh_command(FAR struct nsh_vtbl_s *vtbl, int argc, char *argv[]) +{ + const struct cmdmap_s *cmdmap; + const char *cmd; + nsh_cmd_t handler = cmd_unrecognized; + int ret; + + /* The form of argv is: + * + * argv[0]: The command name. This is argv[0] when the arguments + * are, finally, received by the command vtblr + * argv[1]: The beginning of argument (up to CONFIG_NSH_MAXARGUMENTS) + * argv[argc]: NULL terminating pointer + */ + + cmd = argv[0]; + + /* See if the command is one that we understand */ + + for (cmdmap = g_cmdmap; cmdmap->cmd; cmdmap++) + { + if (strcmp(cmdmap->cmd, cmd) == 0) + { + /* Check if a valid number of arguments was provided. We + * do this simple, imperfect checking here so that it does + * not have to be performed in each command. + */ + + if (argc < cmdmap->minargs) + { + /* Fewer than the minimum number were provided */ + + nsh_error(vtbl, g_fmtargrequired, cmd); + return ERROR; + } + else if (argc > cmdmap->maxargs) + { + /* More than the maximum number were provided */ + + nsh_error(vtbl, g_fmttoomanyargs, cmd); + return ERROR; + } + else + { + /* A valid number of arguments were provided (this does + * not mean they are right). + */ + + handler = cmdmap->handler; + break; + } + } + } + + ret = handler(vtbl, argc, argv); + return ret; +} + +/**************************************************************************** + * Name: nsh_extmatch_count + * + * Description: + * This support function is used to provide support for realine tab- + * completion logic nsh_extmatch_count() counts the number of matching + * nsh command names + * + * Input Parameters: + * name - A point to the name containing the name to be matched. + * matches - A table is size CONFIG_READLINE_MAX_EXTCMDS that can + * be used to remember matching name indices. + * namelen - The length of the name to match + * + * Returned Values: + * The number commands that match to the first namelen characters. + * + ****************************************************************************/ + +#if defined(CONFIG_NSH_READLINE) && defined(CONFIG_READLINE_TABCOMPLETION) && \ + defined(CONFIG_READLINE_HAVE_EXTMATCH) +int nsh_extmatch_count(FAR char *name, FAR int *matches, int namelen) +{ + int nr_matches = 0; + int i; + + for (i = 0; i < NUM_CMDS; i++) + { + if (strncmp(name, g_cmdmap[i].cmd, namelen) == 0) + { + matches[nr_matches] = i; + nr_matches++; + + if (nr_matches >= CONFIG_READLINE_MAX_EXTCMDS) + { + break; + } + } + } + + return nr_matches; +} +#endif + +/**************************************************************************** + * Name: nsh_extmatch_getname + * + * Description: + * This support function is used to provide support for realine tab- + * completion logic nsh_extmatch_getname() will return the full command + * string from an index that was previously saved by nsh_exmatch_count(). + * + * Input Parameters: + * index - The index of the command name to be returned. + * + * Returned Values: + * The numb + * + ****************************************************************************/ + +#if defined(CONFIG_NSH_READLINE) && defined(CONFIG_READLINE_TABCOMPLETION) && \ + defined(CONFIG_READLINE_HAVE_EXTMATCH) +FAR const char *nsh_extmatch_getname(int index) +{ + DEBUGASSERT(index > 0 && index <= NUM_CMDS); + return g_cmdmap[index].cmd; +} +#endif diff --git a/Ubiquitous/Nuttx/app_match_nuttx/build.sh b/Ubiquitous/Nuttx/app_match_nuttx/build.sh new file mode 100644 index 000000000..78545b89f --- /dev/null +++ b/Ubiquitous/Nuttx/app_match_nuttx/build.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +export current=$(pwd) +export nuttx=$current/.. +export top=$current/../../.. + +chmod -R +x $top +find $top -name Kconfig -exec dos2unix -q {} \; + +cp -rf $current/nuttx $nuttx +cp -rf $current/apps $nuttx + +cd ../nuttx diff --git a/Ubiquitous/Nuttx/app_match_nuttx/nuttx/Kconfig b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/Kconfig new file mode 100644 index 000000000..8fa8ef0ed --- /dev/null +++ b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/Kconfig @@ -0,0 +1,1911 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +mainmenu "NuttX/$ARCH Configuration" + +config APPSDIR + string + option env="APPSDIR" + +menu "XIUOS features" + +source "$APPSDIR/../../../APP_Framework/Kconfig" + +endmenu + +menu "Build Setup" + +config EXPERIMENTAL + bool "Prompt for development and/or incomplete code/drivers" + +config DEFAULT_SMALL + bool "Default to smallest size" + default n + ---help--- + When options are present, the default value for certain options will + be the one the results in the smallest size (at a loss of features). + The default is a fuller feature set at a larger size. + + NOTE: This option does not prevent you from overriding the default + to select another alternative. Nor does it affect the settings that + have already been selected in your configuration file. This applies + only to new settings that require a default value. + +choice + prompt "Build Host Platform" + default HOST_LINUX + +config HOST_LINUX + bool "Linux" + +config HOST_MACOS + bool "macOS" + +config HOST_WINDOWS + bool "Windows" + +config HOST_OTHER + bool "Other" + +endchoice + +config TOOLCHAIN_WINDOWS + bool + default n + depends on HOST_WINDOWS + ---help--- + Selected internally if the selected Windows environment is compatible + with the use of Windows native toolchains. + +config CYGWIN_WINTOOL + bool + default n + depends on WINDOWS_CYGWIN + ---help--- + Selected internally if Cygwin environment with the use of Windows + native toolchains. + +choice + prompt "Windows Build Environment" + default WINDOWS_CYGWIN + depends on HOST_WINDOWS + +config WINDOWS_NATIVE + bool "Windows Native" + select TOOLCHAIN_WINDOWS + depends on EXPERIMENTAL + ---help--- + Build natively in a CMD.exe environment with Windows style paths + (like C:\cygwin\home) + + The Windows native build is complete and available, but not often + used or verified. As a consequence, it cannot be assured to be + fully functional at any given time. Hence, it is marked here as + EXPERIMENTAL so that the end user will be aware of this state. + +config WINDOWS_CYGWIN + bool "Cygwin" + select TOOLCHAIN_WINDOWS + ---help--- + Build natively in a Cygwin environment with POSIX style paths (like + /cygdrive/c/Program Files) + +config WINDOWS_MSYS + bool "MSYS or MSYS2" + select TOOLCHAIN_WINDOWS + ---help--- + Build natively in a Cygwin environment with POSIX style paths (like + /cygdrive/c/cygwin/home) + +config WINDOWS_OTHER + bool "Windows POSIX-like environment" + select TOOLCHAIN_WINDOWS + ---help--- + Build natively in another POSIX-like environment. Additional + support may be necessary + +endchoice + +config WINDOWS_MKLINK + bool "Use mklink" + default n + depends on WINDOWS_NATIVE + ---help--- + Use the mklink command to set up symbolic links when NuttX is + configured. Otherwise, configuration directories will be copied to + establish the configuration. + + If directories are copied, then some confusion can result ("Which + version of the file did I modify?"). In that case, it is recommended + that you re-build using 'make clean_context all'. That will cause the + configured directories to be recopied on each build. + + NOTE: This option also (1) that you have administrator privileges, (2) + that you are using Windows 2000 or better, and (3) that you are using + the NTFS file system. Select 'n' is that is not the case. + +menu "Build Configuration" + +config APPS_DIR + string "Application directory" + default "../apps" if !WINDOWS_NATIVE + default "..\apps" if WINDOWS_NATIVE + ---help--- + Identifies the directory that builds the + application to link with NuttX. Default: ../apps This symbol must + be assigned to the path to the application build directory + *relative* to the NuttX top build directory. If you had an + application directory and the NuttX directory each in separate + directory trees like this: + + build + |-nuttx + | | + | `- Makefile + `-application + | + `- Makefile + + Then you would set APPS_DIR=../application. + + The application direction must contain Makefile and this make + file must support the following targets: + + 1)libapps$(LIBEXT) (usually libapps.a). libapps.a is a static + library ( an archive) that contains all of application object + files. + + 2)clean. Do whatever is appropriate to clean the application + directories for a fresh build. + + 3)distclean. Clean everything -- auto-generated files, symbolic + links etc. -- so that the directory contents are the same as + the contents in your configuration management system. + This is only done when you change the NuttX configuration. + + 4)depend. Make or update the application build dependencies. + + When this application is invoked it will receive the setting TOPDIR like: + + $(MAKE) -C $(CONFIG_APPS_DIR) TOPDIR="$(TOPDIR)" + + TOPDIR is the full path to the NuttX directory. It can be used, for + example, to include makefile fragments (e.g., .config or Make.defs) + or to set up include file paths. + +config BUILD_LOADABLE + bool + option modules + ---help--- + Automatically selected if KERNEL build is selected. + This selection only effects the behavior of the 'make export' + target and currently has no effect unless you wish to build + loadable applications in a FLAT build. + +choice + prompt "Memory organization" + default BUILD_FLAT + +config BUILD_FLAT + bool "Flat address space" + ---help--- + Build NuttX as one large, executable "blob". All of the code + within the blob can interrupt with all of the other code within + the blob. There are no special privileges, protections, or + restraints. + +config BUILD_PROTECTED + bool "NuttX protected build" + depends on ARCH_USE_MPU + select LIB_SYSCALL + select BUILD_2PASS + ---help--- + Builds NuttX and selected applications as two "blobs": A protected, + privileged kernel blob and a separate unprivileged, user blob. This + requires use of the two pass build with each blob being build on + each pass. + + NOTE: This build configuration requires that the platform support + a memory protection unit (MPU). Support, however, may not be + implemented on all platforms. + +config BUILD_KERNEL + bool "NuttX kernel build" + depends on ARCH_USE_MMU && ARCH_ADDRENV + select BUILD_LOADABLE + select LIB_SYSCALL + ---help--- + Builds NuttX as a separately compiled kernel. No applications are + built. All user applications must reside in a file system where + they can be loaded into memory for execution. + + NOTE: This build configuration requires that the platform support + a memory management unit (MMU) and address environments. Support, + however, may not be implemented on all platforms. + +endchoice # Build configuration + +config BUILD_2PASS + bool "Two pass build" + default n + ---help--- + Enables the two pass build options. + + Two-pass build options. If the 2 pass build option is selected, then these + options configure the make system build a extra link object. This link object + is assumed to be an incremental (relative) link object, but could be a static + library (archive) (some modification to this Makefile would be required if + PASS1_TARGET generates an archive). Pass 1 1ncremental (relative) link + objects should be put into the processor-specific source directory (where other + link objects will be created). If the pass1 object is an archive, it could + go anywhere. + +if BUILD_2PASS + +config PASS1_TARGET + string "Pass one target" + default "all" + ---help--- + The name of the first pass build target. This + can be specific build target, a special build target (all, default, etc.) + or may just be left undefined. + +config PASS1_BUILDIR + string "Pass one build directory" + default "build" + ---help--- + The path, relative to the top NuttX build + directory to directory that contains the Makefile to build the + first pass object. The Makefile must support the following targets: + The special target PASS1_TARGET (if defined) + and the usual depend, clean, and distclean targets. + +config PASS1_OBJECT + string "Pass one object" + default "" + ---help--- + May be used to include an extra, pass1 object + into the final link. This would probably be the object generated + from the PASS1_TARGET. It may be available at link time + in the arch//src directory. + +config NUTTX_USERSPACE + hex "Beginning of user-space blob" + default 0x0 + depends on BUILD_PROTECTED + ---help--- + In the kernel build, the NuttX kernel and the user-space blob are + built separately linked objects. NUTTX_USERSPACE provides the + address where the user-space blob is loaded into memory. NuttX will + expect to find and instance of struct userspace_s at this location. + +endif # Build 2-pass +endmenu # Build Setup + +menu "Binary Output Formats" + +config INTELHEX_BINARY + bool "Intel HEX binary format" + default n + ---help--- + Create the nuttx.hex in the Intel HEX binary format that is + used with many different loaders. This option will use the GNU objcopy + program and should not be selected if you are not using the GNU + toolchain. + +config MOTOROLA_SREC + bool "Motorola S-Record binary format" + default n + ---help--- + Create the nuttx.srec in the Motorola S-Record binary format that is + used with many different loaders. This option will use the GNU objcopy + program and should not be selected if you are not using the GNU + toolchain. + +config RAW_BINARY + bool "Raw binary format" + default n + ---help--- + Create the nuttx.bin in the raw binary format that is used with many + different loaders using the GNU objcopy program. This option + should not be selected if you are not using the GNU toolchain. + +menuconfig UBOOT_UIMAGE + bool "U-Boot uImage" + select RAW_BINARY + depends on !WINDOWS_NATIVE + ---help--- + Create the uImage binary used with U-Boot. + +if UBOOT_UIMAGE + +config UIMAGE_LOAD_ADDRESS + hex "uImage load address" + default 0x0 + +config UIMAGE_ENTRY_POINT + hex "uImage entry point" + default 0x0 + +endif + +menuconfig DFU_BINARY + bool "DFU binary format" + select RAW_BINARY + ---help--- + Create the dfu binary used with dfu-utils. + +if DFU_BINARY + +config DFU_BASE + hex "Address DFU image is loaded to" + +config DFU_VID + hex "VID to use for DFU image" + +config DFU_PID + hex "PID to use for DFU image" + +endif +endmenu # Binary Output Formats + +menu "Customize Header Files" + +config ARCH_HAVE_STDINT_H + bool + default n + ---help--- + Selected by architecture specific logic if the architecture provides + a stdint.h header file. + +config ARCH_STDINT_H + bool "stdint.h" + default n + depends on ARCH_HAVE_STDINT_H + ---help--- + The stdint.h header file can be found at nuttx/include/stdint.h. + However, that header includes logic to redirect the inclusion of an + architecture specific header file like: + + #ifdef CONFIG_ARCH_STDINT_H + # include + #else + ... + #endif + + Recall that that include path, include/arch, is a symbolic link and + will refer to a version of stdint.h at nuttx/arch//include/stdint.h. + +config ARCH_HAVE_STDBOOL_H + bool + default n + ---help--- + Selected by architecture specific logic if the architecture provides + a stdbool.h header file. + +config ARCH_STDBOOL_H + bool "stdbool.h" + default n + depends on ARCH_HAVE_STDBOOL_H + ---help--- + The stdbool.h header file can be found at nuttx/include/stdbool.h. + However, that header includes logic to redirect the inclusion of an + architecture specific header file like: + + #ifdef CONFIG_ARCH_STDBOOL_H + # include + #else + ... + #endif + + Recall that that include path, include/arch, is a symbolic link and + will refer to a version of stdbool.h at nuttx/arch//include/stdbool.h. + +config ARCH_HAVE_MATH_H + bool + default n + ---help--- + Selected by architecture specific logic if the architecture provides + a math.h header file. + +config ARCH_MATH_H + bool "math.h" + depends on ARCH_HAVE_MATH_H + default n + ---help--- + There is also a re-directing version of math.h in the source tree. + However, it resides out-of-the-way at include/nuttx/lib/math.h because it + conflicts too often with the system math.h. If ARCH_MATH_H=y is + defined, however, the top-level makefile will copy the redirecting + math.h header file from include/nuttx/lib/math.h to include/math.h. math.h + will then include the architecture-specific version of math.h that you + must provide at nuttx/arch/>architecture + #endif + + So for the architectures that define ARCH_MATH_H=y, include/math.h + will be the redirecting math.h header file; for the architectures + that don't select ARCH_MATH_H, the redirecting math.h header file + will stay out-of-the-way in include/nuttx/. + +config ARCH_FLOAT_H + bool "float.h" + default n + ---help--- + The float.h header file defines the properties of your floating + point implementation. It would always be best to use your + toolchain's float.h header file but if none is available, a default + float.h header file will provided if this option is selected. However + there is no assurance that the settings in this float.h are actually + correct for your platform! + +config ARCH_HAVE_STDARG_H + bool + default n + ---help--- + Selected by architecture specific logic if the architecture provides + a math.h header file. + +config ARCH_STDARG_H + bool "stdarg.h" + depends on ARCH_HAVE_STDARG_H + default n + ---help--- + There is a redirecting version of stdarg.h in the source tree. It + resides out-of-the-way at include/nuttx/lib/stdarg.h. This is + because you should normally use your toolchain's stdarg.h file. But + sometimes, your toolchain's stdarg.h file may have other header + file dependencies and so may not be usable in the NuttX build + environment. In those cases, you may have to create a architecture- + specific stdarg.h header file at nuttx/arch//include/stdarg.h + + If ARCH_STDARG_H=y is defined, the top-level makefile will copy the + re-directing stdarg.h header file from include/nuttx/lib/stdarg.h to + include/stdarg.h. So for the architectures that cannot use their + toolchain's stdarg.h file, they can use this alternative by defining + ARCH_STDARG_H=y and providing. If ARCH_STDARG_H, is not defined, then + the stdarg.h header file will stay out-of-the-way in include/nuttx/. + +config ARCH_HAVE_SETJMP + bool + default n + +config ARCH_SETJMP_H + bool "setjmp.h" + default n + depends on ARCH_HAVE_SETJMP + ---help--- + There is a redirecting version of setjmp.h in the source tree. It + resides out-of-the-way at include/nuttx/lib/setjmp.h. This is + because you should normally use your toolchain's setjmp.h file. But + sometimes, your toolchain's setjmp.h file may have other header + file dependencies and so may not be usable in the NuttX build + environment. In those cases, you may have to create a architecture- + specific setjmp.h header file at nuttx/arch//include/setjmp.h + + If ARCH_SETJMP_H=y is defined, the top-level makefile will copy the + re-directing setjmp.h header file from include/nuttx/lib/setjmp.h to + include/setjmp.h. So for the architectures that cannot use their + toolchain's setjmp.h file, they can use this alternative by defining + ARCH_SETJMP_H=y and providing. If ARCH_SETJMP_H, is not defined, then + the setjmp.h header file will stay out-of-the-way in include/nuttx/. + +choice + prompt "debug.h selection" + default ARCH_NONE_DEBUG_H + +config ARCH_NONE_DEBUG_H + bool "None" + ---help--- + No debug.h under include/arch/ and include/arch/chip. + +config ARCH_DEBUG_H + bool "debug.h" + ---help--- + The debug.h under include/arch contains architecture dependent debugging primitives + +config ARCH_CHIP_DEBUG_H + bool "chip debug.h" + ---help--- + The debug.h under include/arch/chip contains architecture dependent debugging primitives + +endchoice # debug.h selection + +endmenu # Customize Header Files + +menu "Debug Options" + +config DEBUG_ALERT + bool + default n + +config DEBUG_FEATURES + bool "Enable Debug Features" + default n + select DEBUG_ALERT + ---help--- + Enables built-in debug features. Selecting this option will (1) Enable + debug assertions in the code, (2) enable extended parameter testing in + many functions, and (3) enable support for debug output to the SYSLOG. + Note that enabling this option by itself does not produce debug output. + Debug output must also be selected on a subsystem-by-subsystem basis. + +if DEBUG_FEATURES + +comment "Debug SYSLOG Output Controls" + +config DEBUG_ERROR + bool "Enable Error Output" + default n + ---help--- + Enables output from [a-z]err() statements. Errors are significant system + exceptions that require immediate attention. + +config DEBUG_WARN + bool "Enable Warnings Output" + default n + depends on DEBUG_ERROR + ---help--- + Enables output from [a-z]warn() statements. Warnings are considered to + be various unexpected conditions, potential errors or errors that will + not have serious consequences. + +config DEBUG_INFO + bool "Enable Informational Debug Output" + default n + depends on DEBUG_WARN + ---help--- + Enables verbose "informational" debug output. If you enable + CONFIG_DEBUG_INFO, then very chatty (and often annoying) output + will be generated. + +config DEBUG_ASSERTIONS + bool "Enable Debug Assertions" + default n + ---help--- + Enables the DEBUGASSERT() macro. When CONFIG_DEBUG_ASSERTIONS is + defined, DEBUGASSERT() will cause the system to halt if the + assertion fails. If CONFIG_DEBUG_ASSERTIONS is not defined + DEBUGASSERT() compiled out of the system. In general, you would + set CONFIG_DEBUG_ASSERTIONS=y during debug, but disable the + assertions on a final, buckled up system. + +comment "Subsystem Debug Options" + +config DEBUG_AUDIO + bool "Audio Device Debug Features" + default n + depends on AUDIO + ---help--- + Enable audio device debug features. + Enable low level debug features for the audio subsystem and for audio + device drivers. (disabled by default). Support for this debug option + is architecture-specific and may not be available for some MCUs. + +if DEBUG_AUDIO + +config DEBUG_AUDIO_ERROR + bool "Audio Device Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable audio device error output to SYSLOG. + +config DEBUG_AUDIO_WARN + bool "Audio Device Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable audio device warning output to SYSLOG. + +config DEBUG_AUDIO_INFO + bool "Audio Device Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable audio device informational output to SYSLOG. + +endif # DEBUG_AUDIO + +config DEBUG_BINFMT + bool "Binary Loader Debug Features" + default n + depends on !BINFMT_DISABLE || LIBC_MODLIB + ---help--- + Enable binary loader debug features. + +if DEBUG_BINFMT + +config DEBUG_BINFMT_ERROR + bool "Binary Loader Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable binary loader error output to SYSLOG. + +config DEBUG_BINFMT_WARN + bool "Binary Loader Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable binary loader warning output to SYSLOG. + +config DEBUG_BINFMT_INFO + bool "Binary Loader Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable binary loader informational output to SYSLOG. + +endif # DEBUG_BINFMT + +config DEBUG_CONTACTLESS + bool "Contactless Debug Features" + default n + depends on DRIVERS_CONTACTLESS + ---help--- + Enable debug features for contactless (aka RFID) subsystem. + +if DEBUG_CONTACTLESS + +config DEBUG_CONTACTLESS_ERROR + bool "Contactless Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable contactless (aka RFID) subsystem error output to + SYSLOG. + +config DEBUG_CONTACTLESS_WARN + bool "Contactless Warnings Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable contactless (aka RFID) subsystem warning output to + SYSLOG. + +config DEBUG_CONTACTLESS_INFO + bool "Contactless Informational Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable contactless (aka RFID) subsystem informational output + to SYSLOG. + +endif # DEBUG_CONTACTLESS + +config DEBUG_CRYPTO + bool "Crypto Debug Features" + default n + depends on CRYPTO + ---help--- + Enable cryptographic debug features. + +if DEBUG_CRYPTO + +config DEBUG_CRYPTO_ERROR + bool "Crypto Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable cryptographic error output to SYSLOG. + +config DEBUG_CRYPTO_WARN + bool "Crypto Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable cryptographic warning output to SYSLOG. + +config DEBUG_CRYPTO_INFO + bool "Crypto Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable cryptographic informational output to SYSLOG. + +endif # DEBUG_CRYPTO + +config DEBUG_FS + bool "File System Debug Features" + default n + ---help--- + Enable file system debug features. + +if DEBUG_FS + +config DEBUG_FS_ERROR + bool "File System Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable file system error output to SYSLOG. + +config DEBUG_FS_WARN + bool "File System Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable file system warning output to SYSLOG. + +config DEBUG_FS_INFO + bool "File System Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable file system informational output to SYSLOG. + +endif # DEBUG_FS + +config DEBUG_GRAPHICS + bool "Graphics Debug Features" + default n + ---help--- + Enable NX graphics subsystem debug features. + +if DEBUG_GRAPHICS + +config DEBUG_GRAPHICS_ERROR + bool "Graphics Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable NX graphics subsystem error output to SYSLOG. + +config DEBUG_GRAPHICS_WARN + bool "Graphics Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable NX graphics subsystem warning output to SYSLOG. + +config DEBUG_GRAPHICS_INFO + bool "Graphics Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable NX graphics subsystem informational output to SYSLOG. + +endif # DEBUG_GRAPHICS + +config DEBUG_LIB + bool "C Library Debug Features" + default n + ---help--- + Enable C library debug features. + +if DEBUG_LIB + +config DEBUG_LIB_ERROR + bool "C Library Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable C library error output to SYSLOG. + +config DEBUG_LIB_WARN + bool "C Library Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable C library warning output to SYSLOG. + +config DEBUG_LIB_INFO + bool "C Library Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable C library informational output to SYSLOG. + +endif # DEBUG_LIB + +config DEBUG_MM + bool "Memory Manager Debug Features" + default n + ---help--- + Enable memory management debug features. + +if DEBUG_MM + +config DEBUG_MM_ERROR + bool "Memory Manager Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable memory management error output to SYSLOG. + +config DEBUG_MM_WARN + bool "Memory Manager Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable memory management warning output to SYSLOG. + +config DEBUG_MM_INFO + bool "Memory Manager Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable memory management informational output to SYSLOG. + +endif # DEBUG_MM + +config DEBUG_SHM + bool "Shared Memory Debug Output" + default n + depends on MM_SHM + ---help--- + Enable shared memory management debug SYSLOG output (disabled by default) + +config DEBUG_NET + bool "Network Debug Features" + default n + depends on ARCH_HAVE_NET + ---help--- + Enable network debug features. + +if DEBUG_NET + +config DEBUG_NET_ERROR + bool "Network Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable network error output to SYSLOG. + +config DEBUG_NET_WARN + bool "Network Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable network warning output to SYSLOG. + +config DEBUG_NET_INFO + bool "Network Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable network informational output to SYSLOG. + +endif # DEBUG_NET + +config DEBUG_POWER + bool "Power-related Debug Features" + default n + ---help--- + Enable power-related debug features. + +if DEBUG_POWER + +config DEBUG_POWER_ERROR + bool "Power-related Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable power-related error output to SYSLOG. + +config DEBUG_POWER_WARN + bool "Power-related Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable power-related warning output to SYSLOG. + +config DEBUG_POWER_INFO + bool "Power-related Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable power-related informational output to SYSLOG. + +endif # DEBUG_POWER + +config DEBUG_WIRELESS + bool "Wireless Debug Features" + default n + depends on WIRELESS || DRIVERS_WIRELESS + ---help--- + Enable wireless debug features. + +if DEBUG_WIRELESS + +config DEBUG_WIRELESS_ERROR + bool "Wireless Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable wireless error output to SYSLOG. + +config DEBUG_WIRELESS_WARN + bool "Wireless Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable wireless warning output to SYSLOG. + +config DEBUG_WIRELESS_INFO + bool "Wireless Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable wireless informational output to SYSLOG. + +endif # DEBUG_WIRELESS + +config DEBUG_SCHED + bool "Scheduler Debug Features" + default n + ---help--- + Enable OS scheduler debug features. + +if DEBUG_SCHED + +config DEBUG_SCHED_ERROR + bool "Scheduler Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable OS scheduler error output to SYSLOG. + +config DEBUG_SCHED_WARN + bool "Scheduler Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable OS scheduler warning output to SYSLOG. + +config DEBUG_SCHED_INFO + bool "Scheduler Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable OS scheduler informational output to SYSLOG. + +endif # DEBUG_SCHED + +config DEBUG_SYSCALL + bool "SYSCALL Debug Features" + default n + depends on LIB_SYSCALL + ---help--- + Enable very low level features related to system calls. If SYSCAL + output is enabled, this gives you basically a poor man's version of + strace. + +if DEBUG_SYSCALL + +config DEBUG_SYSCALL_ERROR + bool "SYSCALL Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable OS SYSCALL error output to SYSLOG. + +config DEBUG_SYSCALL_WARN + bool "SYSCALL Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable OS SYSCALL warning output to SYSLOG. + +config DEBUG_SYSCALL_INFO + bool "SYSCALL Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable OS SYSCALL informational output to SYSLOG. + +endif # DEBUG_SYSCALL + +comment "OS Function Debug Options" + +config DEBUG_DMA + bool "DMA Debug Features" + default n + depends on ARCH_DMA + ---help--- + Enable DMA debug features. + + Support for this debug option is architecture-specific and may not + be available for some MCUs. + +if DEBUG_DMA + +config DEBUG_DMA_ERROR + bool "DMA Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable DMA error output to SYSLOG. + +config DEBUG_DMA_WARN + bool "DMA Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable DMA warning output to SYSLOG. + +config DEBUG_DMA_INFO + bool "DMA Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable DMA informational output to SYSLOG. + +endif # DEBUG_DMA + +config DEBUG_IRQ + bool "Interrupt Controller Debug Features" + default n + ---help--- + Enable interrupt controller debug features. + + Some (but not all) architectures support debug output to verify + interrupt controller logic. If supported, then option will enable + that output. This may interfere with normal operations! You + should *not* enable interrupt controller debug unless you suspect + that here is a problem with that logic. On some platforms, this + option may even cause crashes! Use with care! + +if DEBUG_IRQ + +config DEBUG_IRQ_ERROR + bool "Interrupt Controller Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable interrupt controller error output to SYSLOG. + +config DEBUG_IRQ_WARN + bool "Interrupt Controller Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable interrupt controller warning output to SYSLOG. + +config DEBUG_IRQ_INFO + bool "Interrupt Controller Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable interrupt controller informational output to SYSLOG. + +endif # DEBUG_IRQ + +config DEBUG_PAGING + bool "Paging Debug Features" + default n + depends on PAGING + ---help--- + Enable OS demand paging debug features. + +if DEBUG_PAGING + +config DEBUG_PAGING_ERROR + bool "Paging Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable OS demand paging error output to SYSLOG. + +config DEBUG_PAGING_WARN + bool "Paging Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable OS demand paging warning output to SYSLOG. + +config DEBUG_PAGING_INFO + bool "Paging Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable OS demand paging informational output to SYSLOG. + +endif # DEBUG_PAGING + +comment "Driver Debug Options" + +config DEBUG_LCD + bool "Low-level LCD Debug Features" + default n + depends on LCD + ---help--- + Enable LCD driver debug features. + + Support for this debug option is board-specific and may not + be available for some boards. +if DEBUG_LCD + +config DEBUG_LCD_ERROR + bool "LCD Driver Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable LCD driver error output to SYSLOG. + +config DEBUG_LCD_WARN + bool "LCD Driver Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable LCD driver warning output to SYSLOG. + +config DEBUG_LCD_INFO + bool "LCD Driver Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable LCD driver informational output to SYSLOG. + +endif # DEBUG_LCD + +config DEBUG_LEDS + bool "Low-level LED Debug Features" + default n + depends on ARCH_HAVE_LEDS + ---help--- + Enable LED driver debug features. + + Support for this debug option is board-specific and may not + be available for some boards. + +if DEBUG_LEDS + +config DEBUG_LEDS_ERROR + bool "LED Driver Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable LED driver error output to SYSLOG. + +config DEBUG_LEDS_WARN + bool "LED Driver Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable LED driver warning output to SYSLOG. + +config DEBUG_LEDS_INFO + bool "LED Driver Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable LED driver informational output to SYSLOG. + +endif # DEBUG_LEDS + +config DEBUG_INPUT + bool "Input Device Debug Features" + default n + depends on INPUT + ---help--- + Enable input d. + Enable low level device debug features for the input device drivers + such as mice and touchscreens (disabled by default). Support for + this debug option is board-specific and may not be available for + some boards. + +if DEBUG_INPUT + +config DEBUG_INPUT_ERROR + bool "Input Device Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable input device error output to SYSLOG. + +config DEBUG_INPUT_WARN + bool "Input Device Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable input device warning output to SYSLOG. + +config DEBUG_INPUT_INFO + bool "Input Device Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable input device informational output to SYSLOG. + +endif # DEBUG_INPUT + +config DEBUG_ANALOG + bool "Analog Device Debug Features" + default n + depends on ANALOG + ---help--- + Enable analog device debug features. + Enable low level debug features the analog device drivers such as + A/D and D/A converters (disabled by default). Support for this + debug option is architecture-specific and may not be available for + some MCUs. + +if DEBUG_ANALOG + +config DEBUG_ANALOG_ERROR + bool "Analog Device Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable analog device error output to SYSLOG. + +config DEBUG_ANALOG_WARN + bool "Analog Device Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable analog device warning output to SYSLOG. + +config DEBUG_ANALOG_INFO + bool "Analog Device Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable CAN driver informational output to SYSLOG. + +endif # DEBUG_ANALOG + +config DEBUG_CAN + bool "CAN Debug Features" + default n + depends on CAN + ---help--- + Enable CAN driver debug features. + + Support for this debug option is architecture-specific and may not + be available for some MCUs. + +if DEBUG_CAN + +config DEBUG_CAN_ERROR + bool "CAN Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable CAN driver error output to SYSLOG. + +config DEBUG_CAN_WARN + bool "CAN Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable CAN driver warning output to SYSLOG. + +config DEBUG_CAN_INFO + bool "CAN Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable CAN driver informational output to SYSLOG. + +endif # DEBUG_CAN + +config DEBUG_GPIO + bool "GPIO Debug Features" + default n + ---help--- + Enable GPIO debug features. + + Support for this debug option is architecture-specific and may not + be available for some MCUs. + +if DEBUG_GPIO + +config DEBUG_GPIO_ERROR + bool "GPIO Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable GPIO error output to SYSLOG. + +config DEBUG_GPIO_WARN + bool "GPIO Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable GPIO warning output to SYSLOG. + +config DEBUG_GPIO_INFO + bool "GPIO Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable GPIO informational output to SYSLOG. + +endif # DEBUG_GPIO + +config DEBUG_I2C + bool "I2C Debug Features" + default n + depends on I2C + ---help--- + Enable I2C debug features. + + Support for this debug option is architecture-specific and may not + be available for some MCUs. + +if DEBUG_I2C + +config DEBUG_I2C_ERROR + bool "I2C Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable I2C driver error output to SYSLOG. + +config DEBUG_I2C_WARN + bool "I2C Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable I2C driver warning output to SYSLOG. + +config DEBUG_I2C_INFO + bool "I2C Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable I2C driver informational output to SYSLOG. + +endif # DEBUG_I2C + +config DEBUG_I2S + bool "I2S Debug Features" + default n + depends on I2S + ---help--- + Enable I2S debug features. + + Support for this debug option is architecture-specific and may not + be available for some MCUs. + +if DEBUG_I2S + +config DEBUG_I2S_ERROR + bool "I2S Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable I2S driver error output to SYSLOG. + + Support for this debug option is architecture-specific and may not + be available for some MCUs. + +config DEBUG_I2S_WARN + bool "I2S Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable I2S driver warning output to SYSLOG. + +config DEBUG_I2S_INFO + bool "I2S Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable I2S driver informational output to SYSLOG. + +endif # DEBUG_I2S + +config DEBUG_PWM + bool "PWM Debug Features" + default n + depends on PWM + ---help--- + Enable PWM debug features. + + Support for this debug option is architecture-specific and may not + be available for some MCUs. + +if DEBUG_PWM + +config DEBUG_PWM_ERROR + bool "PWM Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable PWM driver error output to SYSLOG. + + Support for this debug option is architecture-specific and may not + be available for some MCUs. + +config DEBUG_PWM_WARN + bool "PWM Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable PWM driver warning output to SYSLOG. + +config DEBUG_PWM_INFO + bool "PWM Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable PWM driver informational output to SYSLOG. + +endif # DEBUG_PWM + +config DEBUG_RC + bool "RC Debug Features" + default n + depends on DRIVERS_RC + ---help--- + Enable RC debug features. + + Support for this debug option is architecture-specific and may not + be available for some MCUs. + +if DEBUG_RC + +config DEBUG_RC_ERROR + bool "RC Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable RC driver error output to SYSLOG. + + Support for this debug option is architecture-specific and may not + be available for some MCUs. + +config DEBUG_RC_WARN + bool "RC Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable RC driver warning output to SYSLOG. + +config DEBUG_RC_INFO + bool "RC Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable RC driver informational output to SYSLOG. + +endif # DEBUG_RC + +config DEBUG_RTC + bool "RTC Debug Features" + default n + depends on RTC + ---help--- + Enable RTC debug features. + + Support for this debug option is architecture-specific and may not + be available for some MCUs. + +if DEBUG_RTC + +config DEBUG_RTC_ERROR + bool "RTC Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable RTC driver error output to SYSLOG. + + Support for this debug option is architecture-specific and may not + be available for some MCUs. + +config DEBUG_RTC_WARN + bool "RTC Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable RTC driver warning output to SYSLOG. + +config DEBUG_RTC_INFO + bool "RTC Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable RTC driver informational output to SYSLOG. + +endif # DEBUG_RTC + +config DEBUG_MEMCARD + bool "Memory Card Driver Debug Features" + default n + depends on MMCSD + ---help--- + Enable MMC/SD memory card Driver debug features. + + Support for this debug option is architecture-specific and may not + be available for some MCUs. + +if DEBUG_MEMCARD + +config DEBUG_MEMCARD_ERROR + bool "Memory Card Driver Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable MMC/SD memory card driver error output to SYSLOG. + + Support for this debug option is architecture-specific and may not + be available for some MCUs. + +config DEBUG_MEMCARD_WARN + bool "Memory Card Driver Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable MMC/SD memory card driver warning output to SYSLOG. + +config DEBUG_MEMCARD_INFO + bool "Memory Card Driver Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable MMC/SD memory card driver informational output to SYSLOG. + +endif # DEBUG_MEMCARD + +config DEBUG_SENSORS + bool "Sensor Debug Features" + default n + depends on SENSORS + ---help--- + Enable sensor driver debug features. + + Support for this debug option is architecture-specific and may not + be available for some MCUs. + +if DEBUG_SENSORS + +config DEBUG_SENSORS_ERROR + bool "Sensor Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable sensor driver error output to SYSLOG. + +config DEBUG_SENSORS_WARN + bool "Sensor Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable sensor driver warning output to SYSLOG. + +config DEBUG_SENSORS_INFO + bool "Sensor Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable sensor driver informational output to SYSLOG. + +endif # DEBUG_SENSORS + +config DEBUG_SPI + bool "SPI Debug Features" + default n + depends on SPI + ---help--- + Enable SPI debug features. + + Support for this debug option is architecture-specific and may not + be available for some MCUs. + +if DEBUG_SPI + +config DEBUG_SPI_ERROR + bool "SPI Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable SPI error output to SYSLOG. + +config DEBUG_SPI_WARN + bool "SPI Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable SPI warning output to SYSLOG. + +config DEBUG_SPI_INFO + bool "SPI Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable SPI informational output to SYSLOG. + +endif # DEBUG_SPI + +config DEBUG_TIMER + bool "Timer Debug Features" + default n + ---help--- + Enable timer debug features. + + Support for this debug option is architecture-specific and may not + be available for some MCUs. + +if DEBUG_TIMER + +config DEBUG_TIMER_ERROR + bool "Timer Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable timer error output to SYSLOG. + +config DEBUG_TIMER_WARN + bool "Timer Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable timer warning output to SYSLOG. + +config DEBUG_TIMER_INFO + bool "Timer Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable timer informational output to SYSLOG. + +endif # DEBUG_TIMER + +config DEBUG_USB + bool "USB Debug Features" + default n + depends on USBDEV || USBHOST + ---help--- + Enable USB debug features. + +if DEBUG_USB + +config DEBUG_USB_ERROR + bool "USB Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable USB error output to SYSLOG. + +config DEBUG_USB_WARN + bool "USB Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable USB warning output to SYSLOG. + +config DEBUG_USB_INFO + bool "USB Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable USB informational output to SYSLOG. + +endif # DEBUG_USB + +config DEBUG_WATCHDOG + bool "Watchdog Timer Debug Features" + default n + depends on WATCHDOG + ---help--- + Enable watchdog timer debug features. + + Support for this debug option is architecture-specific and may not + be available for some MCUs. + +if DEBUG_WATCHDOG + +config DEBUG_WATCHDOG_ERROR + bool "Watchdog Timer Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable watchdog time error output to SYSLOG. + +config DEBUG_WATCHDOG_WARN + bool "Watchdog Timer Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable watchdog time warning output to SYSLOG. + +config DEBUG_WATCHDOG_INFO + bool "Watchdog Timer Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable watchdog time informational output to SYSLOG. + +endif # DEBUG_WATCHDOG + +if DEBUG_MOTOR + +config DEBUG_MOTOR_ERROR + bool "Motor Error Output" + default n + depends on DEBUG_ERROR + ---help--- + Enable motor error output to SYSLOG. + +config DEBUG_MOTOR_WARN + bool "Motor Warnings Output" + default n + depends on DEBUG_WARN + ---help--- + Enable motor warning output to SYSLOG. + +config DEBUG_MOTOR_INFO + bool "Motor Informational Output" + default n + depends on DEBUG_INFO + ---help--- + Enable motor informational output to SYSLOG. + +endif # DEBUG_MOTOR +endif # DEBUG_FEATURES + +config ARCH_HAVE_STACKCHECK + bool + default n + +config STACK_COLORATION + bool "Stack coloration" + default n + depends on ARCH_HAVE_STACKCHECK + ---help--- + Enable stack coloration to initialize the stack memory to the value + of STACK_COLOR and enable the stack checking APIs that can be used + to monitor the level of stack usage. + + Only supported by a few architectures. + +config STACK_CANARIES + bool "Compiler stack canaries" + depends on ARCH_HAVE_STACKCHECK + default n + ---help--- + This option enables compiler stack canaries. + If stack canaries are supported by the compiler, it will emit + extra code that inserts a canary value into the stack frame when + a function is entered and validates this value upon exit. + Stack corruption (such as that caused by buffer overflow) results + in a fatal error condition for the running entity. + Enabling this option can result in a significant increase + in footprint and an associated decrease in performance. + +config ARCH_HAVE_HEAPCHECK + bool + default n + +config HEAP_COLORATION + bool "Heap coloration" + default n + depends on ARCH_HAVE_HEAPCHECK + ---help--- + Enable heap coloration to check heap usage. Only supported by a few + architectures. + +config DEBUG_SYMBOLS + bool "Generate Debug Symbols" + default n + ---help--- + Build with debug symbols (needed for use with a debugger). + +endmenu # Debug Options + +config ARCH_HAVE_CUSTOMOPT + bool + default n + +choice + prompt "Optimization Level" + default DEBUG_NOOPT if DEBUG_SYMBOLS + default DEBUG_FULLOPT if !DEBUG_SYMBOLS + +config DEBUG_NOOPT + bool "Suppress Optimization" + ---help--- + Build without optimization. This is often helpful when debugging code. + +config DEBUG_CUSTOMOPT + bool "Custom Optimization" + depends on ARCH_HAVE_CUSTOMOPT + ---help--- + Select a custom debug level. This is often helpful if you suspect an + optimization level error and want to lower the level of optimization. + +config DEBUG_FULLOPT + bool "Normal, Full optimization" + ---help--- + Build full optimization. This is the normal case for production + firmware. + +endchoice # Optimization Level + +config DEBUG_OPTLEVEL + string "Custom Optimization Level" + default "-O2" + depends on DEBUG_CUSTOMOPT + ---help--- + This string represents the custom optimization level that will be + used if DEBUG_CUSTOMOPT. + +endmenu # Build Setup + +menu "System Type" +source "arch/Kconfig" +endmenu + +menu "Board Selection" +source "boards/Kconfig" +endmenu + +menu "RTOS Features" +source sched/Kconfig +source syscall/Kconfig +endmenu + +menu "Device Drivers" +source drivers/Kconfig +endmenu + +menu "Networking Support" +source net/Kconfig +endmenu + +menu "Crypto API" +source crypto/Kconfig +endmenu + +menu "File Systems" +source fs/Kconfig +endmenu + +menu "Graphics Support" +source graphics/Kconfig +source libs/libnx/Kconfig +endmenu + +menu "Memory Management" +source mm/Kconfig +endmenu + +menu "Audio Support" +source audio/Kconfig +endmenu + +menu "Video Support" +source video/Kconfig +endmenu + +menu "Wireless Support" +source wireless/Kconfig +endmenu + +menu "Binary Loader" +source binfmt/Kconfig +endmenu + +menu "Library Routines" +source libs/libc/Kconfig +source libs/libxx/Kconfig +source libs/libdsp/Kconfig +endmenu + +menu "Open Asymmetric Multi Processing" +source openamp/Kconfig +endmenu + +menu "Application Configuration" +source "$APPSDIR/Kconfig" +endmenu + +# Support optionally including external code +# into the OS build. EXTERNALDIR will be used +# to either point to 'nuttx/external' or +# 'nuttx/dummy', if 'nuttx/external' +# does not contain a Kconfig file + +config EXTERNALDIR + string + option env="EXTERNALDIR" + +source "$EXTERNALDIR/Kconfig" diff --git a/Ubiquitous/Nuttx/app_match_nuttx/nuttx/Makefile b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/Makefile new file mode 100644 index 000000000..0a97c7365 --- /dev/null +++ b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/Makefile @@ -0,0 +1,48 @@ +############################################################################ +# Makefile +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +# Check if the system has been configured + +ifeq ($(wildcard .config),) +.DEFAULT default: + @echo "NuttX has not been configured!" + @echo "To configure the project:" + @echo " tools/configure.sh " + @echo "For a list of available configurations:" + @echo " tools/configure.sh -L" +else +include .config + +# Build any necessary tools needed early in the build. +# incdir - Is needed immediately by all Make.defs file. + +TOPDIR := ${shell echo $(CURDIR) | sed -e 's/ /\\ /g'} +DUMMY := ${shell $(MAKE) -C tools -f Makefile.host incdir \ + INCDIR="$(TOPDIR)/tools/incdir.sh"} + +# Include the correct Makefile for the selected architecture. + +ifeq ($(CONFIG_WINDOWS_NATIVE),y) +include tools/Makefile.win +else +export KERNEL_ROOT = $(CURDIR) +include tools/Makefile.unix +endif +endif diff --git a/Ubiquitous/Nuttx/app_match_nuttx/nuttx/arch/arm/src/stm32/stm32_serial.c b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/arch/arm/src/stm32/stm32_serial.c new file mode 100644 index 000000000..dc58cd966 --- /dev/null +++ b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/arch/arm/src/stm32/stm32_serial.c @@ -0,0 +1,3404 @@ +/**************************************************************************** + * arch/arm/src/stm32/stm32_serial.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#ifdef CONFIG_SERIAL_TERMIOS +# include +#endif + +#include + +#include "chip.h" +#include "stm32_uart.h" +#include "stm32_dma.h" +#include "stm32_rcc.h" +#include "arm_arch.h" +#include "arm_internal.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Some sanity checks *******************************************************/ + +/* DMA configuration */ + +/* If DMA is enabled on any USART, then very that other pre-requisites + * have also been selected. + */ + +#ifdef SERIAL_HAVE_RXDMA + +# if defined(CONFIG_STM32_HAVE_IP_DMA_V2) +/* Verify that DMA has been enabled and the DMA channel has been defined. + */ + +# if defined(CONFIG_USART1_RXDMA) || defined(CONFIG_USART6_RXDMA) +# ifndef CONFIG_STM32_DMA2 +# error STM32 USART1/6 receive DMA requires CONFIG_STM32_DMA2 +# endif +# endif + +# if defined(CONFIG_USART2_RXDMA) || defined(CONFIG_USART3_RXDMA) || \ + defined(CONFIG_UART4_RXDMA) || defined(CONFIG_UART5_RXDMA) || \ + defined(CONFIG_UART7_RXDMA) || defined(CONFIG_UART8_RXDMA) +# ifndef CONFIG_STM32_DMA1 +# error STM32 USART2/3/4/5/7/8 receive DMA requires CONFIG_STM32_DMA1 +# endif +# endif + +/* Currently RS-485 support cannot be enabled when RXDMA is in use due to + * lack of testing - RS-485 support was developed on STM32F1x + */ + +# if (defined(CONFIG_USART1_RXDMA) && defined(CONFIG_USART1_RS485)) || \ + (defined(CONFIG_USART2_RXDMA) && defined(CONFIG_USART2_RS485)) || \ + (defined(CONFIG_USART3_RXDMA) && defined(CONFIG_USART3_RS485)) || \ + (defined(CONFIG_UART4_RXDMA) && defined(CONFIG_UART4_RS485)) || \ + (defined(CONFIG_UART5_RXDMA) && defined(CONFIG_UART5_RS485)) || \ + (defined(CONFIG_USART6_RXDMA) && defined(CONFIG_USART6_RS485)) || \ + (defined(CONFIG_UART7_RXDMA) && defined(CONFIG_UART7_RS485)) || \ + (defined(CONFIG_UART8_RXDMA) && defined(CONFIG_UART8_RS485)) +# error "RXDMA and RS-485 cannot be enabled at the same time for the same U[S]ART" +# endif + +/* For the F4, there are alternate DMA channels for USART1 and 6. + * Logic in the board.h file make the DMA channel selection by defining + * the following in the board.h file. + */ + +# if defined(CONFIG_USART1_RXDMA) && !defined(DMAMAP_USART1_RX) +# error "USART1 DMA channel not defined (DMAMAP_USART1_RX)" +# endif + +# if defined(CONFIG_USART2_RXDMA) && !defined(DMAMAP_USART2_RX) +# error "USART2 DMA channel not defined (DMAMAP_USART2_RX)" +# endif + +# if defined(CONFIG_USART3_RXDMA) && !defined(DMAMAP_USART3_RX) +# error "USART3 DMA channel not defined (DMAMAP_USART3_RX)" +# endif + +# if defined(CONFIG_UART4_RXDMA) && !defined(DMAMAP_UART4_RX) +# error "UART4 DMA channel not defined (DMAMAP_UART4_RX)" +# endif + +# if defined(CONFIG_UART5_RXDMA) && !defined(DMAMAP_UART5_RX) +# error "UART5 DMA channel not defined (DMAMAP_UART5_RX)" +# endif + +# if defined(CONFIG_USART6_RXDMA) && !defined(DMAMAP_USART6_RX) +# error "USART6 DMA channel not defined (DMAMAP_USART6_RX)" +# endif + +# if defined(CONFIG_UART7_RXDMA) && !defined(DMAMAP_UART7_RX) +# error "UART7 DMA channel not defined (DMAMAP_UART7_RX)" +# endif + +# if defined(CONFIG_UART8_RXDMA) && !defined(DMAMAP_UART8_RX) +# error "UART8 DMA channel not defined (DMAMAP_UART8_RX)" +# endif + +# elif defined(CONFIG_STM32_HAVE_IP_DMA_V1) + +# if defined(CONFIG_USART1_RXDMA) || defined(CONFIG_USART2_RXDMA) || \ + defined(CONFIG_USART3_RXDMA) +# ifndef CONFIG_STM32_DMA1 +# error STM32 USART1/2/3 receive DMA requires CONFIG_STM32_DMA1 +# endif +# endif + +# if defined(CONFIG_UART4_RXDMA) || defined(CONFIG_UART5_RXDMA) +# ifndef CONFIG_STM32_DMA2 +# error STM32 UART4/5 receive DMA requires CONFIG_STM32_DMA2 +# endif +# endif + +/* There are no optional DMA channel assignments for the F1 */ + +# define DMAMAP_USART1_RX DMACHAN_USART1_RX +# define DMAMAP_USART2_RX DMACHAN_USART2_RX +# define DMAMAP_USART3_RX DMACHAN_USART3_RX +# define DMAMAP_UART4_RX DMACHAN_UART4_RX +# define DMAMAP_UART5_RX DMACHAN_UART5_RX + +# endif + +/* The DMA buffer size when using RX DMA to emulate a FIFO. + * + * When streaming data, the generic serial layer will be called + * every time the FIFO receives half this number of bytes. + */ +# if !defined(CONFIG_STM32_SERIAL_RXDMA_BUFFER_SIZE) +# define CONFIG_STM32_SERIAL_RXDMA_BUFFER_SIZE 32 +# endif +# define RXDMA_MUTIPLE 4 +# define RXDMA_MUTIPLE_MASK (RXDMA_MUTIPLE -1) +# define RXDMA_BUFFER_SIZE ((CONFIG_STM32_SERIAL_RXDMA_BUFFER_SIZE \ + + RXDMA_MUTIPLE_MASK) \ + & ~RXDMA_MUTIPLE_MASK) + +/* DMA priority */ + +# ifndef CONFIG_USART_RXDMAPRIO +# if defined(CONFIG_STM32_HAVE_IP_DMA_V1) +# define CONFIG_USART_RXDMAPRIO DMA_CCR_PRIMED +# elif defined(CONFIG_STM32_HAVE_IP_DMA_V2) +# define CONFIG_USART_RXDMAPRIO DMA_SCR_PRIMED +# else +# error "Unknown STM32 DMA" +# endif +# endif +# if defined(CONFIG_STM32_HAVE_IP_DMA_V1) +# if (CONFIG_USART_RXDMAPRIO & ~DMA_CCR_PL_MASK) != 0 +# error "Illegal value for CONFIG_USART_RXDMAPRIO" +# endif +# elif defined(CONFIG_STM32_HAVE_IP_DMA_V2) +# if (CONFIG_USART_RXDMAPRIO & ~DMA_SCR_PL_MASK) != 0 +# error "Illegal value for CONFIG_USART_RXDMAPRIO" +# endif +# else +# error "Unknown STM32 DMA" +# endif + +/* DMA control word */ + +# if defined(CONFIG_STM32_HAVE_IP_DMA_V2) +# define SERIAL_RXDMA_CONTROL_WORD \ + (DMA_SCR_DIR_P2M | \ + DMA_SCR_CIRC | \ + DMA_SCR_MINC | \ + DMA_SCR_PSIZE_8BITS | \ + DMA_SCR_MSIZE_8BITS | \ + CONFIG_USART_RXDMAPRIO | \ + DMA_SCR_PBURST_SINGLE | \ + DMA_SCR_MBURST_SINGLE) +# else +# define SERIAL_RXDMA_CONTROL_WORD \ + (DMA_CCR_CIRC | \ + DMA_CCR_MINC | \ + DMA_CCR_PSIZE_8BITS | \ + DMA_CCR_MSIZE_8BITS | \ + CONFIG_USART_RXDMAPRIO) +# endif + +#endif /* SERIAL_HAVE_RXDMA */ + +#ifdef SERIAL_HAVE_TXDMA + +# if defined(CONFIG_STM32_HAVE_IP_DMA_V2) + +/* Verify that DMA has been enabled and the DMA channel has been defined. + */ + +# if defined(CONFIG_USART1_TXDMA) || defined(CONFIG_USART6_TXDMA) +# ifndef CONFIG_STM32_DMA2 +# error STM32 USART1/6 receive DMA requires CONFIG_STM32_DMA2 +# endif +# endif + +# if defined(CONFIG_USART2_TXDMA) || defined(CONFIG_USART3_TXDMA) || \ + defined(CONFIG_UART4_TXDMA) || defined(CONFIG_UART5_TXDMA) || \ + defined(CONFIG_UART7_TXDMA) || defined(CONFIG_UART8_TXDMA) +# ifndef CONFIG_STM32_DMA1 +# error STM32 USART2/3/4/5/7/8 receive DMA requires CONFIG_STM32_DMA1 +# endif +# endif + +/* Currently RS-485 support cannot be enabled when TXDMA is in use due to + * lack of testing - RS-485 support was developed on STM32F1x + */ + +# if (defined(CONFIG_USART1_TXDMA) && defined(CONFIG_USART1_RS485)) || \ + (defined(CONFIG_USART2_TXDMA) && defined(CONFIG_USART2_RS485)) || \ + (defined(CONFIG_USART3_TXDMA) && defined(CONFIG_USART3_RS485)) || \ + (defined(CONFIG_UART4_TXDMA) && defined(CONFIG_UART4_RS485)) || \ + (defined(CONFIG_UART5_TXDMA) && defined(CONFIG_UART5_RS485)) || \ + (defined(CONFIG_USART6_TXDMA) && defined(CONFIG_USART6_RS485)) || \ + (defined(CONFIG_UART7_TXDMA) && defined(CONFIG_UART7_RS485)) || \ + (defined(CONFIG_UART8_TXDMA) && defined(CONFIG_UART8_RS485)) +# error "TXDMA and RS-485 cannot be enabled at the same time for the same U[S]ART" +# endif + +# if defined(CONFIG_USART1_TXDMA) && !defined(DMAMAP_USART1_TX) +# error "USART1 DMA channel not defined (DMAMAP_USART1_TX)" +# endif + +# if defined(CONFIG_USART2_TXDMA) && !defined(DMAMAP_USART2_TX) +# error "USART2 DMA channel not defined (DMAMAP_USART2_TX)" +# endif + +# if defined(CONFIG_USART3_TXDMA) && !defined(DMAMAP_USART3_TX) +# error "USART3 DMA channel not defined (DMAMAP_USART3_TX)" +# endif + +# if defined(CONFIG_UART4_TXDMA) && !defined(DMAMAP_UART4_TX) +# error "UART4 DMA channel not defined (DMAMAP_UART4_TX)" +# endif + +# if defined(CONFIG_UART5_TXDMA) && !defined(DMAMAP_UART5_TX) +# error "UART5 DMA channel not defined (DMAMAP_UART5_TX)" +# endif + +# if defined(CONFIG_USART6_TXDMA) && !defined(DMAMAP_USART6_TX) +# error "USART6 DMA channel not defined (DMAMAP_USART6_TX)" +# endif + +# if defined(CONFIG_UART7_TXDMA) && !defined(DMAMAP_UART7_TX) +# error "UART7 DMA channel not defined (DMAMAP_UART7_TX)" +# endif + +# if defined(CONFIG_UART8_TXDMA) && !defined(DMAMAP_UART8_TX) +# error "UART8 DMA channel not defined (DMAMAP_UART8_TX)" +# endif + +# elif defined(CONFIG_STM32_HAVE_IP_DMA_V1) + +# if defined(CONFIG_USART1_TXDMA) || defined(CONFIG_USART2_TXDMA) || \ + defined(CONFIG_USART3_TXDMA) +# ifndef CONFIG_STM32_DMA1 +# error STM32 USART1/2/3 receive DMA requires CONFIG_STM32_DMA1 +# endif +# endif + +# if defined(CONFIG_UART4_TXDMA) || defined(CONFIG_UART5_TXDMA) +# ifndef CONFIG_STM32_DMA2 +# error STM32 UART4/5 receive DMA requires CONFIG_STM32_DMA2 +# endif +# endif + +# define DMAMAP_USART1_TX DMACHAN_USART1_TX +# define DMAMAP_USART2_TX DMACHAN_USART2_TX +# define DMAMAP_USART3_TX DMACHAN_USART3_TX +# define DMAMAP_UART4_TX DMACHAN_UART4_TX +# define DMAMAP_UART5_TX DMACHAN_UART5_TX + +# endif + +/* DMA priority */ + +# ifndef CONFIG_USART_TXDMAPRIO +# if defined(CONFIG_STM32_HAVE_IP_DMA_V1) +# define CONFIG_USART_TXDMAPRIO DMA_CCR_PRIMED +# elif defined(CONFIG_STM32_HAVE_IP_DMA_V2) +# define CONFIG_USART_TXDMAPRIO DMA_SCR_PRIMED +# else +# error "Unknown STM32 DMA" +# endif +# endif +# if defined(CONFIG_STM32_HAVE_IP_DMA_V1) +# if (CONFIG_USART_TXDMAPRIO & ~DMA_CCR_PL_MASK) != 0 +# error "Illegal value for CONFIG_USART_TXDMAPRIO" +# endif +# elif defined(CONFIG_STM32_HAVE_IP_DMA_V2) +# if (CONFIG_USART_TXDMAPRIO & ~DMA_SCR_PL_MASK) != 0 +# error "Illegal value for CONFIG_USART_TXDMAPRIO" +# endif +# else +# error "Unknown STM32 DMA" +# endif + +/* DMA control word */ + +# if defined(CONFIG_STM32_HAVE_IP_DMA_V2) +# define SERIAL_TXDMA_CONTROL_WORD \ + (DMA_SCR_DIR_M2P | \ + DMA_SCR_MINC | \ + DMA_SCR_PSIZE_8BITS | \ + DMA_SCR_MSIZE_8BITS | \ + CONFIG_USART_TXDMAPRIO | \ + DMA_SCR_PBURST_SINGLE | \ + DMA_SCR_MBURST_SINGLE) +# elif defined(CONFIG_STM32_HAVE_IP_DMA_V1) +# define SERIAL_TXDMA_CONTROL_WORD \ + (DMA_CCR_DIR | \ + DMA_CCR_MINC | \ + DMA_CCR_PSIZE_8BITS | \ + DMA_CCR_MSIZE_8BITS | \ + CONFIG_USART_TXDMAPRIO) +# else +# error "Unknown STM32 DMA" +# endif + +/* DMA ISR status */ + +# if defined(CONFIG_STM32_HAVE_IP_DMA_V1) +# define DMA_ISR_HTIF_BIT DMA_CHAN_HTIF_BIT +# define DMA_ISR_TCIF_BIT DMA_CHAN_TCIF_BIT +# elif defined(CONFIG_STM32_HAVE_IP_DMA_V2) +# define DMA_ISR_HTIF_BIT DMA_STREAM_HTIF_BIT +# define DMA_ISR_TCIF_BIT DMA_STREAM_TCIF_BIT +# else +# error "Unknown STM32 DMA" +# endif + +#endif /* SERIAL_HAVE_TXDMA */ + +/* Power management definitions */ + +#if defined(CONFIG_PM) && !defined(CONFIG_STM32_PM_SERIAL_ACTIVITY) +# define CONFIG_STM32_PM_SERIAL_ACTIVITY 10 +#endif +#if defined(CONFIG_PM) +# define PM_IDLE_DOMAIN 0 /* Revisit */ +#endif + +/* Since RX DMA or TX DMA or both may be enabled for a given U[S]ART. + * We need runtime detection in up_dma_setup and up_dma_shutdown + * We use the default struct default init value of 0 which maps to + * STM32_DMA_MAP(DMA1,DMA_STREAM0,DMA_CHAN0) which is not a U[S]ART. + */ + +#define INVALID_SERIAL_DMA_CHANNEL 0 + +/* Keep track if a Break was set + * + * Note: + * + * 1) This value is set in the priv->ie but never written to the control + * register. It must not collide with USART_CR1_USED_INTS or USART_CR3_EIE + * 2) USART_CR3_EIE is also carried in the up_dev_s ie member. + * + * See up_restoreusartint where the masking is done. + */ + +#ifdef CONFIG_STM32_SERIALBRK_BSDCOMPAT +# define USART_CR1_IE_BREAK_INPROGRESS_SHFTS 15 +# define USART_CR1_IE_BREAK_INPROGRESS (1 << USART_CR1_IE_BREAK_INPROGRESS_SHFTS) +#endif + +#ifdef USE_SERIALDRIVER +#ifdef HAVE_SERIALDRIVER + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct up_dev_s +{ + struct uart_dev_s dev; /* Generic UART device */ + uint16_t ie; /* Saved interrupt mask bits value */ + uint16_t sr; /* Saved status bits */ + + /* Has been initialized and HW is setup. */ + + bool initialized; + + /* If termios are supported, then the following fields may vary at + * runtime. + */ + +#ifdef CONFIG_SERIAL_TERMIOS + uint8_t parity; /* 0=none, 1=odd, 2=even */ + uint8_t bits; /* Number of bits (7 or 8) */ + bool stopbits2; /* True: Configure with 2 stop bits instead of 1 */ +#ifdef CONFIG_SERIAL_IFLOWCONTROL + bool iflow; /* input flow control (RTS) enabled */ +#endif +#ifdef CONFIG_SERIAL_OFLOWCONTROL + bool oflow; /* output flow control (CTS) enabled */ +#endif + uint32_t baud; /* Configured baud */ +#else + const uint8_t parity; /* 0=none, 1=odd, 2=even */ + const uint8_t bits; /* Number of bits (7 or 8) */ + const bool stopbits2; /* True: Configure with 2 stop bits instead of 1 */ +#ifdef CONFIG_SERIAL_IFLOWCONTROL + const bool iflow; /* input flow control (RTS) enabled */ +#endif +#ifdef CONFIG_SERIAL_OFLOWCONTROL + const bool oflow; /* output flow control (CTS) enabled */ +#endif + const uint32_t baud; /* Configured baud */ +#endif + + const uint8_t irq; /* IRQ associated with this USART */ + const uint32_t apbclock; /* PCLK 1 or 2 frequency */ + const uint32_t usartbase; /* Base address of USART registers */ + const uint32_t tx_gpio; /* U[S]ART TX GPIO pin configuration */ + const uint32_t rx_gpio; /* U[S]ART RX GPIO pin configuration */ +#ifdef CONFIG_SERIAL_IFLOWCONTROL + const uint32_t rts_gpio; /* U[S]ART RTS GPIO pin configuration */ +#endif +#ifdef CONFIG_SERIAL_OFLOWCONTROL + const uint32_t cts_gpio; /* U[S]ART CTS GPIO pin configuration */ +#endif + + /* TX DMA state */ + +#ifdef SERIAL_HAVE_TXDMA + const unsigned int txdma_channel; /* DMA channel assigned */ + DMA_HANDLE txdma; /* currently-open trasnmit DMA stream */ +#endif + +#ifdef SERIAL_HAVE_RXDMA + const unsigned int rxdma_channel; /* DMA channel assigned */ +#endif + + /* RX DMA state */ + +#ifdef SERIAL_HAVE_RXDMA + DMA_HANDLE rxdma; /* currently-open receive DMA stream */ + bool rxenable; /* DMA-based reception en/disable */ + uint32_t rxdmanext; /* Next byte in the DMA buffer to be read */ + char *const rxfifo; /* Receive DMA buffer */ +#endif + +#ifdef HAVE_RS485 + const uint32_t rs485_dir_gpio; /* U[S]ART RS-485 DIR GPIO pin cfg */ + const bool rs485_dir_polarity; /* U[S]ART RS-485 DIR TXEN polarity */ +#endif +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static void up_set_format(struct uart_dev_s *dev); +static int up_setup(struct uart_dev_s *dev); +static void up_shutdown(struct uart_dev_s *dev); +static int up_attach(struct uart_dev_s *dev); +static void up_detach(struct uart_dev_s *dev); +static int up_interrupt(int irq, void *context, void *arg); +static int up_ioctl(struct file *filep, int cmd, unsigned long arg); +#if defined(SERIAL_HAVE_TXDMA_OPS) || defined(SERIAL_HAVE_NODMA_OPS) +static int up_receive(struct uart_dev_s *dev, unsigned int *status); +static void up_rxint(struct uart_dev_s *dev, bool enable); +static bool up_rxavailable(struct uart_dev_s *dev); +#endif +#ifdef CONFIG_SERIAL_IFLOWCONTROL +static bool up_rxflowcontrol(struct uart_dev_s *dev, unsigned int nbuffered, + bool upper); +#endif +static void up_send(struct uart_dev_s *dev, int ch); +#if defined(SERIAL_HAVE_RXDMA_OPS) || defined(SERIAL_HAVE_NODMA_OPS) +static void up_txint(struct uart_dev_s *dev, bool enable); +#endif +static bool up_txready(struct uart_dev_s *dev); + +#ifdef SERIAL_HAVE_TXDMA +static void up_dma_send(struct uart_dev_s *dev); +static void up_dma_txint(struct uart_dev_s *dev, bool enable); +static void up_dma_txavailable(struct uart_dev_s *dev); +static void up_dma_txcallback(DMA_HANDLE handle, uint8_t status, void *arg); +#endif + +#if defined(SERIAL_HAVE_RXDMA) || defined(SERIAL_HAVE_TXDMA) +static int up_dma_setup(struct uart_dev_s *dev); +static void up_dma_shutdown(struct uart_dev_s *dev); +#endif + +#ifdef SERIAL_HAVE_RXDMA +static int up_dma_receive(struct uart_dev_s *dev, unsigned int *status); +static void up_dma_rxint(struct uart_dev_s *dev, bool enable); +static bool up_dma_rxavailable(struct uart_dev_s *dev); + +static void up_dma_rxcallback(DMA_HANDLE handle, uint8_t status, void *arg); +#endif + +#ifdef CONFIG_PM +static void up_pm_notify(struct pm_callback_s *cb, int dowmin, + enum pm_state_e pmstate); +static int up_pm_prepare(struct pm_callback_s *cb, int domain, + enum pm_state_e pmstate); +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#ifdef SERIAL_HAVE_NODMA_OPS +static const struct uart_ops_s g_uart_ops = +{ + .setup = up_setup, + .shutdown = up_shutdown, + .attach = up_attach, + .detach = up_detach, + .ioctl = up_ioctl, + .receive = up_receive, + .rxint = up_rxint, + .rxavailable = up_rxavailable, +#ifdef CONFIG_SERIAL_IFLOWCONTROL + .rxflowcontrol = up_rxflowcontrol, +#endif + .send = up_send, + .txint = up_txint, + .txready = up_txready, + .txempty = up_txready, +}; +#endif + +#ifdef SERIAL_HAVE_RXTXDMA_OPS +static const struct uart_ops_s g_uart_rxtxdma_ops = +{ + .setup = up_dma_setup, + .shutdown = up_dma_shutdown, + .attach = up_attach, + .detach = up_detach, + .ioctl = up_ioctl, + .receive = up_dma_receive, + .rxint = up_dma_rxint, + .rxavailable = up_dma_rxavailable, +#ifdef CONFIG_SERIAL_IFLOWCONTROL + .rxflowcontrol = up_rxflowcontrol, +#endif + .send = up_send, + .txint = up_dma_txint, + .txready = up_txready, + .txempty = up_txready, + .dmatxavail = up_dma_txavailable, + .dmasend = up_dma_send, +}; +#endif + +#ifdef SERIAL_HAVE_RXDMA_OPS +static const struct uart_ops_s g_uart_rxdma_ops = +{ + .setup = up_dma_setup, + .shutdown = up_dma_shutdown, + .attach = up_attach, + .detach = up_detach, + .ioctl = up_ioctl, + .receive = up_dma_receive, + .rxint = up_dma_rxint, + .rxavailable = up_dma_rxavailable, +#ifdef CONFIG_SERIAL_IFLOWCONTROL + .rxflowcontrol = up_rxflowcontrol, +#endif + .send = up_send, + .txint = up_txint, + .txready = up_txready, + .txempty = up_txready, +}; +#endif + +#ifdef SERIAL_HAVE_TXDMA_OPS +static const struct uart_ops_s g_uart_txdma_ops = +{ + .setup = up_dma_setup, + .shutdown = up_dma_shutdown, + .attach = up_attach, + .detach = up_detach, + .ioctl = up_ioctl, + .receive = up_receive, + .rxint = up_rxint, + .rxavailable = up_rxavailable, +#ifdef CONFIG_SERIAL_IFLOWCONTROL + .rxflowcontrol = up_rxflowcontrol, +#endif + .send = up_send, + .txint = up_dma_txint, + .txready = up_txready, + .txempty = up_txready, + .dmatxavail = up_dma_txavailable, + .dmasend = up_dma_send, +}; +#endif + +/* I/O buffers */ + +#ifdef CONFIG_STM32_USART1_SERIALDRIVER +static char g_usart1rxbuffer[CONFIG_USART1_RXBUFSIZE]; +static char g_usart1txbuffer[CONFIG_USART1_TXBUFSIZE]; +# ifdef CONFIG_USART1_RXDMA +static char g_usart1rxfifo[RXDMA_BUFFER_SIZE]; +# endif +#endif + +#ifdef CONFIG_STM32_USART2_SERIALDRIVER +static char g_usart2rxbuffer[CONFIG_USART2_RXBUFSIZE]; +static char g_usart2txbuffer[CONFIG_USART2_TXBUFSIZE]; +# ifdef CONFIG_USART2_RXDMA +static char g_usart2rxfifo[RXDMA_BUFFER_SIZE]; +# endif +#endif + +#ifdef CONFIG_STM32_USART3_SERIALDRIVER +static char g_usart3rxbuffer[CONFIG_USART3_RXBUFSIZE]; +static char g_usart3txbuffer[CONFIG_USART3_TXBUFSIZE]; +# ifdef CONFIG_USART3_RXDMA +static char g_usart3rxfifo[RXDMA_BUFFER_SIZE]; +# endif +#endif + +#ifdef CONFIG_STM32_UART4_SERIALDRIVER +static char g_uart4rxbuffer[CONFIG_UART4_RXBUFSIZE]; +static char g_uart4txbuffer[CONFIG_UART4_TXBUFSIZE]; +# ifdef CONFIG_UART4_RXDMA +static char g_uart4rxfifo[RXDMA_BUFFER_SIZE]; +# endif +#endif + +#ifdef CONFIG_STM32_UART5_SERIALDRIVER +static char g_uart5rxbuffer[CONFIG_UART5_RXBUFSIZE]; +static char g_uart5txbuffer[CONFIG_UART5_TXBUFSIZE]; +# ifdef CONFIG_UART5_RXDMA +static char g_uart5rxfifo[RXDMA_BUFFER_SIZE]; +# endif +#endif + +#ifdef CONFIG_STM32_USART6_SERIALDRIVER +static char g_usart6rxbuffer[CONFIG_USART6_RXBUFSIZE]; +static char g_usart6txbuffer[CONFIG_USART6_TXBUFSIZE]; +# ifdef CONFIG_USART6_RXDMA +static char g_usart6rxfifo[RXDMA_BUFFER_SIZE]; +# endif +#endif + +#ifdef CONFIG_STM32_UART7_SERIALDRIVER +static char g_uart7rxbuffer[CONFIG_UART7_RXBUFSIZE]; +static char g_uart7txbuffer[CONFIG_UART7_TXBUFSIZE]; +# ifdef CONFIG_UART7_RXDMA +static char g_uart7rxfifo[RXDMA_BUFFER_SIZE]; +# endif +#endif + +#ifdef CONFIG_STM32_UART8_SERIALDRIVER +static char g_uart8rxbuffer[CONFIG_UART8_RXBUFSIZE]; +static char g_uart8txbuffer[CONFIG_UART8_TXBUFSIZE]; +# ifdef CONFIG_UART8_RXDMA +static char g_uart8rxfifo[RXDMA_BUFFER_SIZE]; +# endif +#endif + +/* This describes the state of the STM32 USART1 ports. */ + +#ifdef CONFIG_STM32_USART1_SERIALDRIVER +static struct up_dev_s g_usart1priv = +{ + .dev = + { +#if CONSOLE_UART == 1 + .isconsole = true, +#endif + .recv = + { + .size = CONFIG_USART1_RXBUFSIZE, + .buffer = g_usart1rxbuffer, + }, + .xmit = + { + .size = CONFIG_USART1_TXBUFSIZE, + .buffer = g_usart1txbuffer, + }, +#if defined(CONFIG_USART1_RXDMA) && defined(CONFIG_USART1_TXDMA) + .ops = &g_uart_rxtxdma_ops, +#elif defined(CONFIG_USART1_RXDMA) && !defined(CONFIG_USART1_TXDMA) + .ops = &g_uart_rxdma_ops, +#elif !defined(CONFIG_USART1_RXDMA) && defined(CONFIG_USART1_TXDMA) + .ops = &g_uart_txdma_ops, +#else + .ops = &g_uart_ops, +#endif + .priv = &g_usart1priv, + }, + + .irq = STM32_IRQ_USART1, + .parity = CONFIG_USART1_PARITY, + .bits = CONFIG_USART1_BITS, + .stopbits2 = CONFIG_USART1_2STOP, + .baud = CONFIG_USART1_BAUD, +#if defined(CONFIG_STM32_STM32F33XX) || defined(CONFIG_STM32_STM32F302) + .apbclock = STM32_PCLK1_FREQUENCY, /* Errata 2.5.1 */ +#else + .apbclock = STM32_PCLK2_FREQUENCY, +#endif + .usartbase = STM32_USART1_BASE, + .tx_gpio = GPIO_USART1_TX, + .rx_gpio = GPIO_USART1_RX, +#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_USART1_OFLOWCONTROL) + .oflow = true, + .cts_gpio = GPIO_USART1_CTS, +#endif +#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART1_IFLOWCONTROL) + .iflow = true, + .rts_gpio = GPIO_USART1_RTS, +#endif +#ifdef CONFIG_USART1_TXDMA + .txdma_channel = DMAMAP_USART1_TX, +#endif +#ifdef CONFIG_USART1_RXDMA + .rxdma_channel = DMAMAP_USART1_RX, + .rxfifo = g_usart1rxfifo, +#endif + +#ifdef CONFIG_USART1_RS485 + .rs485_dir_gpio = GPIO_USART1_RS485_DIR, +# if (CONFIG_USART1_RS485_DIR_POLARITY == 0) + .rs485_dir_polarity = false, +# else + .rs485_dir_polarity = true, +# endif +#endif +}; +#endif + +/* This describes the state of the STM32 USART2 port. */ + +#ifdef CONFIG_STM32_USART2_SERIALDRIVER +static struct up_dev_s g_usart2priv = +{ + .dev = + { +#if CONSOLE_UART == 2 + .isconsole = true, +#endif + .recv = + { + .size = CONFIG_USART2_RXBUFSIZE, + .buffer = g_usart2rxbuffer, + }, + .xmit = + { + .size = CONFIG_USART2_TXBUFSIZE, + .buffer = g_usart2txbuffer, + }, +#if defined(CONFIG_USART2_RXDMA) && defined(CONFIG_USART2_TXDMA) + .ops = &g_uart_rxtxdma_ops, +#elif defined(CONFIG_USART2_RXDMA) && !defined(CONFIG_USART2_TXDMA) + .ops = &g_uart_rxdma_ops, +#elif !defined(CONFIG_USART2_RXDMA) && defined(CONFIG_USART2_TXDMA) + .ops = &g_uart_txdma_ops, +#else + .ops = &g_uart_ops, +#endif + .priv = &g_usart2priv, + }, + + .irq = STM32_IRQ_USART2, + .parity = CONFIG_USART2_PARITY, + .bits = CONFIG_USART2_BITS, + .stopbits2 = CONFIG_USART2_2STOP, + .baud = CONFIG_USART2_BAUD, + .apbclock = STM32_PCLK1_FREQUENCY, + .usartbase = STM32_USART2_BASE, + .tx_gpio = GPIO_USART2_TX, + .rx_gpio = GPIO_USART2_RX, +#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_USART2_OFLOWCONTROL) + .oflow = true, + .cts_gpio = GPIO_USART2_CTS, +#endif +#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART2_IFLOWCONTROL) + .iflow = true, + .rts_gpio = GPIO_USART2_RTS, +#endif +#ifdef CONFIG_USART2_TXDMA + .txdma_channel = DMAMAP_USART2_TX, +#endif +#ifdef CONFIG_USART2_RXDMA + .rxdma_channel = DMAMAP_USART2_RX, + .rxfifo = g_usart2rxfifo, +#endif + +#ifdef CONFIG_USART2_RS485 + .rs485_dir_gpio = GPIO_USART2_RS485_DIR, +# if (CONFIG_USART2_RS485_DIR_POLARITY == 0) + .rs485_dir_polarity = false, +# else + .rs485_dir_polarity = true, +# endif +#endif +}; +#endif + +/* This describes the state of the STM32 USART3 port. */ + +#ifdef CONFIG_STM32_USART3_SERIALDRIVER +static struct up_dev_s g_usart3priv = +{ + .dev = + { +#if CONSOLE_UART == 3 + .isconsole = true, +#endif + .recv = + { + .size = CONFIG_USART3_RXBUFSIZE, + .buffer = g_usart3rxbuffer, + }, + .xmit = + { + .size = CONFIG_USART3_TXBUFSIZE, + .buffer = g_usart3txbuffer, + }, +#if defined(CONFIG_USART3_RXDMA) && defined(CONFIG_USART3_TXDMA) + .ops = &g_uart_rxtxdma_ops, +#elif defined(CONFIG_USART3_RXDMA) && !defined(CONFIG_USART3_TXDMA) + .ops = &g_uart_rxdma_ops, +#elif !defined(CONFIG_USART3_RXDMA) && defined(CONFIG_USART3_TXDMA) + .ops = &g_uart_txdma_ops, +#else + .ops = &g_uart_ops, +#endif + .priv = &g_usart3priv, + }, + + .irq = STM32_IRQ_USART3, + .parity = CONFIG_USART3_PARITY, + .bits = CONFIG_USART3_BITS, + .stopbits2 = CONFIG_USART3_2STOP, + .baud = CONFIG_USART3_BAUD, + .apbclock = STM32_PCLK1_FREQUENCY, + .usartbase = STM32_USART3_BASE, + .tx_gpio = GPIO_USART3_TX, + .rx_gpio = GPIO_USART3_RX, +#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_USART3_OFLOWCONTROL) + .oflow = true, + .cts_gpio = GPIO_USART3_CTS, +#endif +#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART3_IFLOWCONTROL) + .iflow = true, + .rts_gpio = GPIO_USART3_RTS, +#endif +#ifdef CONFIG_USART3_TXDMA + .txdma_channel = DMAMAP_USART3_TX, +#endif +#ifdef CONFIG_USART3_RXDMA + .rxdma_channel = DMAMAP_USART3_RX, + .rxfifo = g_usart3rxfifo, +#endif + +#ifdef CONFIG_USART3_RS485 + .rs485_dir_gpio = GPIO_USART3_RS485_DIR, +# if (CONFIG_USART3_RS485_DIR_POLARITY == 0) + .rs485_dir_polarity = false, +# else + .rs485_dir_polarity = true, +# endif +#endif +}; +#endif + +/* This describes the state of the STM32 UART4 port. */ + +#ifdef CONFIG_STM32_UART4_SERIALDRIVER +static struct up_dev_s g_uart4priv = +{ + .dev = + { +#if CONSOLE_UART == 4 + .isconsole = true, +#endif + .recv = + { + .size = CONFIG_UART4_RXBUFSIZE, + .buffer = g_uart4rxbuffer, + }, + .xmit = + { + .size = CONFIG_UART4_TXBUFSIZE, + .buffer = g_uart4txbuffer, + }, +#if defined(CONFIG_UART4_RXDMA) && defined(CONFIG_UART4_TXDMA) + .ops = &g_uart_rxtxdma_ops, +#elif defined(CONFIG_UART4_RXDMA) && !defined(CONFIG_UART4_TXDMA) + .ops = &g_uart_rxdma_ops, +#elif !defined(CONFIG_UART4_RXDMA) && defined(CONFIG_UART4_TXDMA) + .ops = &g_uart_txdma_ops, +#else + .ops = &g_uart_ops, +#endif + .priv = &g_uart4priv, + }, + + .irq = STM32_IRQ_UART4, + .parity = CONFIG_UART4_PARITY, + .bits = CONFIG_UART4_BITS, + .stopbits2 = CONFIG_UART4_2STOP, +#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_UART4_OFLOWCONTROL) + .oflow = true, + .cts_gpio = GPIO_UART4_CTS, +#endif +#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_UART4_IFLOWCONTROL) + .iflow = true, + .rts_gpio = GPIO_UART4_RTS, +#endif + .baud = CONFIG_UART4_BAUD, + .apbclock = STM32_PCLK1_FREQUENCY, + .usartbase = STM32_UART4_BASE, + .tx_gpio = GPIO_UART4_TX, + .rx_gpio = GPIO_UART4_RX, +#ifdef CONFIG_UART4_TXDMA + .txdma_channel = DMAMAP_UART4_TX, +#endif +#ifdef CONFIG_UART4_RXDMA + .rxdma_channel = DMAMAP_UART4_RX, + .rxfifo = g_uart4rxfifo, +#endif + +#ifdef CONFIG_UART4_RS485 + .rs485_dir_gpio = GPIO_UART4_RS485_DIR, +# if (CONFIG_UART4_RS485_DIR_POLARITY == 0) + .rs485_dir_polarity = false, +# else + .rs485_dir_polarity = true, +# endif +#endif +}; +#endif + +/* This describes the state of the STM32 UART5 port. */ + +#ifdef CONFIG_STM32_UART5_SERIALDRIVER +static struct up_dev_s g_uart5priv = +{ + .dev = + { +#if CONSOLE_UART == 5 + .isconsole = true, +#endif + .recv = + { + .size = CONFIG_UART5_RXBUFSIZE, + .buffer = g_uart5rxbuffer, + }, + .xmit = + { + .size = CONFIG_UART5_TXBUFSIZE, + .buffer = g_uart5txbuffer, + }, +#if defined(CONFIG_UART5_RXDMA) && defined(CONFIG_UART5_TXDMA) + .ops = &g_uart_rxtxdma_ops, +#elif defined(CONFIG_UART5_RXDMA) && !defined(CONFIG_UART5_TXDMA) + .ops = &g_uart_rxdma_ops, +#elif !defined(CONFIG_UART5_RXDMA) && defined(CONFIG_UART5_TXDMA) + .ops = &g_uart_txdma_ops, +#else + .ops = &g_uart_ops, +#endif + .priv = &g_uart5priv, + }, + + .irq = STM32_IRQ_UART5, + .parity = CONFIG_UART5_PARITY, + .bits = CONFIG_UART5_BITS, + .stopbits2 = CONFIG_UART5_2STOP, +#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_UART5_OFLOWCONTROL) + .oflow = true, + .cts_gpio = GPIO_UART5_CTS, +#endif +#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_UART5_IFLOWCONTROL) + .iflow = true, + .rts_gpio = GPIO_UART5_RTS, +#endif + .baud = CONFIG_UART5_BAUD, + .apbclock = STM32_PCLK1_FREQUENCY, + .usartbase = STM32_UART5_BASE, + .tx_gpio = GPIO_UART5_TX, + .rx_gpio = GPIO_UART5_RX, +#ifdef CONFIG_UART5_TXDMA + .txdma_channel = DMAMAP_UART5_TX, +#endif +#ifdef CONFIG_UART5_RXDMA + .rxdma_channel = DMAMAP_UART5_RX, + .rxfifo = g_uart5rxfifo, +#endif + +#ifdef CONFIG_UART5_RS485 + .rs485_dir_gpio = GPIO_UART5_RS485_DIR, +# if (CONFIG_UART5_RS485_DIR_POLARITY == 0) + .rs485_dir_polarity = false, +# else + .rs485_dir_polarity = true, +# endif +#endif +}; +#endif + +/* This describes the state of the STM32 USART6 port. */ + +#ifdef CONFIG_STM32_USART6_SERIALDRIVER +static struct up_dev_s g_usart6priv = +{ + .dev = + { +#if CONSOLE_UART == 6 + .isconsole = true, +#endif + .recv = + { + .size = CONFIG_USART6_RXBUFSIZE, + .buffer = g_usart6rxbuffer, + }, + .xmit = + { + .size = CONFIG_USART6_TXBUFSIZE, + .buffer = g_usart6txbuffer, + }, +#if defined(CONFIG_USART6_RXDMA) && defined(CONFIG_USART6_TXDMA) + .ops = &g_uart_rxtxdma_ops, +#elif defined(CONFIG_USART6_RXDMA) && !defined(CONFIG_USART6_TXDMA) + .ops = &g_uart_rxdma_ops, +#elif !defined(CONFIG_USART6_RXDMA) && defined(CONFIG_USART6_TXDMA) + .ops = &g_uart_txdma_ops, +#else + .ops = &g_uart_ops, +#endif + .priv = &g_usart6priv, + }, + + .irq = STM32_IRQ_USART6, + .parity = CONFIG_USART6_PARITY, + .bits = CONFIG_USART6_BITS, + .stopbits2 = CONFIG_USART6_2STOP, + .baud = CONFIG_USART6_BAUD, + .apbclock = STM32_PCLK2_FREQUENCY, + .usartbase = STM32_USART6_BASE, + .tx_gpio = GPIO_USART6_TX, + .rx_gpio = GPIO_USART6_RX, +#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_USART6_OFLOWCONTROL) + .oflow = true, + .cts_gpio = GPIO_USART6_CTS, +#endif +#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART6_IFLOWCONTROL) + .iflow = true, + .rts_gpio = GPIO_USART6_RTS, +#endif +#ifdef CONFIG_USART6_TXDMA + .txdma_channel = DMAMAP_USART6_TX, +#endif +#ifdef CONFIG_USART6_RXDMA + .rxdma_channel = DMAMAP_USART6_RX, + .rxfifo = g_usart6rxfifo, +#endif + +#ifdef CONFIG_USART6_RS485 + .rs485_dir_gpio = GPIO_USART6_RS485_DIR, +# if (CONFIG_USART6_RS485_DIR_POLARITY == 0) + .rs485_dir_polarity = false, +# else + .rs485_dir_polarity = true, +# endif +#endif +}; +#endif + +/* This describes the state of the STM32 UART7 port. */ + +#ifdef CONFIG_STM32_UART7_SERIALDRIVER +static struct up_dev_s g_uart7priv = +{ + .dev = + { +#if CONSOLE_UART == 7 + .isconsole = true, +#endif + .recv = + { + .size = CONFIG_UART7_RXBUFSIZE, + .buffer = g_uart7rxbuffer, + }, + .xmit = + { + .size = CONFIG_UART7_TXBUFSIZE, + .buffer = g_uart7txbuffer, + }, +#if defined(CONFIG_UART7_RXDMA) && defined(CONFIG_UART7_TXDMA) + .ops = &g_uart_rxtxdma_ops, +#elif defined(CONFIG_UART7_RXDMA) && !defined(CONFIG_UART7_TXDMA) + .ops = &g_uart_rxdma_ops, +#elif !defined(CONFIG_UART7_RXDMA) && defined(CONFIG_UART7_TXDMA) + .ops = &g_uart_txdma_ops, +#else + .ops = &g_uart_ops, +#endif + .priv = &g_uart7priv, + }, + + .irq = STM32_IRQ_UART7, + .parity = CONFIG_UART7_PARITY, + .bits = CONFIG_UART7_BITS, + .stopbits2 = CONFIG_UART7_2STOP, + .baud = CONFIG_UART7_BAUD, + .apbclock = STM32_PCLK1_FREQUENCY, + .usartbase = STM32_UART7_BASE, + .tx_gpio = GPIO_UART7_TX, + .rx_gpio = GPIO_UART7_RX, +#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_UART7_OFLOWCONTROL) + .oflow = true, + .cts_gpio = GPIO_UART7_CTS, +#endif +#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_UART7_IFLOWCONTROL) + .iflow = true, + .rts_gpio = GPIO_UART7_RTS, +#endif +#ifdef CONFIG_UART7_TXDMA + .txdma_channel = DMAMAP_UART7_TX, +#endif +#ifdef CONFIG_UART7_RXDMA + .rxdma_channel = DMAMAP_UART7_RX, + .rxfifo = g_uart7rxfifo, +#endif + +#ifdef CONFIG_UART7_RS485 + .rs485_dir_gpio = GPIO_UART7_RS485_DIR, +# if (CONFIG_UART7_RS485_DIR_POLARITY == 0) + .rs485_dir_polarity = false, +# else + .rs485_dir_polarity = true, +# endif +#endif +}; +#endif + +/* This describes the state of the STM32 UART8 port. */ + +#ifdef CONFIG_STM32_UART8_SERIALDRIVER +static struct up_dev_s g_uart8priv = +{ + .dev = + { +#if CONSOLE_UART == 8 + .isconsole = true, +#endif + .recv = + { + .size = CONFIG_UART8_RXBUFSIZE, + .buffer = g_uart8rxbuffer, + }, + .xmit = + { + .size = CONFIG_UART8_TXBUFSIZE, + .buffer = g_uart8txbuffer, + }, +#if defined(CONFIG_UART8_RXDMA) && defined(CONFIG_UART8_TXDMA) + .ops = &g_uart_rxtxdma_ops, +#elif defined(CONFIG_UART8_RXDMA) && !defined(CONFIG_UART8_TXDMA) + .ops = &g_uart_rxdma_ops, +#elif !defined(CONFIG_UART8_RXDMA) && defined(CONFIG_UART8_TXDMA) + .ops = &g_uart_txdma_ops, +#else + .ops = &g_uart_ops, +#endif + .priv = &g_uart8priv, + }, + + .irq = STM32_IRQ_UART8, + .parity = CONFIG_UART8_PARITY, + .bits = CONFIG_UART8_BITS, + .stopbits2 = CONFIG_UART8_2STOP, + .baud = CONFIG_UART8_BAUD, + .apbclock = STM32_PCLK1_FREQUENCY, + .usartbase = STM32_UART8_BASE, + .tx_gpio = GPIO_UART8_TX, + .rx_gpio = GPIO_UART8_RX, +#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_UART8_OFLOWCONTROL) + .oflow = true, + .cts_gpio = GPIO_UART8_CTS, +#endif +#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_UART8_IFLOWCONTROL) + .iflow = true, + .rts_gpio = GPIO_UART8_RTS, +#endif +#ifdef CONFIG_UART8_TXDMA + .txdma_channel = DMAMAP_UART8_TX, +#endif +#ifdef CONFIG_UART8_RXDMA + .rxdma_channel = DMAMAP_UART8_RX, + .rxfifo = g_uart8rxfifo, +#endif + +#ifdef CONFIG_UART8_RS485 + .rs485_dir_gpio = GPIO_UART8_RS485_DIR, +# if (CONFIG_UART8_RS485_DIR_POLARITY == 0) + .rs485_dir_polarity = false, +# else + .rs485_dir_polarity = true, +# endif +#endif +}; +#endif + +/* This table lets us iterate over the configured USARTs */ + +static struct up_dev_s * const g_uart_devs[STM32_NUSART] = +{ +#ifdef CONFIG_STM32_USART1_SERIALDRIVER + [0] = &g_usart1priv, +#endif +#ifdef CONFIG_STM32_USART2_SERIALDRIVER + [1] = &g_usart2priv, +#endif +#ifdef CONFIG_STM32_USART3_SERIALDRIVER + [2] = &g_usart3priv, +#endif +#ifdef CONFIG_STM32_UART4_SERIALDRIVER + [3] = &g_uart4priv, +#endif +#ifdef CONFIG_STM32_UART5_SERIALDRIVER + [4] = &g_uart5priv, +#endif +#ifdef CONFIG_STM32_USART6_SERIALDRIVER + [5] = &g_usart6priv, +#endif +#ifdef CONFIG_STM32_UART7_SERIALDRIVER + [6] = &g_uart7priv, +#endif +#ifdef CONFIG_STM32_UART8_SERIALDRIVER + [7] = &g_uart8priv, +#endif +}; + +#ifdef CONFIG_PM +static struct pm_callback_s g_serialcb = +{ + .notify = up_pm_notify, + .prepare = up_pm_prepare, +}; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_serialin + ****************************************************************************/ + +static inline uint32_t up_serialin(struct up_dev_s *priv, int offset) +{ + return getreg32(priv->usartbase + offset); +} + +/**************************************************************************** + * Name: up_serialout + ****************************************************************************/ + +static inline void up_serialout(struct up_dev_s *priv, int offset, + uint32_t value) +{ + putreg32(value, priv->usartbase + offset); +} + +/**************************************************************************** + * Name: up_setusartint + ****************************************************************************/ + +static inline void up_setusartint(struct up_dev_s *priv, uint16_t ie) +{ + uint32_t cr; + + /* Save the interrupt mask */ + + priv->ie = ie; + + /* And restore the interrupt state (see the interrupt enable/usage + * table above) + */ + + cr = up_serialin(priv, STM32_USART_CR1_OFFSET); + cr &= ~(USART_CR1_USED_INTS); + cr |= (ie & (USART_CR1_USED_INTS)); + up_serialout(priv, STM32_USART_CR1_OFFSET, cr); + + cr = up_serialin(priv, STM32_USART_CR3_OFFSET); + cr &= ~USART_CR3_EIE; + cr |= (ie & USART_CR3_EIE); + up_serialout(priv, STM32_USART_CR3_OFFSET, cr); +} + +/**************************************************************************** + * Name: up_restoreusartint + ****************************************************************************/ + +static void up_restoreusartint(struct up_dev_s *priv, uint16_t ie) +{ + irqstate_t flags; + + flags = enter_critical_section(); + + up_setusartint(priv, ie); + + leave_critical_section(flags); +} + +/**************************************************************************** + * Name: up_disableusartint + ****************************************************************************/ + +static void up_disableusartint(struct up_dev_s *priv, uint16_t *ie) +{ + irqstate_t flags; + + flags = enter_critical_section(); + + if (ie) + { + uint32_t cr1; + uint32_t cr3; + + /* USART interrupts: + * + * Enable Status Meaning Usage + * ------------------ --------------- ---------------------- ---------- + * USART_CR1_IDLEIE USART_SR_IDLE Idle Line Detected (not used) + * USART_CR1_RXNEIE USART_SR_RXNE Rx Data Ready + * " " USART_SR_ORE Overrun Error Detected + * USART_CR1_TCIE USART_SR_TC Transmission Complete (RS-485) + * USART_CR1_TXEIE USART_SR_TXE Tx Data Register Empty + * USART_CR1_PEIE USART_SR_PE Parity Error + * + * USART_CR2_LBDIE USART_SR_LBD Break Flag (not used) + * USART_CR3_EIE USART_SR_FE Framing Error + * " " USART_SR_NE Noise Error + * " " USART_SR_ORE Overrun Error Detected + * USART_CR3_CTSIE USART_SR_CTS CTS flag (not used) + */ + + cr1 = up_serialin(priv, STM32_USART_CR1_OFFSET); + cr3 = up_serialin(priv, STM32_USART_CR3_OFFSET); + + /* Return the current interrupt mask value for the used interrupts. + * Notice that this depends on the fact that none of the used interrupt + * enable bits overlap. This logic would fail if we needed the break + * interrupt! + */ + + *ie = (cr1 & (USART_CR1_USED_INTS)) | (cr3 & USART_CR3_EIE); + } + + /* Disable all interrupts */ + + up_setusartint(priv, 0); + + leave_critical_section(flags); +} + +/**************************************************************************** + * Name: up_dma_nextrx + * + * Description: + * Returns the index into the RX FIFO where the DMA will place the next + * byte that it receives. + * + ****************************************************************************/ + +#ifdef SERIAL_HAVE_RXDMA +static int up_dma_nextrx(struct up_dev_s *priv) +{ + size_t dmaresidual; + + dmaresidual = stm32_dmaresidual(priv->rxdma); + + return (RXDMA_BUFFER_SIZE - (int)dmaresidual); +} +#endif + +/**************************************************************************** + * Name: up_set_format + * + * Description: + * Set the serial line format and speed. + * + ****************************************************************************/ + +#ifndef CONFIG_SUPPRESS_UART_CONFIG +static void up_set_format(struct uart_dev_s *dev) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; +#if defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F33XX) || \ + defined(CONFIG_STM32_STM32F37XX) || defined(CONFIG_STM32_STM32G4XXX) + uint32_t usartdiv8; +#else + uint32_t usartdiv32; + uint32_t mantissa; + uint32_t fraction; +#endif + uint32_t regval; + uint32_t brr; + + /* Load CR1 */ + + regval = up_serialin(priv, STM32_USART_CR1_OFFSET); + +#if defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F33XX)|| \ + defined(CONFIG_STM32_STM32F37XX) || defined(CONFIG_STM32_STM32G4XXX) + /* This first implementation is for U[S]ARTs that support oversampling + * by 8 in additional to the standard oversampling by 16. + * With baud rate of fCK / Divider for oversampling by 16. + * and baud rate of 2 * fCK / Divider for oversampling by 8 + * + * In case of oversampling by 8, the equation is: + * + * baud = 2 * fCK / usartdiv8 + * usartdiv8 = 2 * fCK / baud + */ + + usartdiv8 = ((priv->apbclock << 1) + (priv->baud >> 1)) / priv->baud; + + /* Baud rate for standard USART (SPI mode included): + * + * In case of oversampling by 16, the equation is: + * baud = fCK / usartdiv16 + * usartdiv16 = fCK / baud + * = 2 * usartdiv8 + * + * Use oversamply by 8 only if the divisor is small. But what is small? + */ + + if (usartdiv8 > 100) + { + /* Use usartdiv16 */ + + brr = (usartdiv8 + 1) >> 1; + + /* Clear oversampling by 8 to enable oversampling by 16 */ + + regval &= ~USART_CR1_OVER8; + } + else + { + DEBUGASSERT(usartdiv8 >= 8); + + /* Perform mysterious operations on bits 0-3 */ + + brr = ((usartdiv8 & 0xfff0) | ((usartdiv8 & 0x000f) >> 1)); + + /* Set oversampling by 8 */ + + regval |= USART_CR1_OVER8; + } + +#else + /* This second implementation is for U[S]ARTs that support fractional + * dividers. + * + * Configure the USART Baud Rate. The baud rate for the receiver and + * transmitter (Rx and Tx) are both set to the same value as programmed + * in the Mantissa and Fraction values of USARTDIV. + * + * baud = fCK / (16 * usartdiv) + * usartdiv = fCK / (16 * baud) + * + * Where fCK is the input clock to the peripheral (PCLK1 for USART2, 3, + * 4, 5 or PCLK2 for USART1) + * + * First calculate (NOTE: all standard baud values are even so dividing by + * two does not lose precision): + * + * usartdiv32 = 32 * usartdiv = fCK / (baud/2) + */ + + usartdiv32 = priv->apbclock / (priv->baud >> 1); + + /* The mantissa part is then */ + + mantissa = usartdiv32 >> 5; + + /* The fractional remainder (with rounding) */ + + fraction = (usartdiv32 - (mantissa << 5) + 1) >> 1; + +#if defined(CONFIG_STM32_STM32F4XXX) + /* The F4 supports 8 X in oversampling additional to the + * standard oversampling by 16. + * + * With baud rate of fCK / (16 * Divider) for oversampling by 16. + * and baud rate of fCK / (8 * Divider) for oversampling by 8 + */ + + /* Check if 8x oversampling is necessary */ + + if (mantissa == 0) + { + regval |= USART_CR1_OVER8; + + /* Rescale the mantissa */ + + mantissa = usartdiv32 >> 4; + + /* The fractional remainder (with rounding) */ + + fraction = (usartdiv32 - (mantissa << 4) + 1) >> 1; + } + else + { + /* Use 16x Oversampling */ + + regval &= ~USART_CR1_OVER8; + } +#endif + + brr = mantissa << USART_BRR_MANT_SHIFT; + brr |= fraction << USART_BRR_FRAC_SHIFT; +#endif + + up_serialout(priv, STM32_USART_CR1_OFFSET, regval); + up_serialout(priv, STM32_USART_BRR_OFFSET, brr); + + /* Configure parity mode */ + + regval &= ~(USART_CR1_PCE | USART_CR1_PS | USART_CR1_M); + + if (priv->parity == 1) /* Odd parity */ + { + regval |= (USART_CR1_PCE | USART_CR1_PS); + } + else if (priv->parity == 2) /* Even parity */ + { + regval |= USART_CR1_PCE; + } + + /* Configure word length (parity uses one of configured bits) + * + * Default: 1 start, 8 data (no parity), n stop, OR + * 1 start, 7 data + parity, n stop + */ + + if (priv->bits == 9 || (priv->bits == 8 && priv->parity != 0)) + { + /* Select: 1 start, 8 data + parity, n stop, OR + * 1 start, 9 data (no parity), n stop. + */ + + regval |= USART_CR1_M; + } + + up_serialout(priv, STM32_USART_CR1_OFFSET, regval); + + /* Configure STOP bits */ + + regval = up_serialin(priv, STM32_USART_CR2_OFFSET); + regval &= ~(USART_CR2_STOP_MASK); + + if (priv->stopbits2) + { + regval |= USART_CR2_STOP2; + } + + up_serialout(priv, STM32_USART_CR2_OFFSET, regval); + + /* Configure hardware flow control */ + + regval = up_serialin(priv, STM32_USART_CR3_OFFSET); + regval &= ~(USART_CR3_CTSE | USART_CR3_RTSE); + +#if defined(CONFIG_SERIAL_IFLOWCONTROL) && \ + !defined(CONFIG_STM32_FLOWCONTROL_BROKEN) + if (priv->iflow && (priv->rts_gpio != 0)) + { + regval |= USART_CR3_RTSE; + } +#endif + +#ifdef CONFIG_SERIAL_OFLOWCONTROL + if (priv->oflow && (priv->cts_gpio != 0)) + { + regval |= USART_CR3_CTSE; + } +#endif + + up_serialout(priv, STM32_USART_CR3_OFFSET, regval); +} +#endif /* CONFIG_SUPPRESS_UART_CONFIG */ + +/**************************************************************************** + * Name: up_set_apb_clock + * + * Description: + * Enable or disable APB clock for the USART peripheral + * + * Input Parameters: + * dev - A reference to the UART driver state structure + * on - Enable clock if 'on' is 'true' and disable if 'false' + * + ****************************************************************************/ + +static void up_set_apb_clock(struct uart_dev_s *dev, bool on) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + uint32_t rcc_en; + uint32_t regaddr; + + /* Determine which USART to configure */ + + switch (priv->usartbase) + { + default: + return; +#ifdef CONFIG_STM32_USART1_SERIALDRIVER + case STM32_USART1_BASE: + rcc_en = RCC_APB2ENR_USART1EN; + regaddr = STM32_RCC_APB2ENR; + break; +#endif +#ifdef CONFIG_STM32_USART2_SERIALDRIVER + case STM32_USART2_BASE: + rcc_en = RCC_APB1ENR_USART2EN; + regaddr = STM32_RCC_APB1ENR; + break; +#endif +#ifdef CONFIG_STM32_USART3_SERIALDRIVER + case STM32_USART3_BASE: + rcc_en = RCC_APB1ENR_USART3EN; + regaddr = STM32_RCC_APB1ENR; + break; +#endif +#ifdef CONFIG_STM32_UART4_SERIALDRIVER + case STM32_UART4_BASE: + rcc_en = RCC_APB1ENR_UART4EN; + regaddr = STM32_RCC_APB1ENR; + break; +#endif +#ifdef CONFIG_STM32_UART5_SERIALDRIVER + case STM32_UART5_BASE: + rcc_en = RCC_APB1ENR_UART5EN; + regaddr = STM32_RCC_APB1ENR; + break; +#endif +#ifdef CONFIG_STM32_USART6_SERIALDRIVER + case STM32_USART6_BASE: + rcc_en = RCC_APB2ENR_USART6EN; + regaddr = STM32_RCC_APB2ENR; + break; +#endif +#ifdef CONFIG_STM32_UART7_SERIALDRIVER + case STM32_UART7_BASE: + rcc_en = RCC_APB1ENR_UART7EN; + regaddr = STM32_RCC_APB1ENR; + break; +#endif +#ifdef CONFIG_STM32_UART8_SERIALDRIVER + case STM32_UART8_BASE: + rcc_en = RCC_APB1ENR_UART8EN; + regaddr = STM32_RCC_APB1ENR; + break; +#endif + } + + /* Enable/disable APB 1/2 clock for USART */ + + if (on) + { + modifyreg32(regaddr, 0, rcc_en); + } + else + { + modifyreg32(regaddr, rcc_en, 0); + } +} + +/**************************************************************************** + * Name: up_setup + * + * Description: + * Configure the USART baud, bits, parity, etc. This method is called the + * first time that the serial port is opened. + * + ****************************************************************************/ + +static int up_setup(struct uart_dev_s *dev) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + +#ifndef CONFIG_SUPPRESS_UART_CONFIG + uint32_t regval; + + /* Note: The logic here depends on the fact that that the USART module + * was enabled in stm32_lowsetup(). + */ + + /* Enable USART APB1/2 clock */ + + up_set_apb_clock(dev, true); + + /* Configure pins for USART use */ + + stm32_configgpio(priv->tx_gpio); + stm32_configgpio(priv->rx_gpio); + +#ifdef CONFIG_SERIAL_OFLOWCONTROL + if (priv->cts_gpio != 0) + { + stm32_configgpio(priv->cts_gpio); + } +#endif + +#ifdef CONFIG_SERIAL_IFLOWCONTROL + if (priv->rts_gpio != 0) + { + uint32_t config = priv->rts_gpio; + +#ifdef CONFIG_STM32_FLOWCONTROL_BROKEN + /* Instead of letting hw manage this pin, we will bitbang */ + + config = (config & ~GPIO_MODE_MASK) | GPIO_OUTPUT; +#endif + stm32_configgpio(config); + } +#endif + +#ifdef HAVE_RS485 + if (priv->rs485_dir_gpio != 0) + { + stm32_configgpio(priv->rs485_dir_gpio); + stm32_gpiowrite(priv->rs485_dir_gpio, !priv->rs485_dir_polarity); + } +#endif + + /* Configure CR2 + * Clear STOP, CLKEN, CPOL, CPHA, LBCL, and interrupt enable bits + */ + + regval = up_serialin(priv, STM32_USART_CR2_OFFSET); + regval &= ~(USART_CR2_STOP_MASK | USART_CR2_CLKEN | USART_CR2_CPOL | + USART_CR2_CPHA | USART_CR2_LBCL | USART_CR2_LBDIE); + + /* Configure STOP bits */ + + if (priv->stopbits2) + { + regval |= USART_CR2_STOP2; + } + + up_serialout(priv, STM32_USART_CR2_OFFSET, regval); + + /* Configure CR1 + * Clear TE, REm and all interrupt enable bits + */ + + regval = up_serialin(priv, STM32_USART_CR1_OFFSET); + regval &= ~(USART_CR1_TE | USART_CR1_RE | USART_CR1_ALLINTS); + + up_serialout(priv, STM32_USART_CR1_OFFSET, regval); + + /* Configure CR3 + * Clear CTSE, RTSE, and all interrupt enable bits + */ + + regval = up_serialin(priv, STM32_USART_CR3_OFFSET); + regval &= ~(USART_CR3_CTSIE | USART_CR3_CTSE | USART_CR3_RTSE | + USART_CR3_EIE); + + up_serialout(priv, STM32_USART_CR3_OFFSET, regval); + + /* Configure the USART line format and speed. */ + + up_set_format(dev); + + /* Enable Rx, Tx, and the USART */ + + regval = up_serialin(priv, STM32_USART_CR1_OFFSET); + regval |= (USART_CR1_UE | USART_CR1_TE | USART_CR1_RE); + up_serialout(priv, STM32_USART_CR1_OFFSET, regval); + +#endif /* CONFIG_SUPPRESS_UART_CONFIG */ + + /* Set up the cached interrupt enables value */ + + priv->ie = 0; + + /* Mark device as initialized. */ + + priv->initialized = true; + + return OK; +} + +/**************************************************************************** + * Name: up_dma_setup + * + * Description: + * Configure the USART baud, bits, parity, etc. This method is called the + * first time that the serial port is opened. + * + ****************************************************************************/ + +#if defined(SERIAL_HAVE_RXDMA) || defined(SERIAL_HAVE_TXDMA) +static int up_dma_setup(struct uart_dev_s *dev) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + int result; + + /* Do the basic UART setup first, unless we are the console */ + + if (!dev->isconsole) + { + result = up_setup(dev); + if (result != OK) + { + return result; + } + } + +#if defined(SERIAL_HAVE_TXDMA) + /* Acquire the Tx DMA channel. This should always succeed. */ + + if (priv->txdma_channel != INVALID_SERIAL_DMA_CHANNEL) + { + priv->txdma = stm32_dmachannel(priv->txdma_channel); + + /* Enable receive Tx DMA for the UART */ + + modifyreg32(priv->usartbase + STM32_USART_CR3_OFFSET, + 0, USART_CR3_DMAT); + } +#endif + +#if defined(SERIAL_HAVE_RXDMA) + /* Acquire the DMA channel. This should always succeed. */ + + if (priv->rxdma_channel != INVALID_SERIAL_DMA_CHANNEL) + { + priv->rxdma = stm32_dmachannel(priv->rxdma_channel); + + /* Configure for circular DMA reception into the RX fifo */ + + stm32_dmasetup(priv->rxdma, + priv->usartbase + STM32_USART_RDR_OFFSET, + (uint32_t)priv->rxfifo, + RXDMA_BUFFER_SIZE, + SERIAL_RXDMA_CONTROL_WORD); + + /* Reset our DMA shadow pointer to match the address just + * programmed above. + */ + + priv->rxdmanext = 0; + + /* Enable receive Rx DMA for the UART */ + + modifyreg32(priv->usartbase + STM32_USART_CR3_OFFSET, + 0, USART_CR3_DMAR); + + /* Start the DMA channel, and arrange for callbacks at the half and + * full points in the FIFO. This ensures that we have half a FIFO + * worth of time to claim bytes before they are overwritten. + */ + + stm32_dmastart(priv->rxdma, up_dma_rxcallback, (void *)priv, true); + } +#endif + + return OK; +} +#endif + +/**************************************************************************** + * Name: up_shutdown + * + * Description: + * Disable the USART. This method is called when the serial + * port is closed + * + ****************************************************************************/ + +static void up_shutdown(struct uart_dev_s *dev) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + uint32_t regval; + + /* Mark device as uninitialized. */ + + priv->initialized = false; + + /* Disable all interrupts */ + + up_disableusartint(priv, NULL); + + /* Disable USART APB1/2 clock */ + + up_set_apb_clock(dev, false); + + /* Disable Rx, Tx, and the UART */ + + regval = up_serialin(priv, STM32_USART_CR1_OFFSET); + regval &= ~(USART_CR1_UE | USART_CR1_TE | USART_CR1_RE); + up_serialout(priv, STM32_USART_CR1_OFFSET, regval); + + /* Release pins. "If the serial-attached device is powered down, the TX + * pin causes back-powering, potentially confusing the device to the point + * of complete lock-up." + * + * REVISIT: Is unconfiguring the pins appropriate for all device? If not, + * then this may need to be a configuration option. + */ + + stm32_unconfiggpio(priv->tx_gpio); + stm32_unconfiggpio(priv->rx_gpio); + +#ifdef CONFIG_SERIAL_OFLOWCONTROL + if (priv->cts_gpio != 0) + { + stm32_unconfiggpio(priv->cts_gpio); + } +#endif + +#ifdef CONFIG_SERIAL_IFLOWCONTROL + if (priv->rts_gpio != 0) + { + stm32_unconfiggpio(priv->rts_gpio); + } +#endif + +#ifdef HAVE_RS485 + if (priv->rs485_dir_gpio != 0) + { + stm32_unconfiggpio(priv->rs485_dir_gpio); + } +#endif +} + +/**************************************************************************** + * Name: up_dma_shutdown + * + * Description: + * Disable the USART. This method is called when the serial + * port is closed + * + ****************************************************************************/ + +#if defined(SERIAL_HAVE_RXDMA) || defined(SERIAL_HAVE_TXDMA) +static void up_dma_shutdown(struct uart_dev_s *dev) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + + /* Perform the normal UART shutdown */ + + up_shutdown(dev); + +#if defined(SERIAL_HAVE_RXDMA) + /* Stop the RX DMA channel */ + + if (priv->rxdma_channel != INVALID_SERIAL_DMA_CHANNEL) + { + stm32_dmastop(priv->rxdma); + + /* Release the RX DMA channel */ + + stm32_dmafree(priv->rxdma); + priv->rxdma = NULL; + } +#endif + +#if defined(SERIAL_HAVE_TXDMA) + /* Stop the TX DMA channel */ + + if (priv->txdma_channel != INVALID_SERIAL_DMA_CHANNEL) + { + stm32_dmastop(priv->txdma); + + /* Release the TX DMA channel */ + + stm32_dmafree(priv->txdma); + priv->txdma = NULL; + } +#endif +} +#endif + +/**************************************************************************** + * Name: up_attach + * + * Description: + * Configure the USART to operation in interrupt driven mode. This method + * is called when the serial port is opened. Normally, this is just after + * the setup() method is called, however, the serial console may operate + * in a non-interrupt driven mode during the boot phase. + * + * RX and TX interrupts are not enabled when by the attach method (unless + * the hardware supports multiple levels of interrupt enabling). The RX + * and TX interrupts are not enabled until the txint() and rxint() methods + * are called. + * + ****************************************************************************/ + +static int up_attach(struct uart_dev_s *dev) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + int ret; + + /* Attach and enable the IRQ */ + + ret = irq_attach(priv->irq, up_interrupt, priv); + if (ret == OK) + { + /* Enable the interrupt (RX and TX interrupts are still disabled + * in the USART + */ + + up_enable_irq(priv->irq); + } + + return ret; +} + +/**************************************************************************** + * Name: up_detach + * + * Description: + * Detach USART interrupts. This method is called when the serial port is + * closed normally just before the shutdown method is called. The + * exception is the serial console which is never shutdown. + * + ****************************************************************************/ + +static void up_detach(struct uart_dev_s *dev) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + up_disable_irq(priv->irq); + irq_detach(priv->irq); +} + +/**************************************************************************** + * Name: up_interrupt + * + * Description: + * This is the USART interrupt handler. It will be invoked when an + * interrupt received on the 'irq' It should call uart_transmitchars or + * uart_receivechar to perform the appropriate data transfers. The + * interrupt handling logic must be able to map the 'irq' number into the + * appropriate uart_dev_s structure in order to call these functions. + * + ****************************************************************************/ + +static int up_interrupt(int irq, void *context, void *arg) +{ + struct up_dev_s *priv = (struct up_dev_s *)arg; + int passes; + bool handled; + + DEBUGASSERT(priv != NULL); + + /* Report serial activity to the power management logic */ + +#if defined(CONFIG_PM) && CONFIG_STM32_PM_SERIAL_ACTIVITY > 0 + pm_activity(PM_IDLE_DOMAIN, CONFIG_STM32_PM_SERIAL_ACTIVITY); +#endif + + /* Loop until there are no characters to be transferred or, + * until we have been looping for a long time. + */ + + handled = true; + for (passes = 0; passes < 256 && handled; passes++) + { + handled = false; + + /* Get the masked USART status word. */ + + priv->sr = up_serialin(priv, STM32_USART_SR_OFFSET); + + /* USART interrupts: + * + * Enable Status Meaning Usage + * ------------------ --------------- ---------------------- ---------- + * USART_CR1_IDLEIE USART_SR_IDLE Idle Line Detected (not used) + * USART_CR1_RXNEIE USART_SR_RXNE Rx Data Ready + * " " USART_SR_ORE Overrun Error Detected + * USART_CR1_TCIE USART_SR_TC Tx Complete (RS-485) + * USART_CR1_TXEIE USART_SR_TXE Tx Data Register Empty + * USART_CR1_PEIE USART_SR_PE Parity Error + * + * USART_CR2_LBDIE USART_SR_LBD Break Flag (not used) + * USART_CR3_EIE USART_SR_FE Framing Error + * " " USART_SR_NE Noise Error + * " " USART_SR_ORE Overrun Error Detected + * USART_CR3_CTSIE USART_SR_CTS CTS flag (not used) + * + * NOTE: Some of these status bits must be cleared by explicitly + * writing zero to the SR register: USART_SR_CTS, USART_SR_LBD. Note of + * those are currently being used. + */ + +#ifdef HAVE_RS485 + /* Transmission of whole buffer is over - TC is set, TXEIE is cleared. + * Note - this should be first, to have the most recent TC bit value + * from SR register - sending data affects TC, but without refresh we + * will not know that... + */ + + if (((priv->sr & USART_SR_TC) != 0) && + ((priv->ie & USART_CR1_TCIE) != 0) && + ((priv->ie & USART_CR1_TXEIE) == 0)) + { + stm32_gpiowrite(priv->rs485_dir_gpio, !priv->rs485_dir_polarity); + up_restoreusartint(priv, priv->ie & ~USART_CR1_TCIE); + } +#endif + + /* Handle incoming, receive bytes. */ + + if (((priv->sr & USART_SR_RXNE) != 0) && + ((priv->ie & USART_CR1_RXNEIE) != 0)) + { + /* Received data ready... process incoming bytes. NOTE the check + * for RXNEIE: We cannot call uart_recvchards of RX interrupts are + * disabled. + */ + + uart_recvchars(&priv->dev); + handled = true; + } + + /* We may still have to read from the DR register to clear any pending + * error conditions. + */ + + else if ((priv->sr & (USART_SR_ORE | USART_SR_NE | USART_SR_FE)) != 0) + { +#if defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F33XX) || \ + defined(CONFIG_STM32_STM32F37XX) || defined(CONFIG_STM32_STM32G4XXX) + /* These errors are cleared by writing the corresponding bit to the + * interrupt clear register (ICR). + */ + + up_serialout(priv, STM32_USART_ICR_OFFSET, + (USART_ICR_NCF | USART_ICR_ORECF | USART_ICR_FECF)); +#else + /* If an error occurs, read from DR to clear the error (data has + * been lost). If ORE is set along with RXNE then it tells you + * that the byte *after* the one in the data register has been + * lost, but the data register value is correct. That case will + * be handled above if interrupts are enabled. Otherwise, that + * good byte will be lost. + */ + + up_serialin(priv, STM32_USART_RDR_OFFSET); +#endif + } + + /* Handle outgoing, transmit bytes */ + + if (((priv->sr & USART_SR_TXE) != 0) && + ((priv->ie & USART_CR1_TXEIE) != 0)) + { + /* Transmit data register empty ... process outgoing bytes */ + + uart_xmitchars(&priv->dev); + handled = true; + } + } + + return OK; +} + +/**************************************************************************** + * Name: up_ioctl + * + * Description: + * All ioctl calls will be routed through this method + * + ****************************************************************************/ + +static int up_ioctl(struct file *filep, int cmd, unsigned long arg) +{ +#if defined(CONFIG_SERIAL_TERMIOS) || defined(CONFIG_SERIAL_TIOCSERGSTRUCT) \ + || defined(CONFIG_STM32_SERIALBRK_BSDCOMPAT) + struct inode *inode = filep->f_inode; + struct uart_dev_s *dev = inode->i_private; +#endif +#if defined(CONFIG_SERIAL_TERMIOS) || defined(CONFIG_STM32_SERIALBRK_BSDCOMPAT) + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; +#endif + int ret = OK; + + switch (cmd) + { +#ifdef CONFIG_SERIAL_TIOCSERGSTRUCT + case TIOCSERGSTRUCT: + { + struct up_dev_s *user = (struct up_dev_s *)arg; + if (!user) + { + ret = -EINVAL; + } + else + { + memcpy(user, dev, sizeof(struct up_dev_s)); + } + } + break; +#endif + +#ifdef CONFIG_STM32_USART_SINGLEWIRE + case TIOCSSINGLEWIRE: + { + /* Change the TX port to be open-drain/push-pull and enable/disable + * half-duplex mode. + */ + + uint32_t cr = up_serialin(priv, STM32_USART_CR3_OFFSET); + +#if defined(CONFIG_STM32_STM32F10XX) + if ((arg & SER_SINGLEWIRE_ENABLED) != 0) + { + stm32_configgpio((priv->tx_gpio & ~(GPIO_CNF_MASK)) | + GPIO_CNF_AFOD); + cr |= USART_CR3_HDSEL; + } + else + { + stm32_configgpio((priv->tx_gpio & ~(GPIO_CNF_MASK)) | + GPIO_CNF_AFPP); + cr &= ~USART_CR3_HDSEL; + } +#else + if ((arg & SER_SINGLEWIRE_ENABLED) != 0) + { + uint32_t gpio_val = (arg & SER_SINGLEWIRE_PUSHPULL) == + SER_SINGLEWIRE_PUSHPULL ? + GPIO_PUSHPULL : GPIO_OPENDRAIN; + gpio_val |= ((arg & SER_SINGLEWIRE_PULL_MASK) == + SER_SINGLEWIRE_PULLUP) ? GPIO_PULLUP + : GPIO_FLOAT; + gpio_val |= ((arg & SER_SINGLEWIRE_PULL_MASK) == + SER_SINGLEWIRE_PULLDOWN) ? GPIO_PULLDOWN + : GPIO_FLOAT; + stm32_configgpio((priv->tx_gpio & ~(GPIO_PUPD_MASK | + GPIO_OPENDRAIN)) | + gpio_val); + cr |= USART_CR3_HDSEL; + } + else + { + stm32_configgpio((priv->tx_gpio & ~(GPIO_PUPD_MASK | + GPIO_OPENDRAIN)) | + GPIO_PUSHPULL); + cr &= ~USART_CR3_HDSEL; + } +#endif + + up_serialout(priv, STM32_USART_CR3_OFFSET, cr); + } + break; +#endif + +#ifdef CONFIG_SERIAL_TERMIOS + case TCGETS: + { + struct termios *termiosp = (struct termios *)arg; + + if (!termiosp) + { + ret = -EINVAL; + break; + } + + /* Note that since we only support 8/9 bit modes and + * there is no way to report 9-bit mode, we always claim 8. + */ + + termiosp->c_cflag = + ((priv->parity != 0) ? PARENB : 0) | + ((priv->parity == 1) ? PARODD : 0) | + ((priv->stopbits2) ? CSTOPB : 0) | +#ifdef CONFIG_SERIAL_OFLOWCONTROL + ((priv->oflow) ? CCTS_OFLOW : 0) | +#endif +#ifdef CONFIG_SERIAL_IFLOWCONTROL + ((priv->iflow) ? CRTS_IFLOW : 0) | +#endif + CS8; + + cfsetispeed(termiosp, priv->baud); + + /* TODO: CCTS_IFLOW, CCTS_OFLOW */ + } + break; + + case TCSETS: + { + struct termios *termiosp = (struct termios *)arg; + + if (!termiosp) + { + ret = -EINVAL; + break; + } + + /* Perform some sanity checks before accepting any changes */ + + if (((termiosp->c_cflag & CSIZE) != CS8) +#ifdef CONFIG_SERIAL_OFLOWCONTROL + || ((termiosp->c_cflag & CCTS_OFLOW) && (priv->cts_gpio == 0)) +#endif +#ifdef CONFIG_SERIAL_IFLOWCONTROL + || ((termiosp->c_cflag & CRTS_IFLOW) && (priv->rts_gpio == 0)) +#endif + ) + { + ret = -EINVAL; + break; + } + + if (termiosp->c_cflag & PARENB) + { + priv->parity = (termiosp->c_cflag & PARODD) ? 1 : 2; + } + else + { + priv->parity = 0; + } + + priv->stopbits2 = (termiosp->c_cflag & CSTOPB) != 0; +#ifdef CONFIG_SERIAL_OFLOWCONTROL + priv->oflow = (termiosp->c_cflag & CCTS_OFLOW) != 0; +#endif +#ifdef CONFIG_SERIAL_IFLOWCONTROL + priv->iflow = (termiosp->c_cflag & CRTS_IFLOW) != 0; +#endif + + /* Note that since there is no way to request 9-bit mode + * and no way to support 5/6/7-bit modes, we ignore them + * all here. + */ + + /* Note that only cfgetispeed is used because we have knowledge + * that only one speed is supported. + */ + + priv->baud = cfgetispeed(termiosp); + + /* Effect the changes immediately - note that we do not implement + * TCSADRAIN / TCSAFLUSH + */ + + up_set_format(dev); + } + break; +#endif /* CONFIG_SERIAL_TERMIOS */ + +#ifdef CONFIG_STM32_USART_BREAKS +# ifdef CONFIG_STM32_SERIALBRK_BSDCOMPAT + case TIOCSBRK: /* BSD compatibility: Turn break on, unconditionally */ + { + irqstate_t flags; + uint32_t tx_break; + + flags = enter_critical_section(); + + /* Disable any further tx activity */ + + priv->ie |= USART_CR1_IE_BREAK_INPROGRESS; + + up_txint(dev, false); + + /* Configure TX as a GPIO output pin and Send a break signal */ + + tx_break = GPIO_OUTPUT | (~(GPIO_MODE_MASK | GPIO_OUTPUT_SET) & + priv->tx_gpio); + stm32_configgpio(tx_break); + + leave_critical_section(flags); + } + break; + + case TIOCCBRK: /* BSD compatibility: Turn break off, unconditionally */ + { + irqstate_t flags; + + flags = enter_critical_section(); + + /* Configure TX back to U(S)ART */ + + stm32_configgpio(priv->tx_gpio); + + priv->ie &= ~USART_CR1_IE_BREAK_INPROGRESS; + + /* Enable further tx activity */ + + up_txint(dev, true); + + leave_critical_section(flags); + } + break; +# else + case TIOCSBRK: /* No BSD compatibility: Turn break on for M bit times */ + { + uint32_t cr1; + irqstate_t flags; + + flags = enter_critical_section(); + cr1 = up_serialin(priv, STM32_USART_CR1_OFFSET); + up_serialout(priv, STM32_USART_CR1_OFFSET, cr1 | USART_CR1_SBK); + leave_critical_section(flags); + } + break; + + case TIOCCBRK: /* No BSD compatibility: May turn off break too soon */ + { + uint32_t cr1; + irqstate_t flags; + + flags = enter_critical_section(); + cr1 = up_serialin(priv, STM32_USART_CR1_OFFSET); + up_serialout(priv, STM32_USART_CR1_OFFSET, cr1 & ~USART_CR1_SBK); + leave_critical_section(flags); + } + break; +# endif +#endif + + default: + ret = -ENOTTY; + break; + } + + return ret; +} + +/**************************************************************************** + * Name: up_receive + * + * Description: + * Called (usually) from the interrupt level to receive one + * character from the USART. Error bits associated with the + * receipt are provided in the return 'status'. + * + ****************************************************************************/ + +#if defined(SERIAL_HAVE_TXDMA_OPS) || defined(SERIAL_HAVE_NODMA_OPS) +static int up_receive(struct uart_dev_s *dev, unsigned int *status) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + uint32_t rdr; + + /* Get the Rx byte */ + + rdr = up_serialin(priv, STM32_USART_RDR_OFFSET); + + /* Get the Rx byte plux error information. Return those in status */ + + *status = priv->sr << 16 | rdr; + priv->sr = 0; + + /* Then return the actual received byte */ + + return rdr & 0xff; +} +#endif + +/**************************************************************************** + * Name: up_rxint + * + * Description: + * Call to enable or disable RX interrupts + * + ****************************************************************************/ + +#if defined(SERIAL_HAVE_TXDMA_OPS) || defined(SERIAL_HAVE_NODMA_OPS) +static void up_rxint(struct uart_dev_s *dev, bool enable) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + irqstate_t flags; + uint16_t ie; + + /* USART receive interrupts: + * + * Enable Status Meaning Usage + * ------------------ --------------- ------------------------- ---------- + * USART_CR1_IDLEIE USART_SR_IDLE Idle Line Detected (not used) + * USART_CR1_RXNEIE USART_SR_RXNE Rx Data Ready to be Read + * " " USART_SR_ORE Overrun Error Detected + * USART_CR1_PEIE USART_SR_PE Parity Error + * + * USART_CR2_LBDIE USART_SR_LBD Break Flag (not used) + * USART_CR3_EIE USART_SR_FE Framing Error + * " " USART_SR_NE Noise Error + * " " USART_SR_ORE Overrun Error Detected + */ + + flags = enter_critical_section(); + ie = priv->ie; + if (enable) + { + /* Receive an interrupt when their is anything in the Rx data register + * (or an Rx timeout occurs). + */ + +#ifndef CONFIG_SUPPRESS_SERIAL_INTS +#ifdef CONFIG_USART_ERRINTS + ie |= (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR3_EIE); +#else + ie |= USART_CR1_RXNEIE; +#endif +#endif + } + else + { + ie &= ~(USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR3_EIE); + } + + /* Then set the new interrupt state */ + + up_restoreusartint(priv, ie); + leave_critical_section(flags); +} +#endif + +/**************************************************************************** + * Name: up_rxavailable + * + * Description: + * Return true if the receive register is not empty + * + ****************************************************************************/ + +#if defined(SERIAL_HAVE_TXDMA_OPS) || defined(SERIAL_HAVE_NODMA_OPS) +static bool up_rxavailable(struct uart_dev_s *dev) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + return ((up_serialin(priv, STM32_USART_SR_OFFSET) & USART_SR_RXNE) != 0); +} +#endif + +/**************************************************************************** + * Name: up_rxflowcontrol + * + * Description: + * Called when Rx buffer is full (or exceeds configured watermark levels + * if CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS is defined). + * Return true if UART activated RX flow control to block more incoming + * data + * + * Input Parameters: + * dev - UART device instance + * nbuffered - the number of characters currently buffered + * (if CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS is + * not defined the value will be 0 for an empty buffer or the + * defined buffer size for a full buffer) + * upper - true indicates the upper watermark was crossed where + * false indicates the lower watermark has been crossed + * + * Returned Value: + * true if RX flow control activated. + * + ****************************************************************************/ + +#ifdef CONFIG_SERIAL_IFLOWCONTROL +static bool up_rxflowcontrol(struct uart_dev_s *dev, + unsigned int nbuffered, bool upper) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + +#if defined(CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS) && \ + defined(CONFIG_STM32_FLOWCONTROL_BROKEN) + if (priv->iflow && (priv->rts_gpio != 0)) + { + /* Assert/de-assert nRTS set it high resume/stop sending */ + + stm32_gpiowrite(priv->rts_gpio, upper); + + if (upper) + { + /* With heavy Rx traffic, RXNE might be set and data pending. + * Returning 'true' in such case would cause RXNE left unhandled + * and causing interrupt storm. Sending end might be also be slow + * to react on nRTS, and returning 'true' here would prevent + * processing that data. + * + * Therefore, return 'false' so input data is still being processed + * until sending end reacts on nRTS signal and stops sending more. + */ + + return false; + } + + return upper; + } + +#else + if (priv->iflow) + { + /* Is the RX buffer full? */ + + if (upper) + { + /* Disable Rx interrupt to prevent more data being from + * peripheral. When hardware RTS is enabled, this will + * prevent more data from coming in. + * + * This function is only called when UART recv buffer is full, + * that is: "dev->recv.head + 1 == dev->recv.tail". + * + * Logic in "uart_read" will automatically toggle Rx interrupts + * when buffer is read empty and thus we do not have to re- + * enable Rx interrupts. + */ + + uart_disablerxint(dev); + return true; + } + + /* No.. The RX buffer is empty */ + + else + { + /* We might leave Rx interrupt disabled if full recv buffer was + * read empty. Enable Rx interrupt to make sure that more input is + * received. + */ + + uart_enablerxint(dev); + } + } +#endif + + return false; +} +#endif + +/**************************************************************************** + * Name: up_dma_receive + * + * Description: + * Called (usually) from the interrupt level to receive one + * character from the USART. Error bits associated with the + * receipt are provided in the return 'status'. + * + ****************************************************************************/ + +#ifdef SERIAL_HAVE_RXDMA +static int up_dma_receive(struct uart_dev_s *dev, unsigned int *status) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + int c = 0; + + if (up_dma_nextrx(priv) != priv->rxdmanext) + { + c = priv->rxfifo[priv->rxdmanext]; + + priv->rxdmanext++; + if (priv->rxdmanext == RXDMA_BUFFER_SIZE) + { + priv->rxdmanext = 0; + } + } + + return c; +} +#endif + +/**************************************************************************** + * Name: up_dma_rxint + * + * Description: + * Call to enable or disable RX interrupts + * + ****************************************************************************/ + +#ifdef SERIAL_HAVE_RXDMA +static void up_dma_rxint(struct uart_dev_s *dev, bool enable) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + + /* En/disable DMA reception. + * + * Note that it is not safe to check for available bytes and immediately + * pass them to uart_recvchars as that could potentially recurse back + * to us again. Instead, bytes must wait until the next up_dma_poll or + * DMA event. + */ + + priv->rxenable = enable; +} +#endif + +/**************************************************************************** + * Name: up_dma_rxavailable + * + * Description: + * Return true if the receive register is not empty + * + ****************************************************************************/ + +#ifdef SERIAL_HAVE_RXDMA +static bool up_dma_rxavailable(struct uart_dev_s *dev) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + + /* Compare our receive pointer to the current DMA pointer, if they + * do not match, then there are bytes to be received. + */ + + return (up_dma_nextrx(priv) != priv->rxdmanext); +} +#endif + +/**************************************************************************** + * Name: up_dma_txcallback + * + * Description: + * This function clears dma buffer at complete of DMA transfer and wakes up + * threads waiting for space in buffer. + * + ****************************************************************************/ + +#ifdef SERIAL_HAVE_TXDMA +static void up_dma_txcallback(DMA_HANDLE handle, uint8_t status, void *arg) +{ + struct up_dev_s *priv = (struct up_dev_s *)arg; + + /* Update 'nbytes' indicating number of bytes actually transferred by DMA. + * This is important to free TX buffer space by 'uart_xmitchars_done'. + */ + + if (status & DMA_ISR_TCIF_BIT) + { + priv->dev.dmatx.nbytes += priv->dev.dmatx.length; + if (priv->dev.dmatx.nlength) + { + /* Set up DMA on next buffer */ + + stm32_dmasetup(priv->txdma, + priv->usartbase + STM32_USART_TDR_OFFSET, + (uint32_t) priv->dev.dmatx.nbuffer, + (size_t) priv->dev.dmatx.nlength, + SERIAL_TXDMA_CONTROL_WORD); + + /* Set length for the next completion */ + + priv->dev.dmatx.length = priv->dev.dmatx.nlength; + priv->dev.dmatx.nlength = 0; + + /* Start transmission with the callback on DMA completion */ + + stm32_dmastart(priv->txdma, up_dma_txcallback, + (void *)priv, false); + + return; + } + } + else if (status & DMA_ISR_HTIF_BIT) + { + priv->dev.dmatx.nbytes += priv->dev.dmatx.length / 2; + } + + /* Adjust the pointers */ + + uart_xmitchars_done(&priv->dev); +} +#endif + +/**************************************************************************** + * Name: up_dma_txavailable + * + * Description: + * Informs DMA that Tx data is available and is ready for transfer. + * + ****************************************************************************/ + +#ifdef SERIAL_HAVE_TXDMA +static void up_dma_txavailable(struct uart_dev_s *dev) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + + /* Only send when the DMA is idle */ + + if (stm32_dmaresidual(priv->txdma) == 0) + { + uart_xmitchars_dma(dev); + } +} +#endif + +/**************************************************************************** + * Name: up_dma_send + * + * Description: + * Called (usually) from the interrupt level to start DMA transfer. + * (Re-)Configures DMA Stream updating buffer and buffer length. + * + ****************************************************************************/ + +#ifdef SERIAL_HAVE_TXDMA +static void up_dma_send(struct uart_dev_s *dev) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + + /* We need to stop DMA before reconfiguration */ + + stm32_dmastop(priv->txdma); + + /* Reset the number sent */ + + dev->dmatx.nbytes = 0; + + /* Make use of setup function to update buffer and its length for + * next transfer + */ + + stm32_dmasetup(priv->txdma, + priv->usartbase + STM32_USART_TDR_OFFSET, + (uint32_t) dev->dmatx.buffer, + (size_t) dev->dmatx.length, + SERIAL_TXDMA_CONTROL_WORD); + + /* Start transmission with the callback on DMA completion */ + + stm32_dmastart(priv->txdma, up_dma_txcallback, (void *)priv, false); +} +#endif + +/**************************************************************************** + * Name: up_send + * + * Description: + * This method will send one byte on the USART + * + ****************************************************************************/ + +static void up_send(struct uart_dev_s *dev, int ch) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; +#ifdef HAVE_RS485 + if (priv->rs485_dir_gpio != 0) + { + stm32_gpiowrite(priv->rs485_dir_gpio, priv->rs485_dir_polarity); + } +#endif + + up_serialout(priv, STM32_USART_TDR_OFFSET, (uint32_t)ch); +} + +/**************************************************************************** + * Name: up_dma_txint + * + * Description: + * Call to enable or disable TX interrupts from the UART. + * + ****************************************************************************/ + +#ifdef SERIAL_HAVE_TXDMA +static void up_dma_txint(struct uart_dev_s *dev, bool enable) +{ + /* Nothing to do. */ + + /* In case of DMA transfer we do not want to make use of UART interrupts. + * Instead, we use DMA interrupts that are activated once during boot + * sequence. Furthermore we can use up_dma_txcallback() to handle staff at + * half DMA transfer or after transfer completion (depending configuration, + * see stm32_dmastart(...) ). + */ +} +#endif + +/**************************************************************************** + * Name: up_txint + * + * Description: + * Call to enable or disable TX interrupts + * + ****************************************************************************/ + +#if defined(SERIAL_HAVE_RXDMA_OPS) || defined(SERIAL_HAVE_NODMA_OPS) +static void up_txint(struct uart_dev_s *dev, bool enable) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + irqstate_t flags; + + /* USART transmit interrupts: + * + * Enable Status Meaning Usage + * ------------------ --------------- ----------------------- ---------- + * USART_CR1_TCIE USART_SR_TC Tx Complete (RS-485) + * USART_CR1_TXEIE USART_SR_TXE Tx Data Register Empty + * USART_CR3_CTSIE USART_SR_CTS CTS flag (not used) + */ + + flags = enter_critical_section(); + if (enable) + { + /* Set to receive an interrupt when the TX data register is empty */ + +#ifndef CONFIG_SUPPRESS_SERIAL_INTS + uint16_t ie = priv->ie | USART_CR1_TXEIE; + + /* If RS-485 is supported on this U[S]ART, then also enable the + * transmission complete interrupt. + */ + +# ifdef HAVE_RS485 + if (priv->rs485_dir_gpio != 0) + { + ie |= USART_CR1_TCIE; + } +# endif + +# ifdef CONFIG_STM32_SERIALBRK_BSDCOMPAT + if (priv->ie & USART_CR1_IE_BREAK_INPROGRESS) + { + return; + } +# endif + + up_restoreusartint(priv, ie); + + /* Fake a TX interrupt here by just calling uart_xmitchars() with + * interrupts disabled (note this may recurse). + */ + + uart_xmitchars(dev); +#endif + } + else + { + /* Disable the TX interrupt */ + + up_restoreusartint(priv, priv->ie & ~USART_CR1_TXEIE); + } + + leave_critical_section(flags); +} +#endif + +/**************************************************************************** + * Name: up_txready + * + * Description: + * Return true if the transmit data register is empty + * + ****************************************************************************/ + +static bool up_txready(struct uart_dev_s *dev) +{ + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + return ((up_serialin(priv, STM32_USART_SR_OFFSET) & USART_SR_TXE) != 0); +} + +/**************************************************************************** + * Name: up_dma_rxcallback + * + * Description: + * This function checks the current DMA state and calls the generic + * serial stack when bytes appear to be available. + * + ****************************************************************************/ + +#ifdef SERIAL_HAVE_RXDMA +static void up_dma_rxcallback(DMA_HANDLE handle, uint8_t status, void *arg) +{ + struct up_dev_s *priv = (struct up_dev_s *)arg; + + if (priv->rxenable && up_dma_rxavailable(&priv->dev)) + { + uart_recvchars(&priv->dev); + } +} +#endif + +/**************************************************************************** + * Name: up_pm_notify + * + * Description: + * Notify the driver of new power state. This callback is called after + * all drivers have had the opportunity to prepare for the new power state. + * + * Input Parameters: + * + * cb - Returned to the driver. The driver version of the callback + * structure may include additional, driver-specific state data at + * the end of the structure. + * + * pmstate - Identifies the new PM state + * + * Returned Value: + * None - The driver already agreed to transition to the low power + * consumption state when when it returned OK to the prepare() call. + * + * + ****************************************************************************/ + +#ifdef CONFIG_PM +static void up_pm_notify(struct pm_callback_s *cb, int domain, + enum pm_state_e pmstate) +{ + switch (pmstate) + { + case(PM_NORMAL): + { + /* Logic for PM_NORMAL goes here */ + } + break; + + case(PM_IDLE): + { + /* Logic for PM_IDLE goes here */ + } + break; + + case(PM_STANDBY): + { + /* Logic for PM_STANDBY goes here */ + } + break; + + case(PM_SLEEP): + { + /* Logic for PM_SLEEP goes here */ + } + break; + + default: + { + /* Should not get here */ + } + break; + } +} +#endif + +/**************************************************************************** + * Name: up_pm_prepare + * + * Description: + * Request the driver to prepare for a new power state. This is a warning + * that the system is about to enter into a new power state. The driver + * should begin whatever operations that may be required to enter power + * state. The driver may abort the state change mode by returning a + * non-zero value from the callback function. + * + * Input Parameters: + * + * cb - Returned to the driver. The driver version of the callback + * structure may include additional, driver-specific state data at + * the end of the structure. + * + * pmstate - Identifies the new PM state + * + * Returned Value: + * Zero - (OK) means the event was successfully processed and that the + * driver is prepared for the PM state change. + * + * Non-zero - means that the driver is not prepared to perform the tasks + * needed achieve this power setting and will cause the state + * change to be aborted. NOTE: The prepare() method will also + * be called when reverting from lower back to higher power + * consumption modes (say because another driver refused a + * lower power state change). Drivers are not permitted to + * return non-zero values when reverting back to higher power + * consumption modes! + * + * + ****************************************************************************/ + +#ifdef CONFIG_PM +static int up_pm_prepare(struct pm_callback_s *cb, int domain, + enum pm_state_e pmstate) +{ + /* Logic to prepare for a reduced power state goes here. */ + + return OK; +} +#endif +#endif /* HAVE_SERIALDRIVER */ +#endif /* USE_SERIALDRIVER */ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#ifdef USE_SERIALDRIVER + +/**************************************************************************** + * Name: stm32_serial_get_uart + * + * Description: + * Get serial driver structure for STM32 USART + * + ****************************************************************************/ + +#ifdef HAVE_SERIALDRIVER +FAR uart_dev_t *stm32_serial_get_uart(int uart_num) +{ + int uart_idx = uart_num - 1; + + if (uart_idx < 0 || uart_idx >= STM32_NUSART || !g_uart_devs[uart_idx]) + { + return NULL; + } + + if (!g_uart_devs[uart_idx]->initialized) + { + return NULL; + } + + return &g_uart_devs[uart_idx]->dev; +} +#endif /* HAVE_SERIALDRIVER */ + +/**************************************************************************** + * Name: arm_earlyserialinit + * + * Description: + * Performs the low level USART initialization early in debug so that the + * serial console will be available during bootup. This must be called + * before arm_serialinit. + * + ****************************************************************************/ + +#ifdef USE_EARLYSERIALINIT +void arm_earlyserialinit(void) +{ +#ifdef HAVE_SERIALDRIVER + unsigned i; + + /* Disable all USART interrupts */ + + for (i = 0; i < STM32_NUSART; i++) + { + if (g_uart_devs[i]) + { + up_disableusartint(g_uart_devs[i], NULL); + } + } + + /* Configure whichever one is the console */ + +#if CONSOLE_UART > 0 + up_setup(&g_uart_devs[CONSOLE_UART - 1]->dev); +#endif +#endif /* HAVE UART */ +} +#endif + +/**************************************************************************** + * Name: arm_serialinit + * + * Description: + * Register serial console and serial ports. This assumes + * that arm_earlyserialinit was called previously. + * + ****************************************************************************/ + +void arm_serialinit(void) +{ +#ifdef HAVE_SERIALDRIVER + char devname[16]; + unsigned i; +#ifdef CONFIG_PM + int ret; +#endif + + /* Register to receive power management callbacks */ + +#ifdef CONFIG_PM + ret = pm_register(&g_serialcb); + DEBUGASSERT(ret == OK); + UNUSED(ret); +#endif + + /* Register the console */ + +#if CONSOLE_UART > 0 + uart_register("/dev/console", &g_uart_devs[CONSOLE_UART - 1]->dev); + +#ifndef CONFIG_STM32_SERIAL_DISABLE_REORDERING + /* If not disabled, register the console UART to ttyS0 and exclude + * it from initializing it further down + */ + + uart_register("/dev/ttyS0", &g_uart_devs[CONSOLE_UART - 1]->dev); +#endif + +#if defined(SERIAL_HAVE_CONSOLE_RXDMA) || defined(SERIAL_HAVE_CONSOLE_TXDMA) + /* If we need to re-initialise the console to enable DMA do that here. */ + + up_dma_setup(&g_uart_devs[CONSOLE_UART - 1]->dev); +#endif +#endif /* CONSOLE_UART > 0 */ + + /* Register all remaining USARTs */ + + strcpy(devname, "/dev/ttySx"); + + for (i = 0; i < STM32_NUSART; i++) + { + /* Don't create a device for non-configured ports. */ + + if (g_uart_devs[i] == 0) + { + continue; + } + +#ifndef CONFIG_STM32_SERIAL_DISABLE_REORDERING + /* Don't create a device for the console - we did that above */ + + if (g_uart_devs[i]->dev.isconsole) + { + continue; + } +#endif + + /* Register USARTs as devices in increasing order */ + + devname[9] = '0' + (i + 1); + uart_register(devname, &g_uart_devs[i]->dev); + } +#endif /* HAVE UART */ +} + +/**************************************************************************** + * Name: stm32_serial_dma_poll + * + * Description: + * Checks receive DMA buffers for received bytes that have not accumulated + * to the point where the DMA half/full interrupt has triggered. + * + * This function should be called from a timer or other periodic context. + * + ****************************************************************************/ + +#ifdef SERIAL_HAVE_RXDMA +void stm32_serial_dma_poll(void) +{ + irqstate_t flags; + + flags = enter_critical_section(); + +#ifdef CONFIG_USART1_RXDMA + if (g_usart1priv.rxdma != NULL) + { + up_dma_rxcallback(g_usart1priv.rxdma, 0, &g_usart1priv); + } +#endif + +#ifdef CONFIG_USART2_RXDMA + if (g_usart2priv.rxdma != NULL) + { + up_dma_rxcallback(g_usart2priv.rxdma, 0, &g_usart2priv); + } +#endif + +#ifdef CONFIG_USART3_RXDMA + if (g_usart3priv.rxdma != NULL) + { + up_dma_rxcallback(g_usart3priv.rxdma, 0, &g_usart3priv); + } +#endif + +#ifdef CONFIG_UART4_RXDMA + if (g_uart4priv.rxdma != NULL) + { + up_dma_rxcallback(g_uart4priv.rxdma, 0, &g_uart4priv); + } +#endif + +#ifdef CONFIG_UART5_RXDMA + if (g_uart5priv.rxdma != NULL) + { + up_dma_rxcallback(g_uart5priv.rxdma, 0, &g_uart5priv); + } +#endif + +#ifdef CONFIG_USART6_RXDMA + if (g_usart6priv.rxdma != NULL) + { + up_dma_rxcallback(g_usart6priv.rxdma, 0, &g_usart6priv); + } +#endif + +#ifdef CONFIG_UART7_RXDMA + if (g_uart7priv.rxdma != NULL) + { + up_dma_rxcallback(g_uart7priv.rxdma, 0, &g_uart7priv); + } +#endif + +#ifdef CONFIG_UART8_RXDMA + if (g_uart8priv.rxdma != NULL) + { + up_dma_rxcallback(g_uart8priv.rxdma, 0, &g_uart8priv); + } +#endif + + leave_critical_section(flags); +} +#endif + +/**************************************************************************** + * Name: up_putc + * + * Description: + * Provide priority, low-level access to support OS debug writes + * + ****************************************************************************/ + +int up_putc(int ch) +{ +#if CONSOLE_UART > 0 + struct up_dev_s *priv = g_uart_devs[CONSOLE_UART - 1]; + uint16_t ie; + + up_disableusartint(priv, &ie); + + /* Check for LF */ + + if (ch == '\n') + { + /* Add CR */ + + arm_lowputc('\r'); + } + + arm_lowputc(ch); + up_restoreusartint(priv, ie); +#endif + return ch; +} + +#else /* USE_SERIALDRIVER */ + +/**************************************************************************** + * Name: up_putc + * + * Description: + * Provide priority, low-level access to support OS debug writes + * + ****************************************************************************/ + +int up_putc(int ch) +{ +#if CONSOLE_UART > 0 + /* Check for LF */ + + if (ch == '\n') + { + /* Add CR */ + + arm_lowputc('\r'); + } + + arm_lowputc(ch); +#endif + return ch; +} + +#endif /* USE_SERIALDRIVER */ diff --git a/Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/common/include/stm32_hs300x.h b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/common/include/stm32_hs300x.h new file mode 100644 index 000000000..41b717282 --- /dev/null +++ b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/common/include/stm32_hs300x.h @@ -0,0 +1,80 @@ +/**************************************************************************** + * boards/arm/stm32/common/include/stm32_hs300x.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __STM32_HS300X_H +#define __STM32_HS300X_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Inline Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: board_hs300x_initialize + * + * Description: + * Initialize and register the hs300x Temperature Sensor driver. + * + * Input Parameters: + * devno - The device number, used to build the device path as /dev/i2cN + * busno - The I2C bus number + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int board_hs300x_initialize(int devno, int busno); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif // __STM32_HS300X_H diff --git a/Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/common/src/Make.defs b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/common/src/Make.defs new file mode 100644 index 000000000..1983c12fc --- /dev/null +++ b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/common/src/Make.defs @@ -0,0 +1,131 @@ +############################################################################# +# boards/arm/stm32/common/src/Make.defs +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################# + +ifeq ($(CONFIG_SENSORS_BMP180),y) + CSRCS += stm32_bmp180.c +endif + +ifeq ($(CONFIG_LEDS_APA102),y) + CSRCS += stm32_apa102.c +endif + +ifeq ($(CONFIG_WS2812),y) + CSRCS += stm32_ws2812.c +endif + +ifeq ($(CONFIG_SENSORS_MAX6675),y) + CSRCS += stm32_max6675.c +endif + +ifeq ($(CONFIG_SENSORS_VEML6070),y) + CSRCS += stm32_veml6070.c +endif + +ifeq ($(CONFIG_INPUT_NUNCHUCK),y) +CSRCS += stm32_nunchuck.c +endif + +ifeq ($(CONFIG_AUDIO_TONE),y) + CSRCS += stm32_tone.c +endif + +ifeq ($(CONFIG_LCD_BACKPACK),y) + CSRCS += stm32_lcd_backpack.c +endif + +ifeq ($(CONFIG_LCD_SSD1306),y) + CSRCS += stm32_ssd1306.c +endif + +ifeq ($(CONFIG_SENSORS_LM75),y) + CSRCS += stm32_lm75.c +endif + +ifeq ($(CONFIG_WL_NRF24L01),y) + CSRCS += stm32_nrf24l01.c +endif + +ifeq ($(CONFIG_SENSORS_HCSR04),y) + CSRCS += stm32_hcsr04.c +endif + +ifeq ($(CONFIG_SENSORS_APDS9960),y) + CSRCS += stm32_apds9960.c +endif + +ifeq ($(CONFIG_SENSORS_ZEROCROSS),y) + CSRCS += stm32_zerocross.c +endif + +ifeq ($(CONFIG_SENSORS_QENCODER),y) + CSRCS += stm32_qencoder.c +endif + +ifeq ($(CONFIG_SENSORS_INA219),y) + CSRCS += stm32_ina219.c +endif + +ifeq ($(CONFIG_SENSORS_L3GD20),y) + CSRCS += stm32_l3gd20.c +endif + +ifeq ($(CONFIG_SENSORS_MPL115A),y) + CSRCS += stm32_mpl115a.c +endif + +ifeq ($(CONFIG_SENSORS_DHTXX),y) + CSRCS += stm32_dhtxx.c +endif + +ifeq ($(CONFIG_SENSORS_XEN1210),y) + CSRCS += stm32_xen1210.c +endif + +ifeq ($(CONFIG_SENSORS_BH1750FVI),y) + CSRCS += stm32_bh1750.c +endif + +ifeq ($(CONFIG_SENSORS_MLX90614),y) + CSRCS += stm32_mlx90614.c +endif + +ifeq ($(CONFIG_SENSORS_MAX31855),y) + CSRCS += stm32_max31855.c +endif + +ifeq ($(CONFIG_LIS3DSH),y) + CSRCS += stm32_lis3dsh.c +endif + +ifeq ($(CONFIG_BOARD_STM32_IHM07M1),y) + CSRCS += stm32_ihm07m1.c +endif + +ifeq ($(CONFIG_BOARD_STM32_IHM08M1),y) + CSRCS += stm32_ihm08m1.c +endif + +ifeq ($(CONFIG_SENSORS_HS300X),y) + CSRCS += stm32_hs300x.c +endif + +DEPPATH += --dep-path src +VPATH += :src +CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src) diff --git a/Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/common/src/stm32_hs300x.c b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/common/src/stm32_hs300x.c new file mode 100644 index 000000000..4651fa1dd --- /dev/null +++ b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/common/src/stm32_hs300x.c @@ -0,0 +1,102 @@ +/**************************************************************************** + * boards/arm/stm32/common/src/stm32_hs300x.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +#include "stm32.h" +#include "stm32_i2c.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_hs300x_initialize + * + * Description: + * Initialize and register the HS300x Temperature Sensor driver. + * + * Input Parameters: + * devno - The device number, used to build the device path as /dev/i2cN + * busno - The I2C bus number + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int board_hs300x_initialize(int devno, int busno) +{ + FAR struct i2c_master_s *i2c; + char devpath[12]; + int ret; + + /* Get an instance of the I2C1 interface */ + + i2c = stm32_i2cbus_initialize(busno); + if (!i2c) + { + return -ENODEV; + } + + /* Then register the temperature sensor */ + snprintf(devpath, 12, "/dev/i2c%d", devno); + ret = hs300x_register(devpath, i2c, CONFIG_SENSOR_DEVICE_HS300X_I2C_ADDR); + if (ret < 0) + { + stm32_i2cbus_uninitialize(i2c); + } + + return ret; +} diff --git a/Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/stm32f4discovery/scripts/Make.defs b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/stm32f4discovery/scripts/Make.defs new file mode 100644 index 000000000..3429915e4 --- /dev/null +++ b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/stm32f4discovery/scripts/Make.defs @@ -0,0 +1,99 @@ +############################################################################ +# boards/arm/stm32/stm32f4discovery/scripts/Make.defs +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(TOPDIR)/.config +include $(TOPDIR)/tools/Config.mk +include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs + +LDSCRIPT = ld.script + +ifeq ($(CONFIG_CYGWIN_WINTOOL),y) + ARCHSCRIPT = -T "${shell cygpath -w $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)}" +else + ARCHSCRIPT = -T$(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT) +endif + +ifeq ($(CONFIG_DEBUG_SYMBOLS),y) + ARCHOPTIMIZATION = -g +endif + +ifneq ($(CONFIG_DEBUG_NOOPT),y) + ARCHOPTIMIZATION += $(MAXOPTIMIZATION) -fno-strict-aliasing -fomit-frame-pointer +endif + +ARCHCFLAGS = -fno-builtin +ARCHCXXFLAGS = -fno-builtin -fno-exceptions -fcheck-new +ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow -Wundef +ARCHWARNINGSXX = -Wall -Wshadow -Wundef +ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10 + +ifeq ($(CONFIG_ARMV7M_TOOLCHAIN_CLANGL),y) + ARCHCFLAGS += -nostdlib -ffreestanding + ARCHCXXFLAGS += -nostdlib -ffreestanding +else + ARCHCFLAGS += -funwind-tables + ARCHCXXFLAGS += -fno-rtti -funwind-tables + ifneq ($(CONFIG_DEBUG_NOOPT),y) + ARCHOPTIMIZATION += -fno-strength-reduce + endif + +endif + +CFLAGS := $(APPPATHS) $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe +CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS) +CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe +CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS) +CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) +AFLAGS := $(CFLAGS) -D__ASSEMBLY__ + +NXFLATLDFLAGS1 = -r -d -warn-common +NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections +LDNXFLATFLAGS = -e main -s 2048 + +# Loadable module definitions + +CMODULEFLAGS = $(CFLAGS) -mlong-calls # --target1-abs + +LDMODULEFLAGS = -r -e module_initialize +ifeq ($(CONFIG_CYGWIN_WINTOOL),y) + LDMODULEFLAGS += -T "${shell cygpath -w $(TOPDIR)/libs/libc/modlib/gnu-elf.ld}" +else + LDMODULEFLAGS += -T $(TOPDIR)/libs/libc/modlib/gnu-elf.ld +endif + +# ELF module definitions + +CELFFLAGS = $(CFLAGS) -mlong-calls # --target1-abs +CXXELFFLAGS = $(CXXFLAGS) -mlong-calls # --target1-abs + +LDELFFLAGS = -r -e main +ifeq ($(CONFIG_CYGWIN_WINTOOL),y) + LDELFFLAGS += -T "${shell cygpath -w $(BOARD_DIR)$(DELIM)scripts$(DELIM)gnu-elf.ld}" +else + LDELFFLAGS += -T $(BOARD_DIR)$(DELIM)scripts$(DELIM)gnu-elf.ld +endif + + +ifneq ($(CROSSDEV),arm-nuttx-elf-) + LDFLAGS += -nostartfiles -nodefaultlibs +endif +ifeq ($(CONFIG_DEBUG_SYMBOLS),y) + LDFLAGS += -g +endif diff --git a/Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/stm32f4discovery/src/stm32_bringup.c b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/stm32f4discovery/src/stm32_bringup.c new file mode 100644 index 000000000..e33d76a94 --- /dev/null +++ b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/stm32f4discovery/src/stm32_bringup.c @@ -0,0 +1,552 @@ +/**************************************************************************** + * boards/arm/stm32/stm32f4discovery/src/stm32_bringup.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include + +#ifdef CONFIG_USBMONITOR +# include +#endif + +#include "stm32.h" +#include "stm32_romfs.h" + +#ifdef CONFIG_STM32_OTGFS +# include "stm32_usbhost.h" +#endif + +#ifdef CONFIG_INPUT_BUTTONS +# include +#endif + +#ifdef CONFIG_USERLED +# include +#endif + +#ifdef CONFIG_RNDIS +# include +#endif + +#include "stm32f4discovery.h" + +/* Conditional logic in stm32f4discovery.h will determine if certain features + * are supported. Tests for these features need to be made after including + * stm32f4discovery.h. + */ + +#ifdef HAVE_RTC_DRIVER +# include +# include "stm32_rtc.h" +#endif + +/* The following are includes from board-common logic */ + +#ifdef CONFIG_SENSORS_BMP180 +#include "stm32_bmp180.h" +#endif + +#ifdef CONFIG_SENSORS_MAX6675 +#include "stm32_max6675.h" +#endif + +#ifdef CONFIG_INPUT_NUNCHUCK +#include "stm32_nunchuck.h" +#endif + +#ifdef CONFIG_SENSORS_ZEROCROSS +#include "stm32_zerocross.h" +#endif + +#ifdef CONFIG_SENSORS_QENCODER +#include "board_qencoder.h" +#endif + +#ifdef CONFIG_SENSORS_BH1750FVI +#include "stm32_bh1750.h" +#endif + +#ifdef CONFIG_LIS3DSH +#include "stm32_lis3dsh.h" +#endif + +#ifdef CONFIG_LCD_BACKPACK +#include "stm32_lcd_backpack.h" +#endif + +#ifdef CONFIG_SENSORS_MAX31855 +#include "stm32_max31855.h" +#endif + +#ifdef CONFIG_SENSORS_MLX90614 +#include "stm32_mlx90614.h" +#endif + +#ifdef CONFIG_SENSORS_XEN1210 +#include "stm32_xen1210.h" +#endif + +#ifdef CONFIG_SENSORS_HS300X +#include "stm32_hs300x.h" +#endif + +#ifdef CONFIG_USBADB +# include +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_i2c_register + * + * Description: + * Register one I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL) +static void stm32_i2c_register(int bus) +{ + FAR struct i2c_master_s *i2c; + int ret; + + i2c = stm32_i2cbus_initialize(bus); + if (i2c == NULL) + { + syslog(LOG_ERR, "ERROR: Failed to get I2C%d interface\n", bus); + } + else + { + ret = i2c_register(i2c, bus); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n", + bus, ret); + stm32_i2cbus_uninitialize(i2c); + } + } +} +#endif + +/**************************************************************************** + * Name: stm32_i2ctool + * + * Description: + * Register I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL) +static void stm32_i2ctool(void) +{ + stm32_i2c_register(1); +#if 0 + stm32_i2c_register(1); + stm32_i2c_register(2); +#endif +} +#else +# define stm32_i2ctool() +#endif + +/**************************************************************************** + * Name: stm32_bringup + * + * Description: + * Perform architecture-specific initialization + * + * CONFIG_BOARD_LATE_INITIALIZE=y : + * Called from board_late_initialize(). + * + * CONFIG_BOARD_LATE_INITIALIZE=n && CONFIG_LIB_BOARDCTL=y : + * Called from the NSH library + * + ****************************************************************************/ + +int stm32_bringup(void) +{ +#ifdef HAVE_RTC_DRIVER + FAR struct rtc_lowerhalf_s *lower; +#endif + int ret = OK; + +#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL) + stm32_i2ctool(); +#endif + +#ifdef CONFIG_SENSORS_BMP180 + /* Initialize the BMP180 pressure sensor. */ + + ret = board_bmp180_initialize(0, 1); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize BMP180, error %d\n", ret); + return ret; + } +#endif + +#ifdef CONFIG_SENSORS_BH1750FVI + ret = board_bh1750_initialize(0, 1); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: stm32_bh1750initialize() failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_SENSORS_ZEROCROSS + /* Configure the zero-crossing driver */ + + board_zerocross_initialize(0); +#endif + +#ifdef CONFIG_LEDS_MAX7219 + ret = stm32_max7219init("/dev/numdisp0"); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: max7219_leds_register failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_LCD_ST7032 + ret = stm32_st7032init("/dev/slcd0"); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: st7032_register failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_RGBLED + /* Configure the RGB LED driver */ + + stm32_rgbled_setup(); +#endif + +#if defined(CONFIG_PCA9635PW) + /* Initialize the PCA9635 chip */ + + ret = stm32_pca9635_initialize(); + if (ret < 0) + { + serr("ERROR: stm32_pca9635_initialize failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_VIDEO_FB + /* Initialize and register the framebuffer driver */ + + ret = fb_register(0, 0); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: fb_register() failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_LCD_BACKPACK + /* slcd:0, i2c:1, rows=2, cols=16 */ + + ret = board_lcd_backpack_init(0, 1, 2, 16); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize PCF8574 LCD, error %d\n", ret); + return ret; + } +#endif + +#ifdef HAVE_SDIO + /* Initialize the SDIO block driver */ + + ret = stm32_sdio_initialize(); + if (ret != OK) + { + ferr("ERROR: Failed to initialize MMC/SD driver: %d\n", ret); + return ret; + } +#endif + +#ifdef CONFIG_MMCSD_SPI + /* Initialize the MMC/SD SPI driver (SPI2 is used) */ + + ret = stm32_mmcsd_initialize(2, CONFIG_NSH_MMCSDMINOR); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize SD slot %d: %d\n", + CONFIG_NSH_MMCSDMINOR, ret); + } +#endif + +#ifdef HAVE_USBHOST + /* Initialize USB host operation. stm32_usbhost_initialize() starts a + * thread will monitor for USB connection and disconnection events. + */ + + ret = stm32_usbhost_initialize(); + if (ret != OK) + { + uerr("ERROR: Failed to initialize USB host: %d\n", ret); + return ret; + } +#endif + +#ifdef HAVE_USBMONITOR + /* Start the USB Monitor */ + + ret = usbmonitor_start(); + if (ret != OK) + { + uerr("ERROR: Failed to start USB monitor: %d\n", ret); + return ret; + } +#endif + +#ifdef CONFIG_PWM + /* Initialize PWM and register the PWM device. */ + + ret = stm32_pwm_setup(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: stm32_pwm_setup() failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_CAN + /* Initialize CAN and register the CAN driver. */ + + ret = stm32_can_setup(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: stm32_can_setup failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_INPUT_BUTTONS + /* Register the BUTTON driver */ + + ret = btn_lower_initialize("/dev/buttons"); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_INPUT_NUNCHUCK + /* Register the Nunchuck driver */ + + ret = board_nunchuck_initialize(0, 1); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: nunchuck_initialize() failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_SENSORS_MLX90614 + ret = board_mlx90614_initialize(0, 1); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize MLX90614, error %d\n", ret); + return ret; + } +#endif + +#ifdef CONFIG_SENSORS_QENCODER + /* Initialize and register the qencoder driver */ + + ret = board_qencoder_initialize(0, CONFIG_STM32F4DISCO_QETIMER); + if (ret != OK) + { + syslog(LOG_ERR, + "ERROR: Failed to register the qencoder: %d\n", + ret); + return ret; + } +#endif + +#ifdef CONFIG_USERLED + /* Register the LED driver */ + + ret = userled_lower_initialize("/dev/userleds"); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_RTC_DS1307 + ret = stm32_ds1307_init(); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize DS1307 RTC driver: %d\n", ret); + return ret; + } +#endif + +#ifdef HAVE_RTC_DRIVER + /* Instantiate the STM32 lower-half RTC driver */ + + lower = stm32_rtc_lowerhalf(); + if (!lower) + { + serr("ERROR: Failed to instantiate the RTC lower-half driver\n"); + return -ENOMEM; + } + else + { + /* Bind the lower half driver and register the combined RTC driver + * as /dev/rtc0 + */ + + ret = rtc_initialize(0, lower); + if (ret < 0) + { + serr("ERROR: Failed to bind/register the RTC driver: %d\n", ret); + return ret; + } + } +#endif + +#ifdef HAVE_CS43L22 + /* Configure CS43L22 audio */ + + ret = stm32_cs43l22_initialize(1); + if (ret != OK) + { + serr("Failed to initialize CS43L22 audio: %d\n", ret); + } +#endif + +#ifdef CONFIG_SENSORS_MAX31855 + /* Register device 0 on spi channel 2 */ + + ret = board_max31855_initialize(0, 2); + if (ret < 0) + { + serr("ERROR: stm32_max31855initialize failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_SENSORS_MAX6675 + ret = board_max6675_initialize(0, 2); + if (ret < 0) + { + serr("ERROR: stm32_max6675initialize failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_FS_PROCFS + /* Mount the procfs file system */ + + ret = nx_mount(NULL, STM32_PROCFS_MOUNTPOINT, "procfs", 0, NULL); + if (ret < 0) + { + serr("ERROR: Failed to mount procfs at %s: %d\n", + STM32_PROCFS_MOUNTPOINT, ret); + } +#endif + +#ifdef CONFIG_STM32_ROMFS + ret = stm32_romfs_initialize(); + if (ret < 0) + { + serr("ERROR: Failed to mount romfs at %s: %d\n", + CONFIG_STM32_ROMFS_MOUNTPOINT, ret); + } +#endif + +#ifdef CONFIG_SENSORS_XEN1210 + ret = board_xen1210_initialize(0, 1); + if (ret < 0) + { + serr("ERROR: xen1210_archinitialize failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_LIS3DSH + /* Create a lis3dsh driver instance fitting the chip built into + * stm32f4discovery + */ + + ret = board_lis3dsh_initialize(0, 1); + if (ret < 0) + { + serr("ERROR: Failed to initialize LIS3DSH driver: %d\n", ret); + } +#endif + +#ifdef HAVE_HCIUART + ret = hciuart_dev_initialize(); + if (ret < 0) + { + serr("ERROR: Failed to initialize HCI UART driver: %d\n", ret); + } +#endif + +#if defined(CONFIG_RNDIS) + uint8_t mac[6]; + mac[0] = 0xa0; /* TODO */ + mac[1] = (CONFIG_NETINIT_MACADDR_2 >> (8 * 0)) & 0xff; + mac[2] = (CONFIG_NETINIT_MACADDR_1 >> (8 * 3)) & 0xff; + mac[3] = (CONFIG_NETINIT_MACADDR_1 >> (8 * 2)) & 0xff; + mac[4] = (CONFIG_NETINIT_MACADDR_1 >> (8 * 1)) & 0xff; + mac[5] = (CONFIG_NETINIT_MACADDR_1 >> (8 * 0)) & 0xff; + usbdev_rndis_initialize(mac); +#endif + +#ifdef CONFIG_WL_GS2200M + ret = stm32_gs2200m_initialize("/dev/gs2200m", 3); + if (ret < 0) + { + serr("ERROR: Failed to initialize GS2200M: %d \n", ret); + } +#endif + +#ifdef CONFIG_LPWAN_SX127X + ret = stm32_lpwaninitialize(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to initialize wireless driver:" + " %d\n", ret); + } +#endif /* CONFIG_LPWAN_SX127X */ + +#ifdef CONFIG_SENSORS_HS300X + ret = board_hs300x_initialize(1,1); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to initialize hs300x:" + " %d\n", ret); + } +#endif /* CONFIG_SENSORS_HS300X */ + +#ifdef CONFIG_USBADB + usbdev_adb_initialize(); +#endif + + return ret; +} diff --git a/Ubiquitous/Nuttx/app_match_nuttx/nuttx/drivers/sensors/Kconfig b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/drivers/sensors/Kconfig new file mode 100644 index 000000000..c07319a2d --- /dev/null +++ b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/drivers/sensors/Kconfig @@ -0,0 +1,993 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +menuconfig SENSORS + bool "Sensor Device Support" + select MM_CIRCBUF + default n + ---help--- + Drivers for various sensors + +if SENSORS + +config SENSORS_NPOLLWAITERS + int "Number of poll threads" + default 2 + ---help--- + Maximum number of threads than can be waiting for POLL events. + Default: 2 + +config SENSORS_WTGAHRS2 + bool "Wtgahrs2 Sensor Support" + default n + ---help--- + We can read sensor data by serial interface. It need the hardware sensor + wtgashrs2(JY901) as data source. This sensor can generate accelerometer, + gyroscope, magnetic, barometer and gps data. + +config SENSORS_FAKESENSOR + bool "Fake Sensor Support" + default n + ---help--- + Simulate physical sensor by reading data from csv file. + The file structure is as follows: + First row : set interval, unit millisecond + Second row: csv file header + third row : data + (Each line should not exceed 50 characters) + For example: + interval:12 + x,y,z + 2.1234,3.23443,2.23456 + ... + +config SENSORS_APDS9960 + bool "Avago APDS-9960 Gesture Sensor support" + default n + select I2C + ---help--- + Enable driver support for the Avago APDS-9960 gesture sensor. + +config APDS9960_I2C_FREQUENCY + int "APDS-9960 I2C frequency" + default 400000 + depends on SENSORS_APDS9960 + +config SENSORS_AK09912 + bool "Asahi AK09911/AK09912 Compass Sensor" + default n + select I2C + ---help--- + Enable driver for AK09911/AK09912 Compass sensor. + +config SENSORS_AS5048B + bool "AMS AS5048B Magnetic Rotary Encoder support" + default n + select I2C + select SENSORS_QENCODER + ---help--- + Enable driver support for the AMS AS5048B magnetic rotary encoder. + +config SENSORS_AS726X + bool "AMS AS726X Spetral sensor support" + default n + select I2C + ---help--- + Enable driver support for the AS726X Spectral Sensor. + +config SENSORS_BH1750FVI + bool "Rohm BH1750FVI Ambient Light Sensor support" + default n + select I2C + ---help--- + Enable driver support for the Rohm BH1750FVI light sensor. + +config BH1750FVI_I2C_FREQUENCY + int "BH1750FVI I2C frequency" + default 400000 + depends on SENSORS_BH1750FVI + +config SENSORS_BMG160 + bool "Bosch BMG160 Gyroscope Sensor support" + default n + select SPI + ---help--- + Enable driver support for the Bosch BMG160 gyroscope sensor. + + +config SENSORS_BMI160 + bool "Bosch BMI160 Inertial Measurement Sensor support" + default n + select I2C + ---help--- + Enable driver support for the Bosch BMI160 Inertial + Measurement sensor + +if SENSORS_BMI160 + +choice + prompt "BMI160 Interface" + default SENSORS_BMI160_SPI + +config SENSORS_BMI160_I2C + bool "BMI160 I2C Interface" + select I2C + ---help--- + Enables support for the I2C interface + +config SENSORS_BMI160_SPI + bool "BMI160 SPI Interface" + select SPI + ---help--- + Enables support for the SPI interface + +endchoice + +choice + prompt "I2C Address" + default BMI160_I2C_ADDR_68 + +config BMI160_I2C_ADDR_68 + bool "0x68" + ---help--- + Default address. + If SDO pin is pulled to VDDIO, use 0x69 + +config BMI160_I2C_ADDR_69 + bool "0x69" + ---help--- + If SDO pin is pulled to VDDIO, use 0x69 + +endchoice +endif + +config SENSORS_BMP180 + bool "Bosch BMP180 Barometer Sensor support" + default n + select I2C + ---help--- + Enable driver support for the Bosch BMP180 barometer sensor. + +config SENSORS_BMP280 + bool "Bosch BMP280 Barometic Pressure Sensor" + default n + select I2C + ---help--- + Enable driver for the Bosch BMP280 barometic pressure sensor. + +if SENSORS_BMP280 + +config BMP280_I2C_FREQUENCY + int "BMP280 I2C frequency" + default 400000 + +endif # SENSORS_BMP280 + +config SENSORS_DHTXX + bool "DHTxx humidity/temperature Sensor support" + default n + ---help--- + Enable driver support for the DHTxx humidity/temperature sensor. + +config SENSORS_FXOS8700CQ + bool "NXP FXOS8700CQ Motion Sensor support" + default n + select I2C + ---help--- + Enable driver support for the NXP FXOS8700CQ Motion sensor + +config SENSORS_HCSR04 + bool "HC-SR04 Distance Measurement Sensor" + default n + ---help--- + Enable driver support for the HC-SR04 Distance Sensor. + +config SENSORS_HYT271 + bool "IST HYT271 Humidity and Temperature Sensor support" + default n + ---help--- + Enable driver support for the HYT271/HYT221/HYT939 humidity/temperature sensor family. + +config SENSORS_HYT271_POLL + bool "Enables polling sensor data" + depends on SENSORS_HYT271 + default n + ---help--- + Enables polling of sensor. + +config SENSORS_HYT271_POLL_INTERVAL + int "Polling interval in microseconds, default 1 sec" + depends on SENSORS_HYT271 && SENSORS_HYT271_POLL + default 1000000 + range 0 4294967295 + ---help--- + The interval until a new sensor measurement will be triggered. + +config SENSORS_HYT271_THREAD_STACKSIZE + int "Worker thread stack size" + depends on SENSORS_HYT271 && SENSORS_HYT271_POLL + default 1024 + ---help--- + The stack size for the worker thread. + +if SENSORS_HCSR04 + +config HCSR04_DEBUG + bool "Debug support for the HC-SR04" + default n + ---help--- + Enables debug features for the HC-SR04 + +config HCSR04_NPOLLWAITERS + int "Number of waiters to poll" + default 1 + ---help--- + Number of waiters to poll + +endif # SENSORS_HCSR04 + +config SENSORS_ISL29023 + bool "Renesas ISL29023 ALS sensor" + default n + select I2C + ---help--- + Enable driver support for the Renesas ISL29023 ambient light sensor. + +if SENSORS_ISL29023 + +config ISL29023_I2C_FREQUENCY + int "ISL29023 I2C frequency" + default 400000 + +endif # SENSORS_ISL29023 + +config SENSORS_HTS221 + bool "STMicro HTS221 humidity sensor" + default n + select I2C + ---help--- + Enable driver support for the STMicro HTS221 humidity sensor. + +if SENSORS_HTS221 + +config HTS221_I2C_FREQUENCY + int "HTS221 I2C frequency" + default 400000 + range 1 400000 + +config HTS221_DEBUG + bool "Debug support for the HTS221" + default n + ---help--- + Enables debug features for the HTS221 + +config HTS221_NPOLLWAITERS + int "Number of waiters to poll" + default 1 + ---help--- + Number of waiters to poll + +endif # SENSORS_HTS221 + +config SENSORS_L3GD20 + bool "STMicro L3GD20 Gyroscope Sensor support" + default n + select SPI + select SCHED_HPWORK if SENSORS_L3GD20_BUFFER_SIZE > 0 + ---help--- + Enable driver support for the STMicro L3GD20 gyroscope sensor. + +config SENSORS_L3GD20_BUFFER_SIZE + int "size of buffer" + default 1 + depends on SENSORS_L3GD20 + ---help--- + The size of the circular buffer used. If the value equal to zero, + indicates that the circular buffer is disabled. + + +config SENSOR_KXTJ9 + bool "Kionix KXTJ9 Accelerometer support" + default n + select I2C + +if SENSORS_KXTJ9 + +config KXTJ9_I2C_BUS_SPEED + int "Kionix KXTJ9 Bus Speed in Hz" + default 400000 + +endif # SENSORS_KXTJ9 + +config SENSORS_LIS2DH + bool "STMicro LIS2DH device support" + default n + select I2C + ---help--- + Enable driver support for the STMicro LIS2DH accelerometer + +if SENSORS_LIS2DH + +config LIS2DH_I2C_FREQUENCY + int "LIS2DH I2C frequency" + default 400000 + range 1 400000 + +config LIS2DH_DEBUG + bool "Debug support for the LIS2DH" + default n + ---help--- + Enables debug features for the LIS2DH + +config LIS2DH_NPOLLWAITERS + int "Number of waiters to poll" + default 2 + ---help--- + Maximum number of threads that can be waiting on poll() + +config LIS2DH_DRIVER_SELFTEST + bool "Enable selftest in LIS2DH driver" + default n + ---help--- + Enable selftest in LIS2DH driver + +endif # SENSORS_LIS2DH + +config LIS3DSH + bool "STMicro LIS3DSH 3-Axis accelerometer support" + default n + select SPI + ---help--- + Enable driver support for the STMicro LIS3DSH 3-Axis accelerometer. + +config LIS3DH + bool "STMicro LIS3DH 3-Axis accelerometer support" + default n + select SPI + ---help--- + Enable driver support for the STMicro LIS3DH 3-Axis accelerometer. + +config LIS331DL + bool "STMicro LIS331DL device support" + default n + select I2C + +config LIS331DL_I2C_FREQUENCY + int "LIS331DL I2C frequency" + default 100000 + range 1 100000 + depends on LIS331DL + +config SENSORS_LSM330SPI + bool "STMicro LSM330 SPI support" + default n + select SPI + ---help--- + Enable driver support for the STMicro LSM330 on SPI. + +config SENSORS_LSM303AGR + bool "STMicro LSM303AGR support" + default n + select I2C + ---help--- + Enable driver support for the STMicro LSM303AGR. + +config LSM303AGR_I2C_FREQUENCY + int "LSM303AGR I2C frequency" + default 400000 + range 1 400000 + depends on SN_LSM303AGR + +config SENSORS_LSM6DSL + bool "STMicro LSM6DSL support" + default n + select I2C + ---help--- + Enable driver support for the STMicro LSM6DSL. + +config LSM6DSL_I2C_FREQUENCY + int "LSM6DSL I2C frequency" + default 400000 + range 1 400000 + depends on SN_LSM6DSL + +config SENSORS_LSM9DS1 + bool "STMicro LSM9DS1 support" + default n + select I2C + ---help--- + Enable driver support for the STMicro LSM9DS1. + +config LSM9DS1_I2C_FREQUENCY + int "LSM9DS1 I2C frequency" + default 400000 + range 1 400000 + depends on SN_LSM9DS1 + +config SENSORS_LPS25H + bool "STMicro LPS25H pressure sensor" + default n + select I2C + ---help--- + Enable driver support for the STMicro LPS25H barometer sensor. + +if SENSORS_LPS25H + +config LPS25H_I2C_FREQUENCY + int "LPS25H I2C frequency" + default 400000 + range 1 400000 + +config DEBUG_LPS25H + bool "Debug support for the LPS25H" + default n + ---help--- + Enables debug features for the LPS25H + +endif # SENSORS_LPS25H + +config SENSORS_LTC4151 + bool "LTC4151 current and voltage monitor" + default n + select I2C + ---help--- + Enable driver support for the LinearTechnology LTC4151 current and voltage monitor. + +config LTC4151_I2C_FREQUENCY + int "LTC4151 I2C frequency" + default 400000 + depends on SENSORS_LTC4151 + +config SENSORS_INA219 + bool "INA219 current and voltage monitor" + default n + select I2C + ---help--- + Enable driver support for the Texas Instruments INA219 current and voltage monitor. + +config INA219_I2C_FREQUENCY + int "INA219 I2C frequency" + default 400000 + depends on SENSORS_INA219 + +config SENSORS_INA226 + bool "INA226 current and voltage monitor" + default n + select I2C + ---help--- + Enable driver support for the Texas Instruments INA226 power monitor. + +config INA226_I2C_FREQUENCY + int "INA226 I2C frequency" + default 400000 + depends on SENSORS_INA226 + +config SENSORS_INA3221 + bool "INA3221 current and voltage monitor" + default n + select I2C + ---help--- + Enable driver support for the Texas Instruments INA3221 current and voltage monitor. + +config INA3221_I2C_FREQUENCY + int "INA3221 I2C frequency" + default 400000 + depends on SENSORS_INA3221 + +config SENSORS_MB7040 + bool "MaxBotix MB7040 Sonar support" + default n + select I2C + ---help--- + Enable driver support for the MaxBotix MB7040 sonar. + +config MB7040_I2C_FREQUENCY + int "MB7040 I2C frequency" + default 400000 + range 1 400000 + depends on SENSORS_MB7040 + +config SENSORS_MLX90393 + bool "MLX90393 3-Axis Magnetometer" + default n + select SPI + ---help--- + Enable driver support for the Melex MLX90393 3-Axis magnetometer. + +config SENSORS_MLX90614 + bool "MLX90614 Infrared Thermometer" + default n + select I2C + ---help--- + Enable driver support for the Melexis MLX90614 Infrared Thermometer. + +if SENSORS_MLX90614 +config MLX90614_CRC + bool "Enable CRC Checking (verify if PEC field is valid)" + default n + ---help--- + Enable checking of CRC-8 (PEC field) checking to guarantee that + read data is valid. +endif + +config SENSORS_MCP9844 + bool "MCP9844 Temperature Sensor" + default n + select I2C + ---help--- + Enable driver support for the MCP9844 I2C Temperature sensor. + +config MCP9844_I2C_FREQUENCY + int "MCP9844 I2C frequency" + default 400000 + range 1 400000 + depends on SENSORS_MCP9844 + +config SENSORS_MS58XX + bool "MEAS MS58XX Altimeter support" + default n + select I2C + ---help--- + Enable driver support for MEAS MS58XX altimeters. + +config MS58XX_I2C_FREQUENCY + int "MS58XX I2C frequency" + default 400000 + range 1 400000 + depends on SENSORS_MS58XX + +config MS58XX_VDD + int "MEAS MS58XX VDD" + default 30 + depends on SENSORS_MS58XX + +config SENSORS_MPL115A + bool "Freescale MPL115A Barometer Sensor support" + default n + select SPI + ---help--- + Enable driver support for the Freescale MPL115A barometer sensor. + +config MPL115A_REGDEBUG + bool "Debug support for the MPL115A" + default n + depends on SENSORS_MPL115A + ---help--- + Enables register level debug features for the MPL115A + +config SENSORS_ADXL345 + bool "Analog Devices ADXL345 Driver" + default n + ---help--- + Enables support for the ADXL345 driver + +if SENSORS_ADXL345 + +choice + prompt "ADXL345 Interface" + default ADXL345_SPI + +config ADXL345_SPI + bool "ADXL345 SPI Interface" + select SPI + ---help--- + Enables support for the SPI interface. + +config ADXL345_I2C + bool "ADXL345 I2C Interface" + select I2C + ---help--- + Enables support for the I2C interface + +endchoice + +config ADXL345_ACTIVELOW + bool "Active Low Interrupt" + default n + ---help--- + The ADXL345 interrupt will be inverted. Instead starting low and going + high, it will start high and will go low when an interrupt is fired. + Default: Active high/rising edge. + +config ADXL345_REGDEBUG + bool "Enable Register-Level ADXL345 Debug" + default n + depends on DEBUG_FEATURES + ---help--- + Enable very low register-level debug output. + +endif # SENSORS_ADXL345 + +config SENSORS_ADXL372 + bool "Analog Devices ADXL372 Sensor support" + default n + select SPI + ---help--- + Enable driver support for the Analog Devices ADXL372 Sensor. + +config SENSORS_MPU60X0 + bool "Invensense MPU60x0 Sensor support" + default n + ---help--- + Enable driver support for Invensense MPU60x0 MotionTracker(tm) device. + +if SENSORS_MPU60X0 + +choice + prompt "MPU60x0 Interface" + default MPU60X0_SPI + +config MPU60X0_SPI + bool "MPU6000 SPI Interface" + select SPI + ---help--- + Enables support for the SPI interface (MPU6000 only) + +config MPU60X0_I2C + bool "MPU60x0 I2C Interface" + select I2C + ---help--- + Enables support for the I2C interface (MPU6000 + or MPU6050, autodetected during driver initialization) + +endchoice + +config MPU60X0_I2C_FREQ + int "MPU60x0 I2C Frequency" + depends on MPU60X0_I2C + default 400000 + +config MPU60X0_EXTI + bool "Enable interrupts" + default n + ---help--- + Select this when the MPU60x0's INT pin is connected to an + interrupt line on the host processor, and identify the pin + during device registration. The driver will use interrupts to + manage FIFO-full and/or sample-ready events, depending on how + the device is being used. The interface will block until the + next sample is ready, which will naturally synchronize the user + to the sampling rate chosen during operation. + Default: No interrupts or blocking, i.e. user-driven sampling. + +endif # SENSORS_MPU60X0 + +config SENSORS_MAX44009 + bool "Maxim MAX44009 ALS sensor" + default n + select I2C + ---help--- + Enables MAX44009 Ambient Light Sensor + +if SENSORS_MAX44009 + +config MAX44009_I2C_FREQUENCY + int "MAX44009 I2C frequency" + default 400000 + range 1 400000 + +config DEBUG_MAX44009 + bool "Enable debug support for the MAX44009" + default n + ---help--- + Enables debug support for the MAX44009 + +config MAX44009_NPOLLWAITERS + int "Number of waiters to poll" + default 1 + ---help--- + Number of waiters to poll + +endif # SENSORS_MAX44009 + +config SENSORS_MAX31855 + bool "Maxim MAX31855 Driver" + default n + select SPI + ---help--- + Enables support for the MAX31855 driver + +config SENSORS_MAX6675 + bool "Maxim MAX6675 Driver" + default n + select SPI + ---help--- + Enables support for the MAX6675 driver + +config SENSORS_LIS3MDL + bool "STMicro LIS3MDL 3-Axis magnetometer support" + default n + select SPI + ---help--- + Enable driver support for the STMicro LIS3MDL 3-axis magnetometer. + +config LM75_I2C + bool + default y if LM75 + +config SENSORS_LM75 + bool "STMicro LM-75 Temperature Sensor support" + default n + select I2C + select LM75_I2C + ---help--- + Enable driver support for the STMicro LM-75 temperature sensor. + This should also work with compatible temperature sensors such as + the TI TMP100/101. + +config LM75_I2C_FREQUENCY + int "LM75 I2C frequency" + default 100000 + range 1 100000 + depends on LM75_I2C + +config SENSORS_LM92 + bool "TI LM92 Temperature Sensor support" + default n + select I2C + ---help--- + Enable driver support for the TI LM92 Temperature Sensor. + +config LM92_I2C_FREQUENCY + int "LM92 I2C frequency" + default 400000 + range 1 400000 + depends on LM92 + +config SENSORS_SCD30 + bool "Sensirion SCD30 CO2, humidity and temperature sensor" + default n + ---help--- + Enable driver support for the Sensirion SCD30 CO₂, humidity and + temperature sensor. + +if SENSORS_SCD30 + +config SCD30_I2C + bool "Sensirion SCD30 I2C mode" + default y + select I2C + +config SCD30_I2C_FREQUENCY + int "SCD30 I2C frequency" + default 100000 + range 1 100000 + depends on SCD30_I2C + ---help--- + I2C frequency for SCD30. Note, maximum supported frequency for + this sensor is 100kHz. + +config SCD30_DEBUG + bool "Debug support for the SCD30" + default n + ---help--- + Enables debug features for the SCD30 + +endif # SENSORS_SCD30 + +config SENSORS_SGP30 + bool "Sensirion SGP30 Gas Platform sensor" + default n + select I2C + ---help--- + Enable driver support for the Sensirion SCD30 CO₂ and TVOC gas sensor. + +if SENSORS_SGP30 + +config SGP30_I2C_FREQUENCY + int "SGP30 I2C frequency" + default 400000 + range 1 400000 + +config SGP30_DEBUG + bool "Debug support for the SGP30" + default n + ---help--- + Enables debug features for the SGP30 + +endif # SENSORS_SGP30 + +config SENSORS_AHT10 + bool "ASAIR AHT10 temperature and humidity sensor" + default n + select I2C + ---help--- + Enable driver support for the ASAIR AHT10 temperature and humidity sensors. + +if SENSORS_AHT10 +config AHT10_I2C_FREQUENCY + int "AHT10 I2C frequency" + default 400000 + range 1 400000 +endif # SENSORS_AHT10 + +config SENSORS_SHT21 + bool "Sensirion SHT21 temperature and humidity sensor" + default n + select I2C + ---help--- + Enable driver support for the Sensirion SHT20 and SHT21 temperature + and humidity sensors. SHT20 is a budget model with limited humidity + precision. + +if SENSORS_SHT21 + +config SHT21_I2C_FREQUENCY + int "SHT21 I2C frequency" + default 400000 + range 1 400000 + +config SHT21_DEBUG + bool "Debug support for the SHT21" + default n + ---help--- + Enables debug features for the SHT21 + +endif # SENSORS_SHT21 + +config SENSORS_SHT3X + bool "Sensirion SHT3x temperature and humidity sensor" + default n + select I2C + ---help--- + Enable driver support for the Sensirion SHT3x temperature + and humidity sensors. + +if SENSORS_SHT3X + +config SHT3X_I2C_FREQUENCY + int "SHT3x I2C frequency" + default 400000 + range 1 400000 + +config SHT3X_I2C_ADDR + hex "SHT3x I2C addr" + default 0x44 + range 0x44 0x45 + +config SHT3X_DEBUG + bool "Debug support for the SHT3x" + default n + ---help--- + Enables debug features for the SHT3x + +endif # SENSORS_SHT3X + +config SENSORS_SPS30 + bool "Sensirion SPS30 particulate matter sensor" + default n + ---help--- + Enable driver support for the Sensirion SPS30 particulate matter sensor + sensor. + +if SENSORS_SPS30 + +config SPS30_I2C + bool "Sensirion SPS30 I2C mode" + default y + select I2C + +config SPS30_I2C_FREQUENCY + int "SPS30 I2C frequency" + default 100000 + range 1 100000 + depends on SPS30_I2C + ---help--- + I2C frequency for SPS30. Note, maximum supported frequency for + this sensor is 100kHz. + +config SPS30_DEBUG + bool "Debug support for the SPS30" + default n + ---help--- + Enables debug features for the SPS30 + +endif # SENSORS_SPS30 + +config SENSORS_T67XX + bool "Telair T6713 carbon dioxide sensor" + default n + select I2C + ---help--- + Enable driver support for the Telair T6713 and T6703 carbon + dioxide sensors. + +config SENSORS_QENCODER + bool "Qencoder" + default n + +config SENSORS_VEML6070 + bool "Vishay VEML6070 UV-A Light Sensor support" + default n + select I2C + ---help--- + Enable driver support for the Vishay VEML6070 UV-A light sensor. + +config VEML6070_I2C_FREQUENCY + int "VEML6070 I2C frequency" + default 100000 + depends on SENSORS_VEML6070 + +config SENSORS_VL53L1X + bool "ST VL53L1X TOF sensor" + default n + select I2C + ---help--- + Enable driver support for the VL53L1X Time Of Flight sensor. + +config SENSORS_XEN1210 + bool "Sensixs XEN1210 Magnetometer" + default n + select SPI + ---help--- + Enable driver support for the Sensixs XEN1210 Magnetometer. + +config XEN1210_REGDEBUG + bool "Debug support for the XEN1210" + default n + depends on SENSORS_XEN1210 + ---help--- + Enables register level debug features for the XEN1210 + +config SENSORS_ZEROCROSS + bool "Zero Cross Sensor" + default n + +config SENSORS_ADT7320 + bool "Analog Devices ADT7320 Driver" + default n + select SPI + ---help--- + Enables support for the ADT7320 Driver + +config SENSORS_HDC1008 + bool "TI HDC1008 temperature and humidity sensor" + default n + select I2C + ---help--- + Enable driver support for the TI HDC1008 temperature and humidity sensor. + +if SENSORS_HDC1008 + +config HDC1008_I2C_ADDRESS + hex "HDC1008 I2C address" + default 0x40 + range 0x40 0x43 + ---help--- + The I2C address of the HDC1008 sensor. It can be configured via straps to + a value between 0x40 and 0x43. + +config HDC1008_I2C_FREQUENCY + int "HDC1008 I2C frequency" + default 400000 + range 1 400000 + +config HDC1008_DEBUG + bool "Debug support for the HDC1008" + default n + ---help--- + Enables debug features for the HDC1008 + +endif # SENSORS_HDC1008 + +config HS300X_I2C + bool + default y if HS300X + +config SENSORS_HS300X + bool "HS300X Temperature and Humidity Sensor support" + default n + select I2C + select HS300X_I2C + ---help--- + Enable driver support for the HS300X Temperature and Humidity sensor. + +config HS300X_I2C_FREQUENCY + int "HS300X I2C frequency" + default 400000 + range 1 900000 + depends on HS300X_I2C + +endif # SENSORS diff --git a/Ubiquitous/Nuttx/app_match_nuttx/nuttx/drivers/sensors/Make.defs b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/drivers/sensors/Make.defs new file mode 100644 index 000000000..09673ec4f --- /dev/null +++ b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/drivers/sensors/Make.defs @@ -0,0 +1,315 @@ +############################################################################ +# drivers/sensors/Make.defs +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +# Include sensor drivers + +ifeq ($(CONFIG_SENSORS),y) + +CSRCS += sensor.c + +ifeq ($(CONFIG_SENSORS_WTGAHRS2),y) + CSRCS += wtgahrs2.c +endif + +ifeq ($(CONFIG_SENSORS_FAKESENSOR),y) + CSRCS += fakesensor.c +endif + +ifeq ($(CONFIG_SENSORS_HCSR04),y) + CSRCS += hc_sr04.c +endif + +ifeq ($(CONFIG_SENSORS_ADXL345),y) + CSRCS += adxl345_base.c +endif + +ifeq ($(CONFIG_SENSORS_DHTXX),y) + CSRCS += dhtxx.c +endif + +# These drivers depend on I2C support + +ifeq ($(CONFIG_I2C),y) + +ifeq ($(CONFIG_SENSORS_APDS9960),y) + CSRCS += apds9960.c +endif + +ifeq ($(CONFIG_SENSORS_AK09912),y) + CSRCS += ak09912.c +endif + +ifeq ($(CONFIG_SENSORS_AS5048B),y) + CSRCS += as5048b.c +endif + +ifeq ($(CONFIG_SENSORS_AS726X),y) + CSRCS += as726x.c +endif + +ifeq ($(CONFIG_SENSORS_FXOS8700CQ),y) + CSRCS += fxos8700cq.c +endif + +ifeq ($(CONFIG_SENSORS_HYT271),y) + CSRCS += hyt271.c +endif + +ifeq ($(CONFIG_SENSORS_KXTJ9),y) + CSRCS += kxtj9.c +endif + +ifeq ($(CONFIG_SENSORS_LIS2DH),y) + CSRCS += lis2dh.c +endif + +ifeq ($(CONFIG_LIS331DL),y) + CSRCS += lis331dl.c +endif + +ifeq ($(CONFIG_SENSORS_LSM303AGR),y) + CSRCS += lsm303agr.c +endif + +ifeq ($(CONFIG_SENSORS_LSM6DSL),y) + CSRCS += lsm6dsl.c +endif + +ifeq ($(CONFIG_SENSORS_LSM9DS1),y) + CSRCS += lsm9ds1.c +endif + +ifeq ($(CONFIG_SENSORS_LPS25H),y) + CSRCS += lps25h.c +endif + +ifeq ($(CONFIG_ADXL345_I2C),y) + CSRCS += adxl345_i2c.c +endif + +ifeq ($(CONFIG_SENSORS_BH1750FVI),y) + CSRCS += bh1750fvi.c +endif + +ifeq ($(CONFIG_SENSORS_BMG160),y) + CSRCS += bmg160.c +endif + +ifeq ($(CONFIG_SENSORS_BMI160),y) + CSRCS += bmi160.c +endif + +ifeq ($(CONFIG_SENSORS_BMP180),y) + CSRCS += bmp180.c +endif + +ifeq ($(CONFIG_SENSORS_BMP280),y) + CSRCS += bmp280.c +endif + +ifeq ($(CONFIG_SENSORS_ISL29023),y) + CSRCS += isl29023.c +endif + +ifeq ($(CONFIG_SENSORS_HTS221),y) + CSRCS += hts221.c +endif + +ifeq ($(CONFIG_LM75_I2C),y) + CSRCS += lm75.c +endif + +ifeq ($(CONFIG_SENSORS_LM92),y) + CSRCS += lm92.c +endif + +ifeq ($(CONFIG_SENSORS_MAX44009),y) + CSRCS += max44009.c +endif + +ifeq ($(CONFIG_SENSORS_MB7040),y) + CSRCS += mb7040.c +endif + +ifeq ($(CONFIG_SENSORS_MCP9844),y) + CSRCS += mcp9844.c +endif + +ifeq ($(CONFIG_SENSORS_MLX90393),y) + CSRCS += mlx90393.c +endif + +ifeq ($(CONFIG_SENSORS_MLX90614),y) + CSRCS += mlx90614.c +endif + +ifeq ($(CONFIG_SENSORS_MS58XX),y) + CSRCS += ms58xx.c +endif + +ifeq ($(CONFIG_SENSORS_LTC4151),y) + CSRCS += ltc4151.c +endif + +ifeq ($(CONFIG_SENSORS_INA219),y) + CSRCS += ina219.c +endif + +ifeq ($(CONFIG_SENSORS_INA226),y) + CSRCS += ina226.c +endif + +ifeq ($(CONFIG_SENSORS_INA3221),y) + CSRCS += ina3221.c +endif + +ifeq ($(CONFIG_SENSORS_SCD30),y) + CSRCS += scd30.c +endif + +ifeq ($(CONFIG_SENSORS_SGP30),y) + CSRCS += sgp30.c +endif + +ifeq ($(CONFIG_SENSORS_AHT10),y) + CSRCS += aht10.c +endif + +ifeq ($(CONFIG_SENSORS_SHT21),y) + CSRCS += sht21.c +endif + +ifeq ($(CONFIG_SENSORS_SHT3X),y) + CSRCS += sht3x.c +endif + +ifeq ($(CONFIG_SENSORS_SPS30),y) + CSRCS += sps30.c +endif + +ifeq ($(CONFIG_SENSORS_T67XX),y) + CSRCS += t67xx.c +endif + +endif # CONFIG_I2C + +# These drivers depend on SPI support + +ifeq ($(CONFIG_SPI),y) + +ifeq ($(CONFIG_ADXL345_SPI),y) + CSRCS += adxl345_spi.c +endif + +ifeq ($(CONFIG_SENSORS_ADXL372),y) + CSRCS += adxl372.c +endif + +ifeq ($(CONFIG_LIS3DSH),y) + CSRCS += lis3dsh.c +endif + +ifeq ($(CONFIG_LIS3DH),y) + CSRCS += lis3dh.c +endif + +ifeq ($(CONFIG_SENSORS_MAX31855),y) + CSRCS += max31855.c +endif + +ifeq ($(CONFIG_SENSORS_MAX6675),y) + CSRCS += max6675.c +endif + +ifeq ($(CONFIG_SENSORS_MPL115A),y) + CSRCS += mpl115a.c +endif + +ifeq ($(CONFIG_SENSORS_LIS3MDL),y) + CSRCS += lis3mdl.c +endif + +ifeq ($(CONFIG_SENSORS_LSM330SPI),y) + CSRCS += lsm330_spi.c +endif + +ifeq ($(CONFIG_SENSORS_L3GD20),y) + CSRCS += l3gd20.c +endif + +ifeq ($(CONFIG_SENSORS_ADT7320),y) + CSRCS += adt7320.c +endif + +endif # CONFIG_SPI + +ifeq ($(CONFIG_SENSORS_MPU60X0),y) + CSRCS += mpu60x0.c +endif + +# Quadrature encoder upper half + +ifeq ($(CONFIG_SENSORS_QENCODER),y) + CSRCS += qencoder.c +endif + +# Vishay VEML6070 + +ifeq ($(CONFIG_SENSORS_VEML6070),y) + CSRCS += veml6070.c +endif + +# ST VL53L1X + +ifeq ($(CONFIG_SENSORS_VL53L1X),y) + CSRCS += vl53l1x.c +endif + +# Sensixs XEN1210 + +ifeq ($(CONFIG_SENSORS_XEN1210),y) + CSRCS += xen1210.c +endif + +# Zero Cross upper half + +ifeq ($(CONFIG_SENSORS_ZEROCROSS),y) + CSRCS += zerocross.c +endif + +# TI HDC1008 + +ifeq ($(CONFIG_SENSORS_HDC1008),y) + CSRCS += hdc1008.c +endif + +# HS300x + +ifeq ($(CONFIG_SENSORS_HS300X),y) + CSRCS += hs300x.c +endif + +# Include sensor driver build support + +DEPPATH += --dep-path sensors +VPATH += :sensors +CFLAGS += ${shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)sensors} + +endif # CONFIG_SENSORS diff --git a/Ubiquitous/Nuttx/app_match_nuttx/nuttx/drivers/sensors/hs300x.c b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/drivers/sensors/hs300x.c new file mode 100644 index 000000000..c7c1133b1 --- /dev/null +++ b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/drivers/sensors/hs300x.c @@ -0,0 +1,253 @@ +/**************************************************************************** + * drivers/sensors/hs300x.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#if defined(CONFIG_I2C) && defined(CONFIG_HS300X_I2C) + +/**************************************************************************** + * Private + ****************************************************************************/ +struct hs300x_dev_s +{ + FAR struct i2c_master_s *i2c; /* I2C interface */ + uint8_t addr; /* I2C address */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* I2C Helpers */ +static int hs300x_i2c_write(FAR struct hs300x_dev_s *priv, FAR char *buffer, int buflen); +static int hs300x_i2c_read(FAR struct hs300x_dev_s *priv, FAR char *buffer, int buflen); + +/* Character driver methods */ +static int hs300x_open(FAR struct file *filep); +static int hs300x_close(FAR struct file *filep); +static ssize_t hs300x_read(FAR struct file *filep, FAR char *buffer, size_t buflen); +static ssize_t hs300x_write(FAR struct file *filep, FAR const char *buffer, size_t buflen); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations g_hs300xfops = +{ + hs300x_open, + hs300x_close, + hs300x_read, + hs300x_write, + NULL, + NULL, + NULL +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: hs300x_i2c_write + * + * Description: + * Write to the I2C device. + * + ****************************************************************************/ + +static int hs300x_i2c_write(FAR struct hs300x_dev_s *priv, + FAR char *buffer, int buflen) +{ + struct i2c_msg_s msg; + int ret; + + /* Setup for the transfer */ + msg.frequency = CONFIG_HS300X_I2C_FREQUENCY, + msg.addr = priv->addr; + msg.flags = 0; + msg.buffer = (FAR uint8_t *)buffer; /* Override const */ + msg.length = buflen; + + /* Then perform the transfer. */ + ret = I2C_TRANSFER(priv->i2c, &msg, 1); + return (ret >= 0) ? OK : ret; +} + +/**************************************************************************** + * Name: hs300x_i2c_read + * + * Description: + * Read from the I2C device. + * + ****************************************************************************/ + +static int hs300x_i2c_read(FAR struct hs300x_dev_s *priv, + FAR char *buffer, int buflen) +{ + struct i2c_msg_s msg; + int ret; + + /* Setup for the transfer */ + + msg.frequency = CONFIG_HS300X_I2C_FREQUENCY, + msg.addr = priv->addr, + msg.flags = I2C_M_READ; + msg.buffer = (FAR uint8_t *)buffer; + msg.length = buflen; + + /* Then perform the transfer. */ + ret = I2C_TRANSFER(priv->i2c, &msg, 1); + return (ret >= 0) ? OK : ret; +} + + +/**************************************************************************** + * Name: hs300x_open + ****************************************************************************/ +static int hs300x_open(FAR struct file *filep) +{ + return OK; +} + +/**************************************************************************** + * Name: hs300x_close + ****************************************************************************/ + +static int hs300x_close(FAR struct file *filep) +{ + return OK; +} + +/**************************************************************************** + * Name: hs300x_read + ****************************************************************************/ + +static ssize_t hs300x_read(FAR struct file *filep, FAR char *buffer, + size_t buflen) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct hs300x_dev_s *priv = inode->i_private; + int ret; + + if (buflen != 4) + { + snerr("ERROR: You can't read something other than 32 bits (4 bytes)\n"); + return -1; + } + /* Restart and read 32-bits from the register */ + ret = hs300x_i2c_read(priv, buffer, 4); + if (ret < 0) + { + snerr("ERROR: i2c_read failed: %d\n", ret); + return (ssize_t)ret;; + } + + return buflen; +} + +/**************************************************************************** + * Name: hs300x_write + ****************************************************************************/ + +static ssize_t hs300x_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct hs300x_dev_s *priv = inode->i_private; + int ret; + + ret = hs300x_i2c_write(priv, buffer, buflen); + if (ret < 0) + { + snerr("ERROR: i2c_write failed: %d\n", ret); + return (ssize_t)ret;; + } + + return buflen; +} + + +/**************************************************************************** + * Name: hs300x_register + * + * Description: + * Register the HS300x character device as 'devpath' + * + * Input Parameters: + * devpath - The full path to the driver to register. E.g., "/dev/i2c1" + * i2c - An instance of the I2C interface to use to communicate with HS300X + * addr - The I2C address of the HS300x. The base I2C address of the HS300X + * is 0x44. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int hs300x_register(FAR const char *devpath, FAR struct i2c_master_s *i2c, + uint8_t addr) +{ + FAR struct hs300x_dev_s *priv; + int ret; + + /* Sanity check */ + + DEBUGASSERT(i2c != NULL); + DEBUGASSERT(addr == CONFIG_SENSOR_DEVICE_HS300X_I2C_ADDR); + + /* Initialize the HS300x device structure */ + priv = (FAR struct hs300x_dev_s *)kmm_malloc(sizeof(struct hs300x_dev_s)); + if (priv == NULL) + { + snerr("ERROR: Failed to allocate instance\n"); + return -ENOMEM; + } + + priv->i2c = i2c; + priv->addr = addr; + + /* Register the character driver */ + ret = register_driver(devpath, &g_hs300xfops, 0666, priv); + if (ret < 0) + { + snerr("ERROR: Failed to register driver: %d\n", ret); + kmm_free(priv); + } + + sninfo("HS300X driver loaded successfully!\n"); + return ret; +} +#endif /* CONFIG_I2C && CONFIG_HS300X_I2C */ diff --git a/Ubiquitous/Nuttx/app_match_nuttx/nuttx/include/nuttx/sensors/hs300x.h b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/include/nuttx/sensors/hs300x.h new file mode 100644 index 000000000..cc3e556f1 --- /dev/null +++ b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/include/nuttx/sensors/hs300x.h @@ -0,0 +1,88 @@ +/**************************************************************************** + * include/nuttx/sensors/hs300x.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_SENSORS_HS300X_H +#define __INCLUDE_NUTTX_SENSORS_HS300X_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#if defined(CONFIG_I2C) && defined(CONFIG_HS300X_I2C) + +/* HS300X Registers frequency and addresses*/ + +#ifndef CONFIG_HS300X_I2C_FREQUENCY +# define CONFIG_HS300X_I2C_FREQUENCY 400000 +#endif + +#ifndef CONFIG_SENSOR_DEVICE_HS300X_I2C_ADDR +# define CONFIG_SENSOR_DEVICE_HS300X_I2C_ADDR 0x44 +#endif + + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct i2c_master_s; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: hs300x_register + * + * Description: + * Register the HS300x character device as 'devpath' + * + * Input Parameters: + * devpath - The full path to the driver to register. E.g., "/dev/i2c1" + * i2c - An instance of the I2C interface to use to communicate with HS300X + * addr - The I2C address of the HS300x. The base I2C address of the HS300X + * is 0x44. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int hs300x_register(FAR const char *devpath, FAR struct i2c_master_s *i2c, + uint8_t addr); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_I2C && CONFIG_HS300X_I2C */ +#endif /* __INCLUDE_NUTTX_SENSORS_HS300X_H */ diff --git a/Ubiquitous/Nuttx/app_match_nuttx/nuttx/tools/Makefile.unix b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/tools/Makefile.unix new file mode 100644 index 000000000..6189a7176 --- /dev/null +++ b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/tools/Makefile.unix @@ -0,0 +1,618 @@ +############################################################################ +# tools/Makefile.unix +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +export TOPDIR := ${shell echo $(CURDIR) | sed -e 's/ /\\ /g'} +include $(TOPDIR)/Make.defs + +# GIT directory present + +GIT_DIR = $(if $(wildcard $(TOPDIR)$(DELIM).git),y,) + +ifeq ($(GIT_DIR),y) +GIT_PRESENT = `git rev-parse --git-dir 2> /dev/null` +endif + +# In case we cannot get version information from GIT + +ifeq ($(GIT_PRESENT),) +-include $(TOPDIR)/.version + +# In case the version file does not exist + +CONFIG_VERSION_STRING ?= "0.0.0" +CONFIG_VERSION_BUILD ?= "0" + +VERSION_ARG = -v $(CONFIG_VERSION_STRING) -b $(CONFIG_VERSION_BUILD) +else + +# Generate .version every time from GIT history + +.PHONY: $(TOPDIR)/.version +endif + +# Process architecture specific directories + +ARCH_DIR = arch/$(CONFIG_ARCH) +ARCH_SRC = $(ARCH_DIR)/src +ARCH_INC = $(ARCH_DIR)/include + +export APPPATHS = -I$(APPDIR)/../../../APP_Framework/Framework/sensor +APPPATHS += -I$(APPDIR)/../../../APP_Framework/Applications/general_functions/list +APPPATHS += -I$(APPDIR)/../../../APP_Framework/Framework/transform_layer/nuttx + +export SRC_APP_DIR = ../../../APP_Framework + +# CONFIG_APPS_DIR can be over-ridden from the command line or in the .config file. +# The default value of CONFIG_APPS_DIR is ../apps. Ultimately, the application +# will be built if APPDIR is defined. APPDIR will be defined if a directory containing +# a Makefile is found at the path provided by CONFIG_APPS_DIR + +ifeq ($(CONFIG_APPS_DIR),) +CONFIG_APPS_DIR = ../apps +endif +APPDIR := $(realpath ${shell if [ -r $(CONFIG_APPS_DIR)/Makefile ]; then echo "$(CONFIG_APPS_DIR)"; fi}) + +# External code support +# If external/ contains a Kconfig, we define the EXTERNALDIR variable to 'external' +# so that main Kconfig can find it. Otherwise, we redirect it to a dummy Kconfig +# This is due to kconfig inability to do conditional inclusion. + +EXTERNALDIR := $(shell if [ -r $(TOPDIR)/external/Kconfig ]; then echo 'external'; else echo 'dummy'; fi) + +# CONTEXTDIRS include directories that have special, one-time pre-build +# requirements. Normally this includes things like auto-generation of +# configuration specific files or creation of configurable symbolic links +# CLEANDIRS are the directories that the clean target will executed in. +# These are all directories that we know about. +# CCLEANDIRS are directories that the clean_context target will execute in. +# The clean_context target "undoes" the actions of the context target. +# Only directories known to require cleaning are included. +# KERNDEPDIRS are the directories in which we will build target dependencies. +# If NuttX and applications are built separately (CONFIG_BUILD_PROTECTED or +# CONFIG_BUILD_KERNEL), then this holds only the directories containing +# kernel files. +# USERDEPDIRS. If NuttX and applications are built separately (CONFIG_BUILD_PROTECTED), +# then this holds only the directories containing user files. If +# CONFIG_BUILD_KERNEL is selected, then applications are not build at all. + +include tools/Directories.mk + +# +# Extra objects used in the final link. +# +# Pass 1 Incremental (relative) link objects should be put into the +# processor-specific source directory (where other link objects will +# be created). If the pass1 object is an archive, it could go anywhere. + +ifeq ($(CONFIG_BUILD_2PASS),y) +EXTRA_OBJS += $(CONFIG_PASS1_OBJECT) +endif + +# Library build selections +# +# NUTTXLIBS is the list of NuttX libraries that is passed to the +# processor-specific Makefile to build the final NuttX target. +# USERLIBS is the list of libraries used to build the final user-space +# application +# EXPORTLIBS is the list of libraries that should be exported by +# 'make export' is + +ifeq ($(CONFIG_BUILD_PROTECTED),y) +include tools/ProtectedLibs.mk +else ifeq ($(CONFIG_BUILD_KERNEL),y) +include tools/KernelLibs.mk +else +include tools/FlatLibs.mk +endif + +# LINKLIBS derives from NUTTXLIBS and is simply the same list with the +# subdirectory removed + +LINKLIBS = $(patsubst staging/%,%,$(NUTTXLIBS)) + +# Export tool definitions + +MKEXPORT= tools/mkexport.sh +MKEXPORT_ARGS = -t "$(TOPDIR)" -b "$(BOARD_DIR)" + +ifneq ($(CONFIG_BUILD_FLAT),y) +MKEXPORT_ARGS += -u +endif + +ifneq ($(APPDIR),) +ifneq ($(shell [ -e $(APPDIR)/Makefile ] && echo yes),) +MKEXPORT_ARGS += -a "$(APPDIR)" +MKEXPORT_ARGS += -m "$(MAKE)" +endif +endif + +ifeq ($(V),2) +MKEXPORT_ARGS += -d +endif + +# This is the name of the final target (relative to the top level directory) + +BIN = nuttx$(EXEEXT) + +all: $(BIN) +.PHONY: dirlinks context clean_context config oldconfig menuconfig nconfig qconfig gconfig export subdir_clean clean subdir_distclean distclean apps_clean apps_distclean +.PHONY: pass1 pass1dep +.PHONY: pass2 pass2dep + +# Target used to copy include/nuttx/lib/math.h. If CONFIG_ARCH_MATH_H is +# defined, then there is an architecture specific math.h header file +# that will be included indirectly from include/math.h. But first, we +# have to copy math.h from include/nuttx/. to include/. Logic within +# include/nuttx/lib/math.h will hand the redirection to the architecture- +# specific math.h header file. +# +# If the CONFIG_LIBM is defined, the Rhombus libm will be built at libc/math. +# Definitions and prototypes for the Rhombus libm are also contained in +# include/nuttx/lib/math.h and so the file must also be copied in that case. +# +# If neither CONFIG_ARCH_MATH_H nor CONFIG_LIBM is defined, then no math.h +# header file will be provided. You would want that behavior if (1) you +# don't use libm, or (2) you want to use the math.h and libm provided +# within your toolchain. + +ifeq ($(CONFIG_ARCH_MATH_H),y) +NEED_MATH_H = y +else ifeq ($(CONFIG_LIBM),y) +NEED_MATH_H = y +endif + +ifeq ($(NEED_MATH_H),y) +include/math.h: include/nuttx/lib/math.h .clean_context + $(Q) cp -f include/nuttx/lib/math.h include/math.h +else +include/math.h: +endif + +# The float.h header file defines the properties of your floating point +# implementation. It would always be best to use your toolchain's float.h +# header file but if none is available, a default float.h header file will +# provided if this option is selected. However there is no assurance that +# the settings in this float.h are actually correct for your platform! + +ifeq ($(CONFIG_ARCH_FLOAT_H),y) +include/float.h: include/nuttx/lib/float.h .clean_context + $(Q) cp -f include/nuttx/lib/float.h include/float.h +else +include/float.h: +endif + +# Target used to copy include/nuttx/lib/stdarg.h. If CONFIG_ARCH_STDARG_H is +# defined, then there is an architecture specific stdarg.h header file +# that will be included indirectly from include/lib/stdarg.h. But first, we +# have to copy stdarg.h from include/nuttx/. to include/. + +ifeq ($(CONFIG_ARCH_STDARG_H),y) +include/stdarg.h: include/nuttx/lib/stdarg.h .clean_context + $(Q) cp -f include/nuttx/lib/stdarg.h include/stdarg.h +else +include/stdarg.h: +endif + +# Target used to copy include/nuttx/lib/setjmp.h. If CONFIG_ARCH_SETJMP_H is +# defined, then there is an architecture specific setjmp.h header file +# that will be included indirectly from include/lib/setjmp.h. But first, we +# have to copy setjmp.h from include/nuttx/. to include/. + +ifeq ($(CONFIG_ARCH_SETJMP_H),y) +include/setjmp.h: include/nuttx/lib/setjmp.h .clean_context + $(Q) cp -f include/nuttx/lib/setjmp.h include/setjmp.h +else +include/setjmp.h: +endif + +# Targets used to build include/nuttx/version.h. Creation of version.h is +# part of the overall NuttX configuration sequence. Notice that the +# tools/mkversion tool is built and used to create include/nuttx/version.h + +tools/mkversion$(HOSTEXEEXT): + $(Q) $(MAKE) -C tools -f Makefile.host mkversion$(HOSTEXEEXT) + +# [Re-]create .version if it doesn't already exist. + +$(TOPDIR)/.version: + $(Q) echo "Create .version" + $(Q) tools/version.sh $(VERSION_ARG) .version + $(Q) chmod 755 .version + +include/nuttx/version.h: $(TOPDIR)/.version tools/mkversion$(HOSTEXEEXT) .clean_context + $(Q) echo "Create version.h" + $(Q) tools/mkversion $(TOPDIR) > $@.tmp + $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) + +# Targets used to build include/nuttx/config.h. Creation of config.h is +# part of the overall NuttX configuration sequence. Notice that the +# tools/mkconfig tool is built and used to create include/nuttx/config.h + +tools/mkconfig$(HOSTEXEEXT): + $(Q) $(MAKE) -C tools -f Makefile.host mkconfig$(HOSTEXEEXT) + +include/nuttx/config.h: $(TOPDIR)/.config tools/mkconfig$(HOSTEXEEXT) .clean_context + $(Q) tools/mkconfig $(TOPDIR) > $@.tmp + $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) + +# Targets used to create dependencies + +tools/mkdeps$(HOSTEXEEXT): + $(Q) $(MAKE) -C tools -f Makefile.host mkdeps$(HOSTEXEEXT) + +tools/cnvwindeps$(HOSTEXEEXT): + $(Q) $(MAKE) -C tools -f Makefile.host cnvwindeps$(HOSTEXEEXT) + +# dirlinks, and helpers +# +# Directories links. Most of establishing the NuttX configuration involves +# setting up symbolic links with 'generic' directory names to specific, +# configured directories. + +# Link the arch//include directory to include/arch + +include/arch: .clean_context + @echo "LN: include/arch to $(ARCH_DIR)/include" + $(Q) $(DIRLINK) $(TOPDIR)/$(ARCH_DIR)/include include/arch + $(Q) touch $@ + +# Link the boards////include directory to include/arch/board + +include/arch/board: include/arch + @echo "LN: include/arch/board to $(BOARD_DIR)/include" + $(Q) $(DIRLINK) $(BOARD_DIR)/include include/arch/board + $(Q) touch $@ + +ifneq ($(BOARD_COMMON_DIR),) +# Link the boards///common dir to arch//src/board +# Link the boards////src dir to arch//src/board/board + +$(ARCH_SRC)/board: .clean_context + @echo "LN: $(ARCH_SRC)/board to $(BOARD_COMMON_DIR)" + $(Q) $(DIRLINK) $(BOARD_COMMON_DIR) $(ARCH_SRC)/board + @echo "LN: $(ARCH_SRC)/board/board to $(BOARD_DIR)/src" + $(Q) $(DIRLINK) $(BOARD_DIR)/src $(ARCH_SRC)/board/board + $(Q) touch $@ +else +# Link the boards////src dir to arch//src/board + +$(ARCH_SRC)/board: .clean_context + @echo "LN: $(ARCH_SRC)/board to $(BOARD_DIR)/src" + $(Q) $(DIRLINK) $(BOARD_DIR)/src $(ARCH_SRC)/board + $(Q) touch $@ +endif + +# Link the boards///drivers dir to drivers/platform + +drivers/platform: .clean_context + @echo "LN: $(TOPDIR)/drivers/platform to $(BOARD_DRIVERS_DIR)" + $(Q) $(DIRLINK) $(BOARD_DRIVERS_DIR) $(TOPDIR)/drivers/platform + $(Q) touch $@ + +# Link arch//src/ to arch//src/chip + +$(ARCH_SRC)/chip: .clean_context +ifeq ($(CONFIG_ARCH_CHIP_CUSTOM),y) + @echo "LN: $(ARCH_SRC)/chip to $(CHIP_DIR)" + $(Q) $(DIRLINK) $(CHIP_DIR) $(ARCH_SRC)/chip +else ifneq ($(CONFIG_ARCH_CHIP),) + @echo "LN: $(ARCH_SRC)/chip to $(ARCH_SRC)/$(CONFIG_ARCH_CHIP)" + $(Q) $(DIRLINK) $(TOPDIR)/$(ARCH_SRC)/$(CONFIG_ARCH_CHIP) $(ARCH_SRC)/chip +endif + $(Q) cp -f $(CHIP_KCONFIG) $(TOPDIR)/arch/dummy/Kconfig + $(Q) touch $@ + +# Link arch//include/ to include/arch/chip + +include/arch/chip: include/arch +ifeq ($(CONFIG_ARCH_CHIP_CUSTOM),y) + @echo "LN: include/arch/chip to $(CHIP_DIR)/include" + $(Q) $(DIRLINK) $(CHIP_DIR)/include include/arch/chip +else ifneq ($(CONFIG_ARCH_CHIP),) + @echo "LN: include/arch/chip to $(ARCH_INC)/$(CONFIG_ARCH_CHIP)" + $(Q) $(DIRLINK) $(TOPDIR)/$(ARCH_INC)/$(CONFIG_ARCH_CHIP) include/arch/chip +endif + $(Q) touch $@ + +dirlinks: include/arch include/arch/board include/arch/chip $(ARCH_SRC)/board $(ARCH_SRC)/chip drivers/platform + $(Q) $(MAKE) -C libs/libxx dirlinks + $(Q) $(MAKE) -C boards dirlinks + $(Q) $(MAKE) -C openamp dirlinks + $(Q) $(MAKE) -C $(CONFIG_APPS_DIR) dirlinks + +# context +# +# The context target is invoked on each target build to assure that NuttX is +# properly configured. The basic configuration steps include creation of the +# the config.h and version.h header files in the include/nuttx directory and +# the establishment of symbolic links to configured directories. + +context: include/nuttx/config.h include/nuttx/version.h include/math.h include/float.h include/stdarg.h include/setjmp.h dirlinks + $(Q) mkdir -p staging + $(Q) for dir in $(CONTEXTDIRS) ; do \ + $(MAKE) -C $$dir context || exit; \ + done + +# clean_context +# +# This is part of the distclean target. It removes all of the header files +# and symbolic links created by the context target. + +clean_context: + $(Q) for dir in $(CCLEANDIRS) ; do \ + if [ -e $$dir/Makefile ]; then \ + $(MAKE) -C $$dir clean_context ; \ + fi \ + done + $(call DELFILE, include/nuttx/config.h) + $(call DELFILE, include/nuttx/version.h) + $(call DELFILE, include/float.h) + $(call DELFILE, include/math.h) + $(call DELFILE, include/stdarg.h) + $(call DELFILE, include/setjmp.h) + $(call DELFILE, arch/dummy/Kconfig) + $(Q) $(DIRUNLINK) include/arch/board + $(Q) $(DIRUNLINK) include/arch/chip + $(Q) $(DIRUNLINK) include/arch + $(Q) $(DIRUNLINK) $(ARCH_SRC)/board/board + $(Q) $(DIRUNLINK) $(ARCH_SRC)/board + $(Q) $(DIRUNLINK) $(ARCH_SRC)/chip + $(Q) $(DIRUNLINK) $(TOPDIR)/drivers/platform + +.clean_context: .config + +$(Q) $(MAKE) clean_context + $(Q) touch $@ + +# Archive targets. The target build sequence will first create a series of +# libraries, one per configured source file directory. The final NuttX +# execution will then be built from those libraries. The following targets +# build those libraries. + +include tools/LibTargets.mk + +# pass1 and pass2 +# +# If the 2 pass build option is selected, then this pass1 target is +# configured to be built before the pass2 target. This pass1 target may, as an +# example, build an extra link object (CONFIG_PASS1_OBJECT) which may be an +# incremental (relative) link object, but could be a static library (archive); +# some modification to this Makefile would be required if CONFIG_PASS1_OBJECT +# is an archive. Exactly what is performed during pass1 or what it generates +# is unknown to this makefile unless CONFIG_PASS1_OBJECT is defined. + +pass1: $(USERLIBS) + +pass2: $(NUTTXLIBS) + +# $(BIN) +# +# Create the final NuttX executable in a two pass build process. In the +# normal case, all pass1 and pass2 dependencies are created then pass1 +# and pass2 targets are built. However, in some cases, you may need to build +# pass1 dependencies and pass1 first, then build pass2 dependencies and pass2. +# in that case, execute 'make pass1 pass2' from the command line. + +$(BIN): pass1 pass2 +ifeq ($(CONFIG_BUILD_2PASS),y) + $(Q) if [ -z "$(CONFIG_PASS1_BUILDIR)" ]; then \ + echo "ERROR: CONFIG_PASS1_BUILDIR not defined"; \ + exit 1; \ + fi + $(Q) if [ ! -d "$(CONFIG_PASS1_BUILDIR)" ]; then \ + echo "ERROR: CONFIG_PASS1_BUILDIR does not exist"; \ + exit 1; \ + fi + $(Q) if [ ! -f "$(CONFIG_PASS1_BUILDIR)/Makefile" ]; then \ + echo "ERROR: No Makefile in CONFIG_PASS1_BUILDIR"; \ + exit 1; \ + fi + $(Q) $(MAKE) -C $(CONFIG_PASS1_BUILDIR) LINKLIBS="$(LINKLIBS)" USERLIBS="$(USERLIBS)" "$(CONFIG_PASS1_TARGET)" +endif + $(Q) $(MAKE) -C $(ARCH_SRC) EXTRA_OBJS="$(EXTRA_OBJS)" LINKLIBS="$(LINKLIBS)" EXTRAFLAGS="$(KDEFINE) $(EXTRAFLAGS)" $(BIN) + $(Q) if [ -w /tftpboot ] ; then \ + cp -f $(BIN) /tftpboot/$(BIN).${CONFIG_ARCH}; \ + fi + $(Q) echo $(BIN) > nuttx.manifest + $(Q) printf "%s\n" *.map >> nuttx.manifest +ifeq ($(CONFIG_INTELHEX_BINARY),y) + @echo "CP: nuttx.hex" + $(Q) $(OBJCOPY) $(OBJCOPYARGS) -O ihex $(BIN) nuttx.hex + $(Q) echo nuttx.hex >> nuttx.manifest +endif +ifeq ($(CONFIG_MOTOROLA_SREC),y) + @echo "CP: nuttx.srec" + $(Q) $(OBJCOPY) $(OBJCOPYARGS) -O srec $(BIN) nuttx.srec + $(Q) echo nuttx.srec >> nuttx.manifest +endif +ifeq ($(CONFIG_RAW_BINARY),y) + @echo "CP: nuttx.bin" + $(Q) $(OBJCOPY) $(OBJCOPYARGS) -O binary $(BIN) nuttx.bin + $(Q) echo nuttx.bin >> nuttx.manifest +endif +ifeq ($(CONFIG_UBOOT_UIMAGE),y) + @echo "MKIMAGE: uImage" + $(Q) mkimage -A $(CONFIG_ARCH) -O linux -C none -T kernel -a $(CONFIG_UIMAGE_LOAD_ADDRESS) \ + -e $(CONFIG_UIMAGE_ENTRY_POINT) -n $(BIN) -d nuttx.bin uImage + $(Q) if [ -w /tftpboot ] ; then \ + cp -f uImage /tftpboot/uImage; \ + fi + $(Q) echo "uImage" >> nuttx.manifest +endif + $(call POSTBUILD, $(TOPDIR)) + +# download +# +# This is a helper target that will rebuild NuttX and download it to the target +# system in one step. The operation of this target depends completely upon +# implementation of the DOWNLOAD command in the user Make.defs file. It will +# generate an error if the DOWNLOAD command is not defined. + +download: $(BIN) + $(call DOWNLOAD, $<) + +# pass1dep: Create pass1 build dependencies +# pass2dep: Create pass2 build dependencies + +pass1dep: context tools/mkdeps$(HOSTEXEEXT) tools/cnvwindeps$(HOSTEXEEXT) + $(Q) for dir in $(USERDEPDIRS) ; do \ + $(MAKE) -C $$dir depend || exit; \ + done + +pass2dep: context tools/mkdeps$(HOSTEXEEXT) tools/cnvwindeps$(HOSTEXEEXT) + $(Q) for dir in $(KERNDEPDIRS) ; do \ + $(MAKE) -C $$dir EXTRAFLAGS="$(KDEFINE) $(EXTRAFLAGS)" depend || exit; \ + done + +# Configuration targets +# +# These targets depend on the kconfig-frontends packages. To use these, you +# must first download and install the kconfig-frontends package from this +# location: https://bitbucket.org/nuttx/tools/downloads/. See README.txt +# file in the NuttX tools GIT repository for additional information. + +config: apps_preconfig + $(Q) APPSDIR=${CONFIG_APPS_DIR} EXTERNALDIR=$(EXTERNALDIR) kconfig-conf Kconfig + +oldconfig: apps_preconfig + $(Q) APPSDIR=${CONFIG_APPS_DIR} EXTERNALDIR=$(EXTERNALDIR) kconfig-conf --oldconfig Kconfig + +olddefconfig: apps_preconfig + $(Q) APPSDIR=${CONFIG_APPS_DIR} EXTERNALDIR=$(EXTERNALDIR) kconfig-conf --olddefconfig Kconfig + +menuconfig: apps_preconfig + $(Q) APPSDIR=${CONFIG_APPS_DIR} EXTERNALDIR=$(EXTERNALDIR) kconfig-mconf Kconfig + +nconfig: apps_preconfig + $(Q) APPSDIR=${CONFIG_APPS_DIR} EXTERNALDIR=$(EXTERNALDIR) kconfig-nconf Kconfig + +qconfig: apps_preconfig + $(Q) APPSDIR=${CONFIG_APPS_DIR} EXTERNALDIR=$(EXTERNALDIR) kconfig-qconf Kconfig + +gconfig: apps_preconfig + $(Q) APPSDIR=${CONFIG_APPS_DIR} EXTERNALDIR=$(EXTERNALDIR) kconfig-gconf Kconfig + +savedefconfig: apps_preconfig + $(Q) APPSDIR=${CONFIG_APPS_DIR} EXTERNALDIR=$(EXTERNALDIR) kconfig-conf --savedefconfig defconfig.tmp Kconfig + $(Q) kconfig-tweak --file defconfig.tmp -u CONFIG_APPS_DIR + $(Q) grep "CONFIG_ARCH=" .config >> defconfig.tmp + $(Q) grep "^CONFIG_ARCH_CHIP_" .config >> defconfig.tmp; true + $(Q) grep "CONFIG_ARCH_CHIP=" .config >> defconfig.tmp; true + $(Q) grep "CONFIG_ARCH_BOARD=" .config >> defconfig.tmp; true + $(Q) grep "^CONFIG_ARCH_CUSTOM" .config >> defconfig.tmp; true + $(Q) grep "^CONFIG_ARCH_BOARD_CUSTOM" .config >> defconfig.tmp; true + $(Q) export LC_ALL=C; cat defconfig.tmp | sort | uniq > sortedconfig.tmp + $(Q) echo "#" > warning.tmp + $(Q) echo "# This file is autogenerated: PLEASE DO NOT EDIT IT." >> warning.tmp + $(Q) echo "#" >> warning.tmp + $(Q) echo "# You can use \"make menuconfig\" to make any modifications to the installed .config file." >> warning.tmp + $(Q) echo "# You can then do \"make savedefconfig\" to generate a new defconfig file that includes your" >> warning.tmp + $(Q) echo "# modifications." >> warning.tmp + $(Q) echo "#" >> warning.tmp + $(Q) cat warning.tmp sortedconfig.tmp > defconfig + $(Q) rm -f warning.tmp + $(Q) rm -f defconfig.tmp + $(Q) rm -f sortedconfig.tmp + +# export +# +# The export target will package the NuttX libraries and header files into +# an exportable package. Caveats: (1) These needs some extension for the KERNEL +# build; it needs to receive USERLIBS and create a libuser.a). (2) The logic +# in tools/mkexport.sh only supports GCC and, for example, explicitly assumes +# that the archiver is 'ar' + +export: $(NUTTXLIBS) + $(Q) MAKE=${MAKE} $(MKEXPORT) $(MKEXPORT_ARGS) -l "$(EXPORTLIBS)" + +# General housekeeping targets: dependencies, cleaning, etc. +# +# depend: Create both PASS1 and PASS2 dependencies +# clean: Removes derived object files, archives, executables, and +# temporary files, but retains the configuration and context +# files and directories. +# distclean: Does 'clean' then also removes all configuration and context +# files. This essentially restores the directory structure +# to its original, unconfigured stated. + +depend: pass1dep pass2dep + +$(foreach SDIR, $(CLEANDIRS), $(eval $(call SDIR_template,$(SDIR),clean))) + +subdir_clean: $(foreach SDIR, $(CLEANDIRS), $(SDIR)_clean) +ifeq ($(CONFIG_BUILD_2PASS),y) + $(Q) $(MAKE) -C $(CONFIG_PASS1_BUILDIR) clean +endif + +clean: subdir_clean + $(call DELFILE, $(BIN)) + $(call DELFILE, nuttx.*) + $(call DELFILE, *.map) + $(call DELFILE, _SAVED_APPS_config) + $(call DELFILE, nuttx-export*.zip) + $(call DELDIR, nuttx-export*) + $(call DELFILE, nuttx_user*) + $(call DELDIR, staging) + $(call DELFILE, uImage) + $(call CLEAN) + +$(foreach SDIR, $(CLEANDIRS), $(eval $(call SDIR_template,$(SDIR),distclean))) + +subdir_distclean: $(foreach SDIR, $(CLEANDIRS), $(SDIR)_distclean) + +distclean: clean subdir_distclean clean_context +ifeq ($(CONFIG_BUILD_2PASS),y) + $(Q) $(MAKE) -C $(CONFIG_PASS1_BUILDIR) distclean +endif + $(call DELFILE, Make.defs) + $(call DELFILE, defconfig) + $(call DELFILE, .config) + $(call DELFILE, .config.old) + $(call DELFILE, .gdbinit) + $(call DELFILE, .clean_context) + $(Q) $(MAKE) -C tools -f Makefile.host clean + +# Application housekeeping targets. The APPDIR variable refers to the user +# application directory. A sample apps/ directory is included with NuttX, +# however, this is not treated as part of NuttX and may be replaced with a +# different application directory. For the most part, the application +# directory is treated like any other build directory in this script. However, +# as a convenience, the following targets are included to support housekeeping +# functions in the user application directory from the NuttX build directory. +# +# apps_preconfig: Prepare applications to be configured +# apps_clean: Perform the clean operation only in the user application +# directory +# apps_distclean: Perform the distclean operation only in the user application +# directory. + +apps_preconfig: dirlinks +ifneq ($(APPDIR),) + $(Q) $(MAKE) -C $(APPDIR) preconfig +endif + +apps_clean: +ifneq ($(APPDIR),) + $(Q) $(MAKE) -C $(APPDIR) clean +endif + +apps_distclean: +ifneq ($(APPDIR),) + $(Q) $(MAKE) -C $(APPDIR) distclean +endif diff --git a/Ubiquitous/Nuttx/app_match_nuttx/nuttx/tools/cfgdefine.c b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/tools/cfgdefine.c new file mode 100644 index 000000000..7b52a2f2b --- /dev/null +++ b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/tools/cfgdefine.c @@ -0,0 +1,360 @@ +/**************************************************************************** + * tools/cfgdefine.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include "cfgdefine.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +char line[LINESIZE + 1]; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* These are configuration variable name that are quoted by configuration + * tool but which must be unquoted when used in C code. + */ + +static const char *dequote_list[] = +{ + /* NuttX */ + + "CONFIG_DEBUG_OPTLEVEL", /* Custom debug level */ + "CONFIG_EXECFUNCS_NSYMBOLS_VAR", /* Variable holding number of symbols in the table */ + "CONFIG_EXECFUNCS_SYMTAB_ARRAY", /* Symbol table array used by exec[l|v] */ + "CONFIG_INIT_ARGS", /* Argument list of entry point */ + "CONFIG_INIT_SYMTAB", /* Global symbol table */ + "CONFIG_INIT_NEXPORTS", /* Global symbol table size */ + "CONFIG_MODLIB_SYMTAB_ARRAY", /* Symbol table array used by modlib functions */ + "CONFIG_MODLIB_NSYMBOLS_VAR", /* Variable holding number of symbols in the table */ + "CONFIG_PASS1_BUILDIR", /* Pass1 build directory */ + "CONFIG_PASS1_TARGET", /* Pass1 build target */ + "CONFIG_PASS1_OBJECT", /* Pass1 build object */ + "CONFIG_USER_ENTRYPOINT", /* Name of entry point function */ + + /* NxWidgets/NxWM */ + + "CONFIG_NXWM_BACKGROUND_IMAGE", /* Name of bitmap image class */ + "CONFIG_NXWM_CALIBRATION_ICON", /* Name of bitmap image class */ + "CONFIG_NXWM_HEXCALCULATOR_ICON", /* Name of bitmap image class */ + "CONFIG_NXWM_MINIMIZE_BITMAP", /* Name of bitmap image class */ + "CONFIG_NXWM_NXTERM_ICON", /* Name of bitmap image class */ + "CONFIG_NXWM_STARTWINDOW_ICON", /* Name of bitmap image class */ + "CONFIG_NXWM_STOP_BITMAP", /* Name of bitmap image class */ + + /* apps/ definitions */ + + "CONFIG_SYSTEM_NSH_SYMTAB_ARRAYNAME", /* Symbol table array name */ + "CONFIG_SYSTEM_NSH_SYMTAB_COUNTNAME", /* Name of the variable holding the number of symbols */ + NULL /* Marks the end of the list */ +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/* Skip over any spaces */ + +static char *skip_space(char *ptr) +{ + while (*ptr && isspace((int)*ptr)) ptr++; + return ptr; +} + +/* Find the end of a variable string */ + +static char *find_name_end(char *ptr) +{ + while (*ptr && (isalnum((int)*ptr) || *ptr == '_')) ptr++; + return ptr; +} + +/* Find the end of a value string */ + +static char *find_value_end(char *ptr) +{ + while (*ptr && !isspace((int)*ptr)) + { + if (*ptr == '"') + { + do ptr++; while (*ptr && *ptr != '"'); + if (*ptr) ptr++; + } + else + { + do ptr++; while (*ptr && !isspace((int)*ptr) && *ptr != '"'); + } + } + + return ptr; +} + +/* Read the next line from the configuration file */ + +static char *read_line(FILE *stream) +{ + char *ptr; + + for (; ; ) + { + line[LINESIZE] = '\0'; + if (!fgets(line, LINESIZE, stream)) + { + return NULL; + } + else + { + ptr = skip_space(line); + if (*ptr && *ptr != '#' && *ptr != '\n') + { + return ptr; + } + } + } +} + +/* Parse the line from the configuration file into a variable name + * string and a value string. + */ + +static void parse_line(char *ptr, char **varname, char **varval) +{ + /* Skip over any leading spaces */ + + ptr = skip_space(ptr); + + /* The first no-space is the beginning of the variable name */ + + *varname = skip_space(ptr); + *varval = NULL; + + /* Parse to the end of the variable name */ + + ptr = find_name_end(ptr); + + /* An equal sign is expected next, perhaps after some white space */ + + if (*ptr && *ptr != '=') + { + /* Some else follows the variable name. Terminate the variable + * name and skip over any spaces. + */ + + *ptr = '\0'; + ptr = skip_space(ptr + 1); + } + + /* Verify that the equal sign is present */ + + if (*ptr == '=') + { + /* Make sure that the variable name is terminated (this was already + * done if the name was followed by white space. + */ + + *ptr = '\0'; + + /* The variable value should follow =, perhaps separated by some + * white space. + */ + + ptr = skip_space(ptr + 1); + if (*ptr) + { + /* Yes.. a variable follows. Save the pointer to the start + * of the variable string. + */ + + *varval = ptr; + + /* Find the end of the variable string and make sure that it + * is terminated. + */ + + ptr = find_value_end(ptr); + *ptr = '\0'; + } + } +} + +static char *dequote_value(const char *varname, char *varval) +{ + const char **dqnam; + char *dqval = varval; + char *ptr; + int len; + int i; + + if (dqval) + { + /* Check if the variable name is in the dequoted list of strings */ + + for (dqnam = dequote_list; *dqnam; dqnam++) + { + if (strcmp(*dqnam, varname) == 0) + { + break; + } + } + + /* Did we find the variable name in the list of configuration variables + * to be dequoted? + */ + + if (*dqnam) + { + /* Yes... Check if there is a trailing quote */ + + len = strlen(dqval); + if (dqval[len - 1] == '"') + { + /* Yes... replace it with a terminator */ + + dqval[len - 1] = '\0'; + len--; + } + + /* Is there a leading quote? */ + + if (dqval[0] == '"') + { + /* Yes.. skip over the leading quote */ + + dqval++; + len--; + } + + /* A special case is a quoted list of quoted strings. In that case + * we will need to remove the backspaces from the internally quoted + * strings. NOTE: this will not handle nested quoted quotes. + */ + + for (ptr = dqval; *ptr; ptr++) + { + /* Check for a quoted quote */ + + if (ptr[0] == '\\' && ptr[1] == '"') + { + /* Delete the backslash by moving the rest of the string */ + + for (i = 0; ptr[i]; i++) + { + ptr[i] = ptr[i + 1]; + } + + len--; + } + } + + /* Handle the case where nothing is left after dequoting */ + + if (len <= 0) + { + dqval = NULL; + } + } + } + + return dqval; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void generate_definitions(FILE *stream) +{ + char *varname; + char *varval; + char *ptr; + + /* Loop until the entire file has been parsed. */ + + do + { + /* Read the next line from the file */ + + ptr = read_line(stream); + if (ptr) + { + /* Parse the line into a variable and a value field */ + + parse_line(ptr, &varname, &varval); + + /* Was a variable name found? */ + + if (varname) + { + /* Yes.. dequote the value if necessary */ + + varval = dequote_value(varname, varval); + + /* If no value was provided or if the special value 'n' was + * provided, then undefine the configuration variable. + */ + + if (!varval || strcmp(varval, "n") == 0) + { + printf("#undef %s\n", varname); + } + + /* Simply define the configuration variable to '1' if it has + * the special value "y" + */ + + else if (strcmp(varval, "y") == 0) + { + printf("#define %s 1\n", varname); + printf("#define %s 1\n", &varname[7]); + + } + + /* Or to '2' if it has the special value 'm' */ + + else if (strcmp(varval, "m") == 0) + { + printf("#define %s 2\n", varname); + printf("#define %s 2\n", &varname[7]); + } + + /* Otherwise, use the value as provided */ + + else + { + printf("#define %s %s\n", varname, varval); + printf("#define %s %s\n", &varname[7], varval); + } + } + } + } + while (ptr); +} diff --git a/readme.md b/readme.md new file mode 100644 index 000000000..ca08a5932 --- /dev/null +++ b/readme.md @@ -0,0 +1,315 @@ +# 写在前面 + +如果期望该框架运行在Nuttx系统上,请阅读此文档,否则请跳过即可。 + +## 1、感 - 传感器框架支持Nuttx + +目前感框架下面的传感器有I2C和串口两种,使用两种方式的传感器在APP_Framework下的修改大同小异,这里以hs300x传感器测量温度为例,说明增加一款传感器适配Nuttx时APP_Framework目录下需要修改的文件: + +### APP_Framework目录下修改 + +```shell +└── APP_Framework + ├── Applications + │   ├── framework_init.c + │   ├── Make.defs + │   ├── Makefile + │   └── sensor_app + │   ├── Kconfig + │   ├── Make.defs + │   ├── Makefile + │   └── temperature_hs300x.c + ├── Framework + │   ├── Make.defs + │   └── sensor + │   ├── Make.defs + │   ├── Makefile + │   ├── sensor.c + │   └── temperature + │   ├── hs300x_temp + │   │   ├── hs300x_temp.c + │   │   ├── Make.defs + │   │   └── Makefile + │   ├── Kconfig + │   ├── Make.defs + │   └── Makefile + ├── Make.defs + └── Makefile +``` + +(1)在上述文件中,Make.defs文件是Nuttx特有的文件描述,每个Make.defs有两个作用: + +​ ①根据对应的宏控制是否为CONFIGURED_APPS添加需要编译的目录 + +​ ②包含子目录中的所有Make.defs,向上传递 + +(2)Makefile文件是多个操作系统共用的,里面用CONFIG_ADD_XXXX_FETURES宏来区别不同的操作系统 + +(3)Kconfig文件也是多个操作系统共用的,不同操作系统配置时略有差异也用CONFIG_ADD_XXXX_FETURES进行了控制。 + +(4)*.c文件的针对适配Nuttx的修改一般是头文件的包含或者接口的调用需要区分不同的操作系统 + +### Ubiquitous目录下修改 + +#### 使用I2C外设--以hs300x为例 + +```shell +└── Nuttx + └── app_match_nuttx + ├── apps + │   ├── Makefile + │   └── nshlib + │   ├── Kconfig + │   ├── Makefile + │   ├── nsh_Applicationscmd.c + │   ├── nsh_command.c + │   └── nsh.h + ├── build.sh + └── nuttx + ├── boards + │   └── arm + │   └── stm32 + │   ├── common + │   │   ├── include + │   │   │   └── stm32_hs300x.h + │   │   └── src + │   │   ├── Make.defs + │   │   └── stm32_hs300x.c + │   └── stm32f4discovery + │   ├── scripts + │   │   └── Make.defs + │   └── src + │   └── stm32_bringup.c + ├── drivers + │   └── sensors + │   ├── hs300x.c + │   ├── Kconfig + │   └── Make.defs + ├── include + │   └── nuttx + │   └── sensors + │   └── hs300x.h + ├── Kconfig + ├── Makefile + └── tools + ├── cfgdefine.c + └── Makefile.unix +``` + +适配Nuttx系统需要修改Nuttx原生代码中多处文件,为了不破坏Nuttx原生代码,我们可以先在Nuttx原生代码中进行修改,然后将修改的文件导出到app_match_nuttx目录下,该目录下的文件结构与Nuttx原生代码完全一致,在编译前在app_match_nuttx目录执行一下source build.sh即可将修改同步到nuttx中,进行编译。 + +(1)app_match_nuttx/apps下的Makefile文件进行了一处修改,把APP_Framework目录最上层的Make.defs包含进来,这样在编译的时候就会引导进入APP_Framework目录进行相应的编译,该处已经修改完成,后续不用再去修改 + +```makefile +include $(APPDIR)/../../../APP_Framework/Make.defs +``` + +(2)app_match_nuttx/apps/nshlib下的修改,Nuttx下应用的编译方式有两种,一种是编译在Builtin Apps下,另一种是编译成系统命令cmd,为了与XiUos和rt-thread等其他操作系统保持一致,采用后面一种编译方式。具体修改参见该目录下的修改即可,这里不加赘述。 + +(3)app_match_nuttx/nuttx下修改: + +目前感框架的传感器使用的外设有I2C和串口两种,Nuttx针对串口外设的驱动做了比较完善支持,因此使用串口的传感器只需要去使能相应的串口即可使用,目前ps5308传感器就是这种方式,使用I2C和SPI外设的传感器,目前Nuttx的做法是在nuttx/drivers/sensors进行传感器的注册,主要是定义open/close/read/write等标准的操作接口。传感器的注册这一过程主要涉及到文件主要是上图中的 + +stm32_hs300x.h + +stm32_hs300x.c + +stm32f4discovery/stm32_bringup.c(注意支持不同的板子需要在对应的文件下去修改,这里当前是stm32f4discovery) + +hs300x.c + +hs300x.h + +(4)nuttx/Makefile的修改,在这个文件里只有一出修改,设置了一个环境变量 KERNEL_ROOT,这个环境变量在APP_Framework中会用到。该处已经修改完成,后续不用再去修改 + +```makefile +export KERNEL_ROOT = $(CURDIR) +``` + +(5) nuttx/tools/Makefile.unix的修改,这个文件中新定义了一个环境变量APPPATHS,将APP_Framework中所以的头文件的路径包含进去,如果后面有新的头文件加入,一定需要在这里加入新头文件的路径;设置了一个环境变量SRC_APP_DIR这个环境变量在APP_Framework中会用到。 + +```makefile +export APPPATHS = -I$(APPDIR)/../../../APP_Framework/Framework/sensor +APPPATHS += -I$(APPDIR)/../../../APP_Framework/Applications/general_functions/list +APPPATHS += -I$(APPDIR)/../../../APP_Framework/Framework/transform_layer/nuttx + +export SRC_APP_DIR = ../../../APP_Framework +``` + +(6)要使(5)中的修改生效,需要修改对应板子的Make.defs文件,以stm32f4discovery为例,在nuttx/boards/arm/stm32/stm32f4discovery/scripts/Make.defs中CFLAGS编译选项加上在(5)中设置的APPPATHS + +```makefile +CFLAGS := $(APPPATHS) $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe +``` + +该Make.defs文件在实际编译时会被拷贝至nuttx目录下 + +#### 使用串口外设--以ps5308传感器为例 + +``` +. +├── APP_Framework +│   ├── Applications +│   │   ├── framework_init.c +│   │   └── sensor_app +│   │   ├── Kconfig +│   │   ├── Makefile +│   │   ├── pm10_0_ps5308.c +│   │   ├── pm1_0_ps5308.c +│   │   └── pm2_5_ps5308.c +│   └── Framework +│   └── sensor +│   └── pm +│   ├── Kconfig +│   ├── Make.defs +│   └── ps5308 +│   ├── Make.defs +│   ├── Makefile +│   └── ps5308.c +└── Ubiquitous + └── Nuttx + └── app_match_nuttx + ├── apps + │   └── nshlib + │   ├── Kconfig + │   ├── nsh_Applicationscmd.c + │   ├── nsh_command.c + │   └── nsh.h + └── nuttx + └── arch + └── arm + └── src + └── stm32 + └── stm32_serial.c +``` + +(1)Nuttx/app_match_nuttx/apps/nshlib下修改,将应用编译成cmd形式,与上面HS300x处描述一致,参考上面即可 + +(2)/nuttx/arch/arm/src/stm32/stm32_serial.c,此处代码原本是会将所有打开的串口从0开始依次注册为ttyS1-ttySN,比较不方便,例如打开了USART1、USART3、USART5,USART3将会被注册为ttyS2,容易引起歧义,这边做的修改会将USARTN,注册为ttySN。 + +其他架构的板卡,如K210,需要在nuttx/arch/risc-v/src/k210/k210_serial.c进行适配修改。 + +## 2、硬件支持 + +目前Nuttx支持ARM和RISC-V两种架构的微处理器: + +### ARM + +ARM架构系列的开发板有 + + stm32f407-st-discovery + +### RISC-V + +RISC-V架构系列的开发板有 + +​ + +## 3、开发环境 + +### 推荐使用: + +### 操作系统: [Ubuntu18.04](https://ubuntu.com/download/desktop) + +### 开发工具: [VSCode](http://101.36.126.201:8011/vscode_1.55.2-1618307277_amd64.deb) + +### 依赖包安装: + +``` +$ sudo apt install build-essential pkg-config git +$ sudo apt install gcc make libncurses5-dev openssl libssl-dev bison flex libelf-dev autoconf libtool gperf libc6-dev +``` + +### 裁减配置工具: + +kconfig-frontends工具地址: https://forgeplus.trustie.net/projects/xuos/kconfig-frontends,下载与安装的具体命令如下: + +```shell +mkdir kfrontends && cd kfrontends +git clone https://git.trustie.net/xuos/kconfig-frontends.git +``` + +下载源码后按以下步骤执行软件安装: + +```shell +cd kconfig-frontends + ./xs_build.sh +``` + +### 编译工具链: + +ARM: arm-none-eabi,默认安装到Ubuntu的/usr/bin/arm-none-eabi-,使用如下命令行下载 + +```shell +mkdir kfrontends && cd kfrontends +git clone https://git.trustie.net/xuos/kconfig-frontends.git +``` + +## 4、编译及配置 + +#### 在Nuttx\app_match_nuttx目录下执行 + +```shell +chmod +x build.sh + +source build.sh +``` + +#### 执行完毕会跳转到Nuttx\nuttx目录,执行 + +```shell +sudo ./tools/configure.sh stm32f4discovery:nsh (应用内核一起编译) + +sudo ./tools/configure.sh stm32f4discovery:kostest (应用内核分开编译) +``` + +#### 然后执行 + +```shell +sudo make menuconfig +``` + +##### 使用I2C外设--以hs300x温度传感器为例说明配置过程: + +①进入XIUOS features > APP_Framework > Framework ,选择操作系统(这一步一定要最先配置) + +②依次进入XIUOS features > APP_Framework > Framework > support sensor framework > Using temperature sensor device + +​ 进行sensor name、quantity name、device name(这里是一个字符设备的路径)、i2c address的配置。注意这里设置的 HS300x device name 设置的/dev/i2cN需要与第④步勾选的i2cN保持一致 + +③依次进入XIUOS features > APP_Framework > Applications > sensor app > Using sensor apps > Using sensor temperature apps ,并进行勾选 + +④依次进入System Type > STM32 Peripheral Support ,勾选传感器使用的I2C外设。 + +⑤ 进入Device Drivers > I2C Driver Support ,找到I2C Driver Support ,勾选上I2C Slave + +⑥在Device Drivers 下找到Sensor Device Support勾选上后进入,勾选HS300X Temperature and Humidity Sensor support并设置频率 + +退出menuconfig界面,注意记得保存,此时会在nuttx目录下生成一个.config文件。 + +##### 使用串口外设--以ps5308传感器pm1.0为例说明配置过程: + +①进入XIUOS features > APP_Framework > Framework ,选择操作系统(这一步一定要最先配置) + +②依次进入XIUOS features > APP_Framework > Framework > support sensor framework > Using PM sensor device,进行相应的勾选与设置,注意这里设置的 PS5308 device name 设置的/dev/ttySN需要与第④步勾选的USART-N保持一致 + +③依次进入XIUOS features > APP_Framework > Applications > sensor app > Using sensor apps > Using sensor PM1.0 apps,并进行勾选 + +④依次进入System Type > STM32 Peripheral Support ,勾选传感器使用的USART外设。 + +⑤ 依次进入RTOS Features > Tasks and Scheduling,勾选Support parent/child task relationships及Retain child exit status + +⑥ 依次进入Device Drivers > Serial Driver Support > USARTN Configuration进行外设buffesize大小、波特率等设置。 + +退出menuconfig界面,注意记得保存,此时会在nuttx目录下生成一个.config文件。 + + + +#### 在当前目录执行编译 + +```shell +sudo make -j8 +``` + +make时加上V=1参数可以看到较为详细的编译信息,但是编译过程会比较慢。最后在nuttx下会编译出一个nuttx.bin文件(应用内核一起编译) +