Browse Source

Add sensor, modify makefile

pull/3/head
Zhao_Jiasheng 2 years ago
parent
commit
e37efc70ce
  1. 5
      APP_Framework/Applications/Makefile
  2. 3
      APP_Framework/Applications/general_functions/Makefile
  3. 3
      APP_Framework/Applications/general_functions/linklist/Makefile
  4. 84
      APP_Framework/Applications/general_functions/linklist/double_linklist.c
  5. 129
      APP_Framework/Applications/general_functions/linklist/list.h
  6. 91
      APP_Framework/Applications/general_functions/linklist/single_linklist.c
  7. 19
      APP_Framework/Applications/main.c
  8. 0
      APP_Framework/Applications/test
  9. 4
      APP_Framework/Framework/Makefile
  10. 3
      APP_Framework/Framework/sensor/Makefile
  11. 393
      APP_Framework/Framework/sensor/sensor.c
  12. 127
      APP_Framework/Framework/sensor/sensor.h
  13. 0
      APP_Framework/Framework/test
  14. 3
      APP_Framework/Framework/transform_layer/Makefile
  15. 131
      APP_Framework/Framework/transform_layer/transform.h
  16. 43
      APP_Framework/Framework/transform_layer/xiuos/userspace.c
  17. 124
      APP_Framework/Framework/transform_layer/xiuos/xiuos.c
  18. 4
      APP_Framework/Makefile
  19. 3
      APP_Framework/lib/Makefile
  20. 3
      APP_Framework/lib/app_newlib/Makefile
  21. 97
      APP_Framework/lib/app_newlib/fs_syscalls.c
  22. 29
      APP_Framework/lib/app_newlib/include/libc.h
  23. 70
      APP_Framework/lib/app_newlib/mem_syscalls.c
  24. 155
      APP_Framework/lib/app_newlib/stdio.c
  25. 43
      APP_Framework/lib/app_newlib/task_syscalls.c
  26. 32
      APP_Framework/lib/app_newlib/time_syscalls.c

5
APP_Framework/Applications/Makefile

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

3
APP_Framework/Applications/general_functions/Makefile

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

3
APP_Framework/Applications/general_functions/linklist/Makefile

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

84
APP_Framework/Applications/general_functions/linklist/double_linklist.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 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

