HDF khu động khuông giá tham lộ ( tam ): Cơ vu 3516 phối trí nhất sáo khả dĩ đả thông đích HDF khu động trình tự Nguyên sangTinh hoa

Mr_qzk
Phát bố vu 2021-11-30 10:05
Lưu lãm
8 thu tàng

【 bổn văn chính tại tham dữ ưu chất sang tác giả kích lệ 】
Lão quy củ hoàn thị tương tối chung hi vọng bào xuất lai đích hiệu quả phóng xuất lai. Như hạ:
HDF驱动框架探路(三):基于3516配置一套可以打通的HDF驱动程序-鸿蒙开发者社区

@toc

Tiền ngôn

  • Đại gia như quả hữu độc quá đệ nhị thiên văn chương đích thoại, khả năng phát hiện liễu tại cai văn trung nội hạch thái đích khu động trình tự thị trực tiếp dẫn dụng liễu nguyên mã trung dĩ kinh tồn tại đích nhất cá HDF khu động mô khối. Sở dĩ bổn văn đích tựu thị trứ trọng giải quyết giá cá vấn đề, dã tựu thị tự kỷ khứ phối trí nhất cá HDF khu động mô khối.
  • Bổn văn thị cơ vu 3516 đích tiểu hình hệ thống khứ nghiệm chứng đích.

Bổn văn khuông giá đồ

HDF驱动框架探路(三):基于3516配置一套可以打通的HDF驱动程序-鸿蒙开发者社区
Quan sát thượng đồ, kỳ thật bổn văn thị tương thượng văn đích lưu trình tiến nhất bộ tế hóa, thượng văn trung đích khu động trình tự tế phân thành liễu tam cá bộ phân, phân biệt thị: HCS văn kiện phối trí, nội hạch thái đại mã, liteos_a phối trí biên dịch tiến nội hạch. Giá tam cá bộ phân hợp khởi lai tựu thị tự kỷ đáp kiến HDF khu động trình tự đích bộ sậu.

1. HDF phối trí

Giá lí đích HDF phối trí thị án chiếu nguyên mã trung dĩ kinh tồn tại đích sample_driver mô khối lai đích
Đả khai văn kiện vendor/hisilicon/hispark_taurus/hdf_config/hdf_test/hdf_test_manager/device_info.hcs, nhiên hậu gia nhập hạ thuật đại mã trung đích device2.

device1:: deviceNode {
policy = 2;
priority = 10;
preload = 0;
permission = 0644;
moduleName = "sample_driver";
serviceName = "sample_service";
}
device2:: 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 = "talkweb_driver"; // Driver name. The value of this field must be the same as the value of moduleName in the driver entry structure.
serviceName = "talkweb_service"; // Name of the service released by the driver. The name must be unique.
}
}
device_platform_test:: device {
platform_test:: deviceNode {
policy = 1;
priority = 150;
preload = 0;
permission = 0644;
moduleName = "PLATFORM_TEST_DRIVER";
serviceName = "PLATFORM_TEST";
deviceMatchAttr = "platform_test";
}
}

2. liteos_a biên dịch phối trí

Cai bộ sậu đích tác dụng thị tương đệ tam bộ trung đích khu động trình tự biên dịch tiến nhập nội hạch.

2.1 tại BUILD.gn văn kiện trung phối trí

Đả khai drivers/adapter/khdf/liteos/test/BUILD.gn văn kiện

