sync upstream branch and add 'as830' sensor of ch4
This commit is contained in:
parent
cc6c459e7b
commit
f2ba792380
|
@ -17,6 +17,7 @@
|
|||
|
||||
extern int FrameworkInit();
|
||||
extern void ApplicationOtaTaskInit(void);
|
||||
extern void Ch4As830(void);
|
||||
int main(void)
|
||||
{
|
||||
printf("Hello, world!\n");
|
||||
|
@ -24,6 +25,7 @@ int main(void)
|
|||
#ifdef APPLICATION_OTA
|
||||
ApplicationOtaTaskInit();
|
||||
#endif
|
||||
Ch4As830();
|
||||
return 0;
|
||||
}
|
||||
// int cppmain(void);
|
||||
|
|
|
@ -5,6 +5,16 @@ menu "sensor app"
|
|||
default n
|
||||
|
||||
if APPLICATION_SENSOR
|
||||
menuconfig APPLICATION_SENSOR_CH4
|
||||
bool "Using sensor CH4 apps"
|
||||
default n
|
||||
|
||||
if APPLICATION_SENSOR_CH4
|
||||
config APPLICATION_SENSOR_CH4_AS830
|
||||
bool "Using sensor AS830 apps"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_CO2
|
||||
bool "Using sensor CO2 apps"
|
||||
default n
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
SRC_FILES :=
|
||||
|
||||
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
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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 ch4_as830.c
|
||||
* @brief CH4 AS830 example
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.12.10
|
||||
*/
|
||||
|
||||
#include <user_api.h>
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a ch4
|
||||
* @return 0
|
||||
*/
|
||||
void Ch4As830(void)
|
||||
{
|
||||
struct SensorQuantity *ch4 = SensorQuantityFind(SENSOR_QUANTITY_AS830_CH4, SENSOR_QUANTITY_CH4);
|
||||
SensorQuantityOpen(ch4);
|
||||
printf("CH4 : %d %%LTL\n", SensorQuantityRead(ch4));
|
||||
SensorQuantityClose(ch4);
|
||||
}
|
|
@ -4,6 +4,13 @@ menuconfig SUPPORT_SENSOR_FRAMEWORK
|
|||
select TRANSFORM_LAYER_ATTRIUBUTE
|
||||
|
||||
if SUPPORT_SENSOR_FRAMEWORK
|
||||
menuconfig SENSOR_CH4
|
||||
bool "Using Ch4 sensor device"
|
||||
default n
|
||||
if SENSOR_CH4
|
||||
source "$APP_DIR/Framework/sensor/ch4/Kconfig"
|
||||
endif
|
||||
|
||||
menuconfig SENSOR_CO2
|
||||
bool "Using CO2 sensor device"
|
||||
default n
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
SRC_FILES := sensor.c
|
||||
|
||||
ifeq ($(CONFIG_SENSOR_CH4),y)
|
||||
SRC_DIR += ch4
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSOR_CO2),y)
|
||||
SRC_DIR += co2
|
||||
endif
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
|
||||
config SENSOR_AS830
|
||||
bool "Using as830"
|
||||
default n
|
||||
|
||||
if SENSOR_AS830
|
||||
config SENSOR_DEVICE_AS830
|
||||
string "as830 sensor name"
|
||||
default "as830_1"
|
||||
|
||||
config SENSOR_QUANTITY_AS830_CH4
|
||||
string "as830 quantity name"
|
||||
default "ch4_1"
|
||||
|
||||
if ADD_XIUOS_FETURES
|
||||
config SENSOR_AS830_DRIVER_EXTUART
|
||||
bool "Using extra uart to support as830"
|
||||
default y
|
||||
|
||||
config SENSOR_DEVICE_AS830_DEV
|
||||
string "as830 device uart path"
|
||||
default "/dev/uart2_dev2"
|
||||
depends on !SENSOR_AS830_DRIVER_EXTUART
|
||||
|
||||
if SENSOR_AS830_DRIVER_EXTUART
|
||||
config SENSOR_DEVICE_AS830_DEV
|
||||
string "as830 device extra uart path"
|
||||
default "/dev/extuart_dev4"
|
||||
|
||||
config SENSOR_DEVICE_AS830_DEV_EXT_PORT
|
||||
int "if AS830 device using extuart, choose port"
|
||||
default "4"
|
||||
endif
|
||||
endif
|
||||
|
||||
if ADD_NUTTX_FETURES
|
||||
|
||||
endif
|
||||
|
||||
if ADD_RTTHREAD_FETURES
|
||||
|
||||
endif
|
||||
endif
|
|
@ -0,0 +1,5 @@
|
|||
ifeq ($(CONFIG_SENSOR_AS830),y)
|
||||
SRC_DIR += as830
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES := as830.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,223 @@
|
|||
/*
|
||||
* 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 as830.c
|
||||
* @brief AS830 CH4 driver base sensor
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.12.10
|
||||
*/
|
||||
|
||||
#include <sensor.h>
|
||||
|
||||
static struct SensorDevice as830;
|
||||
|
||||
static struct SensorProductInfo info =
|
||||
{
|
||||
SENSOR_ABILITY_CH4,
|
||||
"xxxxx",
|
||||
"AS830",
|
||||
};
|
||||
|
||||
/**
|
||||
* @description: Open AS830 sensor device
|
||||
* @param sdev - sensor device pointer
|
||||
* @return success: 1 , failure: other
|
||||
*/
|
||||
static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
sdev->fd = PrivOpen(SENSOR_DEVICE_AS830_DEV, O_RDWR);
|
||||
|
||||
struct SerialDataCfg cfg;
|
||||
cfg.serial_baud_rate = BAUD_RATE_9600;
|
||||
cfg.serial_data_bits = DATA_BITS_8;
|
||||
cfg.serial_stop_bits = STOP_BITS_1;
|
||||
cfg.serial_buffer_size = 128;
|
||||
cfg.serial_parity_mode = PARITY_NONE;
|
||||
cfg.serial_bit_order = 0;
|
||||
cfg.serial_invert_mode = 0;
|
||||
#ifdef SENSOR_AS830_DRIVER_EXTUART
|
||||
cfg.ext_uart_no = SENSOR_DEVICE_AS830_DEV_EXT_PORT;
|
||||
cfg.port_configure = PORT_CFG_INIT;
|
||||
#endif
|
||||
|
||||
struct PrivIoctlCfg ioctl_cfg;
|
||||
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE;
|
||||
ioctl_cfg.args = &cfg;
|
||||
result = PrivIoctl(sdev->fd, OPE_INT, &ioctl_cfg);
|
||||
|
||||
sdev->done->ioctl(sdev, SENSOR_DEVICE_PASSIVE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Read sensor device
|
||||
* @param sdev - sensor device pointer
|
||||
* @param len - the length of the read data
|
||||
* @return get data length
|
||||
*/
|
||||
static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
|
||||
{
|
||||
uint8_t tmp = 0;
|
||||
uint8_t idx = 0;
|
||||
|
||||
while (1) {
|
||||
if (PrivRead(sdev->fd, &tmp, 1) == 1) {
|
||||
sdev->buffer[idx++] = tmp;
|
||||
}
|
||||
if(0xA == tmp){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
static struct SensorDone done =
|
||||
{
|
||||
SensorDeviceOpen,
|
||||
NULL,
|
||||
SensorDeviceRead,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
/**
|
||||
* @description: Init AS830 sensor and register
|
||||
* @return void
|
||||
*/
|
||||
static void SensorDeviceAs830Init(void)
|
||||
{
|
||||
as830.name = SENSOR_DEVICE_AS830;
|
||||
as830.info = &info;
|
||||
as830.done = &done;
|
||||
|
||||
SensorDeviceRegister(&as830);
|
||||
}
|
||||
|
||||
|
||||
/* check data*/
|
||||
static uint8_t CH4_check(uint8_t *packet)
|
||||
{
|
||||
uint8_t i, high, low;
|
||||
uint8_t checksum = 0;
|
||||
for( i = 0; i < 10; i++)
|
||||
{
|
||||
if(packet[i] == 0x09)
|
||||
break;
|
||||
checksum += packet[i];
|
||||
}
|
||||
checksum = (unsigned char)(-(signed char)checksum);
|
||||
high = (checksum & 0xF0) >> 4;
|
||||
if((high <= 0x0F) && (high >= 0x0A))
|
||||
high += 0x37;
|
||||
else if((high <= 0x09) && (high >= 0x00))
|
||||
high += 0x30;
|
||||
low = (checksum & 0x0F);
|
||||
if((low <= 0x0F) && (low >= 0x0A))
|
||||
low += 0x37;
|
||||
else if((low <= 0x09) && (low >= 0x00))
|
||||
low += 0x30;
|
||||
if((high == packet[i + 1]) && (low == packet[i + 2]))
|
||||
return 0;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static struct SensorQuantity as830_ch4;
|
||||
|
||||
/**
|
||||
* @description: Analysis AS830 CH4 result
|
||||
* @param quant - sensor quantity pointer
|
||||
* @return quantity value
|
||||
*/
|
||||
static int32_t QuantityRead(struct SensorQuantity *quant)
|
||||
{
|
||||
if (!quant)
|
||||
return -1;
|
||||
|
||||
uint32_t result;
|
||||
uint32_t len = 0;
|
||||
if (quant->sdev->done->read != NULL) {
|
||||
if(quant->sdev->status == SENSOR_DEVICE_PASSIVE) {
|
||||
len = quant->sdev->done->read(quant->sdev, 7);
|
||||
if (len == 0)
|
||||
{
|
||||
printf("error read data length = 0.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(CH4_check(quant->sdev->buffer) == 0)
|
||||
{
|
||||
for(int i = 0; i < len; i++)
|
||||
{
|
||||
if(quant->sdev->buffer[i] == 0x09)
|
||||
{
|
||||
break;
|
||||
}
|
||||
result = result *10 + (quant->sdev->buffer[i] - 0x30);
|
||||
}
|
||||
|
||||
if (result > quant->value.max_value)
|
||||
quant->value.max_value = result;
|
||||
else if (result < quant->value.min_value)
|
||||
quant->value.min_value = result;
|
||||
quant->value.last_value = result;
|
||||
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("This reading is wrong\n");
|
||||
result = SENSOR_QUANTITY_VALUE_ERROR;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
if (quant->sdev->status == SENSOR_DEVICE_ACTIVE)
|
||||
{
|
||||
printf("Please set passive mode.\n");
|
||||
}
|
||||
}else{
|
||||
printf("%s don't have read done.\n", quant->name);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Init AS830 CH4 quantity and register
|
||||
* @return 0
|
||||
*/
|
||||
int As830Ch4Init(void)
|
||||
{
|
||||
SensorDeviceAs830Init();
|
||||
|
||||
as830_ch4.name = SENSOR_QUANTITY_AS830_CH4;
|
||||
as830_ch4.type = SENSOR_QUANTITY_CH4;
|
||||
as830_ch4.value.decimal_places = 0;
|
||||
as830_ch4.value.max_std = 1000;
|
||||
as830_ch4.value.min_std = 350;
|
||||
as830_ch4.value.last_value = SENSOR_QUANTITY_VALUE_ERROR;
|
||||
as830_ch4.value.max_value = SENSOR_QUANTITY_VALUE_ERROR;
|
||||
as830_ch4.value.min_value = SENSOR_QUANTITY_VALUE_ERROR;
|
||||
as830_ch4.sdev = &as830;
|
||||
as830_ch4.ReadValue = QuantityRead;
|
||||
|
||||
SensorQuantityRegister(&as830_ch4);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -51,6 +51,7 @@ extern "C" {
|
|||
#define SENSOR_ABILITY_CO ((uint32_t)(1 << SENSOR_QUANTITY_CO))
|
||||
#define SENSOR_ABILITY_PM ((uint32_t)(1 << SENSOR_QUANTITY_PM))
|
||||
#define SENSOR_ABILITY_VOICE ((uint32_t)(1 << SENSOR_QUANTITY_VOICE))
|
||||
#define SENSOR_ABILITY_CH4 ((uint32_t)(1 << SENSOR_QUANTITY_CH4))
|
||||
|
||||
struct SensorProductInfo {
|
||||
uint32_t ability; /* Bitwise OR of sensor ability */
|
||||
|
@ -89,6 +90,7 @@ enum SensorQuantityType {
|
|||
SENSOR_QUANTITY_CO,
|
||||
SENSOR_QUANTITY_PM,
|
||||
SENSOR_QUANTITY_VOICE,
|
||||
SENSOR_QUANTITY_CH4,
|
||||
/* ...... */
|
||||
SENSOR_QUANTITY_END,
|
||||
};
|
||||
|
|
|
@ -30,6 +30,23 @@ extern void timer_initialize(void);
|
|||
extern void gapuino_sysinit(void);
|
||||
|
||||
extern unsigned int __bss_end__;
|
||||
/* Return core id. */
|
||||
uint32_t _procid( void )
|
||||
{
|
||||
uint32_t ulProcid = 0;
|
||||
__asm__ volatile( "csrr %0, mhartid" : "=r"( ulProcid ) );
|
||||
ulProcid = ulProcid & 0xf;
|
||||
return ( ulProcid );
|
||||
}
|
||||
|
||||
/* Return cluster id. */
|
||||
uint32_t _clusterid( void )
|
||||
{
|
||||
uint32_t ulCluster = 0;
|
||||
__asm__ volatile( "csrr %0, mhartid" : "=r"( ulCluster ) );
|
||||
ulCluster = ulCluster >> 5;
|
||||
return ( ulCluster );
|
||||
}
|
||||
|
||||
void GapuinoStart(uint32_t mhartid)
|
||||
{
|
||||
|
@ -51,7 +68,7 @@ void InitBoardHardware(void)
|
|||
timer_initialize();
|
||||
KPrintf("memory address range: [0x%08x - 0x%08x], size: %d\n", (x_ubase) MEMORY_START_ADDRESS, (x_ubase) MEMORY_END_ADDRESS, GAP8_SRAM_SIZE);
|
||||
/* initialize memory system */
|
||||
|
||||
KPrintf("gap8 cluster id: [0x%x], _procid: [0x%x]\n", _clusterid(),_procid());
|
||||
KPrintf("board init done.\n");
|
||||
KPrintf("start kernel...\n");
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue