Browse Source

add hs300x and ps5308 sensor support Nuttx on stm32f407-discovery from Wang_guozhu

it is OK
pull/124/head
xuedongliang 8 months ago
parent
commit
711bd5bd15
  1. 7
      APP_Framework/Applications/Make.defs
  2. 45
      APP_Framework/Applications/Makefile
  3. 10
      APP_Framework/Applications/framework_init.c
  4. 12
      APP_Framework/Applications/general_functions/list/Makefile
  5. 4
      APP_Framework/Applications/general_functions/list/list.h
  6. 45
      APP_Framework/Applications/sensor_app/Kconfig
  7. 6
      APP_Framework/Applications/sensor_app/Make.defs
  8. 120
      APP_Framework/Applications/sensor_app/Makefile
  9. 4
      APP_Framework/Applications/sensor_app/co2_zg09.c
  10. 5
      APP_Framework/Applications/sensor_app/humidity_hs300x.c
  11. 38
      APP_Framework/Applications/sensor_app/pm10_0_ps5308.c
  12. 5
      APP_Framework/Applications/sensor_app/pm1_0_ps5308.c
  13. 38
      APP_Framework/Applications/sensor_app/pm2_5_ps5308.c
  14. 6
      APP_Framework/Applications/sensor_app/temperature_hs300x.c
  15. 5
      APP_Framework/Framework/Make.defs
  16. 7
      APP_Framework/Framework/sensor/Make.defs
  17. 66
      APP_Framework/Framework/sensor/Makefile
  18. 5
      APP_Framework/Framework/sensor/co2/Kconfig
  19. 4
      APP_Framework/Framework/sensor/co2/Make.defs
  20. 6
      APP_Framework/Framework/sensor/co2/zg09/Make.defs
  21. 14
      APP_Framework/Framework/sensor/co2/zg09/Makefile
  22. 20
      APP_Framework/Framework/sensor/co2/zg09/zg09.c
  23. 14
      APP_Framework/Framework/sensor/humidity/Kconfig
  24. 4
      APP_Framework/Framework/sensor/humidity/Make.defs
  25. 2
      APP_Framework/Framework/sensor/humidity/Makefile
  26. 6
      APP_Framework/Framework/sensor/humidity/hs300x_humi/Make.defs
  27. 14
      APP_Framework/Framework/sensor/humidity/hs300x_humi/Makefile
  28. 18
      APP_Framework/Framework/sensor/humidity/hs300x_humi/hs300x_humi.c
  29. 45
      APP_Framework/Framework/sensor/pm/Kconfig
  30. 4
      APP_Framework/Framework/sensor/pm/Make.defs
  31. 6
      APP_Framework/Framework/sensor/pm/ps5308/Make.defs
  32. 12
      APP_Framework/Framework/sensor/pm/ps5308/Makefile
  33. 29
      APP_Framework/Framework/sensor/pm/ps5308/ps5308.c
  34. 11
      APP_Framework/Framework/sensor/sensor.c
  35. 13
      APP_Framework/Framework/sensor/temperature/Kconfig
  36. 4
      APP_Framework/Framework/sensor/temperature/Make.defs
  37. 2
      APP_Framework/Framework/sensor/temperature/Makefile
  38. 6
      APP_Framework/Framework/sensor/temperature/hs300x_temp/Make.defs
  39. 13
      APP_Framework/Framework/sensor/temperature/hs300x_temp/Makefile
  40. 18
      APP_Framework/Framework/sensor/temperature/hs300x_temp/hs300x_temp.c
  41. 5
      APP_Framework/Framework/sensor/voice/Kconfig
  42. 4
      APP_Framework/Framework/sensor/voice/Make.defs
  43. 6
      APP_Framework/Framework/sensor/voice/d124/Make.defs
  44. 13
      APP_Framework/Framework/sensor/voice/d124/Makefile
  45. 30
      APP_Framework/Framework/sensor/voice/d124/d124.c
  46. 5
      APP_Framework/Framework/transform_layer/nuttx/Makefile
  47. 177
      APP_Framework/Framework/transform_layer/nuttx/transform.c
  48. 214
      APP_Framework/Framework/transform_layer/nuttx/transform.h
  49. 5
      APP_Framework/Make.defs
  50. 11
      APP_Framework/Makefile
  51. 224
      Ubiquitous/Nuttx/app_match_nuttx/apps/Makefile
  52. 1312
      Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/Kconfig
  53. 131
      Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/Makefile
  54. 1434
      Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/nsh.h
  55. 158
      Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c
  56. 1161
      Ubiquitous/Nuttx/app_match_nuttx/apps/nshlib/nsh_command.c
  57. 13
      Ubiquitous/Nuttx/app_match_nuttx/build.sh
  58. 1911
      Ubiquitous/Nuttx/app_match_nuttx/nuttx/Kconfig
  59. 48
      Ubiquitous/Nuttx/app_match_nuttx/nuttx/Makefile
  60. 3404
      Ubiquitous/Nuttx/app_match_nuttx/nuttx/arch/arm/src/stm32/stm32_serial.c
  61. 80
      Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/common/include/stm32_hs300x.h
  62. 131
      Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/common/src/Make.defs
  63. 103
      Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/common/src/stm32_hs300x.c
  64. 99
      Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/stm32f4discovery/scripts/Make.defs
  65. 551
      Ubiquitous/Nuttx/app_match_nuttx/nuttx/boards/arm/stm32/stm32f4discovery/src/stm32_bringup.c
  66. 993
      Ubiquitous/Nuttx/app_match_nuttx/nuttx/drivers/sensors/Kconfig
  67. 315
      Ubiquitous/Nuttx/app_match_nuttx/nuttx/drivers/sensors/Make.defs
  68. 253
      Ubiquitous/Nuttx/app_match_nuttx/nuttx/drivers/sensors/hs300x.c
  69. 88
      Ubiquitous/Nuttx/app_match_nuttx/nuttx/include/nuttx/sensors/hs300x.h
  70. 618
      Ubiquitous/Nuttx/app_match_nuttx/nuttx/tools/Makefile.unix
  71. 360
      Ubiquitous/Nuttx/app_match_nuttx/nuttx/tools/cfgdefine.c
  72. 2
      Ubiquitous/Nuttx/nuttx/boards/arm/stm32/aiit-arm32-board/scripts/Make.defs
  73. 12
      Ubiquitous/Nuttx/nuttx/boards/arm/stm32/aiit-arm32-board/src/stm32_bringup.c
  74. 315
      readme.md

7
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)

45
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
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
include $(KERNEL_ROOT)/compiler.mk
endif

10
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);

12
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
ifeq ($(CONFIG_ADD_XIUOS_FETURES),y)
SRC_FILES := double_list.c single_list.c
include $(KERNEL_ROOT)/compiler.mk
endif

4
APP_Framework/Applications/general_functions/list/list.h

@ -22,7 +22,9 @@
#ifndef __LIST_H__
#define __LIST_H__
#include "libc.h"
#include <errno.h>
#include <stdarg.h>
#include <fcntl.h>
#include<stddef.h>
#ifdef __cplusplus
extern "C" {

45
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,25 +95,34 @@ menu "sensor app"
default n
endif
menuconfig APPLICATION_SENSOR_HUMIDITY
bool "Using sensor humidity apps"
menuconfig APPLICATION_SENSOR_TEMPERATURE
bool "Using sensor temperature apps"
default n
if APPLICATION_SENSOR_HUMIDITY
config APPLICATION_SENSOR_HUMIDITY_HS300X
if APPLICATION_SENSOR_TEMPERATURE
config APPLICATION_SENSOR_TEMPERATURE_HS300X
bool "Using sensor HS300x apps"
default n
if ADD_NUTTX_FETURES
endif
endif
menuconfig APPLICATION_SENSOR_TEMPERATURE
bool "Using sensor temperature apps"
menuconfig APPLICATION_SENSOR_HUMIDITY
bool "Using sensor humidity apps"
default n
if APPLICATION_SENSOR_TEMPERATURE
config APPLICATION_SENSOR_TEMPERATURE_HS300X
if APPLICATION_SENSOR_HUMIDITY
config APPLICATION_SENSOR_HUMIDITY_HS300X
bool "Using sensor HS300x apps"
default n
if ADD_NUTTX_FETURES
endif
endif
endif
endmenu

6
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

120
APP_Framework/Applications/sensor_app/Makefile

@ -1,39 +1,103 @@
SRC_FILES :=
include $(KERNEL_ROOT)/.config
ifeq ($(CONFIG_APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS), y)
SRC_FILES += hcho_tb600b_wq_hcho1os.c
endif
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)
SRC_FILES += tvoc_tb600b_tvoc10.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_TVOC_TB600B_TVOC10), y)
CSRCS += tvoc_tb600b_tvoc10.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_IAQ_TB600B_IAQ10), y)
SRC_FILES += iaq_tb600b_iaq10.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_IAQ_TB600B_IAQ10), y)
CSRCS += iaq_tb600b_iaq10.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_CH4_AS830), y)
SRC_FILES += ch4_as830.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_CH4_AS830), y)
CSRCS += ch4_as830.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_ZG09), y)
SRC_FILES += co2_zg09.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_ZG09), y)
CSRCS += co2_zg09.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308), y)
SRC_FILES += pm1_0_ps5308.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308), y)
CSRCS += pm1_0_ps5308.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_VOICE_D124), y)
SRC_FILES += voice_d124.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_PM2_5_PS5308), y)
CSRCS += pm2_5_ps5308.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_HUMIDITY_HS300X), y)
SRC_FILES += humidity_hs300x.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_TEMPERATURE_HS300X), y)
SRC_FILES += temperature_hs300x.c
endif
include $(KERNEL_ROOT)/compiler.mk
ifeq ($(CONFIG_ADD_XIUOS_FETURES),y)
SRC_FILES :=
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_APPLICATION_SENSOR_IAQ_TB600B_IAQ10), y)
SRC_FILES += iaq_tb600b_iaq10.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_CH4_AS830), y)
SRC_FILES += ch4_as830.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_ZG09), y)
SRC_FILES += co2_zg09.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308), y)
SRC_FILES += pm1_0_ps5308.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_PM2_5_PS5308), y)
SRC_FILES += pm2_5_ps5308.c
endif
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

