美文网首页
openharmony:hilog_lite组件移植

openharmony:hilog_lite组件移植

作者: xEndLess | 来源:发表于2022-07-28 15:18 被阅读0次

    kernel:litoes_m
    MCU:stm32f407zgt6

    本文仅介绍HiLog_Lite组件的移植过程,HiLog_Lite原理介绍请移步zh-cn/device-dev/subsystems/subsys-dfx-hilog-lite.md · OpenHarmony/docs - Gitee.com

    概述

    HiLog_Lite是针对轻量系统类设备(参考内存≥128KiB)、小型系统类设备(参考内存≥1MiB)的hilog框架,实现了日志的打印、输出和流控功能。

    1. 源码位置

    hilog_lite组件的源码在路径base/hiviewdfx/hilog_lite/frameworks/mini/hiview_log.c

    //base/hiviewdfx/hilog_lite/frameworks/mini/hiview_log.c
    /* The first step does not involve memory allocation. */
    static void HiLogInit(void)
    {
        HIVIEW_UartPrint("hilog will init.\n");
        InitCoreLogOutput();
    
        /* The module that is not registered cannot print the log. */
        if (HiLogRegisterModule(HILOG_MODULE_HIVIEW, "HIVIEW") == FALSE ||
            HiLogRegisterModule(HILOG_MODULE_SAMGR, "SAMGR") == FALSE ||
            HiLogRegisterModule(HILOG_MODULE_UPDATE, "UPDATE") == FALSE ||
            HiLogRegisterModule(HILOG_MODULE_ACE, "ACE") == FALSE ||
            HiLogRegisterModule(HILOG_MODULE_AAFWK, "AAFWK") == FALSE ||
            HiLogRegisterModule(HILOG_MODULE_APP, "APP") == FALSE ||
            HiLogRegisterModule(HILOG_MODULE_GRAPHIC, "GRAPHIC") == FALSE ||
            HiLogRegisterModule(HILOG_MODULE_MEDIA, "MEDIA") == FALSE ||
            HiLogRegisterModule(HILOG_MODULE_DMS, "DMS") == FALSE ||
            HiLogRegisterModule(HILOG_MODULE_SEN, "SEN") == FALSE ||
            HiLogRegisterModule(HILOG_MODULE_SCY, "SCY") == FALSE ||
            HiLogRegisterModule(HILOG_MODULE_SOFTBUS, "SOFTBUS") == FALSE ||
            HiLogRegisterModule(HILOG_MODULE_POWERMGR, "POWERMGR") == FALSE ||
            HiLogRegisterModule(HILOG_MODULE_UIKIT, "UIKIT") == FALSE) {
            return;
        }
    
        HiviewRegisterInitFunc(HIVIEW_CMP_TYPE_LOG, InitLogOutput);
        HiviewRegisterInitFunc(HIVIEW_CMP_TYPE_LOG_LIMIT, InitLogLimit);
        HILOG_DEBUG(HILOG_MODULE_HIVIEW, "hilog init success.");
    }
    CORE_INIT_PRI(HiLogInit, 0);
    

    根据CORE_INIT_PRI可以看出,为了使用hilog_lite组件,需要先移植bootstrap组件。

    2. 组件加入编译

    vendor/fx/TunnelControl/config.json中增加如下内容。

            {
                "subsystem": "startup",
                "components": [
                    {
                        "component": "bootstrap_lite"
                    }
                ]
            },
            {
                "subsystem": "distributedschedule",
                "components": [
                  {
                    "component": "samgr_lite",
                    "features": []
                  }
                ]
            },
            {
                "subsystem": "hiviewdfx",
                "components": [
                  {
                    "component": "hilog_lite",
                    "features": []
                  }
                ]
            }
    

    3.初始化

    在main.c中调用bootstrap组件的初始化函数OHOS_SystemInit

    /**
     * @brief  The application entry point.
     * @retval int
     */
    int main(void)
    {
        /* MCU Configuration--------------------------------------------------------*/
    
        /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
        HAL_Init();
        /* Configure the system clock */
        SystemClock_Config();
    
        /* Initialize all configured peripherals */
        MX_GPIO_Init();
        //   MX_IWDG_Init();
        HAL_Delay(3000);
        uart_printf_shell_init();
        UINT32 ret = -1;![unalign.png](https://img.haomeiwen.com/i14177609/46c4cae67955a6d9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
    
        ret = LOS_KernelInit();
        OHOS_SystemInit();
    #ifdef LOS_SHELL
        LosShellInit();
    #endif // LOS_SHELL
        led_task_init();
        if (ret == LOS_OK)
        {
            LOS_Start();
        }
        while (1)
        {
            __asm volatile("wfi");
    
        }
    }
    

    4.不使能不对齐访问异常

    进入liteos_m目录下,make menuconfig。不选中Enable Unaligned Exception。

    unalign.png
    如果选中Enable Unaligned Exception。hilog_lite组件源码中的pack(1)会导致操作指针时,引起usage fault。

    相关文章

      网友评论

          本文标题:openharmony:hilog_lite组件移植

          本文链接:https://www.haomeiwen.com/subject/ihczirtx.html