@ -0,0 +1,129 @@
/*
* 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 <libc.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

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

19
APP_Framework/Applications/main.c

@ -0,0 +1,19 @@
/*
* 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 <stdio.h>
#include <string.h>
int main(void)
{
return 0;
}

0
APP_Framework/Applications/test

4
APP_Framework/Framework/Makefile

@ -0,0 +1,4 @@
SRC_DIR := sensor transform_layer
include $(KERNEL_ROOT)/compiler.mk

3
APP_Framework/Framework/sensor/Makefile

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

393
APP_Framework/Framework/sensor/sensor.c

@ -0,0 +1,393 @@
/*
* 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 sensor.c
* @brief Implement the sensor framework management, registration and done
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.03.24
*/
#include <sensor.h>
/* Sensor quantity list table */
static DoubleLinklistType quant_table[SENSOR_QUANTITY_END];
/* Sensor device list */
static DoubleLinklistType sensor_device_list;
/* Sensor quantity list lock */
static int quant_table_lock;
/* Sensor device list lock */
static int sensor_device_list_lock;
/**
* @description: Init perception framework
* @return 0
*/
int SensorFrameworkInit(void)
{
for (int i = 0; i < SENSOR_QUANTITY_END; i++)
InitDoubleLinkList(&quant_table[i]);
InitDoubleLinkList(&sensor_device_list);
quant_table_lock = PrivMutexCreate();
sensor_device_list_lock = PrivMutexCreate();
return 0;
}
/* ============================= Sensor device interface operations ============================= */
/**
* @description: Find sensor device by name
* @param name - name string
* @return sensor device pointer
*/
static struct SensorDevice *SensorDeviceFindByName(const char *name)
{
struct SensorDevice *ret = NULL;
struct SysDoubleLinklistNode *node;
if (name == NULL)
return NULL;
PrivMutexObtain(sensor_device_list_lock, -1);
DOUBLE_LINKLIST_FOR_EACH(node, &sensor_device_list) {
struct SensorDevice *sdev =CONTAINER_OF(node,
struct SensorDevice, link);
if (strncmp(sdev->name, name, NAME_NUM_MAX) == 0) {
ret = sdev;
break;
}
}
PrivMutexAbandon(sensor_device_list_lock);
return ret;
}
/**
* @description: Check whether the sensor is capable
* @param sdev - sensor device pointer
* @param ability - the ability to detect certain data
* @return success: true , failure: false
*/
inline int SensorDeviceCheckAbility(struct SensorDevice *sdev, uint32_t ability)
{
return (sdev->info->ability & ability) != 0;
}
/**
* @description: Register the sensor to the linked list
* @param sdev - sensor device pointer
* @return success: 0 , failure: -1
*/
int SensorDeviceRegister(struct SensorDevice *sdev)
{
if (sdev == NULL)
return -1;
if (SensorDeviceFindByName(sdev->name) != NULL) {
printf("%s: sensor with the same name already registered\n", __func__);
return -1;
}
sdev->ref_cnt = 0;
InitDoubleLinkList(&sdev->quant_list);
PrivMutexObtain(sensor_device_list_lock, -1);
DoubleLinkListInsertNodeAfter(&sensor_device_list, &sdev->link);
PrivMutexAbandon(sensor_device_list_lock);
return 0;
}
/**
* @description: Unregister the sensor from the linked list
* @param sdev - sensor device pointer
* @return 0
*/
int SensorDeviceUnregister(struct SensorDevice *sdev)
{
if (!sdev)
return -1;
PrivMutexObtain(sensor_device_list_lock, -1);
DoubleLinkListRmNode(&sdev->link);
PrivMutexAbandon(sensor_device_list_lock);
return 0;
}
/**
* @description: Open sensor device
* @param sdev - sensor device pointer
* @return success: 0 , failure: other
*/
static int SensorDeviceOpen(struct SensorDevice *sdev)
{
if (!sdev)
return -1;
int result = 0;
if (sdev->done->open != NULL)
result = sdev->done->open(sdev);
if (result == 0) {
printf("Device %s open success.\n", sdev->name);
}else{
if (sdev->fd)
PrivClose(sdev->fd);
printf("Device %s open failed(%d).\n", sdev->name, result);
memset(sdev, 0, sizeof(struct SensorDevice));
}
return result;
}
/**
* @description: Close sensor device
* @param sdev - sensor device pointer
* @return success: 0 , failure: other
*/
static int SensorDeviceClose(struct SensorDevice *sdev)
{
int result = 0;
if (sdev->fd)
PrivClose(sdev->fd);
if (sdev->done->close != NULL)
result = sdev->done->close(sdev);
if (result == 0)
printf("%s successfully closed.\n", sdev->name);
else
printf("Closed %s failure.\n", sdev->name);
return result;
}
/* ============================= Sensor quantity interface operations ============================= */
/**
* @description: Find sensor quantity by name
* @param name - name string
* @param type - the quantity required
* @return sensor quantity pointer
*/
struct SensorQuantity *SensorQuantityFind(const char *name,
enum SensorQuantityType type)
{
struct SensorQuantity *ret = NULL;
struct SysDoubleLinklistNode *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]) {
struct SensorQuantity *quant =CONTAINER_OF(node,
struct SensorQuantity, link);
if (strncmp(quant->name, name, NAME_NUM_MAX) == 0) {
ret = quant;
break;
}
}
PrivMutexAbandon(quant_table_lock);
return ret;
}
/**
* @description: Register the quantity to the linked list
* @param quant - sensor quantity pointer
* @return success: 0 , failure: -1
*/
int SensorQuantityRegister(struct SensorQuantity *quant)
{
if (quant == NULL)
return -1;
if (SensorDeviceFindByName(quant->sdev->name) == NULL) {
if(SensorDeviceRegister(quant->sdev) != 0)
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);
return 0;
}
/**
* @description: Unregister the quantity from the linked list
* @param quant - sensor quantity pointer
* @return 0
*/
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);
return 0;
}
/**
* @description: Open the sensor quantity
* @param quant - sensor quantity pointer
* @return success: 0 , failure: other
*/
int SensorQuantityOpen(struct SensorQuantity *quant)
{
if (!quant)
return -1;
int ret = 0;
struct SensorDevice *sdev = quant->sdev;
if (!sdev)
return -1;
if (sdev->ref_cnt == 0) {
ret = SensorDeviceOpen(sdev);
if (ret != 0) {
printf("%s: open sensor device failed\n", __func__);
return ret;
}
}
sdev->ref_cnt++;
return ret;
}
/**
* @description: Close sensor quantity
* @param quant - sensor quantity pointer
* @return success: 0 , failure: other
*/
int SensorQuantityClose(struct SensorQuantity *quant)
{
if (!quant)
return -1;
int ret = 0;
struct SensorDevice *sdev = quant->sdev;
if (!sdev)
return -1;
if (sdev->ref_cnt == 0)
return ret;
sdev->ref_cnt--;
if (sdev->ref_cnt == 0)
ret = SensorDeviceClose(sdev);
return ret;
}
/**
* @description: Read quantity current value
* @param quant - sensor quantity pointer
* @return quantity value
*/
int SensorQuantityRead(struct SensorQuantity *quant)
{
if (!quant)
return -1;
int result = 0;
struct SensorDevice *sdev = quant->sdev;
if (!sdev)
return -1;
if (quant->ReadValue != NULL) {
result = quant->ReadValue(quant);
}
return result;
}
/**
* @description: Configure quantity mode
* @param quant - sensor quantity pointer
* @param cmd - mode command
* @return success: 0 , failure: other
*/
int SensorQuantityControl(struct SensorQuantity *quant, int cmd)
{
if (!quant)
return -1;
if (quant->sdev->done->ioctl != NULL) {
return quant->sdev->done->ioctl(quant->sdev, cmd);
}
return -1;
}
/* ============================= Check function ============================= */
/**
* @description: CRC16 check
* @param data sensor receive buffer
* @param length sensor receive buffer minus check code
* @return check code
*/
uint32_t Crc16(uint8_t * data, uint8_t length)
{
int j;
unsigned int reg_crc=0xFFFF;
while (length--) {
reg_crc ^= *data++;
for (j=0;j<8;j++) {
if(reg_crc & 0x01)
reg_crc=reg_crc >>1 ^ 0xA001;
else
reg_crc=reg_crc >>1;
}
}
return reg_crc;
}
/**
* @description: The checksum
* @param data sensor receive buffer
* @param head not check head length
* @param length sensor receive buffer minus check code
* @return check code
*/
uint8_t GetCheckSum(uint8_t *data, uint8_t head, uint8_t length)
{
uint8_t i;
uint8_t checksum = 0;
for (i = head; i < length; i++) {
checksum += data[i];
}
checksum = ~checksum + 1;
return checksum;
}

127
APP_Framework/Framework/sensor/sensor.h

@ -0,0 +1,127 @@
/*
* 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 sensor.h
* @brief Structure and function declarations of the sensor framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.03.24
*/
#ifndef SENSOR_H
#define SENSOR_H
#include <list.h>
#include <stdio.h>
#include <string.h>
#include <transform.h>
#define SENSOR_QUANTITY_VALUE_ERROR ((uint32_t)0xffffffff)
/* Sensor quantity report mode */
#define SENSOR_DEVICE_PASSIVE 0x00
#define SENSOR_DEVICE_ACTIVE 0x01
#define SENSOR_RECEIVE_BUFFSIZE 32
#if SENSOR_TYPE_END > 32
#error "Too many sensor types"
#endif
/* Sensor ability */
#define SENSOR_ABILITY_CO2 ((uint32_t)(1 << SENSOR_QUANTITY_CO2))
#define SENSOR_ABILITY_TEMP ((uint32_t)(1 << SENSOR_QUANTITY_TEMP))
#define SENSOR_ABILITY_HUMI ((uint32_t)(1 << SENSOR_QUANTITY_HUMI))
#define SENSOR_ABILITY_HCHO ((uint32_t)(1 << SENSOR_QUANTITY_HCHO))
#define SENSOR_ABILITY_CO ((uint32_t)(1 << SENSOR_QUANTITY_CO))
#define SENSOR_ABILITY_PM ((uint32_t)(1 << SENSOR_QUANTITY_PM))
#define SENSOR_ABILITY_VOICE ((uint32_t)(1 << SENSOR_QUANTITY_VOICE))
struct SensorProductInfo {
uint32_t ability; /* Bitwise OR of sensor ability */
const char *vendor_name;
const char *model_name;
};
struct SensorDevice;
struct SensorDone {
int (*open)(struct SensorDevice *sdev);
int (*close)(struct SensorDevice *sdev);
int (*read)(struct SensorDevice *sdev, size_t len);
int (*write)(struct SensorDevice *sdev, const void *buf, size_t len);
int (*ioctl)(struct SensorDevice *sdev, int cmd);
};
struct SensorDevice {
char *name; /* Name of sensor */
struct SensorProductInfo *info; /* Sensor model info */
struct SensorDone *done;
int fd; /* File descriptor */
int status; /* Sensor work mode */
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 */
};
enum SensorQuantityType {
SENSOR_QUANTITY_CO2 = 0,
SENSOR_QUANTITY_TEMP,
SENSOR_QUANTITY_HUMI,
SENSOR_QUANTITY_HCHO,
SENSOR_QUANTITY_CO,
SENSOR_QUANTITY_PM,
SENSOR_QUANTITY_VOICE,
/* ...... */
SENSOR_QUANTITY_END,
};
struct SensorQuantityValue {
uint8_t decimal_places; /* The decimal place of the result */
uint32_t last_value; /* The last read value, if it does not exist, is SENSOR_QUANTITY_VALUE_ERROR */
uint32_t min_value; /* The minimum read value, if it does not exist, is SENSOR_QUANTITY_VALUE_ERROR */
uint32_t max_value; /* The maximum read value, if it does not exist, is SENSOR_QUANTITY_VALUE_ERROR */
uint32_t min_std; /* The minimum standard value, if it does not exist, is SENSOR_QUANTITY_VALUE_ERROR */
uint32_t max_std; /* The maximum standard value, if it does not exist, is SENSOR_QUANTITY_VALUE_ERROR */
};
struct SensorQuantity {
char *name;
enum SensorQuantityType type;
struct SensorQuantityValue value;
struct SensorDevice *sdev;
int32_t (*ReadValue)(struct SensorQuantity *quant);
struct SysDoubleLinklistNode quant_link;
struct SysDoubleLinklistNode link;
};
int SensorDeviceRegister(struct SensorDevice *sdev);
int SensorDeviceUnregister(struct SensorDevice *sdev);
struct SensorQuantity *SensorQuantityFind(const char *name, enum SensorQuantityType type);
int SensorQuantityRegister(struct SensorQuantity *quant);
int SensorQuantityUnregister(struct SensorQuantity *quant);
int SensorQuantityOpen(struct SensorQuantity *quant);
int SensorQuantityClose(struct SensorQuantity *quant);
int32_t SensorQuantityRead(struct SensorQuantity *quant);
int SensorQuantityControl(struct SensorQuantity *quant, int cmd);
uint32_t Crc16(uint8_t * data, uint8_t length);
uint8_t GetCheckSum(uint8_t *data, uint8_t head, uint8_t length);
#endif

0
APP_Framework/Framework/test

3
APP_Framework/Framework/transform_layer/Makefile

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

131
APP_Framework/Framework/transform_layer/transform.h

@ -0,0 +1,131 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file transform.h
* @brief Interface function declarations required by the framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.06.04
*/
#ifndef TRANSFORM_H
#define TRANSFORM_H
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define NAME_NUM_MAX 32
#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;
};
enum IoctlCmd
{
SERIAL_CFG_SETS = 0,
SERIAL_CFG_GETS,
};
/**********************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);
/*********************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);
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 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);
#ifdef __cplusplus
}
#endif
#endif

43
APP_Framework/Framework/transform_layer/xiuos/userspace.c

@ -0,0 +1,43 @@
#include <stdio.h>
#include <stdint.h>
extern int main(void);
//extern void UserTaskQuit(void);
extern uintptr_t _ustext;
extern uintptr_t _uetext;
extern uintptr_t _ueronly;
extern uintptr_t _usdata;
extern uintptr_t _uedata;
extern uintptr_t _usbss;
extern uintptr_t _uebss;
typedef int (*main_t)(int argc, char *argv[]);
typedef void (*exit_t)(void);
struct userspace_s
{
main_t us_entrypoint;
exit_t us_taskquit;
uintptr_t us_textstart;
uintptr_t us_textend;
uintptr_t us_datasource;
uintptr_t us_datastart;
uintptr_t us_dataend;
uintptr_t us_bssstart;
uintptr_t us_bssend;
uintptr_t us_heapend;
};
const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
{
/* General memory map */
.us_entrypoint = (main_t)main,
//.us_taskquit = (exit_t)UserTaskQuit,
.us_textstart = (uintptr_t)&_ustext,
.us_textend = (uintptr_t)&_uetext,
.us_datasource = (uintptr_t)&_ueronly,
.us_datastart = (uintptr_t)&_usdata,
.us_dataend = (uintptr_t)&_uedata,
.us_bssstart = (uintptr_t)&_usbss,
.us_bssend = (uintptr_t)&_uebss,
};

