OpenHarmony开发08 —— 复现A1 thread
-
远程ssh连接小熊派
-
阅读
thread_example.c
,/* * Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology 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 <string.h> #include <unistd.h> #include "ohos_init.h" #include "cmsis_os2.h" /*****任务一*****/ void thread1(void) { int sum = 0; while (1) { printf("This is BearPi Harmony Thread1----%d\r\n", sum++); usleep(1000000); } } /*****任务二*****/ void thread2(void) { int sum = 0; while (1) { printf("This is BearPi Harmony Thread2----%d\r\n", sum++); usleep(500000); } } /*****任务创建*****/ static void Thread_example(void) { osThreadAttr_t attr; attr.name = "thread1"; attr.attr_bits = 0U; attr.cb_mem = NULL; attr.cb_size = 0U; attr.stack_mem = NULL; attr.stack_size = 1024 * 4; attr.priority = 25; if (osThreadNew((osThreadFunc_t)thread1, NULL, &attr) == NULL) { printf("Falied to create thread1!\n"); } attr.name = "thread2"; if (osThreadNew((osThreadFunc_t)thread2, NULL, &attr) == NULL) { printf("Falied to create thread2!\n"); } } APP_FEATURE_INIT(Thread_example);
-
代码中创建了两个进程,进程内部打印进程信息
-
修改
BearPi-Hm_Nano/sample
下的build.gn
,指定thread_example
# Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology 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")
lite_component("app") {
features = [
"A1_kernal_thread:thread_example",
#"A2_kernel_timer:timer_example",
#"A3_kernel_event:event_example",
#"A4_kernel_mutex:mutex_example",
#"A5_kernel_semaphore:semaphore_example",
#"A6_kernel_message:message_example",
#"B1_basic_led_blink:led_example",
"B2_basic_button:button_example",
#"B3_basic_pwm_led:pwm_example",
#"B4_basic_adc:adc_example",
#"B5_basic_i2c_nfc:i2c_example",
#"B6_basic_uart:uart_example",
#"C1_e53_sf1_mq2:e53_sf1_example",
#"C2_e53_ia1_temp_humi_pls:e53_ia1_example",
#"C3_e53_sc1_pls:e53_sc1_example",
#"C4_e53_sc2_axis:e53_sc2_example",
#"C5_e53_is1_infrared:e53_is1_example",
#"D1_iot_wifi_ap:wifi_ap",
#"D2_iot_wifi_sta_connect:wifi_sta_connect",
#"D3_iot_udp_client:udp_client",
#"D4_iot_tcp_server:tcp_server",
#"D5_iot_mqtt:iot_mqtt",
#"D6_iot_cloud_oc:oc_mqtt",
#"D7_iot_cloud_onenet:onenet_mqtt",
#"D8_iot_cloud_oc_smoke:cloud_oc_smoke",
#"D9_iot_cloud_oc_light:cloud_oc_light",
#"D10_iot_cloud_oc_manhole_cover:cloud_oc_manhole_cover",
#"D11_iot_cloud_oc_infrared:cloud_oc_infrared",
#"D12_iot_cloud_oc_agriculture:cloud_oc_agriculture",
#"D13_iot_cloud_oc_gps:cloud_oc_gps",
]
}
-
在putty连接并且切换到project目录后,输入
hpm dist
进行编译 -
把虚拟机中
out/Hi3861_wifiiot_app_allinone.bin
复制到windows,用Hiburn进行烧录 -
baud设置为921600,点击
connect
-
按下开发板上的reset键,开始下载
-
千万别忘记勾选auto burn选项!
-
在putty进行捕捉串口日志
-
点击
session-logging
如图设置 -
选择
serial
,设置com号,速率设为115200 -
实验结果: