首页 > 其他分享 >OpenHarmony开发08 —— 复现A1 thread

OpenHarmony开发08 —— 复现A1 thread

时间:2023-01-09 17:55:53浏览次数:60  
标签:OpenHarmony License thread 08 iot oc example cloud attr

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

标签:OpenHarmony,License,thread,08,iot,oc,example,cloud,attr
From: https://www.cnblogs.com/ZzTzZ/p/17037772.html

相关文章

  • zookeeper占用8080端口的处理
    今天部署项目,启动时提示8080端口已被占用。用以下命令查看占用情况:lsof-itcp:8080根据列出的信息,查询pid:ps-ef|greppid发现是已经安装好的zookeeper占用了808......
  • 线程数据共享与安全-ThreadLocal
    1.ThreadLocal作用在一个线程中,线程安全的共享数据(实现在同一个线程中共享数据,从而解决多线程数据安全的问题)分析:1.数据:可以是普通变量,对象,数组等。(在一个线程中)一个数据......
  • 【2023.01.08】NUC9I9安装PVE7.3和OpenWrt,WinServer
    前面的教程可以看:【2022.11.17】N5105安装PVE系统,关联proxmox-Mokou-博客园(cnblogs.com)本文主要做一个备注,方便以后查阅同时改路由器将作为一个旁路由使用,不作为......
  • 0801安卓就业班毕业后
    1.1.代码练习提速学员学习的时候只是有一两行代码有问题造成整个程序跑不起来,这一两行学员要找很久为了提高效率现在推荐大家使用一款软件 Be......
  • ThreadLocal源码解析及实战应用
    作者:京东物流闫鹏勃1什么是ThreadLocal?ThreadLocal是一个关于创建线程局部变量的类。通常情况下,我们创建的变量是可以被任何一个线程访问并修改的。而使用ThreadLocal......
  • ThreadLocal原理及使用场景
    ThreadLocalThreadLocal意为线程本地变量,用于解决多线程并发时访问共享变量的问题。所谓的共享变量指的是在堆中的实例、静态属性和数组;对于共享数据的访问受Java的内存模型......
  • rt-thread 中pwm组件不起作用的问题 stm32L431
    board.h中打开如下定义,并新增要使用的通道#defineBSP_USING_PWM1/*#defineBSP_USING_PWM2*//*#defineBSP_USING_PWM3*/#defineBSP_USING_PWM1_CH1drv_pwm.c中......
  • 12.30-0108文献阅读总结
      本周是论文研读第一周,可是一篇都没有仔细读完,怎样才算仔细研读呢,心里的标准是这样的:  1、从一定程度上区分筛选出好论文;  2、对作者及研究机构分析,在大实验的官......
  • CF1088C
    Solution一个很简单的想法就是将整个序列变成\(1\)到\(n\),这时我们需要对每个\(a_i\)执行\(\bmod(a_i-i)\)的操作,但是可能\(a_i<i\),所以我们只需要在一开始加上......
  • 守护线程ScheduledThreadPoolExecutor中两个方法的区别demo
    packagecom.pzistart.msgdemoimpl.renlock;importjdk.nashorn.internal.ir.Block;importjavax.annotation.security.RunAs;importjavax.sound.sampled.FloatContr......