Merge branch 'develop' of https://git.trustie.net/wwg666/xiuos into sensor

This commit is contained in:
Liu_Weichao 2021-06-16 13:47:48 +08:00
commit b6b06aa538
73 changed files with 945 additions and 1442 deletions

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,10 @@
#include <stdio.h>
#include <string.h>
#include <user_api.h>
int main(void)
{
printf("hello world\n");
return 0;
}

View File

@ -0,0 +1,21 @@
config SUPPORT_SENSOR_FRAMEWORK
bool "select sensor framework"
default y
config TRANSFORM_LAYER_ATTRIUBUTE
bool "select 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

View File

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

View File

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

View File

@ -0,0 +1,264 @@
/*
* 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 DoubleLinklistType adapter_list;
static int adapter_list_lock;
/**
* @description: Init adapter framework
* @return 0
*/
int AdapterFrameworkInit(void)
{
InitDoubleLinkList(&adapter_list);
adapter_list_lock = KMutexCreate();
return 0;
}
/**
* @description: Find adapter device by name
* @param name - name string
* @return adapter device pointer
*/
struct Adapter *AdapterDeviceFind(const char *name)
{
struct Adapter *ret = NULL;
struct SysDoubleLinklistNode *node;
if (name == NULL)
return NULL;
UserMutexObtain(adapter_list_lock, -1);
DOUBLE_LINKLIST_FOR_EACH(node, &adapter_list) {
struct Adapter *adapter =CONTAINER_OF(node,
struct Adapter, link);
if (strncmp(adapter->name, name, NAME_NUM_MAX) == 0) {
ret = adapter;
break;
}
}
UserMutexAbandon(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 (adapter == NULL)
return -1;
if (AdapterDeviceFindByName(adapter->name) != NULL) {
printf("%s: sensor with the same name already registered\n", __func__);
return -1;
}
UserMutexObtain(adapter_list_lock, -1);
DoubleLinkListInsertNodeAfter(&adapter_list, &adapter->link);
UserMutexAbandon(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;
UserMutexObtain(adapter_list, -1);
DoubleLinkListRmNode(&adapter->link);
UserMutexAbandon(adapter_list);
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 (priv_done->open == NULL)
return 0;
result = priv_done->open(adapter);
if (result == 0) {
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 (ip_done->open == NULL)
return 0;
result = ip_done->open(adapter);
if (result == 0) {
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 (priv_done->close == NULL)
return 0;
result = priv_done->close(adapter);
if (result == 0)
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 (ip_done->close == NULL)
return 0;
result = ip_done->close(adapter);
if (result == 0)
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 (adapter->done->read == NULL)
return -1;
return adapter->done->read(adapter, dst, len);
}
/**
* @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 (adapter->done->write == NULL)
return -1;
return adapter->done->write(adapter, src, len);
}
/**
* @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 (adapter->done->ioctl == NULL)
return -1;
return adapter->done->ioctl(adapter, cmd, args);
}

View File

@ -0,0 +1,120 @@
/*
* 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 <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;
enum NetProtocolType net_protocol;
enum NetRoleType net_role;
char buffer[ADAPTER_BUFFSIZE];
void *done;
struct SysDoubleLinklistNode link;
};
#endif

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

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,19 +11,16 @@
*/
/**
* @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
@ -38,7 +35,7 @@ int PrivOpen(const char *path, int flags, ...)
return open(path, flags, ...);
}
int PrivClose(int fd, void *buf, size_t len)
int PrivClose(int fd)
{
return close(fd);
}
@ -95,7 +92,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 +117,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 +140,70 @@ 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);
}
/*********************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, 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;
}
}
/********************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
@ -79,51 +86,56 @@ struct SerialDataCfg
uint16_t serial_buffer_size;
};
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

View File

@ -0,0 +1,22 @@
# ifeq ($(CONFIG_POSIX_API),y)
# SRC_FILES += pthread.c
# ifeq ($(CONFIG_KERNEL_SEMAPHORE),y)
# SRC_FILES += semaphore.c
# endif
# ifeq ($(CONFIG_KERNEL_MUTEX),y)
# SRC_FILES += pthread_mutex.c
# endif
# ifeq ($(CONFIG_KERNEL_MESSAGEQUEUE),y)
# SRC_FILES += mqueue.c
# endif
# else
# SRC_FILES :=
# endif
SRC_FILES := pthread.c semaphore.c pthread_mutex.c mqueue.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -63,7 +63,7 @@ int sem_timedwait(sem_t *sem, const struct timespec *abstime)
int sem_trywait(sem_t *sem)
{
int ret ;
ret = KSemaphoreObtain(*sem, 0);
ret = UserSemaphoreObtain(*sem, 0);
return ret;
}
@ -75,7 +75,7 @@ int sem_unlink(const char *name)
int sem_wait(sem_t *sem)
{
int ret ;
ret = KSemaphoreObtain(*sem, -1);
ret = UserSemaphoreObtain(*sem, -1);
return ret;
}

View File

@ -22,16 +22,11 @@
#ifndef XS_USER_API_H
#define XS_USER_API_H
// #include <xiuos.h>
#include <xsconfig.h>
#include "../../../kernel/include/xs_service.h"
#include "../../../kernel/include/xs_base.h"
#include <stddef.h>
#include <stdint.h>
#include "../../../arch/kswitch.h"
#include <libc.h>
#include "../../../../../../Ubiquitous/XiUOS/arch/kswitch.h"
#ifdef SEPARATE_COMPILE

View File

@ -131,6 +131,8 @@ int Userprintf(const char *fmt, ...)
va_list args;
size_t length;
static char logbuf[CONSOLEBUF_SIZE];
// int fd = 0;
// fd = open("/dev/uart0_dev0",O_RDWR);
va_start(args, fmt);
@ -139,6 +141,8 @@ int Userprintf(const char *fmt, ...)
length = CONSOLEBUF_SIZE - 1;
write(stdio, logbuf, length);
// write(fd, logbuf, length);
// close(fd);
va_end(args);
}
return 0;

View File

@ -2,7 +2,7 @@
#include <stdint.h>
extern int main(void);
//extern void UserTaskQuit(void);
extern void UserTaskQuit(void);
extern uintptr_t _ustext;
extern uintptr_t _uetext;
extern uintptr_t _ueronly;
@ -31,7 +31,7 @@ const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
/* General memory map */
.us_entrypoint = (main_t)main,
//.us_taskquit = (exit_t)UserTaskQuit,
.us_taskquit = (exit_t)UserTaskQuit,
.us_textstart = (uintptr_t)&_ustext,
.us_textend = (uintptr_t)&_uetext,
.us_datasource = (uintptr_t)&_ueronly,

View File

@ -1,124 +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 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***************************/
int32_t PrivMutexCreate(void)
{
return 0;
}
void PrivMutexDelete(int32_t mutex)
{
return;
}
int32_t PrivMutexObtain(int32_t mutex, int32_t wait_time)
{
return 0;
}
int32_t PrivMutexAbandon(int32_t mutex)
{
return 0;
}
/**********************semaphore****************************/
int32_t PrivSemaphoreCreate(uint16_t val)
{
return 0;
}
int32_t PrivSemaphoreDelete(int32_t sem)
{
return 0;
}
int32_t PrivSemaphoreObtain(int32_t sem, int32_t wait_time)
{
return 0;
}
int32_t PrivSemaphoreAbandon(int32_t sem)
{
return 0;
}
int32_t PrivSemaphoreSetValue(int32_t sem, uint16_t val)
{
return 0;
}
/**************************task*************************/
int32_t PrivTaskCreate(UtaskType utask)
{
return 0;
}
int32_t PrivTaskStartup(int32_t id)
{
return 0;
}
int32_t PrivTaskDelete(int32_t id)
{
return 0;
}
void PrivTaskQuit(void)
{
return;
}
int32_t PrivTaskDelay(int32_t ms)
{
return 0;
}
/*********************fs**************************/
int PrivOpen(const char *path, int flags, ...)
{
return 0;
}
int PrivRead(int fd, void *buf, size_t len)
{
return 0;
}
int PrivWrite(int fd, const void *buf, size_t len)
{
return 0;
}
int PrivClose(int fd)
{
return 0;
}
int PrivIoctl(int fd, int cmd, void *args)
{
return 0;
}

View File

@ -5,6 +5,6 @@ config APP_DIR
option env="SRC_APP_DIR"
default "."
source "$APP_DIR/Applications/Kconfig"
source "$APP_DIR/Framework/Kconfig"
endmenu

View File

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

View File

@ -1,3 +1,3 @@
SRC_FILES := stdio.c
SRC_FILES := stdio.c fs_syscalls.c mem_syscalls.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -28,6 +28,7 @@ Modification: Use file system functions
#include <sys/errno.h>
#include <stdio.h>
#include <transform.h>
int _close_r(struct _reent *ptr, int fd)
{

View File

@ -27,10 +27,11 @@ Modification: Use malloc, realloc, calloc and free functions
*************************************************/
#include <stddef.h>
#include <transform.h>
void *_malloc_r (struct _reent *ptr, size_t size)
{
void* result = (void*)UserMalloc(size);
void* result = (void*)PrivMalloc(size);
if (result == NULL)
{
@ -42,7 +43,7 @@ void *_malloc_r (struct _reent *ptr, size_t size)
void *_realloc_r (struct _reent *ptr, void *old, size_t newlen)
{
void* result = (void*)UserRealloc(old, newlen);
void* result = (void*)PrivRealloc(old, newlen);
if (result == NULL)
{
@ -54,7 +55,7 @@ void *_realloc_r (struct _reent *ptr, void *old, size_t newlen)
void *_calloc_r (struct _reent *ptr, size_t size, size_t len)
{
void* result = (void*)UserCalloc(size, len);
void* result = (void*)PrivCalloc(size, len);
if (result == NULL)
{
@ -66,5 +67,5 @@ void *_calloc_r (struct _reent *ptr, size_t size, size_t len)
void _free_r (struct _reent *ptr, void *address)
{
UserFree (address);
PrivFree (address);
}

View File

@ -1,5 +1,4 @@
menu "Applications"
source "$KERNEL_DIR/applications/user_api/posix_support/Kconfig"
menu "config stack size and priority of main task"
config MAIN_KTASK_STACK_SIZE

View File

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

View File

@ -1,98 +0,0 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
/**
* @file fs_syscalls.c
* @brief support newlib file system
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-25
*/
/*************************************************
File name: fs_syscalls.c
Description: support newlib file system
Others: take RT-Thread v4.0.2/components/libc/compilers/newlib/syscalls.c for references
https://github.com/RT-Thread/rt-thread/tree/v4.0.2
History:
1. Date: 2021-04-25
Author: AIIT XUOS Lab
Modification: Use file system functions
*************************************************/
#include <sys/errno.h>
#include <stdio.h>
#include <user_api.h>
int _close_r(struct _reent *ptr, int fd)
{
return close(fd);
}
int _fstat_r(struct _reent *ptr, int fd, struct stat *pstat)
{
ptr->_errno = ENOTSUP;
return -1;
}
int _isatty_r(struct _reent *ptr, int fd)
{
if (fd >=0 && fd < 3)
return 1;
ptr->_errno = ENOTSUP;
return -1;
}
int _link_r(struct _reent *ptr, const char *old, const char *new)
{
ptr->_errno = ENOTSUP;
return -1;
}
_off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence)
{
return lseek(fd, pos, whence);
}
int _open_r(struct _reent *ptr, const char *file, int flags, int mode)
{
return open(file, flags, mode);
}
_ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
{
return read(fd, buf, nbytes);
}
void * _sbrk_r(struct _reent *ptr, ptrdiff_t incr)
{
return NONE;
}
int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
{
return stat(file, pstat);
}
int _unlink_r(struct _reent *ptr, const char *file)
{
return unlink(file);
}
int _wait_r(struct _reent *ptr, int *status)
{
ptr->_errno = ENOTSUP;
return -1;
}
_ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
{
return write(fd, buf, nbytes);
}

View File

@ -1,29 +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 libc.h
* @brief using newlib need include
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-25
*/
#ifndef _LIBC_H__
#define _LIBC_H__
#include <errno.h>
#include <stdarg.h>
#include <fcntl.h>
#endif

View File

@ -1,70 +0,0 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
/**
* @file mem_syscalls.c
* @brief support newlib memory
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-25
*/
/*************************************************
File name: mem_syscalls.c
Description: support newlib memory
Others: take RT-Thread v4.0.2/components/libc/compilers/newlib/syscalls.c for references
https://github.com/RT-Thread/rt-thread/tree/v4.0.2
History:
1. Date: 2021-04-25
Author: AIIT XUOS Lab
Modification: Use malloc, realloc, calloc and free functions
*************************************************/
#include <user_api.h>
void *_malloc_r (struct _reent *ptr, size_t size)
{
void* result = (void*)UserMalloc(size);
if (result == NONE)
{
ptr->_errno = ENOMEM;
}
return result;
}
void *_realloc_r (struct _reent *ptr, void *old, size_t newlen)
{
void* result = (void*)UserRealloc(old, newlen);
if (result == NONE)
{
ptr->_errno = ENOMEM;
}
return result;
}
void *_calloc_r (struct _reent *ptr, size_t size, size_t len)
{
void* result = (void*)UserCalloc(size, len);
if (result == NONE)
{
ptr->_errno = ENOMEM;
}
return result;
}
void _free_r (struct _reent *ptr, void *address)
{
UserFree (address);
}

View File

@ -1,155 +0,0 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2017/10/15 bernard the first version
*/
/**
* @file stdio.c
* @brief support newlib stdio
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-25
*/
/*************************************************
File name: stdio.c
Description: support newlib stdio
Others: take RT-Thread v4.0.2/components/libc/compilers/newlib/stdio.c for references
https://github.com/RT-Thread/rt-thread/tree/v4.0.2
History:
1. Date: 2021-04-25
Author: AIIT XUOS Lab
Modification: Use set and get console functions
*************************************************/
#include <libc.h>
#include <stdio.h>
#include <stdlib.h>
#define STDIO_DEVICE_NAME_MAX 32
static FILE* std_console = NULL;
/**
* This function will set system console device.
*
* @param device_name the name of device
* @param mode the mode
*
* @return file number on success; or -1 on failure
*/
int LibcStdioSetConsole(const char* device_name, int mode)
{
FILE *fp;
char name[STDIO_DEVICE_NAME_MAX];
char *file_mode;
snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
switch (mode)
{
case O_RDWR:
file_mode = "r+";
break;
case O_WRONLY:
file_mode = "wb";
break;
default:
file_mode = "rb";
break;
}
/* try to open file */
fp = fopen(name, file_mode);
if (fp)
{
/* set the fp buffer */
setvbuf(fp, NULL, _IONBF, 0);
if (std_console)
/* try to close console device */
fclose(std_console);
std_console = fp;
if (mode == O_RDWR)
{
/* set _stdin as std_console */
_GLOBAL_REENT->_stdin = std_console;
}
else
{
/* set NULL */
_GLOBAL_REENT->_stdin = NULL;
}
if (mode == O_RDONLY)
{
/* set the _stdout as NULL */
_GLOBAL_REENT->_stdout = NULL;
/* set the _stderr as NULL */
_GLOBAL_REENT->_stderr = NULL;
}
else
{
/* set the _stdout as std_console */
_GLOBAL_REENT->_stdout = std_console;
/* set the _stderr as std_console */
_GLOBAL_REENT->_stderr = std_console;
}
/* set the __sdidinit as 1 */
_GLOBAL_REENT->__sdidinit = 1;
}
if (std_console)
/* return the file number */
return fileno(std_console);
/* failure and return -1 */
return -1;
}
/**
* This function will get system console device.
*
* @return file number on success; or -1 on failure
*/
int LibcStdioGetConsole(void) {
if (std_console)
/* return the file number */
return fileno(std_console);
else
/* failure and return -1 */
return -1;
}
/**
* This function will initialize the c library system.
*
* @return 0
*/
int LibcSystemInit(void)
{
#if defined(KERNEL_CONSOLE)
HardwareDevType console;
/* try to get console device */
console = ObtainConsole();
if (console)
{
#if defined(LIB_POSIX)
/* set console device mode */
LibcStdioSetConsole(console->dev_name, O_RDWR);
#else
/* set console device mode */
LibcStdioSetConsole(console->dev_name, O_WRONLY);
#endif
}
#endif
return 0;
}

View File

@ -1,44 +0,0 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
/**
* @file task_syscalls.c
* @brief support newlib abort
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-25
*/
/*************************************************
File name: task_syscalls.c
Description: support newlib abort
Others: take RT-Thread v4.0.2/components/libc/compilers/newlib/syscalls.c for references
https://github.com/RT-Thread/rt-thread/tree/v4.0.2
History:
1. Date: 2021-04-25
Author: AIIT XUOS Lab
Modification: Use abort function
*************************************************/
#include <xiuos.h>
void abort(void)
{
KTaskDescriptorType current = GetKTaskDescriptor();
if (current)
{
KPrintf("Task:%-8.*s will be aborted!\n", NAME_NUM_MAX, current->task_base_info.name);
/* pend current task */
SuspendKTask(current->id.id);
/* schedule */
DO_KTASK_ASSIGN;
}
while (1);
}

View File

@ -1,34 +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.
*/
#include <sys/time.h>
// #include <xiuos.h>
#include <bus_rtc.h>
time_t time(time_t *t)
{
NULL_PARAM_CHECK(t);
time_t current = 0;
#ifdef RESOURCES_RTC
struct RtcSetParam rtc_set_param;
rtc_set_param.rtc_set_cmd = OPER_RTC_GET_TIME;
rtc_set_param.time = &current;
RtcDrvSetFunction(RTC_DRV_NAME, &rtc_set_param);
#endif
*t = current;
return current;
}

View File

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

View File

@ -1,3 +0,0 @@
SRC_DIR := linklist
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 "xs_klist.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,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 "xs_klist.h"
void InitSingleLinkList(SysSingleLinklistType *linklist)
{
linklist->node_next = NONE;
}
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 = NONE;
}
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 != NONE)
{
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 == NONE;
}

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 "../../kernel/include/xs_base.h"
#include "libc.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[NAME_NUM_MAX];
uint8 type;
uint8 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,19 +0,0 @@
ifeq ($(CONFIG_POSIX_API),y)
SRC_FILES += pthread.c
ifeq ($(CONFIG_KERNEL_SEMAPHORE),y)
SRC_FILES += semaphore.c
endif
ifeq ($(CONFIG_KERNEL_MUTEX),y)
SRC_FILES += pthread_mutex.c
endif
ifeq ($(CONFIG_KERNEL_MESSAGEQUEUE),y)
SRC_FILES += mqueue.c
endif
else
SRC_FILES :=
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,4 +1,8 @@
menu "Kernel feature"
config COMPILE_WITH_XIUOS
bool "select xiuos kernel"
default y
menu "separate compile(choose none for compile once)"
config SEPARATE_COMPILE
bool

View File

@ -45,14 +45,6 @@ typedef struct SingleLinklistNode
} SysSingleLinklistType;
struct CommonMember
{
char name[NAME_NUM_MAX];
uint8 type;
uint8 flag;
DoubleLinklistType list;
};
#define CONTAINER_OF(item, type, member) \
((type *)((char *)(item) - (unsigned long)(&((type *)0)->member)))

View File

@ -1,12 +1,15 @@
export APPPATHS :=-I$(BSP_ROOT) \
APPPATHS +=-I$(KERNEL_ROOT)/../../APP_Framework/Applications/general_functions/linklist \
APPPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Applications/general_functions/list \
-I$(KERNEL_ROOT)/../../APP_Framework/lib/app_newlib/include \
-I$(KERNEL_ROOT)/../../APP_Framework/Framework/sensor \
-I$(KERNEL_ROOT)/../../APP_Framework/Framework/transform_layer #
-I$(KERNEL_ROOT)/../../APP_Framework/Framework/sensor #
ifeq ($(CONFIG_COMPILE_WITH_XIUOS), y)
APPPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/transform_layer/xiuos \
-I$(KERNEL_ROOT)/../../APP_Framework/Framework/transform_layer/xiuos/user_api/switch_api \
-I$(KERNEL_ROOT)/../../APP_Framework/Framework/transform_layer/xiuos/user_api/posix_support/include #
endif
COMPILE_APP:
@$(eval CPPPATHS=$(APPPATHS))

View File

@ -157,9 +157,14 @@ ifeq ($(CONFIG_FS_CH376), y)
KERNELPATHS +=-I$(KERNEL_ROOT)/fs/compatibility_ch376 #
endif
ifeq ($(CONFIG_PERCEPTION_SENSORDEVICE), y)
KERNELPATHS += -I$(KERNEL_ROOT)/framework/perception #
endif
# ifeq ($(CONFIG_PERCEPTION_SENSORDEVICE), y)
# KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/sensor #
# endif
KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/transform_layer/xiuos/user_api/posix_support/include #
KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/sensor #
KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/transform_layer/xiuos #
KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Applications/general_functions/list #
ifeq ($(CONFIG_CONNECTION_ADAPTER), y)
KERNELPATHS += -I$(KERNEL_ROOT)/framework/connection/Adapter/include #