--- a/khdf/liteos/test/BUILD.gn
+++ b/khdf/liteos/test/BUILD.gn
@@ -37,6 +37,7 @@ hdf_driver(module_name) {
sources = [
"$HDF_TEST_FRAMWORK_ROOT/common/hdf_main_test.c",
"$HDF_TEST_FRAMWORK_ROOT/manager/sample_driver_test.c",
+ "$HDF_TEST_FRAMWORK_ROOT/talkwebtest/talkweb.c",
"$HDF_TEST_FRAMWORK_ROOT/osal/osal_all_test.c",
"$HDF_TEST_FRAMWORK_ROOT/osal/osal_file_test.c",
"$HDF_TEST_FRAMWORK_ROOT/osal/osal_get_case_test.c",

2.2 tại Makefile trung tiến hành thiêm gia phối trí

drivers/adapter/khdf/liteos/test/Makefile

--- a/khdf/liteos/test/Makefile
+++ b/khdf/liteos/test/Makefile
@@ -34,6 +34,7 @@ HDF_TEST_FRAMWORK_ROOT = $(LITEOSTOPDIR)/../../drivers/framework/test/unittest

LOCAL_SRCS:= $(HDF_TEST_FRAMWORK_ROOT)/common/hdf_main_test.c \
$(HDF_TEST_FRAMWORK_ROOT)/manager/sample_driver_test.c \
+ $(HDF_TEST_FRAMWORK_ROOT)/talkwebtest/talkweb.c \
$(HDF_TEST_FRAMWORK_ROOT)/osal/osal_test_entry.c \
$(HDF_TEST_FRAMWORK_ROOT)/osal/osal_all_test.c \
$(HDF_TEST_FRAMWORK_ROOT)/osal/osal_file_test.c \

3. Khu động trình tự

Tiến nhập drivers/framework/test/unittest mục lục hạ, tân kiến talkwebtest mục lục

3.1 tại thượng thuật mục lục hạ tân kiến talkweb.h văn kiện, tương hạ thuật đại mã phóng nhập

#ifndef HDF_SAMPLE_DRIVER_H
#define HDF_SAMPLE_DRIVER_H

#include "hdf_object.h"

#define SAMPLE_SERVICE "sample_service"

typedef enum {
SAMPLE_DRIVER_REGISTER_DEVICE = 0,
SAMPLE_DRIVER_UNREGISTER_DEVICE,
SAMPLE_DRIVER_SENDEVENT_SINGLE_DEVICE,
SAMPLE_DRIVER_SENDEVENT_BROADCAST_DEVICE,
SAMPLE_DRIVER_PM_STATE_INJECT,
} SAMPLE_DRIVER_CMDID;

struct HdfDeviceObject *GetDeviceObject(void);

#endif // HDF_MAIN_TEST_H

3.2 tại thượng thuật mục lục hạ tân kiến talkweb.c văn kiện, tương hạ thuật đại mã phóng nhập

/*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* HDF is dual licensed: you can use it either under the terms of
* the GPL, or the BSD license, at your option.
* See the LICENSE file in the root of this repository for complete details.
*/
#include "talkweb.h"
#include "devsvc_manager_clnt.h"
#include "devmgr_service.h"
#include "hdf_log.h"
#include "hdf_device_desc.h"
#include "hdf_pm.h"

#include "device_resource_if.h"
#include "osal_io.h"
#include "osal_mem.h"
#include "gpio_if.h"
#include "osal_irq.h"
#include "osal_time.h"
//#define HDF_LOG_TAG led_driver // đả ấn nhật chí sở bao hàm đích tiêu thiêm, như quả bất định nghĩa tắc dụng mặc nhận > định nghĩa đích HDF_TAG tiêu thiêm
#define LED_WRITE_READ 88

#define HDF_LOG_TAG sample_driver_test

#ifndef INT32_MAX
#define INT32_MAX 0x7fffffff
#endif

void HdftalkwebDriverRelease(struct HdfDeviceObject *deviceObject)
{
(void)deviceObject;
return;
}

int32_t talkwebDriverRegisterDevice(struct HdfSBuf *data)
{
const char *moduleName = NULL;
const char *serviceName = NULL;
struct HdfDeviceObject *devObj = NULL;
if (data == NULL) {
return HDF_FAILURE;
}

moduleName = HdfSbufReadString(data);
if (moduleName == NULL) {
return HDF_FAILURE;
}
serviceName = HdfSbufReadString(data);
if (serviceName == NULL) {
return HDF_FAILURE;
}

devObj = HdfRegisterDevice(moduleName, serviceName, NULL);
if (devObj == NULL) {
return HDF_FAILURE;
}
return HDF_SUCCESS;
}

int32_t talkwebDriverUnregisterDevice(struct HdfSBuf *data)
{
const char *moduleName = NULL;
const char *serviceName = NULL;
if (data == NULL) {
return HDF_FAILURE;
}

moduleName = HdfSbufReadString(data);
if (moduleName == NULL) {
return HDF_FAILURE;
}
serviceName = HdfSbufReadString(data);
if (serviceName == NULL) {
return HDF_FAILURE;
}
HdfUnregisterDevice(moduleName, serviceName);
return HDF_SUCCESS;
}

int32_t talkwebDriverSendEvent(struct HdfDeviceIoClient *client, int id, struct HdfSBuf *data, bool broadcast)
{
return broadcast? HdfDeviceSendEvent(client->device, id, data): HdfDeviceSendEventToClient(client, id, data);
}

int32_t talkwebDriverPowerStateInject(uint32_t powerState)
{
int ret;
struct IDevmgrService *devmgrService = DevmgrServiceGetInstance();
if (devmgrService == NULL || devmgrService->PowerStateChange == NULL) {
return HDF_ERR_INVALID_OBJECT;
}
ret = devmgrService->PowerStateChange(devmgrService, powerState);

HDF_LOGI( "%s: inject power state(%d) done, ret = %d", __func__, powerState, ret);
return ret;
}


static int32_t CtlLED(int mode)
{
int32_t ret;
uint16_t valRead;
/* LED đích GPIO quản cước hào */
uint16_t gpio = 5 * 8 + 1; // hồng ngoại bổ quang đăng
// uint16_t gpio = 2 * 8 + 3; // lục sắc chỉ kỳ đăng
// uint16_t gpio = 3 * 8 + 4; // hồng sắc chỉ kỳ đăng

/* tương GPIO quản cước phối trí vi thâu xuất */
ret = GpioSetDir(gpio, GPIO_DIR_OUT);
if (ret!= 0)
{
HDF_LOGE( "GpioSerDir: failed, ret %d\n", ret);
return ret;
}

if (mode == -1)
{
// phiên chuyển thâu xuất khẩu
(void)GpioRead(gpio, &valRead);
ret = GpioWrite(gpio, (valRead == GPIO_VAL_LOW)? GPIO_VAL_HIGH: GPIO_VAL_LOW);
}
else
{
ret = GpioWrite(gpio, mode);
}

if (ret!= 0)
{
HDF_LOGE( "GpioWrite: failed, ret %d\n", ret);
return ret;
}
return ret;
}


int32_t talkwebDriverDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply)
{
HDF_LOGD( "%s::qzk-enter", __func__);
uint32_t powerState = 0;
int32_t ret = HDF_SUCCESS;
if (reply == NULL || client == NULL) {
return HDF_FAILURE;
}
int32_t result = HDF_FAILURE;
switch (cmdId) {
case LED_WRITE_READ:
const char *recv = HdfSbufReadString(data);
if (recv!= NULL)
{
//HDF_LOGI( "recv: %s", recv);
result = CtlLED(-1);
// CtlLED(GPIO_VAL_HIGH);
if (!HdfSbufWriteInt32(reply, result)){
//HDF_LOGE( "replay is fail" );
}
return HdfDeviceSendEvent(client->device, cmdId, data);
}
break;
case SAMPLE_DRIVER_REGISTER_DEVICE: {
ret = talkwebDriverRegisterDevice(data);
HdfSbufWriteInt32(reply, ret);
break;
}
case SAMPLE_DRIVER_UNREGISTER_DEVICE:
ret = talkwebDriverUnregisterDevice(data);
HdfSbufWriteInt32(reply, ret);
break;
case SAMPLE_DRIVER_SENDEVENT_SINGLE_DEVICE:
ret = talkwebDriverSendEvent(client, cmdId, data, false);
HdfSbufWriteInt32(reply, INT32_MAX);
break;
case SAMPLE_DRIVER_SENDEVENT_BROADCAST_DEVICE:
ret = talkwebDriverSendEvent(client, cmdId, data, true);
HdfSbufWriteInt32(reply, INT32_MAX);
break;
case SAMPLE_DRIVER_PM_STATE_INJECT:
HdfSbufReadUint32(data, &powerState);
return talkwebDriverPowerStateInject(powerState);
default:
break;
}

return ret;
}

int HdftalkwebDriverBind(struct HdfDeviceObject *deviceObject)
{
static struct IDeviceIoService testService = {
.Dispatch = talkwebDriverDispatch,
.Open = NULL,
.Release = NULL,
};
HDF_LOGD( "%s::enter", __func__);
if (deviceObject == NULL) {
return HDF_FAILURE;
}

deviceObject->service = &testService;
return HDF_SUCCESS;
}

int HdftalkwebDozeResume(struct HdfDeviceObject *deviceObject)
{
HDF_LOGI( "%s:called", __func__);
return HDF_SUCCESS;
}

int HdftalkwebDozeSuspend(struct HdfDeviceObject *deviceObject)
{
HDF_LOGI( "%s:called", __func__);
return HDF_SUCCESS;
}

int HdftalkwebResume(struct HdfDeviceObject *deviceObject)
{
HDF_LOGI( "%s:called", __func__);
return HDF_SUCCESS;
}

int HdftalkwebSuspend(struct HdfDeviceObject *deviceObject)
{
HDF_LOGI( "%s:called", __func__);
return HDF_SUCCESS;
}

struct talkwebDriverPmListener {
struct IPowerEventListener powerListener;
void *p;
};

int HdftalkwebDriverInit(struct HdfDeviceObject *deviceObject)
{
static struct talkwebDriverPmListener pmListener = {0};
int ret;
HDF_LOGI( "%s::enter!", __func__);
if (deviceObject == NULL) {
HDF_LOGE( "%s::ptr is null!", __func__);
return HDF_FAILURE;
}
HDF_LOGD( "%s:Init success", __func__);

pmListener.powerListener.DozeResume = HdftalkwebDozeResume;
pmListener.powerListener.DozeSuspend = HdftalkwebDozeSuspend;
pmListener.powerListener.Resume = HdftalkwebResume;
pmListener.powerListener.Suspend = HdftalkwebSuspend;

ret = HdfPmRegisterPowerListener(deviceObject, &pmListener.powerListener);
HDF_LOGI( "%s:register power listener, ret = %d", __func__, ret);

return HDF_SUCCESS;
}


struct HdfDriverEntry g_talkwebDriverEntry = {
.moduleVersion = 1,
.moduleName = "talkweb_driver",
.Bind = HdftalkwebDriverBind,
.Init = HdftalkwebDriverInit,
.Release = HdftalkwebDriverRelease,
};

HDF_INIT(g_talkwebDriverEntry);

4. Ứng dụng thái trình tự

Giá lí đích ứng dụng thái trình tự đích đại mã hòa biên dịch phương pháp, trực tiếp khả dĩ thải dụng thượng văn đích tựu khả dĩ.
Giá lí chỉ nhu yếu tu cải SAMPLE_SERVICE_NAME giá cá hoành.

#define SAMPLE_SERVICE_NAME "talkweb_service"

5.hb build -f tiến hành biên dịch thiêu lục

© trứ tác quyền quy tác giả sở hữu, như nhu chuyển tái, thỉnh chú minh xuất xử, phủ tắc tương truy cứu pháp luật trách nhậm
Dĩ vu 2021-11-30 10:05:16 tu cải
Tán 10
Thu tàng 8
Hồi phục
Cử báo
Hồi phục
    Tương quan thôi tiến
    Giá cá dụng hộ ngận lại, hoàn một hữu cá nhân giản giới
    Thiếp tử
    Thị tần
    Thanh vọng
    Phấn ti
    Xã khu tinh hoa nội dung

    Mục lục