add transform layer of xiuos for applications framework from Wang weigen

it is OK
This commit is contained in:
xuedongliang 2021-06-17 16:32:46 +08:00
commit 4510a95e90
6916 changed files with 1529485 additions and 2629 deletions

View File

@ -0,0 +1,93 @@
menu "Applications"
menu "config stack size and priority of main task"
config MAIN_KTASK_STACK_SIZE
int "Set main task stack size"
default 1024
config MAIN_KTASK_PRIORITY
int
default 4 if KTASK_PRIORITY_8
default 10 if KTASK_PRIORITY_32
default 85 if KTASK_PRIORITY_256
endmenu
menuconfig APPLICATION_SENSOR
bool "Using sensor apps"
default n
select PERCEPTION_SENSORDEVICE
if APPLICATION_SENSOR
menuconfig APPLICATION_SENSOR_CO2
bool "Using sensor CO2 apps"
default n
select PERCEPTION_CO2
if APPLICATION_SENSOR_CO2
config APPLICATION_SENSOR_CO2_ZG09
bool "Using sensor ZG09 apps"
default n
select PERCEPTION_ZG09
endif
menuconfig APPLICATION_SENSOR_PM1_0
bool "Using sensor PM1.0 apps"
default n
select PERCEPTION_PM
if APPLICATION_SENSOR_PM1_0
config APPLICATION_SENSOR_PM1_0_PS5308
bool "Using sensor PS5308 apps"
default n
select PERCEPTION_PS5308
endif
menuconfig APPLICATION_SENSOR_VOICE
bool "Using sensor voice apps"
default n
select PERCEPTION_VOICE
if APPLICATION_SENSOR_VOICE
config APPLICATION_SENSOR_VOICE_D124
bool "Using sensor D124 apps"
default n
select PERCEPTION_D124
endif
menuconfig APPLICATION_SENSOR_HUMIDITY
bool "Using sensor humidity apps"
default n
select PERCEPTION_HUMIDITY
if APPLICATION_SENSOR_HUMIDITY
config APPLICATION_SENSOR_HUMIDITY_HS300X
bool "Using sensor HS300x apps"
default n
select PERCEPTION_HS300X
endif
menuconfig APPLICATION_SENSOR_TEMPERATURE
bool "Using sensor temperature apps"
default n
select PERCEPTION_TEMPERATURE
if APPLICATION_SENSOR_TEMPERATURE
config APPLICATION_SENSOR_TEMPERATURE_HS300X
bool "Using sensor HS300x apps"
default n
select PERCEPTION_HS300X
endif
endif
menuconfig CONNECTION_COMMUNICATION_ZIGBEE
bool "enable zigbee demo"
default n
select CONFIG_CONNECTION_COMMUNICATION_ZIGBEE
if CONNECTION_COMMUNICATION_ZIGBEE
source "$KERNEL_DIR/framework/connection/Adapter/zigbee/Kconfig"
endif
source "$APP_DIR/Applications/app_test/Kconfig"
endmenu

View File

