diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..fc95616078fc60759945b16c48f4aa6f9bc63996
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,62 @@
+# Prerequisites
+*.d
+
+# Object files
+*.o
+*.ko
+*.obj
+*.elf
+
+# Linker output
+*.ilk
+*.map
+*.exp
+
+# Precompiled Headers
+*.gch
+*.pch
+
+# Libraries
+*.lib
+*.a
+*.la
+*.lo
+
+# Shared objects (inc. Windows DLLs)
+*.dll
+*.so
+*.so.*
+*.dylib
+
+# Executables
+*.exe
+*.out
+*.app
+*.i*86
+*.x86_64
+*.hex
+
+# Debug files
+*.dSYM/
+*.su
+*.idb
+*.pdb
+
+# Kernel Module Compile Results
+*.mod*
+*.cmd
+.tmp_versions/
+modules.order
+Module.symvers
+Mkfile.old
+dkms.conf
+
+.idea
+.vscode
+
+/sdk_liteos/output/
+/sdk_liteos/tools/nvtool/out_nv_bin/
+/sdk_liteos/tools/nvtool/__pycache__/
+/sdk_liteos/third_party/u-boot-v2019.07/u-boot-v2019.07/
+/sdk_liteos/build/build_tmp/
+/sdk_liteos/build/scripts/__pycache__/
\ No newline at end of file
diff --git a/BUILD.gn b/BUILD.gn
new file mode 100755
index 0000000000000000000000000000000000000000..e936bd8ac3b30b3a1bf082c599bb09cc414a9665
--- /dev/null
+++ b/BUILD.gn
@@ -0,0 +1,4 @@
+# Copyright (C) 2020 Hisilicon (Shanghai) Technologies Co., Ltd. All rights reserved.
+
+group("genkipi") {
+}
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
diff --git a/README.en.md b/README.en.md
old mode 100644
new mode 100755
index 23f3e82185b6c452b8bae1d3db135348391c7d11..b4777e1695e8fbcd652b1cca74ab497b37b7995c
--- a/README.en.md
+++ b/README.en.md
@@ -1,36 +1,111 @@
-# devboard_device_itcast_genkipi
+# Itcast GenkiPi
-#### Description
-{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
+- [Introduction](#section1)
+- [Directory Structure](#section2)
+- [Compilation](#section3)
-#### Software Architecture
-Software architecture description
-#### Installation
-1. xxxx
-2. xxxx
-3. xxxx
+## Introduction
-#### Instructions
+GenkiPi development board is produced by Itcast Co., Ltd. It is equipped with OpenHarmony2.0 operating system; based on Hisilicon HI3861 module, 160MHz main frequency, SRAM 352KB, ROM 288KB, 2M Flash. 。It supports development protocols such as SPI, IIC, UART, ADC, and PWM, and is widely used in smart wear, smart security and industrial IoT scenarios.
-1. xxxx
-2. xxxx
-3. xxxx
+
+
+| 引脚 | Uart | SPI | ADC | PWM | I2S | SDIO | I2C |
+| :-----: | :-------------: | :---: | :---: | :---: | :---: | :--: | :---: |
+| GPIO_07 | CTS_1 | RXD_0 | ADC_3 | PWM_0 | CLK_0 | | |
+| GPIO_08 | RTS_1 | TXD_0 | | PWM_1 | WS_0 | | |
+| GPIO_10 | CTS_2 | CLK_0 | | PWM_1 | TX_0 | D3 | SDA_0 |
+| GPIO_09 | RTS_2 | TXD_0 | ADC_4 | PWM_0 | MCK_0 | D2 | SCL_0 |
+| GPIO_03 | LOG_TXD_0 | | | | | | |
+| GPIO_04 | LOG_RXD_0 | | ADC_1 | | | | |
+| GPIO_02 | | | | PWM_2 | MCK_0 | | |
+| GPIO_05 | RXD_1 | CSI_0 | ADC_2 | PWM_2 | TX_0 | | |
+| GPIO_06 | TXD_1 | CLK_0 | | PWM_3 | | | |
+| GPIO_14 | LOG_RXD_0/CTS_2 | | | PWM_5 | RX_0 | D1 | SCL_0 |
+| GPIO_11 | TXD_2 | RXD_0 | ADC_5 | PWM_2 | CLK_0 | CMD | |
+| GPIO_12 | RXD_2 | CSI_0 | ADC_0 | PWM_3 | WS_0 | CLK | |
+| GPIO_13 | LOG_TXD_0/RTS_2 | | ADC_6 | PWM_4 | | D0 | SDA_0 |
+
+
+
+
+
+## Direction Structure
+
+The root directory of GenkiPi SDK package is `device/itcast/genkipi/`:
+
+```bash
+device/itcast/genkipi
+├── BUILD.gn # GN build script
+├── interfaces # custom interface
+└── sdk_liteos # Liteos kernel directory
+ ├── app # Application layer code (including demo program as a reference example).
+ ├── boot # Flash bootloader code.
+ ├── build # The library files, link files, and configuration files needed for SDK building.
+ ├── BUILD.gn # GN build script
+ ├── build_patch.sh # Used to decompress uboot open source source package and patch.
+ ├── build.sh # Start the compilation script and support "sh build.sh. menuconfig" for customized configuration.
+ ├── components # SDK platform related components.
+ ├── config # SDK system configuration file.
+ ├── config.gni # Support OpenHarmony configuration file.
+ ├── factory.mk # The factory test version compilation script.
+ ├── hm_build.sh # Adapt to OpenHarmony build script.
+ ├── include # API header file storage directory.
+ ├── license # SDK open source license statement.
+ ├── Makefile # Support make compilation, use "make" or "make all" to start compilation.
+ ├── non_factory.mk # Non-factory test version compilation script.
+ ├── platform # SDK platform related files (including: kernel image, driver module, etc.).
+ ├── SConstruct # SCons compile script.
+ ├── third_party # Open source third-party software directory.
+ └── tools # Tools provided by the SDK on Linux and Windows systems (including: NV creation tools, signature tools, Menuconfig, etc.).
+```
+
+
+
+## Compilation
+
+### Source Download
+
+1. repo tool install。if had install it , omit this step.
+
+ ```bash
+ curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > repo
+ sudo mv repo /usr/local/bin/repo
+ sudo chmod a+x /usr/local/bin/repo
+ python3 -m pip install -i https://repo.huaweicloud.com/repository/pypi/simple requests
+ ```
+
+2. download source
+
+ ```bash
+ repo init -u https://gitee.com/openharmony-sig/manifest.git -b master --no-repo-verify -m devboard_itcast_genkipi.xml
+ repo sync -c
+ repo forall -c 'git lfs pull'
+ ```
+
+### Compile Code
+
+1. choose devboard
+
+ ```bash
+ hb set
+ ```
+
+ choose itcast genkipi
+
+2. compile
+
+ ```bash
+ hb build
+ ```
+
+### Burn Bin
+
+burn bin with Hiburn tool.
-#### Contribution
-1. Fork the repository
-2. Create Feat_xxx branch
-3. Commit your code
-4. Create Pull Request
-#### Gitee Feature
-1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
-2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
-3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
-4. The most valuable open source project [GVP](https://gitee.com/gvp)
-5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
-6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
diff --git a/README.md b/README.md
old mode 100644
new mode 100755
index 2b2d963c313095c86c750832d8e72fd2f9bf3711..aba962085d5a390a8ac2a3dc6ca4937de4d3bb82
--- a/README.md
+++ b/README.md
@@ -1,39 +1,109 @@
-# devboard_device_itcast_genkipi
+# 传智教育元气派GenkiPi
-#### 介绍
-{**以下是 Gitee 平台说明,您可以替换此简介**
-Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
-无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
+- [简介](#section1)
+- [目录](#section2)
+- [编译指导](#section3)
-#### 软件架构
-软件架构说明
-#### 安装教程
+## 简介
-1. xxxx
-2. xxxx
-3. xxxx
+元气派GenKiPi开发板由传智播客教育科技股份有限公司出品,搭载OpenHarmony2.0操作系统;基于海思HI3861模组, 160MHz主频、SRAM 352KB、ROM 288KB、2M Flash。支持SPI、IIC、UART、ADC、PWM等开发协议, 广泛适用于智能穿戴、智能安防和工业物联网场景。
-#### 使用说明
+
-1. xxxx
-2. xxxx
-3. xxxx
+| 引脚 | Uart | SPI | ADC | PWM | I2S | SDIO | I2C |
+| :-----: | :-------------: | :---: | :---: | :---: | :---: | :--: | :---: |
+| GPIO_07 | CTS_1 | RXD_0 | ADC_3 | PWM_0 | CLK_0 | | |
+| GPIO_08 | RTS_1 | TXD_0 | | PWM_1 | WS_0 | | |
+| GPIO_10 | CTS_2 | CLK_0 | | PWM_1 | TX_0 | D3 | SDA_0 |
+| GPIO_09 | RTS_2 | TXD_0 | ADC_4 | PWM_0 | MCK_0 | D2 | SCL_0 |
+| GPIO_03 | LOG_TXD_0 | | | | | | |
+| GPIO_04 | LOG_RXD_0 | | ADC_1 | | | | |
+| GPIO_02 | | | | PWM_2 | MCK_0 | | |
+| GPIO_05 | RXD_1 | CSI_0 | ADC_2 | PWM_2 | TX_0 | | |
+| GPIO_06 | TXD_1 | CLK_0 | | PWM_3 | | | |
+| GPIO_14 | LOG_RXD_0/CTS_2 | | | PWM_5 | RX_0 | D1 | SCL_0 |
+| GPIO_11 | TXD_2 | RXD_0 | ADC_5 | PWM_2 | CLK_0 | CMD | |
+| GPIO_12 | RXD_2 | CSI_0 | ADC_0 | PWM_3 | WS_0 | CLK | |
+| GPIO_13 | LOG_TXD_0/RTS_2 | | ADC_6 | PWM_4 | | D0 | SDA_0 |
-#### 参与贡献
-1. Fork 本仓库
-2. 新建 Feat_xxx 分支
-3. 提交代码
-4. 新建 Pull Request
-#### 特技
-1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
-2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
-3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
-4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
-5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
-6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
+## 目录
+
+GenkiPi 的SDK软件包根目录所在位姿为`device/itcast/genkipi/`, 如下所示:
+
+```bash
+device/itcast/genkipi
+├── BUILD.gn # GN构建脚本
+├── interfaces # 自定义接口
+└── sdk_liteos # Liteos内核目录
+ ├── app # 应用层代码(其中包含demo程序为参考示例)。
+ ├── boot # Flash bootloader代码。
+ ├── build # SDK构建所需的库文件、链接文件、配置文件。
+ ├── BUILD.gn # GN构建脚本
+ ├── build_patch.sh # 用于解压uboot开源源码包和打patch。
+ ├── build.sh # 启动编译脚本,同时支持“sh build.sh。 menuconfig”进行客制化配置。
+ ├── components # SDK平台相关的组件。
+ ├── config # SDK系统配置文件。
+ ├── config.gni # 支持OpenHarmony配置文件。
+ ├── factory.mk # 厂测版本编译脚本。
+ ├── hm_build.sh # 适配OpenHarmony构建脚本。
+ ├── include # API头文件存放目录。
+ ├── license # SDK开源license声明。
+ ├── Makefile # 支持make编译,使用“make”或“make all”启动编译。
+ ├── non_factory.mk # 非厂测版本编译脚本。
+ ├── platform # SDK平台相关的文件(包括:内核镜像、驱动模块等)。
+ ├── SConstruct # SCons编译脚本。
+ ├── third_party # 开源第三方软件目录。
+ └── tools # SDK提供的Linux系统和Windows系统上使用的工具(包括:NV制作工具、签名工具、Menuconfig等)。
+```
+
+
+
+## 编译指导
+
+### 源码下载
+
+1. repo工具准备。如果已经安装过repo工具,此步骤省略
+
+ ```bash
+ curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > repo
+ sudo mv repo /usr/local/bin/repo
+ sudo chmod a+x /usr/local/bin/repo
+ python3 -m pip install -i https://repo.huaweicloud.com/repository/pypi/simple requests
+ ```
+
+2. 源码下载
+
+ ```bash
+ repo init -u https://gitee.com/openharmony-sig/manifest.git -b master --no-repo-verify -m devboard_itcast_genkipi.xml
+ repo sync -c
+ repo forall -c 'git lfs pull'
+ ```
+
+### 编译代码
+
+1. 选择开发板
+
+ ```bash
+ hb set
+ ```
+
+ 选中 itcast 下的genkipi 即可
+
+2. 编译
+
+ ```bash
+ hb build
+ ```
+
+### 烧录
+
+通过 hiburn 工具将 out 目录下 allinOne.bin文件进行烧录
+
+
+
diff --git a/asserts/back.png b/asserts/back.png
new file mode 100755
index 0000000000000000000000000000000000000000..0f75c175e71929237de8b7ec2d8da308aac2df0d
Binary files /dev/null and b/asserts/back.png differ
diff --git a/asserts/board.png b/asserts/board.png
new file mode 100755
index 0000000000000000000000000000000000000000..a4beee33ee5ef6d8d294dc6edf7c9339e3c548e8
Binary files /dev/null and b/asserts/board.png differ
diff --git a/asserts/front.png b/asserts/front.png
new file mode 100755
index 0000000000000000000000000000000000000000..a51e9025d63614b295454e5d2ee9db0b424aaf34
Binary files /dev/null and b/asserts/front.png differ
diff --git a/hi3861_adapter/LICENSE b/hi3861_adapter/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..2bb9ad240fa04c8cf706a4901c4807878e90c2dc
--- /dev/null
+++ b/hi3861_adapter/LICENSE
@@ -0,0 +1,176 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
\ No newline at end of file
diff --git a/hi3861_adapter/hals/communication/wifi_lite/wifiaware/BUILD.gn b/hi3861_adapter/hals/communication/wifi_lite/wifiaware/BUILD.gn
new file mode 100755
index 0000000000000000000000000000000000000000..0f20ca095beed8b60bc1af316c281787e33f1b1d
--- /dev/null
+++ b/hi3861_adapter/hals/communication/wifi_lite/wifiaware/BUILD.gn
@@ -0,0 +1,23 @@
+# Copyright (c) 2020 Huawei Device Co., Ltd.
+# 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.
+
+import("//build/lite/config/component/lite_component.gni")
+
+static_library("hal_wifiaware") {
+ sources = [ "source/hal_wifiaware.c" ]
+ include_dirs = [
+ "//device/itcast/genkipi/sdk_liteos/include",
+ "//device/itcast/genkipi/sdk_liteos/third_party/mbedtls-2.16.2/include",
+ "//foundation/communication/wifi_aware/interfaces/kits",
+ ]
+}
diff --git a/hi3861_adapter/hals/communication/wifi_lite/wifiaware/source/hal_wifiaware.c b/hi3861_adapter/hals/communication/wifi_lite/wifiaware/source/hal_wifiaware.c
new file mode 100644
index 0000000000000000000000000000000000000000..cb869a177e22602d8934e58523a7e705b0669a45
--- /dev/null
+++ b/hi3861_adapter/hals/communication/wifi_lite/wifiaware/source/hal_wifiaware.c
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * 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 "hi_cipher.h"
+#include "hi_wifi_api.h"
+#include "hi_wifi_sdp_api.h"
+#include "wifiaware.h"
+
+int HalWifiSdpInit(const char* ifname)
+{
+ if (hi_wifi_sdp_init(ifname) != HISI_OK) {
+ return -1;
+ }
+ return 0;
+}
+
+unsigned int HalCipherHashSha256(const char* input, unsigned int inputLen, unsigned char* hash, unsigned hashLen)
+{
+ if (hi_cipher_hash_sha256((uintptr_t)input, inputLen, hash, hashLen) != HISI_OK) {
+ return -1;
+ }
+ return 0;
+}
+
+int HalWifiSdpStartService(const char* svcName, unsigned char localHandle, RecvCallback recvCB, unsigned char role)
+{
+ if (hi_wifi_sdp_start_service(svcName, localHandle, (hi_wifi_sdp_recv_cb)recvCB, role) != HISI_OK) {
+ return -1;
+ }
+ return 0;
+}
+
+int HalWifiSdpSend(unsigned char* macAddr, unsigned char peerHandle, unsigned char localHandle,
+ unsigned char* msg, int len)
+{
+ if (hi_wifi_sdp_send(macAddr, peerHandle, localHandle, msg, len) != HISI_OK) {
+ return -1;
+ }
+ return 0;
+}
+
+int HalWifiSdpStopService(unsigned char localHandle, unsigned char role)
+{
+ if (hi_wifi_sdp_stop_service(localHandle, role) != HISI_OK) {
+ return -1;
+ }
+ return 0;
+}
+
+int HalWifiSdpDeinit(void)
+{
+ if (hi_wifi_sdp_deinit() != HISI_OK) {
+ return -1;
+ }
+ return 0;
+}
+
+int HalWifiSdpAdjustTxPower(const char *ifname, signed char power)
+{
+ if (hi_wifi_sdp_adjust_tx_power(ifname, power) != HISI_OK) {
+ return -1;
+ }
+ return 0;
+}
+
+int HalWifiSdpRestoreTxPower(const char *ifname)
+{
+ if (hi_wifi_sdp_restore_tx_power(ifname) != HISI_OK) {
+ return -1;
+ }
+ return 0;
+}
+
+int HalWifiSdpBeaconSwitch(const char *ifname, unsigned char enable)
+{
+ if (hi_wifi_sdp_beacon_switch(ifname, enable) != HISI_OK) {
+ return -1;
+ }
+ return 0;
+}
+
+int HalWifiSdpSetRetryTimes(unsigned int retries)
+{
+ if (hi_wifi_sdp_set_retry_times(retries) != HISI_OK) {
+ return -1;
+ }
+ return 0;
+}
+
+int HalWifiSdpGetSyncMode(void)
+{
+ return hi_wifi_sdp_get_sync_mode();
+}
\ No newline at end of file
diff --git a/hi3861_adapter/hals/communication/wifi_lite/wifiservice/BUILD.gn b/hi3861_adapter/hals/communication/wifi_lite/wifiservice/BUILD.gn
new file mode 100755
index 0000000000000000000000000000000000000000..d1af21e4e5195f009209873bf5754e52b784da6a
--- /dev/null
+++ b/hi3861_adapter/hals/communication/wifi_lite/wifiservice/BUILD.gn
@@ -0,0 +1,34 @@
+# Copyright (c) 2020 Huawei Device Co., Ltd.
+# 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.
+import("//build/lite/ndk/ndk.gni")
+static_library("wifiservice") {
+ sources = [
+ "source/wifi_device.c",
+ "source/wifi_device_util.c",
+ "source/wifi_hotspot.c",
+ ]
+ include_dirs = [
+ "//device/itcast/genkipi/sdk_liteos/include",
+ "//foundation/communication/wifi_lite/interfaces/wifiservice",
+ "//kernel/liteos_m/kal",
+ "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr",
+ ]
+}
+if (ohos_kernel_type == "liteos_m") {
+ ndk_lib("wifiservice_ndk") {
+ deps = [ ":wifiservice" ]
+
+ head_files =
+ [ "//foundation/communication/wifi_lite/interfaces/wifiservice" ]
+ }
+}
diff --git a/hi3861_adapter/hals/communication/wifi_lite/wifiservice/source/wifi_device.c b/hi3861_adapter/hals/communication/wifi_lite/wifiservice/source/wifi_device.c
new file mode 100755
index 0000000000000000000000000000000000000000..a4d53fd4dd41df8c6edcc7a7878784d8830fb283
--- /dev/null
+++ b/hi3861_adapter/hals/communication/wifi_lite/wifiservice/source/wifi_device.c
@@ -0,0 +1,990 @@
+/*
+ * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * 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 "wifi_device.h"
+
+#include
+#include
+#include
+
+#include "lwip/if_api.h"
+#include "lwip/netifapi.h"
+#include "wifi_device_util.h"
+#include "wifi_hotspot_config.h"
+#include "utils_file.h"
+
+#define WIFI_RECONN_POLICY_ENABLE 1
+#define WIFI_RECONN_POLICY_TIMEOUT 0xFFFF
+#define WIFI_RECONN_POLICY_PERIOD 100
+#define WIFI_RECONN_POLICY_MAX_TRY_COUNT 100
+#define WIFI_DISCONNECT_REASON_NO_AP 1
+#define WIFI_DEFAULT_KEY_FOR_PSK "wifipskmode"
+#define WLAN_STA_NAME "wlan0"
+#define WIFI_FILE "/usrdata/hilink/wifi.cfg"
+#define WIFI_FILE_EXIST 1
+#define WIFI_FILE_UNEXIST 0
+
+static int g_wifiStaStatus = WIFI_STA_NOT_ACTIVE;
+static WifiDeviceConfig g_wifiConfigs[WIFI_MAX_CONFIG_SIZE] = {
+ {0}, {0}, {0}, 0, WIFI_CONFIG_INVALID, 0, 0, UNKNOWN, {0, 0, {0, 0}, 0}
+};
+static WifiEvent* g_wifiEvents[WIFI_MAX_EVENT_SIZE] = {0};
+static int g_connectState = WIFI_STATE_NOT_AVALIABLE;
+static int g_networkId = -1;
+static bool g_networkConfigReadFlag = false;
+static int g_isNetworkConfigExist = WIFI_FILE_UNEXIST;
+
+static bool IsFileExist(const char* path)
+{
+ if (path == NULL) {
+ return false;
+ }
+ int32_t fd = UtilsFileOpen(path, O_RDONLY_FS, 0);
+ if (fd < 0) {
+ return false;
+ }
+ (void)UtilsFileClose(fd);
+ return true;
+}
+
+static int WriteNetworkConfig(const unsigned char *buf, unsigned int len)
+{
+ int fd;
+
+ if (buf == 0) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ fd = UtilsFileOpen(WIFI_FILE, O_RDWR_FS | O_CREAT_FS | O_TRUNC_FS, 0);
+ if (fd < 0) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ if (UtilsFileWrite(fd, (const char *)buf, len) < 0) {
+ UtilsFileClose(fd);
+ return ERROR_WIFI_UNKNOWN;
+ }
+ UtilsFileClose(fd);
+
+ return WIFI_SUCCESS;
+}
+
+static int ReadNetworkConfig(unsigned char *buf, unsigned int len)
+{
+ int fd;
+ unsigned int fileLen = 0;
+ int ret;
+ bool isFileExist = false;
+
+ if (buf == NULL) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ if (IsFileExist(WIFI_FILE) == true) {
+ isFileExist = true;
+ g_isNetworkConfigExist = WIFI_FILE_EXIST;
+ } else {
+ g_isNetworkConfigExist = WIFI_FILE_UNEXIST;
+ }
+
+ fd = UtilsFileOpen(WIFI_FILE, O_RDWR_FS | O_CREAT_FS, 0);
+ if (fd < 0) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ ret = UtilsFileStat(WIFI_FILE, &fileLen);
+ if (ret != WIFI_SUCCESS) {
+ UtilsFileClose(fd);
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ ret = UtilsFileSeek(fd, 0, SEEK_SET_FS);
+ if (ret != WIFI_SUCCESS) {
+ UtilsFileClose(fd);
+ return ERROR_WIFI_UNKNOWN;
+ }
+ if (fileLen > len) {
+ UtilsFileClose(fd);
+ return ERROR_WIFI_UNKNOWN;
+ }
+ if (isFileExist == true) {
+ ret = UtilsFileRead(fd, (char *)buf, len);
+ if (ret < 0) {
+ UtilsFileClose(fd);
+ return ERROR_WIFI_UNKNOWN;
+ }
+ }
+ UtilsFileClose(fd);
+ return WIFI_SUCCESS;
+}
+
+static void DispatchScanStateChangeEvent(const hi_wifi_event* hisiEvent,
+ const WifiEvent* hosEvent, WifiEventState event)
+{
+ if (hosEvent->OnWifiScanStateChanged == NULL) {
+ return;
+ }
+
+ int size = 0;
+ if (event == WIFI_STATE_NOT_AVALIABLE) {
+ hosEvent->OnWifiScanStateChanged(event, size);
+ return;
+ }
+
+ if (hisiEvent->event == HI_WIFI_EVT_SCAN_DONE) {
+ size = hisiEvent->info.wifi_scan_done.bss_num;
+ hosEvent->OnWifiScanStateChanged(event, size);
+ }
+}
+
+static void StaSetLocaladdr(const struct netif *netif, int gw, int ipaddr, int netmask)
+{
+ ip4_addr_t st_gw;
+ ip4_addr_t st_ipaddr;
+ ip4_addr_t st_netmask;
+
+ if (netif == NULL) {
+ printf("hisi_reset_addr::Null param of netdev\r\n");
+ return;
+ }
+
+ ip4_addr_set_u32(&st_gw, gw);
+ ip4_addr_set_u32(&st_ipaddr, ipaddr);
+ ip4_addr_set_u32(&st_netmask, netmask);
+ netifapi_netif_set_addr(netif, &st_ipaddr, &st_netmask, &st_gw);
+ return;
+}
+
+static void StaSetDNSServer(int switcher)
+{
+ ip4_addr_t tmp_dns_ser[WIFI_MAX_DNS_NUM];
+ for (int i = 0; i < WIFI_MAX_DNS_NUM; i++) {
+ if (switcher == HI_WIFI_EVT_CONNECTED) {
+ ip4_addr_set_u32(&tmp_dns_ser[i], g_wifiConfigs[g_networkId].staticIp.dnsServers[i]);
+ } else {
+ ip4_addr_set_u32(&tmp_dns_ser[i], 0);
+ }
+ lwip_dns_setserver(i, &tmp_dns_ser[i]);
+ }
+ return;
+}
+
+static void StaSetWifiNetConfig(int switcher)
+{
+ struct netif *netif_node = netif_find(WLAN_STA_NAME);
+ if (netif_node == NULL) {
+ printf("[wifi_service]:DispatchConnectEvent netif get fail\r\n");
+ return;
+ }
+ if (switcher == HI_WIFI_EVT_CONNECTED) {
+ if (g_wifiConfigs[g_networkId].ipType == DHCP) {
+ netifapi_dhcp_start(netif_node);
+ } else if (g_wifiConfigs[g_networkId].ipType == STATIC) {
+ (void)netifapi_netif_set_link_up(netif_node);
+ StaSetLocaladdr(netif_node, g_wifiConfigs[g_networkId].staticIp.gateway,
+ g_wifiConfigs[g_networkId].staticIp.ipAddress, g_wifiConfigs[g_networkId].staticIp.netmask);
+ (void)netifapi_netif_set_up(netif_node);
+ StaSetDNSServer(HI_WIFI_EVT_CONNECTED);
+ }
+ } else if (switcher == HI_WIFI_EVT_DISCONNECTED) {
+ if (g_wifiConfigs[g_networkId].ipType == DHCP) {
+ netifapi_dhcp_stop(netif_node);
+ StaSetLocaladdr(netif_node, 0, 0, 0);
+ } else if (g_wifiConfigs[g_networkId].ipType == STATIC) {
+ (void)netifapi_netif_set_link_down(netif_node);
+ (void)netifapi_netif_set_down(netif_node);
+ StaSetLocaladdr(netif_node, 0, 0, 0);
+ StaSetDNSServer(HI_WIFI_EVT_DISCONNECTED);
+ }
+ }
+ return;
+}
+
+static void DispatchConnectEvent(const hi_wifi_event* hisiEvent, const WifiEvent* hosEvent)
+{
+ if (hosEvent->OnWifiConnectionChanged == NULL) {
+ return;
+ }
+
+ int cpyErr;
+ WifiLinkedInfo info = {0};
+
+ if (hisiEvent->event == HI_WIFI_EVT_CONNECTED) {
+ g_connectState = WIFI_STATE_AVALIABLE;
+ cpyErr = memcpy_s(&info.ssid, WIFI_MAX_SSID_LEN,
+ hisiEvent->info.wifi_connected.ssid, HI_WIFI_MAX_SSID_LEN + 1);
+ if (cpyErr != EOK) {
+ printf("[wifi_service]:DispatchConnectEvent memcpy failed, err = %d\n", cpyErr);
+ return;
+ }
+
+ cpyErr = memcpy_s(&info.bssid, WIFI_MAC_LEN,
+ hisiEvent->info.wifi_connected.bssid, HI_WIFI_MAC_LEN);
+ if (cpyErr != EOK) {
+ printf("[wifi_service]:DispatchConnectEvent memcpy failed, err = %d\n", cpyErr);
+ return;
+ }
+
+ StaSetWifiNetConfig(HI_WIFI_EVT_CONNECTED);
+ hosEvent->OnWifiConnectionChanged(WIFI_STATE_AVALIABLE, &info);
+ return;
+ }
+
+ if (hisiEvent->event == HI_WIFI_EVT_STA_FCON_NO_NETWORK && g_connectState == WIFI_STATE_AVALIABLE) {
+ return;
+ }
+
+ info.disconnectedReason = WIFI_DISCONNECT_REASON_NO_AP;
+
+ if (hisiEvent->event == HI_WIFI_EVT_DISCONNECTED) {
+ cpyErr = memcpy_s(&info.bssid, WIFI_MAC_LEN,
+ hisiEvent->info.wifi_disconnected.bssid, HI_WIFI_MAC_LEN);
+ if (cpyErr != EOK) {
+ printf("[wifi_service]:DispatchConnectEvent memcpy failed, err = %d\n", cpyErr);
+ return;
+ }
+ info.disconnectedReason = hisiEvent->info.wifi_disconnected.reason_code;
+ }
+
+ StaSetWifiNetConfig(HI_WIFI_EVT_DISCONNECTED);
+ hosEvent->OnWifiConnectionChanged(WIFI_STATE_NOT_AVALIABLE, &info);
+}
+
+static void DispatchStaConnectEvent(const hi_wifi_event* hisiEvent, const WifiEvent* hosEvent)
+{
+ int cpyErr;
+ StationInfo info = {0};
+ if (hisiEvent->event == HI_WIFI_EVT_STA_CONNECTED) {
+ if (hosEvent->OnHotspotStaJoin == NULL) {
+ return;
+ }
+
+ cpyErr = memcpy_s(&info.macAddress, WIFI_MAC_LEN,
+ hisiEvent->info.ap_sta_connected.addr, HI_WIFI_MAC_LEN);
+ if (cpyErr != EOK) {
+ printf("[wifi_service]:DispatchStaConnectEvent memcpy failed, err = %d\n", cpyErr);
+ return;
+ }
+
+ hosEvent->OnHotspotStaJoin(&info);
+ return;
+ }
+
+ if (hosEvent->OnHotspotStaLeave == NULL) {
+ return;
+ }
+
+ cpyErr = memcpy_s(&info.macAddress, WIFI_MAC_LEN,
+ hisiEvent->info.ap_sta_disconnected.addr, HI_WIFI_MAC_LEN);
+ if (cpyErr != EOK) {
+ printf("[wifi_service]:DispatchStaConnectEvent memcpy failed, err = %d\n", cpyErr);
+ return;
+ }
+ info.disconnectedReason = hisiEvent->info.ap_sta_disconnected.reason_code;
+ hosEvent->OnHotspotStaLeave(&info);
+}
+
+static void DispatchApStartEvent(const WifiEvent* hosEvent)
+{
+ if (hosEvent->OnHotspotStateChanged == NULL) {
+ return;
+ }
+
+ hosEvent->OnHotspotStateChanged(WIFI_STATE_AVALIABLE);
+}
+
+static void DispatchEvent(const hi_wifi_event* hisiEvent, const WifiEvent* hosEvent)
+{
+ switch (hisiEvent->event) {
+ case HI_WIFI_EVT_SCAN_DONE:
+ DispatchScanStateChangeEvent(hisiEvent, hosEvent, WIFI_STATE_AVALIABLE);
+ break;
+ case HI_WIFI_EVT_CONNECTED:
+ case HI_WIFI_EVT_DISCONNECTED:
+ case HI_WIFI_EVT_STA_FCON_NO_NETWORK:
+ DispatchConnectEvent(hisiEvent, hosEvent);
+ break;
+ case HI_WIFI_EVT_STA_CONNECTED:
+ case HI_WIFI_EVT_STA_DISCONNECTED:
+ DispatchStaConnectEvent(hisiEvent, hosEvent);
+ break;
+ case HI_WIFI_EVT_AP_START:
+ DispatchApStartEvent(hosEvent);
+ break;
+ default:
+ // event not supported in current version, do nothing
+ break;
+ }
+}
+
+static void HiWifiWpaEventCb(const hi_wifi_event *hisiEvent)
+{
+ if (hisiEvent == NULL) {
+ return;
+ }
+ if (LockWifiEventLock() != WIFI_SUCCESS) {
+ return;
+ }
+ for (int i = 0; i < WIFI_MAX_EVENT_SIZE; i++) {
+ if (g_wifiEvents[i] == NULL) {
+ continue;
+ }
+ DispatchEvent(hisiEvent, g_wifiEvents[i]);
+ }
+ if (UnlockWifiEventLock() != WIFI_SUCCESS) {
+ return;
+ }
+}
+
+static void RegisterHisiCallback(void)
+{
+ int hiRet = hi_wifi_register_event_callback(HiWifiWpaEventCb);
+ if (hiRet != HISI_OK) {
+ printf("[wifi_service]:RegisterHisiCallback register callback failed\n");
+ }
+ hiRet = hi_wifi_config_callback(1, 0, 0);
+ if (hiRet != HISI_OK) {
+ printf("[wifi_service]:ConfigHisiCallback failed\n");
+ }
+}
+
+WifiErrorCode EnableWifi(void)
+{
+ if (LockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ if (g_wifiStaStatus == WIFI_STA_ACTIVE) {
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_BUSY;
+ }
+
+ char ifName[WIFI_IFNAME_MAX_SIZE + 1] = {0};
+ int len = sizeof(ifName);
+ int hiRet;
+
+ hiRet = hi_wifi_sta_start(ifName, &len);
+ if (hiRet != HISI_OK) {
+ printf("[wifi_service]:EnableWifi sta start fail\n");
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_NOT_STARTED;
+ }
+
+ hiRet = hi_wifi_sta_set_reconnect_policy(WIFI_RECONN_POLICY_ENABLE, WIFI_RECONN_POLICY_TIMEOUT,
+ WIFI_RECONN_POLICY_PERIOD, WIFI_RECONN_POLICY_MAX_TRY_COUNT);
+ if (hiRet != HISI_OK) {
+ printf("[wifi_service]:EnableWifi set reconn policy fail\n");
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ g_wifiStaStatus = WIFI_STA_ACTIVE;
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ return WIFI_SUCCESS;
+}
+
+WifiErrorCode DisableWifi(void)
+{
+ if (LockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ if (g_wifiStaStatus == WIFI_STA_NOT_ACTIVE) {
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_NOT_STARTED;
+ }
+
+ int hiRet;
+
+ hiRet = hi_wifi_sta_stop();
+ if (hiRet != HISI_OK) {
+ printf("[wifi_service]:DisableWifi failed to stop sta\n");
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_NOT_STARTED;
+ }
+
+ g_wifiStaStatus = WIFI_STA_NOT_ACTIVE;
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ return WIFI_SUCCESS;
+}
+
+int IsWifiActive(void)
+{
+ if (LockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ int ret = g_wifiStaStatus;
+
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ret;
+}
+
+WifiErrorCode Scan(void)
+{
+ if (LockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ if (g_wifiStaStatus == WIFI_STA_NOT_ACTIVE) {
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_NOT_STARTED;
+ }
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ if (LockWifiEventLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ for (int i = 0; i < WIFI_MAX_EVENT_SIZE; i++) {
+ if (g_wifiEvents[i] == NULL) {
+ continue;
+ }
+ DispatchScanStateChangeEvent(NULL, g_wifiEvents[i], WIFI_STATE_NOT_AVALIABLE);
+ }
+ if (UnlockWifiEventLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ int hiRet;
+
+ hiRet = hi_wifi_sta_scan();
+ if (hiRet != HISI_OK) {
+ printf("[wifi_service]:Scan failed to start sta scan\n");
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ return WIFI_SUCCESS;
+}
+
+static hi_wifi_scan_type ScanTypeSwitch(WifiScanType type)
+{
+ hi_wifi_scan_type ret = HI_WIFI_BASIC_SCAN;
+
+ switch (type) {
+ case WIFI_FREQ_SCAN:
+ ret = HI_WIFI_CHANNEL_SCAN;
+ break;
+ case WIFI_SSID_SCAN:
+ ret = HI_WIFI_SSID_SCAN;
+ break;
+ case WIFI_BSSID_SCAN:
+ ret = HI_WIFI_BSSID_SCAN;
+ break;
+ default:
+ break;
+ }
+
+ return ret;
+}
+
+WifiErrorCode AdvanceScan(WifiScanParams *params)
+{
+ if (params == NULL) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ if (LockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ if (g_wifiStaStatus == WIFI_STA_NOT_ACTIVE) {
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_NOT_STARTED;
+ }
+
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ if (LockWifiEventLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ for (int i = 0; i < WIFI_MAX_EVENT_SIZE; i++) {
+ if (g_wifiEvents[i] == NULL) {
+ continue;
+ }
+ DispatchScanStateChangeEvent(NULL, g_wifiEvents[i], WIFI_STATE_NOT_AVALIABLE);
+ }
+ if (UnlockWifiEventLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ int hiRet;
+ int cpyErr;
+ hi_wifi_scan_params sp = {0};
+
+ cpyErr = memcpy_s(sp.ssid, sizeof(sp.ssid), params->ssid, params->ssidLen);
+ if (cpyErr != EOK) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ cpyErr = memcpy_s(sp.bssid, sizeof(sp.bssid), params->bssid, sizeof(params->bssid));
+ if (cpyErr != EOK) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ sp.ssid_len = params->ssidLen;
+ sp.scan_type = ScanTypeSwitch(params->scanType);
+ sp.channel = FrequencyToChannel(params->freqs);
+
+ hiRet = hi_wifi_sta_advance_scan(&sp);
+ if (hiRet != HISI_OK) {
+ printf("[wifi_service]:Advance Scan failed\n");
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ return WIFI_SUCCESS;
+}
+
+WifiErrorCode GetScanInfoList(WifiScanInfo* result, unsigned int* size)
+{
+ if (result == NULL || size == NULL || *size == 0) {
+ return ERROR_WIFI_INVALID_ARGS;
+ }
+
+ unsigned int num = WIFI_SCAN_HOTSPOT_LIMIT;
+
+ hi_wifi_ap_info *pstResults = malloc(sizeof(hi_wifi_ap_info) * WIFI_SCAN_HOTSPOT_LIMIT);
+ if (pstResults == NULL) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ int hiRet = hi_wifi_sta_scan_results(pstResults, &num);
+ if (hiRet != HISI_OK) {
+ printf("[wifi_service]:GetScanInfoList hi_wifi_sta_scan_results fail\n");
+ free(pstResults);
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ if (*size < num) {
+ free(pstResults);
+ return ERROR_WIFI_INVALID_ARGS;
+ }
+
+ int cpyErr;
+ for (unsigned int i = 0; i < num; i++) {
+ cpyErr = memcpy_s(result[i].ssid, WIFI_MAX_SSID_LEN, pstResults[i].ssid, HI_WIFI_MAX_SSID_LEN + 1);
+ if (cpyErr != EOK) {
+ free(pstResults);
+ printf("[wifi_service]:GetScanInfoList memcpy failed, err = %d\n", cpyErr);
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ cpyErr = memcpy_s(result[i].bssid, WIFI_MAC_LEN, pstResults[i].bssid, HI_WIFI_MAC_LEN);
+ if (cpyErr != EOK) {
+ free(pstResults);
+ printf("[wifi_service]:GetScanInfoList memcpy failed, err = %d\n", cpyErr);
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ result[i].securityType = HiSecToHoSec(pstResults[i].auth);
+ result[i].rssi = pstResults[i].rssi;
+ result[i].frequency = ChannelToFrequency(pstResults[i].channel);
+ }
+
+ free(pstResults);
+ *size = num;
+
+ return WIFI_SUCCESS;
+}
+
+WifiErrorCode AddDeviceConfig(const WifiDeviceConfig* config, int* result)
+{
+ if (config == NULL || result == NULL) {
+ return ERROR_WIFI_INVALID_ARGS;
+ }
+
+ int netId = WIFI_CONFIG_INVALID;
+ if (LockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ for (int i = 0; i < WIFI_MAX_CONFIG_SIZE; i++) {
+ if (g_wifiConfigs[i].netId != i) {
+ netId = i;
+ break;
+ }
+ }
+
+ if (netId == WIFI_CONFIG_INVALID) {
+ printf("[wifi_service]:AddDeviceConfig wifi config is full, delete one first\n");
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_BUSY;
+ }
+
+ int cpyErr = memcpy_s(&g_wifiConfigs[netId], sizeof(WifiDeviceConfig), config, sizeof(WifiDeviceConfig));
+ if (cpyErr != EOK) {
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ printf("[wifi_service]:AddDeviceConfig memcpy failed, err = %d\n", cpyErr);
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ g_wifiConfigs[netId].netId = netId;
+ if (WriteNetworkConfig((unsigned char *)&g_wifiConfigs[netId], sizeof(WifiDeviceConfig)) != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ *result = netId;
+ return WIFI_SUCCESS;
+}
+
+WifiErrorCode GetDeviceConfigs(WifiDeviceConfig* result, unsigned int* size)
+{
+ if (result == NULL || size == NULL) {
+ return ERROR_WIFI_INVALID_ARGS;
+ }
+
+ unsigned int retIndex = 0;
+
+ if (LockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ if (g_networkConfigReadFlag == false) {
+ g_networkConfigReadFlag = true;
+ if (ReadNetworkConfig((unsigned char *)&g_wifiConfigs[0], sizeof(WifiDeviceConfig)) != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ if (g_isNetworkConfigExist == WIFI_FILE_UNEXIST) {
+ g_wifiConfigs[0].netId = WIFI_CONFIG_INVALID;
+ }
+ }
+
+ for (int i = 0; i < WIFI_MAX_CONFIG_SIZE; i++) {
+ if (g_wifiConfigs[i].netId != i) {
+ continue;
+ }
+
+ int cpyErr = memcpy_s(&result[retIndex], sizeof(WifiDeviceConfig), &g_wifiConfigs[i], sizeof(WifiDeviceConfig));
+ if (cpyErr != EOK) {
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ printf("[wifi_service]:GetDeviceConfig memcpy failed, err = %d\n", cpyErr);
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ retIndex++;
+ if (*size < retIndex) {
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_INVALID_ARGS;
+ }
+ }
+
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ if (retIndex == 0) {
+ return ERROR_WIFI_NOT_AVAILABLE;
+ }
+
+ *size = retIndex;
+ return WIFI_SUCCESS;
+}
+
+static WifiErrorCode StaConnect(unsigned int chan, hi_wifi_assoc_request *assocReq, int pskType)
+{
+ int hiRet = 0;
+ int lastState = g_connectState;
+
+ g_connectState = WIFI_STATE_NOT_AVALIABLE;
+ if (chan == 0) {
+ hiRet = hi_wifi_sta_connect(assocReq);
+ } else {
+ hi_wifi_fast_assoc_request fastReq = {0};
+ fastReq.channel = chan;
+ hiRet += memcpy_s(&fastReq.req, sizeof(hi_wifi_assoc_request), assocReq, sizeof(hi_wifi_assoc_request));
+ if (pskType == WIFI_PSK_TYPE_HEX) {
+ hiRet += memcpy_s(fastReq.req.key, sizeof(fastReq.req.key),
+ WIFI_DEFAULT_KEY_FOR_PSK, sizeof(WIFI_DEFAULT_KEY_FOR_PSK));
+ hiRet += memcpy_s(fastReq.psk, sizeof(fastReq.psk), assocReq->key, HI_WIFI_STA_PSK_LEN);
+ fastReq.psk_flag = HI_WIFI_WPA_PSK_USE_OUTER;
+ }
+ if (hiRet != EOK) {
+ printf("[wifi_service]:StaConnect memcpy failed, err = %d\n", hiRet);
+ g_connectState = lastState;
+ return ERROR_WIFI_UNKNOWN;
+ }
+ hiRet = hi_wifi_sta_fast_connect(&fastReq);
+ if (memset_s(&fastReq, sizeof(hi_wifi_fast_assoc_request), 0, sizeof(hi_wifi_fast_assoc_request)) != EOK) {
+ printf("[wifi_service]:StaConnect memset failed\n");
+ }
+ }
+ if (memset_s(assocReq, sizeof(hi_wifi_assoc_request), 0, sizeof(hi_wifi_assoc_request)) != EOK) {
+ printf("[wifi_service]:StaConnect memset failed\n");
+ }
+ if (hiRet != HISI_OK) {
+ g_connectState = lastState;
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ return WIFI_SUCCESS;
+}
+
+WifiErrorCode ConnectTo(int networkId)
+{
+ if (networkId >= WIFI_MAX_CONFIG_SIZE || networkId < 0) {
+ return ERROR_WIFI_INVALID_ARGS;
+ }
+
+ if (LockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ if (g_wifiConfigs[networkId].netId != networkId) {
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_NOT_AVAILABLE;
+ }
+
+ g_networkId = networkId;
+ hi_wifi_assoc_request assocReq = {0};
+ assocReq.auth = HoSecToHiSec(g_wifiConfigs[networkId].securityType);
+
+ int cpyErr = memcpy_s(assocReq.ssid, sizeof(assocReq.ssid),
+ g_wifiConfigs[networkId].ssid, sizeof(g_wifiConfigs[networkId].ssid));
+ cpyErr += memcpy_s(assocReq.key, sizeof(assocReq.key),
+ g_wifiConfigs[networkId].preSharedKey, sizeof(g_wifiConfigs[networkId].preSharedKey));
+ cpyErr += memcpy_s(assocReq.bssid, sizeof(assocReq.bssid),
+ g_wifiConfigs[networkId].bssid, sizeof(g_wifiConfigs[networkId].bssid));
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ if (cpyErr != EOK) {
+ printf("[wifi_service]:ConnectTo memcpy failed, err = %d\n", cpyErr);
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ unsigned int chan = FrequencyToChannel(g_wifiConfigs[networkId].freq);
+ if (LockWifiEventLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ if (StaConnect(chan, &assocReq, g_wifiConfigs[networkId].wapiPskType) != WIFI_SUCCESS) {
+ if (UnlockWifiEventLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_UNKNOWN;
+ }
+ if (UnlockWifiEventLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return WIFI_SUCCESS;
+}
+
+WifiErrorCode Disconnect(void)
+{
+ int hiRet = hi_wifi_sta_disconnect();
+ if (hiRet != HISI_OK) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return WIFI_SUCCESS;
+}
+
+WifiErrorCode RemoveDevice(int networkId)
+{
+ if (networkId >= WIFI_MAX_CONFIG_SIZE || networkId < 0) {
+ return ERROR_WIFI_INVALID_ARGS;
+ }
+ if (LockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ if (memset_s(&g_wifiConfigs[networkId], sizeof(WifiDeviceConfig),
+ 0, sizeof(WifiDeviceConfig)) != EOK) {
+ printf("[wifi_service]:removeDevice memset failed\n");
+ }
+ g_wifiConfigs[networkId].netId = WIFI_CONFIG_INVALID;
+
+ if (WriteNetworkConfig((unsigned char *)&g_wifiConfigs[networkId], sizeof(WifiDeviceConfig)) != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return WIFI_SUCCESS;
+}
+
+static int GetLocalWifiIp(int * const ip)
+{
+ int ret;
+ struct netif *netif_node = netif_find(WLAN_STA_NAME);
+ if (netif_node == NULL) {
+ printf("GetLocalWifiIp netif get fail\r\n");
+ return HISI_FAIL;
+ }
+
+ ip4_addr_t ipAddr;
+ ip4_addr_t netMask;
+ ip4_addr_t gateWay;
+
+ ret = netifapi_netif_get_addr(netif_node, &ipAddr, &netMask, &gateWay);
+ if (ret == 0) {
+ *ip = ip4_addr_get_u32(&ipAddr);
+ return HISI_OK;
+ }
+ return HISI_FAIL;
+}
+
+WifiErrorCode GetLinkedInfo(WifiLinkedInfo* result)
+{
+ if (result == NULL) {
+ return ERROR_WIFI_INVALID_ARGS;
+ }
+
+ hi_wifi_status connectStatus = {0};
+ int hiRet = hi_wifi_sta_get_connect_info(&connectStatus);
+ if (hiRet != HISI_OK) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ int cpyErr = memcpy_s(result->ssid, WIFI_MAX_SSID_LEN, connectStatus.ssid, HI_WIFI_MAX_SSID_LEN + 1);
+ if (cpyErr != EOK) {
+ printf("[wifi_service]:GetLinkedInfo memcpy failed, err = %d\n", cpyErr);
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ cpyErr = memcpy_s(result->bssid, WIFI_MAC_LEN, connectStatus.bssid, HI_WIFI_MAC_LEN);
+ if (cpyErr != EOK) {
+ printf("[wifi_service]:GetLinkedInfo memcpy failed, err = %d\n", cpyErr);
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ if (connectStatus.status == HI_WIFI_CONNECTED) {
+ result->connState = WIFI_CONNECTED;
+ result->rssi = hi_wifi_sta_get_ap_rssi();
+ } else {
+ result->connState = WIFI_DISCONNECTED;
+ }
+
+ if (GetLocalWifiIp(&(result->ipAddress)) != EOK) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ return WIFI_SUCCESS;
+}
+
+
+WifiErrorCode RegisterWifiEvent(WifiEvent* event)
+{
+ if (event == NULL) {
+ return ERROR_WIFI_INVALID_ARGS;
+ }
+
+ int emptySlot = WIFI_CONFIG_INVALID;
+
+ if (LockWifiEventLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ for (int i = 0; i < WIFI_MAX_EVENT_SIZE; i++) {
+ if (g_wifiEvents[i] == event) {
+ if (UnlockWifiEventLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_INVALID_ARGS;
+ }
+
+ if (g_wifiEvents[i] != NULL) {
+ continue;
+ }
+
+ emptySlot = i;
+ break;
+ }
+
+ if (emptySlot == WIFI_CONFIG_INVALID) {
+ if (UnlockWifiEventLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_BUSY;
+ }
+
+ g_wifiEvents[emptySlot] = event;
+ if (UnlockWifiEventLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ RegisterHisiCallback();
+
+ return WIFI_SUCCESS;
+}
+
+WifiErrorCode UnRegisterWifiEvent(const WifiEvent* event)
+{
+ if (event == NULL) {
+ return ERROR_WIFI_INVALID_ARGS;
+ }
+
+ if (LockWifiEventLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ for (int i = 0; i < WIFI_MAX_EVENT_SIZE; i++) {
+ if (g_wifiEvents[i] != event) {
+ continue;
+ }
+
+ g_wifiEvents[i] = 0;
+
+ if (UnlockWifiEventLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return WIFI_SUCCESS;
+ }
+
+ if (UnlockWifiEventLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_UNKNOWN;
+}
+
+WifiErrorCode GetDeviceMacAddress(unsigned char* result)
+{
+ if (result == NULL) {
+ return ERROR_WIFI_INVALID_ARGS;
+ }
+
+ int hiRet = hi_wifi_get_macaddr((char*)result, WIFI_MAC_LEN);
+ if (hiRet != HISI_OK) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return WIFI_SUCCESS;
+}
\ No newline at end of file
diff --git a/hi3861_adapter/hals/communication/wifi_lite/wifiservice/source/wifi_device_util.c b/hi3861_adapter/hals/communication/wifi_lite/wifiservice/source/wifi_device_util.c
new file mode 100755
index 0000000000000000000000000000000000000000..f0e6ca47cb0a95d3e118d8b7fb5f4e28e6f059e8
--- /dev/null
+++ b/hi3861_adapter/hals/communication/wifi_lite/wifiservice/source/wifi_device_util.c
@@ -0,0 +1,174 @@
+/*
+ * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * 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 "wifi_device_util.h"
+
+#include
+
+#include "cmsis_os.h"
+#include "common.h"
+#include "ohos_init.h"
+
+#include "wifi_hotspot_config.h"
+
+#define WIFI_WAIT_FOREVER 0xFFFFFFFF
+#define CHANNEL_80211B_ONLY 14
+#define FREQ_OF_CHANNEL_1 2412
+#define FREQ_OF_CHANNEL_80211B_ONLY 2484
+#define WIFI_MIN_CHANNEL 1
+#define WIFI_FREQ_INTERVAL 5
+
+static MutexId g_wifiGlobalLock = NULL;
+static MutexId g_wifiEventLock = NULL;
+
+WifiSecurityType HiSecToHoSec(hi_wifi_auth_mode mode)
+{
+ switch (mode) {
+ case HI_WIFI_SECURITY_OPEN:
+ return WIFI_SEC_TYPE_OPEN;
+ case HI_WIFI_SECURITY_WEP:
+ return WIFI_SEC_TYPE_WEP;
+ case HI_WIFI_SECURITY_WPAPSK_WPA2PSK_MIX:
+ return WIFI_SEC_TYPE_PSK;
+ case HI_WIFI_SECURITY_WPA3_WPA2_PSK_MIX:
+ return WIFI_SEC_TYPE_SAE;
+ default:
+ return WIFI_SEC_TYPE_INVALID;
+ }
+}
+
+hi_wifi_auth_mode HoSecToHiSec(WifiSecurityType type)
+{
+ switch (type) {
+ case WIFI_SEC_TYPE_OPEN:
+ return HI_WIFI_SECURITY_OPEN;
+ case WIFI_SEC_TYPE_WEP:
+ return HI_WIFI_SECURITY_WEP;
+ case WIFI_SEC_TYPE_PSK:
+ return HI_WIFI_SECURITY_WPAPSK_WPA2PSK_MIX;
+ case WIFI_SEC_TYPE_SAE:
+ return HI_WIFI_SECURITY_WPA3_WPA2_PSK_MIX;
+ default:
+ return HI_WIFI_SECURITY_UNKNOWN;
+ }
+}
+
+static void InitWifiGlobalLock(void)
+{
+ if (g_wifiGlobalLock == NULL) {
+ osMutexAttr_t globalMutexAttr = {
+ "WifiGloablLock",
+ osMutexRecursive | osMutexPrioInherit,
+ NULL,
+ 0U
+ };
+ g_wifiGlobalLock = osMutexNew(&globalMutexAttr);
+ }
+ if (g_wifiEventLock == NULL) {
+ osMutexAttr_t eventMutexAttr = {
+ "WifiEventLock",
+ osMutexRecursive | osMutexPrioInherit,
+ NULL,
+ 0U
+ };
+ g_wifiEventLock = osMutexNew(&eventMutexAttr);
+ }
+}
+
+WifiErrorCode LockWifiGlobalLock(void)
+{
+ if (g_wifiGlobalLock == NULL) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ osStatus_t ret = osMutexAcquire(g_wifiGlobalLock, WIFI_WAIT_FOREVER);
+ if (ret != osOK) {
+ printf("[wifi_service] osMutexAcquire failed \n");
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ return WIFI_SUCCESS;
+}
+
+WifiErrorCode UnlockWifiGlobalLock(void)
+{
+ if (g_wifiGlobalLock == NULL) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ osStatus_t ret = osMutexRelease(g_wifiGlobalLock);
+ if (ret != osOK) {
+ printf("[wifi_service] osMutexUnlock failed \n");
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ return WIFI_SUCCESS;
+}
+
+WifiErrorCode LockWifiEventLock(void)
+{
+ if (g_wifiEventLock == NULL) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ osStatus_t ret = osMutexAcquire(g_wifiEventLock, WIFI_WAIT_FOREVER);
+ if (ret != osOK) {
+ printf("[wifi_service] osMutexAcquire event failed \n");
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ return WIFI_SUCCESS;
+}
+
+WifiErrorCode UnlockWifiEventLock(void)
+{
+ if (g_wifiEventLock == NULL) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ osStatus_t ret = osMutexRelease(g_wifiEventLock);
+ if (ret != osOK) {
+ printf("[wifi_service] osMutexUnlock event failed \n");
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ return WIFI_SUCCESS;
+}
+
+unsigned int ChannelToFrequency(unsigned int channel)
+{
+ if (channel <= 0) {
+ return 0;
+ }
+ if (channel == CHANNEL_80211B_ONLY) {
+ return FREQ_OF_CHANNEL_80211B_ONLY;
+ }
+ return (((channel - WIFI_MIN_CHANNEL) * WIFI_FREQ_INTERVAL) + FREQ_OF_CHANNEL_1);
+}
+
+unsigned int FrequencyToChannel(unsigned int frequency)
+{
+ if (frequency == FREQ_OF_CHANNEL_80211B_ONLY) {
+ return CHANNEL_80211B_ONLY;
+ }
+
+ if (frequency < FREQ_OF_CHANNEL_1) {
+ return 0;
+ }
+
+ return (frequency - FREQ_OF_CHANNEL_1) / WIFI_FREQ_INTERVAL + WIFI_MIN_CHANNEL;
+}
+
+CORE_INIT(InitWifiGlobalLock);
diff --git a/hi3861_adapter/hals/communication/wifi_lite/wifiservice/source/wifi_device_util.h b/hi3861_adapter/hals/communication/wifi_lite/wifiservice/source/wifi_device_util.h
new file mode 100755
index 0000000000000000000000000000000000000000..af7cec44e5525d13cb9a266df9ccef8e7d00e22f
--- /dev/null
+++ b/hi3861_adapter/hals/communication/wifi_lite/wifiservice/source/wifi_device_util.h
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * 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 _WIFI_DEVICE_UTIL_H
+#define _WIFI_DEVICE_UTIL_H
+
+#include "hi_wifi_api.h"
+
+#include "wifi_device.h"
+#include "wifi_device_config.h"
+#include "wifi_error_code.h"
+
+/**
+ * @brief convert os security type to hisi security type
+ *
+ * @param type [in] os security type.
+ *
+ * @return hisi security type.
+ */
+hi_wifi_auth_mode HoSecToHiSec(WifiSecurityType type);
+
+/**
+ * @brief convert hisi security type to os security type
+ *
+ * @param type [in] hisi security type.
+ *
+ * @return os security type.
+ */
+WifiSecurityType HiSecToHoSec(hi_wifi_auth_mode mode);
+
+/**
+ * @brief get hotspot channel
+ *
+ * @return current channel.
+ */
+int GetHotspotChannel(void);
+
+/**
+ * @brief get hotspot interface name
+ *
+ * @param result [out] hotspot interface name.
+ * @param size [in] result buffer size, must bigger than WIFI_IFNAME_MAX_SIZE + 1.
+ *
+ * @return WifiErrorCode.
+ */
+WifiErrorCode GetHotspotInterfaceName(char* result, int size);
+
+/**
+ * @brief lock wifi global lock
+ *
+ * @return WifiErrorCode.
+ */
+WifiErrorCode LockWifiGlobalLock(void);
+
+/**
+ * @brief unlock wifi global lock
+ *
+ * @return WifiErrorCode.
+ */
+WifiErrorCode UnlockWifiGlobalLock(void);
+
+/**
+ * @brief lock wifi event lock
+ *
+ * @return WifiErrorCode.
+ */
+WifiErrorCode LockWifiEventLock(void);
+
+/**
+ * @brief unlock wifi event lock
+ *
+ * @return WifiErrorCode.
+ */
+WifiErrorCode UnlockWifiEventLock(void);
+
+/**
+ * @brief convert channel to frequency in 2G
+ *
+ * @return frequency.
+ */
+unsigned int ChannelToFrequency(unsigned int channel);
+
+unsigned int FrequencyToChannel(unsigned int frequency);
+#endif // _WIFI_DEVICE_UTIL_H
diff --git a/hi3861_adapter/hals/communication/wifi_lite/wifiservice/source/wifi_hotspot.c b/hi3861_adapter/hals/communication/wifi_lite/wifiservice/source/wifi_hotspot.c
new file mode 100755
index 0000000000000000000000000000000000000000..07883f16ccd56eba44e322334736b61ffcbf0529
--- /dev/null
+++ b/hi3861_adapter/hals/communication/wifi_lite/wifiservice/source/wifi_hotspot.c
@@ -0,0 +1,438 @@
+/*
+ * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * 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 "wifi_hotspot.h"
+#include
+#include "hi_wifi_api.h"
+#include "lwip/netifapi.h"
+#include "wifi_device_util.h"
+
+#define RSSI_LEVEL_4_2_G (-65)
+#define RSSI_LEVEL_3_2_G (-75)
+#define RSSI_LEVEL_2_2_G (-82)
+#define RSSI_LEVEL_1_2_G (-88)
+
+#define RSSI_LEVEL_4_5_G (-65)
+#define RSSI_LEVEL_3_5_G (-72)
+#define RSSI_LEVEL_2_5_G (-79)
+#define RSSI_LEVEL_1_5_G (-85)
+
+#define IP_AP_ADDR0 192
+#define IP_AP_ADDR1 168
+#define IP_AP_ADDR2 5
+#define IP_AP_ADDR3 1
+#define GW_AP_ADDR0 192
+#define GW_AP_ADDR1 168
+#define GW_AP_ADDR2 5
+#define GW_AP_ADDR3 1
+#define NETMSK_ADDR0 255
+#define NETMSK_ADDR1 255
+#define NETMSK_ADDR2 255
+#define NETMSK_ADDR3 0
+
+#define WIFI_TPC_MAX_POWER 20
+#define WIFI_TPC_ID 35
+#define WIFI_TPC_LEN 2
+#define WLAN_AP_NAME "ap0"
+
+static int g_wifiApStatus = WIFI_HOTSPOT_NOT_ACTIVE;
+static HotspotConfig g_wifiApConfig = {0};
+static char g_wifiIfName[WIFI_IFNAME_MAX_SIZE + 1] = {0};
+typedef struct {
+ unsigned char id;
+ unsigned char len;
+ signed char power;
+ unsigned char margin;
+} TpcElement;
+
+static WifiErrorCode SetHotspotIpConfig(void)
+{
+ struct netif *netif = NULL;
+ netif = netif_find(WLAN_AP_NAME);
+ if (netif == NULL) {
+ printf("get netif failed\r\n");
+ return ERROR_WIFI_UNKNOWN;
+ }
+ ip4_addr_t ipAddr;
+ ip4_addr_t netMask;
+ ip4_addr_t gw;
+
+ IP4_ADDR(&ipAddr, IP_AP_ADDR0, IP_AP_ADDR1, IP_AP_ADDR2, IP_AP_ADDR3);
+ IP4_ADDR(&netMask, NETMSK_ADDR0, NETMSK_ADDR1, NETMSK_ADDR2, NETMSK_ADDR3);
+ IP4_ADDR(&gw, GW_AP_ADDR0, GW_AP_ADDR1, GW_AP_ADDR2, GW_AP_ADDR3);
+
+ netifapi_netif_set_addr(netif, &ipAddr, &netMask, &gw);
+
+ if (netifapi_dhcps_start(netif, 0, 0) != 0) {
+ printf("dhcps shell cmd excute fail!\r\n");
+ (void)hi_wifi_softap_stop();
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return WIFI_SUCCESS;
+}
+
+WifiErrorCode EnableHotspot(void)
+{
+ if (LockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ if (g_wifiApStatus == WIFI_HOTSPOT_ACTIVE) {
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_BUSY;
+ }
+
+ hi_wifi_softap_config hapdConf = {0};
+
+ hapdConf.channel_num = HOTSPOT_DEFAULT_CHANNEL;
+ if (g_wifiApConfig.channelNum) {
+ hapdConf.channel_num = g_wifiApConfig.channelNum;
+ }
+ hapdConf.authmode = HoSecToHiSec(g_wifiApConfig.securityType);
+
+ int cpyErr = memcpy_s(hapdConf.ssid, WIFI_MAX_SSID_LEN, g_wifiApConfig.ssid, HI_WIFI_MAX_SSID_LEN + 1);
+ cpyErr += memcpy_s(hapdConf.key, WIFI_MAX_KEY_LEN, g_wifiApConfig.preSharedKey, HI_WIFI_MAX_KEY_LEN + 1);
+ if (cpyErr != EOK) {
+ printf("[wifi_service]:EnableHotspot memcpy fail, err = %d\n", cpyErr);
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ int len = sizeof(g_wifiIfName);
+ int hiRet = hi_wifi_softap_start(&hapdConf, g_wifiIfName, &len);
+ if (hiRet != HISI_OK) {
+ printf("[wifi_service]:EnableHotspot softap start fail, err = %d\n", hiRet);
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_NOT_STARTED;
+ }
+ cpyErr = memset_s(&hapdConf, sizeof(hi_wifi_softap_config), 0, sizeof(hi_wifi_softap_config));
+ if (cpyErr != EOK) {
+ printf("[wifi_service]:EnableHotspot memset fail, err = %d\n", cpyErr);
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ g_wifiApStatus = WIFI_HOTSPOT_ACTIVE;
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ if (SetHotspotIpConfig() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return WIFI_SUCCESS;
+}
+
+WifiErrorCode DisableHotspot(void)
+{
+ if (LockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ if (g_wifiApStatus == WIFI_HOTSPOT_NOT_ACTIVE) {
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_NOT_STARTED;
+ }
+
+ int hiRet = hi_wifi_softap_stop();
+ if (hiRet != HISI_OK) {
+ printf("[wifi_service]:DisableHotspot failed to stop softap, err = %d\n", hiRet);
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_NOT_STARTED;
+ }
+
+ g_wifiApStatus = WIFI_HOTSPOT_NOT_ACTIVE;
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return WIFI_SUCCESS;
+}
+
+WifiErrorCode SetHotspotConfig(const HotspotConfig* config)
+{
+ if (config == NULL) {
+ return ERROR_WIFI_INVALID_ARGS;
+ }
+
+ if (LockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ int cpyErr = memcpy_s(&g_wifiApConfig, sizeof(HotspotConfig), config, sizeof(HotspotConfig));
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ if (cpyErr != EOK) {
+ printf("[wifi_service]:SetHotspotConfig memcpy fail, err = %d\n", cpyErr);
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return WIFI_SUCCESS;
+}
+
+WifiErrorCode GetHotspotConfig(HotspotConfig* result)
+{
+ if (result == NULL) {
+ return ERROR_WIFI_INVALID_ARGS;
+ }
+
+ if (LockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ int cpyErr = memcpy_s(result, sizeof(HotspotConfig), &g_wifiApConfig, sizeof(HotspotConfig));
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ if (cpyErr != EOK) {
+ printf("[wifi_service]:SetHotspotConfig memcpy fail, err = %d\n", cpyErr);
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return WIFI_SUCCESS;
+}
+
+int IsHotspotActive(void)
+{
+ if (LockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ int ret = g_wifiApStatus;
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+
+ return ret;
+}
+
+static int GetPeerSTAWifiIp(const unsigned char *macAddress, int macLen, unsigned int * const ip)
+{
+ int ret;
+ ip4_addr_t clientIP;
+ struct netif *netif_node = netif_find(WLAN_AP_NAME);
+ if (netif_node == NULL) {
+ printf("GetPeerSTAWifiIp netif get fail\r\n");
+ return HISI_FAIL;
+ }
+
+ ret = netifapi_dhcps_get_client_ip(netif_node, macAddress, macLen, &clientIP);
+ if (ret == 0) {
+ *ip = ntohl(ip4_addr_get_u32(&clientIP));
+ return HISI_OK;
+ }
+
+ return HISI_FAIL;
+}
+
+WifiErrorCode GetStationList(StationInfo* result, unsigned int* size)
+{
+ if (result == NULL || size == NULL || *size == 0) {
+ return ERROR_WIFI_INVALID_ARGS;
+ }
+
+ hi_wifi_ap_sta_info staList[WIFI_MAX_STA_NUM] = {0};
+ unsigned int staNum = WIFI_MAX_STA_NUM;
+
+ int hiRet = hi_wifi_softap_get_connected_sta(staList, &staNum);
+ if (hiRet != HISI_OK) {
+ printf("[wifi_service]:GetStationList get connected sta failed, err = %d\r\n", hiRet);
+ return ERROR_WIFI_NOT_AVAILABLE;
+ }
+
+ if (*size < staNum) {
+ return ERROR_WIFI_INVALID_ARGS;
+ }
+
+ int cpyErr;
+ for (unsigned int i = 0; i < staNum; i++) {
+ cpyErr = memcpy_s(result[i].macAddress, WIFI_MAC_LEN, staList[i].mac, HI_WIFI_MAC_LEN);
+ if (cpyErr != EOK) {
+ printf("[wifi_service]:GetStationList memcpy fail, err = %d\r\n", cpyErr);
+ return ERROR_WIFI_UNKNOWN;
+ }
+ result[i].name = NULL;
+
+#if LWIP_NETIFAPI_DHCPS_IP
+ int ret = GetPeerSTAWifiIp(staList[i].mac, WIFI_MAC_LEN, &(result[i].ipAddress));
+ if (ret != HISI_OK) {
+ printf("[wifi_service]:GetPeerSTAWifiIp fail, err = %d\r\n", ret);
+ return ERROR_WIFI_UNKNOWN;
+ }
+#endif
+ }
+ *size = staNum;
+ return WIFI_SUCCESS;
+}
+
+WifiErrorCode SetBand(int band)
+{
+ if (band != HOTSPOT_BAND_TYPE_2G) {
+ return ERROR_WIFI_NOT_SUPPORTED;
+ }
+ if (LockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ g_wifiApConfig.band = band;
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return WIFI_SUCCESS;
+}
+
+WifiErrorCode GetBand(int* result)
+{
+ if (result == NULL) {
+ return ERROR_WIFI_INVALID_ARGS;
+ }
+
+ if (LockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ if (g_wifiApConfig.band == 0) {
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_NOT_AVAILABLE;
+ }
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ *result = HOTSPOT_BAND_TYPE_2G;
+ return WIFI_SUCCESS;
+}
+
+int GetSignalLevel(int rssi, int band)
+{
+ if (band == HOTSPOT_BAND_TYPE_2G) {
+ if (rssi >= RSSI_LEVEL_4_2_G) {
+ return RSSI_LEVEL_4;
+ }
+ if (rssi >= RSSI_LEVEL_3_2_G) {
+ return RSSI_LEVEL_3;
+ }
+ if (rssi >= RSSI_LEVEL_2_2_G) {
+ return RSSI_LEVEL_2;
+ }
+ if (rssi >= RSSI_LEVEL_1_2_G) {
+ return RSSI_LEVEL_1;
+ }
+ }
+
+ if (band == HOTSPOT_BAND_TYPE_5G) {
+ if (rssi >= RSSI_LEVEL_4_5_G) {
+ return RSSI_LEVEL_4;
+ }
+ if (rssi >= RSSI_LEVEL_3_5_G) {
+ return RSSI_LEVEL_3;
+ }
+ if (rssi >= RSSI_LEVEL_2_5_G) {
+ return RSSI_LEVEL_2;
+ }
+ if (rssi >= RSSI_LEVEL_1_5_G) {
+ return RSSI_LEVEL_1;
+ }
+ }
+
+ return ERROR_WIFI_INVALID_ARGS;
+}
+
+int GetHotspotChannel(void)
+{
+ if (LockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ if (g_wifiApStatus == WIFI_HOTSPOT_NOT_ACTIVE) {
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_NOT_STARTED;
+ }
+
+ int channel = hi_wifi_get_channel(g_wifiIfName, WIFI_IFNAME_MAX_SIZE + 1);
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ if (channel == HI_WIFI_INVALID_CHANNEL) {
+ return ERROR_WIFI_INVALID_ARGS;
+ }
+
+ return channel;
+}
+
+WifiErrorCode GetHotspotInterfaceName(char* result, int size)
+{
+ if (LockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ if (g_wifiApStatus == WIFI_HOTSPOT_NOT_ACTIVE) {
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return ERROR_WIFI_NOT_STARTED;
+ }
+
+ int cpyErr = memcpy_s(result, size, g_wifiIfName, WIFI_IFNAME_MAX_SIZE + 1);
+ if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ if (cpyErr != EOK) {
+ printf("[wifi_service]:getifname memcpy fail, err = %d\n", cpyErr);
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return WIFI_SUCCESS;
+}
+
+WifiErrorCode DisassociateSta(unsigned char* mac, int macLen)
+{
+ int ret = hi_wifi_softap_deauth_sta(mac, macLen);
+ if (ret != HISI_OK) {
+ return ERROR_WIFI_UNKNOWN;
+ }
+ return WIFI_SUCCESS;
+}
+
+WifiErrorCode AddTxPowerInfo(int power)
+{
+ TpcElement tpc = { WIFI_TPC_ID, WIFI_TPC_LEN, 0, 0 };
+ if (power > WIFI_TPC_MAX_POWER) {
+ printf("[wifi_service]:Invalid TPC Power (%d)\n", power);
+ return ERROR_WIFI_INVALID_ARGS;
+ } else {
+ tpc.power = power;
+ }
+
+ int ret = hi_wifi_add_usr_app_ie(HI_WIFI_IFTYPE_AP, HI_WIFI_FRAME_TYPE_BEACON, HI_WIFI_USR_IE_TYPE_DEFAULT,
+ (const unsigned char *)&tpc, sizeof(tpc));
+ if (ret != HISI_OK) {
+ printf("[wifi_service]:Wifi Add Beacon IE Fail (%d)\n", ret);
+ (void)hi_wifi_delete_usr_app_ie(HI_WIFI_IFTYPE_AP, HI_WIFI_FRAME_TYPE_BEACON, HI_WIFI_USR_IE_TYPE_DEFAULT);
+ return ret;
+ }
+
+ ret = hi_wifi_add_usr_app_ie(HI_WIFI_IFTYPE_AP, HI_WIFI_FRAME_TYPE_PROBE_RSP, HI_WIFI_USR_IE_TYPE_DEFAULT,
+ (const unsigned char *)&tpc, sizeof(tpc));
+ if (ret != HISI_OK) {
+ printf("Wifi Add ProbResp IE Fail (%d)\n", ret);
+ (void)hi_wifi_delete_usr_app_ie(HI_WIFI_IFTYPE_AP, HI_WIFI_FRAME_TYPE_PROBE_RSP, HI_WIFI_USR_IE_TYPE_DEFAULT);
+ return ret;
+ }
+ return WIFI_SUCCESS;
+}
diff --git a/hi3861_adapter/hals/interfaces/BUILD.gn b/hi3861_adapter/hals/interfaces/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..6c88d99c3b0d1609902b7820e40652b18e376628
--- /dev/null
+++ b/hi3861_adapter/hals/interfaces/BUILD.gn
@@ -0,0 +1,15 @@
+static_library("hal_genkipi_interfaces") {
+ if (board_name == "genkipi") {
+ sources = [
+ "hal_genki_led.c",
+ "hal_genki_wifi_sta.c"
+ ]
+ include_dirs = [
+ "//utils/native/lite/include",
+ "//base/iot_hardware/peripheral/interfaces/kits",
+ "//foundation/communication/wifi_lite/interfaces/wifiservice",
+ "//device/itcast/genkipi/sdk_liteos/include",
+ "//device/itcast/genkipi/interfaces/kits"
+ ]
+ }
+}
diff --git a/hi3861_adapter/hals/interfaces/hal_genki_led.c b/hi3861_adapter/hals/interfaces/hal_genki_led.c
new file mode 100644
index 0000000000000000000000000000000000000000..8e736c07479d01d995c4b334eb13159598b1f499
--- /dev/null
+++ b/hi3861_adapter/hals/interfaces/hal_genki_led.c
@@ -0,0 +1,97 @@
+#include
+#include
+#include
+
+#include "ohos_init.h"
+#include "iot_gpio.h"
+#include "iot_io.h"
+#include "iot_pwm.h"
+
+#include "genki_pin.h"
+#include "genki_led.h"
+
+
+static unsigned char led_init = 0;
+static unsigned char led_state = 0;
+static unsigned char led_pwm_init = 0;
+
+
+static void GenkiLedInit(void) {
+ // 初始化GPIO端口
+ IoTGpioInit(IOT_IO_NAME_2);
+
+ // 设置IO口功能为GPIO
+ IoTIoSetFunc(IOT_IO_NAME_2, IOT_IO_FUNC_2_GPIO);
+
+ // 设置IO口输出方式:输出
+ IoTGpioSetDir(IOT_IO_NAME_2, IOT_GPIO_DIR_OUT);
+
+ IoTGpioSetOutputVal(IOT_IO_NAME_2, IOT_GPIO_VALUE0);
+ IoTGpioGetOutputVal(IOT_IO_NAME_2, &led_state);
+}
+
+void GenkiLedToggle(void) {
+ if (led_init == 0) {
+ GenkiLedInit();
+ led_init = 1;
+ if(led_pwm_init != 0) {
+ GenkiLedPwmStop();
+ }
+ led_pwm_init = 0;
+ }
+
+ if (led_state == IOT_GPIO_VALUE0) {
+ // to high
+ IoTGpioSetOutputVal(IOT_IO_NAME_2, IOT_GPIO_VALUE1);
+ IoTGpioGetOutputVal(IOT_IO_NAME_2, &led_state);
+ } else {
+ // to low
+ IoTGpioSetOutputVal(IOT_IO_NAME_2, IOT_GPIO_VALUE0);
+ IoTGpioGetOutputVal(IOT_IO_NAME_2, &led_state);
+ }
+}
+
+void GenkiLedState(unsigned char *state) {
+ IoTGpioGetOutputVal(IOT_IO_NAME_2, &led_state);
+ *state = led_state;
+}
+
+void GenkiLedOpen(void) {
+ if (led_state == IOT_GPIO_VALUE0) {
+ GenkiLedToggle();
+ }
+}
+
+void GenkiLedClose(void) {
+ if (led_state == IOT_GPIO_VALUE1) {
+ GenkiLedToggle();
+ }
+}
+
+static void GenkiLedPwmInit(void) {
+ // 初始化GPIO端口
+ IoTGpioInit(IOT_IO_NAME_2);
+
+ // 设置IO口功能为GPIO
+ IoTIoSetFunc(IOT_IO_NAME_2, IOT_IO_FUNC_2_PWM2_OUT);
+
+ // 设置IO口输出方式:输出
+ IoTGpioSetDir(IOT_IO_NAME_2, IOT_GPIO_DIR_OUT);
+
+ // 初始化PWM
+ IoTPwmInit(IOT_IO_NAME_2);
+}
+
+void GenkiLedPwmStart(unsigned short duty, unsigned int freq) {
+ if(led_pwm_init == 0) {
+ GenkiLedPwmInit();
+ led_pwm_init = 1;
+ led_init = 0;
+ }
+
+ IoTPwmStart(IOT_IO_NAME_2, duty, freq);
+}
+
+void GenkiLedPwmStop(void) {
+ IoTPwmStop(IOT_IO_NAME_2);
+}
\ No newline at end of file
diff --git a/hi3861_adapter/hals/interfaces/hal_genki_wifi_sta.c b/hi3861_adapter/hals/interfaces/hal_genki_wifi_sta.c
new file mode 100644
index 0000000000000000000000000000000000000000..a194eed952c1f18b8576dbb91a40091561b227b9
--- /dev/null
+++ b/hi3861_adapter/hals/interfaces/hal_genki_wifi_sta.c
@@ -0,0 +1,284 @@
+#include "ohos_init.h"
+#include "ohos_types.h"
+#include
+#include
+#include
+#include "cmsis_os2.h"
+
+#include "wifi_device.h"
+#include "wifi_event.h"
+#include "wifi_error_code.h"
+
+#include "lwip/netif.h"
+#include "lwip/netifapi.h"
+#include "lwip/ip4_addr.h"
+#include "lwip/api_shell.h"
+
+#include "genki_wifi_sta.h"
+
+#define DEF_TIMEOUT 15
+#define ONE_SECOND 1
+
+#define SELECT_WLAN_PORT "wlan0"
+
+WifiEvent wifi_event_handler = {0};
+static int g_staScanSuccess = 0;
+static int g_ConnectSuccess = 0;
+static int ssid_count = 0;
+
+static struct netif *g_lwip_netif = NULL;
+
+
+static void OnWifiConnectionChanged(int state, WifiLinkedInfo *info) {
+ (void) info;
+
+ if (state > 0) {
+ g_ConnectSuccess = 1;
+ printf("[wifi_sta]cb for wifi connect, success\r\n");
+ } else {
+ printf("[wifi_sta]cb for wifi connect, failed, please check password\r\n");
+ }
+ return;
+}
+
+static void OnWifiScanStateChanged(int state, int size) {
+ (void) state;
+ if (size > 0) {
+ ssid_count = size;
+ g_staScanSuccess = 1;
+ }
+ return;
+}
+
+static void OnHotspotStateChanged(int state) {
+ printf("[wifi_sta]cb for HotspotStateChanged:state is %d.\n", state);
+ return;
+}
+
+static void OnHotspotStaJoin(StationInfo *info) {
+ (void) info;
+ printf("[wifi_sta]STA join AP\r\n");
+ return;
+}
+
+static void OnHotspotStaLeave(StationInfo *info) {
+ (void) info;
+ printf("[wifi_sta]cb for HotspotStaLeave:mac is %s.\r\n", info->macAddress);
+ return;
+}
+
+static WifiErrorCode wifi_init(void) {
+ WifiErrorCode error;
+ wifi_event_handler.OnWifiConnectionChanged = OnWifiConnectionChanged;
+ wifi_event_handler.OnWifiScanStateChanged = OnWifiScanStateChanged;
+ wifi_event_handler.OnHotspotStateChanged = OnHotspotStateChanged;
+ wifi_event_handler.OnHotspotStaJoin = OnHotspotStaJoin;
+ wifi_event_handler.OnHotspotStaLeave = OnHotspotStaLeave;
+ error = RegisterWifiEvent(&wifi_event_handler);
+ return error;
+}
+
+static void wait_scan_result(void) {
+ int scanTimeout = DEF_TIMEOUT;
+ while (scanTimeout > 0) {
+ sleep(ONE_SECOND);
+ scanTimeout--;
+ if (g_staScanSuccess == 1) {
+ printf("[wifi_sta]wait scan result: wait success[%d]s\n", (DEF_TIMEOUT - scanTimeout));
+ break;
+ }
+ }
+ if (scanTimeout <= 0) {
+ printf("[wifi_sta]wait scan result:timeout!\n");
+ }
+}
+
+static int wait_connect_result(void)
+{
+ int ConnectTimeout = DEF_TIMEOUT;
+ while (ConnectTimeout > 0)
+ {
+ sleep(1);
+ ConnectTimeout--;
+ if (g_ConnectSuccess == 1)
+ {
+ printf("[wifi_sta]wait connect result:wait success[%d]s\n", (DEF_TIMEOUT - ConnectTimeout));
+ break;
+ }
+ }
+ if (ConnectTimeout <= 0)
+ {
+ printf("[wifi_sta]wait connect result:timeout!\n");
+ return 0;
+ }
+ return 1;
+}
+
+int connect_wifi(const char* ssid, const char* password, const char* hostname) {
+
+ // wifi init
+ WifiErrorCode error = wifi_init();
+ if (WIFI_SUCCESS != error) {
+ printf("[wifi_sta]register wifi event failed, error=%d\r\n", error);
+ return error;
+ }
+ printf("[wifi_sta]register wifi event success\r\n");
+
+ // wifi enable
+ error = EnableWifi();
+ if (WIFI_SUCCESS != error) {
+ printf("[wifi_sta]enable wifi failed, error=%d\r\n", error);
+ return error;
+ }
+ printf("[wifi_sta]enable wifi success\r\n");
+
+ // check wifi active
+ if (IsWifiActive() == 0) {
+ printf("[wifi_sta] wifi station is not active\r\n");
+ return error;
+ }
+
+ unsigned int size = WIFI_SCAN_HOTSPOT_LIMIT;
+ WifiScanInfo *info = NULL;
+ info = malloc(sizeof(WifiScanInfo) * size);
+ if (NULL == info) {
+ printf("[wifi_sta] wifi scan info init failed\r\n");
+ return error;
+ }
+
+ // scan wifi list
+ do {
+ // reset
+ ssid_count = 0;
+ g_staScanSuccess = 0;
+
+ // start scan
+ Scan();
+
+ // wait scan result
+ wait_scan_result();
+
+ // get scan result
+ error = GetScanInfoList(info, &size);
+
+ } while (g_staScanSuccess != 1);
+
+ // print wifi list
+ for (int i = 0; i < ssid_count; ++i) {
+ printf("[wifi_sta]scan wifi: %s\r\n", info[i].ssid);
+
+ if (strcmp(ssid, info[i].ssid) == 0) {
+ WifiDeviceConfig ap_config = {0};
+ strcpy(ap_config.ssid, info[i].ssid);
+ strcpy(ap_config.preSharedKey, password);
+ ap_config.securityType = WIFI_SEC_TYPE_PSK;
+
+ int result;
+ if (AddDeviceConfig(&ap_config, &result) == WIFI_SUCCESS) {
+
+ // connect to wifi
+ if (ConnectTo(result) == WIFI_SUCCESS && wait_connect_result() == 1) {
+ printf("[wifi_sta]wifi connect success!\r\n");
+ g_lwip_netif = netifapi_netif_find(SELECT_WLAN_PORT);
+ break;
+ }
+ }
+ }
+
+ if (i == ssid_count - 1) {
+ printf("[wifi_sta]ERROR No wifi expected \r\n");
+ }
+ }
+
+ if (!g_lwip_netif) {
+ printf("[wifi_sta]netif error \r\n");
+ return error;
+ }
+
+ // start dhcp
+ netifapi_set_hostname(g_lwip_netif, hostname, strlen(hostname));
+ netifapi_dhcp_start(g_lwip_netif);
+
+ // wait dhcp
+ while (1) {
+ if (dhcp_is_bound(g_lwip_netif) == ERR_OK) {
+ printf("[wifi_sta]dhcp bound success\r\n");
+
+ netifapi_netif_common(g_lwip_netif, dhcp_clients_info_show, NULL);
+ break;
+ }
+
+ osDelay(100);
+ }
+
+ return WIFI_SUCCESS;
+}
+
+int disconnect_wifi(void) {
+ if (!g_lwip_netif) {
+ printf("[wifi_sta]netif error \r\n");
+ return -1;
+ }
+
+ WifiErrorCode error = Disconnect();
+ if (WIFI_SUCCESS != error) {
+ printf("[wifi_sta]disconnect wifi failed, error=%d\r\n", error);
+ return error;
+ }
+
+ error = DisableWifi();
+ if (WIFI_SUCCESS != error) {
+ printf("[wifi_sta]disable wifi failed, error=%d\r\n", error);
+ return error;
+ }
+
+ error = UnRegisterWifiEvent(&wifi_event_handler);
+ if (WIFI_SUCCESS != error) {
+ printf("[wifi_sta]unregister wifi event failed, error=%d\r\n", error);
+ return error;
+ }
+ printf("[wifi_sta]disconnect wifi success\r\n");
+ return WIFI_SUCCESS;
+}
+
+static int get_wifi_local_ip() {
+ if (!g_lwip_netif) {
+ printf("[wifi_sta]netif error \r\n");
+ return -1;
+ }
+
+ ip4_addr_t ip_addr;
+ ip4_addr_t netmask_addr;
+ ip4_addr_t gw_addr;
+ if(netifapi_netif_get_addr(g_lwip_netif, &ip_addr, &netmask_addr, &gw_addr) == ERR_OK) {
+ u32_t ip = ip_addr.addr;
+ u32_t netmask = netmask_addr.addr;
+ u32_t gw = gw_addr.addr;
+
+ printf("ip %d.%d.%d.%d\n\r",(ip & 0xff), ((ip >> 8) & 0xff), ((ip >> 16) & 0xff), (ip >> 24));
+ printf("netmask %d.%d.%d.%d\n\r",(netmask & 0xff), ((netmask >> 8) & 0xff), ((netmask >> 16) & 0xff), (netmask >> 24));
+ printf("gw %d.%d.%d.%d\n\r",(gw & 0xff), ((gw >> 8) & 0xff), ((gw >> 16) & 0xff), (gw >> 24));
+ } else {
+ printf("netif get addr failed\r\n");
+ }
+
+ return 1;
+}
+
+int get_wifi_addr(unsigned int *ip, unsigned int *netmask, unsigned int *gateway) {
+ if (!g_lwip_netif) {
+ printf("[wifi_sta]netif error \r\n");
+ return 0;
+ }
+
+ ip4_addr_t ip_addr;
+ ip4_addr_t netmask_addr;
+ ip4_addr_t gw_addr;
+ if(netifapi_netif_get_addr(g_lwip_netif, &ip_addr, &netmask_addr, &gw_addr) == ERR_OK) {
+ *ip = ip_addr.addr;
+ *netmask = netmask_addr.addr;
+ *gateway = gw_addr.addr;
+ return 1;
+ }
+ return 0;
+}
\ No newline at end of file
diff --git a/hi3861_adapter/hals/iot_hardware/wifiiot_lite/BUILD.gn b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/BUILD.gn
new file mode 100755
index 0000000000000000000000000000000000000000..7a328a4a003daf9496640c98297f47b41119f0fa
--- /dev/null
+++ b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/BUILD.gn
@@ -0,0 +1,37 @@
+# Copyright (c) 2020 Huawei Device Co., Ltd.
+# 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.
+
+static_library("hal_iothardware") {
+ if (board_name == "genkipi") {
+ sources = [
+ "hal_iot_adc.c",
+ "hal_iot_flash.c",
+ "hal_iot_gpio.c",
+ "hal_iot_i2c.c",
+ "hal_iot_io.c",
+ "hal_iot_pwm.c",
+ "hal_iot_spi.c",
+ "hal_iot_uart.c",
+ "hal_iot_watchdog.c",
+ "hal_lowpower.c",
+ "hal_reset.c",
+ "hal_time.c"
+ ]
+ include_dirs = [
+ "//utils/native/lite/include",
+ "//base/iot_hardware/peripheral/interfaces/kits",
+ "//device/itcast/genkipi/sdk_liteos/include",
+ "//device/itcast/genkipi/interfaces/kits",
+ ]
+ }
+}
diff --git a/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_adc.c b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_adc.c
new file mode 100644
index 0000000000000000000000000000000000000000..919ab8060de7d1ab48307cb37e4cf3eb800b8b84
--- /dev/null
+++ b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_adc.c
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2020 Itcast Co., Ltd.
+ * 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 "hi_adc.h"
+#include "iot_adc.h"
+
+unsigned int IoTAdcRead(IoTAdcChannelIndex channel, unsigned short *data, IoTAdcEquModelSel equModel,
+ IoTAdcCurBais curBais, unsigned short rstCnt) {
+ return hi_adc_read((hi_adc_channel_index) channel, (hi_u16 *) data, (hi_adc_equ_model_sel) equModel,
+ (hi_adc_cur_bais) curBais, (hi_u16) rstCnt);
+}
diff --git a/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_flash.c b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_flash.c
new file mode 100755
index 0000000000000000000000000000000000000000..e0d7d649164e6a49cc33af2acd10b06745f2f18e
--- /dev/null
+++ b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_flash.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * 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 "iot_errno.h"
+#include "iot_flash.h"
+#include "hi_flash.h"
+
+unsigned int IoTFlashRead(unsigned int flashOffset, unsigned int size, unsigned char *ramData)
+{
+ return hi_flash_read(flashOffset, size, ramData);
+}
+
+unsigned int IoTFlashWrite(unsigned int flashOffset, unsigned int size,
+ const unsigned char *ramData, unsigned char doErase)
+{
+ return hi_flash_write(flashOffset, size, ramData, doErase);
+}
+
+unsigned int IoTFlashErase(unsigned int flashOffset, unsigned int size)
+{
+ return hi_flash_erase(flashOffset, size);
+}
+
+unsigned int IoTFlashInit(void)
+{
+ return hi_flash_init();
+}
+
+unsigned int IoTFlashDeinit(void)
+{
+ return hi_flash_deinit();
+}
diff --git a/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_gpio.c b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_gpio.c
new file mode 100755
index 0000000000000000000000000000000000000000..9c92fa9635a604239ba719a270793d79079b3d8d
--- /dev/null
+++ b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_gpio.c
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * 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 "iot_errno.h"
+#include "iot_gpio.h"
+#include "hi_gpio.h"
+
+
+#define GPIO_PIN_INIT 1
+#define GPIO_PIN_UNINIT 0
+
+static unsigned char g_gpioMap[HI_GPIO_IDX_MAX] = {0};
+static unsigned char g_gpioInitNum = 0;
+
+unsigned int IoTGpioInit(unsigned int id)
+{
+ if (id >= HI_GPIO_IDX_MAX) {
+ return IOT_FAILURE;
+ }
+
+ if (g_gpioInitNum == 0) {
+ (void)hi_gpio_init();
+ }
+
+ if (g_gpioMap[id] == GPIO_PIN_INIT) {
+ return IOT_FAILURE;
+ } else {
+ g_gpioMap[id] = GPIO_PIN_INIT;
+ g_gpioInitNum++;
+ }
+
+ return IOT_SUCCESS;
+}
+
+unsigned int IoTGpioSetDir(unsigned int id, IotGpioDir dir)
+{
+ return hi_gpio_set_dir((hi_gpio_idx)id, (hi_gpio_dir)dir);
+}
+
+unsigned int IoTGpioGetDir(unsigned int id, IotGpioDir *dir)
+{
+ return hi_gpio_get_dir((hi_gpio_idx)id, (hi_gpio_dir *)dir);
+}
+
+unsigned int IoTGpioSetOutputVal(unsigned int id, IotGpioValue val)
+{
+ return hi_gpio_set_ouput_val((hi_gpio_idx)id, (hi_gpio_value)val);
+}
+
+unsigned int IoTGpioGetOutputVal(unsigned int id, IotGpioValue *val)
+{
+ return hi_gpio_get_output_val((hi_gpio_idx)id, (hi_gpio_value *)val);
+}
+
+unsigned int IoTGpioGetInputVal(unsigned int id, IotGpioValue *val)
+{
+ return hi_gpio_get_input_val((hi_gpio_idx)id, (hi_gpio_value *)val);
+}
+
+unsigned int IoTGpioRegisterIsrFunc(unsigned int id, IotGpioIntType intType, IotGpioIntPolarity intPolarity,
+ GpioIsrCallbackFunc func, char *arg)
+{
+ return hi_gpio_register_isr_function((hi_gpio_idx)id, (hi_gpio_int_type)intType,
+ (hi_gpio_int_polarity)intPolarity, (gpio_isr_callback)func, arg);
+}
+
+unsigned int IoTGpioUnregisterIsrFunc(unsigned int id)
+{
+ return hi_gpio_unregister_isr_function((hi_gpio_idx)id);
+}
+
+unsigned int IoTGpioSetIsrMask(unsigned int id, unsigned char mask)
+{
+ return hi_gpio_set_isr_mask((hi_gpio_idx)id, (hi_bool)mask);
+}
+
+unsigned int IoTGpioSetIsrMode(unsigned int id, IotGpioIntType intType, IotGpioIntPolarity intPolarity)
+{
+ return hi_gpio_set_isr_mode((hi_gpio_idx)id, (hi_gpio_int_type)intType, (hi_gpio_int_polarity)intPolarity);
+}
+
+unsigned int IoTGpioDeinit(unsigned int id)
+{
+ if (id >= HI_GPIO_IDX_MAX) {
+ return IOT_FAILURE;
+ }
+
+ if (g_gpioMap[id] == GPIO_PIN_INIT) {
+ g_gpioInitNum--;
+ g_gpioMap[id] = GPIO_PIN_UNINIT;
+ } else {
+ return IOT_FAILURE;
+ }
+
+ if (g_gpioInitNum == 0) {
+ return hi_gpio_deinit();
+ } else {
+ return IOT_SUCCESS;
+ }
+}
+
diff --git a/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_i2c.c b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_i2c.c
new file mode 100755
index 0000000000000000000000000000000000000000..9195994bb6c4e8747664c8d82279396e8435f356
--- /dev/null
+++ b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_i2c.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * 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 "iot_errno.h"
+#include "iot_i2c.h"
+#include "hi_i2c.h"
+
+unsigned int IoTI2cWrite(unsigned int id, unsigned short deviceAddr, const unsigned char *data, unsigned int dataLen) {
+ hi_i2c_data i2cData;
+ i2cData.receive_buf = NULL;
+ i2cData.receive_len = 0;
+ i2cData.send_buf = data;
+ i2cData.send_len = dataLen;
+
+ return hi_i2c_write((hi_i2c_idx) id, deviceAddr, &i2cData);
+}
+
+unsigned int IoTI2cRead(unsigned int id, unsigned short deviceAddr, unsigned char *data, unsigned int dataLen) {
+ hi_i2c_data i2cData;
+ i2cData.receive_buf = data;
+ i2cData.receive_len = dataLen;
+ i2cData.send_buf = NULL;
+ i2cData.send_len = 0;
+
+ return hi_i2c_read((hi_i2c_idx) id, deviceAddr, &i2cData);
+}
+
+unsigned int IoTI2cWriteRead(unsigned int id, unsigned short deviceAddr,
+ const unsigned char *writeData, unsigned int writeDataLen,
+ unsigned char *readData, unsigned int readDataLen) {
+ hi_i2c_data i2cData;
+ i2cData.receive_buf = readData;
+ i2cData.receive_len = readDataLen;
+ i2cData.send_buf = writeData;
+ i2cData.send_len = writeDataLen;
+
+ return hi_i2c_writeread((hi_i2c_idx) id, deviceAddr, &i2cData);
+}
+
+unsigned int IoTI2cInit(unsigned int id, unsigned int baudrate) {
+ return hi_i2c_init((hi_i2c_idx) id, baudrate);
+}
+
+unsigned int IoTI2cDeinit(unsigned int id) {
+ return hi_i2c_deinit((hi_i2c_idx) id);
+}
+
+unsigned int IoTI2cSetBaudrate(unsigned int id, unsigned int baudrate) {
+ return hi_i2c_set_baudrate((hi_i2c_idx) id, baudrate);
+}
diff --git a/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_io.c b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_io.c
new file mode 100644
index 0000000000000000000000000000000000000000..4f3d27f28fa0327294888652eca582729e7e2291
--- /dev/null
+++ b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_io.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2020 Itcast Co., Ltd.
+ * 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 "iot_errno.h"
+#include "iot_io.h"
+
+#include "hi_io.h"
+#include "hi_gpio.h"
+#include "genki_pin.h"
+
+unsigned int IoTIoSetPull(unsigned int id, IoTIoPull val) {
+ if (id >= HI_GPIO_IDX_MAX) {
+ return IOT_FAILURE;
+ }
+ return hi_io_set_pull((hi_io_name) id, (hi_io_pull) val);
+}
+
+unsigned int IoTIoSetFunc(unsigned int id, unsigned char val) {
+ if (id >= HI_GPIO_IDX_MAX) {
+ return IOT_FAILURE;
+ }
+ return hi_io_set_func((hi_io_name) id, val);
+}
+
+unsigned int IoTIoGetPull(unsigned int id, IoTIoPull *val) {
+ if (id >= HI_GPIO_IDX_MAX) {
+ return IOT_FAILURE;
+ }
+ return hi_io_get_pull((hi_io_name) id, (hi_io_pull *) val);
+}
+
+unsigned int IoTIoGetFunc(unsigned int id, unsigned char *val) {
+ if (id >= HI_GPIO_IDX_MAX) {
+ return IOT_FAILURE;
+ }
+ return hi_io_get_func((hi_io_name) id, val);
+}
+
+unsigned int IoTIoGetDriverStrength(unsigned int id, IoTIoDriverStrength *val) {
+ if (id >= HI_GPIO_IDX_MAX) {
+ return IOT_FAILURE;
+ }
+ return hi_io_get_driver_strength((hi_io_name) id, (hi_io_driver_strength *) val);
+}
+
+unsigned int IoTIoSetDriverStrength(unsigned int id, IoTIoDriverStrength val) {
+ if (id >= HI_GPIO_IDX_MAX) {
+ return IOT_FAILURE;
+ }
+ return hi_io_set_driver_strength((hi_io_name) id, (hi_io_driver_strength) val);
+}
\ No newline at end of file
diff --git a/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_pwm.c b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_pwm.c
new file mode 100755
index 0000000000000000000000000000000000000000..a7cbe5e7d7e74c3072d37905a025232529b78c22
--- /dev/null
+++ b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_pwm.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * 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 "iot_errno.h"
+#include "iot_pwm.h"
+#include "hi_pwm.h"
+#include "hi_errno.h"
+
+#define CLK_160M 160000000
+#define DUTY_MIN 0
+#define DUTY_MAX 100
+#define SHORT_MAX 0xFFFF
+
+unsigned int IoTPwmInit(unsigned int port)
+{
+ if (hi_pwm_set_clock(PWM_CLK_160M) != HI_ERR_SUCCESS) {
+ return IOT_FAILURE;
+ }
+ return hi_pwm_init((hi_pwm_port)port);
+}
+
+unsigned int IoTPwmDeinit(unsigned int port)
+{
+ return hi_pwm_deinit((hi_pwm_port)port);
+}
+
+unsigned int IoTPwmStart(unsigned int port, unsigned short duty, unsigned int freq)
+{
+ unsigned short hiDuty;
+ unsigned short hiFreq;
+
+ if ((freq == 0) || (duty >= DUTY_MAX) || (duty == DUTY_MIN)) {
+ return IOT_FAILURE;
+ }
+
+ if ((CLK_160M / freq) > SHORT_MAX) {
+ return IOT_FAILURE;
+ }
+
+ hiFreq = (unsigned short)(CLK_160M / freq);
+ hiDuty = (duty * hiFreq) / DUTY_MAX;
+
+ return hi_pwm_start((hi_pwm_port)port, hiDuty, hiFreq);
+}
+
+unsigned int IoTPwmStop(unsigned int port)
+{
+ return hi_pwm_stop((hi_pwm_port)port);
+}
+
diff --git a/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_spi.c b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_spi.c
new file mode 100644
index 0000000000000000000000000000000000000000..1da873139c1d81ed4f8f637c0caf361130afb9bd
--- /dev/null
+++ b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_spi.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2020 Itcast Co., Ltd.
+ * 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 "iot_spi.h"
+
+#include
+
+#include "hi_spi.h"
+
+unsigned int IoTSpiSlaveWrite(IoTSpiIdx spiId, char *writeData, unsigned int byteLen, unsigned int timeOutMs) {
+ return hi_spi_slave_write((hi_spi_idx) spiId, writeData, byteLen, timeOutMs);
+}
+
+unsigned int IoTSpiSlaveRead(IoTSpiIdx spiId, char *readData, unsigned int byteLen, unsigned int timeOutMs) {
+ return hi_spi_slave_read((hi_spi_idx) spiId, readData, byteLen, timeOutMs);
+}
+
+unsigned int IoTSpiHostWrite(IoTSpiIdx spiId, char *writeData, unsigned int byteLen) {
+ return hi_spi_host_write((hi_spi_idx) spiId, writeData, byteLen);
+}
+
+unsigned int IoTSpiHostRead(IoTSpiIdx spiId, char *readData, unsigned int byteLen) {
+ return hi_spi_host_read((hi_spi_idx) spiId, readData, byteLen);
+}
+
+unsigned int IoTSpiHostWriteread(IoTSpiIdx spiId, char *writeData, char *readData, unsigned int byteLen) {
+ return hi_spi_host_writeread((hi_spi_idx) spiId, writeData, readData, byteLen);
+}
+
+unsigned int IoTSpiSetBasicInfo(IoTSpiIdx spiId, const IoTSpiCfgBasicInfo *param) {
+ return hi_spi_set_basic_info((hi_spi_idx) spiId, (const hi_spi_cfg_basic_info *) param);
+}
+
+unsigned int IoTSpiInit(IoTSpiIdx spiId, IoTSpiCfgInitParam initParam,
+ const IoTSpiCfgBasicInfo *param) {
+ hi_spi_cfg_init_param hiInitParam;
+ hiInitParam.is_slave = initParam.isSlave;
+ hiInitParam.pad = initParam.pad;
+ return hi_spi_init((hi_spi_idx) spiId, hiInitParam, (const hi_spi_cfg_basic_info *) param);
+}
+
+unsigned int IoTSpiDeinit(IoTSpiIdx spiId) {
+ return hi_spi_deinit((hi_spi_idx) spiId);
+}
+
+unsigned int IoTSpiSetIrqMode(IoTSpiIdx spiId, unsigned char irqEn) {
+ return hi_spi_set_irq_mode((hi_spi_idx) spiId, irqEn);
+}
+
+unsigned int IoTSpiSetDmaMode(IoTSpiIdx spiId, unsigned char dmaEn) {
+ return hi_spi_set_dma_mode((hi_spi_idx) spiId, dmaEn);
+}
+
+unsigned int IoTSpiRegisterUsrFunc(IoTSpiIdx spiId, SpiIsrFunc prepareF, SpiIsrFunc restoreF) {
+ return hi_spi_register_usr_func((hi_spi_idx) spiId, prepareF, restoreF);
+}
+
+unsigned int IoTSpiSetLoopBackMode(IoTSpiIdx spiId, unsigned char lbEn) {
+ return hi_spi_set_loop_back_mode((hi_spi_idx) spiId, lbEn);
+}
diff --git a/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_uart.c b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_uart.c
new file mode 100755
index 0000000000000000000000000000000000000000..eb34401880f716e05f3fef9a053560fe6db8ed3f
--- /dev/null
+++ b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_uart.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * 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 "iot_errno.h"
+#include "iot_uart.h"
+#include "hi_uart.h"
+
+unsigned int IoTUartInit(unsigned int id, const IotUartAttribute *param)
+{
+ hi_uart_attribute attr = {0};
+ hi_uart_extra_attr extraAttr = {0};
+
+ if (NULL == param) {
+ return IOT_FAILURE;
+ }
+
+ attr.baud_rate = param->baudRate;
+ attr.data_bits = param->dataBits;
+ attr.pad = param->pad;
+ attr.parity = param->parity;
+ attr.stop_bits = param->stopBits;
+
+ if (IOT_UART_BLOCK_STATE_NONE_BLOCK == param->rxBlock) {
+ extraAttr.rx_block = HI_UART_BLOCK_STATE_NONE_BLOCK;
+ } else {
+ extraAttr.rx_block = HI_UART_BLOCK_STATE_BLOCK;
+ }
+
+ if (IOT_UART_BLOCK_STATE_NONE_BLOCK == param->txBlock) {
+ extraAttr.tx_block = HI_UART_BLOCK_STATE_NONE_BLOCK;
+ } else {
+ extraAttr.tx_block = HI_UART_BLOCK_STATE_BLOCK;
+ }
+
+ return hi_uart_init((hi_uart_idx)id, &attr, &extraAttr);
+}
+
+int IoTUartRead(unsigned int id, unsigned char *data, unsigned int dataLen)
+{
+ return hi_uart_read((hi_uart_idx)id, data, dataLen);
+}
+
+int IoTUartWrite(unsigned int id, const unsigned char *data, unsigned int dataLen)
+{
+ return hi_uart_write((hi_uart_idx)id, data, dataLen);
+}
+
+unsigned int IoTUartDeinit(unsigned int id)
+{
+ return hi_uart_deinit((hi_uart_idx)id);
+}
+
+unsigned int IoTUartSetFlowCtrl(unsigned int id, IotFlowCtrl flowCtrl)
+{
+ return hi_uart_set_flow_ctrl((hi_uart_idx)id, (hi_flow_ctrl)flowCtrl);
+}
diff --git a/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_watchdog.c b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_watchdog.c
new file mode 100755
index 0000000000000000000000000000000000000000..cf34ac83b73d78a5fe799dd4e2fdeb51507256e2
--- /dev/null
+++ b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_iot_watchdog.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * 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 "iot_errno.h"
+#include "iot_watchdog.h"
+#include "hi_watchdog.h"
+
+void IoTWatchDogEnable(void)
+{
+ return hi_watchdog_enable();
+}
+
+void IoTWatchDogKick(void)
+{
+ return hi_watchdog_feed();
+}
+
+void IoTWatchDogDisable(void)
+{
+ return hi_watchdog_disable();
+}
+
diff --git a/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_lowpower.c b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_lowpower.c
new file mode 100755
index 0000000000000000000000000000000000000000..0d1417a943acd11557231fbea91b9110fefd1769
--- /dev/null
+++ b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_lowpower.c
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * 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 "lowpower.h"
+#include "hi_lowpower.h"
+
+unsigned int LpcInit(void)
+{
+ return hi_lpc_init();
+}
+
+unsigned int LpcSetType(LpcType type)
+{
+ return hi_lpc_set_type(type);
+}
+
diff --git a/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_reset.c b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_reset.c
new file mode 100755
index 0000000000000000000000000000000000000000..c82f531d25cde61f6f1efebfe390e39f99d7ae05
--- /dev/null
+++ b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_reset.c
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * 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 "reset.h"
+#include "hi_reset.h"
+
+void RebootDevice(unsigned int cause)
+{
+ hi_hard_reboot(cause);
+}
\ No newline at end of file
diff --git a/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_time.c b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_time.c
new file mode 100644
index 0000000000000000000000000000000000000000..8bb308ca4008a25e9f7642ad43ed35987bcc7d18
--- /dev/null
+++ b/hi3861_adapter/hals/iot_hardware/wifiiot_lite/hal_time.c
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2020 Itcast Co., Ltd.
+ * 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 "time.h"
+#include "hi_time.h"
+
+void IoTUdelay(unsigned int us) {
+ return hi_udelay((hi_u32) us);
+}
+
+unsigned int IoTGetTick(void) {
+ return hi_get_tick();
+}
+
+unsigned long long IoTGetTick64(void) {
+ return hi_get_tick64();
+}
+
+unsigned int IoTGetMilliSeconds(void) {
+ return hi_get_milli_seconds();
+}
+
+unsigned int IoTGetSeconds(void) {
+ return hi_get_seconds();
+}
+
+unsigned long IoTGetUs(void) {
+ return hi_get_us();
+}
diff --git a/hi3861_adapter/hals/update/BUILD.gn b/hi3861_adapter/hals/update/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..b3db6f0347e226ce4b6523f58685378b59da514a
--- /dev/null
+++ b/hi3861_adapter/hals/update/BUILD.gn
@@ -0,0 +1,23 @@
+# Copyright (c) 2020 Huawei Device Co., Ltd.
+# 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.
+
+import("//build/lite/config/component/lite_component.gni")
+
+static_library("hal_update_static") {
+ sources = [ "hal_hota_board.c" ]
+ include_dirs = [
+ "//base/update/ota_lite/hals",
+ "//base/update/ota_lite/interfaces/kits",
+ "//device/itcast/genkipi/sdk_liteos/include",
+ ]
+}
diff --git a/hi3861_adapter/hals/update/hal_hota_board.c b/hi3861_adapter/hals/update/hal_hota_board.c
new file mode 100644
index 0000000000000000000000000000000000000000..37116bafaec7d6e2b872302245db4fe3e5c93f57
--- /dev/null
+++ b/hi3861_adapter/hals/update/hal_hota_board.c
@@ -0,0 +1,202 @@
+/*
+ * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * 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 "hal_hota_board.h"
+#include "hi_upg_api.h"
+#include "stdio.h"
+
+#define PUBKEY_LENGTH 270
+
+
+static const unsigned char g_pubKeyBuf[PUBKEY_LENGTH] = {
+ 0x30, 0x82, 0x01, 0x0A, 0x02, 0x82, 0x01, 0x01, 0x00, 0xBF, 0xAA, 0xA5, 0xB3, 0xC2, 0x78, 0x5E,
+ 0x63, 0x07, 0x84, 0xCF, 0x37, 0xF0, 0x45, 0xE8, 0xB9, 0x6E, 0xEF, 0x04, 0x88, 0xD3, 0x43, 0x06,
+ 0x2C, 0xFC, 0x09, 0x8C, 0x84, 0x3B, 0x43, 0x07, 0x89, 0x6B, 0x23, 0x8F, 0xA2, 0xF0, 0x9D, 0x91,
+ 0xCB, 0xA8, 0x02, 0x60, 0xD8, 0x5C, 0x18, 0xD9, 0x34, 0xF0, 0x3C, 0x49, 0x10, 0x0E, 0xE3, 0xC7,
+ 0x19, 0xA5, 0x51, 0x93, 0x38, 0xFD, 0xE0, 0x62, 0x64, 0xBA, 0x6D, 0x11, 0x2E, 0xE1, 0x6E, 0x60,
+ 0x12, 0x16, 0x1B, 0x35, 0xA6, 0x54, 0x3F, 0x0B, 0x5D, 0x54, 0x08, 0xC9, 0x23, 0x51, 0x15, 0xA9,
+ 0xE2, 0x07, 0xCC, 0xF9, 0xFD, 0x19, 0x8A, 0xB3, 0x7E, 0xCE, 0x69, 0xED, 0x26, 0x34, 0xD2, 0x02,
+ 0xF3, 0xEB, 0x07, 0x13, 0x69, 0xE3, 0x03, 0x87, 0xB3, 0x6A, 0x3E, 0x91, 0x94, 0xAC, 0x2C, 0xBA,
+ 0xF6, 0xEE, 0x4C, 0x41, 0x0C, 0x2E, 0xD0, 0xE7, 0x58, 0xA7, 0xE6, 0x7F, 0x1A, 0xC0, 0xB8, 0xE3,
+ 0x12, 0x18, 0x97, 0x8D, 0x99, 0xAB, 0x35, 0x7B, 0xAD, 0x41, 0xA0, 0xFB, 0xCB, 0x23, 0xF6, 0x51,
+ 0xE6, 0x94, 0x1F, 0xF7, 0xD8, 0x16, 0xCD, 0x15, 0x67, 0x59, 0x10, 0xA2, 0x40, 0x55, 0xD1, 0x67,
+ 0xDA, 0x18, 0xCD, 0x63, 0x5B, 0x10, 0xAF, 0x22, 0x99, 0xD8, 0x9D, 0x56, 0x66, 0xCD, 0x80, 0x64,
+ 0x32, 0xB5, 0xD7, 0xF5, 0xBA, 0x91, 0x4A, 0x8D, 0x97, 0x14, 0x8A, 0xB2, 0xB0, 0x42, 0x4A, 0xE6,
+ 0x43, 0x22, 0x3B, 0x6E, 0xD6, 0x1E, 0x1F, 0xDA, 0xEC, 0x83, 0xCF, 0x20, 0xFA, 0x02, 0xF3, 0xFB,
+ 0x6E, 0x09, 0x2A, 0x0D, 0xB7, 0x81, 0x1E, 0xD5, 0x71, 0xDF, 0x80, 0xC5, 0x33, 0x78, 0xE5, 0x41,
+ 0x33, 0xDF, 0x9A, 0xBD, 0x36, 0x51, 0xAC, 0x96, 0xF4, 0xC6, 0x11, 0xC3, 0x93, 0x78, 0x26, 0x96,
+ 0x9F, 0x67, 0x05, 0x1D, 0xDF, 0xB3, 0xAA, 0x26, 0x25, 0x02, 0x03, 0x01, 0x00, 0x01
+};
+typedef enum {
+ PARTITION_PASS_THROUGH = 0,
+ PARTITION_BOOTLOADER = 2,
+ PARTITION_KERNEL_A = 3,
+ PARTITION_KERNEL_B = 4,
+ PARTITION_ROOTFS = 5,
+ PARTITION_APP = 6,
+ PARTITION_DATA = 7,
+ PARTITION_OTA_TAG = 8,
+ PARTITION_OTA_CONFIG = 9,
+ PARTITION_ROOTFS_EXT4 = 10,
+ PARTITION_MAX
+} HotaPartition;
+
+static const ComponentTableInfo g_componentTable[] = {
+ { PARTITION_PASS_THROUGH, "", "/sdcard/update/ota_pkg_pass_through.bin", 0},
+ { PARTITION_INFO_COMP, "", "/sdcard/update/infocomp.bin", 0},
+ { PARTITION_BOOTLOADER, "bootloader", "/sdcard/update/u-boot.bin", 0},
+ { PARTITION_KERNEL_A, "kernel_A", "/sdcard/update/kernel.bin", 0},
+ { PARTITION_KERNEL_B, "kernel_B", "", 0},
+ { PARTITION_ROOTFS, "rootfs", "/sdcard/update/rootfs.img", 0},
+ { PARTITION_APP, "app", "", 0},
+ { PARTITION_DATA, "data", "", 0},
+ { PARTITION_OTA_TAG, "ota_tag", "/sdcard/update/OTA.tag", 0},
+ { PARTITION_OTA_CONFIG, "config", "/sdcard/update/config", 0},
+ { PARTITION_ROOTFS_EXT4, "rootfs_ext4", "/sdcard/update/rootfs_ext4.img", 0},
+ { PARTITION_MAX, NULL, NULL, 0}
+};
+int HotaHalInit(void)
+{
+ hi_u32 result = hi_upg_init();
+ if (result != HI_ERR_SUCCESS && result != HI_ERR_UPG_INITILIZATION_ALREADY) {
+ printf("hi_upg_init Failed.Result = %x.\r\n", result);
+ return OHOS_FAILURE;
+ }
+ return OHOS_SUCCESS;
+}
+
+int HotaHalGetUpdateIndex(unsigned int *index)
+{
+ if (hi_upg_get_file_index((hi_u8 *)index) != HI_ERR_SUCCESS) {
+ printf("get upgrade index error\r\n");
+ return OHOS_FAILURE;
+ }
+ return OHOS_SUCCESS;
+}
+
+int HotaHalDeInit(void)
+{
+ hi_u32 result = hi_upg_stop();
+ if (result != HI_ERR_SUCCESS) {
+ printf("hi_upg_stop Failed.Result = %x.\r\n", result);
+ return OHOS_FAILURE;
+ }
+ return OHOS_SUCCESS;
+}
+
+int HotaHalRead(int partition, unsigned int offset, unsigned int bufLen, unsigned char *buffer)
+{
+ if ((buffer == NULL) || (bufLen == 0)) {
+ return OHOS_FAILURE;
+ }
+
+ if (hi_upg_get_content(offset, buffer, bufLen) != HI_ERR_SUCCESS) {
+ printf("get ota content error! Partition: %d\r\n", partition);
+ return OHOS_FAILURE;
+ }
+
+ return OHOS_SUCCESS;
+}
+
+int HotaHalWrite(int partition, unsigned char *buffer, unsigned int offset, unsigned int buffLen)
+{
+ if (partition == PARTITION_INFO_COMP) {
+ printf("partition == PARTITION_INFO_COMP, skip it.");
+ return OHOS_SUCCESS;
+ }
+ hi_u32 result = hi_upg_transmit(offset, buffer, buffLen);
+ if (result != HI_ERR_SUCCESS) {
+ printf("hi_upg_transmit failed. retCode = %x.\r\n", result);
+ return OHOS_FAILURE;
+ }
+ return OHOS_SUCCESS;
+}
+
+int HotaHalRestart(void)
+{
+ hi_upg_finish_with_cache();
+ return OHOS_SUCCESS;
+}
+
+int HotaHalSetBootSettings(void)
+{
+ hi_u32 result = hi_upg_transmit_finish_save_cache();
+ if (result != HI_ERR_SUCCESS) {
+ printf("hi_upg_transmit_finish failed. retCode = %x.\r\n", result);
+ return OHOS_FAILURE;
+ }
+ return OHOS_SUCCESS;
+}
+
+int HotaHalRollback(void)
+{
+ return OHOS_SUCCESS;
+}
+
+const ComponentTableInfo *HotaHalGetPartitionInfo()
+{
+ return g_componentTable;
+}
+
+unsigned char *HotaHalGetPubKey(unsigned int *length)
+{
+ if (length == NULL) {
+ printf("OTA pub key is NULL.\r\n");
+ return NULL;
+ }
+
+ *length = sizeof(g_pubKeyBuf);
+ return (unsigned char *)g_pubKeyBuf;
+}
+
+
+int HotaHalGetUpdateAbility(void)
+{
+ return ABILITY_PKG_SEARCH | ABILITY_PKG_DLOAD;
+}
+
+int HotaHalGetOtaPkgPath(char *path, int len)
+{
+ int ret = strcpy_s(path, len ,"/sdcard");
+ if (ret != 0) {
+ return OHOS_FAILURE;
+ }
+ return OHOS_SUCCESS;
+}
+
+int HotaHalIsDeviceCanReboot(void)
+{
+ return 1;
+}
+
+int HotaHalGetMetaData(UpdateMetaData *metaData)
+{
+ return OHOS_SUCCESS;
+}
+
+int HotaHalSetMetaData(UpdateMetaData *metaData)
+{
+ return OHOS_SUCCESS;
+}
+
+int HotaHalRebootAndCleanUserData(void)
+{
+ return OHOS_SUCCESS;
+}
+
+int HotaHalRebootAndCleanCache(void)
+{
+ return OHOS_SUCCESS;
+}
diff --git a/hi3861_adapter/hals/utils/file/BUILD.gn b/hi3861_adapter/hals/utils/file/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..d8d74a9ef6168544b914c4e50a0c49bff71baa10
--- /dev/null
+++ b/hi3861_adapter/hals/utils/file/BUILD.gn
@@ -0,0 +1,22 @@
+# Copyright (c) 2020 Huawei Device Co., Ltd.
+# 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.
+
+import("//build/lite/config/component/lite_component.gni")
+
+static_library("hal_file_static") {
+ sources = [ "src/hal_file.c" ]
+ include_dirs = [
+ "//utils/native/lite/hals/file",
+ "//device/itcast/genkipi/sdk_liteos/include",
+ ]
+}
diff --git a/hi3861_adapter/hals/utils/file/src/hal_file.c b/hi3861_adapter/hals/utils/file/src/hal_file.c
new file mode 100755
index 0000000000000000000000000000000000000000..eb23282f5d6921107bba747033c3137b9b77a43f
--- /dev/null
+++ b/hi3861_adapter/hals/utils/file/src/hal_file.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * 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 "hal_file.h"
+#include "hi_fs.h"
+
+int HalFileOpen(const char* path, int oflag, int mode)
+{
+ (void)mode;
+ return hi_open(path, oflag);
+}
+
+int HalFileClose(int fd)
+{
+ return hi_close(fd);
+}
+
+int HalFileRead(int fd, char *buf, unsigned int len)
+{
+ return hi_read(fd, buf, len);
+}
+
+int HalFileWrite(int fd, const char *buf, unsigned int len)
+{
+ return hi_write(fd, buf, len);
+}
+
+int HalFileDelete(const char *path)
+{
+ return hi_unlink(path);
+}
+
+int HalFileStat(const char *path, unsigned int *fileSize)
+{
+ return hi_stat(path, fileSize);
+}
+
+int HalFileSeek(int fd, int offset, unsigned int whence)
+{
+ return hi_lseek(fd, offset, whence);
+}
diff --git a/hi3861_adapter/kal/BUILD.gn b/hi3861_adapter/kal/BUILD.gn
new file mode 100755
index 0000000000000000000000000000000000000000..883dbd528c11ce8febcfc8982adc5c417059ee4c
--- /dev/null
+++ b/hi3861_adapter/kal/BUILD.gn
@@ -0,0 +1,37 @@
+# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+#
+# 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 the copyright holder 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.
+
+import("//build/lite/config/component/lite_component.gni")
+
+lite_component("kal") {
+ features = [
+ "posix",
+ "cmsis",
+ ]
+}
diff --git a/hi3861_adapter/kal/cmsis/BUILD.gn b/hi3861_adapter/kal/cmsis/BUILD.gn
new file mode 100755
index 0000000000000000000000000000000000000000..d71e564fea328fa8d38abc966c81cb2b52e50671
--- /dev/null
+++ b/hi3861_adapter/kal/cmsis/BUILD.gn
@@ -0,0 +1,43 @@
+# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+#
+# 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 the copyright holder 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.
+
+import("//build/lite/config/component/lite_component.gni")
+
+static_library("cmsis") {
+ sources = [ "cmsis_liteos.c" ]
+
+ include_dirs = [
+ "//device/itcast/genkipi/hi3861_adapter/kal/cmsis",
+ "//third_party/bounds_checking_function/include",
+ ]
+
+ defines = [ "LITEOS_WIFI_IOT_VERSION" ]
+
+ cflags = [ "-Wno-error" ]
+}
diff --git a/hi3861_adapter/kal/cmsis/LICENSE.txt b/hi3861_adapter/kal/cmsis/LICENSE.txt
new file mode 100644
index 0000000000000000000000000000000000000000..8dada3edaf50dbc082c9a125058f25def75e625a
--- /dev/null
+++ b/hi3861_adapter/kal/cmsis/LICENSE.txt
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "{}"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright {yyyy} {name of copyright owner}
+
+ 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.
diff --git a/hi3861_adapter/kal/cmsis/README.OpenSource b/hi3861_adapter/kal/cmsis/README.OpenSource
new file mode 100644
index 0000000000000000000000000000000000000000..cc522613d1c88775821e7297975e4221cf4f5f21
--- /dev/null
+++ b/hi3861_adapter/kal/cmsis/README.OpenSource
@@ -0,0 +1,10 @@
+[
+ {
+ "Name" : "CMSIS",
+ "License" : "Apache License V2.0",
+ "License File" : "LICENSE.txt",
+ "Version Number" : "5.7.0",
+ "Upstream URL" : "http://www.arm.com/zh/products/processors/cortex-m/cortex-microcontroller-software-interface-standard.php",
+ "Description" : "The Cortex Microcontroller Software Interface Standard (CMSIS) is a vendor-independent hardware abstraction layer for microcontrollers that are based on Arm® Cortex® processors"
+ }
+]
diff --git a/hi3861_adapter/kal/cmsis/cmsis_liteos.c b/hi3861_adapter/kal/cmsis/cmsis_liteos.c
new file mode 100755
index 0000000000000000000000000000000000000000..641cd694655298412fd23171471a1d69ebd5b490
--- /dev/null
+++ b/hi3861_adapter/kal/cmsis/cmsis_liteos.c
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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 the copyright holder 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.
+ */
+
+#include "los_config.h"
+
+#if (CMSIS_OS_VER == 1)
+#error "cmsis version 1.0 is not supported now!"
+#elif (CMSIS_OS_VER == 2)
+#include "cmsis_liteos2.c"
+#endif
diff --git a/hi3861_adapter/kal/cmsis/cmsis_liteos2.c b/hi3861_adapter/kal/cmsis/cmsis_liteos2.c
new file mode 100755
index 0000000000000000000000000000000000000000..c9b7e17c7e733a66e0666fe4de6b11b89e8c130b
--- /dev/null
+++ b/hi3861_adapter/kal/cmsis/cmsis_liteos2.c
@@ -0,0 +1,1386 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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 the copyright holder 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.
+ */
+
+#include "cmsis_os.h"
+#include "los_typedef.h"
+#include "los_printf.h"
+
+#include "los_event.h"
+#include "los_membox.h"
+#include "los_memory.h"
+#include "los_hwi.h"
+
+#include "los_mux_pri.h"
+#include "los_queue_pri.h"
+#include "los_sem_pri.h"
+#include "los_swtmr_pri.h"
+#include "los_sys_pri.h"
+#include "los_task_pri.h"
+#include "los_tick_pri.h"
+#include "string.h"
+#include "securec.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+#if (CMSIS_OS_VER == 2)
+
+/* Kernel initialization state */
+static osKernelState_t g_kernelState;
+
+extern BOOL g_taskScheduled;
+
+#define LOS_PRIORITY_WIN 8
+
+const osVersion_t g_stLosVersion = { 001, 001 };
+
+#define LITEOS_VERSION_MAJOR 1
+#define LITEOS_VERSION_MINOR 0
+#define LITEOS_VERSION_BUILD 0
+
+/* Kernel version and identification string definition */
+#define KERNEL_VERSION (((UINT32)LITEOS_VERSION_MAJOR * 10000000UL) | \
+ ((UINT32)LITEOS_VERSION_MINOR * 10000UL) | \
+ ((UINT32)LITEOS_VERSION_BUILD * 1UL))
+
+#define KERNEL_ID "HUAWEI-LiteOS"
+#define UNUSED(var) do { (void)var; } while (0)
+
+// ==== Kernel Management Functions ====
+uint32_t osTaskStackWaterMarkGet(UINT32 taskID);
+
+
+osStatus_t osKernelInitialize(void)
+{
+ if (OS_INT_ACTIVE) {
+ return osErrorISR;
+ }
+
+ if (g_kernelState != osKernelInactive) {
+ return osError;
+ }
+
+ if (LOS_OK == LOS_KernelInit()) {
+ g_kernelState = osKernelReady;
+ return osOK;
+ } else {
+ return osError;
+ }
+}
+
+
+osStatus_t osKernelGetInfo(osVersion_t *version, char *id_buf, uint32_t id_size)
+{
+ uint32_t uwRet;
+
+ if (OS_INT_ACTIVE) {
+ return osErrorISR;
+ }
+
+ if (version != NULL) {
+ version->api = g_stLosVersion.api;
+ version->kernel = g_stLosVersion.kernel;
+ }
+
+ if ((id_buf != NULL) && (id_size != 0U)) {
+ if (id_size > sizeof(KERNEL_ID)) {
+ id_size = sizeof(KERNEL_ID);
+ }
+ uwRet = memcpy_s(id_buf, id_size, KERNEL_ID, id_size);
+ if (uwRet != EOK) {
+ PRINT_ERR("%s[%d] memcpy failed, error type = %u\n", __FUNCTION__, __LINE__, uwRet);
+ return osError;
+ }
+ }
+
+ return osOK;
+}
+
+
+osKernelState_t osKernelGetState(void)
+{
+ if (OS_INT_ACTIVE) {
+ return osKernelError;
+ }
+
+ if (!g_taskScheduled) {
+ if (g_kernelState == osKernelReady) {
+ return osKernelReady;
+ } else {
+ return osKernelInactive;
+ }
+ } else if (g_losTaskLock > 0) {
+ return osKernelLocked;
+ } else {
+ return osKernelRunning;
+ }
+}
+
+
+osStatus_t osKernelStart(void)
+{
+ if (OS_INT_ACTIVE) {
+ return osErrorISR;
+ }
+
+ if (g_kernelState == osKernelReady) {
+ if (LOS_OK == LOS_Start()) {
+ g_kernelState = osKernelRunning;
+ return osOK;
+ } else {
+ return osError;
+ }
+ } else {
+ return osError;
+ }
+}
+
+
+int32_t osKernelLock(void)
+{
+ int32_t lock;
+
+ if (OS_INT_ACTIVE) {
+ return (int32_t)osErrorISR;
+ }
+
+ if (!g_taskScheduled) {
+ return (int32_t)osError;
+ }
+
+ if (g_losTaskLock > 0) {
+ lock = 1;
+ } else {
+ LOS_TaskLock();
+ lock = 0;
+ }
+
+ return lock;
+}
+
+
+int32_t osKernelUnlock(void)
+{
+ int32_t lock;
+
+ if (OS_INT_ACTIVE) {
+ return (int32_t)osErrorISR;
+ }
+
+ if (!g_taskScheduled) {
+ return (int32_t)osError;
+ }
+
+ if (g_losTaskLock > 0) {
+ LOS_TaskUnlock();
+ if (g_losTaskLock != 0) {
+ return (int32_t)osError;
+ }
+ lock = 1;
+ } else {
+ lock = 0;
+ }
+
+ return lock;
+}
+
+
+int32_t osKernelRestoreLock(int32_t lock)
+{
+ if (OS_INT_ACTIVE) {
+ return (int32_t)osErrorISR;
+ }
+
+ if (!g_taskScheduled) {
+ return (int32_t)osError;
+ }
+
+ switch (lock) {
+ case 0:
+ LOS_TaskUnlock();
+ if (g_losTaskLock != 0) {
+ break;
+ }
+ return 0;
+ case 1:
+ LOS_TaskLock();
+ return 1;
+ default:
+ break;
+ }
+
+ return (int32_t)osError;
+}
+
+
+uint32_t osKernelGetTickCount(void)
+{
+ uint64_t ticks;
+ UINTPTR uvIntSave;
+
+ if (OS_INT_ACTIVE) {
+#ifndef LITEOS_WIFI_IOT_VERSION
+ ticks = g_ullTickCount;
+#else
+ ticks = g_tickCount;
+#endif
+ } else {
+ uvIntSave = LOS_IntLock();
+#ifndef LITEOS_WIFI_IOT_VERSION
+ ticks = g_ullTickCount;
+#else
+ ticks = g_tickCount;
+#endif
+ LOS_IntRestore(uvIntSave);
+ }
+
+ return (uint32_t)ticks;
+}
+
+uint32_t osKernelGetTickFreq(void)
+{
+ uint32_t freq;
+
+ if (OS_INT_ACTIVE) {
+ freq = 0U;
+ } else {
+ freq = LOSCFG_BASE_CORE_TICK_PER_SECOND;
+ }
+
+ return (freq);
+}
+
+extern VOID LOS_GetCpuCycle(UINT32 *puwCntHi, UINT32 *puwCntLo);
+uint32_t osKernelGetSysTimerCount(void)
+{
+ uint32_t countHigh = 0;
+ uint32_t countLow = 0;
+ if (OS_INT_ACTIVE) {
+ countLow = 0U;
+ } else {
+ LOS_GetCpuCycle((UINT32 *)&countHigh, (UINT32 *)&countLow);
+ }
+ return countLow;
+}
+
+
+uint32_t osKernelGetSysTimerFreq(void)
+{
+ return OS_SYS_CLOCK;
+}
+
+
+// ==== Thread Management Functions ====
+
+osThreadId_t osThreadNew(osThreadFunc_t func, void *argument, const osThreadAttr_t *attr)
+{
+ UINT32 uwTid;
+ UINT32 uwRet;
+ LosTaskCB *pstTaskCB = NULL;
+ TSK_INIT_PARAM_S stTskInitParam;
+
+ if (OS_INT_ACTIVE) {
+ return NULL;
+ }
+
+ if ((attr == NULL) || (func == NULL) || (attr->priority < osPriorityLow1) ||
+ (attr->priority > osPriorityAboveNormal6)) {
+ return (osThreadId_t)NULL;
+ }
+
+ (void)memset_s(&stTskInitParam, sizeof(TSK_INIT_PARAM_S), 0, sizeof(TSK_INIT_PARAM_S));
+ stTskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)func;
+#ifndef LITEOS_WIFI_IOT_VERSION
+ stTskInitParam.uwArg = (UINT32)argument;
+#else
+ stTskInitParam.auwArgs[0] = (UINT32)argument;
+#endif
+ stTskInitParam.uwStackSize = attr->stack_size;
+ stTskInitParam.pcName = (CHAR *)attr->name;
+ stTskInitParam.usTaskPrio = OS_TASK_PRIORITY_LOWEST - ((UINT16)(attr->priority) - LOS_PRIORITY_WIN); /* 0~31 */
+
+ uwRet = LOS_TaskCreate(&uwTid, &stTskInitParam);
+
+ if (LOS_OK != uwRet) {
+ return (osThreadId_t)NULL;
+ }
+
+ pstTaskCB = OS_TCB_FROM_TID(uwTid);
+
+ return (osThreadId_t)pstTaskCB;
+}
+
+
+const char *osThreadGetName(osThreadId_t thread_id)
+{
+ LosTaskCB *pstTaskCB = NULL;
+
+ if (OS_INT_ACTIVE || thread_id == NULL) {
+ return NULL;
+ }
+
+ pstTaskCB = (LosTaskCB *)thread_id;
+
+ return pstTaskCB->taskName;
+}
+
+
+osThreadId_t osThreadGetId(void)
+{
+ if (OS_INT_ACTIVE) {
+ return NULL;
+ }
+
+ return (osThreadId_t)(g_losTask.runTask);
+}
+
+void *osThreadGetArgument(void)
+{
+ if (OS_INT_ACTIVE) {
+ return 0;
+ }
+
+ LosTaskCB *taskCb = (LosTaskCB *)osThreadGetId();
+ if (taskCb == NULL) {
+ return NULL;
+ }
+#ifndef LITEOS_WIFI_IOT_VERSION
+ return (void *)(taskCb->arg);
+#else
+ return (void *)(taskCb->args[0]);
+#endif
+}
+
+osThreadState_t osThreadGetState(osThreadId_t thread_id)
+{
+ UINT16 taskStatus;
+ osThreadState_t stState;
+ LosTaskCB *pstTaskCB = NULL;
+
+ if (OS_INT_ACTIVE || thread_id == NULL) {
+ return osThreadError;
+ }
+
+ pstTaskCB = (LosTaskCB *)thread_id;
+ taskStatus = pstTaskCB->taskStatus;
+
+ if (taskStatus & OS_TASK_STATUS_RUNNING) {
+ stState = osThreadRunning;
+ } else if (taskStatus & OS_TASK_STATUS_READY) {
+ stState = osThreadReady;
+ } else if (taskStatus &
+ (OS_TASK_STATUS_DELAY | OS_TASK_STATUS_PEND | OS_TASK_STATUS_SUSPEND | OS_TASK_STATUS_PEND_QUEUE)) {
+ stState = osThreadBlocked;
+ } else if (taskStatus & OS_TASK_STATUS_UNUSED) {
+ stState = osThreadInactive;
+ } else {
+ stState = osThreadError;
+ }
+
+ return stState;
+}
+
+
+uint32_t osThreadGetStackSize(osThreadId_t thread_id)
+{
+ LosTaskCB *pstTaskCB = NULL;
+
+ if (OS_INT_ACTIVE || thread_id == NULL) {
+ return 0U;
+ }
+
+ pstTaskCB = (LosTaskCB *)thread_id;
+
+ return pstTaskCB->stackSize;
+}
+
+
+uint32_t osTaskStackWaterMarkGet(UINT32 taskID)
+{
+ UINT32 uwCount = 0;
+ UINT32 *ptopOfStack;
+ UINTPTR uvIntSave;
+ LosTaskCB *pstTaskCB = NULL;
+
+ if (taskID > LOSCFG_BASE_CORE_TSK_LIMIT) {
+ return 0;
+ }
+
+ uvIntSave = LOS_IntLock();
+
+ pstTaskCB = OS_TCB_FROM_TID(taskID);
+ if (OS_TASK_STATUS_UNUSED & (pstTaskCB->taskStatus)) {
+ LOS_IntRestore(uvIntSave);
+ return 0;
+ }
+
+ // first 4 bytes is OS_TASK_MAGIC_WORD, skip
+ ptopOfStack = (UINT32 *)(UINTPTR)pstTaskCB->topOfStack + 1;
+
+ while (*ptopOfStack == (UINT32)OS_TASK_STACK_INIT) {
+ ++ptopOfStack;
+ ++uwCount;
+ }
+
+ uwCount *= sizeof(UINT32);
+
+ LOS_IntRestore(uvIntSave);
+ return uwCount;
+}
+
+
+uint32_t osThreadGetStackSpace(osThreadId_t thread_id)
+{
+ LosTaskCB *pstTaskCB = NULL;
+
+ if (OS_INT_ACTIVE || thread_id == NULL) {
+ return 0U;
+ }
+
+ pstTaskCB = (LosTaskCB *)thread_id;
+
+ return osTaskStackWaterMarkGet(pstTaskCB->taskID);
+}
+
+
+osStatus_t osThreadSetPriority(osThreadId_t thread_id, osPriority_t priority)
+{
+ UINT32 uwRet;
+ UINT16 usPriority;
+ LosTaskCB *pstTaskCB = NULL;
+
+ if (OS_INT_ACTIVE) {
+ return osErrorISR;
+ }
+
+ if (thread_id == NULL) {
+ return osErrorParameter;
+ }
+
+ if (priority < osPriorityLow1 || priority > osPriorityAboveNormal6) {
+ return osErrorParameter;
+ }
+
+ pstTaskCB = (LosTaskCB *)thread_id;
+ usPriority = OS_TASK_PRIORITY_LOWEST - ((UINT16)priority - LOS_PRIORITY_WIN);
+ uwRet = LOS_TaskPriSet(pstTaskCB->taskID, usPriority);
+ switch (uwRet) {
+ case LOS_ERRNO_TSK_PRIOR_ERROR:
+ case LOS_ERRNO_TSK_OPERATE_IDLE:
+ case LOS_ERRNO_TSK_ID_INVALID:
+ return osErrorParameter;
+
+ case LOS_ERRNO_TSK_NOT_CREATED:
+ return osErrorResource;
+
+ default:
+ return osOK;
+ }
+}
+
+
+osPriority_t osThreadGetPriority(osThreadId_t thread_id)
+{
+ UINT16 usRet;
+ LosTaskCB *pstTaskCB = NULL;
+
+ if (OS_INT_ACTIVE || thread_id == NULL) {
+ return osPriorityError;
+ }
+
+ pstTaskCB = (LosTaskCB *)thread_id;
+ usRet = LOS_TaskPriGet(pstTaskCB->taskID);
+
+ if (usRet == (UINT16)OS_INVALID) {
+ return osPriorityError;
+ }
+
+ return (osPriority_t)(OS_TASK_PRIORITY_LOWEST - (usRet - LOS_PRIORITY_WIN));
+}
+
+
+osStatus_t osThreadYield(void)
+{
+ UINT32 uwRet;
+
+ if (OS_INT_ACTIVE) {
+ return osErrorISR;
+ }
+
+ uwRet = LOS_TaskYield();
+
+ if (uwRet == LOS_OK) {
+ return osOK;
+ }
+
+ return osError;
+}
+
+
+osStatus_t osThreadSuspend(osThreadId_t thread_id)
+{
+ UINT32 uwRet;
+ LosTaskCB *pstTaskCB = NULL;
+
+ if (OS_INT_ACTIVE) {
+ return osErrorISR;
+ }
+
+ if (thread_id == NULL) {
+ return osErrorParameter;
+ }
+
+ pstTaskCB = (LosTaskCB *)thread_id;
+ uwRet = LOS_TaskSuspend(pstTaskCB->taskID);
+ switch (uwRet) {
+ case LOS_ERRNO_TSK_OPERATE_IDLE:
+ case LOS_ERRNO_TSK_SUSPEND_SWTMR_NOT_ALLOWED:
+ case LOS_ERRNO_TSK_ID_INVALID:
+ return osErrorParameter;
+
+ case LOS_ERRNO_TSK_NOT_CREATED:
+ case LOS_ERRNO_TSK_ALREADY_SUSPENDED:
+ case LOS_ERRNO_TSK_SUSPEND_LOCKED:
+ return osErrorResource;
+
+ default:
+ return osOK;
+ }
+}
+
+
+osStatus_t osThreadResume(osThreadId_t thread_id)
+{
+ UINT32 uwRet;
+ LosTaskCB *pstTaskCB = NULL;
+
+ if (OS_INT_ACTIVE) {
+ return osErrorISR;
+ }
+
+ if (thread_id == NULL) {
+ return osErrorParameter;
+ }
+
+ pstTaskCB = (LosTaskCB *)thread_id;
+ uwRet = LOS_TaskResume(pstTaskCB->taskID);
+
+ switch (uwRet) {
+ case LOS_ERRNO_TSK_ID_INVALID:
+ return osErrorParameter;
+
+ case LOS_ERRNO_TSK_NOT_CREATED:
+ case LOS_ERRNO_TSK_NOT_SUSPENDED:
+ return osErrorResource;
+
+ default:
+ return osOK;
+ }
+}
+
+
+osStatus_t osThreadTerminate(osThreadId_t thread_id)
+{
+ UINT32 uwRet;
+ LosTaskCB *pstTaskCB = NULL;
+
+ if (OS_INT_ACTIVE) {
+ return osErrorISR;
+ }
+
+ if (thread_id == NULL) {
+ return osErrorParameter;
+ }
+
+ pstTaskCB = (LosTaskCB *)thread_id;
+ uwRet = LOS_TaskDelete(pstTaskCB->taskID);
+
+ switch (uwRet) {
+ case LOS_ERRNO_TSK_OPERATE_IDLE:
+ case LOS_ERRNO_TSK_SUSPEND_SWTMR_NOT_ALLOWED:
+ case LOS_ERRNO_TSK_ID_INVALID:
+ return osErrorParameter;
+
+ case LOS_ERRNO_TSK_NOT_CREATED:
+ return osErrorResource;
+
+ default:
+ return osOK;
+ }
+}
+
+
+uint32_t osThreadGetCount(void)
+{
+ uint32_t uwCount = 0;
+
+ if (OS_INT_ACTIVE) {
+ return 0U;
+ }
+
+ for (uint32_t index = 0; index <= LOSCFG_BASE_CORE_TSK_LIMIT; index++) {
+ if (!((g_taskCBArray + index)->taskStatus & OS_TASK_STATUS_UNUSED)) {
+ uwCount++;
+ }
+ }
+
+ return uwCount;
+}
+
+
+// ==== Generic Wait Functions ====
+WEAK UINT32 LOS_HalDelay(UINT32 ticks)
+{
+ UNUSED(ticks);
+ return LOS_ERRNO_TSK_DELAY_IN_INT;
+}
+
+
+osStatus_t osDelay(uint32_t ticks)
+{
+ UINT32 uwRet;
+ if (ticks == 0) {
+ return osOK;
+ }
+ if (osKernelGetState() != osKernelRunning) {
+ uwRet = LOS_HalDelay(ticks);
+ } else {
+ uwRet = LOS_TaskDelay(ticks);
+ }
+ if (uwRet == LOS_OK) {
+ return osOK;
+ } else {
+ return osError;
+ }
+}
+
+
+osStatus_t osDelayUntil(uint32_t ticks)
+{
+ UINT32 uwRet;
+ UINT32 uwTicks;
+ UINT32 tickCount = osKernelGetTickCount();
+
+ if (ticks < tickCount) {
+ return osError;
+ }
+
+ uwTicks = (UINT32)(ticks - tickCount);
+
+ uwRet = LOS_TaskDelay(uwTicks);
+ if (uwRet == LOS_OK) {
+ return osOK;
+ } else {
+ return osError;
+ }
+}
+
+// ==== Timer Management Functions ====
+#if (LOSCFG_BASE_CORE_SWTMR == 1)
+osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr)
+{
+ UNUSED(attr);
+ UINT16 usSwTmrID;
+ UINT8 mode;
+
+ if ((OS_INT_ACTIVE) || (NULL == func) || ((osTimerOnce != type) && (osTimerPeriodic != type))) {
+ return (osTimerId_t)NULL;
+ }
+
+ if (osTimerOnce == type) {
+ mode = LOS_SWTMR_MODE_NO_SELFDELETE;
+ } else {
+ mode = LOS_SWTMR_MODE_PERIOD;
+ }
+#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
+ if (LOS_OK != LOS_SwtmrCreate(1, mode, (SWTMR_PROC_FUNC)func, &usSwTmrID, (UINT32)(UINTPTR)argument,
+ osTimerRousesAllow, osTimerAlignIgnore)) {
+ return (osTimerId_t)NULL;
+ }
+#else
+ if (LOS_OK != LOS_SwtmrCreate(1, mode, (SWTMR_PROC_FUNC)func, &usSwTmrID, (UINT32)(UINTPTR)argument)) {
+ return (osTimerId_t)NULL;
+ }
+#endif
+
+ return (osTimerId_t)OS_SWT_FROM_SID(usSwTmrID);
+}
+
+osStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks)
+{
+ UINT32 uwRet;
+ SWTMR_CTRL_S *pstSwtmr;
+
+ if ((0 == ticks) || (NULL == timer_id)) {
+ return osErrorParameter;
+ }
+
+ pstSwtmr = (SWTMR_CTRL_S *)timer_id;
+ pstSwtmr->uwInterval = ticks;
+ uwRet = LOS_SwtmrStart(pstSwtmr->usTimerID);
+ if (LOS_OK == uwRet) {
+ return osOK;
+ } else if (LOS_ERRNO_SWTMR_ID_INVALID == uwRet) {
+ return osErrorParameter;
+ } else {
+ return osErrorResource;
+ }
+}
+
+
+const char *osTimerGetName(osTimerId_t timer_id)
+{
+ UNUSED(timer_id);
+ return (const char *)NULL;
+}
+
+
+osStatus_t osTimerStop(osTimerId_t timer_id)
+{
+ UINT32 uwRet;
+ SWTMR_CTRL_S *pstSwtmr = (SWTMR_CTRL_S *)timer_id;
+
+ if (OS_INT_ACTIVE) {
+ return osErrorISR;
+ }
+
+ if (NULL == pstSwtmr) {
+ return osErrorParameter;
+ }
+
+ uwRet = LOS_SwtmrStop(pstSwtmr->usTimerID);
+ if (LOS_OK == uwRet) {
+ return osOK;
+ } else if (LOS_ERRNO_SWTMR_ID_INVALID == uwRet) {
+ return osErrorParameter;
+ } else {
+ return osErrorResource;
+ }
+}
+
+
+uint32_t osTimerIsRunning(osTimerId_t timer_id)
+{
+ if ((OS_INT_ACTIVE) || (NULL == timer_id)) {
+ return 0;
+ }
+
+ return (OS_SWTMR_STATUS_TICKING == ((SWTMR_CTRL_S *)timer_id)->ucState);
+}
+
+
+osStatus_t osTimerDelete(osTimerId_t timer_id)
+{
+ UINT32 uwRet;
+ SWTMR_CTRL_S *pstSwtmr = (SWTMR_CTRL_S *)timer_id;
+
+ if (OS_INT_ACTIVE) {
+ return osErrorISR;
+ }
+
+ if (NULL == pstSwtmr) {
+ return osErrorParameter;
+ }
+
+ uwRet = LOS_SwtmrDelete(pstSwtmr->usTimerID);
+ if (LOS_OK == uwRet) {
+ return osOK;
+ } else if (LOS_ERRNO_SWTMR_ID_INVALID == uwRet) {
+ return osErrorParameter;
+ } else {
+ return osErrorResource;
+ }
+}
+#endif
+
+osEventFlagsId_t osEventFlagsNew(const osEventFlagsAttr_t *attr)
+{
+ PEVENT_CB_S pstEventCB;
+ UINT32 uwRet;
+
+ UNUSED(attr);
+
+ if (OS_INT_ACTIVE) {
+ return (osEventFlagsId_t)NULL;
+ }
+
+ pstEventCB = (PEVENT_CB_S)LOS_MemAlloc(m_aucSysMem0, sizeof(EVENT_CB_S));
+ if (pstEventCB == NULL) {
+ return (osEventFlagsId_t)NULL;
+ }
+
+ uwRet = LOS_EventInit(pstEventCB);
+ if (uwRet == LOS_ERRNO_EVENT_PTR_NULL) {
+ return (osEventFlagsId_t)NULL;
+ } else {
+ return (osEventFlagsId_t)pstEventCB;
+ }
+}
+
+
+const char *osEventFlagsGetName(osEventFlagsId_t ef_id)
+{
+ UNUSED(ef_id);
+
+ if (OS_INT_ACTIVE) {
+ return (const char *)NULL;
+ }
+
+ return (const char *)NULL;
+}
+
+
+uint32_t osEventFlagsSet(osEventFlagsId_t ef_id, uint32_t flags)
+{
+ PEVENT_CB_S pstEventCB = (PEVENT_CB_S)ef_id;
+ UINT32 uwRet;
+ uint32_t rflags;
+ if (pstEventCB == NULL) {
+ return osFlagsErrorParameter;
+ }
+ uwRet = LOS_EventWrite(pstEventCB, (UINT32)flags);
+ if (uwRet != LOS_OK) {
+ return (uint32_t)osFlagsErrorParameter;
+ } else {
+ rflags = pstEventCB->uwEventID;
+ return rflags;
+ }
+}
+
+
+uint32_t osEventFlagsClear(osEventFlagsId_t ef_id, uint32_t flags)
+{
+ PEVENT_CB_S pstEventCB = (PEVENT_CB_S)ef_id;
+ UINTPTR uwIntSave;
+ uint32_t rflags;
+ UINT32 uwRet;
+
+ if (pstEventCB == NULL) {
+ return (uint32_t)osFlagsErrorParameter;
+ }
+
+ uwIntSave = LOS_IntLock();
+ rflags = pstEventCB->uwEventID;
+
+ uwRet = LOS_EventClear(pstEventCB, ~flags);
+ LOS_IntRestore(uwIntSave);
+ if (uwRet != LOS_OK) {
+ return (uint32_t)osFlagsErrorParameter;
+ } else {
+ return rflags;
+ }
+}
+
+
+uint32_t osEventFlagsGet(osEventFlagsId_t ef_id)
+{
+ PEVENT_CB_S pstEventCB = (PEVENT_CB_S)ef_id;
+ UINTPTR uwIntSave;
+ uint32_t rflags;
+
+ if (pstEventCB == NULL) {
+ return (uint32_t)osFlagsErrorParameter;
+ }
+
+ uwIntSave = LOS_IntLock();
+ rflags = pstEventCB->uwEventID;
+ LOS_IntRestore(uwIntSave);
+
+ return rflags;
+}
+
+uint32_t osEventFlagsWait(osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout)
+{
+ PEVENT_CB_S pstEventCB = (PEVENT_CB_S)ef_id;
+ UINT32 uwMode = 0;
+ UINT32 uwRet;
+ uint32_t rflags;
+
+ if (options > (osFlagsWaitAny | osFlagsWaitAll | osFlagsNoClear)) {
+ return (uint32_t)osFlagsErrorParameter;
+ }
+
+ if ((options & osFlagsWaitAll) == osFlagsWaitAll) {
+ uwMode |= LOS_WAITMODE_AND;
+ } else {
+ uwMode |= LOS_WAITMODE_OR;
+ }
+
+ if ((options & osFlagsNoClear) == osFlagsNoClear) {
+ uwMode &= ~LOS_WAITMODE_CLR;
+ } else {
+ uwMode |= LOS_WAITMODE_CLR;
+ }
+
+ uwRet = LOS_EventRead(pstEventCB, (UINT32)flags, uwMode, (UINT32)timeout);
+ switch (uwRet) {
+ case LOS_ERRNO_EVENT_PTR_NULL:
+ case LOS_ERRNO_EVENT_EVENTMASK_INVALID:
+ case LOS_ERRNO_EVENT_SETBIT_INVALID:
+ return (uint32_t)osFlagsErrorParameter;
+
+ case LOS_ERRNO_EVENT_READ_IN_INTERRUPT:
+ case LOS_ERRNO_EVENT_FLAGS_INVALID:
+ case LOS_ERRNO_EVENT_READ_IN_LOCK:
+ return (uint32_t)osFlagsErrorResource;
+
+ case LOS_ERRNO_EVENT_READ_TIMEOUT:
+ return (uint32_t)osFlagsErrorTimeout;
+
+ default:
+ rflags = (uint32_t)uwRet;
+ return rflags;
+ }
+}
+
+osStatus_t osEventFlagsDelete(osEventFlagsId_t ef_id)
+{
+ PEVENT_CB_S pstEventCB = (PEVENT_CB_S)ef_id;
+ UINTPTR uwIntSave;
+ osStatus_t uwRet;
+
+ uwIntSave = LOS_IntLock();
+ if (LOS_EventDestroy(pstEventCB) == LOS_OK) {
+ uwRet = osOK;
+ } else {
+ uwRet = osErrorParameter;
+ }
+ LOS_IntRestore(uwIntSave);
+
+ if (LOS_MemFree(m_aucSysMem0, (void *)pstEventCB) == LOS_OK) {
+ uwRet = osOK;
+ } else {
+ uwRet = osErrorParameter;
+ }
+
+ return uwRet;
+}
+
+// ==== Mutex Management Functions ====
+#if (LOSCFG_BASE_IPC_MUX == 1)
+osMutexId_t osMutexNew(const osMutexAttr_t *attr)
+{
+ UINT32 uwRet;
+ UINT32 uwMuxId;
+
+ UNUSED(attr);
+
+ if (OS_INT_ACTIVE) {
+ return NULL;
+ }
+
+ uwRet = LOS_MuxCreate(&uwMuxId);
+ if (uwRet == LOS_OK) {
+ return (osMutexId_t)(GET_MUX(uwMuxId));
+ } else {
+ return (osMutexId_t)NULL;
+ }
+}
+
+
+osStatus_t osMutexAcquire(osMutexId_t mutex_id, uint32_t timeout)
+{
+ UINT32 uwRet;
+
+ if (mutex_id == NULL) {
+ return osErrorParameter;
+ }
+
+ if (OS_INT_ACTIVE && (timeout != LOS_NO_WAIT)) {
+ timeout = 0;
+ }
+
+ uwRet = LOS_MuxPend(((LosMuxCB *)mutex_id)->muxID, timeout);
+ if (uwRet == LOS_OK) {
+ return osOK;
+ } else if (uwRet == LOS_ERRNO_MUX_TIMEOUT) {
+ return osErrorTimeout;
+ } else if (uwRet == LOS_ERRNO_MUX_INVALID) {
+ return osErrorParameter;
+ } else {
+ return osErrorResource;
+ }
+}
+
+
+osStatus_t osMutexRelease(osMutexId_t mutex_id)
+{
+ UINT32 uwRet;
+
+ if (mutex_id == NULL) {
+ return osErrorParameter;
+ }
+
+ uwRet = LOS_MuxPost(((LosMuxCB *)mutex_id)->muxID);
+ if (uwRet == LOS_OK) {
+ return osOK;
+ } else {
+ return osErrorResource;
+ }
+}
+
+
+osThreadId_t osMutexGetOwner(osMutexId_t mutex_id)
+{
+ UINT32 uwIntSave;
+ LosTaskCB *pstTaskCB;
+
+ if (OS_INT_ACTIVE) {
+ return NULL;
+ }
+
+ if (mutex_id == NULL) {
+ return NULL;
+ }
+
+ uwIntSave = LOS_IntLock();
+ pstTaskCB = ((LosMuxCB *)mutex_id)->owner;
+ LOS_IntRestore(uwIntSave);
+
+ return (osThreadId_t)pstTaskCB;
+}
+
+
+osStatus_t osMutexDelete(osMutexId_t mutex_id)
+{
+ UINT32 uwRet;
+
+ if (OS_INT_ACTIVE) {
+ return osErrorISR;
+ }
+
+ if (mutex_id == NULL) {
+ return osErrorParameter;
+ }
+
+ uwRet = LOS_MuxDelete(((LosMuxCB *)mutex_id)->muxID);
+ if (uwRet == LOS_OK) {
+ return osOK;
+ } else if (uwRet == LOS_ERRNO_MUX_INVALID) {
+ return osErrorParameter;
+ } else {
+ return osErrorResource;
+ }
+}
+#endif
+
+// ==== Semaphore Management Functions ====
+#if (LOSCFG_BASE_IPC_SEM == 1)
+
+osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr)
+{
+ UINT32 uwRet;
+ UINT32 uwSemId;
+
+ UNUSED(attr);
+
+ if (OS_INT_ACTIVE) {
+ return (osSemaphoreId_t)NULL;
+ }
+
+ if (1 == max_count) {
+ uwRet = LOS_BinarySemCreate((UINT16)initial_count, &uwSemId);
+ } else {
+ uwRet = LOS_SemCreate((UINT16)initial_count, &uwSemId);
+ }
+
+ if (uwRet == LOS_OK) {
+ return (osSemaphoreId_t)(GET_SEM(uwSemId));
+ } else {
+ return (osSemaphoreId_t)NULL;
+ }
+}
+
+
+osStatus_t osSemaphoreAcquire(osSemaphoreId_t semaphore_id, uint32_t timeout)
+{
+ UINT32 uwRet;
+
+ if (semaphore_id == NULL) {
+ return osErrorParameter;
+ }
+
+ if (OS_INT_ACTIVE && (timeout != LOS_NO_WAIT)) {
+ return osErrorISR;
+ }
+
+ uwRet = LOS_SemPend(((LosSemCB *)semaphore_id)->semID, timeout);
+ if (uwRet == LOS_OK) {
+ return osOK;
+ } else if (uwRet == LOS_ERRNO_SEM_TIMEOUT) {
+ return osErrorTimeout;
+ } else if (uwRet == LOS_ERRNO_SEM_INVALID) {
+ return osErrorParameter;
+ } else if (uwRet == LOS_ERRNO_SEM_PEND_INTERR) {
+ return osErrorISR;
+ } else {
+ return osErrorResource;
+ }
+}
+
+
+osStatus_t osSemaphoreRelease(osSemaphoreId_t semaphore_id)
+{
+ UINT32 uwRet;
+
+ if (semaphore_id == NULL) {
+ return osErrorParameter;
+ }
+
+ uwRet = LOS_SemPost(((LosSemCB *)semaphore_id)->semID);
+ if (uwRet == LOS_OK) {
+ return osOK;
+ } else if (uwRet == LOS_ERRNO_SEM_INVALID) {
+ return osErrorParameter;
+ } else {
+ return osErrorResource;
+ }
+}
+
+
+uint32_t osSemaphoreGetCount(osSemaphoreId_t semaphore_id)
+{
+ UINT32 uwIntSave;
+ UINT32 uwCount;
+
+ if (OS_INT_ACTIVE) {
+ return 0;
+ }
+
+ if (semaphore_id == NULL) {
+ return 0;
+ }
+
+ uwIntSave = LOS_IntLock();
+ uwCount = ((LosSemCB *)semaphore_id)->semCount;
+ LOS_IntRestore(uwIntSave);
+
+ return uwCount;
+}
+
+
+osStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id)
+{
+ UINT32 uwRet;
+
+ if (OS_INT_ACTIVE) {
+ return osErrorISR;
+ }
+
+ if (semaphore_id == NULL) {
+ return osErrorParameter;
+ }
+
+ uwRet = LOS_SemDelete(((LosSemCB *)semaphore_id)->semID);
+ if (uwRet == LOS_OK) {
+ return osOK;
+ } else if (uwRet == LOS_ERRNO_SEM_INVALID) {
+ return osErrorParameter;
+ } else {
+ return osErrorResource;
+ }
+}
+#endif
+
+
+// ==== Message Queue Management Functions ====
+#if (LOSCFG_BASE_IPC_QUEUE == 1)
+osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr)
+{
+ UINT32 uwQueueID;
+ UINT32 uwRet;
+ UNUSED(attr);
+ osMessageQueueId_t handle;
+
+ if (0 == msg_count || 0 == msg_size || OS_INT_ACTIVE) {
+ return (osMessageQueueId_t)NULL;
+ }
+
+ uwRet = LOS_QueueCreate((char *)NULL, (UINT16)msg_count, &uwQueueID, 0, (UINT16)msg_size);
+ if (uwRet == LOS_OK) {
+ handle = (osMessageQueueId_t)(GET_QUEUE_HANDLE(uwQueueID));
+ } else {
+ handle = (osMessageQueueId_t)NULL;
+ }
+
+ return handle;
+}
+
+
+osStatus_t osMessageQueuePut(osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout)
+{
+ UNUSED(msg_prio);
+ UINT32 uwRet;
+ UINT32 uwBufferSize;
+ LosQueueCB *pstQueue = (LosQueueCB *)mq_id;
+
+ if (pstQueue == NULL || msg_ptr == NULL || ((OS_INT_ACTIVE) && (0 != timeout))) {
+ return osErrorParameter;
+ }
+ if (pstQueue->queueSize < sizeof(UINT32)) {
+ return osErrorParameter;
+ }
+ uwBufferSize = (UINT32)(pstQueue->queueSize - sizeof(UINT32));
+ uwRet = LOS_QueueWriteCopy((UINT32)pstQueue->queueID, (void *)msg_ptr, uwBufferSize, timeout);
+ if (uwRet == LOS_OK) {
+ return osOK;
+ } else if (uwRet == LOS_ERRNO_QUEUE_INVALID || uwRet == LOS_ERRNO_QUEUE_NOT_CREATE) {
+ return osErrorParameter;
+ } else if (uwRet == LOS_ERRNO_QUEUE_TIMEOUT) {
+ return osErrorTimeout;
+ } else {
+ return osErrorResource;
+ }
+}
+
+
+osStatus_t osMessageQueueGet(osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout)
+{
+ UNUSED(msg_prio);
+ UINT32 uwRet;
+ UINT32 uwBufferSize;
+ LosQueueCB *pstQueue = (LosQueueCB *)mq_id;
+
+ if (pstQueue == NULL || msg_ptr == NULL || ((OS_INT_ACTIVE) && (0 != timeout))) {
+ return osErrorParameter;
+ }
+
+ uwBufferSize = (UINT32)(pstQueue->queueSize - sizeof(UINT32));
+ uwRet = LOS_QueueReadCopy((UINT32)pstQueue->queueID, msg_ptr, &uwBufferSize, timeout);
+ if (uwRet == LOS_OK) {
+ return osOK;
+ } else if (uwRet == LOS_ERRNO_QUEUE_INVALID || uwRet == LOS_ERRNO_QUEUE_NOT_CREATE) {
+ return osErrorParameter;
+ } else if (uwRet == LOS_ERRNO_QUEUE_TIMEOUT) {
+ return osErrorTimeout;
+ } else {
+ return osErrorResource;
+ }
+}
+
+uint32_t osMessageQueueGetCapacity(osMessageQueueId_t mq_id)
+{
+ uint32_t capacity;
+ LosQueueCB *pstQueue = (LosQueueCB *)mq_id;
+
+ if (pstQueue == NULL) {
+ capacity = 0U;
+ } else {
+ capacity = pstQueue->queueLen;
+ }
+
+ return (capacity);
+}
+
+uint32_t osMessageQueueGetMsgSize(osMessageQueueId_t mq_id)
+{
+ uint32_t size;
+ LosQueueCB *pstQueue = (LosQueueCB *)mq_id;
+
+ if (pstQueue == NULL) {
+ size = 0U;
+ } else {
+ size = pstQueue->queueSize - sizeof(UINT32);
+ }
+
+ return (size);
+}
+
+
+uint32_t osMessageQueueGetCount(osMessageQueueId_t mq_id)
+{
+ uint32_t count;
+ UINTPTR uwIntSave;
+ LosQueueCB *pstQueue = (LosQueueCB *)mq_id;
+
+ if (pstQueue == NULL) {
+ count = 0U;
+ } else {
+ uwIntSave = LOS_IntLock();
+ count = (uint32_t)(pstQueue->readWriteableCnt[OS_QUEUE_READ]);
+ LOS_IntRestore(uwIntSave);
+ }
+ return count;
+}
+
+
+uint32_t osMessageQueueGetSpace(osMessageQueueId_t mq_id)
+{
+ uint32_t space;
+ UINTPTR uwIntSave;
+ LosQueueCB *pstQueue = (LosQueueCB *)mq_id;
+
+ if (pstQueue == NULL) {
+ space = 0U;
+ } else {
+ uwIntSave = LOS_IntLock();
+ space = (uint32_t)pstQueue->readWriteableCnt[OS_QUEUE_WRITE];
+ LOS_IntRestore(uwIntSave);
+ }
+ return space;
+}
+
+osStatus_t osMessageQueueDelete(osMessageQueueId_t mq_id)
+{
+ LosQueueCB *pstQueue = (LosQueueCB *)mq_id;
+ UINT32 uwRet;
+
+ if (pstQueue == NULL) {
+ return osErrorParameter;
+ }
+
+ if (OS_INT_ACTIVE) {
+ return osErrorISR;
+ }
+
+ uwRet = LOS_QueueDelete((UINT32)pstQueue->queueID);
+ if (uwRet == LOS_OK) {
+ return osOK;
+ } else if (uwRet == LOS_ERRNO_QUEUE_NOT_FOUND || uwRet == LOS_ERRNO_QUEUE_NOT_CREATE) {
+ return osErrorParameter;
+ } else {
+ return osErrorResource;
+ }
+}
+void osThreadExit(void)
+{
+ return;
+}
+#endif
+
+#endif // (CMSIS_OS_VER == 2)
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
diff --git a/hi3861_adapter/kal/cmsis/cmsis_os.h b/hi3861_adapter/kal/cmsis/cmsis_os.h
new file mode 100755
index 0000000000000000000000000000000000000000..bc288b2a34e4c7f9a4fbebcf4684c0d8026efd6d
--- /dev/null
+++ b/hi3861_adapter/kal/cmsis/cmsis_os.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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 the copyright holder 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.
+ */
+
+#ifndef CMSIS_OS_H_
+#define CMSIS_OS_H_
+
+#include "los_config.h"
+
+#if (CMSIS_OS_VER == 1)
+#error "cmsis version 1.0 is not supported now!"
+#elif (CMSIS_OS_VER == 2)
+#include "cmsis_os2.h"
+#endif
+
+#endif /* CMSIS_OS_H_ */
diff --git a/hi3861_adapter/kal/cmsis/cmsis_os2.h b/hi3861_adapter/kal/cmsis/cmsis_os2.h
new file mode 100755
index 0000000000000000000000000000000000000000..394bbd28c590152aa8adfae8290892ec2902a506
--- /dev/null
+++ b/hi3861_adapter/kal/cmsis/cmsis_os2.h
@@ -0,0 +1,1215 @@
+/*
+ * Copyright (c) 2013-2018 Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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
+ *
+ * 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.
+ *
+ * ----------------------------------------------------------------------
+ *
+ * $Date: 18. June 2018
+ * $Revision: V2.1.3
+ *
+ * Project: CMSIS-RTOS2 API
+ * Title: cmsis_os2.h header file
+ *
+ * Version 2.1.3
+ * Additional functions allowed to be called from Interrupt Service Routines:
+ * - osThreadGetId
+ * Version 2.1.2
+ * Additional functions allowed to be called from Interrupt Service Routines:
+ * - osKernelGetInfo, osKernelGetState
+ * Version 2.1.1
+ * Additional functions allowed to be called from Interrupt Service Routines:
+ * - osKernelGetTickCount, osKernelGetTickFreq
+ * Changed Kernel Tick type to uint32_t:
+ * - updated: osKernelGetTickCount, osDelayUntil
+ * Version 2.1.0
+ * Support for critical and uncritical sections (nesting safe):
+ * - updated: osKernelLock, osKernelUnlock
+ * - added: osKernelRestoreLock
+ * Updated Thread and Event Flags:
+ * - changed flags parameter and return type from int32_t to uint32_t
+ * Version 2.0.0
+ * Initial Release
+ *---------------------------------------------------------------------------*/
+
+/**
+ * @addtogroup CMSIS
+ * @{
+ *
+ * @brief Provides standard, universal real-time operating system (RTOS) APIs.
+ *
+ * CMSIS Module may contain portions from ARM Cortex Microcontroller Software Interface Standard (CMSIS) licensed under Apache License v2.0.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+
+#ifndef CMSIS_OS2_H_
+#define CMSIS_OS2_H_
+
+#ifndef __NO_RETURN
+#if defined(__CC_ARM)
+#define __NO_RETURN __declspec(noreturn)
+#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
+#define __NO_RETURN __attribute__((__noreturn__))
+#elif defined(__GNUC__)
+#define __NO_RETURN __attribute__((__noreturn__))
+#elif defined(__ICCARM__)
+#define __NO_RETURN __noreturn
+#else
+#define __NO_RETURN
+#endif
+#endif
+
+#include
+#include
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+// ==== Enumerations, structures, defines ====
+
+/**
+* @brief Describes the system version.
+*
+* @since 1.0
+* @version 1.0
+*/
+typedef struct {
+ /** API version */
+ uint32_t api;
+ /** Kernel version */
+ uint32_t kernel;
+} osVersion_t;
+
+/**
+* @brief Enumerates kernel states.
+*
+*/
+typedef enum {
+ /** The kernel is inactive. */
+ osKernelInactive = 0,
+ /** The kernel is ready. */
+ osKernelReady = 1,
+ /** The kernel is running. */
+ osKernelRunning = 2,
+ /** The kernel is locked. */
+ osKernelLocked = 3,
+ /** The kernel is suspended. */
+ osKernelSuspended = 4,
+ /** The kernel is abnormal. */
+ osKernelError = -1,
+ /** Reserved */
+ osKernelReserved = 0x7FFFFFFFU
+} osKernelState_t;
+
+/**
+* @brief Enumerates thread states.
+*
+*/
+typedef enum {
+ /** The thread is inactive. */
+ osThreadInactive = 0,
+ /** The thread is ready. */
+ osThreadReady = 1,
+ /** The thread is running. */
+ osThreadRunning = 2,
+ /** The thread is blocked. */
+ osThreadBlocked = 3,
+ /** The thread is terminated. */
+ osThreadTerminated = 4,
+ /** The thread is abnormal. */
+ osThreadError = -1,
+ /** Reserved */
+ osThreadReserved = 0x7FFFFFFF
+} osThreadState_t;
+
+/**
+* @brief Enumerates thread priorities.
+*
+*/
+typedef enum {
+ /** Undefined */
+ osPriorityNone = 0,
+ /** Reserved for idle threads */
+ osPriorityIdle = 1,
+ /** Low (unsupported) */
+ osPriorityLow = 8,
+ /** Low + 1 */
+ osPriorityLow1 = 8+1,
+ /** Low + 2 */
+ osPriorityLow2 = 8+2,
+ /** Low + 3 */
+ osPriorityLow3 = 8+3,
+ /** Low + 4 */
+ osPriorityLow4 = 8+4,
+ /** Low + 5 */
+ osPriorityLow5 = 8+5,
+ /** Low + 6 */
+ osPriorityLow6 = 8+6,
+ /** Low + 7 */
+ osPriorityLow7 = 8+7,
+ /** Below normal */
+ osPriorityBelowNormal = 16,
+ /** Below normal + 1 */
+ osPriorityBelowNormal1 = 16+1,
+ /** Below normal + 2 */
+ osPriorityBelowNormal2 = 16+2,
+ /** Below normal + 3 */
+ osPriorityBelowNormal3 = 16+3,
+ /** Below normal + 4 */
+ osPriorityBelowNormal4 = 16+4,
+ /** Below normal + 5 */
+ osPriorityBelowNormal5 = 16+5,
+ /** Below normal + 6 */
+ osPriorityBelowNormal6 = 16+6,
+ /** Below normal + 7 */
+ osPriorityBelowNormal7 = 16+7,
+ /** Normal */
+ osPriorityNormal = 24,
+ /** Normal + 1 */
+ osPriorityNormal1 = 24+1,
+ /** Normal + 2 */
+ osPriorityNormal2 = 24+2,
+ /** Normal + 3 */
+ osPriorityNormal3 = 24+3,
+ /** Normal + 4 */
+ osPriorityNormal4 = 24+4,
+ /** Normal + 5 */
+ osPriorityNormal5 = 24+5,
+ /** Normal + 6 */
+ osPriorityNormal6 = 24+6,
+ /** Normal + 7 */
+ osPriorityNormal7 = 24+7,
+ /** Above normal */
+ osPriorityAboveNormal = 32,
+ /** Above normal + 1 */
+ osPriorityAboveNormal1 = 32+1,
+ /** Above normal + 2 */
+ osPriorityAboveNormal2 = 32+2,
+ /** Above normal + 3 */
+ osPriorityAboveNormal3 = 32+3,
+ /** Above normal + 4 */
+ osPriorityAboveNormal4 = 32+4,
+ /** Above normal + 5 */
+ osPriorityAboveNormal5 = 32+5,
+ /** Above normal + 6 */
+ osPriorityAboveNormal6 = 32+6,
+ /** Above normal + 7 (unsupported) */
+ osPriorityAboveNormal7 = 32+7,
+ /** High (unsupported) */
+ osPriorityHigh = 40,
+ /** High + 1 (unsupported) */
+ osPriorityHigh1 = 40+1,
+ /** High + 2 (unsupported) */
+ osPriorityHigh2 = 40+2,
+ /** High + 3 (unsupported) */
+ osPriorityHigh3 = 40+3,
+ /** High + 4 (unsupported) */
+ osPriorityHigh4 = 40+4,
+ /** High + 5 (unsupported) */
+ osPriorityHigh5 = 40+5,
+ /** High + 6 (unsupported) */
+ osPriorityHigh6 = 40+6,
+ /** High + 7 (unsupported) */
+ osPriorityHigh7 = 40+7,
+ /** Real-time (unsupported) */
+ osPriorityRealtime = 48,
+ /** Real-time + 1 (unsupported) */
+ osPriorityRealtime1 = 48+1,
+ /** Real-time + 2 (unsupported) */
+ osPriorityRealtime2 = 48+2,
+ /** Real-time + 3 (unsupported) */
+ osPriorityRealtime3 = 48+3,
+ /** Real-time + 4 (unsupported) */
+ osPriorityRealtime4 = 48+4,
+ /** Real-time + 5 (unsupported) */
+ osPriorityRealtime5 = 48+5,
+ /** Real-time + 6 (unsupported) */
+ osPriorityRealtime6 = 48+6,
+ /** Real-time + 7 (unsupported) */
+ osPriorityRealtime7 = 48+7,
+ /** Reserved for ISR deferred threads (unsupported) */
+ osPriorityISR = 56,
+ /** Invalid */
+ osPriorityError = -1,
+ /** Reserved. It enables the compiler to identify enumeration variables as 32-bit numbers and prevents the enumeration variables from being optimized. */
+ osPriorityReserved = 0x7FFFFFFF
+} osPriority_t;
+
+/**
+* @brief Callback for thread scheduling
+*
+*/
+typedef void (*osThreadFunc_t) (void *argument);
+
+/**
+* @brief Callback for timer triggering
+*
+*/
+typedef void (*osTimerFunc_t) (void *argument);
+
+/**
+* @brief Enumerates timer types.
+*
+*/
+typedef enum {
+ /** One-shot timer */
+ osTimerOnce = 0,
+ /** Repeating timer */
+ osTimerPeriodic = 1
+} osTimerType_t;
+
+/**
+* @brief Indicates that the RTOS waits forever unless an event flag is received.
+*
+*/
+#define osWaitForever 0xFFFFFFFFU
+
+/**
+* @brief Indicates that the RTOS does not wait.
+*
+*/
+#define osNoWait 0x0U
+
+/**
+* @brief Indicates that the RTOS waits until any event flag is triggered.
+*
+*/
+#define osFlagsWaitAny 0x00000000U
+
+/**
+* @brief Indicates that the system waits until all event flags are triggered.
+*
+*/
+#define osFlagsWaitAll 0x00000001U
+
+/**
+* @brief Indicates that defined flags are not cleared.
+*
+*/
+#define osFlagsNoClear 0x00000002U
+
+/**
+* @brief Indicates a flag error.
+*
+*/
+#define osFlagsError 0x80000000U
+
+/**
+* @brief Indicates an unknown error.
+*
+*/
+#define osFlagsErrorUnknown 0xFFFFFFFFU
+
+/**
+* @brief Indicates a timeout.
+*
+*/
+#define osFlagsErrorTimeout 0xFFFFFFFEU
+
+/**
+* @brief Indicates a resource error.
+*
+*/
+#define osFlagsErrorResource 0xFFFFFFFDU
+
+/**
+* @brief Indicates an incorrect parameter.
+*
+*/
+#define osFlagsErrorParameter 0xFFFFFFFCU
+#define osFlagsErrorISR 0xFFFFFFFAU
+
+// Thread attributes (attr_bits in \ref osThreadAttr_t).
+#define osThreadDetached 0x00000000U
+#define osThreadJoinable 0x00000001U
+
+// Mutex attributes (attr_bits in \ref osMutexAttr_t).
+#define osMutexRecursive 0x00000001U
+#define osMutexPrioInherit 0x00000002U
+#define osMutexRobust 0x00000008U
+
+/**
+* @brief Enumerates return values of CMSIS-RTOS.
+*
+*/
+typedef enum {
+ /** Operation completed successfully */
+ osOK = 0,
+ /** Unspecified error */
+ osError = -1,
+ /** Timeout */
+ osErrorTimeout = -2,
+ /** Resource error */
+ osErrorResource = -3,
+ /** Incorrect parameter */
+ osErrorParameter = -4,
+ /** Insufficient memory */
+ osErrorNoMemory = -5,
+ /** Service interruption */
+ osErrorISR = -6,
+ /** Reserved. It is used to prevent the compiler from optimizing enumerations. */
+ osStatusReserved = 0x7FFFFFFF
+} osStatus_t;
+
+/**
+* @brief Identifies a thread.
+*
+*/
+typedef void *osThreadId_t;
+
+/**
+* @brief Identifies a timer.
+*
+*/
+typedef void *osTimerId_t;
+
+/**
+* @brief Identifies an event flag.
+*
+*/
+typedef void *osEventFlagsId_t;
+
+/**
+* @brief Identifies a mutex.
+*
+*/
+typedef void *osMutexId_t;
+
+/**
+* @brief Identifies a semaphore object.
+*
+*/
+typedef void *osSemaphoreId_t;
+
+
+typedef void *osMemoryPoolId_t;
+
+/**
+* @brief Identifies a message queue.
+*
+*/
+typedef void *osMessageQueueId_t;
+
+
+#ifndef TZ_MODULEID_T
+#define TZ_MODULEID_T
+
+/**
+* @brief Identifies a TrustZone module call process.
+*
+*/
+typedef uint32_t TZ_ModuleId_t;
+#endif
+
+/**
+* @brief Describes thread attributes.
+*
+* @since 1.0
+* @version 1.0
+*/
+typedef struct {
+ /** Thread name */
+ const char *name;
+ /** Thread attribute bits */
+ uint32_t attr_bits;
+ /** Memory for the thread control block */
+ void *cb_mem;
+ /** Size of the memory for the thread control block */
+ uint32_t cb_size;
+ /** Memory for the thread stack */
+ void *stack_mem;
+ /** Size of the thread stack */
+ uint32_t stack_size;
+ /** Thread priority */
+ osPriority_t priority;
+ /** TrustZone module of the thread */
+ TZ_ModuleId_t tz_module;
+ /** Reserved */
+ uint32_t reserved;
+} osThreadAttr_t;
+
+/**
+* @brief Describes timer attributes.
+*
+* @since 1.0
+* @version 1.0
+*/
+typedef struct {
+ /** Timer name */
+ const char *name;
+ /** Reserved attribute bits */
+ uint32_t attr_bits;
+ /** Memory for the timer control block */
+ void *cb_mem;
+ /** Size of the memory for the timer control block */
+ uint32_t cb_size;
+} osTimerAttr_t;
+
+/**
+* @brief Describes event attributes.
+*
+* @since 1.0
+* @version 1.0
+*/
+typedef struct {
+ /** Event name */
+ const char *name;
+ /** Reserved attribute bits */
+ uint32_t attr_bits;
+ /** Memory for the event control block */
+ void *cb_mem;
+ /** Size of the memory for the event control block */
+ uint32_t cb_size;
+} osEventFlagsAttr_t;
+
+/**
+* @brief Describes mutex attributes.
+*
+* @since 1.0
+* @version 1.0
+*/
+typedef struct {
+ /** Mutex name */
+ const char *name;
+ /** Reserved attribute bits */
+ uint32_t attr_bits;
+ /** Memory for the mutex control block */
+ void *cb_mem;
+ /** Size of the memory for the mutex control block */
+ uint32_t cb_size;
+} osMutexAttr_t;
+
+/**
+* @brief Describes semaphore attributes.
+*
+* @since 1.0
+* @version 1.0
+*/
+typedef struct {
+ /** Semaphore name */
+ const char *name;
+ /** Reserved attribute bits */
+ uint32_t attr_bits;
+ /** Memory for the semaphore control block */
+ void *cb_mem;
+ /** Size of the memory for the semaphore control block */
+ uint32_t cb_size;
+} osSemaphoreAttr_t;
+
+
+typedef struct {
+ const char *name;
+ uint32_t attr_bits;
+ void *cb_mem;
+ uint32_t cb_size;
+ void *mp_mem;
+ uint32_t mp_size;
+} osMemoryPoolAttr_t;
+
+/**
+* @brief Describes message queue attributes.
+*
+* @since 1.0
+* @version 1.0
+*/
+typedef struct {
+ /** Message queue name */
+ const char *name;
+ /** Reserved attribute bits */
+ uint32_t attr_bits;
+ /** Memory for the message queue control block */
+ void *cb_mem;
+ /** Size of the memory for the message queue control block */
+ uint32_t cb_size;
+ /** Memory for storing data in the message queue */
+ void *mq_mem;
+ /** Size of the memory for storing data in the message queue */
+ uint32_t mq_size;
+} osMessageQueueAttr_t;
+
+
+// ==== Kernel Management Functions ====
+
+/**
+* @brief Initializes the RTOS kernel.
+*
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osKernelInitialize (void);
+
+/**
+* @brief Obtains the system version and name.
+*
+* @param version Indicates the pointer to the buffer for storing the version.
+* @param id_buf Indicates the pointer to the buffer for storing the kernel ID.
+* @param id_size Indicates the size of the buffer for storing the kernel ID.
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size);
+
+/**
+* @brief Obtains the kernel state.
+*
+* @return Returns the kernel state.
+* @since 1.0
+* @version 1.0
+*/
+osKernelState_t osKernelGetState (void);
+
+/**
+* @brief Starts the kernel.
+*
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osKernelStart (void);
+
+/**
+* @brief Locks the kernel.
+*
+* @return Returns 1 if the kernel is locked successfully; returns 0 if the lock starts; returns a negative value in the case of an error.
+* @since 1.0
+* @version 1.0
+*/
+int32_t osKernelLock (void);
+
+/**
+* @brief Unlocks the kernel.
+*
+* @return Returns 1 if the kernel is unlocked successfully; returns 0 if the kernel is not locked; returns a negative value in the case of an error.
+* @since 1.0
+* @version 1.0
+*/
+int32_t osKernelUnlock (void);
+
+/**
+* @brief Restores the previous lock state of the kernel.
+*
+* @param lock Indicates the lock state to restore to. The value 1 indicates the locked state, and 0 indicates the unlocked state.
+* @return Returns 1 if the kernel is locked; returns 0 if the kernel is not locked; returns a negative value in the case of an error.
+* @since 1.0
+* @version 1.0
+*/
+int32_t osKernelRestoreLock (int32_t lock);
+
+uint32_t osKernelSuspend (void);
+
+void osKernelResume (uint32_t sleep_ticks);
+
+/// Get the RTOS kernel tick count.
+/// \return RTOS kernel current tick count.
+uint32_t osKernelGetTickCount (void);
+
+
+
+/**
+* @brief Obtains the number of kernel ticks per second.
+*
+* @return Returns the number of kernel ticks.
+* @since 1.0
+* @version 1.0
+*/
+uint32_t osKernelGetTickFreq (void);
+
+/**
+* @brief Obtains the kernel system timer.
+*
+* @return Returns the kernel system timer.
+* @since 1.0
+* @version 1.0
+*/
+uint32_t osKernelGetSysTimerCount (void);
+
+/**
+* @brief Obtains the frequency of the system timer.
+*
+* @return Returns the system timer frequency.
+* @since 1.0
+* @version 1.0
+*/
+uint32_t osKernelGetSysTimerFreq (void);
+
+
+// ==== Thread Management Functions ====
+
+/**
+* @brief Creates an active thread.
+*
+* The priority ranges from 9 to 38. Select a proper priority as required.
+* The maximum of tasks is LOSCFG_BASE_CORE_TSK_LIMIT(LOSCFG_BASE_CORE_TSK_LIMIT is defined in the traget_config.h).
+* @param func Indicates the entry of the thread callback function.
+* @param argument Indicates the pointer to the argument passed to the thread.
+* @param attr Indicates the thread attributes.
+* @return Returns the thread ID; returns NULL in the case of an error.
+* @since 1.0
+* @version 1.0
+*/
+osThreadId_t osThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr);
+
+/**
+* @brief Obtains the name of a thread.
+*
+* @param thread_id Indicates the thread ID, which is obtained using osThreadNew or osThreadGetId.
+* @return Returns the thread name; returns NULL in the case of an error.
+* @since 1.0
+* @version 1.0
+*/
+const char *osThreadGetName (osThreadId_t thread_id);
+
+/**
+* @brief Obtains the ID of the currently running thread.
+*
+* @return Returns the thread ID; returns NULL in the case of an error.
+* @since 1.0
+* @version 1.0
+*/
+osThreadId_t osThreadGetId (void);
+
+
+/**
+* @brief Obtains the state of a thread.
+*
+* @param thread_id Indicates the thread ID, which is obtained using osThreadNew or osThreadGetId.
+* @return Returns the thread state.
+* @since 1.0
+* @version 1.0
+*/
+osThreadState_t osThreadGetState (osThreadId_t thread_id);
+
+/**
+* @brief Obtains the stack size of a thread.
+*
+* @param thread_id Indicates the thread ID, which is obtained using osThreadNew or osThreadGetId.
+* @return Returns the stack size, in bytes; returns 0 in the case of an error.
+* @since 1.0
+* @version 1.0
+*/
+uint32_t osThreadGetStackSize (osThreadId_t thread_id);
+
+/**
+* @brief Obtains the size of the available stack space for a thread based on the stack watermark.
+*
+* @param thread_id Indicates the thread ID, which is obtained using osThreadNew or osThreadGetId.
+* @return Returns the available stack size, in bytes; returns 0 in the case of an error.
+* @since 1.0
+* @version 1.0
+*/
+uint32_t osThreadGetStackSpace (osThreadId_t thread_id);
+
+/**
+* @brief Changes the priority of a thread.
+*
+* @param thread_id Indicates the thread ID, which is obtained using osThreadNew or osThreadGetId.
+* @param priority Indicates the new priority.
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osThreadSetPriority (osThreadId_t thread_id, osPriority_t priority);
+
+/**
+* @brief Gets the prority of an active thread.
+*
+* @param thread_id Indicates the thread ID, which is obtained using osThreadNew or osThreadGetId.
+* @return Returns the prority of the thread.
+* @since 1.0
+* @version 1.0
+*/
+osPriority_t osThreadGetPriority (osThreadId_t thread_id);
+
+/**
+* @brief Sets the currently running thread to the ready state.
+*
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osThreadYield (void);
+
+/**
+* @brief Suspends a thread.
+*
+* @param thread_id Indicates the thread ID, which is obtained using osThreadNew or osThreadGetId.
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osThreadSuspend (osThreadId_t thread_id);
+
+/**
+* @brief Resumes a thread from the suspended state.
+*
+* @param thread_id Indicates the thread ID, which is obtained using osThreadNew or osThreadGetId.
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osThreadResume (osThreadId_t thread_id);
+
+osStatus_t osThreadDetach (osThreadId_t thread_id);
+
+osStatus_t osThreadJoin (osThreadId_t thread_id);
+
+void osThreadExit (void);
+
+/**
+* @brief Terminates a thread.
+*
+* @param thread_id Indicates the thread ID, which is obtained using osThreadNew or osThreadGetId.
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osThreadTerminate (osThreadId_t thread_id);
+
+/**
+* @brief Obtains the number of active threads.
+*
+* @return Returns the number; returns 0 in the case of an error.
+* @since 1.0
+* @version 1.0
+*/
+uint32_t osThreadGetCount (void);
+
+uint32_t osThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items);
+
+
+// ==== Thread Flags Functions ====
+
+uint32_t osThreadFlagsSet (osThreadId_t thread_id, uint32_t flags);
+
+uint32_t osThreadFlagsClear (uint32_t flags);
+
+uint32_t osThreadFlagsGet (void);
+
+uint32_t osThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout);
+
+
+// ==== Generic Wait Functions ====
+
+/**
+* @brief Waits for a period of time.
+*
+* @param ticks Indicates the number of ticks to wait for.
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osDelay (uint32_t ticks);
+
+/**
+* @brief Waits until a specified time arrives.
+*
+* This function handles the overflow of the system timer. Note that the maximum value of this parameter is (2^31 - 1) ticks.
+* @param ticks Indicates the number of ticks converted from the absolute time.
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osDelayUntil (uint32_t ticks);
+
+
+// ==== Timer Management Functions ====
+
+/**
+* @brief Creates and initializes a timer.
+*
+* This function creates a timer associated with the arguments callback function. The timer stays in the stopped state until OSTimerStart is used to start the timer.
+* The timer precision is 1000 / LOSCFG_BASE_CORE_TICK_PER_SECOND ms(LOSCFG_BASE_CORE_TICK_PER_SECOND is defined in the traget_config.h).
+* @param func Indicates the entry of the timer callback function.
+* @param type Indicates the timer type.
+* @param argument Indicates the pointer to the argument used in timer callback.
+* @param attr Indicates the pointer to the timer attributes. This parameter is not used.
+* @return Returns the timer ID; returns NULL in the case of an error.
+* @since 1.0
+* @version 1.0
+*/
+osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr);
+
+/**
+* @brief Obtains the timer name.
+*
+* @param timer_id Indicates the timer ID, which is obtained using osTimerNew.
+* @return Returns the timer name; returns NULL in the case of an error.
+* @since 1.0
+* @version 1.0
+*/
+const char *osTimerGetName (osTimerId_t timer_id);
+
+/**
+* @brief Starts or restarts a timer.
+*
+* @param timer_id Indicates the timer ID, which is obtained using osTimerNew.
+* @param ticks Indicates the number of ticks since the timer starts running.
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t ticks);
+
+/**
+* @brief Stops a timer.
+*
+* @param timer_id Indicates the timer ID, which is obtained using osTimerNew.
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osTimerStop (osTimerId_t timer_id);
+
+/**
+* @brief Checks whether a timer is running.
+*
+* @param timer_id Indicates the timer ID, which is obtained using osTimerNew.
+* @return Returns 1 if the timer is running; returns 0 otherwise.
+* @since 1.0
+* @version 1.0
+*/
+uint32_t osTimerIsRunning (osTimerId_t timer_id);
+
+/**
+* @brief Deletes a timer.
+*
+* @param timer_id Indicates the timer ID, which is obtained using osTimerNew.
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osTimerDelete (osTimerId_t timer_id);
+
+
+// ==== Event Flags Management Functions ====
+
+/**
+* @brief Creates and initializes an event flags object.
+*
+* @param attr Indicates the pointer to the event flags attributes. This parameter is not used.
+* @return Returns the event flags ID; returns NULL in the case of an error.
+* @since 1.0
+* @version 1.0
+*/
+osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr);
+
+/**
+* @brief Obtains the name of an event flags object.
+*
+* @param ef_id Indicates the event flags ID, which is obtained using osEventFlagsNew.
+* @return Returns the event flags name; returns NULL in the case of an error.
+* @since 1.0
+* @version 1.0
+*/
+const char *osEventFlagsGetName (osEventFlagsId_t ef_id);
+
+/**
+* @brief Sets event flags.
+*
+* @param ef_id Indicates the event flags ID, which is obtained using osEventFlagsNew.
+* @param flags Indicates the event flags to set.
+* @return Returns the event flags; returns osFlagsErrorParameter in the case of an error.
+* @since 1.0
+* @version 1.0
+*/
+uint32_t osEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags);
+
+/**
+* @brief Clears event flags.
+*
+* @param ef_id Indicates the event flags ID, which is obtained using osEventFlagsNew.
+* @param flags Indicates the event flags to clear.
+* @return Returns the event flags; returns osFlagsErrorParameter in the case of an error.
+* @since 1.0
+* @version 1.0
+*/
+uint32_t osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags);
+
+/**
+* @brief Obtains event flags.
+*
+* @param ef_id Indicates the event flags ID, which is obtained using osEventFlagsNew.
+* @return Returns the event flags triggered.
+* @since 1.0
+* @version 1.0
+*/
+uint32_t osEventFlagsGet (osEventFlagsId_t ef_id);
+
+/**
+* @brief Waits for event flags to trigger.
+*
+* When the specified flag of the event is set, the function returns immediately. Otherwise, the thread is blocked.
+* @param ef_id Indicates the event flags ID, which is obtained using osEventFlagsNew.
+* @param flags Indicates the event flags to trigger.
+* @param options Indicates the configuration of the event flags to trigger.
+* @param timeout Indicates the timeout duration.
+* @return Returns the triggered event flags; returns an error value in the case of an error.
+* @since 1.0
+* @version 1.0
+*/
+uint32_t osEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout);
+
+/**
+* @brief Deletes an event flags object.
+*
+* @param ef_id Indicates the event flags ID, which is obtained using osEventFlagsNew.
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id);
+
+
+// ==== Mutex Management Functions ====
+
+/**
+* @brief Creates and initializes a mutex.
+*
+* @param attr Indicates the pointer to the mutex attributes. This parameter is not used.
+* @return Returns the mutex ID; returns NULL in the case of an error.
+* @since 1.0
+* @version 1.0
+*/
+osMutexId_t osMutexNew (const osMutexAttr_t *attr);
+
+const char *osMutexGetName (osMutexId_t mutex_id);
+
+/**
+* @brief Obtains a mutex.
+*
+* @param mutex_id Indicates the mutex ID, which is obtained using osMutexNew.
+* @param timeout Indicates the timeout duration.
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout);
+
+/**
+* @brief Releases a mutex.
+*
+* @param mutex_id Indicates the mutex ID, which is obtained using osMutexNew.
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osMutexRelease (osMutexId_t mutex_id);
+
+/**
+* @brief Obtains the thread ID of the currently acquired mutex.
+*
+* @param mutex_id Indicates the mutex ID, which is obtained using osMutexNew.
+* @return Returns the thread ID.
+* @since 1.0
+* @version 1.0
+*/
+osThreadId_t osMutexGetOwner (osMutexId_t mutex_id);
+
+/**
+* @brief Deletes a mutex.
+*
+* @param mutex_id Indicates the mutex ID, which is obtained using osMutexNew.
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osMutexDelete (osMutexId_t mutex_id);
+
+
+// ==== Semaphore Management Functions ====
+
+/**
+* @brief Creates and initializes a semaphore object.
+*
+* @param max_count Indicates the maximum number of available tokens that can be applied for.
+* @param initial_count Indicates the initial number of available tokens.
+* @param attr Indicates the pointer to the semaphore attributes. This parameter is not used.
+* @return Returns the semaphore ID; returns NULL in the case of an error.
+* @since 1.0
+* @version 1.0
+*/
+osSemaphoreId_t osSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr);
+
+const char *osSemaphoreGetName (osSemaphoreId_t semaphore_id);
+
+/**
+* @brief Acquires a token of a semaphore object.
+*
+* @param semaphore_id Indicates the semaphore ID, which is obtained using osSemaphoreNew.
+* @param timeout Indicates the timeout duration. This parameter is the number of ticks.
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout);
+
+/**
+* @brief Releases a token of a semaphore object.
+*
+* @param semaphore_id Indicates the semaphore ID, which is obtained using osSemaphoreNew.
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osSemaphoreRelease (osSemaphoreId_t semaphore_id);
+
+/**
+* @brief Obtains the number of available tokens of a semaphore object.
+*
+* @param semaphore_id Indicates the semaphore ID, which is obtained using osSemaphoreNew.
+* @return Returns the number of available tokens.
+* @since 1.0
+* @version 1.0
+*/
+uint32_t osSemaphoreGetCount (osSemaphoreId_t semaphore_id);
+
+/**
+* @brief Deletes a semaphore object.
+*
+* @param semaphore_id Indicates the semaphore ID, which is obtained using osSemaphoreNew.
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osSemaphoreDelete (osSemaphoreId_t semaphore_id);
+
+
+// ==== Memory Pool Management Functions ====
+
+osMemoryPoolId_t osMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr);
+
+const char *osMemoryPoolGetName (osMemoryPoolId_t mp_id);
+
+void *osMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout);
+
+osStatus_t osMemoryPoolFree (osMemoryPoolId_t mp_id, void *block);
+
+uint32_t osMemoryPoolGetCapacity (osMemoryPoolId_t mp_id);
+
+uint32_t osMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id);
+
+uint32_t osMemoryPoolGetCount (osMemoryPoolId_t mp_id);
+
+uint32_t osMemoryPoolGetSpace (osMemoryPoolId_t mp_id);
+
+osStatus_t osMemoryPoolDelete (osMemoryPoolId_t mp_id);
+
+
+// ==== Message Queue Management Functions ====
+
+/**
+* @brief Creates and initializes a message queue.
+*
+* @param msg_count Indicates the number of messages in the message queue.
+* @param msg_size Indicates the size of messages in the message queue.
+* @param attr Indicates the pointer to the message queue attributes. This parameter is not used.
+* @return Returns the message queue ID; returns NULL in the case of an error.
+* @since 1.0
+* @version 1.0
+*/
+osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr);
+
+const char *osMessageQueueGetName (osMessageQueueId_t mq_id);
+
+/**
+* @brief Places a message in a message queue.
+*
+* @param mq_id Indicates the message queue ID, which is obtained using osMessageQueueNew.
+* @param msg_ptr Indicates the pointer to the buffer for storing the message to be placed in the message queue.
+* @param msg_prio Indicates the priority of the message to be placed in the message queue. This parameter is not used.
+* @param timeout Indicates the timeout duration.
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout);
+
+/**
+* @brief Obtains a message in a message queue.
+*
+* @param mq_id Indicates the message queue ID, which is obtained using osMessageQueueNew.
+* @param msg_ptr Indicates the pointer to the buffer for storing the message to be retrieved from the message queue.
+* @param msg_prio Indicates the pointer to the buffer for storing the priority of the message to be retrieved from the message queue. This parameter is not used.
+* @param timeout Indicates the timeout duration.
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout);
+
+/**
+* @brief Obtains the maximum number of messages that can be placed in a message queue.
+*
+* @param mq_id Indicates the message queue ID, which is obtained using osMessageQueueNew.
+* @return Returns the maximum number.
+* @since 1.0
+* @version 1.0
+*/
+uint32_t osMessageQueueGetCapacity (osMessageQueueId_t mq_id);
+
+/**
+* @brief Obtains the maximum size of messages that can be placed in a message queue.
+*
+* @param mq_id Indicates the message queue ID, which is obtained using osMessageQueueNew.
+* @return Returns the maximum message size.
+* @since 1.0
+* @version 1.0
+*/
+uint32_t osMessageQueueGetMsgSize (osMessageQueueId_t mq_id);
+
+/**
+* @brief Obtains the number of queued messages in a message queue.
+*
+* @param mq_id Indicates the message queue ID, which is obtained using osMessageQueueNew.
+* @return Returns the number of queued messages.
+* @since 1.0
+* @version 1.0
+*/
+uint32_t osMessageQueueGetCount (osMessageQueueId_t mq_id);
+
+/**
+* @brief Obtains the number of available slots for messages in a message queue.
+*
+* @param mq_id Indicates the message queue ID, which is obtained using osMessageQueueNew.
+* @return Returns the number of available slots for messages.
+* @since 1.0
+* @version 1.0
+*/
+uint32_t osMessageQueueGetSpace (osMessageQueueId_t mq_id);
+
+osStatus_t osMessageQueueReset (osMessageQueueId_t mq_id);
+
+/**
+* @brief Deletes a message queue.
+*
+* @param mq_id Indicates the message queue ID, which is obtained using osMessageQueueNew.
+* @return Returns the CMSIS-RTOS running result.
+* @since 1.0
+* @version 1.0
+*/
+osStatus_t osMessageQueueDelete (osMessageQueueId_t mq_id);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // CMSIS_OS2_H_
diff --git a/hi3861_adapter/kal/cmsis/hos_cmsis_adp.h b/hi3861_adapter/kal/cmsis/hos_cmsis_adp.h
new file mode 100755
index 0000000000000000000000000000000000000000..78e3c90687b64519a1744faf7da34d4111d073d0
--- /dev/null
+++ b/hi3861_adapter/kal/cmsis/hos_cmsis_adp.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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 the copyright holder 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.
+ */
+
+#ifndef HOS_CMSIS_ADP_H
+#define HOS_CMSIS_ADP_H
+
+#include "cmsis_os.h"
+#include "ohos_types.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* __cplusplus */
+
+typedef struct {
+ osSemaphoreAttr_t attr;
+ uint32 maxCount;
+ uint32 initialCount;
+} SemaphoreEx;
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* __cplusplus */
+
+#endif
diff --git a/hi3861_adapter/kal/posix/BUILD.gn b/hi3861_adapter/kal/posix/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..9a22fda42a9ec7899f0b656ef31c7586c96f9e60
--- /dev/null
+++ b/hi3861_adapter/kal/posix/BUILD.gn
@@ -0,0 +1,48 @@
+# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+#
+# 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 the copyright holder 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.
+
+import("//build/lite/config/component/lite_component.gni")
+
+static_library("posix") {
+ sources = [
+ "src/file.c",
+ "src/libc.c",
+ "src/pthread.c",
+ "src/pthread_attr.c",
+ "src/time.c",
+ ]
+
+ include_dirs = [ "include" ]
+ defines = [
+ "LIBC_VERSION_NUM=0x00010000",
+ "LIBC_VERSION_STR=\"1.0.0-liteos_m\"",
+ ]
+
+ cflags = [ "-Werror" ]
+}
diff --git a/hi3861_adapter/kal/posix/include/README b/hi3861_adapter/kal/posix/include/README
new file mode 100644
index 0000000000000000000000000000000000000000..49d4d90b999840549e26ee0c6882b438f4156b65
--- /dev/null
+++ b/hi3861_adapter/kal/posix/include/README
@@ -0,0 +1,12 @@
+Root directory "//" refers to "/vendor/hisi/hi3861/hi3861".
+We use header files from musl ("//platform/os/Huawei_LiteOS/components/lib/libc/musl/include").
+
+Some posix apis are already defined in different places:
+errno is defined in //build/libs/libc_base.o
+malloc and free are defined in //build/libs/libc_base.o
+pthread_mutex_* are defined in //build/libs/hi3861/release/no_mesh/liblitekernel_flash.a
+semaphore is defined in //build/libs/hi3861/release/no_mesh/liblitekernel_flash.a
+usleep is defined in //build/libs/hi3861/release/no_mesh/liblitekernel_flash.a
+clock_* are defined in //build/libs/liblitekernel_base.o
+printf is defined in //build/libs/liblitekernel_base.o
+fcntl and socket apis are defined in //build/libs/liblwip.a
diff --git a/hi3861_adapter/kal/posix/include/libc.h b/hi3861_adapter/kal/posix/include/libc.h
new file mode 100644
index 0000000000000000000000000000000000000000..7ee6cc587c78356723fa5c86434de28bc38da6bb
--- /dev/null
+++ b/hi3861_adapter/kal/posix/include/libc.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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 the copyright holder 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.
+ */
+
+#ifndef LIBC_H_
+#define LIBC_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+const char *libc_get_version_string(void);
+int libc_get_version(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // LIBC_H_
diff --git a/hi3861_adapter/kal/posix/include/limits.h b/hi3861_adapter/kal/posix/include/limits.h
new file mode 100644
index 0000000000000000000000000000000000000000..417ec2a1afc4b6ed5edb7acb87ab4c449a97c59a
--- /dev/null
+++ b/hi3861_adapter/kal/posix/include/limits.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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 the copyright holder 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.
+ */
+
+#ifndef _KAL_LIMITS_H
+#define _KAL_LIMITS_H
+
+#include_next
+
+#ifndef PTHREAD_STACK_MIN
+#ifdef __LITEOS__
+#define PTHREAD_STACK_MIN LOSCFG_BASE_CORE_TSK_MIN_STACK_SIZE
+#endif
+#endif
+
+#endif
diff --git a/hi3861_adapter/kal/posix/include/pthread.h b/hi3861_adapter/kal/posix/include/pthread.h
new file mode 100644
index 0000000000000000000000000000000000000000..ecff4d2f23ca90165422d006bda25f9f5d9c2611
--- /dev/null
+++ b/hi3861_adapter/kal/posix/include/pthread.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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 the copyright holder 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.
+ */
+
+#ifndef _KAL_PTHREAD_H
+#define _KAL_PTHREAD_H
+
+#include_next
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef _GNU_SOURCE
+int pthread_getname_np(pthread_t, char *, size_t);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/hi3861_adapter/kal/posix/src/file.c b/hi3861_adapter/kal/posix/src/file.c
new file mode 100644
index 0000000000000000000000000000000000000000..7eb1d0d0a6d4e850b967d2eef8e58a3ddaa6ff2f
--- /dev/null
+++ b/hi3861_adapter/kal/posix/src/file.c
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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 the copyright holder 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.
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "lwip/sockets.h"
+#include "hks_client.h"
+
+#define RANDOM_DEV_FD LWIP_CONFIG_NUM_SOCKETS
+#define RANDOM_DEV_PATH "/dev/random"
+
+#define FREE_AND_SET_NULL(ptr) do { \
+ free(ptr); \
+ ptr = NULL; \
+} while (0)
+
+/**
+ * @brief Get canonical form of a given path based on cwd(Current working directory).
+ *
+ * @param cwd Indicates the current working directory.
+ * @param path Indicates the path to be canonicalization.
+ * @param buf Indicates the pointer to the buffer where the result will be return.
+ * @param bufSize Indicates the size of the buffer.
+ * @return Returns the length of the canonical path.
+ *
+ * @attention if path is an absolute path, cwd is ignored. if cwd if not specified, it is assumed to be root('/').
+ * if the buffer is not big enough the result will be truncated, but the return value will always be the
+ * length of the canonical path.
+ */
+static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, size_t bufSize)
+{
+ if (!path) {
+ path = "";
+ }
+
+ if (!cwd || path[0] == '/') {
+ cwd = "";
+ }
+
+ size_t tmpLen = strlen(cwd) + strlen(path) + 4; // three '/' and one '\0'
+ if (tmpLen <= 0) {
+ return 0;
+ }
+ char *tmpBuf = (char *)malloc(tmpLen);
+ if (tmpBuf == NULL) {
+ return 0;
+ }
+
+ if (-1 == sprintf_s(tmpBuf, tmpLen, "/%s/%s/", cwd, path)) {
+ free(tmpBuf);
+ return 0;
+ }
+
+ char *p;
+ /* replace /./ to / */
+ while ((p = strstr(tmpBuf, "/./")) != NULL) {
+ if (EOK != memmove_s(p, tmpLen - (p - tmpBuf), p + 2, tmpLen - (p - tmpBuf) - 2)) {
+ free(tmpBuf);
+ return 0;
+ }
+ }
+
+ /* replace // to / */
+ while ((p = strstr(tmpBuf, "//")) != NULL) {
+ if (EOK != memmove_s(p, tmpLen - (p - tmpBuf), p + 1, tmpLen - (p - tmpBuf) - 1)) {
+ free(tmpBuf);
+ return 0;
+ }
+ }
+
+ /* handle /../ (e.g., replace /aa/bb/../ to /aa/) */
+ while ((p = strstr(tmpBuf, "/../")) != NULL) {
+ char *start = p;
+ while (start > tmpBuf && *--start != '/') {
+ }
+ if (EOK != memmove_s(start, tmpLen - (start - tmpBuf), p + 3, tmpLen - (p - tmpBuf) - 3)) {
+ free(tmpBuf);
+ return 0;
+ }
+ }
+
+ size_t totalLen = strlen(tmpBuf);
+
+ /* strip the last / */
+ if (totalLen > 1 && tmpBuf[totalLen - 1] == '/') {
+ tmpBuf[--totalLen] = 0;
+ }
+
+ if (!buf || bufSize == 0) {
+ free(tmpBuf);
+ return totalLen;
+ }
+
+ if (EOK != memcpy_s(buf, bufSize, tmpBuf, (totalLen + 1 > bufSize) ? bufSize : totalLen + 1)) {
+ free(tmpBuf);
+ return 0;
+ }
+
+ buf[bufSize - 1] = 0;
+ free(tmpBuf);
+ return totalLen;
+}
+
+int open(const char *file, int oflag, ...)
+{
+ unsigned flags = O_RDONLY | O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_LARGEFILE | O_TRUNC | O_EXCL | O_DIRECTORY;
+ if (((unsigned)oflag & ~flags) || (file == NULL)) {
+ errno = EINVAL;
+ return -1;
+ }
+ size_t pathLen = strlen(file) + 1;
+ if (pathLen <= 0) {
+ errno = EINVAL;
+ return -1;
+ }
+ char *canonicalPath = (char *)malloc(pathLen);
+ if (!canonicalPath) {
+ errno = ENOMEM;
+ return -1;
+ }
+ if (GetCanonicalPath(NULL, file, canonicalPath, pathLen) == 0) {
+ FREE_AND_SET_NULL(canonicalPath);
+ errno = ENOMEM;
+ return -1;
+ }
+ if (strcmp(canonicalPath, RANDOM_DEV_PATH) == 0) {
+ FREE_AND_SET_NULL(canonicalPath);
+ if ((O_ACCMODE & (unsigned)oflag) != O_RDONLY) {
+ errno = EPERM;
+ return -1;
+ }
+ if ((unsigned)oflag & O_DIRECTORY) {
+ errno = ENOTDIR;
+ return -1;
+ }
+ return RANDOM_DEV_FD;
+ }
+ if (strcmp(canonicalPath, "/") == 0 || strcmp(canonicalPath, "/dev") == 0) {
+ FREE_AND_SET_NULL(canonicalPath);
+ if ((unsigned)oflag & O_DIRECTORY) {
+ errno = EPERM;
+ return -1;
+ }
+ errno = EISDIR;
+ return -1;
+ }
+ FREE_AND_SET_NULL(canonicalPath);
+ errno = ENOENT;
+ return -1;
+}
+
+int close(int fd)
+{
+ if (fd == RANDOM_DEV_FD) {
+ return 0;
+ }
+ return closesocket(fd);
+}
+
+ssize_t read(int fd, void *buf, size_t nbytes)
+{
+ if (fd == RANDOM_DEV_FD) {
+ if (nbytes == 0) {
+ return 0;
+ }
+ if (buf == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+ if (nbytes > 1024) {
+ nbytes = 1024; /* hks_generate_random: random_size must <= 1024 */
+ }
+ struct hks_blob key = {HKS_BLOB_TYPE_RAW, (uint8_t *)buf, nbytes};
+ if (hks_generate_random(&key) != 0) {
+ errno = EIO;
+ return -1;
+ }
+ return (ssize_t)nbytes;
+ }
+ return recv(fd, buf, nbytes, 0);
+}
+
+ssize_t write(int fd, const void *buf, size_t nbytes)
+{
+ if (fd == RANDOM_DEV_FD) {
+ errno = EBADF; /* "/dev/random" is readonly */
+ return -1;
+ }
+ return send(fd, buf, nbytes, 0);
+}
diff --git a/hi3861_adapter/kal/posix/src/libc.c b/hi3861_adapter/kal/posix/src/libc.c
new file mode 100644
index 0000000000000000000000000000000000000000..9bc3ada298c569e910b4bbf9441bf87c48073bff
--- /dev/null
+++ b/hi3861_adapter/kal/posix/src/libc.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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 the copyright holder 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.
+ */
+
+#include
+
+/**
+ * get libc version string.
+ * @return libc version string. the format is ..[-[-]]
+ */
+const char *libc_get_version_string(void)
+{
+ return LIBC_VERSION_STR;
+}
+
+/**
+ * get libc version code.
+ * @return libc version code. the format is 0x00XXYYZZ, XX is major version, YY is minor version and ZZ is patch version
+ */
+int libc_get_version(void)
+{
+ return LIBC_VERSION_NUM;
+}
diff --git a/hi3861_adapter/kal/posix/src/pthread.c b/hi3861_adapter/kal/posix/src/pthread.c
new file mode 100644
index 0000000000000000000000000000000000000000..c74e986a2a26db705220c0dd641cf4de64fdaf76
--- /dev/null
+++ b/hi3861_adapter/kal/posix/src/pthread.c
@@ -0,0 +1,262 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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 the copyright holder 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.
+ */
+
+#include
+#include
+#include
+#include
+#include "los_task.h"
+#include "los_task_pri.h"
+
+#define PTHREAD_NAMELEN 16
+
+/* this is just an assertion: LOS_TASK_ARG_NUM >= 4 */
+typedef char NULNAM[-!((LOS_TASK_ARG_NUM * 4) >= PTHREAD_NAMELEN)];
+
+static void *PthreadEntry(UINT32 param1, UINT32 param2, UINT32 param3, UINT32 param4)
+{
+ void *(*startRoutine)(void *) = (void *)(UINTPTR)param1;
+ void *param = (void *)(UINTPTR)param2;
+ (void)param3;
+ (void)param4;
+ int ret;
+
+ LosTaskCB *tcb = OS_TCB_FROM_TID(LOS_CurTaskIDGet());
+ char *tmp = tcb->taskName;
+ tcb->taskName = (char *)tcb->args; /* args are reused as task name */
+ ret = strcpy_s(tcb->taskName, PTHREAD_NAMELEN, tmp);
+ if (ret != 0) {
+ free(tmp);
+ return NULL;
+ }
+ free(tmp);
+
+ return startRoutine(param);
+}
+
+static inline int IsPthread(pthread_t thread)
+{
+ return ((UINT32)thread <= LOSCFG_BASE_CORE_TSK_LIMIT) &&
+ (OS_TCB_FROM_TID((UINT32)thread)->taskEntry == PthreadEntry);
+}
+
+int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
+ void *(*startRoutine)(void *), void *arg)
+{
+ TSK_INIT_PARAM_S taskInitParam = {0};
+ UINT32 taskID;
+
+ if ((thread == NULL) || (startRoutine == NULL)) {
+ return EINVAL;
+ }
+
+ taskInitParam.usTaskPrio = LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO;
+ taskInitParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
+ if (attr) {
+ if (attr->detachstate == PTHREAD_CREATE_DETACHED) {
+ return ENOTSUP;
+ }
+ if (attr->stackaddr_set) {
+ return ENOTSUP;
+ }
+ if (attr->stacksize_set) {
+ taskInitParam.uwStackSize = attr->stacksize;
+ }
+ taskInitParam.usTaskPrio = (UINT16)attr->schedparam.sched_priority;
+ }
+
+ taskInitParam.pcName = malloc(PTHREAD_NAMELEN);
+ if (taskInitParam.pcName == NULL) {
+ return ENOMEM;
+ }
+
+ taskInitParam.pfnTaskEntry = PthreadEntry;
+ taskInitParam.auwArgs[0] = (UINT32)(UINTPTR)startRoutine;
+ taskInitParam.auwArgs[1] = (UINT32)(UINTPTR)arg;
+
+ if (LOS_TaskCreateOnly(&taskID, &taskInitParam) != LOS_OK) {
+ free(taskInitParam.pcName);
+ return EINVAL;
+ }
+
+ /* set pthread default name */
+ (void)sprintf_s(taskInitParam.pcName, PTHREAD_NAMELEN, "pthread%u", taskID);
+
+ (void)LOS_TaskResume(taskID);
+
+ *thread = (pthread_t)taskID;
+ return 0;
+}
+
+int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param)
+{
+ if ((param == NULL) || (param->sched_priority < OS_TASK_PRIORITY_HIGHEST) ||
+ (param->sched_priority >= OS_TASK_PRIORITY_LOWEST) || !IsPthread(thread)) {
+ return EINVAL;
+ }
+
+ /* Only support SCHED_RR policy now */
+ if (policy != SCHED_RR) {
+ return ENOTSUP;
+ }
+
+ if (LOS_TaskPriSet((UINT32)thread, (UINT16)param->sched_priority) != LOS_OK) {
+ return EINVAL;
+ }
+
+ return 0;
+}
+
+int pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param)
+{
+ UINT32 prio;
+
+ if ((policy == NULL) || (param == NULL) || !IsPthread(thread)) {
+ return EINVAL;
+ }
+
+ prio = LOS_TaskPriGet((UINT32)thread);
+ if (prio == OS_INVALID) {
+ return EINVAL;
+ }
+
+ *policy = SCHED_RR;
+ param->sched_priority = prio;
+ return 0;
+}
+
+pthread_t pthread_self(void)
+{
+ return (pthread_t)LOS_CurTaskIDGet();
+}
+
+int pthread_cancel(pthread_t thread)
+{
+ if (!IsPthread(thread)) {
+ return EINVAL;
+ }
+
+ return ENOSYS;
+}
+
+static void *VoidTask(UINT32 param1, UINT32 param2, UINT32 param3, UINT32 param4)
+{
+ (void)param1;
+ (void)param2;
+ (void)param3;
+ (void)param4;
+ return 0;
+}
+
+static void CleanupTaskResource(void)
+{
+ TSK_INIT_PARAM_S taskInitParam = {0};
+ UINT32 taskID;
+
+ taskInitParam.pcName = "void";
+ taskInitParam.pfnTaskEntry = VoidTask;
+ taskInitParam.usTaskPrio = LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO;
+ taskInitParam.uwStackSize = LOSCFG_BASE_CORE_TSK_MIN_STACK_SIZE;
+
+ (void)LOS_TaskCreate(&taskID, &taskInitParam);
+}
+
+int pthread_join(pthread_t thread, void **retval)
+{
+ UINT32 taskStatus;
+
+ if (!IsPthread(thread)) {
+ return EINVAL;
+ }
+
+ if (retval) {
+ /* retrieve thread exit code is not supported currently */
+ return ENOTSUP;
+ }
+
+ if (thread == pthread_self()) {
+ return EDEADLK;
+ }
+
+ while (LOS_TaskStatusGet((UINT32)thread, &taskStatus) == LOS_OK) {
+ usleep(10000);
+ }
+
+ CleanupTaskResource();
+ return 0;
+}
+
+int pthread_detach(pthread_t thread)
+{
+ if (!IsPthread(thread)) {
+ return EINVAL;
+ }
+
+ return ENOSYS;
+}
+
+void pthread_exit(void *retVal)
+{
+ (void)retVal;
+ (void)LOS_TaskDelete(LOS_CurTaskIDGet());
+}
+
+int pthread_setname_np(pthread_t thread, const char *name)
+{
+ char *taskName = LOS_TaskNameGet((UINT32)thread);
+ if (taskName == NULL || !IsPthread(thread)) {
+ return EINVAL;
+ }
+ if (strnlen(name, PTHREAD_NAMELEN) >= PTHREAD_NAMELEN) {
+ return ERANGE;
+ }
+ if (strcpy_s(taskName, PTHREAD_NAMELEN, name) != 0) {
+ return ERANGE;
+ }
+ return 0;
+}
+
+int pthread_getname_np(pthread_t thread, char *buf, size_t buflen)
+{
+ int ret;
+
+ const char *name = LOS_TaskNameGet((UINT32)thread);
+ if (name == NULL || !IsPthread(thread)) {
+ return EINVAL;
+ }
+ if (buflen > strlen(name)) {
+ ret = strcpy_s(buf, buflen, name);
+ if (ret == 0) {
+ return 0;
+ }
+ }
+ return ERANGE;
+}
diff --git a/hi3861_adapter/kal/posix/src/pthread_attr.c b/hi3861_adapter/kal/posix/src/pthread_attr.c
new file mode 100644
index 0000000000000000000000000000000000000000..9fdbcebe2cd4211d775b7f539452b22361698bba
--- /dev/null
+++ b/hi3861_adapter/kal/posix/src/pthread_attr.c
@@ -0,0 +1,232 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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 the copyright holder 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.
+ */
+
+#include
+#include
+#include
+
+int pthread_attr_init(pthread_attr_t *attr)
+{
+ if (attr == NULL) {
+ return EINVAL;
+ }
+
+ attr->detachstate = PTHREAD_CREATE_JOINABLE;
+ attr->schedpolicy = SCHED_RR;
+ attr->schedparam.sched_priority = LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO;
+ attr->inheritsched = PTHREAD_INHERIT_SCHED;
+ attr->scope = PTHREAD_SCOPE_PROCESS;
+ attr->stackaddr_set = 0;
+ attr->stackaddr = NULL;
+ attr->stacksize_set = 1;
+ attr->stacksize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
+
+ return 0;
+}
+
+int pthread_attr_destroy(pthread_attr_t *attr)
+{
+ if (attr == NULL) {
+ return EINVAL;
+ }
+
+ /* Nothing to do here... */
+ return 0;
+}
+
+int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachState)
+{
+ if ((attr != NULL) && ((detachState == PTHREAD_CREATE_JOINABLE) || (detachState == PTHREAD_CREATE_DETACHED))) {
+ attr->detachstate = (UINT32)detachState;
+ return 0;
+ }
+
+ return EINVAL;
+}
+
+int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachState)
+{
+ if ((attr == NULL) || (detachState == NULL)) {
+ return EINVAL;
+ }
+
+ *detachState = (int)attr->detachstate;
+
+ return 0;
+}
+
+int pthread_attr_setscope(pthread_attr_t *attr, int scope)
+{
+ if (attr == NULL) {
+ return EINVAL;
+ }
+
+ if (scope == PTHREAD_SCOPE_PROCESS) {
+ attr->scope = (unsigned int)scope;
+ return 0;
+ }
+
+ if (scope == PTHREAD_SCOPE_SYSTEM) {
+ return ENOTSUP;
+ }
+
+ return EINVAL;
+}
+
+int pthread_attr_getscope(const pthread_attr_t *attr, int *scope)
+{
+ if ((attr == NULL) || (scope == NULL)) {
+ return EINVAL;
+ }
+
+ *scope = (int)attr->scope;
+
+ return 0;
+}
+
+int pthread_attr_setinheritsched(pthread_attr_t *attr, int inherit)
+{
+ if ((attr != NULL) && ((inherit == PTHREAD_INHERIT_SCHED) || (inherit == PTHREAD_EXPLICIT_SCHED))) {
+ attr->inheritsched = (UINT32)inherit;
+ return 0;
+ }
+
+ return EINVAL;
+}
+
+int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inherit)
+{
+ if ((attr == NULL) || (inherit == NULL)) {
+ return EINVAL;
+ }
+
+ *inherit = (int)attr->inheritsched;
+
+ return 0;
+}
+
+int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy)
+{
+ if ((attr != NULL) && (policy == SCHED_RR)) {
+ attr->schedpolicy = SCHED_RR;
+ return 0;
+ }
+
+ return EINVAL;
+}
+
+int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy)
+{
+ if ((attr == NULL) || (policy == NULL)) {
+ return EINVAL;
+ }
+
+ *policy = (int)attr->schedpolicy;
+
+ return 0;
+}
+
+int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param)
+{
+ if ((attr == NULL) || (param == NULL)) {
+ return EINVAL;
+ } else if ((param->sched_priority < OS_TASK_PRIORITY_HIGHEST) ||
+ (param->sched_priority >= OS_TASK_PRIORITY_LOWEST)) {
+ return ENOTSUP;
+ }
+
+ attr->schedparam = *param;
+
+ return 0;
+}
+
+int pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param)
+{
+ if ((attr == NULL) || (param == NULL)) {
+ return EINVAL;
+ }
+
+ *param = attr->schedparam;
+
+ return 0;
+}
+
+/*
+ * Set starting address of stack. Whether this is at the start or end of
+ * the memory block allocated for the stack depends on whether the stack
+ * grows up or down.
+ */
+int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackAddr)
+{
+ if (attr == NULL) {
+ return EINVAL;
+ }
+
+ attr->stackaddr_set = 1;
+ attr->stackaddr = stackAddr;
+
+ return 0;
+}
+
+int pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackAddr)
+{
+ if (((attr != NULL) && (stackAddr != NULL)) && attr->stackaddr_set) {
+ *stackAddr = attr->stackaddr;
+ return 0;
+ }
+
+ return EINVAL; /* Stack address not set, return EINVAL. */
+}
+
+int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stackSize)
+{
+ /* Reject inadequate stack sizes */
+ if ((attr == NULL) || (stackSize < PTHREAD_STACK_MIN)) {
+ return EINVAL;
+ }
+
+ attr->stacksize_set = 1;
+ attr->stacksize = stackSize;
+
+ return 0;
+}
+
+int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stackSize)
+{
+ /* Reject attempts to get a stack size when one has not been set. */
+ if ((attr == NULL) || (stackSize == NULL) || (!attr->stacksize_set)) {
+ return EINVAL;
+ }
+
+ *stackSize = attr->stacksize;
+
+ return 0;
+}
diff --git a/hi3861_adapter/kal/posix/src/time.c b/hi3861_adapter/kal/posix/src/time.c
new file mode 100644
index 0000000000000000000000000000000000000000..4b5a43d8cec88d4292f9a41d29411026452f9186
--- /dev/null
+++ b/hi3861_adapter/kal/posix/src/time.c
@@ -0,0 +1,274 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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 the copyright holder 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.
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#ifndef STATIC
+#define STATIC static
+#endif
+
+#define OS_SYS_NS_PER_US 1000
+#define OS_SYS_NS_PER_SECOND 1000000000
+#define OS_SYS_US_PER_SECOND 1000000
+#define OS_SYS_MS_PER_SECOND 1000
+
+STATIC INLINE BOOL ValidTimerID(UINT16 swtmrID)
+{
+ /* check timer id */
+ return (swtmrID < LOSCFG_BASE_CORE_SWTMR_LIMIT);
+}
+
+/* internal functions */
+STATIC INLINE BOOL ValidTimeSpec(const struct timespec *tp)
+{
+ /* Fail a NULL pointer */
+ if (tp == NULL) {
+ return FALSE;
+ }
+
+ /* Fail illegal nanosecond values */
+ if ((tp->tv_nsec < 0) || (tp->tv_nsec >= OS_SYS_NS_PER_SECOND) || (tp->tv_sec < 0)) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+STATIC INLINE UINT32 OsTimeSpec2Tick(const struct timespec *tp)
+{
+ UINT64 tick, ns;
+
+ ns = (UINT64)tp->tv_sec * OS_SYS_NS_PER_SECOND + tp->tv_nsec;
+ /* Round up for ticks */
+ tick = (ns * LOSCFG_BASE_CORE_TICK_PER_SECOND + (OS_SYS_NS_PER_SECOND - 1)) / OS_SYS_NS_PER_SECOND;
+ if (tick > LOS_WAIT_FOREVER) {
+ tick = LOS_WAIT_FOREVER;
+ }
+ return (UINT32)tick;
+}
+
+STATIC INLINE VOID OsTick2TimeSpec(struct timespec *tp, UINT32 tick)
+{
+ UINT64 ns = ((UINT64)tick * OS_SYS_NS_PER_SECOND) / LOSCFG_BASE_CORE_TICK_PER_SECOND;
+ tp->tv_sec = (time_t)(ns / OS_SYS_NS_PER_SECOND);
+ tp->tv_nsec = (long)(ns % OS_SYS_NS_PER_SECOND);
+}
+
+int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
+{
+ UINT64 nseconds;
+ UINT64 tick;
+ UINT32 ret;
+ const UINT32 nsPerTick = OS_SYS_NS_PER_SECOND / LOSCFG_BASE_CORE_TICK_PER_SECOND;
+
+ if (!ValidTimeSpec(rqtp)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ nseconds = (UINT64)rqtp->tv_sec * OS_SYS_NS_PER_SECOND + rqtp->tv_nsec;
+
+ tick = (nseconds + nsPerTick - 1) / nsPerTick; // Round up for ticks
+
+ if (tick >= UINT32_MAX) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ /* PS: skip the first tick because it is NOT a full tick. */
+ ret = LOS_TaskDelay(tick ? (UINT32)(tick + 1) : 0);
+ if (ret == LOS_OK || ret == LOS_ERRNO_TSK_YIELD_NOT_ENOUGH_TASK) {
+ if (rmtp) {
+ rmtp->tv_sec = rmtp->tv_nsec = 0;
+ }
+ return 0;
+ }
+
+ /* sleep in interrupt context or in task sched lock state */
+ errno = EPERM;
+ return -1;
+}
+
+int timer_create(clockid_t clockID, struct sigevent *restrict evp, timer_t *restrict timerID)
+{
+ UINT32 ret;
+ UINT16 swtmrID;
+
+ if (!timerID || (clockID != CLOCK_REALTIME)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (!evp || evp->sigev_notify != SIGEV_THREAD || evp->sigev_notify_attributes) {
+ errno = ENOTSUP;
+ return -1;
+ }
+
+ ret = LOS_SwtmrCreate(1, LOS_SWTMR_MODE_ONCE, (SWTMR_PROC_FUNC)evp->sigev_notify_function,
+ &swtmrID, (UINT32)(UINTPTR)evp->sigev_value.sival_ptr);
+ if (ret != LOS_OK) {
+ errno = (ret == LOS_ERRNO_SWTMR_MAXSIZE) ? EAGAIN : EINVAL;
+ return -1;
+ }
+
+ *timerID = (timer_t)(UINTPTR)swtmrID;
+ return 0;
+}
+
+int timer_delete(timer_t timerID)
+{
+ UINT16 swtmrID = (UINT16)(UINTPTR)timerID;
+
+ if (!ValidTimerID(swtmrID)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (LOS_SwtmrDelete(swtmrID) != LOS_OK) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ return 0;
+}
+
+int timer_settime(timer_t timerID, int flags,
+ const struct itimerspec *restrict value,
+ struct itimerspec *restrict oldValue)
+{
+ UINT16 swtmrID = (UINT16)(UINTPTR)timerID;
+ SWTMR_CTRL_S *swtmr = NULL;
+ UINT32 interval, expiry, ret;
+
+ if (flags != 0) {
+ /* flags not supported currently */
+ errno = ENOSYS;
+ return -1;
+ }
+
+ if (value == NULL || !ValidTimerID(swtmrID)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (!ValidTimeSpec(&value->it_value) || !ValidTimeSpec(&value->it_interval)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ expiry = OsTimeSpec2Tick(&value->it_value);
+ interval = OsTimeSpec2Tick(&value->it_interval);
+
+ /* if specified interval, it must be same with expiry due to the limitation of liteos-m */
+ if (interval && interval != expiry) {
+ errno = ENOTSUP;
+ return -1;
+ }
+
+ if (oldValue) {
+ (VOID)timer_gettime(timerID, oldValue);
+ }
+
+ ret = LOS_SwtmrStop(swtmrID);
+ if ((ret != LOS_OK) && (ret != LOS_ERRNO_SWTMR_NOT_STARTED)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ swtmr = OS_SWT_FROM_SID(swtmrID);
+ ret = LOS_SwtmrModify(swtmrID, expiry, (interval ? LOS_SWTMR_MODE_PERIOD : LOS_SWTMR_MODE_NO_SELFDELETE),
+ swtmr->pfnHandler, swtmr->uwArg);
+ if (ret != LOS_OK) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if ((value->it_value.tv_sec == 0) && (value->it_value.tv_nsec == 0)) {
+ /*
+ * 1) when expiry is 0, means timer should be stopped.
+ * 2) If timer is ticking, stopping timer is already done before.
+ * 3) If timer is created but not ticking, return 0 as well.
+ */
+ return 0;
+ }
+
+ if (LOS_SwtmrStart(swtmr->usTimerID) != LOS_OK) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ return 0;
+}
+
+int timer_gettime(timer_t timerID, struct itimerspec *value)
+{
+ UINT32 tick = 0;
+ SWTMR_CTRL_S *swtmr = NULL;
+ UINT16 swtmrID = (UINT16)(UINTPTR)timerID;
+ UINT32 ret;
+
+ if ((value == NULL) || !ValidTimerID(swtmrID)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ swtmr = OS_SWT_FROM_SID(swtmrID);
+
+ /* get expire time */
+ ret = LOS_SwtmrTimeGet(swtmr->usTimerID, &tick);
+ if ((ret != LOS_OK) && (ret != LOS_ERRNO_SWTMR_NOT_STARTED)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ OsTick2TimeSpec(&value->it_value, tick);
+ OsTick2TimeSpec(&value->it_interval, (swtmr->ucMode == LOS_SWTMR_MODE_ONCE) ? 0 : swtmr->uwInterval);
+ return 0;
+}
+
+int timer_getoverrun(timer_t timerID)
+{
+ UINT16 swtmrID = (UINT16)(UINTPTR)timerID;
+
+ if (!ValidTimerID(swtmrID)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ errno = ENOSYS;
+ return -1;
+}
diff --git a/interfaces/BUILD.gn b/interfaces/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..43fe7ae25803982bd438870111ff9ba7c2363d2f
--- /dev/null
+++ b/interfaces/BUILD.gn
@@ -0,0 +1,29 @@
+# Copyright (c) 2020 Itcast Co., Ltd.
+# 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.
+
+import("//build/lite/ndk/ndk.gni")
+
+group("genkipi_interfaces") {
+ deps = [
+ "$ohos_board_adapter_dir/hals/interfaces:hal_genkipi_interfaces",
+ ]
+}
+
+if (ohos_kernel_type == "liteos_m") {
+ ndk_lib("genkipi_interfaces_ndk") {
+ deps = [
+ "$ohos_board_adapter_dir/hals/interfaces:hal_genkipi_interfaces",
+ ]
+ head_files = [ "//device/itcast/genkipi/interfaces/kits" ]
+ }
+}
diff --git a/interfaces/kits/genki_led.h b/interfaces/kits/genki_led.h
new file mode 100644
index 0000000000000000000000000000000000000000..53887e2cfdcbfb0825bed35b8d018999af0b450a
--- /dev/null
+++ b/interfaces/kits/genki_led.h
@@ -0,0 +1,19 @@
+
+#ifndef GENKI_LED_H
+#define GENKI_LED_H
+
+#include
+
+void GenkiLedToggle(void);
+
+void GenkiLedState(unsigned char *state);
+
+void GenkiLedOpen(void);
+
+void GenkiLedClose(void);
+
+void GenkiLedPwmStart(unsigned short duty, unsigned int freq);
+
+void GenkiLedPwmStop(void);
+
+#endif //GENKI_LED_H
diff --git a/interfaces/kits/genki_pin.h b/interfaces/kits/genki_pin.h
new file mode 100644
index 0000000000000000000000000000000000000000..ffe6afd17eb968aa6b381ee39c2e6bc7abce4fce
--- /dev/null
+++ b/interfaces/kits/genki_pin.h
@@ -0,0 +1,390 @@
+/*
+ * Copyright (c) 2020 Itcast., Ltd.
+ * 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 GENKI_PIN_H
+#define GENKI_PIN_H
+
+/**
+ * @brief Enumerates GPIO hardware pin IDs.
+ */
+typedef enum
+{
+ /** GPIO hardware pin 0 */
+ IOT_IO_NAME_0,
+ /** GPIO hardware pin 1 */
+ IOT_IO_NAME_1,
+ /** GPIO hardware pin 2 */
+ IOT_IO_NAME_2,
+ /** GPIO hardware pin 3 */
+ IOT_IO_NAME_3,
+ /** GPIO hardware pin 4 */
+ IOT_IO_NAME_4,
+ /** GPIO hardware pin 5 */
+ IOT_IO_NAME_5,
+ /** GPIO hardware pin 6 */
+ IOT_IO_NAME_6,
+ /** GPIO hardware pin 7 */
+ IOT_IO_NAME_7,
+ /** GPIO hardware pin 8 */
+ IOT_IO_NAME_8,
+ /** GPIO hardware pin 9 */
+ IOT_IO_NAME_9,
+ /** GPIO hardware pin 10 */
+ IOT_IO_NAME_10,
+ /** GPIO hardware pin 11 */
+ IOT_IO_NAME_11,
+ /** GPIO hardware pin 12 */
+ IOT_IO_NAME_12,
+ /** GPIO hardware pin 13 */
+ IOT_IO_NAME_13,
+ /** GPIO hardware pin 14 */
+ IOT_IO_NAME_14,
+ /**< SFC_CSN */
+ IOT_IO_NAME_SFC_CSN,
+ /**< SFC_IO1 */
+ IOT_IO_NAME_SFC_IO1,
+ /**< SFC_IO2 */
+ IOT_IO_NAME_SFC_IO2,
+ /**< SFC_IO0 */
+ IOT_IO_NAME_SFC_IO0,
+ /**< SFC_CLK */
+ IOT_IO_NAME_SFC_CLK,
+ /**< SFC_IO3 */
+ IOT_IO_NAME_SFC_IO3,
+ /** Maximum value */
+ IOT_IO_NAME_MAX,
+} IoTIoName;
+
+/**
+ * @brief Enumerates the functions of GPIO hardware pin 0.
+ */
+typedef enum
+{
+ /** GPIO0 function */
+ IOT_IO_FUNC_0_GPIO,
+ /** Functions of UART1 TXD */
+ IOT_IO_FUNC_0_UART1_TXD = 2,
+ /** SPI1 CK function */
+ IOT_IO_FUNC_0_SPI1_CK,
+ /** Functions of JTAG TD0 */
+ IOT_IO_FUNC_0_JTAG_TDO,
+ /** PWM3 OUT function */
+ IOT_IO_FUNC_0_PWM3_OUT,
+ /** I2C1 SDA function */
+ IOT_IO_FUNC_0_I2C1_SDA,
+} IoTIoFunc0;
+
+/**
+ * @brief Enumerates the functions of GPIO hardware pin 1.
+ */
+typedef enum
+{
+ /** GPIO1 function */
+ IOT_IO_FUNC_1_GPIO,
+ IOT_IO_FUNC_1_UART1_RXD = 2,
+ IOT_IO_FUNC_1_SPI1_RXD,
+ IOT_IO_FUNC_1_JTAG_TCK,
+ IOT_IO_FUNC_1_PWM4_OUT,
+ IOT_IO_FUNC_1_I2C1_SCL,
+ IOT_IO_FUNC_1_BT_FREQ,
+} IoTIoFunc1;
+
+/**
+ * @brief Enumerates the functions of GPIO hardware pin 2.
+ */
+typedef enum
+{
+ /** GPIO2 function */
+ IOT_IO_FUNC_2_GPIO,
+ /** UART1 RTS function */
+ IOT_IO_FUNC_2_UART1_RTS_N = 2,
+ /** SPI1 TXD function */
+ IOT_IO_FUNC_2_SPI1_TXD,
+ /** JTAG TRSTN function */
+ IOT_IO_FUNC_2_JTAG_TRSTN,
+ /** PWM2 OUT function */
+ IOT_IO_FUNC_2_PWM2_OUT,
+ /** SSI CLK function */
+ IOT_IO_FUNC_2_SSI_CLK = 7,
+} IoTIoFunc2;
+
+/**
+ * @brief Enumerates the functions of GPIO hardware pin 3.
+ */
+typedef enum
+{
+ /** GPIO3 function */
+ IOT_IO_FUNC_3_GPIO,
+ /** UART0 TXD function */
+ IOT_IO_FUNC_3_UART0_TXD,
+ /** UART1 CTS function */
+ IOT_IO_FUNC_3_UART1_CTS_N,
+ /** SPI CSN function */
+ IOT_IO_FUNC_3_SPI1_CSN,
+ /** JTAG TDI function */
+ IOT_IO_FUNC_3_JTAG_TDI,
+ /** PWM5 OUT function */
+ IOT_IO_FUNC_3_PWM5_OUT,
+ /** I2C1 SDA function */
+ IOT_IO_FUNC_3_I2C1_SDA,
+ /** SSI DATA function */
+ IOT_IO_FUNC_3_SSI_DATA,
+} IoTIoFunc3;
+
+/**
+ * @brief Enumerates the functions of GPIO hardware pin 4.
+ */
+typedef enum
+{
+ /** GPIO4 function */
+ IOT_IO_FUNC_4_GPIO,
+ /** UART0 RXD function */
+ IOT_IO_FUNC_4_UART0_RXD = 2,
+ /** JTAG TMS function */
+ IOT_IO_FUNC_4_JTAG_TMS = 4,
+ /** PWM1 OUT function */
+ IOT_IO_FUNC_4_PWM1_OUT,
+ /** I2C1 SCL function */
+ IOT_IO_FUNC_4_I2C1_SCL,
+} IoTIoFunc4;
+
+/**
+ * @brief Enumerates the functions of GPIO hardware pin 5.
+ */
+typedef enum
+{
+ /** GPIO5 function */
+ IOT_IO_FUNC_5_GPIO,
+ /** UART1 RXD function */
+ IOT_IO_FUNC_5_UART1_RXD = 2,
+ /** SPI0 CSN function */
+ IOT_IO_FUNC_5_SPI0_CSN,
+ /** PWM2 OUT function */
+ IOT_IO_FUNC_5_PWM2_OUT = 5,
+ /** I2C0 MCLK function */
+ IOT_IO_FUNC_5_I2S0_MCLK,
+ /** BT STATUS function */
+ IOT_IO_FUNC_5_BT_STATUS,
+} IoTIoFunc5;
+
+/**
+ * @brief Enumerates the functions of GPIO hardware pin 6.
+ */
+typedef enum
+{
+ /** GPIO6 function */
+ IOT_IO_FUNC_6_GPIO,
+ /** UART1 TXD function */
+ IOT_IO_FUNC_6_UART1_TXD = 2,
+ /** SPI0 CK function */
+ IOT_IO_FUNC_6_SPI0_CK,
+ /** PWM3 OUT function */
+ IOT_IO_FUNC_6_PWM3_OUT = 5,
+ /** I2S0 TX function */
+ IOT_IO_FUNC_6_I2S0_TX,
+ /** COEX switch function */
+ IOT_IO_FUNC_6_COEX_SWITCH,
+} IoTIoFunc6;
+
+/**
+ * @brief Enumerates the functions of GPIO hardware pin 7.
+ */
+typedef enum
+{
+ /** GPIO7 function */
+ IOT_IO_FUNC_7_GPIO,
+ /** UART1 CTS function */
+ IOT_IO_FUNC_7_UART1_CTS_N = 2,
+ /** SPI0 RXD function */
+ IOT_IO_FUNC_7_SPI0_RXD,
+ /** PWM0 OUT function */
+ IOT_IO_FUNC_7_PWM0_OUT = 5,
+ /** I2S0 BCLK function */
+ IOT_IO_FUNC_7_I2S0_BCLK,
+ /** BT ACTIVE function */
+ IOT_IO_FUNC_7_BT_ACTIVE,
+} IoTIoFunc7;
+
+/**
+ * @brief Enumerates the functions of GPIO hardware pin 8.
+ */
+typedef enum
+{
+ /** GPIO8 function */
+ IOT_IO_FUNC_8_GPIO,
+ /** UART1 RTS function */
+ IOT_IO_FUNC_8_UART1_RTS_N = 2,
+ /** SPI0 TXD function */
+ IOT_IO_FUNC_8_SPI0_TXD,
+ /** PWM1 OUT function */
+ IOT_IO_FUNC_8_PWM1_OUT = 5,
+ /** I2S0 WS function */
+ IOT_IO_FUNC_8_I2S0_WS,
+ /** WLAN ACTIVE function */
+ IOT_IO_FUNC_8_WLAN_ACTIVE,
+} IoTIoFunc8;
+
+/**
+ * @brief Enumerates the functions of GPIO hardware pin 10.
+ */
+typedef enum
+{
+ /** GPIO10 function */
+ IOT_IO_FUNC_9_GPIO,
+ /** I2C0 SCL function */
+ IOT_IO_FUNC_9_I2C0_SCL,
+ /** UART2 RTS function */
+ IOT_IO_FUNC_9_UART2_RTS_N,
+ /** SDIO D2 function */
+ IOT_IO_FUNC_9_SDIO_D2,
+ /** SPI0 TXD function */
+ IOT_IO_FUNC_9_SPI0_TXD,
+ /** PWM0 OUT function */
+ IOT_IO_FUNC_9_PWM0_OUT,
+ /** I2S0 MCLK function */
+ IOT_IO_FUNC_9_I2S0_MCLK = 7,
+} IoTIoFunc9;
+
+/**
+ * @brief Enumerates the functions of GPIO hardware pin 9.
+ */
+typedef enum
+{
+ /** GPIO9 function */
+ IOT_IO_FUNC_10_GPIO,
+ /** I2C0 SDA function */
+ IOT_IO_FUNC_10_I2C0_SDA,
+ /** UART2 CTS function */
+ IOT_IO_FUNC_10_UART2_CTS_N,
+ /** SDIO D3 function */
+ IOT_IO_FUNC_10_SDIO_D3,
+ /** SPI0 CK function */
+ IOT_IO_FUNC_10_SPI0_CK,
+ /** PWM1 OUT function */
+ IOT_IO_FUNC_10_PWM1_OUT,
+ /** I2S0 TX function */
+ IOT_IO_FUNC_10_I2S0_TX = 7,
+} IoTIoFunc10;
+
+/**
+ * @brief Enumerates the functions of GPIO hardware pin 11.
+ */
+typedef enum
+{
+ /** GPIO11 function */
+ IOT_IO_FUNC_11_GPIO,
+ /** UART2 TXD function */
+ IOT_IO_FUNC_11_UART2_TXD = 2,
+ /** SDIO CMD function */
+ IOT_IO_FUNC_11_SDIO_CMD,
+ /** SDIO RXD function */
+ IOT_IO_FUNC_11_SPI0_RXD,
+ /** PWM2 OUT function */
+ IOT_IO_FUNC_11_PWM2_OUT,
+ /** RF TX_EN_EXT function */
+ IOT_IO_FUNC_11_RF_TX_EN_EXT,
+ /** I2S0 RX function */
+ IOT_IO_FUNC_11_I2S0_RX,
+} IoTIoFunc11;
+
+/**
+ * @brief Enumerates the functions of GPIO hardware pin 12.
+ */
+typedef enum
+{
+ /** GPIO12 function */
+ IOT_IO_FUNC_12_GPIO,
+ /** SUART2 RXD function */
+ IOT_IO_FUNC_12_UART2_RXD = 2,
+ /** SDIO CLK function */
+ IOT_IO_FUNC_12_SDIO_CLK,
+ /** SDIO CSN function */
+ IOT_IO_FUNC_12_SPI0_CSN,
+ /** PWM3 OUT function */
+ IOT_IO_FUNC_12_PWM3_OUT,
+ /** RF RX_EN_EXT function */
+ IOT_IO_FUNC_12_RF_RX_EN_EXT,
+ /** I2S0 BCLK function */
+ IOT_IO_FUNC_12_I2S0_BCLK,
+} IoTIoFunc12;
+
+/**
+ * @brief Enumerates the functions of GPIO hardware pin 13.
+ */
+typedef enum
+{
+ /** SSI DATA function */
+ IOT_IO_FUNC_13_SSI_DATA,
+ /** UART0 TXD function */
+ IOT_IO_FUNC_13_UART0_TXD,
+ /** UART2 RTS function */
+ IOT_IO_FUNC_13_UART2_RTS_N,
+ /** SDIO D0 function */
+ IOT_IO_FUNC_13_SDIO_D0,
+ /** GPIO13 function */
+ IOT_IO_FUNC_13_GPIO,
+ /** PWM4 OUT function */
+ IOT_IO_FUNC_13_PWM4_OUT,
+ /** I2C0 SDA function */
+ IOT_IO_FUNC_13_I2C0_SDA,
+ /** I2S0 WS function */
+ IOT_IO_FUNC_13_I2S0_WS,
+} IoTIoFunc13;
+
+/**
+ * @brief Enumerates the functions of GPIO hardware pin 14.
+ */
+typedef enum
+{
+ /** SSI CLK function */
+ IOT_IO_FUNC_14_SSI_CLK,
+ /** UART0 RXD function */
+ IOT_IO_FUNC_14_UART0_RXD,
+ /** UART2 CTS function */
+ IOT_IO_FUNC_14_UART2_CTS_N,
+ /** SDIO D1 function */
+ IOT_IO_FUNC_14_SDIO_D1,
+ /** GPIO14 function */
+ IOT_IO_FUNC_14_GPIO,
+ /** PWM5 OUT function */
+ IOT_IO_FUNC_14_PWM5_OUT,
+ /** I2C0 SCL function */
+ IOT_IO_FUNC_14_I2C0_SCL,
+} IoTIoFunc14;
+
+
+/**
+* @brief Enumerotes PWM Hardware port IDS
+*/
+typedef enum
+{
+ /** PWM hardware port 0 */
+ IOT_PWM_NAME_0,
+ /** PWM hardware port 1 */
+ IOT_PWM_NAME_1,
+ /** PWM hardware port 2 */
+ IOT_PWM_NAME_2,
+ /** PWM hardware port 3 */
+ IOT_PWM_NAME_3,
+ /** PWM hardware port 4 */
+ IOT_PWM_NAME_4,
+ /** PWM hardware port 5 */
+ IOT_PWM_NAME_5,
+ /** Maximum value */
+ IOT_PWM_NAME_MAX,
+} IoTPwmName;
+
+
+#endif //GENKI_PIN_H
diff --git a/interfaces/kits/genki_wifi_sta.h b/interfaces/kits/genki_wifi_sta.h
new file mode 100644
index 0000000000000000000000000000000000000000..bee34a47606d7ce06c4f0f746f24d718521ba54d
--- /dev/null
+++ b/interfaces/kits/genki_wifi_sta.h
@@ -0,0 +1,27 @@
+#ifndef GENKIPI_GENKI_WIFI_STA_H
+#define GENKIPI_GENKI_WIFI_STA_H
+
+/**
+ * link wifi
+ * @param ssid
+ * @param password
+ * @param hostname
+ * @return 0 failed 1 success
+ */
+int connect_wifi(const char* ssid, const char* password, const char* hostname);
+/**
+ * disconnect wifi
+ * @return 0 failed 1 success
+ */
+int disconnect_wifi(void);
+
+/**
+ * get wifi addr
+ * @param ip
+ * @param netmask
+ * @param gateway
+ * @return
+ */
+int get_wifi_addr(unsigned int *ip, unsigned int *netmask, unsigned int *gateway);
+
+#endif //GENKIPI_GENKI_WIFI_STA_H
diff --git a/sdk_liteos/.sconsign.dblite b/sdk_liteos/.sconsign.dblite
new file mode 100644
index 0000000000000000000000000000000000000000..2f76e6e581d39b95239d1618c6d3134f4f6f2c84
Binary files /dev/null and b/sdk_liteos/.sconsign.dblite differ
diff --git a/sdk_liteos/3rd_sdk/demolink/libs/.gitignore b/sdk_liteos/3rd_sdk/demolink/libs/.gitignore
new file mode 100755
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/sdk_liteos/BUILD.gn b/sdk_liteos/BUILD.gn
new file mode 100755
index 0000000000000000000000000000000000000000..c60718c5e673946997ad617621037bbdaba1cfb8
--- /dev/null
+++ b/sdk_liteos/BUILD.gn
@@ -0,0 +1,35 @@
+# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
+
+import("//build/lite/config/component/lite_component.gni")
+import("//build/lite/config/subsystem/lite_subsystem.gni")
+
+declare_args() {
+ enable_hos_vendor_wifiiot_xts = false
+}
+
+lite_subsystem("wifiiot_sdk") {
+ subsystem_components = [ ":sdk" ]
+}
+
+build_ext_component("run_wifiiot_scons") {
+ exec_path = rebase_path(".", root_build_dir)
+ outdir = rebase_path(root_out_dir)
+ command = "sh hm_build.sh $outdir"
+ deps = [
+ ":sdk",
+ "//base/security/deviceauth/frameworks/deviceauth_lite:hichainsdk",
+ "//build/lite:ohos",
+ ]
+ if (enable_hos_vendor_wifiiot_xts) {
+ deps += [ "//build/lite/config/subsystem/xts:xts" ]
+ }
+}
+
+lite_component("sdk") {
+ features = []
+
+ deps = [
+ "//build/lite/config/component/cJSON:cjson_static",
+ "//device/itcast/genkipi/hi3861_adapter/kal",
+ ]
+}
diff --git a/sdk_liteos/Makefile b/sdk_liteos/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..a1c2fd2a7ffe6f0ad86fbc8c63b107d1af2243b0
--- /dev/null
+++ b/sdk_liteos/Makefile
@@ -0,0 +1,31 @@
+# Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
+# 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.
+#
+MAIN_TOPDIR = $(shell pwd)
+export MAIN_TOPDIR
+
+all:
+ $(MAKE) -f non_factory.mk all
+
+clean:
+ $(MAKE) -f non_factory.mk clean
+
+all_clean:
+ $(MAKE) -f non_factory.mk all_clean
+
+factory:
+ $(MAKE) -f factory.mk all
+
+clean_factory:
+ $(MAKE) -f factory.mk clean
+
diff --git a/sdk_liteos/NOTICE b/sdk_liteos/NOTICE
new file mode 100644
index 0000000000000000000000000000000000000000..6c34a396b81d8688a756aceae914eb766ee5a926
--- /dev/null
+++ b/sdk_liteos/NOTICE
@@ -0,0 +1,3687 @@
+OPEN SOURCE SOFTWARE NOTICE
+
+Please note we provide an open source software notice for the third party open source software along with this software and/or this software component (in the following just “this SOFTWARE”). The open source software licenses are granted by the respective right holders.
+
+Warranty Disclaimer
+THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
+
+Copyright Notice and License Texts
+
+----------------------------------------------------------------------
+Software: mbed TLS 2.16.6
+
+Copyright notice:
+Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+Copyright (C) 2016, ARM Limited, All Rights Reserved
+Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
+Copyright (c) 2014-2017, ARM Limited, All Rights Reserved
+Copyright (c) 2016, ARM Limited, All Rights Reserved
+Copyright (c) 2018, Arm Limited, All Rights Reserved
+Copyright (c) 2018, ARM Limited, All Rights Reserved
+Copyright (c) 2015-2019, ARM Limited, All Rights Reserved
+Copyright (C) 2018, Arm Limited, All Rights Reserved
+Copyright (C) 2018, ARM Limited, All Rights Reserved
+Copyright (c) 2017, ARM Limited, All Rights Reserved
+Copyright (C) 2006-2017, ARM Limited, All Rights Reserved
+Copyright (C) 2016-2018, ARM Limited, All Rights Reserved
+Copyright (C) 2018, Arm Limited (or its affiliates), All Rights Reserved
+Copyright (C) 2019, ARM Limited, All Rights Reserved
+Copyright (c) 2012-2016, ARM Limited, All Rights Reserved
+Copyright (c) 2015-2016, ARM Limited, All Rights Reserved
+Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved.
+Copyright (C) 2006-2018, ARM Limited, All Rights Reserved
+Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
+Copyright (C) 2015-2018, Arm Limited (or its affiliates), All Rights Reserved
+Copyright (C) 2006-2019, Arm Limited (or its affiliates), All Rights Reserved
+Copyright (C) 2016-2019, ARM Limited, All Rights Reserved
+Copyright (C) 2006-2019, ARM Limited, All Rights Reserved
+
+License: Apache License V2.0
+Unless specifically indicated otherwise in a file, files are licensed
+under the Apache 2.0 license, as can be found in: apache-2.0.txt
+
+----------------------------------------------------------------------
+Software: musl 1.2.0
+
+Copyright notice:
+Copyright © 2005-2020 Rich Felker, et al.
+Copyright © 1993,2004 Sun Microsystems or
+Copyright © 2003-2011 David Schultz or
+Copyright © 2003-2009 Steven G. Kargl or
+Copyright © 2003-2009 Bruce D. Evans or
+Copyright © 2008 Stephen L. Moshier or
+Copyright © 2017-2018 Arm Limited
+Copyright © 1994 David Burren.
+Copyright (c) 2008 Stephen L. Moshier
+Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
+Copyright (c) 2011 David Schultz
+Copyright (c) 2007 David Schultz
+Copyright (c) 2011 David Schultz
+Copyright (c) 1998-2012 Solar Designer
+Copyright (c) 1994 David Burren
+Copyright (c) 2000,2002,2010,2012 Solar Designer
+Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+Copyright (c) 2009-2011, Bruce D. Evans, Steven G. Kargl, David Schultz.
+Copyright (c) 2018, Arm Limited.
+Copyright (c) 2017-2018, Arm Limited.
+Copyright (c) 2005-2008 David Schultz
+Copyright (c) 2005-2011 David Schultz
+Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans.
+Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
+Copyright (c) 2001-2009 Ville Laurikari
+Copyright (C) 2011 by Valentin Ochs
+
+License: BSD 2-Clause License
+musl as a whole is licensed under the following standard MIT license:
+
+Copyright © 2005-2020 Rich Felker, et al.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Authors/contributors include:
+
+A. Wilcox
+Ada Worcester
+Alex Dowad
+Alex Suykov
+Alexander Monakov
+Andre McCurdy
+Andrew Kelley
+Anthony G. Basile
+Aric Belsito
+Arvid Picciani
+Bartosz Brachaczek
+Benjamin Peterson
+Bobby Bingham
+Boris Brezillon
+Brent Cook
+Chris Spiegel
+Clément Vasseur
+Daniel Micay
+Daniel Sabogal
+Daurnimator
+David Carlier
+David Edelsohn
+Denys Vlasenko
+Dmitry Ivanov
+Dmitry V. Levin
+Drew DeVault
+Emil Renner Berthing
+Fangrui Song
+Felix Fietkau
+Felix Janda
+Gianluca Anzolin
+Hauke Mehrtens
+He X
+Hiltjo Posthuma
+Isaac Dunham
+Jaydeep Patil
+Jens Gustedt
+Jeremy Huntwork
+Jo-Philipp Wich
+Joakim Sindholt
+John Spencer
+Julien Ramseier
+Justin Cormack
+Kaarle Ritvanen
+Khem Raj
+Kylie McClain
+Leah Neukirchen
+Luca Barbato
+Luka Perkov
+M Farkas-Dyck (Strake)
+Mahesh Bodapati
+Markus Wichmann
+Masanori Ogino
+Michael Clark
+Michael Forney
+Mikhail Kremnyov
+Natanael Copa
+Nicholas J. Kain
+orc
+Pascal Cuoq
+Patrick Oppenlander
+Petr Hosek
+Petr Skocik
+Pierre Carrier
+Reini Urban
+Rich Felker
+Richard Pennington
+Ryan Fairfax
+Samuel Holland
+Segev Finer
+Shiz
+sin
+Solar Designer
+Stefan Kristiansson
+Stefan O'Rear
+Szabolcs Nagy
+Timo Teräs
+Trutz Behn
+Valentin Ochs
+Will Dietz
+William Haddon
+William Pitcock
+
+Portions of this software are derived from third-party works licensed
+under terms compatible with the above MIT license:
+
+The TRE regular expression implementation (src/regex/reg* and
+src/regex/tre*) is Copyright © 2001-2008 Ville Laurikari and licensed
+under a 2-clause BSD license (license text in the source files). The
+included version has been heavily modified by Rich Felker in 2012, in
+the interests of size, simplicity, and namespace cleanliness.
+
+Much of the math library code (src/math/* and src/complex/*) is
+Copyright © 1993,2004 Sun Microsystems or
+Copyright © 2003-2011 David Schultz or
+Copyright © 2003-2009 Steven G. Kargl or
+Copyright © 2003-2009 Bruce D. Evans or
+Copyright © 2008 Stephen L. Moshier or
+Copyright © 2017-2018 Arm Limited
+and labelled as such in comments in the individual source files. All
+have been licensed under extremely permissive terms.
+
+The ARM memcpy code (src/string/arm/memcpy_el.S) is Copyright © 2008
+The Android Open Source Project and is licensed under a two-clause BSD
+license. It was taken from Bionic libc, used on Android.
+
+The implementation of DES for crypt (src/crypt/crypt_des.c) is
+Copyright © 1994 David Burren. It is licensed under a BSD license.
+
+The implementation of blowfish crypt (src/crypt/crypt_blowfish.c) was
+originally written by Solar Designer and placed into the public
+domain. The code also comes with a fallback permissive license for use
+in jurisdictions that may not recognize the public domain.
+
+The smoothsort implementation (src/stdlib/qsort.c) is Copyright © 2011
+Valentin Ochs and is licensed under an MIT-style license.
+
+The x86_64 port was written by Nicholas J. Kain and is licensed under
+the standard MIT terms.
+
+The mips and microblaze ports were originally written by Richard
+Pennington for use in the ellcc project. The original code was adapted
+by Rich Felker for build system and code conventions during upstream
+integration. It is licensed under the standard MIT terms.
+
+The mips64 port was contributed by Imagination Technologies and is
+licensed under the standard MIT terms.
+
+The powerpc port was also originally written by Richard Pennington,
+and later supplemented and integrated by John Spencer. It is licensed
+under the standard MIT terms.
+
+All other files which have no copyright comments are original works
+produced specifically for use as part of this library, written either
+by Rich Felker, the main author of the library, or by one or more
+contibutors listed above. Details on authorship of individual files
+can be found in the git version control history of the project. The
+omission of copyright and license comments in each file is in the
+interest of source tree size.
+
+In addition, permission is hereby granted for all public header files
+(include/* and arch/*/bits/*) and crt files intended to be linked into
+applications (crt/*, ldso/dlstart.c, and arch/*/crt_arch.h) to omit
+the copyright notice and permission notice otherwise required by the
+license, and to use these files without any requirement of
+attribution. These files include substantial contributions from:
+
+Bobby Bingham
+John Spencer
+Nicholas J. Kain
+Rich Felker
+Richard Pennington
+Stefan Kristiansson
+Szabolcs Nagy
+
+all of whom have explicitly granted such permission.
+
+This file previously contained text expressing a belief that most of
+the files covered by the above exception were sufficiently trivial not
+to be subject to copyright, resulting in confusion over whether it
+negated the permissions granted in the license. In the spirit of
+permissive licensing, and of not having licensing issues being an
+obstacle to adoption, that text has been removed.
+----------------------------------------------------------------------
+Software:WPA supplicant 2.9
+
+Copyright notice:
+Copyright (c) 2002-2013, Jouni Malinen
+Copyright (c) 2002-2015, Jouni Malinen
+Copyright (c) 2002-2009, Jouni Malinen
+Copyright (c) 2000-2003 Intel Corporation
+Copyright (c) 2006-2007 Sony Corporation
+Copyright (c) 2008-2009 Atheros Communications
+Copyright (c) 2009, Jouni Malinen
+Copyright 2008 Atheros Communications
+Copyright (c) 2009-2012, Masashi Honma
+Copyright (c) 2007-2009, Jouni Malinen
+Copyright (c) 2007-2016, Jouni Malinen
+Copyright (c) 2008-2016, Jouni Malinen
+Copyright (c) 2008, Jouni Malinen
+Copyright (c) 2008-2012, Jouni Malinen
+Copyright (c) 2009-2013, Jouni Malinen
+Copyright (c) 2014, Jouni Malinen
+Copyright (c) 2009-2010, Jouni Malinen
+Copyright 2008 Atheros Communications.
+Copyright (c) 2006-2007 Sony Corporation. All Rights Reserved.
+Copyright (c) 2010, Atheros Communications, Inc.
+Copyright (c) 2006-2014, Jouni Malinen
+Copyright (c) 2006, Jouni Malinen
+Copyright (c) 2006-2009, Jouni Malinen
+Copyright (c) 2009-2015, Jouni Malinen
+Copyright (c) 2006-2019, Jouni Malinen
+Copyright (c) 2006-2011, Jouni Malinen
+Copyright (c) 2015, Jouni Malinen
+Copyright (c) 2006-2015, Jouni Malinen
+Copyright (c) 2006-2007, Jouni Malinen
+Copyright (c) 2005-2019, Jouni Malinen
+Copyright (c) 2005, Jouni Malinen
+Copyright (c) 2013, Jouni Malinen
+Copyright (c) 2013, Qualcomm Atheros, Inc.
+Copyright (c) 2005-2006, Jouni Malinen
+Copyright (c) 2002-2019, Jouni Malinen
+Copyright (c) 2002-2007, Jouni Malinen
+Copyright (c) 2019, The Linux Foundation
+Copyright (c) 2010, Jouni Malinen
+Copyright (c) 2010-2011, Jouni Malinen
+Copyright (c) 2002-2006, Jouni Malinen
+Copyright (c) 2012, Jouni Malinen
+Copyright (c) 2012-2013, Qualcomm Atheros, Inc.
+Copyright (c) 2012-2014, Qualcomm Atheros, Inc.
+Copyright (c) 2003-2006, Jouni Malinen
+Copyright (c) 2017, Qualcomm Atheros, Inc.
+Copyright (c) 2009-2019, Jouni Malinen
+Copyright (c) 2014-2015, Jouni Malinen
+Copyright (c) 2005-2009, Jouni Malinen
+Copyright (c) 2004-2007, 2012, Jouni Malinen
+Copyright (c) 2004-2006, 2012, Jouni Malinen
+Copyright 2007 Andy Green
+Copyright 2009 Johannes Berg
+Copyright (c) 2003, 2004 David Young. All rights reserved.
+Copyright (c) 2002-2005, Jouni Malinen
+Copyright (c) 2007-2012, Jouni Malinen
+Copyright (c) 2002-2009, 2011-2015, Jouni Malinen
+Copyright (c) 2002-2009, 2012, 2014-2015, Jouni Malinen
+Copyright (c) 2012-2013, Jouni Malinen
+Copyright (c) 2005-2009, 2011-2019, Jouni Malinen
+Copyright (c) 2005-2009, 2011, Jouni Malinen
+Copyright (c) 2004-2016, Jouni Malinen
+Copyright (c) 2004-2016, Roshan Pius
+Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
+(c) The contribution was provided directly to me by some other
+person who certified (a), (b) or (c) and I have not modified
+Copyright (c) 2002-2019, Jouni Malinen and contributors
+Copyright (c) 2013-2014, Qualcomm Atheros, Inc.
+Copyright (c) 2003-2017, Jouni Malinen
+Copyright (c) 2004-2005, Jouni Malinen
+Copyright (c) 2004, Sam Leffler
+Copyright (c) 2004, Video54 Technologies
+Copyright (c) 2005-2007, Jouni Malinen
+Copyright (c) 2009, Atheros Communications
+Copyright (c) 2004, 2Wire, Inc
+Copyright (c) 2003-2005, Jouni Malinen
+Copyright (c) 2016, Sabrina Dubroca and Red Hat, Inc.
+Copyright (c) 2004, Gunter Burchardt
+Copyright (c) 2004-2007, Jouni Malinen
+Copyright (c) 2004-2006, Jouni Malinen
+Copyright (c) 2003-2004, Instant802 Networks, Inc.
+Copyright (c) 2005-2006, Devicescape Software, Inc.
+Copyright (c) 2007, Johannes Berg
+Copyright (c) 2009-2010, Atheros Communications
+Copyright (c) 2002-2014, Jouni Malinen
+Copyright (c) 2002-2017, Jouni Malinen
+Copyright(c) 2015 Intel Deutschland GmbH
+Copyright (c) 2008, Atheros Communications
+Copyright (c) 2013, Mark Kettenis
+Copyright (c) 2008-2012 Jouke Witteveen
+Copyright (c) 2003-2015, Jouni Malinen
+Copyright (c) 2002-2010, Jouni Malinen
+Copyright (c) 2003-2011, Jouni Malinen
+Copyright 2006-2010 Johannes Berg
+Copyright 2008 Michael Wu
+Copyright 2008 Luis Carlos Cobo
+Copyright 2008 Michael Buesch
+Copyright 2008, 2009 Luis R. Rodriguez
+Copyright 2008 Jouni Malinen
+Copyright 2008 Colin McCabe
+Copyright 2015-2017 Intel Deutschland GmbH
+Copyright (C) 2018-2019 Intel Corporation
+Copyright (c) 2010, Atheros Communications
+Copyright (c) 2004-2014, Jouni Malinen
+Copyright (c) 2004-2012, Jouni Malinen
+Copyright (c) 2003-2013, Jouni Malinen
+Copyright (c) 2004-2015, Jouni Malinen
+Copyright (c) 2007-2014, Jouni Malinen
+Copyright (c) 2004-2008, Jouni Malinen
+Copyright (c) 2005-2008, Jouni Malinen
+Copyright (c) 2004-2019, Jouni Malinen
+Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
+Copyright (c) 2013 Qualcomm Atheros, Inc.
+Copyright (c) 2010, Dan Harkins
+Copyright (c) 2004-2008, 2012-2015, Jouni Malinen
+Copyright (c) 2004-2009, 2012, Jouni Malinen
+Copyright (c) 2007, Jouni Malinen
+Copyright (c) 2005-2015, Jouni Malinen
+Copyright (c) 2007-2009, 2012, Jouni Malinen
+Copyright (c) 2003-2007, Jouni Malinen
+Copyright (c) 2010-2012, Jouni Malinen
+Copyright (c) 2003-2012, Jouni Malinen
+Copyright (c) 2013 Cozybit, Inc.
+Copyright (c) 2004-2017, Jouni Malinen
+Copyright (c) 2017, Jouni Malinen
+Copyright (c) 2009, 2012, Jouni Malinen
+Copyright (c) 2003-2009, Jouni Malinen
+Copyright (c) 2006-2007
+Copyright (c) 2004-2009, Jouni Malinen
+Copyright (c) 2014-2017, Jouni Malinen
+Copyright (c) 2003-2016, Jouni Malinen
+Copyright (c) 2011, Jouni Malinen
+Copyright (c) 2015, Pali Roh��r
+Copyright (c) 2015-2017, Jouni Malinen
+Copyright (c) 2003-2018, Jouni Malinen
+Copyright (c) 2004-2013, Jouni Malinen
+Copyright (c) 2014, Qualcomm Atheros, Inc.
+Copyright (c) 2012, Intel Corporation. All rights reserved.
+Copyright 2015 Intel Deutschland GmbH
+Copyright (c) 2003-2008, Jouni Malinen
+Copyright (c) 2018-2019, The Linux Foundation
+Copyright (c) 2003-2019, Jouni Malinen
+Copyright (c) 2011-2014, Qualcomm Atheros, Inc.
+Copyright (c) 2011-2014, Jouni Malinen
+Copyright (c) 2011, Qualcomm Atheros
+Copyright (c) 2009, Atheros Communications, Inc.
+Copyright (c) 2011-2013, Qualcomm Atheros, Inc.
+Copyright (c) 2011-2012, Qualcomm Atheros
+Copyright (c) 2013-2014, cozybit, Inc. All rights reserved.
+Copyright (c) 2010-2014, Jouni Malinen
+Copyright (c) 2003-2019, Jouni Malinen and contributors
+Copyright (c) 2003-2009, Jouni Malinen and contributors
+Copyright (c) 2003-2014, Jouni Malinen
+Copyright (c) 2009-2014, Jouni Malinen
+Copyright (c) 2011, Atheros Communications, Inc.
+Copyright (c) 2011-2012, Qualcomm Atheros, Inc.
+Copyright(c) 2014, Intel Mobile Communication GmbH.
+Copyright(c) 2014, Intel Corporation. All rights reserved.
+Copyright (C) 2010 The Android Open Source Project
+Copyright (c) 2008-2014, Jouni Malinen
+Copyright (c) 2012, Intel Corporation
+Copyright (c) 2008 Bernard Gray
+Copyright (c) 2014-2019, Jouni Malinen
+Copyright (c) 2015, Qualcomm Atheros, Inc.
+Copyright (c) 2004-2018, Jouni Malinen
+Copyright (c) 2014-2017, Qualcomm Atheros, Inc.
+Copyright (c) 2012-2016, Jouni Malinen
+Copyright (c) 2007-2008 Intel Corporation
+Copyright (c) 2016, Jouni Malinen
+Copyright (c) 2018, Mathy Vanhoef
+Copyright (c) 2002-2018, Jouni Malinen
+Copyright (c) 2010-2011, Atheros Communications, Inc.
+Copyright (c) 2002-2009, 2012-2015, Jouni Malinen
+Copyright (c) 2011, Atheros Communications
+Copyright (c) 2018-2019, Toke H?iland-J?rgensen
+Copyright (c) 2006, Devicescape Software, Inc.
+Copyright (c) 2002-2003, Jouni Malinen
+Copyright 2003-2006, Jouni Malinen
+Copyright 2003-2004, Instant802 Networks, Inc.
+Copyright 2005-2006, Devicescape Software, Inc.
+Copyright 2003, Jouni Malinen
+Copyright (c) 2002-2004, Instant802 Networks, Inc.
+Copyright (c) 2013-2017, Qualcomm Atheros, Inc.
+Copyright (c) 2011-2017, Qualcomm Atheros, Inc.
+Copyright (c) 2011-2017, Qualcomm Atheros
+Copyright 2002-2003, Instant802 Networks, Inc.
+Copyright (c) 2008-2011, Jouni Malinen
+Copyright (c) 2016-2017, Qualcomm Atheros, Inc.
+Copyright (c) 2019 John Crispin
+Copyright (c) 2007-2008, Intel Corporation
+Copyright (c) 2002-2012, Jouni Malinen
+Copyright (c) 2016, Qualcomm Atheros, Inc.
+Copyright(c) 2013 - 2016 Intel Mobile Communications GmbH.
+Copyright(c) 2011 - 2016 Intel Corporation. All rights reserved.
+Copyright (c) 2004-2008, 2012, Jouni Malinen
+Copyright (c) 2016-2017, Jouni Malinen
+Copyright (c) 2015 Google, Inc.
+Copyright 2003, Instant802 Networks, Inc.
+Copyright 2005, Devicescape Software, Inc.
+Copyright (c) 2012, Michael Braun
+Copyright (c) 2011-2013, Jouni Malinen
+Copyright (c) 2009, Dan Harkins
+Copyright (c) 2008-2019, Jouni Malinen
+Copyright (c) 2005, Sam Leffler
+Copyright (c) 2004-2009, 2011-2015, Jouni Malinen
+Copyright (c) 2003-2009, 2011-2012, Jouni Malinen
+Copyright (c) 2010-2011, Atheros Communications
+Copyright (c) 2006-2018, Jouni Malinen
+Copyright (c) 2015, Adrian Nowicki
+Copyright (c) 2011, Kel Modderman
+Copyright (c) 2005-2011, Jouni Malinen
+Copyright (c) 2006, Dan Williams and Red Hat, Inc.
+Copyright (c) 2009, Witold Sowa
+Copyright (c) 2009-2010, Witold Sowa
+Copyright (c) 2011-2012, Intel Corporation
+Copyright (c) 2005-2012, Jouni Malinen
+Copyright (c) 2007-2010, Jouni Malinen
+Copyright (c) 2004-2011, Jouni Malinen
+Copyright (c) 2007-2008, Jouni Malinen
+Copyright (c) 2005-2010, 2012, Jouni Malinen
+Copyright (c) 2005-2008, 2012, Jouni Malinen
+
+License: BSD License
+Copyright (c) ,
+All rights reserved.
+
+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 the copyright holder 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.
+----------------------------------------------------------------------
+Software:Das U-Boot 2019.07
+
+Copyright notice:
+Copyright (C) 2015 Sakari Ailus
+Copyright (C) 2018, STMicroelectronics - All Rights Reserved
+Copyright (c) 2017 Intel Corporation
+Copyright (C) Freescale Semiconductor, Inc. 2006-2007
+(C) Copyright 2010
+Copyright (C) 2017, Bin Meng
+Copyright (C) 2015, Intel Corporation
+Copyright (C) 2015-2016 Marvell International Ltd.
+Copyright 2008 Freescale Semiconductor, Inc.
+(C) Copyright 2000
+Copyright 2008-2012 Freescale Semiconductor, Inc.
+Copyright (C) 2016 Google, Inc
+Copyright (C) 2012-2020 ASPEED Technology Inc.
+Copyright 2016 Google, Inc
+(C) Copyright 2002
+(C) Copyright 2003
+(C) Copyright 2004
+(C) Copyright 2016 Linaro
+Copyright (C) 2015-2016 Wills Wang
+(C) Copyright 2013 Siemens Schweiz AG
+(C) Heiko Schocher, DENX Software Engineering, hs@denx.de.
+Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
+Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
+(C) Copyright 2013
+Copyright 2016-2017 Texas Instruments, Inc.
+(C) Copyright 2012
+(C) Copyright 2016-2017
+(C) Copyright 2017 Linaro Ltd.
+(C) Copyright 2008
+Copyright 2011 Linaro Limited
+Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
+(C) Copyright 2018
+Copyright (C) 2017 Álvaro Fernández Rojas
+Copyright (C) 2015, Bin Meng
+Copyright (C) 2014, Bin Meng
+(C) Copyright 2019 Rockchip Electronics Co., Ltd
+(C) Copyright 2009 Magnus Lilja
+(c) 2007 Pengutronix, Sascha Hauer
+Copyright (C) 2010-2011 Freescale Semiconductor, Inc.
+Copyright (C) 2014 Gateworks Corporation
+Copyright (C) 2015-2016 Freescale Semiconductor, Inc.
+Copyright (C) 2016 Grinn
+(C) Copyright 2014
+(C) Copyright 2009 Freescale Semiconductor, Inc.
+Copyright (C) 2018 Armadeus Systems
+(C) Copyright 2007
+(C) Copyright 2000-2003
+Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
+(C) Copyright 2004-2007, 2012 Freescale Semiconductor, Inc.
+(C) Copyright 2019
+(C) Copyright 2000-2004
+Copyright (c) 2015 Google, Inc
+Copyright (C) Freescale Semiconductor, Inc. 2006.
+Copyright (C) 2016 Stefan Roese
+(C) Copyright 2016
+Copyright (C) 2010 Freescale Semiconductor, Inc.
+(C) Copyright 2019 NXP, Inc.
+Copyright (C) 2008,2010 Freescale Semiconductor, Inc.
+Copyright (C) 2007-2008 Freescale Semiconductor, Inc.
+Copyright (C) 2008 Freescale Semiconductor, Inc.
+Copyright (C) 2010 Albert ARIBAUD
+Copyright (C) 2000-2005, DENX Software Engineering
+Copyright (C) Procsys. All rights reserved.
+(C) Copyright 2015 - 2016 Xilinx, Inc.
+Copyright (C) Excito Elektronik i Skåne AB, 2010.
+Copyright (C) 2015, 2019 Stefan Roese
+Copyright (C) 2015 Google, Inc
+Copyright (C) 2011 Freescale Semiconductor, Inc.
+Copyright (C) Excito Elektronik i Skåne AB, All rights reserved.
+(C) Copyright 2007-2008
+Copyright (C) 2013 Ludovic Desroches
+Copyright (C) 2018 Álvaro Fernández Rojas
+Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com
+Copyright 2014 Maxime Ripard
+Copyright (c) 2016 Google, Inc
+Copyright (C) 2011 The Chromium OS Authors. All rights reserved.
+Copyright (c) 2014 Google, Inc
+Copyright (C) 2000 Ronald G. Minnich
+Copyright (C) 2012 Google Inc.
+Copyright (C) 2018 Ãlvaro Fernández Rojas
+(C) Copyright 2014, Cavium Inc.
+(C) Copyright 2014 - 2018 Xilinx, Inc.
+Copyright (C) 2013 The Chromium OS Authors.
+(C) Copyright 2018 Cisco Systems, Inc.
+(C) Copyright 2019 Synamedia
+Copyright 2018 NXP
+Copyright (C) 2017 Marek Behun
+Copyright (C) 2016 Tomas Hlavacek
+Copyright (C) 2012 Altera Corporation
+(c) Copyright 2010-2014 Xilinx, Inc. All rights reserved.
+(C) Copyright 2011
+Copyright (C) 2015 Atmel Corporation
+(C) 2006 Andrew Victor
+Copyright (C) 2007 Atmel Corporation.
+Copyright (C) SAN People
+(C) 2007 Atmel Corporation.
+Copyright (C) 2006 Atmel Corporation.
+(C) 2008 Atmel Corporation.
+Copyright (C) 2008 Atmel Corporation.
+Copyright (C) 2007 Atmel Corporation
+Copyright (C) 2012-2013 Atmel Corporation.
+Copyright (C) 2009 Jean-Christophe PLAGNIOL-VILLARD
+Copyright (C) 2009 Jean-Christophe PLAGNIOL-VILLARD
+Copyright (C) 2007 Andrew Victor
+Copyright (C) 2010
+Copyright (C) 2009 Jens Scharsig (jsatng@scharsoft.de)
+Copyright (C) 2005 Ivan Kokshaysky
+Copyright (C) 2008 Jean-Christophe PLAGNIOL-VILLARD
+Copyright (C) 2018 Microchip Technology Inc.
+Copyright (C) 2013 Atmel Corporation
+Copyright (C) 2015 Atmel Corporation.
+Copyright (c) 2015 Atmel Corporation
+Copyright (C) 2005-2013 Atmel Corporation
+Copyright (C) 2005 HP Labs
+Copyright (C) 2015 Atmel
+Copyright (C) 2017 Microchip Corporation.
+(C) 2012 - 2013 Atmel Corporation.
+Copyright (C) 2012 Atmel Corporation.
+Copyright (C) 2014 Atmel
+Copyright (C) 2016 Marek Vasut
+Copyright (C) 2013 DENX Software Engineering, hs@denx.de
+(C) Copyright 2014 DENX Software Engineering
+Copyright 2012 Freescale Semiconductor, Inc.
+Copyright 2013 Freescale Semiconductor, Inc.
+Copyright 2007-2012 Freescale Semiconductor, Inc.
+Copyright 2014 Freescale Semiconductor, Inc.
+Copyright 2009-2012 Freescale Semiconductor, Inc.
+Copyright 2011-2012 Freescale Semiconductor, Inc.
+Copyright (C) 2015-2016 Socionext Inc.
+Copyright (C) 2012-2015 Panasonic Corporation
+Copyright (C) 2014 Panasonic Corporation
+Copyright (C) 2013-2014 Panasonic Corporation
+Copyright (C) 2015-2017 Socionext Inc.
+Copyright (C) 2016 Socionext Inc.
+Copyright (C) 2016-2018 Socionext Inc.
+Copyright (C) 2011-2015 Panasonic Corporation
+Copyright (C) 2016 Socionext Inc.
+Copyright (C) 2012-2014 Panasonic Corporation
+Copyright (C) 2011-2015 Copyright (C) 2011-2015 Panasonic Corporation
+Copyright (C) 2016-2017 Socionext Inc.
+Copyright (C) 2017 Socionext Inc.
+Copyright (C) 2008-2009 Samsung Electronics
+(C) Copyright 2017
+(C) Copyright 2017, 2018
+Copyright (c) 2018, Heinrich Schuchardt
+Copyright (C) 2006 David Gibson, IBM Corporation.
+Copyright 2012 Kim Phillips, Freescale Semiconductor.
+Copyright (C) 2014 David Gibson
+Copyright (C) 2012 David Gibson, IBM Corporation.
+Copyright (C) 2016 Free Electrons
+Copyright (C) 2016 NextThing Co.
+Copyright (c) 2017 Heinrich Schuchardt
+Copyright (C) 2007
+Copyright (C) 2014 STMicroelectronics All Rights Reserved
+Copyright (c) 2018 Microsemi Corporation
+Copyright (c) 2019 Microsemi Corporation
+Copyright 2019, Heinrich Schuchardt
+Copyright (c) 2017 Heinrich Schuchardt
+Copyright (c) 2018 Heinrich Schuchardt
+Copyright (c) 2018 AKASHI Takahiro, Linaro Limited
+Copyright 2006 - 2016 Unified EFI, Inc.
+Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2019 Heinrich Schuchardt
+Copyright (c) 2018 Heinrich Schuchardt
+Copyright (C) 2018 MediaTek Inc.
+Copyright (c) 2018 Emlid Limited
+Copyright (C) 2018, Bin Meng
+Copyright (C) 2013 Texas Instruments
+Copyright (c) 1999-2002 Vojtech Pavlik
+Copyright (c) 2015 Hans de Goede
+Copyright (C) 2013 Boundary Devices
+Copyright (C) 2013, 2014 Markus Niebel
+Copyright (C) 2012 Freescale Semiconductor, Inc.
+Copyright (C) 2013, 2014 TQ Systems (ported SabreSD to TQMa6x)
+Copyright (C) 2014 - 2015 Markus Niebel
+Copyright (C) 2013, 2014 TQ Systems
+Copyright (C) 2015 Stefan Roese
+Copyright (C) 2013 Suriyan Ramasami
+Copyright (C) 2010 Eric C. Cooper
+(C) Copyright 2009
+Copyright 2011, 2013 Freescale Semiconductor, Inc.
+Copyright (C) 2017
+Copyright 2010-2011 Freescale Semiconductor, Inc.
+Copyright (C) 2013, Texas Instruments, Incorporated - http://www.ti.com/
+Copyright 2017 Bernecker & Rainer Industrieelektronik GmbH
+Copyright 2011 Freescale Semiconductor, Inc.
+Copyright (C) 2015 Amlogic, Inc. All rights reserved.
+Copyright (C) 2016 BayLibre, SAS. All rights reserved.
+(C) 2012 NetModule AG, David Andrey, added KSZ9031
+(C) Copyright 2017 Adaptrum, Inc.
+(C) Copyright 2009 Industrie Dial Face S.p.A.
+(C) Copyright 2001
+Copyright (c) 2016 Microsemi Corporation
+(C) Copyright 2015
+Copyright 2010-2011, 2015 Freescale Semiconductor, Inc.
+Copyright 2016 Karsten Merker
+Copyright (c) 2006 Herbert Valerio Riedel
+Copyright 2010-2014 Freescale Semiconductor, Inc.
+Copyright (C) 2015 - 2016 Xilinx, Inc.
+Copyright (C) 2018 Rosy Song
+Copyright (C) 2017 Linaro
+JFFS2 version 2.2. (NAND) (C) 2001-2006 Red Hat, Inc.
+Copyright (C) 2019 Jagan Teki
+(C) Copyright 2017 Theobroma Systems Design und Consulting GmbH
+Copyright (c) 2010-2013, NVIDIA CORPORATION. All rights reserved.
+Copyright (c) 2010-2014, NVIDIA CORPORATION. All rights reserved.
+Copyright (c) 2013, NVIDIA CORPORATION. All rights reserved.
+Copyright (C) 2008 Maxime Bizon
+Copyright (C) 2009 Florian Fainelli
+Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
+Copyright (C) 2017, STMicroelectronics - All Rights Reserved
+(C) Copyright 2012 Michal Simek
+(C) Copyright 2013 - 2018 Xilinx, Inc.
+Copyright (C) 2018 Xilinx, Inc.
+Copyright 2009-2011 Freescale Semiconductor, Inc.
+Copyright 2016 Freescale Semiconductor, Inc.
+Copyright 2011-2015 Freescale Semiconductor, Inc.
+Copyright 2015 Freescale Semiconductor, Inc.
+(C) Copyright 2004-2011
+Copyright (C) 2014 STMicroelectronics
+Copyright (C) 2017 Rockchip Electronics Co., Ltd
+Copyright (c) 2016 Rockchip Electronics Co., Ltd
+Copyright (c) 2016 Andreas Färber
+(C) Copyright 2017 Rockchip Electronics Co., Ltd
+(C) Copyright 2016 Beniamino Galvani
+Copyright (c) 2012 Michael Walle
+(C) Copyright 2011 Andes Technology Corp
+Copyright (C) 2016 BayLibre, SAS
+Copyright (c) 2011 IDS GmbH, Germany
+Copyright (c) 2017 Rockchip Electronics Co., Ltd
+Copyright (C) 2007 Free Software Foundation, Inc.
+(C) Copyright 2011-2012 Pali Rohár
+(C) Copyright 2008-2009
+Copyright 2010 Nicolas Palix
+Copyright 2010 Julia Lawall
+Copyright 2010 Gilles Muller
+Copyright (C) 2015
+(C) Copyright 2014 Red Hat Inc.
+Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.
+Copyright (C) 2015 K. Merker
+Copyright (c) 2011 The Chromium OS Authors.
+(C) Copyright 2014 Google, Inc
+Copyright (C) 2012 Samsung Electronics
+Copyright (c) 2007
+Copyright 2010-2011 Calxeda, Inc.
+Copyright (C) 2017 NXP Semiconductors
+Copyright (C) 2017 Bin Meng
+(C) Copyright 2014 Samsung Electronics
+Copyright (C) 2017, Tuomas Tynkkynen
+Copyright (C) 2006 Free Software Foundation, Inc.
+Copyright (C) 2015 Google. Inc
+(C) 2003 Arun Dharankar
+Copyright 2014 Broadcom Corporation.
+Copyright (c) 2007,2008
+Copyright 2005-2007 Rodolfo Giometti
+Copyright (c) 2013 The Chromium OS Authors.
+Copyright (C) Thomas Gleixner
+Copyright (C) 2013, Miao Yan
+Copyright (C) 2015-2018, Bin Meng
+Copyright (C) 2014, Simon Glass
+(C) Copyright 2013 Xilinx, Inc.
+Copyright (C) 2018 Synopsys, Inc. All rights reserved.
+(C) Copyright 2016 Rockchip Electronics Co., Ltd
+Copyright (c) 2016-2019 Toradex, Inc.
+Copyright (c) 2016 Toradex, Inc.
+(C) Copyright 2015 Google, Inc
+Copyright (C) 2016-2018 Toradex AG
+Copyright (C) 2015 Freescale Semiconductor, Inc.
+2015 Toradex AG
+Copyright (C) 2011 Samsung Electronics
+Copyright (C) 2017 Marek Vasut
+(C) Copyright 2011 Freescale Semiconductor, Inc.
+Copyright (C) 2018 Dennis Gilmore
+(c) Copyright 2015 Xilinx, Inc. All rights reserved.
+(C) Copyright 2010-2015
+Copyright (c) 2012 The Chromium OS Authors.
+(C) Copyright 2010,2011
+Copyright (c) 2014-2016, NVIDIA CORPORATION.
+Copyright (c) 2019 NVIDIA Corporation. All rights reserved.
+(C) Copyright 2010-2014
+Copyright (c) 2010-2012, NVIDIA CORPORATION. All rights reserved.
+Copyright (c) 2011, Google Inc. All rights reserved.
+Copyright (c) 2016, NVIDIA CORPORATION.
+(C) Copyright 2010-2019
+Copyright 2018 Google LLC
+Copyright 2010-2011 NVIDIA Corporation
+Copyright (c) 2011-2013, NVIDIA CORPORATION. All rights reserved.
+(C) Copyright 2009 SAMSUNG Electronics
+Copyright (C) 2011-2012 NVIDIA Corporation
+Copyright (c) 2013 NVIDIA Corporation
+(C) Copyright 2010, 2011
+Copyright (C) 2019, STMicroelectronics - All Rights Reserved
+Copyright (C) 2007-2009 Industrie Dial Face S.p.A.
+Copyright (C) 1999-2005 Igor Pavlov
+Copyright (C) 2007-2008 Industrie Dial Face S.p.A.
+Copyright (C) 2015 Paul Kocialkowski