添加niobeu4开发板

Signed-off-by: fangye <fangye@talkweb.com.cn>
This commit is contained in:
fangye
2022-06-09 10:21:46 +08:00
parent 233867f759
commit f7a433abad
71 changed files with 7170 additions and 37 deletions
+19
View File
@@ -0,0 +1,19 @@
# Copyright (c) 2022 OpenValley Digital Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//kernel/liteos_m/liteos.gni")
module_name = get_path_info(rebase_path("."), "name")
module_group(module_name) {
modules = [ "niobeu4" ]
}
+16
View File
@@ -0,0 +1,16 @@
# Copyright (c) 2022 OpenValley Digital 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.
if SOC_ESP32
orsource "niobeu4/Kconfig.liteos_m.board"
endif
+14
View File
@@ -0,0 +1,14 @@
# Copyright (c) 2022 OpenValley Digital 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.
orsource "*/Kconfig.liteos_m.defconfig.board"
+14
View File
@@ -0,0 +1,14 @@
# Copyright (c) 2022 OpenValley Digital 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.
orsource "shields/Kconfig.liteos_m.shields"
+201
View File
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+59
View File
@@ -0,0 +1,59 @@
<?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="copyright" name="OpenValley Digital Co., Ltd." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="Developed By OpenValley Digital Co., Ltd."/>
</policy>
</policylist>
<filefilterlist>
</filefilterlist>
</oatconfig>
</configuration>
-36
View File
@@ -1,36 +0,0 @@
# device_board_openvalley
#### Description
该仓库托管湖南开鸿智谷数字产业发展有限公司Niobe系列开发板的板级配置、驱动代码及文档
#### 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/)
+3 -1
View File
@@ -1,7 +1,9 @@
# device_board_openvalley
#### 介绍
该仓库托管湖南开鸿智谷数字产业发展有限公司Niobe系列开发板的板级配置、驱动代码及文档
{**以下是 Gitee 平台说明,您可以替换此简介**
Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
#### 软件架构
软件架构说明
+40
View File
@@ -0,0 +1,40 @@
# Copyright (c) 2022 OpenValley Digital Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//kernel/liteos_m/liteos.gni")
if (ohos_kernel_type == "liteos_m") {
module_name = get_path_info(rebase_path("."), "name")
module_group(module_name) {
modules = [ "liteos_m" ]
}
group("process_after_build") {
deps = [
":elf2bin",
]
}
ESP_SDK_PATH="//device/soc/espressif/esp32/components/"
import("${ESP_SDK_PATH}sdkconfig.gni")
build_ext_component("elf2bin") {
exec_path = rebase_path(ESP_SDK_PATH)
_output_file = rebase_path("$root_out_dir/OHOS_Image.bin")
_input_file = rebase_path("$root_out_dir/OHOS_Image")
command = "python esptool_py/esptool/esptool.py --chip ${CONFIG_IDF_TARGET} elf2image --flash_mode ${CONFIG_ESPTOOLPY_FLASHMODE} --flash_freq ${CONFIG_ESPTOOLPY_FLASHFREQ} --flash_size ${CONFIG_ESPTOOLPY_FLASHSIZE} --min-rev 0 --elf-sha256-offset 0xb0 -o ${_output_file} ${_input_file}"
deps = [
"//build/lite:ohos",
"//kernel/liteos_m:build_kernel_image",
]
}
}
+229
View File
@@ -0,0 +1,229 @@
# Copyright (c) 2022 OpenValley Digital 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.
menuconfig BOARD_NIOBEU4
bool "select board niobeu4"
depends on SOC_ESP32
if BOARD_NIOBEU4
config USE_TALKWEB_COMPONENTS
bool "use talkweb components"
default n
help
This is a switch for use talkweb component.
config DRIVERS_HDF_PLATFORM_WIFI
bool "use wifi components"
default n
help
This is a switch for use wifi component.
config USE_TALKWEB_MAILBOX
bool "use mailbox components"
default n
help
This is a switch for use mailbox component.
config TALKWEB_TWNFC_COMPONENT
bool "use the nfc component"
default n
help
This is a switch for nfc component.
config USE_TALKWEB_TASK_WDT
bool "use task watchdog components"
default n
help
This is a switch for use task watchdog component.
config USE_TALKWEB_TASK_WDT_TIMEOUT
int "task watchdog timeout(seconds)"
range 1 6000
default 5
depends on USE_TALKWEB_TASK_WDT
if USE_TALKWEB_COMPONENTS
config TALKWEB_DEVICEAUTH_COMPONENT
bool "use the deviceauth component"
default n
help
This is a switch for deviceauth component.
config TALKWEB_SNTP_MANAGER_COMPONENT
bool "use the sntpmanager component"
default n
help
This is a switch for sntpmanager component.
config TALKWEB_TLINKSDK_COMPONENT
bool "use the tlinksdk component" if TALKWEB_DEVICEAUTH_COMPONENT
default y
help
This is a switch for tlinksdk component.
config TALKWEB_TWOTA_COMPONENT
bool "use the twota components"
default n
help
This is a switch for twota component.
endif #USE_TALKWEB_COMPONENTS
config USE_TALKWEB_APPLICATION
bool "use talkweb niobeu4 application"
default n
help
This is a switch for use talkweb niobe407 application.
If you want to write your application code, please close it.
choice
prompt "niobeu4 application choose"
depends on USE_TALKWEB_APPLICATION
default NIOBEU4_APPLICATION_001
help
This is a choose for application name
config NIOBEU4_APPLICATION_001
bool "001_system_helloworld"
config NIOBEU4_APPLICATION_002
bool "002_system_thread"
config NIOBEU4_APPLICATION_003
bool "003_system_timer"
config NIOBEU4_APPLICATION_004
bool "004_system_event"
config NIOBEU4_APPLICATION_005
bool "005_system_mutex"
config NIOBEU4_APPLICATION_006
bool "006_system_semp"
config NIOBEU4_APPLICATION_007
bool "007_system_message"
config NIOBEU4_APPLICATION_011
bool "011_system_los_thread"
config NIOBEU4_APPLICATION_012
bool "012_system_los_timer"
config NIOBEU4_APPLICATION_013
bool "013_system_los_event"
config NIOBEU4_APPLICATION_014
bool "014_system_los_mutex"
config NIOBEU4_APPLICATION_015
bool "015_system_los_semp"
config NIOBEU4_APPLICATION_016
bool "016_system_los_message"
config NIOBEU4_APPLICATION_017
bool "017_system_ringbuf"
config NIOBEU4_APPLICATION_018
bool "018_system_mailbox"
select USE_TALKWEB_MAILBOX
config NIOBEU4_APPLICATION_019
bool "019_system_taskwdt"
select USE_TALKWEB_TASK_WDT
config NIOBEU4_APPLICATION_200
bool "200_hdf_watchdog"
select DRIVERS
select DRIVERS_HDF
select DRIVERS_HDF_PLATFORM
select DRIVERS_HDF_PLATFORM_WATCHDOG
config NIOBEU4_APPLICATION_301
bool "301_network_tcpclient"
config NIOBEU4_APPLICATION_302
bool "302_network_tcpserver"
config NIOBEU4_APPLICATION_303
bool "303_network_udptest"
config NIOBEU4_APPLICATION_304
bool "304_network_twlink_example"
config NIOBEU4_APPLICATION_305
bool "305_network_sntpclient_example"
config NIOBEU4_APPLICATION_306
bool "306_network_httpclient_example"
config NIOBEU4_APPLICATION_307
bool "307_network_ota_example"
config NIOBEU4_APPLICATION_308
bool "308_network_hwiotlink_example"
config NIOBEU4_APPLICATION_401
bool "401_file_nvs"
config NIOBEU4_APPLICATION_402
bool "402_file_littlefs"
select FS_VFS
select FS_LITTLEFS
config NIOBEU4_APPLICATION_403
bool "403_spi_lcd"
config NIOBEU4_APPLICATION_405
bool "405_LogLevel"
config NIOBEU4_APPLICATION_406
bool "406_UART"
config NIOBEU4_APPLICATION_407
bool "407_NFC"
config NIOBEU4_APPLICATION_501
select FS_VFS
bool "501_WIFI_STA"
config NIOBEU4_APPLICATION_601
bool "601_I2C"
config NIOBEU4_APPLICATION_701
bool "701_GPIO"
config NIOBEU4_APPLICATION_702
bool "702_GPIO_INTERRUPT"
config NIOBEU4_APPLICATION_801
bool "801_ADC"
endchoice
config NIOBEU4_APPLICATION_NAME
string
depends on USE_TALKWEB_APPLICATION
default "001_system_helloworld" if NIOBEU4_APPLICATION_001
default "002_system_thread" if NIOBEU4_APPLICATION_002
default "003_system_timer" if NIOBEU4_APPLICATION_003
default "004_system_event" if NIOBEU4_APPLICATION_004
default "005_system_mutex" if NIOBEU4_APPLICATION_005
default "006_system_semp" if NIOBEU4_APPLICATION_006
default "007_system_message" if NIOBEU4_APPLICATION_007
default "011_system_los_thread" if NIOBEU4_APPLICATION_011
default "012_system_los_timer" if NIOBEU4_APPLICATION_012
default "013_system_los_event" if NIOBEU4_APPLICATION_013
default "014_system_los_mutex" if NIOBEU4_APPLICATION_014
default "015_system_los_semp" if NIOBEU4_APPLICATION_015
default "016_system_los_message" if NIOBEU4_APPLICATION_016
default "017_system_ringbuf" if NIOBEU4_APPLICATION_017
default "018_system_mailbox" if NIOBEU4_APPLICATION_018
default "019_system_taskwdt" if NIOBEU4_APPLICATION_019
default "200_hdf_watchdog" if NIOBEU4_APPLICATION_200
default "301_network_tcpclient" if NIOBEU4_APPLICATION_301
default "302_network_tcpserver" if NIOBEU4_APPLICATION_302
default "303_network_udptest" if NIOBEU4_APPLICATION_303
default "304_network_twlink_example" if NIOBEU4_APPLICATION_304
default "305_network_sntpclient_example" if NIOBEU4_APPLICATION_305
default "306_network_httpclient_example" if NIOBEU4_APPLICATION_306
default "307_network_ota_example" if NIOBEU4_APPLICATION_307
default "308_network_hwiotlink_example" if NIOBEU4_APPLICATION_308
default "401_file_nvs" if NIOBEU4_APPLICATION_401
default "402_file_littlefs" if NIOBEU4_APPLICATION_402
default "403_spi_lcd" if NIOBEU4_APPLICATION_403
default "405_LogLevel" if NIOBEU4_APPLICATION_405
default "406_UART" if NIOBEU4_APPLICATION_406
default "407_NFC" if NIOBEU4_APPLICATION_407
default "501_WIFI_STA" if NIOBEU4_APPLICATION_501
default "601_I2C" if NIOBEU4_APPLICATION_601
default "701_GPIO" if NIOBEU4_APPLICATION_701
default "702_GPIO_INTERRUPT" if NIOBEU4_APPLICATION_702
default "801_ADC" if NIOBEU4_APPLICATION_801
endif #BOARD_NIOBEU4
+17
View File
@@ -0,0 +1,17 @@
# Copyright (c) 2022 OpenValley Digital 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.
if BOARD_NIOBEU4
endif #BOARD_NIOBEU4
+26
View File
@@ -0,0 +1,26 @@
# Copyright (c) 2022 OpenValley Digital 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.
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 = [
"target",
"littlefs",
"drivers",
"hals",
"arch",
]
}
}
+26
View File
@@ -0,0 +1,26 @@
# Copyright (c) 2022 OpenValley Digital Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//kernel/liteos_m/liteos.gni")
module_name = "arch"
kernel_module(module_name) {
sources = [
"los_context.c",
"los_interrupt.c",
]
}
config("public") {
include_dirs = [ "." ]
}
+32
View File
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LOS_ARCH_ATOMIC_H
#define _LOS_ARCH_ATOMIC_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_ARCH_CONTEXT_H */
+77
View File
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_ARCH_CONTEXT_H
#define _LOS_ARCH_CONTEXT_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define SAVED_REG_NUM 8
#define SPILL_WINDOW_SIZE 8
typedef struct {
UINT32 pc;
UINT32 ps;
UINT32 regA[16];
UINT32 sar;
UINT32 excCause;
UINT32 excVaddr;
UINT32 lbeg;
UINT32 lend;
UINT32 lcount;
#if (defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U))
UINT32 temp;
UINT16 cpenable;
UINT16 cpstored;
UINT32 fcr;
UINT32 fsr;
UINT32 regF[16];
#endif
UINT32 res[4];
} TaskContext;
VOID ArchTaskContextSwitch(VOID);
VOID HalIrqEndCheckNeedSched(VOID);
VOID EnableExceptionInterface(VOID);
UINT32 HalIrqMask(HWI_HANDLE_T hwiNum);
UINT32 HalIrqUnmask(HWI_HANDLE_T hwiNum);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_ARCH_CONTEXT_H */
+245
View File
@@ -0,0 +1,245 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_ARCH_INTERRUPT_H
#define _LOS_ARCH_INTERRUPT_H
#include "los_config.h"
#include "los_compiler.h"
#include "los_interrupt.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
typedef struct {
UINT32 pc;
UINT32 ps;
UINT32 regA[16];
UINT32 sar;
UINT32 excCause;
UINT32 excVaddr;
UINT32 lbeg;
UINT32 lend;
UINT32 lcount;
#if (defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U))
UINT32 temp;
UINT16 cpenable;
UINT16 cpstored;
UINT32 fcr;
UINT32 fsr;
UINT32 regF[16];
#endif
UINT32 res[4];
} EXC_CONTEXT_S;
/* *
* @ingroup los_arch_interrupt
* Maximum number of used hardware interrupts.
*/
#ifndef OS_HWI_MAX_NUM
#define OS_HWI_MAX_NUM LOSCFG_PLATFORM_HWI_LIMIT
#endif
/* *
* @ingroup los_arch_interrupt
* Highest priority of a hardware interrupt.
*/
#ifndef OS_HWI_PRIO_HIGHEST
#define OS_HWI_PRIO_HIGHEST 0
#endif
/* *
* @ingroup los_arch_interrupt
* Lowest priority of a hardware interrupt.
*/
#ifndef OS_HWI_PRIO_LOWEST
#define OS_HWI_PRIO_LOWEST 7
#endif
#define OS_EXC_IN_INIT 0
#define OS_EXC_IN_TASK 1
#define OS_EXC_IN_HWI 2
/* *
* @ingroup los_arch_interrupt
* Define the type of a hardware interrupt vector table function.
*/
typedef VOID (**HWI_VECTOR_FUNC)(VOID);
/* *
* @ingroup los_arch_interrupt
* Count of interrupts.
*/
extern UINT32 g_intCount;
/* *
* @ingroup los_arch_interrupt
* Count of Xtensa system interrupt vector.
*/
#define OS_SYS_VECTOR_CNT 0
/* *
* @ingroup los_arch_interrupt
* Count of Xtensa interrupt vector.
*/
#define OS_VECTOR_CNT (OS_SYS_VECTOR_CNT + OS_HWI_MAX_NUM)
/* *
* @ingroup los_arch_interrupt
* Hardware interrupt error code: Invalid interrupt number.
*
* Value: 0x02000900
*
* Solution: Ensure that the interrupt number is valid.
*/
#define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00)
/* *
* @ingroup los_arch_interrupt
* Hardware interrupt error code: Null hardware interrupt handling function.
*
* Value: 0x02000901
*
* Solution: Pass in a valid non-null hardware interrupt handling function.
*/
#define OS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x01)
/* *
* @ingroup los_arch_interrupt
* Hardware interrupt error code: Insufficient interrupt resources for hardware interrupt creation.
*
* Value: 0x02000902
*
* Solution: Increase the configured maximum number of supported hardware interrupts.
*/
#define OS_ERRNO_HWI_CB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x02)
/* *
* @ingroup los_arch_interrupt
* Hardware interrupt error code: Insufficient memory for hardware interrupt initialization.
*
* Value: 0x02000903
*
* Solution: Expand the configured memory.
*/
#define OS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x03)
/* *
* @ingroup los_arch_interrupt
* Hardware interrupt error code: The interrupt has already been created.
*
* Value: 0x02000904
*
* Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
*/
#define OS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x04)
/* *
* @ingroup los_arch_interrupt
* Hardware interrupt error code: Invalid interrupt priority.
*
* Value: 0x02000905
*
* Solution: Ensure that the interrupt priority is valid.
*/
#define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05)
/* *
* @ingroup los_arch_interrupt
* Hardware interrupt error code: Incorrect interrupt creation mode.
*
* Value: 0x02000906
*
* Solution: The interrupt creation mode can be only set to OS_HWI_MODE_COMM or OS_HWI_MODE_FAST.
*/
#define OS_ERRNO_HWI_MODE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x06)
/* *
* @ingroup los_arch_interrupt
* Hardware interrupt error code: The interrupt has already been created as a fast interrupt.
*
* Value: 0x02000907
*
* Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
*/
#define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07)
#if (OS_HWI_WITH_ARG == 1)
/* *
* @ingroup los_arch_interrupt
* Set interrupt vector table.
*/
extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg);
#else
/* *
* @ingroup los_arch_interrupt
* Set interrupt vector table.
*/
extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector);
#endif
VOID HalInterrupt(VOID);
UINT32 HalIntNumGet(VOID);
VOID HalHwiDefaultHandler(VOID);
VOID HalExcHandleEntry(UINTPTR faultAddr, EXC_CONTEXT_S *excBufAddr, UINT32 type);
VOID HalHwiInit(VOID);
/**
* @ingroup los_exc
* Exception information structure
*
* Description: Exception information saved when an exception is triggered on the Xtensa platform.
*
*/
typedef struct TagExcInfo {
UINT16 phase;
UINT16 type;
UINT32 faultAddr;
UINT32 thrdPid;
UINT16 nestCnt;
UINT16 reserved;
EXC_CONTEXT_S *context;
} ExcInfo;
extern UINT32 g_curNestCount;
#define MAX_INT_INFO_SIZE (8 + 0x164)
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_ARCH_INTERRUPT_H */
+171
View File
@@ -0,0 +1,171 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_ARCH_MACRO_H
#define _LOS_ARCH_MACRO_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
.macro POP_ALL_REG SP PC PState
#if (defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U))
l16ui a3, \SP, CONTEXT_OFF_CPENABLE
wsr a3, CPENABLE
rsync
l16ui a3, \SP, CONTEXT_OFF_CPSTORED
bbci.l a3, 0, 2f
l32i a3, \SP, CONTEXT_OFF_FCR
wur.FCR a3
l32i a3, \SP, CONTEXT_OFF_FSR
wur.FSR a3
lsi f0, \SP, CONTEXT_OFF_F0
lsi f1, \SP, CONTEXT_OFF_F1
lsi f2, \SP, CONTEXT_OFF_F2
lsi f3, \SP, CONTEXT_OFF_F3
lsi f4, \SP, CONTEXT_OFF_F4
lsi f5, \SP, CONTEXT_OFF_F5
lsi f6, \SP, CONTEXT_OFF_F6
lsi f7, \SP, CONTEXT_OFF_F7
lsi f8, \SP, CONTEXT_OFF_F8
lsi f9, \SP, CONTEXT_OFF_F9
lsi f10, \SP, CONTEXT_OFF_F10
lsi f11, \SP, CONTEXT_OFF_F11
lsi f12, \SP, CONTEXT_OFF_F12
lsi f13, \SP, CONTEXT_OFF_F13
lsi f14, \SP, CONTEXT_OFF_F14
lsi f15, \SP, CONTEXT_OFF_F15
2:
movi a4, 0
s16i a4, \SP, CONTEXT_OFF_CPSTORED
#endif
l32i a3, \SP, CONTEXT_OFF_LBEG
l32i a4, \SP, CONTEXT_OFF_LEND
wsr a3, LBEG
l32i a3, \SP, CONTEXT_OFF_LCOUNT
wsr a4, LEND
wsr a3, LCOUNT
l32i a3, \SP, CONTEXT_OFF_SAR
l32i a1, \SP, CONTEXT_OFF_A1
wsr a3, SAR
l32i a3, \SP, CONTEXT_OFF_A3
l32i a4, \SP, CONTEXT_OFF_A4
l32i a5, \SP, CONTEXT_OFF_A5
l32i a6, \SP, CONTEXT_OFF_A6
l32i a7, \SP, CONTEXT_OFF_A7
l32i a8, \SP, CONTEXT_OFF_A8
l32i a9, \SP, CONTEXT_OFF_A9
l32i a10, \SP, CONTEXT_OFF_A10
l32i a11, \SP, CONTEXT_OFF_A11
l32i a12, \SP, CONTEXT_OFF_A12
l32i a13, \SP, CONTEXT_OFF_A13
l32i a14, \SP, CONTEXT_OFF_A14
l32i a15, \SP, CONTEXT_OFF_A15
l32i a0, \SP, CONTEXT_OFF_PS
wsr a0, \PState
l32i a0, \SP, CONTEXT_OFF_PC
wsr a0, \PC
l32i a0, \SP, CONTEXT_OFF_A0
l32i a2, \SP, CONTEXT_OFF_A2
.endm
.macro PUSH_ALL_REG SP
s32i a0, \SP, CONTEXT_OFF_A0
s32i a1, \SP, CONTEXT_OFF_A1
s32i a2, \SP, CONTEXT_OFF_A2
s32i a3, \SP, CONTEXT_OFF_A3
s32i a4, \SP, CONTEXT_OFF_A4
s32i a5, \SP, CONTEXT_OFF_A5
s32i a6, \SP, CONTEXT_OFF_A6
s32i a7, \SP, CONTEXT_OFF_A7
s32i a8, \SP, CONTEXT_OFF_A8
s32i a9, \SP, CONTEXT_OFF_A9
s32i a10, \SP, CONTEXT_OFF_A10
s32i a11, \SP, CONTEXT_OFF_A11
s32i a12, \SP, CONTEXT_OFF_A12
s32i a13, \SP, CONTEXT_OFF_A13
s32i a14, \SP, CONTEXT_OFF_A14
s32i a15, \SP, CONTEXT_OFF_A15
rsr a3, SAR
s32i a3, \SP, CONTEXT_OFF_SAR
rsr a3, LBEG
s32i a3, \SP, CONTEXT_OFF_LBEG
rsr a3, LEND
s32i a3, \SP, CONTEXT_OFF_LEND
rsr a3, LCOUNT
s32i a3, \SP, CONTEXT_OFF_LCOUNT
rsr a3, PS
s32i a3, \SP, CONTEXT_OFF_PS
#if (defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U))
rsr a3, CPENABLE
beqz a3, 1f
s16i a3, \SP, CONTEXT_OFF_CPSTORED
s16i a3, \SP, CONTEXT_OFF_CPENABLE
bbci.l a3, 0, 1f
rur.FCR a3
s32i a3, \SP, CONTEXT_OFF_FCR
rur.FSR a3
s32i a3, \SP, CONTEXT_OFF_FSR
ssi f0, \SP, CONTEXT_OFF_F0
ssi f1, \SP, CONTEXT_OFF_F1
ssi f2, \SP, CONTEXT_OFF_F2
ssi f3, \SP, CONTEXT_OFF_F3
ssi f4, \SP, CONTEXT_OFF_F4
ssi f5, \SP, CONTEXT_OFF_F5
ssi f6, \SP, CONTEXT_OFF_F6
ssi f7, \SP, CONTEXT_OFF_F7
ssi f8, \SP, CONTEXT_OFF_F8
ssi f9, \SP, CONTEXT_OFF_F9
ssi f10, \SP, CONTEXT_OFF_F10
ssi f11, \SP, CONTEXT_OFF_F11
ssi f12, \SP, CONTEXT_OFF_F12
ssi f13, \SP, CONTEXT_OFF_F13
ssi f14, \SP, CONTEXT_OFF_F14
ssi f15, \SP, CONTEXT_OFF_F15
1:
#endif
.endm
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_ARCH_MACRO_H */
+172
View File
@@ -0,0 +1,172 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @defgroup Special Register Fields and Values
* @ingroup kernel
*/
#ifndef __LOS_ARCH_REGS_H__
#define __LOS_ARCH_REGS_H__
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/* PS register -- imprecise exception */
#define SPREG_PS_DEPC_SHIFT 4
#define SPREG_PS_DEPC_MASK 0x00000004
#define SPREG_PS_DEPC SPREG_PS_DEPC_MASK
/* PS register -- interrupt part */
#define SPREG_PS_DI_SHIFT 3
#define SPREG_PS_DI_MASK 0x0000000F
#define SPREG_PS_DI SPREG_PS_DI_MASK
#define SPREG_PS_DI_DEPC 0x0000000C
/* PS register -- stack part */
#define SPREG_PS_STACK_SHIFT 5
#define SPREG_PS_STACK_MASK 0x000000E0
#define SPREG_PS_STACK_INTERRUPT 0x00000000
#define SPREG_PS_STACK_CROSS 0x00000020
#define SPREG_PS_STACK_IDLE 0x00000040
#define SPREG_PS_STACK_KERNEL 0x00000060
#define SPREG_PS_STACK_PAGE 0x000000E0
#define SPREG_PS_STACK_FIRSTINT 0x00000080
#define SPREG_PS_STACK_FIRSTKER 0x000000A0
/* PS register -- entry no rotate */
#define SPREG_PS_ENTRYNR_SHIFT 22
#define SPREG_PS_ENTRYNR_MASK 0x00400000
#define SPREG_PS_ENTRYNR SPREG_PS_ENTRYNR_MASK
/* Exccause Register -- cause */
#define SPREG_EXCCAUSE_CAUSE_SHIFT 0
#define SPREG_EXCCAUSE_CAUSE_BITS 4
#define SPREG_EXCCAUSE_CAUSE_MASK 0x0000000F
/**
* @ingroup Execute level of core
*/
#define EXEC_LEVEL_APPLICATION_CODE 2
#define EXEC_LEVEL_EXCEPTION_HANDLER 3
#define EXEC_LEVEL_INTERRUPT_HANDLER 4
#define EXEC_LEVEL_NON_INTERRUPTIBLE 5
/**
* @ingroup Schedule Flag stored on Task Context
*/
#define OS_SCHED_FLAG_TASKPREEMT 4 /* Task Preemted through LOS_Schedule */
/**
* @ingroup Context Fields Define
*/
#define CONTEXT_OFF_EPC 0
#define CONTEXT_OFF_PC 0 /* reuse with EPC */
#define CONTEXT_OFF_PS 4
#define CONTEXT_OFF_A0 8
#define CONTEXT_OFF_A1 12
#define CONTEXT_OFF_A2 16
#define CONTEXT_OFF_A3 20
#define CONTEXT_OFF_A4 24
#define CONTEXT_OFF_A5 28
#define CONTEXT_OFF_A6 32
#define CONTEXT_OFF_A7 36
#define CONTEXT_OFF_A8 40
#define CONTEXT_OFF_A9 44
#define CONTEXT_OFF_A10 48
#define CONTEXT_OFF_A11 52
#define CONTEXT_OFF_A12 56
#define CONTEXT_OFF_A13 60
#define CONTEXT_OFF_A14 64
#define CONTEXT_OFF_A15 68
#define CONTEXT_OFF_RESERVED 72
#define CONTEXT_OFF_SAR 72
#define CONTEXT_OFF_SCHED_FLAG 76 /* reuse with exccause */
#define CONTEXT_OFF_EXCCAUSE 76
#define CONTEXT_OFF_EXCVADDR 80
#define CONTEXT_OFF_LBEG 84
#define CONTEXT_OFF_LEND 88
#define CONTEXT_OFF_LCOUNT 92
#if (defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U))
#define CONTEXT_OFF_TMP0 96
#define CONTEXT_OFF_CPENABLE 100
#define CONTEXT_OFF_CPSTORED 102
#define CONTEXT_OFF_FCR 104
#define CONTEXT_OFF_FSR 108
#define CONTEXT_OFF_F0 112
#define CONTEXT_OFF_F1 116
#define CONTEXT_OFF_F2 120
#define CONTEXT_OFF_F3 124
#define CONTEXT_OFF_F4 128
#define CONTEXT_OFF_F5 132
#define CONTEXT_OFF_F6 136
#define CONTEXT_OFF_F7 140
#define CONTEXT_OFF_F8 144
#define CONTEXT_OFF_F9 148
#define CONTEXT_OFF_F10 152
#define CONTEXT_OFF_F11 156
#define CONTEXT_OFF_F12 160
#define CONTEXT_OFF_F13 164
#define CONTEXT_OFF_F14 168
#define CONTEXT_OFF_F15 172
#define CONTEXT_SIZE 192
#else
#define CONTEXT_SIZE 112
#endif
#define EXCCAUSE_LEVEL1INTERRUPT 4
#define XTENSA_LOGREG_NUM 16
#define INDEX_OF_SP 1
#define INDEX_OF_ARGS0 6
#define WINDOWSTARTBITS 16
#define WINDOWBASEBITS 4
#define WINDOWSTARTMASK ((1 << WINDOWSTARTBITS) - 1)
#define WOE_ENABLE 0x40000
#define BIT_CALLINC 16
#define LEVEL_MASK 0xf
#define INT_MASK 5
#define LEVEL1_INT_MASK 1
#define USER_VECTOR_MODE 0x20
#define LEVEL1 1
#define LEVEL2 2
#define LEVEL3 3
#define LEVEL4 4
#define LEVEL5 5
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* __LOS_ARCH_REGS_H__ */
+72
View File
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_ARCH_TIMER_H
#define _LOS_ARCH_TIMER_H
#include "los_config.h"
#include "los_compiler.h"
#include "los_context.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
VOID SysTick_Handler(VOID);
#define TIM0_GROUP0 0x3FF5F000
#define TIM0_GROUP1 0x3FF60000
#define TIM1_GROUP0 0x3FF5F024
#define TIM1_GROUP1 0x3FF60024
#define TIM0_INT_ENABLE_GROUP0 0x3FF5F098
#define TIM0_INT_ENABLE_GROUP1 0x3FF60098
#define TIM0_INT_CLEAR_GROUP0 0x3FF5F0A4
#define TIM0_INT_CLEAR_GROUP1 0x3FF600A4
typedef struct {
UINT32 CTRL;
UINT64 VAL;
UINT32 UPDATE;
UINT64 ALARM;
UINT64 LOAD;
UINT32 LOAD_TRI;
} Systick_t;
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_ARCH_TIMER_H */
+129
View File
@@ -0,0 +1,129 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "los_context.h"
#include "los_arch_context.h"
#include "los_arch_interrupt.h"
#include "los_arch_regs.h"
#include "los_arch_timer.h"
#include "los_debug.h"
#include "los_interrupt.h"
#include "los_sched.h"
#include "los_task.h"
#include "los_timer.h"
#include "securec.h"
UINT64 OsTickCount = 0;
LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
{
}
static VOID ArchSysTickLock()
{
}
static VOID ArchSysTickUnlock()
{
}
LITE_OS_SEC_TEXT_MINOR VOID ArchSysExit(VOID)
{
PRINTK("ArchSysExit");
LOS_IntLock();
while (1) {
;
}
}
LITE_OS_SEC_TEXT_INIT VOID *ArchTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack)
{
vPortStoreTaskSettings((void *)topStack, stackSize, taskID);
return (void *)pxPortInitialiseStack((uint8_t *)topStack + stackSize - 1,
((void (*)(void *))OsTaskEntry), (void *)taskID, 0);
}
LITE_OS_SEC_TEXT_INIT VOID *ArchSignalContextInit(VOID *stackPointer, VOID *stackTop,
UINTPTR sigHandler, UINT32 param)
{
(VOID) stackTop;
(VOID) sigHandler;
(VOID) param;
return (void *)stackPointer;
}
void xPortSysTickHandler(void)
{
OsTickCount++;
OsTickHandler();
}
static UINT32 ArchTickStart(void *handler)
{
OsTickCount = 0;
return LOS_OK;
}
static UINT64 ArchGetTickCycle(UINT32 *period)
{
return (UINT64)OsTickCount * (OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND);
}
UINT32 ArchStartSchedule(VOID)
{
ArchIntLock();
OsSchedStart();
xPortStartScheduler();
return LOS_OK;
}
VOID ArchTaskSchedule(VOID)
{
if (OS_INT_ACTIVE) {
_frxt_setup_switch();
return;
}
vPortYield();
return;
}
static VOID ArchSysTickReload(UINT64 nextResponseTime)
{
}
UINT32 ArchEnterSleep(VOID)
{
__asm__ volatile("dsync\n waiti 0"
:
:
: "memory");
return LOS_OK;
}
STATIC ArchTickTimer g_archTickTimer = {
.freq = OS_SYS_CLOCK,
.irqNum = OS_TICK_INT_NUM,
.init = ArchTickStart,
.getCycle = ArchGetTickCycle,
.reload = ArchSysTickReload,
.lock = ArchSysTickLock,
.unlock = ArchSysTickUnlock,
.tickHandler = NULL,
};
ArchTickTimer *ArchSysTickTimerGet(VOID)
{
return &g_archTickTimer;
}
+82
View File
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdarg.h>
#include <stdint.h>
#include "los_interrupt.h"
#include "los_arch_context.h"
#include "los_arch_interrupt.h"
#include "los_arch_regs.h"
#include "los_context.h"
#include "los_debug.h"
#include "los_hook.h"
#include "los_membox.h"
#include "los_memory.h"
#include "los_sched.h"
#include "los_task.h"
#include "securec.h"
#define IRAM_ATTR __attribute__((section(".iram1.__COUNTER__")))
static const char DefVectorName[] = {"LiteosVector"};
#if (OS_HWI_WITH_ARG == 1)
VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg)
{
xt_set_interrupt_handler(num, (void (*)(void *))vector, arg ? arg : DefVectorName);
}
#else
VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector)
{
}
#endif
INLINE IRAM_ATTR UINT32 HwiNumValid(UINT32 num)
{
return (num >= OS_SYS_VECTOR_CNT) && (num <= OS_VECTOR_CNT);
}
IRAM_ATTR UINT32 HalIrqUnmask(HWI_HANDLE_T hwiNum)
{
if (!HwiNumValid(hwiNum)) {
return OS_ERRNO_HWI_NUM_INVALID;
}
xt_ints_on(1 << hwiNum);
return LOS_OK;
}
IRAM_ATTR UINT32 HalIrqMask(HWI_HANDLE_T hwiNum)
{
if (!HwiNumValid(hwiNum)) {
return OS_ERRNO_HWI_NUM_INVALID;
}
xt_ints_off(1 << hwiNum);
return LOS_OK;
}
+84
View File
@@ -0,0 +1,84 @@
# Copyright (c) 2021-2022 Talkweb 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.
# Kernel type, e.g. "linux", "liteos_a", "liteos_m".
kernel_type = "liteos_m"
# Kernel version.
kernel_version = "3.0.0"
# Board arch, e.g. "armv7-a", "rv32imac".
board_arch = ""
board="esp32u4"
board_cpu=""
# Toolchain name used for system compiling.
# E.g. gcc-arm-none-eabi, arm-linux-harmonyeabi-gcc, ohos-clang, riscv32-unknown-elf.
# Note: The default toolchain is "ohos-clang". It's not mandatory if you use the default toochain.
board_toolchain = "xtensa-esp32-elf-gcc"
# The toolchain path instatlled, it's not mandatory if you have added toolchian path to your ~/.bashrc.
board_toolchain_path = ""
# Compiler prefix.
board_toolchain_prefix = "xtensa-esp32-elf-"
# Compiler type, "gcc" or "clang".
board_toolchain_type = "gcc"
# Board related common compile flags.
board_cflags = [
"-mlongcalls",
"-O2",
"-Wall",
"-Wextra",
"-fno-common",
"-Wdouble-promotion",
"-mtext-section-literals",
"-DESP32",
"-Wno-implicit-function-declaration",
"-Wno-sign-conversion",
"-Wno-sign-compare",
"-W",
"-Wshadow",
"-ffunction-sections",
"-fdata-sections",
"-Wno-conversion",
"-Wno-unused-parameter",
"-Wno-unused-variable",
"-Wno-type-limits",
"-Wno-cast-function-type",
"-Wno-implicit-fallthrough",
"-Wno-parentheses",
"-Wno-pointer-sign",
]
board_cxx_flags = board_cflags
board_ld_flags = []
# Board related headfiles search path.
board_include_dirs = [
"//utils/native/lite/include",
]
# Board adapter dir for OHOS components.
board_adapter_dir = ""
# Sysroot path.
board_configed_sysroot = ""
# Board storage type, it used for file system generation.
storage_type = ""
+27
View File
@@ -0,0 +1,27 @@
# Copyright (c) 2022 OpenValley Digital Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
module_group("drivers") {
modules = [
"osal",
"watchdog",
"wifi",
"adc",
"gpio",
"uart",
"i2c",
]
}
+24
View File
@@ -0,0 +1,24 @@
# Copyright (c) 2022 OpenValley Digital Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
module_switch = defined(LOSCFG_DRIVERS_HDF_PLATFORM_ADC)
hdf_driver("adc") {
sources = [
"adc.c",
]
}
config("public") {
include_dirs = [ "." ]
}
+104
View File
@@ -0,0 +1,104 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include <string.h>
#include "adc_core.h"
#include "adc_if.h"
#include "cmsis_os2.h"
#include "device_resource_if.h"
#include "hdf_base.h"
#include "hdf_device_desc.h"
#include "hdf_io_service_if.h"
#include "hdf_log.h"
#include "osal_irq.h"
int32_t AdcDevOpen(struct AdcDevice *device, uint32_t number);
void AdcDevClose(struct AdcDevice *device);
int32_t AdcDevRead(struct AdcDevice *device, uint32_t number, uint32_t channel, uint32_t *val);
struct AdcMethod g_AdcCntlrMethod = {
.read = AdcDevRead,
.start = AdcDevOpen,
.stop = AdcDevClose,
};
static int32_t DeviceInit(struct HdfDeviceObject *object);
static int32_t DeviceBind(struct HdfDeviceObject *object);
static void DeviceRelease(struct HdfDeviceObject *object);
static const struct HdfDriverEntry ADC_DriverEntry = {
.moduleVersion = 1,
.moduleName = "HDF_ADC_MODULE",
.Bind = DeviceBind,
.Init = DeviceInit,
.Release = DeviceRelease,
};
HDF_INIT(ADC_DriverEntry);
typedef struct {
uint32_t unit;
uint32_t channel;
} DeviceInfo_t;
static const DeviceInfo_t DeviceInfoDefault = {
.unit = -1,
.channel = -1,
};
static int32_t DeviceInit(struct HdfDeviceObject *object)
{
DeviceInfo_t *dev;
int ret;
if (object == NULL) {
return HDF_FAILURE;
}
dev = (DeviceInfo_t *)OsalMemAlloc(sizeof(DeviceInfo_t));
if (dev == NULL) {
HDF_LOGE("%s.malloc\n", ADC_DriverEntry.moduleName);
return HDF_DEV_ERR_NO_MEMORY;
}
object->priv = (void *)dev;
ret = memcpy_s(dev, sizeof(DeviceInfoDefault), &DeviceInfoDefault, sizeof(DeviceInfoDefault));
if (ret != 0) {
HDF_LOGE("memcpy_s fail!\n");
return HDF_FAILURE;
}
if (object->property) {
const struct DeviceResourceNode *node = object->property;
struct DeviceResourceIface *resource = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
resource->GetUint32(node, "unit", &dev->unit, -1);
resource->GetUint32(node, "channel", &dev->channel, -1);
}
return HDF_SUCCESS;
}
static int32_t DeviceBind(struct HdfDeviceObject *object)
{
return HDF_SUCCESS;
}
static void DeviceRelease(struct HdfDeviceObject *object)
{
if (!object) {
return;
}
if (object->priv) {
DeviceInfo_t *dev = (DeviceInfo_t *)object->priv;
AdcDevClose(AdcDevClose);
OsalMemFree(object->priv);
}
object->priv = NULL;
}
+29
View File
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __ADC_H__
#define __ADC_H__
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /* __ESP32_ADC_H__ */
+24
View File
@@ -0,0 +1,24 @@
# Copyright (c) 2022 OpenValley Digital Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
module_switch = defined(LOSCFG_DRIVERS_HDF_PLATFORM_GPIO)
hdf_driver("gpio") {
sources = [
"gpio.c",
]
}
config("public") {
include_dirs = [ "." ]
}
+164
View File
@@ -0,0 +1,164 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include <string.h>
#include "cmsis_os2.h"
#include "device_resource_if.h"
#include "gpio_core.h"
#include "gpio_if.h"
#include "hdf_base.h"
#include "hdf_device_desc.h"
#include "hdf_io_service_if.h"
#include "hdf_log.h"
#include "osal_irq.h"
#define GPIO_OUTPUT_IO_0 18
#define GPIO_OUTPUT_IO_1 19
#define GPIO_OUTPUT_PIN_SEL ((1ULL << GPIO_OUTPUT_IO_0) | (1ULL << GPIO_OUTPUT_IO_1))
#define GPIO_INPUT_IO_0 4
#define GPIO_INPUT_IO_1 5
#define GPIO_INPUT_PIN_SEL ((1ULL << GPIO_INPUT_IO_0) | (1ULL << GPIO_INPUT_IO_1))
#define LED_GPIO 5
#define LED_OFF 0x00
#define LED_ON 0x01
typedef void (*gpio_isr_t)(void *);
int32_t InitGpioDevice(int pin);
int32_t GpioDevWrite(int pin, int val);
int32_t GpioDevRead(int pin, unsigned int *val);
int32_t GpioDevSetDir(int pin, int dir);
int32_t GpioDevGetDir(int pin);
int32_t GpioDevSetIrq(int pin, int mode, int pin_bit_mask);
int32_t GpioDevUnSetIrq(int pin);
int32_t GpioDevEnableIrq(int pin, int int_type, gpio_isr_t isr_handler, void *args);
int32_t GpioDevDisableIrq(int pin);
struct GpioMethod g_GpioCntlrMethod = {
.request = NULL,
.release = NULL,
.write = GpioDevWrite,
.read = GpioDevRead,
.setDir = GpioDevSetDir,
.getDir = GpioDevGetDir,
.toIrq = NULL,
.setIrq = GpioDevSetIrq,
.unsetIrq = GpioDevUnSetIrq,
.enableIrq = GpioDevEnableIrq,
.disableIrq = GpioDevDisableIrq,
};
static int32_t DeviceInit(struct HdfDeviceObject *object);
static int32_t DeviceBind(struct HdfDeviceObject *object);
static void DeviceRelease(struct HdfDeviceObject *object);
static const struct HdfDriverEntry GPIO_DriverEntry = {
.moduleVersion = 1,
.moduleName = "HDF_GPIO_MODULE",
.Bind = DeviceBind,
.Init = DeviceInit,
.Release = DeviceRelease,
};
HDF_INIT(GPIO_DriverEntry);
typedef struct {
int16_t power_pin;
int16_t address;
int8_t port;
DevHandle handle;
} DeviceInfo_t;
static const DeviceInfo_t DeviceInfoDefault = {
.power_pin = -1,
.address = -1,
.port = -1,
};
/**
* @brief Enumerates GPIO directions.
*
* @since 1.0
*/
enum HDF_GpioDirType {
HDF_GPIO_DIR_IN = (0x00000001), /**< Input direction */
HDF_GPIO_DIR_OUT = (0x00000002), /**< Output direction */
HDF_GPIO_DIR_ERR, /**< Invalid direction */
};
typedef enum {
GPIO_INTR_DISABLE = 0, /*!< Disable GPIO interrupt */
GPIO_INTR_POSEDGE = 1, /*!< GPIO interrupt type : rising edge */
GPIO_INTR_NEGEDGE = 2, /*!< GPIO interrupt type : falling edge */
GPIO_INTR_ANYEDGE = 3, /*!< GPIO interrupt type : both rising and falling edge */
GPIO_INTR_LOW_LEVEL = 4, /*!< GPIO interrupt type : input low level trigger */
GPIO_INTR_HIGH_LEVEL = 5, /*!< GPIO interrupt type : input high level trigger */
GPIO_INTR_MAX,
} gpio_int_type_t;
static void gpio_isr_handler(void *arg)
{
uint32_t gpio_num = (uint32_t)arg;
HDF_LOGE("gpio_isr_handler success !");
}
static int32_t DeviceInit(struct HdfDeviceObject *object)
{
DeviceInfo_t *dev;
int ret;
static unsigned int g_irqData = 100;
struct GpioCntlr *gpioCntlr = NULL;
if (object == NULL) {
return HDF_FAILURE;
}
dev = (DeviceInfo_t *)OsalMemAlloc(sizeof(DeviceInfo_t));
if (dev == NULL) {
HDF_LOGE("%s.malloc\n", GPIO_DriverEntry.moduleName);
return HDF_DEV_ERR_NO_MEMORY;
}
object->priv = (void *)dev;
ret = memcpy_s(dev, sizeof(DeviceInfoDefault), &DeviceInfoDefault, sizeof(DeviceInfoDefault));
if (ret != 0) {
HDF_LOGE("memcpy_s fail!\r\n");
return HDF_FAILURE;
}
if (!OsalRegisterIrq(LED_GPIO, 0, gpio_isr_handler, "test", &g_irqData)) {
HDF_LOGE("OsalRegisterIrq success!...\n\r");
} else {
HDF_LOGE("OsalRegisterIrq error!...\n\r");
}
if (!OsalDisableIrq(LED_GPIO)) {
HDF_LOGE("OsalDisableIrq success!...\n\r");
} else {
HDF_LOGE("OsalDisableIrq error!...\n\r");
}
return HDF_SUCCESS;
}
static int32_t DeviceBind(struct HdfDeviceObject *object)
{
return HDF_SUCCESS;
}
static void DeviceRelease(struct HdfDeviceObject *object)
{
if (!object) {
return;
}
if (object->priv) {
DeviceInfo_t *dev = (DeviceInfo_t *)object->priv;
InitGpioDevice(dev->port);
OsalMemFree(object->priv);
}
object->priv = NULL;
}
+29
View File
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __GPIO_H__
#define __GPIO_H__
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /* __ESP32_GPIO_H__ */
+26
View File
@@ -0,0 +1,26 @@
# Copyright (c) 2022 OpenValley Digital Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
module_switch = defined(LOSCFG_DRIVERS_HDF_PLATFORM_I2C)
module_name = "i2c"
hdf_driver(module_name) {
sources = [
"i2c.c",
]
}
config("public") {
include_dirs = [ "." ]
}
+170
View File
@@ -0,0 +1,170 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include <string.h>
#include "cmsis_os2.h"
#include "device_resource_if.h"
#include "hdf_base.h"
#include "hdf_device_desc.h"
#include "hdf_io_service_if.h"
#include "hdf_log.h"
#include "i2c_core.h"
#include "i2c.h"
#define LOG_TAG "I2C"
#define I2C_SPEED (400 * 1000)
static int32_t DeviceInit(struct HdfDeviceObject *object);
static int32_t DeviceBind(struct HdfDeviceObject *object);
static void DeviceRelease(struct HdfDeviceObject *object);
static int32_t ClientOpen(struct HdfDeviceIoClient *client);
static int32_t ClientDispatch(struct HdfDeviceIoClient *client, int cmdId,
struct HdfSBuf *data, struct HdfSBuf *reply);
static void ClientRelease(struct HdfDeviceIoClient *client);
static int32_t DeviceTransfer(struct I2cCntlr *cntlr, struct I2cMsg *msgs, int16_t count);
int DeviceI2cInit(DeviceI2cParams *params);
unsigned int DeviceI2cWrite(int id, unsigned char addr, const unsigned char *data, unsigned int dataLen, int ack);
unsigned int DeviceI2cRead(int id, unsigned char addr, const unsigned char *data, unsigned int dataLen, int ack);
static const struct HdfDriverEntry I2C_DriverEntry = {
.moduleVersion = 1,
.moduleName = "HDF_I2C_MODULE",
.Bind = DeviceBind,
.Init = DeviceInit,
.Release = DeviceRelease,
};
static struct IDeviceIoService DriverService = {
.object.objectId = 0,
.Open = ClientOpen,
.Dispatch = ClientDispatch,
.Release = ClientRelease,
};
#define DriverEntry I2C_DriverEntry
HDF_INIT(I2C_DriverEntry);
typedef struct {
struct I2cCntlr cntlr;
uint8_t scl_pin[3];
uint8_t sda_pin[3];
uint8_t mode;
uint8_t port;
uint32_t speed;
} DeviceInfo_t;
static const struct I2cMethod I2cOpsDefault = {
.transfer = DeviceTransfer};
static const DeviceInfo_t DeviceInfoDefault = {
.cntlr.ops = &I2cOpsDefault,
.cntlr.lockOps = NULL,
};
static int32_t DeviceTransfer(struct I2cCntlr *cntlr, struct I2cMsg *msgs, int16_t count)
{
for (; count > 0; --count, ++msgs) {
if ((msgs->flags) == 0) {
if (DeviceI2cWrite(cntlr->busId, msgs->addr, msgs->buf, msgs->len, 1)) {
break;
}
} else if ((msgs->flags) == I2C_FLAG_READ) {
if (DeviceI2cRead(cntlr->busId, msgs->addr, msgs->buf, msgs->len, 1)) {
break;
}
}
}
return count;
}
static uint32_t DeviceIRQ(uint32_t irqId, void *dev)
{
return 0;
}
static int32_t DeviceInit(struct HdfDeviceObject *object)
{
DeviceInfo_t *dev;
int ret;
if (object == NULL) {
return HDF_FAILURE;
}
dev = (DeviceInfo_t *)OsalMemAlloc(sizeof(DeviceInfo_t));
if (dev == NULL) {
HDF_LOGE("%s.malloc\n", DriverEntry.moduleName);
return HDF_DEV_ERR_NO_MEMORY;
}
object->priv = (void *)dev;
ret = memcpy_s(dev, sizeof(DeviceInfoDefault), &DeviceInfoDefault, sizeof(DeviceInfoDefault));
if (ret != 0) {
HDF_LOGE("memcpy_s fail!\r\n");
return HDF_FAILURE;
}
if (object->property) {
struct I2cCntlr *cntlr;
const struct DeviceResourceNode *node = object->property;
struct DeviceResourceIface *resource = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
cntlr = &dev->cntlr;
resource->GetUint8(node, "port", &dev->port, 0);
resource->GetUint8Array(node, "scl_pin", dev->scl_pin, sizeof(dev->scl_pin) / sizeof(dev->scl_pin[0]), 0);
resource->GetUint8Array(node, "sda_pin", dev->sda_pin, sizeof(dev->sda_pin) / sizeof(dev->sda_pin[0]), 0);
resource->GetUint8(node, "mode", &dev->mode, 0xFF);
resource->GetUint32(node, "speed", &dev->speed, 0);
cntlr->busId = dev->port;
}
DeviceI2cParams dev_params = {
.cmd = 0,
.id = dev->port,
.scl_pin = dev->scl_pin[0],
.sda_pin = dev->sda_pin[0],
.speed = dev->speed,
.mode = dev->mode,
};
DeviceI2cInit(&dev_params);
if (I2cCntlrAdd(&dev->cntlr) != HDF_SUCCESS) {
OsalMemFree(dev);
HDF_LOGE("%s.I2cCntlrAdd\n", DriverEntry.moduleName);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t DeviceBind(struct HdfDeviceObject *object)
{
return HDF_SUCCESS;
}
static void DeviceRelease(struct HdfDeviceObject *object)
{
if (!object) {
return;
}
if (object->priv) {
DeviceInfo_t *dev = (DeviceInfo_t *)object->priv;
I2cCntlrRemove(&dev->cntlr);
DeviceI2cParams dev_params = {
.cmd = -1,
.id = dev->port,
.scl_pin = dev->scl_pin,
.sda_pin = dev->sda_pin,
.speed = I2C_SPEED,
.mode = dev->mode,
};
DeviceI2cInit(&dev_params);
OsalMemFree(object->priv);
}
object->priv = NULL;
}
+37
View File
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __ESP32_I2C_H__
#define __ESP32_I2C_H__
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _DeviceI2cParams {
int cmd;
int id;
int scl_pin;
int sda_pin;
int speed;
int mode;
} DeviceI2cParams;
#ifdef __cplusplus
}
#endif
#endif /* __ESP32_I2C_H__ */
+30
View File
@@ -0,0 +1,30 @@
# Copyright (c) 2022 OpenValley Digital Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
module_switch = defined(LOSCFG_DRIVERS_HDF)
module_name = "esp_osal"
hdf_driver(module_name) {
sources = [
"osal.c",
]
include_dirs = [
"../../../../components/esp_system/include",
"../../../../components/esp_common/include"
]
}
config("public") {
include_dirs = [ "." ]
}
+67
View File
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include <string.h>
#include "esp_intr_alloc.h"
#include "device_resource_if.h"
#include "hdf_device_desc.h"
#include "hdf_io_service_if.h"
#include "osal.h"
#define LOG_TAG "esp_osal"
#define MAX_IRQ_ID 71
static intr_handle_data_t *OaslIntrHandle[MAX_IRQ_ID] = {NULL};
int32_t OsalRegisterIrq(uint32_t irqId, uint32_t config, OsalIRQHandle handle, const char *name, void *dev)
{
// xt_set_interrupt_handler
int ret;
if (irqId >= MAX_IRQ_ID)
return HDF_FAILURE;
if (OaslIntrHandle[irqId])
OsalUnregisterIrq(irqId, dev);
ret = esp_intr_alloc(irqId, config, (intr_handler_t)handle, dev, &OaslIntrHandle[irqId]);
return (ret == ESP_OK) ? HDF_SUCCESS : HDF_FAILURE;
}
int32_t OsalUnregisterIrq(uint32_t irqId, void *dev)
{
intr_handle_data_t *handle;
if (irqId > MAX_IRQ_ID)
return HDF_FAILURE;
handle = OaslIntrHandle[irqId];
OaslIntrHandle[irqId] = NULL;
if (!handle)
return HDF_FAILURE;
return (ESP_OK == esp_intr_free(handle)) ? HDF_SUCCESS : HDF_FAILURE;
}
int32_t OsalEnableIrq(uint32_t irqId)
{
if (irqId > MAX_IRQ_ID)
return HDF_FAILURE;
if (!OaslIntrHandle[irqId])
return HDF_FAILURE;
return (ESP_OK == esp_intr_enable(OaslIntrHandle[irqId])) ? HDF_SUCCESS : HDF_FAILURE;
}
int32_t OsalDisableIrq(uint32_t irqId)
{
if (irqId > MAX_IRQ_ID)
return HDF_FAILURE;
if (!OaslIntrHandle[irqId])
return HDF_FAILURE;
return (ESP_OK == esp_intr_disable(OaslIntrHandle[irqId])) ? HDF_SUCCESS : HDF_FAILURE;
}
+25
View File
@@ -0,0 +1,25 @@
# Copyright (c) 2022 OpenValley Digital Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
module_switch = defined(LOSCFG_DRIVERS_HDF_PLATFORM_UART)
hdf_driver("uart") {
sources = [
"uart.c",
]
#defines = [ "ARM_CMNS=1" ]
}
config("public") {
include_dirs = [ "." ]
}
+164
View File
@@ -0,0 +1,164 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include <string.h>
#include "cmsis_os2.h"
#include "device_resource_if.h"
#include "hdf_base.h"
#include "hdf_device_desc.h"
#include "hdf_io_service_if.h"
#include "hdf_log.h"
#include "uart_core.h"
#include "uart_if.h"
typedef struct {
uint8_t port;
uint8_t tx_io;
uint8_t rx_io;
uint8_t flow_ctrl;
uint8_t rts_io;
uint8_t cts_io;
} uartInfo_t;
int32_t uartInit(struct UartHost *host);
int32_t uartDeinit(struct UartHost *host);
int32_t uartRead(struct UartHost *host, uint8_t *data, uint32_t size);
int32_t uartWrite(struct UartHost *host, uint8_t *data, uint32_t size);
int32_t uartGetBaud(struct UartHost *host, uint32_t *baudRate);
int32_t uartSetBaud(struct UartHost *host, uint32_t baudRate);
int32_t uartGetAttribute(struct UartHost *host, struct UartAttribute *attribute);
int32_t uartSetAttribute(struct UartHost *host, struct UartAttribute *attribute);
int32_t uartSetTransMode(struct UartHost *host, enum UartTransMode mode);
int32_t uartpollEvent(struct UartHost *host, void *filep, void *table);
int32_t UartDeviceBind(struct HdfDeviceObject *object);
int32_t UartDeviceInit(struct HdfDeviceObject *object);
void UartDeviceRelease(struct HdfDeviceObject *object);
static const struct UartHostMethod g_uartMethodDefault = {
.Init = uartInit,
.Deinit = uartDeinit,
.Read = uartRead,
.Write = uartWrite,
.GetAttribute = uartGetAttribute,
.GetBaud = uartGetBaud,
.pollEvent = uartpollEvent,
.SetAttribute = uartSetAttribute,
.SetBaud = uartSetBaud,
.SetTransMode = uartSetTransMode,
};
static const uartInfo_t uartInfoDefault = {
.port = -1,
.tx_io = -1,
.rx_io = -1,
.flow_ctrl = -1,
.rts_io = -1,
.cts_io = -1,
};
static const struct HdfDriverEntry UartDriverEntry = {
.moduleVersion = 1,
.moduleName = "HDF_PLATFORM_UART",
.Bind = UartDeviceBind,
.Init = UartDeviceInit,
.Release = UartDeviceRelease,
};
HDF_INIT(UartDriverEntry);
int32_t UartDeviceBind(struct HdfDeviceObject *object)
{
esp_rom_printf("%s come in\n", __func__);
if (object == NULL) {
return HDF_ERR_INVALID_OBJECT;
}
return (UartHostCreate(object) == NULL) ? HDF_FAILURE : HDF_SUCCESS;
}
int32_t UartDeviceInit(struct HdfDeviceObject *object)
{
int ret;
uartInfo_t *dev;
struct UartHost *host = NULL;
esp_rom_printf("%s come in\n", __func__);
if (object == NULL) {
return HDF_FAILURE;
}
host = UartHostFromDevice(object);
if (host == NULL) {
esp_rom_printf("%s: host is null", __func__);
return HDF_FAILURE;
}
dev = (uartInfo_t *)OsalMemAlloc(sizeof(uartInfo_t));
if (dev == NULL) {
esp_rom_printf("%s.malloc\n", UartDriverEntry.moduleName);
return HDF_DEV_ERR_NO_MEMORY;
}
ret = memcpy_s(dev, sizeof(uartInfoDefault), &uartInfoDefault, sizeof(uartInfoDefault));
if (ret != 0) {
HDF_LOGE("memcpy_s fail!\r\n");
return HDF_FAILURE;
}
if (object->property) {
const struct DeviceResourceNode *node = object->property;
struct DeviceResourceIface *resource = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
resource->GetUint8(node, "port", &dev->port, -1);
resource->GetUint8(node, "tx_io", &dev->tx_io, -1);
resource->GetUint8(node, "rx_io", &dev->rx_io, -1);
resource->GetUint8(node, "flow_ctrl", &dev->flow_ctrl, -1);
resource->GetUint8(node, "rts_io", &dev->rts_io, -1);
resource->GetUint8(node, "cts_io", &dev->cts_io, -1);
}
host->priv = dev;
host->num = dev->port;
host->method = &g_uartMethodDefault;
return HDF_SUCCESS;
}
void UartDeviceRelease(struct HdfDeviceObject *object)
{
esp_rom_printf("%s come in\n", __func__);
struct UartHost *host = NULL;
if (!object) {
return;
}
host = UartHostFromDevice(object);
if (host == NULL) {
esp_rom_printf("%s: host is null", __func__);
return;
}
if (host->priv != NULL) {
host->priv = NULL;
}
OsalMemFree(host->priv);
}
+23
View File
@@ -0,0 +1,23 @@
# Copyright (c) 2022 OpenValley Digital Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
module_switch = defined(LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG)
module_name = "watchdog"
hdf_driver(module_name) {
sources = [
"watchdog.c",
]
}
+247
View File
@@ -0,0 +1,247 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include <string.h>
#include "cmsis_os2.h"
#include "device_resource_if.h"
#include "hdf_base.h"
#include "hdf_device_desc.h"
#include "hdf_io_service_if.h"
#include "hdf_log.h"
#include "watchdog_core.h"
#define RWDT_PROTECT_KEY 0x50d83aa1
#define RWDT_PROTECT 0x3ff480a4
#define RWDT_CFG0 0x3ff4808c
#define RWDT_CFG0_VALUE ((1 << 10) | (7 << 11) | (3 << 28) | (1 << 31))
#define RWDT_CFG1 0x3ff48090
#define RWDT_FEED 0x3ff480a0
#define RWDT_TICKS_TYPE 0x3ff48070
#define RWDT_WOG_VALUE (1 << 31)
#define RWDT_IS_RUN_BIT (1 << 31)
#define OFFSET_30 30
#define BIT_3 3
#define SLOW_CK_TICKS (150 * 1000)
#define XTAL_32K_TICKS (32768)
#define CK8M_D256_OUT_CK_TICKS (8 * 1000 * 1000 / 256)
#define WATCHDOG_TIMEOUT 5
static int32_t WatchdogDeviceInit(struct HdfDeviceObject *object);
static int32_t WatchdogDeviceBind(struct HdfDeviceObject *object);
static void WatchdogDeviceRelease(struct HdfDeviceObject *object);
static int32_t WatchdogDevGetStatus(struct WatchdogCntlr *wdt, int32_t *status);
static int32_t WatchdogDevSetTimeout(struct WatchdogCntlr *wdt, uint32_t seconds);
static int32_t WatchdogDevGetTimeout(struct WatchdogCntlr *wdt, uint32_t *seconds);
static int32_t WatchdogDevStart(struct WatchdogCntlr *wdt);
static int32_t WatchdogDevStop(struct WatchdogCntlr *wdt);
static int32_t WatchdogDevFeed(struct WatchdogCntlr *wdt);
static int32_t WatchdogDevGetPriv(struct WatchdogCntlr *wdt);
static void WatchdogDevReleasePriv(struct WatchdogCntlr *wdt);
typedef struct {
struct WatchdogCntlr cntlr;
uint32_t timeout;
} PrivWatchdog_t;
static struct WatchdogMethod WatchdogCntlrMethod = {
.getStatus = WatchdogDevGetStatus,
.setTimeout = WatchdogDevSetTimeout,
.getTimeout = WatchdogDevGetTimeout,
.start = WatchdogDevStart,
.stop = WatchdogDevStop,
.feed = WatchdogDevFeed,
.getPriv = NULL,
.releasePriv = NULL};
static const struct HdfDriverEntry WatchdogDriverEntry = {
.moduleVersion = 1,
.moduleName = "HDF_WATCHDOG_MODULE",
.Bind = WatchdogDeviceBind,
.Init = WatchdogDeviceInit,
.Release = WatchdogDeviceRelease,
};
#define DriverEntry WatchdogDriverEntry
HDF_INIT(WatchdogDriverEntry);
static uint32_t GetRwdtTicksType()
{
volatile uint32_t *ptr = RWDT_TICKS_TYPE;
return (((*ptr) >> OFFSET_30) & BIT_3);
}
static void RWDT_WOG(void)
{
*(volatile uint32_t *)RWDT_FEED = RWDT_WOG_VALUE;
}
static uint32_t RWDT_IS_RUN(void)
{
return (*(volatile uint32_t *)RWDT_CFG0) & RWDT_IS_RUN_BIT;
}
static int32_t WatchdogDeviceInit(struct HdfDeviceObject *object)
{
if (!object)
return HDF_ERR_INVALID_OBJECT;
PrivWatchdog_t *dev;
int ret;
dev = (PrivWatchdog_t *)OsalMemAlloc(sizeof(PrivWatchdog_t));
if (dev == NULL) {
HDF_LOGE("%s.malloc\n", DriverEntry.moduleName);
return HDF_DEV_ERR_NO_MEMORY;
}
ret = memset_s(dev, sizeof(PrivWatchdog_t), 0, sizeof(PrivWatchdog_t));
if (ret != 0) {
HDF_LOGE("memset_s fail!\r\n");
return HDF_FAILURE;
}
object->priv = (void *)dev;
object->service = &dev->cntlr.service;
dev->timeout = WATCHDOG_TIMEOUT;
dev->cntlr.wdtId = 0;
dev->cntlr.device = object;
dev->cntlr.ops = &WatchdogCntlrMethod;
dev->cntlr.priv = (void *)dev;
if (WatchdogCntlrAdd(&dev->cntlr) != HDF_SUCCESS) {
OsalMemFree(dev);
HDF_LOGE("%s.WatchdogCntlrAdd\n", DriverEntry.moduleName);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t WatchdogDeviceBind(struct HdfDeviceObject *object)
{
return HDF_SUCCESS;
}
static void WatchdogDeviceRelease(struct HdfDeviceObject *object)
{
if (!object) {
return;
}
if (object->priv) {
return;
}
WatchdogDevStop(&((PrivWatchdog_t *)object->priv)->cntlr);
OsalMemFree(object->priv);
object->priv = NULL;
return;
}
static int32_t WatchdogDevGetStatus(struct WatchdogCntlr *wdt, int32_t *status)
{
if (!wdt) {
return HDF_FAILURE;
}
if (status) {
*status = RWDT_IS_RUN() ? 1 : 0;
}
return HDF_SUCCESS;
}
static int32_t WatchdogDevSetTimeout(struct WatchdogCntlr *wdt, uint32_t seconds)
{
if (!wdt)
return HDF_FAILURE;
if (!wdt->priv)
return HDF_FAILURE;
((PrivWatchdog_t *)wdt->priv)->timeout = seconds;
return HDF_SUCCESS;
}
static int32_t WatchdogDevGetTimeout(struct WatchdogCntlr *wdt, uint32_t *seconds)
{
if (!wdt)
return HDF_FAILURE;
if (seconds) {
if (!wdt->priv)
return HDF_FAILURE;
*seconds = ((PrivWatchdog_t *)wdt->priv)->timeout;
}
return HDF_SUCCESS;
}
static int32_t WatchdogDevStart(struct WatchdogCntlr *wdt)
{
uint32_t ticks;
if (!wdt)
return HDF_FAILURE;
if (!wdt->priv)
return HDF_FAILURE;
switch (GetRwdtTicksType()) {
case 1:
ticks = XTAL_32K_TICKS;
break; // XTAL_32K
case 2:
ticks = CK8M_D256_OUT_CK_TICKS;
break; // CK8M_D256_OUT
default:
ticks = SLOW_CK_TICKS;
break; // SLOW_CK
}
// ====== RTC_WDT_CFG0
/* 7: pause WDT in sleep */
/* 8: enable WDT reset APP CPU */
/* 9: enable WDT reset PRO CPU */
/* 10: enable WDT in flash boot */
/* 11-13: system reset counter length */
/* 14-16: CPU reset counter length */
/* 17: When set, level type interrupt generation is enabled */
/* 18: When set, edge type interrupt generation is enabled */
/* 19-21: 1: interrupt stage en 2: CPU reset stage en 3: system reset stage en 4: RTC reset stage en */
/* 22-24: 1: interrupt stage en 2: CPU reset stage en 3: system reset stage en 4: RTC reset stage en */
/* 25-27: 1: interrupt stage en 2: CPU reset stage en 3: system reset stage en 4: RTC reset stage en */
/* 28-30: 1: interrupt stage en 2: CPU reset stage en 3: system reset stage en 4: RTC reset stage en */
/* 31: enable RTC WDT */
*(volatile uint32_t *)RWDT_PROTECT = RWDT_PROTECT_KEY;
RWDT_WOG();
*(volatile uint32_t *)RWDT_CFG0 = RWDT_CFG0_VALUE;
// 最大超时时间 4G / (150K 或 32768 或 8M/256)
*(volatile uint32_t *)RWDT_CFG1 = ((PrivWatchdog_t *)wdt->priv)->timeout * ticks;
*(volatile uint32_t *)RWDT_PROTECT = 0;
return HDF_SUCCESS;
}
static int32_t WatchdogDevStop(struct WatchdogCntlr *wdt)
{
if (!wdt) {
return HDF_FAILURE;
}
if (!RWDT_IS_RUN()) {
return HDF_SUCCESS;
}
*(volatile uint32_t *)RWDT_PROTECT = RWDT_PROTECT_KEY;
RWDT_WOG();
*(volatile uint32_t *)RWDT_CFG0 = 0;
*(volatile uint32_t *)RWDT_PROTECT = 0;
return HDF_SUCCESS;
}
static int32_t WatchdogDevFeed(struct WatchdogCntlr *wdt)
{
if (!wdt) {
return HDF_FAILURE;
}
*(volatile uint32_t *)RWDT_PROTECT = RWDT_PROTECT_KEY;
RWDT_WOG();
*(volatile uint32_t *)RWDT_PROTECT = 0;
return HDF_SUCCESS;
}
static int32_t WatchdogDevGetPriv(struct WatchdogCntlr *wdt)
{
if (!wdt) {
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static void WatchdogDevReleasePriv(struct WatchdogCntlr *wdt)
{
}
+44
View File
@@ -0,0 +1,44 @@
# Copyright (c) 2022 OpenValley Digital Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
module_switch = defined(LOSCFG_DRIVERS_HDF_PLATFORM_WIFI)
hdf_driver("wifi_sta") {
sources = [
"wifi_sta.c",
]
include_dirs = [
"//foundation/communication/wifi_lite/interfaces/wifiservice",
"//device/soc/espressif/esp32/components/lwip/include/apps",
"//device/soc/espressif/esp32/components/lwip/include/apps/sntp",
"//device/soc/espressif/esp32/components/lwip/lwip/src/include",
"//device/soc/espressif/esp32/components/lwip/port/esp32/include",
"//device/soc/espressif/esp32/components/lwip/port/esp32/include/arch",
"//device/soc/espressif/esp32/components/esp_common/include",
"//device/soc/espressif/esp32/components",
"//device/soc/espressif/esp32/components/freertos/include",
"//device/soc/espressif/esp32/components/freertos/port/xtensa/include",
"//device/soc/espressif/esp32/components/xtensa/include",
"//device/soc/espressif/esp32/components/xtensa/esp32/include",
"//device/soc/espressif/esp32/components/esp_rom/include",
"//device/soc/espressif/esp32/components/spi_flash/sim/stubs/esp_timer/include",
"//device/soc/espressif/esp32/components/esp_system/include",
"//device/soc/espressif/esp32/components/newlib/platform_include",
"//device/soc/espressif/esp32/components/esp_hw_support/include",
"//device/soc/espressif/esp32/components/hal/include",
"//device/soc/espressif/esp32/components/soc/esp32/include",
"//device/soc/espressif/esp32/components/hal/esp32/include",
"//device/soc/espressif/esp32/components/soc/include",
"//device/soc/espressif/esp32/components/heap/include",
]
}
+34
View File
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __WIFI_H__
#define __WIFI_H__
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
void OnWifiConnectSocket(int port, const char *ip); // 指定端口连接socket
void OnWifiConnectDevice(const char *wifi_name, const char *wifi_pwd); // 指定wifi名和密码进行连接wifi设备
int32_t GetWifiConnectStatus(void); // 获取wifi连接状态
int32_t getmac(uint8_t *mac); // 获取以太网mac地址
#ifdef __cplusplus
}
#endif
#endif /* __ESP32_WIFI_H__ */
+270
View File
@@ -0,0 +1,270 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "cmsis_os2.h"
#include "device_resource_if.h"
#include "hdf_base.h"
#include "hdf_device_desc.h"
#include "hdf_io_service_if.h"
#include "hdf_log.h"
#include "los_debug.h"
#include "los_task.h"
#include "lwip/netifapi.h"
#include "lwip/sockets.h"
#include "ohos_init.h"
#include "ohos_types.h"
#include "stdio.h"
#include "wifi.h"
#include "wifi_device.h"
#define TICK_COUNT 1000
#define INDEX_0 0
#define INDEX_1 1
#define INDEX_2 2
#define INDEX_3 3
#define INDEX_4 4
#define INDEX_5 5
#define INDEX_6 6
#define INDEX_7 7
#define INDEX_8 8
#define INDEX_9 9
#define MOV_8 8
#define MOV_16 16
#define MOV_24 24
INT32 app_main2(void);
int32_t EnableWifi(void);
int32_t DisableWifi(void);
int32_t Scan(void);
int32_t GetScanInfoList(WifiScanInfo *result, unsigned int *size);
int32_t AddDeviceConfig(const WifiDeviceConfig *config, int *result);
int32_t ConnectTo(int networkId);
int32_t RegisterWifiEvent_(WifiEvent *arg);
int32_t GetWifiConnectStatus(void);
void OnWifiConnectDevice(const char *wifi_name, const char *wifi_pwd);
static int32_t DeviceInit(struct HdfDeviceObject *object);
static int32_t DeviceBind(struct HdfDeviceObject *object);
static void DeviceRelease(struct HdfDeviceObject *object);
static const struct HdfDriverEntry WIFI_DriverEntry = {
.moduleVersion = 1,
.moduleName = "HDF_WIFI_MODULE",
.Bind = DeviceBind,
.Init = DeviceInit,
.Release = DeviceRelease,
};
HDF_INIT(WIFI_DriverEntry);
typedef struct {
uint32_t mode;
} DeviceInfo_t;
static const DeviceInfo_t DeviceInfoDefault = {
.mode = -1,
};
// static const char TAG[]={"WIFI_STA"};
int g_wifiState = 0;
static void Delay(uint32_t ms)
{
osDelay(ms * osKernelGetTickFreq() / TICK_COUNT);
}
/** Connection state change */
static void OnWifiConnectionChanged(int state, WifiLinkedInfo *info)
{
if (!info) {
return;
}
HDF_LOGE("%s , state = %d \r\n", __FUNCTION__, state);
g_wifiState = state;
}
static int print_ap_info(WifiScanInfo *ap_info, int max_num)
{
int index = -1;
for (unsigned int i = 0; i < max_num; ++i) {
HDF_LOGE("SSID\t\t%s\nRSSI\t\t%d\nfrequency\t%d\n", ap_info[i].ssid,
ap_info[i].rssi, ap_info[i].frequency);
HDF_LOGE("MAC \t\t%02X:%02X:%02X:%02X:%02X:%02X\n",
ap_info[i].bssid[INDEX_0], ap_info[i].bssid[INDEX_1],
ap_info[i].bssid[INDEX_2], ap_info[i].bssid[INDEX_3],
ap_info[i].bssid[INDEX_4], ap_info[i].bssid[INDEX_5]);
if (!strcmp((const char *)ap_info[i].ssid, "HUAWEIP40")) {
index = i;
}
}
return index;
}
static void OnWifiScanStateChanged(int state, int size)
{
int ret;
unsigned int maxi = size;
if (!state || (size <= 0)) {
return;
}
WifiScanInfo *ap_info = (WifiScanInfo *)malloc(sizeof(WifiScanInfo) * size);
if (ap_info == NULL) {
HDF_LOGE("malloc WifiScanInfo fail!\r\n");
return;
}
WifiErrorCode error = GetScanInfoList(ap_info, &maxi);
if (error != WIFI_SUCCESS || maxi == 0) {
HDF_LOGE("WIFI NOT SUCCESS in GetScanInfoList\r\n");
return;
}
WifiDeviceConfig config = {0};
int index = print_ap_info(ap_info, maxi);
if (index >= 0) {
int netId = 0;
HDF_LOGE("connect:%s\n", ap_info[index].ssid);
config.freq = ap_info[index].frequency;
config.securityType = ap_info[index].securityType;
config.wapiPskType = WIFI_PSK_TYPE_ASCII;
ret = memcpy_s(config.bssid, sizeof(config.bssid), ap_info[index].bssid, WIFI_MAC_LEN);
if (ret != 0) {
HDF_LOGE("memcpy_s bssid fail!\r\n");
return HDF_FAILURE;
}
ret = strcpy_s(config.ssid, sizeof(config.bssid), ap_info[index].ssid);
if (ret != 0) {
HDF_LOGE("strcpy_s ssid fail!\r\n");
return HDF_FAILURE;
}
free(ap_info);
ret = strcpy_s(config.preSharedKey, sizeof(config.preSharedKey), "houpengfei8");
if (ret != 0) {
HDF_LOGE("strcpy_s password fail!\r\n");
return HDF_FAILURE;
}
AddDeviceConfig(&config, &netId);
ConnectTo(netId);
} else {
free(ap_info);
}
}
/** Hotspot state change */
void OnHotspotStateChanged(int state)
{
HDF_LOGE("%s state = %X\r\n", __FUNCTION__, state);
}
/** Station connected */
void OnHotspotStaJoin(StationInfo *info)
{
if (!info) {
HDF_LOGE("%s info=NULL\n", __FUNCTION__);
return;
}
HDF_LOGE("%s name:%s mac:%02X:%02X:%02X:%02X:%02X:%02X ip:%d.%d.%d.%d connect:%d\r\n", __FUNCTION__, info->name,
info->macAddress[INDEX_0], info->macAddress[INDEX_1], info->macAddress[INDEX_2],
info->macAddress[INDEX_3], info->macAddress[INDEX_4], info->macAddress[INDEX_5],
(info->ipAddress >> MOV_24) & 0xFF, (info->ipAddress >> MOV_16) & 0xFF,
(info->ipAddress >> MOV_8) & 0xFF, (info->ipAddress) & 0xFF,
info->disconnectedReason);
}
/** Station disconnected */
void OnHotspotStaLeave(StationInfo *info)
{
if (!info) {
HDF_LOGE("%s info=NULL\n", __FUNCTION__);
return;
}
HDF_LOGE("%s name:%s mac:%02X:%02X:%02X:%02X:%02X:%02X ip:%d.%d.%d.%d connect:%d\r\n", __FUNCTION__, info->name,
info->macAddress[INDEX_0], info->macAddress[INDEX_1], info->macAddress[INDEX_2],
info->macAddress[INDEX_3], info->macAddress[INDEX_4], info->macAddress[INDEX_5],
(info->ipAddress >> MOV_24) & 0xFF, (info->ipAddress >> MOV_16) & 0xFF,
(info->ipAddress >> MOV_8) & 0xFF, (info->ipAddress) & 0xFF, info->disconnectedReason);
}
/**
* @brief WiFi连接程序,CMSIS线程回调函数
* @param arg 线程参数
*/
static void IotWifiConnectTask(void)
{
WifiEvent eventListener = {
.OnWifiConnectionChanged = OnWifiConnectionChanged,
.OnWifiScanStateChanged = OnWifiScanStateChanged,
.OnHotspotStateChanged = OnHotspotStateChanged,
.OnHotspotStaJoin = OnHotspotStaJoin,
.OnHotspotStaLeave = OnHotspotStaLeave};
g_wifiState = 0;
RegisterWifiEvent_(&eventListener);
WifiErrorCode error = EnableWifi();
HDF_LOGE("EnableWifi errCode: %d\r\n", error);
if (error != WIFI_SUCCESS) {
return;
}
error = Scan();
HDF_LOGE("ScanWifi errCode: %d\r\n", error);
if (error != WIFI_SUCCESS) {
return;
}
OnWifiConnectDevice("HUAWEIP40", "houpengfei8");
HDF_LOGE("GetWifiConnectStatus: %d\r\n", GetWifiConnectStatus());
}
static int32_t DeviceInit(struct HdfDeviceObject *object)
{
DeviceInfo_t *dev;
int ret;
if (object == NULL) {
return HDF_FAILURE;
}
dev = (DeviceInfo_t *)OsalMemAlloc(sizeof(DeviceInfo_t));
if (dev == NULL) {
HDF_LOGE("%s.malloc\n", WIFI_DriverEntry.moduleName);
return HDF_DEV_ERR_NO_MEMORY;
}
object->priv = (void *)dev;
ret = memcpy_s(dev, sizeof(DeviceInfoDefault), &DeviceInfoDefault, sizeof(DeviceInfoDefault));
if (ret != 0) {
HDF_LOGE("memcpy_s DeviceInfoDefault fail!\r\n");
return HDF_FAILURE;
}
if (object->property) {
const struct DeviceResourceNode *node = object->property;
struct DeviceResourceIface *resource = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
resource->GetUint32(node, "mode", &dev->mode, -1);
}
return HDF_SUCCESS;
}
static int32_t DeviceBind(struct HdfDeviceObject *object)
{
return HDF_SUCCESS;
}
static void DeviceRelease(struct HdfDeviceObject *object)
{
if (!object) {
return;
}
if (object->priv) {
DeviceInfo_t *dev = (DeviceInfo_t *)object->priv;
OsalMemFree(object->priv);
}
object->priv = NULL;
}
+33
View File
@@ -0,0 +1,33 @@
# Copyright (c) 2022 OpenValley Digital Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//kernel/liteos_m/liteos.gni")
module_name = get_path_info(rebase_path("."), "name")
# module_switch = defined(LOSCFG_FS_LITTLEFS)
kernel_module(module_name) {
sources = [
"driver/hm_sys.c",
"driver/hal_watchdog.c",
"libc/syscalls.c",
"libc/log.c",
]
include_dirs = [
"//utils/native/lite/memory/include",
"//base/hiviewdfx/hiview_lite",
"//base/hiviewdfx/hilog_lite/frameworks/mini",
"//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite",
"//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr"
]
deps = [ "driver/wifi_lite" ]
}
+106
View File
@@ -0,0 +1,106 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdint.h>
#define RWDT_PROTECT_KEY 0x50d83aa1
#define RWDT_PROTECT 0x3ff480a4
#define RWDT_CFG0 0x3ff4808c
#define RWDT_CFG0_VALUE ((1 << 10) | (7 << 11) | (3 << 28) | (1 << 31))
#define RWDT_CFG1 0x3ff48090
#define RWDT_FEED 0x3ff480a0
#define RWDT_TICKS_TYPE 0x3ff48070
#define RWDT_WOG_VALUE (1 << 31)
#define RWDT_IS_RUN_BIT (1 << 31)
#define OFFSET_30 30
#define BIT_3 3
#define SLOW_CK_TICKS (150 * 1000)
#define XTAL_32K_TICKS (32768)
#define CK8M_D256_OUT_CK_TICKS (8 * 1000 * 1000 / 256)
static uint32_t GetRwdtTicksType(void)
{
volatile uint32_t *ptr = RWDT_TICKS_TYPE;
return (((*ptr) >> OFFSET_30) & BIT_3);
}
static void RWDT_WOG(void)
{
*(volatile uint32_t *)RWDT_FEED = RWDT_WOG_VALUE;
}
static uint32_t RWDT_IS_RUN(void)
{
return (*(volatile uint32_t *)RWDT_CFG0) & RWDT_IS_RUN_BIT;
}
void WdtEnable(void)
{
uint32_t ticks;
if (RWDT_IS_RUN()) {
return;
}
switch (GetRwdtTicksType()) {
case 1:
ticks = XTAL_32K_TICKS;
break; // XTAL_32K
case 2:
ticks = CK8M_D256_OUT_CK_TICKS;
break; // CK8M_D256_OUT
default:
ticks = SLOW_CK_TICKS;
break; // SLOW_CK
}
*(volatile uint32_t *)RWDT_PROTECT = RWDT_PROTECT_KEY;
RWDT_WOG();
*(volatile uint32_t *)RWDT_CFG0 = RWDT_CFG0_VALUE;
*(volatile uint32_t *)RWDT_CFG1 = 5 * ticks; // 最大超时时间 4G / (150K 或 32768 或 8M/256)
*(volatile uint32_t *)RWDT_PROTECT = 0;
}
void WdtDisable(void)
{
if (!RWDT_IS_RUN()) {
return;
}
*(volatile uint32_t *)RWDT_PROTECT = RWDT_PROTECT_KEY;
RWDT_WOG();
*(volatile uint32_t *)RWDT_CFG0 = 0;
*(volatile uint32_t *)RWDT_PROTECT = 0;
}
void WdtFeed(void)
{
*(volatile uint32_t *)RWDT_PROTECT = RWDT_PROTECT_KEY;
RWDT_WOG();
*(volatile uint32_t *)RWDT_PROTECT = 0;
}
void IoTWatchDogEnable(void)
{
WdtEnable();
}
void IoTWatchDogKick(void)
{
WdtFeed();
}
void IoTWatchDogDisable(void)
{
WdtDisable();
}
+30
View File
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "los_memory.h"
#include "ohos_mem_pool.h"
/**
* @brief implement for ohos_mem_pool.h
*/
void *OhosMalloc(MemType type, uint32 size)
{
return LOS_MemAlloc(OS_SYS_MEM_ADDR, size);
}
void OhosFree(void *ptr)
{
LOS_MemFree(OS_SYS_MEM_ADDR, ptr);
}
+57
View File
@@ -0,0 +1,57 @@
# Copyright (c) 2022 OpenValley Digital Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//kernel/liteos_m/liteos.gni")
module_switch = true
# defined(LOSCFG_DRIVERS_HDF_PLATFORM_WIFI)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [
"wifi_device.c",
]
deps = [ "//foundation/communication/wifi_lite:wifi" ]
# include_dirs = [ "//kernel/liteos_m/components/net/lwip-2.1/porting/include" ]
# include_dirs += [ "//third_party/lwip/src/include" ]
ESP_SDK_PATH="//device/soc/espressif/esp32/components/"
include_dirs = [
"//foundation/communication/wifi_lite/interfaces/wifiservice",
ESP_SDK_PATH+"esp_wifi/include",
ESP_SDK_PATH+"esp_event/include",
ESP_SDK_PATH+"esp_netif/include",
ESP_SDK_PATH+"esp_eth/include",
ESP_SDK_PATH+"tcpip_adapter/include",
ESP_SDK_PATH+"lwip/include/apps",
# "//device/soc/espressif/esp32/components/lwip/include/apps",
# "//device/soc/espressif/esp32/components/lwip/include/apps/sntp",
# "//device/soc/espressif/esp32/components/lwip/lwip/src/include",
# "//device/soc/espressif/esp32/components/lwip/port/esp32/include",
# "//device/soc/espressif/esp32/components/lwip/port/esp32/include/arch",
# "//device/soc/espressif/esp32/components/esp_common/include",
# "//device/soc/espressif/esp32/components",
# "//device/soc/espressif/esp32/components/freertos/include",
# "//device/soc/espressif/esp32/components/freertos/port/xtensa/include",
# "//device/soc/espressif/esp32/components/xtensa/include",
# "//device/soc/espressif/esp32/components/xtensa/esp32/include",
# "//device/soc/espressif/esp32/components/esp_rom/include",
# "//device/soc/espressif/esp32/components/spi_flash/sim/stubs/esp_timer/include",
# "//device/soc/espressif/esp32/components/esp_system/include",
# "//device/soc/espressif/esp32/components/newlib/platform_include",
# "//device/soc/espressif/esp32/components/esp_hw_support/include",
# "//device/soc/espressif/esp32/components/hal/include",
# "//device/soc/espressif/esp32/components/soc/esp32/include",
# "//device/soc/espressif/esp32/components/hal/esp32/include",
# "//device/soc/espressif/esp32/components/soc/include",
# "//device/soc/espressif/esp32/components/heap/include",
]
}
+990
View File
@@ -0,0 +1,990 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "esp_wifi.h"
#include "cmsis_os2.h"
#include "esp_event.h"
#include "esp_event_legacy.h"
#include "los_memory.h"
#include "los_mux.h"
#include "los_task.h"
#include "lwip/err.h"
#include "lwip/sockets.h"
#include "lwip/tcpip.h"
#include "station_info.h"
#include "wifi_error_code.h"
#include "wifi_event.h"
#include "wifi_hotspot.h"
#include "wifi_linked_info.h"
#include "wifi_device.h"
#undef LOG
#undef LOGE
#define LOG
#define LOGE(fmt, ...) printf("Error %s%s." fmt "\r\n", TAG, __func__, ##__VA_ARGS__)
#define CHANNEL_80211B_ONLY 14
#define FREQ_OF_CHANNEL_1 2412
#define FREQ_OF_CHANNEL_80211B_ONLY 2484
#define WIFI_MIN_CHANNEL 1
#define WIFI_FREQ_INTERVAL 5
#define ESP_EXAMPLE_MAX_STA_CONN 4
#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 WIFI_ACTIVE 1
#define WIFI_NOT_ACTIVE 0
#define EPS_STR_LEN 4
#define DELAY_10_TICK 10
#define DELAY_30_TICK 30
#define DELAY_50_TICK 50
#define DELAY_LOOP_TIMES 50
#define MAX_INDEX 60
#define MUX_HANDLE_OFFSET 8
#define ERROR_ESP_WIFI_START (-103)
#define ERROR_NETIF_NULL (-8)
#define ERROR_REGISTER_FAIL (-9)
#define SCANING 0x50
typedef struct {
volatile uint8_t ip_ok;
volatile uint8_t scan_ok;
union {
uint8_t staStatus;
uint8_t apStatus;
};
WifiEvent *event[WIFI_MAX_EVENT_SIZE];
esp_netif_t *netif;
WifiDeviceConfig config[WIFI_MAX_CONFIG_SIZE];
HotspotConfig hotConfig[1];
UINT32 muxHandle;
esp_event_handler_instance_t eventHandle[2];
} DevWifiInfo_t;
static DevWifiInfo_t DevWifiInfo = {0};
static const char TAG[] = {"WifiLite."};
static const char NullBssid[WIFI_MAC_LEN] = {0, 0, 0, 0, 0, 0};
static void MEMCPY_S(void *dst, int dstSize, void *src, int srcSize)
{
if ((dst == NULL) || (src == NULL)) {
return;
}
int ret;
ret = memcpy_s(dst, src, (dstSize > srcSize) ? srcSize : dstSize);
if (ret != 0) {
LOGE("memcpy_s fail!!\n");
}
}
static void WifiLock(void)
{
if (!DevWifiInfo.muxHandle) {
UINT32 muxHandle = 0;
if (LOS_OK != LOS_MuxCreate(&muxHandle)) {
LOGE("LOS_MuxCreate");
return;
}
DevWifiInfo.muxHandle = muxHandle + MUX_HANDLE_OFFSET;
}
LOS_MuxPend(DevWifiInfo.muxHandle - MUX_HANDLE_OFFSET, LOS_WAIT_FOREVER);
}
static void WifiUnlock(void)
{
if (!DevWifiInfo.muxHandle)
return;
LOS_MuxPost(DevWifiInfo.muxHandle - MUX_HANDLE_OFFSET);
}
int IsWifiActive(void)
{
return ((DevWifiInfo.staStatus == WIFI_ACTIVE) ? WIFI_STA_ACTIVE : WIFI_STA_NOT_ACTIVE);
}
WifiErrorCode UnRegisterWifiEvent(const WifiEvent *event)
{
WifiErrorCode ret = ERROR_WIFI_UNKNOWN;
if (!event)
return ERROR_WIFI_INVALID_ARGS;
WifiLock();
for (unsigned i = 0; i < WIFI_MAX_EVENT_SIZE; i++) {
if (DevWifiInfo.event[i] == event) {
DevWifiInfo.event[i] = NULL;
ret = WIFI_SUCCESS;
break;
}
}
WifiUnlock();
return ret;
}
WifiErrorCode RegisterWifiEvent(WifiEvent *event)
{
WifiErrorCode ret = ERROR_WIFI_UNKNOWN;
if (event == NULL) {
return ERROR_WIFI_INVALID_ARGS;
}
WifiLock();
for (unsigned i = 0; i < WIFI_MAX_EVENT_SIZE; i++) {
if (DevWifiInfo.event[i] == event) {
ret = ERROR_WIFI_INVALID_ARGS;
break;
}
if (DevWifiInfo.event[i] == NULL) {
DevWifiInfo.event[i] = event;
ret = WIFI_SUCCESS;
break;
}
}
WifiUnlock();
return ret;
}
static unsigned int ChannelToFrequency(unsigned int channel)
{
if (channel <= 0) {
return 0;
}
if (channel == CHANNEL_80211B_ONLY) {
return FREQ_OF_CHANNEL_80211B_ONLY;
}
return (((channel - WIFI_MIN_CHANNEL) * WIFI_FREQ_INTERVAL) + FREQ_OF_CHANNEL_1);
}
static unsigned int FrequencyToChannel(unsigned int frequency)
{
if (frequency == FREQ_OF_CHANNEL_80211B_ONLY) {
return CHANNEL_80211B_ONLY;
}
if (frequency < FREQ_OF_CHANNEL_1) {
return 0;
}
return (frequency - FREQ_OF_CHANNEL_1) / WIFI_FREQ_INTERVAL + WIFI_MIN_CHANNEL;
}
/** Scan state change */
static void SendOnWifiScanStateChanged(DevWifiInfo_t *info, WifiEventState event, uint16_t size)
{
WifiEvent **pevent = info->event;
for (unsigned i = 0; i < WIFI_MAX_EVENT_SIZE; i++) {
if (pevent[i] == NULL) {
continue;
}
if (pevent[i]->OnWifiScanStateChanged == NULL) {
continue;
}
pevent[i]->OnWifiScanStateChanged(event, size);
}
}
/** Connection state change */
static void SendOnWifiConnectionChanged(DevWifiInfo_t *info, WifiEventState event, WifiLinkedInfo *linkInfo)
{
WifiEvent **pevent = info->event;
for (unsigned i = 0; i < WIFI_MAX_EVENT_SIZE; i++) {
if (pevent[i] == NULL) {
continue;
}
if (pevent[i]->OnWifiConnectionChanged == NULL) {
continue;
}
pevent[i]->OnWifiConnectionChanged(event, linkInfo);
}
}
/** Station connected */
static void SendOnHotspotStaJoin(DevWifiInfo_t *info, StationInfo *staInfo)
{
WifiEvent **pevent = info->event;
for (unsigned i = 0; i < WIFI_MAX_EVENT_SIZE; i++) {
if (pevent[i] == NULL) {
continue;
}
if (pevent[i]->OnHotspotStaJoin == NULL) {
continue;
}
pevent[i]->OnHotspotStaJoin(staInfo);
}
}
/** Station disconnected */
static void SendOnHotspotStaLeave(DevWifiInfo_t *info, StationInfo *staInfo)
{
WifiEvent **pevent = info->event;
for (unsigned i = 0; i < WIFI_MAX_EVENT_SIZE; i++) {
if (pevent[i] == NULL) {
continue;
}
if (pevent[i]->OnHotspotStaLeave == NULL) {
continue;
}
pevent[i]->OnHotspotStaLeave(staInfo);
}
}
/** Hotspot state change */
static void SendOnHotspotStateChanged(DevWifiInfo_t *info, WifiEventState event)
{
WifiEvent **pevent = info->event;
for (unsigned i = 0; i < WIFI_MAX_EVENT_SIZE; i++) {
if (pevent[i] == NULL) {
continue;
}
if (pevent[i]->OnHotspotStateChanged == NULL) {
continue;
}
pevent[i]->OnHotspotStateChanged(event);
}
}
static void event_got_ip_handler(void *arg, esp_event_base_t event_base,
int32_t event_id, void *event_data)
{
DevWifiInfo.ip_ok = 1;
}
static void wifi_event_scan_down_proc(void *event_data)
{
uint16_t size = 0;
DevWifiInfo.scan_ok = 1;
esp_wifi_scan_get_ap_num(&size);
SendOnWifiScanStateChanged(&DevWifiInfo, WIFI_STATE_AVALIABLE, size);
}
static void wifi_event_sta_connected_proc(void *event_data)
{
WifiLinkedInfo linkInfo = {0};
wifi_ap_record_t ap_info;
esp_wifi_sta_get_ap_info(&ap_info);
MEMCPY_S(&linkInfo.ssid, sizeof(linkInfo.ssid), ap_info.ssid, sizeof(ap_info.ssid));
MEMCPY_S(&linkInfo.bssid, sizeof(linkInfo.bssid), ap_info.bssid, sizeof(ap_info.bssid));
linkInfo.rssi = ap_info.rssi;
linkInfo.connState = WIFI_CONNECTED;
linkInfo.frequency = ChannelToFrequency(ap_info.primary);
SendOnWifiConnectionChanged(&DevWifiInfo, WIFI_STATE_AVALIABLE, &linkInfo);
}
static void wifi_event_sta_disconnected_proc(void *event_data)
{
WifiLinkedInfo linkInfo = {0};
wifi_event_sta_disconnected_t *disconnected = (wifi_event_sta_disconnected_t *)event_data;
MEMCPY_S(&linkInfo.ssid, sizeof(linkInfo.ssid), disconnected->ssid, sizeof(disconnected->ssid));
MEMCPY_S(&linkInfo.bssid, sizeof(linkInfo.bssid), disconnected->bssid, sizeof(disconnected->bssid));
linkInfo.disconnectedReason = disconnected->reason;
linkInfo.connState = WIFI_DISCONNECTED;
SendOnWifiConnectionChanged(&DevWifiInfo, WIFI_STATE_NOT_AVALIABLE, &linkInfo);
}
static void wifi_event_ap_connected_proc(void *event_data)
{
StationInfo staInfo = {0};
wifi_event_ap_staconnected_t *connect_event = (wifi_event_ap_staconnected_t *)event_data;
MEMCPY_S(&staInfo.macAddress, sizeof(staInfo.macAddress), connect_event->mac, sizeof(connect_event->mac));
SendOnHotspotStaJoin(&DevWifiInfo, &staInfo);
}
static void wifi_event_ap_disconnected_proc(void *event_data)
{
StationInfo staInfo = {0};
wifi_event_ap_stadisconnected_t *disconnect_event = (wifi_event_ap_stadisconnected_t *)event_data;
MEMCPY_S(&staInfo.macAddress, sizeof(staInfo.macAddress),
disconnect_event->mac, sizeof(disconnect_event->mac));
staInfo.disconnectedReason = WIFI_REASON_UNSPECIFIED;
SendOnHotspotStaLeave(&DevWifiInfo, &staInfo);
}
static void wifi_event_ap_start_proc(void *event_data)
{
SendOnHotspotStateChanged(&DevWifiInfo, WIFI_STATE_AVALIABLE);
}
static void event_handler(void *arg, esp_event_base_t event_base,
int32_t event_id, void *event_data)
{
LOG("event=%d", event_id);
switch (event_id) {
case WIFI_EVENT_SCAN_DONE:
wifi_event_scan_down_proc(event_data);
break;
case WIFI_EVENT_STA_CONNECTED:
wifi_event_sta_connected_proc(event_data);
break;
case WIFI_EVENT_STA_DISCONNECTED:
wifi_event_sta_disconnected_proc(event_data);
break;
case WIFI_EVENT_AP_STACONNECTED:
wifi_event_ap_connected_proc(event_data);
break;
case WIFI_EVENT_AP_STADISCONNECTED:
wifi_event_ap_disconnected_proc(event_data);
break;
case WIFI_EVENT_AP_START:
wifi_event_ap_start_proc(event_data);
break;
default:
break;
}
}
int DeviceWifiStart(void)
{
esp_err_t err;
DevWifiInfo_t *info = &DevWifiInfo;
memset_s(info, sizeof(DevWifiInfo_t), 0, sizeof(*info));
for (unsigned i = 0; i < WIFI_MAX_CONFIG_SIZE; i++) {
info->config[i].netId = WIFI_CONFIG_INVALID;
}
err = esp_netif_init();
if (err != ESP_OK) {
LOGE("esp_netif_init.err=0x%X", err);
}
err = esp_event_loop_create_default();
if (err != ESP_OK) {
LOGE("esp_event_loop_create_default.err=0x%X", err);
}
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
cfg.nvs_enable = 0;
err = esp_wifi_init(&cfg);
if (err != ESP_OK) {
LOGE("esp_wifi_init.err=0x%X", err);
}
esp_wifi_set_storage(WIFI_STORAGE_RAM);
return 0;
}
static void UnregisterEspEvent(void)
{
DevWifiInfo_t *info = &DevWifiInfo;
WifiLock();
DevWifiInfo.ip_ok = 0;
DevWifiInfo.scan_ok = 0;
if (info->eventHandle[0] != NULL) {
esp_event_handler_instance_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, info->eventHandle[0]);
info->eventHandle[0] = NULL;
}
if (info->eventHandle[1] != NULL) {
esp_event_handler_instance_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, info->eventHandle[1]);
info->eventHandle[1] = NULL;
}
if (info->netif != NULL) {
esp_netif_destroy(info->netif);
info->netif = NULL;
}
WifiUnlock();
}
static int RegisterEspEvent(int apMode)
{
esp_err_t err;
DevWifiInfo_t *info = &DevWifiInfo;
WifiLock();
if (apMode) {
info->netif = esp_netif_create_default_wifi_ap();
} else {
info->netif = esp_netif_create_default_wifi_sta();
}
err = esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, event_handler,
NULL, &info->eventHandle[0]);
if (err != ESP_OK) {
LOGE("WIFI_EVENT err=0x%X", err);
}
err = esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, event_got_ip_handler,
NULL, &info->eventHandle[1]);
if (err != ESP_OK) {
LOGE("IP_EVENT err=0x%X", err);
}
err = esp_wifi_set_storage(WIFI_STORAGE_RAM);
if (err != ESP_OK) {
LOGE("set_storage err=0x%X", err);
}
err = esp_wifi_set_mode(apMode ? WIFI_MODE_AP : WIFI_MODE_STA);
if (err != ESP_OK) {
LOGE("set_mode(%d) err=0x%X", apMode, err);
}
WifiUnlock();
return (info->netif == NULL) ? ERROR_NETIF_NULL : (err ? ERROR_REGISTER_FAIL : 0);
}
WifiErrorCode EnableWifi(void)
{
DevWifiInfo_t *info = &DevWifiInfo;
int err = 0;
if (info->staStatus == WIFI_ACTIVE) {
return ERROR_WIFI_BUSY;
}
UnregisterEspEvent();
err = RegisterEspEvent(0);
if (err == 0) {
WifiLock();
while (1) {
if (esp_wifi_start() != ESP_OK) {
err = ERROR_ESP_WIFI_START;
break;
}
info->staStatus = WIFI_ACTIVE;
break;
}
WifiUnlock();
}
if (err) {
LOGE("err=%d", err);
return ERROR_WIFI_IFACE_INVALID;
}
return WIFI_SUCCESS;
}
WifiErrorCode DisableWifi(void)
{
DevWifiInfo_t *info = &DevWifiInfo;
if (info->staStatus == WIFI_NOT_ACTIVE) {
return ERROR_WIFI_NOT_STARTED;
}
WifiLock();
info->staStatus = WIFI_NOT_ACTIVE;
esp_wifi_disconnect();
UnregisterEspEvent();
esp_wifi_stop();
WifiUnlock();
return WIFI_SUCCESS;
}
WifiErrorCode Scan(void)
{
wifi_scan_config_t config = {0};
DevWifiInfo_t *info = &DevWifiInfo;
WifiDeviceConfig *pconfig;
if (info->staStatus != WIFI_ACTIVE) {
return ERROR_WIFI_NOT_STARTED;
}
SendOnWifiScanStateChanged(info, WIFI_STATE_NOT_AVALIABLE, 0);
esp_wifi_scan_stop();
if (esp_wifi_scan_start(NULL, false) != ESP_OK) {
return ERROR_WIFI_UNKNOWN;
}
info->scan_ok = SCANING;
return WIFI_SUCCESS;
}
WifiErrorCode AddDeviceConfig(const WifiDeviceConfig *config, int *result)
{
DevWifiInfo_t *info = &DevWifiInfo;
if (!config)
return ERROR_WIFI_INVALID_ARGS;
WifiLock();
for (unsigned i = 0; i < WIFI_MAX_CONFIG_SIZE; i++) {
if (info->config[i].netId != i) {
MEMCPY_S(&info->config[i], sizeof(WifiDeviceConfig), config, sizeof(WifiDeviceConfig));
info->config[i].netId = i;
WifiUnlock();
if (result) {
*result = i;
}
return WIFI_SUCCESS;
}
}
WifiUnlock();
if (result) {
*result = 0;
}
return ERROR_WIFI_BUSY;
}
WifiErrorCode GetDeviceConfigs(WifiDeviceConfig *result, unsigned int *size)
{
unsigned retIndex = 0, maxIndex;
DevWifiInfo_t *info = &DevWifiInfo;
if ((!result) || (!size))
return ERROR_WIFI_INVALID_ARGS;
if (!*size)
return ERROR_WIFI_INVALID_ARGS;
maxIndex = *size;
WifiLock();
for (unsigned i = 0; i < WIFI_MAX_CONFIG_SIZE; i++) {
if (info->config[i].netId != i) {
continue;
}
MEMCPY_S(&result[retIndex++], sizeof(WifiDeviceConfig), &info->config[i], sizeof(WifiDeviceConfig));
if (maxIndex < retIndex) {
break;
}
}
WifiUnlock();
if (retIndex == 0) {
return ERROR_WIFI_NOT_AVAILABLE;
}
*size = retIndex;
return WIFI_SUCCESS;
}
WifiErrorCode RemoveDevice(int networkId)
{
DevWifiInfo_t *info = &DevWifiInfo;
if ((networkId >= WIFI_MAX_CONFIG_SIZE) || (networkId < 0)) {
return ERROR_WIFI_INVALID_ARGS;
}
WifiLock();
memset_s(&info->config[networkId], sizeof(WifiDeviceConfig), 0, sizeof(WifiDeviceConfig));
info->config[networkId].netId = WIFI_CONFIG_INVALID;
WifiUnlock();
return WIFI_SUCCESS;
}
WifiErrorCode GetDeviceMacAddress(unsigned char *result)
{
if (!result) {
return ERROR_WIFI_INVALID_ARGS;
}
if (esp_wifi_get_mac(WIFI_IF_STA, (uint8_t *)result) != ESP_OK) {
return ERROR_WIFI_UNKNOWN;
}
return WIFI_SUCCESS;
}
static WifiSecurityType ESPSecToHoSec(wifi_auth_mode_t mode)
{
switch (mode) {
case WIFI_AUTH_OPEN:
return WIFI_SEC_TYPE_OPEN;
case WIFI_AUTH_WEP:
return WIFI_SEC_TYPE_WEP;
case WIFI_AUTH_WPA_PSK:
case WIFI_AUTH_WPA2_PSK:
case WIFI_AUTH_WPA_WPA2_PSK:
return WIFI_SEC_TYPE_PSK;
case WIFI_AUTH_WPA3_PSK:
case WIFI_AUTH_WPA2_WPA3_PSK:
return WIFI_SEC_TYPE_SAE;
default:
return WIFI_SEC_TYPE_INVALID;
}
}
static wifi_auth_mode_t HoSecToESPSec(WifiSecurityType type)
{
switch (type) {
case WIFI_SEC_TYPE_OPEN:
return WIFI_SEC_TYPE_OPEN;
case WIFI_SEC_TYPE_WEP:
return WIFI_SEC_TYPE_WEP;
case WIFI_SEC_TYPE_PSK:
return WIFI_AUTH_WPA_PSK;
case WIFI_SEC_TYPE_SAE:
return WIFI_AUTH_WPA3_PSK;
default:
return WIFI_AUTH_MAX;
}
}
static int GetScanInfoListNext(WifiScanInfo *result, uint16_t ap_count, unsigned int *size)
{
DevWifiInfo_t *info = &DevWifiInfo;
wifi_ap_record_t *ap_info;
unsigned int maxi = *size;
info->scan_ok = 0x51;
esp_wifi_scan_get_ap_num(&ap_count);
if (maxi > ap_count) {
*size = maxi = ap_count;
}
if (maxi == 0) {
return WIFI_SUCCESS;
}
ap_info = (wifi_ap_record_t *)LOS_MemAlloc(OS_SYS_MEM_ADDR, sizeof(wifi_ap_record_t) * maxi);
if (!ap_info) {
return ERROR_WIFI_UNKNOWN;
}
for (int i = 0; i < maxi; ++i) {
MEMCPY_S(result[i].ssid, sizeof(result[i].ssid), ap_info[i].ssid, sizeof(ap_info[i].ssid));
MEMCPY_S(result[i].bssid, sizeof(result[i].bssid), ap_info[i].bssid, sizeof(ap_info[i].bssid));
result[i].securityType = ESPSecToHoSec(ap_info[i].authmode);
result[i].rssi = ap_info[i].rssi;
result[i].band = 0;
result[i].frequency = ChannelToFrequency(ap_info[i].primary);
}
LOS_MemFree(OS_SYS_MEM_ADDR, ap_info);
return WIFI_SUCCESS;
}
WifiErrorCode GetScanInfoList(WifiScanInfo *result, unsigned int *size)
{
DevWifiInfo_t *info = &DevWifiInfo;
uint16_t ap_count = 0;
unsigned int i, maxi;
if ((!result) || (!size) || (*size == 0)) {
return ERROR_WIFI_INVALID_ARGS;
}
if (info->staStatus != WIFI_ACTIVE) {
return ERROR_WIFI_NOT_STARTED;
}
if (info->scan_ok == SCANING) {
maxi = MAX_INDEX;
for (i = 0; (i < maxi) && (info->scan_ok == SCANING); ++i) {
LOS_Msleep(DELAY_50_TICK);
}
if (i >= maxi) {
return ERROR_WIFI_BUSY;
}
}
if (info->scan_ok != 1) {
wifi_ap_record_t t_info[1];
ap_count = 1;
esp_wifi_scan_get_ap_records(&ap_count, t_info);
*size = 0;
return WIFI_SUCCESS;
}
return GetScanInfoListNext(result, ap_count, size);
}
WifiErrorCode ConnectTo(int networkId)
{
WifiDeviceConfig *pconfig;
DevWifiInfo_t *info = &DevWifiInfo;
if ((networkId >= WIFI_MAX_CONFIG_SIZE) || (networkId < 0)) {
return ERROR_WIFI_INVALID_ARGS;
}
if (info->staStatus != WIFI_ACTIVE)
return ERROR_WIFI_NOT_AVAILABLE;
WifiLock();
pconfig = &info->config[networkId];
if (pconfig->netId != networkId) {
WifiUnlock();
return ERROR_WIFI_NOT_AVAILABLE;
}
info->ip_ok = 0;
WifiUnlock();
wifi_config_t assocReq = {0};
assocReq.sta.threshold.authmode = HoSecToESPSec(pconfig->securityType);
MEMCPY_S(assocReq.sta.ssid, sizeof(assocReq.sta.ssid), pconfig->ssid, sizeof(pconfig->ssid));
MEMCPY_S(assocReq.sta.password, sizeof(assocReq.sta.password),
pconfig->preSharedKey, sizeof(pconfig->preSharedKey));
MEMCPY_S(assocReq.sta.bssid, sizeof(assocReq.sta.bssid), pconfig->bssid, sizeof(pconfig->bssid));
assocReq.sta.channel = FrequencyToChannel(pconfig->freq);
assocReq.sta.pmf_cfg.capable = true;
assocReq.sta.pmf_cfg.required = false;
esp_wifi_set_config(WIFI_IF_STA, &assocReq);
if (esp_wifi_connect() != ESP_OK) {
return ERROR_WIFI_UNKNOWN;
}
for (int i = 0; i < DELAY_LOOP_TIMES; ++i) {
if (info->ip_ok == 1) {
break;
}
LOS_Msleep(DELAY_50_TICK);
}
return WIFI_SUCCESS;
}
WifiErrorCode Disconnect(void)
{
if (esp_wifi_disconnect() != ESP_OK) {
return ERROR_WIFI_UNKNOWN;
}
return WIFI_SUCCESS;
}
WifiErrorCode GetLinkedInfo(WifiLinkedInfo *result)
{
DevWifiInfo_t *info = &DevWifiInfo;
esp_err_t err;
if (!result) {
return ERROR_WIFI_INVALID_ARGS;
}
memset_s(result, sizeof(WifiLinkedInfo), 0, sizeof(WifiLinkedInfo));
if (info->staStatus != WIFI_ACTIVE)
return ERROR_WIFI_NOT_STARTED;
wifi_ap_record_t ap_info = {0};
if (esp_wifi_sta_get_ap_info(&ap_info) != ESP_OK) {
result->connState = WIFI_DISCONNECTED;
return ERROR_WIFI_UNKNOWN;
}
MEMCPY_S(result->ssid, sizeof(result->ssid), ap_info.ssid, sizeof(ap_info.ssid));
MEMCPY_S(result->bssid, sizeof(result->bssid), ap_info.bssid, sizeof(ap_info.bssid));
result->connState = WIFI_CONNECTED;
result->rssi = ap_info.rssi;
esp_netif_ip_info_t ip_info;
err = esp_netif_get_ip_info(info->netif, &ip_info);
if (err != ESP_OK) {
LOGE("esp_netif_get_ip_info.err = %d", err);
return ERROR_WIFI_UNKNOWN;
}
result->ipAddress = ip_info.ip.addr;
return WIFI_SUCCESS;
}
int IsHotspotActive(void)
{
return ((DevWifiInfo.staStatus == WIFI_ACTIVE) ? WIFI_HOTSPOT_ACTIVE : WIFI_HOTSPOT_NOT_ACTIVE);
}
WifiErrorCode DisableHotspot(void)
{
return DisableWifi();
}
WifiErrorCode GetStationList(StationInfo *result, unsigned int *size)
{
if ((!result) || (!size))
return ERROR_WIFI_INVALID_ARGS;
if (!*size)
return ERROR_WIFI_INVALID_ARGS;
wifi_sta_list_t wifi_sta_list = {0};
unsigned int staNum = 0;
esp_err_t ret = esp_wifi_ap_get_sta_list(&wifi_sta_list);
if (ret != ESP_OK) {
LOGE("esp_wifi_ap_get_sta_list.err=0x%X", ret);
return ERROR_WIFI_NOT_AVAILABLE;
}
staNum = wifi_sta_list.num;
if (*size < staNum) {
staNum = *size;
}
memset_s(result, (sizeof(result[0]) * staNum), 0, sizeof(result[0]) * staNum);
for (unsigned int i = 0; i < staNum; i++) {
MEMCPY_S(result[i].macAddress, sizeof(result[i].macAddress),
wifi_sta_list.sta[i].mac, sizeof(wifi_sta_list.sta[i].mac));
}
return WIFI_SUCCESS;
}
WifiErrorCode SetBand(int band)
{
DevWifiInfo_t *info = &DevWifiInfo;
if (band != HOTSPOT_BAND_TYPE_2G) {
return ERROR_WIFI_NOT_SUPPORTED;
}
info->hotConfig[0].band = band;
return WIFI_SUCCESS;
}
WifiErrorCode GetBand(int *result)
{
DevWifiInfo_t *info = &DevWifiInfo;
if (result == NULL) {
return ERROR_WIFI_INVALID_ARGS;
}
if (info->hotConfig[0].band == 0) {
return ERROR_WIFI_NOT_AVAILABLE;
}
*result = (int)info->hotConfig[0].band;
return WIFI_SUCCESS;
}
WifiErrorCode SetHotspotConfig(const HotspotConfig *config)
{
DevWifiInfo_t *info = &DevWifiInfo;
if (!config) {
return ERROR_WIFI_INVALID_ARGS;
}
WifiLock();
MEMCPY_S(&info->hotConfig[0], sizeof(HotspotConfig), config, sizeof(HotspotConfig));
WifiUnlock();
return WIFI_SUCCESS;
}
WifiErrorCode GetHotspotConfig(HotspotConfig *result)
{
DevWifiInfo_t *info = &DevWifiInfo;
if (result == NULL) {
return ERROR_WIFI_INVALID_ARGS;
}
WifiLock();
MEMCPY_S(result, sizeof(HotspotConfig), &info->hotConfig[0], sizeof(HotspotConfig));
WifiUnlock();
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 EnableHotspot(void)
{
int err;
DevWifiInfo_t *info = &DevWifiInfo;
if (info->apStatus == WIFI_ACTIVE) {
return ERROR_WIFI_BUSY;
}
UnregisterEspEvent();
err = RegisterEspEvent(1);
if (err) {
LOGE("esp_wifi_start.err=0x%X", err);
return ERROR_WIFI_INVALID_ARGS;
}
WifiLock();
wifi_config_t wifi_config = {0};
HotspotConfig *hotConfig = &info->hotConfig[0];
wifi_config.ap.channel = HOTSPOT_DEFAULT_CHANNEL;
if (hotConfig->channelNum) {
wifi_config.ap.channel = hotConfig->channelNum;
}
wifi_config.ap.authmode = HoSecToESPSec(hotConfig->securityType);
wifi_config.ap.max_connection = ESP_EXAMPLE_MAX_STA_CONN;
MEMCPY_S(wifi_config.ap.ssid, sizeof(wifi_config.ap.ssid), hotConfig->ssid, sizeof(hotConfig->ssid));
MEMCPY_S(wifi_config.ap.password, sizeof(wifi_config.ap.password),
hotConfig->preSharedKey, sizeof(hotConfig->preSharedKey));
wifi_config.ap.ssid_len = (uint8_t)strlen((const char *)wifi_config.ap.ssid);
if ((uint8_t)strlen((const char *)wifi_config.ap.password) == 0) {
wifi_config.ap.authmode = WIFI_AUTH_OPEN;
}
info->ip_ok = 0;
esp_wifi_set_config(WIFI_IF_AP, &wifi_config);
esp_err_t ret = esp_wifi_start();
if (ret != ESP_OK) {
LOGE("esp_wifi_start.err=0x%X", ret);
WifiUnlock();
return ERROR_WIFI_BUSY;
}
info->staStatus = WIFI_ACTIVE;
WifiUnlock();
LOS_Msleep(DELAY_10_TICK);
for (int i = 0; i < DELAY_LOOP_TIMES; ++i) {
if (info->ip_ok == 1) {
break;
}
LOS_Msleep(DELAY_30_TICK);
}
return WIFI_SUCCESS;
}
WifiErrorCode AdvanceScan(WifiScanParams *params)
{
DevWifiInfo_t *info = &DevWifiInfo;
if (params == NULL) {
return ERROR_WIFI_UNKNOWN;
}
if (info->staStatus != WIFI_ACTIVE) {
return ERROR_WIFI_NOT_STARTED;
}
SendOnWifiScanStateChanged(info, WIFI_STATE_NOT_AVALIABLE, 0);
wifi_scan_config_t config = {0};
if (params->scanType == WIFI_FREQ_SCAN) {
if (params->freqs <= 0) {
return ERROR_WIFI_UNKNOWN;
}
config.channel = FrequencyToChannel(params->freqs);
} else if (params->scanType == WIFI_SSID_SCAN) {
if (params->ssidLen == 0) {
return ERROR_WIFI_UNKNOWN;
}
config.ssid = (uint8_t *)params->ssid;
} else if (params->scanType == WIFI_BSSID_SCAN) {
if (!memcmp(NullBssid, params->bssid, WIFI_MAC_LEN)) {
return ERROR_WIFI_UNKNOWN;
}
config.bssid = (uint8_t *)params->bssid;
}
config.show_hidden = false;
config.scan_type = WIFI_SCAN_TYPE_ACTIVE;
config.scan_time.active.min = 0;
config.scan_time.active.max = 0;
config.scan_time.passive = 0;
esp_wifi_scan_stop();
if (esp_wifi_scan_start(&config, false) != ESP_OK) {
return ERROR_WIFI_BUSY;
}
info->scan_ok = SCANING;
return WIFI_SUCCESS;
}
int GetHotspotChannel(void)
{
DevWifiInfo_t *info = &DevWifiInfo;
if (info->apStatus != WIFI_ACTIVE) {
return ERROR_WIFI_NOT_STARTED;
}
wifi_config_t wifi_cfg = {0};
esp_err_t ret = esp_wifi_get_config(WIFI_IF_AP, &wifi_cfg);
if (ret != ESP_OK) {
return ERROR_WIFI_UNKNOWN;
}
return wifi_cfg.ap.channel;
}
WifiErrorCode GetHotspotInterfaceName(char *result, int size)
{
DevWifiInfo_t *info = &DevWifiInfo;
if (info->apStatus != WIFI_ACTIVE) {
return ERROR_WIFI_NOT_STARTED;
}
MEMCPY_S(result, size, "esp", EPS_STR_LEN);
return WIFI_SUCCESS;
}
+33
View File
@@ -0,0 +1,33 @@
# Copyright (c) 2022 OpenValley Digital Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/lite/config/component/lite_component.gni")
import("//build/lite/ndk/ndk.gni")
lite_library("hal_iothardware") {
target_type = "static_library"
sources = [
"hal_iot_flash.c",
"hal_iot_gpio.c",
"hal_iot_i2c.c",
"hal_iot_pwm.c",
"hal_iot_uart.c",
"hal_iot_watchdog.c",
"hal_lowpower.c",
"hal_reset.c",
]
include_dirs = [
"//base/iot_hardware/peripheral/interfaces/kits",
"//device/soc/espressif/esp32/components/esp_ringbuf/include",
]
}
@@ -0,0 +1,122 @@
// Copyright 2022 Espressif Systems (Shanghai) PTE 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.
/****************************************************************************
* Included Files
****************************************************************************/
#include "iot_errno.h"
#include "iot_flash.h"
#include "esp_err.h"
#include "esp_spi_flash.h"
#define FLASH_WAIT_FOREVER 0xFFFFFFFF
#define FLASH_SECTOR_SIZE (4096)
static uint32_t ESPErrToHoErr(esp_err_t ret)
{
if (ret == ESP_OK) {
return IOT_SUCCESS;
} else {
return IOT_FAILURE;
}
}
unsigned int IoTFlashRead(unsigned int flashOffset, unsigned int size, unsigned char *ramData)
{
if (size == 0 || ramData == NULL) {
return IOT_FAILURE;
}
esp_err_t ret = spi_flash_read(flashOffset, ramData, size);
return ESPErrToHoErr(ret);
}
unsigned int IoTFlashWrite(unsigned int flashOffset, unsigned int size,
const unsigned char *ramData, unsigned char doErase)
{
if (size == 0 || ramData == NULL) {
return IOT_FAILURE;
}
esp_err_t ret = ESP_OK;
if (doErase == true) {
uint32_t startEraseAddr = (flashOffset / FLASH_SECTOR_SIZE) * FLASH_SECTOR_SIZE;
uint32_t endEraseAddr = ((flashOffset + size) / FLASH_SECTOR_SIZE + 1) * FLASH_SECTOR_SIZE - 1;
uint32_t eraseSecNum = (endEraseAddr - startEraseAddr + 1) / FLASH_SECTOR_SIZE;
uint32_t startBackupSize = flashOffset % FLASH_SECTOR_SIZE;
uint32_t lastBackupSize = endEraseAddr - (flashOffset + size);
uint8_t *backupBuffer = (uint8_t *)malloc(startBackupSize + lastBackupSize);
if (backupBuffer == NULL) {
return IOT_FAILURE;
}
ret = spi_flash_read(startEraseAddr, backupBuffer, startBackupSize);
if (ret != ESP_OK) {
free(backupBuffer);
return IOT_FAILURE;
}
ret = spi_flash_read(flashOffset + size + 1, backupBuffer + startBackupSize, lastBackupSize);
if (ret != ESP_OK) {
free(backupBuffer);
return IOT_FAILURE;
}
ret = spi_flash_erase_range(startEraseAddr, eraseSecNum * FLASH_SECTOR_SIZE);
if (ret != ESP_OK) {
free(backupBuffer);
return IOT_FAILURE;
}
ret = spi_flash_write(startEraseAddr, backupBuffer, startBackupSize);
if (ret != ESP_OK) {
free(backupBuffer);
return IOT_FAILURE;
}
ret = spi_flash_write(flashOffset + size + 1, backupBuffer + startBackupSize, lastBackupSize);
if (ret != ESP_OK) {
free(backupBuffer);
return IOT_FAILURE;
}
free(backupBuffer);
}
ret = spi_flash_write(flashOffset, ramData, size);
return ESPErrToHoErr(ret);
}
unsigned int IoTFlashErase(unsigned int flashOffset, unsigned int size)
{
if (size == 0) {
return IOT_FAILURE;
}
esp_err_t ret = spi_flash_erase_range(flashOffset, size);
return ESPErrToHoErr(ret);
}
unsigned int IoTFlashInit(void)
{
return IOT_SUCCESS;
}
unsigned int IoTFlashDeinit(void)
{
return IOT_SUCCESS;
}
@@ -0,0 +1,278 @@
// Copyright 2022 Espressif Systems (Shanghai) PTE 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.
/****************************************************************************
* Included Files
****************************************************************************/
#include <securec.h>
#include "iot_errno.h"
#include "iot_gpio.h"
#include "driver/gpio.h"
typedef enum {
GPIO_PIN_UNINIT = 0,
GPIO_PIN_INIT = 1
} gpio_status_e;
typedef struct {
IotGpioValue output_value;
gpio_status_e gpio_state;
gpio_config_t gpio_attr;
} gpio_driver_data_t;
static gpio_driver_data_t g_gpioMap[GPIO_NUM_MAX] = {0};
static void InitIo(gpio_num_t num, gpio_config_t *io_conf)
{
assert(num < GPIO_NUM_MAX);
assert(io_conf != NULL);
io_conf->intr_type = GPIO_INTR_DISABLE;
io_conf->mode = GPIO_MODE_DISABLE;
io_conf->pin_bit_mask = (1ULL << num);
io_conf->pull_down_en = 0;
io_conf->pull_up_en = 0;
}
static gpio_int_type_t HoIntrToESPIntr(IotGpioIntType intType, IotGpioIntPolarity intPolarity)
{
gpio_int_type_t intr_type;
if (intType == IOT_INT_TYPE_LEVEL) {
switch (intPolarity) {
case IOT_GPIO_EDGE_FALL_LEVEL_LOW:
intr_type = GPIO_INTR_LOW_LEVEL;
break;
case IOT_GPIO_EDGE_RISE_LEVEL_HIGH:
intr_type = GPIO_INTR_HIGH_LEVEL;
break;
default:
intr_type = GPIO_INTR_DISABLE;
break;
}
} else {
switch (intPolarity) {
case IOT_GPIO_EDGE_FALL_LEVEL_LOW:
intr_type = GPIO_INTR_NEGEDGE;
break;
case IOT_GPIO_EDGE_RISE_LEVEL_HIGH:
intr_type = GPIO_INTR_POSEDGE;
break;
default:
intr_type = GPIO_INTR_DISABLE;
break;
}
}
return intr_type;
}
static uint32_t ESPErrToHoErr(esp_err_t ret)
{
if (ret == ESP_OK) {
return IOT_SUCCESS;
} else {
return IOT_FAILURE;
}
}
unsigned int IoTGpioInit(unsigned int id)
{
if (id >= GPIO_NUM_MAX) {
return IOT_FAILURE;
}
gpio_driver_data_t *gpio_data = &g_gpioMap[id];
if (gpio_data->gpio_state == GPIO_PIN_INIT) {
return IOT_FAILURE;
}
gpio_data->gpio_state = GPIO_PIN_INIT;
InitIo((gpio_num_t)id, &(gpio_data->gpio_attr));
gpio_config(&(gpio_data->gpio_attr));
return IOT_SUCCESS;
}
unsigned int IoTGpioSetDir(unsigned int id, IotGpioDir dir)
{
if (id >= GPIO_NUM_MAX) {
return IOT_FAILURE;
}
gpio_driver_data_t *gpio_data = &g_gpioMap[id];
if (dir == IOT_GPIO_DIR_IN) {
gpio_data->gpio_attr.mode = GPIO_MODE_INPUT;
} else {
gpio_data->gpio_attr.mode = GPIO_MODE_OUTPUT;
}
esp_err_t ret = gpio_set_direction(id, gpio_data->gpio_attr.mode);
return ESPErrToHoErr(ret);
}
unsigned int IoTGpioGetDir(unsigned int id, IotGpioDir *dir)
{
if (id >= GPIO_NUM_MAX) {
return IOT_FAILURE;
}
gpio_driver_data_t *gpio_data = &g_gpioMap[id];
if (gpio_data->gpio_attr.mode == GPIO_MODE_DISABLE) {
return IOT_FAILURE;
} else if (gpio_data->gpio_attr.mode == GPIO_MODE_INPUT) {
*dir = IOT_GPIO_DIR_IN;
} else {
*dir = IOT_GPIO_DIR_OUT;
}
return IOT_SUCCESS;
}
unsigned int IoTGpioSetOutputVal(unsigned int id, IotGpioValue val)
{
if (id >= GPIO_NUM_MAX) {
return IOT_FAILURE;
}
gpio_driver_data_t *gpio_data = &g_gpioMap[id];
gpio_data->output_value = val;
esp_err_t ret = gpio_set_level(id, val);
return ESPErrToHoErr(ret);
}
unsigned int IoTGpioGetOutputVal(unsigned int id, IotGpioValue *val)
{
if (id >= GPIO_NUM_MAX) {
return IOT_FAILURE;
}
gpio_driver_data_t *gpio_data = &g_gpioMap[id];
*val = gpio_data->output_value;
return IOT_SUCCESS;
}
unsigned int IoTGpioGetInputVal(unsigned int id, IotGpioValue *val)
{
if (id >= GPIO_NUM_MAX) {
return IOT_FAILURE;
}
*val = gpio_get_level(id);
return IOT_SUCCESS;
}
unsigned int IoTGpioRegisterIsrFunc(unsigned int id, IotGpioIntType intType, IotGpioIntPolarity intPolarity,
GpioIsrCallbackFunc func, char *arg)
{
if (id >= GPIO_NUM_MAX) {
return IOT_FAILURE;
}
gpio_driver_data_t *gpio_data = &g_gpioMap[id];
gpio_int_type_t intr_type = HoIntrToESPIntr(intType, intPolarity);
if ((gpio_data->gpio_attr.intr_type != GPIO_INTR_DISABLE) || (intr_type == GPIO_INTR_DISABLE)) {
return IOT_FAILURE;
}
gpio_data->gpio_attr.intr_type = intr_type;
gpio_set_intr_type(id, intr_type);
gpio_install_isr_service(0);
esp_err_t ret = gpio_isr_handler_add(id, func, (void *)arg);
return ESPErrToHoErr(ret);
}
unsigned int IoTGpioUnregisterIsrFunc(unsigned int id)
{
if (id >= GPIO_NUM_MAX) {
return IOT_FAILURE;
}
gpio_driver_data_t *gpio_data = &g_gpioMap[id];
if (gpio_data->gpio_attr.intr_type == GPIO_INTR_DISABLE) {
return IOT_FAILURE;
}
gpio_data->gpio_attr.intr_type = GPIO_INTR_DISABLE;
gpio_intr_disable(id);
esp_err_t ret = gpio_isr_handler_remove(id);
gpio_uninstall_isr_service();
return ESPErrToHoErr(ret);
}
unsigned int IoTGpioSetIsrMask(unsigned int id, unsigned char mask)
{
if (id >= GPIO_NUM_MAX) {
return IOT_FAILURE;
}
gpio_driver_data_t *gpio_data = &g_gpioMap[id];
if (mask == true) {
if (gpio_data->gpio_attr.intr_type == GPIO_INTR_DISABLE) {
return IOT_SUCCESS;
}
gpio_data->gpio_attr.intr_type = GPIO_INTR_DISABLE;
gpio_config(&gpio_data->gpio_attr);
gpio_intr_disable(id);
}
return IOT_SUCCESS;
}
unsigned int IoTGpioSetIsrMode(unsigned int id, IotGpioIntType intType, IotGpioIntPolarity intPolarity)
{
if (id >= GPIO_NUM_MAX) {
return IOT_FAILURE;
}
gpio_driver_data_t *gpio_data = &g_gpioMap[id];
gpio_int_type_t intr_type = HoIntrToESPIntr(intType, intPolarity);
gpio_data->gpio_attr.intr_type = intr_type;
gpio_config(&gpio_data->gpio_attr);
return IOT_SUCCESS;
}
unsigned int IoTGpioDeinit(unsigned int id)
{
if (id >= GPIO_NUM_MAX) {
return IOT_FAILURE;
}
gpio_driver_data_t *gpio_data = &g_gpioMap[id];
if (gpio_data->gpio_state == GPIO_PIN_INIT) {
gpio_data->gpio_state = GPIO_PIN_UNINIT;
if (gpio_data->gpio_attr.intr_type != GPIO_INTR_DISABLE) {
gpio_intr_disable(id);
esp_err_t ret = gpio_isr_handler_remove(id);
gpio_uninstall_isr_service();
gpio_data->gpio_attr.intr_type = GPIO_INTR_DISABLE;
return ESPErrToHoErr(ret);
}
} else {
return IOT_FAILURE;
}
if (memset_s(gpio_data, sizeof(gpio_driver_data_t),
0, sizeof(gpio_driver_data_t)) != EOK) {
return IOT_FAILURE;
}
gpio_config(&gpio_data->gpio_attr);
return IOT_SUCCESS;
}
@@ -0,0 +1,239 @@
// Copyright 2022 Espressif Systems (Shanghai) PTE 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.
/****************************************************************************
* Included Files
****************************************************************************/
#include "iot_errno.h"
#include "iot_i2c.h"
#include "driver/i2c.h"
#include "esp_err.h"
#define DATA_LENGTH (512) /*!< Data buffer length for test buffer */
#define I2C_SLAVE_NUM (0) /*!< I2C port number for slave dev */
#define I2C_MASTER_NUM (1) /*!< I2C port number for master dev */
#define I2C_SLAVE_SCL_IO (5) /*!< gpio number for i2c slave clock */
#define I2C_SLAVE_SDA_IO (4) /*!< gpio number for i2c slave data */
#define I2C_MASTER_SCL_IO (4) /*!< gpio number for I2C master clock */
#define I2C_MASTER_SDA_IO (9) /*!< gpio number for I2C master data */
#define I2C_MASTER_FREQ_HZ (100000) /*!< I2C master clock frequency */
#define I2C_SLAVE_ADDRESS (0x28) /*!< ESP32 slave address, you can set any 7bit value */
#define ACK_CHECK_EN (0x1) /*!< I2C master will check ack from slave */
#define ACK_VAL (0x0) /*!< I2C ack value */
#define NACK_VAL (0x1) /*!< I2C nack value */
#define I2C_MASTER_BUF_LEN (0) /*!< I2C master do not need buffer */
#define I2C_SLAVE_BUF_LEN (2 * DATA_LENGTH) /*!< I2C slave rx buffer size */
#define I2C_READ_WRITE_TIMEOUT (1000)
#define I2C_SLAVE_DEFAULT \
{ \
.mode = (I2C_MODE_SLAVE), \
.sda_io_num = (I2C_SLAVE_SDA_IO), \
.scl_io_num = (I2C_SLAVE_SCL_IO), \
.sda_pullup_en = (GPIO_PULLUP_ENABLE), \
.scl_pullup_en = (GPIO_PULLUP_ENABLE), \
.slave.addr_10bit_en = (0), \
.slave.slave_addr = (I2C_SLAVE_ADDRESS), \
}
#define I2C_MASTER_DEFAULT \
{ \
.mode = (I2C_MODE_MASTER), \
.sda_io_num = (I2C_MASTER_SDA_IO), \
.scl_io_num = (I2C_MASTER_SCL_IO), \
.sda_pullup_en = (GPIO_PULLUP_ENABLE), \
.scl_pullup_en = (GPIO_PULLUP_ENABLE), \
.master.clk_speed = (I2C_MASTER_FREQ_HZ), \
.clk_flags = (I2C_MASTER_FREQ_HZ), \
}
typedef enum {
I2C_UNINIT = 0,
I2C_INIT = 1
} i2c_status_e;
typedef struct {
i2c_port_t i2c_port;
i2c_status_e i2c_state;
i2c_config_t i2c_conf;
size_t buf_len;
} i2c_driver_data_t;
static i2c_driver_data_t i2c_conf_0 = {
.i2c_port = I2C_SLAVE_NUM,
.i2c_state = I2C_UNINIT,
.i2c_conf = I2C_SLAVE_DEFAULT,
.buf_len = I2C_SLAVE_BUF_LEN,
};
static i2c_driver_data_t i2c_conf_1 = {
.i2c_port = I2C_MASTER_NUM,
.i2c_state = I2C_UNINIT,
.i2c_conf = I2C_MASTER_DEFAULT,
.buf_len = I2C_MASTER_BUF_LEN,
};
static i2c_driver_data_t *g_i2c_conf[I2C_MODE_MAX] = {&i2c_conf_0, &i2c_conf_1};
static uint32_t ESPErrToHoErr(esp_err_t ret)
{
if (ret == ESP_OK) {
return IOT_SUCCESS;
} else {
return IOT_FAILURE;
}
}
unsigned int IoTI2cWrite(unsigned int id, unsigned short deviceAddr, const unsigned char *data, unsigned int dataLen)
{
if (id >= I2C_MODE_MAX || data == NULL || dataLen == 0) {
return IOT_FAILURE;
}
i2c_driver_data_t *i2c_data = g_i2c_conf[id];
if (i2c_data->i2c_state == I2C_UNINIT) {
return IOT_FAILURE;
}
if (i2c_data->i2c_conf.mode == I2C_MODE_MASTER) {
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (deviceAddr << 1) | I2C_MASTER_WRITE, ACK_CHECK_EN);
i2c_master_write(cmd, data, dataLen, ACK_CHECK_EN);
i2c_master_stop(cmd);
esp_err_t ret = i2c_master_cmd_begin(i2c_data->i2c_port, cmd, I2C_READ_WRITE_TIMEOUT / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
return ESPErrToHoErr(ret);
}
size_t d_size = 0;
while (1) {
if (dataLen > d_size) {
int ret = i2c_slave_write_buffer(i2c_data->i2c_port, data + d_size, dataLen - d_size,
I2C_READ_WRITE_TIMEOUT / portTICK_RATE_MS);
if (ret < 0) {
return IOT_FAILURE;
} else if (ret == 0) {
break;
}
d_size += ret;
} else {
break;
}
}
return IOT_SUCCESS;
}
unsigned int IoTI2cRead(unsigned int id, unsigned short deviceAddr, unsigned char *data, unsigned int dataLen)
{
if (id >= I2C_MODE_MAX || data == NULL || dataLen == 0) {
return IOT_FAILURE;
}
i2c_driver_data_t *i2c_data = g_i2c_conf[id];
if (i2c_data->i2c_state == I2C_UNINIT) {
return IOT_FAILURE;
}
if (i2c_data->i2c_conf.mode == I2C_MODE_MASTER) {
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (deviceAddr << 1) | I2C_MASTER_READ, ACK_CHECK_EN);
if (dataLen > 1) {
i2c_master_read(cmd, data, dataLen - 1, ACK_VAL);
}
i2c_master_read_byte(cmd, data + dataLen - 1, NACK_VAL);
i2c_master_stop(cmd);
esp_err_t ret = i2c_master_cmd_begin(i2c_data->i2c_port, cmd, I2C_READ_WRITE_TIMEOUT / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
return ESPErrToHoErr(ret);
} else {
int size_rd = 0;
int len = 0;
while (1) {
len = i2c_slave_read_buffer(I2C_SLAVE_NUM, data + size_rd, dataLen - size_rd,
I2C_READ_WRITE_TIMEOUT / portTICK_RATE_MS);
if (len == 0) {
break;
} else if (len < 0) {
return IOT_FAILURE;
}
size_rd += len;
}
}
return IOT_SUCCESS;
}
unsigned int IoTI2cInit(unsigned int id, unsigned int baudrate)
{
if (id >= I2C_MODE_MAX) {
return IOT_FAILURE;
}
i2c_driver_data_t *i2c_data = g_i2c_conf[id];
if (i2c_data->i2c_state == I2C_INIT) {
return IOT_FAILURE;
}
if (id == I2C_MODE_MASTER) {
if (baudrate == 0) {
return IOT_FAILURE;
}
i2c_data->i2c_conf.master.clk_speed = baudrate;
}
i2c_data->i2c_state = I2C_INIT;
esp_err_t ret = i2c_param_config(i2c_data->i2c_port, &(i2c_data->i2c_conf));
if (ret != ESP_OK) {
return IOT_FAILURE;
}
ret = i2c_driver_install(i2c_data->i2c_port, i2c_data->i2c_conf.mode, i2c_data->buf_len, i2c_data->buf_len, 0);
return ESPErrToHoErr(ret);
}
unsigned int IoTI2cDeinit(unsigned int id)
{
if (id >= I2C_MODE_MAX) {
return IOT_FAILURE;
}
i2c_driver_data_t *i2c_data = g_i2c_conf[id];
if (i2c_data->i2c_state == I2C_UNINIT) {
return IOT_FAILURE;
}
i2c_data->i2c_state = I2C_UNINIT;
esp_err_t ret = i2c_driver_delete(i2c_data->i2c_port);
return ESPErrToHoErr(ret);
}
unsigned int IoTI2cSetBaudrate(unsigned int id, unsigned int baudrate)
{
if (id >= I2C_MODE_MAX) {
return IOT_FAILURE;
}
return IOT_SUCCESS;
}
@@ -0,0 +1,178 @@
// Copyright 2022 Espressif Systems (Shanghai) PTE 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.
/****************************************************************************
* Included Files
****************************************************************************/
#include <securec.h>
#include "iot_errno.h"
#include "iot_pwm.h"
#include "driver/ledc.h"
#include "esp_err.h"
#define CLK_40M (40000000)
#define DUTY_MIN (0)
#define DUTY_MAX (100)
#define DUTY_RES_MIN (128)
#define LEDC_OUTPUT_IO (5)
#define LEDC_TIMER LEDC_TIMER_0
#define NUM2 2
#define DUTY_RESOLUTION_MAX (NUM2 << ((LEDC_TIMER_BIT_MAX) - 1))
#if SOC_LEDC_SUPPORT_HS_MODE
#define LEDC_MODE LEDC_HIGH_SPEED_MODE
#else
#define LEDC_MODE LEDC_LOW_SPEED_MODE
#endif
typedef enum {
PWM_UNINIT = 0,
PWM_INIT = 1
} pwm_status_e;
typedef struct {
pwm_status_e pwm_state;
ledc_channel_config_t pwm_attr;
} pwm_driver_data_t;
static pwm_driver_data_t g_pwm[LEDC_CHANNEL_MAX] = {0};
static unsigned int PwmDutyCalc(uint8_t TimerBit, uint32_t duty)
{
return ((((NUM2 >> TimerBit) - 1) * duty) / DUTY_MAX);
}
static void InitPwm(ledc_channel_t num, ledc_channel_config_t *pwm_conf)
{
assert(num < LEDC_CHANNEL_MAX);
assert(pwm_conf != NULL);
pwm_conf->speed_mode = LEDC_MODE;
pwm_conf->channel = num;
pwm_conf->timer_sel = LEDC_TIMER;
pwm_conf->intr_type = LEDC_INTR_DISABLE;
pwm_conf->gpio_num = LEDC_OUTPUT_IO;
pwm_conf->duty = 0;
pwm_conf->hpoint = 0;
}
static uint32_t ESPErrToHoErr(esp_err_t ret)
{
if (ret == ESP_OK) {
return IOT_SUCCESS;
} else {
return IOT_FAILURE;
}
}
unsigned int IoTPwmInit(unsigned int port)
{
if (port >= LEDC_CHANNEL_MAX) {
return IOT_FAILURE;
}
pwm_driver_data_t *pwm = &g_pwm[port];
if (pwm->pwm_state == PWM_INIT) {
return IOT_FAILURE;
}
pwm->pwm_state = PWM_INIT;
InitPwm((ledc_channel_t)port, &(pwm->pwm_attr));
return IOT_SUCCESS;
}
unsigned int IoTPwmDeinit(unsigned int port)
{
if (port >= LEDC_CHANNEL_MAX) {
return IOT_FAILURE;
}
pwm_driver_data_t *pwm = &g_pwm[port];
if (pwm->pwm_state == PWM_UNINIT) {
return IOT_FAILURE;
}
memset_s(pwm, sizeof(pwm_driver_data_t), 0, sizeof(pwm_driver_data_t));
return IOT_SUCCESS;
}
unsigned int IoTPwmStart(unsigned int port, unsigned short duty, unsigned int freq)
{
if (port >= LEDC_CHANNEL_MAX) {
return IOT_FAILURE;
}
pwm_driver_data_t *pwm = &g_pwm[port];
if (pwm->pwm_state == PWM_UNINIT) {
return IOT_FAILURE;
}
if ((freq == 0) || (duty >= DUTY_MAX) || (duty == DUTY_MIN)) {
return IOT_FAILURE;
}
uint32_t DutyResolution = CLK_40M / freq;
if (DutyResolution < DUTY_RES_MIN || DutyResolution > DUTY_RESOLUTION_MAX) {
return IOT_FAILURE;
}
uint8_t TimerBit = 0;
while (DutyResolution) {
DutyResolution = DutyResolution >> 1;
TimerBit++;
}
ledc_timer_config_t ledc_timer = {
.speed_mode = LEDC_MODE,
.timer_num = LEDC_TIMER,
.duty_resolution = (TimerBit - 1),
.freq_hz = freq,
.clk_cfg = LEDC_AUTO_CLK};
esp_err_t ret = ledc_timer_config(&ledc_timer);
if (ret != ESP_OK) {
return IOT_FAILURE;
}
ret = ledc_channel_config(&(pwm->pwm_attr));
if (ret != ESP_OK) {
return IOT_FAILURE;
}
uint32_t PwmDuty = PwmDutyCalc(TimerBit, duty);
ret = ledc_set_duty(LEDC_MODE, port, PwmDuty);
if (ret != ESP_OK) {
return IOT_FAILURE;
}
ret = ledc_update_duty(LEDC_MODE, port);
return ESPErrToHoErr(ret);
}
unsigned int IoTPwmStop(unsigned int port)
{
if (port >= LEDC_CHANNEL_MAX) {
return IOT_FAILURE;
}
pwm_driver_data_t *pwm = &g_pwm[port];
if (pwm->pwm_state == PWM_UNINIT) {
return IOT_FAILURE;
}
esp_err_t ret = ledc_stop(LEDC_MODE, port, 0);
return ESPErrToHoErr(ret);
}
@@ -0,0 +1,272 @@
// Copyright 2022 Espressif Systems (Shanghai) PTE 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.
/****************************************************************************
* Included Files
****************************************************************************/
#include "iot_errno.h"
#include "iot_uart.h"
#include "driver/gpio.h"
#include "driver/uart.h"
#include "esp_err.h"
#ifndef portMAX_DELAY
#define portMAX_DELAY (TickType_t)0xffffffffUL
#endif
#define TXD_PIN (GPIO_NUM_4)
#define RXD_PIN (GPIO_NUM_5)
#define UART_ATTR_DEFAULT \
{ \
115200, UART_DATA_8_BITS, UART_PARITY_DISABLE, UART_STOP_BITS_1, \
UART_HW_FLOWCTRL_DISABLE, UART_SCLK_APB \
}
typedef enum {
ESP_UART_BLOCK_STATE_NONE_BLOCK = 1,
ESP_UART_BLOCK_STATE_BLOCK,
} uart_block_state_e;
typedef enum {
UART_STATE_NOT_OPENED = 0,
UART_STATE_USEABLE
} uart_status_e;
typedef struct {
uart_port_t num;
uart_status_e uart_state;
uart_block_state_e tx_block_state;
uart_block_state_e rx_block_state;
uart_config_t attr;
uint8_t pad;
} uart_driver_data_t;
static uart_driver_data_t g_uart_0 = {
.num = UART_NUM_0,
.uart_state = UART_STATE_NOT_OPENED,
.tx_block_state = ESP_UART_BLOCK_STATE_NONE_BLOCK,
.rx_block_state = ESP_UART_BLOCK_STATE_NONE_BLOCK,
.attr = UART_ATTR_DEFAULT,
.pad = 0,
};
static uart_driver_data_t g_uart_1 = {
.num = UART_NUM_1,
.uart_state = UART_STATE_NOT_OPENED,
.tx_block_state = ESP_UART_BLOCK_STATE_NONE_BLOCK,
.rx_block_state = ESP_UART_BLOCK_STATE_NONE_BLOCK,
.attr = UART_ATTR_DEFAULT,
.pad = 0,
};
static uart_driver_data_t g_uart_2 = {
.num = UART_NUM_2,
.uart_state = UART_STATE_NOT_OPENED,
.tx_block_state = ESP_UART_BLOCK_STATE_NONE_BLOCK,
.rx_block_state = ESP_UART_BLOCK_STATE_NONE_BLOCK,
.attr = UART_ATTR_DEFAULT,
.pad = 0,
};
static const int RX_BUF_SIZE = 1024;
static uart_driver_data_t *g_uart[UART_NUM_MAX] = {&g_uart_0, &g_uart_1, &g_uart_2};
static uart_word_length_t HoDataBitsToESPDataBits(IotUartIdxDataBit DataBits)
{
switch (DataBits) {
case IOT_UART_DATA_BIT_5:
return UART_DATA_5_BITS;
case IOT_UART_DATA_BIT_6:
return UART_DATA_6_BITS;
case IOT_UART_DATA_BIT_7:
return UART_DATA_7_BITS;
case IOT_UART_DATA_BIT_8:
return UART_DATA_8_BITS;
default:
return UART_DATA_BITS_MAX;
}
}
static uart_parity_t HoParityToESParity(IotUartParity Parity)
{
switch (Parity) {
case IOT_UART_PARITY_NONE:
return UART_PARITY_DISABLE;
case IOT_UART_PARITY_ODD:
return UART_PARITY_ODD;
case IOT_UART_PARITY_EVEN:
return UART_PARITY_EVEN;
default:
assert(0);
}
return UART_PARITY_DISABLE;
}
static uart_stop_bits_t HoStopBitsToESPStopBits(IotUartStopBit StopBits)
{
switch (StopBits) {
case IOT_UART_STOP_BIT_1:
return UART_STOP_BITS_1;
case IOT_UART_STOP_BIT_2:
return UART_STOP_BITS_2;
default:
return UART_STOP_BITS_MAX;
}
}
static uart_hw_flowcontrol_t HoflowCtrlToESPflowCtrl(IotFlowCtrl flowCtrl)
{
switch (flowCtrl) {
case IOT_FLOW_CTRL_NONE:
return UART_HW_FLOWCTRL_DISABLE;
case IOT_FLOW_CTRL_RTS_CTS:
return UART_HW_FLOWCTRL_CTS_RTS;
case IOT_FLOW_CTRL_RTS_ONLY:
return UART_HW_FLOWCTRL_RTS;
case IOT_FLOW_CTRL_CTS_ONLY:
return UART_HW_FLOWCTRL_CTS;
default:
return UART_HW_FLOWCTRL_MAX;
}
}
unsigned int IoTUartInit(unsigned int id, const IotUartAttribute *param)
{
if (id > UART_NUM_MAX || param == NULL) {
return IOT_FAILURE;
}
uart_driver_data_t *uart = g_uart[id];
if (uart->uart_state == UART_STATE_USEABLE) {
return IOT_FAILURE;
}
uart->attr.baud_rate = param->baudRate;
uart->attr.data_bits = HoDataBitsToESPDataBits(param->dataBits);
assert(uart->attr.data_bits != UART_DATA_BITS_MAX);
uart->attr.parity = HoParityToESParity(param->parity);
uart->attr.stop_bits = HoStopBitsToESPStopBits(param->stopBits);
assert(uart->attr.stop_bits != UART_STOP_BITS_MAX);
uart->pad = param->pad;
if (IOT_UART_BLOCK_STATE_NONE_BLOCK == param->rxBlock) {
uart->rx_block_state = ESP_UART_BLOCK_STATE_NONE_BLOCK;
} else {
uart->rx_block_state = ESP_UART_BLOCK_STATE_BLOCK;
}
if (IOT_UART_BLOCK_STATE_NONE_BLOCK == param->txBlock) {
uart->tx_block_state = ESP_UART_BLOCK_STATE_NONE_BLOCK;
} else {
uart->tx_block_state = ESP_UART_BLOCK_STATE_BLOCK;
}
int ret = uart_driver_install(uart->num, RX_BUF_SIZE * 2, 0, 0, NULL, 0);
ret += uart_param_config(uart->num, &(uart->attr));
ret += uart_set_pin(uart->num, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
if (ret != ESP_OK) {
return IOT_FAILURE;
}
uart->uart_state = UART_STATE_USEABLE;
return IOT_SUCCESS;
}
int IoTUartRead(unsigned int id, unsigned char *data, unsigned int dataLen)
{
if (id > UART_NUM_MAX) {
return IOT_FAILURE;
}
uart_driver_data_t *uart = g_uart[id];
if (data == NULL || dataLen == 0) {
return IOT_FAILURE;
}
if (uart->uart_state == UART_STATE_NOT_OPENED) {
return IOT_FAILURE;
}
uint8_t *rd_data = data;
int data_received = 0;
int data_remaining = dataLen;
while (data_remaining) {
if (uart->rx_block_state == ESP_UART_BLOCK_STATE_BLOCK) {
data_received += uart_read_bytes(uart->num, (void *)(&rd_data[data_received]),
data_remaining, (TickType_t)portMAX_DELAY);
} else {
data_received += uart_read_bytes(uart->num, (void *)(&rd_data[data_received]), data_remaining, 0);
}
if (data_received < 0) {
return IOT_FAILURE;
}
data_remaining -= data_received;
}
return IOT_SUCCESS;
}
int IoTUartWrite(unsigned int id, const unsigned char *data, unsigned int dataLen)
{
if (id > UART_NUM_MAX) {
return IOT_FAILURE;
}
uart_driver_data_t *uart = g_uart[id];
if (uart->uart_state == UART_STATE_NOT_OPENED) {
return IOT_FAILURE;
}
int txBytes = uart_write_bytes(uart->num, (const char *)data, dataLen);
if (uart->tx_block_state == ESP_UART_BLOCK_STATE_BLOCK) {
int ret = uart_wait_tx_done(uart->num, (TickType_t)portMAX_DELAY);
if (txBytes != dataLen || ret != ESP_OK) {
return IOT_FAILURE;
}
}
return IOT_SUCCESS;
}
unsigned int IoTUartDeinit(unsigned int id)
{
if (id > UART_NUM_MAX) {
return IOT_FAILURE;
}
uart_driver_data_t *uart = g_uart[id];
if (uart->uart_state == UART_STATE_NOT_OPENED) {
return IOT_FAILURE;
}
return uart_driver_delete(uart->num);
}
unsigned int IoTUartSetFlowCtrl(unsigned int id, IotFlowCtrl flowCtrl)
{
if (id > UART_NUM_MAX) {
return IOT_FAILURE;
}
uart_driver_data_t *uart = g_uart[id];
uart->attr.flow_ctrl = HoflowCtrlToESPflowCtrl(flowCtrl);
assert(uart->attr.flow_ctrl != UART_HW_FLOWCTRL_MAX);
return uart_param_config(uart->num, &(uart->attr));
}
@@ -0,0 +1,90 @@
// Copyright 2022 Espressif Systems (Shanghai) PTE 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.
/****************************************************************************
* Included Files
****************************************************************************/
#include "los_task.h"
#include "esp_task_wdt.h"
#define TWDT_TIMEOUT_DEFAULT 3
typedef enum {
WATCHDOG_DISABLED = 0,
WATCHDOG_ENABLED = 1
} watchdog_status_e;
#ifdef CONFIG_ESP_TASK_WDT
static watchdog_status_e g_watchdogStatus = WATCHDOG_ENABLED;
#else
static watchdog_status_e g_watchdogStatus = WATCHDOG_DISABLED;
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
void IoTWatchDogEnable(void)
{
if (g_watchdogStatus == WATCHDOG_ENABLED) {
return;
}
esp_err_t ret = ESP_OK;
#ifdef CONFIG_ESP_TASK_WDT_PANIC
ret = esp_task_wdt_init(CONFIG_ESP_TASK_WDT_TIMEOUT_S, true);
#elif CONFIG_ESP_TASK_WDT
ret = esp_task_wdt_init(CONFIG_ESP_TASK_WDT_TIMEOUT_S, false);
#endif
if (ret != ESP_OK) {
return;
}
if (g_idleTaskID) {
ret = esp_task_wdt_add(g_idleTaskID);
if (ret == ESP_OK) {
g_watchdogStatus = WATCHDOG_ENABLED;
} else {
esp_task_wdt_deinit();
}
}
}
void IoTWatchDogKick(void)
{
if (g_watchdogStatus == WATCHDOG_DISABLED) {
return;
}
esp_task_wdt_reset();
}
void IoTWatchDogDisable(void)
{
if (g_watchdogStatus == WATCHDOG_DISABLED) {
return;
}
esp_err_t ret = esp_task_wdt_delete(g_idleTaskID);
if (ret != ESP_OK) {
return;
}
ret = esp_task_wdt_deinit();
if (ret == ESP_OK) {
g_watchdogStatus = WATCHDOG_DISABLED;
}
}
@@ -0,0 +1,56 @@
// Copyright 2022 Espressif Systems (Shanghai) PTE 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.
/****************************************************************************
* Included Files
****************************************************************************/
#include "iot_errno.h"
#include "lowpower.h"
#include "esp_err.h"
#include "esp_sleep.h"
#define WAKE_TIME_DEFAULT 20
static uint32_t ESPErrToHoErr(esp_err_t ret)
{
if (ret == ESP_OK) {
return IOT_SUCCESS;
} else {
return IOT_FAILURE;
}
}
unsigned int LpcInit(void)
{
return IOT_SUCCESS;
}
unsigned int LpcSetType(LpcType type)
{
esp_err_t ret = esp_sleep_enable_timer_wakeup(WAKE_TIME_DEFAULT * 1000000);
if (ret != ESP_OK) {
return IOT_FAILURE;
}
if (type == LIGHT_SLEEP) {
ret = esp_light_sleep_start();
return ESPErrToHoErr(ret);
} else if (type == DEEP_SLEEP) {
esp_deep_sleep_start();
}
return IOT_SUCCESS;
}
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "esp_system.h"
void RebootDevice(unsigned int cause)
{
esp_restart();
}
+127
View File
@@ -0,0 +1,127 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdarg.h>
#include <unistd.h>
#include "cmsis_os2.h"
#include "los_compiler.h"
#include "los_debug.h"
#include "los_task.h"
#include "los_sched.h"
#include "nvs.h"
#include "ohos_init.h"
#include "ohos_types.h"
#include "samgr_lite.h"
#include "stdio.h"
#include "hal/uart_ll.h"
#include "hiview_def.h"
#include "hiview_output_log.h"
#define NUM_2 2
#define SAFE_OFFSET 4
#define BUFF_MAX_LEN 512
static UINT32 s_LogMuxHandle = 0;
static void s_vprintf(const char *fmt, va_list ap)
{
int len;
uint8_t taskLock;
static char buf[NUM_2][BUFF_MAX_LEN];
char *pbuf;
if (xPortInterruptedFromISRContext() || g_losTaskLock || (!g_taskScheduled)) {
taskLock = 1;
pbuf = buf[1];
} else {
taskLock = 0;
pbuf = buf[0];
}
if (!taskLock) {
while (!s_LogMuxHandle) {
LOS_MuxCreate(&s_LogMuxHandle);
LOS_TaskDelay(1);
}
LOS_MuxPend(s_LogMuxHandle, LOS_WAIT_FOREVER);
}
len = vsnprintf_s(pbuf, sizeof(buf[0]), sizeof(buf[0]) - SAFE_OFFSET, fmt, ap);
if (len > 0) {
uint16_t fill_len;
for (fill_len = uart_ll_get_txfifo_len(&UART0); fill_len < len;) {
if (fill_len) {
uart_ll_write_txfifo(&UART0, (uint8_t *)pbuf, fill_len);
len -= fill_len;
pbuf += fill_len;
}
if (!taskLock)
LOS_TaskDelay(1);
fill_len = uart_ll_get_txfifo_len(&UART0);
}
if (len > 0)
uart_ll_write_txfifo(&UART0, (uint8_t *)pbuf, len);
}
if (!taskLock)
LOS_MuxPost(s_LogMuxHandle);
}
// Liteos_m的打印
int printf(const char *__restrict __format, ...)
{
va_list ap;
va_start(ap, __format);
s_vprintf(__format, ap);
va_end(ap);
return 0;
}
int hal_trace_printf(int level, const char *fmt, ...)
{
if (level <= PRINT_LEVEL) {
va_list ap;
va_start(ap, fmt);
s_vprintf(fmt, ap);
va_end(ap);
}
return 0;
}
bool HilogProc_Impl(const HiLogContent *hilogContent, uint32_t len)
{
char tempOutStr[LOG_FMT_MAX_LEN];
tempOutStr[0] = 0, tempOutStr[1] = 0;
if (LogContentFmt(tempOutStr, sizeof(tempOutStr), hilogContent) > 0) {
printf("%s", tempOutStr);
}
return true;
}
int HiLogWriteInternal(const char *buffer, size_t bufLen)
{
if (!buffer) {
return -1;
}
if (bufLen < NUM_2) {
return 0;
}
if (buffer[bufLen - NUM_2] != '\n') {
*((char *)buffer + bufLen - 1) = '\n';
}
printf("%s\n", buffer);
return 0;
}
int init_trace_system(void)
{
int ret = 1;
HiviewRegisterHilogProc(HilogProc_Impl);
return ret;
}
+110
View File
@@ -0,0 +1,110 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <unistd.h>
#include "cmsis_os2.h"
#include "los_compiler.h"
#include "los_debug.h"
#include "los_task.h"
#include "nvs.h"
#include "ohos_init.h"
#include "ohos_types.h"
#include "pthread.h"
#include "samgr_lite.h"
#include "stdio.h"
#define DELAY_1S 1000
#define DELAY_10S (DELAY_1S * 10)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattribute-alias"
static int s_raise(int sig)
{
if (SIGABRT == sig) {
LOS_TaskDelete(LOS_CurTaskIDGet());
while (1) {
LOS_Msleep(DELAY_1S);
}
}
return 0;
}
int raise(int sig) __attribute__((alias("s_raise")));
static int s_raise_r(struct _reent *r, int sig)
{
return 0;
}
int _raise_r(struct _reent *r, int sig) __attribute__((alias("s_raise_r")));
#pragma GCC diagnostic pop
int _open_r(struct _reent *r, const char *path, int flags, int mode)
{
return _open(path, flags, mode);
}
int _close_r(struct _reent *r, int fd)
{
return _close(fd);
}
off_t _lseek_r(struct _reent *r, int fd, off_t size, int mode)
{
return _lseek(fd, size, mode);
}
int _link_r(struct _reent *r, const char *n1, const char *n2)
{
return link(n1, n2);
}
int _unlink_r(struct _reent *r, const char *path)
{
return _unlink(path);
}
int _stat_r(struct _reent *r, const char *path, struct stat *st)
{
return _stat(path, st);
}
int _rename_r(struct _reent *r, const char *src, const char *dst)
{
return rename(src, dst);
}
int _fstat_r(struct _reent *r, int fd, struct stat *st)
{
return _fstat(fd, st);
}
int _getpid_r(struct _reent *r)
{
return LOS_CurTaskIDGet();
}
int _kill_r(struct _reent *r, int pid, int sig)
{
return LOS_TaskDelete(pid);
}
void *_sbrk_r(struct _reent *r, ptrdiff_t sz)
{
char *name;
UINT32 taskId = LOS_CurTaskIDGet();
name = LOS_TaskNameGet(taskId);
esp_rom_printf("\e[0;36msbrk.taskName=%s taskId=%d\e[0m\r\n", name ? name : "NULL", taskId);
LOS_TaskDelete(taskId);
LOS_TaskSuspend(taskId);
while (1) {
LOS_TaskDelay(DELAY_10S);
}
}
+26
View File
@@ -0,0 +1,26 @@
# Copyright (c) 2022 OpenValley Digital Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/lite/config/component/lite_component.gni")
import("//build/lite/ndk/ndk.gni")
lite_library("hal_update_static") {
target_type = "static_library"
sources = [
"update_adapter.c",
]
include_dirs = [
"//base/update/ota_lite/hals",
"//base/update/ota_lite/interfaces/kits",
]
}
+299
View File
@@ -0,0 +1,299 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "hal_hota_board.h"
#include "hota_partition.h"
#define NOT_SUPPORT 4096
#define PATH_SEPARATE_LEN 2
typedef struct {
uint8_t index;
uint8_t init;
UpdateMetaData metaData;
ComponentTableInfo componentTableInfo;
uint8_t pubKey[16];
} UpdateInfo_t;
static UpdateInfo_t UpdateInfo = {0};
/**
* @brief OTA module initialization.
*
* @return OHOS_SUCCESS: Success,
* Others: Failure.
*/
int HotaHalInit(void)
{
if (UpdateInfo.init != 0) {
return OHOS_FAILURE;
}
UpdateInfo.init = 1;
memset_s(&UpdateInfo, sizeof(UpdateInfo), 0, sizeof(UpdateInfo));
UpdateInfo.componentTableInfo.componentName = "OpenValley";
UpdateInfo.componentTableInfo.imgPath = "/";
return OHOS_SUCCESS;
}
/**
* @brief Release OTA module resource.
*
* @return OHOS_SUCCESS: Success,
* Others: Failure.
*/
int HotaHalDeInit(void)
{
if (UpdateInfo.init == 0) {
return OHOS_FAILURE;
}
UpdateInfo.init = 0;
return OHOS_SUCCESS;
}
/**
* @brief Release OTA module resource.
*
* @return OHOS_SUCCESS: Success,
* Others: Failure.
*/
int HotaHalGetUpdateIndex(unsigned int *index)
{
if (index == NULL) {
return OHOS_FAILURE;
}
*index = UpdateInfo.index;
return OHOS_SUCCESS;
}
/**
* @brief Write image to partition.
*
* @param partition [in] scan result, result array size must larger than WIFI_SCAN_AP_LIMIT.
* @param buffer [in] image buffer.
* @param offset [in] The buffer offset of file.
* @param bufLen [in] The Length of buffer.
*
* @return OHOS_SUCCESS: Success,
* Others: Failure.
*/
int HotaHalWrite(int partition, unsigned char *buffer, unsigned int offset, unsigned int bufLen)
{
if ((buffer == NULL) || (offset == 0) || (bufLen == 0)) {
return OHOS_FAILURE;
}
return OHOS_SUCCESS;
}
/**
* @brief read image of partition.
*
* @param partition [in] scan result, result array size must larger than WIFI_SCAN_AP_LIMIT.
* @param offset [in] The buffer offset of file.
* @param bufLen [in] The Length of buffer.
* @param buffer [out] image buffer.
*
* @return OHOS_SUCCESS: Success,
* Others: Failure.
*/
int HotaHalRead(int partition, unsigned int offset, unsigned int bufLen, unsigned char *buffer)
{
if ((buffer == NULL) || (offset == 0) || (bufLen == 0)) {
return OHOS_FAILURE;
}
return OHOS_SUCCESS;
}
/**
* @brief Write Boot Settings in order to notify device upgrade success or enter Recovery Part.
*
* @return OHOS_SUCCESS: Success,
* Others: Failure.
*/
int HotaHalSetBootSettings(void)
{
UpdateInfo.index ^= 1;
return OHOS_SUCCESS;
}
/**
* @brief Restart after upgrade finish or go bootloader to upgrade.
*
* @return OHOS_SUCCESS: Success,
* Others: Failure.
*/
int HotaHalRestart(void)
{
void panic_restart(void);
panic_restart();
return OHOS_SUCCESS;
}
/**
* @brief Get partition info.
*
* You need to call this funtion in Init function, you need partition info when upgrade. \n
*
* @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise.
*
* @since 1.0
* @version 1.0
*/
const ComponentTableInfo *HotaHalGetPartitionInfo();
/**
* @brief Get public key.
*
* You need to call this funtion when verfiy sign data \n
*
* @param length Indicates pubkey len.
*
* @return Returns <b>0</b> if the operation is successful; public key.
*
* @since 1.0
* @version 1.0
*/
unsigned char *HotaHalGetPubKey(unsigned int *length)
{
if (length == NULL) {
return NULL;
}
*length = sizeof(UpdateInfo.pubKey);
return UpdateInfo.pubKey;
}
/**
* @brief get update ability.
*
* You need to call this function when update process init. \n
*
* @return Returns update abilty.
*
* @since 1.0
* @version 1.0
*/
int HotaHalGetUpdateAbility(void)
{
return NOT_SUPPORT;
}
/**
* @brief get ota package update path.
*
* You need to call this function before update process. \n
*
* @param path Indicates where ota package you place.
* @param len Indicates path len.
*
* @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise.
*
* @since 1.0
* @version 1.0
*/
int HotaHalGetOtaPkgPath(char *path, int len)
{
int ret;
if ((path == NULL) || (len == 0)) {
return OHOS_FAILURE;
}
ret = memcpy_s(path, len, "/", PATH_SEPARATE_LEN);
if (ret != 0) {
HDF_LOGE("memcpy_s fail!\r\n");
return OHOS_FAILURE;
}
return OHOS_SUCCESS;
}
/**
* @brief get update metadata.
*
* You need to call this function when update process .\n
*
* @return Returns OtaStatus if the operation is successful; returns <b>-1</b> otherwise.
*
* @since 1.0
* @version 1.0
*/
int HotaHalGetMetaData(UpdateMetaData *metaData)
{
int ret;
if (metaData == NULL) {
return OHOS_FAILURE;
}
ret = memcpy_s(metaData, sizeof(UpdateMetaData), &UpdateInfo.metaData, sizeof(UpdateMetaData));
if (ret != 0) {
HDF_LOGE("memcpy_s fail!\r\n");
return OHOS_FAILURE;
}
return OHOS_SUCCESS;
}
/**
* @brief set update metadata.
*
* You need to call this function when update process.\n
*
* @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise.
*
* @since 1.0
* @version 1.0
*/
int HotaHalSetMetaData(UpdateMetaData *metaData)
{
int ret;
if (metaData == NULL) {
return OHOS_FAILURE;
}
ret = memcpy_s(&UpdateInfo.metaData, sizeof(UpdateMetaData), metaData, sizeof(UpdateMetaData));
if (ret != 0) {
HDF_LOGE("memcpy_s fail!\r\n");
return OHOS_FAILURE;
}
return OHOS_SUCCESS;
}
/**
* @brief check whether pkgVersion is valid.
*
* You need to call this function before update process.\n
*
* @return Returns <b>1</b> if pkgVersion is valid compared to currentVersion; returns <b>0</b> otherwise.
*
* @since 1.0
* @version 1.0
*/
int HotaHalCheckVersionValid(const char *currentVersion, const char *pkgVersion, unsigned int pkgVersionLength)
{
if ((currentVersion == NULL) || (pkgVersion == NULL) || (pkgVersionLength == 0)) {
return OHOS_FAILURE;
}
return 0;
}
/**
* @brief Get partition info.
*
* You need to call this funtion in Init function, you need partition info when upgrade. \n
*
* @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise.
*
* @since 1.0
* @version 1.0
*/
const ComponentTableInfo *HotaHalGetPartitionInfo()
{
return &UpdateInfo.componentTableInfo;
}
+22
View File
@@ -0,0 +1,22 @@
# Copyright (c) 2022 OpenValley Digital Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
static_library("hal_file_static") {
sources = [
"hal_file.c",
]
include_dirs = [
"//utils/native/lite/hals/file",
"//utils/native/lite/include"
]
}
+175
View File
@@ -0,0 +1,175 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "fcntl.h"
#include "lfs.h"
#include "littlefs.h"
#include "securec.h"
#include "sys/stat.h"
#include "utils_file.h"
#define OFFSET_FD 8
static int sHalFileGetPath(char *tmpPath, const char *path)
{
char *ptr_path = path;
if (!path || !tmpPath) {
return -1;
}
for (; ptr_path[0] == '.'; ptr_path++) {
;
}
for (; ptr_path[0] == '/'; ptr_path++) {
;
}
(void)snprintf_s(tmpPath, LITTLEFS_MAX_LFN_LEN, LITTLEFS_MAX_LFN_LEN, "%s/%s", LITTLEFS_MOUNT_POINT, ptr_path);
return 0;
}
int HalFileOpen(const char *path, int oflag, int mode)
{
int fd, tflag = 0;
char tmpPath[LITTLEFS_MAX_LFN_LEN];
if (sHalFileGetPath(tmpPath, path)) {
return -1;
}
if (O_CREAT_FS == (oflag & O_CREAT_FS)) {
tflag |= O_CREAT;
}
#if O_WRONLY_FS != 0
if (O_RDWR_FS == (oflag & O_RDWR_FS)) {
tflag |= O_RDWR;
} else if (O_WRONLY_FS == (oflag & O_WRONLY_FS)) {
tflag |= O_WRONLY;
} else {
tflag |= O_RDONLY;
}
#else
if (O_RDWR_FS == (oflag & O_RDWR_FS)) {
tflag |= O_RDWR;
} else if (O_RDONLY_FS == (oflag & O_RDONLY_FS)) {
tflag |= O_RDONLY;
} else {
tflag |= O_WRONLY;
}
#endif
if (O_APPEND_FS == (oflag & O_APPEND_FS)) {
tflag |= O_APPEND;
}
if (O_EXCL_FS == (oflag & O_EXCL_FS)) {
tflag |= O_EXCL;
}
if (O_TRUNC_FS == (oflag & O_TRUNC_FS)) {
tflag |= O_TRUNC;
}
fd = _open(tmpPath, tflag);
if (fd < 0) {
return fd;
}
return fd + OFFSET_FD;
}
int HalFileClose(int fd)
{
if (fd < OFFSET_FD) {
return -1;
}
return _close(fd - OFFSET_FD);
}
int HalFileRead(int fd, char *buf, unsigned int len)
{
if (fd < OFFSET_FD) {
return -1;
}
return _read(fd - OFFSET_FD, buf, len);
}
int HalFileWrite(int fd, const char *buf, unsigned int len)
{
if (fd < OFFSET_FD) {
return -1;
}
return _write(fd - OFFSET_FD, buf, len);
}
int HalFileDelete(const char *path)
{
char tmpPath[LITTLEFS_MAX_LFN_LEN];
if (sHalFileGetPath(tmpPath, path)) {
return -1;
}
return _unlink(tmpPath);
}
int HalFileStat(const char *path, unsigned int *fileSize)
{
off_t len;
int fd;
char tmpPath[LITTLEFS_MAX_LFN_LEN];
if (sHalFileGetPath(tmpPath, path)) {
return -1;
}
fd = _open(tmpPath, O_RDONLY);
if (fd < 0) {
return -1;
}
len = _lseek(fd, 0, SEEK_END);
_close(fd);
if (fileSize) {
*fileSize = len;
}
return 0;
}
int HalFileSeek(int fd, int offset, unsigned int whence)
{
int _offset = offset;
int type = whence;
int fd_tmp = fd;
if (fd_tmp < OFFSET_FD) {
return -1;
}
switch (type) {
case SEEK_SET_FS:
type = SEEK_SET;
break;
case SEEK_CUR_FS:
type = SEEK_CUR;
break;
case SEEK_END_FS:
type = SEEK_END;
break;
default:
return -1;
}
fd_tmp -= OFFSET_FD;
if ((SEEK_SET == type) || (SEEK_CUR == type)) {
off_t len, len2;
len = _lseek(fd_tmp, 0, SEEK_CUR);
len2 = _lseek(fd_tmp, 0, SEEK_END);
if (SEEK_CUR == type) {
_offset += len;
}
if (_offset > len2) {
_lseek(fd_tmp, len, SEEK_SET);
return -1;
}
return _lseek(fd_tmp, (off_t)_offset, SEEK_SET);
}
return _lseek(fd_tmp, (off_t)_offset, type);
}
+40
View File
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __OHOS_RUN_H__
#define __OHOS_RUN_H__
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/**
* @brief 用与指定系统运行之前的程序入口函数
*
*/
#define BEFORE_OHOS_RUN(func) {void *BEFORE_OHOS_RUN_FUNC_ENTRY=func}
/**
* @brief 用与指定系统运行之后的程序入口函数
*
*/
#define OHOS_APP_RUN(func) {void *OHOS_APP_FUNC_ENTRY=func}
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __OHOS_RUN_H__ */
+130
View File
@@ -0,0 +1,130 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _TARGET_CONFIG_H
#define _TARGET_CONFIG_H
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
int esp_rom_printf(const char *, ...);
#define LOSCFG_TASK_STRUCT_EXTENSION \
UINT32 MPUSettings[1]; \
UINT16 basePriority; \
void *LocalStoragePointer[1]; \
void *LocalDelCallback[1]
void TaskDeleteExtensionHook(void *);
#define LOSCFG_TASK_DELETE_EXTENSION_HOOK(taskCB) TaskDeleteExtensionHook(taskCB)
#define LOSCFG_STACK_POINT_ALIGN_SIZE 16
#define OS_HWI_WITH_ARG 1
#define OS_TICK_INT_NUM 6
/*=============================================================================
System clock module configuration
=============================================================================*/
#define OS_SYS_CLOCK (100UL) // 160000000
#define LOSCFG_BASE_CORE_TICK_PER_SECOND OS_SYS_CLOCK // (100UL)
#define LOSCFG_BASE_CORE_TICK_HW_TIME 0
#define LOSCFG_BASE_CORE_TICK_WTIMER 1
#define LOSCFG_BASE_CORE_TICK_RESPONSE_MAX OS_SYS_CLOCK // 1600000
/*=============================================================================
Hardware interrupt module configuration
=============================================================================*/
#define LOSCFG_PLATFORM_HWI 1
#define OS_TICK_INT_NUM 6
#define LOSCFG_PLATFORM_HWI_LIMIT 32
/*=============================================================================
Task module configuration
=============================================================================*/
#define LOSCFG_BASE_CORE_TSK_LIMIT 24
#define LOSCFG_BASE_CORE_TSK_IDLE_STACK_SIZE (0x800U)
#define LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE (0x1000U)
#define LOSCFG_BASE_CORE_TSK_MIN_STACK_SIZE (256U)
#define LOSCFG_BASE_CORE_TIMESLICE 1
#define LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT 20000
/*=============================================================================
Semaphore module configuration
=============================================================================*/
#define LOSCFG_BASE_IPC_SEM 1
#define LOSCFG_BASE_IPC_SEM_LIMIT 48
/*=============================================================================
Mutex module configuration
=============================================================================*/
#define LOSCFG_BASE_IPC_MUX 1
#define LOSCFG_BASE_IPC_MUX_LIMIT 24
/*=============================================================================
Queue module configuration
=============================================================================*/
#define LOSCFG_BASE_IPC_QUEUE 1
#define LOSCFG_BASE_IPC_QUEUE_LIMIT 24
/*=============================================================================
Software timer module configuration
=============================================================================*/
#define LOSCFG_BASE_CORE_SWTMR 1
#define LOSCFG_BASE_CORE_SWTMR_ALIGN 1
#define LOSCFG_BASE_CORE_SWTMR_LIMIT 48
/*=============================================================================
Memory module configuration
=============================================================================*/
#define LOSCFG_SYS_EXTERNAL_HEAP 1
#define LOSCFG_SYS_HEAP_ADDR m_aucSysMem0
#define LOSCFG_SYS_HEAP_SIZE 0x14000UL
#define LOSCFG_MEM_MUL_POOL 1
#define OS_SYS_MEM_NUM 8
#define LOSCFG_MEM_FREE_BY_TASKID 0
#define LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK 1
#define LOSCFG_MEM_LEAKCHECK 0
#define LOSCFG_MEMORY_BESTFIT 1
#define LOSCFG_KERNEL_MEM_SLAB 0
/*=============================================================================
Exception module configuration
=============================================================================*/
#define LOSCFG_PLATFORM_EXC 0
/* =============================================================================
printf module configuration
============================================================================= */
#define LOSCFG_KERNEL_PRINTF 1
#define LOSCFG_BACKTRACE_TYPE 0
#define LOSCFG_BACKTRACE_DEPTH 4
#define LOSCFG_DEBUG_HOOK 0
#define LOS_KERNEL_TEST_NOT_SMOKE 0
/*=============================================================================
shell module configuration
=============================================================================*/
#define LOSCFG_USE_SHELL 1
#define PRINT_LEVEL LOG_DEBUG_LEVEL
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _TARGET_CONFIG_H */
+28
View File
@@ -0,0 +1,28 @@
# Copyright (c) 2022 OpenValley Digital Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//kernel/liteos_m/liteos.gni")
module_name = get_path_info(rebase_path("."), "name")
module_switch = defined(LOSCFG_FS_LITTLEFS)
kernel_module(module_name) {
sources = [
"littlefs.c",
]
}
config("public") {
include_dirs = [
".",
]
}
+140
View File
@@ -0,0 +1,140 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <dirent.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include "fcntl.h"
#include "lfs.h"
#include "los_compiler.h"
#include "los_memory.h"
#include "los_task.h"
#include "ohos_init.h"
#include "ohos_types.h"
static const char *LITTLEFS_MOUNT_POINT = "/Talkweb";
static const char TAG[] = {"Littlefs"};
#define LFS_LOG printf
#define LSF_ERROR (-1)
#include "esp_partition.h"
/* ESP32的分区类型, 0x00-0x3F系统保留分区类型,0x40-0xFE自定义分区 */
#define LITTLEFS_PARTITION_TYPE ESP_PARTITION_TYPE_DATA
/* ESP32的子分区类型,0x00-0xFE0xFF(ESP_PARTITION_SUBTYPE_ANY)所有子分区 */
#define LITTLEFS_PARTITION_SUBTYPE ESP_PARTITION_SUBTYPE_DATA_SPIFFS
/* ESP32的分区名称 */
#define LITTLEFS_PARTITION_NAME NULL
#define READ_SIZE 256 /* 最小读取字节数,所有的读取操作字节数必须是它的倍数(影响内存消耗) */
#define PROG_SIZE 256 /* 最小写入字节数,所有的写入操作字节数必须是它的倍数(影响内存消耗) */
#define BLOCK_SIZE 4096 /* 擦除块字节数,不会影响内存消耗,每个文件至少占用一个块,必须是READ_SIZE/PROG_SIZE的倍数 */
#define CACHE_SIZE 256 /* 块缓存的大小,缓存越大磁盘访问越小,性能越高,必须是READ_SIZE/PROG_SIZE的倍数,且是BLOCK_SIZE的因数 */
#define LOOKAHEAD_SIZE 16 /* 块分配预测深度,分配块时每次步进多少个块,必须为8的整数倍,对于内存消耗影响不大 */
#define BLOCK_CYCLES 16 /* 逐出元数据日志并将元数据移动到另一个块之前的擦除周期数,值越大性能越好,但磨损越不均匀,-1将禁用块级磨损均衡 */
#define BLOCK_SIZE_BIT_MOVE 10
static lfs_size_t calc_lfs_size(lfs_size_t block_count, lfs_size_t block_size)
{
return ((block_count)*(block_size))>>BLOCK_SIZE_BIT_MOVE;
}
const char *GetLittlefsMountPoint(void)
{
return LITTLEFS_MOUNT_POINT;
}
/* lfs读接口 */
static int LittlefsRead(const struct lfs_config *cfg, lfs_block_t block,
lfs_off_t off, char *buffer, lfs_size_t size)
{
return spi_flash_read((size_t)cfg->context + cfg->block_size * block + off, buffer, size);
}
/* lfs写接口 */
static int LittlefsProg(const struct lfs_config *cfg, lfs_block_t block,
lfs_off_t off, const char *buffer, lfs_size_t size)
{
return spi_flash_write((size_t)cfg->context + cfg->block_size * block + off, buffer, size);
}
/* lfs擦除接口 */
static int LittlefsErase(const struct lfs_config *cfg, lfs_block_t block)
{
return spi_flash_erase_range((size_t)cfg->context + cfg->block_size * block, cfg->block_size);
}
/* lfs同步接口 */
static int LittlefsSync(const struct lfs_config *cfg)
{
return LFS_ERR_OK;
}
/* 接口兼容 */
int __attribute__((weak)) SetDefaultMountPath(int pathNameIndex, const char *target)
{
return LOS_OK;
}
/* lfs初始化 */
static INT32 LittlefsInit(void)
{
int err = 0;
static struct lfs_config s_lfsConfig = {0}; /* lfs配置变量,必须是全局内存或静态内存 */
s_lfsConfig.read = LittlefsRead; /* lfs 读接口 */
s_lfsConfig.prog = LittlefsProg; /* lfs 写接口 */
s_lfsConfig.erase = LittlefsErase; /* lfs 擦除接口 */
s_lfsConfig.sync = LittlefsSync; /* lfs 同步接口 */
#if defined(LITTLEFS_PHYS_ADDR) && defined(BLOCK_COUNT)
s_lfsConfig.context = (void *)LITTLEFS_PHYS_ADDR;
s_lfsConfig.block_count = BLOCK_COUNT,
#else
const esp_partition_t *part;
part = esp_partition_find_first(LITTLEFS_PARTITION_TYPE, LITTLEFS_PARTITION_SUBTYPE, LITTLEFS_PARTITION_NAME);
if (!part) {
LFS_LOG("Error %s.esp_partition_find_first\n", TAG);
return LSF_ERROR;
}
s_lfsConfig.context = (void *)part->address;
s_lfsConfig.block_count = part->size / BLOCK_SIZE;
#endif
s_lfsConfig.read_size = READ_SIZE;
s_lfsConfig.prog_size = PROG_SIZE;
s_lfsConfig.block_size = BLOCK_SIZE;
s_lfsConfig.cache_size = CACHE_SIZE;
s_lfsConfig.lookahead_size = LOOKAHEAD_SIZE;
s_lfsConfig.block_cycles = BLOCK_CYCLES;
s_lfsConfig.read_buffer = NULL;
s_lfsConfig.prog_buffer = NULL;
s_lfsConfig.lookahead_buffer = NULL;
s_lfsConfig.name_max = 0;
s_lfsConfig.file_max = 0;
s_lfsConfig.attr_max = 0;
err = SetDefaultMountPath(0, LITTLEFS_MOUNT_POINT); /* 设置缺省挂载点 */
if (err != LOS_OK) {
LFS_LOG("Error %s.SetDefaultMountPath=0x%X\n", TAG, err);
return LSF_ERROR;
}
err = mount(NULL, LITTLEFS_MOUNT_POINT, "littlefs", 0, &s_lfsConfig); /* 设置挂载Littlefs */
if (err != LOS_OK) {
LFS_LOG("Error %s.mount=0x%X\n", TAG, err);
return LSF_ERROR;
}
LFS_LOG("%s.mount=%s addr=0x%X size=%dK OK!!!\n", TAG, LITTLEFS_MOUNT_POINT, (size_t)s_lfsConfig.context,
calc_lfs_size(s_lfsConfig.block_count, s_lfsConfig.block_size));
return 0;
}
SYS_SERVICE_INIT(LittlefsInit);
+33
View File
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __LITTLEFS_H_
#define __LITTLEFS_H_
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
const char *GetLittlefsMountPoint(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* __LITTLEFS_H_ */
+189
View File
@@ -0,0 +1,189 @@
# Copyright (c) 2022 OpenValley Digital Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//kernel/liteos_m/liteos.gni")
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [
"target_run.c",
"target_startup.o",
]
include_dirs = [
"//kernel/liteos_m/include",
"//kernel/liteos_m/kernel/include",
"//utils/native/lite/include",
"//utils/native/lite/memory/include",
"//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr",
"//base/hiviewdfx/hiview_lite",
"//base/hiviewdfx/hilog_lite/frameworks/mini",
"//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite",
"//drivers/framework/core/common/include/manager",
]
}
config("public") {
ESP_SDK_PATH="//device/soc/espressif/esp32/components/"
include_dirs = [
".",
"../include",
ESP_SDK_PATH+"esp_rom/include",
ESP_SDK_PATH+"esp_rom/esp32",
ESP_SDK_PATH+"esp_rom/include/esp32",
ESP_SDK_PATH+"spi_flash/include",
ESP_SDK_PATH+"spiffs/include",
ESP_SDK_PATH+"lwip",
ESP_SDK_PATH+"lwip/lwip/src/include",
ESP_SDK_PATH+"lwip/port/esp32/include",
ESP_SDK_PATH+"esp_common/include",
ESP_SDK_PATH+"driver/include",
ESP_SDK_PATH,
ESP_SDK_PATH+"xtensa/include",
ESP_SDK_PATH+"esp_system/include",
ESP_SDK_PATH+"soc/esp32/include",
ESP_SDK_PATH+"hal/include",
ESP_SDK_PATH+"hal/esp32/include",
ESP_SDK_PATH+"soc/include",
ESP_SDK_PATH+"esp_rom/include",
ESP_SDK_PATH+"freertos/include",
ESP_SDK_PATH+"freertos/port/xtensa/include",
ESP_SDK_PATH+"xtensa/esp32/include",
ESP_SDK_PATH+"esp_timer/include",
ESP_SDK_PATH+"newlib/platform_include",
ESP_SDK_PATH+"esp_hw_support/include",
ESP_SDK_PATH+"heap/include",
ESP_SDK_PATH+"log/include",
ESP_SDK_PATH+"hal/esp32/include",
ESP_SDK_PATH+"hal/include",
ESP_SDK_PATH+"spi_flash/include",
ESP_SDK_PATH+"nvs_flash/include",
]
lib_dirs = [
rebase_path(ESP_SDK_PATH+"libs"),
"$root_out_dir/libs"
]
ldflags = [
"-nostdlib",
"-ucall_user_start_cpu0",
"-Wl,--gc-sections",
"-Wl,-static",
"-uesp_app_desc",
"-Wl,--wrap=_Unwind_SetEnableExceptionFdeSorting",
"-Wl,--wrap=__register_frame_info_bases",
"-Wl,--wrap=__register_frame_info",
"-Wl,--wrap=__register_frame",
"-Wl,--wrap=__register_frame_info_table_bases",
"-Wl,--wrap=__register_frame_info_table",
"-Wl,--wrap=__register_frame_table",
"-Wl,--wrap=__deregister_frame_info_bases",
"-Wl,--wrap=__deregister_frame_info",
"-Wl,--wrap=_Unwind_Find_FDE",
"-Wl,--wrap=_Unwind_GetGR",
"-Wl,--wrap=_Unwind_GetCFA",
"-Wl,--wrap=_Unwind_GetIP",
"-Wl,--wrap=_Unwind_GetIPInfo",
"-Wl,--wrap=_Unwind_GetRegionStart",
"-Wl,--wrap=_Unwind_GetDataRelBase",
"-Wl,--wrap=_Unwind_GetTextRelBase",
"-Wl,--wrap=_Unwind_SetIP",
"-Wl,--wrap=_Unwind_SetGR",
"-Wl,--wrap=_Unwind_GetLanguageSpecificData",
"-Wl,--wrap=_Unwind_FindEnclosingFunction",
"-Wl,--wrap=_Unwind_Resume",
"-Wl,--wrap=_Unwind_RaiseException",
"-Wl,--wrap=_Unwind_DeleteException",
"-Wl,--wrap=_Unwind_ForcedUnwind",
"-Wl,--wrap=_Unwind_Resume_or_Rethrow",
"-Wl,--wrap=_Unwind_Backtrace",
"-Wl,--wrap=__cxa_call_unexpected",
"-Wl,--wrap=__gxx_personality_v0",
"-Wl,--wrap=OsMemSystemInit",
"-Wl,--wrap=LOS_MemAlloc",
"-Wl,--wrap=LOS_MemFree",
"-Wl,--wrap=LOS_MemAllocAlign",
"-Wl,--wrap=OsShellCmdFree",
# "-Wl,--wrap=_exit",
# "-Wl,--wrap=ioctl",
# "-Wl,--wrap=LOS_FsMount",
"-u__cxx_fatal_exception",
"-Tesp32_out.ld",
"-uld_include_panic_highint_hdl",
"-Tesp32.project.ld",
"-Tesp32.peripherals.ld",
# "-Tesp32.rom.ld",
"-Tesp32.rom.libgcc.ld",
# "-Tesp32.rom.syscalls.ld",
# "-Tesp32.rom.newlib-data.ld",
# "-Tesp32.rom.api.ld",
"-Tesp32.rom.tw.ld",
# "-Tesp32.rom.newlib-funcs.ld",
# "-Tesp32.rom.newlib-time.ld",
"-Wl,--wrap=longjmp",
"-Wl,--undefined=uxTopUsedPriority",
"-Wl,--wrap=mbedtls_mpi_exp_mod",
"-unewlib_include_heap_impl",
"-unewlib_include_syscalls_impl",
"-upthread_include_pthread_impl",
"-upthread_include_pthread_cond_impl",
"-upthread_include_pthread_local_storage_impl",
"-Wl,-EL",
"-fno-rtti",
]
defines = ["__XTENSA_LX6__=1"]
libs = [
"c",
"m",
"gcc",
"stdc++",
"core",
"rtc",
"net80211",
"pp",
"phy",
"xt_hal",
]
if(build_xts) {
ldflags += [
"-Wl,--whole-archive",
"-lbootstrap",
"-lbroadcast",
"-lhctest",
"-lmodule_ActsSamgrTest",
"-lmodule_ActsUtilsFileTest",
"-lmodule_ActsKvStoreTest",
"-lmodule_ActsParameterTest",
"-lmodule_ActsBootstrapTest",
"-lmodule_ActsDfxFuncTest",
"-lmodule_ActsHieventLiteTest",
"-lmodule_ActsWifiServiceTest",
# "-lmodule_ActsLwipTest",
"-lmodule_ActsWifiIotTest",
# "-lmodule_ActsDsoftbusMgrTest",
"-lhota",
"-lhal_update_static",
"-lmodule_ActsUpdaterFuncTest",
"-lhuks_test_common",
"-lmodule_ActsHuksHalFunctionTest",
"-Wl,--no-whole-archive",
]
defines += [
"CONFIG_I2C_SUPPORT",
"CONFIG_PWM_SUPPORT",
]
}
}
+37
View File
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include "los_task.h"
#define DEALY_10_TICKS 10
void *__attribute__((weak)) OHOS_APP_FUNC_ENTRY = NULL;
void *__attribute__((weak)) BEFORE_OHOS_RUN_FUNC_ENTRY = NULL;
void ohos_app_main()
{
LOS_TaskDelay(DEALY_10_TICKS);
if (OHOS_APP_FUNC_ENTRY) {
((void (*)(void)) OHOS_APP_FUNC_ENTRY)();
}
}
void before_ohos_run()
{
if (BEFORE_OHOS_RUN_FUNC_ENTRY) {
((void (*)(void)) BEFORE_OHOS_RUN_FUNC_ENTRY)();
}
}
Binary file not shown.
+33
View File
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2022 OpenValley Digital Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _TARGET_UART_H
#define _TARGET_UART_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
unsigned char UartGetc(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _TARGET_CONFIG_H */
+10
View File
@@ -0,0 +1,10 @@
{
"subsystem":"device_niobeu4",
"parts": {
"device_niobeu4": {
"module_list": [
"//device/board/openvalley/niobeu4:process_after_build"
]
}
}
}