forked from xuos/xiuos

commit
6001051eb7
1331 changed files with 433955 additions and 0 deletions
@ -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; |
|||