From f7a433abad0eadbb915ec73169f66594da18bd56 Mon Sep 17 00:00:00 2001 From: fangye Date: Thu, 9 Jun 2022 10:21:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0niobeu4=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fangye --- BUILD.gn | 19 + Kconfig.liteos_m.boards | 16 + Kconfig.liteos_m.defconfig.boards | 14 + Kconfig.liteos_m.shields | 14 + LICENSE | 201 ++++ OAT.xml | 59 ++ README.en.md | 36 - README.md => README_zh.md | 4 +- niobeu4/BUILD.gn | 40 + niobeu4/Kconfig.liteos_m.board | 229 ++++ niobeu4/Kconfig.liteos_m.defconfig.board | 17 + niobeu4/liteos_m/BUILD.gn | 26 + niobeu4/liteos_m/arch/BUILD.gn | 26 + niobeu4/liteos_m/arch/los_arch_atomic.h | 32 + niobeu4/liteos_m/arch/los_arch_context.h | 77 ++ niobeu4/liteos_m/arch/los_arch_interrupt.h | 245 +++++ niobeu4/liteos_m/arch/los_arch_macro.h | 171 +++ niobeu4/liteos_m/arch/los_arch_regs.h | 172 +++ niobeu4/liteos_m/arch/los_arch_timer.h | 72 ++ niobeu4/liteos_m/arch/los_context.c | 129 +++ niobeu4/liteos_m/arch/los_interrupt.c | 82 ++ niobeu4/liteos_m/config.gni | 84 ++ niobeu4/liteos_m/drivers/BUILD.gn | 27 + niobeu4/liteos_m/drivers/adc/BUILD.gn | 24 + niobeu4/liteos_m/drivers/adc/adc.c | 104 ++ niobeu4/liteos_m/drivers/adc/adc.h | 29 + niobeu4/liteos_m/drivers/gpio/BUILD.gn | 24 + niobeu4/liteos_m/drivers/gpio/gpio.c | 164 +++ niobeu4/liteos_m/drivers/gpio/gpio.h | 29 + niobeu4/liteos_m/drivers/i2c/BUILD.gn | 26 + niobeu4/liteos_m/drivers/i2c/i2c.c | 170 +++ niobeu4/liteos_m/drivers/i2c/i2c.h | 37 + niobeu4/liteos_m/drivers/osal/BUILD.gn | 30 + niobeu4/liteos_m/drivers/osal/osal.c | 67 ++ niobeu4/liteos_m/drivers/uart/BUILD.gn | 25 + niobeu4/liteos_m/drivers/uart/uart.c | 164 +++ niobeu4/liteos_m/drivers/watchdog/BUILD.gn | 23 + niobeu4/liteos_m/drivers/watchdog/watchdog.c | 247 +++++ niobeu4/liteos_m/drivers/wifi/BUILD.gn | 44 + niobeu4/liteos_m/drivers/wifi/wifi.h | 34 + niobeu4/liteos_m/drivers/wifi/wifi_sta.c | 270 +++++ niobeu4/liteos_m/hals/BUILD.gn | 33 + niobeu4/liteos_m/hals/driver/hal_watchdog.c | 106 ++ niobeu4/liteos_m/hals/driver/hm_sys.c | 30 + .../liteos_m/hals/driver/wifi_lite/BUILD.gn | 57 + .../hals/driver/wifi_lite/wifi_device.c | 990 ++++++++++++++++++ .../hals/iot_hardware/wifiiot_lite/BUILD.gn | 33 + .../iot_hardware/wifiiot_lite/hal_iot_flash.c | 122 +++ .../iot_hardware/wifiiot_lite/hal_iot_gpio.c | 278 +++++ .../iot_hardware/wifiiot_lite/hal_iot_i2c.c | 239 +++++ .../iot_hardware/wifiiot_lite/hal_iot_pwm.c | 178 ++++ .../iot_hardware/wifiiot_lite/hal_iot_uart.c | 272 +++++ .../wifiiot_lite/hal_iot_watchdog.c | 90 ++ .../iot_hardware/wifiiot_lite/hal_lowpower.c | 56 + .../iot_hardware/wifiiot_lite/hal_reset.c | 21 + niobeu4/liteos_m/hals/libc/log.c | 127 +++ niobeu4/liteos_m/hals/libc/syscalls.c | 110 ++ niobeu4/liteos_m/hals/update/BUILD.gn | 26 + niobeu4/liteos_m/hals/update/update_adapter.c | 299 ++++++ niobeu4/liteos_m/hals/utils/file/BUILD.gn | 22 + niobeu4/liteos_m/hals/utils/file/hal_file.c | 175 ++++ niobeu4/liteos_m/include/ohos_run.h | 40 + niobeu4/liteos_m/include/target_config.h | 130 +++ niobeu4/liteos_m/littlefs/BUILD.gn | 28 + niobeu4/liteos_m/littlefs/littlefs.c | 140 +++ niobeu4/liteos_m/littlefs/littlefs.h | 33 + niobeu4/liteos_m/target/BUILD.gn | 189 ++++ niobeu4/liteos_m/target/target_run.c | 37 + niobeu4/liteos_m/target/target_startup.o | Bin 0 -> 83664 bytes niobeu4/liteos_m/target/uart.h | 33 + niobeu4/ohos.build | 10 + 71 files changed, 7170 insertions(+), 37 deletions(-) create mode 100644 BUILD.gn create mode 100644 Kconfig.liteos_m.boards create mode 100644 Kconfig.liteos_m.defconfig.boards create mode 100644 Kconfig.liteos_m.shields create mode 100644 LICENSE create mode 100644 OAT.xml delete mode 100644 README.en.md rename README.md => README_zh.md (68%) create mode 100644 niobeu4/BUILD.gn create mode 100644 niobeu4/Kconfig.liteos_m.board create mode 100644 niobeu4/Kconfig.liteos_m.defconfig.board create mode 100644 niobeu4/liteos_m/BUILD.gn create mode 100755 niobeu4/liteos_m/arch/BUILD.gn create mode 100755 niobeu4/liteos_m/arch/los_arch_atomic.h create mode 100755 niobeu4/liteos_m/arch/los_arch_context.h create mode 100755 niobeu4/liteos_m/arch/los_arch_interrupt.h create mode 100755 niobeu4/liteos_m/arch/los_arch_macro.h create mode 100755 niobeu4/liteos_m/arch/los_arch_regs.h create mode 100755 niobeu4/liteos_m/arch/los_arch_timer.h create mode 100755 niobeu4/liteos_m/arch/los_context.c create mode 100644 niobeu4/liteos_m/arch/los_interrupt.c create mode 100644 niobeu4/liteos_m/config.gni create mode 100755 niobeu4/liteos_m/drivers/BUILD.gn create mode 100644 niobeu4/liteos_m/drivers/adc/BUILD.gn create mode 100755 niobeu4/liteos_m/drivers/adc/adc.c create mode 100644 niobeu4/liteos_m/drivers/adc/adc.h create mode 100644 niobeu4/liteos_m/drivers/gpio/BUILD.gn create mode 100755 niobeu4/liteos_m/drivers/gpio/gpio.c create mode 100644 niobeu4/liteos_m/drivers/gpio/gpio.h create mode 100755 niobeu4/liteos_m/drivers/i2c/BUILD.gn create mode 100755 niobeu4/liteos_m/drivers/i2c/i2c.c create mode 100755 niobeu4/liteos_m/drivers/i2c/i2c.h create mode 100755 niobeu4/liteos_m/drivers/osal/BUILD.gn create mode 100755 niobeu4/liteos_m/drivers/osal/osal.c create mode 100755 niobeu4/liteos_m/drivers/uart/BUILD.gn create mode 100755 niobeu4/liteos_m/drivers/uart/uart.c create mode 100755 niobeu4/liteos_m/drivers/watchdog/BUILD.gn create mode 100755 niobeu4/liteos_m/drivers/watchdog/watchdog.c create mode 100644 niobeu4/liteos_m/drivers/wifi/BUILD.gn create mode 100644 niobeu4/liteos_m/drivers/wifi/wifi.h create mode 100644 niobeu4/liteos_m/drivers/wifi/wifi_sta.c create mode 100755 niobeu4/liteos_m/hals/BUILD.gn create mode 100755 niobeu4/liteos_m/hals/driver/hal_watchdog.c create mode 100755 niobeu4/liteos_m/hals/driver/hm_sys.c create mode 100755 niobeu4/liteos_m/hals/driver/wifi_lite/BUILD.gn create mode 100755 niobeu4/liteos_m/hals/driver/wifi_lite/wifi_device.c create mode 100755 niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/BUILD.gn create mode 100755 niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_flash.c create mode 100755 niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_gpio.c create mode 100755 niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_i2c.c create mode 100755 niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_pwm.c create mode 100755 niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_uart.c create mode 100755 niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_watchdog.c create mode 100755 niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_lowpower.c create mode 100755 niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_reset.c create mode 100644 niobeu4/liteos_m/hals/libc/log.c create mode 100755 niobeu4/liteos_m/hals/libc/syscalls.c create mode 100755 niobeu4/liteos_m/hals/update/BUILD.gn create mode 100755 niobeu4/liteos_m/hals/update/update_adapter.c create mode 100755 niobeu4/liteos_m/hals/utils/file/BUILD.gn create mode 100755 niobeu4/liteos_m/hals/utils/file/hal_file.c create mode 100644 niobeu4/liteos_m/include/ohos_run.h create mode 100755 niobeu4/liteos_m/include/target_config.h create mode 100755 niobeu4/liteos_m/littlefs/BUILD.gn create mode 100755 niobeu4/liteos_m/littlefs/littlefs.c create mode 100755 niobeu4/liteos_m/littlefs/littlefs.h create mode 100755 niobeu4/liteos_m/target/BUILD.gn create mode 100644 niobeu4/liteos_m/target/target_run.c create mode 100644 niobeu4/liteos_m/target/target_startup.o create mode 100755 niobeu4/liteos_m/target/uart.h create mode 100755 niobeu4/ohos.build diff --git a/BUILD.gn b/BUILD.gn new file mode 100644 index 0000000..9ed8569 --- /dev/null +++ b/BUILD.gn @@ -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" ] +} + diff --git a/Kconfig.liteos_m.boards b/Kconfig.liteos_m.boards new file mode 100644 index 0000000..c49264a --- /dev/null +++ b/Kconfig.liteos_m.boards @@ -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 diff --git a/Kconfig.liteos_m.defconfig.boards b/Kconfig.liteos_m.defconfig.boards new file mode 100644 index 0000000..fac8d1c --- /dev/null +++ b/Kconfig.liteos_m.defconfig.boards @@ -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" diff --git a/Kconfig.liteos_m.shields b/Kconfig.liteos_m.shields new file mode 100644 index 0000000..530cfc7 --- /dev/null +++ b/Kconfig.liteos_m.shields @@ -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" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..29f81d8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/OAT.xml b/OAT.xml new file mode 100644 index 0000000..499e722 --- /dev/null +++ b/OAT.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/README.en.md b/README.en.md deleted file mode 100644 index 74a89fa..0000000 --- a/README.en.md +++ /dev/null @@ -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/) diff --git a/README.md b/README_zh.md similarity index 68% rename from README.md rename to README_zh.md index b06df3b..2f88d17 100644 --- a/README.md +++ b/README_zh.md @@ -1,7 +1,9 @@ # device_board_openvalley #### 介绍 -该仓库托管湖南开鸿智谷数字产业发展有限公司Niobe系列开发板的板级配置、驱动代码及文档 +{**以下是 Gitee 平台说明,您可以替换此简介** +Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 +无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)} #### 软件架构 软件架构说明 diff --git a/niobeu4/BUILD.gn b/niobeu4/BUILD.gn new file mode 100644 index 0000000..c50ec85 --- /dev/null +++ b/niobeu4/BUILD.gn @@ -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", + ] + } +} \ No newline at end of file diff --git a/niobeu4/Kconfig.liteos_m.board b/niobeu4/Kconfig.liteos_m.board new file mode 100644 index 0000000..5cc5045 --- /dev/null +++ b/niobeu4/Kconfig.liteos_m.board @@ -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 diff --git a/niobeu4/Kconfig.liteos_m.defconfig.board b/niobeu4/Kconfig.liteos_m.defconfig.board new file mode 100644 index 0000000..beee379 --- /dev/null +++ b/niobeu4/Kconfig.liteos_m.defconfig.board @@ -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 + diff --git a/niobeu4/liteos_m/BUILD.gn b/niobeu4/liteos_m/BUILD.gn new file mode 100644 index 0000000..7fd29ac --- /dev/null +++ b/niobeu4/liteos_m/BUILD.gn @@ -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", + ] + } +} diff --git a/niobeu4/liteos_m/arch/BUILD.gn b/niobeu4/liteos_m/arch/BUILD.gn new file mode 100755 index 0000000..4e87dc5 --- /dev/null +++ b/niobeu4/liteos_m/arch/BUILD.gn @@ -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 = [ "." ] +} diff --git a/niobeu4/liteos_m/arch/los_arch_atomic.h b/niobeu4/liteos_m/arch/los_arch_atomic.h new file mode 100755 index 0000000..60e2bf0 --- /dev/null +++ b/niobeu4/liteos_m/arch/los_arch_atomic.h @@ -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 */ diff --git a/niobeu4/liteos_m/arch/los_arch_context.h b/niobeu4/liteos_m/arch/los_arch_context.h new file mode 100755 index 0000000..eb91e3e --- /dev/null +++ b/niobeu4/liteos_m/arch/los_arch_context.h @@ -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 */ diff --git a/niobeu4/liteos_m/arch/los_arch_interrupt.h b/niobeu4/liteos_m/arch/los_arch_interrupt.h new file mode 100755 index 0000000..c780174 --- /dev/null +++ b/niobeu4/liteos_m/arch/los_arch_interrupt.h @@ -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 */ diff --git a/niobeu4/liteos_m/arch/los_arch_macro.h b/niobeu4/liteos_m/arch/los_arch_macro.h new file mode 100755 index 0000000..7e758aa --- /dev/null +++ b/niobeu4/liteos_m/arch/los_arch_macro.h @@ -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 */ + diff --git a/niobeu4/liteos_m/arch/los_arch_regs.h b/niobeu4/liteos_m/arch/los_arch_regs.h new file mode 100755 index 0000000..3d9fcf2 --- /dev/null +++ b/niobeu4/liteos_m/arch/los_arch_regs.h @@ -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__ */ diff --git a/niobeu4/liteos_m/arch/los_arch_timer.h b/niobeu4/liteos_m/arch/los_arch_timer.h new file mode 100755 index 0000000..db3cb64 --- /dev/null +++ b/niobeu4/liteos_m/arch/los_arch_timer.h @@ -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 */ diff --git a/niobeu4/liteos_m/arch/los_context.c b/niobeu4/liteos_m/arch/los_context.c new file mode 100755 index 0000000..bda32fb --- /dev/null +++ b/niobeu4/liteos_m/arch/los_context.c @@ -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; +} diff --git a/niobeu4/liteos_m/arch/los_interrupt.c b/niobeu4/liteos_m/arch/los_interrupt.c new file mode 100644 index 0000000..f862776 --- /dev/null +++ b/niobeu4/liteos_m/arch/los_interrupt.c @@ -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 +#include +#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; +} \ No newline at end of file diff --git a/niobeu4/liteos_m/config.gni b/niobeu4/liteos_m/config.gni new file mode 100644 index 0000000..073497f --- /dev/null +++ b/niobeu4/liteos_m/config.gni @@ -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 = "" diff --git a/niobeu4/liteos_m/drivers/BUILD.gn b/niobeu4/liteos_m/drivers/BUILD.gn new file mode 100755 index 0000000..3dc3f9f --- /dev/null +++ b/niobeu4/liteos_m/drivers/BUILD.gn @@ -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", + ] +} + diff --git a/niobeu4/liteos_m/drivers/adc/BUILD.gn b/niobeu4/liteos_m/drivers/adc/BUILD.gn new file mode 100644 index 0000000..e17bd1b --- /dev/null +++ b/niobeu4/liteos_m/drivers/adc/BUILD.gn @@ -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 = [ "." ] +} diff --git a/niobeu4/liteos_m/drivers/adc/adc.c b/niobeu4/liteos_m/drivers/adc/adc.c new file mode 100755 index 0000000..394585a --- /dev/null +++ b/niobeu4/liteos_m/drivers/adc/adc.c @@ -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 +#include +#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; +} \ No newline at end of file diff --git a/niobeu4/liteos_m/drivers/adc/adc.h b/niobeu4/liteos_m/drivers/adc/adc.h new file mode 100644 index 0000000..2e3fcf8 --- /dev/null +++ b/niobeu4/liteos_m/drivers/adc/adc.h @@ -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 + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __ESP32_ADC_H__ */ \ No newline at end of file diff --git a/niobeu4/liteos_m/drivers/gpio/BUILD.gn b/niobeu4/liteos_m/drivers/gpio/BUILD.gn new file mode 100644 index 0000000..fcd8df6 --- /dev/null +++ b/niobeu4/liteos_m/drivers/gpio/BUILD.gn @@ -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 = [ "." ] +} diff --git a/niobeu4/liteos_m/drivers/gpio/gpio.c b/niobeu4/liteos_m/drivers/gpio/gpio.c new file mode 100755 index 0000000..6ffecc2 --- /dev/null +++ b/niobeu4/liteos_m/drivers/gpio/gpio.c @@ -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 +#include +#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; +} diff --git a/niobeu4/liteos_m/drivers/gpio/gpio.h b/niobeu4/liteos_m/drivers/gpio/gpio.h new file mode 100644 index 0000000..3bd8d7d --- /dev/null +++ b/niobeu4/liteos_m/drivers/gpio/gpio.h @@ -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 + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __ESP32_GPIO_H__ */ diff --git a/niobeu4/liteos_m/drivers/i2c/BUILD.gn b/niobeu4/liteos_m/drivers/i2c/BUILD.gn new file mode 100755 index 0000000..6ab6133 --- /dev/null +++ b/niobeu4/liteos_m/drivers/i2c/BUILD.gn @@ -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 = [ "." ] +} diff --git a/niobeu4/liteos_m/drivers/i2c/i2c.c b/niobeu4/liteos_m/drivers/i2c/i2c.c new file mode 100755 index 0000000..e853190 --- /dev/null +++ b/niobeu4/liteos_m/drivers/i2c/i2c.c @@ -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 +#include +#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; +} \ No newline at end of file diff --git a/niobeu4/liteos_m/drivers/i2c/i2c.h b/niobeu4/liteos_m/drivers/i2c/i2c.h new file mode 100755 index 0000000..ceb4637 --- /dev/null +++ b/niobeu4/liteos_m/drivers/i2c/i2c.h @@ -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 + +#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__ */ diff --git a/niobeu4/liteos_m/drivers/osal/BUILD.gn b/niobeu4/liteos_m/drivers/osal/BUILD.gn new file mode 100755 index 0000000..3b05016 --- /dev/null +++ b/niobeu4/liteos_m/drivers/osal/BUILD.gn @@ -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 = [ "." ] +} diff --git a/niobeu4/liteos_m/drivers/osal/osal.c b/niobeu4/liteos_m/drivers/osal/osal.c new file mode 100755 index 0000000..b6e7337 --- /dev/null +++ b/niobeu4/liteos_m/drivers/osal/osal.c @@ -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 +#include +#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; +} diff --git a/niobeu4/liteos_m/drivers/uart/BUILD.gn b/niobeu4/liteos_m/drivers/uart/BUILD.gn new file mode 100755 index 0000000..a19aaad --- /dev/null +++ b/niobeu4/liteos_m/drivers/uart/BUILD.gn @@ -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 = [ "." ] +} diff --git a/niobeu4/liteos_m/drivers/uart/uart.c b/niobeu4/liteos_m/drivers/uart/uart.c new file mode 100755 index 0000000..e7d4fd6 --- /dev/null +++ b/niobeu4/liteos_m/drivers/uart/uart.c @@ -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 +#include +#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); +} diff --git a/niobeu4/liteos_m/drivers/watchdog/BUILD.gn b/niobeu4/liteos_m/drivers/watchdog/BUILD.gn new file mode 100755 index 0000000..9d6bef6 --- /dev/null +++ b/niobeu4/liteos_m/drivers/watchdog/BUILD.gn @@ -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", + ] +} + diff --git a/niobeu4/liteos_m/drivers/watchdog/watchdog.c b/niobeu4/liteos_m/drivers/watchdog/watchdog.c new file mode 100755 index 0000000..ac3a2e7 --- /dev/null +++ b/niobeu4/liteos_m/drivers/watchdog/watchdog.c @@ -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 +#include +#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) +{ +} diff --git a/niobeu4/liteos_m/drivers/wifi/BUILD.gn b/niobeu4/liteos_m/drivers/wifi/BUILD.gn new file mode 100644 index 0000000..2ccc095 --- /dev/null +++ b/niobeu4/liteos_m/drivers/wifi/BUILD.gn @@ -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", + ] +} diff --git a/niobeu4/liteos_m/drivers/wifi/wifi.h b/niobeu4/liteos_m/drivers/wifi/wifi.h new file mode 100644 index 0000000..142d525 --- /dev/null +++ b/niobeu4/liteos_m/drivers/wifi/wifi.h @@ -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 + +#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__ */ \ No newline at end of file diff --git a/niobeu4/liteos_m/drivers/wifi/wifi_sta.c b/niobeu4/liteos_m/drivers/wifi/wifi_sta.c new file mode 100644 index 0000000..99df8f5 --- /dev/null +++ b/niobeu4/liteos_m/drivers/wifi/wifi_sta.c @@ -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 +#include +#include +#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; +} \ No newline at end of file diff --git a/niobeu4/liteos_m/hals/BUILD.gn b/niobeu4/liteos_m/hals/BUILD.gn new file mode 100755 index 0000000..e4059ed --- /dev/null +++ b/niobeu4/liteos_m/hals/BUILD.gn @@ -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" ] +} \ No newline at end of file diff --git a/niobeu4/liteos_m/hals/driver/hal_watchdog.c b/niobeu4/liteos_m/hals/driver/hal_watchdog.c new file mode 100755 index 0000000..6ea3f07 --- /dev/null +++ b/niobeu4/liteos_m/hals/driver/hal_watchdog.c @@ -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 + +#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(); +} diff --git a/niobeu4/liteos_m/hals/driver/hm_sys.c b/niobeu4/liteos_m/hals/driver/hm_sys.c new file mode 100755 index 0000000..fb0f4ff --- /dev/null +++ b/niobeu4/liteos_m/hals/driver/hm_sys.c @@ -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); +} diff --git a/niobeu4/liteos_m/hals/driver/wifi_lite/BUILD.gn b/niobeu4/liteos_m/hals/driver/wifi_lite/BUILD.gn new file mode 100755 index 0000000..6b3fe03 --- /dev/null +++ b/niobeu4/liteos_m/hals/driver/wifi_lite/BUILD.gn @@ -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", + ] +} diff --git a/niobeu4/liteos_m/hals/driver/wifi_lite/wifi_device.c b/niobeu4/liteos_m/hals/driver/wifi_lite/wifi_device.c new file mode 100755 index 0000000..4518955 --- /dev/null +++ b/niobeu4/liteos_m/hals/driver/wifi_lite/wifi_device.c @@ -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; +} diff --git a/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/BUILD.gn b/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/BUILD.gn new file mode 100755 index 0000000..eca08f0 --- /dev/null +++ b/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/BUILD.gn @@ -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", + ] +} diff --git a/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_flash.c b/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_flash.c new file mode 100755 index 0000000..e1940ed --- /dev/null +++ b/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_flash.c @@ -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; +} diff --git a/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_gpio.c b/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_gpio.c new file mode 100755 index 0000000..1dba30b --- /dev/null +++ b/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_gpio.c @@ -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 + +#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; +} diff --git a/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_i2c.c b/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_i2c.c new file mode 100755 index 0000000..0e03512 --- /dev/null +++ b/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_i2c.c @@ -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; +} diff --git a/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_pwm.c b/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_pwm.c new file mode 100755 index 0000000..f23ee35 --- /dev/null +++ b/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_pwm.c @@ -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 + +#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); +} diff --git a/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_uart.c b/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_uart.c new file mode 100755 index 0000000..756aea3 --- /dev/null +++ b/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_uart.c @@ -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)); +} diff --git a/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_watchdog.c b/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_watchdog.c new file mode 100755 index 0000000..e2caacf --- /dev/null +++ b/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_iot_watchdog.c @@ -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; + } +} diff --git a/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_lowpower.c b/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_lowpower.c new file mode 100755 index 0000000..35e9faf --- /dev/null +++ b/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_lowpower.c @@ -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; +} diff --git a/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_reset.c b/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_reset.c new file mode 100755 index 0000000..8fc9462 --- /dev/null +++ b/niobeu4/liteos_m/hals/iot_hardware/wifiiot_lite/hal_reset.c @@ -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(); +} \ No newline at end of file diff --git a/niobeu4/liteos_m/hals/libc/log.c b/niobeu4/liteos_m/hals/libc/log.c new file mode 100644 index 0000000..43c9ad5 --- /dev/null +++ b/niobeu4/liteos_m/hals/libc/log.c @@ -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 +#include +#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; +} diff --git a/niobeu4/liteos_m/hals/libc/syscalls.c b/niobeu4/liteos_m/hals/libc/syscalls.c new file mode 100755 index 0000000..600b338 --- /dev/null +++ b/niobeu4/liteos_m/hals/libc/syscalls.c @@ -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 +#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); + } +} diff --git a/niobeu4/liteos_m/hals/update/BUILD.gn b/niobeu4/liteos_m/hals/update/BUILD.gn new file mode 100755 index 0000000..c446f94 --- /dev/null +++ b/niobeu4/liteos_m/hals/update/BUILD.gn @@ -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", + ] +} \ No newline at end of file diff --git a/niobeu4/liteos_m/hals/update/update_adapter.c b/niobeu4/liteos_m/hals/update/update_adapter.c new file mode 100755 index 0000000..efb173d --- /dev/null +++ b/niobeu4/liteos_m/hals/update/update_adapter.c @@ -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 +#include +#include +#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 0 if the operation is successful; returns -1 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 0 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 0 if the operation is successful; returns -1 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 -1 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 0 if the operation is successful; returns -1 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 1 if pkgVersion is valid compared to currentVersion; returns 0 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 0 if the operation is successful; returns -1 otherwise. + * + * @since 1.0 + * @version 1.0 + */ +const ComponentTableInfo *HotaHalGetPartitionInfo() +{ + return &UpdateInfo.componentTableInfo; +} \ No newline at end of file diff --git a/niobeu4/liteos_m/hals/utils/file/BUILD.gn b/niobeu4/liteos_m/hals/utils/file/BUILD.gn new file mode 100755 index 0000000..de15e01 --- /dev/null +++ b/niobeu4/liteos_m/hals/utils/file/BUILD.gn @@ -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" + ] +} diff --git a/niobeu4/liteos_m/hals/utils/file/hal_file.c b/niobeu4/liteos_m/hals/utils/file/hal_file.c new file mode 100755 index 0000000..6b18fa4 --- /dev/null +++ b/niobeu4/liteos_m/hals/utils/file/hal_file.c @@ -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); +} diff --git a/niobeu4/liteos_m/include/ohos_run.h b/niobeu4/liteos_m/include/ohos_run.h new file mode 100644 index 0000000..37b61ea --- /dev/null +++ b/niobeu4/liteos_m/include/ohos_run.h @@ -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 + +#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__ */ \ No newline at end of file diff --git a/niobeu4/liteos_m/include/target_config.h b/niobeu4/liteos_m/include/target_config.h new file mode 100755 index 0000000..30f118d --- /dev/null +++ b/niobeu4/liteos_m/include/target_config.h @@ -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 */ diff --git a/niobeu4/liteos_m/littlefs/BUILD.gn b/niobeu4/liteos_m/littlefs/BUILD.gn new file mode 100755 index 0000000..fca2f90 --- /dev/null +++ b/niobeu4/liteos_m/littlefs/BUILD.gn @@ -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 = [ + ".", + ] +} \ No newline at end of file diff --git a/niobeu4/liteos_m/littlefs/littlefs.c b/niobeu4/liteos_m/littlefs/littlefs.c new file mode 100755 index 0000000..db23bca --- /dev/null +++ b/niobeu4/liteos_m/littlefs/littlefs.c @@ -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 +#include +#include +#include +#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-0xFE,0xFF(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); diff --git a/niobeu4/liteos_m/littlefs/littlefs.h b/niobeu4/liteos_m/littlefs/littlefs.h new file mode 100755 index 0000000..debc23a --- /dev/null +++ b/niobeu4/liteos_m/littlefs/littlefs.h @@ -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_ */ diff --git a/niobeu4/liteos_m/target/BUILD.gn b/niobeu4/liteos_m/target/BUILD.gn new file mode 100755 index 0000000..ea81d7a --- /dev/null +++ b/niobeu4/liteos_m/target/BUILD.gn @@ -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", + ] + } +} diff --git a/niobeu4/liteos_m/target/target_run.c b/niobeu4/liteos_m/target/target_run.c new file mode 100644 index 0000000..32c21a3 --- /dev/null +++ b/niobeu4/liteos_m/target/target_run.c @@ -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 +#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)(); + } +} \ No newline at end of file diff --git a/niobeu4/liteos_m/target/target_startup.o b/niobeu4/liteos_m/target/target_startup.o new file mode 100644 index 0000000000000000000000000000000000000000..e397bfcb8de0461a786afb9618d1d1dc768ceaf8 GIT binary patch literal 83664 zcmeF4dwf*Yx%c;;37C-4hA?74)F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;DXyQxflcFYW*&biq}$l^&T&A%UhsI`C0!eI(O4&q^Z!R(J9LVX<;p)i zN8QLAbrW;cy$v0GRbSCR{YM258U5{FEZ)=2lXi%TL1t6 literal 0 HcmV?d00001 diff --git a/niobeu4/liteos_m/target/uart.h b/niobeu4/liteos_m/target/uart.h new file mode 100755 index 0000000..8c29ca2 --- /dev/null +++ b/niobeu4/liteos_m/target/uart.h @@ -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 */ diff --git a/niobeu4/ohos.build b/niobeu4/ohos.build new file mode 100755 index 0000000..c48488b --- /dev/null +++ b/niobeu4/ohos.build @@ -0,0 +1,10 @@ +{ + "subsystem":"device_niobeu4", + "parts": { + "device_niobeu4": { + "module_list": [ + "//device/board/openvalley/niobeu4:process_after_build" + ] + } + } +}