更多内容请访问:与华为官方HDF驱动框架合作建立的鸿蒙技术社区https://harmonyos.51cto.com,贴出链接。你得自己用HDF写驱动来测试移植的效果。不说代码是最现实的,看代码就知道了。1、内核态驱动代码是一个简单的测试驱动,可以认为是一个串口驱动。因为是linux内核下,驱动放在linux\platform\uart目录下。drivers\adapter\khdf\linux\platform\uart\my_hdf_uart.c#include"hdf_device_desc.h"//驱动开发相关能力接口的HDF框架头文件#include"hdf_log.h"//HDF框架提供的日志接口头文件#defineHDF_LOG_TAG"my_hdf_uart"//打印log中包含的tag,如果没有定义,则使用默认的HDF_TAGtag//【3.1Driver消息机制管理】Dispatch用于处理用户态发送的消息int32_tMyUartDriverDispatch(structHdfDeviceIoClient*client,intcmdId,structHdfSBuf*data,structHdfSBuf*reply){HDF_LOGE("%s::enter",__func__);HDF_LOGE("getcmdId::%d",cmdId);returnHDF_SUCCESS;}//【1.驱动开发】驱动对外提供的服务能力,将相关服务接口绑定到HDF框架int32_tMyHdfUartDriverBind(structHdfDeviceObject*deviceObject){HDF_LOGE("%s::enter",__func__);//【2.驱动服务管理】deviceObject是HDF框架为每个驱动创建的设备对象,用于保存设备相关的私有数据和服务接口.Dispatch=MyUartDriverDispatch,//【3.2驱动消息机制管理】在服务实现过程中,实现服务基类成员IDeviceIoService中的Dispatch方法。Open=NULL,//【2.司机服务管理】司机提供的其他服务。.Release=NULL,//.ServiceA=SampleDriverServiceA,};deviceObject->service=&testService;returnHDF_SUCCESS;}//【1.驱动开发】Int32_tMyHdfUartDriverInit(structHdfDeviceObject*deviceObject){HDF_LOGE("%s::enter",__func__);HDF_LOGD("Uartdriverbindsuccess");return0;}staticint32_tMyUartParseAndInit(structHdfDeviceObject*device,conststructDeviceResourceNode*node){HDF_LOGE("%s::enter",__func__);return0;}//【1.驱动开发】驱动资源释放接口voidMyHdfUartDriverRelease(structHdfDeviceObject*deviceObject){HDF_LOGE("%s::enter",__func__);return;}//[1.驱动开发】定义驱动入口的对象必须是HdfDriverEntry(在hdf_device_desc.h中定义)类型全局变量structHdfDriverEntryg_myhdfUartDriverEntry={.moduleVersion=1,.moduleName="my_hdf_uart",.Bind=MyHdfUartDriverBind,.Init=MyHdfUartDriverInit,.Release=MyHdfUartDriverRelease,};//【1.驱动开发】调用HDF_INIT将驱动入口注册到HDF框架中。在加载驱动时,HDF框架会先调用Bind函数,然后调用Init函数加载驱动。当Init调用异常时,HDF框架会调用Release释放驱动资源并退出。HDF_INIT(g_myhdfUartDriverEntry);drivers\adapter\khdf\linux\platform\uart\Makefile:添加驱动到内核编译-uart_adapter.o+uart_adapter.o\+my_hdf_uart.o2。添加驱动配置文件vendor\raspberrypi\RPI4B\hdf_config\khdf\device_info\device_info.hcs#device_uart::deviceadddevice2::deviceNode{policy=2;permission=0644;priority=40;moduleName="my_hdf_uart";serviceName="my_hdf_uart_service";}3.用户态HDF驱动交互验证applications\standard\app\myuarttest.c:用户态主程序,主要代码已注释。#include
