5

Openharmony 添加内核驱动(L1)

 2 years ago
source link: https://os.51cto.com/article/705085.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Openharmony 添加内核驱动(L1)-51CTO.COM
Openharmony 添加内核驱动(L1)
作者:拓维信息_青松 2022-03-28 15:40:34
此文章以openharmony 3.1代码基础,介绍liteos-a ipcamera_hispark_taurus上添加khdf步骤。

18c54521714b863681c072f87991f935a04c32.png

​想了解更多内容,请访问:​

​51CTO和华为官方合作共建的鸿蒙技术社区​

​https://ost.51cto.com​

此文章以openharmony 3.1代码基础

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

驱动目录结构

d4547fc71a12735ad5351454f34948937c12f3.png

驱动代码见附件。

驱动目录以外的文件配置

文件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

c2aa93d947c7a71eb9f075619c377629d497cf.png

文件drivers\adapter\khdf\liteos\Kconfig。

source "../../drivers/adapter/khdf/liteos/my_sample_driver/Kconfig"

d1fa2cc28aa296b9299565c95572c1bd3588c0.png

文件drivers\adapter\khdf\liteos\BUILD.gn。

78ae9c9858c22cd73160809fad3af5cf5e448c.png

文件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.
                }
            }
        }

05e51182118f5d5b0c445879c3c6caab9fdbd3.png

驱动编译配置

从代码根目录切换到kernel/liteos_a/。

cd kernel/liteos_a/

执行make menuconfig。

选择driver。

7120d3464876fd533830637dfd2fd6a4d7d305.png

选择framework support。

78a2cda609a473b7a4603452e421a220975093.png

选择my_sample driver。

39dbd3818034e5eb1a6069c690c9ce2538f219.png

按q,保存退出。

驱动调用可执行程序

2562aa37920463194a50278ea5c763ae96a2ce.png

驱动调用代码。

924843980877b14a1e98607a579a7f36f18cc4.png

驱动调用可执行程序详细代码见附件。

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

文件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":[] }
        ]
      }

f7a13bb3786964d0e26887e93bea76c4c7243d.png

编译环境参考:​​3516应用调用到驱动实践​​。

执行下面2条命令。

hb set
.

d2639a2736747a2ef1655490d5d9eab904d15f.png

执行hb build -f。

f7d549954eeead99644531890cc85067f53a3f.png

烧录步骤参考:​​3516应用调用到驱动实践​​。

切换到/bin目录下执行:./my_sample_driver_test。

结果如图:

592bf437732987e4eb050200147d446fe29546.png

​官网文档​

​想了解更多内容,请访问:​

​51CTO和华为官方合作共建的鸿蒙技术社区​

​https://ost.51cto.com​

71eea7105a1cf9982d2996c42d853b97bd50ef.jpg


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK