Browse Source

First commit XiUOS

tags/v1.0.0
xuetest 7 months ago
commit
6001051eb7
1331 changed files with 433955 additions and 0 deletions
  1. +8
    -0
      .gitignore
  2. +10
    -0
      Kconfig
  3. +112
    -0
      Makefile
  4. +68
    -0
      README.md
  5. +100
    -0
      applications/Kconfig
  6. +54
    -0
      applications/Makefile
  7. +3
    -0
      applications/app_newlib/Makefile
  8. +98
    -0
      applications/app_newlib/fs_syscalls.c
  9. +29
    -0
      applications/app_newlib/include/libc.h
  10. +70
    -0
      applications/app_newlib/mem_syscalls.c
  11. +155
    -0
      applications/app_newlib/stdio.c
  12. +44
    -0
      applications/app_newlib/task_syscalls.c
  13. +34
    -0
      applications/app_newlib/time_syscalls.c
  14. +10
    -0
      applications/app_test/Kconfig
  15. +7
    -0
      applications/app_test/Makefile
  16. +20
    -0
      applications/app_test/test_adhoc_lora.c
  17. +7
    -0
      applications/connection_demo/Makefile
  18. +3
    -0
      applications/connection_demo/ethernet_demo/Makefile
  19. +196
    -0
      applications/connection_demo/ethernet_demo/ethernet_demo.c
  20. +3
    -0
      applications/connection_demo/wifi_demo/Makefile
  21. +179
    -0
      applications/connection_demo/wifi_demo/wifi_demo.c
  22. +3
    -0
      applications/connection_demo/zigbee_demo/Makefile
  23. +86
    -0
      applications/connection_demo/zigbee_demo/zigbee_receive_demo.c
  24. +61
    -0
      applications/connection_demo/zigbee_demo/zigbee_send_demo.c
  25. +122
    -0
      applications/cppmain.cpp
  26. +153
    -0
      applications/framework_init.c
  27. +36
    -0
      applications/main.c
  28. +41
    -0
      applications/sd_card_mount.c
  29. +23
    -0
      applications/sensor_app/Makefile
  30. +34
    -0
      applications/sensor_app/co2_zg09.c
  31. +35
    -0
      applications/sensor_app/humidity_hs300x.c
  32. +35
    -0
      applications/sensor_app/pm1_0_ps5308.c
  33. +38
    -0
      applications/sensor_app/temperature_hs300x.c
  34. +36
    -0
      applications/sensor_app/voice_d124.c
  35. +46
    -0
      applications/spi_sd_card_mount.c
  36. +2
    -0
      applications/tflite_mnist/.gitignore
  37. +4
    -0
      applications/tflite_mnist/Kconfig
  38. +8
    -0
      applications/tflite_mnist/Makefile
  39. +19
    -0
      applications/tflite_mnist/README.md
  40. +42
    -0
      applications/tflite_mnist/digit.h
  41. +103
    -0
      applications/tflite_mnist/mnistapp.cpp
  42. +20
    -0
      applications/tflite_mnist/mnistmain.c
  43. +31420
    -0
      applications/tflite_mnist/model.h
  44. +47
    -0
      applications/tflite_mnist/tools/mnist-c-digit.py
  45. +34
    -0
      applications/tflite_mnist/tools/mnist-c-model.py
  46. +51
    -0
      applications/tflite_mnist/tools/mnist-inference.py
  47. +120
    -0
      applications/tflite_mnist/tools/mnist-train.py
  48. +4
    -0
      applications/tflite_sin/Kconfig
  49. +11
    -0
      applications/tflite_sin/Makefile
  50. +19
    -0
      applications/tflite_sin/constants.cc
  51. +32
    -0
      applications/tflite_sin/constants.h
  52. +119
    -0
      applications/tflite_sin/main_functions.cc
  53. +37
    -0
      applications/tflite_sin/main_functions.h
  54. +237
    -0
      applications/tflite_sin/model.cc
  55. +31
    -0
      applications/tflite_sin/model.h
  56. +24
    -0
      applications/tflite_sin/output_handler.cc
  57. +26
    -0
      applications/tflite_sin/output_handler.h
  58. +33
    -0
      applications/tflite_sin/sinmain.c
  59. +12
    -0
      applications/user_api/Makefile
  60. +3
    -0
      applications/user_api/general_functions/Makefile
  61. +3
    -0
      applications/user_api/general_functions/linklist/Makefile
  62. +84
    -0
      applications/user_api/general_functions/linklist/double_linklist.c
  63. +91
    -0
      applications/user_api/general_functions/linklist/single_linklist.c
  64. +129
    -0
      applications/user_api/general_functions/linklist/xs_klist.h
  65. +35
    -0
      applications/user_api/include/bus.h
  66. +67
    -0
      applications/user_api/include/bus_serial.h
  67. +70
    -0
      applications/user_api/include/dev_serial.h
  68. +4
    -0
      applications/user_api/posix_support/Kconfig
  69. +19
    -0
      applications/user_api/posix_support/Makefile
  70. +55
    -0
      applications/user_api/posix_support/include/fs.h
  71. +57
    -0
      applications/user_api/posix_support/include/mqueue.h
  72. +67
    -0
      applications/user_api/posix_support/include/pthread arm.h
  73. +107
    -0
      applications/user_api/posix_support/include/pthread.h
  74. +49
    -0
      applications/user_api/posix_support/include/semaphore.h
  75. +94
    -0
      applications/user_api/posix_support/mqueue.c
  76. +94
    -0
      applications/user_api/posix_support/pthread.c
  77. +125
    -0
      applications/user_api/posix_support/pthread_mutex.c
  78. +97
    -0
      applications/user_api/posix_support/semaphore.c
  79. +27
    -0
      applications/user_api/switch_api/Makefile
  80. +247
    -0
      applications/user_api/switch_api/user_api.h
  81. +73
    -0
      applications/user_api/switch_api/user_event.c
  82. +144
    -0
      applications/user_api/switch_api/user_fs.c
  83. +103
    -0
      applications/user_api/switch_api/user_mem.c
  84. +120
    -0
      applications/user_api/switch_api/user_msg.c
  85. +71
    -0
      applications/user_api/switch_api/user_mutex.c
  86. +28
    -0
      applications/user_api/switch_api/user_print_info.c
  87. +73
    -0
      applications/user_api/switch_api/user_semaphore.c
  88. +128
    -0
      applications/user_api/switch_api/user_task.c
  89. +43
    -0
      applications/userspace.c
  90. +13
    -0
      arch/Kconfig
  91. +3
    -0
      arch/Makefile
  92. +4
    -0
      arch/arm/Makefile
  93. +0
    -0
      arch/arm/cortex-m0/Makefile
  94. +7
    -0
      arch/arm/cortex-m4/Makefile
  95. +25
    -0
      arch/arm/cortex-m4/arch_interrupt.h
  96. +99
    -0
      arch/arm/cortex-m4/boot.S
  97. +98
    -0
      arch/arm/cortex-m4/coreclock.c
  98. +80
    -0
      arch/arm/cortex-m4/interrupt.c
  99. +160
    -0
      arch/arm/cortex-m4/interrupt_vector.S
  100. +292
    -0
      arch/arm/cortex-m4/kswitch.h

+ 8
- 0
.gitignore View File

@ -0,0 +1,8 @@
xsconfig.h
xsconfig.mk
.config
.config.old
build
XiUOS.*
*.swp
.vscode

+ 10
- 0
Kconfig View File

@ -0,0 +1,10 @@
source "$KERNEL_DIR/kernel/Kconfig"
source "$KERNEL_DIR/fs/Kconfig"
source "$KERNEL_DIR/framework/Kconfig"
source "$KERNEL_DIR/applications/Kconfig"

+ 112
- 0
Makefile View File

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

+ 68
- 0
README.md View File

@ -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文件。**

+ 100
- 0
applications/Kconfig View File

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

+ 54
- 0
applications/Makefile View File

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

+ 3
- 0
applications/app_newlib/Makefile View File

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

+ 98
- 0
applications/app_newlib/fs_syscalls.c View File

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

+ 29
- 0
applications/app_newlib/include/libc.h View File

@ -0,0 +1,29 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file libc.h
* @brief using newlib need include
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-25
*/
#ifndef _LIBC_H__
#define _LIBC_H__
#include <errno.h>
#include <stdarg.h>
#include <fcntl.h>
#endif

+ 70
- 0
applications/app_newlib/mem_syscalls.c View File

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

+ 155
- 0
applications/app_newlib/stdio.c View File

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

+ 44
- 0
applications/app_newlib/task_syscalls.c View File

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

+ 34
- 0
applications/app_newlib/time_syscalls.c View File

@ -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 = &current;
RtcDrvSetFunction(RTC_DRV_NAME, &rtc_set_param);
#endif
*t = current;
return current;
}

+ 10
- 0
applications/app_test/Kconfig View File

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

+ 7
- 0
applications/app_test/Makefile View File

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

+ 20
- 0
applications/app_test/test_adhoc_lora.c View File

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

+ 7
- 0
applications/connection_demo/Makefile View File

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

+ 3
- 0
applications/connection_demo/ethernet_demo/Makefile View File

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

+ 196
- 0
applications/connection_demo/ethernet_demo/ethernet_demo.c View File

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

+ 3
- 0
applications/connection_demo/wifi_demo/Makefile View File

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

+ 179
- 0
applications/connection_demo/wifi_demo/wifi_demo.c View File

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

+ 3
- 0
applications/connection_demo/zigbee_demo/Makefile View File

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

+ 86
- 0
applications/connection_demo/zigbee_demo/zigbee_receive_demo.c View File

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

+ 61
- 0
applications/connection_demo/zigbee_demo/zigbee_send_demo.c View File

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

+ 122
- 0
applications/cppmain.cpp View File

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

+ 153
- 0
applications/framework_init.c View File

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

+ 36
- 0
applications/main.c View File

@ -0,0 +1,36 @@
/*