@ -1,5 +1,45 @@
SRC_FILES := main.c
SRC_DIR := general_functions
SRC_FILES := main.c framework_init.c
ifeq ($(CONFIG_RESOURCES_SDIO), y)
SRC_FILES += sd_card_mount.c
endif
ifeq ($(CONFIG_RESOURCES_SPI_SD), y)
SRC_FILES += spi_sd_card_mount.c
endif
ifeq ($(CONFIG_CONNECTION_COMMUNICATION_BOOTSTART_LORA_NET_SAMPLE), y)
SRC_DIR += connection_demo/adhoc_lora_demo
endif
ifeq ($(CONFIG_CONNECTION_COMMUNICATION_ZIGBEE), y)
SRC_DIR += connection_demo/zigbee_demo
endif
ifeq ($(CONFIG_CONNECTION_COMMUNICATION_ETHERNET), y)
SRC_DIR += connection_demo/ethernet_demo
endif
ifeq ($(CONFIG_CONNECTION_COMMUNICATION_WIFI), y)
SRC_DIR += connection_demo/wifi_demo
endif
ifeq ($(CONFIG_CONNECTION_COMMUNICATION_NB_IOT), y)
SRC_DIR += connection_demo/nbiot_demo
endif
# ifeq ($(CONFIG_CONNECTION_COMMUNICATION_4G), y)
# SRC_DIR += connection_demo/4G_demo
# endif
ifeq ($(CONFIG_CONNECTION_COMMUNICATION_BLUETOOTH), y)
SRC_DIR += connection_demo/bluetooth_demo
endif
ifeq ($(CONFIG_APPLICATION_SENSOR),y)
SRC_DIR += sensor_app
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@ -50,7 +50,7 @@ static int AppInitDesc(struct InitDesc sub_desc[])
static struct InitDesc framework[] =
{
#ifdef PERCEPTION_SENSORDEVICE
#ifdef SUPPORT_SENSOR_FRAMEWORK
{ "perception_framework", SensorFrameworkInit },
#endif
@ -150,7 +150,7 @@ static int ConnectionFrameworkInit(struct InitDesc sub_desc[])
*/
int FrameworkInit()
{
#ifdef PERCEPTION_SENSORDEVICE
#ifdef SUPPORT_SENSOR_FRAMEWORK
PerceptionFrameworkInit(framework);
#endif

View File

@ -1,3 +1,3 @@
SRC_DIR := linklist
SRC_DIR := list
include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,3 +0,0 @@
SRC_FILES := double_linklist.c single_linklist.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,84 +0,0 @@
/*
* 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: double_link.c
* @brief: functions definition of double linklist for application
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/15
*
*/
#include "list.h"
void InitDoubleLinkList(DoubleLinklistType *linklist_head)
{
linklist_head->node_next = linklist_head;
linklist_head->node_prev = linklist_head;
}
void DoubleLinkListInsertNodeAfter(DoubleLinklistType *linklist, DoubleLinklistType *linklist_node)
{
linklist->node_next->node_prev = linklist_node;
linklist_node->node_next = linklist->node_next;
linklist->node_next = linklist_node;
linklist_node->node_prev = linklist;
}
void DoubleLinkListInsertNodeBefore(DoubleLinklistType *linklist, DoubleLinklistType *linklist_node)
{
linklist->node_prev->node_next = linklist_node;
linklist_node->node_prev = linklist->node_prev;
linklist->node_prev = linklist_node;
linklist_node->node_next = linklist;
}
void DoubleLinkListRmNode(DoubleLinklistType *linklist_node)
{
linklist_node->node_next->node_prev = linklist_node->node_prev;
linklist_node->node_prev->node_next = linklist_node->node_next;
linklist_node->node_next = linklist_node;
linklist_node->node_prev = linklist_node;
}
int IsDoubleLinkListEmpty(const DoubleLinklistType *linklist)
{
return linklist->node_next == linklist;
}
struct SysDoubleLinklistNode *DoubleLinkListGetHead(const DoubleLinklistType *linklist)
{
return IsDoubleLinkListEmpty(linklist) ? NULL : linklist->node_next;
}
struct SysDoubleLinklistNode *DoubleLinkListGetNext(const DoubleLinklistType *linklist,
const struct SysDoubleLinklistNode *linklist_node)
{
return linklist_node->node_next == linklist ? NULL : linklist_node->node_next;
}
unsigned int DoubleLinkListLenGet(const DoubleLinklistType *linklist)
{
unsigned int linklist_length = 0;
const DoubleLinklistType *tmp_node = linklist;
while (tmp_node->node_next != linklist)
{
tmp_node = tmp_node->node_next;
linklist_length ++;
}
return linklist_length;
}

View File

@ -1,129 +0,0 @@
/*
* 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: xs_klist.h
* @brief: function declaration and structure defintion of linklist
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/2
*
*/
#ifndef __XS_KLIST_H__
#define __XS_KLIST_H__
#include <errno.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define LINKLIST_FLAG_FIFO 0x00
#define LINKLIST_FLAG_PRIO 0x01
typedef struct SysDoubleLinklistNode
{
struct SysDoubleLinklistNode *node_next;
struct SysDoubleLinklistNode *node_prev;
} DoubleLinklistType;
// Single List
typedef struct SingleLinklistNode
{
struct SingleLinklistNode *node_next;
} SysSingleLinklistType;
struct CommonMember
{
char name[32];
uint8_t type;
uint8_t flag;
DoubleLinklistType list;
};
#define CONTAINER_OF(item, type, member) \
((type *)((char *)(item) - (unsigned long)(&((type *)0)->member)))
#define DOUBLE_LINKLIST_OBJ_INIT(obj) { &(obj), &(obj) }
void InitDoubleLinkList(DoubleLinklistType *linklist_head);
void DoubleLinkListInsertNodeAfter(DoubleLinklistType *linklist, DoubleLinklistType *linklist_node);
void DoubleLinkListInsertNodeBefore(DoubleLinklistType *linklist, DoubleLinklistType *linklist_node);
void DoubleLinkListRmNode(DoubleLinklistType *linklist_node);
int IsDoubleLinkListEmpty(const DoubleLinklistType *linklist);
struct SysDoubleLinklistNode *DoubleLinkListGetHead(const DoubleLinklistType *linklist);
struct SysDoubleLinklistNode *DoubleLinkListGetNext(const DoubleLinklistType *linklist,
const struct SysDoubleLinklistNode *linklist_node);
unsigned int DoubleLinkListLenGet(const DoubleLinklistType *linklist);
#define SYS_DOUBLE_LINKLIST_ENTRY(item, type, member) \
CONTAINER_OF(item, type, member)
#define DOUBLE_LINKLIST_FOR_EACH(item, head) \
for (item = (head)->node_next; item != (head); item = item->node_next)
#define DOUBLE_LINKLIST_FOR_EACH_SAFE(item, node_next, head) \
for (item = (head)->node_next, node_next = item->node_next; item != (head); \
item = node_next, node_next = item->node_next)
#define DOUBLE_LINKLIST_FOR_EACH_ENTRY(item, head, member) \
for (item = SYS_DOUBLE_LINKLIST_ENTRY((head)->node_next, typeof(*item), member); \
&item->member != (head); \
item = SYS_DOUBLE_LINKLIST_ENTRY(item->member.node_next, typeof(*item), member))
#define DOUBLE_LINKLIST_FOR_EACH_ENTRY_SAFE(item, node_next, head, member) \
for (item = SYS_DOUBLE_LINKLIST_ENTRY((head)->node_next, typeof(*item), member), \
node_next = SYS_DOUBLE_LINKLIST_ENTRY(item->member.node_next, typeof(*item), member); \
&item->member != (head); \
item = node_next, node_next = SYS_DOUBLE_LINKLIST_ENTRY(node_next->member.node_next, typeof(*node_next), member))
#define DOUBLE_LINKLIST_FIRST_ENTRY(ptr, type, member) \
SYS_DOUBLE_LINKLIST_ENTRY((ptr)->node_next, type, member)
#define SYS_SINGLE_LINKLIST_OBJ_INIT(obj) { NONE }
void InitSingleLinkList(SysSingleLinklistType *linklist);
void AppendSingleLinkList(SysSingleLinklistType *linklist, SysSingleLinklistType *linklist_node);
void SingleLinkListNodeInsert(SysSingleLinklistType *linklist, SysSingleLinklistType *linklist_node);
unsigned int SingleLinkListGetLen(const SysSingleLinklistType *linklist);
SysSingleLinklistType *SingleLinkListRmNode(SysSingleLinklistType *linklist, SysSingleLinklistType *linklist_node);
SysSingleLinklistType *SingleLinkListGetFirstNode(SysSingleLinklistType *linklist);
SysSingleLinklistType *SingleLinkListGetTailNode(SysSingleLinklistType *linklist);
SysSingleLinklistType *SingleLinkListGetNextNode(SysSingleLinklistType *linklist_node);
int IsSingleLinkListEmpty(SysSingleLinklistType *linklist);
#define SYS_SINGLE_LINKLIST_ENTRY(node, type, member) \
CONTAINER_OF(node, type, member)
#define SINGLE_LINKLIST_FOR_EACH(item, head) \
for (item = (head)->node_next; item != NONE; item = item->node_next)
#define SINGLE_LINKLIST_FOR_EACH_ENTRY(item, head, member) \
for (item = SYS_SINGLE_LINKLIST_ENTRY((head)->node_next, typeof(*item), member); \
&item->member != (NONE); \
item = SYS_SINGLE_LINKLIST_ENTRY(item->member.node_next, typeof(*item), member))
#define SINGLE_LINKLIST_FIRST_ENTRY(ptr, type, member) \
SYS_SINGLE_LINKLIST_ENTRY((ptr)->node_next, type, member)
#define SINGLE_LINKLIST_TAIL_ENTRY(ptr, type, member) \
SYS_SINGLE_LINKLIST_ENTRY(SingleLinkListGetTailNode(ptr), type, member)
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,91 +0,0 @@
/*
* 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: double_link.c
* @brief: functions definition of single linklist for application
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/15
*
*/
#include "list.h"
void InitSingleLinkList(SysSingleLinklistType *linklist)
{
linklist->node_next = NULL;
}
void AppendSingleLinkList(SysSingleLinklistType *linklist, SysSingleLinklistType *linklist_node)
{
struct SingleLinklistNode *node;
node = linklist;
while (node->node_next) node = node->node_next;
node->node_next = linklist_node;
linklist_node->node_next = NULL;
}
void SingleLinkListNodeInsert(SysSingleLinklistType *linklist, SysSingleLinklistType *linklist_node)
{
linklist_node->node_next = linklist->node_next;
linklist->node_next = linklist_node;
}
unsigned int SingleLinkListGetLen(const SysSingleLinklistType *linklist)
{
unsigned int length = 0;
const SysSingleLinklistType *tmp_list = linklist->node_next;
while (tmp_list != NULL)
{
tmp_list = tmp_list->node_next;
length ++;
}
return length;
}
SysSingleLinklistType *SingleLinkListRmNode(SysSingleLinklistType *linklist, SysSingleLinklistType *linklist_node)
{
struct SingleLinklistNode *node = linklist;
while (node->node_next && node->node_next != linklist_node) node = node->node_next;
if (node->node_next != (SysSingleLinklistType *)0){
node->node_next = node->node_next->node_next;
}
return linklist;
}
SysSingleLinklistType *SingleLinkListGetFirstNode(SysSingleLinklistType *linklist)
{
return linklist->node_next;
}
SysSingleLinklistType *SingleLinkListGetTailNode(SysSingleLinklistType *linklist)
{
while (linklist->node_next) linklist = linklist->node_next;
return linklist;
}
SysSingleLinklistType *SingleLinkListGetNextNode(SysSingleLinklistType *linklist_node)
{
return linklist_node->node_next;
}
int IsSingleLinkListEmpty(SysSingleLinklistType *linklist)
{
return linklist->node_next == NULL;
}

View File

@ -0,0 +1,3 @@
SRC_FILES := double_list.c single_list.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,84 @@
/*
* 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: double_link.c
* @brief: functions definition of double list for application
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/15
*
*/
#include "list.h"
void AppInitDoubleList(DoublelistType *list_head)
{
list_head->node_next = list_head;
list_head->node_prev = list_head;
}
void AppDoubleListInsertNodeAfter(DoublelistType *list, DoublelistType *list_node)
{
list->node_next->node_prev = list_node;
list_node->node_next = list->node_next;
list->node_next = list_node;
list_node->node_prev = list;
}
void AppDoubleListInsertNodeBefore(DoublelistType *list, DoublelistType *list_node)
{
list->node_prev->node_next = list_node;
list_node->node_prev = list->node_prev;
list->node_prev = list_node;
list_node->node_next = list;
}
void AppDoubleListRmNode(DoublelistType *list_node)
{
list_node->node_next->node_prev = list_node->node_prev;
list_node->node_prev->node_next = list_node->node_next;
list_node->node_next = list_node;
list_node->node_prev = list_node;
}
int AppIsDoubleListEmpty(const DoublelistType *list)
{
return list->node_next == list;
}
struct DoublelistNode *AppDoubleListGetHead(const DoublelistType *list)
{
return AppIsDoubleListEmpty(list) ? NULL : list->node_next;
}
struct DoublelistNode *AppDoubleListGetNext(const DoublelistType *list,
const struct DoublelistNode *list_node)
{
return list_node->node_next == list ? NULL : list_node->node_next;
}
unsigned int AppDoubleListLenGet(const DoublelistType *list)
{
unsigned int linklist_length = 0;
const DoublelistType *tmp_node = list;
while (tmp_node->node_next != list)
{
tmp_node = tmp_node->node_next;
linklist_length ++;
}
return linklist_length;
}

View File

@ -0,0 +1,118 @@
/*
* 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: xs_klist.h
* @brief: function declaration and structure defintion of list
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/2
*
*/
#ifndef __LIST_H__
#define __LIST_H__
#include "libc.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct DoublelistNode
{
struct DoublelistNode *node_next;
struct DoublelistNode *node_prev;
} DoublelistType;
// Single List
typedef struct SinglelistNode
{
struct SinglelistNode *node_next;
} SinglelistType;
#define CONTAINER_OF(item, type, member) \
((type *)((char *)(item) - (unsigned long)(&((type *)0)->member)))
#define DOUBLE_LIST_OBJ_INIT(obj) { &(obj), &(obj) }
void AppInitDoubleList(DoublelistType *linklist_head);
void AppDoubleListInsertNodeAfter(DoublelistType *list, DoublelistType *list_node);
void AppDoubleListInsertNodeBefore(DoublelistType *list, DoublelistType *list_node);
void AppDoubleListRmNode(DoublelistType *list_node);
int AppIsDoubleListEmpty(const DoublelistType *list);
struct DoublelistNode *AppDoubleLinkListGetHead(const DoublelistType *list);
struct DoublelistNode *AppDoubleLinkListGetNext(const DoublelistType *list,
const struct DoublelistNode *list_node);
unsigned int AppDoubleListLenGet(const DoublelistType *list);
#define DOUBLE_LIST_ENTRY(item, type, member) \
CONTAINER_OF(item, type, member)
#define DOUBLE_LIST_FOR_EACH(item, head) \
for (item = (head)->node_next; item != (head); item = item->node_next)
#define DOUBLE_LIST_FOR_EACH_SAFE(item, node_next, head) \
for (item = (head)->node_next, node_next = item->node_next; item != (head); \
item = node_next, node_next = item->node_next)
#define DOUBLE_LIST_FOR_EACH_ENTRY(item, head, member) \
for (item = DOUBLE_LIST_ENTRY((head)->node_next, typeof(*item), member); \
&item->member != (head); \
item = DOUBLE_LIST_ENTRY(item->member.node_next, typeof(*item), member))
#define DOUBLE_LIST_FOR_EACH_ENTRY_SAFE(item, node_next, head, member) \
for (item = DOUBLE_LIST_ENTRY((head)->node_next, typeof(*item), member), \
node_next = DOUBLE_LIST_ENTRY(item->member.node_next, typeof(*item), member); \
&item->member != (head); \
item = node_next, node_next = DOUBLE_LIST_ENTRY(node_next->member.node_next, typeof(*node_next), member))
#define DOUBLE_LIST_FIRST_ENTRY(ptr, type, member) \
DOUBLE_LIST_ENTRY((ptr)->node_next, type, member)
#define SINGLE_LIST_OBJ_INIT(obj) { NONE }
void AppInitSingleList(SinglelistType *list);
void AppAppendSingleList(SinglelistType *list, SinglelistType *list_node);
void AppSingleListNodeInsert(SinglelistType *list, SinglelistType *list_node);
unsigned int AppSingleListGetLen(const SinglelistType *list);
SinglelistType *AppSingleListRmNode(SinglelistType *list, SinglelistType *list_node);
SinglelistType *AppSingleListGetFirstNode(SinglelistType *list);
SinglelistType *AppSingleListGetTailNode(SinglelistType *list);
SinglelistType *AppSingleListGetNextNode(SinglelistType *list_node);
int AppIsSingleListEmpty(SinglelistType *list);
#define SINGLE_LIST_ENTRY(node, type, member) \
CONTAINER_OF(node, type, member)
#define SINGLE_LIST_FOR_EACH(item, head) \
for (item = (head)->node_next; item != NONE; item = item->node_next)
#define SINGLE_LIST_FOR_EACH_ENTRY(item, head, member) \
for (item = SINGLE_LIST_ENTRY((head)->node_next, typeof(*item), member); \
&item->member != (NONE); \
item = SINGLE_LIST_ENTRY(item->member.node_next, typeof(*item), member))
#define SINGLE_LIST_FIRST_ENTRY(ptr, type, member) \
SINGLE_LIST_ENTRY((ptr)->node_next, type, member)
#define SINGLE_LIST_TAIL_ENTRY(ptr, type, member) \
SINGLE_LIST_ENTRY(AppSingleListGetTailNode(ptr), type, member)
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,91 @@
/*
* 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: double_link.c
* @brief: functions definition of single list for application
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2020/3/15
*
*/
#include "list.h"
void AppInitSingleList(SinglelistType *list)
{
list->node_next = NULL;
}
void AppAppendSingleList(SinglelistType *list, SinglelistType *list_node)
{
struct SinglelistNode *node;
node = list;
while (node->node_next) node = node->node_next;
node->node_next = list_node;
list_node->node_next = NULL;
}
void AppSingleListNodeInsert(SinglelistType *list, SinglelistType *list_node)
{
list_node->node_next = list->node_next;
list->node_next = list_node;
}
unsigned int AppSingleListGetLen(const SinglelistType *list)
{
unsigned int length = 0;
const SinglelistType *tmp_list = list->node_next;
while (tmp_list != NULL)
{
tmp_list = tmp_list->node_next;
length ++;
}
return length;
}
SinglelistType *AppSingleListRmNode(SinglelistType *list, SinglelistType *list_node)
{
struct SinglelistNode *node = list;
while (node->node_next && node->node_next != list_node) node = node->node_next;
if (node->node_next != (SinglelistType *)0){
node->node_next = node->node_next->node_next;
}
return list;
}
SinglelistType *AppSingleListGetFirstNode(SinglelistType *list)
{
return list->node_next;
}
SinglelistType *AppSingleListGetTailNode(SinglelistType *list)
{
while (list->node_next) list = list->node_next;
return list;
}
SinglelistType *AppSingleListGetNextNode(SinglelistType *list_node)
{
return list_node->node_next;
}
int AppIsSingleListEmpty(SinglelistType *list)
{
return list->node_next == NULL;
}

View File

@ -12,8 +12,16 @@
#include <stdio.h>
#include <string.h>
#include <user_api.h>
extern int FrameworkInit();
int main(void)
{
printf("Hello, world!\n");
FrameworkInit();
return 0;
}
// int cppmain(void);

View File

@ -0,0 +1,22 @@
config TRANSFORM_LAYER_ATTRIUBUTE
bool "support transform layer"
default y
choice
prompt "select os features"
default ADD_XIUOS_FETURES
config ADD_XIUOS_FETURES
bool "add xiuos fetures"
config ADD_NUTTX_FETURES
bool "add nuttx fetures"
config ADD_RTTHREAD_FETURES
bool "add rt_thread fetures"
endchoice
source "$APP_DIR/Framework/sensor/Kconfig"
source "$APP_DIR/Framework/connection/Kconfig"
source "$APP_DIR/Framework/know/tflite_sin/Kconfig"
source "$APP_DIR/Framework/know/tflite_mnist/Kconfig"

View File

@ -1,4 +1,12 @@
SRC_DIR := sensor transform_layer
SRC_DIR := transform_layer
ifeq ($(CONFIG_SUPPORT_SENSOR_FRAMEWORK),y)
SRC_DIR += sensor
endif
ifeq ($(CONFIG_SUPPORT_CONNECTION_FRAMEWORK),y)
SRC_DIR += connection
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,3 @@
menuconfig SUPPORT_CONNECTION_FRAMEWORK
bool "support connection framework"
default n

View File

@ -0,0 +1,3 @@
SRC_FILES := adapter.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,310 @@
/*
* 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 adapter.c
* @brief Implement the communication adapter framework management and API
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.05.10
*/
#include <adapter.h>
static DoublelistType adapter_list;
static int adapter_list_lock;
/**
* @description: Init adapter framework
* @return 0
*/
int AdapterFrameworkInit(void)
{
int ret = 0;
AppInitDoubleList(&adapter_list);
ret = PrivMutexCreate(&adapter_list_lock, 0);
if(ret < 0) {
printf("AdapterFrameworkInit mutex create failed.\n");
}
return 0;
}
/**
* @description: Find adapter device by name
* @param name - name string
* @return adapter device pointer
*/
struct Adapter *AdapterDeviceFindByName(const char *name)
{
struct Adapter *ret = NULL;
struct DoublelistNode *node;
if (NULL == name)
return NULL;
PrivMutexObtain(&adapter_list_lock);
DOUBLE_LIST_FOR_EACH(node, &adapter_list) {
struct Adapter *adapter = CONTAINER_OF(node,
struct Adapter, link);
if (0 == strncmp(adapter->name, name, NAME_NUM_MAX)) {
ret = adapter;
break;
}
}
PrivMutexAbandon(&adapter_list_lock);
return ret;
}
/**
* @description: Register the adapter to the linked list
* @param adapter - adapter device pointer
* @return success: 0 , failure: -1
*/
int AdapterDeviceRegister(struct Adapter *adapter)
{
if (NULL == adapter )
return -1;
if (NULL != AdapterDeviceFindByName(adapter->name)) {
printf("%s: sensor with the same name already registered\n", __func__);
return -1;
}
PrivMutexObtain(&adapter_list_lock);
AppDoubleListInsertNodeAfter(&adapter_list, &adapter->link);
PrivMutexAbandon(&adapter_list_lock);
return 0;
}
/**
* @description: Unregister the adapter from the linked list
* @param adapter - adapter device pointer
* @return 0
*/
int AdapterDeviceUnregister(struct Adapter *adapter)
{
if (!adapter)
return -1;
PrivMutexObtain(&adapter_list_lock);
AppDoubleListRmNode(&adapter->link);
PrivMutexAbandon(&adapter_list_lock);
return 0;
}
/**
* @description: Open adapter device
* @param adapter - adapter device pointer
* @return success: 0 , failure: other
*/
int AdapterDeviceOpen(struct Adapter *adapter)
{
if (!adapter)
return -1;
int result = 0;
struct IpProtocolDone *ip_done = NULL;
struct PrivProtocolDone *priv_done = NULL;
switch (adapter->net_protocol)
{
case PRIVATE_PROTOCOL:
priv_done = (struct PrivProtocolDone *)adapter->done;
if (NULL == priv_done->open)
return 0;
result = priv_done->open(adapter);
if (0 == result) {
printf("Device %s open success.\n", adapter->name);
}else{
if (adapter->fd) {
PrivClose(adapter->fd);
adapter->fd = 0;
}
printf("Device %s open failed(%d).\n", adapter->name, result);
}
break;
case IP_PROTOCOL:
ip_done = (struct IpProtocolDone *)adapter->done;
if (NULL == ip_done->open)
return 0;
result = ip_done->open(adapter);
if (0 == result) {
printf("Device %s open success.\n", adapter->name);
}else{
if (adapter->fd) {
PrivClose(adapter->fd);
adapter->fd = 0;
}
printf("Device %s open failed(%d).\n", adapter->name, result);
}
break;
default:
break;
}
return result;
}
/**
* @description: Close adapter device
* @param adapter - adapter device pointer
* @return success: 0 , failure: other
*/
int AdapterDeviceClose(struct Adapter *adapter)
{
if (!adapter)
return -1;
int result = 0;
struct IpProtocolDone *ip_done = NULL;
struct PrivProtocolDone *priv_done = NULL;
switch (adapter->net_protocol)
{
case PRIVATE_PROTOCOL:
priv_done = (struct PrivProtocolDone *)adapter->done;
if (NULL == priv_done->close)
return 0;
result = priv_done->close(adapter);
if (0 == result)
printf("%s successfully closed.\n", adapter->name);
else
printf("Closed %s failure.\n", adapter->name);
break;
case IP_PROTOCOL:
ip_done = (struct IpProtocolDone *)adapter->done;
if (NULL == ip_done->close)
return 0;
result = ip_done->close(adapter);
if (0 == result)
printf("%s successfully closed.\n", adapter->name);
else
printf("Closed %s failure.\n", adapter->name);
break;
default:
break;
}
return result;
}
/**
* @description: Read data from adapter
* @param adapter - adapter device pointer
* @param dst - buffer to save data
* @param len - buffer length
* @return gotten data length
*/
ssize_t AdapterDeviceRead(struct Adapter *adapter, void *dst, size_t len)
{
if (!adapter)
return -1;
if (PRIVATE_PROTOCOL == adapter->net_protocol) {
struct PrivProtocolDone *priv_done = (struct PrivProtocolDone *)adapter->done;
if (NULL == priv_done->recv)
return -1;
return priv_done->recv(adapter, dst, len);
} else if (IP_PROTOCOL == adapter->net_protocol) {
struct IpProtocolDone *ip_done = (struct IpProtocolDone *)adapter->done;
if (NULL == ip_done->recv)
return -1;
return ip_done->recv(adapter->socket, dst, len);
} else {
printf("AdapterDeviceRead net_protocol %d not support\n", adapter->net_protocol);
return -1;
}
}
/**
* @description: Write data to adapter
* @param adapter - adapter device pointer
* @param src - data buffer
* @param len - data length
* @return length of data written
*/
ssize_t AdapterDeviceWrite(struct Adapter *adapter, const void *src, size_t len)
{
if (!adapter)
return -1;
if (PRIVATE_PROTOCOL == adapter->net_protocol) {
struct PrivProtocolDone *priv_done = (struct PrivProtocolDone *)adapter->done;
if (NULL == priv_done->send)
return -1;
return priv_done->send(adapter, src, len);
} else if (IP_PROTOCOL == adapter->net_protocol) {
struct IpProtocolDone *ip_done = (struct IpProtocolDone *)adapter->done;
if (NULL == ip_done->send)
return -1;
return ip_done->send(adapter->socket, src, len);
} else {
printf("AdapterDeviceWrite net_protocol %d not support\n", adapter->net_protocol);
return -1;
}
}
/**
* @description: Configure adapter
* @param adapter - adapter device pointer
* @param cmd - command
* @param args - command parameter
* @return success: 0 , failure: other
*/
int AdapterDeviceControl(struct Adapter *adapter, int cmd, void *args)
{
if (!adapter)
return -1;
if (PRIVATE_PROTOCOL == adapter->net_protocol) {
struct PrivProtocolDone *priv_done = (struct PrivProtocolDone *)adapter->done;
if (NULL == priv_done->ioctl)
return -1;
return priv_done->ioctl(adapter, cmd, args);
} else if (IP_PROTOCOL == adapter->net_protocol) {
struct IpProtocolDone *ip_done = (struct IpProtocolDone *)adapter->done;
if (NULL == ip_done->ioctl)
return -1;
return ip_done->ioctl(adapter, cmd, args);
} else {
printf("AdapterDeviceControl net_protocol %d not support\n", adapter->net_protocol);
return -1;
}
}

View File

@ -0,0 +1,123 @@
/*
* 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 adapter.h
* @brief Structure and function declarations of the communication adapter framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.05.10
*/
#ifndef ADAPTER_H
#define ADAPTER_H
#include <list.h>
#include <transform.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <sys/types.h>
#define ADAPTER_BUFFSIZE 64
#define ADAPTER_LORA_FUNC ((uint32_t)(1 << ATAPTER_LORA))
#define ADAPTER_4G_FUNC ((uint32_t)(1 << ADAPTER_4G))
#define ADAPTER_NBIOT_FUNC ((uint32_t)(1 << ADAPTER_NBIOT))
#define ADAPTER_WIFI_FUNC ((uint32_t)(1 << ADAPTER_WIFI))
#define ADAPTER_ETHERNET_FUNC ((uint32_t)(1 << ADAPTER_ETHERNET))
#define ADAPTER_BLUETOOTH_FUNC ((uint32_t)(1 << ADAPTER_BLUETOOTH))
#define ADAPTER_ZIGBEE_FUNC ((uint32_t)(1 << ADAPTER_ZIGBEE))
#define ADAPTER_5G_FUNC ((uint32_t)(1 << ADAPTER_5G))
struct Adapter;
struct Socket
{
int id;
struct Adapter *adapter;
};
enum AdapterType
{
ADAPTER_LORA = 0,
ADAPTER_4G ,
ADAPTER_NBIOT ,
ADAPTER_WIFI ,
ADAPTER_ETHERNET ,
ADAPTER_BLUETOOTH ,
ADAPTER_ZIGBEE ,
ADAPTER_5G ,
};
enum NetProtocolType
{
PRIVATE_PROTOCOL = 1,
IP_PROTOCOL,
PROTOCOL_NONE,
};
enum NetRoleType
{
CLIENT = 1,
SERVER,
ROLE_NONE,
};
struct AdapterProductInfo
{
uint32_t functions;
const char *vendor_name;
const char *model_name;
};
struct IpProtocolDone
{
int (*open)(struct Adapter *adapter);
int (*close)(struct Adapter *adapter);
int (*ioctl)(struct Adapter *adapter, int cmd, void *args);
int (*connect)(struct Adapter *adapter, const char *ip, const char *port, uint8_t ip_type);
int (*send)(struct Socket *socket, const void *buf, size_t len);
int (*recv)(struct Socket *socket, void *buf, size_t len);
int (*disconnect)(struct Socket *socket);
};
struct PrivProtocolDone
{
int (*open)(struct Adapter *adapter);
int (*close)(struct Adapter *adapter);
int (*ioctl)(struct Adapter *adapter, int cmd, void *args);
int (*join)(struct Adapter *adapter, const char *priv_net_group);
int (*send)(struct Adapter *adapter, const void *buf, size_t len);
int (*recv)(struct Adapter *adapter, void *buf, size_t len);
int (*disconnect)(struct Adapter *adapter);
};
struct Adapter
{
char *name;
int fd;
struct AdapterProductInfo *info;
struct Socket *socket;
enum NetProtocolType net_protocol;
enum NetRoleType net_role;
char buffer[ADAPTER_BUFFSIZE];
void *done;
struct DoublelistNode link;
};
#endif

View File

@ -0,0 +1,40 @@
menuconfig SUPPORT_SENSOR_FRAMEWORK
bool "support sensor framework"
default y
if SUPPORT_SENSOR_FRAMEWORK
menuconfig SENSOR_CO2
bool "Using CO2 sensor device"
default n
if SENSOR_CO2
source "$APP_DIR/Framework/sensor/co2/Kconfig"
endif
menuconfig SENSOR_PM
bool "Using PM sensor device"
default n
if SENSOR_PM
source "$APP_DIR/Framework/sensor/pm/Kconfig"
endif
menuconfig SENSOR_VOICE
bool "Using voice sensor device"
default n
if SENSOR_VOICE
source "$APP_DIR/Framework/sensor/voice/Kconfig"
endif
menuconfig SENSOR_TEMPERATURE
bool "Using temperature sensor device"
default n
if SENSOR_TEMPERATURE
source "$APP_DIR/Framework/sensor/temperature/Kconfig"
endif
menuconfig SENSOR_HUMIDITY
bool "Using humidity sensor device"
default n
if SENSOR_HUMIDITY
source "$APP_DIR/Framework/sensor/humidity/Kconfig"
endif
endif

View File

@ -1,3 +1,23 @@
SRC_FILES := sensor.c
include $(KERNEL_ROOT)/compiler.mk
ifeq ($(CONFIG_SENSOR_CO2),y)
SRC_DIR += co2
endif
ifeq ($(CONFIG_SENSOR_PM),y)
SRC_DIR += pm
endif
ifeq ($(CONFIG_SENSOR_VOICE),y)
SRC_DIR += voice
endif
ifeq ($(CONFIG_SENSOR_TEMPERATURE),y)
SRC_DIR += temperature
endif
ifeq ($(CONFIG_SENSOR_HUMIDITY),y)
SRC_DIR += humidity
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,9 +1,9 @@
config PERCEPTION_ZG09
config SENSOR_ZG09
bool "Using zg09"
default n
if PERCEPTION_ZG09
if SENSOR_ZG09
config SENSOR_DEVICE_ZG09
string "zg09 sensor name"
default "zg09_1"

View File

@ -1,4 +1,4 @@
ifeq ($(CONFIG_PERCEPTION_ZG09),y)
ifeq ($(CONFIG_SENSOR_ZG09),y)
SRC_DIR += zg09
endif

View File

@ -20,9 +20,9 @@
#include <sensor.h>
static uint8 zg09_set_passive[8]={0xFE, 0x06, 0x00, 0x05, 0x00, 0x00, 0x8D, 0xC4};
static uint8 zg09_set_active[8]={0xFE, 0x06, 0x00, 0x05, 0x00, 0x01, 0x4C, 0x04};
static uint8 zg09_read_instruction[8]={0xFE, 0x03, 0x00, 0x0B, 0x00, 0x01, 0xE1, 0xC7};
static uint8_t zg09_set_passive[8]={0xFE, 0x06, 0x00, 0x05, 0x00, 0x00, 0x8D, 0xC4};
static uint8_t zg09_set_active[8]={0xFE, 0x06, 0x00, 0x05, 0x00, 0x01, 0x4C, 0x04};
static uint8_t zg09_read_instruction[8]={0xFE, 0x03, 0x00, 0x0B, 0x00, 0x01, 0xE1, 0xC7};
static struct SensorDevice zg09;
@ -36,13 +36,13 @@ static struct SensorProductInfo info =
/**
* @description: Open ZG09 sensor device
* @param sdev - sensor device pointer
* @return success: EOK , failure: other
* @return success: 1 , failure: other
*/
static int SensorDeviceOpen(struct SensorDevice *sdev)
{
int result = EOK;
int result = 1;
sdev->fd = open(SENSOR_DEVICE_ZG09_DEV, O_RDWR);
sdev->fd = PrivOpen(SENSOR_DEVICE_ZG09_DEV, O_RDWR);
struct SerialDataCfg cfg;
cfg.serial_baud_rate = BAUD_RATE_9600;
@ -55,7 +55,10 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
cfg.ext_uart_no = SENSOR_DEVICE_ZG09_DEV_EXT_PORT;
cfg.port_configure = PORT_CFG_INIT;
ioctl(sdev->fd, OPE_INT, &cfg);
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);
@ -68,12 +71,12 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
* @param len - the length of the read data
* @return get data length
*/
static x_size_t SensorDeviceRead(struct SensorDevice *sdev, size_t len)
static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
{
uint8 tmp = 0;
uint8_t tmp = 0;
int timeout = 0;
while (1) {
read(sdev->fd, &tmp, 1);
PrivRead(sdev->fd, &tmp, 1);
if ((tmp == 0xFE) || (timeout >= 1000))
break;
UserTaskDelay(10);
@ -81,13 +84,13 @@ static x_size_t SensorDeviceRead(struct SensorDevice *sdev, size_t len)
}
if(tmp != 0xFE)
return -ERROR;
return -1;
uint8 idx = 0;
uint8_t idx = 0;
sdev->buffer[idx++] = tmp;
while ((idx < len) && (timeout < 1000)) {
if (read(sdev->fd, &tmp, 1) == 1) {
if (PrivRead(sdev->fd, &tmp, 1) == 1) {
timeout = 0;
sdev->buffer[idx++] = tmp;
}
@ -101,27 +104,27 @@ static x_size_t SensorDeviceRead(struct SensorDevice *sdev, size_t len)
* @description: set sensor work mode
* @param sdev - sensor device pointer
* @param cmd - mode command
* @return success: EOK , failure: -ERROR
* @return success: 1 , failure: -1
*/
static int SensorDeviceIoctl(struct SensorDevice *sdev, int cmd)
{
switch (cmd)
{
case SENSOR_DEVICE_PASSIVE:
write(sdev->fd, zg09_set_passive, 8);
PrivWrite(sdev->fd, zg09_set_passive, 8);
sdev->done->read(sdev, 8);
if (memcmp(sdev->buffer, zg09_set_passive, 8) == 0) {
sdev->status = SENSOR_DEVICE_PASSIVE;
return EOK;
return 1;
}
break;
case SENSOR_DEVICE_ACTIVE:
write(sdev->fd, zg09_set_active, 8);
PrivWrite(sdev->fd, zg09_set_active, 8);
sdev->done->read(sdev, 8);
if (memcmp(sdev->buffer, zg09_set_active, 8) == 0) {
sdev->status = SENSOR_DEVICE_ACTIVE;
return EOK;
return 1;
}
break;
@ -130,15 +133,15 @@ static int SensorDeviceIoctl(struct SensorDevice *sdev, int cmd)
break;
}
return -ERROR;
return -1;
}
static struct SensorDone done =
{
SensorDeviceOpen,
NONE,
NULL,
SensorDeviceRead,
NONE,
NULL,
SensorDeviceIoctl,
};
@ -164,18 +167,18 @@ static struct SensorQuantity zg09_co2;
* @param quant - sensor quantity pointer
* @return quantity value
*/
static int32 QuantityRead(struct SensorQuantity *quant)
static int32_t QuantityRead(struct SensorQuantity *quant)
{
if (!quant)
return -ERROR;
return -1;
uint32 result;
if (quant->sdev->done->read != NONE) {
uint32_t result;
if (quant->sdev->done->read != NULL) {
if(quant->sdev->status == SENSOR_DEVICE_PASSIVE) {
write(quant->sdev->fd, zg09_read_instruction, 8);
PrivWrite(quant->sdev->fd, zg09_read_instruction, 8);
quant->sdev->done->read(quant->sdev, 7);
if(Crc16(quant->sdev->buffer, 5) == ((uint32)quant->sdev->buffer[6] << 8) + ((uint32)quant->sdev->buffer[5])) {
result = (uint32)quant->sdev->buffer[3] * 256 + (uint32)quant->sdev->buffer[4];
if(Crc16(quant->sdev->buffer, 5) == ((uint32_t)quant->sdev->buffer[6] << 8) + ((uint32_t)quant->sdev->buffer[5])) {
result = (uint32_t)quant->sdev->buffer[3] * 256 + (uint32_t)quant->sdev->buffer[4];
if (result > quant->value.max_value)
quant->value.max_value = result;
else if (result < quant->value.min_value)
@ -196,7 +199,7 @@ static int32 QuantityRead(struct SensorQuantity *quant)
printf("%s don't have read done.\n", quant->name);
}
return -ERROR;
return -1;
}
/**

View File

@ -1,4 +1,4 @@
ifeq ($(CONFIG_PERCEPTION_HS300X),y)
ifeq ($(CONFIG_SENSOR_HS300X),y)
SRC_DIR += hs300x_humi
endif

View File

@ -32,41 +32,41 @@ static struct SensorProductInfo info =
/**
* @description: Open HS300x sensor device
* @param sdev - sensor device pointer
* @return EOK
* @return 1
*/
static int SensorDeviceOpen(struct SensorDevice *sdev)
{
sdev->fd = open(SENSOR_DEVICE_HS300X_DEV, O_RDWR);
sdev->fd = PrivOpen(SENSOR_DEVICE_HS300X_DEV, O_RDWR);
return EOK;
return 1;
}
/**
* @description: Read sensor device
* @param sdev - sensor device pointer
* @param len - the length of the read data
* @return success: EOK , failure: -ERROR
* @return success: 1 , failure: -1
*/
static x_size_t SensorDeviceRead(struct SensorDevice *sdev, size_t len)
static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
{
if (write(sdev->fd, NONE, 0) != 1)
return -ERROR;
if (PrivWrite(sdev->fd, NULL, 0) != 1)
return -1;
UserTaskDelay(50);
if (read(sdev->fd, sdev->buffer, len) != 1)
return -ERROR;
if (PrivRead(sdev->fd, sdev->buffer, len) != 1)
return -1;
return EOK;
return 1;
}
static struct SensorDone done =
{
SensorDeviceOpen,
NONE,
NULL,
SensorDeviceRead,
NONE,
NONE,
NULL,
NULL,
};
/**
@ -92,19 +92,19 @@ static struct SensorQuantity hs300x_humidity;
* @param quant - sensor quantity pointer
* @return quantity value
*/
static int32 ReadHumidity(struct SensorQuantity *quant)
static int32_t ReadHumidity(struct SensorQuantity *quant)
{
if (!quant)
return -ERROR;
return -1;
float result = 0.0;
if (quant->sdev->done->read != NONE) {
if (quant->sdev->done->read != NULL) {
if (quant->sdev->status == SENSOR_DEVICE_PASSIVE) {
quant->sdev->done->read(quant->sdev, 4);
quant->sdev->done->read(quant->sdev, 4); /* It takes two reads to get the data right */
result = ((quant->sdev->buffer[0] << 8 | quant->sdev->buffer[1] ) & 0x3fff) * 100.0 / ( (1 << 14) - 1);
return (int32)(result * 10);
return (int32_t)(result * 10);
}
if (quant->sdev->status == SENSOR_DEVICE_ACTIVE) {
printf("Please set passive mode.\n");
@ -113,7 +113,7 @@ static int32 ReadHumidity(struct SensorQuantity *quant)
printf("%s don't have read done.\n", quant->name);
}
return -ERROR;
return -1;
}
/**

View File

@ -1,9 +1,9 @@
config PERCEPTION_PS5308
config SENSOR_PS5308
bool "Using PS5308"
default n
if PERCEPTION_PS5308
if SENSOR_PS5308
config SENSOR_DEVICE_PS5308
string "PS5308 sensor name"
default "ps5308_1"

View File

@ -1,4 +1,4 @@
ifeq ($(CONFIG_PERCEPTION_PS5308),y)
ifeq ($(CONFIG_SENSOR_PS5308),y)
SRC_DIR += ps5308
endif

View File

@ -48,11 +48,11 @@ static void ReadTask(struct SensorDevice *sdev)
/**
* @description: Open PS5308 sensor device
* @param sdev - sensor device pointer
* @return success: EOK , failure: other
* @return success: 1 , failure: other
*/
static int SensorDeviceOpen(struct SensorDevice *sdev)
{
int result = EOK;
int result = 1;
buff_lock = UserMutexCreate();
@ -89,13 +89,13 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
/**
* @description: Close PS5308 sensor device
* @param sdev - sensor device pointer
* @return EOK
* @return 1
*/
static int SensorDeviceClose(struct SensorDevice *sdev)
{
UserTaskDelete(active_task_id);
UserMutexDelete(buff_lock);
return EOK;
return 1;
}
/**
@ -104,9 +104,9 @@ static int SensorDeviceClose(struct SensorDevice *sdev)
* @param len - the length of the read data
* @return get data length
*/
static x_size_t SensorDeviceRead(struct SensorDevice *sdev, size_t len)
static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
{
uint8 tmp = 0;
uint8_t tmp = 0;
int timeout = 0;
while (1) {
read(sdev->fd, &tmp, 1);
@ -117,9 +117,9 @@ static x_size_t SensorDeviceRead(struct SensorDevice *sdev, size_t len)
}
if (tmp != 0x44)
return -ERROR;
return -1;
uint8 idx = 0;
uint8_t idx = 0;
sdev->buffer[idx++] = tmp;
while ((idx < len) && (timeout < 1000)) {
@ -138,8 +138,8 @@ static struct SensorDone SensorDeviceDone =
SensorDeviceOpen,
SensorDeviceClose,
SensorDeviceRead,
NONE,
NONE,
NULL,
NULL,
};
/**
@ -165,21 +165,21 @@ static struct SensorQuantity ps5308_pm1_0;
* @param quant - sensor quantity pointer
* @return quantity value
*/
static int32 ReadPm1_0(struct SensorQuantity *quant)
static int32_t ReadPm1_0(struct SensorQuantity *quant)
{
if (!quant)
return -ERROR;
return -1;
uint32 result;
if (quant->sdev->done->read != NONE) {
uint16 checksum = 0;
uint32_t result;
if (quant->sdev->done->read != NULL) {
uint16_t checksum = 0;
UserMutexObtain(buff_lock, WAITING_FOREVER);
for (uint8 i = 0; i < 30; i++)
for (uint8_t i = 0; i < 30; i++)
checksum += quant->sdev->buffer[i];
if (checksum == (((uint16)quant->sdev->buffer[30] << 8) + ((uint16)quant->sdev->buffer[31]))) {
result = ((uint16)quant->sdev->buffer[4] << 8) + (uint16)quant->sdev->buffer[5];
if (checksum == (((uint16_t)quant->sdev->buffer[30] << 8) + ((uint16_t)quant->sdev->buffer[31]))) {
result = ((uint16_t)quant->sdev->buffer[4] << 8) + (uint16_t)quant->sdev->buffer[5];
if (result > quant->value.max_value)
quant->value.max_value = result;
else if (result < quant->value.min_value)
@ -196,7 +196,7 @@ static int32 ReadPm1_0(struct SensorQuantity *quant)
printf("%s don't have read done.\n", quant->name);
}
return -ERROR;
return -1;
}
/**
@ -232,21 +232,21 @@ static struct SensorQuantity ps5308_pm2_5;
* @param quant - sensor quantity pointer
* @return quantity value
*/
static int32 ReadPm2_5(struct SensorQuantity *quant)
static int32_t ReadPm2_5(struct SensorQuantity *quant)
{
if (!quant)
return -ERROR;
return -1;
uint32 result;
if (quant->sdev->done->read != NONE) {
uint16 checksum = 0;
uint32_t result;
if (quant->sdev->done->read != NULL) {
uint16_t checksum = 0;
UserMutexObtain(buff_lock, WAITING_FOREVER);
for (uint i = 0; i < 30; i++)
checksum += quant->sdev->buffer[i];
if (checksum == (((uint16)quant->sdev->buffer[30] << 8) + ((uint16)quant->sdev->buffer[31]))) {
result = ((uint16)quant->sdev->buffer[6] << 8) + (uint16)quant->sdev->buffer[7];
if (checksum == (((uint16_t)quant->sdev->buffer[30] << 8) + ((uint16_t)quant->sdev->buffer[31]))) {
result = ((uint16_t)quant->sdev->buffer[6] << 8) + (uint16_t)quant->sdev->buffer[7];
if (result > quant->value.max_value)
quant->value.max_value = result;
else if (result < quant->value.min_value)
@ -263,7 +263,7 @@ static int32 ReadPm2_5(struct SensorQuantity *quant)
printf("%s don't have read done.\n", quant->name);
}
return -ERROR;
return -1;
}
/**
@ -299,21 +299,21 @@ static struct SensorQuantity ps5308_pm10;
* @param quant - sensor quantity pointer
* @return quantity value
*/
static int32 ReadPm10(struct SensorQuantity *quant)
static int32_t ReadPm10(struct SensorQuantity *quant)
{
if (!quant)
return -ERROR;
return -1;
uint32 result;
if (quant->sdev->done->read != NONE) {
uint16 checksum = 0;
uint32_t result;
if (quant->sdev->done->read != NULL) {
uint16_t checksum = 0;
UserMutexObtain(buff_lock, WAITING_FOREVER);
for (uint i = 0; i < 30; i++)
checksum += quant->sdev->buffer[i];
if (checksum == (((uint16)quant->sdev->buffer[30] << 8) + ((uint16)quant->sdev->buffer[31]))) {
result = ((uint16)quant->sdev->buffer[8] << 8) + (uint16)quant->sdev->buffer[9];
if (checksum == (((uint16_t)quant->sdev->buffer[30] << 8) + ((uint16_t)quant->sdev->buffer[31]))) {
result = ((uint16_t)quant->sdev->buffer[8] << 8) + (uint16_t)quant->sdev->buffer[9];
if (result > quant->value.max_value)
quant->value.max_value = result;
else if (result < quant->value.min_value)
@ -330,7 +330,7 @@ static int32 ReadPm10(struct SensorQuantity *quant)
printf("%s don't have read done.\n", quant->name);
}
return -ERROR;
return -1;
}
/**

View File

@ -21,10 +21,10 @@
#include <sensor.h>
/* Sensor quantity list table */
static DoubleLinklistType quant_table[SENSOR_QUANTITY_END];
static DoublelistType quant_table[SENSOR_QUANTITY_END];
/* Sensor device list */
static DoubleLinklistType sensor_device_list;
static DoublelistType sensor_device_list;
/* Sensor quantity list lock */
static int quant_table_lock;
@ -38,12 +38,19 @@ static int sensor_device_list_lock;
*/
int SensorFrameworkInit(void)
{
int ret = 0;
for (int i = 0; i < SENSOR_QUANTITY_END; i++)
InitDoubleLinkList(&quant_table[i]);
InitDoubleLinkList(&sensor_device_list);
AppInitDoubleList(&quant_table[i]);
AppInitDoubleList(&sensor_device_list);
quant_table_lock = PrivMutexCreate();
sensor_device_list_lock = PrivMutexCreate();
ret = PrivMutexCreate(&quant_table_lock, 0);
if(ret < 0) {
printf("quant_table_lock mutex create failed.\n");
}
ret = PrivMutexCreate(&sensor_device_list_lock, 0);
if(ret < 0) {
printf("sensor_device_list_lock mutex create failed.\n");
}
return 0;
}
@ -58,13 +65,13 @@ int SensorFrameworkInit(void)
static struct SensorDevice *SensorDeviceFindByName(const char *name)
{
struct SensorDevice *ret = NULL;
struct SysDoubleLinklistNode *node;
struct DoublelistNode *node;
if (name == NULL)
return NULL;
PrivMutexObtain(sensor_device_list_lock, -1);
DOUBLE_LINKLIST_FOR_EACH(node, &sensor_device_list) {
PrivMutexObtain(&sensor_device_list_lock);
DOUBLE_LIST_FOR_EACH(node, &sensor_device_list) {
struct SensorDevice *sdev =CONTAINER_OF(node,
struct SensorDevice, link);
if (strncmp(sdev->name, name, NAME_NUM_MAX) == 0) {
@ -72,7 +79,7 @@ static struct SensorDevice *SensorDeviceFindByName(const char *name)
break;
}
}
PrivMutexAbandon(sensor_device_list_lock);
PrivMutexAbandon(&sensor_device_list_lock);
return ret;
}
@ -104,11 +111,11 @@ int SensorDeviceRegister(struct SensorDevice *sdev)
}
sdev->ref_cnt = 0;
InitDoubleLinkList(&sdev->quant_list);
AppInitDoubleList(&sdev->quant_list);
PrivMutexObtain(sensor_device_list_lock, -1);
DoubleLinkListInsertNodeAfter(&sensor_device_list, &sdev->link);
PrivMutexAbandon(sensor_device_list_lock);
PrivMutexObtain(&sensor_device_list_lock);
AppDoubleListInsertNodeAfter(&sensor_device_list, &sdev->link);
PrivMutexAbandon(&sensor_device_list_lock);
return 0;
}
@ -122,9 +129,9 @@ int SensorDeviceUnregister(struct SensorDevice *sdev)
{
if (!sdev)
return -1;
PrivMutexObtain(sensor_device_list_lock, -1);
DoubleLinkListRmNode(&sdev->link);
PrivMutexAbandon(sensor_device_list_lock);
PrivMutexObtain(&sensor_device_list_lock);
AppDoubleListRmNode(&sdev->link);
PrivMutexAbandon(&sensor_device_list_lock);
return 0;
}
@ -192,13 +199,13 @@ struct SensorQuantity *SensorQuantityFind(const char *name,
enum SensorQuantityType type)
{
struct SensorQuantity *ret = NULL;
struct SysDoubleLinklistNode *node;
struct DoublelistNode *node;
if (name == NULL || type < 0 || type >= SENSOR_QUANTITY_END)
return NULL;
PrivMutexObtain(quant_table_lock, -1);
DOUBLE_LINKLIST_FOR_EACH(node, &quant_table[type]) {
PrivMutexObtain(&quant_table_lock);
DOUBLE_LIST_FOR_EACH(node, &quant_table[type]) {
struct SensorQuantity *quant =CONTAINER_OF(node,
struct SensorQuantity, link);
if (strncmp(quant->name, name, NAME_NUM_MAX) == 0) {
@ -206,7 +213,7 @@ struct SensorQuantity *SensorQuantityFind(const char *name,
break;
}
}
PrivMutexAbandon(quant_table_lock);
PrivMutexAbandon(&quant_table_lock);
return ret;
}
@ -226,10 +233,10 @@ int SensorQuantityRegister(struct SensorQuantity *quant)
return -1;
}
PrivMutexObtain(quant_table_lock, -1);
DoubleLinkListInsertNodeAfter(&quant->sdev->quant_list, &quant->quant_link);
DoubleLinkListInsertNodeAfter(&quant_table[quant->type], &quant->link);
PrivMutexAbandon(quant_table_lock);
PrivMutexObtain(&quant_table_lock);
AppDoubleListInsertNodeAfter(&quant->sdev->quant_list, &quant->quant_link);
AppDoubleListInsertNodeAfter(&quant_table[quant->type], &quant->link);
PrivMutexAbandon(&quant_table_lock);
return 0;
}
@ -243,10 +250,10 @@ int SensorQuantityUnregister(struct SensorQuantity *quant)
{
if (!quant)
return -1;
PrivMutexObtain(quant_table_lock, -1);
DoubleLinkListRmNode(&quant->quant_link);
DoubleLinkListRmNode(&quant->link);
PrivMutexAbandon(quant_table_lock);
PrivMutexObtain(&quant_table_lock);
AppDoubleListRmNode(&quant->quant_link);
AppDoubleListRmNode(&quant->link);
PrivMutexAbandon(&quant_table_lock);
return 0;
}

View File

@ -73,8 +73,8 @@ struct SensorDevice {
uint8_t buffer[SENSOR_RECEIVE_BUFFSIZE]; /* Buffer for read data */
int ref_cnt; /* Reference count */
DoubleLinklistType quant_list; /* Sensor quantity link */
struct SysDoubleLinklistNode link; /* Sensors link node */
DoublelistType quant_list; /* Sensor quantity link */
struct DoublelistNode link; /* Sensors link node */
};
enum SensorQuantityType {
@ -106,8 +106,8 @@ struct SensorQuantity {
int32_t (*ReadValue)(struct SensorQuantity *quant);
struct SysDoubleLinklistNode quant_link;
struct SysDoubleLinklistNode link;
struct DoublelistNode quant_link;
struct DoublelistNode link;
};
int SensorDeviceRegister(struct SensorDevice *sdev);
@ -118,7 +118,7 @@ int SensorQuantityRegister(struct SensorQuantity *quant);
int SensorQuantityUnregister(struct SensorQuantity *quant);
int SensorQuantityOpen(struct SensorQuantity *quant);
int SensorQuantityClose(struct SensorQuantity *quant);
int32_t SensorQuantityRead(struct SensorQuantity *quant);
int SensorQuantityRead(struct SensorQuantity *quant);
int SensorQuantityControl(struct SensorQuantity *quant, int cmd);
uint32_t Crc16(uint8_t * data, uint8_t length);

View File

@ -1,9 +1,9 @@
config PERCEPTION_HS300X
config SENSOR_HS300X
bool "Using HS300x"
default n
if PERCEPTION_HS300X
if SENSOR_HS300X
config SENSOR_DEVICE_HS300X
string "HS300x sensor name"
default "hs300x_1"

View File

@ -1,4 +1,4 @@
ifeq ($(CONFIG_PERCEPTION_HS300X),y)
ifeq ($(CONFIG_SENSOR_HS300X),y)
SRC_DIR += hs300x_temp
endif

View File

@ -32,41 +32,41 @@ static struct SensorProductInfo info =
/**
* @description: Open HS300x sensor device
* @param sdev - sensor device pointer
* @return EOK
* @return 1
*/
static int SensorDeviceOpen(struct SensorDevice *sdev)
{
sdev->fd = open(SENSOR_DEVICE_HS300X_DEV, O_RDWR);
sdev->fd = PrivOpen(SENSOR_DEVICE_HS300X_DEV, O_RDWR);
return EOK;
return 1;
}
/**
* @description: Read sensor device
* @param sdev - sensor device pointer
* @param len - the length of the read data
* @return success: EOK , failure: -ERROR
* @return success: 1 , failure: -1
*/
static x_size_t SensorDeviceRead(struct SensorDevice *sdev, size_t len)
static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
{
if (write(sdev->fd, NONE, 0) != 1)
return -ERROR;
if (PrivWrite(sdev->fd, NULL, 0) != 1)
return -1;
UserTaskDelay(50);
if (read(sdev->fd, sdev->buffer, len) != 1)
return -ERROR;
if (PrivRead(sdev->fd, sdev->buffer, len) != 1)
return -1;
return EOK;
return 1;
}
static struct SensorDone done =
{
SensorDeviceOpen,
NONE,
NULL,
SensorDeviceRead,
NONE,
NONE,
NULL,
NULL,
};
/**
@ -92,19 +92,19 @@ static struct SensorQuantity hs300x_temperature;
* @param quant - sensor quantity pointer
* @return quantity value
*/
static int32 ReadTemperature(struct SensorQuantity *quant)
static int32_t ReadTemperature(struct SensorQuantity *quant)
{
if (!quant)
return -ERROR;
return -1;
float result;
if (quant->sdev->done->read != NONE) {
if (quant->sdev->done->read != NULL) {
if (quant->sdev->status == SENSOR_DEVICE_PASSIVE) {
quant->sdev->done->read(quant->sdev, 4);
quant->sdev->done->read(quant->sdev, 4); /* It takes two reads to get the data right */
result = ((quant->sdev->buffer[2] << 8 | quant->sdev->buffer[3]) >> 2) * 165.0 /( (1 << 14) - 1) - 40.0;
return (int32)(result * 10);
return (int32_t)(result * 10);
}
if (quant->sdev->status == SENSOR_DEVICE_ACTIVE) {
printf("Please set passive mode.\n");
@ -113,7 +113,7 @@ static int32 ReadTemperature(struct SensorQuantity *quant)
printf("%s don't have read done.\n", quant->name);
}
return -ERROR;
return -1;
}
/**

View File

@ -1,9 +1,9 @@
config PERCEPTION_D124
config SENSOR_D124
bool "Using D124"
default n
if PERCEPTION_D124
if SENSOR_D124
config SENSOR_DEVICE_D124
string "D124 sensor name"
default "d124_1"

View File

@ -1,4 +1,4 @@
ifeq ($(CONFIG_PERCEPTION_D124),y)
ifeq ($(CONFIG_SENSOR_D124),y)
SRC_DIR += d124
endif

View File

@ -48,15 +48,15 @@ static void ReadTask(struct SensorDevice *sdev)
/**
* @description: Open D124 voice device
* @param sdev - sensor device pointer
* @return success: EOK , failure: other
* @return success: 1 , failure: other
*/
static int SensorDeviceOpen(struct SensorDevice *sdev)
{
int result = EOK;
int result = 1;
buff_lock = UserMutexCreate();
sdev->fd = open(SENSOR_DEVICE_D124_DEV, O_RDWR);
sdev->fd = PrivOpen(SENSOR_DEVICE_D124_DEV, O_RDWR);
struct SerialDataCfg cfg;
cfg.serial_baud_rate = BAUD_RATE_9600;
@ -69,7 +69,10 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
cfg.ext_uart_no = SENSOR_DEVICE_D124_DEV_EXT_PORT;
cfg.port_configure = PORT_CFG_INIT;
result = ioctl(sdev->fd, OPE_INT, &cfg);
struct PrivIoctlCfg ioctl_cfg;
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE;
ioctl_cfg.args = &cfg;
result = PrivIoctl(sdev->fd, OPE_INT, &ioctl_cfg);
UtaskType active_task;
const char name[NAME_NUM_MAX] = "d124_task";
@ -89,13 +92,13 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
/**
* @description: Close D124 sensor device
* @param sdev - sensor device pointer
* @return EOK
* @return 1
*/
static int SensorDeviceClose(struct SensorDevice *sdev)
{
UserTaskDelete(active_task_id);
UserMutexDelete(buff_lock);
return EOK;
return 1;
}
/**
@ -104,12 +107,12 @@ static int SensorDeviceClose(struct SensorDevice *sdev)
* @param len - the length of the read data
* @return get data length
*/
static x_size_t SensorDeviceRead(struct SensorDevice *sdev, size_t len)
static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
{
uint8 tmp = 0;
uint8_t tmp = 0;
int timeout = 0;
while (1) {
read(sdev->fd, &tmp, 1);
PrivRead(sdev->fd, &tmp, 1);
if ((tmp == 0xAA) || (timeout >= 1000))
break;
UserTaskDelay(10);
@ -117,13 +120,13 @@ static x_size_t SensorDeviceRead(struct SensorDevice *sdev, size_t len)
}
if(tmp != 0xAA)
return -ERROR;
return -1;
uint8 idx = 0;
uint8_t idx = 0;
sdev->buffer[idx++] = tmp;
while ((idx < len) && (timeout < 1000)) {
if (read(sdev->fd, &tmp, 1) == 1) {
if (PrivRead(sdev->fd, &tmp, 1) == 1) {
timeout = 0;
sdev->buffer[idx++] = tmp;
}
@ -138,8 +141,8 @@ static struct SensorDone done =
SensorDeviceOpen,
SensorDeviceClose,
SensorDeviceRead,
NONE,
NONE,
NULL,
NULL,
};
/**
@ -164,17 +167,17 @@ static struct SensorQuantity d124_voice;
* @param quant - sensor quantity pointer
* @return quantity value
*/
static int32 ReadVoice(struct SensorQuantity *quant)
static int32_t ReadVoice(struct SensorQuantity *quant)
{
if (!quant)
return -ERROR;
return -1;
uint32 result;
if (quant->sdev->done->read != NONE) {
uint32_t result;
if (quant->sdev->done->read != NULL) {
UserMutexObtain(buff_lock, WAITING_FOREVER);
if (quant->sdev->buffer[3] == quant->sdev->buffer[1] + quant->sdev->buffer[2]) {
result = ((uint16)quant->sdev->buffer[1] << 8) + (uint16)quant->sdev->buffer[2];
result = ((uint16_t)quant->sdev->buffer[1] << 8) + (uint16_t)quant->sdev->buffer[2];
if (result > quant->value.max_value)
quant->value.max_value = result;
else if (result < quant->value.min_value)
@ -191,7 +194,7 @@ static int32 ReadVoice(struct SensorQuantity *quant)
printf("%s don't have read done.\n", quant->name);
}
return -ERROR;
return -1;
}
/**

View File

@ -1,127 +0,0 @@
/*
* 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 define the struct and transform function
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.06.07
*/
#include <xiuos.h>
#include <iot-vfs.h>
#include <pthread.h>
#include <semaphore.h>
#include <stdint.h>
#include <time.h>
//for test
#define XIUOS_OS
#define OPE_INT 0x0000
#define OPE_CFG 0x0001
#ifdef XIUOS_OS
/************************Serial Configure 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 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;
};
/************************Driver Posix Transform***********************/
enum IoctlDriverType
{
SERIAL_TYPE = 0,
SPI_TYPE,
I2C_TYPE,
DEFAULT_TYPE,
}
struct PrivIoctlCfg
{
enum IoctlDriverType ioctl_driver_type;
void *args;
}
int PrivOpen(const char *path, int flags, ...);
int PrivClose(int fd, void *buf, size_t len);
int PrivRead(int fd, void *buf, size_t len);
int PrivWrite(int fd, const void *buf, size_t len);
int PrivIoctl(int fd, int cmd, void *args);
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);
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);
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(const struct timespec *rqtp, struct timespec *rmtp);
#endif

View File

@ -1,3 +1,7 @@
SRC_FILES := xiuos/xiuos.c xiuos/userspace.c
SRC_DIR :=
ifeq ($(CONFIG_ADD_XIUOS_FETURES),y)
SRC_DIR += xiuos
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,5 @@
SRC_DIR := user_api
SRC_FILES := userspace.c transform.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -11,68 +11,21 @@
*/
/**
* @file transform.c
* @brief support to transform the application interface from private api to posix api
* @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 <pthread.h>
#include <semaphore.h>
#include <stdint.h>
#include <time.h>
#include <transform.h>
#include "transform.h"
/**************************mutex***************************/
//for test
#define XIUOS_OS
#ifdef XIUOS_OS
/************************Kernel Posix Transform***********************/
/************************Driver Posix Transform***********************/
int PrivOpen(const char *path, int flags, ...)
{
return open(path, flags, ...);
}
int PrivClose(int fd, void *buf, size_t len)
{
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, void *args)
{
struct SerialDataCfg *serial_cfg = (struct SerialDataCfg *)args;
return ioctl(fd, OPE_INT, &serial_cfg);
}
int PrivIoctl(int fd, int cmd, void *args)
{
struct PrivIoctlCfg *ioctl_cfg = (struct PrivIoctlCfg *)args;
switch (ioctl_cfg->ioctl_driver_type)
{
case SERIAL_TYPE:
PrivSerialIoctl(fd, ioctl_cfg->args);
break;
default:
break;
}
}
/* private mutex API */
int PrivMutexCreate(pthread_mutex_t *p_mutex, const pthread_mutexattr_t *attr)
@ -95,7 +48,8 @@ int PrivMutexAbandon(pthread_mutex_t *p_mutex)
return pthread_mutex_lock(p_mutex);
}
/* private sem API */
/**********************semaphore****************************/
int PrivSemaphoreCreate(sem_t *sem, int pshared, unsigned int value)
{
return sem_init(sem, pshared, value);
@ -119,7 +73,7 @@ int PrivSemaphoreAbandon(sem_t *sem)
return sem_post(sem);
}
/* private task API */
/**************************task*************************/
int PrivTaskCreate(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine)(void *), void *arg)
@ -142,8 +96,72 @@ void PrivTaskQuit(void *value_ptr)
pthread_exit(value_ptr);
}
int PrivTaskDelay(const struct timespec *rqtp, struct timespec *rmtp)
int PrivTaskDelay(int32_t ms)
{
nanosleep(rqtp,rmtp);
UserTaskDelay(ms);
}
#endif
/*********************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);
}
int PrivIoctl(int fd, int cmd, void *args)
{
struct PrivIoctlCfg *ioctl_cfg = (struct PrivIoctlCfg *)args;
switch (ioctl_cfg->ioctl_driver_type)
{
case SERIAL_TYPE:
PrivSerialIoctl(fd, cmd, ioctl_cfg->args);
break;
default:
break;
}
}
/********************memory api************/
void *PrivMalloc(size_t size)
{
return UserMalloc(size);
}
void *PrivRealloc(void *pointer, size_t size)
{
return UserRealloc(pointer, size);
}
void *PrivCalloc(size_t count, size_t size)
{
return UserCalloc(count, size);
}
void PrivFree(void *pointer)
{
UserFree(pointer);
}
#endif

View File

@ -21,13 +21,20 @@
#ifndef TRANSFORM_H
#define TRANSFORM_H
#include <pthread.h>
#include <semaphore.h>
#include <stddef.h>
#include <stdint.h>
#include <time.h>
#include <user_api.h>
#ifdef __cplusplus
extern "C" {
#endif
#define OPE_INT 0x0000
#define OPE_CFG 0x0001
#define NAME_NUM_MAX 32
#define BAUD_RATE_2400 2400
@ -68,6 +75,14 @@ extern "C" {
#define SERIAL_RB_BUFSZ 128
#endif
enum ExtSerialPortConfigure
{
PORT_CFG_INIT = 0,
PORT_CFG_PARITY_CHECK,
PORT_CFG_DISABLE,
PORT_CFG_DIV,
};
struct SerialDataCfg
{
uint32_t serial_baud_rate;
@ -77,53 +92,61 @@ struct SerialDataCfg
uint8_t serial_bit_order;
uint8_t serial_invert_mode;
uint16_t serial_buffer_size;
uint8 ext_uart_no;
enum ExtSerialPortConfigure port_configure;
};
enum IoctlCmd
enum IoctlDriverType
{
SERIAL_CFG_SETS = 0,
SERIAL_CFG_GETS,
SERIAL_TYPE = 0,
SPI_TYPE,
I2C_TYPE,
DEFAULT_TYPE,
};
struct PrivIoctlCfg
{
enum IoctlDriverType ioctl_driver_type;
void *args;
};
/**********************mutex**************************/
int32_t PrivMutexCreate(void);
void PrivMutexDelete(int32_t mutex);
int32_t PrivMutexObtain(int32_t mutex, int32_t wait_time);
int32_t PrivMutexAbandon(int32_t 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**********************/
int32_t PrivSemaphoreCreate(uint16_t val);
int32_t PrivSemaphoreDelete(int32_t sem);
int32_t PrivSemaphoreObtain(int32_t sem, int32_t wait_time);
int32_t PrivSemaphoreAbandon(int32_t sem);
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**************************/
struct utask
{
char name[NAME_NUM_MAX];
void *func_entry;
void *func_param;
int32_t stack_size;
uint8_t prio;
};
typedef struct utask UtaskType;
int32_t PrivTaskCreate(UtaskType utask);
int32_t PrivTaskStartup(int32_t id);
int32_t PrivTaskDelete(int32_t id);
void PrivTaskQuit(void);
int32_t PrivTaskDelay(int32_t ms);
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);
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);
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

View File

@ -0,0 +1,7 @@
SRC_DIR := posix_support
ifeq ($(CONFIG_SEPARATE_COMPILE),y)
SRC_DIR += switch_api
endif
include $(KERNEL_ROOT)/compiler.mk

Some files were not shown because too many files have changed in this diff Show More