124
APP_Framework/Framework/transform_layer/xiuos/xiuos.c

@ -0,0 +1,124 @@
/*
* 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;
}

4
APP_Framework/Makefile

@ -0,0 +1,4 @@
SRC_DIR := Applications Framework lib
include $(KERNEL_ROOT)/compiler.mk

3
APP_Framework/lib/Makefile

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

3
APP_Framework/lib/app_newlib/Makefile

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

97
APP_Framework/lib/app_newlib/fs_syscalls.c

@ -0,0 +1,97 @@
/*
* 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>
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);
}

29
APP_Framework/lib/app_newlib/include/libc.h

@ -0,0 +1,29 @@
/*
* 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

70
APP_Framework/lib/app_newlib/mem_syscalls.c

@ -0,0 +1,70 @@
/*
* 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 <stddef.h>
void *_malloc_r (struct _reent *ptr, size_t size)
{
void* result = (void*)UserMalloc(size);
if (result == NULL)
{
ptr->_errno = 12;
}
return result;
}
void *_realloc_r (struct _reent *ptr, void *old, size_t newlen)
{
void* result = (void*)UserRealloc(old, newlen);
if (result == NULL)
{
ptr->_errno = 12;
}
return result;
}
void *_calloc_r (struct _reent *ptr, size_t size, size_t len)
{
void* result = (void*)UserCalloc(size, len);
if (result == NULL)
{
ptr->_errno = 12;
}
return result;
}
void _free_r (struct _reent *ptr, void *address)
{
UserFree (address);
}

155
APP_Framework/lib/app_newlib/stdio.c

@ -0,0 +1,155 @@
/*
* 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;
}

43
APP_Framework/lib/app_newlib/task_syscalls.c

@ -0,0 +1,43 @@
/*
* 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
*************************************************/
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);
}

32
APP_Framework/lib/app_newlib/time_syscalls.c

@ -0,0 +1,32 @@
/*
* 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.