您当前的位置: 首页 >  HarmonyOS

仙剑情缘

暂无认证

  • 2浏览

    0关注

    333博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

bearpi开发板之HarmonyOS编译框架介绍

仙剑情缘 发布时间:2022-04-24 22:32:09 ,浏览量:2

编译控制的Json文件

在这里插入图片描述

业务gn文件,这里以my_led目录下的为例

在这里插入图片描述

  • 编译后生的libmyled.a 在这里插入图片描述
模块gn文件,这里选择 "my_led:myled"模块参与编译
# 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",
        
        "my_led:myled",
 
    ]
}

注册入口函数
void my_led_example(void)
{    
    static uint8_t cnt;
    cnt++;
    printf("-------> my_led_example %d",cnt);
    usleep(1000000);
}
SYS_RUN(my_led_example);
  • 使用SYS_RUN宏关联入口函数,SYS_RUN宏原型如下:
#define SYS_RUN(func) LAYER_INITCALL_DEF(func, run, "run")
  • LAYER_INITCALL_DEF宏原型如下:
#define LAYER_INITCALL_DEF(func, layer, clayer) \
    LAYER_INITCALL(func, layer, clayer, 2)
  • LAYER_INITCALL宏原型如下:
#define LAYER_INITCALL(func, layer, clayer, priority)            \
    static const InitCall USED_ATTR __zinitcall_##layer##_##func \
        __attribute__((section(".zinitcall." clayer #priority ".init"))) = func
  • InitCall 原型
typedef void (*InitCall)(void);
  • USED_ATTR宏原型
#define USED_ATTR __attribute__((used))
  • SYS_RUN(my_led_example)展开分析:

  • LAYER_INITCALL_DEF(my_led_example, run, “run”)

  • LAYER_INITCALL(my_led_example, run, “run”, 2)

  • static const InitCall USED_ATTR __zinitcall_run_my_led_example attribute((section(“.zinitcall.run2.init”))) = my_led_example 这样函数指针_zinitcall_run_my_led_example指向了my_led_example,并编译到.zinitcall.run2.init段当中。

HOS_SystemInit中调用MODULE_INIT(run)来调用注册的入口函数my_led_example
void HOS_SystemInit(void)
{
   
    MODULE_INIT(bsp);
    MODULE_INIT(device);
    MODULE_INIT(core);
    SYS_INIT(service);
    SYS_INIT(feature);
    MODULE_INIT(run);
    SAMGR_Bootstrap();
}
  • MODULE_INIT宏原型如下:
#define MODULE_INIT(name)     \
    do {                      \
        MODULE_CALL(name, 0); \
    } while (0)

  • MODULE_CALL宏原型
#define MODULE_CALL(name, step)                                      \
    do {                                                             \
        InitCall *initcall = (InitCall *)(MODULE_BEGIN(name, step)); \
        InitCall *initend = (InitCall *)(MODULE_END(name, step));    \
        for (; initcall             
关注
打赏
1658017818
查看更多评论
0.7690s