4
APP_Framework/Applications/sensor_app/co2_zg09.c

@ -18,7 +18,9 @@
* @date 2021.04.23
*/
#include <user_api.h>
#ifdef ADD_XIUOS_FETURES
# include <user_api.h>
#endif
#include <sensor.h>
/**

5
APP_Framework/Applications/sensor_app/humidity_hs300x.c

@ -18,7 +18,10 @@
* @date 2021.04.23
*/
#include <user_api.h>
#ifdef ADD_XIUOS_FETURES
# include <user_api.h>
#endif
#include <sensor.h>
/**

38
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 <user_api.h>
#endif
#include <sensor.h>
/**
* @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);
}

5
APP_Framework/Applications/sensor_app/pm1_0_ps5308.c

@ -18,7 +18,10 @@
* @date 2021.04.23
*/
#include <user_api.h>
#ifdef ADD_XIUOS_FETURES
# include <user_api.h>
#endif
#include <sensor.h>
/**

38
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 <user_api.h>
#endif
#include <sensor.h>
/**
* @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);
}

6
APP_Framework/Applications/sensor_app/temperature_hs300x.c

@ -18,7 +18,10 @@
* @date 2021.04.23
*/
#include <user_api.h>
#ifdef ADD_XIUOS_FETURES
# include <user_api.h>
#endif
#include <sensor.h>
/**
@ -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);

5
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)

7
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)

66
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
ifeq ($(CONFIG_SENSOR_TEMPERATURE),y)
SRC_DIR += temperature
endif
include $(KERNEL_ROOT)/compiler.mk
ifeq ($(CONFIG_SENSOR_HUMIDITY),y)
SRC_DIR += humidity
endif
include $(KERNEL_ROOT)/compiler.mk
endif

5
APP_Framework/Framework/sensor/co2/Kconfig

@ -34,6 +34,11 @@ config SENSOR_ZG09
endif
if ADD_NUTTX_FETURES
config SENSOR_DEVICE_ZG09_DEV
string "CO2 device name"
default "/dev/ttyS1"
---help---
If USART1 is selected, then fill in /dev/ttyS1 here.
endif

4
APP_Framework/Framework/sensor/co2/Make.defs

@ -0,0 +1,4 @@
############################################################################
# APP_Framework/Framework/sensor/co2/Make.defs
############################################################################
include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/sensor/co2/*/Make.defs)

6
APP_Framework/Framework/sensor/co2/zg09/Make.defs

@ -0,0 +1,6 @@
############################################################################
# APP_Framework/Framework/sensor/co2/zg09/Make.defs
############################################################################
ifneq ($(CONFIG_SENSOR_ZG09),)
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/sensor/co2/zg09
endif

14
APP_Framework/Framework/sensor/co2/zg09/Makefile

@ -1,3 +1,13 @@
SRC_FILES := zg09.c
include $(KERNEL_ROOT)/.config
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
include $(APPDIR)/Make.defs
CSRCS += zg09.c
include $(APPDIR)/Application.mk
endif
ifeq ($(CONFIG_ADD_XIUOS_FETURES),y)
SRC_FILES := zg09.c
include $(KERNEL_ROOT)/compiler.mk
endif
include $(KERNEL_ROOT)/compiler.mk

20
APP_Framework/Framework/sensor/co2/zg09/zg09.c

@ -38,6 +38,25 @@ static struct SensorProductInfo info =
* @param sdev - sensor device pointer
* @return success: 1 , failure: other
*/
#ifdef ADD_NUTTX_FETURES
static int SensorDeviceOpen(struct SensorDevice *sdev)
{
int result = 0;
sdev->fd = PrivOpen(SENSOR_DEVICE_ZG09_DEV, O_RDWR);
if (sdev->fd < 0) {
printf("open %s error\n", SENSOR_DEVICE_ZG09_DEV);
return -1;
}
result = sdev->done->ioctl(sdev, SENSOR_DEVICE_PASSIVE);
if (result != 0){
printf("SensorDeviceOpen:ioctl failed, status=%d\n", result);
}
return result;
}
#else
static int SensorDeviceOpen(struct SensorDevice *sdev)
{
int result = 0;
@ -70,6 +89,7 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
return result;
}
#endif
/**
* @description: Read sensor device

14
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_dev0"
config SENSOR_DEVICE_HS300X_I2C_ADDR
hex "HS300x device i2c address"
default 0x44
endif

4
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)

2
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

6
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

14
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

18
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 =

45
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

4
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)

6
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

12
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

29
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

11
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;
}

13
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_dev0"
config SENSOR_DEVICE_HS300X_I2C_ADDR
hex "HS300x device i2c address"
default 0x44
endif

4
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)

2
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

6
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

13
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

18
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 =

5
APP_Framework/Framework/sensor/voice/Kconfig

@ -34,6 +34,11 @@ config SENSOR_D124
endif
if ADD_NUTTX_FETURES
config SENSOR_DEVICE_D124_DEV
string "D124 device name"
default "/dev/ttyS1"
---help---
If USART1 is selected, then fill in /dev/ttyS1 here.
endif

4
APP_Framework/Framework/sensor/voice/Make.defs

@ -0,0 +1,4 @@
############################################################################
# APP_Framework/Framework/sensor/voice/Make.defs
############################################################################
include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/sensor/voice/*/Make.defs)

6
APP_Framework/Framework/sensor/voice/d124/Make.defs

@ -0,0 +1,6 @@
############################################################################
# APP_Framework/Framework/sensor/voice/d124/Make.defs
############################################################################
ifneq ($(CONFIG_SENSOR_D124),)
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/sensor/voice/d124
endif

13
APP_Framework/Framework/sensor/voice/d124/Makefile

@ -1,3 +1,12 @@
SRC_FILES := d124.c
include $(KERNEL_ROOT)/.config
include $(KERNEL_ROOT)/compiler.mk
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
include $(APPDIR)/Make.defs
CSRCS += d124.c
include $(APPDIR)/Application.mk
endif
ifeq ($(CONFIG_ADD_XIUOS_FETURES),y)
SRC_FILES := d124.c
include $(KERNEL_ROOT)/compiler.mk
endif

30
APP_Framework/Framework/sensor/voice/d124/d124.c

@ -51,6 +51,35 @@ 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;
pthread_attr_t attr = PTHREAD_ATTR_INITIALIZER;
result = PrivMutexCreate(&buff_lock, NULL);
if (result != 0){
printf("SensorDeviceOpen:mutex create failed, status=%d\n", result);
}
sdev->fd = PrivOpen(SENSOR_DEVICE_D124_DEV, O_RDWR);
if (sdev->fd < 0) {
printf("SensorDeviceOpen:open %s error\n", SENSOR_DEVICE_D124_DEV);
return -1;
}
attr.priority = 20;
attr.stacksize = 2048;
result = PrivTaskCreate(&active_task_id, &attr, &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;
@ -90,6 +119,7 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
return result;
}
#endif
/**
* @description: Close D124 sensor device

5
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

177
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);
}

214
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 <nuttx/pthread.h>
#include <nuttx/semaphore.h>
#include <nuttx/time.h>
#include <stddef.h>
#include <stdint.h>
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);