!2 feat:增加厂商SDK代码,修改readme描述

Merge pull request !2 from qubo/master
This commit is contained in:
openharmony_sig_ci
2022-03-12 12:10:35 +00:00
committed by Gitee
288 changed files with 77839 additions and 75 deletions
Executable
+23
View File
@@ -0,0 +1,23 @@
# Copyright (C) 2022 HiHope Open Source Organization .
# 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.
if (ohos_kernel_type == "liteos_m") {
import("//kernel/liteos_m/liteos.gni")
module_name = get_path_info(rebase_path("."), "name")
module_group(module_name) {
modules = [
"hals",
"wm800",
]
}
}
+14
View File
@@ -0,0 +1,14 @@
# Copyright (C) 2022 HiHope Open Source Organization .
# 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.
rsource "*/Kconfig.liteos_m.defconfig.series"
+14
View File
@@ -0,0 +1,14 @@
# Copyright (C) 2022 HiHope Open Source Organization .
# 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.
rsource "*/Kconfig.liteos_m.series"
+22
View File
@@ -0,0 +1,22 @@
# Copyright (C) 2022 HiHope Open Source Organization .
# 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.
config SOC_COMPANY_WINNERMICRO
bool
if SOC_COMPANY_WINNERMICRO
config SOC_COMPANY
default "winnermicro"
rsource "*/Kconfig.liteos_m.soc"
endif # SOC_COMPANY_WINNERMICRO
Executable
+176
View File
@@ -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
Executable
+81
View File
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2022 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.
This is the configuration file template for OpenHarmony OSS Audit Tool, please copy it to your project root dir and modify it refer to OpenHarmony/tools_oat/README.
All configurations in this file will be merged to OAT-Default.xml, if you have any questions or concerns, please create issue in OpenHarmony/tools_oat and @jalenchen or chenyaxun.
licensefile:
1.If the project don't have "LICENSE" in root dir, please define all the license files in this project in , OAT will check license files according to this rule.
policylist:
1. policy: If the OAT-Default.xml policies do not meet your requirements, please add policies here.
2. policyitem: The fields type, name, path, desc is required, and the fields rule, group, filefilter is optional,the default value is:
<policyitem type="" name="" path="" desc="" rule="may" group="defaultGroup" filefilter="defaultPolicyFilter"/>
3. policyitem type:
"compatibility" is used to check license compatibility in the specified path;
"license" is used to check source license header in the specified path;
"copyright" is used to check source copyright header in the specified path;
"import" is used to check source dependency in the specified path, such as import ... ,include ...
"filetype" is used to check file type in the specified path, supported file types: archive, binary
"filename" is used to check whether the specified file exists in the specified path(projectroot means the root dir of the project), supported file names: LICENSE, README, README.OpenSource
4. policyitem name: This field is used for define the license, copyright, "*" means match all, the "!" prefix means could not match this value. For example, "!GPL" means can not use GPL license.
5. policyitem path: This field is used for define the source file scope to apply this policyitem, the "!" prefix means exclude the files. For example, "!.*/lib/.*" means files in lib dir will be exclude while process this policyitem.
6. policyitem rule and group: These two fields are used together to merge policy results. "may" policyitems in the same group means any one in this group passed, the result will be passed.
7. policyitem filefilter: Used to bind filefilter which define filter rules.
7. policyitem desc: Used to describe the reason of this policy item, committers will check this while merging the code.
8. filefilter: Filter rules, the type filename is used to filter file name, the type filepath is used to filter file path.
Note:If the text contains special characters, please escape them according to the following rules:
" == &quot;
& == &amp;
' == &apos;
< == &lt;
> == &gt;
-->
<configuration>
<oatconfig>
<licensefile></licensefile>
<policylist>
<policy name="projectPolicy" desc="">
<!--policyitem type="compatibility" name="GPL-2.0+" path=".*" desc="Process that runs independently, invoked by the X process."/-->
<!--policyitem type="license" name="LGPL" path=".*" desc="Dynamically linked by module X"/-->
<policyitem type="copyright" name="Huawei Technologies Co., Ltd." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="Developed by Huawei Technologies"/>
<policyitem type="copyright" name="Huawei Device Co., Ltd." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="Developed by Huawei Device"/>
<policyitem type="copyright" name="HiHope Open Source Organization ." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="Developed By Hihope"/>
</policy>
</policylist>
<filefilterlist>
<filefilter name="defaultFilter" desc="Files not to check">
<filteritem type="filename" name="*.iml|*.json|*.txt" desc="desc files"/>
</filefilter>
<filefilter name="defaultPolicyFilter" desc="Filters for compatibilitylicense header policies">
<filteritem type="filename" name="BUILD.gn" desc="Compilation scripts do not declare license"/>
<!-- <filteritem type="filename" name="fstab" desc="This type configuration file can not declare license"/> -->
</filefilter>
<filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies">
</filefilter>
<filefilter name="licenseFileNamePolicyFilter" desc="Filters for LICENSE file policies">
</filefilter>
<filefilter name="readmeFileNamePolicyFilter" desc="Filters for README file policies">
</filefilter>
<filefilter name="readmeOpenSourcefileNamePolicyFilter" desc="Filters for README.OpenSource file policies">
</filefilter>
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies">
</filefilter>
</filefilterlist>
</oatconfig>
</configuration>
-36
View File
@@ -1,36 +0,0 @@
# device_soc_winnermicro
#### 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**}
#### Software Architecture
Software architecture description
#### Installation
1. xxxx
2. xxxx
3. xxxx
#### Instructions
1. xxxx
2. xxxx
3. xxxx
#### 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/)
-39
View File
@@ -1,39 +0,0 @@
# device_soc_winnermicro
#### 介绍
{**以下是 Gitee 平台说明,您可以替换此简介**
Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
#### 软件架构
软件架构说明
#### 安装教程
1. xxxx
2. xxxx
3. xxxx
#### 使用说明
1. xxxx
2. xxxx
3. xxxx
#### 参与贡献
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/)
+199
View File
@@ -0,0 +1,199 @@
# device_soc_winnermicro
#### 介绍
##### 目录
```
device/soc/
├── wm800 # 芯片SOC名称
├── ... # 芯片SOC名称
|
├── hals # hals适配目录
│ └── console # 连接类接口适配目录
├── Kconfig.liteos_m.defconfig # kconfig 默认宏配置
├── Kconfig.liteos_m.series # W800系列soc配置宏
└── Kconfig.liteos_m.soc # soc kconfig配置宏
```
仓库包含编译构建脚本和打包镜像工具。
系统要求: Ubuntu18.04 64位系统版本。
编译环境搭建包含如下几步:
1. 获取源码
2. 安装的库和工具
3. 安装python3
4. 安装hb
5. 安装csky-abiv2-elf-gcc
6. 编译流程
7. 烧录打印
## 获取源码
```shell
mkdir openharmony_winnermicro
cd openharmony_winnermicro
repo init -u git@gitee.com:openharmony/manifest.git -b OpenHarmony-3.1-Beta --no-repo-verify
repo sync -c
repo forall -c 'git lfs pull'
```
## 安装的库和工具
> - 通常系统默认安装samba、vim等常用软件。
> - 使用如下apt-get命令安装下面的库和工具:
```
sudo apt-get install build-essential gcc g++ make zlib* libffi-dev e2fsprogs pkg-config flex bison perl bc openssl libssl-dev libelf-dev libc6-dev-amd64 binutils binutils-dev libdwarf-dev u-boot-tools mtd-utils gcc-arm-linux-gnueabi
```
## 安装Python3
1. 打开Linux编译服务器终端。
2. 输入如下命令,查看python版本号:
```
python3 --version
```
1. 运行如下命令,查看Ubuntu版本:
```
cat /etc/issue
```
2. ubuntu 18安装python。
```
sudo apt-get install python3.8
```
3. 设置python和python3软链接为python3.8。
```
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
```
4. 安装并升级Python包管理工具(pip3),任选如下一种方式。
- **命令行方式:**
```
sudo apt-get install python3-setuptools python3-pip -y
sudo pip3 install --upgrade pip
```
- **安装包方式:**
```
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
```
## 安装hb
### 安装方法
1. 运行如下命令安装hb
```
pip3 uninstall ohos-build # 如果安装了hb,先卸载
pip3 install build/lite
```
2. 设置环境变量
```
vim ~/.bashrc
```
将以下命令拷贝到.bashrc文件的最后一行,保存并退出。
```
export PATH=~/.local/bin:$PATH
```
执行如下命令更新环境变量。
```
source ~/.bashrc
```
3. 执行"hb -h",有打印以下信息即表示安装成功:
```
usage: hb
OHOS build system
positional arguments:
{build,set,env,clean}
build Build source code
set OHOS build settings
env Show OHOS build env
clean Clean output
optional arguments:
-h, --help show this help message and exit
```
## 安装csky-abiv2-elf-gcc
1. 打开Linux编译服务器终端。
2. 下载[csky-abiv2-elf-gcc 编译工具下载](https://occ.t-head.cn/community/download?id=3885366095506644992)
选择下载 csky-elfabiv2-tools-x86_64-minilibc-20210423.tar。
3. 解压 csky-elfabiv2-tools-x86_64-minilibc-20210423.tar 安装包至\~/toolchain/路径下,并将解压生成的bin目录名修改为csky-elfabiv2-bin。
```shell
cd toolchain
tar zxvf csky-elfabiv2-tools-x86_64-minilibc-20210423.tar
mv bin csky-elfabiv2-bin
```
4. 设置环境变量。
```
vim ~/.bashrc
```
将以下命令拷贝到.bashrc文件的最后一行,保存并退出。
```
export PATH=~/toolchain/csky-elfabiv2-bin:$PATH
```
5. 生效环境变量。
```
source ~/.bashrc
```
## 编译流程
[编译构建使用指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/subsys-build-mini-lite.md)
```shell
hb set
hihope
> neptune100
选择neptune100
hb build -f
```
## 烧录打印
windows下:
1. 下载PC端固件烧录工具并安装(HW Upgrade Tools) [w800串口烧录工具下载参考](https://www.winnermicro.com/html/1/156/158/558.html)。
2. 在代码根目录下执行编译命令hb build -f,编译成功会在out/neptune100/neptune100/bin目录下生成 .fls文件。
3. 通过USB转接线连接PC和w800开发板,在PC的设备管理器中确认与w800连接所用的COM口。
4. 打开烧录工具(Upgrade_Tools),选定COM口并选择打开串口,选择固件为hihope_neptune100.fls文件,勾选擦除Flash(波特率:115200,型号:W80X)。
5. 点击下载键等待烧录。
6. 烧录成功图形界面会显示file success以及烧录成功之后的启动log,反之显示fail。
7. 打开烧录工具(Upgrade_Tools),选择复位,可在图形界面看到板子启动log;或打开串口调试工具,RST按键启动板子,查看log。
# 相关仓
* [device/board/hihope](https://gitee.com/openharmony-sig/device_board_hihope)
* [vendor/hihope](https://gitee.com/openharmony-sig/vendor_hihope)
Executable
+23
View File
@@ -0,0 +1,23 @@
# Copyright (C) 2022 HiHope Open Source Organization .
# 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("//kernel/liteos_m/liteos.gni")
module_name = get_path_info(rebase_path("."), "name")
module_group(module_name) {
modules = [
"console",
"communication/wifi_lite/wifiservice",
"communication/bt_lite/ble",
]
}
+52
View File
@@ -0,0 +1,52 @@
# Copyright (c) 2020, HiHope Community.
#
# 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("//kernel/liteos_m/liteos.gni")
module_switch = defined(LOSCFG_HALS_COMMUCATION_BT_LITE)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [
"source/nble.c",
"source/nble_server.c",
"source/ble_util.c",
]
deps = [ "//foundation/communication/bt_lite:bt" ]
visibility += [ "../../.." ]
include_dirs = [
"//utils/native/lite/include",
"//device/soc/winnermicro/w800/board/include/",
"//foundation/communication/bt_lite/interfaces/ble",
"//device/soc/winnermicro/w800/board/src/bt/blehost/nimble",
"//device/soc/winnermicro/w800/board/src/bt/blehost/nimble/include",
"//device/soc/winnermicro/w800/board/src/bt/blehost/nimble/host/include",
"//device/soc/winnermicro/w800/board/src/bt/blehost/porting/w800/include",
"//device/soc/winnermicro/w800/board/src/bt/blehost/nimble/host/util/include",
]
}
+159
View File
@@ -0,0 +1,159 @@
#include "ble_util.h"
#include "bt_def.h"
#include "wm_bt_def.h"
#include "wm_type_def.h"
#include "stdbool.h"
// typedef enum {
// false,
// true
// } bool;
static unsigned char BASE_UUID[16] =
{
0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static int uuidType(unsigned char *p_uuid)
{
int i = 0;
int match = 0;
int all_zero = 1;
for(i = 0; i != 16; ++i)
{
if(i == 12 || i == 13)
{
continue;
}
if(p_uuid[i] == BASE_UUID[i])
{
++match;
}
if(p_uuid[i] != 0)
{
all_zero = 0;
}
}
if(all_zero)
{
return 0;
}
if(match == 12)
{
return 32;
}
if(match == 14)
{
return 16;
}
return 128;
}
void app_to_btif_uuid(tls_bt_uuid_t *p_dest, BtUuid *p_src)
{
int i = 0;
if(p_src->uuidLen == 16 || p_src->uuidLen == 32)
{
for(i = 0; i != 16; ++i)
{
p_dest->uu[i] = BASE_UUID[i];
}
}
switch(p_src->uuidLen)
{
case 0:
break;
case 16:
p_dest->uu[12] = p_src->uuid[0]& 0xff; //endian???
p_dest->uu[13] = p_src->uuid[1]& 0xff;
break;
case 32:
p_dest->uu[12] = p_src->uuid[0]& 0xff;
p_dest->uu[13] = p_src->uuid[1]& 0xff;
p_dest->uu[14] = p_src->uuid[2]& 0xff;
p_dest->uu[15] = p_src->uuid[3]& 0xff;
break;
case 128:
for(i = 0; i != 16; ++i)
{
p_dest->uu[i] = p_src->uuid[i];
}
break;
default:
BLE_IF_DEBUG("Unknown UUID length %d!", p_src->uuidLen);
break;
}
}
void btif_to_app_uuid(BtUuid *p_dest, tls_bt_uuid_t *p_src)
{
char *p_byte = (char *)p_src;
int i = 0;
p_dest->uuidLen = uuidType(p_src->uu);
switch(p_dest->uuidLen)
{
case 16:
p_dest->uuid[0] = p_src->uu[12];
p_dest->uuid[1] = p_src->uu[13];
break;
case 32:
p_dest->uuid[0] = p_src->uu[12];
p_dest->uuid[1] = p_src->uu[13];
p_dest->uuid[2] = p_src->uu[14];
p_dest->uuid[3] = p_src->uu[15];
break;
case 128:
for(i = 0; i != 16; ++i)
{
p_dest->uuid[i] = p_byte[i];
}
break;
default:
BLE_IF_DEBUG("Unknown UUID length %d!", p_dest->uuidLen);
break;
}
}
static tls_bt_uuid_t app_base_uuid =
{
{
0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0x34, 0x12, 0x00, 0x00
}
};
uint16_t btif_uuid128_to_uuid16(tls_bt_uuid_t *uuid)
{
uint16_t id = 0;
memcpy(&id, uuid->uu+12, 2);
return id;
}
tls_bt_uuid_t * btif_uuid16_to_uuid128(uint16_t uuid16)
{
memcpy(app_base_uuid.uu+12, &uuid16, 2);
return &app_base_uuid;
}
+45
View File
@@ -0,0 +1,45 @@
#ifndef __BLE_UTIL_H__
#define __BLE_UTIL_H__
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
// #include "harmony_bt_def.h"
#include "bt_def.h"
#include "wm_bt_def.h"
#define BLE_IF_DBG 1
#ifndef BLE_IF_DBG
#define BLE_IF_DBG 0
#endif
#if BLE_IF_DBG
#define BLE_IF_DEBUG(fmt, ...) \
do{\
if(1) \
printf("%s(L%d): " fmt, __FUNCTION__, __LINE__, ## __VA_ARGS__); \
}while(0)
#define BLE_IF_PRINTF(fmt, ...) \
do{\
if(1) \
printf(fmt, ## __VA_ARGS__); \
}while(0)
#else
#define BLE_IF_DEBUG(param, ...)
#define BLE_IF_PRINTF(param, ...)
#endif
#ifndef MIN
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#endif
extern void app_to_btif_uuid(tls_bt_uuid_t *p_dest, BtUuid *p_src);
extern void btif_to_app_uuid(BtUuid *p_dest, tls_bt_uuid_t *p_src);
extern uint16_t btif_uuid128_to_uuid16(tls_bt_uuid_t *uuid);
tls_bt_uuid_t * btif_uuid16_to_uuid128(uint16_t uuid16);
#endif
File diff suppressed because it is too large Load Diff
+552
View File
@@ -0,0 +1,552 @@
/*
* Copyright (c) 2020, HiHope Community.
*
* 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 <string.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "wm_ble.h"
#include "wm_bt_def.h"
#include "bt_gatt.h"
#include "wm_mem.h"
#include "list.h"
#include "ble_util.h"
#include "host/ble_hs.h"
#include "host/util/util.h"
// #include "harmony_bt_def.h"
// #include "harmony_bt_gatt.h"
typedef struct{
struct dl_list list;
BleAttribType attr_type;
uint16_t attr_handle;
ble_uuid_any_t uuid;
BleGattOperateFunc func;
struct ble_npl_mutex service_mutex;
} service_elem_t;
typedef struct{
struct dl_list list;
uint16_t server_id;
uint8_t srvc_count;
void *priv_data;
service_elem_t srvc_list;
struct ble_npl_mutex server_mutex;
} server_elem_t;
typedef struct{
struct dl_list list;
struct ble_gatt_svc_def *svc;
} nim_service_t;
static uint16_t g_server_id;
static server_elem_t server_list;
static nim_service_t nim_service_list;
void ble_server_gap_event(struct ble_gap_event *event, void *arg)
{
int rc;
BdAddr bdaddr;
struct ble_gap_conn_desc desc;
server_elem_t *svr_item = NULL;
BtGattServerCallbacks *gatts_struct_func_ptr_cb = (BtGattServerCallbacks *)arg;
switch(event->type)
{
case BLE_GAP_EVENT_CONNECT:
if (event->connect.status == 0)
{
rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
assert(rc == 0);
memcpy(bdaddr.addr, desc.peer_id_addr.val, 6);
if(gatts_struct_func_ptr_cb && gatts_struct_func_ptr_cb->connectServerCb)
{
dl_list_for_each(svr_item, &server_list.list, server_elem_t, list)
gatts_struct_func_ptr_cb->connectServerCb(event->connect.conn_handle, svr_item->server_id,&bdaddr);
}
}
break;
case BLE_GAP_EVENT_DISCONNECT:
memcpy(bdaddr.addr, event->disconnect.conn.peer_id_addr.val, 6);
if(gatts_struct_func_ptr_cb && gatts_struct_func_ptr_cb->disconnectServerCb)
{
dl_list_for_each(svr_item, &server_list.list, server_elem_t, list)
gatts_struct_func_ptr_cb->disconnectServerCb(event->disconnect.conn.conn_handle, svr_item->server_id,&bdaddr);
}
break;
default:
break;
}
}
void ble_server_retrieve_id_by_uuid(ble_uuid_t *uuid, uint16_t *server_id)
{
server_elem_t *svr_item = NULL;
service_elem_t *svc_item = NULL;
dl_list_for_each(svr_item, &server_list.list, server_elem_t, list)
{
svc_item = dl_list_first(&svr_item->srvc_list.list, service_elem_t, list);
if(ble_uuid_cmp(uuid,&svc_item->uuid) == 0)
{
//BLE_IF_DEBUG("got server id:(%d)\r\n", svr_item->server_id);
*server_id = svr_item->server_id;
}
}
}
void ble_server_retrieve_id_by_service_id(uint16_t svc_handle, uint16_t *server_id)
{
server_elem_t *svr_item = NULL;
service_elem_t *svc_item = NULL;
dl_list_for_each(svr_item, &server_list.list, server_elem_t, list)
{
svc_item = dl_list_first(&svr_item->srvc_list.list, service_elem_t, list);
if(svc_item->attr_handle == svc_handle)
{
//BLE_IF_DEBUG("svc_handle=%d, got server id:(%d)\r\n", svc_handle,svr_item->server_id);
*server_id = svr_item->server_id;
}
}
}
void ble_server_retrieve_service_handle_by_server_id(uint16_t server_id, uint16_t *service_handle)
{
server_elem_t *svr_item = NULL;
service_elem_t *svc_item = NULL;
dl_list_for_each(svr_item, &server_list.list, server_elem_t, list)
{
if(svr_item->server_id == server_id)
{
svc_item = dl_list_first(&svr_item->srvc_list.list, service_elem_t, list);
if(svc_item)
{
*service_handle = svc_item->attr_handle;
}
}
}
}
void ble_server_update_svc_handle(ble_uuid_t *uuid, uint16_t attr_handle)
{
server_elem_t *svr_item = NULL;
service_elem_t *svc_item = NULL;
dl_list_for_each(svr_item, &server_list.list, server_elem_t, list)
{
svc_item = dl_list_first(&svr_item->srvc_list.list, service_elem_t, list);
if(ble_uuid_cmp(uuid,&svc_item->uuid) == 0)
{
//BLE_IF_DEBUG("greate update success:(%d-->%d), addr=0x%08x\r\n", svc_item->attr_handle, attr_handle, &svc_item->attr_handle);
svc_item->attr_handle = attr_handle;
}
}
}
#if BLE_IF_DBG
static void
ble_server_gatt_dump_hexstring(const char *info, uint8_t *p, int length)
{
int i = 0, j = 0;
printf("%s\r\n", info);
for(i = 0; i<length; i++)
{
j++;
printf("%02x ", p[i]);
if((j % 16) == 0)
{
printf("\r\n");
}
}
printf("\r\n");
}
#endif
void ble_server_func_by_attr_handle(uint16_t attr_handle ,uint8_t op, uint8_t *data, int *len)
{
server_elem_t *svr_item = NULL;
service_elem_t *svc_item = NULL;
/*match the attr_handle and do the callback*/
dl_list_for_each(svr_item, &server_list.list, server_elem_t, list)
{
dl_list_for_each(svc_item, &svr_item->srvc_list.list, service_elem_t, list)
{
if(svc_item->attr_handle == attr_handle)
{
switch(op)
{
case BLE_GATT_ACCESS_OP_WRITE_CHR:
if(svc_item->func.write)
{
#if BLE_IF_DBG
//ble_server_gatt_dump_hexstring("TO HILINK:", data, *len);
#endif
svc_item->func.write(data, (int)*len);
}
break;
case BLE_GATT_ACCESS_OP_READ_CHR:
if(svc_item->func.read)
{
svc_item->func.read(data, len);
#if BLE_IF_DBG
ble_server_gatt_dump_hexstring("FROM HILINK:", data, *len);
#endif
}
break;
default:
break;
}
}
}
}
}
static uint8_t cache_buffer[512];
static int
ble_server_gatt_svc_access_func(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt, void *arg)
{
int rc = 0;
int length = 0;
int offset = 0;
struct os_mbuf *om = ctxt->om;
BLE_IF_DEBUG("%s, op=%d,attr_handle=%d\r\n", __FUNCTION__, ctxt->op,attr_handle);
switch (ctxt->op) {
case BLE_GATT_ACCESS_OP_WRITE_CHR:
{
while(om) {
length = om->om_len;
memcpy(cache_buffer+offset, om->om_data, length);
offset += length;
assert(offset <= sizeof(cache_buffer));
//ble_server_func_by_attr_handle(attr_handle, ctxt->op, om->om_data, &length);
om = SLIST_NEXT(om, om_next);
}
if(offset>0)ble_server_func_by_attr_handle(attr_handle, ctxt->op, cache_buffer, &offset);
return 0;
}
case BLE_GATT_ACCESS_OP_READ_CHR:
{
ble_server_func_by_attr_handle(attr_handle, ctxt->op, cache_buffer, &length);
if(length>0)
{
rc = os_mbuf_append(ctxt->om, &cache_buffer[0],length);
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
}
return 0;
}
default:
return BLE_ATT_ERR_UNLIKELY;
}
}
int
ble_server_uuid_init_from_buf(ble_uuid_any_t *uuid, const void *buf, size_t len)
{
switch (len) {
case OHOS_UUID_TYPE_16_BIT:
uuid->u.type = BLE_UUID_TYPE_16;
uuid->u16.value = get_le16(buf);
return 0;
case OHOS_UUID_TYPE_32_BIT:
uuid->u.type = BLE_UUID_TYPE_32;
uuid->u32.value = get_le32(buf);
return 0;
case OHOS_UUID_TYPE_128_BIT:
uuid->u.type = BLE_UUID_TYPE_128;
memcpy(uuid->u128.value, buf, 16);
return 0;
}
return BLE_HS_EINVAL;
}
int ble_server_alloc(BleGattService *srvcinfo)
{
int i = 0, rc = 0;
ble_uuid_t uuid;
uint8_t srvc_counter = 0;
uint8_t char_counter = 0;
uint8_t desc_counter = 0;
service_elem_t *srvc_elem = NULL;
service_elem_t *srvc_sub_elem = NULL;
struct ble_gatt_svc_def *gatt_svc_array = NULL;
struct ble_gatt_chr_def *gatt_chr_array = NULL;
struct ble_gatt_dsc_def *gatt_dsc_array = NULL;
assert(srvcinfo != NULL);
server_elem_t *serv_elem = (server_elem_t *)tls_mem_alloc(sizeof(server_elem_t));
assert(serv_elem != NULL);
memset(serv_elem, 0, sizeof(server_elem_t));
/*init the service list attached to the server element*/
dl_list_init(&serv_elem->srvc_list.list);
serv_elem->server_id = g_server_id++;
serv_elem->srvc_count = 0;
//presearch to get the counter of character and descriptor;
for(i = 0; i<srvcinfo->attrNum; i++)
{
if(srvcinfo->attrList[i].attrType == OHOS_BLE_ATTRIB_TYPE_SERVICE)
{
srvc_counter++;
}else if(srvcinfo->attrList[i].attrType == OHOS_BLE_ATTRIB_TYPE_CHAR)
{
char_counter++;
BLE_IF_DEBUG("CHAR PROP=0x%02x, PERM=0x%02x\r\n",srvcinfo->attrList[i].properties, srvcinfo->attrList[i].permission);
}else if(srvcinfo->attrList[i].attrType == OHOS_BLE_ATTRIB_TYPE_CHAR_USER_DESCR)
{
desc_counter++;
BLE_IF_DEBUG("DESC PROP=0x%02x, PERM=0x%02x\r\n",srvcinfo->attrList[i].properties, srvcinfo->attrList[i].permission);
}
}
assert(srvc_counter == 1);
assert(char_counter >= 1);
BLE_IF_DEBUG("Adding service srvc=%d, char=%d, dsc=%d\r\n",srvc_counter,char_counter, desc_counter);
/*alloc service array*/
gatt_svc_array = (struct ble_gatt_svc_def *)tls_mem_alloc(2*sizeof(struct ble_gatt_svc_def));
assert(gatt_svc_array != NULL);
memset(gatt_svc_array, 0, 2*sizeof(struct ble_gatt_svc_def));
/*prealloc charactertistic array*/
gatt_chr_array = (struct ble_gatt_chr_def *)tls_mem_alloc((1+char_counter) * sizeof(struct ble_gatt_chr_def));
assert(gatt_chr_array != NULL);
memset(gatt_chr_array, 0, (1+char_counter) * sizeof(struct ble_gatt_chr_def));
/*preappending to character array*/
gatt_svc_array[0].characteristics = gatt_chr_array;
/*create a service item and appending it to the servcie array*/
nim_service_t *nim_service = (nim_service_t *)tls_mem_alloc(sizeof(nim_service_t));
assert(nim_service != NULL);
memset(nim_service, 0, sizeof(nim_service_t));
nim_service->svc = gatt_svc_array;
dl_list_add_tail(&nim_service_list.list, &nim_service->list);
for(i = 0; i<srvcinfo->attrNum; i++)
{
if(srvcinfo->attrList[i].attrType == OHOS_BLE_ATTRIB_TYPE_SERVICE)
{
srvc_elem = (service_elem_t *)tls_mem_alloc(sizeof(service_elem_t));
assert(srvc_elem != NULL);
srvc_elem->attr_type = srvcinfo->attrList[i].attrType;
ble_server_uuid_init_from_buf(&srvc_elem->uuid,srvcinfo->attrList[i].uuid, srvcinfo->attrList[i].uuidType);
srvc_elem->attr_handle = 0xFFFF;
dl_list_add_tail(&serv_elem->srvc_list.list, &srvc_elem->list);
//first fill with element used for nimble stack;
gatt_svc_array[0].type = BLE_GATT_SVC_TYPE_PRIMARY;
gatt_svc_array[0].uuid= &srvc_elem->uuid;
//BLE_IF_DEBUG("Adding service\r\n");
}else if(srvcinfo->attrList[i].attrType == OHOS_BLE_ATTRIB_TYPE_CHAR)
{
srvc_sub_elem = (service_elem_t *)tls_mem_alloc(sizeof(service_elem_t));
assert(srvc_sub_elem != NULL);
srvc_sub_elem->attr_type = srvcinfo->attrList[i].attrType;
ble_server_uuid_init_from_buf(&srvc_sub_elem->uuid,srvcinfo->attrList[i].uuid, srvcinfo->attrList[i].uuidType);
srvc_sub_elem->func = srvcinfo->attrList[i].func;
dl_list_add_tail(&serv_elem->srvc_list.list, &srvc_sub_elem->list);
/*process stack env*/
gatt_chr_array[serv_elem->srvc_count].uuid = &srvc_sub_elem->uuid;
gatt_chr_array[serv_elem->srvc_count].access_cb = ble_server_gatt_svc_access_func;
//gatt_chr_array[serv_elem->srvc_count].flags = srvcinfo->attrList[i].properties |srvcinfo->attrList[i].permission<<8;
gatt_chr_array[serv_elem->srvc_count].flags = srvcinfo->attrList[i].properties;
gatt_chr_array[serv_elem->srvc_count].min_key_size = 16;
gatt_chr_array[serv_elem->srvc_count].val_handle = &srvc_sub_elem->attr_handle;
gatt_chr_array[serv_elem->srvc_count].arg = (void*)&srvc_elem->attr_handle; //give the service handle as arg, char added callback will handle it;
//BLE_IF_DEBUG("Adding char(%d), arg=0x%08x\r\n",serv_elem->srvc_count,&srvc_elem->attr_handle);
serv_elem->srvc_count++;
}else if(srvcinfo->attrList[i].attrType == OHOS_BLE_ATTRIB_TYPE_CHAR_USER_DESCR)
{
// stack will handle the cccd
serv_elem->srvc_count--; //fill with descriptor attached to this character
srvc_sub_elem = (service_elem_t *)tls_mem_alloc(sizeof(service_elem_t));
assert(srvc_sub_elem != NULL);
srvc_sub_elem->attr_type = srvcinfo->attrList[i].attrType;
ble_server_uuid_init_from_buf(&srvc_sub_elem->uuid,srvcinfo->attrList[i].uuid, srvcinfo->attrList[i].uuidType);
srvc_sub_elem->func = srvcinfo->attrList[i].func;
dl_list_add_tail(&serv_elem->srvc_list.list, &srvc_sub_elem->list);
if(gatt_chr_array[serv_elem->srvc_count].flags & BLE_GATT_CHR_F_NOTIFY || gatt_chr_array[serv_elem->srvc_count].flags & BLE_GATT_CHR_F_INDICATE)
{
//NimBLE stack will auto add the cccd.
}else
{
gatt_dsc_array = (struct ble_gatt_dsc_def *)tls_mem_alloc(2*sizeof(struct ble_gatt_dsc_def));
memset(gatt_dsc_array, 0, 2*sizeof(struct ble_gatt_dsc_def));
gatt_dsc_array[0].uuid = &srvc_sub_elem->uuid;
gatt_dsc_array[0].access_cb = ble_server_gatt_svc_access_func;
gatt_dsc_array[0].att_flags = srvcinfo->attrList[i].properties |srvcinfo->attrList[i].permission<<8;
gatt_dsc_array[0].min_key_size = 16;
gatt_dsc_array[0].arg = (void*)&srvc_elem->attr_handle; //give the service handle as arg, char added callback will handle it;
gatt_chr_array[serv_elem->srvc_count].descriptors = gatt_dsc_array;
}
serv_elem->srvc_count++; //restore it;
//BLE_IF_DEBUG("Adding desc\r\n");
}
}
serv_elem->priv_data = (void*)nim_service;
//appending the server elem to the server list;
dl_list_add_tail(&server_list.list, &serv_elem->list);
return serv_elem->server_id;
}
int ble_server_free(int server_id)
{
int c = 0, d = 0;
nim_service_t *nim_service_item = NULL;
server_elem_t *svr_item = NULL;
server_elem_t *svr_item_next = NULL;
service_elem_t *svc_item = NULL;
service_elem_t *svc_item_next = NULL;
struct ble_gatt_svc_def *svc_array = NULL;
struct ble_gatt_chr_def *chr_array = NULL;
//free list entry for application level
dl_list_for_each_safe(svr_item, svr_item_next, &server_list.list, server_elem_t, list)
{
if(svr_item->server_id == server_id)
{
nim_service_item = (nim_service_t *)svr_item->priv_data; // the svc_array to be freed;
dl_list_for_each_safe(svc_item, svc_item_next, &svr_item->srvc_list.list, service_elem_t, list)
{
dl_list_del(&svc_item->list);
tls_mem_free(svc_item);
}
dl_list_del(&svr_item->list);
tls_mem_free(svr_item);
break;
}
}
//free servcie array used for nimble stack;
if(nim_service_item)
{
svc_array = nim_service_item->svc;
if(svc_array)
{
if(svc_array->characteristics != NULL)
{
for (c = 0; svc_array->characteristics[c].uuid != NULL; c++)
{
chr_array = svc_array->characteristics + c;
if(chr_array->descriptors != NULL)
{
tls_mem_free(chr_array->descriptors);
}
}
tls_mem_free(svc_array->characteristics);
}
tls_mem_free(svc_array);
}
dl_list_del(&nim_service_item->list);
tls_mem_free(nim_service_item);
}
}
void ble_server_start_service()
{
int rc;
nim_service_t *svc_item = NULL;
if(!dl_list_empty(&nim_service_list.list))
{
dl_list_for_each(svc_item, &nim_service_list.list, nim_service_t, list)
{
if(svc_item == NULL)
{
BLE_IF_PRINTF("ERROR, LIST ERROR\r\n");
return;
}
rc = ble_gatts_count_cfg(svc_item->svc);
assert(rc == 0);
rc = ble_gatts_add_svcs(svc_item->svc);
assert(rc == 0);
}
rc = ble_gatts_start();
assert(rc == 0);
}
}
void ble_server_init()
{
memset(&server_list, 0, sizeof(server_elem_t));
dl_list_init(&server_list.list);
dl_list_init(&nim_service_list.list);
}
+24
View File
@@ -0,0 +1,24 @@
#ifndef __NBLE_SERVER_H__
#define __NBLE_SERVER_H__
/*Initialize the list for ble server*/
extern void ble_server_init();
extern void ble_server_start_service();
/*Free servcie*/
extern int ble_server_free(int server_id);
/*Register one service, and return server if*/
extern int ble_server_alloc(BleGattService *srvcinfo);
extern void ble_server_gap_event(struct ble_gap_event *event, void *arg);
/*Internal function*/
extern void ble_server_update_svc_handle(ble_uuid_t *uuid, uint16_t attr_handle);
extern void ble_server_retrieve_id_by_service_id(uint16_t svc_handle, uint16_t *server_id);
extern void ble_server_retrieve_id_by_uuid(ble_uuid_t *uuid, uint16_t *server_id);
extern void ble_server_retrieve_service_handle_by_server_id(uint16_t server_id, uint16_t *service_handle);
#endif
+53
View File
@@ -0,0 +1,53 @@
# Copyright (c) 2020, HiHope Community.
#
# 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("//kernel/liteos_m/liteos.gni")
module_switch = defined(LOSCFG_HALS_COMMUCATION_WIFI_LITE)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [
"source/wifi_device.c",
"source/wifi_hotspot.c",
"source/wifi_device_util.c",
]
deps = [ "//foundation/communication/wifi_lite:wifi" ]
visibility += [ "../../.." ]
include_dirs = [
"//utils/native/lite/include",
"//device/soc/winnermicro/w800/board/include/os",
"//device/soc/winnermicro/w800/board/include/app",
"//device/soc/winnermicro/w800/board/include/net",
"//device/soc/winnermicro/w800/board/include/wifi",
"//device/soc/winnermicro/w800/board/include/driver",
"//device/soc/winnermicro/w800/board/platform",
"//device/soc/winnermicro/w800/board/include/arch/xt804",
"//foundation/communication/wifi_lite/interfaces/wifiservice",
]
}
@@ -0,0 +1,944 @@
/*
* Copyright (c) 2020, HiHope Community.
*
* 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.
*/
/* From w800 sdk */
#include "wm_type_def.h"
#include "wm_wifi.h"
#include "wm_params.h"
#include "wm_mem.h"
#include "wm_efuse.h"
#include "wm_netif.h"
/* Why we doing this?
* Symbol @WIFI_DISCONNECTED conflict with OHOS wifiservice,
* locate in foundation/communication/interfaces/kits/wifi_lite/wifiservice/wifi_linked_info.h
* They have different types. to avoid this confliction, redefine this macro with another name.
*/
#ifdef WIFI_DISCONNECTED
#undef WIFI_DISCONNECTED // avoid conflict with wifi_linked_info.h
#endif
#include "wifi_error_code.h"
#include "wifi_device.h"
#include "wifi_event.h"
#include "wifi_linked_info.h"
#include "securec.h"
#include <stdio.h>
#define BSS_BUFFER_SIZE (2048)
#define TLS_SSID_MAX_LEN (32) /* see wifi/wm_wifi.h ssid definition */
static WifiDeviceConfig gWifiConfigs[WIFI_MAX_CONFIG_SIZE] = {{{0}, {0}, {0}, 0, WIFI_CONFIG_INVALID, 0, 0}};
static int gWifiStaStatus = WIFI_STA_NOT_ACTIVE;
static WifiEvent* gWifiEvents[WIFI_MAX_EVENT_SIZE] = {0};
static u8 gWifiScanDone = FALSE;
static volatile u8 g_connectStatus = 0; // 0x1: NETIF_WIFI_JOIN_SUCCESS, 0x2: NETIF_WIFI_JOIN_FAILED, 0x3: NETIF_WIFI_DISCONNECTED
u8 g_hasConnected = 0;
/* Store Scanned AP count
* TODO: Use lock to protect Scan result.
*/
#define WIFI_CFG_INFO "wifi_cfg_info"
static int gScannedAPCount;
static u8* gScannedBuffer;
//#ifndef DEBUG
#define DEBUG (1)
//#endif
#define debug_wifi(fmt, ...) \
do { \
if (DEBUG) { \
printf(fmt, ##__VA_ARGS__); \
} \
} while(0)
/*
* w800 doesn't support enable/disable wifi sta function
* always return success.
*/
WifiErrorCode EnableWifi(void)
{
if (LockWifiGlobalLock() != WIFI_SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
if (gWifiStaStatus == WIFI_STA_ACTIVE) {
if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
return ERROR_WIFI_BUSY;
}
gWifiStaStatus = WIFI_STA_ACTIVE;
if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
/* FIXME: Should reset gWifiStaStatus here? */
return ERROR_WIFI_UNKNOWN;
}
return WIFI_SUCCESS;
}
WifiErrorCode DisableWifi(void)
{
if (LockWifiGlobalLock() != WIFI_SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
if (gWifiStaStatus == WIFI_STA_NOT_ACTIVE) {
if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
return ERROR_WIFI_NOT_STARTED;
}
gWifiStaStatus = WIFI_STA_NOT_ACTIVE;
if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
return WIFI_SUCCESS;
}
int IsWifiActive(void)
{
int ret;
if (LockWifiGlobalLock() != WIFI_SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
ret = gWifiStaStatus;
if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
return ret;
}
static void DispatchScanStateChangeEvent(const WifiEvent* event, WifiEventState state)
{
int bssCount = 0;
if (event == NULL || event->OnWifiScanStateChanged == NULL) {
return;
}
if (state == WIFI_STATE_NOT_AVALIABLE) {
event->OnWifiScanStateChanged(state, bssCount);
return;
}
if (state == WIFI_STATE_AVALIABLE) {
bssCount = gScannedAPCount;
if (bssCount < 0) {
printf("Get scanned count failed.\n");
bssCount = 0;
}
event->OnWifiScanStateChanged(state, bssCount);
return;
}
}
static void DispatchConnectEvent(int state, WifiLinkedInfo* info)
{
for (int i = 0; i < WIFI_MAX_EVENT_SIZE; ++i) {
if (gWifiEvents[i] != NULL && gWifiEvents[i]->OnWifiConnectionChanged != NULL) {
gWifiEvents[i]->OnWifiConnectionChanged(state, info);
}
}
}
static void DispatchHotspotStateChangedEvent(int state)
{
for (int i = 0; i < WIFI_MAX_EVENT_SIZE; ++i) {
if (gWifiEvents[i] != NULL && gWifiEvents[i]->OnHotspotStateChanged != NULL) {
gWifiEvents[i]->OnHotspotStateChanged(state);
}
}
}
static void DispatchJoinEvent(StationInfo* info)
{
if (!info) return;
for (int i = 0; i < WIFI_MAX_EVENT_SIZE; ++i) {
if (gWifiEvents[i] != NULL && gWifiEvents[i]->OnHotspotStaJoin != NULL) {
gWifiEvents[i]->OnHotspotStaJoin(info);
}
}
}
static void DispatchLeaveEvent(StationInfo* info)
{
if (!info) return;
for (int i = 0; i < WIFI_MAX_EVENT_SIZE; ++i) {
if (gWifiEvents[i] != NULL && gWifiEvents[i]->OnHotspotStaLeave != NULL) {
gWifiEvents[i]->OnHotspotStaLeave(info);
}
}
}
static void WifiScanHandler(void)
{
int ret;
struct tls_scan_bss_t *scanRes = NULL;
if (gScannedBuffer == NULL) {
printf("[wifi_device]: scan buffer is NULL!\n");
#if defined(OHOS_XTS_WITH_W800)
gWifiScanDone = TRUE;
#endif
return;
}
ret = tls_wifi_get_scan_rslt(gScannedBuffer, BSS_BUFFER_SIZE);
if (ret == WM_FAILED) {
printf("[wifi_device]: get scan result failed.\n");
tls_mem_free(gScannedBuffer);
gScannedBuffer = NULL;
#if defined(OHOS_XTS_WITH_W800)
gWifiScanDone = TRUE;
#endif
return;
}
scanRes = (struct tls_scan_bss_t *)gScannedBuffer;
gScannedAPCount = scanRes->count;
LockWifiEventLock();
printf("[wifi_service]: dispatch scan event.\n");
for (int i = 0; i < WIFI_MAX_EVENT_SIZE; ++i) {
if (gWifiEvents[i] != NULL) {
DispatchScanStateChangeEvent(gWifiEvents[i], WIFI_STATE_AVALIABLE);
}
}
UnlockWifiEventLock();
gWifiScanDone = TRUE;
}
WifiErrorCode Scan(void)
{
/* Check wifi station status */
if (LockWifiGlobalLock() != WIFI_SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
if (gWifiStaStatus == 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 (gWifiEvents[i] == NULL) {
continue;
}
DispatchScanStateChangeEvent(gWifiEvents[i], WIFI_STATE_NOT_AVALIABLE);
}
if (UnlockWifiEventLock() != WIFI_SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
if (gScannedBuffer != NULL) {
memset(gScannedBuffer, 0, BSS_BUFFER_SIZE);
} else {
gScannedBuffer = tls_mem_alloc(BSS_BUFFER_SIZE);
if (gScannedBuffer == NULL) {
printf("[wifi_device]: Scan allocate memory failed.\n");
return ERROR_WIFI_UNKNOWN;
}
}
tls_wifi_scan_result_cb_register(WifiScanHandler);
if (tls_wifi_scan() != WM_SUCCESS) {
printf("[wifi_service]:Scan failed to start sta scan.\n");
tls_wifi_scan_result_cb_register(NULL);
return ERROR_WIFI_UNKNOWN;
}
while(gWifiScanDone == FALSE) {
osDelay(50); /* 500 ms */
}
gWifiScanDone = FALSE; /* Reset scan flag */
return WIFI_SUCCESS;
}
static void WifiEventCallback(u8 status)
{
switch(status) {
case NETIF_WIFI_JOIN_SUCCESS:
debug_wifi("WifiEventCallback status = WIFI_JOIN_SUCCESS\n");
WifiLinkedInfo info = {0};
WifiErrorCode err = GetLinkedInfo(&info);
if (err != WIFI_SUCCESS) {
DispatchConnectEvent(WIFI_STATE_NOT_AVALIABLE, NULL);
} else {
DispatchConnectEvent(WIFI_STATE_AVALIABLE, &info);
}
break;
case NETIF_WIFI_JOIN_FAILED:
debug_wifi("WifiEventCallback status = WIFI_JOIN_FAILED\n");
DispatchConnectEvent(WIFI_STATE_NOT_AVALIABLE, NULL);
break;
case NETIF_WIFI_DISCONNECTED:
debug_wifi("WifiEventCallback status = WIFI_DISCONNECTED\n");
DispatchConnectEvent(WIFI_STATE_NOT_AVALIABLE, NULL);
break;
case NETIF_IP_NET_UP:
debug_wifi("WifiEventCallback status = NETIF_IP_NET_UP\n");
break;
case NETIF_WIFI_SOFTAP_SUCCESS: /* ap */
debug_wifi("WifiEventCallback status = WIFI_SOFTAP_SUCCESS\n");
DispatchHotspotStateChangedEvent(WIFI_HOTSPOT_ACTIVE);
break;
case NETIF_WIFI_SOFTAP_FAILED:
debug_wifi("WifiEventCallback status = WIFI_SOFTAP_FAILED\n");
DispatchHotspotStateChangedEvent(WIFI_HOTSPOT_NOT_ACTIVE);
break;
case NETIF_WIFI_SOFTAP_CLOSED:
debug_wifi("WifiEventCallback status = WIFI_SOFTAP_CLOSED\n");
DispatchHotspotStateChangedEvent(WIFI_HOTSPOT_NOT_ACTIVE);
break;
case NETIF_IP_NET2_UP:
debug_wifi("WifiEventCallback status = NETIF_IP_NET2_UP\n");
break;
case NETIF_IPV6_NET_UP:
debug_wifi("WifiEventCallback status = NETIF_IPV6_NET_UP\n");
break;
default:
debug_wifi("WifiEventCallback invalid status: %d\n", status);
break;
}
}
static void WifiHotspotEventCallback(u8 *mac, enum tls_wifi_client_event_type event)
{
StationInfo info = {0};
memcpy(info.macAddress, mac, sizeof(info.macAddress));
switch (event) {
case WM_WIFI_CLIENT_EVENT_ONLINE:
debug_wifi("WifiHotspotEventCallback event = ONLINE\n");
DispatchJoinEvent(&info);
break;
case WM_WIFI_CLIENT_EVENT_OFFLINE:
debug_wifi("WifiHotspotEventCallback event = OFFLINE\n");
DispatchLeaveEvent(&info);
break;
}
}
WifiErrorCode RegisterWifiEvent(WifiEvent* event)
{
int i;
if (event == NULL) {
return ERROR_WIFI_INVALID_ARGS;
}
if (LockWifiEventLock() != WIFI_SUCCESS) {
printf("[wifi_device]: RegisterWifiEvent lock wifi event lock failed.\n");
return ERROR_WIFI_UNKNOWN;
}
for (i = 0; i < WIFI_MAX_EVENT_SIZE; ++i) {
if (gWifiEvents[i] == event) {
printf("[wifi_device]: event already registered.\n");
if (UnlockWifiEventLock() != WIFI_SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
return ERROR_WIFI_INVALID_ARGS;
}
if (gWifiEvents[i] == NULL) {
gWifiEvents[i] = event;
break;
}
}
if (UnlockWifiEventLock() != WIFI_SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
err_t err = tls_netif_add_status_event(WifiEventCallback);
if (err != 0) {
printf("[wifi_device]: tls_netif_add_status_event failed.\n");
return ERROR_WIFI_UNKNOWN;
}
tls_wifi_softap_client_event_register(WifiHotspotEventCallback);
return WIFI_SUCCESS;
}
WifiErrorCode UnRegisterWifiEvent(const WifiEvent* event)
{
int i;
if (event == NULL) {
printf("[wifi_device]: UnRegisterWifiEvent event is null.\n");
return ERROR_WIFI_INVALID_ARGS;
}
if (LockWifiEventLock() != WIFI_SUCCESS) {
printf("[wifi_device]: UnRegisterWifiEvent lock wifi event lock failed.\n");
return ERROR_WIFI_UNKNOWN;
}
for (i = 0; i < WIFI_MAX_EVENT_SIZE; ++i) {
if (gWifiEvents[i] == event) {
gWifiEvents[i] = NULL;
UnlockWifiEventLock();
return WIFI_SUCCESS;
}
}
UnlockWifiEventLock();
err_t err = tls_netif_remove_status_event(WifiEventCallback);
if (err != 0) {
printf("[wifi_device]: tls_netif_add_status_event failed.\n");
return ERROR_WIFI_UNKNOWN;
}
printf("UnRegisterWifiEvent wifi event is not registered\n");
return ERROR_WIFI_UNKNOWN;
}
WifiErrorCode AdvanceScan(WifiScanParams *params)
{
if (params == NULL) {
return ERROR_WIFI_UNKNOWN;
}
if (params->scanType == WIFI_FREQ_SCAN && params->freqs == 0) {
return ERROR_WIFI_UNKNOWN;
}
if (params->scanType == WIFI_SSID_SCAN && (params->ssidLen == 0 || strlen(params->ssid) == 0)) {
printf("[wifi_service] WIFI_SSID_SCAN, but ssid empty!\n");
return ERROR_WIFI_UNKNOWN;
}
char emptyBssid[WIFI_MAC_LEN] = {0};
if (params->scanType == WIFI_BSSID_SCAN && memcmp(params->bssid, emptyBssid, sizeof(emptyBssid)) == 0) {
printf("[wifi_service] WIFI_BSSID_SCAN, but bssid empty!\n");
return ERROR_WIFI_UNKNOWN;
}
if (params->scanType == WIFI_BAND_SCAN && params->band == 0) {
/// FIXME: test case code logic error, but we follow it, need update when test code update.
printf("[wifi_service] WIFI_BAND_SCAN, but band = %d invalid!\n", params->band);
}
if (params->scanType < 0 || params->scanType > WIFI_BAND_SCAN) {
printf("[wifi_service] scanType invalid!\n");
return WIFI_SUCCESS; // TODO: test case code logic error, but we follow it, need update when test code update.
}
if (LockWifiGlobalLock() != WIFI_SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
if (gWifiStaStatus == 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 (gWifiEvents[i] == NULL) {
continue;
}
DispatchScanStateChangeEvent(gWifiEvents[i], WIFI_STATE_NOT_AVALIABLE);
}
if (UnlockWifiEventLock() != WIFI_SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
// TODO(xu): filter scan result by params
return Scan();
}
WifiErrorCode GetScanInfoList(WifiScanInfo* result, unsigned int* size)
{
int ret;
struct tls_scan_bss_t *scanRes = NULL;
struct tls_bss_info_t *bssInfo;
u32 scanCount, i;
if (result == NULL || size == NULL || *size == 0) {
return ERROR_WIFI_INVALID_ARGS;
}
/*
* scan result already stored in gScannedBuffer
* from scan callbcak.
*/
if (gScannedBuffer == NULL) {
printf("[wifi_device]: no cached scan result.\n");
*size = 0;
return WIFI_SUCCESS;
}
scanRes = (struct tls_scan_bss_t *)gScannedBuffer;
bssInfo = scanRes->bss;
scanCount = scanRes->count;
if (scanCount > *size) {
printf("[wifi_device]: scan count overflow.\n");
return ERROR_WIFI_INVALID_ARGS;
}
if (scanCount > WIFI_SCAN_HOTSPOT_LIMIT) {
printf("[wifi_device]: too many scan results.\n");
printf("[wifi_device]: limit to %d\n", WIFI_SCAN_HOTSPOT_LIMIT);
scanCount = WIFI_SCAN_HOTSPOT_LIMIT;
}
int cpyErr;
for (i = 0; i < scanCount; ++i) {
cpyErr = memcpy_s(result[i].ssid, WIFI_MAX_SSID_LEN, bssInfo->ssid, bssInfo->ssid_len);
if (cpyErr != EOK) {
printf("[wifi_device]: copy ssid of scan result failed\n");
return ERROR_WIFI_UNKNOWN;
}
cpyErr = memcpy_s(result[i].bssid, WIFI_MAC_LEN, bssInfo->bssid, ETH_ALEN);
if (cpyErr != EOK) {
printf("[wifi_device]: copy bssid from scan result failed\n");
return ERROR_WIFI_UNKNOWN;
}
/* FIXME: should do some conversion.
* make sure w800 security type compat to OHOS security type.
* Fix this later.
*/
result[i].securityType = WmAuth2HoSec(bssInfo->privacy);
result[i].rssi = (char)bssInfo->rssi;
/* FIXME: @frequency with unit MHZ.
* @max_data_rate with unit Mbps.
* Should do unit conversion. Fix this later.
*/
result[i].frequency = bssInfo->max_data_rate;
bssInfo++;
}
/*
* Free gScannedBuffer here.
* Since We've already copied scan result to user.
* This is not useful anymore. free the memory
* The @Scan triggered again will re-allocate the memory.
*/
tls_mem_free(gScannedBuffer);
gScannedBuffer = NULL;
*size = scanCount;
return WIFI_SUCCESS;
}
WifiErrorCode GetDeviceMacAddress(unsigned char* result)
{
if (result == NULL) {
return ERROR_WIFI_INVALID_ARGS;
}
if (tls_get_mac_addr((u8 *)result) != TLS_EFUSE_STATUS_OK) {
printf("GetDeviceMacAddress get mac address failed");
return ERROR_WIFI_UNKNOWN;
}
return WIFI_SUCCESS;
}
WifiErrorCode AddDeviceConfig(const WifiDeviceConfig* config, int* result)
{
int netId = WIFI_CONFIG_INVALID;
int i;
if (config == NULL || result == NULL) {
printf("[wifi_device]:add device config invalid argument.\n");
return ERROR_WIFI_INVALID_ARGS;
}
if (LockWifiGlobalLock() != WIFI_SUCCESS) {
printf("[wifi_device]:Lock wifi global lock failed.\n");
return ERROR_WIFI_UNKNOWN;
}
int ret = WM_KvWrite(WIFI_CFG_INFO, config, sizeof(WifiDeviceConfig));
if (ret < 0 ) {
printf("\r\n save wifi cfg info fail\r\n");
} else {
printf("\r\n save wifi cfg info ok\r\n");
}
for (i = 0; i < WIFI_MAX_CONFIG_SIZE; ++i) {
if (gWifiConfigs[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) {
printf("[wifi_device] Unlock wifi global lock failed.\n");
return ERROR_WIFI_UNKNOWN;
}
return ERROR_WIFI_BUSY;
}
int cpyErr = memcpy_s(&gWifiConfigs[netId], sizeof(WifiDeviceConfig), config, sizeof(WifiDeviceConfig));
if (cpyErr != EOK) {
printf("[wifi_service]:AddDeviceConfig memcpy failed, err = %d\n", cpyErr);
if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
printf("[wifi_device] Unlock wifi global lock failed.\n");
}
return ERROR_WIFI_UNKNOWN;
}
gWifiConfigs[netId].netId = netId;
if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
printf("[wifi_device] Unlock wifi global lock failed after copy config.\n");
return ERROR_WIFI_UNKNOWN;
}
*result = netId;
return WIFI_SUCCESS;
}
WifiErrorCode GetDeviceConfigs(WifiDeviceConfig* result, unsigned int* size)
{
unsigned int retIndex = 0;
int i = 0;
int cpyErr;
if (result == NULL || size == NULL || *size == 0) {
return ERROR_WIFI_INVALID_ARGS;
}
//printf("\r\nGetDeviceConfigs, *size=%d, caller addr=%p\n", *size, __builtin_return_address(0));
if (LockWifiGlobalLock() != WIFI_SUCCESS) {
printf("[wifi_device]: Unlock wifi global lock failed in get device config.\n");
return ERROR_WIFI_UNKNOWN;
}
int ret = WM_KvRead(WIFI_CFG_INFO, &gWifiConfigs[0], sizeof(WifiDeviceConfig));
if (ret <= 0 ) {
printf("\r\n read wifi cfg info fail");
if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
printf("[wifi_device] Unlock wifi global lock failed in get device config.\n");
}
return ERROR_WIFI_NOT_AVAILABLE;
} else {
//printf("\r\n read wifi cfg info ok");
}
for (i = 0; i < WIFI_MAX_CONFIG_SIZE; ++i) {
if (gWifiConfigs[i].netId != i) {
continue;
}
cpyErr = memcpy_s(&result[retIndex], sizeof(WifiDeviceConfig), &gWifiConfigs[i], sizeof(WifiDeviceConfig));
if (cpyErr != EOK) {
printf("[wifi_service]: GetDeviceConfig memcpy failed, err = %d\n", cpyErr);
if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
printf("[wifi_device] Unlock wifi global lock failed in get device config.\n");
}
return ERROR_WIFI_UNKNOWN;
}
retIndex++;
if (*size < retIndex) {
printf("[wifi_service: wifi device config overflow.\n");
return UnlockWifiGlobalLock() != WIFI_SUCCESS ? ERROR_WIFI_UNKNOWN : ERROR_WIFI_INVALID_ARGS;
}
}
if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
printf("[wifi_service: sem unlock failed.\n");
return ERROR_WIFI_UNKNOWN;
}
if (retIndex == 0) {
printf("[wifi_service: ERROR_WIFI_NOT_AVAILABLE.\n");
return ERROR_WIFI_NOT_AVAILABLE;
}
*size = retIndex;
return WIFI_SUCCESS;
}
WifiErrorCode Disconnect(void)
{
printf("\r\nDisconnect: g_connectStatus=%d", g_connectStatus);
if (g_connectStatus != NETIF_WIFI_JOIN_SUCCESS) {
#if defined(OHOS_XTS_WITH_W800)
return ERROR_WIFI_UNKNOWN;
#endif
}
tls_wifi_disconnect();
g_connectStatus = NETIF_WIFI_DISCONNECTED;
return WIFI_SUCCESS;
}
WifiErrorCode RemoveDevice(int networkId)
{
if (networkId >= WIFI_MAX_CONFIG_SIZE || networkId < 0) {
printf("[wifi_service]:removeDevice invalid param: networkId=%d\n", networkId);
return ERROR_WIFI_INVALID_ARGS;
}
if (LockWifiGlobalLock() != WIFI_SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
if (memset_s(&gWifiConfigs[networkId], sizeof(WifiDeviceConfig),
0, sizeof(WifiDeviceConfig)) != EOK) {
printf("[wifi_service]:removeDevice memset failed\n");
}
gWifiConfigs[networkId].netId = WIFI_CONFIG_INVALID;
gWifiStaStatus = WIFI_STA_NOT_ACTIVE;
g_connectStatus = 0;
g_hasConnected = 0;
#if 1
int ret = WM_KvDelete(WIFI_CFG_INFO);
if (ret < 0 ) {
printf("\r\n clear wifi cfg info fail");
} else {
printf("\r\n clear wifi cfg info ok");
}
#else
extern void HalFlashFileDeInit(void);
HalFlashFileDeInit();
#endif
if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
return WIFI_SUCCESS;
}
WifiErrorCode GetLinkedInfo(WifiLinkedInfo* result)
{
struct tls_curr_bss_t *bss;
int cpyErr;
WifiErrorCode retCode = WIFI_SUCCESS;
if (result == NULL) {
return ERROR_WIFI_INVALID_ARGS;
}
enum tls_wifi_states wifi_states; /* wifi states */
wifi_states = tls_wifi_get_state();
bss = tls_mem_alloc(sizeof(struct tls_curr_bss_t));
if (!bss) {
printf("[wifi_device]: GetLinkedInfo allocate memory failed.\n");
return ERROR_WIFI_UNKNOWN;
}
(void)memset_s(bss, sizeof(struct tls_curr_bss_t), 0x00, sizeof(struct tls_curr_bss_t));
tls_wifi_get_current_bss(bss);
cpyErr = memcpy_s(result->ssid, WIFI_MAX_SSID_LEN, bss->ssid, TLS_SSID_MAX_LEN + 1);
if (cpyErr != EOK) {
printf("[wifi_device]: GetLinkedInfo copy ssid failed. err = %d.\n", cpyErr);
tls_mem_free(bss);
return ERROR_WIFI_UNKNOWN;
}
cpyErr = memcpy_s(result->bssid, WIFI_MAC_LEN, bss->bssid, ETH_ALEN);
if (cpyErr != EOK) {
printf("[wifi_device]: GetLinkedInfo copy bssid failed. err = %d.\n", cpyErr);
tls_mem_free(bss);
return ERROR_WIFI_UNKNOWN;
}
struct tls_ethif *netif = tls_netif_get_ethif();
cpyErr = memcpy_s(&result->ipAddress, sizeof(ip_addr_t), &netif->ip_addr, sizeof(ip_addr_t));
if (cpyErr != EOK) {
printf("[wifi_device]: GetLinkedInfo copy ipaddr failed. err = %d.\n", cpyErr);
tls_mem_free(bss);
return ERROR_WIFI_UNKNOWN;
}
switch(wifi_states) {
case WM_WIFI_DISCONNECTED:
result->connState = WIFI_DISCONNECTED;
break;
case WM_WIFI_JOINED:
result->connState = WIFI_CONNECTED;
result->rssi = (signed char)(0 - bss->rssi);
break;
case WM_WIFI_SCANNING: /* fall through */
case WM_WIFI_JOINING:
printf("[wifi_device]: connecting is in progroess.\n");
retCode = ERROR_WIFI_BUSY; /* Mark Wi-Fi is busy. Is it reasonable? */
break;
default:
printf("[wifi_device]: GetLinkedInfo, unknown wifi states.\n");
retCode = ERROR_WIFI_INVALID_ARGS;
break;
}
tls_mem_free(bss);
return retCode;
}
static void InitWifiConfig(void)
{
u8 wireless_protocol = 0;
struct tls_param_ip *ip_param = NULL;
debug_wifi("InitWifiConfig, disconnect wifi...\n");
tls_wifi_disconnect();
tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void *) &wireless_protocol, TRUE);
if (TLS_PARAM_IEEE80211_INFRA != wireless_protocol) {
debug_wifi("InitWifiConfig, destroy softap...\n");
tls_wifi_softap_destroy();
osDelay(10);
wireless_protocol = TLS_PARAM_IEEE80211_INFRA;
tls_param_set(TLS_PARAM_ID_WPROTOCOL, (void *) &wireless_protocol, TRUE);//FALSE
}
tls_wifi_set_oneshot_flag(0);
ip_param = tls_mem_alloc(sizeof(struct tls_param_ip));
if (ip_param != NULL) {
tls_param_get(TLS_PARAM_ID_IP, ip_param, FALSE);
ip_param->dhcp_enable = TRUE;
tls_param_set(TLS_PARAM_ID_IP, ip_param, FALSE);
tls_mem_free(ip_param);
} else {
debug_wifi("InitWifiConfig, alloc memory failed.\n");
}
}
static void WifiStatusHandler(u8 status)
{
printf("\r\n WifiStatusHandler status=%d", status);
g_connectStatus = status;
}
WifiErrorCode ConnectTo(int networkId)
{
if (networkId >= WIFI_MAX_CONFIG_SIZE || networkId < 0) {
return ERROR_WIFI_INVALID_ARGS;
}
InitWifiConfig();
if (LockWifiGlobalLock() != WIFI_SUCCESS) {
printf("[wifi_device]: ConnectTo lock wifi global lock failed.\n");
return ERROR_WIFI_UNKNOWN;
}
if (gWifiConfigs[networkId].netId != networkId) {
printf("[wifi_device]: Connectto network id %d is not valid.\n", networkId);
if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
printf("[wifi_device]: ConnectTo unlock wifi global lock failed.\n");
return ERROR_WIFI_UNKNOWN;
}
return ERROR_WIFI_NOT_AVAILABLE;
}
if (gWifiConfigs[networkId].preSharedKey[0] == '\0') {
debug_wifi("[wifi_device]: Connectto PSK is empty, auth mode is OPEN.\n");
}
printf("wifi device connect to SSID:%s, KEY:%s\r\n",gWifiConfigs[networkId].ssid, gWifiConfigs[networkId].preSharedKey);
if (gWifiConfigs[networkId].wapiPskType == WIFI_PSK_TYPE_HEX) {
debug_wifi("[wifi_device]: psk type is HEX type.\n");
}
WifiDeviceConfig connConfig = gWifiConfigs[networkId];
if (tls_wifi_connect((u8*)connConfig.ssid, strlen(connConfig.ssid),
(u8*)connConfig.preSharedKey, strlen(connConfig.preSharedKey)) != WM_SUCCESS) {
#if TLS_CONFIG_DEBUG
printf("[wifi_device]: connect to %s failed.\n", connConfig.ssid);
#endif
UnlockWifiGlobalLock();
return ERROR_WIFI_UNKNOWN;
}
if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
g_connectStatus = 0;
err_t err = tls_netif_add_status_event(WifiStatusHandler);
if (err != 0) {
printf("[wifi_device]: tls_netif_add_status_event for ConnectTo failed.\n");
return ERROR_WIFI_UNKNOWN;
}
while (g_connectStatus == 0) {
osDelay(10);
}
#if TLS_CONFIG_DEBUG
debug_wifi("Connect to %s done, status = %d!\n", connConfig.ssid, g_connectStatus);
#endif
if (g_connectStatus == NETIF_WIFI_JOIN_SUCCESS) {
g_hasConnected = 1;
return WIFI_SUCCESS;
}
err = tls_netif_remove_status_event(WifiStatusHandler);
if (err != 0) {
printf("[wifi_device]: tls_netif_remove_status_event for ConnectTo failed.\n");
return ERROR_WIFI_UNKNOWN;
}
printf("[wifi_device]: ConnectTo failed due to unknown reason.\n");
return ERROR_WIFI_UNKNOWN;
}
@@ -0,0 +1,189 @@
/*
* Copyright (c) 2020, HiHope Community.
*
* 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 "wifi_device_util.h"
#include <stdio.h>
#include "cmsis_os2.h"
#include "ohos_init.h"
#include "wifi_hotspot_config.h"
#include "wm_type_def.h"
#include "wm_wifi.h"
#define WIFI_MUTEX_TIMEOUT osWaitForever
static osMutexId_t g_wifiGlobalLock = NULL;
static osMutexId_t g_wifiEventLock = NULL;
static void InitWifiGlobalLock(void)
{
if (g_wifiGlobalLock == NULL) {
osMutexAttr_t globalMutexAttr = {
"WifiGloablLock",
osMutexRecursive | osMutexPrioInherit,
NULL,
0U
};
g_wifiGlobalLock = osMutexNew(&globalMutexAttr);
}
}
static void InitWifiEventLock(void)
{
if (g_wifiEventLock == NULL) {
osMutexAttr_t eventMutexAttr = {
"WifiEventLock",
osMutexRecursive | osMutexPrioInherit,
NULL,
0U
};
g_wifiEventLock = osMutexNew(&eventMutexAttr);
}
}
WifiErrorCode LockWifiGlobalLock(void)
{
if (g_wifiGlobalLock == NULL) {
InitWifiGlobalLock();
}
osStatus_t ret = osMutexAcquire(g_wifiGlobalLock, WIFI_MUTEX_TIMEOUT);
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) {
InitWifiEventLock();
}
osStatus_t ret = osMutexAcquire(g_wifiEventLock, WIFI_MUTEX_TIMEOUT);
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;
}
WifiSecurityType WmSec2HoSec(int mode)
{
switch (mode) {
case IEEE80211_ENCRYT_NONE:
return WIFI_SEC_TYPE_OPEN;
case IEEE80211_ENCRYT_WEP40:
case IEEE80211_ENCRYT_WEP104:
return WIFI_SEC_TYPE_WEP;
case IEEE80211_ENCRYT_TKIP_WPA:
case IEEE80211_ENCRYT_CCMP_WPA:
case IEEE80211_ENCRYT_TKIP_WPA2:
case IEEE80211_ENCRYT_CCMP_WPA2:
case IEEE80211_ENCRYT_AUTO_WPA:
case IEEE80211_ENCRYT_AUTO_WPA2:
return WIFI_SEC_TYPE_PSK;
// case /* */:
// return WIFI_SEC_TYPE_SAE;
default:
return -1;
}
}
WifiSecurityType WmAuth2HoSec(int mode)
{
switch (mode) {
case WM_WIFI_AUTH_MODE_OPEN:
return WIFI_SEC_TYPE_OPEN;
case WM_WIFI_AUTH_MODE_WEP_AUTO:
return WIFI_SEC_TYPE_WEP;
case WM_WIFI_AUTH_MODE_WPA_PSK_TKIP:
case WM_WIFI_AUTH_MODE_WPA_PSK_CCMP:
case WM_WIFI_AUTH_MODE_WPA_PSK_AUTO:
case WM_WIFI_AUTH_MODE_WPA2_PSK_TKIP:
case WM_WIFI_AUTH_MODE_WPA2_PSK_CCMP:
case WM_WIFI_AUTH_MODE_WPA2_PSK_AUTO:
case WM_WIFI_AUTH_MODE_WPA_WPA2_PSK_TKIP:
case WM_WIFI_AUTH_MODE_WPA_WPA2_PSK_CCMP:
case WM_WIFI_AUTH_MODE_WPA_WPA2_PSK_AUTO:
return WIFI_SEC_TYPE_PSK;
case WM_WIFI_AUTH_MODE_UNKNOWN:
return -1;
}
return -1;
}
int HoSec2WmSec(WifiSecurityType type)
{
switch (type) {
case WIFI_SEC_TYPE_OPEN:
return IEEE80211_ENCRYT_NONE;
case WIFI_SEC_TYPE_WEP:
return IEEE80211_ENCRYT_WEP40;
case WIFI_SEC_TYPE_PSK:
return IEEE80211_ENCRYT_CCMP_WPA2;
// case WIFI_SEC_TYPE_SAE:
// return IEEE80211_ENCRYT_AUTO_WPA2;
default:
return -1;
}
}
@@ -0,0 +1,95 @@
/*
* Copyright (c) 2020, HiHope Community.
*
* 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 WIFI_DEVICE_UTIL_H
#define WIFI_DEVICE_UTIL_H
#include "wifi_device.h"
#include "wifi_device_config.h"
#include "wifi_error_code.h"
#include "wm_wifi_api.h"
/**
* @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 Harmony OS security type to WinnerMicro security type
*
* @param type [in] Harmony OS security type.
*
* @return WinnerMicro security type.
*/
int HoSec2WmSec(WifiSecurityType type);
/**
* @brief convert WinnerMicro security type to Harmony OS security type
*
* @param type [in] WinnerMicro security type.
*
* @return Harmony OS security type.
*/
WifiSecurityType WmSec2HoSec(int mode);
/**
* @brief convert WinnerMicro enum tls_wifi_auth_mode to Harmony OS WifiSecurityType
*
* @param mode in WinnerMicro enum tls_wifi_auth_mode type.
*
* @return Harmony OS WifiSecurityType
*/
WifiSecurityType WmAuth2HoSec(int mode);
#endif // WIFI_DEVICE_UTIL_H
@@ -0,0 +1,301 @@
/*
* Copyright (c) 2020, HiHope Community.
*
* 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 "wifi_hotspot.h"
#include "wifi_device_util.h"
#include <string.h>
#include <securec.h>
#include "wm_type_def.h"
#include "wm_wifi.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 W800_MAX_STA_NUM 8
static int g_wifiApStatus = WIFI_HOTSPOT_NOT_ACTIVE;
static HotspotConfig g_wifiApConfig = {0};
WifiErrorCode SetHotspotConfig(const HotspotConfig* config)
{
if (config == NULL) {
return ERROR_WIFI_INVALID_ARGS;
}
if (LockWifiGlobalLock() != WIFI_SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
errno_t err = memcpy_s(&g_wifiApConfig, sizeof(g_wifiApConfig), config, sizeof(*config));
if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
if (err != EOK) {
printf("[wifi_service]:SetHotspotConfig memcpy fail, err = %d\n", err);
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;
}
errno_t err = memcpy_s(result, sizeof(*result), &g_wifiApConfig, sizeof(g_wifiApConfig));
if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
if (err != EOK) {
printf("[wifi_service]:SetHotspotConfig memcpy fail, err = %d\n", err);
return ERROR_WIFI_UNKNOWN;
}
return WIFI_SUCCESS;
}
WifiErrorCode EnableHotspot()
{
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;
}
struct tls_softap_info_t apinfo = {0};
strcpy(apinfo.ssid, g_wifiApConfig.ssid);
// errno_t err = strcpy_s(apinfo.ssid, sizeof(apinfo.ssid), g_wifiApConfig.ssid);
apinfo.encrypt = HoSec2WmSec(g_wifiApConfig.securityType);
apinfo.channel = g_wifiApConfig.channelNum;
strcpy(apinfo.keyinfo.key, g_wifiApConfig.preSharedKey);
// err += strcpy_s(apinfo.keyinfo.key, sizeof(apinfo.keyinfo.key), g_wifiApConfig.preSharedKey);
apinfo.keyinfo.key_len = strlen(g_wifiApConfig.preSharedKey);
apinfo.keyinfo.format = 1; // 0-hex, 1-ascii
if (g_wifiApConfig.securityType == WIFI_SEC_TYPE_WEP) {
apinfo.keyinfo.index = 1; // 1-4 (only wep)
}
// if (err != EOK) {
// printf("[wifi_service]:EnableHotspot memset fail, err = %d\n", err);
// if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
// return ERROR_WIFI_UNKNOWN;
// }
// return ERROR_WIFI_UNKNOWN;
// }
// TODO(xu): add API to set AP's ipinfo
struct tls_ip_info_t ipinfo = {0};
ipinfo.ip_addr[0] = 192;
ipinfo.ip_addr[1] = 168;
ipinfo.ip_addr[2] = 1;
ipinfo.ip_addr[3] = 1;
ipinfo.netmask[0] = 255;
ipinfo.netmask[1] = 255;
ipinfo.netmask[2] = 255;
ipinfo.netmask[3] = 0;
int retval = tls_wifi_softap_create(&apinfo, &ipinfo);
if (retval != WM_SUCCESS) {
printf("[wifi_service]:EnableHotspot tls_wifi_softap_create fail, err = %d\n", retval);
if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
}
g_wifiApStatus = WIFI_HOTSPOT_ACTIVE;
if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
return ERROR_WIFI_UNKNOWN;
}
return WIFI_SUCCESS;
}
WifiErrorCode DisableHotspot()
{
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;
}
tls_wifi_softap_destroy();
g_wifiApStatus = WIFI_HOTSPOT_NOT_ACTIVE;
if (UnlockWifiGlobalLock() != WIFI_SUCCESS) {
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;
}
WifiErrorCode GetStationList(StationInfo* result, unsigned int* size)
{
if (result == NULL || size == NULL || *size == 0) {
return ERROR_WIFI_INVALID_ARGS;
}
struct tls_sta_info_t staList[W800_MAX_STA_NUM] = {0};
unsigned int staNum = 0;
tls_wifi_get_authed_sta_info(&staNum, staList, sizeof(staList));
if (*size < staNum) {
return ERROR_WIFI_INVALID_ARGS;
}
for (unsigned int i = 0; i < staNum; i++) {
errno_t err = memcpy_s(result[i].macAddress, WIFI_MAC_LEN, staList[i].mac_addr, ETH_ALEN);
if (err != EOK) {
printf("[wifi_service]:GetStationList memcpy fail, err = %d\n", err);
return ERROR_WIFI_UNKNOWN;
}
}
*size = staNum;
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;
}
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;
}
WifiErrorCode DisassociateSta(unsigned char* mac, int macLen) {
if (mac == NULL) {
printf("[wifi_service]: MAC is NULL\r\n");
return ERROR_WIFI_INVALID_ARGS;
}
int ret = tls_wifi_softap_del_station(mac);
if (ret != WIFI_SUCCESS) {
printf("[wifi_service]: remove station device failed.\r\n");
return ERROR_WIFI_UNKNOWN;
}
return WIFI_SUCCESS;
}
WifiErrorCode AddTxPowerInfo(int power) {
printf("Neptune not support.\r\n");
return ERROR_WIFI_UNKNOWN;
}
+21
View File
@@ -0,0 +1,21 @@
# Copyright (C) 2022 HiHope Open Source Organization .
# 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("//kernel/liteos_m/liteos.gni")
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [
"hal_trace.c",
]
}
+42
View File
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2022 HiHope Open Source Organization .
* 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 "wm_include.h"
#if !(defined(LOSCFG_BASE_CORE_HILOG))
#include "stdarg.h"
#include "stdio.h"
int hal_trace_printf(int attr, const char *fmt, ...)
{
int ret = 0;
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
return ret;
}
#endif
int HdfSysEventSend(unsigned long eventClass, unsigned int event, const char *content, bool sync)
{
int ret = 0;
return ret;
}
Executable
+10
View File
@@ -0,0 +1,10 @@
{
"parts": {
"device_winnermicro": {
"module_list": [
"//device/soc/winnermicro:winnermicro"
]
}
},
"subsystem": "device_winnermicro"
}
+80
View File
@@ -0,0 +1,80 @@
#!/bin/sh
ProjName=$1
OutPath=$2
ToolPath="./tools"
signature=0
prikey_sel=0
code_encrypt=0
sign_pubkey_src=0
img_type=1
zip_type=1
sec_img_header=8002000
sec_img_pos=8002400
run_img_header=80d0000
run_img_pos=80d0400
upd_img_pos=8010000
echo $ProjName
if [ $prikey_sel -gt 0 ]
then
let img_type=$img_type+32*$prikey_sel
fi
if [ $code_encrypt -eq 1 ]
then
let img_type=$img_type+16
fi
if [ $signature -eq 1 ]
then
let img_type=$img_type+256
fi
if [ $sign_pubkey_src -eq 1 ]
then
let img_type=$img_type+512
fi
echo $img_type
if [ $code_encrypt -eq 1 ]
then
let prikey_sel=$prikey_sel+1
openssl enc -aes-128-ecb -in $OutPath/"$ProjName".bin -out $OutPath/"$ProjName"_enc.bin -K 30313233343536373839616263646566 -iv 01010101010101010101010101010101
openssl rsautl -encrypt -in $ToolPath/key.txt -inkey $ToolPath/ca/capub_"$prikey_sel".pem -pubin -out $OutPath/key_en.dat
cat $OutPath/"$ProjName"_enc.bin $OutPath/key_en.dat > $OutPath/"$ProjName"_enc_key.bin
cat $OutPath/"$ProjName"_enc_key.bin $ToolPath/ca/capub_"$prikey_sel"_N.dat > $OutPath/"$ProjName"_enc_key_N.bin
$ToolPath/wm_tool -b $OutPath/"$ProjName"_enc_key_N.bin -o $OutPath/"$ProjName" -it $img_type -fc 0 -ra $run_img_pos -ih $run_img_header -ua $upd_img_pos -nh 0 -un 0
else
$ToolPath/wm_tool -b $OutPath/"$ProjName".bin -o $OutPath/"$ProjName" -it $img_type -fc 0 -ra $run_img_pos -ih $run_img_header -ua $upd_img_pos -nh 0 -un 0
fi
if [ $signature -eq 1 ]
then
openssl dgst -sign $ToolPath/ca/cakey.pem -sha1 -out $OutPath/"$ProjName"_sign.dat $OutPath/"$ProjName".img
cat $OutPath/"$ProjName".img $OutPath/"$ProjName"_sign.dat > $OutPath/"$ProjName"_sign.img
#when you change run-area image's ih, you must remake secboot img with secboot img's -nh address same as run-area image's ih
$ToolPath/wm_tool -b $ToolPath/w800_secboot.bin -o $ToolPath/w800_secboot -it 0 -fc 0 -ra $sec_img_pos -ih $sec_img_header -ua $upd_img_pos -nh $run_img_header -un 0
cat $ToolPath/w800_secboot.img $OutPath/"$ProjName"_sign.img > $OutPath/"$ProjName".fls
else
#when you change run-area image's ih, you must remake secboot img with secboot img's -nh address same as run-area image's ih
$ToolPath/wm_tool -b $ToolPath/w800_secboot.bin -o $ToolPath/w800_secboot -it 0 -fc 0 -ra $sec_img_pos -ih $sec_img_header -ua $upd_img_pos -nh $run_img_header -un 0
cat $ToolPath/w800_secboot.img $OutPath/"$ProjName".img > $OutPath/"$ProjName".fls
fi
#produce compressed ota firmware*/
if [ $zip_type -eq 1 ]
then
if [ $signature -eq 1 ]
then
$ToolPath/wm_tool -b $OutPath/"$ProjName"_sign.img -o $OutPath/"$ProjName"_sign -it $img_type -fc 1 -ra $run_img_pos -ih $run_img_header -ua $upd_img_pos -nh 0 -un 0
mv $OutPath/"$ProjName"_sign_gz.img $OutPath/"$ProjName"_sign_ota.img
else
$ToolPath/wm_tool -b $OutPath/"$ProjName".img -o $OutPath/"$ProjName" -it $img_type -fc 1 -ra $run_img_pos -ih $run_img_header -ua $upd_img_pos -nh 0 -un 0
mv $OutPath/"$ProjName"_gz.img $OutPath/"$ProjName"_ota.img
fi
fi
#openssl --help
+15
View File
@@ -0,0 +1,15 @@
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQDPFl2+EagsO7AaH2N9b1d7pnOQ1dtQoahmOJRCc+6ZBLS4fpDj
Ahl8kpt43f/JTWBdTyIPti6rVKYuWHVozJ0dccgJl2FuklPICoLSxVv5ExknIm2Q
TIgS8WpxuoqhrCtNeJXWrcpAa09d6BtZXE1kN6eh000zq1yLyE5tXLA+vwIDAQAB
AoGARF94F/cwdVpHrHhMmu+WDMdKRLm3LYoSVZ28pawtTOxW1stC/xCEZbLqDiAO
AeLAPE6SSmm2Qu8x5v9h1HYqMSQ3LMhF9Da3zGy+cPiAoAUM26R1+6oF7Rbjf89f
n4a4b/57YhefcE1ZuU94fpZFHi3mE4Nq/vR/eg+q5JPe6RECQQD1GlBETd+mcHgX
a7//AkVwykSNxCaf/2wb5Db3YlIUF8INOO80T53i3Yyok1MH4xWRmCc6/bSYtB7d
daM9N7YrAkEA2EtfXipKshrhiTEtDV11MZJWZBaEY2w+eYTre+rrvGv2Gc6eCglF
UZh5L/zX/YgXq23Ba+oZl5wpcXkGtmTDvQJAAazsX4sovDqIl6Bk75lUYDEBxvZQ
TUextX8Z4RcK+Jgw+2YoPHNO4P4iuARJzQQAYb5ohj61vVV94IWtV/3JgQJBALwh
8zXIu2fnkbzvFSzG2aTgkFxGaajBAiZYwyrpz1n43frciQJZxf2PDfn7hzNzKINn
2BGxcck5f6K/jmMfilECQGAA5FekuiIWs7VY1St/blRqcISuqcqBnA2464dqJ9RL
FM2V12eP4kGSsXWIrM+BgWBLnQyQfK4uNoBnsoWaGus=
-----END RSA PRIVATE KEY-----
+6
View File
@@ -0,0 +1,6 @@
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDPFl2+EagsO7AaH2N9b1d7pnOQ
1dtQoahmOJRCc+6ZBLS4fpDjAhl8kpt43f/JTWBdTyIPti6rVKYuWHVozJ0dccgJ
l2FuklPICoLSxVv5ExknIm2QTIgS8WpxuoqhrCtNeJXWrcpAa09d6BtZXE1kN6eh
000zq1yLyE5tXLA+vwIDAQAB
-----END PUBLIC KEY-----
+6
View File
@@ -0,0 +1,6 @@
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDR/Wu8GvbFc/efFoIMMpTdwM3P
uw2FX7Id1hq9MmnztxvZtECeax33ooSiLr14O1BbUmRUfkIprLmJCObiF6Poqohz
cIFehYusXLwjlonexLkA+gn1IRPbtPtYrqu0uipipE1V3maA/2sBZB5HwfHps48e
iSicAsv/lnT/24796QIDAQAB
-----END PUBLIC KEY-----
BIN
View File
Binary file not shown.
+6
View File
@@ -0,0 +1,6 @@
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDSiRrRM6Pb9waV2u+Wm0iMEH40
3t661seujk72gayxdrFzbZCCQuUb/rEmQ7xUR/7iM+vdaiUmFzN+Jd+GVNU8ng+B
cevgtuBM9wf7Z2Oq/u16VvmiMkwcg1YSzsdAbiAEEfHMMpAopdYrXU3hRP+Qa4C7
BJjTwpnb0sVqFSTWtQIDAQAB
-----END PUBLIC KEY-----
+1
View File
@@ -0,0 +1 @@
҉Ń3ŁŰ÷•Úď–›HŚ~4ŢŢşÖÇ®ŽNö¬±v±sm‚Bĺţ±&CĽTGţâ3ëÝj%&3~%߆TŐ<žqëŕ¶ŕL÷űgcŞţízVů˘2LVÎÇ@n ńĚ2(ĄÖ+]MáD˙k€»Ó™ŰŇĹj$Öµ
+6
View File
@@ -0,0 +1,6 @@
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDMVPvnEKbq8N2PjonaPLOa4Gb2
kur6bF5yTiR2X/OCDvVynnNBxFncjzuKSk+BFvvI7USRBYuXjovKWH/e4mYg3apb
2OxX9SwBKbXH3E3Kt5BCqAltvDpTRfnadSimncZUMSvHmPr3C44cXMsb3ZGjwflG
mabfxn6AAC1ifZNcEQIDAQAB
-----END PUBLIC KEY-----
BIN
View File
Binary file not shown.
+6
View File
@@ -0,0 +1,6 @@
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCjQuZYXi5h7QEgGAfDd7MRqCh0
AVZWYixUFUi54q9ON2UKSX4Ku2+2zIJagEa/JjKix3wMJXdqhwBkKLc1EeMx8sib
6OqeVS9cOk3lqHWFDMNy6v9aF6pcChHksWC+pZQ0DiILCvp/PQqAw0Ax0PTFvJOv
96mMS7rAT8YXJOQxDwIDAQAB
-----END PUBLIC KEY-----
BIN
View File
Binary file not shown.
+6
View File
@@ -0,0 +1,6 @@
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCZwi/qgKzT5wZj+U1a6dJaqOVv
xiKuiYi2qgJ/ZZyPG5LJHa7dQUvW+zY8kLF0KF3IpyyswuApI799oK1IJ04aosNy
Xa128J34MpEn41zWfkb2OQWhTCPqwF6H1lBwG1BEPR1On9mna01d7FuIKw0VonhF
/kmbQ81vWOe96IZr6wIDAQAB
-----END PUBLIC KEY-----
+1
View File
@@ -0,0 +1 @@
™В/кЂ¬УзcщMZйТZЁеoЖ"®‰€¶ЄeњЏ’Й®ЭAKЦы6<ђ±t(]И§,¬Ва)#ї} ­H'NўГr]­vрќш2'г\Ц~Fц9ЎL#кА^‡ЦPpPD=NџЩ§kM]м[€+
+6
View File
@@ -0,0 +1,6 @@
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8/M1npFNzH79BrxmeaW1ixw1i
kLZ98k7vo5EI9Gp/yP+mSb6Hr57Jx+Q19yG2Q76VobqFpxveZNn7xSDGgobqn9jt
+z/RIYLPYl5xCLtuDl1uXX+nAOriaBRCBaHfQ3RwcWuClQ+gLZdPYo0GMnt23xPU
RHDWJB+D/2/0EYWDdQIDAQAB
-----END PUBLIC KEY-----
BIN
View File
Binary file not shown.
+6
View File
@@ -0,0 +1,6 @@
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCzkfkhRIdjxPN6gXZB8DTNVlJ0
E5R0z/sEbwat5EoILt7VJG6oTP/bc16CJOa4E1Pu7tQn3NZg6cdK95kk6B3Ak460
592YZlX/3cGPCN4W+JXWjrl0bQQiweemxjZVK7Sm+SVht6tfsarVMnH/yuAy9Ck5
bVs0R2fHbf81yeaf1QIDAQAB
-----END PUBLIC KEY-----
+1
View File
@@ -0,0 +1 @@
³‘ù!D‡cÄózvAð4ÍVRt”tÏûo­äJ.ÞÕ$n¨LÿÛs^‚$æ¸SîîÔ'ÜÖ`éÇJ÷™$èÀ“Ž´çݘfUÿÝÁÞø•ÖŽ¹tm"Áç¦Æ6U+´¦ù%a·«_±ªÕ2qÿÊà2ô)9m[4GgÇmÿ5ÉæŸÕ
+6
View File
@@ -0,0 +1,6 @@
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDB36Jwh7S7OCMY/qIxNf3aapw5
L+CT35cibdbD3uy8Ewg0fSUwmL+JkOtqNxa5ejU37mbVy/8rQAczSV6muBVSHWgO
7HgI6criU1ufvxDphced6Oko7YpA4IJzjeUNgOYLkau276Sr9/bV15zFM907q3ma
LPuTocNyUbIvJuFHVQIDAQAB
-----END PUBLIC KEY-----
+1
View File
@@ -0,0 +1 @@
Áߢp‡´»8#þ¢15ýÚjœ9/à“ß—"mÖÃÞì¼4}%0˜¿‰ëj7¹z57îfÕËÿ+@3I^¦¸RhìxéÊâS[Ÿ¿é…Çèé(íŠ@à‚så
Executable
+1
View File
@@ -0,0 +1 @@
0123456789abcdef
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Executable
BIN
View File
Binary file not shown.
+5061
View File
File diff suppressed because it is too large Load Diff
BIN
View File
Binary file not shown.
Executable
+90
View File
@@ -0,0 +1,90 @@
# Copyright (C) 2022 HiHope Open Source Organization .
# 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.
if (ohos_kernel_type == "liteos_m") {
import("//build/lite/config/component/lite_component.gni")
import("//build/lite/config/subsystem/lite_subsystem.gni")
import("//kernel/liteos_m/liteos.gni")
module_name = get_path_info(rebase_path("."), "name")
module_group(module_name) {
modules = [
"board",
]
}
# global config
out_product_path = "${ohos_root_path}out/${board_name}/${product_name}"
# config bin from vendor/<board_name>/<product_name>/config.json
foreach(bin_file, bin_list) {
build_enable = bin_file.enable
out_bin_path = "${out_product_path}/bin/"
exe_bin = "${bin_file.elf_name}_${board_name}"
print("build", exe_bin, ":", build_enable)
# generate execute bin
executable(exe_bin) {
output_name = exe_bin
output_extension = "elf"
ldflags = [
"-Wl,--gc-sections",
"-Wl,-Map=bin/$output_name.map",
]
deps = [ ]
if (build_enable == "true") {
# force link invisible function ,which ar to lib
ldflags += [
"-L" + "${out_product_path}/libs",
"-Wl,--whole-archive",
]
foreach(force_link_lib, bin_file.force_link_libs) {
ldflags += [ "-l${force_link_lib}" ]
}
ldflags += [ "-Wl,--no-whole-archive" ]
deps += [ "//test/xts/tools/lite:tools" ]
deps += [ "//test/xts/acts/build_lite:acts" ]
}
deps += [ "//build/lite:ohos" ]
deps += [ "//build/lite:product" ]
}
build_ext_component("build_kernel_image") {
deps = [ ":${exe_bin}" ]
output_name = exe_bin
exec_path = out_bin_path
objcopy = "${compile_prefix}objcopy$toolchain_cmd_suffix"
objdump = "${compile_prefix}objdump$toolchain_cmd_suffix"
command = "$objcopy -O binary $output_name.elf $output_name.bin"
command +=
" && sh -c '$objdump -t $output_name.elf | sort >$output_name.sym.sorted'"
command += " && sh -c '$objdump -d $output_name.elf >$output_name.asm'"
}
build_ext_component("build_image") {
deps = [ ":build_kernel_image" ]
exec_path = "${ohos_root_path}${ohos_vendor_adapter_dir}"
print("out_bin_path:", out_bin_path)
command = "./tools/aft_build_project.sh ${exe_bin} ${out_bin_path}"
}
}
}
+23
View File
@@ -0,0 +1,23 @@
# Copyright (C) 2022 HiHope Open Source Organization .
# 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.
if SOC_SERIES_WM800
rsource "Kconfig.liteos_m.defconfig.wm800"
config SOC_SERIES
string
default "wm800"
endif
+17
View File
@@ -0,0 +1,17 @@
# Copyright (C) 2022 HiHope Open Source Organization .
# 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.
config SOC
string
default "wm800"
depends on SOC_WM800
+21
View File
@@ -0,0 +1,21 @@
# Copyright (C) 2022 HiHope Open Source Organization .
# 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.
config SOC_SERIES_WM800
bool "winnermicro 800 Series"
select ARM
select SOC_COMPANY_WINNERMICRO
select CPU_XT804
help
Enable support for winnermicro 800 series
+21
View File
@@ -0,0 +1,21 @@
# Copyright (C) 2022 HiHope Open Source Organization .
# 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.
choice
prompt "Winnermicro 800 series SoC"
depends on SOC_SERIES_WM800
config SOC_WM800
bool "SoC WM800"
endchoice
+76
View File
@@ -0,0 +1,76 @@
# Copyright (C) 2022 HiHope Open Source Organization .
# 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.
if (ohos_kernel_type == "liteos_m") {
import("//kernel/liteos_m/liteos.gni")
module_name = get_path_info(rebase_path("."), "name")
config("board_config") {
ldflags = [
"-mcpu=ck804ef",
"-mhard-float",
"-Wl,--gc-sections",
"-Wl,-zmax-page-size=1024",
"-Wl,-T" + rebase_path("ld/w800/gcc_csky.ld"),
"-Wl,--start-group",
"-Wl,--end-group",
"-nostartfiles",
"-nodefaultlibs",
"-L" + rebase_path("./lib/w800"),
]
libs = [
"gcc",
#"c",
"btcontroller",
"wlan",
"dsp",
]
include_dirs = [
".",
"include",
"include/app",
"include/arch/xt804",
"include/arch/xt804/csi_core",
"include/arch/xt804/csi_dsp",
"include/bt",
"include/driver",
"include/net",
"include/os",
"include/platform",
"include/wifi",
"platform/common/params",
"platform/drivers/spi",
"platform/inc",
"platform/sys",
"src/os/liteos/include",
"src/os/liteos/include_standrd",
"//utils/native/lite/include",
"//third_party/musl/porting/liteos_m/kernel/src/include",
"//third_party/musl/porting/liteos_m/kernel/src/internal",
"//third_party/wpa_supplicant/wpa_supplicant-2.9/src/utils",
"//drivers/framework/core/common/include/manager",
"//drivers/framework/include/platform",
"//drivers/framework/include/utils",
"//drivers/adapter/khdf/liteos_m/osal/include",
]
}
module_group(module_name) {
modules = [
"platform",
"app",
"src",
]
configs = [ ":board_config" ]
}
}
+22
View File
@@ -0,0 +1,22 @@
# Copyright (C) 2022 HiHope Open Source Organization .
# 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("//kernel/liteos_m/liteos.gni")
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [
"main.c",
]
include_dirs = []
}
+15
View File
@@ -0,0 +1,15 @@
TOP_DIR = ..
sinclude $(TOP_DIR)/tools/w800/conf.mk
ifndef PDIR
GEN_LIBS = libuser$(LIB_EXT)
endif
#DEFINES +=
sinclude $(TOP_DIR)/tools/w800/rules.mk
INCLUDES := $(INCLUDES) -I $(PDIR)include
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile
+29
View File
@@ -0,0 +1,29 @@
/*****************************************************************************
*
* File Name : main.c
*
* Description: main
*
* Copyright (c) 2014 Winner Micro Electronic Design Co., Ltd.
* All rights reserved.
*
* Author : dave
*
* Date : 2014-6-14
*****************************************************************************/
#include "devmgr_service_start.h"
void UserMain(void)
{
printf("\n user task \n");
#if DEMO_CONSOLE
CreateDemoTask();
#endif
//Óû§×Ô¼ºµÄtask
if (DeviceManagerStart()) {
printf("[%s] No drivers need load by hdf manager!",__func__);
}
}
+211
View File
@@ -0,0 +1,211 @@
/*
* Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/******************************************************************************
* @file gcc_csky.ld
* @brief csky linker file
* @version V1.0
* @date 02. June 2017
******************************************************************************/
MEMORY
{
I-SRAM : ORIGIN = 0x080d0400 , LENGTH = 0x120000 /* I-SRAM 1M+128KB */
D-SRAM : ORIGIN = 0x20000100 , LENGTH = 0x47f00 /* D-SRAM 288KB */
V-SRAM : ORIGIN = 0x20000000 , LENGTH = 0x100 /* off-chip SRAM 8MB */
}
__min_heap_size = 0x18000;
PROVIDE (__ram_end = 0x2003A000);
PROVIDE (__heap_end = __ram_end);
REGION_ALIAS("REGION_TEXT", I-SRAM);
REGION_ALIAS("REGION_RODATA", I-SRAM);
REGION_ALIAS("REGION_VDATA", V-SRAM);
REGION_ALIAS("REGION_DATA", D-SRAM);
REGION_ALIAS("REGION_BSS", D-SRAM);
ENTRY(Reset_Handler)
SECTIONS
{
.text : {
. = ALIGN(0x4) ;
KEEP(*startup.o(.vectors))
__stext = . ;
__text_start = . ;
*(.text)
*(.text*)
*(.text.*)
*(.gnu.warning)
*(.stub)
*(.gnu.linkonce.t*)
*(.glue_7t)
*(.glue_7)
*(.jcr)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN (4) ;
PROVIDE(__ctbp = .);
*(.call_table_data)
*(.call_table_text)
. = ALIGN(0x10) ;
__etext = . ;
__text_end = . ;
} > REGION_TEXT
.rodata : {
. = ALIGN(0x4) ;
__srodata = .;
*(.rdata)
*(.rdata*)
*(.rdata1)
*(.rdata.*)
*(.rodata)
*(.rodata1)
*(.rodata*)
*(.rodata.*)
*(.rodata.str1.4)
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
. = ALIGN(0x4) ;
__erodata = .;
} > REGION_RODATA
.vdata : {
. = ALIGN(0x4) ;
__vdata_start__ = . ;
KEEP(*startup.o(.vdata))
. = ALIGN(0x4) ;
__vdata_end__ = .;
} > REGION_VDATA
.data : {
. = ALIGN(0x4) ;
__sdata = . ;
__data_start__ = . ;
data_start = . ;
*(.got.plt)
*(.got)
*(.gnu.linkonce.r*)
*(.data)
*(.data*)
*(.data1)
*(.data.*)
*(.gnu.linkonce.d*)
*(.data1)
*(.gcc_except_table)
*(.gcc_except_table*)
__start_init_call = .;
*(.initcall.init)
__stop_init_call = .;
__start_cmd = .;
*(.bootloaddata.cmd)
. = ALIGN(4) ;
__stop_cmd = .;
*(.sdata)
*(.sdata.*)
*(.gnu.linkonce.s.*)
*(__libc_atexit)
*(__libc_subinit)
*(__libc_subfreeres)
*(.note.ABI-tag)
. = ALIGN(0x4) ;
__edata = .;
__data_end__ = .;
} > REGION_DATA AT > REGION_RODATA
.bss : {
. = ALIGN(0x4) ;
__sbss = ALIGN(0x4) ;
__bss_start__ = . ;
*(.dynsbss)
*(.sbss)
*(.sbss.*)
*(.scommon)
*(.dynbss)
*(.bss)
*(.bss.*)
*(COMMON)
. = ALIGN(0x4) ;
__ebss = . ;
__end = . ;
end = . ;
__bss_end__ = .;
} > REGION_BSS
._user_heap : {
. = ALIGN(0x4) ;
__heap_start = .;
. += __min_heap_size;
. = ALIGN(0x4) ;
} > REGION_BSS
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) } > REGION_BSS
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) } > REGION_BSS
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
.eh_frame_hdr : { *(.eh_frame_hdr) }
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
}
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
}
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(.fini_array))
KEEP (*(SORT(.fini_array.*)))
PROVIDE_HIDDEN (__fini_array_end = .);
}
.junk 0 : { *(.rel*) *(.rela*) }
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
.debug_pubtypes 0 : { *(.debug_pubtypes) }
.debug_ranges 0 : { *(.debug_ranges) }
.gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
}
+79
View File
@@ -0,0 +1,79 @@
/**
* @file wm_at_ri_init.h
*
* @brief AT_RI task and interface resource initial Module
*
* @author winnermicro
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_AT_RI_H
#define WM_AT_RI_H
/**
* @defgroup APP_APIs APP APIs
* @brief APP APIs
*/
/**
* @addtogroup APP_APIs
* @{
*/
/**
* @defgroup AT_RI_APIs AT_RI APIs
* @brief AT_RI command APIs
*/
/**
* @addtogroup AT_RI_APIs
* @{
*/
/**
* @brief This function is used to initialize hostif task
used by AT&RI Command
*
* @param None
*
* @retval 0 success
* @retval other failed
*
* @note Usually the system will call this api at power on.
*/
int tls_hostif_init(void);
/**
* @}
*/
/**
* @}
*/
/**
* @brief This function is used to initialize high speed SPI
*
* @param None
*
* @retval 0 success
* @retval other failed
*
* @note Users can decide to call this api or not according to his application.
*/
int tls_hspi_init(void);
/**
* @brief This function is used to initialize UART
*
* @param None
*
* @return None
*
* @note Usually the system will call this api at power on.
*/
void tls_uart_init(void);
#endif /* WM_AT_RI_H */
+91
View File
@@ -0,0 +1,91 @@
/**
* @file wm_crypto.h
*
* @brief crypto driver module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_CRYPTO_H
#define WM_CRYPTO_H
/**
* @brief Encrypt plain data by 128 AES crypto
* @param[in] key the key for encryption
* @param[in] iv the IV value for encryption
* @param[in] data where the plain data stored
* @param[in] data_len length of the plain data to be encrypted
* @retval 0 finish Encryption successfully
* @retval -1 Error
* @note Encrypted data will be placed into the plain @data area
*
*/
int aes_128_cbc_encrypt (const u8 *key, const u8 *iv, u8 *data, size_t data_len) ;
/**
* @brief Decrypt data by 128 AES crypto
* @param[in] key the key for encryption
* @param[in] iv the IV value for encryption
* @param[in] data where the plain data stored
* @param[in] data_len length of the plain data to be decrypted
* @retval 0 finish Decryption successfully
* @retval -1 Error
* @note plain data will be placed into the encrypted @data area
*
*/
int aes_128_cbc_decrypt(const u8 *key, const u8 *iv, u8 *data,
size_t data_len);
/**
* @brief XOR RC4 stream to given data with skip-stream-start
* @param[in] key RC4 key
* @param[in] keylen RC4 key length
* @param[in] data data to be XOR'ed with RC4 stream
* @param[in] data_len length of the plain data to be encrypted
* @retval 0 finish Encryption/Decryption successfully
* @retval -1 Error
* @note this function should be used for Encryption & Decryption both For the Encryption, the plain @data
* will be replaced by the encrypted output, and vice versa;
*/
int rc4(const u8 *key, size_t keylen, u8 *data, size_t data_len);
/**
* @brief MD5 hash for data vector
* @param[in] addr Pointers to the data area
* @param[in] len Lengths of the data block
* @param[in] mac Buffer for the hash (16 bytes)
* @retval 0 finish caculation successfully
* @retval -1 Error
* @note
*/
int md5(const u8 *addr, int len, u8 *mac);
/**
* @brief HMAC-MD5 over data buffer (RFC 2104)
* @param[in] key Key for HMAC operations
* @param[in] keylen Length of the key in bytes
* @param[in] data data to be caculated
* @param[in] data_len Lengths of the data block
* @param[in] mac Buffer for the hash (16 bytes)
* @retval 0 finish caculation successfully
* @retval -1 Error
* @note
*/
int hmac_md5(const u8 *key, size_t key_len, const u8 *data, size_t data_len, u8 *mac);
/**
* @brief SHA1 hash for data vector
* @param[in] addr Pointers to the data area
* @param[in] len Lengths of the data block
* @param[in] mac Buffer for the hash (16 bytes)
* @retval 0 finish caculation successfully
* @retval -1 Error
* @note
*/
int sha1(const u8 *addr, int len, u8 *mac);
#endif
+91
View File
@@ -0,0 +1,91 @@
/**
* @file wm_dhcp_server.h
*
* @brief DHCP SERVER
*
* @author winnermicro
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_DHCP_SERVER_H
#define WM_DHCP_SERVER_H
/**
* @defgroup APP_APIs APP APIs
* @brief APP APIs
*/
/**
* @addtogroup APP_APIs
* @{
*/
/**
* @defgroup DHCPS_APIs DHCPS APIs
* @brief DHCP server APIs
*/
/**
* @addtogroup DHCPS_APIs
* @{
*/
/**
* @brief This function is used to start DHCP Server for a network
interface
*
* @param None
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
s8 tls_dhcps_start(void);
/**
* @brief This function is used to stop DHCP server
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_dhcps_stop(void);
/**
* @brief This function is used to get station's IP address by
MAC address
*
* @param[in] *mac STA's MAC address
*
* @retval ip_addr STA's IP address
* @retval NULL Not found match IP with MAC address
*
* @note None
*/
ip_addr_t *tls_dhcps_getip(const u8 *mac);
/**
* @brief This function is used to set DHCP server's DNS address
*
* @param[in] numdns the index of the DNS server to set must be 0 or 1
*
* @return None
*
* @note None
*/
void tls_dhcps_setdns(u8 numdns);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_DHCP_SERVER_H */
+66
View File
@@ -0,0 +1,66 @@
/**
* @file wm_dns_server.h
*
* @brief DNS SERVER
*
* @author winnermicro
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_DNS_SERVER_H
#define WM_DNS_SERVER_H
/**
* @defgroup APP_APIs APP APIs
* @brief APP APIs
*/
/**
* @addtogroup APP_APIs
* @{
*/
/**
* @defgroup DNSS_APIs DNSS APIs
* @brief DNS server APIs
*/
/**
* @addtogroup DNSS_APIs
* @{
*/
/**
* @brief This function is used to start DNS service
*
* @param[in] *dnsname Specify the server's dns name
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
s8 tls_dnss_start(u8 *dnsname);
/**
* @brief This function is used to stop DNS service
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_dnss_stop(void);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_DNS_SERVER_H */
+486
View File
@@ -0,0 +1,486 @@
/**
* @file wm_http_client.h
*
* @brief Http client APIs
*
* @author wanghf
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_HTTP_CLIENT_H
#define WM_HTTP_CLIENT_H
#include "wm_config.h"
#include "wm_type_def.h"
#ifdef BOOL
#undef BOOL
#endif
#ifdef UCHAR
#undef UCHAR
#endif
#ifdef CHAR
#undef CHAR
#endif
#ifdef UINT16
#undef UINT16
#endif
#ifdef INT16
#undef INT16
#endif
#ifdef UINT32
#undef UINT32
#endif
#ifdef INT32
#undef INT32
#endif
#ifdef UINT64
#undef UINT64
#endif
#ifdef INT64
#undef INT64
#endif
#ifdef ULONG
#undef ULONG
#endif
#ifdef LONG
#undef LONG
#endif
#define VOID void
typedef int BOOL;
typedef unsigned char UCHAR;
//typedef signed char CHAR;
typedef char CHAR;
typedef unsigned short UINT16;
typedef signed short INT16;
typedef unsigned int UINT32;
typedef signed int INT32;
typedef unsigned long long UINT64;
typedef long long INT64;
typedef unsigned long ULONG;
typedef signed long LONG;
/* HTTP Status, API Return codes */
/** HTTP Success status */
#define HTTP_CLIENT_SUCCESS 0
/** Unknown error */
#define HTTP_CLIENT_UNKNOWN_ERROR 1
/** an Invalid handle or possible bad pointer was passed to a function */
#define HTTP_CLIENT_ERROR_INVALID_HANDLE 2
/** Buffer too small or a failure while in memory allocation */
#define HTTP_CLIENT_ERROR_NO_MEMORY 3
/** an attempt to use an invalid socket handle was made */
#define HTTP_CLIENT_ERROR_SOCKET_INVALID 4
/** Can't send socket parameters */
#define HTTP_CLIENT_ERROR_SOCKET_CANT_SET 5
/** Error while resolving host name */
#define HTTP_CLIENT_ERROR_SOCKET_RESOLVE 6
/** Error while connecting to the remote server */
#define HTTP_CLIENT_ERROR_SOCKET_CONNECT 7
/** socket time out error */
#define HTTP_CLIENT_ERROR_SOCKET_TIME_OUT 8
/** Error while receiving data */
#define HTTP_CLIENT_ERROR_SOCKET_RECV 9
/** Error while sending data */
#define HTTP_CLIENT_ERROR_SOCKET_SEND 10
/** Error while receiving the remote HTTP headers */
#define HTTP_CLIENT_ERROR_HEADER_RECV 11
/** Could not find element within header */
#define HTTP_CLIENT_ERROR_HEADER_NOT_FOUND 12
/** The headers search clue was too large for the internal API buffer */
#define HTTP_CLIENT_ERROR_HEADER_BIG_CLUE 13
/** No content length was specified for the outgoing data. the caller should
specify chunking mode in the session creation */
#define HTTP_CLIENT_ERROR_HEADER_NO_LENGTH 14
/** The HTTP chunk token that was received from the server was too big and possibly wrong */
#define HTTP_CLIENT_ERROR_CHUNK_TOO_BIG 15
/** Could not authenticate with the remote host */
#define HTTP_CLIENT_ERROR_AUTH_HOST 16
/** Could not authenticate with the remote proxy */
#define HTTP_CLIENT_ERROR_AUTH_PROXY 17
/** Bad or not supported HTTP verb was passed to a function */
#define HTTP_CLIENT_ERROR_BAD_VERB 18
/** a function received a parameter that was too large */
#define HTTP_CLIENT_ERROR_LONG_INPUT 19
/** The session state prevents the current function from proceeding */
#define HTTP_CLIENT_ERROR_BAD_STATE 20
/** Could not parse the chunk length while in chunked transfer */
#define HTTP_CLIENT_ERROR_CHUNK 21
/** Could not parse curtail elements from the URL (such as the host name, HTTP prefix act') */
#define HTTP_CLIENT_ERROR_BAD_URL 22
/** Could not detect key elements in the received headers */
#define HTTP_CLIENT_ERROR_BAD_HEADER 23
/** Error while attempting to resize a buffer */
#define HTTP_CLIENT_ERROR_BUFFER_RSIZE 24
/** Authentication schema is not supported */
#define HTTP_CLIENT_ERROR_BAD_AUTH 25
/** The selected authentication schema does not match the server response */
#define HTTP_CLIENT_ERROR_AUTH_MISMATCH 26
/** an element was missing while parsing the digest authentication challenge */
#define HTTP_CLIENT_ERROR_NO_DIGEST_TOKEN 27
/** Digest algorithem could be MD5 or MD5-sess other types are not supported */
#define HTTP_CLIENT_ERROR_NO_DIGEST_ALG 28
/** Binding error */
#define HTTP_CLIENT_ERROR_SOCKET_BIND 29
/** Tls negotiation error */
#define HTTP_CLIENT_ERROR_TLS_NEGO 30
/** Feature is not (yet) implemented */
#define HTTP_CLIENT_ERROR_NOT_IMPLEMENTED 64
/** HTTP end of stream message */
#define HTTP_CLIENT_EOS 1000
// HTTP Session flags (Public flags)
#define HTTP_CLIENT_FLAG_KEEP_ALIVE 0x00000001 // Set the keep alive header
#define HTTP_CLIENT_FLAG_SEND_CHUNKED 0x00000002 // The outgoing should chunked
#define HTTP_CLIENT_FLAG_NO_CACHE 0x00000004 // Set the no cache header
#define HTTP_CLIENT_FLAG_ASYNC 0x00000008 // Currently not implemented
#define HTTP_CLIENT_FLAG_MULTIPART_FORM 0x00000010 // The outgoing should multipart/form-data
// HTTP Type Definitions
typedef UINT32 HTTP_SESSION_HANDLE;
typedef UINT32 HTTP_CLIENT_SESSION_FLAGS;
/******************************************************************************
*
* Section : HTTP API structures
*
******************************************************************************/
/* HTTP Type Definitions */
/** http seesion handle */
typedef u32 tls_http_session_handle_t;
/** http seesion flags */
typedef u32 tls_http_session_flags_t;
/** HTTP Supported authentication methods */
typedef enum _HTTP_AUTH_SCHEMA
{
AuthSchemaNone = 0,
AuthSchemaBasic,
AuthSchemaDigest,
AuthSchemaKerberos,
AuthNotSupported
} HTTP_AUTH_SCHEMA;
/** HTTP supported verbs */
typedef enum _HTTP_VERB
{
VerbGet = 0,
VerbHead,
VerbPost,
VerbPut,
VerbFwup,
VerbNotSupported
// Note: others verb such as connect and put are currently not supported
} HTTP_VERB;
/** Data structure that the caller can request at any time that will include
some information regarding the session */
typedef struct _HTTP_CLIENT
{
UINT32 HTTPStatusCode; // HTTP Status code (200 OK)
UINT32 RequestBodyLengthSent; // Total bytes sent (body only)
UINT32 ResponseBodyLengthReceived; // Total bytes received (body only)
UINT32 TotalResponseBodyLength; // as extracted from the “content-length" header
UINT32 HttpState;
} HTTP_CLIENT;
/** HTTP parameters */
typedef struct _HTTPParameters
{
CHAR* Uri;
CHAR* ProxyHost;
UINT32 UseProxy ;
UINT32 ProxyPort;
UINT32 Verbose;
CHAR* UserName;
CHAR* Password;
HTTP_AUTH_SCHEMA AuthType;
} HTTPParameters;
#if TLS_CONFIG_HTTP_CLIENT_TASK
/** the callback function of http clent for received */
typedef void (*http_client_recv_callback_fn)(HTTP_SESSION_HANDLE pSession, CHAR * data, UINT32 totallen, UINT32 datalen);
/** the callback function of http clent for err */
typedef void (*http_client_err_callback_fn)(HTTP_SESSION_HANDLE pSession, int err);
/** message of the http client */
typedef struct _http_client_msg
{
HTTP_SESSION_HANDLE pSession;
HTTPParameters param;
HTTP_VERB method;
CHAR* sendData;
UINT32 dataLen;
http_client_recv_callback_fn recv_fn;
http_client_err_callback_fn err_fn;
} http_client_msg;
#endif
/**
* @defgroup APP_APIs APP APIs
* @brief APP APIs
*/
/**
* @addtogroup APP_APIs
* @{
*/
/**
* @defgroup HTTPC_APIs HTTPC APIs
* @brief HTTP client APIs
*/
/**
* @addtogroup HTTPC_APIs
* @{
*/
/******************************************************************************
*
* Section : HTTP API public interface
*
******************************************************************************/
/**
* @brief Allocate memory for a new HTTP Session
*
* @param[in] Flags HTTP Session internal API flags, 0 should be passed here
*
* @retval 0 failed
* @retval other HTTP Session handle
*
* @note None
*/
HTTP_SESSION_HANDLE HTTPClientOpenRequest (HTTP_CLIENT_SESSION_FLAGS Flags);
/**
* @brief Closes the active connection and free the corresponding memory
*
* @param[in] *pSession HTTP Session handle
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientCloseRequest (HTTP_SESSION_HANDLE *pSession);
/**
* @brief Sets the HTTP authentication schema
*
* @param[in] pSession HTTP Session handle
* @param[in] AuthSchema HTTP Supported authentication methods
* @param[in] *pReserved Reserved parameter
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientSetAuth (HTTP_SESSION_HANDLE pSession, HTTP_AUTH_SCHEMA AuthSchema, void *pReserved);
/**
* @brief Sets credentials for the target host
*
* @param[in] pSession HTTP Session handle
* @param[in] *pUserName User name
* @param[in] *pPassword Password
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientSetCredentials (HTTP_SESSION_HANDLE pSession, CHAR *pUserName, CHAR *pPassword);
/**
* @brief Sets all the proxy related parameters
*
* @param[in] pSession HTTP Session handle
* @param[in] *pProxyName The host name
* @param[in] nPort The proxy port number
* @param[in] *pUserName User name for proxy authentication (can be null)
* @param[in] *pPassword User password for proxy authentication (can be null)
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientSetProxy (HTTP_SESSION_HANDLE pSession, CHAR *pProxyName, UINT16 nPort, CHAR *pUserName, CHAR *pPassword);
/**
* @brief Sets the HTTP verb for the outgoing request
*
* @param[in] pSession HTTP Session handle
* @param[in] HttpVerb HTTP supported verbs
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientSetVerb (HTTP_SESSION_HANDLE pSession, HTTP_VERB HttpVerb);
/**
* @brief Add headers into the outgoing request
*
* @param[in] pSession HTTP Session
* @param[in] *pHeaderName The Header name
* @param[in] *pHeaderData The header data
* @param[in] nInsert Reserved, could be any
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientAddRequestHeaders (HTTP_SESSION_HANDLE pSession, CHAR *pHeaderName, CHAR *pHeaderData, BOOL nInsert);
/**
* @brief This function builds the request headers, performs a DNS resolution,
* opens the connection (if it was not opened yet by a previous request
* or if it has closed) and sends the request headers
*
* @param[in] pSession HTTP Session handle
* @param[in] *pUrl The requested URL
* @param[in] *pData Data to post to the server
* @param[in] nDataLength Length of posted data
* @param[in] TotalLength Valid only when http method is post
* TRUE: Post data to http server.
* FALSE: In a post request without knowing the total
* length in advance so return error or use chunking.
* @param[in] nTimeout Operation timeout
* @param[in] nClientPort Client side port 0 for none
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientSendRequest (HTTP_SESSION_HANDLE pSession, CHAR *pUrl, VOID *pData, UINT32 nDataLength, BOOL TotalLength, UINT32 nTimeout,UINT32 nClientPort);
/**
* @brief Write data to the remote server
*
* @param[in] pSession HTTP Session handle
* @param[in] *pBuffer Data to write to the server
* @param[in] nBufferLength Length of wtitten data
* @param[in] nTimeout Timeout for the operation
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientWriteData (HTTP_SESSION_HANDLE pSession, VOID *pBuffer, UINT32 nBufferLength, UINT32 nTimeout);
/**
* @brief Receives the response header on the connection and parses it.
* Performs any required authentication.
*
* @param[in] pSession HTTP Session handle
* @param[in] nTimeout Timeout for the operation
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientRecvResponse (HTTP_SESSION_HANDLE pSession, UINT32 nTimeout);
/**
* @brief Read data from the server. Parse out the chunks data
*
* @param[in] pSession HTTP Session handle
* @param[out] *pBuffer A pointer to a buffer that will be filled with the servers response
* @param[in] nBytesToRead The size of the buffer (numbers of bytes to read)
* @param[in] nTimeout Operation timeout in seconds
* @param[out] *nBytesRecived Count of the bytes that were received in this operation
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientReadData (HTTP_SESSION_HANDLE pSession, VOID *pBuffer, UINT32 nBytesToRead, UINT32 nTimeout, UINT32 *nBytesRecived);
/**
* @brief Fill the users structure with the session information
*
* @param[in] pSession HTTP Session handle
* @param[out] *HTTPClient The session information
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientGetInfo (HTTP_SESSION_HANDLE pSession, HTTP_CLIENT *HTTPClient);
/**
* @brief Initiate the headr searching functions and find the first header
*
* @param[in] pSession HTTP Session handle
* @param[in] *pSearchClue Search clue
* @param[out] *pHeaderBuffer A pointer to a buffer that will be filled with the header name and value
* @param[out] *nLength Count of the bytes that were received in this operation
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientFindFirstHeader (HTTP_SESSION_HANDLE pSession, CHAR *pSearchClue,CHAR *pHeaderBuffer, UINT32 *nLength);
/**
* @brief Find the next header.
*
* @param[in] pSession HTTP Session handle
* @param[out] *pHeaderBuffer A pointer to a buffer that will be filled with the header name and value
* @param[out] *nLength Count of the bytes that were received in this operation
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientGetNextHeader (HTTP_SESSION_HANDLE pSession, CHAR *pHeaderBuffer, UINT32 *nLength);
/**
* @brief Terminate a headers search session
*
* @param[in] pSession HTTP Session handle
*
* @retval HTTP_CLIENT_SUCCESS success
* @retval other failed
*
* @note None
*/
UINT32 HTTPClientFindCloseHeader (HTTP_SESSION_HANDLE pSession);
#if TLS_CONFIG_HTTP_CLIENT_TASK
/**
* @brief initialize task of the http client
*
* @param None
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int http_client_task_init(void);
/**
* @brief post message to the task of http client
*
* @param[in] msg pointer to the message
*
* @retval ERR_OK success
* @retval other failed
*
* @note None
*/
int http_client_post(http_client_msg * msg);
#endif /* TLS_CONFIG_HTTP_CLIENT_TASK */
/**
* @}
*/
/**
* @}
*/
#endif /* WM_HTTP_CLIENT_H */
+15
View File
@@ -0,0 +1,15 @@
/**
* @file wm_netif.h
*
* @brief ETHERNET INIT Interface
*
* @author winnermicro
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_NETIF_H
#define WM_NETIF_H
#include "wm_config.h"
#include "wm_netif2.0.3.h"
#endif /* WM_NETIF_H */
+437
View File
@@ -0,0 +1,437 @@
/**
* @file wm_netif2.0.3.h
*
* @brief netif203 module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_NETIF2_0_3_H
#define WM_NETIF2_0_3_H
#include "wm_config.h"
#include "wm_type_def.h"
#include "wm_sockets.h"
#include "wm_wifi.h"
#include "wm_params.h"
/** MACRO for callback EVENT to join AP or create soft-AP successfully */
#define NETIF_WIFI_JOIN_SUCCESS 0x1
/** MACRO for callback EVENT to fail to join AP */
#define NETIF_WIFI_JOIN_FAILED 0x2
/** MACRO for callback EVENT to disconnect from AP or destroy soft-AP */
#define NETIF_WIFI_DISCONNECTED 0x3
/** MACRO for callbck EVENT to get IP address */
#define NETIF_IP_NET_UP 0x4
/** MACRO for callback EVNET to create AP successfully */
#define NETIF_WIFI_SOFTAP_SUCCESS 0x5
/** MACRO for callback EVNET to create soft-AP failed */
#define NETIF_WIFI_SOFTAP_FAILED 0x6
/** MACRO for callback EVNET to close soft-AP */
#define NETIF_WIFI_SOFTAP_CLOSED 0x7
/** MACRO for callback EVNET to inform soft ap's net */
#define NETIF_IP_NET2_UP 0x8
#define NETIF_IPV6_NET_UP 0x9
/** These are the values for ip_addr_t.type */
#define IPADDR_TYPE_V4 0U
#define IPADDR_TYPE_V6 6U
#define IPADDR_TYPE_ANY 46U
#define IPV6_ADDR_MAX_NUM 3
#if 0
struct ip_addr {
u32_t addr;
};
typedef struct ip_addr ip_addr_t;
#endif
#if 0
struct ip4_addr {
u32_t addr;
};
typedef struct ip4_addr ip4_addr_t;
struct ip6_addr {
u32_t addr[4];
};
typedef struct ip6_addr ip6_addr_t;
#if (TLS_CONFIG_IPV4 && TLS_CONFIG_IPV6)
typedef struct _ip_addr {
union {
ip6_addr_t ip6;
ip4_addr_t ip4;
} u_addr;
u8_t type;
} ip_addr_t;
#else
#if TLS_CONFIG_IPV4
typedef ip4_addr_t ip_addr_t;
#else
typedef ip6_addr_t ip_addr_t;
#endif
#endif
#endif
struct tls_ethif {
ip_addr_t ip_addr;
ip_addr_t netmask;
ip_addr_t gw;
#if TLS_CONFIG_IPV6
ip_addr_t ip6_addr[IPV6_ADDR_MAX_NUM];
#endif
ip_addr_t dns1;
ip_addr_t dns2;
u8 status; //0:net down; 1:net up
#if TLS_CONFIG_IPV6
u8 ipv6_status[IPV6_ADDR_MAX_NUM]; //0:net down; 1:net up
#endif
};
//type defination of netif status changed callback.
typedef void (*tls_netif_status_event_fn)(u8 status);
/**
* @defgroup APP_APIs APP APIs
* @brief APP APIs
*/
/**
* @addtogroup APP_APIs
* @{
*/
/**
* @defgroup NETIF_APIs NETIF APIs
* @brief network interface APIs
*/
/**
* @addtogroup NETIF_APIs
* @{
*/
/**
* @brief This function is used to initialize TCP/IP Stack
*
* @param[in] None
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_ethernet_init(void);
/**
* @brief This function is used to get IP information stored in
tls_ethif struct
*
* @param[in] None
*
* @retval tls_ethif * Pointer to struct tls_ethif
*
* @note None
*/
struct tls_ethif * tls_netif_get_ethif(void);
/**
* @brief This function is used to set tls_ethif status
*
* @param[in] status net status, 0-up, 1-down
*
* @return None
*
* @note None
*/
void tls_netif_set_status(u8 status);
/**
* @brief This function is used to start DHCP Client
*
* @param[in] None
*
* @retval 0 success
* @retval Minus failed
*
* @note None
*/
err_t tls_dhcp_start(void);
/**
* @brief This function is used to stop DHCP client
*
* @param[in] None
*
* @retval 0 success
* @retval Minus failed
*
* @note None
*/
err_t tls_dhcp_stop(void);
/**
* @brief This function is used to change IP information
*
* @param[in] *ipaddr IP address
* @param[in] *netmask netmask
* @param[in] *gw default gateway
*
* @retval 0 success
* @retval Minus failed
*
* @note None
*/
err_t tls_netif_set_addr(ip_addr_t *ipaddr,
ip_addr_t *netmask,
ip_addr_t *gw);
/**
* @brief This function is used to set dns servers
*
* @param[in] numdns index of the DNS server to set
must be < DNS_MAX_SERVERS
* @param[in] *dnsserver IP address of the DNS server to set
*
* @return None
*
* @note None
*/
void tls_netif_dns_setserver(u8 numdns, ip_addr_t *dnsserver);
/**
* @brief This function is used to bring up an interface,available
for processing traffic
*
* @param[in] None
*
* @retval 0 success
* @retval Minus failed
*
* @note None
*/
err_t tls_netif_set_up(void);
/**
* @brief This function is used to bring down an interface,disabling
any traffic processing
*
* @param[in] None
*
* @retval 0 success
* @retval Minus failed
*
* @note None
*/
err_t tls_netif_set_down(void);
/**
* @brief This function is used to add netif status changed callback
to event list,if exists, do nothing
*
* @param[in] event_fn pointer to tls_netif_status_event_fn
*
* @retval 0 success
* @retval Minus failed
*
* @note None
*/
err_t tls_netif_add_status_event(tls_netif_status_event_fn event_fn);
/**
* @brief This function is used to remove netif status changed
callback function from event list,if not exists, do nothing
*
* @param[in] event_fn pointer to tls_netif_status_event_fn
*
* @retval 0 success
* @retval Minus failed
*
* @note None
*/
err_t tls_netif_remove_status_event(tls_netif_status_event_fn event_fn);
/**
* @brief This function is used to get pointer of netif
*
* @param[in] None
*
* @retval pointer of netif
*
* @note None
*/
struct netif *tls_get_netif(void);
#if TLS_CONFIG_AP
/**
* @brief Start DHCP Server for a network interface
* *
* @retval DHCPS_ERR_SUCCESS - No error
* @retval DHCPS_ERR_MEM - Out of memory
* @retval DHCPS_ERR_LINKDOWN - The NI is inactive
*
* @note None
*/
INT8S tls_dhcps_start(void);
/**
* @brief This function is used to stop DHCP Server
*
* @param[in] None
*
* @retval None
*
* @note None
*/
void tls_dhcps_stop(void);
/**
* @brief Start the dns server's service
* *
* @retval DHCPS_ERR_SUCCESS - No error
* @retval DHCPS_ERR_MEM - Out of memory
* @retval DHCPS_ERR_LINKDOWN - The NI is inactive
* @retval DNSS_ERR_PARAM - Input parameter error
*
* @note None
*/
INT8S tls_dnss_start(INT8U * DnsName);
/**
* @brief Stop the dns server's service
*
* @param[in] None
*
* @retval None
*
* @note None
*/
void tls_dnss_stop(void);
/**
* @brief Get station's ip address by mac address
*
* @param[in] mac station's mac address
*
* @retval ip_addr station's ip address
*
* @note None
*/
ip_addr_t *tls_dhcps_getip(const u8_t *mac);
/**
* @brief Get station's mac address by ip address
*
* @param[in] ip station's ip address
*
* @retval u8* station's mac address
*
* @note None
*/
u8 *tls_dhcps_getmac(const ip_addr_t *ip);
#endif //TLS_CONFIG_AP
#if TLS_CONFIG_RMMS
/**
* @brief Start remote manager server.
* *
* @retval DHCPS_ERR_SUCCESS - No error
* @retval DHCPS_ERR_MEM - Out of memory
* @retval DHCPS_ERR_LINKDOWN - The NIF is inactive
*
* @note None
*/
INT8S tls_rmms_start(void);
/**
* @brief Disable remote manager server
*
* @param[in] None
*
* @retval None
*
* @note None
*/
void tls_rmms_stop(void);
#endif
#if TLS_CONFIG_AP
/**
* @brief This is used to bring up an interface for APSTA,available
for processing traffic
*
* @param[in] None
*
* @retval 0 success
* @retval Minus failed
*
* @note Can only be used at APSTA mode
*/
err_t tls_netif2_set_up(void);
/**
* @brief This function is used to bring down an interface for APSTA, disabling
any traffic processing
*
* @param[in] None
*
* @retval 0 success
* @retval Minus failed
*
* @note Can only be used at APSTA mode
*/
err_t tls_netif2_set_down(void);
/**
* @brief This function is used to change IP information for
a network interface for APSTA
*
* @param[in] *ipaddr IP address
* @param[in] *netmask netmask
* @param[in] *gw default gateway
*
* @retval 0 success
* @retval Minus failed
*
* @note Can only be used at APSTA mode
*/
err_t tls_netif2_set_addr(ip_addr_t *ipaddr,
ip_addr_t *netmask,
ip_addr_t *gw);
/***************************************************************************
* Function: tls_dhcps_setdns
* Description: Set dhcp server's dns address.
*
* Input: numdns: the index of the DNS server to set must be less than DNS_MAX_SERVERS
*
* Output: None
*
* Return: None
*
* Date : 2015-3-10
****************************************************************************/
/**
* @brief Set dhcp server's dns address
*
* @param[in] numdns the index of the DNS server to set must be less than DNS_MAX_SERVERS
*
* @retval None
*
* @note Can only be used at APSTA mode
*/
void tls_dhcps_setdns(u8_t numdns);
#endif
/**
* @}
*/
/**
* @}
*/
#endif //WM_NETIF_H
+80
View File
@@ -0,0 +1,80 @@
/**
* @file wm_ntp.h
*
* @brief ntp module
*
* @author dave
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_NTP_H
#define WM_NTP_H
#include "wm_type_def.h"
/**
* @defgroup APP_APIs APP APIs
* @brief APP APIs
*/
/**
* @addtogroup APP_APIs
* @{
*/
/**
* @defgroup NTP_APIs NTP APIs
* @brief NTP APIs
*/
/**
* @addtogroup NTP_APIs
* @{
*/
/**
* @brief This function is used to get network time.
*
* @param None
*
* @retval time value
*
* @note None
*/
u32 tls_ntp_client(void);
/**
* @brief This function is used to set ntp servers.
*
* @param[in] *ipaddr xxx.xxx.xxx.xxx
* @param[in] server_no max num is three
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_ntp_set_server(char *ipaddr, int server_no);
/**
* @brief This function is used to query params of the ntp servers
*
*
* @retval WM_SUCCESS success
* @retval WM_FAILED failed
*
* @note None
*/
int tls_ntp_query_sntpcfg(void);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_NTP_H */
+159
View File
@@ -0,0 +1,159 @@
#ifndef _SSL_SERVER_H_
#define _SSL_SERVER_H_
#include "wm_config.h"
#include "HTTPClientWrapper.h"
#if 1//for doxygen
//#if TLS_CONFIG_SERVER_SIDE_SSL
#if TLS_CONFIG_USE_POLARSSL
#include "polarssl/config.h"
#include "polarssl/ssl.h"
#error "PolaSSL does not support ssl server now!"
#elif TLS_CONFIG_USE_MBEDTLS
typedef void tls_ssl_key_t;
#endif
//key type for tls_ssl_server_init
#define KEY_RSA 1
#define KEY_ECC 2
#define KEY_DH 3
/**
* @defgroup APP_APIs APP APIs
* @brief APP APIs
*/
/**
* @addtogroup APP_APIs
* @{
*/
/**
* @defgroup SSL_SERVER_APIs SSL SERVER APIs
* @brief SSL Server APIs
*/
/**
* @addtogroup SSL_SERVER_APIs
* @{
*/
/**
* @brief This function is used to initialize SSL Server
*
* @param[in] *arg proto version: 0 - sslv3
* 1 - tls1.0
* 2 - tls1.1
* 3 - tls1.2
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_ssl_server_init(void * arg);
/**
* @brief This function is used to set SSL keys
*
* @param[in] **keys SSL key pointer
* @param[in] *certBuf SSL certificate
* @param[in] certLen SSL certificate length
* @param[in] *privBuf SSL private key
* @param[in] privLen SSL private key length
* @param[in] *CAbuf CA certificate
* @param[in] CAlen CA certificate length
* @param[in] keyType key type: KEY_RSA,KEY_ECC,KEY_DH
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_ssl_server_load_keys(tls_ssl_key_t **keys, unsigned char *certBuf,
int32 certLen, unsigned char *privBuf, int32 privLen,
unsigned char *CAbuf, int32 CAlen, int keyType);
/**
* @brief This function is used to set SSL Server working
*
* @param[in] **ssl_p SSL hanlde
* @param[in] fd socket number
* @param[in] *keys SSL keys
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_ssl_server_handshake(tls_ssl_t **ssl_p, int fd, tls_ssl_key_t *keys);
/**
* @brief This function is used to send data
*
* @param[in] *ssl SSL hanlde
* @param[in] s socket number
* @param[in] *sndbuf send buffer
* @param[in] len send length
* @param[in] flags some flags
*
* @retval > 0 success
* @retval <=0 failed
*
* @note None
*/
int tls_ssl_server_send(tls_ssl_t *ssl, int s,char *sndbuf, int len,int flags);
/**
* @brief This function is used to receive data
*
* @param[in] *ssl SSL hanlde
* @param[in] s socket number
* @param[in] *buf receive buffer
* @param[in] len receive buffer length
* @param[in] flags some flags
*
* @retval > 0 success
* @retval <=0 failed
*
* @note None
*/
int tls_ssl_server_recv(tls_ssl_t *ssl,int s,char *buf, int len,int flags);
/**
* @brief This function is used to close connection
*
* @param[in] *ssl SSL hanlde
* @param[in] s socket number
*
* @return None
*
* @note None
*/
void tls_ssl_server_close_conn(tls_ssl_t *ssl, int s);
/**
* @brief This function is used to close SSL Server
*
* @param[in] *keys SSL keys
*
* @retval 0 success
* @retval other failed
*
* @note None
*/
int tls_ssl_server_close(tls_ssl_key_t * keys);
/**
* @}
*/
/**
* @}
*/
#endif /*TLS_CONFIG_SERVER_SIDE_SSL*/
#endif /*_SSL_SERVER_H_*/
+65
View File
@@ -0,0 +1,65 @@
/**
* @file wm_webserver.h
*
* @brief WEB SERVER
*
* @author winnermicro
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef __WEBSERVER_H__
#define __WEBSERVER_H__
/**
* @defgroup APP_APIs APP APIs
* @brief APP APIs
*/
/**
* @addtogroup APP_APIs
* @{
*/
/**
* @defgroup WEB_APIs WEB APIs
* @brief WEB server APIs
*/
/**
* @addtogroup WEB_APIs
* @{
*/
/**
* @brief This function is used to start WEB SERVER service
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_webserver_init(void);
/**
* @brief This function is used to deinit WEB SERVER service
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_webserver_deinit(void);
/**
* @}
*/
/**
* @}
*/
#endif /*__WEBSERVER_H__*/
+291
View File
@@ -0,0 +1,291 @@
/**
* @file wm_wifi_oneshot.h
*
* @brief Wi-Fi OneShot
*
* @author winnermicro
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_WIFI_ONESHOT_H
#define WM_WIFI_ONESHOT_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wm_type_def.h>
#if (GCC_COMPILE==1)
#include "wm_ieee80211_gcc.h"
#else
#include <wm_ieee80211.h>
#endif
#include "wm_config.h"
#include "wm_bt_config.h"
/** DEBUG USE MAC FILTER START */
#define CONFIG_ONESHOT_MAC_FILTER 0
extern int tls_filter_module_srcmac(u8 *mac);
#define ONESHOT_ON 1
#define ONESHOT_OFF 0
/* ONE SHOT */
/** UDP MULTICAST ONE SHOT */
#define TLS_CONFIG_UDP_ONE_SHOT ONESHOT_ON
/** WinnerMicro ONSHOT */
#define TLS_CONFIG_UDP_LSD_SPECIAL (ONESHOT_ON&& TLS_CONFIG_UDP_ONE_SHOT)
/** AP ONESHOT */
#define TLS_CONFIG_AP_MODE_ONESHOT (ONESHOT_ON && TLS_CONFIG_AP)
#define TLS_CONFIG_WEB_SERVER_MODE (ONESHOT_ON && TLS_CONFIG_AP_MODE_ONESHOT)
#define TLS_CONFIG_SOCKET_MODE (ONESHOT_ON && TLS_CONFIG_AP_MODE_ONESHOT)
/** AIRKISS ONESHOT */
#define TLS_CONFIG_AIRKISS_MODE_ONESHOT (ONESHOT_OFF && TLS_CONFIG_UDP_ONE_SHOT)
#define AIRKISS_USE_SELF_WRITE 1
/** BLE ONESHOT */
#define TLS_CONFIG_BLE_WIFI_ONESHOT (ONESHOT_ON && (WM_BLE_INCLUDED == CFG_ON || WM_NIMBLE_INCLUDED == CFG_ON))
typedef enum{
ONESHOT_SCAN_START,
ONESHOT_SCAN_FINISHED,
ONESHOT_SWITCH_CHANNEL,
ONESHOT_STOP_TMP_CHAN_SWITCH,
ONESHOT_STOP_CHAN_SWITCH,
ONESHOT_HANDSHAKE_TIMEOUT,
ONESHOT_RECV_TIMEOUT,
ONESHOT_RECV_ERR,
ONESHOT_STOP_DATA_CLEAR,
ONESHOT_NET_UP,
AP_SOCK_S_MSG_SOCKET_RECEIVE_DATA,
AP_WEB_S_MSG_RECEIVE_DATA,
AP_SOCK_S_MSG_SOCKET_CREATE,
AP_SOCK_S_MSG_WJOIN_FAILD,
}ONESHOT_MSG_ENUM;
/**
* @defgroup APP_APIs APP APIs
* @brief APP APIs
*/
/**
* @addtogroup APP_APIs
* @{
*/
/**
* @defgroup Oneshot_APIs Oneshot APIs
* @brief Wi-Fi oneshot APIs
*/
/**
* @addtogroup Oneshot_APIs
* @{
*/
/**
* @brief This function is used to set oneshot flag.
*
* @param[in] flag, 0: one shot closed
* 1: one shot open
* 2: AP+socket
* 3: AP+WEBSERVER
* 4: bt
*
* @param[out] None
*
* @retval 0: success
* -1: failed
*
* @note None
*/
int tls_wifi_set_oneshot_flag(u8 flag);
/**
* @brief This function is used to get oneshot flag.
*
* @param[in] None
*
* @param[out] None
*
* @retval 0: one shot closed
* 1: one shot open
* 2: AP+socket
* 3: AP+WEBSERVER
* 4: bt
*
* @note None
*/
int tls_wifi_get_oneshot_flag(void);
/**
* @}
*/
/**
* @}
*/
/**
* @brief Handle wild packets coming from the air.
*
* @param[in] *hdr point to ieee80211 data header
* @param[in] data_len data len of ieee80211 data
*
* @retval no mean
*
* @note None
*/
u8 tls_wifi_dataframe_recv(struct ieee80211_hdr *hdr, u32 data_len);
#if TLS_CONFIG_AIRKISS_MODE_ONESHOT
/**
* @brief This function is used to acknowledge app when airkiss process is done.
*
* @param[in] None
*
* @return None
*
* @note None
*/
void oneshot_airkiss_send_reply(void);
/**
* @brief This function is used to deal with airkiss's
wild packet
*
* @param[in] *data ieee80211 packet
* @param[in] data_len packet length
*
* @return None
*
* @note None
*/
void tls_airkiss_recv(u8 *data, u16 data_len);
/**
* @brief This function is used to start airkiss
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_airkiss_start(void);
/**
* @brief This function is used to stop airkiss
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_airkiss_stop(void);
/**
* @brief This function is used to change channel for airkiss
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_oneshot_airkiss_change_channel(void);
#endif /*TLS_CONFIG_AIRKISS_MODE_ONESHOT*/
/**
* @brief This function is used to init oneshot task
*
* @param[in] None
*
* @return None
*
* @note Not in use now
*/
int wm_oneshot_task_init(void);
/**
* @brief This function is used to stop oneshot timer
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_oneshot_switch_channel_tim_stop(struct ieee80211_hdr *hdr);
/**
* @brief This function is used to stop oneshot temp timer
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_oneshot_switch_channel_tim_temp_stop(void);
/**
* @brief handle if use bssid to connect wifi.
*
* @param[in] *ssid : ap name to connect
* @param[in] *ssid_len: ap name's length to connect
* @param[in] *bssid : ap bssid
*
* @retval no mean
*
* @note None
*/
int tls_oneshot_if_use_bssid(u8 *ssid, u8 *ssid_len, u8 *bssid);
/**
* @brief Find channel according to ssid
*
* @param[in] *ssid ssid to be compared
* @param[in] ssid_len ssid length
* @param[out] chlist chlist to be add according to ssid info
*
* @retval None
*
* @note None
*/
void tls_oneshot_find_chlist(u8 *ssid, u8 ssid_len, u16 *chlist);
/**
* @brief This function is to deal with oneshot event according netif status.
*
* @param[in] status:net status
*
* @param[out] None
*
* @retval None
*
* @note None
*/
void wm_oneshot_netif_status_event(u8 status );
#if TLS_CONFIG_WEB_SERVER_MODE
/**
* @brief This function is used to send web config msg to oneshot task.
*
* @param[in] None
*
* @param[out] None
*
* @retval None
*
* @note None
*/
void tls_oneshot_send_web_connect_msg(void);
#endif
#endif /*WM_WIFI_ONESHOT_H*/
+17
View File
@@ -0,0 +1,17 @@
#ifndef __CSI_CONFIG_H__
#define __CSI_CONFIG_H__
#define CONFIG_CHIP_SL04 1
#define CONFIG_KERNEL_LITEOS 1
//#define CONFIG_KERNEL_FREERTOS 1
//#define CONFIG_KERNEL_NONE 1
#define CONFIG_HAVE_VIC 1
#define CONFIG_SEPARATE_IRQ_SP 1
#define CONFIG_ARCH_INTERRUPTSTACK 4096
#define CONFIG_IRQ_VECTOR_SIZE 256
#define USE_UART0_PRINT 1
#ifdef CONFIG_KERNEL_NONE
#define CONFIG_SYSTEM_SECURE 1
#endif
#endif
File diff suppressed because it is too large Load Diff
+63
View File
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/******************************************************************************
* @file csi_core.h
* @brief CSI Core Layer Header File
* @version V1.0
* @date 02. June 2017
******************************************************************************/
#ifndef _CORE_H_
#define _CORE_H_
#include <stdint.h>
#if defined(__CK801__) || defined(__E801__)
#include <core_801.h>
#elif defined(__CK802__) || defined(__E802__) || defined(__S802__)
#include <core_802.h>
#elif defined(__E803__) || defined(__S803__)
#include <core_803.h>
#elif defined(__CK803__) || defined(__CK804__) || defined(__E804__) || defined(__E804D__) || defined(__E804F__) || defined (__E804DF__)
#include <core_804.h>
#elif defined(__CK805__) || defined(__I805__) || defined(__I805F__)
#include <core_805.h>
#elif defined(__CK610__)
#include <core_ck610.h>
#elif defined(__CK810__) || defined(__C810__) || defined(__C810V__)
#include <core_810.h>
#elif defined(__CK807__) || defined(__C807__) || defined(__C807F__) || defined(__C807FV__)
#include <core_807.h>
#elif defined(__riscv)
#include <core_rv32.h>
#endif
#ifdef __riscv
#include <csi_rv32_gcc.h>
#else
#include <csi_gcc.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /* _CORE_H_ */
File diff suppressed because it is too large Load Diff
+351
View File
@@ -0,0 +1,351 @@
/******************************************************************************
* @file csky_common_tables.h
* @brief This file has extern declaration for common tables like
* Bitreverse, reciprocal etc which are used across different functions.
* @version V1.0
* @date 20. Dec 2016
******************************************************************************/
/* ---------------------------------------------------------------------------
* Copyright (C) 2016 CSKY Limited. All rights reserved.
*
* Redistribution and use of this software in source and binary forms,
* with or without modification, are permitted provided that the following
* conditions are met:
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of CSKY Ltd. nor the names of CSKY's contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission of CSKY Ltd.
*
* 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 OWNER 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 _CSKY_COMMON_TABLES_H
#define _CSKY_COMMON_TABLES_H
#include "csky_math.h"
extern const uint16_t cskyBitRevTable[1024];
extern const q15_t cskyRecipTableQ15[64];
extern const q31_t cskyRecipTableQ31[64];
extern const float32_t twiddleCoef_16[32];
extern const float32_t twiddleCoef_32[64];
extern const float32_t twiddleCoef_64[128];
extern const float32_t twiddleCoef_128[256];
extern const float32_t twiddleCoef_256[512];
extern const float32_t twiddleCoef_512[1024];
extern const float32_t twiddleCoef_1024[2048];
extern const float32_t twiddleCoef_2048[4096];
extern const float32_t twiddleCoef_4096[8192];
extern const q31_t twiddleCoef_16_q31[24];
extern const q31_t twiddleCoef_32_q31[48];
extern const q31_t twiddleCoef_64_q31[96];
extern const q31_t twiddleCoef_128_q31[192];
extern const q31_t twiddleCoef_256_q31[384];
extern const q31_t twiddleCoef_512_q31[768];
extern const q31_t twiddleCoef_1024_q31[1536];
extern const q31_t twiddleCoef_2048_q31[3072];
extern const q31_t twiddleCoef_4096_q31[6144];
extern const q15_t twiddleCoef_16_q15[24];
extern const q15_t twiddleCoef_32_q15[48];
extern const q15_t twiddleCoef_64_q15[96];
extern const q15_t twiddleCoef_128_q15[192];
extern const q15_t twiddleCoef_256_q15[384];
extern const q15_t twiddleCoef_512_q15[768];
extern const q15_t twiddleCoef_1024_q15[1536];
extern const q15_t twiddleCoef_2048_q15[3072];
extern const q15_t twiddleCoef_4096_q15[6144];
extern const float32_t twiddleCoef_rfft_32[32];
extern const float32_t twiddleCoef_rfft_64[64];
extern const float32_t twiddleCoef_rfft_128[128];
extern const float32_t twiddleCoef_rfft_256[256];
extern const float32_t twiddleCoef_rfft_512[512];
extern const float32_t twiddleCoef_rfft_1024[1024];
extern const float32_t twiddleCoef_rfft_2048[2048];
extern const float32_t twiddleCoef_rfft_4096[4096];
extern const float32_t twiddleCoef_rfft_8192[8192];
extern const q15_t realCoefAQ15_8192[8192];
extern const q31_t realCoefAQ31_8192[8192];
/*Tables for RFFT.*/
extern const q15_t ALIGN4 realCoefAQ15_32[32];
extern const q15_t ALIGN4 realCoefAQ15_64[64];
extern const q15_t ALIGN4 realCoefAQ15_128[128];
extern const q15_t ALIGN4 realCoefAQ15_256[256];
extern const q15_t ALIGN4 realCoefAQ15_512[512];
extern const q15_t ALIGN4 realCoefAQ15_1024[1024];
extern const q15_t ALIGN4 realCoefAQ15_2048[2048];
extern const q15_t ALIGN4 realCoefAQ15_4096[4096];
extern const q31_t realCoefAQ31_32[32];
extern const q31_t realCoefAQ31_64[64];
extern const q31_t realCoefAQ31_128[128];
extern const q31_t realCoefAQ31_256[256];
extern const q31_t realCoefAQ31_512[512];
extern const q31_t realCoefAQ31_1024[1024];
extern const q31_t realCoefAQ31_2048[2048];
extern const q31_t realCoefAQ31_4096[4096];
extern const float32_t realCoefA[8192];
extern const float32_t realCoefB[8192];
/*Tables for DCT4*/
extern const q15_t ALIGN4 WeightsQ15_128[128+2];
extern const q15_t ALIGN4 WeightsQ15_512[512+2];
extern const q15_t ALIGN4 WeightsQ15_2048[2048+2];
extern const q15_t ALIGN4 WeightsQ15_8192[8192+2];
extern const q15_t ALIGN4 cos_factorsQ15_128[128];
extern const q15_t ALIGN4 cos_factorsQ15_512[512];
extern const q15_t ALIGN4 cos_factorsQ15_2048[2048];
extern const q15_t ALIGN4 cos_factorsQ15_8192[8192];
extern const q31_t WeightsQ31_128[128+2];
extern const q31_t WeightsQ31_512[512+2];
extern const q31_t WeightsQ31_2048[2048+2];
extern const q31_t WeightsQ31_8192[8192+2];
extern const q31_t cos_factorsQ31_128[128];
extern const q31_t cos_factorsQ31_512[512];
extern const q31_t cos_factorsQ31_2048[2048];
extern const q31_t cos_factorsQ31_8192[8192];
extern const float32_t Weights_128[128+2];
extern const float32_t Weights_512[512+2];
extern const float32_t Weights_2048[2048+2];
extern const float32_t Weights_8192[8192+2];
extern const float32_t cos_factors_128[128];
extern const float32_t cos_factors_512[512];
extern const float32_t cos_factors_2048[2048];
extern const float32_t cos_factors_8192[8192];
/* floating-point bit reversal tables */
#define CSKYBITREVINDEXTABLE__16_TABLE_LENGTH ((uint16_t)20 )
#define CSKYBITREVINDEXTABLE__32_TABLE_LENGTH ((uint16_t)48 )
#define CSKYBITREVINDEXTABLE__64_TABLE_LENGTH ((uint16_t)56 )
#define CSKYBITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208 )
#define CSKYBITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440 )
#define CSKYBITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448 )
#define CSKYBITREVINDEXTABLE1024_TABLE_LENGTH ((uint16_t)1800)
#define CSKYBITREVINDEXTABLE2048_TABLE_LENGTH ((uint16_t)3808)
#define CSKYBITREVINDEXTABLE4096_TABLE_LENGTH ((uint16_t)4032)
extern const uint16_t cskyBitRevIndexTable16[CSKYBITREVINDEXTABLE__16_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable32[CSKYBITREVINDEXTABLE__32_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable64[CSKYBITREVINDEXTABLE__64_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable128[CSKYBITREVINDEXTABLE_128_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable256[CSKYBITREVINDEXTABLE_256_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable512[CSKYBITREVINDEXTABLE_512_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable1024[CSKYBITREVINDEXTABLE1024_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable2048[CSKYBITREVINDEXTABLE2048_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable4096[CSKYBITREVINDEXTABLE4096_TABLE_LENGTH];
/* fixed-point bit reversal tables */
#define CSKYBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH ((uint16_t)12 )
#define CSKYBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH ((uint16_t)24 )
#define CSKYBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH ((uint16_t)56 )
#define CSKYBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH ((uint16_t)112 )
#define CSKYBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH ((uint16_t)240 )
#define CSKYBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH ((uint16_t)480 )
#define CSKYBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH ((uint16_t)992 )
#define CSKYBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH ((uint16_t)1984)
#define CSKYBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH ((uint16_t)4032)
extern const uint16_t cskyBitRevIndexTable_fixed_16[CSKYBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable_fixed_32[CSKYBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable_fixed_64[CSKYBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable_fixed_128[CSKYBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable_fixed_256[CSKYBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable_fixed_512[CSKYBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable_fixed_1024[CSKYBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable_fixed_2048[CSKYBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH];
extern const uint16_t cskyBitRevIndexTable_fixed_4096[CSKYBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH];
/* Tables for Fast Math Sine and Cosine */
extern const float32_t sinTable_f32[FAST_MATH_TABLE_SIZE + 1];
extern const q31_t sinTable_q31[FAST_MATH_TABLE_SIZE + 1];
extern const q15_t sinTable_q15[FAST_MATH_TABLE_SIZE + 1];
/*Table for Fast math pow*/
extern const log2_cof1 ui;
extern const log2_cof2 vj;
extern const exp_cof1 coar;
extern const exp_cof2 fine;
/*Table for Fast math pow2*/
extern const float64_t exp2_accuratetable[512];
extern const float32_t exp2_deltatable[512];
/*Table for Fast math pow2*/
extern const mynumber Iu[182];
extern const mynumber Iv[362];
extern const mynumber Lu[182][2];
extern const mynumber Lv[362][2];
/*constant for Fast math*/
const static mynumber
nZERO = {{0, 0x80000000}}, /* -0.0 */
INF = {{0x00000000, 0x7ff00000}}, /* INF */
nINF = {{0x00000000, 0xfff00000}}, /* -INF */
sqrt_2 = {{0x667f3bcc, 0x3ff6a09e}}, /* sqrt(2) */
ln2a = {{0xfefa3800, 0x3fe62e42}}, /* ln(2) 43 bits */
ln2b = {{0x93c76730, 0x3d2ef357}}, /* ln(2)-ln2a */
bigu = {{0xfffffd2c, 0x4297ffff}}, /* 1.5*2**42 -724*2**-10 */
bigv = {{0xfff8016a, 0x4207ffff}}, /* 1.5*2**33-1+362*2**-19 */
t52 = {{0x00000000, 0x43300000}}, /* 2**52 */
two52e = {{0x000003ff, 0x43300000}}, /* 2**52' */
//nan = {{0x00000000, 0x7ff80000}}, /* NAN */
t256 = {{0, 0x4ff00000}}, /* 2^256 */
ln_two1 = {{0xFEFA3800, 0x3FE62E42}}, /* 0.69314718055989033 */
ln_two2 = {{0x93C76730, 0x3D2EF357}}, /* 5.4979230187083712e-14*/
log2e = {{0x652B82FE, 0x3FF71547}}, /* 1.4426950408889634 */
ep2 = {{0x000004DC, 0x3FE00000}}, /* 0.50000000000013811 */
ep3 = {{0x55555A0F, 0x3FC55555}}, /* 0.16666666666670024 */
three33 = {{0, 0x42180000}}, /* 25769803776 */
three51 = {{0, 0x43380000}}; /* 6755399441055744 */
const static float64_t
p2 = -0.5, p3 = 3.3333333333333333333e-1, p4 = -0.25,
q2 = -0.5, q3 = 3.3333333333331404e-01, q4 = -2.4999999999996436e-01,
q5 = 2.0000010500004459e-01, q6 = -1.6666678916688004e-01,
r3 = 3.33333333333333333372884096563030E-01,
r4 = -2.50000000000000000213574153875908E-01,
r5 = 1.99999999999683593814072199830603E-01,
r6 = -1.66666666666065494878165510225378E-01,
r7 = 1.42857517857114380606360005067609E-01,
r8 = -1.25000449999974370683775964001702E-01,
s3 = 0.333251953125000000e0,
ss3 = 8.138020833333333333e-05,
s4 = -2.500000000000000000e-01,
s5 = 1.999999999999960937e-01,
s6 = -1.666666666666592447e-01,
s7 = 1.428571845238194705e-01;
// s8 = -1.250000500000149097e-01;
const static float64_t huge = 1.0e300, tiny = 1.0e-300;
const static float64_t err_0 = 1.000014, err_1 = 0.000016, zero = 0.0;
const static q31_t bigint = 0x40862002,
badint = 0x40876000, smallint = 0x3C8fffff;
const static q31_t hugeint = 0x7fffffff, infint = 0x7ff00000;
static const mynumber
/* polynomial I */
a2 = {{0x0001aa8f, 0xbfe00000} }, /* -0.500... */
a3 = {{0x55588d2e, 0x3fd55555} }, /* 0.333... */
/*polynomial II */
b0 = {{0x55555555, 0x3fd55555} }, /* 0.333... */
b1 = {{0xffffffbb, 0xbfcfffff} }, /* -0.249... */
b2 = {{0x9999992f, 0x3fc99999} }, /* 0.199... */
b3 = {{0x556503fd, 0xbfc55555} }, /* -0.166... */
b4 = {{0x925b3d62, 0x3fc24924} }, /* 0.142... */
b5 = {{0x160472fc, 0xbfbffffe} }, /* -0.124... */
b6 = {{0x25db58ac, 0x3fbc71c5} }, /* 0.111... */
b7 = {{0x11a2a61c, 0xbfb9a4ac} }, /* -0.100... */
b8 = {{0x0df2b591, 0x3fb75077} }, /* 0.091... */
/*polynomial III */
c2 = {{0x00000000, 0xbfe00000} }, /* -1/2 */
c3 = {{0x55555555, 0x3fd55555} }, /* 1/3 */
c4 = {{0x00000000, 0xbfd00000} }, /* -1/4 */
c5 = {{0x9999999a, 0x3fc99999} }, /* 1/5 */
/*polynomial IV */
d2 = {{0x00000000, 0xbfe00000} }, /* -1/2 */
dd2 = {{0x00000000, 0x00000000} }, /* -1/2-d2 */
d3 = {{0x55555555, 0x3fd55555} }, /* 1/3 */
dd3 = {{0x55555555, 0x3c755555} }, /* 1/3-d3 */
d4 = {{0x00000000, 0xbfd00000} }, /* -1/4 */
dd4 = {{0x00000000, 0x00000000} }, /* -1/4-d4 */
d5 = {{0x9999999a, 0x3fc99999} }, /* 1/5 */
dd5 = {{0x9999999a, 0xbc699999} }, /* 1/5-d5 */
d6 = {{0x55555555, 0xbfc55555} }, /* -1/6 */
dd6 = {{0x55555555, 0xbc655555} }, /* -1/6-d6 */
d7 = {{0x92492492, 0x3fc24924} }, /* 1/7 */
dd7 = {{0x92492492, 0x3c624924} }, /* 1/7-d7 */
d8 = {{0x00000000, 0xbfc00000} }, /* -1/8 */
dd8 = {{0x00000000, 0x00000000} }, /* -1/8-d8 */
d9 = {{0x1c71c71c, 0x3fbc71c7} }, /* 1/9 */
dd9 = {{0x1c71c71c, 0x3c5c71c7} }, /* 1/9-d9 */
d10 = {{0x9999999a, 0xbfb99999} }, /* -1/10 */
dd10 = {{0x9999999a, 0x3c599999} }, /* -1/10-d10 */
d11 = {{0x745d1746, 0x3fb745d1} }, /* 1/11 */
d12 = {{0x55555555, 0xbfb55555} }, /* -1/12 */
d13 = {{0x13b13b14, 0x3fb3b13b} }, /* 1/13 */
d14 = {{0x92492492, 0xbfb24924} }, /* -1/14 */
d15 = {{0x11111111, 0x3fb11111} }, /* 1/15 */
d16 = {{0x00000000, 0xbfb00000} }, /* -1/16 */
d17 = {{0x1e1e1e1e, 0x3fae1e1e} }, /* 1/17 */
d18 = {{0x1c71c71c, 0xbfac71c7} }, /* -1/18 */
d19 = {{0xbca1af28, 0x3faaf286} }, /* 1/19 */
d20 = {{0x9999999a, 0xbfa99999} }, /* -1/20 */
/*constants */
h1 = {{0x00000000, 0x3fd2e000} }, /* 151/2**9 */
h2 = {{0x00000000, 0x3f669000} }, /* 361/2**17 */
delu = {{0x00000000, 0x3f700000} }, /* 1/2**8 */
delv = {{0x00000000, 0x3ef00000} }, /* 1/2**16 */
e1 = {{0x00000000, 0x3bbcc868} }, /* 6.095e-21 */
e2 = {{0x00000000, 0x3c1138ce} }, /* 2.334e-19 */
e3 = {{0x00000000, 0x3aa1565d} }, /* 2.801e-26 */
e4 = {{0x00000000, 0x39809d88} }, /* 1.024e-31 */
e[4] = {{{0x00000000, 0x37da223a} },/* 1.2e-39 */
{{0x00000000, 0x35c851c4} }, /* 1.3e-49 */
{{0x00000000, 0x2ab85e51} }, /* 6.8e-103 */
{{0x00000000, 0x17383827} }},/* 8.1e-197 */
two54 = {{0x00000000, 0x43500000} }, /* 2**54 */
u03 = {{0xeb851eb8, 0x3f9eb851} }; /* 0.03 */
#define SQRT_2 sqrt_2.x
#define DEL_U delu.x
#define DEL_V delv.x
#define LN2A ln2a.x
#define LN2B ln2b.x
#define E1 e1.x
#define E2 e2.x
#define E3 e3.x
#define E4 e4.x
#define U03 u03.x
#define HALF 0x1.0p-1 /* 1/2 */
#define MHALF -0x1.0p-1 /* -1/2 */
/*coeffient for log2 funtion*/
static const float64_t
ln2 = 0.69314718055994530942,
two54_d = 1.80143985094819840000e+16, /* 43500000 00000000 */
Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */
Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */
Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */
Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */
Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */
Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */
Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
/*coeffient for log10 function*/
static const float64_t
ivln10 = 4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */
log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */
log10_2lo = 3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */
/*constant for log10 function*/
static const float64_t
TWO1023 = 8.988465674311579539e+307,
TWOM1000 = 9.3326361850321887899e-302;
#endif /* CSKY_COMMON_TABLES_H */
+140
View File
@@ -0,0 +1,140 @@
/******************************************************************************
* @file csky_const_structs.h
* @brief This file has constant structs that are initialized for
* user convenience. For example, some can be given as
* arguments to the csky_cfft_f32() function.
* @version V1.0
* @date 20. Dec 2016
******************************************************************************/
/* ---------------------------------------------------------------------------
* Copyright (C) 2016 CSKY Limited. All rights reserved.
*
* Redistribution and use of this software in source and binary forms,
* with or without modification, are permitted provided that the following
* conditions are met:
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of CSKY Ltd. nor the names of CSKY's contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission of CSKY Ltd.
*
* 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 OWNER 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 _CSKY_CONST_STRUCTS_H
#define _CSKY_CONST_STRUCTS_H
#include "csky_math.h"
#include "csky_common_tables.h"
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len16;
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len32;
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len64;
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len128;
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len256;
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len512;
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len1024;
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len2048;
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len4096;
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len16;
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len32;
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len64;
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len128;
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len256;
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len512;
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len1024;
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len2048;
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len4096;
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len16;
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len32;
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len64;
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len128;
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len256;
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len512;
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len1024;
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len2048;
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len4096;
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len32;
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len64;
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len128;
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len256;
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len512;
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len1024;
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len2048;
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len4096;
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len8192;
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len32;
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len64;
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len128;
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len256;
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len512;
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len1024;
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len2048;
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len4096;
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len8192;
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len32;
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len64;
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len128;
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len256;
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len512;
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len1024;
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len2048;
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len4096;
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len8192;
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len32;
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len64;
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len128;
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len256;
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len512;
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len1024;
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len2048;
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len4096;
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len8192;
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len32;
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len64;
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len128;
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len256;
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len512;
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len1024;
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len2048;
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len4096;
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len8192;
extern csky_dct4_instance_q15 csky_dct4_sR_q15_len128;
extern csky_dct4_instance_q15 csky_dct4_sR_q15_len512;
extern csky_dct4_instance_q15 csky_dct4_sR_q15_len2048;
extern csky_dct4_instance_q15 csky_dct4_sR_q15_len8192;
extern csky_dct4_instance_q31 csky_dct4_sR_q31_len128;
extern csky_dct4_instance_q31 csky_dct4_sR_q31_len512;
extern csky_dct4_instance_q31 csky_dct4_sR_q31_len2048;
extern csky_dct4_instance_q31 csky_dct4_sR_q31_len8192;
extern csky_dct4_instance_f32 csky_dct4_sR_f32_len128;
extern csky_dct4_instance_f32 csky_dct4_sR_f32_len512;
extern csky_dct4_instance_f32 csky_dct4_sR_f32_len2048;
extern csky_dct4_instance_f32 csky_dct4_sR_f32_len8192;
#endif
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,140 @@
/******************************************************************************
* @file csky_vdsp2_const_structs.h
* @brief This file has constant structs that are initialized for
* user convenience. For example, some can be given as
* arguments to the csky_vdsp2_cfft_f32() function.
* @version V1.0
* @date 20. Dec 2016
******************************************************************************/
/* ---------------------------------------------------------------------------
* Copyright (C) 2016 CSKY Limited. All rights reserved.
*
* Redistribution and use of this software in source and binary forms,
* with or without modification, are permitted provided that the following
* conditions are met:
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of CSKY Ltd. nor the names of CSKY's contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission of CSKY Ltd.
*
* 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 OWNER 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 _CSKY_CONST_STRUCTS_H
#define _CSKY_CONST_STRUCTS_H
#include "csky_vdsp2_math.h"
#include "csky_common_tables.h"
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len16;
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len32;
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len64;
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len128;
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len256;
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len512;
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len1024;
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len2048;
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len4096;
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len16;
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len32;
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len64;
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len128;
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len256;
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len512;
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len1024;
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len2048;
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len4096;
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len16;
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len32;
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len64;
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len128;
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len256;
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len512;
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len1024;
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len2048;
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len4096;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len32;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len64;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len128;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len256;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len512;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len1024;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len2048;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len4096;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len8192;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len32;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len64;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len128;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len256;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len512;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len1024;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len2048;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len4096;
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len8192;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len32;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len64;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len128;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len256;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len512;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len1024;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len2048;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len4096;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len8192;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len32;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len64;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len128;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len256;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len512;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len1024;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len2048;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len4096;
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len8192;
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len32;
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len64;
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len128;
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len256;
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len512;
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len1024;
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len2048;
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len4096;
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len8192;
extern csky_vdsp2_dct4_instance_q15 csky_vdsp2_dct4_sR_q15_len128;
extern csky_vdsp2_dct4_instance_q15 csky_vdsp2_dct4_sR_q15_len512;
extern csky_vdsp2_dct4_instance_q15 csky_vdsp2_dct4_sR_q15_len2048;
extern csky_vdsp2_dct4_instance_q15 csky_vdsp2_dct4_sR_q15_len8192;
extern csky_vdsp2_dct4_instance_q31 csky_vdsp2_dct4_sR_q31_len128;
extern csky_vdsp2_dct4_instance_q31 csky_vdsp2_dct4_sR_q31_len512;
extern csky_vdsp2_dct4_instance_q31 csky_vdsp2_dct4_sR_q31_len2048;
extern csky_vdsp2_dct4_instance_q31 csky_vdsp2_dct4_sR_q31_len8192;
extern csky_vdsp2_dct4_instance_f32 csky_vdsp2_dct4_sR_f32_len128;
extern csky_vdsp2_dct4_instance_f32 csky_vdsp2_dct4_sR_f32_len512;
extern csky_vdsp2_dct4_instance_f32 csky_vdsp2_dct4_sR_f32_len2048;
extern csky_vdsp2_dct4_instance_f32 csky_vdsp2_dct4_sR_f32_len8192;
#endif
File diff suppressed because it is too large Load Diff
+248
View File
@@ -0,0 +1,248 @@
/**
* @file wm_ble.h
*
* @brief Bluetooth API
*
* @author WinnerMicro
*
* Copyright (c) 2020 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_BLE_H
#define WM_BLE_H
#include "wm_bt_def.h"
/**
* @defgroup BT_APIs Bluetooth APIs
* @brief Bluetooth related APIs
*/
/**
* @addtogroup BT_APIs
* @{
*/
/**
* @defgroup BLE_APIs BLE APIs
* @brief BLE APIs
*/
/**
* @addtogroup BLE_APIs
* @{
*/
/**
* @brief initialize the application callback function
*
* @param[in] *p_callback pointer on callback function
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_dm_init(tls_ble_dm_callback_t callback);
/**
* @brief start/stop ble advertisement
*
* @param[in] start 1 connectable and discoverable; 2 disconnectable and discoverable; 0 stop
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_adv(uint8_t adv_state);
/**
* @brief configure the advertisment content
*
* @param[in] *data @ref btif_dm_adv_data_t
*
* @retval @ref tls_bt_status_t
*
* @note if pure_data equals to true, the filed of manufacturer equals to all fileds of advetisement data.
* otherwise, the filed manufacturer will be advertised in 0xFF filed.
*
*/
tls_bt_status_t tls_ble_set_adv_data(tls_ble_dm_adv_data_t *data);
/**
* @brief configure the advertisment parameters
*
* @param[in] *param @ref btif_dm_adv_param_t
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_set_adv_param(tls_ble_dm_adv_param_t *param);
/**
* @brief configure the advertisment extented parameters
*
* @param[in] *param @ref tls_ble_dm_adv_ext_param_t
*
* @retval @ref tls_bt_status_t
*
* @note if you know how to config all the parameters, you can use this function; otherwise, tls_ble_set_adv_param will be recommanded strongly;
*/
tls_bt_status_t tls_ble_set_adv_ext_param(tls_ble_dm_adv_ext_param_t *param);
/**
* @brief start/stop ble scan
*
* @param[in] start TRUE enable; FALSE disable
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_scan(bool start);
/**
* @brief configure the scan parameters
*
* @param[in] window scan window size
* @param[in] interval scan interval length
* @param[in] scan mode 0 passive scan; 1 active scan;
*
* @retval @ref tls_bt_status_t
*
* @note interval should greater or equals to windows,
* both range should be within (0x0004, 0x4000)
*/
tls_bt_status_t tls_ble_set_scan_param(int window, int interval, uint8_t scan_mode);
/**
* @brief enable a async process evt
*
* @param[in] id user specific definition
* @param[in] *p_callback callback function
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_dm_evt_triger(int id, tls_ble_dm_triger_callback_t callback);
/**
* @brief configure the max transmit unit
*
* @param[in] *bd_addr the remote device address
* @param[in] length range [27 - 251]
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_dm_set_data_length(tls_bt_addr_t *bd_addr, uint16_t length);
/**
* @brief configure the ble privacy
*
* @param[in] enable TRUE: using rpa/random address, updated every 15 mins
** FALSE: public address
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_dm_set_privacy(uint8_t enable);
/**
* @brief update the connection parameters
*
* @param[in] *bd_addr remote device address
* @param[in] min_interval
* @param[in] max_interval
* @param[in] latency
* @param[in] timeout
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_conn_parameter_update(const tls_bt_addr_t *bd_addr,
int min_interval,
int max_interval,
int latency,
int timeout);
/**
* @brief read the remote device signal strength connected
*
* @param[in] *bd_addr remote device address
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_dm_read_remote_rssi(const tls_bt_addr_t *bd_addr);
/**
* @brief config the io capabilities of local device
*
* @param[in] io_cap
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_set_sec_io_cap(uint8_t io_cap);
/**
* @brief config the auth requirement of local device
*
* @param[in] auth_req
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_set_sec_auth_req(uint8_t auth_req);
/**
* @brief This function is called to ensure that connection is
* encrypted. Should be called only on an open connection.
* Typically only needed for connections that first want to
* bring up unencrypted links, then later encrypt them.
* @param[in]sec_act - This is the security action to indicate
* what knid of BLE security level is required for
* the BLE link if the BLE is supported
* @param[in]bd_addr - Address of the peer device
* @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_set_sec(const tls_bt_addr_t *bd_addr, uint8_t sec_act);
/**
* @brief only used to start/stop ble advertisement
*
* @param[in] start 1 start advertisement; 0 stop advertisement;
* @param[in] duration valid for start advertisement. 0 for forever, otherwise the last seconds of advertisement
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_gap_adv(uint8_t start, int duration);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_BLE_H */
+480
View File
@@ -0,0 +1,480 @@
/**
* @file wm_ble_gatt.h
*
* @brief Bluetooth API
*
* @author WinnerMicro
*
* Copyright (c) 2020 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_BLE_GATT_H
#define WM_BLE_GATT_H
#include "wm_bt_def.h"
/**
* @defgroup BT_APIs Bluetooth APIs
* @brief Bluetooth related APIs
*/
/**
* @addtogroup BT_APIs
* @{
*/
/**
* @defgroup BLE_GATT_Client_APIs BLE GATT Client APIs
* @brief BLE GATT Client APIs
*/
/**
* @addtogroup BLE_GATT_Client_APIs
* @{
*/
/**
* @brief initialize the btif_gatt_client callback function
*
* @param[in] *p_callback pointer on callback function
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_app_init(tls_ble_callback_t callback);
/**
* @brief free the tls_ble_callback_t pointer
*
* @param None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_app_deinit(void);
/**
* @brief this function is called to register client application
*
* @param[in] *uuid pointer on uuid
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_app_register(tls_bt_uuid_t *uuid);
/**
* @brief this function is called to unregister client application
*
* @param[in] client_if gatt client access interface
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_app_unregister(uint8_t client_if);
/**
* @brief this function is called to open an BLE connection to a remote
* device or add a background auto connection
*
* @param[in] client_if gatt client access interface
* @param[in] *bd_addr remote device bluetooth device address
* @param[in] is_direct direct connection or background auto connection
* @param[in] transport specific BLE/BR-EDR/mixed
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_connect(uint8_t client_if, const tls_bt_addr_t *bd_addr, uint8_t is_direct, int transport);
/**
* @brief this function is called to disconnect with gatt server connection
*
* @param[in] client_if gatt client access interface
* @param[in] *bd_addr remote device bluetooth device address
* @param[in] conn_id connection ID to be closed
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_disconnect(uint8_t client_if, const tls_bt_addr_t *bd_addr, int conn_id);
/**
* @brief start or stop advertisements to listen for incoming connections
*
* @param[in] client_if gatt client access interface
* @param[in] start start: 1; stop 0
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_listen(uint8_t client_if, uint8_t start);
/**
* @brief clear the attribute cache for a given device
*
* @param[in] client_if gatt client access interface
* @param[in] *bd_addr remote device address
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_refresh(uint8_t client_if, const tls_bt_addr_t *bd_addr);
/**
* @brief enumerate all GATT services on a connected device
*
* @param[in] conn_id connection indicator return value when connected
* @param[in] *filter_uuid filter this uuid
*
* @retval @ref tls_bt_status_t
*
* @note Optionally, the results can be filtered for a given UUID
*/
tls_bt_status_t tls_ble_client_search_service(uint16_t conn_id, tls_bt_uuid_t *filter_uuid);
/**
* @brief write a remote characteristic
*
* @param[in] conn_id connection indicator return value when connected
* @param[in] handle the character attribute handle
* @param[in] write_type the type of attribute write operation
* @param[in] len length of the value to be written
* @param[in] auth_req authentication request
* @param[in] *p_value the value to be written
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_write_characteristic(uint16_t conn_id, uint16_t handle, int write_type, int len, int auth_req, char *p_value);
/**
* @brief read a characteristic on a remote device
*
* @param[in] conn_id connection indicator return value when connected
* @param[in] handle the character attribute handle
* @param[in] auth_req authentication request
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_read_characteristic(uint16_t conn_id, uint16_t handle, int auth_req);
/**
* @brief read the descriptor for a given characteristic
*
* @param[in] conn_id connection indicator return value when connected
* @param[in] handle the character attribute handle
* @param[in] auth_req authentication request
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_read_descriptor(uint16_t conn_id, uint16_t handle, int auth_req);
/**
* @brief write a remote descriptor for a given characteristic
*
* @param[in] conn_id connection indicator return value when connected
* @param[in] handle the character attribute handle
* @param[in] write_type the type of attribute write operation
* @param[in] len length of the value to be written
* @param[in] auth_req authentication request
* @param[in] *p_value the value to be written
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_write_descriptor(uint16_t conn_id, uint16_t handle, int write_type, int len, int auth_req, char *p_value);
/**
* @brief execute a prepared write operation
*
* @param[in] conn_id connection indicator return value when connected
* @param[in] execute execute or cancel
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_execute_write(uint16_t conn_id, int execute);
/**
* @brief Register to receive notifications or indications for a given
* characteristic
*
* @param[in] client_if gatt client access interface
* @param[in] *bd_addr the target server address
* @param[in] handle the attribute handle of characteristic
* @param[in] conn_id the connection id
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_register_for_notification(int client_if, const tls_bt_addr_t *bd_addr, uint16_t handle, uint16_t conn_id);
/**
* @brief deregister a previous request for notifications/indications
*
* @param[in] client_if gatt client access interface
* @param[in] *bd_addr the target server address
* @param[in] handle the attribute handle of characteristic
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_deregister_for_notification(int client_if, const tls_bt_addr_t *bd_addr, uint16_t handle,uint16_t conn_id);
/**
* @brief configure the MTU for a given connection
*
* @param[in] conn_id connection indicator return value when connected
* @param[in] mtu the max transmit unit of this connection
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_configure_mtu(uint16_t conn_id, uint16_t mtu);
/**
* @brief get gatt db content
*
* @param[in] conn_id connection indicator return value when connected
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_client_get_gatt_db(uint16_t conn_id);
/**
* @}
*/
/**
* @defgroup BLE_GATT_Server_APIs BLE GATT Server APIs
* @brief BLE GATT Server APIs
*/
/**
* @addtogroup BLE_GATT_Server_APIs
* @{
*/
/**
* @brief initialize the btif_gatt_server callback function
*
* @param[in] *p_callback pointer on callback function
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_app_init(tls_ble_callback_t callback);
/*******************************************************************************
**
** Function tls_ble_server_app_deinit
**
** Description free the tls_ble_callback_t pointer
**
** Parameters None
**
** Returns TLS_BT_STATUS_SUCCESS
** TLS_BT_STATUS_DONE
**
*******************************************************************************/
tls_bt_status_t tls_ble_server_app_deinit();
/**
* @brief this function is called to register server application
*
* @param[in] *uuid pointer on uuid
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_app_register(tls_bt_uuid_t *uuid);
/**
* @brief this function is called to unregister server application
*
* @param[in] server_if assigned after app registering
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_app_unregister(uint8_t server_if);
/**
* @brief create a new service
*
* @param[in] server_if the gatt server access interface created by app register
* @param[in] inst_id instance identifier of this service
* @param[in] primay is primary or not service
* @param[in] *uuid the id property of this service
* @param[in] num_handles number of handle requested for this service
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_add_service(uint8_t server_if, int inst_id, int primay, tls_bt_uuid_t *uuid, int num_handles);
/**
* @brief add a characteristic to a service
*
* @param[in] server_if the gatt server access interface created by app register
* @param[in] service_handle the handle of this service assigned when creating a service
* @param[in] *uuid the id property of this characteristic
* @param[in] properties access properties
* @param[in] permission access permission
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_add_characteristic(uint8_t server_if, uint16_t service_handle, tls_bt_uuid_t *uuid, int properties, int permission);
/**
* @brief add a descriptor to a given service
*
* @param[in] server_if the gatt server access interface created by app register
* @param[in] service_handle the handle of this service assigned when creating a service
* @param[in] *uuid the id property of this characteristic
* @param[in] permission access permission
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_add_descriptor(uint8_t server_if, uint16_t service_handle, tls_bt_uuid_t *uuid, int permissions);
/**
* @brief starts a local service
*
* @param[in] server_if the gatt server access interface created by app register
* @param[in] service_handle the handle of this service assigned when creating a service
* @param[in] transport tranport type, BLE/BR-EDR/MIXED
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_start_service(uint8_t server_if, uint16_t service_handle, int transport);
/**
* @brief stop a local service
*
* @param[in] server_if the gatt server access interface created by app register
* @param[in] service_handle the handle of this service assigned when creating a service
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_stop_service(uint8_t server_if, uint16_t service_handle);
/**
* @brief delete a local service
*
* @param[in] server_if the gatt server access interface created by app register
* @param[in] service_handle the handle of this service assigned when creating a service
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_delete_service(uint8_t server_if, uint16_t service_handle);
/**
* @brief create a connection to a remote peripheral
*
* @param[in] server_if the gatt server access interface created by app register
* @param[in] *bd_addr the remote device address
* @param[in] is_direct true direct connection; false: background auto connection
* @param[in] transport tranport type, BLE/BR-EDR/MIXED
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_connect(uint8_t server_if, const tls_bt_addr_t *bd_addr, uint8_t is_direct, int transport);
/**
* @brief disconnect an established connection or cancel a pending one
*
* @param[in] server_if the gatt server access interface created by app register
* @param[in] *bd_addr the remote device address
* @param[in] conn_id connection id create when connection established
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_disconnect(uint8_t server_if, const tls_bt_addr_t *bd_addr, uint16_t conn_id);
/**
* @brief send value indication to a remote device
*
* @param[in] server_if the gatt server access interface created by app register
* @param[in] attribute_handle the handle of characteristic
* @param[in] conn_id connection id create when connection established
* @param[in] len the length of value to be sent
* @param[in] confirm need the remote device acked after receive the message , normally
* Whether a confirmation is required. FALSE sends a GATT notification,
* TRUE sends a GATT indication
* @param[in] *p_value the value to be written
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_send_indication(uint8_t server_if, uint16_t attribute_handle, uint16_t conn_id, int len, int confirm, char *p_value);
/**
* @brief send a response to a read/write operation
*
* @param[in] conn_id connection id create when connection established
* @param[in] trans_id the transation identifier
* @param[in] status TODO:
* @param[in] offset the offset the fragmented value
* @param[in] attr_handle the attribute handle
* @param[in] auth_req access properties
* @param[in] *p_value the value to be written
* @param[in] len the length of value to be written
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_ble_server_send_response(uint16_t conn_id, uint32_t trans_id, uint8_t status, int offset, uint16_t attr_handle, int auth_req, uint8_t *p_value, int len);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_BLE_GATT_H */
+422
View File
@@ -0,0 +1,422 @@
/**
* @file wm_bt.h
*
* @brief Bluetooth API
*
* @author WinnerMicro
*
* Copyright (c) 2020 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_BT_H
#define WM_BT_H
#include "wm_bt_def.h"
/**
* @defgroup BT_APIs Bluetooth APIs
* @brief Bluetooth related APIs
*/
/**
* @addtogroup BT_APIs
* @{
*/
/**
* @defgroup BT_Host_APIs BT Host APIs
* @brief BT Host APIs
*/
/**
* @addtogroup BT_Host_APIs
* @{
*/
/**
* @brief reply the pin request
*
* @param[in] *bd_addr remote device address
* @param[in] accept
* @param[in] pin_len
* @param[in] *pin_code
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_pin_reply(const tls_bt_addr_t *bd_addr, uint8_t accept,
uint8_t pin_len, tls_bt_pin_code_t *pin_code);
/**
* @brief reply the ssp request
*
* @param[in] *bd_addr remote device address
* @param[in] variant @ref tls_bt_ssp_variant_t
* @param[in] accept
* @param[in] passkey
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_ssp_reply(const tls_bt_addr_t *bd_addr, tls_bt_ssp_variant_t variant,
uint8_t accept, uint32_t passkey);
/**
* @brief set the adapter property
*
* @param[in] *property remote device address
* @param[in] update_to_flash save the property to flash or not
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_set_adapter_property(const tls_bt_property_t *property, uint8_t update_to_flash);
/**
* @brief get the adapter property
*
* @param[in] type @ref tls_bt_property_type_t
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_get_adapter_property(tls_bt_property_type_t type);
/**
* @brief
*
* @param None
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_start_discovery(void);
/**
* @brief
*
* @param None
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_cancel_discovery(void);
/**
* @brief
*
* @param[in] *bd_addr
* @param[in] transport
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_create_bond(const tls_bt_addr_t *bd_addr, int transport);
/**
* @brief
*
* @param[in] *bd_addr
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_cancel_bond(const tls_bt_addr_t *bd_addr);
/**
* @brief
*
* @param[in] *bd_addr
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_remove_bond(const tls_bt_addr_t *bd_addr);
/**
* @brief
*
* @param None
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_host_cleanup(void);
/**
* @brief
*
* @param[in] callback
* @param[in] *p_hci_if
* @param[in] log_level
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_enable(tls_bt_host_callback_t callback, tls_bt_hci_if_t *p_hci_if, tls_bt_log_level_t log_level);
/**
* @brief
*
* @param None
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_disable();
/**
* @}
*/
/**
* @defgroup BT_Controller_APIs BT Controller APIs
* @brief BT Controller APIs
*/
/**
* @addtogroup BT_Controller_APIs
* @{
*/
/**
* @brief enable the bluetooth controller stack
*
* @param[in] *p_hci_if pointer on uart property
* @param[in] log_level @ref tls_bt_log_level_t
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_ctrl_enable(tls_bt_hci_if_t *p_hci_if, tls_bt_log_level_t log_level);
/**
* @brief disable the bluetooth controller stack
*
* @param None
*
* @return @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_ctrl_disable(void);
/**
* @brief configure the ble emit power of different ble handle type
*
* @param[in] power_type @ref tls_ble_power_type_t
* @param[in] power_level_index [1,2,3,4,5] map to[1,4,7,10,13]dBm
*
* @retval @ref tls_bt_status_t
*
* @note power_type, supports TLS_BLE_PWR_TYPE_DEFAULT only.
*/
tls_bt_status_t tls_ble_set_tx_power(tls_ble_power_type_t power_type, int8_t power_level_index);
/**
* @brief get the ble emit power of different ble handle type
*
* @param[in] power_type @ref tls_ble_power_type_t
*
* @retval power value db
*
* @note power_type, supports TLS_BLE_PWR_TYPE_DEFAULT only.
*/
int8_t tls_ble_get_tx_power(tls_ble_power_type_t power_type);
/**
* @brief configure the classic/enhanced bluetooth transmit power
*
* @param[in] min_power_level power level[1,13]dBm
* @param[in] max_power_level power level[1,13]dBm
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bredr_set_tx_power(int8_t min_power_level,int8_t max_power_level);
/**
* @brief get the classic/enhanced bluetooth transmit power level
*
* @param[in] *min_power_level pointer on min_power_level
* @param[in] *max_power_level pointer on max_power_level
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bredr_get_tx_power(int8_t* min_power_level, int8_t* max_power_level);
/**
* @brief configure the voice output path
*
* @param[in] data_path @ref tls_sco_data_path_t
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bredr_sco_datapath_set(tls_sco_data_path_t data_path);
/**
* @brief get controller stack status
*
* @param None
*
* @retval @ref tls_bt_ctrl_status_t
*
* @note None
*/
tls_bt_ctrl_status_t tls_bt_controller_get_status(void);
/**
* @brief this function receive the hci message from host hci_h4 inteface
*
* @param[in] *data hci formated message
* @param[in] len command length
*
* @retval @ref tls_bt_ctrl_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_vuart_host_send_packet( uint8_t *data, uint16_t len);
/**
* @brief this function register the host stack receive message function
* and indication the controller receive hci command avaiable
*
* @param[in] *p_host_if @ref tls_bt_host_if_t
*
* @retval @ref tls_bt_ctrl_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_ctrl_if_register(const tls_bt_host_if_t *p_host_if);
/**
* @brief this function unregister the host stack receive message function
* and indication the controller receive hci command avaiable
*
* @param None
*
* @retval @ref tls_bt_ctrl_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_ctrl_if_unregister();
/**
* @brief this function configure the controller enter into sleep mode when controller
* is in idle mode
*
* @param[in] enable TRUE: enable
* FALSE: didsable
*
* @retval @ref tls_bt_ctrl_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_ctrl_sleep(bool enable);
/**
* @brief this function look up the controller is in sleep mode or not
*
* @param None
*
* @retval TRUE: sleep mode
* FALSE: not sleep mode
*
* @note None
*/
bool tls_bt_ctrl_is_sleep(void);
/**
* @brief this function wake up the controller, in other words exit sleep mode
*
* @param None
*
* @retval @ref tls_bt_ctrl_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_ctrl_wakeup(void);
/**
* @brief this function check controller can handle hci commands yes or no
*
* @param None
*
* @retval @ref bool TRUE or FALSE
*
* @note None
*/
bool tls_bt_vuart_host_check_send_available();
/**
* @brief this function exit bluetooth test mode
*
* @param None
*
* @retval @ref tls_bt_ctrl_status_t
*
* @note None
*/
tls_bt_status_t exit_bt_test_mode();
/**
* @brief this function enable bluetooth test mode
*
* @param[in] p_hci_if, specific the uart port property
*
* @retval @ref tls_bt_ctrl_status_t
*
* @note None
*/
tls_bt_status_t enable_bt_test_mode(tls_bt_hci_if_t *p_hci_if);
/**
* @brief this function enable rf to bluetooth mode
*
* @param[in] 1, bluetooth mode, 0 wifi/bluetooth mode
*
* @retval None
*
* @note None
*/
void tls_rf_bt_mode(uint8_t enable);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_BT_H */
+300
View File
@@ -0,0 +1,300 @@
/**
* @file wm_bt_av.h
*
* @brief Bluetooth API
*
* @author WinnerMicro
*
* Copyright (c) 2020 Winner Microelectronics Co., Ltd.
*/
#ifndef __WM_BT_A2DP_H__
#define __WM_BT_A2DP_H__
#include "wm_bt.h"
/**
* @defgroup BT_APIs Bluetooth APIs
* @brief Bluetooth related APIs
*/
/**
* @addtogroup BT_APIs
* @{
*/
/**
* @defgroup BT_AV_APIs
* @brief BT_AV APIs
*/
/**
* @addtogroup BT_AV_APIs
* @{
*/
/**sink realed api*/
/**
* @brief Initializes the AV interface for sink mode
*
* @param[in] callback pointer on callback function
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_av_sink_init(tls_bt_a2dp_sink_callback_t callback);
/**
* @brief Shuts down the AV sink interface and does the cleanup
*
* @param None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_av_sink_deinit(void);
/**
* @brief Establishes the AV signalling channel with the source
*
* @param[in] *bd_addr remote device bluetooth device address
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_av_sink_connect_src(tls_bt_addr_t *bd_addr);
/**
* @brief Tears down the AV signalling channel with the source side
*
* @param[in] *bd_addr remote device bluetooth device address
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_av_sink_disconnect(tls_bt_addr_t *bd_addr);
/**src realed api*/
/**
* @brief Initializes the AV interface for source mode
*
* @param[in] callback pointer on callback function
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_av_src_init(tls_bt_a2dp_src_callback_t callback);
/**
* @brief Shuts down the AV source interface and does the cleanup
*
* @param None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_av_src_deinit(void);
/**
* @brief Establishes the AV signalling channel with the sink
*
* @param[in] *bd_addr remote device bluetooth device address
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_av_src_connect_sink(tls_bt_addr_t *bd_addr);
/**
* @brief Tears down the AV signalling channel with the sink side
*
* @param[in] *bd_addr remote device bluetooth device address
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_av_src_disconnect(tls_bt_addr_t *bd_addr);
/**btrc related api supported by now*/
/**
* @brief Initializes the AVRC interface
*
* @param[in] callback pointer on callback function
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_btrc_init(tls_btrc_callback_t callback);
/**
* @brief Closes the AVRC interface
*
* @param None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_btrc_deinit(void);
/**
* @brief Returns the current play status.
*
* @param[in] tls_btrc_play_status_t stopped, playing, paused...
* @param[in] song_len seconds of the song
* @param[in] song_pos played seconds of the song
*
* @retval @ref tls_bt_status_t
*
* @note This method is called in response to GetPlayStatus request.
*/
tls_bt_status_t tls_btrc_get_play_status_rsp(tls_btrc_play_status_t play_status, uint32_t song_len,
uint32_t song_pos);
/**
* @brief Returns the current songs' element attributes in text
*
* @param[in] num_attr counter of song`s element attributes
* @param[in] p_attrs pointer of element attributes
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_btrc_get_element_attr_rsp(uint8_t num_attr, tls_btrc_element_attr_val_t *p_attrs);
/**
* @brief Response to the register notification request in text
*
* @param[in] event_id play_status, track or play_pos changed
* @param[in] type notification type
* @param[in] p_param pointer to details of notification structer
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_btrc_register_notification_rsp(tls_btrc_event_id_t event_id,
tls_btrc_notification_type_t type, tls_btrc_register_notification_t *p_param);
/**
* @brief Send current volume setting to remote side
*
* @param[in] volue Should be in the range 0-127. bit7 is reseved and cannot be set
*
* @retval @ref tls_bt_status_t
*
* @note Support limited to SetAbsoluteVolume
* This can be enhanced to support Relative Volume (AVRCP 1.0).
* With RelateVolume, we will send VOLUME_UP/VOLUME_DOWN
* as opposed to absolute volume level
*/
tls_bt_status_t tls_btrc_set_volume(uint8_t volume);
/**btrc ctrl related api supported by now*/
/**
* @brief Initializes the AVRC ctrl interface
*
* @param[in] callback pointer on callback function
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_btrc_ctrl_init(tls_btrc_ctrl_callback_t callback);
/**
* @brief Closes the AVRC ctrl interface
*
* @param None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_btrc_ctrl_deinit(void);
/**
* @brief Send Pass-Through command
*
* @param[in] bd_addr remote device bluetooth device address
* @param[in] key_code code definition of the key
* @param[in] key_state key stae
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_btrc_ctrl_send_passthrough_cmd(tls_bt_addr_t *bd_addr, uint8_t key_code, uint8_t key_state);
/**
* @brief Send group navigation command
*
* @param[in] bd_addr remote device bluetooth device address
* @param[in] key_code code definition of the key
* @param[in] key_state key stae
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_btrc_ctrl_send_groupnavigation_cmd(tls_bt_addr_t *bd_addr, uint8_t key_code, uint8_t key_state);
/**
* @brief Set current values of Player Attributes
*
* @param[in] bd_addr remote device bluetooth device address
* @param[in] num_attrib couner of attributes
* @param[in] attrib_ids atrribute of index indicator
* @param[in] attrib_vals attribute of values
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_btrc_ctrl_change_player_app_setting(tls_bt_addr_t *bd_addr, uint8_t num_attrib, uint8_t *attrib_ids, uint8_t *attrib_vals);
/**
* @brief Rsp for SetAbsoluteVolume Command
*
* @param[in] bd_addr remote device bluetooth device address
* @param[in] abs_vol the absolute volume
* @param[in] label label indicator
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_btrc_ctrl_set_volume_rsp(tls_bt_addr_t *bd_addr, uint8_t abs_vol, uint8_t label);
/**
* @brief Rsp for Notification of Absolute Volume
*
* @param[in] bd_addr remote device bluetooth device address
* @param[in] rsp_type interim or changed
* @param[in] abs_vol the absolute volume value
* @param[in] label label indicator
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_btrc_ctrl_volume_change_notification_rsp(tls_bt_addr_t *bd_addr, tls_btrc_notification_type_t rsp_type,uint8_t abs_vol, uint8_t label);
#endif
+1893
View File
File diff suppressed because it is too large Load Diff
+261
View File
@@ -0,0 +1,261 @@
/**
* @file wm_bt_hf_client.h
*
* @brief Bluetooth API
*
* @author WinnerMicro
*
* Copyright (c) 2020 Winner Microelectronics Co., Ltd.
*/
#ifndef __WM_BT_HF_CLIENT_H__
#define __WM_BT_HF_CLIENT_H__
#include "wm_bt.h"
/**
* @defgroup BT_APIs Bluetooth APIs
* @brief Bluetooth related APIs
*/
/**
* @addtogroup BT_APIs
* @{
*/
/**
* @defgroup BT_HF_CLIENT_APIs
* @brief BT_HF_CLIENT APIs
*/
/**
* @addtogroup BT_HF_CLIENT_APIs
* @{
*/
/**
* @brief initializes the hf client interface
*
* @param[in] callback pointer on callback function
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_init(tls_bthf_client_callback_t callback);
/**
* @brief Closes the HF client interface
*
* @param None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_deinit(void);
/**
* @brief connect to audio gateway
*
* @param[in] *bd_addr remote device bluetooth device address
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_connect(tls_bt_addr_t *bd_addr);
/**
* @brief disconnect from audio gateway
*
* @param[in] *bd_addr remote device bluetooth device address
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_disconnect(tls_bt_addr_t *bd_addr);
/**
* @brief create an audio connection
*
* @param[in] *bd_addr remote device bluetooth device address
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_connect_audio(tls_bt_addr_t *bd_addr);
/**
* @brief close the audio connection
*
* @param[in] *bd_addr remote device bluetooth device address
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_disconnect_audio(tls_bt_addr_t *bd_addr);
/**
* @brief start voice recognition
*
* @param[in] None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_start_voice_recognition(void);
/**
* @brief stop voice recognition
*
* @param[in] None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_stop_voice_recognition(void);
/**
* @brief volume control
*
* @param[in] type Mic or speaker
* @param[in] volume index value
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_volume_control(tls_bthf_client_volume_type_t type, int volume);
/**
* @brief place a call
*
* @param[in] number phone number to be called
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_dial(const char *number);
/**
* @brief place a call with number specified by location (speed dial)
*
* @param[in] location
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_dial_memory(int location);
/**
* @brief handle specified call related action
*
* @param[in] action call action
* @param[in] idx index indicator
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_handle_call_action(tls_bthf_client_call_action_t action, int idx);
/**
* @brief query list of current calls
*
* @param[in] None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_query_current_calls(void);
/**
* @brief query current selected operator name
*
* @param[in] None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_query_current_operator_name(void);
/**
* @brief retrieve subscriber number information
*
* @param[in] None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_retrieve_subscriber_info(void);
/**
* @brief send dtmf
*
* @param[in] code number code
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_send_dtmf(char code);
/**
* @brief Request number from AG for VR purposes
*
* @param[in] None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_request_last_voice_tag_number(void);
/**
* @brief Send requested AT command to remote device
*
* @param[in] cmd
* @param[in] val1
* @param[in] val2
* @param[in] arg
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_send_at_cmd(int cmd, int val1, int val2, const char *arg);
/**
* @brief Send audio to audio gateway
*
* @param[in] bd_addr bluetooth address of audio gateway
* @param[in] p_data audio data
* @param[in] length audio length
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_hf_client_send_audio(tls_bt_addr_t *bd_addr, uint8_t *p_data, uint16_t length);
+151
View File
@@ -0,0 +1,151 @@
/**
* @file wm_bt_spp.h
*
* @brief Bluetooth API
*
* @author WinnerMicro
*
* Copyright (c) 2020 Winner Microelectronics Co., Ltd.
*/
#ifndef __WM_BT_SPP_H__
#define __WM_BT_SPP_H__
#include "wm_bt.h"
/**
* @defgroup BT_APIs Bluetooth APIs
* @brief Bluetooth related APIs
*/
/**
* @addtogroup BT_APIs
* @{
*/
/**
* @defgroup BT_SPP_APIs
* @brief BT_SPP APIs
*/
/**
* @addtogroup BT_SPP_APIs
* @{
*/
/**spp realed api*/
/**
* @brief Initializes the SPP interface
*
* @param[in] callback pointer on callback function
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_spp_init(tls_bt_spp_callback_t callback);
/**
* @brief Shuts down the SPP interface and does the cleanup
*
* @param None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_spp_deinit(void);
/**
* @brief Enable the bta jv interface
*
* @param[in] None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_spp_enable(void);
/**
* @brief Disable the bta jv interface and cleanup internal resource
*
* @param[in] None
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_spp_disable(void);
/**
* @brief Discovery the spp service by the given peer device.
*
* @param[in] *bd_addr remote device bluetooth device address
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_spp_start_discovery(tls_bt_addr_t *bd_addr, tls_bt_uuid_t *uuid);
/**
* @brief Create a spp connection to the remote device
*
* @param[in] sec_mask: Security Setting Mask
* @param[in] role: Server or client
* @param[in] remote_scn: Remote device bluetooth device SCN
* @param[in] *bd_addr remote device bluetooth device address
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_spp_connect(wm_spp_sec_t sec_mask,
tls_spp_role_t role, uint8_t remote_scn, tls_bt_addr_t *bd_addr);
/**
* @brief Close a spp connection
*
* @param[in] handle: The connection handle
*
* @retval @ref tls_bt_status_t
*
* @note None
*/
tls_bt_status_t tls_bt_spp_disconnect(uint32_t handle);
/**
* @brief This function create a SPP server and starts listening for an
* SPP connection request from a remote Bluetooth device
*
* @param[in] sec_mask: Security Setting Mask .
* @param[in] role: Server or client.
* @param[in] local_scn: The specific channel you want to get.
* If channel is 0, means get any channel.
* @param[in] name: Server's name.
*
* @retval @ref tls_bt_status_t
*/
tls_bt_status_t tls_bt_spp_start_server(wm_spp_sec_t sec_mask,
tls_spp_role_t role, uint8_t local_scn, const char *name);
/**
* @brief This function is used to write data
*
* @param[in] handle: The connection handle.
* @param[in] len: The length of the data written.
* @param[in] p_data: The data written.
*
* @retval @ref tls_bt_status_t
*/
tls_bt_status_t tls_bt_spp_write(uint32_t handle, uint8_t *p_data, int length);
#endif
+270
View File
@@ -0,0 +1,270 @@
/**************************************************************************//**
* @file wm_7816.h
* @author
* @version
* @date
* @brief
* @copyright (c) 2014 Winner Microelectronics Co., Ltd. All rights reserved.
*****************************************************************************/
#ifndef WM_7816_H_
#define WM_7816_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <string.h>
#include <stdbool.h>
#include "wm_regs.h"
#include "wm_type_def.h"
#include "wm_io.h"
#define WM_SC_RST_PIN WM_IO_PB_23 //(23)
#define WM_SC_PWR_PIN WM_IO_PB_24 //(29)
#define WM_SC_DEFAULT_FD (372)
typedef struct sc_io_map_ {
enum tls_io_name clk_pin_num;
uint32_t clk_opt;
enum tls_io_name io_pin_num;
uint32_t io_opt;
uint8_t initialed;
} sc_io_map;
extern sc_io_map sc_io;
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup 7816_Driver_APIs 7816 Driver APIs
* @brief 7816 driver APIs
*/
/**
* @addtogroup 7816_Driver_APIs
* @{
*/
/**
* @brief
* This function is used to config the pin in gpio or 7816 mode for the 7816 power on timing
*
* @param[in] mode : 1--gpio mode ; 0--7816 mode
*
* @retval
*/
void wm_sc_io_clk_config(uint8_t mode);
/**
* @brief
* close af to use as gpio
* @retval
*/
void wm_sc_powerInit(void);
/**
* @brief
* power on the 7816 device if power is controled by GPIO
* @retval
*/
void wm_sc_poweron(void);
/**
* @brief
* power off the 7816 device if power is controled by GPIO
* @retval
*/
void wm_sc_poweroff(void);
/**
* @brief
* driver the reset gpio in low level
* @retval
*/
void wm_sc_rst_low(void);
/**
* @brief
* driver the reset gpio in high level
* @retval
*/
void wm_sc_rst_high(void);
/**
* @brief
* hotrest the 7816 device obey the 7816-3 timing
* @retval
*/
void wm_sc_hotreset(void);
/**
* @brief
* colreset the 7816 device obey the 7816-3 timing
* @retval
*/
void wm_sc_colreset(void);
/**
* @brief
* deactive the 7816 device obey the 7816-3 timing
* @retval
*/
void wm_sc_deactive(void);
/**
* @brief
* This function is used to config the block guard time param in 7816 mode
* @param[in] bgt : the value of blcok guard time will be set
* @retval
*/
void wm_sc_set_bgt(uint8_t bgt);
/**
* @brief
* This function is used to config the tx retry count when detect err signal
* @param[in] count : the value of retry time will be set 7 for max
* @retval
*/
void wm_sc_tx_retry_times(uint8_t count);
/**
* @brief
* This function is used to config the rx retry count when detect parity error
* @param[in] count : the value of retry time will be set 7 for max
* @retval
*/
void wm_sc_rx_retry_times(uint8_t count);
/**
* @brief
* This function is used to config the etu param
* @param[in] etu : the value of etu will be set
* @retval
*/
void wm_sc_set_etu(uint16_t etu);
/**
* @brief
* This function config the module clock freq
* @param[in] freq : the value of clock freq
* @retval
*/
void wm_sc_set_frequency(uint32_t freq);
/**
* @brief
* config recv or not when parity error
* @param[in] bl : 1--- recv
* 0--- don't recv
* @retval
*/
static inline void wm_sc_parity_recv(bool bl)
{
tls_bitband_write(HR_UART2_LINE_CTRL, 9, bl);
}
/**
* @brief
* select the model in 7816 or uart function
* @param[in] bl : 1---7816 mode
* 0---uart mode
* @retval
*/
static inline void wm_sc_7816_mode(bool bl)
{
tls_bitband_write(HR_UART2_LINE_CTRL, 24, bl);
}
/**
* @brief
* This function is used to config the guard time param
* @param[in] bwt : the value of the guard time will be set
* @retval
*/
static inline void wm_sc_set_guardtime(uint8_t gt)
{
tls_reg_write32(HR_UART2_GUARD_TIME, gt);
}
/**
* @brief
* This function is used to config the CWT or BWT param
* @param[in] bwt : the value of CWT or BWT will be set
* @retval
*/
static inline void wm_sc_set_bcwt(uint32_t bwt)
{
bwt = (bwt > 0xFFFFFF) ? 0xFFFFFF : bwt;
tls_reg_write32(HR_UART2_WAIT_TIME, bwt);
}
/**
* @brief
* module errsignal int enable or disable
* @param[in] bl : 1---enable
* 0---disable
* @retval
*/
static inline void wm_sc_tx_errsignal_mask(bool bl)
{
tls_bitband_write(HR_UART2_INT_MASK, 9, bl);
}
/**
* @brief
* config the module protol
* @param[in] bl : 1--- T1 protocol
* 0--- T0 protocol
* @retval
*/
static inline void wm_sc_set_protocol(bool bl)
{
tls_bitband_write(HR_UART2_LINE_CTRL, 8, bl);
}
/**
* @brief
* get the module protol
* @retval
* 1--- T1 protocol
* 0--- T0 protocol
*/
static inline uint8_t wm_sc_get_protocol()
{
return tls_bitband_read(HR_UART2_LINE_CTRL, 8);
}
/**
* @brief
* smart card clock output enable or disable
* @param[in] bl : 0---enable;
* 1---disable;
* @retval
*/
static inline void wm_sc_clk_enable(bool bl)
{
tls_bitband_write(HR_UART2_LINE_CTRL, 10, bl);
}
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif
+316
View File
@@ -0,0 +1,316 @@
/*****************************************************************************
*
* File Name : wm_adc.h
*
* Description: adc Driver Module
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
* All rights reserved.
*
* Author : dave
*
* Date : 2014-8-15
*****************************************************************************/
#ifndef WM_ADC_H
#define WM_ADC_H
#include "wm_type_def.h"
#define ADC_DEST_BUFFER_SIZE 16383//以字为单位
/*ADC Result*/
#define ADC_RESULT_MASK (0x3FFFC)
#define ADC_RESULT_VAL(n) ((n)&ADC_RESULT_MASK)
/*ADC_ANALOG_CTRL*/
#define CONFIG_ADC_CHL_SEL_MASK (0xF<<8)
#define CONFIG_ADC_CHL_SEL(n) ((n)<<8)
#define CONFIG_PD_ADC_MASK (0x1<<2)
#define CONFIG_PD_ADC_VAL(n) ((n)<<2) /*1:pd adc, 0: normal work*/
#define CONFIG_RSTN_ADC_MASK (0x1<<1)
#define CONFIG_RSTN_ADC_VAL(n) ((n)<<1) /*1:normal work, 0:adc reset*/
#define CONFIG_EN_LDO_ADC_MASK (0x1<<0)
#define CONFIG_EN_LDO_ADC_VAL(n) ((n)<<0) /*1:ldo work, 0: ldo shutdown*/
/*PGA_CTRL*/
#define CLK_CHOP_SEL_PGA_MASK (0x7<<4)
#define CLK_CHOP_SEL_PGA_VAL(n) ((n)<<4)
#define GAIN_CTRL_PGA_MASK (0x3<<7)
#define GAIN_CTRL_PGA_VAL(n) ((n)<<7)
#define PGA_BYPASS_MASK (0x1<<3)
#define PGA_BYPASS_VAL(n) ((n)<<3) /*1:bypass pga, 0:use pga*/
#define BYPASS_INNER_REF_SEL (0x1<<2) /*Internal or external reference select*/
#define PGA_CHOP_ENP_MASK (0x1<<1)
#define PGA_CHOP_ENP_VAL(n) ((n)<<1) /*1: enable chop, 0: disable chop*/
#define PGA_EN_MASK (0x1<<0)
#define PGA_EN_VAL(n) ((n)<<0) /*1: enable pga, 0: disable pga*/
/*Temperature Control*/
#define TEMP_GAIN_MASK (0x3<<4)
#define TEMP_GAIN_VAL(n) ((n)<<4)
#define TEMP_CAL_OFFSET_MASK (0x1<<1)
#define TEMP_EN_MASK (0x1<<0)
#define TEMP_EN_VAL(n) ((n)<<0) /*1: enable temperature, 0: disable temperature*/
/*ADC CTRL*/
#define ANALOG_SWITCH_TIME_MASK (0x3FF<<20)
#define ANALOG_SWITCH_TIME_VAL(n) (((n)&0x3FF)<<20)
#define ANALOG_INIT_TIME_MASK (0x3FF<<8)
#define ANALOG_INIT_TIME_VAL(n) (((n)&0x3FF)<<8)
#define CMP_POLAR_MASK (0x1<<6)
#define CMP_IRQ_EN_MASK (0x1<<5)
#define CMP_IRQ_EN_VAL(n) ((n)<<5) /*1: enable cmp irq, 0: disable cmp irq*/
#define CMP_EN_MASK (0x1<<4)
#define CMP_EN_VAL(n) ((n)<<4) /*1: enable cmp function, 0: disable cmp function*/
#define ADC_IRQ_EN_MASK (0x1<<1)
#define ADC_IRQ_EN_VAL(n) ((n)<<1) /*1:enable adc transfer irq, 0: disable*/
#define ADC_DMA_EN_MASK (0x1<<0)
#define ADC_DMA_EN_VAL(n) ((n)<<0) /*1:enable adc dma, 0: disable*/
/*ADC IRQ Status*/
#define CMP_INT_MASK (0x1<<1)
#define ADC_INT_MASK (0x1<<0)
/*CMP Value*/
#define CONFIG_ADC_INPUT_CMP_VAL(n) ((n)&0x3FFFF)
/*ADC Channel*/
#define CONFIG_ADC_CHL_OFFSET (0x0E)
#define CONFIG_ADC_CHL_VOLT (0x0D)
#define CONFIG_ADC_CHL_TEMP (0x0C)
#define ADC_INT_TYPE_ADC 0
#define ADC_INT_TYPE_DMA 1
#define ADC_INT_TYPE_ADC_COMP 2
#define ADC_REFERENCE_EXTERNAL 0 //外部参考
#define ADC_REFERENCE_INTERNAL 1 //内部参考
typedef struct adc_st{
u8 dmachannel;
void (*adc_cb)(int *buf, u16 len);
void (*adc_bigger_cb)(int *buf, u16 len);
void (*adc_dma_cb)(int *buf,u16 len);
u16 valuelen; /*dma 采样数据长度*/
u16 offset;
}ST_ADC;
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup ADC_Driver_APIs ADC Driver APIs
* @brief ADC driver APIs
*/
/**
* @addtogroup ADC_Driver_APIs
* @{
*/
/**
* @brief This function is used to init adc.
*
* @param[in] ifusedma if use dma
* @param[in] dmachannel dma channel
*
* @return None
*
* @note None
*/
void tls_adc_init(u8 ifusedma,u8 dmachannel);
/**
* @brief This function is used to register interrupt callback function.
*
* @param[in] inttype interrupt type:
* ADC_INT_TYPE_ADC adc interrupt,user get adc result from the callback function.
* ADC_INT_TYPE_DMA dma interrupt,dma transfer the adc result to the user's buffer.
* @param[in] callback interrupt callback function.
*
* @return None
*
* @note None
*/
void tls_adc_irq_register(int inttype, void (*callback)(int *buf, u16 len));
/**
* @brief This function is used to clear the interrupt source.
*
* @param[in] inttype interrupt type:
* ADC_INT_TYPE_ADC adc interrupt,user get adc result from the callback function.
* ADC_INT_TYPE_DMA dma interrupt,dma transfer the adc result to the user's buffer.
*
* @return None
*
* @note None
*/
void tls_adc_clear_irq(int inttype);
/**
* @brief This function is used to register interrupt callback function.
*
* @param[in] Channel adc channel,from 0 to 3 is single input;4 and 5 is differential input.
* @param[in] Length byte data length,is an integer multiple of half word,need <= 0x500
*
* @return None
*
* @note None
*/
void tls_adc_start_with_dma(int Channel, int Length);
/**
* @brief This function is used to start adc.
*
* @param[in] Channel adc channel,from 0 to 3 is single input;4 and 5 is differential input.
*
* @return None
*
* @note None
*/
void tls_adc_start_with_cpu(int Channel);
/**
* @brief This function is used to read adc result.
*
* @param[in] None
*
* @retval adc result
*
* @note None
*/
u32 tls_read_adc_result(void);
/**
* @brief This function is used to stop the adc.
*
* @param[in] ifusedma if use dma
*
* @return None
*
* @note None
*/
void tls_adc_stop(int ifusedma);
/**
* @brief This function is used to config adc bigger register.
*
* @param[in] cmp_data compare data
* @param[in] cmp_pol compare pol
*
* @return None
*
* @note None
*/
void tls_adc_config_cmp_reg(int cmp_data, int cmp_pol);
/**
* @brief This function is used to set adc reference source.
*
* @param[in] ref ADC_REFERENCE_EXTERNAL,ADC_REFERENCE_INTERNAL
*
* @return None
*
* @note None
*/
void tls_adc_reference_sel(int ref);
/**
* @brief This function is used to read internal temperature.
*
* @param[in] None
*
* @retval temperature
*
* @note None
*/
int adc_get_interTemp(void);
/**
* @brief This function is used to read input voltage.
*
* @param[in] channel adc channel,from 0 to 3 is single input;8 and 9 is differential input.
*
* @retval voltage unit:mV
*
* @note None
*/
int adc_get_inputVolt(u8 channel);
/**
* @brief This function is used to read internal voltage.
*
* @param[in] None
*
* @retval voltage (mV)
*
* @note None
*/
u32 adc_get_interVolt(void);
/**
* @brief This function is used to read temperature.
*
* @param[in] None
*
* @retval temperature
*
* @note None
*/
int adc_temp(void);
/**
* @}
*/
/**
* @}
*/
void tls_adc_enable_calibration_buffer_offset(void);
void tls_adc_voltage_start_with_cpu(void);
void tls_adc_temp_offset_with_cpu(u8 calTemp12);
void tls_adc_voltage_start_with_dma(int Length);
void tls_adc_set_clk(int div);
void signedToUnsignedData(int *adcValue);
void tls_adc_buffer_bypass_set(u8 isset);
void tls_adc_cmp_start(int Channel, int cmp_data, int cmp_pol);
u32 adc_get_offset(void);
#endif
+101
View File
@@ -0,0 +1,101 @@
/**
* @file wm_cpu.h
*
* @brief cpu driver module
*
* @author dave
*
* @copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_CPU_H
#define WM_CPU_H
#include <stdint.h>
/**W800 BASE PLL CLOCK*/
#define W800_PLL_CLK_MHZ (480)
enum CPU_CLK{
CPU_CLK_240M = 2,
CPU_CLK_160M = 3,
CPU_CLK_80M = 6,
CPU_CLK_40M = 12,
CPU_CLK_2M = 240,
};
typedef union {
struct {
uint32_t CPU: 8; /*!< bit: 0.. 7 cpu clock divider */
uint32_t WLAN: 8; /*!< bit: 8.. 15 Wlan clock divider */
uint32_t BUS2: 8; /*!< bit: 16.. 23 clock dividing ratio of bus2 & bus1 */
uint32_t PD: 4; /*!< bit: 24.. 27 peripheral divider */
uint32_t RSV: 3; /*!< bit: 28.. 30 Reserved */
uint32_t DIV_EN: 1; /*!< bit: 31 divide frequency enable */
} b;
uint32_t w;
} clk_div_reg;
#define UNIT_MHZ (1000000)
typedef struct{
u32 apbclk;
u32 cpuclk;
u32 wlanclk;
}tls_sys_clk;
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup CPUCLK_Driver_APIs CPU CLOCK Driver APIs
* @brief CPU CLOCK driver APIs
*/
/**
* @addtogroup CPUCLK_Driver_APIs
* @{
*/
/**
* @brief This function is used to set cpu clock
*
* @param[in] clk select cpu clock
* clk == CPU_CLK_80M 80M
* clk == CPU_CLK_40M 40M
*
* @return None
*
* @note None
*/
void tls_sys_clk_set(u32 clk);
/**
* @brief This function is used to get cpu clock
*
* @param[out] *sysclk point to the addr for system clk output
*
* @return None
*
* @note None
*/
void tls_sys_clk_get(tls_sys_clk *sysclk);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_CPU_H */
+233
View File
@@ -0,0 +1,233 @@
/**
* @file wm_dma.h
*
* @brief DMA Driver Module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef __WM_DMA_H_
#define __WM_DMA_H_
#define TLS_DMA_SEL_UART_RX 0
#define TLS_DMA_SEL_UART_TX 1
#define TLS_DMA_SEL_PWM_CAP0 2
#define TLS_DMA_SEL_PWM_CAP1 3
#define TLS_DMA_SEL_LSSPI_RX 4
#define TLS_DMA_SEL_LSSPI_TX 5
#define TLS_DMA_SEL_SDADC_CH0 6
#define TLS_DMA_SEL_SDADC_CH1 7
#define TLS_DMA_SEL_SDADC_CH2 8
#define TLS_DMA_SEL_SDADC_CH3 9
#define TLS_DMA_SEL_I2S_RX 10
#define TLS_DMA_SEL_I2S_TX 11
#define TLS_DMA_SEL_SDIO_HOST 12
#define TLS_DMA_FLAGS_HARD_MODE (1 << 0)
#define TLS_DMA_FLAGS_CHAIN_MODE (1 << 1)
#define TLS_DMA_FLAGS_CHANNEL_SEL(n) ((n) << 2)
#define TLS_DMA_FLAGS_CHAIN_LINK_EN (1 << 6)
#define TLS_DMA_FLAGS_CHANNEL_VALID (1 << 7)
#define TLS_DMA_DESC_VALID (1U << 31)
#define TLS_DMA_DESC_CTRL_SRC_ADD_INC (1 << 0)
#define TLS_DMA_DESC_CTRL_DEST_ADD_INC (1 << 2)
#define TLS_DMA_DESC_CTRL_DATA_SIZE_BYTE (0 << 4)
#define TLS_DMA_DESC_CTRL_DATA_SIZE_SHORT (1 << 4)
#define TLS_DMA_DESC_CTRL_DATA_SIZE_WORD (2 << 4)
#define TLS_DMA_DESC_CTRL_BURST_SIZE1 (0 << 6)
#define TLS_DMA_DESC_CTRL_BURST_SIZE4 (1 << 6)
#define TLS_DMA_DESC_CTRL_TOTAL_BYTES(n) ((n) << 7)
/* dma interrupt flags */
#define TLS_DMA_IRQ_BURST_DONE (1 << 0)
#define TLS_DMA_IRQ_TRANSFER_DONE (1 << 1)
#define TLS_DMA_IRQ_BOTH_DONE (TLS_DMA_IRQ_BURST_DONE | TLS_DMA_IRQ_TRANSFER_DONE)
struct tls_dma_descriptor {
unsigned int valid;
unsigned int dma_ctrl;
unsigned int src_addr;
unsigned int dest_addr;
struct tls_dma_descriptor *next; /**< next dms descriptor */
};
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup DMA_Driver_APIs DMA Driver APIs
* @brief DMA driver APIs
*/
/**
* @addtogroup DMA_Driver_APIs
* @{
*/
/**
* @brief This function is used to clear dma interrupt flag.
*
* @param[in] ch Channel no.[0~7]
* @param[in] flags Flags setted to TLS_DMA_IRQ_BURST_DONE, TLS_DMA_IRQ_TRANSFER_DONE, TLS_DMA_IRQ_BOTH_DONE.
*
* @return None
*
* @note None
*/
void tls_dma_irq_clr(unsigned char ch, unsigned char flags);
/**
* @brief This function is used to register dma interrupt callback function.
*
* @param[in] ch Channel no.[0~7]
* @param[in] callback is the dma interrupt call back function.
* @param[in] arg the param of the callback function.
* @param[in] flags Flags setted to TLS_DMA_IRQ_BURST_DONE, TLS_DMA_IRQ_TRANSFER_DONE, TLS_DMA_IRQ_BOTH_DONE.
*
* @return None
*
* @note None
*/
void tls_dma_irq_register(unsigned char ch, void (*callback)(void *p), void *arg, unsigned char flags);
/**
* @brief This function is used to register dma interrupt
*
* @param[in] ch DMA channel no.[0~7]
*
* @return None
*
* @note None
*/
int tls_dma_wait_complt(unsigned char ch);
/**
* @brief This function is used to Start the DMA controller by Wrap
*
* @param[in] autoReload Does restart when current transfer complete?
* @param[in] ch Channel no.[0~7]
* @param[in] pDmaDesc Pointer to DMA channel descriptor structure.
*
* @retval Always STATUS_SUCCESS.
*
* @note
* DMA Descriptor:
* +--------------------------------------------------------------+
* |Vld[31] | RSV |
* +--------------------------------------------------------------+
* | RSV | Dma_Ctrl[16:0] |
* +--------------------------------------------------------------+
* | Src_Addr[31:0] |
* +--------------------------------------------------------------+
* | Dest_Addr[31:0] |
* +--------------------------------------------------------------+
* | Next_Desc_Add[31:0] |
* +--------------------------------------------------------------+
*/
unsigned char tls_dma_start_by_wrap(unsigned char ch, struct tls_dma_descriptor *dma_desc,
unsigned char auto_reload, unsigned short src_zize,
unsigned short dest_zize);
/**
* @brief This function is used to Wait until DMA operation completes
*
* @param[in] autoReload Does restart when current transfer complete?
* @param[in] ch Channel no.[0~7]
* @param[in] pDmaDesc Pointer to DMA channel descriptor structure.
*
* @retval Always STATUS_SUCCESS.
*
* @note
* DMA Descriptor:
* +--------------------------------------------------------------+
* |Vld[31] | RSV |
* +--------------------------------------------------------------+
* | RSV | Dma_Ctrl[16:0] |
* +--------------------------------------------------------------+
* | Src_Addr[31:0] |
* +--------------------------------------------------------------+
* | Dest_Addr[31:0] |
* +--------------------------------------------------------------+
* | Next_Desc_Add[31:0] |
* +--------------------------------------------------------------+
*/
unsigned char tls_dma_start(unsigned char ch, struct tls_dma_descriptor *dma_desc,
unsigned char auto_reload);
/**
* @brief This function is used to To stop current DMA channel transfer
*
* @param[in] ch channel no. to be stopped
*
* @retval Always STATUS_SUCCESS
*
* @note If channel stop, DMA_CHNL_CTRL_CHNL_ON bit in DMA_CHNLCTRL_REG is cleared.
*/
unsigned char tls_dma_stop(unsigned char ch);
/**
* @brief This function is used to Request a free dma channel
* If ch is out of range [0,7] or valid but used, the function will select another free channel.
* else return the selected channel no.
* @param[in] ch specified channel when ch is valid and not used.
* @param[in] flags flags setted to selected channel
*
* @return Real DMA Channel No: if there is free dma channel.
* 0xFF: when DMA channels are all used.
*
* @note If ch is invalid or valid but used, the function will select another free channel.
* else return the selected channel no.
*/
unsigned char tls_dma_request(unsigned char ch, unsigned char flags);
/**
* @brief This function is used to Free the DMA channel when not use
*
* @param[in] ch channel no. that is ready to free
*
* @return None
*
* @note None
*/
void tls_dma_free(unsigned char ch);
/**
* @brief This function is used to Initialize DMA Control
*
* @param[in] None
*
* @return None
*
* @note None
*/
void tls_dma_init(void);
/**
* @}
*/
/**
* @}
*/
#endif /* __TLS_DMA_H_151606__ */
+285
View File
@@ -0,0 +1,285 @@
/**
* @file wm_efuse.h
*
* @brief virtual efuse Driver Module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_EFUSE_H
#define WM_EFUSE_H
#define TLS_EFUSE_STATUS_OK (0)
#define TLS_EFUSE_STATUS_EINVALID (1)
#define TLS_EFUSE_STATUS_EIO (2)
enum {
CMD_WIFI_MAC = 0x01,
CMD_BT_MAC,
CMD_TX_DC,
CMD_RX_DC,
CMD_TX_IQ_GAIN,
CMD_RX_IQ_GAIN,
CMD_TX_IQ_PHASE,
CMD_RX_IQ_PHASE,
CMD_TX_GAIN,
CMD_ALL,
};
#define FREQERR_ADDR (FT_MAGICNUM_ADDR + sizeof(FT_PARAM_ST))
#define FREQERR_LEN (4)
#define CAL_FLAG_ADDR (FT_MAGICNUM_ADDR + sizeof(FT_PARAM_ST)+4)
#define CAL_FLAG_LEN (4)
//#define TX_GAIN_NEW_ADDR (VCG_ADDR+VCG_LEN)
#define TX_GAIN_LEN (28*3)
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup EFUSE_Driver_APIs EFUSE Driver APIs
* @brief EFUSE driver APIs
*/
/**
* @addtogroup EFUSE_Driver_APIs
* @{
*/
/**
* @brief This function is used to init ft param.
*
* @param[in] None
*
* @retval TRUE init success
* @retval FALSE init failed
*/
int tls_ft_param_init(void);
/**
* @brief This function is used to write ft_param.
*
* @param[in] opnum ft cmd
* @param[in] data data pointer
* @param[in] len len to write data
*
* @retval TLS_EFUSE_STATUS_OK set success
* @retval TLS_EFUSE_STATUS_EIO set failed
*/
int tls_ft_param_set(unsigned int opnum, void *data, unsigned int len);
/**
* @brief This function is used to read ft_param.
*
* @param[in] opnum ft cmd
* @param[in] data data pointer
* @param[in] len len to read data
*
* @retval TLS_EFUSE_STATUS_OK get success
* @retval TLS_EFUSE_STATUS_EIO get failed
*/
int tls_ft_param_get(unsigned int opnum, void *data, unsigned int rdlen);
/**
* @brief This function is used to get mac addr
*
* @param[in] mac mac addr,6 byte
*
* @retval TLS_EFUSE_STATUS_OK get success
* @retval TLS_EFUSE_STATUS_EIO get failed
*/
int tls_get_mac_addr(u8 *mac);
/**
* @brief This function is used to set mac addr
*
* @param[in] mac mac addr,6 byte
*
* @retval TLS_EFUSE_STATUS_OK set success
* @retval TLS_EFUSE_STATUS_EIO set failed
*/
int tls_set_mac_addr(u8 *mac);
/**
* @brief This function is used to get bluetooth mac addr
*
* @param[in] mac mac addr,6 byte
*
* @retval TLS_EFUSE_STATUS_OK get success
* @retval TLS_EFUSE_STATUS_EIO get failed
*/
int tls_get_bt_mac_addr(u8 *mac);
/**
* @brief This function is used to set bluetooth mac addr
*
* @param[in] mac mac addr,6 byte
*
* @retval TLS_EFUSE_STATUS_OK set success
* @retval TLS_EFUSE_STATUS_EIO set failed
*/
int tls_set_bt_mac_addr(u8 *mac);
/**
* @brief This function is used to get tx gain
*
* @param[in] txgain tx gain,12 byte
*
* @retval TLS_EFUSE_STATUS_OK get success
* @retval TLS_EFUSE_STATUS_EIO get failed
*/
int tls_get_tx_gain(u8 *txgain);
/**
* @brief This function is used to set tx gain
*
* @param[in] txgain tx gain,12 byte
*
* @retval TLS_EFUSE_STATUS_OK set success
* @retval TLS_EFUSE_STATUS_EIO set failed
*/
int tls_set_tx_gain(u8 *txgain);
/**
* @brief This function is used to get tx lod
*
* @param[in] txlo tx lod
*
* @retval TLS_EFUSE_STATUS_OK get success
* @retval TLS_EFUSE_STATUS_EIO get failed
*/
int tls_get_tx_lo(u8 *txlo);
/**
* @brief This function is used to set tx lod
*
* @param[in] txlo tx lod
*
* @retval TLS_EFUSE_STATUS_OK set success
* @retval TLS_EFUSE_STATUS_EIO set failed
*/
int tls_set_tx_lo(u8 *txlo);
/**
* @brief This function is used to get tx iq gain
*
* @param[in] txGain
*
* @retval TLS_EFUSE_STATUS_OK get success
* @retval TLS_EFUSE_STATUS_EIO get failed
*/
int tls_get_tx_iq_gain(u8 *txGain);
/**
* @brief This function is used to set tx iq gain
*
* @param[in] txGain
*
* @retval TLS_EFUSE_STATUS_OK set success
* @retval TLS_EFUSE_STATUS_EIO set failed
*/
int tls_set_tx_iq_gain(u8 *txGain);
/**
* @brief This function is used to get rx iq gain
*
* @param[in] rxGain
*
* @retval TLS_EFUSE_STATUS_OK get success
* @retval TLS_EFUSE_STATUS_EIO get failed
*/
int tls_get_rx_iq_gain(u8 *rxGain);
/**
* @brief This function is used to get rx iq gain
*
* @param[in] rxGain
*
* @retval TLS_EFUSE_STATUS_OK set success
* @retval TLS_EFUSE_STATUS_EIO set failed
*/
int tls_set_rx_iq_gain(u8 *rxGain);
/**
* @brief This function is used to get tx iq phase
*
* @param[in] txPhase
*
* @retval TLS_EFUSE_STATUS_OK get success
* @retval TLS_EFUSE_STATUS_EIO get failed
*/
int tls_get_tx_iq_phase(u8 *txPhase);
/**
* @brief This function is used to set tx iq phase
*
* @param[in] txPhase
*
* @retval TLS_EFUSE_STATUS_OK set success
* @retval TLS_EFUSE_STATUS_EIO set failed
*/
int tls_set_tx_iq_phase(u8 *txPhase);
/**
* @brief This function is used to get rx iq phase
*
* @param[in] rxPhase
*
* @retval TLS_EFUSE_STATUS_OK get success
* @retval TLS_EFUSE_STATUS_EIO get failed
*/
int tls_get_rx_iq_phase(u8 *rxPhase);
/**
* @brief This function is used to set rx iq phase
*
* @param[in] rxPhase
*
* @retval TLS_EFUSE_STATUS_OK set success
* @retval TLS_EFUSE_STATUS_EIO set failed
*/
int tls_set_rx_iq_phase(u8 *rxPhase);
/**
* @brief This function is used to set/get freq err
*
* @param[in] freqerr (Unit:Hz),relative to base frequency(chan 1,2,3,4,5......13,14)
* @param[in] flag 1-set 0-get
* @retval TLS_EFUSE_STATUS_OK set/get success
* @retval TLS_EFUSE_STATUS_EIO set/get failed
*/
int tls_freq_err_op(u8 *freqerr, u8 flag);
/**
* @brief This function is used to set/get cal finish flag
*
* @param[in] calflag 1- finish calibration, non-1-do not calibration
* @param[in] flag 1-set 0-get
*
* @retval TLS_EFUSE_STATUS_OK set/get success
* @retval TLS_EFUSE_STATUS_EIO set/get failed
*/
int tls_rf_cal_finish_op(u8 *calflag, u8 flag);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_EFUSE_H */
+159
View File
@@ -0,0 +1,159 @@
/**
* @file wm_flash.h
*
* @brief flash Driver module
*
* @author dave
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_FLASH_H
#define WM_FLASH_H
#include "wm_type_def.h"
#include "wm_osal.h"
#define TLS_FLS_STATUS_OK (0)
#define TLS_FLS_STATUS_EINVAL (1)
#define TLS_FLS_STATUS_EBUSY (2)
#define TLS_FLS_STATUS_EPERM (3)
#define TLS_FLS_STATUS_ENOSUPPORT (4)
#define TLS_FLS_STATUS_EEXIST (5)
#define TLS_FLS_STATUS_ENOMEM (6)
#define TLS_FLS_STATUS_EOVERFLOW (7)
#define TLS_FLS_STATUS_ENODEV (8)
#define TLS_FLS_STATUS_EDEV (9)
#define TLS_FLS_STATUS_EIO (10)
#define TLS_FLS_STATUS_ENODRV (11)
#define TLS_FLS_PARAM_TYPE_ID (0)
#define TLS_FLS_PARAM_TYPE_SIZE (1)
#define TLS_FLS_PARAM_TYPE_PAGE_SIZE (2)
#define TLS_FLS_PARAM_TYPE_PROG_SIZE (3)
#define TLS_FLS_PARAM_TYPE_SECTOR_SIZE (4)
#define TLS_FLS_FLAG_UNDER_PROTECT (1<<0)
#define TLS_FLS_FLAG_FAST_READ (1<<1)
#define TLS_FLS_FLAG_AAAI (1<<2)
#define FLS_CMD_READ_DEV_ID (0x9F) // read device id //(0x9f)
/**
* @struct fls_list list
*/
struct fls_list
{
struct fls_list *next;
struct fls_list *prev;
};
/**
* @struct tls_fls_drv flash driver
*/
struct tls_fls_drv
{
struct fls_list drv_list;
u32 id;
u32 total_size;
u32 page_size;
u32 program_size;
u32 sector_size;
u32 clock;
u8 mode;
u8 cs_active;
u8 flags;
int (*read) (u32, u8 *, u32);
int (*fast_read) (u32, u8 *, u32);
int (*page_write) (u32, u8 *);
int (*erase) (u32);
int (*chip_erase) (void);
int (*probe)(u32 id);
void (*remove) (void);
};
/**
* @struct tls_fls flash
*/
struct tls_fls
{
struct fls_list fls_drvs;
struct tls_fls_drv *current_drv;
tls_os_sem_t *fls_lock;
};
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup SPIFLASH_Driver_APIs SPI FLASH Driver APIs
* @brief SPI FLASH driver APIs
*/
/**
* @addtogroup SPIFLASH_Driver_APIs
* @{
*/
/**
* @brief This function is used to initial flash module structer.
*
* @param[in] None
*
* @retval TLS_FLS_STATUS_OK if init sucsess
* @retval TLS_FLS_STATUS_EBUSY already inited
* @retval TLS_FLS_STATUS_ENOMEM memory error
*
* @note None
*/
int tls_spifls_init(void);
/**
* @brief This function is used to read data from the flash.
*
* @param[in] addr Specifies the starting address to read from
* @param[in] buf Pointer to a byte array that is to be written.
* @param[in] len length to read.
*
* @retval TLS_FLS_STATUS_OK if read sucsess
* @retval TLS_FLS_STATUS_EIO if read fail
*
* @note None
*/
int tls_spifls_read(u32 addr, u8 * buf, u32 len);
/**
* @brief This function is used to write data into the flash.
*
* @param[in] addr Specifies the starting address to write to.
* @param[in] buf Pointer to a byte array that holds the data to be written.
* @param[in] len length to write.
*
* @retval TLS_FLS_STATUS_OK if write flash success
* @retval TLS_FLS_STATUS_EPERM if flash struct point is null
* @retval TLS_FLS_STATUS_ENODRV if flash driver is not installed
* @retval TLS_FLS_STATUS_EINVAL if argument is invalid
* @retval TLS_FLS_STATUS_EIO if io error
*
* @note None
*/
int tls_spifls_write(u32 addr, u8 * buf, u32 len);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_FLASH_H */
+39
View File
@@ -0,0 +1,39 @@
/**
* @file wm_flash_map.h
*
* @brief flash zone map
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef __WM_FLASH_MAP_H__
#define __WM_FLASH_MAP_H__
/**FLASH MAP**/
/**Flash Base Address */
#define FLASH_BASE_ADDR (0x8000000UL)
/**Upgrade image area*/
#define CODE_UPD_START_ADDR (0x8010000UL)
/**Run-time image header area*/
#define CODE_RUN_START_ADDR (0x80D0000UL)
/**Area can be used by User*/
#define USER_ADDR_START (0x81E0000UL)
/**System parameter defined in wm_internal_fls.c*/
extern unsigned int TLS_FLASH_PARAM_DEFAULT;
extern unsigned int TLS_FLASH_PARAM1_ADDR;
extern unsigned int TLS_FLASH_PARAM2_ADDR;
extern unsigned int TLS_FLASH_PARAM_RESTORE_ADDR;
extern unsigned int TLS_FLASH_OTA_FLAG_ADDR;
extern unsigned int TLS_FLASH_END_ADDR;
#define SIGNATURE_WORD (0xA0FFFF9FUL)
#define IMAGE_START_ADDR_MSK (0x400)
#endif /*__WM_CONFIG_H__*/
+60
View File
@@ -0,0 +1,60 @@
/**
* @file wm_fls_gd25qxx.h
*
* @brief wm gd25qxx flash driver
*
* @author dave
*
* @copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef TLS_EXSPIFLS_H
#define TLS_EXSPIFLS_H
#define SPI_SCLK (10000000) /** 10MHz. */
#define FLASH_TOTAL_SIZE (1024*1024)
#define PAGE_SIZE 256
#define PROGRAM_SIZE 256
#define PAGE_ADDR_OFFSET 8
#define SECTOR_SIZE 4096
/**
* command code define.
*/
#define EXSPIFLASH_WRITE_ENABLE (0x06) /** Global write enable */
#define EXSPIFLASH_WRITE_DISABLE (0x04) /** Global write disable */
#define EXSPIFLASH_READ_SR1 (0x05) /** Read flash status register s0~s7 */
#define EXSPIFLASH_READ_SR2 (0x35) /** Read flash status register s8~s15 */
#define EXSPIFLASH_WRITE_SR (0x01) /** Write flash status register s0~s15 */
#define EXSPIFLASH_PAGE_PROGRAM (0x02) /** program one page */
#define EXSPIFLASH_DATA_READ (0x03) /** read data from specified address */
#define EXSPIFLASH_DATA_FAST_READ (0x0b) /** fast read data from specified address */
#define EXSPIFLASH_SECTOR_ERASE (0x20) /** Sector erase */
#define EXSPIFLASH_BLOCK32_ERASE (0x52) /** 32KB Block erase(128 pages) */
#define EXSPIFLASH_BLOCK64_ERASE (0xd8) /** 64kb Block erase(256 pages) */
#define EXSPIFLASH_CHIP_ERASE (0xc7) /** Chip erase */
#define EXSPIFLASH_FLASH_DEVICEID (0x90) /** Read flash manufacturer/device ID */
#define EXSPIFLASH_FLASH_ID (0x9f) /** Read flash ID */
#define FLASH_STATUS_BUSY (1 << 0)
#define FLASH_STATUS_WEL (1 << 1)
/**
* @brief This function is used to install gd25qxx driver.
*
* @param[in] None
*
* @retval TLS_FLS_STATUS_OK if write flash success
* @retval TLS_FLS_STATUS_EPERM if flash struct point is null
* @retval TLS_FLS_STATUS_ENODRV if flash driver is not installed
* @retval TLS_FLS_STATUS_EINVAL if argument is invalid
* @retval TLS_FLS_STATUS_EIO if io error
* @retval TLS_FLS_STATUS_EEXIST if driver is already existed
*
* @note None
*/
int tls_spifls_drv_install(void);
#endif /* TLS_FLS_GD25QXX_H */
+181
View File
@@ -0,0 +1,181 @@
/**
* @file wm_gpio.h
*
* @brief GPIO Driver Module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_GPIO_H
#define WM_GPIO_H
#include "wm_type_def.h"
#include "wm_io.h"
/** gpio interrupte callback function */
typedef void (*tls_gpio_irq_callback)(void *arg);
/** Indicating gpio direction */
enum tls_gpio_dir {
WM_GPIO_DIR_OUTPUT, /**< output */
WM_GPIO_DIR_INPUT /**< input */
};
/** Indicating gpio attribute */
enum tls_gpio_attr {
WM_GPIO_ATTR_FLOATING, /**< floating status */
WM_GPIO_ATTR_PULLHIGH, /**< pull high */
WM_GPIO_ATTR_PULLLOW /**< pull low */
};
/** Indicating gpio interrupt trigger type */
enum tls_gpio_irq_trig {
WM_GPIO_IRQ_TRIG_RISING_EDGE, /**< rising edge arises the interrupt */
WM_GPIO_IRQ_TRIG_FALLING_EDGE, /**< falling edge arises the interrupt */
WM_GPIO_IRQ_TRIG_DOUBLE_EDGE, /**< both rising edge and falling edge arise the interrupt */
WM_GPIO_IRQ_TRIG_HIGH_LEVEL, /**< high power level arises the interrupt */
WM_GPIO_IRQ_TRIG_LOW_LEVEL /**< low power level arises the interrupt */
};
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup GPIO_Driver_APIs GPIO Driver APIs
* @brief GPIO driver APIs
*/
/**
* @addtogroup GPIO_Driver_APIs
* @{
*/
/**
* @brief This function is used to config gpio function
*
* @param[in] gpio_pin gpio pin num
* @param[in] dir gpio direction
* @param[in] attr gpio attribute
*
* @return None
*
* @note None
*/
void tls_gpio_cfg(enum tls_io_name gpio_pin, enum tls_gpio_dir dir, enum tls_gpio_attr attr);
/**
* @brief This function is used to read gpio status
*
* @param[in] gpio_pin gpio pin num
*
* @retval 0 power level is low
* @retval 1 power level is high
*
* @note None
*/
u8 tls_gpio_read(enum tls_io_name gpio_pin);
/**
* @brief This function is used to modify gpio status
*
* @param[in] gpio_pin gpio pin num
* @param[in] value power level
* 0: low power level
* 1: high power level
*
* @return None
*
* @note None
*/
void tls_gpio_write(enum tls_io_name gpio_pin, u8 value);
/**
* @brief This function is used to config gpio interrupt
*
* @param[in] gpio_pin gpio pin num
* @param[in] mode interrupt trigger type
*
* @return None
*
* @note None
*/
void tls_gpio_irq_enable(enum tls_io_name gpio_pin, enum tls_gpio_irq_trig mode);
/**
* @brief This function is used to disable gpio interrupt
*
* @param[in] gpio_pin gpio pin num
*
* @return None
*
* @note None
*/
void tls_gpio_irq_disable(enum tls_io_name gpio_pin);
/**
* @brief This function is used to get gpio interrupt status
*
* @param[in] gpio_pin gpio pin num
*
* @retval 0 no interrupt happened
* @retval 1 interrupt happened
*
* @note None
*/
u8 tls_get_gpio_irq_status(enum tls_io_name gpio_pin);
/**
* @brief This function is used to clear gpio interrupt flag
*
* @param[in] gpio_pin gpio pin num
*
* @return None
*
* @note None
*/
void tls_clr_gpio_irq_status(enum tls_io_name gpio_pin);
/**
* @brief This function is used to register gpio interrupt
*
* @param[in] gpio_pin gpio pin num
* @param[in] callback the gpio interrupt call back function
* @param[in] arg parammeter for the callback
*
* @return None
*
* @note
* gpio callback function is called in interrupt,
* so can not operate the critical data in the callback fuuction,
* recommendation to send messages to other tasks to operate it.
*/
void tls_gpio_isr_register(enum tls_io_name gpio_pin,
tls_gpio_irq_callback callback,
void *arg);
/**
* @}
*/
/**
* @}
*/
#endif /* end of WM_GPIO_H */
+589
View File
@@ -0,0 +1,589 @@
/**
* @file wm_gpio_afsel.h
*
* @brief GPIO Driver Module
*
* @author dave
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_GPIO_AFSEL_H
#define WM_GPIO_AFSEL_H
#include "wm_gpio.h"
#include "wm_regs.h"
#include "wm_irq.h"
#include "wm_osal.h"
#include "tls_common.h"
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup IOMUX_Driver_APIs IOMUX Driver APIs
* @brief IO Multiplex driver APIs
*/
/**
* @addtogroup IOMUX_Driver_APIs
* @{
*/
/**
* @brief config the pins used for highspeed spi
* @param numsel: config highspeed spi pins multiplex relation,valid para 0,1
* 0: hspi0 1: hspi1 only for 56pin
* hspi_ck PB06 hspi_ck PB12
* hspi_int PB07 hspi_int PB13
* hspi_cs PB09 hspi_cs PB14
* hspi_di PB10 hspi_di PB15
* hspi_do PB11 hspi_do PB16
* @return None
*/
void wm_hspi_gpio_config(uint8_t numsel);
/**
* @brief config the pins used for spi ck
* @param io_name: config spi ck pins name
* WM_IO_PB_01
* WM_IO_PB_02
* WM_IO_PB_15 only for 56pin
* WM_IO_PB_24 only for 56pin
*
* @return None
*/
void wm_spi_ck_config(enum tls_io_name io_name);
/**
* @brief config the pins used for spi cs
* @param io_name: config spi cs pins name
* WM_IO_PA_00
* WM_IO_PB_04
* WM_IO_PB_14 only for 56pin
* WM_IO_PB_23 only for 56pin
*
* @return None
*/
void wm_spi_cs_config(enum tls_io_name io_name);
/**
* @brief config the pins used for spi di
* @param io_name: config spi di pins name
* WM_IO_PB_00
* WM_IO_PB_03
* WM_IO_PB_16 only for 56pin
* WM_IO_PB_25 only for 56pin
*
* @return None
*/
void wm_spi_di_config(enum tls_io_name io_name);
/**
* @brief config the pins used for spi do
* @param io_name: config spi do pins name
* WM_IO_PA_07
* WM_IO_PB_05
* WM_IO_PB_17 only for 56pin
* WM_IO_PB_26 only for 56pin
*
* @return None
*/
void wm_spi_do_config(enum tls_io_name io_name);
/**
* @brief config the pins used for sdio host ck dat0 dat1 dat2 dat3
* @param numsel: config sdio ck cmd dat0 dat1 dat2 dat3 pins multiplex relation,valid para 0,1
* 0: 1: only for 56pin
* sdio_ck PB06 sdio_ck PA09
* sdio_cmd PB07 sdio_cmd PA10
* sdio_dat0 PB08 sdio_dat0 PA11
* sdio_dat1 PB09 sdio_dat1 PA12
* sdio_dat2 PB10 sdio_dat2 PA13
* sdio_dat3 PB11 sdio_dat3 PA14
*
* @return None
*/
void wm_sdio_host_config(uint8_t numsel);
/**
* @brief config the pins used for sdio slave ck dat0 dat1 dat2 dat3
* @param numsel: config sdio ck cmd dat0 dat1 dat2 dat3 pins multiplex relation,valid para 0
* 0:
* sdio_ck PB06
* sdio_cmd PB07
* sdio_dat0 PB08
* sdio_dat1 PB09
* sdio_dat2 PB10
* sdio_dat3 PB11
*
* @return None
*/
void wm_sdio_slave_config(uint8_t numsel);
/**
* @brief config the pins used for psram ck cs dat0 dat1 dat2 dat3
* @param numsel: config psram ck cs dat0 dat1 dat2 dat3 pins multiplex relation,valid para 0,1
* 0: 1: only for 56pin
* psram_ck PB00 psram_ck PA15
* psram_cs PB01 psram_cs PB27
* psram_dat0 PB02 psram_dat0 PB02
* psram_dat1 PB03 psram_dat1 PB03
* psram_dat2 PB04 psram_dat2 PB04
* psram_dat3 PB05 psram_dat3 PB05
* @return None
*/
void wm_psram_config(uint8_t numsel);
/**
* @brief config the pins used for uart0 tx
* @param io_name: config uart0 tx pins name
* WM_IO_PB_19
* WM_IO_PB_27 only for 56pin
*
* @return None
*/
void wm_uart0_tx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart0 rx
* @param io_name: config uart0 rx pins name
* WM_IO_PB_20
*
* @return None
*/
void wm_uart0_rx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart1 tx
* @param io_name: config uart1 tx pins name
* WM_IO_PB_06
*
* @return None
*/
void wm_uart1_tx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart1 rx
* @param io_name: config uart1 rx pins name
* WM_IO_PB_07
* WM_IO_PB_16 only for 56pin
*
* @return None
*/
void wm_uart1_rx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart1 rts
* @param io_name: config uart1 rts pins name
* WM_IO_PB_19
* WM_IO_PA_02 only for 56pin
*
* @return None
*/
void wm_uart1_rts_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart1 cts
* @param io_name: config uart1 cts pins name
* WM_IO_PB_20
* WM_IO_PA_03 only for 56pin
*
* @return None
*/
void wm_uart1_cts_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart2 tx or 7816-io
* @param io_name: config uart2 tx or 7816-io pins name
* WM_IO_PB_02
* WM_IO_PA_02 only for 56pin
*
* @return None
*/
void wm_uart2_tx_scio_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart2 rx
* @param io_name: config uart2 rx pins name
* WM_IO_PB_03
* WM_IO_PA_03 only for 56pin
*
* @return None
*/
void wm_uart2_rx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart2 rts or 7816-clk
* @param io_name: config uart2 rts or 7816-clk pins name
* WM_IO_PB_04
* WM_IO_PA_05 only for 56pin
*
* @return None
*/
void wm_uart2_rts_scclk_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart2 cts
* @param io_name: config uart2 cts pins name
* WM_IO_PB_05
* WM_IO_PA_06 only for 56pin
*
* @return None
*/
void wm_uart2_cts_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart3 tx
* @param io_name: config uart1 tx pins name
* WM_IO_PB_00
* WM_IO_PA_05 only for 56pin
*
* @return None
*/
void wm_uart3_tx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart3 rx
* @param io_name: config uart1 rx pins name
* WM_IO_PB_01
* WM_IO_PA_06 only for 56pin
*
* @return None
*/
void wm_uart3_rx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart3 rts
* @param io_name: config uart3 rts pins name
* WM_IO_PA_02
*
* @return None
*/
void wm_uart3_rts_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart3 cts
* @param io_name: config uart3 cts pins name
* WM_IO_PA_03
*
* @return None
*/
void wm_uart3_cts_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart4 tx
* @param io_name: config uart1 tx pins name
* WM_IO_PB_04
* WM_IO_PA_08 only for 56pin
*
* @return None
*/
void wm_uart4_tx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart4 rx
* @param io_name: config uart1 rx pins name
* WM_IO_PB_05
* WM_IO_PA_09 only for 56pin
*
* @return None
*/
void wm_uart4_rx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart4 rts
* @param io_name: config uart4 rts pins name
* WM_IO_PA_05 only for 56pin
* WM_IO_PA_10 only for 56pin
*
* @return None
*/
void wm_uart4_rts_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart4 cts
* @param io_name: config uart4 cts pins name
* WM_IO_PA_06 only for 56pin
* WM_IO_PA_11 only for 56pin
*
* @return None
*/
void wm_uart4_cts_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart4 tx
* @param io_name: config uart1 tx pins name
* WM_IO_PA_08 only for 56pin
* WM_IO_PA_12 only for 56pin
* WM_IO_PB_18 only for 56pin
*
* @return None
*/
void wm_uart5_tx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart4 rx
* @param io_name: config uart1 rx pins name
* WM_IO_PA_09 only for 56pin
* WM_IO_PA_13 only for 56pin
* WM_IO_PB_17 only for 56pin
*
* @return None
*/
void wm_uart5_rx_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart4 rts
* @param io_name: config uart4 rts pins name
* WM_IO_PA_14 only for 56pin
* WM_IO_PB_12 only for 56pin
*
* @return None
*/
void wm_uart5_rts_config(enum tls_io_name io_name);
/**
* @brief config the pins used for uart4 cts
* @param io_name: config uart4 cts pins name
* WM_IO_PA_15 only for 56pin
* WM_IO_PB_13 only for 56pin
*
* @return None
*/
void wm_uart5_cts_config(enum tls_io_name io_name);
/**
* @brief config the pins used for i2s ck
* @param io_name: config i2s master ck pins name
* WM_IO_PA_04
* WM_IO_PB_08
* WM_IO_PA_08 only for 56pin
* WM_IO_PB_12 only for 56pin
*
* @return None
*/
void wm_i2s_ck_config(enum tls_io_name io_name);
/**
* @brief config the pins used for i2s ws
* @param io_name: config i2s master ws pins name
* WM_IO_PA_01
* WM_IO_PB_09
* WM_IO_PA_09 only for 56pin
* WM_IO_PB_13 only for 56pin
*
* @return None
*/
void wm_i2s_ws_config(enum tls_io_name io_name);
/**
* @brief config the pins used for i2s do
* @param io_name: config i2s master do pins name
* WM_IO_PA_00
* WM_IO_PB_11
* WM_IO_PA_10 only for 56pin
* WM_IO_PB_14 only for 56pin
*
* @return None
*/
void wm_i2s_do_config(enum tls_io_name io_name);
/**
* @brief config the pins used for i2s di
* @param io_name: config i2s slave di pins name
* WM_IO_PA_07
* WM_IO_PB_10
* WM_IO_PA_11 only for 56pin
* WM_IO_PB_15 only for 56pin
*
* @return None
*/
void wm_i2s_di_config(enum tls_io_name io_name);
/**
* @brief config the pins used for i2s mclk
* @param io_name: config i2s mclk pins name
* WM_IO_PA_00
*
* @return None
*/
void wm_i2s_mclk_config(enum tls_io_name io_name);
/**
* @brief config the pins used for i2s extclk
* @param io_name: config i2s extclk pins name
* WM_IO_PA_07
*
* @return None
*/
void wm_i2s_extclk_config(enum tls_io_name io_name);
/**
* @brief config the pins used for i2c scl
* @param io_name: config i2c scl pins name
* WM_IO_PA_01
* WM_IO_PB_20
*
* @return None
*/
void wm_i2c_scl_config(enum tls_io_name io_name);
/**
* @brief config the pins used for i2c sda
* @param io_name: config i2c sda pins name
* WM_IO_PA_04
* WM_IO_PB_19
*
* @return None
*/
void wm_i2c_sda_config(enum tls_io_name io_name);
/**
* @brief config the pins used for pwm0
* @param io_name: config pwm1 pins name
* WM_IO_PB_00
* WM_IO_PB_19
* WM_IO_PA_02 only for 56pin
* WM_IO_PA_10 only for 56pin
* WM_IO_PB_12 only for 56pin
*
* @return None
*/
void wm_pwm0_config(enum tls_io_name io_name);
/**
* @brief config the pins used for pwm1
* @param io_name: config pwm1 pins name
* WM_IO_PB_01
* WM_IO_PB_20
* WM_IO_PA_03 only for 56pin
* WM_IO_PA_11 only for 56pin
* WM_IO_PB_13 only for 56pin
*
* @return None
*/
void wm_pwm1_config(enum tls_io_name io_name);
/**
* @brief config the pins used for pwm2
* @param io_name: config pwm3 pins name
* WM_IO_PA_00
* WM_IO_PB_02
* WM_IO_PA_12 only for 56pin
* WM_IO_PB_14 only for 56pin
* WM_IO_PB_24 only for 56pin
*
* @return None
*/
void wm_pwm2_config(enum tls_io_name io_name);
/**
* @brief config the pins used for pwm3
* @param io_name: config pwm4 pins name
* WM_IO_PA_01
* WM_IO_PB_03
* WM_IO_PA_13 only for 56pin
* WM_IO_PB_15 only for 56pin
* WM_IO_PB_25 only for 56pin
*
* @return None
*/
void wm_pwm3_config(enum tls_io_name io_name);
/**
* @brief config the pins used for pwm4
* @param io_name: config pwm5 pins name
* WM_IO_PA_04
* WM_IO_PA_07
* WM_IO_PA_14 only for 56pin
* WM_IO_PB_16 only for 56pin
* WM_IO_PB_26 only for 56pin
*
* @return None
*/
void wm_pwm4_config(enum tls_io_name io_name);
/**
* @brief config the pins used for pwm break
* @param io_name: config pwm break pins name
* WM_IO_PB_08
* WM_IO_PA_05 only for 56pin
* WM_IO_PA_08 only for 56pin
* WM_IO_PA_15 only for 56pin
* WM_IO_PB_17 only for 56pin
*
* @return None
*/
void wm_pwmbrk_config(enum tls_io_name io_name);
/**
* @brief config the pins used for swd
* @param enable: enable or disable chip swd function
* 1: enable
* 0: disable
*
* @return None
*/
void wm_swd_config(bool enable);
/**
* @brief config the pins used for adc
* @param Channel: the channel that shall be used
* 0~1: single-ended input
* 2~3: single-ended input only for 56pin
* 0 and 1 can be used differential input
* 2 and 3 can be used differential input only for 56pin
*
* @return None
*/
void wm_adc_config(u8 Channel);
/**
* @brief config the pins used for touch sensor
* @param io_name: config touch sensor pins name
* WM_IO_PA_07
* WM_IO_PB_00
* WM_IO_PB_01
* WM_IO_PB_02
* WM_IO_PB_03
* WM_IO_PB_04
* WM_IO_PB_05
* WM_IO_PB_06
* WM_IO_PB_07
* WM_IO_PB_08
* WM_IO_PB_09
* WM_IO_PA_09 only for 56pin
* WM_IO_PA_10 only for 56pin
* WM_IO_PA_12 only for 56pin
* WM_IO_PA_14 only for 56pin
*
* @return None
* @note If user use touch sensor function, firstly consider using WM_IO_PA_07 as TOUCH SENSOR pin.
*/
void wm_touch_sensor_config(enum tls_io_name io_name);
/**
* @brief disable all the gpio af
*
* @return None
*
* @note This function must call before any others for configure
* gpio Alternate functions
*/
void wm_gpio_af_disable(void);
/**
* @}
*/
/**
* @}
*/
#endif /* end of WM_GPIO_AFSEL_H */
+289
View File
@@ -0,0 +1,289 @@
/**
* @file wm_hostspi.h
*
* @brief host spi Driver Module
*
* @author dave
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_HOST_SPI_H
#define WM_HOST_SPI_H
#include "wm_type_def.h"
#include "list.h"
#include "wm_osal.h"
#include "wm_ram_config.h"
#define SPI_USE_DMA
#define SPI_DMA_CMD_MAX_SIZE (0x20)
#define SPI_DMA_BUF_MAX_SIZE (8160)
#define SPI_DMA_MAX_TRANS_SIZE (4092)
/**
* error code.
*/
#define TLS_SPI_STATUS_OK (0)
#define TLS_SPI_STATUS_EINVAL (-1)
#define TLS_SPI_STATUS_ENOMEM (-2)
#define TLS_SPI_STATUS_EBUSY (-3)
#define TLS_SPI_STATUS_ESHUTDOWN (-4)
#define TLS_SPI_STATUS_EPERM (-5)
#define TLS_SPI_STATUS_ECLKNOSUPPORT (-6)
#define TLS_SPI_STATUS_EMODENOSUPPORT (-7)
#define SPI_MASTER_FIFO_SIZE (32)
/**
* the SPI master controller's configuration data.
*/
/** configuration data. */
#define SPI_CPHA (0x01) /** clock phase. */
#define SPI_CPOL (0x02) /** clock polarity. */
#define TLS_SPI_MODE_0 (0|0) /** motorola mode. */
#define TLS_SPI_MODE_1 (0|SPI_CPHA)
#define TLS_SPI_MODE_2 (SPI_CPOL|0)
#define TLS_SPI_MODE_3 (SPI_CPOL|SPI_CPHA)
#define TLS_SPI_CS_LOW 0x00 /** chipselect active low. */
#define TLS_SPI_CS_HIGH 0x01 /** chipselect active high. */
#define TLS_SPI_FCLK_MIN (1000) /** minimum work clock rate(Hz). */
#define TLS_SPI_FCLK_MAX (APB_CLK/2) /** maximum work clock rate(Hz). */
/** default configuration data. */
#define SPI_DEFAULT_SPEED (2000000) /** default clock rate is 2MHz. */
#define SPI_DEFAULT_MODE (TLS_SPI_MODE_0) /** default mode MODE_0. */
#define SPI_CS_ACTIVE_MODE (TLS_SPI_CS_LOW) /** default chipselect mode is active low. */
#define SPI_CS_INACTIVE_MODE (TLS_SPI_CS_HIGH)
/** SPI transaction message status. */
#define SPI_MESSAGE_STATUS_IDLE (0)
#define SPI_MESSAGE_STATUS_INPROGRESS (1)
#define SPI_MESSAGE_STATUS_DONE (2)
/**slave type*/
#define SPI_SLAVE_FLASH 0 /**flash */
#define SPI_SLAVE_CARD 1 /** SD card */
#define SPI_SLAVE_CONTROL_PIN 0
/**transfer type*/
#define SPI_BYTE_TRANSFER 0 /**byte transfer*/
#define SPI_WORD_TRANSFER 1 /**word transfer*/
#define SPI_USE_DMA_TRANSFER 2 /** DMA transfer */
/**
* a read/write buffer pair
*
* SPI transfers always write the same number of bytes as they read.
* If the transmit buffer is null, zeroes will be shifted out while
* filling rx_buf. If the receive buffer is null, the data shifted in
* will be discarded.
*/
struct tls_spi_transfer
{
struct dl_list transfer_list; /**< transfers are sequenced through
tls_spi_message.transfers. */
const void *tx_buf; /**< data to be written, or NULL. */
void *rx_buf; /**< data to be read, or NULL. */
u32 len; /**< size of rx and tx buffers (in bytes). */
u32 delay_usecs; /**< microseconds to delay after this transfer. */
};
/**
* one multi-segment SPI transaction
*
* A struct tls_spi_message is used to execute an atomic sequence of data
* transfers, each represented by a struct tls_spi_transfer. The sequence
* is "atomic" in the sense that no other spi_message may use that SPI bus
* until that sequence completes.
*/
struct tls_spi_message
{
struct dl_list queue; /**< transaction messages are sequenced through
tls_spi_port.wait_queue. */
struct dl_list transfers; /**< list of transfer segments in this transaction. */
void (*complete) (void *); /**< called to report transaction completions. */
void *context; /**< the argument to complete() when it's called. */
u32 status; /**< transaction message status. */
};
/**
* driver structure to SPI master controller
*
* This data structure presents the SPI master controller's configuration
* data. The device attached to this SPI master controller share the same
* transfer mode, chipselect mode and clock rate. And this structure maintains
* a queue of tls_spi_message transactions and uses this tls_spi_message transaction
* to access to the SPI device. For each such message it queues, it calls the message's
* completion function when the transaction completes.
*/
struct tls_spi_port
{
u32 speed_hz; /**< clock rate to be used. */
u8 cs_active; /**< chipselect mode, maybe active low or active
high. */
u8 mode; /**< SPI transfer mode: mode_0(CPHA=0, CHOL=0),
mode_1(CPHA=0, CHOL=1), mode_2(CPHA=1,
CHOL=0), mode_3(CPHA=1, CHOL=1). */
u8 reconfig;
struct dl_list wait_queue; /**< wait list of transaction messages. */
tls_os_queue_t *lock;
tls_os_queue_t *msg_queue; /**< notify the schedule thread that there's
transaction message queued. */
struct tls_spi_message *current_message; /**< current transaction message
in-progressing. */
u32 current_remaining_transfer; /**< remaining transfer segments count in
current transaction message. */
struct tls_spi_transfer *current_transfer; /**< current transfer segment
in-progressing. */
u32 current_remaining_bytes; /**< remaining data length in current
transfer segment. */
u8 transtype; /**< transfer type */
};
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup MASTERSPI_Driver_APIs MASTER SPI Driver APIs
* @brief MASTERSPI driver APIs
*/
/**
* @addtogroup MASTERSPI_Driver_APIs
* @{
*/
/**
* @brief This function is used to initialize the SPI master driver.
*
* @param[in] None
*
* @retval TLS_SPI_STATUS_OK if initialize success
* @retval TLS_SPI_STATUS_EBUSY if SPI is already initialized
* @retval TLS_SPI_STATUS_ENOMEM if malloc SPI memory fail
*
* @note None
*/
int tls_spi_init(void);
/**
* @brief This function is used to setup the spi controller.
*
* @param[in] mode is CPOL and CPHA type defined in TLS_SPI_MODE_0 to TLS_SPI_MODE_3
* @param[in] cs_active is cs mode, defined as TLS_SPI_CS_LOW or TLS_SPI_CS_HIGH
* @param[in] fclk is spi clock,the unit is HZ.
*
* @retval TLS_SPI_STATUS_OK if setup success
* @retval TLS_SPI_STATUS_EMODENOSUPPORT if mode is not support
* @retval TLS_SPI_STATUS_EINVAL if cs_active is not support
* @retval TLS_SPI_STATUS_ECLKNOSUPPORT if fclk is not support
*
* @note None
*/
int tls_spi_setup(u8 mode, u8 cs_active, u32 fclk);
/**
* @brief This function is used to synchronous write data by SPI.
*
* @param[in] buf data to be sent.
* @param[in] len data length.
*
* @retval TLS_SPI_STATUS_OK if write success.
* @retval TLS_SPI_STATUS_EINVAL if argument is invalid.
* @retval TLS_SPI_STATUS_ENOMEM if there is no enough memory.
* @retval TLS_SPI_STATUS_ESHUTDOWN if SPI driver does not installed.
*
* @note None
*/
int tls_spi_write(const u8 * buf, u32 len);
/**
* @brief This function is used to synchronously read data from SPI.
*
* @param[in] buf is the buffer for saving SPI data.
* @param[in] len is the data length.
*
* @retval TLS_SPI_STATUS_OK if write success.
* @retval TLS_SPI_STATUS_EINVAL if argument is invalid.
* @retval TLS_SPI_STATUS_ENOMEM if there is no enough memory.
* @retval TLS_SPI_STATUS_ESHUTDOWN if SPI driver does not installed.
*
* @note None
*/
int tls_spi_read(u8 * buf, u32 len);
/**
* @brief This function is used to synchronously write command and then read data from SPI.
*
* @param[in] txbuf is the write data buffer.
* @param[in] n_tx is the write data length.
* @param[in] rxbuf is the read data buffer.
* @param[in] n_rx is the read data length.
*
* @retval TLS_SPI_STATUS_OK if write success.
* @retval TLS_SPI_STATUS_EINVAL if argument is invalid.
* @retval TLS_SPI_STATUS_ENOMEM if there is no enough memory.
* @retval TLS_SPI_STATUS_ESHUTDOWN if SPI driver has not been installed.
*
* @note None
*/
int tls_spi_read_with_cmd(const u8 * txbuf, u32 n_tx, u8 * rxbuf, u32 n_rx);
/**
* @brief This function is used to synchronous write 32bit command then write data from SPI.
*
* @param[in] cmd is the command data.
* @param[in] n_cmd is the command len,can not bigger than four
* @param[in] txbuf is the write data buffer.
* @param[in] n_tx is the write data length.
*
* @retval TLS_SPI_STATUS_OK if write success.
* @retval TLS_SPI_STATUS_EINVAL if argument is invalid.
* @retval TLS_SPI_STATUS_ENOMEM if there is no enough memory.
* @retval TLS_SPI_STATUS_ESHUTDOWN if SPI driver does not installed.
*
* @note None
*/
int tls_spi_write_with_cmd(const u8 * cmd, u32 n_cmd, const u8 * txbuf, u32 n_tx);
/**
* @brief This function is used to set SPI transfer mode.
*
* @param[in] type is the transfer type.
* SPI_BYTE_TRANSFER ->byte transfer;
* SPI_WORD_TRANSFER ->word transfer;
* SPI_USE_DMA_TRANSFER ->DMA transfer;
*
* @return None
*
* @note None
*/
void tls_spi_trans_type(u8 type);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_HOST_SPI_H */
+253
View File
@@ -0,0 +1,253 @@
/**
* @file wm_hspi.h
*
*
* @brief High speed spi slave Module
*
* @author dave
*
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
*/
#ifndef WM_HSPI_H
#define WM_HSPI_H
#include "wm_type_def.h"
#include "wm_ram_config.h"
#define HSPI_TX_MEM_MALLOC 0 /** tx mem dynamic malloc*/
#define HSPI_INTERFACE_SPI 2 /** spi interface*/
#define HSPI_INTERFACE_SDIO 3 /** sdio interface*/
/**rx message*/
#define HSPI_RX_CMD_MSG 1
#define HSPI_RX_DATA_MSG 2
/**spi/sdio buffer*/
#define HSPI_TXBUF_NUM 2
#define HSPI_TX_DESC_NUM HSPI_TXBUF_NUM
#define HSPI_RXBUF_NUM 3
#define HSPI_RX_DESC_NUM HSPI_RXBUF_NUM
#define HSPI_TXBUF_SIZE 1500
#define HSPI_RXBUF_SIZE 1500
#define HSPI_TX_DESC_SIZE sizeof(struct tls_hspi_tx_desc)
#define HSPI_RX_DESC_SIZE sizeof(struct tls_hspi_rx_desc)
/*****************************************************************************
* sdio/hspi sram partition
******************************************************************************/
/* HSPI txbuf zone */
#define HSPI_TXBUF_BASE_ADDR ((u32)(SLAVE_HSPI_SDIO_ADDR))
#if HSPI_TX_MEM_MALLOC
#define HSPI_TXBUF_TOTAL_SIZE 0
#else
#define HSPI_TXBUF_TOTAL_SIZE (HSPI_TXBUF_SIZE * HSPI_TXBUF_NUM)
#endif
/** HSPI tx desc zone */
#define HSPI_TX_DESC_BASE_ADDR ((u32)(HSPI_TXBUF_BASE_ADDR + HSPI_TXBUF_TOTAL_SIZE))
#define HSPI_TX_DESC_TOTAL_SIZE (HSPI_TX_DESC_SIZE * HSPI_TX_DESC_NUM) //28*3=84
/** HSPI rxbuf zone */
#define HSPI_RXBUF_BASE_ADDR ((u32)(HSPI_TX_DESC_BASE_ADDR + HSPI_TX_DESC_TOTAL_SIZE))
#define HSPI_RXBUF_TOTAL_SIZE (HSPI_RXBUF_NUM * HSPI_RXBUF_SIZE) //4500
/** HSPI rx desc zone */
#define HSPI_RX_DESC_BASE_ADDR ((u32)(HSPI_RXBUF_BASE_ADDR + HSPI_RXBUF_TOTAL_SIZE))
#define HSPI_RX_DESC_TOTAL_SIZE (HSPI_RX_DESC_SIZE * HSPI_RX_DESC_NUM) //36
#define SDIO_CIS_SIZE (0x80)
#define SDIO_CMD_RXBUF_SIZE 256
#define SDIO_CIS0_ADDR (HSPI_RX_DESC_BASE_ADDR + HSPI_RX_DESC_TOTAL_SIZE) //128
#define SDIO_CIS1_ADDR (SDIO_CIS0_ADDR + SDIO_CIS_SIZE) //128
#define SDIO_CMD_RXBUF_ADDR (SDIO_CIS1_ADDR + SDIO_CIS_SIZE)
#define CIS_FUN0_ADDR ((u32)SDIO_CIS0_ADDR)
#define CIS_FUN1_ADDR ((u32)SDIO_CIS1_ADDR)
#define FN0_TPL_FUNCID (CIS_FUN0_ADDR + 0x00)
#define FN0_TPL_FUNCE (CIS_FUN0_ADDR + 0x04)
#define FN0_TPL_FUNCE_MAXBLK (CIS_FUN0_ADDR + 0x08)
#define FN0_TPL_MANFID_MID (CIS_FUN0_ADDR + 0x0C)
#define FN0_TPL_END (CIS_FUN0_ADDR + 0x10)
#define FN1_TPL_FUNCID (CIS_FUN1_ADDR + 0x00)
#define FN1_TPL_FUNCE (CIS_FUN1_ADDR + 0x04)
#define FN1_TPL_FUNCE_VER (CIS_FUN1_ADDR + 0x08)
#define FN1_TPL_FUNCE_NSN (CIS_FUN1_ADDR + 0x0C)
#define FN1_TPL_FUNCE_CSASIZE (CIS_FUN1_ADDR + 0x10)
#define FN1_TPL_FUNCE_OCR (CIS_FUN1_ADDR + 0x14)
#define FN1_TPL_FUNCE_MINPWR (CIS_FUN1_ADDR + 0x18)
#define FN1_TPL_FUNCE_STANDBY (CIS_FUN1_ADDR + 0x1C)
#define FN1_TPL_FUNCE_OPTBW (CIS_FUN1_ADDR + 0x20)
#define FN1_TPL_FUNCE_NTIMEOUT (CIS_FUN1_ADDR + 0x24)
#define FN1_TPL_FUNCE_AVGPWR (CIS_FUN1_ADDR + 0x28)
#define FN1_TPL_END (CIS_FUN1_ADDR + 0x30)
/** SDIO interrupt bit definition */
#define SDIO_WP_INT_SRC_CMD_DOWN (1UL<<3)
#define SDIO_WP_INT_SRC_CMD_UP (1UL<<2)
#define SDIO_WP_INT_SRC_DATA_DOWN (1UL<<1)
#define SDIO_WP_INT_SRC_DATA_UP (1UL<<0)
/** Definition of send data descriptor structure */
struct tls_hspi_tx_desc {
volatile u32 valid_ctrl;
u32 buf_info;
u32 buf_addr[3];
u32 next_desc_addr;
#if HSPI_TX_MEM_MALLOC
u32 txbuf_addr; /**< txbuf addr, pbuf and buf_addr[0] are different */
#endif
};
/** Definition of receive data descriptor structure */
struct tls_hspi_rx_desc {
u32 valid_ctrl;
u32 buf_addr;
u32 next_desc_addr;
};
/** struct tls_slave_hspi */
struct tls_slave_hspi {
u8 ifusermode;
s16 (*rx_cmd_callback)(char *buf);
s16 (*rx_data_callback)(char *buf);
s16 (*tx_data_callback)(char *buf);
struct tls_hspi_tx_desc *curr_tx_desc; /**< Upstream data management */
struct tls_hspi_rx_desc *curr_rx_desc; /**< Downlink data management */
#if HSPI_TX_MEM_MALLOC
u8 txdoneflag; /**< tx done falg*/
#endif
};
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup HSPI_Driver_APIs HSPI Driver APIs
* @brief HSPI driver APIs
*/
/**
* @addtogroup HSPI_Driver_APIs
* @{
*/
/**
* @brief This function is used to initial HSPI register.
*
* @param[in] None
*
* @retval 0 success
* @retval other failed
*
* @note When the system is initialized, the function has been called, so users can not call this function.
*/
int tls_slave_spi_init(void);
/**
* @brief This function is used to enable or disable user mode.
*
* @param[in] ifenable TRUE or FALSE
*
* @return None
*
* @note If the user enables the user mode, RICM instruction in the system will not be used by SPI.
* If the user wants to use the SPI interface as other use, need to enable the user mode.
* This function must be called before the register function.
*/
void tls_set_hspi_user_mode(u8 ifenable);
/**
* @brief This function is used to set high speed interface type.
*
* @param[in] type is the interface type. HSPI_INTERFACE_SPI or HSPI_INTERFACE_SDIO
*
* @return None
*
* @note None
*/
void tls_set_high_speed_interface_type(int type);
/**
* @brief This function is used to register hspi rx command interrupt.
*
* @param[in] rx_cmd_callback is the hspi rx interrupt call back function.
*
* @return None
*
* @note None
*/
void tls_hspi_rx_cmd_callback_register(s16 (*rx_cmd_callback)(char *buf));
/**
* @brief This function is used to register hspi rx data interrupt.
*
* @param[in] rx_data_callback is the hspi rx interrupt call back function.
*
* @return None
*
* @note None
*/
void tls_hspi_rx_data_callback_register(s16 (*rx_data_callback)(char *buf));
/**
* @brief This function is used to register hspi tx data interrupt.
*
* @param[in] tx_data_callback is the hspi tx interrupt call back function.
*
* @return None
*
* @note None
*/
void tls_hspi_tx_data_callback_register(s16 (*tx_data_callback)(char *buf));
/**
* @brief This function is used to transfer data.
*
* @param[in] txbuf is a buf for saving user data.
* @param[in] len is the data length.
*
* @retval transfer data len success
* @retval 0 failed
*
* @note None
*/
int tls_hspi_tx_data(char *txbuf, int len);
/**
* @}
*/
/**
* @}
*/
#endif /* WM_HSPI_H */
+140
View File
@@ -0,0 +1,140 @@
/**************************************************************************//**
* @file wm_i2c.h
* @author
* @version
* @date
* @brief
* @copyright (c) 2014 Winner Microelectronics Co., Ltd. All rights reserved.
*****************************************************************************/
#ifndef __WM_I2C_H
#define __WM_I2C_H
#ifdef __cplusplus
extern "C" {
#endif
#include "wm_regs.h"
#include "wm_type_def.h"
#include "wm_cpu.h"
#include "wm_irq.h"
typedef struct
{
__IO uint32_t PRER_LO;
__IO uint32_t PRER_HI;
__IO uint32_t CTRL;
__O uint32_t TX_RX;
__O uint32_t CR_SR;
__I uint32_t TXR;
__I uint32_t CR;
}I2C_T;
#define I2C ((I2C_T *)(HR_I2C_BASE_ADDR))
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup I2C_Driver_APIs I2C Driver APIs
* @brief I2C driver APIs
*/
/**
* @addtogroup I2C_Driver_APIs
* @{
*/
/**
* @brief Init the I2C module
* @param freq I2C reference clock frequency in Hz that will be used
* @note
* the value must be between 100k and 400k
*/
void tls_i2c_init(u32 freq);
/** I2C initialization mask */
#define wm_i2c_int_mask(bl) do { tls_bitband_write(HR_I2C_CTRL, 6, bl);}while(0);
/**
* @brief send stop signal
*
*/
void tls_i2c_stop(void);
/**
* @brief Waiting for ack signal
* @retval
* - \ref WM_FAILED
* - \ref WM_SUCCESS
*/
int tls_i2c_wait_ack(void);
/**
* @brief Writes the data to data register of I2C module
* when ifstart one the start signal will be sent followed by the data
* when ifstart zero only the data will be send
* @param[in] data the data will be write to the data register of I2C module
* @param[in] ifstart when one send start signal, when zero don't
* @retval
*
*/
void tls_i2c_write_byte(u8 data, u8 ifstart);
/**
* @brief Get the data stored in data register of I2C module
* @param[in] ifack when one send ack after reading the data register,when zero don't
* @param[in] ifstop when one send stop signal after read, when zero do not send stop
* @retval
* the received data
*/
u8 tls_i2c_read_byte(u8 ifack, u8 ifstop);
/**
* @brief This function is used to register i2c transfer done callback function.
* @param[in] done is the i2c transfer done callback function.
* @retval None
* @note None
*/
void wm_i2c_transfer_done_register(void (*done)(void));
/**
* @brief Start writing through int mode
* @param[in] devaddr the device address
* @param[in] wordaddr when one send stop signal after read, when zero do not send stop
* @param[in] buf the address point where data shoule be stored
* @param[in] len the length of data will be received
* @retval
* - \ref WM_FAILED
* - \ref WM_SUCCESS
*/
int wm_i2c_start_write_it(uint8_t devaddr, uint8_t wordaddr, uint8_t * buf, uint16_t len);
/**
* @brief Get the data stored in data register of I2C module
* @param[in] ifack when one send ack after reading the data register,when zero don't
* @param[in] ifstop when one send stop signal after read, when zero do not send stop
* @retval the received data
*/
int wm_i2c_start_read_it(uint8_t devaddr, uint8_t wordaddr, uint8_t * buf, uint16_t len);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif
/*** (C) COPYRIGHT 2014 Winner Microelectronics Co., Ltd. ***/
+300
View File
@@ -0,0 +1,300 @@
#ifndef __WM_I2S_H
#define __WM_I2S_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
//#include "wm_regs_cm3.h"
#include "wm_regs.h"
#include "wm_debug.h"
#include "wm_dma.h"
typedef void (*tls_i2s_callback)(uint32_t *data, uint16_t *len);
typedef struct {
__IO uint32_t CTRL;
__IO uint32_t INT_MASK;
__IO uint32_t INT_SRC;
__I uint32_t INT_STATUS;
__O uint32_t TX;
__I uint32_t RX;
} I2S_T;
typedef struct {
uint32_t I2S_Mode_MS; //master or slave mode
uint32_t I2S_Mode_SS; //stereo or single channel
uint32_t I2S_Mode_LR; //left or right channel
uint32_t I2S_Trans_STD;
uint32_t I2S_DataFormat;
uint32_t I2S_AudioFreq;
uint32_t I2S_MclkFreq;
} I2S_InitDef;
typedef struct _wm_dma_desc
{
unsigned int valid;
unsigned int dma_ctrl;
unsigned int src_addr;
unsigned int dest_addr;
struct _wm_dma_desc * next;
}wm_dma_desc;
typedef struct _dma_handler_type
{
uint8_t channel;
void (* XferCpltCallback)( struct _dma_handler_type * hdma); /*!< DMA transfer complete callback */
void (* XferHalfCpltCallback)( struct _dma_handler_type * hdma); /*!< DMA Half transfer complete callback */
}wm_dma_handler_type;
#define I2S ((I2S_T *)HR_I2S_REG_BASE)
#define I2S_MODE_MASTER ((bool)0x0)
#define I2S_MODE_SLAVE ((bool)0x1)
#define I2S_RIGHT_CHANNEL ((bool)0x0)
#define I2S_LEFT_CHANNEL ((bool)0x1)
#define I2S_Standard (0x0UL)
#define I2S_Standard_MSB (0x1000000UL)
#define I2S_Standard_PCMA (0x2000000UL)
#define I2S_Standard_PCMB (0x3000000UL)
#define I2S_DataFormat_8 (8)
#define I2S_DataFormat_16 (16)
#define I2S_DataFormat_24 (24)
#define I2S_DataFormat_32 (32)
#define I2S_CTRL_CHSEL_MASK (1UL<<23)
#define I2S_CTRL_CHSEL_LEFT (1UL<<23)
#define I2S_CTRL_MONO (1UL<<22)
#define I2S_CTRL_STEREO (0UL<<22)
#define I2S_CTRL_RXDMA_EN (1UL<<21)
#define I2S_CTRL_TXDMA_EN (1UL<<20)
#define I2S_CTRL_RX_CLR (1UL<<19)
#define I2S_CTRL_TX_CLR (1UL<<18)
#define I2S_CTRL_LZCEN (1UL<<17)
#define I2S_CTRL_RZCEN (1UL<<16)
#define I2S_CTRL_RXTH(n) ((n-1)<<12)
#define I2S_CTRL_TXTH(n) ((n)<<9)
#define I2S_CTRL_SLAVE_SEL (1UL<<8)
#define I2S_CTRL_MUTE (1UL<<3)
#define I2S_CTRL_RXE (1UL<<2)
#define I2S_CTRL_TXE (1UL<<1)
#define I2S_CTRL_EN (1UL<<0)
#define I2S_INT_MASK_LZC ((uint16_t)0x200)
#define I2S_INT_MASK_RZC ((uint16_t)0x100)
#define I2S_INT_MASK_TXDONE ((uint16_t)0x080)
#define I2S_INT_MASK_TXTH ((uint16_t)0x040)
#define I2S_INT_MASK_TXOV ((uint16_t)0x020)
#define I2S_INT_MASK_TXUD ((uint16_t)0x010)
#define I2S_INT_MASK_RXDONE ((uint16_t)0x008)
#define I2S_INT_MASK_RXTH ((uint16_t)0x004)
#define I2S_INT_MASK_RXOV ((uint16_t)0x002)
#define I2S_INT_MASK_RXUD ((uint16_t)0x002)
#define I2S_FLAG_TX ((uint16_t)0x1000)
#define I2S_FLAG_RX ((uint16_t)0x0800)
#define I2S_FLAG_I2S ((uint16_t)0x0400)
#define I2S_FLAG_LZC ((uint16_t)0x0200)
#define I2S_FLAG_RZC ((uint16_t)0x0100)
#define I2S_FLAG_TXDONE ((uint16_t)0x0080)
#define I2S_FLAG_TXTH ((uint16_t)0x0040)
#define I2S_FLAG_TXOV ((uint16_t)0x0020)
#define I2S_FLAG_TXUD ((uint16_t)0x0010)
#define I2S_FLAG_RXDONE ((uint16_t)0x0008)
#define I2S_FLAG_RXTH ((uint16_t)0x0004)
#define I2S_FLAG_RXOV ((uint16_t)0x0002)
#define I2S_FLAG_RXUD ((uint16_t)0x0001)
#define WM_I2S_TX_DMA_CHANNEL (1)
#define WM_I2S_RX_DMA_CHANNEL (5)
typedef struct wm_i2s_buf_s {
volatile uint32_t *txbuf;
volatile uint32_t txlen;
volatile uint32_t txtail;
volatile uint32_t *rxbuf;
volatile uint32_t rxlen;
volatile uint32_t int_txlen;
volatile uint32_t rxhead;
volatile uint8_t rxdata_ready;
volatile uint8_t txdata_done;
/** function pointer for data receiver */
void (*rx_callback)(void);
/** function pointer for data transmit */
void (*tx_callback)(uint32_t *data, uint16_t *len);
} wm_i2s_buf_t;
/**
* @defgroup Driver_APIs Driver APIs
* @brief Driver APIs
*/
/**
* @addtogroup Driver_APIs
* @{
*/
/**
* @defgroup I2S_Driver_APIs I2S Driver APIs
* @brief I2S driver APIs
*/
/**
* @addtogroup I2S_Driver_APIs
* @{
*/
/**
* @brief Register a callback function
* @param callback pointer to a callback function in which you can prepare the next buffer
* @param callback->data pointer to data buffer to be prepared
* @param callback->len size of the data buffer to be prepared in 32-bit
* @note The registerred callback function will be called as long as the transmission begins
* @retval none
*/
void wm_i2s_register_callback(tls_i2s_callback callback);
/**
* @brief Initializes the I2S according to the specified parameters
* in the I2S_InitDef.
* @param opts pointer to a I2S_InitDef structure that contains
* the configuration information for I2S module
* @retval status
*/
int wm_i2s_port_init(I2S_InitDef *opts);
/**
* @brief stop i2s module
* @retval none
*/
void wm_i2s_tx_rx_stop(void);
/**
* @brief Transmit an amount of data in blocking mode with Interrupt
* @param data a 16-bit pointer to data buffer.
* @param len number of data sample to be sent:
* @param next_data a 16-bit pointer to the next data buffer, same size with data; set to NULL if it's not needed
* @note the len parameter means the number of 16-bit data length.
* @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
* between Master and Slave(example: audio streaming).
* @note This function will block its task until the transmission is over,so perpare the next data
* buffer at another task during this interval.
* @note This function will call the registerred callback function as long as the transmission begins
* @retval status
*/
int wm_i2s_tx_int(int16_t *data, uint16_t len, int16_t *next_data);
/**
* @brief Transmit an amount of data in blocking mode with DMA's normal mode
* @param data a 16-bit pointer to data buffer.
* @param len number of data sample to be sent:
* @param next_data a 16-bit pointer to the next data buffer, same size with data; set to NULL if it's not needed
* @note the len parameter means the number of 32-bit data length.
* @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
* between Master and Slave(example: audio streaming).
* @note This function will block its task until the transmission is over,so perpare the next data
* buffer at another task during this interval.
* @note This function will call the registerred callback function as long as the transmission begins
* @retval status
*/
int wm_i2s_tx_dma(int16_t *data, uint16_t len, int16_t *next_data);
/**
* @brief Transmit an amount of data in blocking mode with DMA's link mode
* @param data a 16-bit pointer to data buffer.
* @param len number of data sample to be sent:
* @param next_data a 16-bit pointer to the next data buffer, same size with data:
* @note the len parameter means the number of 32-bit data length.
* @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
* between Master and Slave(example: audio streaming).
* @note This function will block its task until the transmission is over,so perpare the next data
* buffer at another task during this interval.Set len to 0xffff will exit this rountine.
* @note This function will call the registerred callback function as long as the data or next_data
* is sent out.So prepare it in the callback.
* @note See the demo for detail use.
* @retval status
*/
int wm_i2s_tx_dma_link(int16_t *data, uint16_t len, int16_t *next_data);
/**
* @brief Receive an amount of data in blocking mode with Interrupt
* @param data a 16-bit pointer to the Receive data buffer.
* @param len number of data sample to be received:
* @note the len parameter means the number of 16-bit data length.
* @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
* between Master and Slave(example: audio streaming).
* @note This function will block its task until the transmission is over,so perpare the next data
* buffer at another task during this interval.
* @retval status
*/
int wm_i2s_rx_int(int16_t *data, uint16_t len);
/**
* @brief Receive an amount of data in blocking mode with DMA
* @param data a 16-bit pointer to the Receive data buffer.
* @param len number of data sample to be received:
* @note the len parameter means the number of 16-bit data length.
* @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
* between Master and Slave(example: audio streaming).
* @note This function will block its task until the transmission is over,so perpare the next data
* buffer at another task during this interval.
* @retval status
*/
int wm_i2s_rx_dma(int16_t *data, uint16_t len);
/**
* @brief Full-Duplex Transmit/Receive data in blocking mode using Interrupt
* @param opts pointer to a I2S_InitDef structure that contains
* the configuration information for I2S module
* @param data_tx a 16-bit pointer to the Transmit data buffer.
* @param data_rx a 16-bit pointer to the Receive data buffer.
* @param len number of data sample to be sent:
* @note the len parameter means the number of 16-bit data length.
* @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
* between Master and Slave(example: audio streaming).
* @note This function will block its task until the transmission is over,so perpare the next data
* buffer at another task during this interval.
* @retval status
*/
int wm_i2s_tx_rx_int(I2S_InitDef *opts, int16_t *data_tx, int16_t *data_rx, uint16_t len);
/**
* @brief Full-Duplex Transmit/Receive data in blocking mode using DMA
* @param opts pointer to a I2S_InitDef structure that contains
* the configuration information for I2S module
* @param data_tx a 16-bit pointer to the Transmit data buffer.
* @param data_rx a 16-bit pointer to the Receive data buffer.
* @param len number of data sample to be sent:
* @note the len parameter means the number of 16-bit data length.
* @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
* between Master and Slave(example: audio streaming).
* @note This function will block its task until the transmission is over,so perpare the next data
* buffer at another task during this interval.
* @retval status
*/
int wm_i2s_tx_rx_dma(I2S_InitDef *opts, int16_t *data_tx, int16_t *data_rx, uint16_t len);
int wm_i2s_transmit_dma(wm_dma_handler_type *hdma, uint16_t *data, uint16_t len);
int wm_i2s_receive_dma(wm_dma_handler_type *hdma, uint16_t *data, uint16_t len);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif

Some files were not shown because too many files have changed in this diff Show More