forked from xuos/xiuos
First commit XiUOS
This commit is contained in:
commit
6001051eb7
|
@ -0,0 +1,8 @@
|
|||
xsconfig.h
|
||||
xsconfig.mk
|
||||
.config
|
||||
.config.old
|
||||
build
|
||||
XiUOS.*
|
||||
*.swp
|
||||
.vscode
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
source "$KERNEL_DIR/kernel/Kconfig"
|
||||
|
||||
|
||||
source "$KERNEL_DIR/fs/Kconfig"
|
||||
|
||||
|
||||
source "$KERNEL_DIR/framework/Kconfig"
|
||||
|
||||
source "$KERNEL_DIR/applications/Kconfig"
|
|
@ -0,0 +1,112 @@
|
|||
MAKEFLAGS += --no-print-directory
|
||||
|
||||
|
||||
.PHONY:all clean distclean show_info menuconfig
|
||||
.PHONY:COMPILE_APP COMPILE_KERNEL
|
||||
|
||||
|
||||
support :=kd233 stm32f407-st-discovery maix-go stm32f407zgt6 aiit-riscv64-board aiit-arm32-board hifive1-rev-B
|
||||
SRC_DIR:=
|
||||
|
||||
export BOARD ?=kd233
|
||||
|
||||
ifeq ($(filter $(BOARD),$(support)),)
|
||||
$(warning "You should choose board like this:make BOARD=kd233")
|
||||
$(warning "This is what we support:")
|
||||
$(warning "$(support)")
|
||||
$(error "break" )
|
||||
endif
|
||||
|
||||
export TARGET
|
||||
export COMPILE_TYPE
|
||||
export KERNEL_ROOT ?=$(strip $(shell pwd))
|
||||
|
||||
MAKEFILES =$(KERNEL_ROOT)/.config
|
||||
-include $(KERNEL_ROOT)/.config
|
||||
|
||||
export BSP_ROOT ?= $(KERNEL_ROOT)/board/$(BOARD)
|
||||
include board/$(BOARD)/config.mk
|
||||
export BSP_BUILD_DIR := board/$(BOARD)
|
||||
export HOSTTOOLS_DIR ?= $(KERNEL_ROOT)/tool/hosttools
|
||||
export CONFIG2H_EXE ?= $(HOSTTOOLS_DIR)/xsconfig.sh
|
||||
|
||||
export CPPPATHS
|
||||
export SRC_APP_DIR := applications framework
|
||||
export SRC_KERNEL_DIR := arch board lib fs kernel resources tool
|
||||
export SRC_DIR:= $(SRC_APP_DIR) $(SRC_KERNEL_DIR)
|
||||
|
||||
PART:=
|
||||
|
||||
all:
|
||||
|
||||
ifeq ($(CONFIG_COMPILER_APP)_$(CONFIG_COMPILER_KERNEL),y_)
|
||||
include path_app.mk
|
||||
PART += COMPILE_APP
|
||||
|
||||
else ifeq ($(CONFIG_COMPILER_APP)_$(CONFIG_COMPILER_KERNEL),_y)
|
||||
include path_kernel.mk
|
||||
PART += COMPILE_KERNEL
|
||||
|
||||
else ifeq ($(CONFIG_COMPILER_APP)_$(CONFIG_COMPILER_KERNEL),y_y)
|
||||
include path_app.mk
|
||||
include path_kernel.mk
|
||||
PART := COMPILE_APP COMPILE_KERNEL
|
||||
|
||||
else
|
||||
include path_kernel.mk
|
||||
CPPPATHS := $(KERNELPATHS)
|
||||
PART := COMPILE_ALL
|
||||
endif
|
||||
|
||||
|
||||
|
||||
all: $(PART)
|
||||
|
||||
|
||||
COMPILE_ALL:
|
||||
@for dir in $(SRC_DIR);do \
|
||||
$(MAKE) -C $$dir; \
|
||||
done
|
||||
@cp link.mk build/Makefile
|
||||
@$(MAKE) -C build TARGET=XiUOS_$(BOARD).elf LINK_FLAGS=LFLAGS
|
||||
@rm build/Makefile build/make.obj
|
||||
|
||||
|
||||
|
||||
show_info:
|
||||
@echo "TARGET is :" $(TARGET)
|
||||
@echo "VPATH is :" $(VPATH)
|
||||
@echo "BSP_ROOT is :" $(BSP_ROOT)
|
||||
@echo "KERNEL_ROOT is :" $(KERNEL_ROOT)
|
||||
@echo "CPPPATHS is :" $(CPPPATHS)
|
||||
@echo "SRC_DIR is :" $(SRC_DIR)
|
||||
@echo "BUILD_DIR is :" $(BUILD_DIR)
|
||||
@echo "RTT_ROOT_DIR is :" $(RTT_ROOT_DIR)
|
||||
@echo "BSP_BUILD_DIR is :" $(BSP_BUILD_DIR)
|
||||
@echo "OBJS is :" $(OBJS)
|
||||
@for f in $(CPPPATHS); do \
|
||||
echo $$f; \
|
||||
done
|
||||
|
||||
|
||||
|
||||
menuconfig:
|
||||
@if [ -f "$(BSP_ROOT)/.config" ]; then \
|
||||
cp $(BSP_ROOT)/.config $(KERNEL_ROOT)/.config; \
|
||||
else if [ -f "$(BSP_ROOT)/.defconfig" ]; then \
|
||||
cp $(BSP_ROOT)/.defconfig $(KERNEL_ROOT)/.config ;\
|
||||
fi ;fi
|
||||
@kconfig-mconf $(BSP_ROOT)/Kconfig
|
||||
@$(CONFIG2H_EXE) .config
|
||||
@cp $(KERNEL_ROOT)/.config $(BSP_ROOT)/.config
|
||||
|
||||
clean:
|
||||
@echo Clean target and build_dir
|
||||
@rm -rf build
|
||||
@rm -rf temp.txt
|
||||
|
||||
distclean:
|
||||
@echo Clean all configuration
|
||||
@make clean
|
||||
@rm -f .config*
|
||||
@rm -f $(BSP_ROOT)/.config
|
|
@ -0,0 +1,68 @@
|
|||
# XiUOS README
|
||||
|
||||
[XiUOS](http://xuos.io/) (X Industrial Ubiquitous Operating System) 矽璓工业物联操作系统是一款面向工业物联场景的泛在操作系统,来自泛在操作系统研究计划。所谓泛在操作系统(UOS: Ubiquitous Operating Systems),是支持互联网时代人机物融合泛在计算应用模式的新型操作系统,是传统操作系统概念的泛化与延伸。在泛在操作系统技术体系中,不同的泛在计算设备和泛在应用场景需要符合各自特性的不同UOS,XiUOS即是面向工业物联场景的一种UOS,主要由一个极简的微型实时操作系统(RTOS)内核和其上的智能工业物联框架构成,支持工业物联网(IIoT: Industrial Internet of Things)应用。
|
||||
|
||||
## 目录结构
|
||||
|
||||
| 名称 | 说明 |
|
||||
| -- | -- |
|
||||
| application | 应用代码 |
|
||||
| board | 板级支持包 |
|
||||
| framework | 应用框架 |
|
||||
| fs | 文件系统 |
|
||||
| kernel | 内核源码 |
|
||||
| resources | 驱动文件 |
|
||||
| tool | 系统工具 |
|
||||
| | |
|
||||
|
||||
## 硬件支持
|
||||
|
||||
目前XiUOS支持ARM和RISC-V两种架构的微处理器:
|
||||
|
||||
### ARM
|
||||
|
||||
ARM架构系列的开发板有
|
||||
|
||||
aiit-arm32-board stm32f407-st-discovery stm32f407zgt6
|
||||
|
||||
### RISC-V
|
||||
|
||||
RISC-V架构系列的开发板有
|
||||
|
||||
aiit-riscv64-board hifive1-rev-B kd233 maix-go
|
||||
|
||||
## 开发环境
|
||||
|
||||
### 推荐使用:
|
||||
|
||||
### 操作系统: [Ubuntu18.04](https://ubuntu.com/download/desktop)
|
||||
|
||||
### 开发工具: [VSCode](https://code.visualstudio.com/)
|
||||
|
||||
### 依赖包安装:
|
||||
|
||||
```
|
||||
$ sudo apt-get install build-essential pkg-config
|
||||
$ sudo apt-get install gcc make libncurses5-dev openssl libssl-dev bison flex libelf-dev autoconf libtool gperf libc6-dev
|
||||
```
|
||||
|
||||
### 编译工具链:
|
||||
|
||||
ARM: arm-none-eabi,默认安装到Ubuntu的/usr/bin/arm-none-eabi-,使用如下命令行下载
|
||||
```shell
|
||||
$ sudo apt-get install gcc-arm-none-eabi
|
||||
```
|
||||
|
||||
RISC-V: riscv-none-embed-,默认安装到Ubuntu的/opt/,下载源码并解压。[下载网址](https://github.com/ilg-archived/riscv-none-gcc/releases)
|
||||
|
||||
```shell
|
||||
$ tar -zxvf gnu-mcu-eclipse-riscv-none-gcc-8.2.0-2.1-20190425-1021-centos64.tgz -C /opt/
|
||||
```
|
||||
|
||||
### 烧写工具
|
||||
|
||||
ARM:ST-LINK
|
||||
|
||||
RISC-V:K-FLash
|
||||
|
||||
**每种开发板分别对应board目录下的一个文件夹,具体编译及烧录步骤请参见board目录下对应文件夹下的README文件。**
|
|
@ -0,0 +1,100 @@
|
|||
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
|
||||
int "Set main task stack size"
|
||||
default 1024
|
||||
config MAIN_KTASK_PRIORITY
|
||||
int
|
||||
default 4 if KTASK_PRIORITY_8
|
||||
default 10 if KTASK_PRIORITY_32
|
||||
default 85 if KTASK_PRIORITY_256
|
||||
endmenu
|
||||
|
||||
menuconfig APPLICATION_SENSOR
|
||||
bool "Using sensor apps"
|
||||
default n
|
||||
select PERCEPTION_SENSORDEVICE
|
||||
|
||||
if APPLICATION_SENSOR
|
||||
menuconfig APPLICATION_SENSOR_CO2
|
||||
bool "Using sensor CO2 apps"
|
||||
default n
|
||||
select PERCEPTION_CO2
|
||||
|
||||
if APPLICATION_SENSOR_CO2
|
||||
config APPLICATION_SENSOR_CO2_ZG09
|
||||
bool "Using sensor ZG09 apps"
|
||||
default n
|
||||
select PERCEPTION_ZG09
|
||||
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_PM1_0
|
||||
bool "Using sensor PM1.0 apps"
|
||||
default n
|
||||
select PERCEPTION_PM
|
||||
|
||||
if APPLICATION_SENSOR_PM1_0
|
||||
config APPLICATION_SENSOR_PM1_0_PS5308
|
||||
bool "Using sensor PS5308 apps"
|
||||
default n
|
||||
select PERCEPTION_PS5308
|
||||
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_VOICE
|
||||
bool "Using sensor voice apps"
|
||||
default n
|
||||
select PERCEPTION_VOICE
|
||||
|
||||
if APPLICATION_SENSOR_VOICE
|
||||
config APPLICATION_SENSOR_VOICE_D124
|
||||
bool "Using sensor D124 apps"
|
||||
default n
|
||||
select PERCEPTION_D124
|
||||
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_HUMIDITY
|
||||
bool "Using sensor humidity apps"
|
||||
default n
|
||||
select PERCEPTION_HUMIDITY
|
||||
|
||||
if APPLICATION_SENSOR_HUMIDITY
|
||||
config APPLICATION_SENSOR_HUMIDITY_HS300X
|
||||
bool "Using sensor HS300x apps"
|
||||
default n
|
||||
select PERCEPTION_HS300X
|
||||
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_TEMPERATURE
|
||||
bool "Using sensor temperature apps"
|
||||
default n
|
||||
select PERCEPTION_TEMPERATURE
|
||||
|
||||
if APPLICATION_SENSOR_TEMPERATURE
|
||||
config APPLICATION_SENSOR_TEMPERATURE_HS300X
|
||||
bool "Using sensor HS300x apps"
|
||||
default n
|
||||
select PERCEPTION_HS300X
|
||||
|
||||
endif
|
||||
endif
|
||||
|
||||
menuconfig CONNECTION_COMMUNICATION_ZIGBEE
|
||||
bool "enable zigbee demo"
|
||||
default n
|
||||
select CONFIG_CONNECTION_COMMUNICATION_ZIGBEE
|
||||
if CONNECTION_COMMUNICATION_ZIGBEE
|
||||
source "$KERNEL_DIR/framework/connection/Adapter/zigbee/Kconfig"
|
||||
endif
|
||||
|
||||
|
||||
source "$KERNEL_DIR/applications/tflite_sin/Kconfig"
|
||||
source "$KERNEL_DIR/applications/tflite_mnist/Kconfig"
|
||||
source "$KERNEL_DIR/applications/app_test/Kconfig"
|
||||
|
||||
endmenu
|
|
@ -0,0 +1,54 @@
|
|||
SRC_DIR := tflite_sin tflite_mnist
|
||||
|
||||
ifeq ($(CONFIG_USER_APPLICATION),y)
|
||||
SRC_FILES := main.c framework_init.c
|
||||
SRC_DIR += user_api
|
||||
|
||||
ifeq ($(CONFIG_SEPARATE_COMPILE),y)
|
||||
SRC_DIR += app_newlib
|
||||
SRC_FILES += userspace.c
|
||||
else
|
||||
SRC_FILES += cppmain.cpp
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST),y)
|
||||
SRC_DIR += app_test
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_RESOURCES_SDIO), y)
|
||||
SRC_FILES += sd_card_mount.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_RESOURCES_SPI_SD), y)
|
||||
SRC_FILES += spi_sd_card_mount.c
|
||||
endif
|
||||
|
||||
# ifeq ($(CONFIG_CONNECTION_COMMUNICATION_BOOTSTART_LORA_NET_SAMPLE), y)
|
||||
# SRC_DIR += connection_demo/adhoc_lora_demo
|
||||
# endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_COMMUNICATION_ZIGBEE), y)
|
||||
SRC_DIR += connection_demo/zigbee_demo
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_COMMUNICATION_ETHERNET), y)
|
||||
SRC_DIR += connection_demo/ethernet_demo
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_COMMUNICATION_WIFI), y)
|
||||
SRC_DIR += connection_demo/wifi_demo
|
||||
endif
|
||||
|
||||
# ifeq ($(CONFIG_CONNECTION_COMMUNICATION_4G), y)
|
||||
# SRC_DIR += connection_demo/4G_demo
|
||||
# endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR),y)
|
||||
SRC_DIR += sensor_app
|
||||
endif
|
||||
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES := stdio.c fs_syscalls.c mem_syscalls.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* 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/switch_api/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);
|
||||
}
|
|
@ -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
|
||||
|
|
@ -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 "../user_api/switch_api/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);
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* 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);
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
#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 = ¤t;
|
||||
|
||||
RtcDrvSetFunction(RTC_DRV_NAME, &rtc_set_param);
|
||||
#endif
|
||||
|
||||
*t = current;
|
||||
|
||||
return current;
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
menuconfig USER_TEST
|
||||
bool "Enable application test function "
|
||||
default n
|
||||
|
||||
if USER_TEST
|
||||
config USER_TEST_LORA_ADHOC
|
||||
bool "Config test lora adhoc"
|
||||
default n
|
||||
|
||||
endif
|
|
@ -0,0 +1,7 @@
|
|||
SRC_FILES :=
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_LORA_ADHOC),y)
|
||||
SRC_FILES += test_adhoc_lora.c
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,20 @@
|
|||
#include <xiuos.h>
|
||||
|
||||
extern void net_lora_client(int argc, char *argv[]);
|
||||
extern void net_lora_gateway(int argc, char *argv[]);
|
||||
|
||||
void demo_lora_adhoc()
|
||||
{
|
||||
#ifdef CONNECTION_COMMUNICATION_SET_AS_LORA_CLIENT
|
||||
char pgk_count[32];
|
||||
char* param[3];
|
||||
param[0] = "xxx";
|
||||
param[1] = CONNECTION_COMMUNICATION_LORA_CLIENT_NAME;
|
||||
itoa(CONNECTION_COMMUNICATION_LORA_CLIENT_PKG_COUNT, pgk_count, 10);
|
||||
param[2] = pgk_count;
|
||||
net_lora_client(2, param);
|
||||
#endif
|
||||
#ifdef CONNECTION_COMMUNICATION_SET_AS_LORA_GATEWAY
|
||||
net_lora_gateway(0, 0);
|
||||
#endif
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
SRC_DIR +=
|
||||
|
||||
|
||||
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES := ethernet_demo.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,196 @@
|
|||
/*
|
||||
* 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 ethernet_demo.c
|
||||
* @brief Demo for ethernet function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.22
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <user_api.h>
|
||||
#include <xs_adapter_manager.h>
|
||||
#include <xs_adapter_at_ethernet.h>
|
||||
|
||||
static bool opened = false;
|
||||
|
||||
void OpenEthernetMsg()
|
||||
{
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
|
||||
if (!at_adapter)
|
||||
printf("ATAdapterFind failed .\n");
|
||||
|
||||
if (!opened){
|
||||
opened = true;
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SendEthernetMsg(int argc, char *argv[])
|
||||
{
|
||||
char ethernet_msg[128];
|
||||
if (argc >= 1){
|
||||
memset(ethernet_msg, 0, 128);
|
||||
strncpy(ethernet_msg, argv[1], strlen(argv[1]));
|
||||
printf("SendEthernetMsg(%s).\n", ethernet_msg);
|
||||
}
|
||||
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
|
||||
if (!at_adapter)
|
||||
printf("ATAdapterFind failed .\n");
|
||||
|
||||
if (!opened){
|
||||
opened = true;
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
}
|
||||
|
||||
at_adapter->parent.done.NetAiitSend(&at_adapter->parent, ethernet_msg, strlen(ethernet_msg), true, 1000, 0, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
void RecvEthernetMsg()
|
||||
{
|
||||
char ethernet_recv_msg[128];
|
||||
memset(ethernet_recv_msg, 0, sizeof(ethernet_recv_msg));
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
|
||||
if (!at_adapter)
|
||||
printf("ATAdapterFind failed .\n");
|
||||
|
||||
if (!opened){
|
||||
opened = true;
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
}
|
||||
|
||||
while (1){
|
||||
memset(ethernet_recv_msg, 0, sizeof(ethernet_recv_msg));
|
||||
if (EOK == at_adapter->parent.done.NetAiitReceive(&at_adapter->parent, ethernet_recv_msg, 128, 40000, true, NULL))
|
||||
printf("ethernet_recv_msg (%s)\n", ethernet_recv_msg);
|
||||
else
|
||||
printf("ethernet_recv_msg failed .\n");
|
||||
}
|
||||
}
|
||||
|
||||
void DhcpEthernet()
|
||||
{
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
|
||||
if (!at_adapter)
|
||||
printf("ATAdapterFind failed .\n");
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
if (!opened){
|
||||
opened = true;
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
}
|
||||
|
||||
if (EOK != at_adapter->atdone.ATOperateDHCP(at_adapter, 1))
|
||||
printf("EthernetNetstat failed \n");
|
||||
}
|
||||
|
||||
void PingEthernet()
|
||||
{
|
||||
char ethernet_recv_msg[128];
|
||||
memset(ethernet_recv_msg, 0, sizeof(ethernet_recv_msg));
|
||||
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
|
||||
if (!at_adapter)
|
||||
printf("ATAdapterFind failed .\n");
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
struct ping_result result;
|
||||
char *ip_str = "192.168.250.250";
|
||||
|
||||
if (!opened){
|
||||
opened = true;
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
}
|
||||
|
||||
if (EOK == at_adapter->atdone.ATPing(at_adapter, ip_str, &result))
|
||||
printf("EthernetPing success (%s)\n", result.ip_addr.ipv4);
|
||||
else
|
||||
printf("EthernetPing failed \n");
|
||||
}
|
||||
|
||||
void SetUpEthernet()
|
||||
{
|
||||
char ethernet_recv_msg[128];
|
||||
memset(ethernet_recv_msg, 0, sizeof(ethernet_recv_msg));
|
||||
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
|
||||
if (!at_adapter)
|
||||
printf("ATAdapterFind failed .\n");
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
struct ping_result result;
|
||||
|
||||
if (!opened){
|
||||
opened = true;
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
}
|
||||
|
||||
if (EOK == at_adapter->atdone.ATOperateUp(at_adapter))
|
||||
printf("EthernetSetUp success (%s)\n", result.ip_addr.ipv4);
|
||||
else
|
||||
printf("EthernetSetUp failed \n");
|
||||
}
|
||||
|
||||
void NetstatEthernet()
|
||||
{
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
|
||||
if (!at_adapter)
|
||||
printf("ATAdapterFind failed .\n");
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
if (!opened){
|
||||
opened = true;
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
}
|
||||
|
||||
if (EOK != at_adapter->atdone.ATNetstat(at_adapter))
|
||||
printf("EthernetNetstat failed \n");
|
||||
}
|
||||
|
||||
void AtTestCmdEthernet(int argc, char *argv[])
|
||||
{
|
||||
char cmd[64];
|
||||
if (argc >= 1){
|
||||
memset(cmd, 0, sizeof(cmd));
|
||||
strncpy(cmd, argv[1], strlen(argv[1]));
|
||||
printf("AT cmd send(%s).\n", cmd);
|
||||
}
|
||||
|
||||
strcat(cmd,"\r");
|
||||
struct AdapterAT* at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
|
||||
|
||||
if (!opened){
|
||||
opened = true;
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
ATOrderSend(at_adapter->agent, REPLY_TIME_OUT, NULL, "+++");
|
||||
UserTaskDelay(100);
|
||||
|
||||
ATOrderSend(at_adapter->agent, REPLY_TIME_OUT, NULL, "a");
|
||||
|
||||
UserTaskDelay(2500);
|
||||
|
||||
ATOrderSend(at_adapter->agent,REPLY_TIME_OUT, NULL,cmd);
|
||||
UserTaskDelay(2500);
|
||||
|
||||
ATOrderSend(at_adapter->agent,REPLY_TIME_OUT, NULL,"AT+Z\r");
|
||||
UserTaskDelay(5000);
|
||||
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES :=wifi_demo.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,179 @@
|
|||
/*
|
||||
* 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 wifi_demo.c
|
||||
* @brief Demo for wifi function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.22
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <user_api.h>
|
||||
#include <xs_adapter_manager.h>
|
||||
#include <xs_adapter_at_wifi.h>
|
||||
|
||||
void SendWiftMsg(int argc, char *argv[])
|
||||
{
|
||||
char wifi_msg[128];
|
||||
if (argc >= 1) {
|
||||
memset(wifi_msg, 0, 128);
|
||||
strncpy(wifi_msg, argv[1], strlen(argv[1]));
|
||||
printf("SendWiftMsg(%s).\n", wifi_msg);
|
||||
}
|
||||
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
if (!at_adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
|
||||
at_adapter->parent.done.NetAiitSend(&at_adapter->parent, wifi_msg, strlen(wifi_msg), true, 1000, 0, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
void RecvWifiMsg()
|
||||
{
|
||||
char wifi_recv_msg[128];
|
||||
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
if (!at_adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
|
||||
while (1) {
|
||||
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
|
||||
if (EOK == at_adapter->parent.done.NetAiitReceive(&at_adapter->parent, wifi_recv_msg, 128, 40000, true, NULL)) {
|
||||
printf("wifi_recv_msg (%s)\n", wifi_recv_msg);
|
||||
} else {
|
||||
printf("wifi_recv_msg failed .\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetAddrWifi()
|
||||
{
|
||||
struct AdapterAT* at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
if (!at_adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
|
||||
if(EOK != at_adapter->atdone.ATOperateAddr(at_adapter, IpTint("10.10.100.222"), IpTint("255.255.255.0"), IpTint("255.255.255.0")))
|
||||
printf("WifiSetAddr failed \n");
|
||||
}
|
||||
|
||||
void DhcpWifi()
|
||||
{
|
||||
struct AdapterAT* at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
if (!at_adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
|
||||
if(EOK != at_adapter->atdone.ATOperateDHCP(at_adapter,1))
|
||||
printf("WifiDHCP failed \n");
|
||||
}
|
||||
|
||||
void PingWifi()
|
||||
{
|
||||
char wifi_recv_msg[128];
|
||||
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
|
||||
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
if (!at_adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
struct ping_result result;
|
||||
//www.baidu.com
|
||||
char *ip_str = "36.152.44.95";
|
||||
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
|
||||
at_adapter->atdone.ATPing(at_adapter, ip_str, &result);
|
||||
}
|
||||
|
||||
void SetUpWifi()
|
||||
{
|
||||
char wifi_recv_msg[128];
|
||||
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
|
||||
|
||||
struct AdapterAT* at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
if (!at_adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
struct ping_result result;
|
||||
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
|
||||
if (EOK == at_adapter->atdone.ATOperateUp(at_adapter)) {
|
||||
printf("WifiSetUp success (%s)\n", result.ip_addr.ipv4);
|
||||
} else {
|
||||
printf("WifiSetUp failed \n");
|
||||
}
|
||||
}
|
||||
|
||||
void NetstatWifi()
|
||||
{
|
||||
struct AdapterAT* at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
if (!at_adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
|
||||
if (EOK != at_adapter->atdone.ATNetstat(at_adapter))
|
||||
printf("WifiNetstat failed \n");
|
||||
}
|
||||
|
||||
void AtTestCmdWifi(int argc, char *argv[])
|
||||
{
|
||||
char cmd[64];
|
||||
if (argc >= 1) {
|
||||
memset(cmd, 0, sizeof(cmd));
|
||||
strncpy(cmd, argv[1], strlen(argv[1]));
|
||||
printf("AT cmd send(%s).\n", cmd);
|
||||
}
|
||||
|
||||
strcat(cmd,"\r");
|
||||
struct AdapterAT* at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
ATOrderSend(at_adapter->agent, REPLY_TIME_OUT, NULL, "+++");
|
||||
UserTaskDelay(100);
|
||||
|
||||
ATOrderSend(at_adapter->agent, REPLY_TIME_OUT, NULL, "a");
|
||||
|
||||
UserTaskDelay(2500);
|
||||
|
||||
ATOrderSend(at_adapter->agent,REPLY_TIME_OUT, NULL,cmd);
|
||||
UserTaskDelay(2500);
|
||||
|
||||
ATOrderSend(at_adapter->agent,REPLY_TIME_OUT, NULL,"AT+Z\r");
|
||||
UserTaskDelay(5000);
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES := zigbee_receive_demo.c
|
||||
# zigbee_send_demo.c zigbee_receive_demo.c
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* 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: zigbee_receive_demo.c
|
||||
* @brief: using zigbee to receive message
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/25
|
||||
*
|
||||
*/
|
||||
#include <xs_adapter_zigbee.h>
|
||||
#include <string.h>
|
||||
#include <xs_klist.h>
|
||||
#include <xs_adapter_manager.h>
|
||||
#include "../applications/user_api/switch_api/user_api.h"
|
||||
static int re_sem;
|
||||
|
||||
static int buff_sem;
|
||||
|
||||
|
||||
/*Critical zone protection function for*/
|
||||
void ZigbeeWait(char *rev_buffer)
|
||||
{
|
||||
while(1){
|
||||
if (strlen(rev_buffer)>1){
|
||||
UserSemaphoreAbandon(re_sem);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* receive message from another zigbee device*/
|
||||
void ZigbeeReceiveDemo(int argc, char *argv[])
|
||||
{
|
||||
adapter_t padapter = ZigbeeAdapterFind("zigbee");
|
||||
if (NONE == padapter){
|
||||
KPrintf("adapter find failed!\n");
|
||||
return;
|
||||
}
|
||||
/*Open adapter*/
|
||||
if (0 != padapter->done.NetAiitOpen(padapter)){
|
||||
KPrintf("adapter open failed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
char rev_buffer[NAME_NUM_MAX];
|
||||
/* Initialize semaphore */
|
||||
re_sem = UserSemaphoreCreate(0);
|
||||
|
||||
padapter->done.NetAiitReceive(padapter,rev_buffer,strlen(rev_buffer),10000,false,NULL);
|
||||
ZigbeeWait(rev_buffer);
|
||||
UserSemaphoreObtain(re_sem,-1);
|
||||
|
||||
|
||||
printf("\n");
|
||||
for (int i=0;i<strlen(rev_buffer);i++)
|
||||
{
|
||||
if(rev_buffer[i] != 0Xff)
|
||||
printf("%c",rev_buffer[i]);
|
||||
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
|
||||
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
ZigbeeReceiveDemo, ZigbeeReceiveDemo, zigbee receive function );
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* 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: zigbee_send_demo.c
|
||||
* @brief: using zigbee to send message
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/25
|
||||
*
|
||||
*/
|
||||
#include <xs_adapter_zigbee.h>
|
||||
#include <string.h>
|
||||
#include <xs_klist.h>
|
||||
#include <xs_adapter_manager.h>
|
||||
|
||||
adapter_t padapter;
|
||||
/* a demo function to send message through command line using zigbee*/
|
||||
|
||||
void ZigbeeOpenDemo()
|
||||
{
|
||||
/*Find from the list of registered adapters*/
|
||||
// adapter_t padapter = ZigbeeAdapterFind("zigbee");
|
||||
padapter = ZigbeeAdapterFind("zigbee");
|
||||
if (NONE == padapter){
|
||||
KPrintf("adapter find failed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/*Open adapter*/
|
||||
if (0 != padapter->done.NetAiitOpen(padapter)){
|
||||
KPrintf("adapter open failed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
ZigbeeOpenDemo, ZigbeeOpenDemo, zigbee send function );
|
||||
|
||||
|
||||
void ZigbeeSendDemo(int argc, char *argv[])
|
||||
{
|
||||
/*Find from the list of registered adapters*/
|
||||
bool v = false;
|
||||
padapter->done.NetAiitSend(padapter, argv[1], strlen(argv[1]) ,true,10000,0, NULL,&v,NULL);
|
||||
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
ZigbeeSendDemo, ZigbeeSendDemo, zigbee send function );
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* 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 <xiuos.h>
|
||||
#include <stdio.h>
|
||||
#include <cstdlib>
|
||||
using namespace std;
|
||||
extern "C" void KPrintf(const char *fmt, ...);
|
||||
|
||||
class Animal //parent class
|
||||
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
virtual void eat()
|
||||
{
|
||||
|
||||
KPrintf("eat\n");
|
||||
|
||||
}
|
||||
|
||||
void sleep()
|
||||
{
|
||||
KPrintf("sleep\n");
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
class Fish :public Animal //subclass
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
void eat()
|
||||
{
|
||||
KPrintf("fish eat\n");
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
void doeat(Animal& animal)
|
||||
{
|
||||
animal.eat();
|
||||
}
|
||||
|
||||
|
||||
void mem_test2()
|
||||
{
|
||||
int i;
|
||||
char *ptr = NULL; /* memory pointer */
|
||||
|
||||
for (i = 0; ; i++)
|
||||
{
|
||||
/* allocate (1<<i) bytes memory every single time */
|
||||
ptr = (char *)operator new(1 << i);
|
||||
|
||||
/* if allocate successfully */
|
||||
if (ptr != NULL)
|
||||
{
|
||||
KPrintf("get memory :%d byte\n", (1 << i));
|
||||
/* release the memory */
|
||||
operator delete(ptr);
|
||||
KPrintf("free memory :%d byte\n", (1 << i));
|
||||
ptr = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
KPrintf("try to get %d byte memory failed!\n", (1 << i));
|
||||
break;
|
||||
//return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void overload_test(int a)
|
||||
{
|
||||
KPrintf("output is a int number: %d\n", a);
|
||||
}
|
||||
void overload_test(int a,int b )
|
||||
{
|
||||
KPrintf("output is 2 int number: %d and %d\n", a,b);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void myswap(T& a, T& b)
|
||||
{
|
||||
T temp = a;
|
||||
a = b;
|
||||
b = temp;
|
||||
}
|
||||
|
||||
extern "C" int cppmain(void)
|
||||
{
|
||||
mem_test2();
|
||||
|
||||
class Fish fish;
|
||||
doeat(fish);
|
||||
|
||||
int a = 3;
|
||||
int b = 5;
|
||||
void overload_test(int a, int b);
|
||||
overload_test(a, b);
|
||||
myswap(a,b);
|
||||
KPrintf("with template the output is: %d and %d\n", a,b);
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
* 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>
|
||||
#include <user_api.h>
|
||||
|
||||
extern int SensorFrameworkInit(void);
|
||||
extern int RegisterAdapterEthernet(void);
|
||||
extern int RegisterAdapterWifi(void);
|
||||
extern int RegisterAdapterZigbee(void);
|
||||
extern int LORA_sx12xx_spi_device_init();
|
||||
|
||||
extern int D124VoiceInit(void);
|
||||
extern int Hs300xTemperatureInit(void);
|
||||
extern int Hs300xHumidityInit(void);
|
||||
extern int Ps5308Pm1_0Init(void);
|
||||
extern int Zg09Co2Init(void);
|
||||
|
||||
typedef int (*InitFunc)(void);
|
||||
struct InitDesc
|
||||
{
|
||||
const char* fn_name;
|
||||
const InitFunc fn;
|
||||
};
|
||||
|
||||
static int AppInitDesc(struct InitDesc sub_desc[])
|
||||
{
|
||||
int i = 0;
|
||||
int ret = 0;
|
||||
for( i = 0; sub_desc[i].fn != NULL; i++ ) {
|
||||
ret = sub_desc[i].fn();
|
||||
printf("initialize %s %s\n",sub_desc[i].fn_name, ret == 0 ? "success" : "failed");
|
||||
if(0 != ret) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct InitDesc framework[] =
|
||||
{
|
||||
#ifdef PERCEPTION_SENSORDEVICE
|
||||
{ "perception_framework", SensorFrameworkInit },
|
||||
#endif
|
||||
|
||||
{ "NULL", NULL },
|
||||
};
|
||||
|
||||
static struct InitDesc perception_desc[] =
|
||||
{
|
||||
#ifdef PERCEPTION_D124
|
||||
{ "d124_voice", D124VoiceInit },
|
||||
#endif
|
||||
|
||||
#ifdef PERCEPTION_HS300X
|
||||
#ifdef SENSOR_QUANTITY_HS300X_TEMPERATURE
|
||||
{ "hs300x_temperature", Hs300xTemperatureInit },
|
||||
#endif
|
||||
#ifdef SENSOR_QUANTITY_HS300X_HUMIDITY
|
||||
{ "hs300x_humidity", Hs300xHumidityInit },
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef PERCEPTION_PS5308
|
||||
#ifdef SENSOR_QUANTITY_PS5308_PM1_0
|
||||
{ "ps5308_pm1_0", Ps5308Pm1_0Init },
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef PERCEPTION_ZG09
|
||||
{ "zg09_co2", Zg09Co2Init },
|
||||
#endif
|
||||
|
||||
{ "NULL", NULL },
|
||||
};
|
||||
|
||||
static struct InitDesc connection_desc[] =
|
||||
{
|
||||
#ifdef CONNECTION_COMMUNICATION_ETHERNET
|
||||
{ "ethernet adpter", RegisterAdapterEthernet },
|
||||
#endif
|
||||
|
||||
#ifdef CONNECTION_COMMUNICATION_WIFI
|
||||
{ "wifi adpter", RegisterAdapterWifi },
|
||||
#endif
|
||||
|
||||
#ifdef CONNECTION_COMMUNICATION_LORA
|
||||
{ "lora adpter", LORA_sx12xx_spi_device_init},
|
||||
#endif
|
||||
|
||||
#ifdef CONNECTION_COMMUNICATION_ZIGBEE
|
||||
{ "zigbee adpter", RegisterAdapterZigbee},
|
||||
#endif
|
||||
{ "NULL", NULL },
|
||||
};
|
||||
|
||||
/**
|
||||
* This function will init perception framework and all sub perception sensors
|
||||
* @param sub_desc framework
|
||||
*
|
||||
*/
|
||||
static int PerceptionFrameworkInit(struct InitDesc sub_desc[])
|
||||
{
|
||||
int i = 0;
|
||||
int ret = 0;
|
||||
for ( i = 0; sub_desc[i].fn != NULL; i++ ) {
|
||||
if (0 == strncmp(sub_desc[i].fn_name, "perception_framework", strlen("perception_framework"))) {
|
||||
ret = sub_desc[i].fn();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == ret) {
|
||||
printf("initialize perception_framework success.\n");
|
||||
AppInitDesc(perception_desc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will init connection framework and all sub components
|
||||
* @param sub_desc framework
|
||||
*
|
||||
*/
|
||||
static int ConnectionFrameworkInit(struct InitDesc sub_desc[])
|
||||
{
|
||||
return AppInitDesc(connection_desc);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will init system framework
|
||||
*
|
||||
*/
|
||||
int FrameworkInit()
|
||||
{
|
||||
#ifdef PERCEPTION_SENSORDEVICE
|
||||
PerceptionFrameworkInit(framework);
|
||||
#endif
|
||||
|
||||
#ifdef CONNECTION_ADAPTER
|
||||
ConnectionFrameworkInit(framework);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* 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 <user_api.h>
|
||||
#include <string.h>
|
||||
|
||||
extern int FrameworkInit();
|
||||
|
||||
#ifdef SEPARATE_COMPILE
|
||||
int main(void)
|
||||
{
|
||||
UserPrintInfo(1);
|
||||
FrameworkInit();
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
||||
int main(void)
|
||||
{
|
||||
UserPrintf("Hello, world!\n");
|
||||
FrameworkInit();
|
||||
return 0;
|
||||
}
|
||||
// int cppmain(void);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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 sd_card_mount.c
|
||||
* @brief Mount SD card when opened SDIO
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.19
|
||||
*/
|
||||
|
||||
#include "user_api/switch_api/user_api.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(FS_VFS)
|
||||
#include <iot-vfs.h>
|
||||
|
||||
/**
|
||||
* @description: Mount SD card
|
||||
* @return 0
|
||||
*/
|
||||
int MountSDCard(void)
|
||||
{
|
||||
if (MountFilesystem(SDIO_BUS_NAME, SDIO_DEVICE_NAME, SDIO_DRIVER_NAME, FSTYPE_FATFS, "/") == 0)
|
||||
DBG("sd card mount to '/'");
|
||||
else
|
||||
SYS_WARN("sd card mount to '/' failed!");
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),MountSDCard, MountSDCard, MountSDCard );
|
|
@ -0,0 +1,23 @@
|
|||
SRC_FILES :=
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_ZG09), y)
|
||||
SRC_FILES += co2_zg09.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308), y)
|
||||
SRC_FILES += pm1_0_ps5308.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_VOICE_D124), y)
|
||||
SRC_FILES += voice_d124.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_HUMIDITY_HS300X), y)
|
||||
SRC_FILES += humidity_hs300x.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_TEMPERATURE_HS300X), y)
|
||||
SRC_FILES += temperature_hs300x.c
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file co2_zg09.c
|
||||
* @brief ZG09 CO2 example
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.23
|
||||
*/
|
||||
|
||||
#include "../user_api/switch_api/user_api.h"
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a CO2
|
||||
* @return 0
|
||||
*/
|
||||
void Co2Zg09(void)
|
||||
{
|
||||
struct SensorQuantity *co2 = SensorQuantityFind(SENSOR_QUANTITY_ZG09_CO2, SENSOR_QUANTITY_CO2);
|
||||
SensorQuantityOpen(co2);
|
||||
printf("CO2 : %d ppm\n", SensorQuantityRead(co2));
|
||||
SensorQuantityClose(co2);
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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 humidity_hs300x.c
|
||||
* @brief HS300x humidity example
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.23
|
||||
*/
|
||||
|
||||
#include "../user_api/switch_api/user_api.h"
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a himidity
|
||||
* @return 0
|
||||
*/
|
||||
void HumiHs300x(void)
|
||||
{
|
||||
struct SensorQuantity *humi = SensorQuantityFind(SENSOR_QUANTITY_HS300X_HUMIDITY, SENSOR_QUANTITY_HUMI);
|
||||
SensorQuantityOpen(humi);
|
||||
int32 humidity = SensorQuantityRead(humi);
|
||||
printf("Humidity : %d.%d %%RH\n", humidity/10, humidity%10);
|
||||
SensorQuantityClose(humi);
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiOS 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 pm1_0_ps5308.c
|
||||
* @brief PS5308 PM1.0 example
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.23
|
||||
*/
|
||||
|
||||
#include "../user_api/switch_api/user_api.h"
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a PM1.0
|
||||
* @return 0
|
||||
*/
|
||||
void Pm1_0Ps5308(void)
|
||||
{
|
||||
struct SensorQuantity *pm1_0 = SensorQuantityFind(SENSOR_QUANTITY_PS5308_PM1_0, SENSOR_QUANTITY_PM);
|
||||
SensorQuantityOpen(pm1_0);
|
||||
UserTaskDelay(2000);
|
||||
printf("PM1.0 : %d ug/m³\n", SensorQuantityRead(pm1_0));
|
||||
SensorQuantityClose(pm1_0);
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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 temperature_hs300x.c
|
||||
* @brief HS300x temperature example
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.23
|
||||
*/
|
||||
|
||||
#include "../user_api/switch_api/user_api.h"
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a temperature
|
||||
* @return 0
|
||||
*/
|
||||
void TempHs300x(void)
|
||||
{
|
||||
struct SensorQuantity *temp = SensorQuantityFind(SENSOR_QUANTITY_HS300X_TEMPERATURE, SENSOR_QUANTITY_TEMP);
|
||||
SensorQuantityOpen(temp);
|
||||
int32 temperature = SensorQuantityRead(temp);
|
||||
if (temperature > 0)
|
||||
printf("Temperature : %d.%d ℃\n", temperature/10, temperature%10);
|
||||
else
|
||||
printf("Temperature : %d.%d ℃\n", temperature/10, -temperature%10);
|
||||
SensorQuantityClose(temp);
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiOS 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 voice_d124.c
|
||||
* @brief D124 voice example
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.23
|
||||
*/
|
||||
|
||||
#include "../user_api/switch_api/user_api.h"
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a voice
|
||||
* @return 0
|
||||
*/
|
||||
void VoiceD124(void)
|
||||
{
|
||||
struct SensorQuantity *voice = SensorQuantityFind(SENSOR_QUANTITY_D124_VOICE, SENSOR_QUANTITY_VOICE);
|
||||
SensorQuantityOpen(voice);
|
||||
UserTaskDelay(2000);
|
||||
uint16 result = SensorQuantityRead(voice);
|
||||
printf("voice : %d.%d dB\n", result/(10*voice->value.decimal_places), result%(10*voice->value.decimal_places));
|
||||
SensorQuantityClose(voice);
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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 spi_sd_card_mount.c
|
||||
* @brief Mount SD card when opened SPI SD card
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.01
|
||||
*/
|
||||
|
||||
#include "user_api/switch_api/user_api.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(FS_VFS)
|
||||
#include <iot-vfs.h>
|
||||
|
||||
/**
|
||||
* @description: Mount SD card
|
||||
* @return 0
|
||||
*/
|
||||
int MountSDCard(void)
|
||||
{
|
||||
struct Bus *spi_bus;
|
||||
spi_bus = BusFind(SPI_BUS_NAME_1);
|
||||
|
||||
if (NONE == SpiSdInit(spi_bus, SPI_1_DEVICE_NAME_0, SPI_1_DRV_NAME, SPI_SD_NAME)) {
|
||||
KPrintf("MountSDCard SpiSdInit error!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (EOK == MountFilesystem(SPI_BUS_NAME_1, SPI_SD_NAME, SPI_1_DRV_NAME, FSTYPE_FATFS, "/"))
|
||||
KPrintf("SPI SD card fatfs mounted\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,2 @@
|
|||
*.h5
|
||||
*.tflite
|
|
@ -0,0 +1,4 @@
|
|||
config USING_TFLITE_MNIST
|
||||
bool "mnist demo app for tflite micro"
|
||||
depends on INTELLIGENT_TFLITE
|
||||
default n
|
|
@ -0,0 +1,8 @@
|
|||
ifeq ($(CONFIG_USING_TFLITE_MNIST),y)
|
||||
SRC_FILES := \
|
||||
mnistapp.cpp \
|
||||
mnistmain.c
|
||||
CPPPATHS += -I.
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,19 @@
|
|||
# MNIST 说明
|
||||
|
||||
## 使用
|
||||
|
||||
tools/mnist-train.py 训练生成 mnist 模型。
|
||||
|
||||
tools/mnist-inference.py 使用 mnist 模型进行推理。
|
||||
|
||||
tools/mnist-c-model.py 将 mnist 模型转换成 C 的数组保存在 model.h 中。
|
||||
|
||||
tools/mnist-c-digit.py 将 mnist 数据集中的某个数字转成数组保存在 digit.h 中。
|
||||
|
||||
## 参考资料
|
||||
|
||||
https://tensorflow.google.cn/lite/performance/post_training_quantization
|
||||
|
||||
https://tensorflow.google.cn/lite/performance/post_training_integer_quant
|
||||
|
||||
https://colab.research.google.com/github/tensorflow/tensorflow/blob/master/tensorflow/lite/micro/examples/hello_world/train/train_hello_world_model.ipynb
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiOS 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.
|
||||
*/
|
||||
const float mnist_digit[] = {
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.33, 0.73, 0.62, 0.59, 0.24, 0.14, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.87, 1.00, 1.00, 1.00, 1.00, 0.95, 0.78, 0.78, 0.78, 0.78, 0.78, 0.78, 0.78, 0.78, 0.67, 0.20, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.26, 0.45, 0.28, 0.45, 0.64, 0.89, 1.00, 0.88, 1.00, 1.00, 1.00, 0.98, 0.90, 1.00, 1.00, 0.55, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.07, 0.26, 0.05, 0.26, 0.26, 0.26, 0.23, 0.08, 0.93, 1.00, 0.42, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.33, 0.99, 0.82, 0.07, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.09, 0.91, 1.00, 0.33, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.51, 1.00, 0.93, 0.17, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.23, 0.98, 1.00, 0.24, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.52, 1.00, 0.73, 0.02, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.04, 0.80, 0.97, 0.23, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.49, 1.00, 0.71, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.29, 0.98, 0.94, 0.22, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.07, 0.87, 1.00, 0.65, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.01, 0.80, 1.00, 0.86, 0.14, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.15, 1.00, 1.00, 0.30, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.12, 0.88, 1.00, 0.45, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.52, 1.00, 1.00, 0.20, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.24, 0.95, 1.00, 1.00, 0.20, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.47, 1.00, 1.00, 0.86, 0.16, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.47, 1.00, 0.81, 0.07, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
|
||||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00
|
||||
};
|
||||
const int mnist_label = 7;
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiOS 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 <xiuos.h>
|
||||
|
||||
#include "tensorflow/lite/micro/all_ops_resolver.h"
|
||||
#include "tensorflow/lite/micro/micro_error_reporter.h"
|
||||
#include "tensorflow/lite/micro/micro_interpreter.h"
|
||||
#include "tensorflow/lite/schema/schema_generated.h"
|
||||
#include "tensorflow/lite/version.h"
|
||||
|
||||
#include "digit.h"
|
||||
#include "model.h"
|
||||
|
||||
namespace {
|
||||
tflite::ErrorReporter* error_reporter = nullptr;
|
||||
const tflite::Model* model = nullptr;
|
||||
tflite::MicroInterpreter* interpreter = nullptr;
|
||||
TfLiteTensor* input = nullptr;
|
||||
TfLiteTensor* output = nullptr;
|
||||
constexpr int kTensorArenaSize = 110 * 1024;
|
||||
//uint8_t *tensor_arena = nullptr;
|
||||
uint8_t tensor_arena[kTensorArenaSize];
|
||||
}
|
||||
|
||||
extern "C" void mnist_app() {
|
||||
tflite::MicroErrorReporter micro_error_reporter;
|
||||
error_reporter = µ_error_reporter;
|
||||
|
||||
model = tflite::GetModel(mnist_model);
|
||||
if (model->version() != TFLITE_SCHEMA_VERSION) {
|
||||
TF_LITE_REPORT_ERROR(error_reporter,
|
||||
"Model provided is schema version %d not equal "
|
||||
"to supported version %d.",
|
||||
model->version(), TFLITE_SCHEMA_VERSION);
|
||||
return;
|
||||
}
|
||||
/*
|
||||
tensor_arena = (uint8_t *)rt_malloc(kTensorArenaSize);
|
||||
if (tensor_arena == nullptr) {
|
||||
TF_LITE_REPORT_ERROR(error_reporter, "malloc for tensor_arena failed");
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
tflite::AllOpsResolver resolver;
|
||||
tflite::MicroInterpreter static_interpreter(
|
||||
model, resolver, tensor_arena, kTensorArenaSize, error_reporter);
|
||||
interpreter = &static_interpreter;
|
||||
|
||||
// Allocate memory from the tensor_arena for the model's tensors.
|
||||
TfLiteStatus allocate_status = interpreter->AllocateTensors();
|
||||
if (allocate_status != kTfLiteOk) {
|
||||
TF_LITE_REPORT_ERROR(error_reporter, "AllocateTensors() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
input = interpreter->input(0);
|
||||
output = interpreter->output(0);
|
||||
|
||||
KPrintf("\n------- Input Digit -------\n");
|
||||
for (int i = 0; i < 28; i++) {
|
||||
for (int j = 0; j < 28; j++) {
|
||||
if (mnist_digit[i*28+j] > 0.3)
|
||||
KPrintf("#");
|
||||
else
|
||||
KPrintf(".");
|
||||
}
|
||||
KPrintf("\n");
|
||||
}
|
||||
|
||||
for (int i = 0; i < 28*28; i++) {
|
||||
input->data.f[i] = mnist_digit[i];
|
||||
}
|
||||
|
||||
TfLiteStatus invoke_status = interpreter->Invoke();
|
||||
if (invoke_status != kTfLiteOk) {
|
||||
TF_LITE_REPORT_ERROR(error_reporter, "Invoke failed on x_val\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Read the predicted y value from the model's output tensor
|
||||
float max = 0.0;
|
||||
int index;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if(output->data.f[i]>max){
|
||||
max = output->data.f[i];
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
|
||||
KPrintf("\n------- Output Result -------\n");
|
||||
KPrintf("result is %d\n\n", index);
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiOS 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 <xiuos.h>
|
||||
|
||||
void mnist_app(void);
|
||||
|
||||
int tfmnist(void) {
|
||||
mnist_app();
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), tfmnist, tfmnist, run mnist demo of tflite);
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,47 @@
|
|||
# ==========================================================================================
|
||||
# Copyright (c) 2020 AIIT XUOS Lab
|
||||
# XiOS 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.
|
||||
# ==========================================================================================
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import tensorflow as tf
|
||||
|
||||
print("TensorFlow version %s" % (tf.__version__))
|
||||
|
||||
def show(image):
|
||||
for i in range(28):
|
||||
for j in range(28):
|
||||
if image[i][j] > 0.3:
|
||||
print('#', end = '')
|
||||
else:
|
||||
print('.', end = '')
|
||||
print()
|
||||
|
||||
digit_file_path = 'digit.h'
|
||||
digit_content = '''const float mnist_digit[] = {
|
||||
%s
|
||||
};
|
||||
const int mnist_label = %d;
|
||||
'''
|
||||
|
||||
if __name__ == '__main__':
|
||||
mnist = tf.keras.datasets.mnist
|
||||
(_, _), (test_images, test_labels) = mnist.load_data()
|
||||
index = 0
|
||||
shape = 28
|
||||
image = test_images[index].astype('float32')/255
|
||||
label = test_labels[index]
|
||||
print('label: %d' % label)
|
||||
#show(image)
|
||||
digit_data = (',\n ').join([ (', ').join([ '%.2f' % image[row][col] for col in range(shape)]) for row in range(shape)])
|
||||
digit_file = open(digit_file_path, 'w')
|
||||
digit_file.write(digit_content % (digit_data, label))
|
||||
digit_file.close()
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
# ==========================================================================================
|
||||
# Copyright (c) 2020 AIIT XUOS Lab
|
||||
# XiOS 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.
|
||||
# ==========================================================================================
|
||||
#!/usr/bin/env python3
|
||||
|
||||
#tflite_file_path = 'mnist-default-quan.tflite'
|
||||
tflite_file_path = 'mnist.tflite'
|
||||
model_file_path = 'model.h'
|
||||
|
||||
tflite_file = open(tflite_file_path, 'rb')
|
||||
tflite_data = tflite_file.read()
|
||||
tflite_file.close()
|
||||
tflite_array = [ '0x%02x' % byte for byte in tflite_data ]
|
||||
|
||||
model_content = '''unsigned char mnist_model[] = {
|
||||
%s
|
||||
};
|
||||
unsigned int mnist_model_len = %d;
|
||||
'''
|
||||
# 12 bytes in a line, the same with xxd
|
||||
bytes_of_line = 12
|
||||
model_data = (',\n ').join([ (', ').join(tflite_array[i:i+bytes_of_line]) for i in range(0, len(tflite_array), bytes_of_line) ])
|
||||
model_file = open(model_file_path, 'w')
|
||||
model_file.write(model_content % (model_data, len(tflite_array)))
|
||||
model_file.close()
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
# ==========================================================================================
|
||||
# Copyright (c) 2020 AIIT XUOS Lab
|
||||
# XiOS 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.
|
||||
# ==========================================================================================
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import tensorflow as tf
|
||||
|
||||
print("TensorFlow version %s" % (tf.__version__))
|
||||
|
||||
MODEL_NAME_H5 = 'mnist.h5'
|
||||
MODEL_NAME_TFLITE = 'mnist.tflite'
|
||||
DEFAULT_QUAN_MODEL_NAME_TFLITE = 'mnist-default-quan.tflite'
|
||||
FULL_QUAN_MODEL_NAME_TFLITE = 'mnist-full-quan.tflite'
|
||||
|
||||
|
||||
def show(image):
|
||||
for i in range(28):
|
||||
for j in range(28):
|
||||
if image[i][j][0] > 0.3:
|
||||
print('#', end = '')
|
||||
else:
|
||||
print(' ', end = '')
|
||||
print()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
mnist = tf.keras.datasets.mnist
|
||||
(_, _), (test_images, test_labels) = mnist.load_data()
|
||||
test_images = test_images.reshape(10000, 28, 28, 1)
|
||||
index = 0
|
||||
input_image = test_images[index].astype('float32')/255
|
||||
target_label = test_labels[index]
|
||||
|
||||
interpreter = tf.lite.Interpreter(model_path = DEFAULT_QUAN_MODEL_NAME_TFLITE)
|
||||
interpreter.allocate_tensors()
|
||||
input_details = interpreter.get_input_details()[0]
|
||||
output_details = interpreter.get_output_details()[0]
|
||||
interpreter.set_tensor(input_details['index'], [input_image])
|
||||
interpreter.invoke()
|
||||
output = interpreter.get_tensor(output_details['index'])[0]
|
||||
|
||||
show(input_image)
|
||||
print('target label: %d, predict label: %d' % (target_label, output.argmax()))
|
|
@ -0,0 +1,120 @@
|
|||
# ==========================================================================================
|
||||
# Copyright (c) 2020 AIIT XUOS Lab
|
||||
# XiOS 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.
|
||||
# ==========================================================================================
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import tensorflow as tf
|
||||
|
||||
print("TensorFlow version %s" % (tf.__version__))
|
||||
|
||||
MODEL_NAME_H5 = 'mnist.h5'
|
||||
MODEL_NAME_TFLITE = 'mnist.tflite'
|
||||
DEFAULT_QUAN_MODEL_NAME_TFLITE = 'mnist-default-quan.tflite'
|
||||
FULL_QUAN_MODEL_NAME_TFLITE = 'mnist-full-quan.tflite'
|
||||
|
||||
def build_model(model_name):
|
||||
print('\n>>> load mnist dataset')
|
||||
mnist = tf.keras.datasets.mnist
|
||||
(train_images, train_labels),(test_images, test_labels) = mnist.load_data()
|
||||
print("train images shape: ", train_images.shape)
|
||||
print("train labels shape: ", train_labels.shape)
|
||||
print("test images shape: ", test_images.shape)
|
||||
print("test labels shape: ", test_labels.shape)
|
||||
|
||||
# transform label to categorical, like: 2 -> [0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
|
||||
print('\n>>> transform label to categorical')
|
||||
train_labels = tf.keras.utils.to_categorical(train_labels)
|
||||
test_labels = tf.keras.utils.to_categorical(test_labels)
|
||||
print("train labels shape: ", train_labels.shape)
|
||||
print("test labels shape: ", test_labels.shape)
|
||||
|
||||
# transform color like: [0, 255] -> 0.xxx
|
||||
print('\n>>> transform image color into float32')
|
||||
train_images = train_images.astype('float32') / 255
|
||||
test_images = test_images.astype('float32') / 255
|
||||
|
||||
# reshape image like: (60000, 28, 28) -> (60000, 28, 28, 1)
|
||||
print('\n>>> reshape image with color channel')
|
||||
train_images = train_images.reshape((60000, 28, 28, 1))
|
||||
test_images = test_images.reshape((10000, 28, 28, 1))
|
||||
print("train images shape: ", train_images.shape)
|
||||
print("test images shape: ", test_images.shape)
|
||||
|
||||
print('\n>>> build model')
|
||||
model = tf.keras.models.Sequential([
|
||||
tf.keras.layers.Conv2D(32, (3, 3), activation=tf.nn.relu, input_shape=(28, 28, 1)),
|
||||
tf.keras.layers.MaxPooling2D((2, 2)),
|
||||
tf.keras.layers.Conv2D(64, (3, 3), activation=tf.nn.relu),
|
||||
tf.keras.layers.MaxPooling2D((2, 2)),
|
||||
tf.keras.layers.Conv2D(64, (3, 3), activation=tf.nn.relu),
|
||||
tf.keras.layers.Flatten(),
|
||||
tf.keras.layers.Dense(64, activation=tf.nn.relu),
|
||||
tf.keras.layers.Dense(10, activation=tf.nn.softmax)
|
||||
])
|
||||
model.compile(optimizer='rmsprop',
|
||||
loss='categorical_crossentropy',
|
||||
metrics=['accuracy'])
|
||||
model.summary()
|
||||
|
||||
print('\n>>> train the model')
|
||||
early_stopping = tf.keras.callbacks.EarlyStopping(
|
||||
monitor='loss', min_delta=0.0005, patience=3, verbose=1, mode='auto',
|
||||
baseline=None, restore_best_weights=True
|
||||
)
|
||||
model.fit(train_images, train_labels, epochs=100, batch_size=64, callbacks=[early_stopping])
|
||||
|
||||
print('\n>>> evaluate the model')
|
||||
test_loss, test_acc = model.evaluate(test_images, test_labels)
|
||||
print("lost: %f, accuracy: %f" % (test_loss, test_acc))
|
||||
|
||||
print('\n>>> save the keras model as %s' % model_name)
|
||||
model.save(model_name)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if not os.path.exists(MODEL_NAME_H5):
|
||||
build_model(MODEL_NAME_H5)
|
||||
|
||||
if not os.path.exists(MODEL_NAME_TFLITE):
|
||||
print('\n>>> save the tflite model as %s' % MODEL_NAME_TFLITE)
|
||||
converter = tf.lite.TFLiteConverter.from_keras_model(tf.keras.models.load_model(MODEL_NAME_H5))
|
||||
tflite_model = converter.convert()
|
||||
with open(MODEL_NAME_TFLITE, "wb") as f:
|
||||
f.write(tflite_model)
|
||||
|
||||
if not os.path.exists(DEFAULT_QUAN_MODEL_NAME_TFLITE):
|
||||
print('\n>>> save the default quantized model as %s' % DEFAULT_QUAN_MODEL_NAME_TFLITE)
|
||||
converter = tf.lite.TFLiteConverter.from_keras_model(tf.keras.models.load_model(MODEL_NAME_H5))
|
||||
converter.optimizations = [tf.lite.Optimize.DEFAULT]
|
||||
tflite_model = converter.convert()
|
||||
with open(DEFAULT_QUAN_MODEL_NAME_TFLITE, "wb") as f:
|
||||
f.write(tflite_model)
|
||||
|
||||
if not os.path.exists(FULL_QUAN_MODEL_NAME_TFLITE):
|
||||
mnist = tf.keras.datasets.mnist
|
||||
(train_images, _), (_, _) = mnist.load_data()
|
||||
train_images = train_images.astype('float32') / 255
|
||||
train_images = train_images.reshape((60000, 28, 28, 1))
|
||||
def representative_data_gen():
|
||||
for input_value in tf.data.Dataset.from_tensor_slices(train_images).batch(1).take(100):
|
||||
yield [input_value]
|
||||
print('\n>>> save the full quantized model as %s' % DEFAULT_QUAN_MODEL_NAME_TFLITE)
|
||||
converter = tf.lite.TFLiteConverter.from_keras_model(tf.keras.models.load_model(MODEL_NAME_H5))
|
||||
converter.optimizations = [tf.lite.Optimize.DEFAULT]
|
||||
converter.representative_dataset = representative_data_gen
|
||||
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
|
||||
converter.inference_input_type = tf.uint8
|
||||
converter.inference_output_type = tf.uint8
|
||||
tflite_model = converter.convert()
|
||||
with open(FULL_QUAN_MODEL_NAME_TFLITE, "wb") as f:
|
||||
f.write(tflite_model)
|
|
@ -0,0 +1,4 @@
|
|||
config USING_TFLITE_SIN
|
||||
bool "sin(x) demo app for tflite micro"
|
||||
depends on INTELLIGENT_TFLITE
|
||||
default n
|
|
@ -0,0 +1,11 @@
|
|||
ifeq ($(CONFIG_USING_TFLITE_SIN),y)
|
||||
SRC_FILES := \
|
||||
sinmain.c \
|
||||
main_functions.cc \
|
||||
model.cc \
|
||||
output_handler.cc \
|
||||
constants.cc
|
||||
CPPPATHS += -I.
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,19 @@
|
|||
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==============================================================================*/
|
||||
|
||||
#include "constants.h"
|
||||
|
||||
// This is a small number so that it's easy to read the logs
|
||||
const int kInferencesPerCycle = 20;
|
|
@ -0,0 +1,32 @@
|
|||
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==============================================================================*/
|
||||
|
||||
#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_CONSTANTS_H_
|
||||
#define TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_CONSTANTS_H_
|
||||
|
||||
// This constant represents the range of x values our model was trained on,
|
||||
// which is from 0 to (2 * Pi). We approximate Pi to avoid requiring additional
|
||||
// libraries.
|
||||
const float kXrange = 2.f * 3.14159265359f;
|
||||
|
||||
// This constant determines the number of inferences to perform across the range
|
||||
// of x values defined above. Since each inference takes time, the higher this
|
||||
// number, the more time it will take to run through the entire range. The value
|
||||
// of this constant can be tuned so that one full cycle takes a desired amount
|
||||
// of time. Since different devices take different amounts of time to perform
|
||||
// inference, this value should be defined per-device.
|
||||
extern const int kInferencesPerCycle;
|
||||
|
||||
#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_CONSTANTS_H_
|
|
@ -0,0 +1,119 @@
|
|||
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==============================================================================*/
|
||||
|
||||
#include "main_functions.h"
|
||||
|
||||
#include "tensorflow/lite/micro/all_ops_resolver.h"
|
||||
#include "constants.h"
|
||||
#include "model.h"
|
||||
#include "output_handler.h"
|
||||
#include "tensorflow/lite/micro/micro_error_reporter.h"
|
||||
#include "tensorflow/lite/micro/micro_interpreter.h"
|
||||
#include "tensorflow/lite/schema/schema_generated.h"
|
||||
#include "tensorflow/lite/version.h"
|
||||
|
||||
// Globals, used for compatibility with Arduino-style sketches.
|
||||
namespace {
|
||||
tflite::ErrorReporter* error_reporter = nullptr;
|
||||
const tflite::Model* model = nullptr;
|
||||
tflite::MicroInterpreter* interpreter = nullptr;
|
||||
TfLiteTensor* input = nullptr;
|
||||
TfLiteTensor* output = nullptr;
|
||||
int inference_count = 0;
|
||||
|
||||
constexpr int kTensorArenaSize = 10240;
|
||||
uint8_t tensor_arena[kTensorArenaSize];
|
||||
} // namespace
|
||||
|
||||
// The name of this function is important for Arduino compatibility.
|
||||
void setup() {
|
||||
// Set up logging. Google style is to avoid globals or statics because of
|
||||
// lifetime uncertainty, but since this has a trivial destructor it's okay.
|
||||
// NOLINTNEXTLINE(runtime-global-variables)
|
||||
static tflite::MicroErrorReporter micro_error_reporter;
|
||||
error_reporter = µ_error_reporter;
|
||||
|
||||
// Map the model into a usable data structure. This doesn't involve any
|
||||
// copying or parsing, it's a very lightweight operation.
|
||||
model = tflite::GetModel(g_model);
|
||||
if (model->version() != TFLITE_SCHEMA_VERSION) {
|
||||
TF_LITE_REPORT_ERROR(error_reporter,
|
||||
"Model provided is schema version %d not equal "
|
||||
"to supported version %d.",
|
||||
model->version(), TFLITE_SCHEMA_VERSION);
|
||||
return;
|
||||
}
|
||||
|
||||
// This pulls in all the operation implementations we need.
|
||||
// NOLINTNEXTLINE(runtime-global-variables)
|
||||
static tflite::AllOpsResolver resolver;
|
||||
|
||||
// Build an interpreter to run the model with.
|
||||
static tflite::MicroInterpreter static_interpreter(
|
||||
model, resolver, tensor_arena, kTensorArenaSize, error_reporter);
|
||||
interpreter = &static_interpreter;
|
||||
|
||||
// Allocate memory from the tensor_arena for the model's tensors.
|
||||
TfLiteStatus allocate_status = interpreter->AllocateTensors();
|
||||
if (allocate_status != kTfLiteOk) {
|
||||
TF_LITE_REPORT_ERROR(error_reporter, "AllocateTensors() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
// Obtain pointers to the model's input and output tensors.
|
||||
input = interpreter->input(0);
|
||||
output = interpreter->output(0);
|
||||
|
||||
// Keep track of how many inferences we have performed.
|
||||
inference_count = 0;
|
||||
}
|
||||
|
||||
// The name of this function is important for Arduino compatibility.
|
||||
void loop() {
|
||||
// Calculate an x value to feed into the model. We compare the current
|
||||
// inference_count to the number of inferences per cycle to determine
|
||||
// our position within the range of possible x values the model was
|
||||
// trained on, and use this to calculate a value.
|
||||
float position = static_cast<float>(inference_count) /
|
||||
static_cast<float>(kInferencesPerCycle);
|
||||
float x = position * kXrange;
|
||||
|
||||
// Quantize the input from floating-point to integer
|
||||
int8_t x_quantized = x / input->params.scale + input->params.zero_point;
|
||||
// Place the quantized input in the model's input tensor
|
||||
input->data.int8[0] = x_quantized;
|
||||
|
||||
// Run inference, and report any error
|
||||
TfLiteStatus invoke_status = interpreter->Invoke();
|
||||
if (invoke_status != kTfLiteOk) {
|
||||
TF_LITE_REPORT_ERROR(error_reporter, "Invoke failed on x: %f\n",
|
||||
static_cast<double>(x));
|
||||
return;
|
||||
}
|
||||
|
||||
// Obtain the quantized output from model's output tensor
|
||||
int8_t y_quantized = output->data.int8[0];
|
||||
// Dequantize the output from integer to floating-point
|
||||
float y = (y_quantized - output->params.zero_point) * output->params.scale;
|
||||
|
||||
// Output the results. A custom HandleOutput function can be implemented
|
||||
// for each supported hardware target.
|
||||
HandleOutput(error_reporter, x, y);
|
||||
|
||||
// Increment the inference_counter, and reset it if we have reached
|
||||
// the total number per cycle
|
||||
inference_count += 1;
|
||||
if (inference_count >= kInferencesPerCycle) inference_count = 0;
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==============================================================================*/
|
||||
|
||||
#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_MAIN_FUNCTIONS_H_
|
||||
#define TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_MAIN_FUNCTIONS_H_
|
||||
|
||||
// Expose a C friendly interface for main functions.
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Initializes all data needed for the example. The name is important, and needs
|
||||
// to be setup() for Arduino compatibility.
|
||||
void setup();
|
||||
|
||||
// Runs one iteration of data gathering and inference. This should be called
|
||||
// repeatedly from the application code. The name needs to be loop() for Arduino
|
||||
// compatibility.
|
||||
void loop();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_MAIN_FUNCTIONS_H_
|
|
@ -0,0 +1,237 @@
|
|||
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==============================================================================*/
|
||||
|
||||
// Automatically created from a TensorFlow Lite flatbuffer using the command:
|
||||
// xxd -i model.tflite > model.cc
|
||||
|
||||
// This is a standard TensorFlow Lite model file that has been converted into a
|
||||
// C data array, so it can be easily compiled into a binary for devices that
|
||||
// don't have a file system.
|
||||
|
||||
// See train/README.md for a full description of the creation process.
|
||||
|
||||
#include "model.h"
|
||||
|
||||
// Keep model aligned to 8 bytes to guarantee aligned 64-bit accesses.
|
||||
alignas(8) const unsigned char g_model[] = {
|
||||
0x1c, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x14, 0x00, 0x20, 0x00,
|
||||
0x1c, 0x00, 0x18, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00,
|
||||
0x08, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
|
||||
0x98, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x1c, 0x03, 0x00, 0x00,
|
||||
0x2c, 0x03, 0x00, 0x00, 0x30, 0x09, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x60, 0xf7, 0xff, 0xff,
|
||||
0x10, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00,
|
||||
0x44, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x73, 0x65, 0x72, 0x76,
|
||||
0x65, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x73, 0x65, 0x72, 0x76,
|
||||
0x69, 0x6e, 0x67, 0x5f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xbc, 0xff, 0xff, 0xff,
|
||||
0x09, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
|
||||
0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x34, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x04, 0x00, 0x00, 0x00, 0x76, 0xfd, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00,
|
||||
0x0d, 0x00, 0x00, 0x00, 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x32, 0x5f,
|
||||
0x69, 0x6e, 0x70, 0x75, 0x74, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00,
|
||||
0x08, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0x13, 0x00, 0x00, 0x00, 0x6d, 0x69, 0x6e, 0x5f, 0x72, 0x75, 0x6e, 0x74,
|
||||
0x69, 0x6d, 0x65, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x00,
|
||||
0x0c, 0x00, 0x00, 0x00, 0x50, 0x02, 0x00, 0x00, 0x48, 0x02, 0x00, 0x00,
|
||||
0x34, 0x02, 0x00, 0x00, 0xdc, 0x01, 0x00, 0x00, 0x8c, 0x01, 0x00, 0x00,
|
||||
0x6c, 0x01, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
|
||||
0x34, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
|
||||
0x04, 0x00, 0x00, 0x00, 0xfa, 0xfd, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00,
|
||||
0x10, 0x00, 0x00, 0x00, 0x31, 0x2e, 0x35, 0x2e, 0x30, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0xfd, 0xff, 0xff,
|
||||
0x88, 0xfd, 0xff, 0xff, 0x8c, 0xfd, 0xff, 0xff, 0x22, 0xfe, 0xff, 0xff,
|
||||
0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x21, 0xa5, 0x8b, 0xca,
|
||||
0x5e, 0x1d, 0xce, 0x42, 0x9d, 0xce, 0x1f, 0xb0, 0xdf, 0x54, 0x2f, 0x81,
|
||||
0x3e, 0xfe, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
|
||||
0xee, 0xfc, 0x00, 0xec, 0x05, 0x17, 0xef, 0xec, 0xe6, 0xf8, 0x03, 0x01,
|
||||
0x00, 0xfa, 0xf8, 0xf5, 0xdc, 0xeb, 0x27, 0x14, 0xf1, 0xde, 0xe2, 0xdb,
|
||||
0xf0, 0xde, 0x31, 0x06, 0x02, 0xe6, 0xee, 0xf9, 0x00, 0x16, 0x07, 0xe0,
|
||||
0xfe, 0xff, 0xe9, 0x06, 0xe7, 0xef, 0x81, 0x1b, 0x18, 0xea, 0xc9, 0x01,
|
||||
0x0f, 0x00, 0xda, 0xf7, 0x0e, 0xec, 0x13, 0x1f, 0x04, 0x13, 0xb4, 0xe6,
|
||||
0xfd, 0x06, 0xb9, 0xe0, 0x0d, 0xec, 0xf0, 0xde, 0xeb, 0xf7, 0x05, 0x26,
|
||||
0x1a, 0xe4, 0x6f, 0x1a, 0xea, 0x1e, 0x35, 0xdf, 0x1a, 0xf3, 0xf1, 0x19,
|
||||
0x0f, 0x03, 0x1b, 0xe1, 0xde, 0x13, 0xf6, 0x19, 0xff, 0xf6, 0x1b, 0x18,
|
||||
0xf0, 0x1c, 0xda, 0x1b, 0x1b, 0x20, 0xe5, 0x1a, 0xf5, 0xff, 0x96, 0x0b,
|
||||
0x00, 0x01, 0xcd, 0xde, 0x0d, 0xf6, 0x16, 0xe3, 0xed, 0xfc, 0x0e, 0xe9,
|
||||
0xfa, 0xeb, 0x5c, 0xfc, 0x1d, 0x02, 0x5b, 0xe2, 0xe1, 0xf5, 0x15, 0xec,
|
||||
0xf4, 0x00, 0x13, 0x05, 0xec, 0x0c, 0x1d, 0x14, 0x0e, 0xe7, 0x0b, 0xf4,
|
||||
0x19, 0x00, 0xd7, 0x05, 0x27, 0x02, 0x15, 0xea, 0xea, 0x02, 0x9b, 0x00,
|
||||
0x0c, 0xfa, 0xe8, 0xea, 0xfd, 0x00, 0x14, 0xfd, 0x0b, 0x02, 0xef, 0xee,
|
||||
0x06, 0xee, 0x01, 0x0d, 0x06, 0xe6, 0xf7, 0x11, 0xf7, 0x09, 0xf8, 0xf1,
|
||||
0x21, 0xff, 0x0e, 0xf3, 0xec, 0x12, 0x26, 0x1d, 0xf2, 0xe9, 0x28, 0x18,
|
||||
0xe0, 0xfb, 0xf3, 0xf4, 0x05, 0x1d, 0x1d, 0xfb, 0xfd, 0x1e, 0xfc, 0x11,
|
||||
0xe8, 0x07, 0x09, 0x03, 0x12, 0xf2, 0x36, 0xfb, 0xdc, 0x1c, 0xf9, 0xef,
|
||||
0xf3, 0xe7, 0x6f, 0x0c, 0x1d, 0x00, 0x45, 0xfd, 0x0e, 0xf0, 0x0b, 0x19,
|
||||
0x1a, 0xfa, 0xe0, 0x19, 0x1f, 0x13, 0x36, 0x1c, 0x12, 0xeb, 0x3b, 0x0c,
|
||||
0xb4, 0xcb, 0xe6, 0x13, 0xfa, 0xeb, 0xf1, 0x06, 0x1c, 0xfa, 0x18, 0xe5,
|
||||
0xeb, 0xcb, 0x0c, 0xf4, 0x4a, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00,
|
||||
0x10, 0x00, 0x00, 0x00, 0x75, 0x1c, 0x11, 0xe1, 0x0c, 0x81, 0xa5, 0x42,
|
||||
0xfe, 0xd5, 0xd4, 0xb2, 0x61, 0x78, 0x19, 0xdf, 0x66, 0xff, 0xff, 0xff,
|
||||
0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0x77, 0x0b, 0x00, 0x00, 0x53, 0xf6, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
|
||||
0x77, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xd3, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x72, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2f, 0x07, 0x00, 0x00,
|
||||
0x67, 0xf5, 0xff, 0xff, 0x34, 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
|
||||
0xb2, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xb5, 0x04, 0x00, 0x00, 0x78, 0x0a, 0x00, 0x00,
|
||||
0x2d, 0x06, 0x00, 0x00, 0x71, 0xf8, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
|
||||
0x9a, 0x0a, 0x00, 0x00, 0xfe, 0xf7, 0xff, 0xff, 0x0e, 0x05, 0x00, 0x00,
|
||||
0xd4, 0x09, 0x00, 0x00, 0x47, 0xfe, 0xff, 0xff, 0xb6, 0x04, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xac, 0xf7, 0xff, 0xff, 0x4b, 0xf9, 0xff, 0xff,
|
||||
0x4a, 0x05, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00,
|
||||
0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0x8c, 0xef, 0xff, 0xff, 0x84, 0xff, 0xff, 0xff, 0x88, 0xff, 0xff, 0xff,
|
||||
0x0f, 0x00, 0x00, 0x00, 0x4d, 0x4c, 0x49, 0x52, 0x20, 0x43, 0x6f, 0x6e,
|
||||
0x76, 0x65, 0x72, 0x74, 0x65, 0x64, 0x2e, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00,
|
||||
0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00,
|
||||
0x14, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0xdc, 0x00, 0x00, 0x00,
|
||||
0xe0, 0x00, 0x00, 0x00, 0xe4, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
|
||||
0x84, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0x96, 0xff, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
|
||||
0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00,
|
||||
0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00,
|
||||
0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0xca, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
|
||||
0xba, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00,
|
||||
0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
|
||||
0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00,
|
||||
0x16, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x04, 0x00,
|
||||
0x0e, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
|
||||
0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00,
|
||||
0x08, 0x00, 0x07, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x4c, 0x04, 0x00, 0x00,
|
||||
0xd0, 0x03, 0x00, 0x00, 0x68, 0x03, 0x00, 0x00, 0x0c, 0x03, 0x00, 0x00,
|
||||
0x98, 0x02, 0x00, 0x00, 0x24, 0x02, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00,
|
||||
0x24, 0x01, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0xf0, 0xfb, 0xff, 0xff, 0x18, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
|
||||
0x54, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09,
|
||||
0x6c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
|
||||
0x01, 0x00, 0x00, 0x00, 0xdc, 0xfb, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00,
|
||||
0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x4a, 0xce, 0x0a, 0x3c, 0x01, 0x00, 0x00, 0x00,
|
||||
0x34, 0x84, 0x85, 0x3f, 0x01, 0x00, 0x00, 0x00, 0xc5, 0x02, 0x8f, 0xbf,
|
||||
0x1e, 0x00, 0x00, 0x00, 0x53, 0x74, 0x61, 0x74, 0x65, 0x66, 0x75, 0x6c,
|
||||
0x50, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x65, 0x64, 0x43,
|
||||
0x61, 0x6c, 0x6c, 0x3a, 0x30, 0x5f, 0x69, 0x6e, 0x74, 0x38, 0x00, 0x00,
|
||||
0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x80, 0xfc, 0xff, 0xff, 0x18, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
|
||||
0x54, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09,
|
||||
0x64, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
|
||||
0x10, 0x00, 0x00, 0x00, 0x6c, 0xfc, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00,
|
||||
0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0x01, 0x00, 0x00, 0x00, 0x93, 0xd0, 0xc0, 0x3b, 0x01, 0x00, 0x00, 0x00,
|
||||
0xc2, 0x0f, 0xc0, 0x3f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x14, 0x00, 0x00, 0x00, 0x74, 0x66, 0x6c, 0x2e, 0x66, 0x75, 0x6c, 0x6c,
|
||||
0x79, 0x5f, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x31,
|
||||
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x10, 0x00, 0x00, 0x00, 0x08, 0xfd, 0xff, 0xff, 0x18, 0x00, 0x00, 0x00,
|
||||
0x20, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x09, 0x64, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
|
||||
0xff, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0xf4, 0xfc, 0xff, 0xff,
|
||||
0x10, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
|
||||
0x24, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0xe0, 0xdb, 0x47, 0x3c, 0x01, 0x00, 0x00, 0x00, 0x04, 0x14, 0x47, 0x40,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
|
||||
0x74, 0x66, 0x6c, 0x2e, 0x66, 0x75, 0x6c, 0x6c, 0x79, 0x5f, 0x63, 0x6f,
|
||||
0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x00, 0x02, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x02, 0xfe, 0xff, 0xff,
|
||||
0x14, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x09, 0x50, 0x00, 0x00, 0x00, 0x6c, 0xfd, 0xff, 0xff,
|
||||
0x10, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
|
||||
0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xfb, 0x4b, 0x0b, 0x3c,
|
||||
0x01, 0x00, 0x00, 0x00, 0x40, 0x84, 0x4b, 0x3f, 0x01, 0x00, 0x00, 0x00,
|
||||
0x63, 0x35, 0x8a, 0xbf, 0x0d, 0x00, 0x00, 0x00, 0x73, 0x74, 0x64, 0x2e,
|
||||
0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x32, 0x00, 0x00, 0x00,
|
||||
0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
|
||||
0x72, 0xfe, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00,
|
||||
0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x50, 0x00, 0x00, 0x00,
|
||||
0xdc, 0xfd, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
|
||||
0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x60, 0x01, 0x4f, 0x3c, 0x01, 0x00, 0x00, 0x00, 0x47, 0x6d, 0xb3, 0x3f,
|
||||
0x01, 0x00, 0x00, 0x00, 0x5d, 0x63, 0xcd, 0xbf, 0x0d, 0x00, 0x00, 0x00,
|
||||
0x73, 0x74, 0x64, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74,
|
||||
0x31, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
|
||||
0x10, 0x00, 0x00, 0x00, 0xe2, 0xfe, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00,
|
||||
0x48, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09,
|
||||
0x50, 0x00, 0x00, 0x00, 0x4c, 0xfe, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00,
|
||||
0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0xd5, 0x6b, 0x8a, 0x3b, 0x01, 0x00, 0x00, 0x00,
|
||||
0xab, 0x49, 0x01, 0x3f, 0x01, 0x00, 0x00, 0x00, 0xfd, 0x56, 0x09, 0xbf,
|
||||
0x0c, 0x00, 0x00, 0x00, 0x73, 0x74, 0x64, 0x2e, 0x63, 0x6f, 0x6e, 0x73,
|
||||
0x74, 0x61, 0x6e, 0x74, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
|
||||
0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x52, 0xff, 0xff, 0xff,
|
||||
0x14, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x02, 0x3c, 0x00, 0x00, 0x00, 0x44, 0xff, 0xff, 0xff,
|
||||
0x08, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x28, 0xb3, 0xd9, 0x38, 0x0c, 0x00, 0x00, 0x00,
|
||||
0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x32, 0x2f, 0x62, 0x69, 0x61, 0x73,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
|
||||
0xaa, 0xff, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00,
|
||||
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x38, 0x00, 0x00, 0x00,
|
||||
0x9c, 0xff, 0xff, 0xff, 0x08, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0xdd, 0x9b, 0x21, 0x39, 0x0c, 0x00, 0x00, 0x00,
|
||||
0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x33, 0x2f, 0x62, 0x69, 0x61, 0x73,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, 0x13, 0x00, 0x0c, 0x00,
|
||||
0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
|
||||
0x40, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
|
||||
0x48, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
|
||||
0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0xf4, 0xd4, 0x51, 0x38, 0x0c, 0x00, 0x00, 0x00, 0x64, 0x65, 0x6e, 0x73,
|
||||
0x65, 0x5f, 0x34, 0x2f, 0x62, 0x69, 0x61, 0x73, 0x00, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x1c, 0x00,
|
||||
0x18, 0x00, 0x17, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
|
||||
0x2c, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x09, 0x84, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
|
||||
0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x14, 0x00,
|
||||
0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00,
|
||||
0x10, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
|
||||
0x24, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x5d, 0x4f, 0xc9, 0x3c, 0x01, 0x00, 0x00, 0x00, 0x0e, 0x86, 0xc8, 0x40,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
|
||||
0x73, 0x65, 0x72, 0x76, 0x69, 0x6e, 0x67, 0x5f, 0x64, 0x65, 0x66, 0x61,
|
||||
0x75, 0x6c, 0x74, 0x5f, 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x32, 0x5f,
|
||||
0x69, 0x6e, 0x70, 0x75, 0x74, 0x3a, 0x30, 0x5f, 0x69, 0x6e, 0x74, 0x38,
|
||||
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
|
||||
0x24, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xd8, 0xff, 0xff, 0xff,
|
||||
0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
|
||||
0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00,
|
||||
0x0c, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72,
|
||||
0x0c, 0x00, 0x10, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00,
|
||||
0x0c, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x09};
|
||||
const int g_model_len = 2488;
|
|
@ -0,0 +1,31 @@
|
|||
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==============================================================================*/
|
||||
|
||||
// Automatically created from a TensorFlow Lite flatbuffer using the command:
|
||||
// xxd -i model.tflite > model.cc
|
||||
|
||||
// This is a standard TensorFlow Lite model file that has been converted into a
|
||||
// C data array, so it can be easily compiled into a binary for devices that
|
||||
// don't have a file system.
|
||||
|
||||
// See train/README.md for a full description of the creation process.
|
||||
|
||||
#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_MODEL_H_
|
||||
#define TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_MODEL_H_
|
||||
|
||||
extern const unsigned char g_model[];
|
||||
extern const int g_model_len;
|
||||
|
||||
#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_MODEL_H_
|
|
@ -0,0 +1,24 @@
|
|||
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==============================================================================*/
|
||||
|
||||
#include "output_handler.h"
|
||||
|
||||
void HandleOutput(tflite::ErrorReporter* error_reporter, float x_value,
|
||||
float y_value) {
|
||||
// Log the current X and Y values
|
||||
TF_LITE_REPORT_ERROR(error_reporter, "x_value: %f, y_value: %f\n",
|
||||
static_cast<double>(x_value),
|
||||
static_cast<double>(y_value));
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==============================================================================*/
|
||||
|
||||
#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_OUTPUT_HANDLER_H_
|
||||
#define TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_OUTPUT_HANDLER_H_
|
||||
|
||||
#include "tensorflow/lite/c/common.h"
|
||||
#include "tensorflow/lite/micro/micro_error_reporter.h"
|
||||
|
||||
// Called by the main loop to produce some output based on the x and y values
|
||||
void HandleOutput(tflite::ErrorReporter* error_reporter, float x_value,
|
||||
float y_value);
|
||||
|
||||
#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_OUTPUT_HANDLER_H_
|
|
@ -0,0 +1,33 @@
|
|||
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==============================================================================*/
|
||||
|
||||
#include <xiuos.h>
|
||||
#include "main_functions.h"
|
||||
|
||||
// This is the default main used on systems that have the standard C entry
|
||||
// point. Other devices (for example FreeRTOS or ESP32) that have different
|
||||
// requirements for entry code (like an app_main function) should specialize
|
||||
// this main.cc file in a target-specific subfolder.
|
||||
int tfsin(void) {
|
||||
setup();
|
||||
int count = 10;
|
||||
while (count--) {
|
||||
loop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), tfsin, tfsin, run sin demo of tflite);
|
|
@ -0,0 +1,12 @@
|
|||
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
|
|
@ -0,0 +1,3 @@
|
|||
SRC_DIR := linklist
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES := double_linklist.c single_linklist.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -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 "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;
|
||||
}
|
|
@ -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 "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;
|
||||
}
|
|
@ -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 "../../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
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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 bus.h
|
||||
* @brief define bus driver framework function and common API
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#ifndef BUS_H
|
||||
#define BUS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define OPE_INT 0x0000
|
||||
#define OPE_CFG 0x0001
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* 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 bus_serial.h
|
||||
* @brief define serial bus and drv function using bus driver framework
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date
|
||||
*/
|
||||
|
||||
#ifndef BUS_SERIAL_H
|
||||
#define BUS_SERIAL_H
|
||||
|
||||
#include <xs_klist.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum ExtSerialPortConfigure
|
||||
{
|
||||
PORT_CFG_INIT = 0,
|
||||
PORT_CFG_PARITY_CHECK,
|
||||
PORT_CFG_DISABLE,
|
||||
PORT_CFG_DIV,
|
||||
};
|
||||
|
||||
struct SerialDataCfg
|
||||
{
|
||||
uint32 serial_baud_rate;
|
||||
uint8 serial_data_bits;
|
||||
uint8 serial_stop_bits;
|
||||
uint8 serial_parity_mode;
|
||||
uint8 serial_bit_order;
|
||||
uint8 serial_invert_mode;
|
||||
uint16 serial_buffer_size;
|
||||
|
||||
uint8 ext_uart_no;
|
||||
enum ExtSerialPortConfigure port_configure;
|
||||
};
|
||||
|
||||
struct SerialHwCfg
|
||||
{
|
||||
uint32 serial_register_base;
|
||||
uint32 serial_irq_interrupt;
|
||||
void *private_data;
|
||||
};
|
||||
|
||||
struct SerialCfgParam
|
||||
{
|
||||
struct SerialDataCfg data_cfg;
|
||||
struct SerialHwCfg hw_cfg;
|
||||
};
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* 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 dev_serial.h
|
||||
* @brief define serial dev function using bus driver framework
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date
|
||||
*/
|
||||
|
||||
#ifndef DEV_SERIAL_H
|
||||
#define DEV_SERIAL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#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
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,4 @@
|
|||
config POSIX_API
|
||||
bool "support posix api"
|
||||
default n
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
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
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* 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: fs.h
|
||||
* @brief: the macor definition of posix fs
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef POSIX_FS_H
|
||||
#define POSIX_FS_H
|
||||
|
||||
// #include "../../switch_api/user_api.h"
|
||||
|
||||
// #define open UserOpen
|
||||
// #define read UserRead
|
||||
// #define write UserWrite
|
||||
// #define close UserClose
|
||||
// #define lseek UserLseek
|
||||
// #define rename UserRename
|
||||
// #define unlink UserUnlink
|
||||
// #define stat UserStat
|
||||
// #define fstat UserFstat
|
||||
// #define fsync UserFsync
|
||||
// #define ftruncate UserFtruncate
|
||||
// #define mkdir UserMkdir
|
||||
// #define opendir UserOpendir
|
||||
// #define closedir UserClosedir
|
||||
// #define readdir UserReaddir
|
||||
// #define rmdir UserRmdir
|
||||
// #define chdir UserChdir
|
||||
// #define getcwd UserGetcwd
|
||||
// #define telldir UserTelldir
|
||||
// #define seekdir UserSeekdir
|
||||
// #define rewinddir UserRewinddir
|
||||
// #define printf UserPrintf
|
||||
|
||||
// #ifdef FS_DFS
|
||||
// #define statfs UserStatfs
|
||||
// #endif
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* 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: msgqueue.h
|
||||
* @brief: the function definition of posix msg queue
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MQUEUE_H
|
||||
#define MQUEUE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "../../switch_api/user_api.h"
|
||||
#include <time.h>
|
||||
|
||||
#define DEFAULT_MQUEUE_SIZE (10 * 1024)
|
||||
#define DEFAULT_MAX_MSG_SIZE (1024)
|
||||
|
||||
typedef int mqd_t;
|
||||
|
||||
struct mq_attr {
|
||||
long mq_flags; /* message queue flags */
|
||||
long mq_maxmsg; /* maximum number of messages */
|
||||
long mq_msgsize; /* maximum message size */
|
||||
long mq_curmsgs; /* number of messages currently queued */
|
||||
};
|
||||
|
||||
mqd_t mq_open(const char *name, int oflag, ...);
|
||||
int mq_close(mqd_t mqdes);
|
||||
ssize_t mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio);
|
||||
int mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio);
|
||||
int mq_setattr(mqd_t mqdes, const struct mq_attr *mqstat, struct mq_attr *omqstat);
|
||||
int mq_getattr(mqd_t mqdes, struct mq_attr *mqstat);
|
||||
ssize_t mq_timedreceive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio, const struct timespec *abs_timeout);
|
||||
int mq_timedsend(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio, const struct timespec *abs_timeout);
|
||||
int mq_unlink(const char *name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* 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: pthread_arm.h
|
||||
* @brief: the attribute definition of posix pthread for arm
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PTHREAD_ARM_H
|
||||
#define PTHREAD_ARM_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
typedef int pid_t;
|
||||
typedef unsigned long int pthread_t;
|
||||
|
||||
struct sched_param {
|
||||
int sched_priority; /* process execution scheduling priority */
|
||||
size_t slice; /* time slice in SCHED_RR mode (ms) */
|
||||
};
|
||||
typedef struct pthread_attr {
|
||||
unsigned char is_initialized; /* if the attr is initialized set to 1, otherwise set to 0 */
|
||||
void *stackaddr; /* the start addr of the stack of the pthead */
|
||||
size_t stacksize; /* the size of the stack of the pthead */
|
||||
unsigned char contentionscope; /* the scope of contention, only PTHREAD_SCOPE_SYSTEM is supported */
|
||||
unsigned char inheritsched; /* when set to PTHREAD_INHERIT_SCHED, specifies that the thread scheduling attributes
|
||||
shall be inherited from the creating thread, and the scheduling attributes in this
|
||||
attr argument shall be ignored */
|
||||
unsigned char schedpolicy; /* the sched policy of the thread */
|
||||
struct sched_param schedparam; /* the parameter of the thread scheduling */
|
||||
size_t guardsize; /* guardsize is set to protect the stack, not supported */
|
||||
unsigned char detachstate; /* when set to PTHREAD_CREATE_JOINABLE, thread will not end untill the creating thread end */
|
||||
} pthread_attr_t;
|
||||
|
||||
typedef struct pthread_mutexattr {
|
||||
int is_initialized;
|
||||
int type;
|
||||
int protocol;
|
||||
int prioceiling;
|
||||
int pshared;
|
||||
} pthread_mutexattr_t;
|
||||
|
||||
typedef int pthread_mutex_t ;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* PTHREAD_H */
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* 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: pthread.h
|
||||
* @brief: the attribute definition of posix pthread
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PTHREAD_H
|
||||
#define PTHREAD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "../../switch_api/user_api.h"
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#if defined(ARCH_ARM)
|
||||
#include "pthread arm.h"
|
||||
#endif
|
||||
|
||||
// enum {
|
||||
// PTHREAD_BARRIER_SERIAL_THREAD,
|
||||
// PTHREAD_CANCEL_ASYNCHRONOUS,
|
||||
// PTHREAD_CANCEL_ENABLE,
|
||||
// PTHREAD_CANCEL_DEFERRED,
|
||||
// PTHREAD_CANCEL_DISABLE,
|
||||
// PTHREAD_CANCELED,
|
||||
// PTHREAD_CREATE_DETACHED,
|
||||
// PTHREAD_CREATE_JOINABLE,
|
||||
// PTHREAD_EXPLICIT_SCHED,
|
||||
// PTHREAD_INHERIT_SCHED,
|
||||
// PTHREAD_MUTEX_DEFAULT,
|
||||
// PTHREAD_MUTEX_ERRORCHECK,
|
||||
// PTHREAD_MUTEX_NORMAL,
|
||||
// PTHREAD_MUTEX_RECURSIVE,
|
||||
// PTHREAD_MUTEX_ROBUST,
|
||||
// PTHREAD_MUTEX_STALLED,
|
||||
// PTHREAD_ONCE_INIT,
|
||||
// PTHREAD_PRIO_INHERIT,
|
||||
// PTHREAD_PRIO_NONE,
|
||||
// PTHREAD_PRIO_PROTECT,
|
||||
// PTHREAD_PROCESS_SHARED,
|
||||
// PTHREAD_PROCESS_PRIVATE,
|
||||
// PTHREAD_SCOPE_PROCESS,
|
||||
// PTHREAD_SCOPE_SYSTEM,
|
||||
// };
|
||||
|
||||
typedef int pid_t;
|
||||
|
||||
/* function in pthread.c */
|
||||
int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void));
|
||||
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
||||
void *(*start_routine)(void *), void *arg);
|
||||
void pthread_exit(void *value_ptr);
|
||||
int pthread_detach(pthread_t thread);
|
||||
int pthread_join(pthread_t thread, void **retval);
|
||||
int pthread_cancel(pthread_t thread);
|
||||
void pthread_testcancel(void);
|
||||
int pthread_setcancelstate(int state, int *oldstate);
|
||||
int pthread_setcanceltype(int type, int *oldtype);
|
||||
int pthread_kill(pthread_t thread, int sig);
|
||||
int pthread_equal(pthread_t t1, pthread_t t2);
|
||||
int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *pParam);
|
||||
void pthread_cleanup_pop(int execute);
|
||||
void pthread_cleanup_push(void (*routine)(void *), void *arg);
|
||||
pthread_t pthread_self(void);
|
||||
int pthread_getcpuclockid(pthread_t thread_id, clockid_t *clock_id);
|
||||
int pthread_setconcurrency(int new_level);
|
||||
int pthread_getconcurrency(void);
|
||||
int pthread_setschedprio(pthread_t thread, int prio);
|
||||
int pthread_setname_np(pthread_t thread, const char *name);
|
||||
int pthread_timedjoin_np(pthread_t thread, void **retval, const struct timespec *abstime);
|
||||
|
||||
/* function in pthread_mutex.c */
|
||||
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr);
|
||||
int pthread_mutex_destroy(pthread_mutex_t *mutex);
|
||||
int pthread_mutex_lock(pthread_mutex_t *mutex);
|
||||
int pthread_mutex_unlock(pthread_mutex_t *mutex);
|
||||
int pthread_mutex_trylock(pthread_mutex_t *mutex);
|
||||
|
||||
int pthread_mutexattr_init(pthread_mutexattr_t *attr);
|
||||
int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
|
||||
int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type);
|
||||
int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
|
||||
int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared);
|
||||
int pthread_mutexattr_getpshared(pthread_mutexattr_t *attr, int *pshared);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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: semaphore.h
|
||||
* @brief: the functions definition of posix semaphore
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SEMAPHORE_H
|
||||
#define SEMAPHORE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../../switch_api/user_api.h"
|
||||
#include <time.h>
|
||||
|
||||
typedef int sem_t;
|
||||
|
||||
int sem_init(sem_t *sem, int pshared, unsigned int value);
|
||||
sem_t *sem_open(const char *name, int oflag, ...);
|
||||
int sem_post(sem_t *sem);
|
||||
int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout);
|
||||
int sem_trywait(sem_t *sem);
|
||||
int sem_unlink(const char *name);
|
||||
int sem_wait(sem_t *sem);
|
||||
int sem_getvalue(sem_t *sem, int *sval);
|
||||
int sem_close(sem_t *sem);
|
||||
int sem_destroy(sem_t *sem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* SEMAPHORE_H */
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* 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: mqueue.c
|
||||
* @brief: posix api of mqueue
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#include "include/mqueue.h"
|
||||
|
||||
mqd_t mq_open(const char *name, int oflag, ...)
|
||||
{
|
||||
|
||||
mqd_t mq;
|
||||
|
||||
mq = UserMsgQueueCreate( DEFAULT_MQUEUE_SIZE, DEFAULT_MAX_MSG_SIZE);
|
||||
if (mq < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return mq;
|
||||
}
|
||||
|
||||
int mq_close(mqd_t mqdes)
|
||||
{
|
||||
return UserMsgQueueDelete(mqdes);
|
||||
}
|
||||
|
||||
ssize_t mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
*msg_prio = 0;
|
||||
ret = UserMsgQueueRecv(mqdes, msg_ptr, (unsigned long)&msg_len, 0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio)
|
||||
{
|
||||
int ret;
|
||||
ret = UserMsgQueueSend(mqdes, (void *)msg_ptr, msg_len);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int mq_setattr(mqd_t mqdes, const struct mq_attr *mqstat, struct mq_attr *omqstat)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mq_getattr(mqd_t mqdes, struct mq_attr *mqstat)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t mq_timedreceive(mqd_t mqdes, char *msg_ptr, size_t msg_len,
|
||||
unsigned *msg_prio, const struct timespec *abstime)
|
||||
{
|
||||
ssize_t ret;
|
||||
int ticks;
|
||||
|
||||
*msg_prio = 0;
|
||||
ticks = abstime->tv_sec * 1000 +
|
||||
(abstime->tv_nsec / 1000000 ) ;
|
||||
|
||||
ret = UserMsgQueueRecv(mqdes, msg_ptr, msg_len, ticks);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int mq_timedsend(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
|
||||
unsigned msg_prio, const struct timespec *abstime)
|
||||
{
|
||||
int ret;
|
||||
int ticks;
|
||||
ticks = abstime->tv_sec * 1000 +
|
||||
(abstime->tv_nsec / 1000000 ) ;
|
||||
|
||||
ret = UserMsgQueueSendwait(mqdes, (void *)msg_ptr, msg_len, ticks);
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* 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: pthread.c
|
||||
* @brief: posix api of pthread
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#include "include/pthread.h"
|
||||
|
||||
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
||||
void *(*start_routine)(void *), void *arg)
|
||||
{
|
||||
int ret ;
|
||||
int pid ;
|
||||
utask_x task ;
|
||||
task.func_entry = start_routine ;
|
||||
task.func_param = arg ;
|
||||
memcpy(task.name , "utask", 6);
|
||||
task.prio = 20 ;
|
||||
task.stack_size = 1024 ;
|
||||
|
||||
pid = UserTaskCreate(task);
|
||||
if (pid < 0)
|
||||
return -1 ;
|
||||
|
||||
ret = UserTaskStartup(pid);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
void pthread_exit(void *value_ptr){
|
||||
//todo add exit value
|
||||
UserTaskQuit();
|
||||
}
|
||||
|
||||
pthread_t pthread_self(void){
|
||||
|
||||
pthread_t pthread ;
|
||||
pthread = UserGetTaskID();
|
||||
return pthread;
|
||||
}
|
||||
|
||||
int pthread_setschedprio(pthread_t thread, int prio)
|
||||
{
|
||||
//add syscall
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_equal(pthread_t t1, pthread_t t2)
|
||||
{
|
||||
return (int)(t1 == t2);
|
||||
}
|
||||
|
||||
int pthread_cancel(pthread_t thread)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
void pthread_testcancel(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int pthread_setcancelstate(int state, int *oldstate)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pthread_setcanceltype(int type, int *oldtype)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pthread_kill(pthread_t thread, int sig)
|
||||
{
|
||||
/* This api should not be used, and will not be supported */
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* 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: pthread_mutex.c
|
||||
* @brief: posix api of mutex
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
#include "include/pthread.h"
|
||||
|
||||
int pthread_mutex_init(pthread_mutex_t *p_mutex, const pthread_mutexattr_t *attr)
|
||||
{
|
||||
*p_mutex = UserMutexCreate();
|
||||
if (*p_mutex < 0) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_mutex_destroy(pthread_mutex_t *p_mutex)
|
||||
{
|
||||
UserMutexDelete(*p_mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_mutex_lock(pthread_mutex_t *p_mutex)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
|
||||
ret = UserMutexObtain(*p_mutex, WAITING_FOREVER);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pthread_mutex_unlock(pthread_mutex_t *p_mutex)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
ret = UserMutexAbandon( *p_mutex );
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pthread_mutex_trylock(pthread_mutex_t *p_mutex)
|
||||
{
|
||||
int ret = -1;
|
||||
ret = UserMutexObtain( *p_mutex , 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pthread_mutexattr_init(pthread_mutexattr_t *attr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *restrict attr, int *restrict protocol)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_mutex_getprioceiling(const pthread_mutex_t *restrict mutex, int *restrict prioceiling)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_mutex_setprioceiling(pthread_mutex_t *restrict mutex, int prioceiling, int *restrict old_ceiling)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *restrict attr, int *restrict prioceiling)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr, int prioceiling)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_mutexattr_getpshared(pthread_mutexattr_t *attr, int *pshared)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* 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: semaphore.c
|
||||
* @brief: posix api of semphore
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#include "include/semaphore.h"
|
||||
#include <time.h>
|
||||
|
||||
int sem_init(sem_t *sem, int pshared, unsigned int value)
|
||||
{
|
||||
int32 ret = 0;
|
||||
ret = UserSemaphoreCreate(value);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sem_t *sem_open(const char *name, int oflag, ...)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sem_post(sem_t *sem)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = UserSemaphoreAbandon(*sem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sem_timedwait(sem_t *sem, const struct timespec *abstime)
|
||||
{
|
||||
int ret ;
|
||||
int ticks = -1 ;
|
||||
|
||||
if (abstime != NULL) {
|
||||
ticks = abstime->tv_sec * 1000 +
|
||||
(abstime->tv_nsec / 1000000 ) ;
|
||||
}
|
||||
|
||||
ret = UserSemaphoreObtain(*sem, ticks);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sem_trywait(sem_t *sem)
|
||||
{
|
||||
int ret ;
|
||||
ret = KSemaphoreObtain(*sem, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sem_unlink(const char *name)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sem_wait(sem_t *sem)
|
||||
{
|
||||
int ret ;
|
||||
ret = KSemaphoreObtain(*sem, -1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sem_getvalue(sem_t *sem, int *sval)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sem_close(sem_t *sem)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sem_destroy(sem_t *sem)
|
||||
{
|
||||
UserSemaphoreDelete(*sem);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
ifeq ($(CONFIG_SEPARATE_COMPILE),y)
|
||||
SRC_FILES :=user_print_info.c user_task.c user_mem.c
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_SEMAPHORE),y)
|
||||
SRC_FILES += user_semaphore.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_MUTEX),y)
|
||||
SRC_FILES += user_mutex.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_EVENT),y)
|
||||
SRC_FILES += user_event.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_KERNEL_MESSAGEQUEUE),y)
|
||||
SRC_FILES += user_msg.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_FS_VFS),y)
|
||||
SRC_FILES += user_fs.c
|
||||
endif
|
||||
else
|
||||
SRC_FILES :=
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,247 @@
|
|||
/*
|
||||
* 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: user_api.h
|
||||
* @brief: the priviate user api for application
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#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>
|
||||
|
||||
|
||||
#ifdef SEPARATE_COMPILE
|
||||
|
||||
#define TASK_INFO 1
|
||||
#define MEM_INFO 2
|
||||
#define SEM_INFO 3
|
||||
#define EVENT_INFO 4
|
||||
#define MUTEX_INFO 5
|
||||
#define MEMPOOL_INFO 6
|
||||
#define MSGQUEUE_INFO 7
|
||||
#define DEVICE_INFO 8
|
||||
#define TIMER_INFO 9
|
||||
|
||||
int UserPrintInfo(unsigned long i);
|
||||
|
||||
struct utask
|
||||
{
|
||||
char name[NAME_NUM_MAX];
|
||||
void *func_entry;
|
||||
void *func_param;
|
||||
int32_t stack_size;
|
||||
uint8_t prio;
|
||||
};
|
||||
typedef struct utask utask_x;
|
||||
|
||||
typedef void DIR;
|
||||
|
||||
int32_t UserTaskCreate(utask_x utask);
|
||||
|
||||
x_err_t UserTaskStartup(int32_t id);
|
||||
x_err_t UserTaskDelete(int32_t id);
|
||||
void UserTaskQuit(void);
|
||||
x_err_t UserTaskDelay(int32_t ms);
|
||||
x_err_t UserGetTaskName(int32_t id ,char *name);
|
||||
int32_t UserGetTaskID(void);
|
||||
uint8_t UserGetTaskStat(int32_t id);
|
||||
|
||||
#ifdef ARCH_SMP
|
||||
x_err_t UserTaskCoreCombine(int32_t id,uint8_t core_id);
|
||||
x_err_t UserTaskCoreUnCombine(int32_t id);
|
||||
uint8_t UserGetTaskCombinedCore(int32_t id);
|
||||
uint8_t UserGetTaskRunningCore(int32_t id);
|
||||
#endif
|
||||
|
||||
x_err_t UserGetTaskErrorstatus(int32_t id);
|
||||
uint8_t UserGetTaskPriority(int32_t id);
|
||||
|
||||
|
||||
void *UserMalloc(size_t size);
|
||||
void *UserRealloc(void *pointer, size_t size);
|
||||
void *UserCalloc(size_t count, size_t size);
|
||||
void UserFree(void *pointer);
|
||||
|
||||
#ifdef KERNEL_MUTEX
|
||||
int32_t UserMutexCreate();
|
||||
void UserMutexDelete(int32_t mutex);
|
||||
int32_t UserMutexObtain(int32_t mutex, int32_t wait_time);
|
||||
int32_t UserMutexAbandon(int32_t mutex);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef KERNEL_SEMAPHORE
|
||||
typedef int32 sem_t;
|
||||
sem_t UserSemaphoreCreate(uint16_t val);
|
||||
x_err_t UserSemaphoreDelete(sem_t sem);
|
||||
x_err_t UserSemaphoreObtain(sem_t sem, int32_t wait_time);
|
||||
x_err_t UserSemaphoreAbandon(sem_t sem);
|
||||
x_err_t UserSemaphoreSetValue(sem_t sem, uint16_t val);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef KERNEL_EVENT
|
||||
typedef int32 EventIdType;
|
||||
EventIdType UserEventCreate(uint8_t flag);
|
||||
void UserEventDelete(EventIdType event);
|
||||
x_err_t UserEventTrigger(EventIdType event, uint32_t set);
|
||||
x_err_t UserEventProcess(EventIdType event, uint32_t set, uint8_t option,
|
||||
int32_t wait_time, uint32_t *Recved);
|
||||
x_err_t UserEventReinit(EventIdType event);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef KERNEL_MESSAGEQUEUE
|
||||
int32_t UserMsgQueueCreate(size_t msg_size, size_t max_msgs);
|
||||
x_err_t UserMsgQueueDelete(int32_t mq );
|
||||
x_err_t UserMsgQueueSendwait(int32_t mq, const void *buffer,
|
||||
size_t size, int32_t wait_time);
|
||||
x_err_t UserMsgQueueSend(int32_t mq, const void *buffer, size_t size);
|
||||
x_err_t UserMsgQueueUrgentSend(int32_t mq, const void *buffer, size_t size);
|
||||
x_err_t UserMsgQueueRecv(int32_t mq, void *buffer, size_t size,int32_t wait_time);
|
||||
x_err_t UserMsgQueueReinit(int32_t mq);
|
||||
#endif
|
||||
|
||||
int open(const char *path, int flags, ...);
|
||||
int read(int fd, void *buf, size_t len);
|
||||
int write(int fd, const void *buf, size_t len);
|
||||
int close(int fd);
|
||||
int ioctl(int fd, int cmd, void *args);
|
||||
off_t lseek(int fd, off_t offset, int whence);
|
||||
int rename(const char *from, const char *to);
|
||||
int unlink(const char *path);
|
||||
int stat(const char *path, struct stat *buf);
|
||||
int fstat(int fd, struct stat *buf);
|
||||
int fsync(int fd);
|
||||
int ftruncate(int fd, off_t length);
|
||||
|
||||
int mkdir(const char *path, mode_t mode);
|
||||
DIR *opendir(const char *path);
|
||||
int closedir(DIR *dirp);
|
||||
struct dirent *readdir(DIR *dirp);
|
||||
int rmdir(const char *path);
|
||||
int chdir(const char *path);
|
||||
char *getcwd(char *buf, size_t size);
|
||||
long telldir(DIR *dirp);
|
||||
void seekdir(DIR *dirp, off_t offset);
|
||||
void rewinddir(DIR *dirp);
|
||||
|
||||
#ifdef FS_VFS
|
||||
struct statfs {
|
||||
size_t f_bsize;
|
||||
size_t f_blocks;
|
||||
size_t f_bfree;
|
||||
};
|
||||
|
||||
int statfs(const char *path, struct statfs *buf);
|
||||
#endif
|
||||
|
||||
void Userprintf(const char *fmt, ...);
|
||||
|
||||
#define printf Userprintf
|
||||
|
||||
#else
|
||||
|
||||
#ifdef FS_VFS
|
||||
#include <iot-vfs_posix.h>
|
||||
#endif
|
||||
|
||||
struct utask
|
||||
{
|
||||
char name[NAME_NUM_MAX];
|
||||
void *func_entry;
|
||||
void *func_param;
|
||||
int32_t stack_size;
|
||||
uint8_t prio;
|
||||
};
|
||||
typedef struct utask utask_x;
|
||||
int32_t UserTaskCreate(utask_x utask);
|
||||
|
||||
#define UserTaskStartup StartupKTask
|
||||
#define UserTaskDelete KTaskDelete
|
||||
#define UserTaskQuit KTaskQuit
|
||||
#define UserTaskDelay MdelayKTask
|
||||
|
||||
x_err_t UserGetTaskName(int32_t id ,char *name);
|
||||
int32_t UserGetTaskID(void);
|
||||
uint8_t UserGetTaskStat(int32_t id);
|
||||
|
||||
#ifdef ARCH_SMP
|
||||
#define UserTaskCoreCombine KTaskCoreCombine
|
||||
#define UserTaskCoreUnCombine KTaskCoreUnCombine
|
||||
|
||||
uint8_t UserGetTaskCombinedCore(int32_t id);
|
||||
uint8_t UserGetTaskRunningCore(int32_t id);
|
||||
#endif
|
||||
|
||||
x_err_t UserGetTaskErrorstatus(int32_t id);
|
||||
uint8_t UserGetTaskPriority(int32_t id);
|
||||
|
||||
#define UserMalloc x_malloc
|
||||
#define UserRealloc x_realloc
|
||||
#define UserCalloc x_calloc
|
||||
#define UserFree x_free
|
||||
|
||||
#ifdef KERNEL_MUTEX
|
||||
#define UserMutexCreate KMutexCreate
|
||||
#define UserMutexDelete KMutexDelete
|
||||
#define UserMutexObtain KMutexObtain
|
||||
#define UserMutexAbandon KMutexAbandon
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef KERNEL_SEMAPHORE
|
||||
#define UserSemaphoreCreate KSemaphoreCreate
|
||||
#define UserSemaphoreDelete KSemaphoreDelete
|
||||
#define UserSemaphoreObtain KSemaphoreObtain
|
||||
#define UserSemaphoreAbandon KSemaphoreAbandon
|
||||
#define UserSemaphoreSetValue KSemaphoreSetValue
|
||||
#endif
|
||||
|
||||
#ifdef KERNEL_EVENT
|
||||
#define UserEventCreate KEventCreate
|
||||
#define UserEventDelete KEventDelete
|
||||
#define UserEventTrigger KEventTrigger
|
||||
#define UserEventProcess KEventProcess
|
||||
#endif
|
||||
|
||||
#ifdef KERNEL_MESSAGEQUEUE
|
||||
#define UserMsgQueueCreate KCreateMsgQueue
|
||||
#define UserMsgQueueDelete KDeleteMsgQueue
|
||||
#define UserMsgQueueSendwait KMsgQueueSendwait
|
||||
#define UserMsgQueueSend KMsgQueueSend
|
||||
#define UserMsgQueueUrgentSend KMsgQueueUrgentSend
|
||||
#define UserMsgQueueRecv KMsgQueueRecv
|
||||
#define UserMsgQueueReinit KMsgQueueReinit
|
||||
#endif
|
||||
|
||||
#define UserPrintf KPrintf
|
||||
#define printf KPrintf
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* 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: user_event.c
|
||||
* @brief: the priviate user api of event for application
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#include "user_api.h"
|
||||
|
||||
/**
|
||||
* This function will create a event.
|
||||
*
|
||||
* @param flag the trigger way of event.
|
||||
*
|
||||
* @return id
|
||||
*/
|
||||
EventIdType UserEventCreate(uint8_t flag){
|
||||
return (EventIdType)KSwitch1(KS_USER_EVENT_CREATE,(uintptr_t)flag );
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will delete a event.
|
||||
*
|
||||
* @param event the id number of event.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
void UserEventDelete(EventIdType event){
|
||||
KSwitch1(KS_USER_EVENT_DELETE,(uintptr_t)event);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will trigger the event
|
||||
*
|
||||
* @param event the id number of event
|
||||
* @param set trigger way & events flag
|
||||
*
|
||||
* @return EOK on success.
|
||||
*/
|
||||
x_err_t UserEventTrigger(EventIdType event, uint32_t set){
|
||||
return (x_err_t)KSwitch2(KS_USER_EVENT_TRIGGER,(uintptr_t)event, (uintptr_t)set );
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will get the event and process this event
|
||||
*
|
||||
* @param event the id number of event
|
||||
* @param set events flag
|
||||
* @param option trigger way
|
||||
* @param wait_time timeout
|
||||
* @param Recved event processed flag
|
||||
*
|
||||
* @return EOK on success.
|
||||
*/
|
||||
x_err_t UserEventProcess(EventIdType event, uint32_t set, uint8_t option,
|
||||
int32_t wait_time, uint32_t *Recved){
|
||||
return (x_err_t)KSwitch5(KS_USER_EVENT_PROCESS,(uintptr_t)event, (uintptr_t)set, (uintptr_t)option, (uintptr_t)wait_time, (uintptr_t)Recved);
|
||||
}
|
||||
|
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* 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: user_fs.c
|
||||
* @brief: the priviate user api of fs for application
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#include "user_api.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
#define stdio 1
|
||||
#define CONSOLEBUF_SIZE 128
|
||||
|
||||
int open(const char *path, int flags, ...){
|
||||
va_list ap;
|
||||
mode_t mode;
|
||||
|
||||
va_start(ap, flags);
|
||||
mode = va_arg(ap, mode_t);
|
||||
va_end(ap);
|
||||
return (int)(KSwitch3(KS_USER_OPEN,(uintptr_t)path,(uintptr_t)flags,(uintptr_t)mode));
|
||||
}
|
||||
|
||||
int read(int fd, void *buf, size_t len){
|
||||
return (int)(KSwitch3(KS_USER_READ,(uintptr_t)fd,(uintptr_t)buf,(uintptr_t)len));
|
||||
}
|
||||
|
||||
int write(int fd, const void *buf, size_t len){
|
||||
return (int)(KSwitch3(KS_USER_WRITE,(uintptr_t)fd,(uintptr_t)buf,(uintptr_t)len));
|
||||
}
|
||||
|
||||
int close(int fd){
|
||||
return (int)(KSwitch1(KS_USER_CLOSE,(uintptr_t)fd));
|
||||
}
|
||||
|
||||
int ioctl(int fd, int cmd, void *args){
|
||||
return (int)(KSwitch3(KS_USER_IOCTL,(uintptr_t)fd,(uintptr_t)cmd,(uintptr_t)args));
|
||||
}
|
||||
|
||||
off_t lseek(int fd, off_t offset, int whence){
|
||||
return (off_t)(KSwitch3(KS_USER_LSEEK,(uintptr_t)fd,(uintptr_t)offset,(uintptr_t)whence));
|
||||
}
|
||||
|
||||
int rename(const char *from, const char *to){
|
||||
return (int)(KSwitch2(KS_USER_RENAME,(uintptr_t)from,(uintptr_t)to));
|
||||
}
|
||||
|
||||
int unlink(const char *path){
|
||||
return (int)(KSwitch1(KS_USER_UNLINK,(uintptr_t)path));
|
||||
}
|
||||
|
||||
int stat(const char *path, struct stat *buf){
|
||||
return (int)(KSwitch2(KS_USER_STAT,(uintptr_t)path,(uintptr_t)buf));
|
||||
}
|
||||
|
||||
int fstat(int fd, struct stat *buf){
|
||||
return (int)(KSwitch2(KS_USER_FS_STAT,(uintptr_t)fd,(uintptr_t)buf));
|
||||
}
|
||||
|
||||
int fsync(int fd){
|
||||
return (int)(KSwitch1(KS_USER_FS_SYNC,(uintptr_t)fd));
|
||||
}
|
||||
|
||||
int ftruncate(int fd, off_t length){
|
||||
return (int)(KSwitch2(KS_USER_FTRUNCATE,(uintptr_t)fd,(uintptr_t)length));
|
||||
}
|
||||
|
||||
int mkdir(const char *path, mode_t mode){
|
||||
return (int)(KSwitch2(KS_USER_MKDIR,(uintptr_t)path,(uintptr_t)mode));
|
||||
}
|
||||
|
||||
DIR *opendir(const char *path){
|
||||
return (DIR *)(KSwitch1(KS_USER_OPENDIR,(uintptr_t)path));
|
||||
}
|
||||
|
||||
int closedir(DIR *dirp){
|
||||
return (int)(KSwitch1(KS_USER_CLOSEDIR,(uintptr_t)dirp));
|
||||
}
|
||||
|
||||
struct dirent *readdir(DIR *dirp){
|
||||
return (struct dirent *)(KSwitch1(KS_USER_READDIR,(uintptr_t)dirp));
|
||||
}
|
||||
|
||||
int rmdir(const char *path){
|
||||
return (int)(KSwitch1(KS_USER_RMDIR,(uintptr_t)path));
|
||||
}
|
||||
|
||||
int chdir(const char *path){
|
||||
return (int)(KSwitch1(KS_USER_CHDIR,(uintptr_t)path));
|
||||
}
|
||||
|
||||
char *getcwd(char *buf, size_t size){
|
||||
return (char *)(KSwitch2(KS_USER_GETCWD,(uintptr_t)buf,(uintptr_t)size ));
|
||||
}
|
||||
|
||||
long telldir(DIR *dirp){
|
||||
return (long)(KSwitch1(KS_USER_TELLDIR,(uintptr_t)dirp));
|
||||
}
|
||||
|
||||
void seekdir(DIR *dirp, off_t offset){
|
||||
return (void)(KSwitch2(KS_USER_SEEKDIR,(uintptr_t)dirp,(uintptr_t)offset));
|
||||
}
|
||||
|
||||
void rewinddir(DIR *dirp){
|
||||
return (void)(KSwitch1(KS_USER_REWIND_DIR,(uintptr_t)dirp));
|
||||
}
|
||||
|
||||
int statfs(const char *path, struct statfs *buf){
|
||||
return (int)(KSwitch2(KS_USER_STAT_FS,(uintptr_t)path,(uintptr_t)buf));
|
||||
}
|
||||
|
||||
void Userprintf(const char *fmt, ...)
|
||||
{
|
||||
if(stdio != NONE)
|
||||
{
|
||||
va_list args;
|
||||
size_t length;
|
||||
static char logbuf[CONSOLEBUF_SIZE];
|
||||
|
||||
va_start(args, fmt);
|
||||
|
||||
length = vsnprintf(logbuf, sizeof(logbuf) - 1, fmt, args);
|
||||
if (length > CONSOLEBUF_SIZE - 1)
|
||||
length = CONSOLEBUF_SIZE - 1;
|
||||
|
||||
write(stdio, logbuf, length);
|
||||
va_end(args);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* 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: user_mem.c
|
||||
* @brief: the priviate user api of mem for application
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#include "user_api.h"
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* This function is provided to allocate memory block.
|
||||
*
|
||||
* @param size the memory size to be allocated
|
||||
*
|
||||
* @return pointer on success; NULL on failure
|
||||
*/
|
||||
void *UserMalloc(size_t size){
|
||||
return (void *)(KSwitch1(KS_USER_MALLOC,(uintptr_t)size));
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is provided to release memory block.
|
||||
*
|
||||
* @param pointer the memory to be released
|
||||
*/
|
||||
void UserFree(void *pointer){
|
||||
KSwitch1(KS_USER_FREE,(uintptr_t)pointer);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is provided to re-allocate memory block.
|
||||
*
|
||||
* @param pointer the old memory pointer
|
||||
* @param size the memory size to be re-allocated
|
||||
*
|
||||
* @return pointer on success; NULL on failure
|
||||
*/
|
||||
void *UserRealloc(void *pointer, size_t size){
|
||||
x_size_t newsize = 0;
|
||||
x_size_t oldsize = 0;
|
||||
void *newmem = NONE;
|
||||
|
||||
/* the given pointer is NULL */
|
||||
if (pointer == NONE)
|
||||
return UserMalloc(size);
|
||||
|
||||
/* parameter detection */
|
||||
if (size == 0) {
|
||||
UserFree(pointer);
|
||||
return NONE;
|
||||
}
|
||||
|
||||
/* allocate new memory */
|
||||
newmem = UserMalloc(size);
|
||||
if(newmem == NONE) {
|
||||
return NONE;
|
||||
}
|
||||
|
||||
/* copy the old memory and then release old memory pointer */
|
||||
memcpy((char*)newmem, (char*) pointer,size > oldsize ? oldsize : size);
|
||||
UserFree(pointer);
|
||||
|
||||
return newmem;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will allocate memory blocks and then clear the memory.
|
||||
*
|
||||
* @param count the number of memory blocks
|
||||
* @param size the size of a memory block
|
||||
*
|
||||
* @return pointer on success; NULL on failure
|
||||
*/
|
||||
void *UserCalloc(size_t count, size_t size){
|
||||
void *p = NONE;
|
||||
|
||||
/* calls x_malloc to allocate count * size memory */
|
||||
p = UserMalloc(count * size);
|
||||
|
||||
/* zero the memory */
|
||||
if (p)
|
||||
memset((char*)p, 0, count * size);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
|
@ -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: user_msg.c
|
||||
* @brief: the priviate user api of msg queue for application
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#include "user_api.h"
|
||||
|
||||
/**
|
||||
* This function will create a msg queue.
|
||||
*
|
||||
* @param msg_size the length of the msg queue.
|
||||
* @param max_msgs the max length of the msg queue.
|
||||
*
|
||||
* @return id on success;ENOMEMORY/ERROR on failure
|
||||
*/
|
||||
int32_t UserMsgQueueCreate( size_t msg_size,
|
||||
size_t max_msgs){
|
||||
return (int32_t)KSwitch2(KS_USER_MSGQUEUE_CREATE, (uintptr_t)msg_size, (uintptr_t)max_msgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* a dynamic messagequeue will be deleted from the manage list
|
||||
*
|
||||
* @param id the message id
|
||||
*
|
||||
* @return EOK on success;EINVALED on failure
|
||||
*
|
||||
*/
|
||||
x_err_t UserMsgQueueDelete(int32_t mq ){
|
||||
return (x_err_t)KSwitch1(KS_USER_MSGQUEUE_DELETE, (uintptr_t)mq);
|
||||
}
|
||||
|
||||
/**
|
||||
* send message with waiting time,current suspend task will be resumed
|
||||
*
|
||||
* @param id the message id
|
||||
* @param buffer message info
|
||||
* @param size the size of buffer
|
||||
* @param timeout waiting time
|
||||
*
|
||||
* @return EOK on success;EINVALED on failure
|
||||
*
|
||||
*/
|
||||
x_err_t UserMsgQueueSendwait(int32_t mq, const void *buffer,
|
||||
size_t size, int32_t wait_time){
|
||||
return (x_err_t)KSwitch3(KS_USER_MSGQUEUE_SEND , (uintptr_t)mq, (uintptr_t)buffer, (uintptr_t)size );
|
||||
}
|
||||
|
||||
/**
|
||||
* send message without waiting time,current suspend task will be resumed
|
||||
*
|
||||
* @param id the message id
|
||||
* @param buffer message info
|
||||
* @param size the size of buffer
|
||||
*
|
||||
* @return EOK on success;EINVALED on failure
|
||||
*
|
||||
*/
|
||||
x_err_t UserMsgQueueSend(int32_t mq, const void *buffer, size_t size){
|
||||
|
||||
return (x_err_t)KSwitch3(KS_USER_MSGQUEUE_SEND , (uintptr_t)mq, (uintptr_t)buffer, (uintptr_t)size );
|
||||
|
||||
}
|
||||
/**
|
||||
* send urgent message without waiting time, this message will be inserted to the head of the queue
|
||||
*
|
||||
* @param id the message id
|
||||
* @param buffer message info
|
||||
* @param size the size of buffer
|
||||
*
|
||||
* @return EOK on success;EINVALED on failure
|
||||
*
|
||||
*/
|
||||
x_err_t UserMsgQueueUrgentSend(int32_t mq, const void *buffer, size_t size){
|
||||
|
||||
return (x_err_t)KSwitch3(KS_USER_MSGQUEUE_URGENTSEND , (uintptr_t)mq, (uintptr_t)buffer, (uintptr_t)size );
|
||||
}
|
||||
|
||||
/**
|
||||
* receive message with some waiting time
|
||||
*
|
||||
* @param id the message id
|
||||
* @param buffer message info
|
||||
* @param size the size of buffer
|
||||
* @param timeout time needed waiting
|
||||
*
|
||||
* @return EOK on success;EINVALED on failure
|
||||
*
|
||||
*/
|
||||
x_err_t UserMsgQueueRecv(int32_t mq, void *buffer,
|
||||
size_t size,int32_t wait_time){
|
||||
return (x_err_t)KSwitch4(KS_USER_MSGQUEUE_RECV ,(uintptr_t)mq, (uintptr_t)buffer, (uintptr_t)size, (uintptr_t)wait_time );
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will reset a event.
|
||||
*
|
||||
* @param id the id number of event.
|
||||
*
|
||||
* @return EOK on success;EINVALED on failure
|
||||
*/
|
||||
x_err_t UserMsgQueueReinit(int32_t mq){
|
||||
return (x_err_t)KSwitch1(KS_USER_MSGQUEUE_REINIT ,(uintptr_t)mq );
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* 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: user_mutex.c
|
||||
* @brief: the priviate user api of mutex for application
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#include "user_api.h"
|
||||
|
||||
/**
|
||||
* a mutex will be inited in static way,then this mutex will be inserted to the manage list
|
||||
*
|
||||
* @param mutex the mutex descriptor
|
||||
* @param name mutex name
|
||||
* @param flag mutex flag
|
||||
*
|
||||
* @return EOK on success
|
||||
*
|
||||
*/
|
||||
int32_t UserMutexCreate(){
|
||||
return (int32_t)KSwitch0(KS_USER_MUTEX_CREATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* a dynamic mutex will be deleted from the manage list
|
||||
*
|
||||
* @param mutex mutex descriptor
|
||||
*
|
||||
*/
|
||||
void UserMutexDelete(int32_t mutex){
|
||||
KSwitch1(KS_USER_MUTEX_DELETE,(uintptr_t)mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* a mutex will be taken when mutex is available
|
||||
*
|
||||
* @param mutex mutex descriptor
|
||||
* @param msec the time needed waiting
|
||||
*
|
||||
* @return EOK on success;ERROR on failure
|
||||
*
|
||||
*/
|
||||
int32_t UserMutexObtain(int32_t mutex, int32_t wait_time){
|
||||
return (int32_t)KSwitch2(KS_USER_MUTEX_OBTAIN,(uintptr_t)mutex, (uintptr_t)wait_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* release the mutex and resume corresponding suspended task
|
||||
*
|
||||
* @param mutex mutex descriptor
|
||||
*
|
||||
* @return EOK on success;ERROR on failure
|
||||
*/
|
||||
int32_t UserMutexAbandon(int32_t mutex){
|
||||
return (int32_t)KSwitch1(KS_USER_MUTEX_ABANDON,(uintptr_t)mutex);
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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: user_print_info.c
|
||||
* @brief: the priviate user api of user info print for application
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#include "user_api.h"
|
||||
|
||||
/* for debug */
|
||||
int UserPrintInfo(unsigned long i){
|
||||
return (int)KSwitch1(KS_USER_PRINT_INFO,i);
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* 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: user_semaphore.c
|
||||
* @brief: the priviate user api of semphore for application
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#include "user_api.h"
|
||||
|
||||
/**
|
||||
* Create a new semaphore with specified initial value.
|
||||
*
|
||||
* @param val initial value
|
||||
* @return id of the semaphore
|
||||
*/
|
||||
sem_t UserSemaphoreCreate(uint16_t val){
|
||||
return (sem_t)KSwitch1(KS_USER_SEMAPHORE_CREATE,(uintptr_t)val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a semaphore and wakeup all pending tasks on it.
|
||||
*
|
||||
* @param id id of the semaphore to be deleted
|
||||
*/
|
||||
x_err_t UserSemaphoreDelete(sem_t sem){
|
||||
return (x_err_t)KSwitch1(KS_USER_SEMAPHORE_DELETE,(uintptr_t)sem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain a semaphore when its value is greater than 0; pend on it otherwise.
|
||||
*
|
||||
* @param id id of the semaphore to be obtained
|
||||
* @param msec wait time in millisecond
|
||||
* @return EOK on success, error code on failure
|
||||
*/
|
||||
x_err_t UserSemaphoreObtain(sem_t sem, int32_t wait_time){
|
||||
return (x_err_t)KSwitch2(KS_USER_SEMAPHORE_OBTAIN,(uintptr_t)sem,(uintptr_t)wait_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abandon a semaphore and wakeup a pending task if any.
|
||||
*
|
||||
* @param id id of the semaphore to be abandoned
|
||||
* @return EOK on success, error code on failure
|
||||
*/
|
||||
x_err_t UserSemaphoreAbandon(sem_t sem){
|
||||
return (x_err_t)KSwitch1(KS_USER_SEMAPHORE_ABANDON,(uintptr_t)sem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of a semaphore, wakeup all pending tasks if new value is positive.
|
||||
*
|
||||
* @param id id of the semaphore for which to set value
|
||||
* @param val new value
|
||||
* @return EOK on success, error code on failure
|
||||
*/
|
||||
x_err_t UserSemaphoreSetValue(sem_t sem, uint16_t val){
|
||||
return (x_err_t)KSwitch2(KS_USER_SEMAPHORE_SETVALUE,(uintptr_t)sem,(uintptr_t)val);
|
||||
}
|
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* 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: user_task.c
|
||||
* @brief: the priviate user api of task for application
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
|
||||
#include "user_api.h"
|
||||
|
||||
/**
|
||||
*
|
||||
* This function init a user task in dynamic way .
|
||||
*
|
||||
* @param name task name
|
||||
* @param parameter task process function
|
||||
* @param parameter task arg
|
||||
* @param stack_size task stack size
|
||||
* @param priority task priority
|
||||
* @param tick task time slice
|
||||
*
|
||||
* @return EOK on success; ENOMEMORY/EEMPTY on failure
|
||||
*/
|
||||
int32_t UserTaskCreate(utask_x utask){
|
||||
return (int32_t) KSwitch5(KS_USER_TASK_CREATE,(uintptr_t)utask.name,(uintptr_t)utask.func_entry,(uintptr_t)utask.func_param,(uintptr_t)utask.stack_size,(uintptr_t)utask.prio);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will insert task to ready queue then schedule
|
||||
*
|
||||
* @param id task id
|
||||
*
|
||||
* @return EOK on success; EINVALED on failure
|
||||
*/
|
||||
x_err_t UserTaskStartup(int32_t id){
|
||||
return (x_err_t)KSwitch1(KS_USER_TASK_STARTUP,(uintptr_t)id);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will remove a dynamic task out of the task manage list.
|
||||
*
|
||||
* @param id task id
|
||||
*
|
||||
* @return EOK on success; EINVALED on failure
|
||||
*/
|
||||
x_err_t UserTaskDelete(int32_t id){
|
||||
return (x_err_t)KSwitch1(KS_USER_TASK_DELETE,(uintptr_t)id);
|
||||
}
|
||||
|
||||
void UserTaskQuit(void){
|
||||
KSwitch0(KS_USER_TASK_EXECEXIT);
|
||||
return ;
|
||||
}
|
||||
/**
|
||||
* This function will delay current task running with some ticks.
|
||||
*
|
||||
* @param tick delay ticks
|
||||
* @return EOK on success; EINVALED/EEMPTY on failure
|
||||
*/
|
||||
x_err_t UserTaskDelay(int32_t ms){
|
||||
return (x_err_t)KSwitch1(KS_USER_TASK_DELAY,(uintptr_t)ms);
|
||||
}
|
||||
|
||||
x_err_t UserGetTaskName( int32_t id, char *name){
|
||||
return (x_err_t)KSwitch2(KS_USER_GET_TASK_NAME,(uintptr_t)id, (uintptr_t)name);
|
||||
}
|
||||
|
||||
int32_t UserGetTaskID(void){
|
||||
return (int32_t)KSwitch0(KS_USER_GET_TASK_ID);
|
||||
}
|
||||
|
||||
uint8_t UserGetTaskStat(int32_t id){
|
||||
return (uint8_t)KSwitch1(KS_USER_GET_TASK_STAT,(uintptr_t)id );
|
||||
}
|
||||
|
||||
#ifdef ARCH_SMP
|
||||
/**
|
||||
* This function binds a task to cpu core.
|
||||
*
|
||||
* @param id task id
|
||||
* @param coreid cpu core id
|
||||
*
|
||||
* @return EOK
|
||||
*/
|
||||
x_err_t UserTaskCoreCombine(int32_t id,uint8_t core_id){
|
||||
return (x_err_t)KSwitch2(KS_USER_TASK_CORE_COMBINE,(uintptr_t)id,core_id);
|
||||
}
|
||||
/**
|
||||
* This function unbinds a task with cpu core.
|
||||
*
|
||||
* @param id task id
|
||||
*
|
||||
* @return EOK
|
||||
*/
|
||||
x_err_t UserTaskCoreUnCombine(int32_t id){
|
||||
return (x_err_t)KSwitch1(KS_USER_TASK_CORE_UNCOMBINE,(uintptr_t)id);
|
||||
}
|
||||
|
||||
uint8_t UserGetTaskCombinedCore(int32_t id){
|
||||
return (uint8_t)KSwitch1(KS_USER_GET_TASK_COMBINEED_CORE,(uintptr_t)id );
|
||||
}
|
||||
|
||||
uint8 UserGetTaskRunningCore(int32_t id){
|
||||
return (uint8_t)KSwitch1(KS_USER_GET_TASK_RUNNING_CORE,(uintptr_t)id );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
x_err_t UserGetTaskErrorstatus(int32_t id){
|
||||
return (x_err_t)KSwitch1(KS_USER_GET_TASK_ERROR_STATUS,(uintptr_t)id );
|
||||
}
|
||||
|
||||
uint8_t UserGetTaskPriority(int32_t id){
|
||||
return (uint8_t)KSwitch1(KS_USER_GET_TASK_PRIORITY,(uintptr_t)id );
|
||||
}
|
|
@ -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,
|
||||
|
||||
};
|
|
@ -0,0 +1,13 @@
|
|||
config ARCH_CPU_64BIT
|
||||
bool
|
||||
|
||||
config ARCH_RISCV
|
||||
bool
|
||||
|
||||
config ARCH_ARM
|
||||
bool
|
||||
|
||||
config ARCH_RISCV64
|
||||
select ARCH_RISCV
|
||||
select ARCH_CPU_64BIT
|
||||
bool
|
|
@ -0,0 +1,3 @@
|
|||
SRC_DIR := $(ARCH)
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,4 @@
|
|||
#公共部分
|
||||
SRC_DIR := shared cortex-m4
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,7 @@
|
|||
SRC_FILES := system_init.c boot.S interrupt_vector.S coreclock.c interrupt.c svc_entry.S
|
||||
|
||||
ifeq ($(CONFIG_TASK_ISOLATION),y)
|
||||
SRC_FILES += svc_handle.c mpu.c
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ARCH_INTERRUPT_H__
|
||||
#define ARCH_INTERRUPT_H__
|
||||
|
||||
#include <xs_base.h>
|
||||
|
||||
#define ARCH_MAX_IRQ_NUM (256 + 16)
|
||||
|
||||
#define ARCH_IRQ_NUM_OFFSET 16
|
||||
|
||||
int32 ArchEnableHwIrq(uint32 irq_num);
|
||||
int32 ArchDisableHwIrq(uint32 irq_num);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,99 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* @file startup_stm32f407xx.s
|
||||
* @author MCD Application Team
|
||||
* @brief STM32F407xx Devices vector table for GCC based toolchains.
|
||||
* This module performs:
|
||||
* - Set the initial SP
|
||||
* - Set the initial PC == Reset_Handler,
|
||||
* - Set the vector table entries with the exceptions ISR address
|
||||
* - Branches to main in the C library (which eventually
|
||||
* calls main()).
|
||||
* After Reset the Cortex-M4 processor is in Thread mode,
|
||||
* priority is Privileged, and the Stack is set to Main.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file coreclock.c
|
||||
* @brief derived from ST standard peripheral library
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-25
|
||||
*/
|
||||
|
||||
.syntax unified
|
||||
.cpu cortex-m4
|
||||
.fpu softvfp
|
||||
.thumb
|
||||
|
||||
.word _sidata
|
||||
.word _sdata
|
||||
.word _edata
|
||||
.word __bss_start
|
||||
.word __bss_end
|
||||
|
||||
.section .text.Reset_Handler
|
||||
.weak Reset_Handler
|
||||
.type Reset_Handler, %function
|
||||
Reset_Handler:
|
||||
ldr sp, =__stack_tp
|
||||
movs r1, #0
|
||||
|
||||
/* Copy the data segment initializers from flash to SRAM */
|
||||
DataInit:
|
||||
ldr r0, =_sdata
|
||||
ldr r3, =_edata
|
||||
adds r2, r0, r1
|
||||
cmp r2, r3
|
||||
bcs DataInitEnd
|
||||
ldr r3, =_sidata
|
||||
ldr r3, [r3, r1]
|
||||
str r3, [r0, r1]
|
||||
adds r1, r1, #4
|
||||
b DataInit
|
||||
|
||||
DataInitEnd:
|
||||
ldr r2, =__bss_start
|
||||
|
||||
/* Zero fill the bss segment. */
|
||||
BSSInit:
|
||||
ldr r3, = __bss_end
|
||||
cmp r2, r3
|
||||
bcs BSSInitEnd
|
||||
movs r3, #0
|
||||
str r3, [r2], #4
|
||||
b BSSInit
|
||||
|
||||
BSSInitEnd:
|
||||
bl SystemInit
|
||||
bl stm32f407_start
|
||||
bx lr
|
||||
.size Reset_Handler, .-Reset_Handler
|
|
@ -0,0 +1,98 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* @file system_stm32f4xx.c
|
||||
* @author MCD Application Team
|
||||
* @brief CMSIS Cortex-M4 Device Peripheral Access Layer System Source File.
|
||||
*
|
||||
* This file provides two functions and one global variable to be called from
|
||||
* user application:
|
||||
* - SystemInit(): This function is called at startup just after reset and
|
||||
* before branch to main program. This call is made inside
|
||||
* the "startup_stm32f4xx.s" file.
|
||||
*
|
||||
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
|
||||
* by the user application to setup the SysTick
|
||||
* timer or configure other parameters.
|
||||
*
|
||||
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
|
||||
* be called whenever the core clock is changed
|
||||
* during program execution.
|
||||
*
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file coreclock.c
|
||||
* @brief derived from ST standard peripheral library
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-25
|
||||
*/
|
||||
|
||||
#include "stm32f4xx.h"
|
||||
|
||||
uint32_t system_core_clock = 16000000;
|
||||
const uint8_t ahb_presc_table[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||
const uint8_t apb_presc_table[8] = {0, 0, 0, 0, 1, 2, 3, 4};
|
||||
|
||||
void SystemCoreClockUpdate(void)
|
||||
{
|
||||
uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;
|
||||
|
||||
tmp = RCC->CFGR & RCC_CFGR_SWS;
|
||||
|
||||
switch (tmp) {
|
||||
case 0x00:
|
||||
system_core_clock = HSI_VALUE;
|
||||
break;
|
||||
case 0x04:
|
||||
system_core_clock = HSE_VALUE;
|
||||
break;
|
||||
case 0x08:
|
||||
pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
|
||||
pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
|
||||
|
||||
if (pllsource != 0)
|
||||
pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
|
||||
else
|
||||
pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
|
||||
|
||||
pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2;
|
||||
system_core_clock = pllvco/pllp;
|
||||
break;
|
||||
default:
|
||||
system_core_clock = HSI_VALUE;
|
||||
break;
|
||||
}
|
||||
|
||||
tmp = ahb_presc_table[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
|
||||
system_core_clock >>= tmp;
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* 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 <xs_base.h>
|
||||
#include <xs_isr.h>
|
||||
#include <misc.h>
|
||||
#include <stm32f4xx.h>
|
||||
|
||||
x_base __attribute__((naked)) DisableLocalInterrupt()
|
||||
{
|
||||
asm volatile ("MRS r0, PRIMASK");
|
||||
asm volatile ("CPSID I");
|
||||
asm volatile ("BX LR ");
|
||||
}
|
||||
|
||||
void __attribute__((naked)) EnableLocalInterrupt(x_base level)
|
||||
{
|
||||
asm volatile ("MSR PRIMASK, r0");
|
||||
asm volatile ("BX LR");
|
||||
}
|
||||
|
||||
int32 ArchEnableHwIrq(uint32 irq_num)
|
||||
{
|
||||
NVIC_InitTypeDef nvic_init;
|
||||
|
||||
nvic_init.NVIC_IRQChannel = irq_num;
|
||||
nvic_init.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
nvic_init.NVIC_IRQChannelSubPriority = 0;
|
||||
nvic_init.NVIC_IRQChannelCmd = ENABLE;
|
||||
|
||||
NVIC_Init(&nvic_init);
|
||||
|
||||
return EOK;
|
||||
}
|
||||
|
||||
int32 ArchDisableHwIrq(uint32 irq_num)
|
||||
{
|
||||
NVIC_InitTypeDef nvic_init;
|
||||
|
||||
nvic_init.NVIC_IRQChannel = irq_num;
|
||||
nvic_init.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
nvic_init.NVIC_IRQChannelSubPriority = 0;
|
||||
nvic_init.NVIC_IRQChannelCmd = DISABLE;
|
||||
|
||||
NVIC_Init(&nvic_init);
|
||||
|
||||
return EOK;
|
||||
}
|
||||
|
||||
extern void KTaskOsAssignAfterIrq(void *context);
|
||||
|
||||
void IsrEntry()
|
||||
{
|
||||
uint32 ipsr;
|
||||
|
||||
__asm__ volatile("MRS %0, IPSR" : "=r"(ipsr));
|
||||
|
||||
isrManager.done->incCounter();
|
||||
isrManager.done->handleIrq(ipsr);
|
||||
KTaskOsAssignAfterIrq(NONE);
|
||||
isrManager.done->decCounter();
|
||||
|
||||
}
|
||||
|
||||
uintptr_t *Svcall(unsigned int ipsr , uintptr_t* contex )
|
||||
{
|
||||
#ifdef TASK_ISOLATION
|
||||
__svcall(contex);
|
||||
#endif
|
||||
return contex;
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* @file startup_stm32f407xx.s
|
||||
* @author MCD Application Team
|
||||
* @brief STM32F407xx Devices vector table for GCC based toolchains.
|
||||
* This module performs:
|
||||
* - Set the initial SP
|
||||
* - Set the initial PC == Reset_Handler,
|
||||
* - Set the vector table entries with the exceptions ISR address
|
||||
* - Branches to main in the C library (which eventually
|
||||
* calls main()).
|
||||
* After Reset the Cortex-M4 processor is in Thread mode,
|
||||
* priority is Privileged, and the Stack is set to Main.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file coreclock.c
|
||||
* @brief derived from ST standard peripheral library
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-25
|
||||
*/
|
||||
|
||||
.globl InterruptVectors
|
||||
|
||||
/******************************************************************************
|
||||
*******************************************************************************/
|
||||
.section .isr_vector,"a",%progbits
|
||||
.type InterruptVectors, %object
|
||||
.size InterruptVectors, .-InterruptVectors
|
||||
|
||||
InterruptVectors:
|
||||
.word __stack_end__
|
||||
|
||||
.word Reset_Handler
|
||||
.word NMI_Handler
|
||||
.word HardFaultHandler
|
||||
.word MemFaultHandler
|
||||
.word BusFault_Handler
|
||||
.word UsageFault_Handler
|
||||
.word IsrEntry
|
||||
.word IsrEntry
|
||||
.word IsrEntry
|
||||
.word IsrEntry
|
||||
.word SVC_Entry /* SVC */
|
||||
.word IsrEntry /* DebugMon */
|
||||
.word IsrEntry
|
||||
.word PendSV_Handler
|
||||
.word IsrEntry /* SysTick */
|
||||
|
||||
.word IsrEntry /* Window WatchDog */
|
||||
.word IsrEntry /* PVD through EXTI Line detection */
|
||||
.word IsrEntry /* Tamper and TimeStamps through the EXTI line */
|
||||
.word IsrEntry /* RTC Wakeup through the EXTI line */
|
||||
.word IsrEntry /* FLASH */
|
||||
.word IsrEntry /* RCC */
|
||||
.word IsrEntry /* EXTI Line0 */
|
||||
.word IsrEntry /* EXTI Line1 */
|
||||
.word IsrEntry /* EXTI Line2 */
|
||||
.word IsrEntry /* EXTI Line3 */
|
||||
.word IsrEntry /* EXTI Line4 */
|
||||
.word IsrEntry /* DMA1 Stream 0 */
|
||||
.word IsrEntry /* DMA1 Stream 1 */
|
||||
.word IsrEntry /* DMA1 Stream 2 */
|
||||
.word IsrEntry /* DMA1 Stream 3 */
|
||||
.word IsrEntry /* DMA1 Stream 4 */
|
||||
.word IsrEntry /* DMA1 Stream 5 */
|
||||
.word IsrEntry /* DMA1 Stream 6 */
|
||||
.word IsrEntry /* ADC1, ADC2 and ADC3s */
|
||||
.word IsrEntry /* CAN1 TX */
|
||||
.word IsrEntry /* CAN1 RX0 */
|
||||
.word IsrEntry /* CAN1 RX1 */
|
||||
.word IsrEntry /* CAN1 SCE */
|
||||
.word IsrEntry /* External Line[9:5]s */
|
||||
.word IsrEntry /* TIM1 Break and TIM9 */
|
||||
.word IsrEntry /* TIM1 Update and TIM10 */
|
||||
.word IsrEntry /* TIM1 Trigger and Commutation and TIM11 */
|
||||
.word IsrEntry /* TIM1 Capture Compare */
|
||||
.word IsrEntry /* TIM2 */
|
||||
.word IsrEntry /* TIM3 */
|
||||
.word IsrEntry /* TIM4 */
|
||||
.word IsrEntry /* I2C1 Event */
|
||||
.word IsrEntry /* I2C1 Error */
|
||||
.word IsrEntry /* I2C2 Event */
|
||||
.word IsrEntry /* I2C2 Error */
|
||||
.word IsrEntry /* SPI1 */
|
||||
.word IsrEntry /* SPI2 */
|
||||
.word IsrEntry /* USART1 */
|
||||
.word IsrEntry /* USART2 */
|
||||
.word IsrEntry /* USART3 */
|
||||
.word IsrEntry /* External Line[15:10]s */
|
||||
.word IsrEntry /* RTC Alarm (A and B) through EXTI Line */
|
||||
.word IsrEntry /* USB OTG FS Wakeup through EXTI line */
|
||||
.word IsrEntry /* TIM8 Break and TIM12 */
|
||||
.word IsrEntry /* TIM8 Update and TIM13 */
|
||||
.word IsrEntry /* TIM8 Trigger and Commutation and TIM14 */
|
||||
.word IsrEntry /* TIM8 Capture Compare */
|
||||
.word IsrEntry /* DMA1 Stream7 */
|
||||
.word IsrEntry /* FSMC */
|
||||
.word IsrEntry /* SDIO */
|
||||
.word IsrEntry /* TIM5 */
|
||||
.word IsrEntry /* SPI3 */
|
||||
.word IsrEntry /* UART4 */
|
||||
.word IsrEntry /* UART5 */
|
||||
.word IsrEntry /* TIM6 and DAC1&2 underrun errors */
|
||||
.word IsrEntry /* TIM7 */
|
||||
.word IsrEntry /* DMA2 Stream 0 */
|
||||
.word IsrEntry /* DMA2 Stream 1 */
|
||||
.word IsrEntry /* DMA2 Stream 2 */
|
||||
.word IsrEntry /* DMA2 Stream 3 */
|
||||
.word IsrEntry /* DMA2 Stream 4 */
|
||||
.word IsrEntry /* Ethernet */
|
||||
.word IsrEntry /* Ethernet Wakeup through EXTI line */
|
||||
.word IsrEntry /* CAN2 TX */
|
||||
.word IsrEntry /* CAN2 RX0 */
|
||||
.word IsrEntry /* CAN2 RX1 */
|
||||
.word IsrEntry /* CAN2 SCE */
|
||||
.word IsrEntry /* USB OTG FS */
|
||||
.word IsrEntry /* DMA2 Stream 5 */
|
||||
.word IsrEntry /* DMA2 Stream 6 */
|
||||
.word IsrEntry /* DMA2 Stream 7 */
|
||||
.word IsrEntry /* USART6 */
|
||||
.word IsrEntry /* I2C3 event */
|
||||
.word IsrEntry /* I2C3 error */
|
||||
.word IsrEntry /* USB OTG HS End Point 1 Out */
|
||||
.word IsrEntry /* USB OTG HS End Point 1 In */
|
||||
.word IsrEntry /* USB OTG HS Wakeup through EXTI */
|
||||
.word IsrEntry /* USB OTG HS */
|
||||
.word IsrEntry /* DCMI */
|
||||
.word IsrEntry /* CRYP crypto */
|
||||
.word IsrEntry /* Hash and Rng */
|
||||
.word IsrEntry /* FPU */
|
|
@ -0,0 +1,292 @@
|
|||
/****************************************************************************
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file kswitch.h
|
||||
* @brief risc-v ecall function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: kswitch.h
|
||||
Description: arm svc function
|
||||
Others: take incubator-nuttx arch/arm/include/armv7-m/syscall.h for references
|
||||
https://github.com/apache/incubator-nuttx/tree/master/arch/arm/include/armv7-m/syscall.h
|
||||
History:
|
||||
1. Date: 2021-04-25
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. Modify function name for a unified
|
||||
2. Add some functions when there is no system call
|
||||
*************************************************/
|
||||
#ifndef __XS_ARM_M4_KSWITCH_H__
|
||||
#define __XS_ARM_M4_KSWITCH_H__
|
||||
|
||||
#include <stdint.h>
|
||||
// #include <xs_service.h>
|
||||
#include "../../../kernel/include/xs_service.h"
|
||||
|
||||
#ifdef TASK_ISOLATION
|
||||
#define KERNEL_SWITCH 0x00
|
||||
|
||||
/****************************************************************************
|
||||
* kernel switch functions
|
||||
****************************************************************************/
|
||||
|
||||
/* SVC call with call number and no parameters */
|
||||
static inline unsigned long KSwitch0(unsigned int nbr)
|
||||
{
|
||||
register long reg0 __asm__("r0") = (long)(nbr);
|
||||
|
||||
__asm__ __volatile__
|
||||
(
|
||||
"svc %1"
|
||||
: "=r"(reg0)
|
||||
: "i"(KERNEL_SWITCH), "r"(reg0)
|
||||
: "memory"
|
||||
);
|
||||
|
||||
return reg0;
|
||||
}
|
||||
|
||||
/* SVC call with call number and one parameter */
|
||||
static inline unsigned long KSwitch1(unsigned int nbr, unsigned long parm1)
|
||||
{
|
||||
register long reg0 __asm__("r0") = (long)(nbr);
|
||||
register long reg1 __asm__("r1") = (long)(parm1);
|
||||
|
||||
__asm__ __volatile__
|
||||
(
|
||||
"svc %1"
|
||||
: "=r"(reg0)
|
||||
: "i"(KERNEL_SWITCH), "r"(reg0), "r"(reg1)
|
||||
: "memory"
|
||||
);
|
||||
|
||||
return reg0;
|
||||
}
|
||||
|
||||
/* SVC call with call number and two parameters */
|
||||
static inline unsigned long KSwitch2(unsigned int nbr, unsigned long parm1,
|
||||
unsigned long parm2)
|
||||
{
|
||||
register long reg0 __asm__("r0") = (long)(nbr);
|
||||
register long reg2 __asm__("r2") = (long)(parm2);
|
||||
register long reg1 __asm__("r1") = (long)(parm1);
|
||||
|
||||
__asm__ __volatile__
|
||||
(
|
||||
"svc %1"
|
||||
: "=r"(reg0)
|
||||
: "i"(KERNEL_SWITCH), "r"(reg0), "r"(reg1), "r"(reg2)
|
||||
: "memory"
|
||||
);
|
||||
|
||||
return reg0;
|
||||
}
|
||||
|
||||
|
||||
/* SVC call with call number and four parameters.
|
||||
*
|
||||
*/
|
||||
static inline unsigned long KSwitch3(unsigned int nbr, unsigned long parm1,
|
||||
unsigned long parm2, unsigned long parm3)
|
||||
{
|
||||
register long reg0 __asm__("r0") = (long)(nbr);
|
||||
register long reg1 __asm__("r1") = (long)(parm1);
|
||||
register long reg2 __asm__("r2") = (long)(parm2);
|
||||
register long reg3 __asm__("r3") = (long)(parm3);
|
||||
|
||||
|
||||
|
||||
__asm__ __volatile__
|
||||
(
|
||||
"svc %1"
|
||||
: "=r"(reg0)
|
||||
: "i"(KERNEL_SWITCH), "r"(reg0), "r"(reg1), "r"(reg2),
|
||||
"r"(reg3)
|
||||
: "memory"
|
||||
);
|
||||
|
||||
return reg0;
|
||||
}
|
||||
|
||||
static inline unsigned long KSwitch4(unsigned int nbr, unsigned long parm1,
|
||||
unsigned long parm2, unsigned long parm3,
|
||||
unsigned long parm4)
|
||||
{
|
||||
register long reg0 __asm__("r0") = (long)(nbr);
|
||||
register long reg4 __asm__("r4") = (long)(parm4);
|
||||
register long reg3 __asm__("r3") = (long)(parm3);
|
||||
register long reg2 __asm__("r2") = (long)(parm2);
|
||||
register long reg1 __asm__("r1") = (long)(parm1);
|
||||
|
||||
__asm__ __volatile__
|
||||
(
|
||||
"svc %1"
|
||||
: "=r"(reg0)
|
||||
: "i"(KERNEL_SWITCH), "r"(reg0), "r"(reg1), "r"(reg2),
|
||||
"r"(reg3), "r"(reg4)
|
||||
: "memory"
|
||||
);
|
||||
|
||||
return reg0;
|
||||
}
|
||||
|
||||
/* SVC call with call number and five parameters.
|
||||
*
|
||||
*/
|
||||
static inline unsigned long KSwitch5(unsigned int nbr, unsigned long parm1,
|
||||
unsigned long parm2, unsigned long parm3,
|
||||
unsigned long parm4, unsigned long parm5)
|
||||
{
|
||||
register long reg0 __asm__("r0") = (long)(nbr);
|
||||
register long reg5 __asm__("r5") = (long)(parm5);
|
||||
register long reg4 __asm__("r4") = (long)(parm4);
|
||||
register long reg3 __asm__("r3") = (long)(parm3);
|
||||
register long reg2 __asm__("r2") = (long)(parm2);
|
||||
register long reg1 __asm__("r1") = (long)(parm1);
|
||||
|
||||
__asm__ __volatile__
|
||||
(
|
||||
"svc %1"
|
||||
: "=r"(reg0)
|
||||
: "i"(KERNEL_SWITCH), "r"(reg0), "r"(reg1), "r"(reg2),
|
||||
"r"(reg3), "r"(reg4), "r"(reg5)
|
||||
: "memory"
|
||||
);
|
||||
|
||||
return reg0;
|
||||
}
|
||||
|
||||
/* SVC call with call number and six parameters.
|
||||
*
|
||||
*/
|
||||
static inline unsigned long KSwitch6(unsigned int nbr, unsigned long parm1,
|
||||
unsigned long parm2, unsigned long parm3,
|
||||
unsigned long parm4, unsigned long parm5,
|
||||
unsigned long parm6)
|
||||
{
|
||||
register long reg0 __asm__("r0") = (long)(nbr);
|
||||
register long reg6 __asm__("r6") = (long)(parm6);
|
||||
register long reg5 __asm__("r5") = (long)(parm5);
|
||||
register long reg4 __asm__("r4") = (long)(parm4);
|
||||
register long reg3 __asm__("r3") = (long)(parm3);
|
||||
register long reg2 __asm__("r2") = (long)(parm2);
|
||||
register long reg1 __asm__("r1") = (long)(parm1);
|
||||
|
||||
__asm__ __volatile__
|
||||
(
|
||||
"svc %1"
|
||||
: "=r"(reg0)
|
||||
: "i"(KERNEL_SWITCH), "r"(reg0), "r"(reg1), "r"(reg2),
|
||||
"r"(reg3), "r"(reg4), "r"(reg5), "r"(reg6)
|
||||
: "memory"
|
||||
);
|
||||
|
||||
return reg0;
|
||||
}
|
||||
#else
|
||||
|
||||
static inline unsigned long KSwitch0(unsigned int knum)
|
||||
{
|
||||
uintptr_t param[1] = {0};
|
||||
uint8_t num = 0;
|
||||
(struct Kernel_Service*)SERVICETABLE[knum].fun(knum, param, num);
|
||||
}
|
||||
|
||||
static inline unsigned long KSwitch1(unsigned int knum, unsigned long arg1)
|
||||
{
|
||||
uintptr_t param[1] = {0};
|
||||
uint8_t num = 1;
|
||||
param[0] = arg1;
|
||||
(struct Kernel_Service*)SERVICETABLE[knum].fun(knum, param, num);
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned long KSwitch2(unsigned int knum, unsigned long arg1,
|
||||
unsigned long arg2)
|
||||
{
|
||||
uintptr_t param[2] = {0};
|
||||
uint8_t num = 2;
|
||||
param[0] = arg1;
|
||||
param[1] = arg2;
|
||||
(struct Kernel_Service*)SERVICETABLE[knum].fun(knum, param, num);
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned long KSwitch3(unsigned int knum, unsigned long arg1,
|
||||
unsigned long arg2, unsigned long arg3)
|
||||
{
|
||||
uintptr_t param[3] = {0};
|
||||
uint8_t num = 3;
|
||||
param[0] = arg1;
|
||||
param[1] = arg2;
|
||||
param[2] = arg3;
|
||||
|
||||
(struct Kernel_Service*)SERVICETABLE[knum].fun(knum, param, num);
|
||||
}
|
||||
|
||||
static inline unsigned long KSwitch4(unsigned int knum, unsigned long arg1,
|
||||
unsigned long arg2, unsigned long arg3,
|
||||
unsigned long arg4)
|
||||
{
|
||||
uintptr_t param[4] = {0};
|
||||
uint8_t num = 4;
|
||||
param[0] = arg1;
|
||||
param[1] = arg2;
|
||||
param[2] = arg3;
|
||||
param[3] = arg4;
|
||||
(struct Kernel_Service*)SERVICETABLE[knum].fun(knum, param, num);
|
||||
}
|
||||
|
||||
static inline unsigned long KSwitch5(unsigned int knum, unsigned long arg1,
|
||||
unsigned long arg2, unsigned long arg3,
|
||||
unsigned long arg4, unsigned long arg5)
|
||||
{
|
||||
uintptr_t param[5] = {0};
|
||||
uint8_t num = 5;
|
||||
param[0] = arg1;
|
||||
param[1] = arg2;
|
||||
param[2] = arg3;
|
||||
param[3] = arg4;
|
||||
param[4] = arg5;
|
||||
(struct Kernel_Service*)SERVICETABLE[knum].fun(knum, param, num);
|
||||
}
|
||||
|
||||
static inline unsigned long KSwitch6(unsigned int knum, unsigned long arg1,
|
||||
unsigned long arg2, unsigned long arg3,
|
||||
unsigned long arg4, unsigned long arg5,
|
||||
unsigned long arg6)
|
||||
{
|
||||
uintptr_t param[6] = {0};
|
||||
uint8_t num = 6;
|
||||
param[0] = arg1;
|
||||
param[1] = arg2;
|
||||
param[2] = arg3;
|
||||
param[3] = arg4;
|
||||
param[4] = arg5;
|
||||
param[5] = arg6;
|
||||
(struct Kernel_Service*)SERVICETABLE[knum].fun(knum, param, num);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue