update OpenHarmony 3.0 LTS
This commit is contained in:
parent
0953469eb5
commit
bf36baa0e3
177
LICENSE
177
LICENSE
|
@ -1 +1,176 @@
|
|||
Please fill the license file.
|
||||
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
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
## 一、拓维信息Niobe开发板介绍
|
||||
|
||||
拓维Niobe开发板是一块专门基于OpenHarmony 2.2系统设计的开发板,板载高度集成了2.4GHz WLAN SoC芯片Hi3861,搭配电池充电基板、NFC板、OLED显示板、环境检测板、LED灯板、人体感应板、6轴传感器板、马达板、实时时钟板等,标准接口可扩展智能环境检测、智能灯带、智能安防、智能烟感等案例。
|
||||
拓维Niobe开发板是一块专门基于OpenHarmony 3.0LTS版本设计的开发板,板载高度集成了2.4GHz WLAN SoC芯片Hi3861,搭配电池充电基板、NFC板、OLED显示板、环境检测板、LED灯板、人体感应板、6轴传感器板、马达板、实时时钟板等,标准接口可扩展智能环境检测、智能灯带、智能安防、智能烟感等案例。
|
||||
|
||||
- 主控为WiFi SOC Hi3861,160MHz主频,SRAM 352KB、ROM 288KB、2M Flash。
|
||||
- 一根TypeC USB线,即可实现供电、下载、调试等多种功能。
|
||||
|
|
|
@ -15,7 +15,7 @@ import("//build/lite/config/component/lite_component.gni")
|
|||
|
||||
lite_component("app") {
|
||||
features = [
|
||||
"TW001_OS_helloworld:helloworld",
|
||||
# "TW001_OS_helloworld:helloworld",
|
||||
# "TW002_OS_thread:os_thread_example",
|
||||
# "TW003_OS_timer:os_timer_example",
|
||||
# "TW004_OS_event:os_event_example",
|
||||
|
@ -31,7 +31,7 @@ lite_component("app") {
|
|||
# "TW201_Module_oled:module_oled_example",
|
||||
# "TW202_Module_traffic_light:module_traffic_light_example",
|
||||
# "TW203_Module_tricolor_light:module_tricolor_light_example",
|
||||
# "TW204_Module_enviroment:module_enviroment_example",
|
||||
"TW204_Module_enviroment:module_enviroment_example",
|
||||
# "TW205_Module_motor:module_motor_example",
|
||||
# "TW207_Module_gyro:module_gyro_example",
|
||||
# "TW208_Module_JYRTC:module_JYRTC_example",
|
||||
|
|
|
@ -0,0 +1,176 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
|
@ -12,11 +12,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
static_library("helloworld"){
|
||||
sources =[
|
||||
sources = [
|
||||
"hello_world.c"
|
||||
]
|
||||
|
||||
include_dirs =[
|
||||
"//utils/native/liteos/include"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -12,12 +12,11 @@
|
|||
# limitations under the License.
|
||||
|
||||
static_library("os_thread_example"){
|
||||
sources =[
|
||||
sources = [
|
||||
"os_thread_example.c"
|
||||
]
|
||||
|
||||
include_dirs =[
|
||||
"//utils/native/liteos/include"
|
||||
"//kernel/liteos_m/components/cmsis/2.0",
|
||||
include_dirs = [
|
||||
"//third_party/cmsis/CMSIS/RTOS2/Include"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -12,12 +12,11 @@
|
|||
# limitations under the License.
|
||||
|
||||
static_library("os_timer_example"){
|
||||
sources =[
|
||||
sources = [
|
||||
"os_timer_example.c"
|
||||
]
|
||||
|
||||
include_dirs =[
|
||||
"//utils/native/liteos/include"
|
||||
"//kernel/liteos_m/components/cmsis/2.0",
|
||||
include_dirs = [
|
||||
"//third_party/cmsis/CMSIS/RTOS2/Include"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -90,4 +90,5 @@ static void OS_Timer_example(void)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
APP_FEATURE_INIT(OS_Timer_example);
|
||||
|
|
|
@ -12,12 +12,11 @@
|
|||
# limitations under the License.
|
||||
|
||||
static_library("os_event_example"){
|
||||
sources =[
|
||||
sources = [
|
||||
"os_event_example.c"
|
||||
]
|
||||
|
||||
include_dirs =[
|
||||
"//utils/native/liteos/include"
|
||||
"//kernel/liteos_m/components/cmsis/2.0",
|
||||
include_dirs = [
|
||||
"//third_party/cmsis/CMSIS/RTOS2/Include"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -165,6 +165,7 @@ static void OS_Event_example(void)
|
|||
printf("Falied to create Thread_EventSender!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
attr.name = "Thread_EventReceiver";
|
||||
if (osThreadNew(OS_Thread_EventReceiver, NULL, &attr) == NULL)
|
||||
{
|
||||
|
|
|
@ -106,6 +106,7 @@ static void OS_Event_example(void)
|
|||
printf("Falied to create Thread_EventSender!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
attr.name = "Thread_EventReceiver";
|
||||
if (osThreadNew(OS_Thread_EventReceiver, NULL, &attr) == NULL)
|
||||
{
|
||||
|
|
|
@ -12,12 +12,11 @@
|
|||
# limitations under the License.
|
||||
|
||||
static_library("mutex_example"){
|
||||
sources =[
|
||||
sources = [
|
||||
"os_mutex_example.c"
|
||||
]
|
||||
|
||||
include_dirs =[
|
||||
"//utils/native/liteos/include"
|
||||
"//kernel/liteos_m/kal/cmsis",
|
||||
include_dirs = [
|
||||
"//third_party/cmsis/CMSIS/RTOS2/Include"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -83,71 +83,73 @@ osMutexRelease (osMutexId_t mutex_id);
|
|||
```c
|
||||
void firstThread(void)
|
||||
{
|
||||
osDelay(100U);
|
||||
for(i=0;i<3;i++)
|
||||
{
|
||||
osMutexAcquire(mutex_id, osWaitForever);
|
||||
printf("firstThread is Acquire.\r\n");
|
||||
osDelay(200U);
|
||||
osMutexRelease(mutex_id);
|
||||
}
|
||||
osDelay(100U);
|
||||
while(1)
|
||||
{
|
||||
osMutexAcquire(mutex_id, osWaitForever);
|
||||
printf("firstThread is Acquire.\r\n");
|
||||
osDelay(100U);
|
||||
osMutexRelease(mutex_id);
|
||||
}
|
||||
}
|
||||
|
||||
void twoThread(void)
|
||||
{
|
||||
osDelay(100U);
|
||||
for(i=0;i<3;i++)
|
||||
{
|
||||
printf("twoThread is Acquire.\r\n");
|
||||
osDelay(50U);
|
||||
}
|
||||
osDelay(100U);
|
||||
while(1)
|
||||
{
|
||||
printf("twoThread is Acquire.\r\n");
|
||||
osDelay(100U);
|
||||
}
|
||||
}
|
||||
|
||||
void threeThread(void)
|
||||
{
|
||||
osDelay(100U);
|
||||
for(i=0;i<3;i++)
|
||||
{
|
||||
osMutexAcquire(mutex_id, osWaitForever);
|
||||
printf("threeThread is Acquire.\r\n");
|
||||
osDelay(100U);
|
||||
osMutexRelease(mutex_id);
|
||||
}
|
||||
while(1)
|
||||
{
|
||||
osMutexAcquire(mutex_id, osWaitForever);
|
||||
printf("threeThread is Acquire.\r\n");
|
||||
osDelay(300U);
|
||||
osMutexRelease(mutex_id);
|
||||
}
|
||||
}
|
||||
|
||||
void os_mutex_example(void)
|
||||
{
|
||||
osThreadAttr_t attr;
|
||||
osThreadAttr_t attr;
|
||||
|
||||
attr.attr_bits = 0U;
|
||||
attr.cb_mem = NULL;
|
||||
attr.cb_size = 0U;
|
||||
attr.stack_mem = NULL;
|
||||
attr.stack_size = 1024 * 4;
|
||||
attr.attr_bits = 0U;
|
||||
attr.cb_mem = NULL;
|
||||
attr.cb_size = 0U;
|
||||
attr.stack_mem = NULL;
|
||||
attr.stack_size = 1024 * 4;
|
||||
|
||||
attr.name = "firstThread";
|
||||
attr.priority = 0;
|
||||
if (osThreadNew((osThreadFunc_t)firstThread, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("create firstThread failed!\n");
|
||||
}
|
||||
attr.name = "twoThread";
|
||||
attr.priority = 1;
|
||||
if (osThreadNew((osThreadFunc_t)twoThread, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("create twoThread failed!\n");
|
||||
}
|
||||
attr.name = "threeThread";
|
||||
attr.priority = 2;
|
||||
if (osThreadNew((osThreadFunc_t)threeThread, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("create threeThread failed!\n");
|
||||
}
|
||||
mutex_id = osMutexNew(NULL);
|
||||
if (mutex_id == NULL)
|
||||
{
|
||||
printf("create Mutex failed!\n");
|
||||
}
|
||||
attr.name = "firstThread";
|
||||
attr.priority = 26;
|
||||
if (osThreadNew((osThreadFunc_t)firstThread, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("create firstThread failed!\n");
|
||||
}
|
||||
|
||||
attr.name = "twoThread";
|
||||
attr.priority = 25;
|
||||
if (osThreadNew((osThreadFunc_t)twoThread, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("create twoThread failed!\n");
|
||||
}
|
||||
|
||||
attr.name = "threeThread";
|
||||
attr.priority = 24;
|
||||
if (osThreadNew((osThreadFunc_t)threeThread, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("create threeThread failed!\n");
|
||||
}
|
||||
|
||||
mutex_id = osMutexNew(NULL);
|
||||
if (mutex_id == NULL)
|
||||
{
|
||||
printf("create Mutex failed!\n");
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
|
|
@ -21,66 +21,76 @@
|
|||
#include "cmsis_os2.h"
|
||||
|
||||
osMutexId_t mutex_id;
|
||||
int i;
|
||||
|
||||
void firstThread(void)
|
||||
{
|
||||
osDelay(100U);
|
||||
osMutexAcquire(mutex_id, osWaitForever);
|
||||
printf("firstThread is Acquire.\r\n");
|
||||
osDelay(200U);
|
||||
osMutexRelease(mutex_id);
|
||||
osDelay(100U);
|
||||
while(1)
|
||||
{
|
||||
osMutexAcquire(mutex_id, osWaitForever);
|
||||
printf("firstThread is Acquire.\r\n");
|
||||
osDelay(100U);
|
||||
osMutexRelease(mutex_id);
|
||||
}
|
||||
}
|
||||
|
||||
void twoThread(void)
|
||||
{
|
||||
osDelay(100U);
|
||||
printf("twoThread is Acquire.\r\n");
|
||||
osDelay(50U);
|
||||
osDelay(100U);
|
||||
while(1)
|
||||
{
|
||||
printf("twoThread is Acquire.\r\n");
|
||||
osDelay(100U);
|
||||
}
|
||||
}
|
||||
|
||||
void threeThread(void)
|
||||
{
|
||||
osDelay(100U);
|
||||
osMutexAcquire(mutex_id, osWaitForever);
|
||||
printf("threeThread is Acquire.\r\n");
|
||||
osDelay(100U);
|
||||
osMutexRelease(mutex_id);
|
||||
while(1)
|
||||
{
|
||||
osMutexAcquire(mutex_id, osWaitForever);
|
||||
printf("threeThread is Acquire.\r\n");
|
||||
osDelay(300U);
|
||||
osMutexRelease(mutex_id);
|
||||
}
|
||||
}
|
||||
|
||||
void os_mutex_example(void)
|
||||
{
|
||||
osThreadAttr_t attr;
|
||||
osThreadAttr_t attr;
|
||||
|
||||
attr.attr_bits = 0U;
|
||||
attr.cb_mem = NULL;
|
||||
attr.cb_size = 0U;
|
||||
attr.stack_mem = NULL;
|
||||
attr.stack_size = 1024 * 4;
|
||||
attr.attr_bits = 0U;
|
||||
attr.cb_mem = NULL;
|
||||
attr.cb_size = 0U;
|
||||
attr.stack_mem = NULL;
|
||||
attr.stack_size = 1024 * 4;
|
||||
|
||||
attr.name = "firstThread";
|
||||
attr.priority = 0;
|
||||
if (osThreadNew((osThreadFunc_t)firstThread, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("create firstThread failed!\n");
|
||||
}
|
||||
attr.name = "twoThread";
|
||||
attr.priority = 1;
|
||||
if (osThreadNew((osThreadFunc_t)twoThread, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("create twoThread failed!\n");
|
||||
}
|
||||
attr.name = "threeThread";
|
||||
attr.priority = 2;
|
||||
if (osThreadNew((osThreadFunc_t)threeThread, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("create threeThread failed!\n");
|
||||
}
|
||||
mutex_id = osMutexNew(NULL);
|
||||
if (mutex_id == NULL)
|
||||
{
|
||||
printf("create Mutex failed!\n");
|
||||
}
|
||||
attr.name = "firstThread";
|
||||
attr.priority = 26;
|
||||
if (osThreadNew((osThreadFunc_t)firstThread, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("create firstThread failed!\n");
|
||||
}
|
||||
|
||||
attr.name = "twoThread";
|
||||
attr.priority = 25;
|
||||
if (osThreadNew((osThreadFunc_t)twoThread, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("create twoThread failed!\n");
|
||||
}
|
||||
|
||||
attr.name = "threeThread";
|
||||
attr.priority = 24;
|
||||
if (osThreadNew((osThreadFunc_t)threeThread, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("create threeThread failed!\n");
|
||||
}
|
||||
|
||||
mutex_id = osMutexNew(NULL);
|
||||
if (mutex_id == NULL)
|
||||
{
|
||||
printf("create Mutex failed!\n");
|
||||
}
|
||||
}
|
||||
|
||||
APP_FEATURE_INIT(os_mutex_example);
|
||||
|
|
|
@ -12,12 +12,11 @@
|
|||
# limitations under the License.
|
||||
|
||||
static_library("semp_example"){
|
||||
sources =[
|
||||
sources = [
|
||||
"os_semp_example.c"
|
||||
]
|
||||
|
||||
include_dirs =[
|
||||
"//utils/native/liteos/include"
|
||||
"//kernel/liteos_m/kal/cmsis",
|
||||
include_dirs = [
|
||||
"//third_party/cmsis/CMSIS/RTOS2/Include"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -90,17 +90,22 @@ osStatus_t osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout)
|
|||
```c
|
||||
void Thread_Semp1(void)
|
||||
{
|
||||
osSemaphoreRelease(sem1);
|
||||
|
||||
printf("Thread_Semp1 Release Semap \n");
|
||||
osDelay(100);
|
||||
while(1)
|
||||
{
|
||||
osSemaphoreRelease(sem1);
|
||||
printf("Thread_Semp1 Release Semap \n");
|
||||
osDelay(200U);
|
||||
}
|
||||
}
|
||||
|
||||
void Thread_Semp2(void)
|
||||
{
|
||||
osSemaphoreAcquire(sem1, osWaitForever);
|
||||
|
||||
printf("Thread_Semp2 get Semap \n");
|
||||
osDelay(200);
|
||||
while(1)
|
||||
{
|
||||
osSemaphoreAcquire(sem1, osWaitForever);
|
||||
printf("Thread_Semp2 get Semap \n");
|
||||
osDelay(100U);
|
||||
}
|
||||
}
|
||||
|
||||
void semp_example(void)
|
||||
|
@ -119,11 +124,13 @@ void semp_example(void)
|
|||
{
|
||||
printf("create Thread_Semp1 failed!\n");
|
||||
}
|
||||
|
||||
attr.name = "Thread_Semp2";
|
||||
if (osThreadNew((osThreadFunc_t)Thread_Semp2, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("create Thread_Semp2 failed!\n");
|
||||
}
|
||||
|
||||
sem1 = osSemaphoreNew(3, 0, NULL);
|
||||
if (sem1 == NULL)
|
||||
{
|
||||
|
|
|
@ -24,17 +24,22 @@ osSemaphoreId_t sem1;
|
|||
|
||||
void Thread_Semp1(void)
|
||||
{
|
||||
osSemaphoreRelease(sem1);
|
||||
|
||||
printf("Thread_Semp1 Release Semap \n");
|
||||
osDelay(100);
|
||||
while(1)
|
||||
{
|
||||
osSemaphoreRelease(sem1);
|
||||
printf("Thread_Semp1 Release Semap \n");
|
||||
osDelay(200U);
|
||||
}
|
||||
}
|
||||
|
||||
void Thread_Semp2(void)
|
||||
{
|
||||
osSemaphoreAcquire(sem1, osWaitForever);
|
||||
|
||||
printf("Thread_Semp2 get Semap \n");
|
||||
osDelay(200);
|
||||
while(1)
|
||||
{
|
||||
osSemaphoreAcquire(sem1, osWaitForever);
|
||||
printf("Thread_Semp2 get Semap \n");
|
||||
osDelay(100U);
|
||||
}
|
||||
}
|
||||
|
||||
void semp_example(void)
|
||||
|
@ -53,15 +58,18 @@ void semp_example(void)
|
|||
{
|
||||
printf("create Thread_Semp1 failed!\n");
|
||||
}
|
||||
|
||||
attr.name = "Thread_Semp2";
|
||||
if (osThreadNew((osThreadFunc_t)Thread_Semp2, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("create Thread_Semp2 failed!\n");
|
||||
}
|
||||
|
||||
sem1 = osSemaphoreNew(3, 0, NULL);
|
||||
if (sem1 == NULL)
|
||||
{
|
||||
printf("Semp1 create failed!\n");
|
||||
}
|
||||
}
|
||||
|
||||
APP_FEATURE_INIT(semp_example);
|
|
@ -12,12 +12,11 @@
|
|||
# limitations under the License.
|
||||
|
||||
static_library("Msg_example"){
|
||||
sources =[
|
||||
sources = [
|
||||
"os_message_example.c"
|
||||
]
|
||||
|
||||
include_dirs =[
|
||||
"//utils/native/liteos/include"
|
||||
"//kernel/liteos_m/kal/cmsis",
|
||||
include_dirs = [
|
||||
"//third_party/cmsis/CMSIS/RTOS2/Include"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -94,58 +94,59 @@ osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id,void *msg_ptr,uint8_t *ms
|
|||
```c
|
||||
void Thread_MsgQueue1(void *arg)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
osMessageQueuePut(MsgQueue, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0], 0U, 0U);
|
||||
//suspend thread
|
||||
osThreadYield();
|
||||
osDelay(100);
|
||||
}
|
||||
while (1)
|
||||
{
|
||||
osMessageQueuePut(MsgQueue, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0], 0U, 0U);
|
||||
//suspend thread
|
||||
osThreadYield();
|
||||
osDelay(100);
|
||||
}
|
||||
}
|
||||
|
||||
void Thread_MsgQueue2(void *arg)
|
||||
{
|
||||
osStatus_t status;
|
||||
osStatus_t status;
|
||||
|
||||
while (1)
|
||||
{
|
||||
//wait for message
|
||||
status = osMessageQueueGet(MsgQueue,g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0], NULL, 0U);
|
||||
if (status == osOK)
|
||||
{
|
||||
printf("Thread_MsgQueue2 Get msg:%s\n", g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0]);
|
||||
}
|
||||
}
|
||||
while (1)
|
||||
{
|
||||
//wait for message
|
||||
status = osMessageQueueGet(MsgQueue, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0], NULL, 0U);
|
||||
if (status == osOK)
|
||||
{
|
||||
printf("Thread_MsgQueue2 Get msg:%s\n", g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void Msg_example(void)
|
||||
{
|
||||
|
||||
MsgQueue = osMessageQueueNew(10, 50, NULL);
|
||||
if (MsgQueue == NULL)
|
||||
{
|
||||
printf("create Message Queue failed!\n");
|
||||
}
|
||||
MsgQueue = osMessageQueueNew(10, 50, NULL);
|
||||
if (MsgQueue == NULL)
|
||||
{
|
||||
printf("create Message Queue failed!\n");
|
||||
}
|
||||
|
||||
osThreadAttr_t attr;
|
||||
osThreadAttr_t attr;
|
||||
|
||||
attr.attr_bits = 0U;
|
||||
attr.cb_mem = NULL;
|
||||
attr.cb_size = 0U;
|
||||
attr.stack_mem = NULL;
|
||||
attr.stack_size = 1024 * 10;
|
||||
attr.priority = 10;
|
||||
attr.attr_bits = 0U;
|
||||
attr.cb_mem = NULL;
|
||||
attr.cb_size = 0U;
|
||||
attr.stack_mem = NULL;
|
||||
attr.stack_size = 1024 * 10;
|
||||
attr.priority = 10;
|
||||
|
||||
attr.name = "Thread_MsgQueue1";
|
||||
if (osThreadNew(Thread_MsgQueue1, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("create Thread_MsgQueue1 failed!\n");
|
||||
}
|
||||
attr.name = "Thread_MsgQueue2";
|
||||
if (osThreadNew(Thread_MsgQueue2, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("create Thread_MsgQueue2 failed!\n");
|
||||
}
|
||||
attr.name = "Thread_MsgQueue1";
|
||||
if (osThreadNew(Thread_MsgQueue1, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("create Thread_MsgQueue1 failed!\n");
|
||||
}
|
||||
|
||||
attr.name = "Thread_MsgQueue2";
|
||||
if (osThreadNew(Thread_MsgQueue2, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("create Thread_MsgQueue2 failed!\n");
|
||||
}
|
||||
}
|
||||
|
||||
APP_FEATURE_INIT(Msg_example);
|
||||
|
|
|
@ -24,63 +24,61 @@
|
|||
#define MSGQUEUE_COUNT_INDEX_2 2
|
||||
static char *g_cmsisMessageInfo[] = {"msg1", "msg2", "msg3", "msg4", "msg5", "msg6", "msg7", "msg8"};
|
||||
|
||||
//message queue id
|
||||
osMessageQueueId_t MsgQueue;
|
||||
|
||||
void Thread_MsgQueue1(void *arg)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
osMessageQueuePut(MsgQueue, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0], 0U, 0U);
|
||||
//suspend thread
|
||||
osThreadYield();
|
||||
osDelay(100);
|
||||
}
|
||||
while (1)
|
||||
{
|
||||
osMessageQueuePut(MsgQueue, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0], 0U, 0U);
|
||||
osThreadYield();
|
||||
osDelay(100);
|
||||
}
|
||||
}
|
||||
|
||||
void Thread_MsgQueue2(void *arg)
|
||||
{
|
||||
osStatus_t status;
|
||||
osStatus_t status;
|
||||
|
||||
while (1)
|
||||
{
|
||||
//wait for message
|
||||
status = osMessageQueueGet(MsgQueue,g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0], NULL, 0U);
|
||||
if (status == osOK)
|
||||
{
|
||||
printf("Thread_MsgQueue2 Get msg:%s\n", g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0]);
|
||||
}
|
||||
}
|
||||
while (1)
|
||||
{
|
||||
//wait for message
|
||||
status = osMessageQueueGet(MsgQueue, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0], NULL, 0U);
|
||||
if (status == osOK)
|
||||
{
|
||||
printf("Thread_MsgQueue2 Get msg: %s\n", g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void Msg_example(void)
|
||||
{
|
||||
MsgQueue = osMessageQueueNew(10, 50, NULL);
|
||||
if (MsgQueue == NULL)
|
||||
{
|
||||
printf("create Message Queue failed!\n");
|
||||
}
|
||||
|
||||
MsgQueue = osMessageQueueNew(10, 50, NULL);
|
||||
if (MsgQueue == NULL)
|
||||
{
|
||||
printf("create Message Queue failed!\n");
|
||||
}
|
||||
osThreadAttr_t attr;
|
||||
|
||||
osThreadAttr_t attr;
|
||||
attr.attr_bits = 0U;
|
||||
attr.cb_mem = NULL;
|
||||
attr.cb_size = 0U;
|
||||
attr.stack_mem = NULL;
|
||||
attr.stack_size = 1024 * 10;
|
||||
attr.priority = 25;
|
||||
|
||||
attr.attr_bits = 0U;
|
||||
attr.cb_mem = NULL;
|
||||
attr.cb_size = 0U;
|
||||
attr.stack_mem = NULL;
|
||||
attr.stack_size = 1024 * 10;
|
||||
attr.priority = 10;
|
||||
attr.name = "Thread_MsgQueue1";
|
||||
if (osThreadNew(Thread_MsgQueue1, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("create Thread_MsgQueue1 failed!\n");
|
||||
}
|
||||
|
||||
attr.name = "Thread_MsgQueue1";
|
||||
if (osThreadNew(Thread_MsgQueue1, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("create Thread_MsgQueue1 failed!\n");
|
||||
}
|
||||
attr.name = "Thread_MsgQueue2";
|
||||
if (osThreadNew(Thread_MsgQueue2, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("create Thread_MsgQueue2 failed!\n");
|
||||
}
|
||||
attr.name = "Thread_MsgQueue2";
|
||||
if (osThreadNew(Thread_MsgQueue2, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("create Thread_MsgQueue2 failed!\n");
|
||||
}
|
||||
}
|
||||
|
||||
APP_FEATURE_INIT(Msg_example);
|
||||
|
|
|
@ -18,8 +18,7 @@ static_library("gpio_led_example") {
|
|||
|
||||
include_dirs = [
|
||||
"//utils/native/lite/include",
|
||||
"//kernel/liteos_m/components/cmsis/2.0",
|
||||
"//third_party/cmsis/CMSIS/RTOS2/Include",
|
||||
"//base/iot_hardware/peripheral/interfaces/kits",
|
||||
"//device/talkweb/niobe/sdk_liteos/include/",
|
||||
]
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ static void *LedLightTask(const char *arg)
|
|||
printf("-----entry gpio demo -----\r\n");
|
||||
|
||||
IoTGpioInit(IOT_GPIO_IO_GPIO_9);
|
||||
IotIoSetFunc(IOT_GPIO_IO_GPIO_9, HI_IO_FUNC_GPIO_9_GPIO);
|
||||
IoTIoSetFunc(IOT_GPIO_IO_GPIO_9, IOT_IO_FUNC_GPIO_9_GPIO);
|
||||
IoTGpioSetDir(IOT_GPIO_IO_GPIO_9, IOT_GPIO_DIR_OUT);
|
||||
|
||||
while (1)
|
||||
|
|
|
@ -12,14 +12,13 @@
|
|||
# limitations under the License.
|
||||
|
||||
static_library("exti_key_example"){
|
||||
sources =[
|
||||
sources = [
|
||||
"exti_example.c"
|
||||
]
|
||||
|
||||
include_dirs =[
|
||||
include_dirs = [
|
||||
"//utils/native/lite/include",
|
||||
"//kernel/liteos_m/components/cmsis/2.0",
|
||||
"//third_party/cmsis/CMSIS/RTOS2/Include",
|
||||
"//base/iot_hardware/peripheral/interfaces/kits",
|
||||
"//device/talkweb/niobe/sdk_liteos/include/",
|
||||
]
|
||||
}
|
||||
|
|
|
@ -65,14 +65,14 @@ static void *ClickKeyTask(const char *arg)
|
|||
printf("----- gpio isr demo -----\r\n");
|
||||
|
||||
IoTGpioInit(IOT_GPIO_IO_GPIO_9);
|
||||
IotIoSetFunc(IOT_GPIO_IO_GPIO_9, HI_IO_FUNC_GPIO_9_GPIO);
|
||||
IoTIoSetFunc(IOT_GPIO_IO_GPIO_9, HI_IO_FUNC_GPIO_9_GPIO);
|
||||
IoTGpioSetDir(IOT_GPIO_IO_GPIO_9, IOT_GPIO_DIR_OUT);
|
||||
IoTGpioSetOutputVal(IOT_GPIO_IO_GPIO_9, IOT_GPIO_VALUE0);
|
||||
|
||||
//初始化GPIO5引脚
|
||||
IoTGpioInit(IOT_GPIO_IO_GPIO_5);
|
||||
IotIoSetFunc(IOT_GPIO_IO_GPIO_5, HI_IO_FUNC_GPIO_5_GPIO);
|
||||
IotIoSetPull(IOT_GPIO_IO_GPIO_5, IOT_IO_PULL_UP);
|
||||
IoTIoSetFunc(IOT_GPIO_IO_GPIO_5, HI_IO_FUNC_GPIO_5_GPIO);
|
||||
IoTIoSetPull(IOT_GPIO_IO_GPIO_5, IOT_IO_PULL_UP);
|
||||
IoTGpioSetDir(IOT_GPIO_IO_GPIO_5, IOT_GPIO_DIR_IN);
|
||||
|
||||
//设置GPIO5中断
|
||||
|
|
|
@ -54,14 +54,14 @@ static void *ClickKeyTask(const char *arg)
|
|||
printf("----- gpio isr demo -----\r\n");
|
||||
|
||||
IoTGpioInit(IOT_GPIO_IO_GPIO_9);
|
||||
IotIoSetFunc(IOT_GPIO_IO_GPIO_9, HI_IO_FUNC_GPIO_9_GPIO);
|
||||
IoTIoSetFunc(IOT_GPIO_IO_GPIO_9, IOT_IO_FUNC_GPIO_9_GPIO);
|
||||
IoTGpioSetDir(IOT_GPIO_IO_GPIO_9, IOT_GPIO_DIR_OUT);
|
||||
IoTGpioSetOutputVal(IOT_GPIO_IO_GPIO_9, IOT_GPIO_VALUE0);
|
||||
|
||||
//初始化GPIO5引脚
|
||||
IoTGpioInit(IOT_GPIO_IO_GPIO_5);
|
||||
IotIoSetFunc(IOT_GPIO_IO_GPIO_5, HI_IO_FUNC_GPIO_5_GPIO);
|
||||
IotIoSetPull(IOT_GPIO_IO_GPIO_5, IOT_IO_PULL_UP);
|
||||
IoTIoSetFunc(IOT_GPIO_IO_GPIO_5, IOT_IO_FUNC_GPIO_5_GPIO);
|
||||
IoTIoSetPull(IOT_GPIO_IO_GPIO_5, IOT_IO_PULL_UP);
|
||||
IoTGpioSetDir(IOT_GPIO_IO_GPIO_5, IOT_GPIO_DIR_IN);
|
||||
|
||||
//设置GPIO5中断
|
||||
|
|
|
@ -12,14 +12,13 @@
|
|||
# limitations under the License.
|
||||
|
||||
static_library("pwm_led_example"){
|
||||
sources =[
|
||||
sources = [
|
||||
"pwm_led_example.c"
|
||||
]
|
||||
|
||||
include_dirs =[
|
||||
include_dirs = [
|
||||
"//utils/native/lite/include",
|
||||
"//kernel/liteos_m/components/cmsis/2.0",
|
||||
"//third_party/cmsis/CMSIS/RTOS2/Include",
|
||||
"//base/iot_hardware/peripheral/interfaces/kits",
|
||||
"//device/talkweb/niobe/sdk_liteos/include/",
|
||||
]
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ static void *LedLightTask(const char *arg)
|
|||
printf("-----entry pwm demo -----\r\n");
|
||||
|
||||
IoTGpioInit(IOT_GPIO_IO_GPIO_9);
|
||||
IotIoSetFunc(IOT_GPIO_IO_GPIO_9, HI_IO_FUNC_GPIO_9_PWM0_OUT);
|
||||
IoTIoSetFunc(IOT_GPIO_IO_GPIO_9, HI_IO_FUNC_GPIO_9_PWM0_OUT);
|
||||
IoTGpioSetDir(IOT_GPIO_IO_GPIO_9, IOT_GPIO_DIR_OUT);
|
||||
|
||||
IoTPwmInit(HI_PWM_PORT_PWM0);
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#include "cmsis_os2.h"
|
||||
#include "iot_gpio.h"
|
||||
#include "iot_pwm.h"
|
||||
#include "hi_pwm.h"
|
||||
|
||||
#define LED_INTERVAL_TIME_US 15000
|
||||
#define LED_TASK_STACK_SIZE 1024
|
||||
|
@ -33,10 +32,10 @@ static void *LedLightTask(const char *arg)
|
|||
printf("-----entry pwm demo -----\r\n");
|
||||
|
||||
IoTGpioInit(IOT_GPIO_IO_GPIO_9);
|
||||
IotIoSetFunc(IOT_GPIO_IO_GPIO_9, HI_IO_FUNC_GPIO_9_PWM0_OUT);
|
||||
IoTIoSetFunc(IOT_GPIO_IO_GPIO_9, IOT_IO_FUNC_GPIO_9_PWM0_OUT);
|
||||
IoTGpioSetDir(IOT_GPIO_IO_GPIO_9, IOT_GPIO_DIR_OUT);
|
||||
|
||||
IoTPwmInit(HI_PWM_PORT_PWM0);
|
||||
IoTPwmInit(IOT_PWM_PORT_PWM0);
|
||||
|
||||
unsigned short duty = 0;
|
||||
unsigned int freq = 15000;
|
||||
|
@ -63,7 +62,7 @@ static void *LedLightTask(const char *arg)
|
|||
}
|
||||
|
||||
usleep(LED_INTERVAL_TIME_US);
|
||||
IoTPwmStart(HI_PWM_PORT_PWM0, duty, freq);
|
||||
IoTPwmStart(IOT_PWM_PORT_PWM0, duty, freq);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
|
|
@ -18,8 +18,7 @@ static_library("adc_voltage"){
|
|||
|
||||
include_dirs =[
|
||||
"//utils/native/liteos/include",
|
||||
"//device/talkweb/niobe/sdk_liteos/include",
|
||||
"//device/talkweb/niobe/hi3861_adapter/kal/cmsis",
|
||||
"//third_party/cmsis/CMSIS/RTOS2/Include",
|
||||
"//base/iot_hardware/peripheral/interfaces/kits",
|
||||
]
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include "ohos_init.h"
|
||||
#include "cmsis_os2.h"
|
||||
#include "hi_errno.h"
|
||||
#include "ohos_error.h"
|
||||
#include "iot_adc.h"
|
||||
#include "iot_gpio.h"
|
||||
|
||||
|
@ -36,8 +36,8 @@ static void adcTask(void)
|
|||
for(;;)
|
||||
{
|
||||
//获取ADC采集值
|
||||
ret = IoTAdcRead(WIFI_IOT_ADC_CHANNEL_2,&val,WIFI_IOT_ADC_EQU_MODEL_8,WIFI_IOT_ADC_CUR_BAIS_DEFAULT,256);
|
||||
if(ret != HI_ERR_SUCCESS)
|
||||
ret = IoTAdcRead(IOT_ADC_CHANNEL_2, &val, IOT_ADC_EQU_MODEL_8, IOT_ADC_CUR_BAIS_DEFAULT, 256);
|
||||
if(ret != EC_SUCCESS)
|
||||
{
|
||||
printf("Failed to read adc! Err code = %d\n", ret);
|
||||
continue;
|
||||
|
|
|
@ -18,8 +18,7 @@ static_library("i2c_sht30"){
|
|||
|
||||
include_dirs =[
|
||||
"//utils/native/liteos/include",
|
||||
"//device/talkweb/niobe/sdk_liteos/include",
|
||||
"//device/talkweb/niobe/hi3861_adapter/kal/cmsis",
|
||||
"//third_party/cmsis/CMSIS/RTOS2/Include",
|
||||
"//base/iot_hardware/peripheral/interfaces/kits",
|
||||
]
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#include "iot_i2c.h"
|
||||
#include "iot_errno.h"
|
||||
#include "iot_gpio.h"
|
||||
#include "hi_i2c.h"
|
||||
|
||||
#define SHT30_TASK_STACK_SIZE 4096
|
||||
#define SHT30_TASK_PRIO 25
|
||||
|
@ -87,7 +86,7 @@ static int SHT3xPeriodicReadData(unsigned short cmd, unsigned char *pbuf)
|
|||
|
||||
buf[0] = (unsigned char)(cmd >> 8)&0XFF;
|
||||
buf[1] = (unsigned char)(cmd >> 0)&0XFF;
|
||||
ret = IoTI2cWrite(HI_I2C_IDX_0, WriteHeader, buf, 2);
|
||||
ret = IoTI2cWrite(IOT_I2C_IDX_0, WriteHeader, buf, 2);
|
||||
if(ret != IOT_SUCCESS)
|
||||
{
|
||||
printf("I2C write data fail, ret = %d\r\n",ret);
|
||||
|
@ -95,7 +94,7 @@ static int SHT3xPeriodicReadData(unsigned short cmd, unsigned char *pbuf)
|
|||
}
|
||||
|
||||
usleep(20000);
|
||||
ret = IoTI2cRead(HI_I2C_IDX_0, ReadHeader, buf, 6);
|
||||
ret = IoTI2cRead(IOT_I2C_IDX_0, ReadHeader, buf, 6);
|
||||
if(ret != IOT_SUCCESS)
|
||||
{
|
||||
printf("I2C read data fail, ret = %d\r\n",ret);
|
||||
|
@ -139,13 +138,13 @@ static void I2cSht30Task(void)
|
|||
IoTGpioInit(IOT_GPIO_IO_GPIO_13);
|
||||
IoTGpioInit(IOT_GPIO_IO_GPIO_14);
|
||||
|
||||
IotIoSetPull(IOT_GPIO_IO_GPIO_13, IOT_IO_PULL_UP);
|
||||
IotIoSetPull(IOT_GPIO_IO_GPIO_14, IOT_IO_PULL_UP);
|
||||
IoTIoSetPull(IOT_GPIO_IO_GPIO_13, IOT_IO_PULL_UP);
|
||||
IoTIoSetPull(IOT_GPIO_IO_GPIO_14, IOT_IO_PULL_UP);
|
||||
|
||||
IotIoSetFunc(IOT_GPIO_IO_GPIO_13, HI_IO_FUNC_GPIO_13_I2C0_SDA);
|
||||
IotIoSetFunc(IOT_GPIO_IO_GPIO_14, HI_IO_FUNC_GPIO_14_I2C0_SCL);
|
||||
IoTIoSetFunc(IOT_GPIO_IO_GPIO_13, IOT_IO_FUNC_GPIO_13_I2C0_SDA);
|
||||
IoTIoSetFunc(IOT_GPIO_IO_GPIO_14, IOT_IO_FUNC_GPIO_14_I2C0_SCL);
|
||||
|
||||
ret = IoTI2cInit(HI_I2C_IDX_0, 400000);
|
||||
ret = IoTI2cInit(IOT_I2C_IDX_0, 400000);
|
||||
if(ret != IOT_SUCCESS)
|
||||
{
|
||||
printf("I2c Init failed, ret = %d\r\n",ret);
|
||||
|
|
|
@ -18,8 +18,6 @@ static_library("module_oled_example"){
|
|||
|
||||
include_dirs =[
|
||||
"//utils/native/liteos/include",
|
||||
"//device/talkweb/niobe/sdk_liteos/include",
|
||||
"//device/talkweb/niobe/hi3861_adapter/kal/cmsis",
|
||||
"//base/iot_hardware/peripheral/interfaces/kits",
|
||||
]
|
||||
}
|
||||
|
|
|
@ -17,9 +17,7 @@
|
|||
#include "ohos_init.h"
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
#include "hi_i2c.h"
|
||||
#include "hi_io.h"
|
||||
#include "hi_errno.h"
|
||||
#include "iot_errno.h"
|
||||
#include "iot_gpio.h"
|
||||
#include "iot_i2c.h"
|
||||
#include "iot_adc.h"
|
||||
|
@ -41,19 +39,16 @@ unsigned char g_send_data[2] = { 0 };
|
|||
* @param device_addr: Oled的设备地址,这里默认是0X78
|
||||
* @param send_len: 写入的数据长度
|
||||
*/
|
||||
unsigned int IICWrite(hi_i2c_idx id, unsigned short device_addr, unsigned int send_len)
|
||||
unsigned int IICWrite(unsigned int id, unsigned short device_addr, unsigned int send_len)
|
||||
{
|
||||
int status = 0;
|
||||
hi_i2c_data es8311_i2c_data = { 0 };
|
||||
|
||||
es8311_i2c_data.send_buf = g_send_data;
|
||||
es8311_i2c_data.send_len = send_len;
|
||||
status = hi_i2c_write(id, device_addr, &es8311_i2c_data);
|
||||
if (status != HI_ERR_SUCCESS) {
|
||||
status = IoTI2cWrite(id, device_addr, g_send_data, send_len);
|
||||
if (status != IOT_SUCCESS) {
|
||||
printf("===== Error: I2C write status = %d! =====\r\n", status);
|
||||
return status;
|
||||
}
|
||||
return HI_ERR_SUCCESS;
|
||||
return IOT_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,7 +60,7 @@ void IICWriteCommand(unsigned char IIC_Command)
|
|||
g_send_data[0] = 0x00;
|
||||
g_send_data[1] = IIC_Command;
|
||||
|
||||
IICWrite(HI_I2C_IDX_0, 0x78, 2);
|
||||
IICWrite(IOT_I2C_IDX_0, 0x78, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,7 +72,7 @@ void IICWriteData(unsigned char IIC_Data)
|
|||
g_send_data[0] = 0x40;
|
||||
g_send_data[1] = IIC_Data;
|
||||
|
||||
IICWrite(HI_I2C_IDX_0, 0x78, 2);
|
||||
IICWrite(IOT_I2C_IDX_0, 0x78, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -171,10 +166,10 @@ void OledClear(void)
|
|||
void OledDrawPoint(unsigned char x,unsigned char y)
|
||||
{
|
||||
unsigned char i,m,n;
|
||||
i=y/8;
|
||||
m=y%8;
|
||||
n=1<<m;
|
||||
OLED_GRAM[x][i]|=n;
|
||||
i = y/8;
|
||||
m = y%8;
|
||||
n = 1<<m;
|
||||
OLED_GRAM[x][i] |= n;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -311,13 +306,13 @@ static void OledDemoTask(void)
|
|||
IoTGpioInit(IOT_GPIO_IO_GPIO_13);
|
||||
IoTGpioInit(IOT_GPIO_IO_GPIO_14);
|
||||
|
||||
IotIoSetPull(IOT_GPIO_IO_GPIO_13, IOT_IO_PULL_UP);
|
||||
IotIoSetPull(IOT_GPIO_IO_GPIO_14, IOT_IO_PULL_UP);
|
||||
IoTIoSetPull(IOT_GPIO_IO_GPIO_13, IOT_IO_PULL_UP);
|
||||
IoTIoSetPull(IOT_GPIO_IO_GPIO_14, IOT_IO_PULL_UP);
|
||||
|
||||
IotIoSetFunc(IOT_GPIO_IO_GPIO_13,HI_IO_FUNC_GPIO_13_I2C0_SDA);
|
||||
IotIoSetFunc(IOT_GPIO_IO_GPIO_14,HI_IO_FUNC_GPIO_14_I2C0_SCL);
|
||||
IoTIoSetFunc(IOT_GPIO_IO_GPIO_13, IOT_IO_FUNC_GPIO_13_I2C0_SDA);
|
||||
IoTIoSetFunc(IOT_GPIO_IO_GPIO_14, IOT_IO_FUNC_GPIO_14_I2C0_SCL);
|
||||
|
||||
hi_i2c_init(HI_I2C_IDX_0, 400*1000);
|
||||
IoTI2cInit(IOT_I2C_IDX_0, 400*1000);
|
||||
|
||||
//oled初始化配置
|
||||
OledInit();
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
参数说明:
|
||||
–id Indicates the GPIO pin number.
|
||||
|
||||
IotIoSetFunc(IOT_GPIO_IO_NAME id, unsigned char val): 注册功能
|
||||
IoTIoSetFunc(IOT_GPIO_IO_NAME id, unsigned char val): 注册功能
|
||||
参数说明:
|
||||
-id Indicates the GPIO pin number.
|
||||
-val 复用功能
|
||||
|
|
22
applications/app/TW202_Module_traffic_light/traffic_light_example.c
Executable file → Normal file
22
applications/app/TW202_Module_traffic_light/traffic_light_example.c
Executable file → Normal file
|
@ -21,11 +21,9 @@
|
|||
#include "iot_gpio.h"
|
||||
#include "iot_watchdog.h"
|
||||
#include "iot_pwm.h"
|
||||
#include "hi_pwm.h"
|
||||
#include "hi_io.h"
|
||||
|
||||
//蜂鸣器PWM端口号
|
||||
#define HI_PWM_BEEP_PORT HI_PWM_PORT_PWM0
|
||||
#define HI_PWM_BEEP_PORT IOT_PWM_PORT_PWM0
|
||||
//蜂鸣频率
|
||||
#define PWM_BEEP_FREQ (4 * 1000)
|
||||
//蜂鸣占空比
|
||||
|
@ -36,7 +34,7 @@ static int gBeepState = 0;
|
|||
|
||||
typedef struct
|
||||
{
|
||||
IOT_GPIO_IO_NAME gpioName; //灯的GPIO
|
||||
IotGpioIoName gpioName; //灯的GPIO
|
||||
int ioFunc; //IO hi_io_func_gpio
|
||||
IotGpioDir dir; //GPIO 方向
|
||||
IotGpioValue value; //灯当前值
|
||||
|
@ -47,22 +45,22 @@ static int gCurrentLightId = 0;
|
|||
static TrafficLight lights[] = {
|
||||
//red
|
||||
{IOT_GPIO_IO_GPIO_10,
|
||||
HI_IO_FUNC_GPIO_10_GPIO,
|
||||
IOT_IO_FUNC_GPIO_10_GPIO,
|
||||
IOT_GPIO_DIR_OUT,
|
||||
IOT_GPIO_VALUE0},
|
||||
//GREEN
|
||||
{IOT_GPIO_IO_GPIO_11,
|
||||
HI_IO_FUNC_GPIO_11_GPIO,
|
||||
IOT_IO_FUNC_GPIO_11_GPIO,
|
||||
IOT_GPIO_DIR_OUT,
|
||||
IOT_GPIO_VALUE0},
|
||||
//BLUE
|
||||
{IOT_GPIO_IO_GPIO_12,
|
||||
HI_IO_FUNC_GPIO_12_GPIO,
|
||||
IOT_IO_FUNC_GPIO_12_GPIO,
|
||||
IOT_GPIO_DIR_OUT,
|
||||
IOT_GPIO_VALUE0},
|
||||
//WHITE
|
||||
{IOT_GPIO_IO_GPIO_5,
|
||||
HI_IO_FUNC_GPIO_5_GPIO,
|
||||
IOT_IO_FUNC_GPIO_5_GPIO,
|
||||
IOT_GPIO_DIR_OUT,
|
||||
IOT_GPIO_VALUE0}};
|
||||
#define MAX_LIGHTS (sizeof(lights) / sizeof(lights[0]))
|
||||
|
@ -165,23 +163,23 @@ static void LightExampleEntry(void)
|
|||
TrafficLight *l = &lights[i];
|
||||
IoTGpioInit(l->gpioName);
|
||||
//注册功能
|
||||
IotIoSetFunc(l->gpioName, l->ioFunc);
|
||||
IoTIoSetFunc(l->gpioName, l->ioFunc);
|
||||
|
||||
//注册io方向
|
||||
IoTGpioSetDir(l->gpioName, l->dir);
|
||||
}
|
||||
//按键处理
|
||||
IoTGpioInit(IOT_GPIO_IO_GPIO_8);
|
||||
IotIoSetFunc(IOT_GPIO_IO_GPIO_8, HI_IO_FUNC_GPIO_8_GPIO);
|
||||
IoTIoSetFunc(IOT_GPIO_IO_GPIO_8, IOT_IO_FUNC_GPIO_8_GPIO);
|
||||
//上升
|
||||
IotIoSetPull(IOT_GPIO_IO_GPIO_8, IOT_IO_PULL_UP);
|
||||
IoTIoSetPull(IOT_GPIO_IO_GPIO_8, IOT_IO_PULL_UP);
|
||||
|
||||
IoTGpioSetDir(IOT_GPIO_IO_GPIO_8, IOT_GPIO_DIR_IN);
|
||||
//注册按键回调
|
||||
IoTGpioRegisterIsrFunc(IOT_GPIO_IO_GPIO_8, IOT_INT_TYPE_EDGE, IOT_GPIO_EDGE_RISE_LEVEL_HIGH, OnKeyPressed, NULL);
|
||||
|
||||
//蜂鸣器GPIO09/PWM0
|
||||
IotIoSetFunc(IOT_GPIO_IO_GPIO_9, HI_IO_FUNC_GPIO_9_PWM0_OUT);
|
||||
IoTIoSetFunc(IOT_GPIO_IO_GPIO_9, IOT_IO_FUNC_GPIO_9_PWM0_OUT);
|
||||
IoTGpioSetOutputVal(IOT_GPIO_IO_GPIO_9, IOT_GPIO_DIR_OUT);
|
||||
// 初始化PWM设备,这里是蜂鸣器
|
||||
IoTPwmInit(HI_PWM_BEEP_PORT);
|
||||
|
|
|
@ -18,12 +18,11 @@ static_library("module_tricolor_light_example") {
|
|||
"src/light_demo.c",
|
||||
"src/beep_demo.c",
|
||||
"src/main_demo.c",
|
||||
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"//utils/native/lite/include",
|
||||
"//kernel/liteos_m/components/cmsis/2.0",
|
||||
"//third_party/cmsis/CMSIS/RTOS2/Include",
|
||||
"//base/iot_hardware/peripheral/interfaces/kits",
|
||||
"include"
|
||||
]
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#define _BEEP_DEMO_H
|
||||
#include "iot_gpio.h"
|
||||
#include "iot_pwm.h"
|
||||
#include "hi_pwm.h"
|
||||
|
||||
struct BEEPCTRLATTR{
|
||||
unsigned int times; //响的次数
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#define _LIGHT_DEMO_H
|
||||
#include "iot_gpio.h"
|
||||
#include "iot_adc.h"
|
||||
#include "iot_errno.h"
|
||||
|
||||
//当前环境光照状态
|
||||
enum ENV_LIGHT_STATE{
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#define _TRICLOLR_LIGHT_DEMO_H
|
||||
#include "iot_gpio.h"
|
||||
#include "iot_pwm.h"
|
||||
#include "hi_pwm.h"
|
||||
#include "iot_errno.h"
|
||||
|
||||
void TricolorLightInit(void);
|
||||
|
|
|
@ -17,20 +17,19 @@
|
|||
void BeepInit(void)
|
||||
{
|
||||
IoTGpioInit(IOT_GPIO_IO_GPIO_9);
|
||||
IotIoSetFunc(IOT_GPIO_IO_GPIO_9, HI_IO_FUNC_GPIO_9_PWM0_OUT);
|
||||
IoTIoSetFunc(IOT_GPIO_IO_GPIO_9, IOT_IO_FUNC_GPIO_9_PWM0_OUT);
|
||||
IoTGpioSetDir(IOT_GPIO_IO_GPIO_9, IOT_GPIO_DIR_OUT);
|
||||
|
||||
IoTPwmInit(HI_PWM_PORT_PWM0);
|
||||
IoTPwmInit(IOT_PWM_PORT_PWM0);
|
||||
}
|
||||
|
||||
static void BeepStart(void)
|
||||
{
|
||||
IoTPwmStart(HI_PWM_PORT_PWM0, 50, 4000);
|
||||
IoTPwmStart(IOT_PWM_PORT_PWM0, 50, 4000);
|
||||
}
|
||||
|
||||
static void BeepStop(void)
|
||||
{
|
||||
IoTPwmStop(HI_PWM_PORT_PWM0);
|
||||
IoTPwmStop(IOT_PWM_PORT_PWM0);
|
||||
}
|
||||
|
||||
void BeepCtrl(struct BEEPCTRLATTR* ctrlAttr)
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
void InfraredSensorInit(void)
|
||||
{
|
||||
IoTGpioInit(IOT_GPIO_IO_GPIO_7);
|
||||
IotIoSetFunc(IOT_GPIO_IO_GPIO_7, HI_IO_FUNC_GPIO_7_GPIO);
|
||||
IotIoSetPull(IOT_GPIO_IO_GPIO_7, IOT_IO_PULL_DOWN);
|
||||
IoTIoSetFunc(IOT_GPIO_IO_GPIO_7, IOT_IO_FUNC_GPIO_7_GPIO);
|
||||
IoTIoSetPull(IOT_GPIO_IO_GPIO_7, IOT_IO_PULL_DOWN);
|
||||
IoTGpioSetDir(IOT_GPIO_IO_GPIO_7,IOT_GPIO_DIR_IN);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
|
||||
int LightSensorVal(unsigned short* val)
|
||||
{
|
||||
int ret = IoTAdcRead(WIFI_IOT_ADC_CHANNEL_6,val,WIFI_IOT_ADC_EQU_MODEL_8,WIFI_IOT_ADC_CUR_BAIS_DEFAULT,256);
|
||||
if(ret != HI_ERR_SUCCESS)
|
||||
int ret = IoTAdcRead(IOT_ADC_CHANNEL_6,val, IOT_ADC_EQU_MODEL_8, IOT_ADC_CUR_BAIS_DEFAULT, 256);
|
||||
if(ret != IOT_SUCCESS)
|
||||
{
|
||||
printf("Failed to read adc! Err code = %d\n", ret);
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ int GetLightAverageVal(unsigned char cnt)
|
|||
|
||||
for(unsigned char i=0; i<cnt; i++)
|
||||
{
|
||||
if(LightSensorVal(&readVal) == HI_ERR_SUCCESS)
|
||||
if(LightSensorVal(&readVal) == IOT_SUCCESS)
|
||||
{
|
||||
totalVal += readVal;
|
||||
totalCnt++;
|
||||
|
|
|
@ -17,29 +17,29 @@
|
|||
void TricolorLightInit(void)
|
||||
{
|
||||
IoTGpioInit(IOT_GPIO_IO_GPIO_10); // 红灯
|
||||
IotIoSetFunc(IOT_GPIO_IO_GPIO_10, HI_IO_FUNC_GPIO_10_PWM1_OUT);
|
||||
IoTIoSetFunc(IOT_GPIO_IO_GPIO_10, IOT_IO_FUNC_GPIO_10_PWM1_OUT);
|
||||
IoTGpioSetDir(IOT_GPIO_IO_GPIO_10, IOT_GPIO_DIR_OUT);
|
||||
|
||||
IoTGpioInit(IOT_GPIO_IO_GPIO_11); // 绿灯
|
||||
IotIoSetFunc(IOT_GPIO_IO_GPIO_11, HI_IO_FUNC_GPIO_11_PWM2_OUT);
|
||||
IoTIoSetFunc(IOT_GPIO_IO_GPIO_11, IOT_IO_FUNC_GPIO_11_PWM2_OUT);
|
||||
IoTGpioSetDir(IOT_GPIO_IO_GPIO_11, IOT_GPIO_DIR_OUT);
|
||||
|
||||
IoTGpioInit(IOT_GPIO_IO_GPIO_12); // 蓝灯
|
||||
IotIoSetFunc(IOT_GPIO_IO_GPIO_12, HI_IO_FUNC_GPIO_12_PWM3_OUT);
|
||||
IoTIoSetFunc(IOT_GPIO_IO_GPIO_12, IOT_IO_FUNC_GPIO_12_PWM3_OUT);
|
||||
IoTGpioSetDir(IOT_GPIO_IO_GPIO_12, IOT_GPIO_DIR_OUT);
|
||||
|
||||
IoTPwmInit(HI_PWM_PORT_PWM1);
|
||||
IoTPwmInit(HI_PWM_PORT_PWM2);
|
||||
IoTPwmInit(HI_PWM_PORT_PWM3);
|
||||
IoTPwmInit(IOT_PWM_PORT_PWM1);
|
||||
IoTPwmInit(IOT_PWM_PORT_PWM2);
|
||||
IoTPwmInit(IOT_PWM_PORT_PWM3);
|
||||
}
|
||||
|
||||
void TricolorLightStart(char redDuty, char GreenDuty, char BlueDuty)
|
||||
{
|
||||
int ret = IOT_SUCCESS;
|
||||
|
||||
ret |= IoTPwmStart(HI_PWM_PORT_PWM1, redDuty, 40000);
|
||||
ret |= IoTPwmStart(HI_PWM_PORT_PWM2, GreenDuty, 40000);
|
||||
ret |= IoTPwmStart(HI_PWM_PORT_PWM3, BlueDuty, 40000);
|
||||
ret |= IoTPwmStart(IOT_PWM_PORT_PWM1, redDuty, 40000);
|
||||
ret |= IoTPwmStart(IOT_PWM_PORT_PWM2, GreenDuty, 40000);
|
||||
ret |= IoTPwmStart(IOT_PWM_PORT_PWM3, BlueDuty, 40000);
|
||||
|
||||
if(ret != IOT_SUCCESS)
|
||||
{
|
||||
|
@ -50,9 +50,9 @@ void TricolorLightStart(char redDuty, char GreenDuty, char BlueDuty)
|
|||
void TricolorLightStop(void)
|
||||
{
|
||||
int ret = IOT_SUCCESS;
|
||||
ret |= IoTPwmStop(HI_PWM_PORT_PWM1);
|
||||
ret |= IoTPwmStop(HI_PWM_PORT_PWM2);
|
||||
ret |= IoTPwmStop(HI_PWM_PORT_PWM3);
|
||||
ret |= IoTPwmStop(IOT_PWM_PORT_PWM1);
|
||||
ret |= IoTPwmStop(IOT_PWM_PORT_PWM2);
|
||||
ret |= IoTPwmStop(IOT_PWM_PORT_PWM3);
|
||||
|
||||
if(ret != IOT_SUCCESS)
|
||||
{
|
||||
|
|
|
@ -15,12 +15,11 @@ static_library("module_enviroment_example") {
|
|||
sources = [
|
||||
"THsensor.c",
|
||||
"CGsensor.c",
|
||||
"buzze.c"
|
||||
"buzzer.c"
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"//utils/native/lite/include",
|
||||
"//kernel/liteos_m/kal/cmsis",
|
||||
"//base/iot_hardware/peripheral/interfaces/kits",
|
||||
]
|
||||
}
|
||||
|
|
|
@ -17,13 +17,11 @@
|
|||
#include "stdio.h"
|
||||
#include "ohos_init.h"
|
||||
#include "cmsis_os2.h"
|
||||
#include "securec.h"
|
||||
|
||||
#include <hi_io.h>
|
||||
#include <iot_gpio.h>
|
||||
#include <hi_adc.h>
|
||||
#include <hi_types_base.h>
|
||||
#include <hi_early_debug.h>
|
||||
#include <hi_stdlib.h>
|
||||
#include "iot_gpio.h"
|
||||
#include "iot_adc.h"
|
||||
#include "iot_errno.h"
|
||||
#include "sensor.h"
|
||||
#include "buzze.h"
|
||||
|
||||
|
@ -67,8 +65,8 @@ static void *CGsensorTask(const char *arg)
|
|||
|
||||
for (size_t i = 0; i < ADC_TEST_LENGTH; i++)
|
||||
{
|
||||
ret = hi_adc_read((hi_adc_channel_index)HI_ADC_CHANNEL_5, &th_adc_buf[i], HI_ADC_EQU_MODEL_1, HI_ADC_CUR_BAIS_DEFAULT, 0);
|
||||
if (ret != HI_ERR_SUCCESS)
|
||||
ret = IoTAdcRead(IOT_ADC_CHANNEL_5, &th_adc_buf[i], IOT_ADC_EQU_MODEL_1, IOT_ADC_CUR_BAIS_DEFAULT, 0);
|
||||
if (ret != IOT_SUCCESS)
|
||||
{
|
||||
printf("ADC Read Fail\n");
|
||||
return NULL;
|
||||
|
@ -87,10 +85,10 @@ static void CGsensorExampleEntry(void)
|
|||
|
||||
//ADC PORT
|
||||
IoTGpioInit(IOT_GPIO_IO_GPIO_11);
|
||||
IotIoSetFunc(IOT_GPIO_IO_GPIO_11, HI_IO_FUNC_GPIO_11_GPIO);
|
||||
IoTIoSetFunc(IOT_GPIO_IO_GPIO_11, IOT_IO_FUNC_GPIO_11_GPIO);
|
||||
IoTGpioSetDir(IOT_GPIO_IO_GPIO_11, IOT_GPIO_DIR_IN);
|
||||
|
||||
if (ret != HI_ERR_SUCCESS)
|
||||
if (ret != IOT_SUCCESS)
|
||||
{
|
||||
printf("[CGsensorExampleEntry]===== ERROR ======gpio -> hi_gpio_set_dir1 ret:%d\r\n", ret);
|
||||
return;
|
||||
|
|
|
@ -1,3 +1,61 @@
|
|||
# 温湿度和烟感
|
||||
# OpenHarmony模组开发-温湿度和烟感
|
||||
|
||||
本案例使用到了三组设备,通过MQ-2传感器和AHT20传感器,获取是否煤气泄漏和温湿度,如果煤气泄漏,蜂鸣器会报警。
|
||||
|
||||
# 目录结构:
|
||||
## include
|
||||
buzzer.h --蜂鸣器控制头文件
|
||||
sensor.h --传感器头文件
|
||||
## src
|
||||
buzzer.c --蜂鸣器控制源文件
|
||||
CGsensor.c --烟感传感器源文件
|
||||
THsensor.c --温湿度源文件
|
||||
|
||||
# 相关API介绍
|
||||
## beep_demo
|
||||
1.BeepInit(): 蜂鸣器初始化函数,初始化GPIO9为PWM0输出
|
||||
2.BeepStart(): 蜂鸣器使能函数
|
||||
3.BeepStop(): 蜂鸣器停止函数
|
||||
4.BeepCtrl(struct BEEPCTRLATTR* ctrlAttr):蜂鸣器控制函数
|
||||
ctrlAttr参数说明:
|
||||
times //响的次数
|
||||
duty //每次响的占空比
|
||||
period //每响一次的时间周期
|
||||
callTime //控制函数的调用周期
|
||||
|
||||
## infrared_demo
|
||||
1.InfraredSensorInit(): 红外传感初始化函数,初始化GPIO7为IO输入
|
||||
2.GetInfraredSensorVal(): 获取红外传感IO引脚当前的状态值
|
||||
3.GetEnvBodyState(): 获取红外人体感应目前的环境状态
|
||||
返回值(enum ENV_BODY_STATE):
|
||||
BODY_NOT //无人靠近
|
||||
BODY_COME //有人靠近
|
||||
BODY_KEEP //有人靠近后保持
|
||||
BODY_LEAVE //有人离开
|
||||
|
||||
## light_demo
|
||||
1.LightSensorVal(unsigned short* val): 获取当前环境光照值,保存到val中
|
||||
2.GetLightAverageVal(unsigned char cnt): 多次获取当前环境光照并取平均值
|
||||
cnt为多次获取次数
|
||||
return 返回多次获取的平均值
|
||||
3.GetEnvLightState(): 获取当前环境光照状态
|
||||
返回值(enum ENV_LIGHT_STATE):
|
||||
LIGHT_DAY //白天
|
||||
LIGHT_DUSK //黄昏
|
||||
LIGHT_NIGHT //黑夜
|
||||
|
||||
## tricolor_light_demo
|
||||
1.TricolorLightInit(): 三色灯初始化函数,初始化GPIO10,GPIO11,GPIO12为PWM1,PWM2,PWM3输出
|
||||
2.TricolorLightStart(char redDuty, char GreenDuty, char BlueDuty): 设置PWM输出值,并开启PWM输出
|
||||
redDuty: 红灯PWM占空比
|
||||
GreenDuty: 绿灯PWM占空比
|
||||
BlueDuty: 蓝灯PWM占空比
|
||||
3.TricolorLightStop(): 三色灯P输出停止函数
|
||||
|
||||
# 运行结果
|
||||
当红外检测到有人接近时,蜂鸣器响两声,同时:
|
||||
当环境光线充足时,三色灯熄灭;
|
||||
当环境光线较昏暗时,三色灯显示低亮度;
|
||||
当环境光线非常不足时,三色灯显示高亮度;
|
||||
当红外检测到有人离开时,蜂鸣器响两声,且三色灯熄灭
|
||||
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
#include "cmsis_os2.h"
|
||||
|
||||
#include <hi_types_base.h>
|
||||
#include <hi_i2c.h>
|
||||
#include <iot_i2c.h>
|
||||
#include <hi_early_debug.h>
|
||||
#include <hi_stdlib.h>
|
||||
#include "sensor.h"
|
||||
|
@ -214,7 +212,7 @@ static void THsensorExampleEntry(void)
|
|||
{
|
||||
osThreadAttr_t attr;
|
||||
|
||||
IoTI2cInit(HI_I2C_IDX_0, 100 * 1000); /* baudrate: 100K */
|
||||
IoTI2cInit(IOT_I2C_IDX_0, 100 * 1000); /* baudrate: 100K */
|
||||
|
||||
attr.name = "THsensorTask";
|
||||
attr.attr_bits = 0U;
|
||||
|
|
|
@ -1,111 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "ohos_init.h"
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
#include "iot_gpio.h"
|
||||
#include "hi_io.h"
|
||||
#include "hi_pwm.h"
|
||||
#include "hi_time.h"
|
||||
#include "buzze.h"
|
||||
volatile uint8_t buzze_flag = 0; // 是否正在播放标志 1. playing 0. free
|
||||
|
||||
#define PWM_BEEP_PORT HI_PWM_PORT_PWM0
|
||||
|
||||
static const uint16_t gTuneFreqs40M[] = {
|
||||
0, //40MHz时钟源
|
||||
38223, // 1 1046.5
|
||||
34052, // 2 1174.7
|
||||
30338, // 3 1318.5
|
||||
28635, // 4 1396.4
|
||||
25511, // 5 1568
|
||||
22728, // 6 1760
|
||||
20249, // 7 1975.5
|
||||
};
|
||||
|
||||
static const uint8_t gScoreNotesBeep[] = {
|
||||
5, 3, 3, 4, 2, 2, 1, 2, 3, 4, 5, 5, 5,
|
||||
5, 3, 3, 4, 2, 2, 1, 3, 5, 5, 1,
|
||||
2, 2, 2, 2, 2, 3, 4,
|
||||
3, 3, 3, 3, 3, 4, 5,
|
||||
5, 3, 3, 4, 2, 2, 1, 3, 5, 5, 1
|
||||
|
||||
};
|
||||
|
||||
static const uint8_t gScoreDurationsBeep[] = {
|
||||
4, 4, 8, 4, 4, 8, 4, 4, 4, 4, 4, 4, 8,
|
||||
4, 4, 8, 4, 4, 8, 4, 4, 4, 4, 8,
|
||||
4, 4, 4, 4, 4, 4, 8,
|
||||
4, 4, 4, 4, 4, 4, 8,
|
||||
4, 4, 8, 4, 4, 8, 4, 4, 4, 4, 8};
|
||||
|
||||
static void PlayTuneTask(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
uint32_t tune;
|
||||
uint16_t freqDivisor;
|
||||
uint32_t tuneInterval;
|
||||
|
||||
for (size_t i = 0; i < sizeof(gScoreNotesBeep) / sizeof(gScoreNotesBeep[0]); i++)
|
||||
{
|
||||
tune = gScoreNotesBeep[i];
|
||||
freqDivisor = gTuneFreqs40M[tune];
|
||||
tuneInterval = gScoreDurationsBeep[i] * (125 * 1000); // 时间
|
||||
|
||||
hi_pwm_start(PWM_BEEP_PORT, freqDivisor / 2, freqDivisor);
|
||||
hi_udelay(tuneInterval);
|
||||
hi_pwm_stop(PWM_BEEP_PORT);
|
||||
}
|
||||
|
||||
if (buzze_flag == 1)
|
||||
{
|
||||
buzze_flag = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void StartBuzz()
|
||||
{
|
||||
|
||||
if (buzze_flag == 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
buzze_flag = 1;
|
||||
|
||||
{ //蜂鸣器端口初始化
|
||||
IoTGpioInit(IOT_GPIO_IO_GPIO_9);
|
||||
IotIoSetFunc(IOT_GPIO_IO_GPIO_9, HI_IO_FUNC_GPIO_9_PWM0_OUT);
|
||||
|
||||
hi_pwm_init(PWM_BEEP_PORT);
|
||||
//时钟
|
||||
hi_pwm_set_clock(PWM_CLK_XTAL);
|
||||
}
|
||||
osThreadAttr_t attr;
|
||||
attr.name = "BuzzTask";
|
||||
attr.attr_bits = 0U;
|
||||
attr.cb_mem = NULL;
|
||||
attr.cb_size = 0U;
|
||||
attr.stack_mem = NULL;
|
||||
attr.stack_size = 1024;
|
||||
attr.priority = 25;
|
||||
|
||||
if (osThreadNew(PlayTuneTask, NULL, &attr) == NULL)
|
||||
{
|
||||
buzze_flag = 0;
|
||||
printf("[pwm] Falied to create BuzzTask!\n");
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#ifndef __BUZZE_H__
|
||||
#define __BUZZE_H__
|
||||
#include <stdint.h>
|
||||
|
||||
extern volatile uint8_t buzze_flag;
|
||||
|
||||
void StartBuzz();
|
||||
|
||||
#endif
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "ohos_init.h"
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
#include "iot_gpio.h"
|
||||
#include "iot_pwm.h"
|
||||
#include "buzzer.h"
|
||||
|
||||
// 是否正在播放标志 1. playing 0. free
|
||||
volatile uint8_t buzz_flag = 0;
|
||||
|
||||
#define PWM_BEEP_PORT IOT_PWM_PORT_PWM0
|
||||
|
||||
static const uint16_t gTuneFreqs40M[] = {
|
||||
0, //40MHz时钟源
|
||||
38223, // 1 1046.5
|
||||
34052, // 2 1174.7
|
||||
30338, // 3 1318.5
|
||||
28635, // 4 1396.4
|
||||
25511, // 5 1568
|
||||
22728, // 6 1760
|
||||
20249, // 7 1975.5
|
||||
};
|
||||
|
||||
static const uint8_t gScoreNotesBeep[] = {
|
||||
5, 3, 3, 4, 2, 2, 1, 2, 3, 4, 5, 5, 5,
|
||||
5, 3, 3, 4, 2, 2, 1, 3, 5, 5, 1,
|
||||
2, 2, 2, 2, 2, 3, 4,
|
||||
3, 3, 3, 3, 3, 4, 5,
|
||||
5, 3, 3, 4, 2, 2, 1, 3, 5, 5, 1
|
||||
|
||||
};
|
||||
|
||||
static const uint8_t gScoreDurationsBeep[] = {
|
||||
4, 4, 8, 4, 4, 8, 4, 4, 4, 4, 4, 4, 8,
|
||||
4, 4, 8, 4, 4, 8, 4, 4, 4, 4, 8,
|
||||
4, 4, 4, 4, 4, 4, 8,
|
||||
4, 4, 4, 4, 4, 4, 8,
|
||||
4, 4, 8, 4, 4, 8, 4, 4, 4, 4, 8};
|
||||
|
||||
static void PlayTuneTask(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
uint32_t tune;
|
||||
uint16_t freqDivisor;
|
||||
uint32_t tuneInterval;
|
||||
|
||||
for (size_t i = 0; i < sizeof(gScoreNotesBeep) / sizeof(gScoreNotesBeep[0]); i++)
|
||||
{
|
||||
tune = gScoreNotesBeep[i];
|
||||
freqDivisor = gTuneFreqs40M[tune];
|
||||
tuneInterval = gScoreDurationsBeep[i] * (125 * 1000); // 时间
|
||||
|
||||
IoTPwmStart(PWM_BEEP_PORT, freqDivisor / 2, freqDivisor);
|
||||
usleep(tuneInterval);
|
||||
IoTPwmStop(PWM_BEEP_PORT);
|
||||
}
|
||||
|
||||
if (buzz_flag == 1)
|
||||
{
|
||||
buzz_flag = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void StartBuzz()
|
||||
{
|
||||
if (buzz_flag == 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 蜂鸣器端口初始化
|
||||
IoTGpioInit(IOT_GPIO_IO_GPIO_9);
|
||||
IoTIoSetFunc(IOT_GPIO_IO_GPIO_9, IOT_IO_FUNC_GPIO_9_PWM0_OUT);
|
||||
|
||||
IoTPwmInit(PWM_BEEP_PORT);
|
||||
// 时钟
|
||||
IoTPwmSetClock(IOT_PWM_CLK_XTAL);
|
||||
|
||||
osThreadAttr_t attr;
|
||||
attr.name = "BuzzTask";
|
||||
attr.attr_bits = 0U;
|
||||
attr.cb_mem = NULL;
|
||||
attr.cb_size = 0U;
|
||||
attr.stack_mem = NULL;
|
||||
attr.stack_size = 1024;
|
||||
attr.priority = 25;
|
||||
|
||||
if (osThreadNew(PlayTuneTask, NULL, &attr) == NULL)
|
||||
{
|
||||
printf("[pwm] Falied to create BuzzTask!\n");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#ifndef __BUZZE_H__
|
||||
#define __BUZZE_H__
|
||||
|
||||
#include "ohos_types.h"
|
||||
|
||||
void StartBuzz();
|
||||
|
||||
#endif
|
|
@ -0,0 +1,33 @@
|
|||
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#ifndef _BEEP_DEMO_H
|
||||
#define _BEEP_DEMO_H
|
||||
|
||||
#include "iot_gpio.h"
|
||||
#include "iot_pwm.h"
|
||||
|
||||
typedef struct {
|
||||
unsigned int times; //响的次数
|
||||
float duty; //每次响的占空比
|
||||
unsigned int period; //每响一次的时间周期
|
||||
unsigned int callTime; //控制函数的调用周期
|
||||
} BeepCtrlAttr;
|
||||
|
||||
void BeepInit(void);
|
||||
void BeepCtrl(BeepCtrlAttr* ctrlAttr);
|
||||
|
||||
#endif
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef __SENSOR_H
|
||||
#define __SENSOR_H
|
||||
|
||||
#include "iot_i2c.h"
|
||||
|
||||
//MQ-2
|
||||
#define ADC_TEST_LENGTH 64
|
||||
|
||||
|
@ -23,7 +25,7 @@
|
|||
#define THSENSOR_TASK_PRIO 25
|
||||
|
||||
//AHT20
|
||||
#define AHT20_I2C_IDX HI_I2C_IDX_0 //I2C ID
|
||||
#define AHT20_I2C_IDX IOT_I2C_IDX_0 //I2C ID
|
||||
|
||||
#define AHT20_RECEIVE_MAX 6 //AHT20 返回最大字节数
|
||||
#define AHT20_MAX_RETRY 10 //当AHT20未初始化,最大尝试重新初始化次数
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
#include "beep_demo.h"
|
||||
|
||||
void BeepInit(void)
|
||||
{
|
||||
IoTGpioInit(IOT_GPIO_IO_GPIO_9);
|
||||
IoTIoSetFunc(IOT_GPIO_IO_GPIO_9, IOT_IO_FUNC_GPIO_9_PWM0_OUT);
|
||||
IoTGpioSetDir(IOT_GPIO_IO_GPIO_9, IOT_GPIO_DIR_OUT);
|
||||
IoTPwmInit(IOT_PWM_PORT_PWM0);
|
||||
}
|
||||
|
||||
static void BeepStart(void)
|
||||
{
|
||||
IoTPwmStart(IOT_PWM_PORT_PWM0, 50, 4000);
|
||||
}
|
||||
|
||||
static void BeepStop(void)
|
||||
{
|
||||
IoTPwmStop(IOT_PWM_PORT_PWM0);
|
||||
}
|
||||
|
||||
void BeepCtrl(BeepCtrlAttr* ctrlAttr)
|
||||
{
|
||||
static unsigned char step = 0;
|
||||
static unsigned int onceOpenCnt = 0, onceCloseCnt = 0;
|
||||
|
||||
if(ctrlAttr->times <= 0)
|
||||
{
|
||||
step = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if(step == 0)
|
||||
{
|
||||
onceOpenCnt = (ctrlAttr->duty*ctrlAttr->period)/ctrlAttr->callTime;
|
||||
onceCloseCnt= ((1-ctrlAttr->duty)*ctrlAttr->period)/ctrlAttr->callTime;
|
||||
BeepStart();
|
||||
step++;
|
||||
}
|
||||
|
||||
else if(step == 1)
|
||||
{
|
||||
if(--onceOpenCnt <= 0)
|
||||
{
|
||||
BeepStop();
|
||||
step++;
|
||||
}
|
||||
}
|
||||
|
||||
else if(step == 2)
|
||||
{
|
||||
if(--onceCloseCnt <= 0)
|
||||
{
|
||||
ctrlAttr->times--;
|
||||
step = 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -62,8 +62,8 @@ void InitGpioIsrFunc(void)
|
|||
unsigned int ret = 0;
|
||||
|
||||
IoTGpioInit(IOT_GPIO_IO_GPIO_5);
|
||||
IotIoSetFunc(IOT_GPIO_IO_GPIO_5, HI_IO_FUNC_GPIO_5_GPIO);
|
||||
IotIoSetPull(IOT_GPIO_IO_GPIO_5, IOT_IO_PULL_UP);
|
||||
IoTIoSetFunc(IOT_GPIO_IO_GPIO_5, IOT_IO_FUNC_GPIO_5_GPIO);
|
||||
IoTIoSetPull(IOT_GPIO_IO_GPIO_5, IOT_IO_PULL_UP);
|
||||
ret = IoTGpioSetDir(IOT_GPIO_IO_GPIO_5, IOT_GPIO_DIR_IN);
|
||||
if (ret != 0)
|
||||
{
|
||||
|
|
|
@ -40,7 +40,7 @@ git clone https://gitee.com/talkweb_oh/niobe.git
|
|||
|
||||
```
|
||||
# 初始化
|
||||
repo init -u https://gitee.com/openharmony/manifest.git --no-repo-verify -m devboard_talkweb_niobe.xml --depth=1
|
||||
repo init -u https://gitee.com/openharmony-sig/manifest.git --no-repo-verify -m devboard_talkweb_niobe.xml --depth=1
|
||||
# 同步代码
|
||||
repo sync -c
|
||||
# 下载大文件
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/lite/ndk/ndk.gni")
|
||||
|
||||
static_library("blackbox") {
|
||||
sources = [
|
||||
"blackbox_adapter.c",
|
||||
"blackbox_core.c",
|
||||
"blackbox_detector.c",
|
||||
]
|
||||
defines = []
|
||||
cflags = [ "-Wall" ]
|
||||
deps = []
|
||||
include_dirs = [
|
||||
"//base/hiviewdfx/blackbox",
|
||||
"//base/hiviewdfx/blackbox/interfaces/native/kits",
|
||||
"//base/hiviewdfx/hiview_lite",
|
||||
"//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite",
|
||||
"//utils/native/lite/include",
|
||||
]
|
||||
}
|
|
@ -0,0 +1,177 @@
|
|||
|
||||
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
|
|
@ -0,0 +1,36 @@
|
|||
# hiviewdfx_blackbox
|
||||
|
||||
#### Description
|
||||
{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
|
||||
|
||||
#### Software Architecture
|
||||
Software architecture description
|
||||
|
||||
#### Installation
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### Instructions
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### Contribution
|
||||
|
||||
1. Fork the repository
|
||||
2. Create Feat_xxx branch
|
||||
3. Commit your code
|
||||
4. Create Pull Request
|
||||
|
||||
|
||||
#### Gitee Feature
|
||||
|
||||
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
|
||||
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
|
||||
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
|
||||
4. The most valuable open source project [GVP](https://gitee.com/gvp)
|
||||
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
|
||||
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
|
@ -0,0 +1,39 @@
|
|||
# hiviewdfx_blackbox
|
||||
|
||||
#### 介绍
|
||||
{**以下是 Gitee 平台说明,您可以替换此简介**
|
||||
Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
|
||||
无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
|
||||
|
||||
#### 软件架构
|
||||
软件架构说明
|
||||
|
||||
|
||||
#### 安装教程
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### 使用说明
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### 参与贡献
|
||||
|
||||
1. Fork 本仓库
|
||||
2. 新建 Feat_xxx 分支
|
||||
3. 提交代码
|
||||
4. 新建 Pull Request
|
||||
|
||||
|
||||
#### 特技
|
||||
|
||||
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
|
||||
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
|
||||
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
|
||||
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
|
||||
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
|
||||
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
|
@ -42,10 +42,6 @@ struct BBoxOps {
|
|||
};
|
||||
|
||||
/******************global functions*******************/
|
||||
extern unsigned int LOS_BinarySemCreate(unsigned short count, unsigned int *semHandle);
|
||||
extern unsigned int LOS_SemPend(unsigned int semHandle, unsigned int timeout);
|
||||
extern unsigned int LOS_SemPost(unsigned int semHandle);
|
||||
|
||||
/******************local variables*******************/
|
||||
static UTILS_DL_LIST_HEAD(g_opsList);
|
||||
static unsigned int g_opsListSem;
|
||||
|
@ -59,12 +55,14 @@ static void GetDirName(char *dirBuf, unsigned int dirBufSize, const char *path)
|
|||
}
|
||||
|
||||
char *end = path + strlen(path);
|
||||
while (*end != '/') {
|
||||
while (*end != '/' && end >= path) {
|
||||
end--;
|
||||
}
|
||||
if (end != NULL) {
|
||||
if (end >= path) {
|
||||
(void)memset_s(dirBuf, dirBufSize, 0, dirBufSize);
|
||||
(void)strncpy_s(dirBuf, dirBufSize - 1, path, end - path + strlen("/"));
|
||||
if (strncpy_s(dirBuf, dirBufSize - 1, path, end - path + strlen("/")) != EOK) {
|
||||
BBOX_PRINT_ERR("strncpy_s failed or the dirBuf is not enough!\n");
|
||||
}
|
||||
} else {
|
||||
BBOX_PRINT_ERR("no / has been found!\n");
|
||||
}
|
||||
|
@ -82,12 +80,18 @@ static void FormatErrorInfo(struct ErrorInfo *info,
|
|||
}
|
||||
|
||||
(void)memset_s(info, sizeof(*info), 0, sizeof(*info));
|
||||
strncpy_s(info->event, sizeof(info->event), event,
|
||||
Min(strlen(event), sizeof(info->event) - 1));
|
||||
strncpy_s(info->module, sizeof(info->module), module,
|
||||
Min(strlen(module), sizeof(info->module) - 1));
|
||||
strncpy_s(info->errorDesc, sizeof(info->errorDesc), errorDesc,
|
||||
Min(strlen(errorDesc), sizeof(info->errorDesc) - 1));
|
||||
if (strncpy_s(info->event, sizeof(info->event), event,
|
||||
Min(strlen(event), sizeof(info->event) - 1)) != EOK) {
|
||||
BBOX_PRINT_ERR("strncpy_s failed or the info->event is not enough!\n");
|
||||
}
|
||||
if (strncpy_s(info->module, sizeof(info->module), module,
|
||||
Min(strlen(module), sizeof(info->module) - 1)) != EOK) {
|
||||
BBOX_PRINT_ERR("strncpy_s failed or the info->module is not enough!\n");
|
||||
}
|
||||
if (strncpy_s(info->errorDesc, sizeof(info->errorDesc), errorDesc,
|
||||
Min(strlen(errorDesc), sizeof(info->errorDesc) - 1)) != EOK) {
|
||||
BBOX_PRINT_ERR("strncpy_s failed or the info->errorDesc is not enough!\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void WaitForLogRootDir(const char *rootDir)
|
||||
|
@ -107,7 +111,7 @@ static void WaitForLogRootDir(const char *rootDir)
|
|||
|
||||
static void SaveBasicErrorInfo(const char *filePath, struct ErrorInfo *info)
|
||||
{
|
||||
char *buf;
|
||||
char *buf = NULL;
|
||||
|
||||
if (filePath == NULL || info == NULL) {
|
||||
BBOX_PRINT_ERR("filePath: %p, info: %p!\n", filePath, info);
|
||||
|
@ -120,11 +124,14 @@ static void SaveBasicErrorInfo(const char *filePath, struct ErrorInfo *info)
|
|||
return;
|
||||
}
|
||||
(void)memset_s(buf, ERROR_INFO_MAX_LEN, 0, ERROR_INFO_MAX_LEN);
|
||||
(void)snprintf_s(buf, ERROR_INFO_MAX_LEN, ERROR_INFO_MAX_LEN - 1,
|
||||
if (snprintf_s(buf, ERROR_INFO_MAX_LEN, ERROR_INFO_MAX_LEN - 1,
|
||||
ERROR_INFO_HEADER ERROR_INFO_HEADER_FORMAT,
|
||||
info->event, info->module, info->errorDesc);
|
||||
*(buf + ERROR_INFO_MAX_LEN - 1) = '\0';
|
||||
(void)FullWriteFile(filePath, buf, strlen(buf), 0);
|
||||
info->event, info->module, info->errorDesc) != -1) {
|
||||
*(buf + ERROR_INFO_MAX_LEN - 1) = '\0';
|
||||
(void)FullWriteFile(filePath, buf, strlen(buf), 0);
|
||||
} else {
|
||||
PRINT_ERR("buf is not enough or snprintf_s failed\n");
|
||||
}
|
||||
free(buf);
|
||||
BBOX_PRINT_INFO("[%s] starts uploading event [%s]\n",
|
||||
info->module, info->event);
|
||||
|
@ -135,9 +142,9 @@ static void SaveBasicErrorInfo(const char *filePath, struct ErrorInfo *info)
|
|||
|
||||
static void* SaveErrorLog(void *param)
|
||||
{
|
||||
struct ErrorInfo *info;
|
||||
struct BBoxOps *ops;
|
||||
char dirName[PATH_MAX_LEN];
|
||||
struct ErrorInfo *info = NULL;
|
||||
struct BBoxOps *ops = NULL;
|
||||
char dirName[PATH_MAX_LEN] = { 0 };
|
||||
|
||||
info = malloc(sizeof(*info));
|
||||
if (info == NULL) {
|
||||
|
@ -157,7 +164,7 @@ static void* SaveErrorLog(void *param)
|
|||
continue;
|
||||
}
|
||||
if (ops->ops.GetLastLogInfo != NULL && ops->ops.SaveLastLog != NULL) {
|
||||
memset(info, 0, sizeof(*info));
|
||||
(void)memset_s(info, sizeof(*info), 0, sizeof(*info));
|
||||
if (ops->ops.GetLastLogInfo(info) != 0) {
|
||||
BBOX_PRINT_ERR("[%s] failed to get log info!\n",
|
||||
ops->ops.module);
|
||||
|
@ -183,7 +190,7 @@ static void* SaveErrorLog(void *param)
|
|||
#ifdef BLACKBOX_DEBUG
|
||||
static void PrintModuleOps(void)
|
||||
{
|
||||
struct BBoxOps *temp;
|
||||
struct BBoxOps *temp = NULL;
|
||||
|
||||
BBOX_PRINT_INFO("The following modules have been registered!\n");
|
||||
UTILS_DL_LIST_FOR_EACH_ENTRY(temp, &g_opsList, struct BBoxOps, opsList) {
|
||||
|
@ -197,8 +204,8 @@ static void PrintModuleOps(void)
|
|||
|
||||
int BBoxRegisterModuleOps(struct ModuleOps *ops)
|
||||
{
|
||||
struct BBoxOps *newOps;
|
||||
struct BBoxOps *temp;
|
||||
struct BBoxOps *newOps = NULL;
|
||||
struct BBoxOps *temp = NULL;
|
||||
|
||||
if (ops == NULL) {
|
||||
BBOX_PRINT_ERR("ops: %p!\n", ops);
|
||||
|
@ -247,9 +254,9 @@ int BBoxNotifyError(const char event[EVENT_MAX_LEN],
|
|||
int needSysReset)
|
||||
{
|
||||
int findModule = 0;
|
||||
struct BBoxOps *ops;
|
||||
struct BBoxOps *ops = NULL;
|
||||
struct ErrorInfo *info = NULL;
|
||||
char dirName[PATH_MAX_LEN];
|
||||
char dirName[PATH_MAX_LEN] = { 0 };
|
||||
|
||||
info = malloc(sizeof(*info));
|
||||
if (info == NULL) {
|
||||
|
@ -259,11 +266,11 @@ int BBoxNotifyError(const char event[EVENT_MAX_LEN],
|
|||
|
||||
GetDirName(dirName, sizeof(dirName), GetFaultLogPath());
|
||||
if (needSysReset == 0) {
|
||||
WaitForLogRootDir(dirName);
|
||||
if (LOS_SemPend(g_opsListSem, LOS_NO_WAIT) != 0) {
|
||||
BBOX_PRINT_ERR("Request g_opsListSem failed!\n");
|
||||
goto __out;
|
||||
}
|
||||
WaitForLogRootDir(dirName);
|
||||
if (LOS_SemPend(g_opsListSem, LOS_NO_WAIT) != 0) {
|
||||
BBOX_PRINT_ERR("Request g_opsListSem failed!\n");
|
||||
goto __out;
|
||||
}
|
||||
}
|
||||
|
||||
UTILS_DL_LIST_FOR_EACH_ENTRY(ops, &g_opsList, struct BBoxOps, opsList) {
|
||||
|
@ -309,8 +316,8 @@ __out:
|
|||
|
||||
static void BBoxInit(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_t taskId;
|
||||
int ret = -1;
|
||||
pthread_t taskId = 0;
|
||||
|
||||
if (LOS_BinarySemCreate(1, &g_opsListSem) != LOS_OK) {
|
||||
BBOX_PRINT_ERR("Create binary semaphore failed!\n");
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BLACKBOX_H
|
||||
#define BLACKBOX_H
|
||||
|
||||
#include "hiview_log.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* End of #if __cplusplus */
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#define ERROR_INFO_HEADER "#### error info ####\r\n"
|
||||
#define ERROR_INFO_HEADER_FORMAT "event: %s\r\nmodule: %s\r\nerrorDesc: %s\r\n"
|
||||
#define ERROR_INFO_MAX_LEN 768
|
||||
#define Min(a, b) (((a) > (b)) ? (b) : (a))
|
||||
#define BBOX_PRINT_ERR(format, ...) HILOG_DEBUG(HILOG_MODULE_HIVIEW, "bbox: func: %s line: %d, Err: " \
|
||||
format, __func__, __LINE__, ##__VA_ARGS__)
|
||||
#define BBOX_PRINT_INFO(format, ...) HILOG_DEBUG(HILOG_MODULE_HIVIEW, "bbox: Info: " format, ##__VA_ARGS__)
|
||||
|
||||
#define PATH_MAX_LEN 256
|
||||
#define EVENT_MAX_LEN 32
|
||||
#define MODULE_MAX_LEN 32
|
||||
#define ERROR_DESC_MAX_LEN 512
|
||||
#define MODULE_SYSTEM "SYSTEM"
|
||||
#define EVENT_SYSREBOOT "SYSREBOOT"
|
||||
#define EVENT_LONGPRESS "LONGPRESS"
|
||||
#define EVENT_COMBINATIONKEY "COMBINATIONKEY"
|
||||
#define EVENT_SUBSYSREBOOT "SUBSYSREBOOT"
|
||||
#define EVENT_POWEROFF "POWEROFF"
|
||||
#define EVENT_PANIC "PANIC"
|
||||
#define EVENT_SYS_WATCHDOG "SYSWATCHDOG"
|
||||
#define EVENT_HUNGTASK "HUNGTASK"
|
||||
#define EVENT_BOOTFAIL "BOOTFAIL"
|
||||
|
||||
struct ErrorInfo {
|
||||
char event[EVENT_MAX_LEN];
|
||||
char module[MODULE_MAX_LEN];
|
||||
char errorDesc[ERROR_DESC_MAX_LEN];
|
||||
};
|
||||
|
||||
struct ModuleOps {
|
||||
char module[MODULE_MAX_LEN];
|
||||
void (*Dump)(const char *logDir, struct ErrorInfo *info);
|
||||
void (*Reset)(struct ErrorInfo *info);
|
||||
int (*GetLastLogInfo)(struct ErrorInfo *info);
|
||||
int (*SaveLastLog)(const char *logDir, struct ErrorInfo *info);
|
||||
};
|
||||
|
||||
int BBoxRegisterModuleOps(struct ModuleOps *ops);
|
||||
int BBoxNotifyError(const char event[EVENT_MAX_LEN],
|
||||
const char module[MODULE_MAX_LEN],
|
||||
const char errorDesc[ERROR_DESC_MAX_LEN],
|
||||
int needSysReset);
|
||||
int BBoxDriverInit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* End of #if __cplusplus */
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#endif /* End of #ifndef BLACKBOX_H */
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BLACKBOX_ADAPTER_H
|
||||
#define BLACKBOX_ADAPTER_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* End of #if __cplusplus */
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#ifndef WEAK
|
||||
#define WEAK __attribute__((weak))
|
||||
#endif
|
||||
|
||||
/* The following functions need to be implemented by yourself */
|
||||
extern void SystemModuleDump(const char *logDir, struct ErrorInfo *info);
|
||||
extern void SystemModuleReset(struct ErrorInfo *info);
|
||||
extern int SystemModuleGetLastLogInfo(struct ErrorInfo *info);
|
||||
extern int SystemModuleSaveLastLog(const char *logDir, struct ErrorInfo *info);
|
||||
extern int FullWriteFile(const char *filePath, const char *buf, unsigned int bufSize, int isAppend);
|
||||
extern char *GetFaultLogPath(void);
|
||||
extern void RebootSystem(void);
|
||||
|
||||
/* The following functions have been implemented in the kernel */
|
||||
extern unsigned int LOS_BinarySemCreate(unsigned short count, unsigned int *semHandle);
|
||||
extern unsigned int LOS_SemPend(unsigned int semHandle, unsigned int timeout);
|
||||
extern unsigned int LOS_SemPost(unsigned int semHandle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* End of #if __cplusplus */
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#endif /* End of #ifndef BLACKBOX_ADAPTER_H */
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BLACKBOX_H
|
||||
#define BLACKBOX_H
|
||||
|
||||
#include "hiview_log.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* End of #if __cplusplus */
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#define ERROR_INFO_HEADER "#### error info ####\r\n"
|
||||
#define ERROR_INFO_HEADER_FORMAT "event: %s\r\nmodule: %s\r\nerrorDesc: %s\r\n"
|
||||
#define ERROR_INFO_MAX_LEN 768
|
||||
#define Min(a, b) (((a) > (b)) ? (b) : (a))
|
||||
#define BBOX_PRINT_ERR(format, ...) HILOG_DEBUG(HILOG_MODULE_HIVIEW, "bbox: func: %s line: %d, Err: " \
|
||||
format, __func__, __LINE__, ##__VA_ARGS__)
|
||||
#define BBOX_PRINT_INFO(format, ...) HILOG_DEBUG(HILOG_MODULE_HIVIEW, "bbox: Info: " format, ##__VA_ARGS__)
|
||||
|
||||
#define PATH_MAX_LEN 256
|
||||
#define EVENT_MAX_LEN 32
|
||||
#define MODULE_MAX_LEN 32
|
||||
#define ERROR_DESC_MAX_LEN 512
|
||||
#define MODULE_SYSTEM "SYSTEM"
|
||||
#define EVENT_SYSREBOOT "SYSREBOOT"
|
||||
#define EVENT_LONGPRESS "LONGPRESS"
|
||||
#define EVENT_COMBINATIONKEY "COMBINATIONKEY"
|
||||
#define EVENT_SUBSYSREBOOT "SUBSYSREBOOT"
|
||||
#define EVENT_POWEROFF "POWEROFF"
|
||||
#define EVENT_PANIC "PANIC"
|
||||
#define EVENT_SYS_WATCHDOG "SYSWATCHDOG"
|
||||
#define EVENT_HUNGTASK "HUNGTASK"
|
||||
#define EVENT_BOOTFAIL "BOOTFAIL"
|
||||
|
||||
struct ErrorInfo {
|
||||
char event[EVENT_MAX_LEN];
|
||||
char module[MODULE_MAX_LEN];
|
||||
char errorDesc[ERROR_DESC_MAX_LEN];
|
||||
};
|
||||
|
||||
struct ModuleOps {
|
||||
char module[MODULE_MAX_LEN];
|
||||
void (*Dump)(const char *logDir, struct ErrorInfo *info);
|
||||
void (*Reset)(struct ErrorInfo *info);
|
||||
int (*GetLastLogInfo)(struct ErrorInfo *info);
|
||||
int (*SaveLastLog)(const char *logDir, struct ErrorInfo *info);
|
||||
};
|
||||
|
||||
int BBoxRegisterModuleOps(struct ModuleOps *ops);
|
||||
int BBoxNotifyError(const char event[EVENT_MAX_LEN],
|
||||
const char module[MODULE_MAX_LEN],
|
||||
const char errorDesc[ERROR_DESC_MAX_LEN],
|
||||
int needSysReset);
|
||||
int BBoxDriverInit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* End of #if __cplusplus */
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#endif /* End of #ifndef BLACKBOX_H */
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BLACKBOX_ADAPTER_H
|
||||
#define BLACKBOX_ADAPTER_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* End of #if __cplusplus */
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#ifndef WEAK
|
||||
#define WEAK __attribute__((weak))
|
||||
#endif
|
||||
|
||||
/* The following functions need to be implemented by yourself */
|
||||
extern void SystemModuleDump(const char *logDir, struct ErrorInfo *info);
|
||||
extern void SystemModuleReset(struct ErrorInfo *info);
|
||||
extern int SystemModuleGetLastLogInfo(struct ErrorInfo *info);
|
||||
extern int SystemModuleSaveLastLog(const char *logDir, struct ErrorInfo *info);
|
||||
extern int FullWriteFile(const char *filePath, const char *buf, unsigned int bufSize, int isAppend);
|
||||
extern char *GetFaultLogPath(void);
|
||||
extern void RebootSystem(void);
|
||||
|
||||
/* The following functions have been implemented in the kernel */
|
||||
extern unsigned int LOS_BinarySemCreate(unsigned short count, unsigned int *semHandle);
|
||||
extern unsigned int LOS_SemPend(unsigned int semHandle, unsigned int timeout);
|
||||
extern unsigned int LOS_SemPost(unsigned int semHandle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* End of #if __cplusplus */
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#endif /* End of #ifndef BLACKBOX_ADAPTER_H */
|
|
@ -0,0 +1,26 @@
|
|||
# Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
|
||||
static_library("hidumper_static") {
|
||||
sources = [ "hidumper.c"]
|
||||
cflags = [ "-Wall" ]
|
||||
include_dirs = [ "//third_party/bounds_checking_function/include" ]
|
||||
deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
|
||||
}
|
||||
|
||||
lite_component("hidumper") {
|
||||
target_type = "executable"
|
||||
features = [ ":hidumper_static" ]
|
||||
}
|
|
@ -0,0 +1,177 @@
|
|||
|
||||
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
|
|
@ -0,0 +1,36 @@
|
|||
# hiviewdfx_hidumper_lite
|
||||
|
||||
#### Description
|
||||
{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
|
||||
|
||||
#### Software Architecture
|
||||
Software architecture description
|
||||
|
||||
#### Installation
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### Instructions
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### Contribution
|
||||
|
||||
1. Fork the repository
|
||||
2. Create Feat_xxx branch
|
||||
3. Commit your code
|
||||
4. Create Pull Request
|
||||
|
||||
|
||||
#### Gitee Feature
|
||||
|
||||
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
|
||||
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
|
||||
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
|
||||
4. The most valuable open source project [GVP](https://gitee.com/gvp)
|
||||
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
|
||||
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
|
@ -0,0 +1,39 @@
|
|||
# hiviewdfx_hidumper_lite
|
||||
|
||||
#### 介绍
|
||||
{**以下是 Gitee 平台说明,您可以替换此简介**
|
||||
Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
|
||||
无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
|
||||
|
||||
#### 软件架构
|
||||
软件架构说明
|
||||
|
||||
|
||||
#### 安装教程
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### 使用说明
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### 参与贡献
|
||||
|
||||
1. Fork 本仓库
|
||||
2. 新建 Feat_xxx 分支
|
||||
3. 提交代码
|
||||
4. 新建 Pull Request
|
||||
|
||||
|
||||
#### 特技
|
||||
|
||||
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
|
||||
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
|
||||
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
|
||||
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
|
||||
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
|
||||
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
|
@ -0,0 +1,217 @@
|
|||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "securec.h"
|
||||
|
||||
#define HIDUMPER_DEVICE "/dev/hidumper"
|
||||
#define USER_FAULT_ADDR 0x3
|
||||
#define USER_FAULT_VALUE 0x4
|
||||
#define PATH_MAX_LEN 256
|
||||
|
||||
#define ONE_OF_ARGC_PARAMETERS 1
|
||||
#define TWO_OF_ARGC_PARAMETERS 2
|
||||
#define THREE_OF_ARGC_PARAMETERS 3
|
||||
#define FOUR_OF_ARGC_PARAMETERS 4
|
||||
#define FIVE_OF_ARGC_PARAMETERS 5
|
||||
|
||||
#define BUF_SIZE_16 16
|
||||
|
||||
enum MemDumpType {
|
||||
DUMP_TO_STDOUT,
|
||||
DUMP_REGION_TO_STDOUT,
|
||||
DUMP_TO_FILE,
|
||||
DUMP_REGION_TO_FILE
|
||||
};
|
||||
|
||||
struct MemDumpParam {
|
||||
enum MemDumpType type;
|
||||
unsigned long long start;
|
||||
unsigned long long size;
|
||||
char filePath[PATH_MAX_LEN];
|
||||
};
|
||||
|
||||
#define HIDUMPER_IOC_BASE 'd'
|
||||
#define HIDUMPER_DUMP_ALL _IO(HIDUMPER_IOC_BASE, 1)
|
||||
#define HIDUMPER_CPU_USAGE _IO(HIDUMPER_IOC_BASE, 2)
|
||||
#define HIDUMPER_MEM_USAGE _IO(HIDUMPER_IOC_BASE, 3)
|
||||
#define HIDUMPER_TASK_INFO _IO(HIDUMPER_IOC_BASE, 4)
|
||||
#define HIDUMPER_INJECT_KERNEL_CRASH _IO(HIDUMPER_IOC_BASE, 5)
|
||||
#define HIDUMPER_DUMP_FAULT_LOG _IO(HIDUMPER_IOC_BASE, 6)
|
||||
#define HIDUMPER_MEM_DATA _IOW(HIDUMPER_IOC_BASE, 7, struct MemDumpParam)
|
||||
|
||||
static void Usage(void)
|
||||
{
|
||||
printf("Usage:\n"
|
||||
" hidumper dump cpu usage, memory usage and all tasks.\n"
|
||||
"or:\n"
|
||||
" hidumper -dc dump the cpu usage.\n"
|
||||
" hidumper -df dump the fault logs.\n"
|
||||
" hidumper -dm dump the memory usage.\n"
|
||||
" hidumper -dt dump all the tasks.\n"
|
||||
" hidumper -h help text for the tool.\n"
|
||||
" hidumper -ikc inject kernel crash for debug version.\n"
|
||||
" hidumper -iuc inject user crash for debug version.\n");
|
||||
printf(" hidumper -m dump memory to stdout in hex format for debug version.\n"
|
||||
" hidumper -m filepath dump memory to filepath in the device in hex format for "
|
||||
"debug version.\n"
|
||||
" hidumper -m memstart memsize dump memory with starting address memstart(hex) and\n"
|
||||
" size memsize(hex) to stdout in hex format for debug version.\n"
|
||||
" hidumper -m memstart memsize filepath dump memory with starting address memstart(hex) and\n"
|
||||
" size memsize(hex) to filepath in hex format for debug version.\n");
|
||||
}
|
||||
|
||||
static void ExecAction(int fd, unsigned int cmd)
|
||||
{
|
||||
if (fd < 0) {
|
||||
printf("Invalid fd: %d\n", fd);
|
||||
return;
|
||||
}
|
||||
|
||||
int ret = ioctl(fd, cmd, NULL);
|
||||
if (ret < 0) {
|
||||
printf("Failed to ioctl [%u], error [%s]\n", cmd, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
static void DumpALLInfo(int fd)
|
||||
{
|
||||
ExecAction(fd, HIDUMPER_DUMP_ALL);
|
||||
}
|
||||
|
||||
static void DumpCpuUsage(int fd)
|
||||
{
|
||||
ExecAction(fd, HIDUMPER_CPU_USAGE);
|
||||
}
|
||||
|
||||
static void DumpMemUsage(int fd)
|
||||
{
|
||||
ExecAction(fd, HIDUMPER_MEM_USAGE);
|
||||
}
|
||||
|
||||
static void DumpTaskInfo(int fd)
|
||||
{
|
||||
ExecAction(fd, HIDUMPER_TASK_INFO);
|
||||
}
|
||||
|
||||
static void DumpMemData(int fd, struct MemDumpParam *param)
|
||||
{
|
||||
#ifdef OHOS_DEBUG
|
||||
int ret = ioctl(fd, HIDUMPER_MEM_DATA, param);
|
||||
if (ret < 0) {
|
||||
printf("Failed to ioctl [%s], error [%s]\n", HIDUMPER_DEVICE, strerror(errno));
|
||||
}
|
||||
#else
|
||||
(void)fd;
|
||||
(void)param;
|
||||
printf("Unsupported!\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
static void InjectKernelCrash(int fd)
|
||||
{
|
||||
#ifdef OHOS_DEBUG
|
||||
ExecAction(fd, HIDUMPER_INJECT_KERNEL_CRASH);
|
||||
#else
|
||||
(void)fd;
|
||||
printf("Unsupported!\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
static void DumpFaultLog(int fd)
|
||||
{
|
||||
ExecAction(fd, HIDUMPER_DUMP_FAULT_LOG);
|
||||
}
|
||||
|
||||
static void InjectUserCrash(void)
|
||||
{
|
||||
#ifdef OHOS_DEBUG
|
||||
*((int *)USER_FAULT_ADDR) = USER_FAULT_VALUE;
|
||||
#else
|
||||
printf("Unsupported!\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
int ParameterMatching(int argc, const char *argv[], int fd)
|
||||
{
|
||||
struct MemDumpParam param;
|
||||
if (argc == ONE_OF_ARGC_PARAMETERS) {
|
||||
DumpALLInfo(fd);
|
||||
} else if (argc == TWO_OF_ARGC_PARAMETERS && strcmp(argv[ONE_OF_ARGC_PARAMETERS], "-dc") == 0) {
|
||||
DumpCpuUsage(fd);
|
||||
} else if (argc == TWO_OF_ARGC_PARAMETERS && strcmp(argv[ONE_OF_ARGC_PARAMETERS], "-df") == 0) {
|
||||
DumpFaultLog(fd);
|
||||
} else if (argc == TWO_OF_ARGC_PARAMETERS && strcmp(argv[ONE_OF_ARGC_PARAMETERS], "-dm") == 0) {
|
||||
DumpMemUsage(fd);
|
||||
} else if (argc == TWO_OF_ARGC_PARAMETERS && strcmp(argv[ONE_OF_ARGC_PARAMETERS], "-dt") == 0) {
|
||||
DumpTaskInfo(fd);
|
||||
} else if (argc == TWO_OF_ARGC_PARAMETERS && strcmp(argv[ONE_OF_ARGC_PARAMETERS], "-ikc") == 0) {
|
||||
InjectKernelCrash(fd);
|
||||
} else if (argc == TWO_OF_ARGC_PARAMETERS && strcmp(argv[ONE_OF_ARGC_PARAMETERS], "-iuc") == 0) {
|
||||
InjectUserCrash();
|
||||
} else if (argc == TWO_OF_ARGC_PARAMETERS && strcmp(argv[ONE_OF_ARGC_PARAMETERS], "-m") == 0) {
|
||||
param.type = DUMP_TO_STDOUT;
|
||||
DumpMemData(fd, ¶m);
|
||||
} else if (argc == THREE_OF_ARGC_PARAMETERS && strcmp(argv[ONE_OF_ARGC_PARAMETERS], "-m") == 0) {
|
||||
param.type = DUMP_TO_FILE;
|
||||
if (strncpy_s(param.filePath, sizeof(param.filePath),
|
||||
argv[TWO_OF_ARGC_PARAMETERS], sizeof(param.filePath) - 1) != EOK) {
|
||||
printf("param.filePath is not enough or strncpy_s failed\n");
|
||||
return -1;
|
||||
}
|
||||
DumpMemData(fd, ¶m);
|
||||
} else if (argc == FOUR_OF_ARGC_PARAMETERS && strcmp(argv[ONE_OF_ARGC_PARAMETERS], "-m") == 0) {
|
||||
param.type = DUMP_TO_STDOUT;
|
||||
param.start = strtoull(argv[TWO_OF_ARGC_PARAMETERS], NULL, BUF_SIZE_16);
|
||||
param.size = strtoull(argv[THREE_OF_ARGC_PARAMETERS], NULL, BUF_SIZE_16);
|
||||
DumpMemData(fd, ¶m);
|
||||
} else if (argc == FIVE_OF_ARGC_PARAMETERS && strcmp(argv[ONE_OF_ARGC_PARAMETERS], "-m") == 0) {
|
||||
param.type = DUMP_TO_FILE;
|
||||
param.start = strtoull(argv[TWO_OF_ARGC_PARAMETERS], NULL, BUF_SIZE_16);
|
||||
param.size = strtoull(argv[THREE_OF_ARGC_PARAMETERS], NULL, BUF_SIZE_16);
|
||||
if (strncpy_s(param.filePath, sizeof(param.filePath),
|
||||
argv[FOUR_OF_ARGC_PARAMETERS], sizeof(param.filePath) - 1) != EOK) {
|
||||
printf("param.filePath is not enough or strncpy_s failed\n");
|
||||
return -1;
|
||||
}
|
||||
DumpMemData(fd, ¶m);
|
||||
} else {
|
||||
Usage();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int fd = -1;
|
||||
fd = open(HIDUMPER_DEVICE, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
printf("Failed to open [%s], error [%s]\n", HIDUMPER_DEVICE, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = ParameterMatching(argc, argv, fd);
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
# Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
|
||||
static_library("hidumper_mini") {
|
||||
sources = [
|
||||
"hidumper_core.c",
|
||||
"hidumper_adapter.c",
|
||||
]
|
||||
include_dirs = [
|
||||
"//base/hiviewdfx/hidumper_lite/mini/interfaces/native/kits",
|
||||
"//kernel/liteos_m/kernel/include",
|
||||
"//kernel/liteos_m/utils",
|
||||
"//kernel/liteos_m/kernel/arch/include",
|
||||
"//kernel/liteos_m/kal/posix/include"
|
||||
]
|
||||
cflags = [ "-Wall" ]
|
||||
deps = []
|
||||
}
|
|
@ -13,14 +13,17 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "hidumper.h"
|
||||
#include "hidumper_adapter.h"
|
||||
#include "ohos_types.h"
|
||||
#include "ohos_init.h"
|
||||
#include <securec.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "securec.h"
|
||||
|
||||
#include "hidumper_adapter.h"
|
||||
|
||||
#include "hidumper.h"
|
||||
#include "ohos_init.h"
|
||||
#include "ohos_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
@ -103,4 +106,4 @@ CORE_INIT_PRI(HiDumperAdapterInit, 3);
|
|||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
|
@ -13,11 +13,12 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "hidumper.h"
|
||||
#include <securec.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "hidumper.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
|
@ -71,7 +72,7 @@ static void InjectKernelCrash(void)
|
|||
int *ptr = (int *)FAULT_ADDR;
|
||||
*ptr = FAULT_VALUE;
|
||||
#else
|
||||
printf("Fault inject isn't supported in release version!\n");
|
||||
printf("Unsupported!\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -92,23 +93,20 @@ int HiDumperRegisterAdapter(struct HiDumperAdapter *pAdapter)
|
|||
printf("Invalid adapter funcs!\n");
|
||||
return -1;
|
||||
}
|
||||
memcpy_s(&g_hidumperAdapter, sizeof(g_hidumperAdapter),
|
||||
pAdapter, sizeof(*pAdapter));
|
||||
if (memcpy_s(&g_hidumperAdapter, sizeof(g_hidumperAdapter),
|
||||
pAdapter, sizeof(*pAdapter)) != EOK) {
|
||||
printf("memcpy_s is error\n");
|
||||
}
|
||||
g_isAdapterRegistered = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int at_hidumper(unsigned int argc, const char **argv)
|
||||
void ParameterMatching(int argc, const char *argv[])
|
||||
{
|
||||
if (g_isAdapterRegistered == 0) {
|
||||
printf("No adapter has been registered!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (argc == 0) {
|
||||
DumpAllInfo();
|
||||
} else if (argc == 1) {
|
||||
} else if (argc == ONE_OF_ARGC_PARAMETERS) {
|
||||
if (strcmp(argv[0], "-h") == 0) {
|
||||
Usage();
|
||||
} else if (strcmp(argv[0], "-dc") == 0) {
|
||||
|
@ -128,29 +126,40 @@ unsigned int at_hidumper(unsigned int argc, const char **argv)
|
|||
#ifdef OHOS_DEBUG
|
||||
g_hidumperAdapter.DumpAllMem();
|
||||
#else
|
||||
printf("mem dump isn't supported in release version!\n");
|
||||
printf("Unsupported!\n");
|
||||
#endif
|
||||
} else {
|
||||
Usage();
|
||||
}
|
||||
} else if (argc == 2 && strcmp(argv[0], "-m") == 0) {
|
||||
printf("Unsupported!\r\n");
|
||||
} else if (argc == 3) {
|
||||
} else if (argc == TWO_OF_ARGC_PARAMETERS && strcmp(argv[0], "-m") == 0) {
|
||||
printf("Unsupported!\n");
|
||||
} else if (argc == THREE_OF_ARGC_PARAMETERS) {
|
||||
if (strcmp(argv[0], "-m") == 0) {
|
||||
#ifdef OHOS_DEBUG
|
||||
g_hidumperAdapter.DumpMemRegion(strtoull(argv[1], NULL, 16),
|
||||
strtoull(argv[2], NULL, 16));
|
||||
g_hidumperAdapter.DumpMemRegion(
|
||||
strtoull(argv[ONE_OF_ARGC_PARAMETERS], NULL, BUF_SIZE_16),
|
||||
strtoull(argv[TWO_OF_ARGC_PARAMETERS], NULL, BUF_SIZE_16));
|
||||
#else
|
||||
printf("mem dump isn't supported in release version!\n");
|
||||
printf("Unsupported!\n");
|
||||
#endif
|
||||
} else {
|
||||
Usage();
|
||||
}
|
||||
} else if (argc == 4 && strcmp(argv[0], "-m") == 0) {
|
||||
} else if (argc == FOUR_OF_ARGC_PARAMETERS && strcmp(argv[0], "-m") == 0) {
|
||||
printf("Unsupported!\r\n");
|
||||
} else {
|
||||
Usage();
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int at_hidumper(unsigned int argc, const char **argv)
|
||||
{
|
||||
if (g_isAdapterRegistered == 0) {
|
||||
printf("No adapter has been registered!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
ParameterMatching(argc, argv);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef HIDUMPER_H
|
||||
#define HIDUMPER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* End of #if __cplusplus */
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
struct HiDumperAdapter {
|
||||
int (*DumpSysInfo)(void);
|
||||
int (*DumpCpuUsage)(void);
|
||||
int (*DumpMemUsage)(void);
|
||||
int (*DumpTaskInfo)(void);
|
||||
int (*DumpFaultLog)(void);
|
||||
int (*DumpMemRegion)(unsigned long long addr, unsigned long long size);
|
||||
int (*DumpAllMem)(void);
|
||||
};
|
||||
|
||||
int HiDumperRegisterAdapter(struct HiDumperAdapter *pAdapter);
|
||||
unsigned int at_hidumper(unsigned int argc, const char **argv);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* End of #if __cplusplus */
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#endif /* End of #ifndef HIDUMPER_H */
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef HIDUMPER_ADAPTER_H
|
||||
#define HIDUMPER_ADAPTER_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* End of #if __cplusplus */
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#ifndef WEAK
|
||||
#define WEAK __attribute__((weak))
|
||||
#endif
|
||||
|
||||
extern int DumpSysInfo(void);
|
||||
extern int DumpCpuUsage(void);
|
||||
extern int DumpMemUsage(void);
|
||||
extern int DumpTaskInfo(void);
|
||||
extern int DumpFaultLog(void);
|
||||
extern int DumpMemRegion(unsigned long long addr, unsigned long long size);
|
||||
extern int DumpAllMem(void);
|
||||
extern int PlatformHiDumperIinit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* End of #if __cplusplus */
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#endif /* End of #ifndef HIDUMPER_ADAPTER_H */
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef HIDUMPER_H
|
||||
#define HIDUMPER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* End of #if __cplusplus */
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#define ONE_OF_ARGC_PARAMETERS 1
|
||||
#define TWO_OF_ARGC_PARAMETERS 2
|
||||
#define THREE_OF_ARGC_PARAMETERS 3
|
||||
#define FOUR_OF_ARGC_PARAMETERS 4
|
||||
|
||||
#define BUF_SIZE_16 16
|
||||
|
||||
struct HiDumperAdapter {
|
||||
int (*DumpSysInfo)(void);
|
||||
int (*DumpCpuUsage)(void);
|
||||
int (*DumpMemUsage)(void);
|
||||
int (*DumpTaskInfo)(void);
|
||||
int (*DumpFaultLog)(void);
|
||||
int (*DumpMemRegion)(unsigned long long addr, unsigned long long size);
|
||||
int (*DumpAllMem)(void);
|
||||
};
|
||||
|
||||
int HiDumperRegisterAdapter(struct HiDumperAdapter *pAdapter);
|
||||
unsigned int at_hidumper(unsigned int argc, const char **argv);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* End of #if __cplusplus */
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#endif /* End of #ifndef HIDUMPER_H */
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef HIDUMPER_ADAPTER_H
|
||||
#define HIDUMPER_ADAPTER_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* End of #if __cplusplus */
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#ifndef WEAK
|
||||
#define WEAK __attribute__((weak))
|
||||
#endif
|
||||
|
||||
extern int DumpSysInfo(void);
|
||||
extern int DumpCpuUsage(void);
|
||||
extern int DumpMemUsage(void);
|
||||
extern int DumpTaskInfo(void);
|
||||
extern int DumpFaultLog(void);
|
||||
extern int DumpMemRegion(unsigned long long addr, unsigned long long size);
|
||||
extern int DumpAllMem(void);
|
||||
extern int PlatformHiDumperIinit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* End of #if __cplusplus */
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#endif /* End of #ifndef HIDUMPER_ADAPTER_H */
|
|
@ -12,28 +12,29 @@
|
|||
# limitations under the License.
|
||||
|
||||
declare_args() {
|
||||
ohos_hiviewdfx_hievent_lite_fault_file_size = 1024
|
||||
ohos_hiviewdfx_hievent_lite_ue_file_size = 1024
|
||||
ohos_hiviewdfx_hievent_lite_stat_file_size = 1024
|
||||
ohos_hiviewdfx_hievent_lite_fault_file_size = 1024
|
||||
ohos_hiviewdfx_hievent_lite_ue_file_size = 1024
|
||||
ohos_hiviewdfx_hievent_lite_stat_file_size = 1024
|
||||
}
|
||||
|
||||
static_library("hievent_lite") {
|
||||
sources = [
|
||||
"frameworks/hiview_event.c",
|
||||
"frameworks/hiview_output_event.c",
|
||||
]
|
||||
cflags = [ "-Wall" ]
|
||||
defines = [
|
||||
"FAULT_EVENT_FILE_SIZE = $ohos_hiviewdfx_hievent_lite_fault_file_size",
|
||||
"UE_EVENT_FILE_SIZE = $ohos_hiviewdfx_hievent_lite_ue_file_size",
|
||||
"STAT_EVENT_FILE_SIZE = $ohos_hiviewdfx_hievent_lite_stat_file_size"
|
||||
]
|
||||
include_dirs = [
|
||||
"//base/hiviewdfx/hievent_lite/interfaces/native/innerkits",
|
||||
"//base/hiviewdfx/hiview_lite",
|
||||
"//utils/native/lite/include",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr",
|
||||
]
|
||||
public_configs = ["//base/hiviewdfx/hiview_lite:hiview_lite_config"]
|
||||
deps = ["//base/hiviewdfx/hiview_lite"]
|
||||
sources = [
|
||||
"frameworks/hiview_event.c",
|
||||
"frameworks/hiview_output_event.c",
|
||||
]
|
||||
cflags = [ "-Wall" ]
|
||||
defines = [
|
||||
"FAULT_EVENT_FILE_SIZE = $ohos_hiviewdfx_hievent_lite_fault_file_size",
|
||||
"UE_EVENT_FILE_SIZE = $ohos_hiviewdfx_hievent_lite_ue_file_size",
|
||||
"STAT_EVENT_FILE_SIZE = $ohos_hiviewdfx_hievent_lite_stat_file_size",
|
||||
]
|
||||
include_dirs = [
|
||||
"//base/hiviewdfx/hievent_lite/interfaces/native/innerkits",
|
||||
"//base/hiviewdfx/hiview_lite",
|
||||
"//utils/native/lite/include",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr",
|
||||
]
|
||||
public_configs = [ "//base/hiviewdfx/hiview_lite:hiview_lite_config" ]
|
||||
deps = [ "//base/hiviewdfx/hiview_lite" ]
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue