OpenHarmony开发08 —— 复现A1 thread

OpenHarmony开发08 —— 复现A1 thread

技术文档:applications/BearPi/BearPi-HM_Nano/sample/A1_kernal_thread/README.md · 小熊派开源社区/BearPi-HM_Nano - Gitee.com

  1. 远程ssh连接小熊派

  2. 阅读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);
    
    
  3. 代码中创建了两个进程,进程内部打印进程信息

  4. 修改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",
    ]
}



  1. 在putty连接并且切换到project目录后,输入hpm dist进行编译

    image

  2. 把虚拟机中out/Hi3861_wifiiot_app_allinone.bin复制到windows,用Hiburn进行烧录

  3. baud设置为921600,点击connect

  4. 按下开发板上的reset键,开始下载

    img

  5. 千万别忘记勾选auto burn选项!

    image

  6. 在putty进行捕捉串口日志

  7. 点击session-logging如图设置

    image

  8. 选择serial,设置com号,速率设为115200

  9. 实验结果:

image

posted @   ZzTzZ  阅读(30)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示