OpenHarmony 3516添加内核驱动(L1) 原创 精华

碼磚民工
发布于 2022-3-26 16:50
浏览
6收藏

@toc

简介

此文章以OpenHarmony 3.1代码基础

  • 介绍liteos-a ipcamera_hispark_taurus上添加khdf步骤。
  • 介绍驱动的简单调用(3516开发板:HiSpark_AI_Hi3516D_One_Light_VER.B开发板上测试)

驱动添加

驱动目录结构

OpenHarmony 3516添加内核驱动(L1)-鸿蒙开发者社区
驱动代码见附件

驱动目录以外的文件配置

  • 文件drivers\adapter\khdf\liteos\hdf_lite.mk
# my sample test
ifeq ($(LOSCFG_DRIVERS_HDF_MY_SAMPLE_DRIVER), y)
    LITEOS_BASELIB += -lmy_sample_driver
    LIB_SUBDIRS    +=  $(LITEOS_DRIVERS_HDF)/my_sample_driver
endif

OpenHarmony 3516添加内核驱动(L1)-鸿蒙开发者社区

  • 文件drivers\adapter\khdf\liteos\Kconfig
source "../../drivers/adapter/khdf/liteos/my_sample_driver/Kconfig"

OpenHarmony 3516添加内核驱动(L1)-鸿蒙开发者社区

  • 文件drivers\adapter\khdf\liteos\BUILD.gn
    OpenHarmony 3516添加内核驱动(L1)-鸿蒙开发者社区
  • 文件vendor\hisilicon\hispark_taurus\hdf_config\device_info\device_info.hcs
        my_sample :: host {
            hostName = "my_sample_host";
            device_mysample :: device {
                device0 :: deviceNode {             // DeviceNode of the sample driver
                    policy = 2;                     // Driver service release policy. For details, see section Driver Service Management.
                    priority= 10;                  // Driver startup priority (0-200). A larger value indicates a lower priority. The default value 100 is recommended. If the priorities are the same, the device loading sequence is random.
                    preload = 0;                    // On-demand loading of the driver. For details, see "NOTE" at the end of this section.
                    permission = 0664;              // Permission for the driver to create device nodes.
                    moduleName = "my_sample_driver";       // Driver name. The value of this field must be the same as the value of moduleName in the driver entry structure.
                    serviceName = "my_sample_service";     // Name of the service released by the driver. The name must be unique.
                }
            }
        }

OpenHarmony 3516添加内核驱动(L1)-鸿蒙开发者社区

驱动编译配置

  • 从代码根目录切换到kernel/liteos_a/
cd kernel/liteos_a/
  • 执行make menuconfig
    选择driver
    OpenHarmony 3516添加内核驱动(L1)-鸿蒙开发者社区
    选择framework support
    OpenHarmony 3516添加内核驱动(L1)-鸿蒙开发者社区
    选择my_sample driver
    OpenHarmony 3516添加内核驱动(L1)-鸿蒙开发者社区
    q,保存退出

驱动调用可执行程序

目录结构

OpenHarmony 3516添加内核驱动(L1)-鸿蒙开发者社区

  • 驱动调用代码
    OpenHarmony 3516添加内核驱动(L1)-鸿蒙开发者社区
    驱动调用可执行程序详细代码见附件

代码目录结构之外的文件配置

  • 文件build\lite\components\myapp.json
{
  "components": [
    {
      "component": "myapp",
      "description": "my app",
      "optional": "false",
      "dirs": [
        "myapp"
      ],
      "targets": [
        "//myapp:myapp"
      ],
      "rom": "",
      "ram": "",
      "output": [
      ],
      "adapted_kernel": [
        "liteos_a",
        "liteos_m"
      ],
      "features": [],
      "deps": {
        "third_party": [
          "bounds_checking_function"
        ],
        "components": []
      }
    }
  ]
}

  • 文件vendor\hisilicon\hispark_taurus\config.json
     {
        "subsystem": "myapp",
        "components": [
          { "component": "myapp", "features":[] }
        ]
      }

OpenHarmony 3516添加内核驱动(L1)-鸿蒙开发者社区

编译

编译环境参考:3516应用调用到驱动实践
执行下面2条命令。

hb set
.

OpenHarmony 3516添加内核驱动(L1)-鸿蒙开发者社区
执行hb build -f
OpenHarmony 3516添加内核驱动(L1)-鸿蒙开发者社区

烧录测试

烧录步骤参考:3516应用调用到驱动实践
切换到/bin目录下执行:./my_sample_driver_test
结果如图:
OpenHarmony 3516添加内核驱动(L1)-鸿蒙开发者社区

官网文档

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
add_driver.rar 9.22K 41次下载
已于2022-12-15 14:21:04修改
9
收藏 6
回复
举报
2条回复
按时间正序
/
按时间倒序
民之码农
民之码农

666

4
回复
2022-3-28 08:32:49
科技维度
科技维度

好文收藏了

 

2
回复
2022-3-29 11:18:52
回复
    相关推荐