Browse Source

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

pull/3/head
Liu_Weichao 1 year ago
parent
commit
b6b06aa538
  1. 2
      APP_Framework/Applications/general_functions/Makefile
  2. 3
      APP_Framework/Applications/general_functions/linklist/Makefile
  3. 84
      APP_Framework/Applications/general_functions/linklist/double_linklist.c
  4. 129
      APP_Framework/Applications/general_functions/linklist/list.h
  5. 91
      APP_Framework/Applications/general_functions/linklist/single_linklist.c
  6. 3
      APP_Framework/Applications/general_functions/list/Makefile
  7. 84
      APP_Framework/Applications/general_functions/list/double_list.c
  8. 118
      APP_Framework/Applications/general_functions/list/list.h
  9. 91
      APP_Framework/Applications/general_functions/list/single_list.c
  10. 2
      APP_Framework/Applications/main.c
  11. 21
      APP_Framework/Framework/Kconfig
  12. 6
      APP_Framework/Framework/Makefile
  13. 3
      APP_Framework/Framework/connection/Makefile
  14. 264
      APP_Framework/Framework/connection/adapter.c
  15. 120
      APP_Framework/Framework/connection/adapter.h
  16. 65
      APP_Framework/Framework/sensor/sensor.c
  17. 8
      APP_Framework/Framework/sensor/sensor.h
  18. 127
      APP_Framework/Framework/transform.h
  19. 6
      APP_Framework/Framework/transform_layer/Makefile
  20. 5
      APP_Framework/Framework/transform_layer/xiuos/Makefile
  21. 86
      APP_Framework/Framework/transform_layer/xiuos/transform.c
  22. 66
      APP_Framework/Framework/transform_layer/xiuos/transform.h
  23. 7
      APP_Framework/Framework/transform_layer/xiuos/user_api/Makefile
  24. 0
      APP_Framework/Framework/transform_layer/xiuos/user_api/include/bus.h
  25. 0
      APP_Framework/Framework/transform_layer/xiuos/user_api/include/bus_serial.h
  26. 0
      APP_Framework/Framework/transform_layer/xiuos/user_api/include/dev_serial.h
  27. 0
      APP_Framework/Framework/transform_layer/xiuos/user_api/posix_support/Kconfig
  28. 22
      APP_Framework/Framework/transform_layer/xiuos/user_api/posix_support/Makefile
  29. 0
      APP_Framework/Framework/transform_layer/xiuos/user_api/posix_support/include/fs.h
  30. 0
      APP_Framework/Framework/transform_layer/xiuos/user_api/posix_support/include/mqueue.h
  31. 0
      APP_Framework/Framework/transform_layer/xiuos/user_api/posix_support/include/pthread arm.h
  32. 0
      APP_Framework/Framework/transform_layer/xiuos/user_api/posix_support/include/pthread.h
  33. 0
      APP_Framework/Framework/transform_layer/xiuos/user_api/posix_support/include/semaphore.h
  34. 0
      APP_Framework/Framework/transform_layer/xiuos/user_api/posix_support/mqueue.c
  35. 0
      APP_Framework/Framework/transform_layer/xiuos/user_api/posix_support/pthread.c
  36. 0
      APP_Framework/Framework/transform_layer/xiuos/user_api/posix_support/pthread_mutex.c
  37. 4
      APP_Framework/Framework/transform_layer/xiuos/user_api/posix_support/semaphore.c
  38. 0
      APP_Framework/Framework/transform_layer/xiuos/user_api/switch_api/Makefile
  39. 7
      APP_Framework/Framework/transform_layer/xiuos/user_api/switch_api/user_api.h
  40. 0
      APP_Framework/Framework/transform_layer/xiuos/user_api/switch_api/user_event.c
  41. 6
      APP_Framework/Framework/transform_layer/xiuos/user_api/switch_api/user_fs.c
  42. 0
      APP_Framework/Framework/transform_layer/xiuos/user_api/switch_api/user_mem.c
  43. 0
      APP_Framework/Framework/transform_layer/xiuos/user_api/switch_api/user_msg.c
  44. 0
      APP_Framework/Framework/transform_layer/xiuos/user_api/switch_api/user_mutex.c
  45. 0
      APP_Framework/Framework/transform_layer/xiuos/user_api/switch_api/user_print_info.c
  46. 0
      APP_Framework/Framework/transform_layer/xiuos/user_api/switch_api/user_semaphore.c
  47. 0
      APP_Framework/Framework/transform_layer/xiuos/user_api/switch_api/user_task.c
  48. 4
      APP_Framework/Framework/transform_layer/xiuos/userspace.c
  49. 124
      APP_Framework/Framework/transform_layer/xiuos/xiuos.c
  50. 2
      APP_Framework/Kconfig
  51. 6
      APP_Framework/lib/Makefile
  52. 2
      APP_Framework/lib/app_newlib/Makefile
  53. 1
      APP_Framework/lib/app_newlib/fs_syscalls.c
  54. 9
      APP_Framework/lib/app_newlib/mem_syscalls.c
  55. 1
      Ubiquitous/XiUOS/applications/Kconfig
  56. 3
      Ubiquitous/XiUOS/applications/app_newlib/Makefile
  57. 98
      Ubiquitous/XiUOS/applications/app_newlib/fs_syscalls.c
  58. 29
      Ubiquitous/XiUOS/applications/app_newlib/include/libc.h
  59. 70
      Ubiquitous/XiUOS/applications/app_newlib/mem_syscalls.c
  60. 155
      Ubiquitous/XiUOS/applications/app_newlib/stdio.c
  61. 44
      Ubiquitous/XiUOS/applications/app_newlib/task_syscalls.c
  62. 34
      Ubiquitous/XiUOS/applications/app_newlib/time_syscalls.c
  63. 12
      Ubiquitous/XiUOS/applications/user_api/Makefile
  64. 3
      Ubiquitous/XiUOS/applications/user_api/general_functions/Makefile
  65. 3
      Ubiquitous/XiUOS/applications/user_api/general_functions/linklist/Makefile
  66. 84
      Ubiquitous/XiUOS/applications/user_api/general_functions/linklist/double_linklist.c
  67. 91
      Ubiquitous/XiUOS/applications/user_api/general_functions/linklist/single_linklist.c
  68. 129
      Ubiquitous/XiUOS/applications/user_api/general_functions/linklist/xs_klist.h
  69. 19
      Ubiquitous/XiUOS/applications/user_api/posix_support/Makefile
  70. 4
      Ubiquitous/XiUOS/kernel/Kconfig
  71. 8
      Ubiquitous/XiUOS/kernel/include/xs_klist.h
  72. 11
      Ubiquitous/XiUOS/path_app.mk
  73. 11
      Ubiquitous/XiUOS/path_kernel.mk

2
APP_Framework/Applications/general_functions/Makefile

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

3
APP_Framework/Applications/general_functions/linklist/Makefile

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

84
APP_Framework/Applications/general_functions/linklist/double_linklist.c

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

129
APP_Framework/Applications/general_functions/linklist/list.h

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

91
APP_Framework/Applications/general_functions/linklist/single_linklist.c

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

3
APP_Framework/Applications/general_functions/list/Makefile

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

84
APP_Framework/Applications/general_functions/list/double_list.c

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

118
APP_Framework/Applications/general_functions/list/list.h

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

91
APP_Framework/Applications/general_functions/list/single_list.c

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

2
APP_Framework/Applications/main.c

@ -12,8 +12,10 @@
#include <stdio.h>
#include <string.h>
#include <user_api.h>
int main(void)
{
printf("hello world\n");
return 0;
}

21
APP_Framework/Framework/Kconfig

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

6
APP_Framework/Framework/Makefile

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

3
APP_Framework/Framework/connection/Makefile

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

264
APP_Framework/Framework/connection/adapter.c

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

120
APP_Framework/Framework/connection/adapter.h

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

65
APP_Framework/Framework/sensor/sensor.c

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

8
APP_Framework/Framework/sensor/sensor.h

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

127
APP_Framework/Framework/transform.h

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

6
APP_Framework/Framework/transform_layer/Makefile

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

5
APP_Framework/Framework/transform_layer/xiuos/Makefile

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

86
APP_Framework/Framework/transform.c → APP_Framework/Framework/transform_layer/xiuos/transform.c

@ -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)
{
UserTaskDelay(ms);
}
/*********************fs**************************/
/************************Driver Posix Transform***********************/
int PrivOpen(const char *path, int flags, ...)
{
nanosleep(rqtp,rmtp);
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);
}
#endif
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);