diff --git a/.gitignore b/.gitignore
index d1606884fa9fc2c49467d620e7c6d2317ebfa5b1..48fd83b28816e46bab4cba422a93d96e7174fb7d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1 @@
-*.o
-*.a
-*.d
-*.cmd
tools/hc-gen/build
diff --git a/OAT.xml b/OAT.xml
index 3b80ed211f30e0b960ea3d5b0ad38b288076ce75..71a26d5310f6e5296aa0fcd68f3d7e05ee623297 100644
--- a/OAT.xml
+++ b/OAT.xml
@@ -61,6 +61,7 @@ Note:If the text contains special characters, please escape them according to th
+
diff --git a/core/adapter/syscall/src/hdf_syscall_adapter.c b/core/adapter/syscall/src/hdf_syscall_adapter.c
index 2759120dc6fdacb63d7613ae8b2bec7ebdb8f693..88db2dc937325e4723812826254af750327f3f86 100644
--- a/core/adapter/syscall/src/hdf_syscall_adapter.c
+++ b/core/adapter/syscall/src/hdf_syscall_adapter.c
@@ -664,7 +664,7 @@ static int32_t HdfSyscallAdapterDispatch(struct HdfObject *object, int32_t code,
wrBuf.cmdCode = code;
int32_t ret = ioctl(ioService->fd, HDF_WRITE_READ, &wrBuf);
if (ret < 0) {
- HDF_LOGE("Failed to dispatch serv call ioctl %d", errno);
+ HDF_LOGE("Failed to dispatch serv call ioctl %{public}d", errno);
}
if (reply != NULL) {
HdfSbufSetDataSize(reply, wrBuf.readConsumed);
diff --git a/core/adapter/vnode/src/hdf_vnode_adapter.c b/core/adapter/vnode/src/hdf_vnode_adapter.c
index dab5a350ee3c6535b231d291604c205f5a650603..90e357ec018595f51ff462fe890bf10b896003e4 100644
--- a/core/adapter/vnode/src/hdf_vnode_adapter.c
+++ b/core/adapter/vnode/src/hdf_vnode_adapter.c
@@ -199,8 +199,10 @@ static int HdfVNodeAdapterServCall(const struct HdfVNodeAdapterClient *client, u
struct HdfSBuf *reply = NULL;
int ret;
- if (client->serv == NULL) {
- return HDF_DEV_ERR_NO_DEVICE;
+ if (client->serv == NULL || client->adapter == NULL ||
+ client->adapter->ioService.dispatcher == NULL ||
+ client->adapter->ioService.dispatcher->Dispatch == NULL) {
+ return HDF_ERR_INVALID_OBJECT;
}
if (bwrUser == NULL) {
@@ -545,8 +547,9 @@ static unsigned int HdfVNodeAdapterPoll(struct file *filep, poll_table *wait)
static int HdfVNodeAdapterClose(struct OsalCdev *cdev, struct file *filep)
{
+ struct HdfVNodeAdapterClient *client = NULL;
(void)cdev;
- struct HdfVNodeAdapterClient *client = (struct HdfVNodeAdapterClient *)OsalGetFilePriv(filep);
+ client = (struct HdfVNodeAdapterClient *)OsalGetFilePriv(filep);
if (client->ioServiceClient.device != NULL && client->ioServiceClient.device->service != NULL &&
client->ioServiceClient.device->service->Release != NULL) {
client->ioServiceClient.device->service->Release(&client->ioServiceClient);
@@ -642,7 +645,7 @@ int32_t HdfDeviceSendEvent(const struct HdfDeviceObject *deviceObject, uint32_t
}
deviceNode = CONTAINER_OF(deviceObject, struct HdfDeviceNode, deviceObject);
- if (deviceNode->deviceInfo->policy != SERVICE_POLICY_CAPACITY) {
+ if (deviceNode->policy != SERVICE_POLICY_CAPACITY) {
return HDF_ERR_NOT_SUPPORT;
}
diff --git a/core/common/src/buildin_config_entry.c b/core/common/src/buildin_config_entry.c
new file mode 100644
index 0000000000000000000000000000000000000000..cbf8ca2e95c86d245d7b5bda52fac5485e5573ef
--- /dev/null
+++ b/core/common/src/buildin_config_entry.c
@@ -0,0 +1,14 @@
+/*
+ * 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 "hcs_tree_if.h"
+
+const struct DeviceResourceNode *HdfGetHcsRootNode(void)
+{
+ return HcsGetRootNode();
+}
\ No newline at end of file
diff --git a/core/common/src/devlite_object_config.c b/core/common/src/devlite_object_config.c
index bea66407d5329eed3c48ff628f80b3de81747963..8be58a208403c8b712ee141eb39461dadf78217e 100644
--- a/core/common/src/devlite_object_config.c
+++ b/core/common/src/devlite_object_config.c
@@ -6,15 +6,16 @@
* See the LICENSE file in the root of this repository for complete details.
*/
-#include "hdf_object_manager.h"
#include "devhost_service.h"
#include "devmgr_service.h"
#include "devsvc_manager.h"
+#include "devsvc_manager_ext.h"
#include "hdf_device.h"
#include "hdf_device_node_ext.h"
#include "hdf_device_token.h"
#include "hdf_driver_installer.h"
#include "hdf_driver_loader.h"
+#include "hdf_object_manager.h"
static const struct HdfObjectCreator g_liteObjectCreators[] = {
[HDF_OBJECT_ID_DEVMGR_SERVICE] =
@@ -24,8 +25,8 @@ static const struct HdfObjectCreator g_liteObjectCreators[] = {
},
[HDF_OBJECT_ID_DEVSVC_MANAGER] =
{
- .Create = DevSvcManagerCreate,
- .Release = DevSvcManagerRelease,
+ .Create = DevSvcManagerExtCreate,
+ .Release = DevSvcManagerExtRelease,
},
[HDF_OBJECT_ID_DEVHOST_SERVICE] =
{
diff --git a/core/common/src/devmgr_service_start.c b/core/common/src/devmgr_service_start.c
index a7d27eb9c3d596b8d1e6db7e9fa7b0bc94fd805d..b537fbc2735bfb86d874a159446ab1335a6f273d 100644
--- a/core/common/src/devmgr_service_start.c
+++ b/core/common/src/devmgr_service_start.c
@@ -9,41 +9,27 @@
#include "devmgr_service_start.h"
#include "devhost_service_clnt.h"
#include "devmgr_service.h"
+#include "devsvc_manager.h"
#include "devsvc_manager_clnt.h"
#include "hdf_base.h"
#include "hdf_device_node.h"
#include "hdf_io_service.h"
#include "hdf_log.h"
+#include "hdf_power_manager.h"
#include "hdf_sbuf.h"
#define DEV_MGR_NODE_PERM 0660
static int g_isQuickLoad = DEV_MGR_SLOW_LOAD;
-static void GetDeviceServiceNameByClass(DeviceClass deviceClass, struct HdfSBuf *reply)
+static void GetDeviceServiceNameByClass(struct HdfSBuf *reply, DeviceClass deviceClass)
{
- struct HdfSListIterator itDeviceInfo;
- struct HdfDeviceInfo *deviceInfo = NULL;
- struct DevHostServiceClnt *hostClnt = NULL;
- struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
- if (devMgrSvc == NULL || reply == NULL) {
+ if (reply == NULL) {
return;
}
HdfSbufFlush(reply);
- DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) {
- HdfSListIteratorInit(&itDeviceInfo, hostClnt->deviceInfos);
- while (HdfSListIteratorHasNext(&itDeviceInfo)) {
- deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo);
- if (deviceInfo->policy == SERVICE_POLICY_CAPACITY) {
- struct HdfDeviceObject *deviceObject = DevSvcManagerClntGetDeviceObject(deviceInfo->svcName);
- if (deviceObject == NULL || (deviceObject->deviceClass != deviceClass)) {
- continue;
- }
- HdfSbufWriteString(reply, deviceInfo->svcName);
- }
- }
- }
+ DevSvcManagerListService(reply, deviceClass);
HdfSbufWriteString(reply, NULL);
}
@@ -52,7 +38,11 @@ int DeviceManagerDispatch(struct HdfObject *stub, int code, struct HdfSBuf *data
int ret = HDF_FAILURE;
int32_t deviceClass = 0;
const char *svcName = NULL;
- struct DevmgrService *devMgrSvc = (struct DevmgrService *)stub;
+ struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
+ static struct SubscriberCallback callback = {
+ .deviceObject = NULL,
+ .OnServiceConnected = NULL,
+ };
if (data == NULL || devMgrSvc == NULL) {
HDF_LOGE("%s: input param is invalid", __func__);
return ret;
@@ -65,10 +55,6 @@ int DeviceManagerDispatch(struct HdfObject *stub, int code, struct HdfSBuf *data
HDF_LOGE("%s: get svc name is null", __func__);
break;
}
- static struct SubscriberCallback callback = {
- .deviceObject = NULL,
- .OnServiceConnected = NULL,
- };
ret = DevSvcManagerClntSubscribeService(svcName, callback);
break;
case DEVMGR_UNLOAD_SERVICE:
@@ -84,7 +70,7 @@ int DeviceManagerDispatch(struct HdfObject *stub, int code, struct HdfSBuf *data
HDF_LOGE("%s: failed to get deviceClass", __func__);
break;
}
- GetDeviceServiceNameByClass(deviceClass, reply);
+ GetDeviceServiceNameByClass(reply, deviceClass);
ret = HDF_SUCCESS;
break;
default:
@@ -107,30 +93,39 @@ int DeviceManagerIsQuickLoad(void)
int DeviceManagerStart(void)
{
+ struct HdfIoService *ioService = NULL;
+ int ret;
struct IDevmgrService *instance = DevmgrServiceGetInstance();
if (instance == NULL || instance->StartService == NULL) {
HDF_LOGE("device manager start failed, service instance is null");
return HDF_FAILURE;
}
- struct HdfIoService *ioService = HdfIoServicePublish(DEV_MGR_NODE, DEV_MGR_NODE_PERM);
+ ioService = HdfIoServicePublish(DEV_MGR_NODE, DEV_MGR_NODE_PERM);
if (ioService != NULL) {
static struct HdfIoDispatcher dispatcher = {
.Dispatch = DeviceManagerDispatch,
};
ioService->dispatcher = &dispatcher;
- ioService->target = &instance->base;
+ ioService->target = NULL;
}
- return instance->StartService(instance);
+ ret = instance->StartService(instance);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("failed to start hdf devmgr");
+ return ret;
+ }
+
+ return HdfPowerManagerInit();
}
int DeviceManagerStartStep2()
{
+ struct DevmgrService *devMgrSvc = NULL;
if (DeviceManagerIsQuickLoad() == DEV_MGR_SLOW_LOAD) {
HDF_LOGW("%s: device manager is not set to QuickLoad mode", __func__);
return HDF_SUCCESS;
}
- struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
+ devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
return DevmgrServiceLoadLeftDriver(devMgrSvc);
}
diff --git a/core/common/src/hdf_attribute.c b/core/common/src/hdf_attribute.c
index 3234d52d6eab7419e9157835738bc206e2fdd900..4ceb22c92b3642a668e024d447c83415b0420bc3 100644
--- a/core/common/src/hdf_attribute.c
+++ b/core/common/src/hdf_attribute.c
@@ -8,16 +8,9 @@
#include "hdf_attribute_manager.h"
#include "devhost_service_clnt.h"
-#include "devmgr_service.h"
-#include "hcs_blob_if.h"
-#include "hcs_parser.h"
#include "hcs_tree_if.h"
-#include "hdf_base.h"
-#include "hdf_device_info.h"
#include "hdf_host_info.h"
#include "hdf_log.h"
-#include "osal_mem.h"
-#include "securec.h"
#ifdef LOSCFG_DRIVERS_HDF_USB_PNP_NOTIFY
#include "usb_pnp_manager.h"
#endif
@@ -32,45 +25,17 @@
#define ATTR_DEV_MATCHATTR "deviceMatchAttr"
#define MANAGER_NODE_MATCH_ATTR "hdf_manager"
-static struct DeviceResourceNode *g_hcsTreeRoot = NULL;
-
-void HdfGetBuildInConfigData(const unsigned char **data, unsigned int *size);
-
-static bool CreateHcsToTree(void)
-{
- uint32_t length;
- const unsigned char *hcsBlob = NULL;
- HdfGetBuildInConfigData(&hcsBlob, &length);
- if (!HcsCheckBlobFormat((const char *)hcsBlob, length)) {
- return false;
- }
- if (!HcsDecompile((const char *)hcsBlob, HBC_HEADER_LENGTH, &g_hcsTreeRoot)) {
- return false;
- }
- return true;
-}
-
-const struct DeviceResourceNode *HcsGetRootNode(void)
-{
- if ((g_hcsTreeRoot == NULL) && !CreateHcsToTree()) {
- HDF_LOGE("%s: failed", __func__);
- return NULL;
- }
- return g_hcsTreeRoot;
-}
-
-const struct DeviceResourceNode *HdfGetRootNode(void)
-{
- return HcsGetRootNode();
-}
+#define DEFATLT_DEV_PRIORITY 100
static bool HdfHostListCompare(struct HdfSListNode *listEntryFirst, struct HdfSListNode *listEntrySecond)
{
+ struct HdfHostInfo *attrFirst = NULL;
+ struct HdfHostInfo *attrSecond = NULL;
if (listEntryFirst == NULL || listEntrySecond == NULL) {
return false;
}
- struct HdfHostInfo *attrFirst = (struct HdfHostInfo *)listEntryFirst;
- struct HdfHostInfo *attrSecond = (struct HdfHostInfo *)listEntrySecond;
+ attrFirst = (struct HdfHostInfo *)listEntryFirst;
+ attrSecond = (struct HdfHostInfo *)listEntrySecond;
return attrFirst->priority <= attrSecond->priority;
}
@@ -105,14 +70,14 @@ bool HdfAttributeManagerGetHostList(struct HdfSList *hostList)
return false;
}
- hdfManagerNode = GetHdfManagerNode(HcsGetRootNode());
+ hdfManagerNode = GetHdfManagerNode(HdfGetHcsRootNode());
if (hdfManagerNode == NULL) {
HDF_LOGE("%s: get hdf manager node is null", __func__);
return false;
}
hostNode = hdfManagerNode->child;
- while (hostNode != NULL) {
+ for (; hostNode != NULL; hostNode = hostNode->sibling) {
struct HdfHostInfo *hostInfo = HdfHostInfoNewInstance();
if (hostInfo == NULL) {
HdfSListFlush(hostList, HdfHostInfoDelete);
@@ -121,28 +86,27 @@ bool HdfAttributeManagerGetHostList(struct HdfSList *hostList)
}
if (!GetHostInfo(hostNode, hostInfo)) {
HdfHostInfoFreeInstance(hostInfo);
- hostNode = hostNode->sibling;
continue;
}
hostInfo->hostId = hostId;
if (!HdfSListAddOrder(hostList, &hostInfo->node, HdfHostListCompare)) {
HdfHostInfoFreeInstance(hostInfo);
- hostNode = hostNode->sibling;
continue;
}
hostId++;
- hostNode = hostNode->sibling;
}
return true;
}
static bool HdfDeviceListCompare(struct HdfSListNode *listEntryFirst, struct HdfSListNode *listEntrySecond)
{
+ struct HdfDeviceInfo *attrFirst = NULL;
+ struct HdfDeviceInfo *attrSecond = NULL;
if (listEntryFirst == NULL || listEntrySecond == NULL) {
return false;
}
- struct HdfDeviceInfo *attrFirst = (struct HdfDeviceInfo *)listEntryFirst;
- struct HdfDeviceInfo *attrSecond = (struct HdfDeviceInfo *)listEntrySecond;
+ attrFirst = (struct HdfDeviceInfo *)listEntryFirst;
+ attrSecond = (struct HdfDeviceInfo *)listEntrySecond;
return attrFirst->priority <= attrSecond->priority;
}
@@ -154,7 +118,7 @@ static const struct DeviceResourceNode *GetHostNode(const char *inHostName)
if (inHostName == NULL) {
return NULL;
}
- hdfManagerNode = GetHdfManagerNode(HcsGetRootNode());
+ hdfManagerNode = GetHdfManagerNode(HdfGetHcsRootNode());
if (hdfManagerNode == NULL) {
return NULL;
}
@@ -174,7 +138,7 @@ static const struct DeviceResourceNode *GetHostNode(const char *inHostName)
static bool CheckDeviceInfo(const struct HdfDeviceInfo *deviceNodeInfo)
{
- if (deviceNodeInfo->policy > SERVICE_POLICY_PRIVATE) {
+ if (deviceNodeInfo->policy >= SERVICE_POLICY_INVALID) {
HDF_LOGE("%s: policy %u is invalid", __func__, deviceNodeInfo->policy);
return false;
}
@@ -184,7 +148,7 @@ static bool CheckDeviceInfo(const struct HdfDeviceInfo *deviceNodeInfo)
return false;
}
- if (deviceNodeInfo->preload > DEVICE_PRELOAD_DISABLE) {
+ if (deviceNodeInfo->preload >= DEVICE_PRELOAD_INVALID) {
HDF_LOGE("%s: preload %u is invalid", __func__, deviceNodeInfo->preload);
return false;
}
@@ -194,179 +158,81 @@ static bool CheckDeviceInfo(const struct HdfDeviceInfo *deviceNodeInfo)
static bool GetDeviceNodeInfo(const struct DeviceResourceNode *deviceNode, struct HdfDeviceInfo *deviceNodeInfo)
{
- uint16_t readNum = 0;
- const char *readString = NULL;
- if (HcsGetUint16(deviceNode, ATTR_DEV_POLICY, &readNum, 0) != HDF_SUCCESS) {
- HDF_LOGE("%s: failed to get policy", __func__);
- return false;
- }
- deviceNodeInfo->policy = readNum;
+ HcsGetUint16(deviceNode, ATTR_DEV_POLICY, &deviceNodeInfo->policy, 0);
+ HcsGetUint16(deviceNode, ATTR_DEV_PRIORITY, &deviceNodeInfo->priority, DEFATLT_DEV_PRIORITY);
+ HcsGetUint16(deviceNode, ATTR_DEV_PRELOAD, &deviceNodeInfo->preload, 0);
+ HcsGetUint16(deviceNode, ATTR_DEV_PERMISSION, &deviceNodeInfo->permission, 0);
+ HcsGetString(deviceNode, ATTR_DEV_MATCHATTR, &deviceNodeInfo->deviceMatchAttr, NULL);
- if (HcsGetUint16(deviceNode, ATTR_DEV_PRIORITY, &readNum, 0) != HDF_SUCCESS) {
- HDF_LOGE("%s: failed to get priority", __func__);
- return false;
- }
- deviceNodeInfo->priority = readNum;
-
- if (HcsGetUint16(deviceNode, ATTR_DEV_PRELOAD, &readNum, 0) != HDF_SUCCESS) {
- HDF_LOGE("%s: failed to get preload", __func__);
- return false;
- }
- deviceNodeInfo->preload = readNum;
-
- if (HcsGetUint16(deviceNode, ATTR_DEV_PERMISSION, &readNum, 0) != HDF_SUCCESS) {
- HDF_LOGE("%s: failed to get permission", __func__);
- return false;
- }
- deviceNodeInfo->permission = readNum;
-
- if (HcsGetString(deviceNode, ATTR_DEV_MODULENAME, &readString, NULL) != HDF_SUCCESS) {
+ if (HcsGetString(deviceNode, ATTR_DEV_MODULENAME, &deviceNodeInfo->moduleName, NULL) != HDF_SUCCESS) {
HDF_LOGE("%s: failed to get module name", __func__);
return false;
}
- deviceNodeInfo->moduleName = readString;
- if (HcsGetString(deviceNode, ATTR_DEV_SVCNAME, &readString, NULL) != HDF_SUCCESS) {
+ if (HcsGetString(deviceNode, ATTR_DEV_SVCNAME, &deviceNodeInfo->svcName, NULL) != HDF_SUCCESS) {
HDF_LOGE("%s: failed to get service name", __func__);
return false;
}
- deviceNodeInfo->svcName = readString;
- if (HcsGetString(deviceNode, ATTR_DEV_MATCHATTR, &readString, NULL) != HDF_SUCCESS) {
- HDF_LOGE("%s: failed to get matchattr name", __func__);
- return false;
- }
- deviceNodeInfo->deviceMatchAttr = readString;
return CheckDeviceInfo(deviceNodeInfo);
}
-struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *hostName)
+static bool GetDevcieNodeList(const struct DeviceResourceNode *device,
+ struct DevHostServiceClnt *hostClnt, uint16_t deviceIdx)
{
- uint16_t deviceIdx = 0;
- const struct DeviceResourceNode *hostNode = GetHostNode(hostName);
- if (hostNode == NULL) {
- return NULL;
- }
- struct HdfSList *deviceList = (struct HdfSList *)OsalMemCalloc(sizeof(struct HdfSList));
- if (deviceList == NULL) {
- return NULL;
- }
- const struct DeviceResourceNode *device = hostNode->child;
- while (device != NULL) {
- const struct DeviceResourceNode *deviceNode = device->child;
- while (deviceNode != NULL) {
- struct HdfDeviceInfo *deviceNodeInfo = HdfDeviceInfoNewInstance();
- if (deviceNodeInfo == NULL) {
- HdfSListFlush(deviceList, HdfDeviceInfoDelete);
- OsalMemFree(deviceList);
- return NULL;
- }
- deviceNodeInfo->hostId = hostId;
- if (!GetDeviceNodeInfo(deviceNode, deviceNodeInfo)) {
- HdfDeviceInfoFreeInstance(deviceNodeInfo);
- HDF_LOGE("%s: failed to get device", __func__);
- deviceNodeInfo = NULL;
- deviceNode = deviceNode->sibling;
- continue;
- }
- if (!HdfSListAddOrder(deviceList, &deviceNodeInfo->node, HdfDeviceListCompare)) {
- HDF_LOGE("%s: failed to add device %s", __func__, deviceNodeInfo->svcName);
+ uint8_t deviceNodeIdx = 1;
+ uint16_t hostId = hostClnt->hostId;
+ struct HdfDeviceInfo *deviceNodeInfo = NULL;
+ const struct DeviceResourceNode *devNodeResource = device->child;
+
+ for (; devNodeResource != NULL; devNodeResource = devNodeResource->sibling) {
+ deviceNodeInfo = HdfDeviceInfoNewInstance();
+ if (deviceNodeInfo == NULL) {
+ return false;
+ }
+ if (!GetDeviceNodeInfo(devNodeResource, deviceNodeInfo)) {
+ HdfDeviceInfoFreeInstance(deviceNodeInfo);
+ HDF_LOGE("%s: failed to parse device node info, ignore", __func__);
+ continue;
+ }
+
+ deviceNodeInfo->deviceId = MK_DEVID(hostId, deviceIdx, deviceNodeIdx);
+ if (deviceNodeInfo->preload != DEVICE_PRELOAD_DISABLE) {
+ if (!HdfSListAddOrder(&hostClnt->unloadDevInfos, &deviceNodeInfo->node, HdfDeviceListCompare)) {
+ HDF_LOGE("%s: failed to add device info to list %s", __func__, deviceNodeInfo->svcName);
HdfDeviceInfoFreeInstance(deviceNodeInfo);
- deviceNodeInfo = NULL;
- deviceNode = deviceNode->sibling;
continue;
}
- deviceNodeInfo->deviceId = deviceIdx;
- deviceNode = deviceNode->sibling;
+ } else {
+ HdfSListAdd(&hostClnt->dynamicDevInfos, &deviceNodeInfo->node);
}
- device = device->sibling;
- deviceIdx++;
- }
- if (HdfSListCount(deviceList) == 0) {
- OsalMemFree(deviceList);
- return NULL;
+
+ deviceNodeIdx++;
}
- return deviceList;
+ return deviceNodeIdx > 1;
}
-bool HdfDeviceListAdd(const char *moduleName, const char *serviceName, const void *privateData)
+int HdfAttributeManagerGetDeviceList(struct DevHostServiceClnt *hostClnt)
{
- struct HdfSListIterator itDeviceInfo;
- struct HdfDeviceInfo *deviceInfo = NULL;
- struct DevHostServiceClnt *hostClnt = NULL;
- struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
- if (devMgrSvc == NULL || moduleName == NULL || serviceName == NULL) {
- return false;
- }
+ uint16_t deviceIdx = 1;
+ const struct DeviceResourceNode *hostNode = NULL;
+ const struct DeviceResourceNode *device = NULL;
+ int ret = HDF_DEV_ERR_NO_DEVICE;
- struct HdfDeviceInfo *deviceNodeInfo = HdfDeviceInfoNewInstance();
- if (deviceNodeInfo == NULL) {
- return false;
+ if (hostClnt == NULL) {
+ return HDF_ERR_INVALID_PARAM;
}
- DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) {
- HdfSListIteratorInit(&itDeviceInfo, hostClnt->deviceInfos);
- while (HdfSListIteratorHasNext(&itDeviceInfo)) {
- deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo);
- if (deviceInfo->moduleName == NULL) {
- continue;
- }
- if (strcmp(deviceInfo->moduleName, moduleName) == 0) {
- deviceInfo->isDynamic = true;
- deviceNodeInfo->hostId = deviceInfo->hostId;
- deviceNodeInfo->deviceId = hostClnt->devCount;
- deviceNodeInfo->policy = deviceInfo->policy;
- deviceNodeInfo->priority = deviceInfo->priority;
- deviceNodeInfo->preload = DEVICE_PRELOAD_DISABLE;
- deviceNodeInfo->permission = deviceInfo->permission;
- deviceNodeInfo->deviceMatchAttr = deviceInfo->deviceMatchAttr;
- deviceNodeInfo->moduleName = deviceInfo->moduleName;
- char *svcName = OsalMemCalloc(strlen(serviceName) + 1);
- if (svcName == NULL) {
- break;
- }
- if (strcpy_s(svcName, strlen(serviceName) + 1, serviceName) != EOK) {
- HDF_LOGE("%s: failed to copy string", __func__);
- OsalMemFree(svcName);
- break;
- }
- deviceNodeInfo->svcName = svcName;
-#ifdef LOSCFG_DRIVERS_HDF_USB_PNP_NOTIFY
- if (!UsbPnpManagerAddPrivateData(deviceNodeInfo, privateData)) {
- break;
- }
-#endif
- HdfSListAdd(hostClnt->deviceInfos, &deviceNodeInfo->node);
- hostClnt->devCount++;
- return true;
- }
- }
- }
- HdfDeviceInfoFreeInstance(deviceNodeInfo);
- return false;
-}
-void HdfDeviceListDel(const char *moduleName, const char *serviceName)
-{
- struct HdfSListIterator itDeviceInfo;
- struct HdfDeviceInfo *deviceInfo = NULL;
- struct DevHostServiceClnt *hostClnt = NULL;
- struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
- if (devMgrSvc == NULL || moduleName == NULL || serviceName == NULL) {
- return;
+ hostNode = GetHostNode(hostClnt->hostName);
+ if (hostNode == NULL) {
+ return ret;
}
- DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) {
- HdfSListIteratorInit(&itDeviceInfo, hostClnt->deviceInfos);
- while (HdfSListIteratorHasNext(&itDeviceInfo)) {
- deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo);
- if ((strcmp(deviceInfo->moduleName, moduleName) == 0) &&
- (strcmp(deviceInfo->svcName, serviceName) == 0)) {
- HdfSListRemove(hostClnt->deviceInfos, &deviceInfo->node);
- HdfDeviceInfoFreeInstance(deviceInfo);
- hostClnt->devCount--;
- return;
- }
+ for(device = hostNode->child; device != NULL; device = device->sibling, deviceIdx++) {
+ if (!GetDevcieNodeList(device, hostClnt, deviceIdx)) {
+ return ret;
}
}
-}
+ return HDF_SUCCESS;
+}
\ No newline at end of file
diff --git a/core/common/src/hdf_device_node_ext.c b/core/common/src/hdf_device_node_ext.c
index a8143a44132b635657c5d68af71a6a559c725c79..030b0a83f6a8f30e0865ef8f32b2ffe8ac5be1b4 100644
--- a/core/common/src/hdf_device_node_ext.c
+++ b/core/common/src/hdf_device_node_ext.c
@@ -15,19 +15,18 @@
#include "hdf_sbuf.h"
#include "osal_mem.h"
-#define HDF_LOG_TAG device_node_ext
+#define HDF_LOG_TAG devnode_ext
static int DeviceNodeExtDispatch(struct HdfObject *stub, int code, struct HdfSBuf *data, struct HdfSBuf *reply)
{
struct IDeviceIoService *deviceMethod = NULL;
- const struct HdfDeviceInfo *deviceInfo = NULL;
struct HdfDeviceNode *devNode = NULL;
+ uint64_t ioClientPtr = 0;
if (stub == NULL) {
HDF_LOGE("device ext dispatch: stub is null");
return HDF_FAILURE;
}
- uint64_t ioClientPtr = 0;
if (!HdfSbufReadUint64(reply, &ioClientPtr) || ioClientPtr == 0) {
HDF_LOGE("device ext dispatch: input ioClient is null");
return HDF_FAILURE;
@@ -39,12 +38,8 @@ static int DeviceNodeExtDispatch(struct HdfObject *stub, int code, struct HdfSBu
HDF_LOGE("device ext dispatch: device service interface is null");
return HDF_FAILURE;
}
- deviceInfo = devNode->deviceInfo;
- if (deviceInfo == NULL) {
- HDF_LOGE("device ext dispatch: device deviceInfo is null");
- return HDF_FAILURE;
- }
- if (deviceInfo->policy == SERVICE_POLICY_CAPACITY) {
+
+ if (devNode->policy == SERVICE_POLICY_CAPACITY) {
if (deviceMethod->Dispatch == NULL) {
HDF_LOGE("device ext dispatch: remote service dispatch method is null");
return HDF_FAILURE;
@@ -54,56 +49,82 @@ static int DeviceNodeExtDispatch(struct HdfObject *stub, int code, struct HdfSBu
return HDF_FAILURE;
}
-static int DeviceNodeExtPublishService(struct HdfDeviceNode *inst, const char *serviceName)
+static int DeviceNodeExtPublishService(struct HdfDeviceNode *devNode)
{
- const struct HdfDeviceInfo *deviceInfo = NULL;
struct HdfDeviceObject *deviceObject = NULL;
- struct DeviceNodeExt *devNodeExt = (struct DeviceNodeExt *)inst;
+ struct DeviceNodeExt *devNodeExt = (struct DeviceNodeExt *)devNode;
+ int ret;
+ static struct HdfIoDispatcher dispatcher = { .Dispatch = DeviceNodeExtDispatch };
+
if (devNodeExt == NULL) {
return HDF_FAILURE;
}
- int ret = HdfDeviceNodePublishPublicService(inst, serviceName);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("failed to publish device service, ret is %d", ret);
- return HDF_FAILURE;
- }
- deviceInfo = inst->deviceInfo;
deviceObject = &devNodeExt->super.deviceObject;
- if ((deviceObject->service == NULL) || (deviceInfo == NULL)) {
- HDF_LOGE("Device service interface or deviceInfo is null");
+ if (deviceObject->service == NULL) {
+ HDF_LOGE("device service interface is null");
return HDF_FAILURE;
}
- if (deviceInfo->policy == SERVICE_POLICY_CAPACITY) {
- devNodeExt->ioService = HdfIoServicePublish(serviceName, deviceInfo->permission);
+ if (devNode->policy == SERVICE_POLICY_CAPACITY) {
+ devNodeExt->ioService = HdfIoServicePublish(devNode->servName, devNode->permission);
if (devNodeExt->ioService != NULL) {
- devNodeExt->ioService->target = (struct HdfObject*)(&inst->deviceObject);
- static struct HdfIoDispatcher dispatcher = {
- .Dispatch = DeviceNodeExtDispatch
- };
+ devNodeExt->ioService->target = (struct HdfObject *)(deviceObject);
devNodeExt->ioService->dispatcher = &dispatcher;
} else {
- HDF_LOGE("Device remote service bind failed");
- HdfDeviceNodeReclaimService(serviceName);
- return HDF_FAILURE;
+ HDF_LOGE("device remote service publish failed");
+ return HDF_DEV_ERR_NO_DEVICE_SERVICE;
}
}
+
+ // base(device node) publish inner service
+ ret = HdfDeviceNodePublishPublicService(devNode);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("failed to publish device service, ret is %d", ret);
+ HdfIoServiceRemove(devNodeExt->ioService);
+ devNodeExt->ioService = NULL;
+ return ret;
+ }
+
return HDF_SUCCESS;
}
+int DeviceNodeExtRemoveService(struct HdfDeviceNode *devNode)
+{
+ struct DeviceNodeExt *devNodeExt = CONTAINER_OF(devNode, struct DeviceNodeExt, super);
+ if (devNode == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ if (devNode->policy == SERVICE_POLICY_CAPACITY) {
+ HdfIoServiceRemove(devNodeExt->ioService);
+ devNodeExt->ioService = NULL;
+ }
+
+ // remove inner service published by base
+ return HdfDeviceNodeRemoveService(devNode);
+}
+
static void DeviceNodeExtConstruct(struct DeviceNodeExt *inst)
{
struct IDeviceNode *nodeIf = (struct IDeviceNode *)inst;
if (nodeIf != NULL) {
HdfDeviceNodeConstruct(&inst->super);
nodeIf->PublishService = DeviceNodeExtPublishService;
+ nodeIf->RemoveService = DeviceNodeExtRemoveService;
}
}
+static void DeviceNodeExtDestruct(struct DeviceNodeExt *devnode)
+{
+ if (DeviceNodeExtRemoveService(&devnode->super) != HDF_SUCCESS) {
+ HDF_LOGE("failed to remove serivce");
+ }
+ HdfDeviceNodeDestruct(&devnode->super);
+}
+
struct HdfObject *DeviceNodeExtCreate()
{
- struct DeviceNodeExt *instance =
- (struct DeviceNodeExt *)OsalMemCalloc(sizeof(struct DeviceNodeExt));
+ struct DeviceNodeExt *instance = (struct DeviceNodeExt *)OsalMemCalloc(sizeof(struct DeviceNodeExt));
if (instance != NULL) {
DeviceNodeExtConstruct(instance);
instance->ioService = NULL;
@@ -113,13 +134,9 @@ struct HdfObject *DeviceNodeExtCreate()
void DeviceNodeExtRelease(struct HdfObject *object)
{
- struct DeviceNodeExt *instance = (struct DeviceNodeExt *)object;
- if (instance != NULL) {
- if (instance->ioService != NULL) {
- HdfIoServiceRemove(instance->ioService);
- }
- HdfDeviceNodeDestruct(&instance->super);
- OsalMemFree(instance);
+ struct DeviceNodeExt *devnode = (struct DeviceNodeExt *)object;
+ if (devnode != NULL) {
+ DeviceNodeExtDestruct(devnode);
+ OsalMemFree(devnode);
}
}
-
diff --git a/core/common/src/load_driver_entry.c b/core/common/src/load_driver_entry.c
deleted file mode 100644
index 9a42ecbdc2b7c98342481ec1d0f2758be1c5f73d..0000000000000000000000000000000000000000
--- a/core/common/src/load_driver_entry.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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 "hdf_driver_loader.h"
-#include "hdf_log.h"
-#include "osal_mem.h"
-
-static struct HdfDriverEntry *HdfDriverEntryConstruct(int32_t *driverCount)
-{
- int i;
- *driverCount = (int32_t)(((uint8_t *)(HDF_DRIVER_END()) - (uint8_t *)(HDF_DRIVER_BEGIN())) / sizeof(size_t));
- if (*driverCount <= 0) {
- HDF_LOGE("%s: failed to hdf get device counts", __func__);
- return NULL;
- }
- struct HdfDriverEntry *driverEntry = OsalMemCalloc(*driverCount * sizeof(struct HdfDriverEntry));
- if (driverEntry == NULL) {
- HDF_LOGE("%s: failed to alloc driver entry mem", __func__);
- *driverCount = 0;
- return NULL;
- }
- size_t *addrBegin = (size_t *)(HDF_DRIVER_BEGIN());
- for (i = 0; i < *driverCount; i++) {
- driverEntry[i] = *(struct HdfDriverEntry *)(*addrBegin);
- addrBegin++;
- }
- return driverEntry;
-}
-
-struct HdfDriverEntry *HdfDriverLoaderGetDriverEntry(const struct HdfDeviceInfo *deviceInfo)
-{
- int i;
- if ((deviceInfo == NULL) || (deviceInfo->moduleName == NULL) || (deviceInfo->svcName == NULL)) {
- HDF_LOGE("%s: failed to get device entry, input deviceInfo is NULL", __func__);
- return NULL;
- }
- static struct HdfDriverEntry *driverEntry = NULL;
- static int32_t driverCount = 0;
- if (driverEntry == NULL) {
- driverEntry = HdfDriverEntryConstruct(&driverCount);
- if (driverEntry == NULL) {
- HDF_LOGE("%s: failed to construct driver entry", __func__);
- return NULL;
- }
- }
- for (i = 0; i < driverCount; i++) {
- if (driverEntry == NULL) {
- HDF_LOGE("%s: driver entry is null", __func__);
- return NULL;
- }
- if (driverEntry[i].moduleName == NULL) {
- HDF_LOGE("%s: driver entry module name is null", __func__);
- continue;
- }
- if (strcmp(deviceInfo->moduleName, driverEntry[i].moduleName) == 0) {
- return &driverEntry[i];
- }
- }
- HDF_LOGE("failed to get device entry %s", deviceInfo->svcName);
- return NULL;
-}
-
diff --git a/core/host/include/devhost_service.h b/core/host/include/devhost_service.h
index eb7347eef9363e207d75d864b6e786bcc291dbd4..8ddba0ce75209d2a4e96c589914bc3a14263454c 100644
--- a/core/host/include/devhost_service.h
+++ b/core/host/include/devhost_service.h
@@ -27,7 +27,7 @@ struct DevHostService {
void DevHostServiceConstruct(struct DevHostService *service);
void DevHostServiceDestruct(struct DevHostService *service);
int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDeviceInfo *deviceInfo);
-int DevHostServiceDelDevice(struct IDevHostService *inst, const struct HdfDeviceInfo *deviceInfo);
+int DevHostServiceDelDevice(struct IDevHostService *inst, devid_t devId);
struct IDevHostService *DevHostServiceNewInstance(uint16_t hostId, const char *hostName);
void DevHostServiceFreeInstance(struct IDevHostService *service);
struct HdfObject *DevHostServiceCreate(void);
diff --git a/core/host/include/devmgr_service_clnt.h b/core/host/include/devmgr_service_clnt.h
index 87216668fade2f27a7ea7a9bbbd92017f39cc3f3..d5aecee85e3f44d8e7b5abe6a4514dd7a1d079c9 100644
--- a/core/host/include/devmgr_service_clnt.h
+++ b/core/host/include/devmgr_service_clnt.h
@@ -19,7 +19,8 @@ struct DevmgrServiceClnt {
struct DevmgrServiceClnt *DevmgrServiceClntGetInstance(void);
void DevmgrServiceClntFreeInstance(struct DevmgrServiceClnt *inst);
-int DevmgrServiceClntAttachDevice(const struct HdfDeviceInfo *deviceInfo, struct IHdfDeviceToken *deviceToken);
+int DevmgrServiceClntAttachDevice(struct IHdfDeviceToken *deviceToken);
+int DevmgrServiceClntDetachDevice(devid_t devid);
int DevmgrServiceClntAttachDeviceHost(uint16_t hostId, struct IDevHostService *hostService);
#endif /* DEVMGR_SERVICE_CLIENT_H */
diff --git a/core/host/include/devsvc_manager_clnt.h b/core/host/include/devsvc_manager_clnt.h
index ec7f7bec7a6a1502e694a7d72d2ac5296b00bf90..34c748069ac7d63a78042d4800e4bb7dfe2b015b 100644
--- a/core/host/include/devsvc_manager_clnt.h
+++ b/core/host/include/devsvc_manager_clnt.h
@@ -17,11 +17,12 @@ struct DevSvcManagerClnt {
struct DevSvcManagerClnt *DevSvcManagerClntGetInstance(void);
struct HdfDeviceObject *DevSvcManagerClntGetDeviceObject(const char *svcName);
-int DevSvcManagerClntAddService(const char *svcName, struct HdfDeviceObject *service);
+int DevSvcManagerClntAddService(const char *svcName, uint16_t devClass,
+ struct HdfDeviceObject *service, const char *servinfo);
+int DevSvcManagerClntUpdateService(const char *svcName, uint16_t devClass,
+ struct HdfDeviceObject *service, const char *servinfo);
void DevSvcManagerClntRemoveService(const char *svcName);
int DevSvcManagerClntSubscribeService(const char *svcName, struct SubscriberCallback callback);
int DevSvcManagerClntUnsubscribeService(const char *svcName);
-struct HdfDeviceObject *HdfRegisterDevice(const char *moduleName, const char *serviceName, const void *privateData);
-void HdfUnregisterDevice(const char *moduleName, const char *serviceName);
#endif /* DEVSVC_MANAGER_CLNT_H */
diff --git a/core/host/include/hdf_device.h b/core/host/include/hdf_device.h
index 25e2a065077b5426a1c2b4519d46d20a3e62edf2..a61d784b42345eb909924555999dcf0de1bc57ba 100644
--- a/core/host/include/hdf_device.h
+++ b/core/host/include/hdf_device.h
@@ -9,35 +9,55 @@
#ifndef HDF_DEVICE_H
#define HDF_DEVICE_H
-#include "devhost_service.h"
-#include "device_token_if.h"
#include "hdf_device_desc.h"
-#include "hdf_object.h"
-#include "hdf_service_observer.h"
#include "hdf_dlist.h"
-#include "osal_mutex.h"
+#include "hdf_object.h"
+
+/*
+ * -----------------+----------------+----------------+----------------+
+ * | BYTE | BYTE | BYTE | BYTE |
+ * +---------------------------------+---------------------------------+
+ * | host id | device id | device node id |
+ * -----------------+---------------------------------+----------------+
+ */
+typedef uint32_t devid_t;
+
+#define HOSTID_BITS 8
+#define DEVICEID_BITS 16
+#define DEVNODEID_BITS 8
+#define DEVNODEID_MASK ((1 << DEVNODEID_BITS) - 1)
+#define DEVICEID_MASK ((1 << DEVICEID_BITS) - 1)
+
+#define HOSTID(devid) (devid >> (DEVICEID_BITS + DEVNODEID_BITS))
+#define DEVICEID(devid) ((devid >> DEVNODEID_BITS) & DEVICEID_MASK)
+#define DEVNODEID(devid) (devid & DEVNODEID_MASK)
+
+#define MK_DEVID(hostId, deviceId, devnodeId) \
+ (hostId << (DEVICEID_BITS + DEVNODEID_BITS) | deviceId << DEVNODEID_BITS | devnodeId)
struct HdfDeviceNode;
struct IHdfDevice {
struct HdfObject object;
- int (*Attach)(struct IHdfDevice *, struct HdfDeviceNode *);
- void (*Detach)(struct IHdfDevice *, struct HdfDeviceNode *);
+ int (*Attach)(struct IHdfDevice *device, struct HdfDeviceNode *deviceNode);
+ int (*Detach)(struct IHdfDevice *device, struct HdfDeviceNode *deviceNode);
+ struct HdfDeviceNode *(*GetDeviceNode)(struct IHdfDevice *device, devid_t devid);
+ int (*DetachWithDevid)(struct IHdfDevice *device, devid_t devid);
};
struct HdfDevice {
struct IHdfDevice super;
struct DListHead node;
struct DListHead devNodes;
- uint16_t deviceId;
- uint16_t hostId;
+ devid_t deviceId;
+ uint16_t devidIndex;
};
+int HdfDeviceDetach(struct IHdfDevice *devInst, struct HdfDeviceNode *devNode);
void HdfDeviceConstruct(struct HdfDevice *device);
void HdfDeviceDestruct(struct HdfDevice *device);
struct HdfObject *HdfDeviceCreate(void);
void HdfDeviceRelease(struct HdfObject *object);
struct HdfDevice *HdfDeviceNewInstance(void);
void HdfDeviceFreeInstance(struct HdfDevice *device);
-void HdfDeviceDelete(struct HdfSListNode *deviceEntry);
#endif /* HDF_DEVICE_H */
diff --git a/core/host/include/hdf_device_node.h b/core/host/include/hdf_device_node.h
index 475158eada8f93249a2fd0a333b4eefa10b5fe0f..c0e5a034f8a1dbe6d0a66c1af36f8185a5c4c23b 100644
--- a/core/host/include/hdf_device_node.h
+++ b/core/host/include/hdf_device_node.h
@@ -13,6 +13,7 @@
#include "hdf_device_info.h"
#include "hdf_device_desc.h"
#include "hdf_dlist.h"
+#include "hdf_driver.h"
#include "hdf_pm.h"
struct HdfDeviceNode;
@@ -20,8 +21,10 @@ struct DevHostService;
struct IDeviceNode {
struct HdfObject object;
- int (*PublishService)(struct HdfDeviceNode *, const char *);
- int (*LaunchNode)(struct HdfDeviceNode *, struct IHdfDevice *);
+ int (*PublishService)(struct HdfDeviceNode *devNode);
+ int (*RemoveService)(struct HdfDeviceNode *devNode);
+ int (*LaunchNode)(struct HdfDeviceNode *devNode);
+ void (*UnlaunchNode)(struct HdfDeviceNode *devNode);
};
struct HdfDeviceNode {
@@ -31,20 +34,35 @@ struct HdfDeviceNode {
struct DevHostService *hostService;
struct HdfDeviceObject deviceObject;
struct IHdfDeviceToken *token;
- struct HdfDriverEntry *driverEntry;
- const struct HdfDeviceInfo *deviceInfo;
+ struct HdfDriver *driver;
+ struct HdfDevice *device;
+ char *servName;
+ const char *servInfo;
+ char *driverName;
+ devid_t devId;
+ uint16_t policy;
+ uint16_t permission;
+ uint8_t devStatus;
+ bool servStatus;
+};
+
+enum DevNodeStaus {
+ DEVNODE_NONE = 0,
+ DEVNODE_INITED,
+ DEVNODE_LAUNCHED,
};
int HdfDeviceNodeAddPowerStateListener(
struct HdfDeviceNode *devNode, const struct IPowerEventListener *listener);
void HdfDeviceNodeRemovePowerStateListener(
struct HdfDeviceNode *devNode, const struct IPowerEventListener *listener);
-void HdfDeviceNodeConstruct(struct HdfDeviceNode *service);
-void HdfDeviceNodeDestruct(struct HdfDeviceNode *service);
-struct HdfDeviceNode *HdfDeviceNodeNewInstance(void);
-void HdfDeviceNodeFreeInstance(struct HdfDeviceNode *service);
+void HdfDeviceNodeConstruct(struct HdfDeviceNode *devNode);
+void HdfDeviceNodeDestruct(struct HdfDeviceNode *devNode);
+struct HdfDeviceNode *HdfDeviceNodeNewInstance(const struct HdfDeviceInfo *deviceInfo, struct HdfDriver *driver);
+void HdfDeviceNodeFreeInstance(struct HdfDeviceNode *devNode);
void HdfDeviceNodeDelete(struct HdfDeviceNode *devNode);
-int HdfDeviceNodePublishPublicService(struct HdfDeviceNode *service, const char *svcName);
-void HdfDeviceNodeReclaimService(const char *svcName);
+int HdfDeviceNodePublishPublicService(struct HdfDeviceNode *devNode);
+int HdfDeviceNodeRemoveService(struct HdfDeviceNode *devNode);
+int DeviveDriverBind(struct HdfDeviceNode *devNode);
#endif /* HDF_DEVICE_NODE_H */
diff --git a/core/host/include/hdf_device_object.h b/core/host/include/hdf_device_object.h
index ec194e465170541640a62747c20cd6990ae9f9ec..8c52698a97bc4743817f351487979708d7d3358f 100644
--- a/core/host/include/hdf_device_object.h
+++ b/core/host/include/hdf_device_object.h
@@ -12,5 +12,13 @@
#include "hdf_device_desc.h"
void HdfDeviceObjectConstruct(struct HdfDeviceObject *deviceObject);
-
+struct HdfDeviceObject *HdfDeviceObjectAlloc(struct HdfDeviceObject *parent, const char *driverName);
+void HdfDeviceObjectRelease(struct HdfDeviceObject *deviceObject);
+int HdfDeviceObjectRegister(struct HdfDeviceObject *deviceObject);
+int HdfDeviceObjectUnRegister(struct HdfDeviceObject *deviceObject);
+int HdfDeviceObjectPublishService(struct HdfDeviceObject *deviceObject,
+ const char *servName, uint8_t policy, uint32_t perm);
+int HdfRemoveService(struct HdfDeviceObject *deviceObject);
+int HdfDeviceObjectSetServInfo(struct HdfDeviceObject *dev, const char *info);
+int HdfDeviceObjectUpdate(struct HdfDeviceObject *dev);
#endif /* HDF_DEVICE_OBJECT_H */
diff --git a/core/host/include/hdf_driver_loader.h b/core/host/include/hdf_driver_loader.h
index 56048807b6c75b8e75bb24bfa335601afdccf002..e22d29c2eea55a9678dd6fac6e3b9f4edbc93811 100644
--- a/core/host/include/hdf_driver_loader.h
+++ b/core/host/include/hdf_driver_loader.h
@@ -15,9 +15,8 @@
struct IDriverLoader {
struct HdfObject object;
- struct HdfDriverEntry *(*GetDriverEntry)(const struct HdfDeviceInfo *deviceInfo);
- struct HdfDeviceNode *(*LoadNode)(struct IDriverLoader *, const struct HdfDeviceInfo *deviceInfo);
- void (*UnLoadNode)(struct IDriverLoader *, const struct HdfDeviceInfo *deviceInfo);
+ struct HdfDriver *(*GetDriver)(const char *driverName);
+ void (*ReclaimDriver)(struct HdfDriver *driver);
};
struct HdfDriverLoader {
@@ -28,7 +27,7 @@ struct HdfObject *HdfDriverLoaderCreate(void);
void HdfDriverLoaderConstruct(struct HdfDriverLoader *inst);
void HdfDriverLoaderRelease(struct HdfObject *object);
struct IDriverLoader *HdfDriverLoaderGetInstance(void);
-struct HdfDriverEntry *HdfDriverLoaderGetDriverEntry(const struct HdfDeviceInfo *deviceInfo);
+struct HdfDriver *HdfDriverLoaderGetDriver(const char *moduleName);
struct HdfDeviceNode *HdfDriverLoaderLoadNode(
struct IDriverLoader *loader, const struct HdfDeviceInfo *deviceInfo);
void HdfDriverLoaderUnLoadNode(struct IDriverLoader *loader, const struct HdfDeviceInfo *deviceInfo);
diff --git a/core/host/include/hdf_observer_record.h b/core/host/include/hdf_observer_record.h
index a8bcbd93f4ff9b5028dc8b48b2fde03349c00b58..7e63ab82cf4f6d863c408f675edddafbee0dd7cf 100644
--- a/core/host/include/hdf_observer_record.h
+++ b/core/host/include/hdf_observer_record.h
@@ -9,6 +9,7 @@
#ifndef HDF_OBSERVER_RECORD_H
#define HDF_OBSERVER_RECORD_H
+#include "hdf_device.h"
#include "hdf_object.h"
#include "hdf_slist.h"
#include "osal_mutex.h"
@@ -17,18 +18,17 @@ struct HdfServiceObserverRecord {
struct HdfSListNode entry;
uint32_t serviceKey;
uint16_t policy;
- uint32_t matchId;
+ devid_t devId;
struct OsalMutex obsRecMutex;
struct HdfSList subscribers;
struct HdfObject *publisher;
};
-uint32_t HdfMakeHardwareId(uint16_t hostId, uint16_t deviceId);
struct HdfServiceObserverRecord *HdfServiceObserverRecordObtain(uint32_t serviceKey);
void HdfServiceObserverRecordRecycle(struct HdfServiceObserverRecord *record);
bool HdfServiceObserverRecordCompare(struct HdfSListNode *listEntry, uint32_t serviceKey);
void HdfServiceObserverRecordNotifySubscribers(
- struct HdfServiceObserverRecord *record, uint32_t matchId, uint16_t policy);
+ struct HdfServiceObserverRecord *record, devid_t devid, uint16_t policy);
void HdfServiceObserverRecordDelete(struct HdfSListNode *listEntry);
#endif /* HDF_OBSERVER_RECORD_H */
diff --git a/core/host/include/hdf_pm_reg.h b/core/host/include/hdf_pm_reg.h
new file mode 100755
index 0000000000000000000000000000000000000000..f065a46732ed03fc4365c405c483f380de25ab97
--- /dev/null
+++ b/core/host/include/hdf_pm_reg.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef HDF_PM_REG_H
+#define HDF_PM_REG_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+int DevMgrPmRegister(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* HDF_PM_REG_H */
diff --git a/core/host/include/hdf_power_manager.h b/core/host/include/hdf_power_manager.h
new file mode 100755
index 0000000000000000000000000000000000000000..2ed3cdb3f6fbd885b0b0259b215174927245ffb6
--- /dev/null
+++ b/core/host/include/hdf_power_manager.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef HDF_POWER_MANAGER_H
+#define HDF_POWER_MANAGER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include "hdf_task_queue.h"
+#include "power_state_token.h"
+
+typedef enum {
+ HDF_PM_REQUEST_ACQUIRE,
+ HDF_PM_REQUEST_RELEASE,
+} HDF_PM_REQUEST_TYPE;
+
+struct HdfPmRequest {
+ struct PowerStateToken *token;
+ HDF_PM_REQUEST_TYPE pmType;
+ struct HdfTaskType task;
+};
+
+int32_t HdfPowerManagerInit(void);
+void HdfPmTaskPut(struct PowerStateToken *powerToken, HDF_PM_REQUEST_TYPE type);
+void HdfPowerManagerExit(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* HDF_POWER_MANAGER_H */
diff --git a/core/host/include/hdf_service_subscriber.h b/core/host/include/hdf_service_subscriber.h
index 2d2528b0d5b3f51f91749b1f4729bde45f798220..29ba7477ba7a107bf0905e03f90f4e5db7003c98 100644
--- a/core/host/include/hdf_service_subscriber.h
+++ b/core/host/include/hdf_service_subscriber.h
@@ -9,13 +9,14 @@
#ifndef HDF_SERVICE_SUBSCRIBER_H
#define HDF_SERVICE_SUBSCRIBER_H
+#include "hdf_device.h"
#include "hdf_device_desc.h"
#include "hdf_slist.h"
struct HdfServiceSubscriber {
struct HdfSListNode entry;
uint32_t state;
- uint32_t matchId;
+ uint32_t devId;
struct SubscriberCallback callback;
};
@@ -24,7 +25,7 @@ enum {
HDF_SUBSCRIBER_STATE_READY
};
-struct HdfServiceSubscriber *HdfServiceSubscriberObtain(struct SubscriberCallback callback, uint32_t matchId);
+struct HdfServiceSubscriber *HdfServiceSubscriberObtain(struct SubscriberCallback callback, devid_t devid);
void HdfServiceSubscriberRecycle(struct HdfServiceSubscriber *subscriber);
void HdfServiceSubscriberDelete(struct HdfSListNode *listEntry);
diff --git a/core/host/src/devhost_service.c b/core/host/src/devhost_service.c
index bd0c84135221790a15807a06461559078de79168..ff86228ba9a61c62ee8826164f5521eb6558a53b 100644
--- a/core/host/src/devhost_service.c
+++ b/core/host/src/devhost_service.c
@@ -10,6 +10,7 @@
#include "devmgr_service_clnt.h"
#include "devsvc_manager_clnt.h"
#include "hdf_base.h"
+#include "hdf_driver.h"
#include "hdf_driver_loader.h"
#include "hdf_log.h"
#include "hdf_object_manager.h"
@@ -20,30 +21,29 @@
static struct HdfDevice *DevHostServiceFindDevice(struct DevHostService *hostService, uint16_t deviceId)
{
- struct HdfDevice *deviceNode = NULL;
+ struct HdfDevice *device = NULL;
if (hostService == NULL) {
HDF_LOGE("failed to find driver, hostService is null");
return NULL;
}
- DLIST_FOR_EACH_ENTRY(deviceNode, &hostService->devices, struct HdfDevice, node) {
- if (deviceNode->deviceId == deviceId) {
- return deviceNode;
+ DLIST_FOR_EACH_ENTRY(device, &hostService->devices, struct HdfDevice, node) {
+ if (DEVICEID(device->deviceId) == deviceId) {
+ return device;
}
}
return NULL;
}
-static void DevHostServiceFreeDevice(struct DevHostService *hostService, uint16_t deviceId)
+static void DevHostServiceFreeDevice(struct DevHostService *hostService, struct HdfDevice *device)
{
- struct HdfDevice *device = DevHostServiceFindDevice(hostService, deviceId);
if (device != NULL) {
DListRemove(&device->node);
HdfDeviceFreeInstance(device);
}
}
-static struct HdfDevice *DevHostServiceGetDevice(struct DevHostService *inst, uint16_t deviceId)
+static struct HdfDevice *DevHostServiceQueryOrAddDevice(struct DevHostService *inst, uint16_t deviceId)
{
struct HdfDevice *device = DevHostServiceFindDevice(inst, deviceId);
if (device == NULL) {
@@ -52,8 +52,7 @@ static struct HdfDevice *DevHostServiceGetDevice(struct DevHostService *inst, ui
HDF_LOGE("Dev host service failed to create driver instance");
return NULL;
}
- device->hostId = inst->hostId;
- device->deviceId = deviceId;
+ device->deviceId = MK_DEVID(inst->hostId, deviceId, 0);
DListInsertHead(&device->node, &inst->devices);
}
return device;
@@ -64,78 +63,86 @@ int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDevice
int ret = HDF_FAILURE;
struct HdfDevice *device = NULL;
struct HdfDeviceNode *devNode = NULL;
+ struct HdfDriver *driver = NULL;
struct DevHostService *hostService = CONTAINER_OF(inst, struct DevHostService, super);
struct IDriverLoader *driverLoader = HdfDriverLoaderGetInstance();
- if (inst == NULL || deviceInfo == NULL || driverLoader == NULL || driverLoader->LoadNode == NULL) {
+ if (inst == NULL || deviceInfo == NULL || driverLoader == NULL || driverLoader->GetDriver == NULL) {
HDF_LOGE("failed to add device, input param is null");
return ret;
}
- device = DevHostServiceGetDevice(hostService, deviceInfo->deviceId);
+ device = DevHostServiceQueryOrAddDevice(hostService, DEVICEID(deviceInfo->deviceId));
if (device == NULL || device->super.Attach == NULL) {
ret = HDF_DEV_ERR_NO_DEVICE;
goto error;
}
+ devNode = device->super.GetDeviceNode(&device->super, deviceInfo->deviceId);
+ if (devNode != NULL) {
+ HDF_LOGE("failed to add device %d, device already exist", deviceInfo->deviceId);
+ return HDF_ERR_DEVICE_BUSY;
+ }
+ driver = driverLoader->GetDriver(deviceInfo->moduleName);
+ if (driver == NULL) {
+ ret = HDF_DEV_ERR_NODATA;
+ goto error;
+ }
- devNode = driverLoader->LoadNode(driverLoader, deviceInfo);
+ devNode = HdfDeviceNodeNewInstance(deviceInfo, driver);
if (devNode == NULL) {
- ret = HDF_DEV_ERR_NO_DEVICE_SERVICE;
- goto error;
+ driverLoader->ReclaimDriver(driver);
+ return HDF_DEV_ERR_NO_MEMORY;
}
+
devNode->hostService = hostService;
+ devNode->device = device;
+ devNode->driver = driver;
ret = device->super.Attach(&device->super, devNode);
if (ret != HDF_SUCCESS) {
+ HdfDeviceNodeFreeInstance(devNode);
goto error;
}
return HDF_SUCCESS;
error:
- DevHostServiceFreeDevice(hostService, device->deviceId);
- return ret;
-}
-
-static struct HdfDeviceNode *DevHostServiceSeparateDeviceNode(struct DListHead *deviceNodes,
- const struct HdfDeviceInfo *deviceInfo)
-{
- struct HdfDeviceNode *deviceNode = NULL;
- DLIST_FOR_EACH_ENTRY(deviceNode, deviceNodes, struct HdfDeviceNode, entry) {
- if (strcmp(deviceNode->deviceInfo->svcName, deviceInfo->svcName) == 0 &&
- strcmp(deviceNode->deviceInfo->moduleName, deviceInfo->moduleName) == 0) {
- DListRemove(&deviceNode->entry);
- return deviceNode;
- }
+ if (DListIsEmpty(&device->devNodes)) {
+ DevHostServiceFreeDevice(hostService, device);
}
- return NULL;
+
+ return ret;
}
-int DevHostServiceDelDevice(struct IDevHostService *inst, const struct HdfDeviceInfo *deviceInfo)
+int DevHostServiceDelDevice(struct IDevHostService *inst, devid_t devId)
{
struct HdfDevice *device = NULL;
struct DevHostService *hostService = (struct DevHostService *)inst;
- struct IDriverLoader *driverLoader = HdfDriverLoaderGetInstance();
-
- if ((deviceInfo == NULL) || (driverLoader == NULL) || (driverLoader->UnLoadNode == NULL)) {
- HDF_LOGE("failed to del device, input param is null");
- return HDF_FAILURE;
- }
+ struct HdfDeviceNode *devNode = NULL;
- device = DevHostServiceFindDevice(hostService, deviceInfo->deviceId);
+ device = DevHostServiceFindDevice(hostService, DEVICEID(devId));
if (device == NULL) {
HDF_LOGW("failed to del device, device is not exist");
return HDF_SUCCESS;
}
- driverLoader->UnLoadNode(driverLoader, deviceInfo);
- struct HdfDeviceNode *devNode = DevHostServiceSeparateDeviceNode(&device->devNodes, deviceInfo);
- if (device->super.Detach != NULL) {
- device->super.Detach(&device->super, devNode);
- } else {
- HdfDeviceNodeFreeInstance(devNode);
+ devNode = device->super.GetDeviceNode(&device->super, devId);
+ if (devNode == NULL) {
+ HDF_LOGI("failed to del device %u, not exist", devId);
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+
+ if (device->super.Detach == NULL) {
+ HDF_LOGE("failed to del device %u, invalid device", devId);
+ return HDF_ERR_INVALID_OBJECT;
}
- DevSvcManagerClntRemoveService(deviceInfo->svcName);
+
+ if (device->super.Detach(&device->super, devNode) != HDF_SUCCESS) {
+ HDF_LOGE("failed to detach device %u", devId);
+ return HDF_FAILURE;
+ }
+ HdfDeviceNodeFreeInstance(devNode);
+
if (DListIsEmpty(&device->devNodes)) {
- DevHostServiceFreeDevice(hostService, device->deviceId);
+ DevHostServiceFreeDevice(hostService, device);
}
return HDF_SUCCESS;
}
@@ -162,7 +169,7 @@ static int ApplyDevicesPowerState(struct HdfDevice *device, uint32_t state)
if (deviceNode->powerToken != NULL) {
ret = PowerStateChange(deviceNode->powerToken, state);
if (ret != HDF_SUCCESS) {
- HDF_LOGE("device %s failed to resume(%d)", deviceNode->driverEntry->moduleName, state);
+ HDF_LOGE("device %s failed to resume(%d)", deviceNode->driver->entry->moduleName, state);
}
}
}
@@ -171,7 +178,7 @@ static int ApplyDevicesPowerState(struct HdfDevice *device, uint32_t state)
if (deviceNode->powerToken != NULL) {
ret = PowerStateChange(deviceNode->powerToken, state);
if (ret != HDF_SUCCESS) {
- HDF_LOGE("device %s failed to suspend(%d)", deviceNode->driverEntry->moduleName, state);
+ HDF_LOGE("device %s failed to suspend(%d)", deviceNode->driver->entry->moduleName, state);
}
}
}
@@ -223,12 +230,12 @@ void DevHostServiceConstruct(struct DevHostService *service)
void DevHostServiceDestruct(struct DevHostService *service)
{
+ struct HdfDevice *device = NULL;
+ struct HdfDevice *tmp = NULL;
if (service == NULL) {
return;
}
- struct HdfDevice *device = NULL;
- struct HdfDevice *tmp = NULL;
DLIST_FOR_EACH_ENTRY_SAFE(device, tmp, &service->devices, struct HdfDevice, node) {
HdfDeviceFreeInstance(device);
}
diff --git a/core/host/src/devmgr_service_clnt.c b/core/host/src/devmgr_service_clnt.c
index 378ec5f59755f9decf580e252ab65c62118afd2d..6788fa4485bb861bf1494e368e9fde329ab7cbbf 100644
--- a/core/host/src/devmgr_service_clnt.c
+++ b/core/host/src/devmgr_service_clnt.c
@@ -31,7 +31,7 @@ int DevmgrServiceClntAttachDeviceHost(uint16_t hostId, struct IDevHostService *h
return devMgrSvcIf->AttachDeviceHost(devMgrSvcIf, hostId, hostService);
}
-int DevmgrServiceClntAttachDevice(const struct HdfDeviceInfo *deviceInfo, struct IHdfDeviceToken *deviceToken)
+int DevmgrServiceClntAttachDevice(struct IHdfDeviceToken *deviceToken)
{
struct IDevmgrService *devMgrSvcIf = NULL;
struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance();
@@ -45,7 +45,23 @@ int DevmgrServiceClntAttachDevice(const struct HdfDeviceInfo *deviceInfo, struct
HDF_LOGE("devmgr client failed to attach device, dmsOps->AttachDevice is nul");
return HDF_FAILURE;
}
- return devMgrSvcIf->AttachDevice(devMgrSvcIf, deviceInfo, deviceToken);
+ return devMgrSvcIf->AttachDevice(devMgrSvcIf, deviceToken);
+}
+
+int DevmgrServiceClntDetachDevice(devid_t devid)
+{
+ struct IDevmgrService *devMgrSvcIf = NULL;
+ struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance();
+ if (inst == NULL || inst->devMgrSvcIf == NULL) {
+ HDF_LOGE("devmgr client failed to deatch device, inst is null");
+ return HDF_FAILURE;
+ }
+
+ devMgrSvcIf = inst->devMgrSvcIf;
+ if (devMgrSvcIf->DetachDevice == NULL) {
+ return HDF_FAILURE;
+ }
+ return devMgrSvcIf->DetachDevice(devMgrSvcIf, devid);
}
struct DevmgrServiceClnt *DevmgrServiceClntGetInstance()
@@ -64,4 +80,3 @@ void DevmgrServiceClntFreeInstance(struct DevmgrServiceClnt *inst)
inst->devMgrSvcIf = NULL;
}
}
-
diff --git a/core/host/src/devsvc_manager_clnt.c b/core/host/src/devsvc_manager_clnt.c
index 479839b941d54aa39ac819bcdb3383c98ad39033..e3643a05c31f3184710024a5e1a01e5a3691ac8c 100644
--- a/core/host/src/devsvc_manager_clnt.c
+++ b/core/host/src/devsvc_manager_clnt.c
@@ -7,40 +7,65 @@
*/
#include "devsvc_manager_clnt.h"
-#include "devmgr_service.h"
-#include "devsvc_manager.h"
-#include "hdf_attribute_manager.h"
-#include "hdf_base.h"
#include "hdf_log.h"
#include "hdf_object_manager.h"
#define HDF_LOG_TAG devsvc_manager_clnt
-int DevSvcManagerClntAddService(const char *svcName, struct HdfDeviceObject *service)
+int DevSvcManagerClntAddService(const char *svcName, uint16_t devClass,
+ struct HdfDeviceObject *service, const char *servinfo)
{
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
+ struct IDevSvcManager *serviceManager = NULL;
if (devSvcMgrClnt == NULL) {
HDF_LOGE("failed to add service, client is null");
return HDF_FAILURE;
}
+ if (devClass >= DEVICE_CLASS_MAX) {
+ HDF_LOGE("failed to add service, invalid class");
+ return HDF_FAILURE;
+ }
- struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
+ serviceManager = devSvcMgrClnt->devSvcMgrIf;
if (serviceManager == NULL || serviceManager->AddService == NULL) {
HDF_LOGE("serviceManager AddService function is null");
return HDF_FAILURE;
}
- return serviceManager->AddService(serviceManager, svcName, service);
+ return serviceManager->AddService(serviceManager, svcName, devClass, service, servinfo);
+}
+
+int DevSvcManagerClntUpdateService(const char *svcName, uint16_t devClass,
+ struct HdfDeviceObject *service, const char *servinfo)
+{
+ struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
+ struct IDevSvcManager *serviceManager = NULL;
+ if (devSvcMgrClnt == NULL) {
+ HDF_LOGE("failed to add service, client is null");
+ return HDF_FAILURE;
+ }
+ if (devClass >= DEVICE_CLASS_MAX) {
+ HDF_LOGE("failed to add service, invalid class");
+ return HDF_FAILURE;
+ }
+
+ serviceManager = devSvcMgrClnt->devSvcMgrIf;
+ if (serviceManager == NULL || serviceManager->UpdateService == NULL) {
+ HDF_LOGE("serviceManager UpdateService function is null");
+ return HDF_FAILURE;
+ }
+ return serviceManager->UpdateService(serviceManager, svcName, devClass, service, servinfo);
}
const struct HdfObject *DevSvcManagerClntGetService(const char *svcName)
{
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
+ struct IDevSvcManager *serviceManager = NULL;
if (devSvcMgrClnt == NULL) {
HDF_LOGE("failed to get service, client is null");
return NULL;
}
- struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
+ serviceManager = devSvcMgrClnt->devSvcMgrIf;
if (serviceManager == NULL || serviceManager->GetService == NULL) {
HDF_LOGE("serviceManager GetService function is null");
return NULL;
@@ -51,12 +76,13 @@ const struct HdfObject *DevSvcManagerClntGetService(const char *svcName)
struct HdfDeviceObject *DevSvcManagerClntGetDeviceObject(const char *svcName)
{
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
+ struct IDevSvcManager *serviceManager = NULL;
if (devSvcMgrClnt == NULL) {
HDF_LOGE("failed to get device object, client is null");
return NULL;
}
- struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
+ serviceManager = devSvcMgrClnt->devSvcMgrIf;
if (serviceManager == NULL || serviceManager->GetObject == NULL) {
HDF_LOGE("failed to get device object, method not implement");
return NULL;
@@ -64,39 +90,16 @@ struct HdfDeviceObject *DevSvcManagerClntGetDeviceObject(const char *svcName)
return serviceManager->GetObject(serviceManager, svcName);
}
-struct HdfDeviceObject *HdfRegisterDevice(const char *moduleName, const char *serviceName, const void *privateData)
-{
- int ret;
- if (!HdfDeviceListAdd(moduleName, serviceName, privateData)) {
- HDF_LOGE("%s device info add failed!", __func__);
- return NULL;
- }
- ret = DevmgrServiceLoadDevice(serviceName);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s load device %s failed!", __func__, serviceName);
- HdfDeviceListDel(moduleName, serviceName);
- return NULL;
- }
- return DevSvcManagerClntGetDeviceObject(serviceName);
-}
-
-void HdfUnregisterDevice(const char *moduleName, const char *serviceName)
-{
- if (DevmgrServiceUnLoadDevice(serviceName) != HDF_SUCCESS) {
- HDF_LOGE("%s:failed to unload device %s !", __func__, serviceName);
- }
- HdfDeviceListDel(moduleName, serviceName);
-}
-
int DevSvcManagerClntSubscribeService(const char *svcName, struct SubscriberCallback callback)
{
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
+ struct IDevSvcManager *serviceManager = NULL;
if (devSvcMgrClnt == NULL) {
HDF_LOGE("failed to subscribe service, client is null");
return HDF_FAILURE;
}
- struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
+ serviceManager = devSvcMgrClnt->devSvcMgrIf;
if (serviceManager == NULL || serviceManager->SubscribeService == NULL) {
HDF_LOGE("failed to subscribe service, method not implement");
return HDF_FAILURE;
@@ -107,12 +110,13 @@ int DevSvcManagerClntSubscribeService(const char *svcName, struct SubscriberCall
int DevSvcManagerClntUnsubscribeService(const char *svcName)
{
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
+ struct IDevSvcManager *serviceManager = NULL;
if (devSvcMgrClnt == NULL) {
HDF_LOGE("failed to unsubscribe service, client is null");
return HDF_FAILURE;
}
- struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
+ serviceManager = devSvcMgrClnt->devSvcMgrIf;
if (serviceManager == NULL || serviceManager->UnsubscribeService == NULL) {
HDF_LOGE("failed to unsubscribe service, method not implement");
return HDF_FAILURE;
@@ -123,14 +127,14 @@ int DevSvcManagerClntUnsubscribeService(const char *svcName)
void DevSvcManagerClntRemoveService(const char *svcName)
{
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
+ struct IDevSvcManager *serviceManager = NULL;
if (devSvcMgrClnt == NULL) {
HDF_LOGE("failed to remove service, devSvcMgrClnt is null");
return;
}
- struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
+ serviceManager = devSvcMgrClnt->devSvcMgrIf;
if (serviceManager == NULL || serviceManager->RemoveService == NULL) {
- HDF_LOGE("failed to remove service, method not implement");
return;
}
serviceManager->RemoveService(serviceManager, svcName);
diff --git a/core/host/src/hdf_device.c b/core/host/src/hdf_device.c
index d61036007dacfdc41726ca361f5187fb5182b04a..43487d5fd4aec45d9ec3ca0fb0376ec3d6f5eaed 100644
--- a/core/host/src/hdf_device.c
+++ b/core/host/src/hdf_device.c
@@ -18,37 +18,120 @@
#define HDF_LOG_TAG hdf_device
+static void UpdateDeivceNodeIdIndex(struct HdfDevice *device, devid_t nodeDevid)
+{
+ if (device->devidIndex < DEVICEID(nodeDevid)) {
+ device->devidIndex = DEVICEID(nodeDevid);
+ }
+}
+
+static int AcquireNodeDeivceId(struct HdfDevice *device, devid_t *devid)
+{
+ if (device->devidIndex >= DEVICEID_MASK) {
+ return HDF_FAILURE;
+ }
+ device->devidIndex++;
+ *devid = MK_DEVID(HOSTID(device->deviceId), DEVICEID(device->deviceId), device->devidIndex);
+
+ return HDF_SUCCESS;
+}
+
static int HdfDeviceAttach(struct IHdfDevice *devInst, struct HdfDeviceNode *devNode)
{
+ int ret;
struct HdfDevice *device = (struct HdfDevice *)devInst;
struct IDeviceNode *nodeIf = (struct IDeviceNode *)devNode;
+
if (device == NULL || nodeIf == NULL || nodeIf->LaunchNode == NULL) {
HDF_LOGE("failed to attach device, input params invalid");
return HDF_ERR_INVALID_PARAM;
}
- DListInsertTail(&devNode->entry, &device->devNodes);
- return nodeIf->LaunchNode(devNode, devInst);
+
+ // for dynamic added device node, assign device id here
+ if (devNode->devId == 0 && AcquireNodeDeivceId(device, &devNode->devId) != HDF_SUCCESS) {
+ HDF_LOGE("failed to attach device, invalid device id");
+ return HDF_ERR_INVALID_PARAM;
+ }
+ devNode->token->devid = devNode->devId;
+ ret = nodeIf->LaunchNode(devNode);
+ if (ret == HDF_SUCCESS) {
+ DListInsertTail(&devNode->entry, &device->devNodes);
+ UpdateDeivceNodeIdIndex(device, devNode->devId);
+ }
+
+ return ret;
+}
+
+int HdfDeviceDetach(struct IHdfDevice *devInst, struct HdfDeviceNode *devNode)
+{
+ struct HdfDevice *device = NULL;
+ if (devInst == NULL || devNode == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ device = CONTAINER_OF(devInst, struct HdfDevice, super);
+ if (DEVICEID(device->deviceId) != DEVICEID(devNode->devId)) {
+ HDF_LOGE("%s: device %x detach unknown devnode %x", __func__, device->deviceId, devNode->devId);
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+
+ if (devNode->entry.next != NULL) {
+ DListRemove(&devNode->entry);
+ }
+ if (devNode->super.UnlaunchNode != NULL) {
+ devNode->super.UnlaunchNode(devNode);
+ }
+
+ return HDF_SUCCESS;
+}
+
+static struct HdfDeviceNode *HdfDeviceGetDeviceNode(struct IHdfDevice *device, devid_t devid)
+{
+ struct HdfDeviceNode *devNode = NULL;
+ struct HdfDevice *dev = CONTAINER_OF(device, struct HdfDevice, super);
+ DLIST_FOR_EACH_ENTRY(devNode, &dev->devNodes, struct HdfDeviceNode, entry) {
+ if (devNode->devId == devid) {
+ return devNode;
+ };
+ }
+ return NULL;
+}
+
+static int HdfDeviceDetachWithDevid(struct IHdfDevice *device, devid_t devid)
+{
+ struct HdfDevice *dev = CONTAINER_OF(device, struct HdfDevice, super);
+ struct HdfDeviceNode *devNode = HdfDeviceGetDeviceNode(device, devid);
+ if (devNode == NULL) {
+ HDF_LOGE("detach device node %x not in device %x", devid, dev->deviceId);
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+
+ return HdfDeviceDetach(device, devNode);
}
void HdfDeviceConstruct(struct HdfDevice *device)
{
device->super.Attach = HdfDeviceAttach;
+ device->super.Detach = HdfDeviceDetach;
+ device->super.DetachWithDevid = HdfDeviceDetachWithDevid;
+ device->super.GetDeviceNode = HdfDeviceGetDeviceNode;
+
DListHeadInit(&device->devNodes);
}
void HdfDeviceDestruct(struct HdfDevice *device)
{
struct HdfDeviceNode *devNode = NULL;
- DLIST_FOR_EACH_ENTRY(devNode, &device->devNodes, struct HdfDeviceNode, entry) {
- HdfDeviceNodeDelete(devNode);
+ struct HdfDeviceNode *tmp = NULL;
+ DLIST_FOR_EACH_ENTRY_SAFE(devNode, tmp, &device->devNodes, struct HdfDeviceNode, entry) {
+ HdfDeviceNodeFreeInstance(devNode);
}
DListHeadInit(&device->devNodes);
}
struct HdfObject *HdfDeviceCreate()
{
- struct HdfDevice *device =
- (struct HdfDevice *)OsalMemCalloc(sizeof(struct HdfDevice));
+ struct HdfDevice *device = (struct HdfDevice *)OsalMemCalloc(sizeof(struct HdfDevice));
if (device != NULL) {
HdfDeviceConstruct(device);
}
@@ -75,13 +158,3 @@ void HdfDeviceFreeInstance(struct HdfDevice *device)
HdfObjectManagerFreeObject(&device->super.object);
}
}
-
-void HdfDeviceDelete(struct HdfSListNode *listEntry)
-{
- if (listEntry != NULL) {
- struct HdfDevice *device = (struct HdfDevice *)HDF_SLIST_CONTAINER_OF(
- struct HdfSListNode, listEntry, struct HdfDevice, node);
- HdfDeviceFreeInstance(device);
- }
-}
-
diff --git a/core/host/src/hdf_device_node.c b/core/host/src/hdf_device_node.c
index 06f46b43651fa723daeaa9ecb2733d8797743249..5bb1309dfa4c0df14010c4a1b5628d025634b75e 100644
--- a/core/host/src/hdf_device_node.c
+++ b/core/host/src/hdf_device_node.c
@@ -10,9 +10,13 @@
#include "devhost_service.h"
#include "devmgr_service_clnt.h"
#include "devsvc_manager_clnt.h"
+#include "hcs_tree_if.h"
+#include "hdf_attribute_manager.h"
#include "hdf_base.h"
+#include "hdf_cstring.h"
#include "hdf_device_object.h"
#include "hdf_device_token.h"
+#include "hdf_driver_loader.h"
#include "hdf_log.h"
#include "hdf_object_manager.h"
#include "hdf_observer_record.h"
@@ -21,79 +25,99 @@
#define HDF_LOG_TAG device_node
-static int HdfDeviceNodePublishLocalService(
- struct HdfDeviceNode *devNode, const struct HdfDeviceInfo *deviceInfo)
+static int HdfDeviceNodePublishLocalService(struct HdfDeviceNode *devNode)
{
- uint32_t matchId;
- if ((devNode == NULL) || (deviceInfo == NULL)) {
+ if (devNode == NULL) {
HDF_LOGE("failed to publish local service, device is null");
return HDF_FAILURE;
}
- struct DevHostService *hostService = devNode->hostService;
- if (hostService == NULL) {
+ if (devNode->hostService == NULL) {
HDF_LOGE("failed to publish local service, host service is null");
return HDF_FAILURE;
}
- matchId = HdfMakeHardwareId(deviceInfo->hostId, deviceInfo->deviceId);
- return HdfServiceObserverPublishService(&hostService->observer, deviceInfo->svcName,
- matchId, deviceInfo->policy, (struct HdfObject *)devNode->deviceObject.service);
+ return HdfServiceObserverPublishService(&(devNode->hostService->observer), devNode->servName,
+ devNode->devId, devNode->policy, (struct HdfObject *)devNode->deviceObject.service);
}
-static int HdfDeviceNodePublishService(
- struct HdfDeviceNode *devNode, const struct HdfDeviceInfo *deviceInfo, struct IHdfDevice *device)
+static int HdfDeviceNodePublishService(struct HdfDeviceNode *devNode)
{
- (void)device;
int status = HDF_SUCCESS;
- if ((deviceInfo->policy == SERVICE_POLICY_NONE) ||
- ((deviceInfo->svcName != NULL) && (strlen(deviceInfo->svcName) == 0))) {
- HDF_LOGI("policy is %d", SERVICE_POLICY_NONE);
+ struct IDeviceNode *nodeIf = NULL;
+ if (devNode->policy == SERVICE_POLICY_NONE ||
+ (devNode->servName != NULL && strlen(devNode->servName) == 0)) {
return status;
}
- struct IDeviceNode *nodeIf = &devNode->super;
- if ((deviceInfo->policy == SERVICE_POLICY_PUBLIC) ||
- (deviceInfo->policy == SERVICE_POLICY_CAPACITY)) {
+ nodeIf = &devNode->super;
+ if (devNode->policy == SERVICE_POLICY_PUBLIC || devNode->policy == SERVICE_POLICY_CAPACITY) {
if (nodeIf->PublishService != NULL) {
- status = nodeIf->PublishService(devNode, deviceInfo->svcName);
+ status = nodeIf->PublishService(devNode);
}
}
if (status == HDF_SUCCESS) {
- status = HdfDeviceNodePublishLocalService(devNode, deviceInfo);
+ status = HdfDeviceNodePublishLocalService(devNode);
}
return status;
}
-int HdfDeviceLaunchNode(struct HdfDeviceNode *devNode, struct IHdfDevice *devInst)
+int DeviveDriverBind(struct HdfDeviceNode *devNode)
{
- struct HdfDevice *device = (struct HdfDevice *)devInst;
- if (device == NULL || devNode == NULL) {
- HDF_LOGE("failed to launch service, device or service is null");
+ int ret;
+ const struct HdfDriverEntry *driverEntry = NULL;
+ if (devNode == NULL) {
return HDF_ERR_INVALID_PARAM;
}
- struct HdfDriverEntry *driverEntry = devNode->driverEntry;
- const struct HdfDeviceInfo *deviceInfo = devNode->deviceInfo;
- struct IHdfDeviceToken *deviceToken = NULL;
+ driverEntry = devNode->driver->entry;
+ if (devNode->policy == SERVICE_POLICY_PUBLIC || devNode->policy == SERVICE_POLICY_CAPACITY) {
+ if (driverEntry->Bind == NULL) {
+ HDF_LOGE("driver %s bind method not implement", driverEntry->moduleName);
+ devNode->devStatus = DEVNODE_NONE;
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ ret = driverEntry->Bind(&devNode->deviceObject);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("bind driver %s failed", driverEntry->moduleName);
+ return HDF_DEV_ERR_DEV_INIT_FAIL;
+ }
+ }
- if (deviceInfo == NULL) {
- HDF_LOGE("failed to launch service, deviceInfo is null");
+ return HDF_SUCCESS;
+}
+
+int HdfDeviceLaunchNode(struct HdfDeviceNode *devNode)
+{
+ const struct HdfDriverEntry *driverEntry = NULL;
+ int ret;
+ if (devNode == NULL) {
+ HDF_LOGE("failed to launch service, device or service is null");
return HDF_ERR_INVALID_PARAM;
}
- if ((driverEntry == NULL) || (driverEntry->Init == NULL)) {
+ HDF_LOGI("launch devnode %s", devNode->servName ? devNode->servName : "");
+ driverEntry = devNode->driver->entry;
+ if (driverEntry == NULL || driverEntry->Init == NULL) {
HDF_LOGE("failed to launch service, deviceEntry invalid");
return HDF_ERR_INVALID_PARAM;
}
- int ret = driverEntry->Init(&devNode->deviceObject);
+ devNode->devStatus = DEVNODE_LAUNCHED;
+
+ ret = DeviveDriverBind(devNode);
+ if (ret != HDF_SUCCESS) {
+ return ret;
+ }
+
+ ret = driverEntry->Init(&devNode->deviceObject);
if (ret != HDF_SUCCESS) {
return HDF_DEV_ERR_DEV_INIT_FAIL;
}
- ret = HdfDeviceNodePublishService(devNode, deviceInfo, devInst);
+
+ ret = HdfDeviceNodePublishService(devNode);
if (ret != HDF_SUCCESS) {
return HDF_DEV_ERR_PUBLISH_FAIL;
}
- deviceToken = devNode->token;
- ret = DevmgrServiceClntAttachDevice(deviceInfo, deviceToken);
+
+ ret = DevmgrServiceClntAttachDevice(devNode->token);
if (ret != HDF_SUCCESS) {
return HDF_DEV_ERR_ATTACHDEV_FAIL;
}
@@ -123,19 +147,63 @@ void HdfDeviceNodeRemovePowerStateListener(
devNode->powerToken = NULL;
}
-
-int HdfDeviceNodePublishPublicService(struct HdfDeviceNode *devNode, const char *svcName)
+int HdfDeviceNodePublishPublicService(struct HdfDeviceNode *devNode)
{
- if ((devNode == NULL) || (devNode->deviceObject.service == NULL)) {
- HDF_LOGE("failed to publish public service: devNode is NULL");
+ int ret;
+ if (devNode == NULL || devNode->deviceObject.service == NULL) {
+ HDF_LOGE("failed to publish public service, devNode is NULL");
return HDF_FAILURE;
}
- return DevSvcManagerClntAddService(svcName, &devNode->deviceObject);
+
+ ret = DevSvcManagerClntAddService(devNode->servName,
+ devNode->deviceObject.deviceClass, &devNode->deviceObject, devNode->servInfo);
+ if (ret == HDF_SUCCESS) {
+ devNode->servStatus = true;
+ }
+
+ return ret;
}
-void HdfDeviceNodeReclaimService(const char *svcName)
+int HdfDeviceNodeRemoveService(struct HdfDeviceNode *devNode)
{
- DevSvcManagerClntRemoveService(svcName);
+ if (devNode != NULL && devNode->servStatus) {
+ DevSvcManagerClntRemoveService(devNode->servName);
+ devNode->servStatus = false;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static void HdfDeviceUnlaunchNode(struct HdfDeviceNode *devNode)
+{
+ const struct HdfDriverEntry *driverEntry = NULL;
+ struct IDriverLoader *driverLoader = NULL;
+ if (devNode == NULL || devNode->devStatus != DEVNODE_LAUNCHED) {
+ return;
+ }
+
+ if (devNode->driver != NULL) {
+ driverEntry = devNode->driver->entry;
+ }
+
+ if (driverEntry != NULL && driverEntry->Release != NULL) {
+ driverEntry->Release(&devNode->deviceObject);
+ }
+
+ if (devNode->servStatus) {
+ devNode->super.RemoveService(devNode);
+ }
+ DevmgrServiceClntDetachDevice(devNode->devId);
+
+ // release driver object or close driver library
+ driverLoader = HdfDriverLoaderGetInstance();
+ if (driverLoader != NULL) {
+ driverLoader->ReclaimDriver(devNode->driver);
+ devNode->driver = NULL;
+ } else {
+ HDF_LOGE("failed to get driver loader");
+ }
+ devNode->devStatus = DEVNODE_INITED;
}
void HdfDeviceNodeConstruct(struct HdfDeviceNode *devNode)
@@ -146,6 +214,8 @@ void HdfDeviceNodeConstruct(struct HdfDeviceNode *devNode)
devNode->token = HdfDeviceTokenNewInstance();
nodeIf->LaunchNode = HdfDeviceLaunchNode;
nodeIf->PublishService = HdfDeviceNodePublishPublicService;
+ nodeIf->RemoveService = HdfDeviceNodeRemoveService;
+ nodeIf->UnlaunchNode = HdfDeviceUnlaunchNode;
}
}
@@ -154,31 +224,58 @@ void HdfDeviceNodeDestruct(struct HdfDeviceNode *devNode)
if (devNode == NULL) {
return;
}
- HdfDeviceTokenFreeInstance(devNode->token);
- devNode->token = NULL;
- PowerStateTokenFreeInstance(devNode->powerToken);
- devNode->powerToken = NULL;
-}
-
-struct HdfDeviceNode *HdfDeviceNodeNewInstance()
-{
- return (struct HdfDeviceNode *)HdfObjectManagerGetObject(HDF_OBJECT_ID_DEVICE_SERVICE);
-}
-
-void HdfDeviceNodeFreeInstance(struct HdfDeviceNode *devNode)
-{
- HdfObjectManagerFreeObject((struct HdfObject *) devNode);
+ HDF_LOGI("release devnode %s", devNode->servName);
+ switch (devNode->devStatus) {
+ case DEVNODE_LAUNCHED: // fall-through
+ HdfDeviceUnlaunchNode(devNode);
+ case DEVNODE_INITED:
+ HdfDeviceTokenFreeInstance(devNode->token);
+ devNode->token = NULL;
+ PowerStateTokenFreeInstance(devNode->powerToken);
+ devNode->powerToken = NULL;
+ OsalMemFree(devNode->servName);
+ OsalMemFree((char *)devNode->servInfo);
+ OsalMemFree(devNode->driverName);
+ devNode->servName = NULL;
+ devNode->servInfo = NULL;
+ break;
+ case DEVNODE_NONE:
+ break;
+ default:
+ break;
+ }
}
-void HdfDeviceNodeDelete(struct HdfDeviceNode *devNode)
+struct HdfDeviceNode *HdfDeviceNodeNewInstance(const struct HdfDeviceInfo *deviceInfo, struct HdfDriver *driver)
{
+ struct HdfDeviceNode *devNode = NULL;
+ if (deviceInfo == NULL) {
+ return NULL;
+ }
+ devNode = (struct HdfDeviceNode *)HdfObjectManagerGetObject(HDF_OBJECT_ID_DEVICE_SERVICE);
if (devNode == NULL) {
- return;
+ return NULL;
}
- if (devNode->driverEntry->Release != NULL) {
- devNode->driverEntry->Release(&devNode->deviceObject);
+ devNode->driver = driver;
+ devNode->devId = deviceInfo->deviceId;
+ devNode->permission = deviceInfo->permission;
+ devNode->policy = deviceInfo->policy;
+ devNode->token->devid = deviceInfo->deviceId;
+ devNode->servName = HdfStringCopy(deviceInfo->svcName);
+ if (devNode->servName == NULL) {
+ HdfDeviceNodeFreeInstance(devNode);
+ return NULL;
+ }
+ devNode->deviceObject.property = HcsGetNodeByMatchAttr(HdfGetHcsRootNode(), deviceInfo->deviceMatchAttr);
+ if (devNode->deviceObject.property == NULL) {
+ HDF_LOGD("node %s property empty, match attr: %s", deviceInfo->moduleName, deviceInfo->deviceMatchAttr);
}
- HdfDeviceNodeFreeInstance(devNode);
+ devNode->devStatus = DEVNODE_INITED;
+ return devNode;
}
+void HdfDeviceNodeFreeInstance(struct HdfDeviceNode *devNode)
+{
+ HdfObjectManagerFreeObject((struct HdfObject *)devNode);
+}
diff --git a/core/host/src/hdf_device_object.c b/core/host/src/hdf_device_object.c
index 832b11d8e9fb2e308f928e40d1cca6df3a5d9baa..a1f2d48533e035bc12dddd8e6bcfd9cc70587f81 100644
--- a/core/host/src/hdf_device_object.c
+++ b/core/host/src/hdf_device_object.c
@@ -7,86 +7,89 @@
*/
#include "hdf_device_object.h"
+#include "devhost_service.h"
+#include "devsvc_manager_clnt.h"
#include "hdf_base.h"
+#include "hdf_cstring.h"
#include "hdf_device_node.h"
+#include "hdf_driver_loader.h"
#include "hdf_log.h"
+#include "hdf_object_manager.h"
#include "hdf_observer_record.h"
+#include "hdf_power_manager.h"
#include "hdf_service_observer.h"
+#include "osal_mem.h"
#include "power_state_token.h"
#define HDF_LOG_TAG device_object
+#define SERVICE_INFO_LEN_MAX 128
+
int32_t HdfDeviceSubscribeService(
struct HdfDeviceObject *deviceObject, const char *serviceName, struct SubscriberCallback callback)
{
- uint32_t matchId;
struct DevHostService *hostService = NULL;
- const struct HdfDeviceInfo *deviceInfo = NULL;
+ struct HdfDeviceNode *devNode = NULL;
if (deviceObject == NULL || serviceName == NULL) {
- HDF_LOGE("failed to subscribe service, deviceObject/serviceName is null");
+ HDF_LOGE("failed to subscribe service, serviceName is null");
return HDF_FAILURE;
}
- struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
+ devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
hostService = devNode->hostService;
if (hostService == NULL) {
HDF_LOGE("failed to subscribe service, hostService is null");
return HDF_FAILURE;
}
- deviceInfo = devNode->deviceInfo;
- if (deviceInfo == NULL) {
- HDF_LOGE("failed to subscribe service, deviceInfo is null");
- return HDF_FAILURE;
- }
- matchId = HdfMakeHardwareId(deviceInfo->hostId, deviceInfo->deviceId);
- return HdfServiceObserverSubscribeService(&hostService->observer, serviceName, matchId, callback);
+
+ return HdfServiceObserverSubscribeService(&hostService->observer, serviceName, devNode->devId, callback);
}
const char *HdfDeviceGetServiceName(const struct HdfDeviceObject *deviceObject)
{
+ struct HdfDeviceNode *devNode = NULL;
if (deviceObject == NULL) {
HDF_LOGE("failed to get service name, deviceObject is invalid");
return NULL;
}
- struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
+ devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
- const struct HdfDeviceInfo *deviceInfo = devNode->deviceInfo;
- if (deviceInfo == NULL) {
- HDF_LOGE("failed to get service name, deviceInfo is null");
- return NULL;
- }
- return deviceInfo->svcName;
+ return devNode->servName;
}
int HdfPmRegisterPowerListener(struct HdfDeviceObject *deviceObject, const struct IPowerEventListener *listener)
{
+ struct HdfDeviceNode *devNode = NULL;
if (deviceObject == NULL) {
return HDF_ERR_INVALID_PARAM;
}
- struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
+ devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
return HdfDeviceNodeAddPowerStateListener(devNode, listener);
}
void HdfPmUnregisterPowerListener(struct HdfDeviceObject *deviceObject, const struct IPowerEventListener *listener)
{
+ struct HdfDeviceNode *devNode = NULL;
if (deviceObject == NULL) {
return;
}
- struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
+ devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
HdfDeviceNodeRemovePowerStateListener(devNode, listener);
}
void HdfPmAcquireDevice(struct HdfDeviceObject *deviceObject)
{
+ struct HdfDeviceNode *devNode = NULL;
+ struct IPowerStateToken *tokenIf = NULL;
if (deviceObject == NULL) {
HDF_LOGE("%s: input param is invalid", __func__);
return;
}
- struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
+ devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
- struct IPowerStateToken *tokenIf = (struct IPowerStateToken *)devNode->powerToken;
+ tokenIf = (struct IPowerStateToken *)devNode->powerToken;
if ((tokenIf != NULL) && (tokenIf->AcquireWakeLock != NULL)) {
tokenIf->AcquireWakeLock(tokenIf);
}
@@ -94,27 +97,59 @@ void HdfPmAcquireDevice(struct HdfDeviceObject *deviceObject)
void HdfPmReleaseDevice(struct HdfDeviceObject *deviceObject)
{
+ struct HdfDeviceNode *devNode = NULL;
+ struct IPowerStateToken *tokenIf = NULL;
if (deviceObject == NULL) {
HDF_LOGE("%s: input param is invalid", __func__);
return;
}
- struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
+ devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
- struct IPowerStateToken *tokenIf = (struct IPowerStateToken *)devNode->powerToken;
+ tokenIf = (struct IPowerStateToken *)devNode->powerToken;
if ((tokenIf != NULL) && (tokenIf->ReleaseWakeLock != NULL)) {
tokenIf->ReleaseWakeLock(tokenIf);
}
}
+void HdfPmAcquireDeviceAsync(struct HdfDeviceObject *deviceObject)
+{
+ struct HdfDeviceNode *devNode = NULL;
+
+ if (deviceObject == NULL) {
+ HDF_LOGE("%s: input param is invalid", __func__);
+ return;
+ }
+
+ devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
+ struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
+ HdfPmTaskPut(devNode->powerToken, HDF_PM_REQUEST_ACQUIRE);
+}
+
+void HdfPmReleaseDeviceAsync(struct HdfDeviceObject *deviceObject)
+{
+ struct HdfDeviceNode *devNode = NULL;
+
+ if (deviceObject == NULL) {
+ HDF_LOGE("%s: input param is invalid", __func__);
+ return;
+ }
+
+ devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
+ struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
+ HdfPmTaskPut(devNode->powerToken, HDF_PM_REQUEST_RELEASE);
+}
+
void HdfPmSetMode(struct HdfDeviceObject *deviceObject, uint32_t mode)
{
+ struct HdfDeviceNode *devNode = NULL;
+ struct PowerStateToken *token = NULL;
if (deviceObject == NULL || mode > HDF_POWER_MODE_MAX) {
HDF_LOGE("%s: input param is invalid", __func__);
return;
}
- struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
+ devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
- struct PowerStateToken *token = devNode->powerToken;
+ token = devNode->powerToken;
if (token != NULL) {
token->mode = mode;
}
@@ -122,8 +157,7 @@ void HdfPmSetMode(struct HdfDeviceObject *deviceObject, uint32_t mode)
bool HdfDeviceSetClass(struct HdfDeviceObject *deviceObject, DeviceClass deviceClass)
{
- if ((deviceObject == NULL) || (deviceClass >= DEVICE_CLASS_MAX) ||
- (deviceClass < DEVICE_CLASS_DEFAULT)) {
+ if ((deviceObject == NULL) || (deviceClass >= DEVICE_CLASS_MAX) || (deviceClass >= DEVICE_CLASS_MAX)) {
return false;
}
deviceObject->deviceClass = deviceClass;
@@ -138,3 +172,154 @@ void HdfDeviceObjectConstruct(struct HdfDeviceObject *deviceObject)
deviceObject->deviceClass = DEVICE_CLASS_DEFAULT;
}
}
+
+struct HdfDeviceObject *HdfDeviceObjectAlloc(struct HdfDeviceObject *parent, const char *driverName)
+{
+ struct HdfDeviceNode *newNode = NULL;
+ struct HdfDeviceNode *parentDevNode = CONTAINER_OF(parent, struct HdfDeviceNode, deviceObject);
+
+ if (parent == NULL) {
+ HDF_LOGE("failed to alloc device, parent invalid");
+ return NULL;
+ }
+
+ if (parentDevNode->devStatus != DEVNODE_LAUNCHED) {
+ HDF_LOGE("failed to alloc device, parent status invalid %u", parentDevNode->devStatus);
+ return NULL;
+ }
+
+ newNode = (struct HdfDeviceNode *)HdfObjectManagerGetObject(HDF_OBJECT_ID_DEVICE_SERVICE);
+ if (newNode == NULL) {
+ return NULL;
+ }
+ newNode->driverName = HdfStringCopy(driverName);
+ if (newNode->driverName == NULL) {
+ HdfDeviceNodeFreeInstance(newNode);
+ return NULL;
+ }
+
+ newNode->hostService = parentDevNode->hostService;
+ newNode->device = parentDevNode->device;
+
+ return &newNode->deviceObject;
+}
+
+void HdfDeviceObjectRelease(struct HdfDeviceObject *dev)
+{
+ struct HdfDeviceNode *devNode = CONTAINER_OF(dev, struct HdfDeviceNode, deviceObject);
+ if (dev == NULL) {
+ return;
+ }
+
+ if (devNode->device != NULL && devNode->device->super.Detach != NULL) {
+ devNode->device->super.Detach(&devNode->device->super, devNode);
+ }
+ HdfDeviceNodeFreeInstance(devNode);
+}
+
+int HdfDeviceObjectRegister(struct HdfDeviceObject *dev)
+{
+ int ret = HDF_FAILURE;
+ struct HdfDeviceNode *devNode = CONTAINER_OF(dev, struct HdfDeviceNode, deviceObject);
+ struct IDriverLoader *driverLoader = HdfDriverLoaderGetInstance();
+
+ if (dev == NULL || devNode->driverName == NULL || devNode->device == NULL || driverLoader == NULL ||
+ driverLoader->GetDriver == NULL) {
+ HDF_LOGE("failed to add device, param invalid");
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ devNode->driver = driverLoader->GetDriver(devNode->driverName);
+ if (devNode->driver == NULL) {
+ HDF_LOGE("can not found driver %s", devNode->driverName);
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+
+ ret = devNode->device->super.Attach(&devNode->device->super, devNode);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("faild to attach device %s", devNode->driverName);
+ return HDF_DEV_ERR_ATTACHDEV_FAIL;
+ }
+
+ return ret;
+}
+
+int HdfDeviceObjectUnRegister(struct HdfDeviceObject *dev)
+{
+ struct HdfDeviceNode *devNode = CONTAINER_OF(dev, struct HdfDeviceNode, deviceObject);
+ if (devNode == NULL || devNode->device == NULL) {
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ return devNode->device->super.Detach(&devNode->device->super, devNode);
+}
+
+int HdfDeviceObjectPublishService(struct HdfDeviceObject *dev, const char *servName, uint8_t policy, uint32_t perm)
+{
+ int ret;
+ struct HdfDeviceNode *devNode = CONTAINER_OF(dev, struct HdfDeviceNode, deviceObject);
+ if (dev == NULL || servName == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ if (policy <= SERVICE_POLICY_NONE || policy >= SERVICE_POLICY_INVALID) {
+ return HDF_DEV_ERR_NO_DEVICE_SERVICE;
+ }
+
+ if (devNode->servStatus) {
+ HDF_LOGE("failed to publish public service, repeat publish");
+ return HDF_FAILURE;
+ }
+
+ devNode->servName = HdfStringCopy(servName);
+ if (devNode->servName == NULL) {
+ return HDF_DEV_ERR_NO_MEMORY;
+ }
+
+ devNode->policy = policy;
+ devNode->permission = perm;
+
+ ret = DeviveDriverBind(devNode);
+ if (ret != HDF_SUCCESS) {
+ return ret;
+ }
+
+ return devNode->super.PublishService(devNode);
+}
+
+int HdfDeviceObjectRemoveService(struct HdfDeviceObject *dev)
+{
+ struct HdfDeviceNode *devNode = CONTAINER_OF(dev, struct HdfDeviceNode, deviceObject);
+ if (dev == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ return devNode->super.RemoveService(devNode);
+}
+int HdfDeviceObjectSetServInfo(struct HdfDeviceObject *dev, const char *info)
+{
+ if (dev == NULL || info == NULL || strlen(info) > SERVICE_INFO_LEN_MAX) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ struct HdfDeviceNode *devNode = CONTAINER_OF(dev, struct HdfDeviceNode, deviceObject);
+ if (devNode->servInfo != NULL) {
+ OsalMemFree((char *)devNode->servInfo);
+ }
+ devNode->servInfo = HdfStringCopy(info);
+ if (devNode->servInfo == NULL) {
+ return HDF_ERR_MALLOC_FAIL;
+ }
+ return HDF_SUCCESS;
+}
+
+int HdfDeviceObjectUpdate(struct HdfDeviceObject *dev)
+{
+ struct HdfDeviceNode *devNode = CONTAINER_OF(dev, struct HdfDeviceNode, deviceObject);
+ if (dev == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ return DevSvcManagerClntUpdateService(
+ devNode->servName, devNode->deviceObject.deviceClass, &devNode->deviceObject, devNode->servInfo);
+}
diff --git a/core/host/src/hdf_driver_loader.c b/core/host/src/hdf_driver_loader.c
index 98cfbee6ced8669aa349eba5d482588d8f7d9e0e..9ce739227855393c85d2355346b36ffd034a6b63 100755
--- a/core/host/src/hdf_driver_loader.c
+++ b/core/host/src/hdf_driver_loader.c
@@ -7,92 +7,56 @@
*/
#include "hdf_driver_loader.h"
-#include "devsvc_manager_clnt.h"
-#include "hcs_tree_if.h"
-#include "hdf_device_desc.h"
-#include "hdf_device_node.h"
+#include "hdf_driver.h"
#include "hdf_log.h"
#include "hdf_object_manager.h"
-#include "hdf_attribute_manager.h"
#define HDF_LOG_TAG driver_loader
-struct HdfDeviceNode *HdfDriverLoaderLoadNode(
- struct IDriverLoader *loader, const struct HdfDeviceInfo *deviceInfo)
+int32_t HdfDriverEntryConstruct()
{
+ int i;
struct HdfDriverEntry *driverEntry = NULL;
- struct HdfDeviceNode *devNode = NULL;
- if ((loader == NULL) || (loader->GetDriverEntry == NULL)) {
- HDF_LOGE("failed to load node, loader is invalid");
- return NULL;
+ size_t *addrBegin = NULL;
+ int32_t count = (int32_t)(((uint8_t *)(HDF_DRIVER_END()) - (uint8_t *)(HDF_DRIVER_BEGIN())) / sizeof(size_t));
+ if (count <= 0) {
+ HDF_LOGE("%s: no hdf driver exist", __func__);
+ return HDF_FAILURE;
}
- driverEntry = loader->GetDriverEntry(deviceInfo);
- if (driverEntry == NULL) {
- HDF_LOGE("failed to load node, deviceEntry is null");
- return NULL;
+ addrBegin = (size_t *)(HDF_DRIVER_BEGIN());
+ for (i = 0; i < count; i++) {
+ driverEntry = (struct HdfDriverEntry *)(*addrBegin);
+ if (HdfRegisterDriverEntry(driverEntry) != HDF_SUCCESS) {
+ HDF_LOGE("failed to register driver %s, skip and try another", driverEntry ? driverEntry->moduleName : "");
+ continue;
+ }
+ addrBegin++;
}
+ return HDF_SUCCESS;
+}
- devNode = HdfDeviceNodeNewInstance();
- if (devNode == NULL) {
- HDF_LOGE("failed to load node, device node is null");
+struct HdfDriver *HdfDriverLoaderGetDriver(const char *moduleName)
+{
+ if (moduleName == NULL) {
+ HDF_LOGE("%s: failed to get device entry, moduleName is NULL", __func__);
return NULL;
}
- devNode->driverEntry = driverEntry;
- devNode->deviceInfo = deviceInfo;
- devNode->deviceObject.property = HcsGetNodeByMatchAttr(HdfGetRootNode(), deviceInfo->deviceMatchAttr);
- devNode->deviceObject.priv = (void *)(deviceInfo->private);
- if (devNode->deviceObject.property == NULL) {
- HDF_LOGW("failed to load node, property is null, match attr is: %s", deviceInfo->deviceMatchAttr);
- }
-
- if ((deviceInfo->policy == SERVICE_POLICY_PUBLIC) || (deviceInfo->policy == SERVICE_POLICY_CAPACITY)) {
- if (driverEntry->Bind == NULL) {
- HDF_LOGE("driver bind method is null");
- HdfDeviceNodeFreeInstance(devNode);
- return NULL;
- }
- if (driverEntry->Bind(&devNode->deviceObject) != 0) {
- HDF_LOGE("bind driver failed");
- HdfDeviceNodeFreeInstance(devNode);
- return NULL;
- }
- }
- return devNode;
+ return HdfDriverManagerGetDriver(moduleName);
}
-void HdfDriverLoaderUnLoadNode(struct IDriverLoader *loader, const struct HdfDeviceInfo *deviceInfo)
+void HdfDriverLoaderReclaimDriver(struct HdfDriver *driver)
{
- struct HdfDriverEntry *driverEntry = NULL;
- struct HdfDeviceObject *deviceObject = NULL;
- if ((loader == NULL) || (loader->GetDriverEntry == NULL)) {
- HDF_LOGE("failed to unload service, loader invalid");
- return;
- }
-
- driverEntry = loader->GetDriverEntry(deviceInfo);
- if (driverEntry == NULL) {
- HDF_LOGE("failed to unload service, driverEntry is null");
- return;
- }
- if (driverEntry->Release == NULL) {
- HDF_LOGI("device release func is null");
- return;
- }
- deviceObject = DevSvcManagerClntGetDeviceObject(deviceInfo->svcName);
- if (deviceObject != NULL) {
- driverEntry->Release(deviceObject);
- }
+ // kernel driver do not need release
+ (void)driver;
}
void HdfDriverLoaderConstruct(struct HdfDriverLoader *inst)
{
if (inst != NULL) {
- struct IDriverLoader *driverLoaderIf = (struct IDriverLoader *)inst;
- driverLoaderIf->LoadNode = HdfDriverLoaderLoadNode;
- driverLoaderIf->UnLoadNode = HdfDriverLoaderUnLoadNode;
- driverLoaderIf->GetDriverEntry = HdfDriverLoaderGetDriverEntry;
+ inst->super.GetDriver = HdfDriverLoaderGetDriver;
+ inst->super.ReclaimDriver = HdfDriverLoaderReclaimDriver;
}
}
@@ -101,6 +65,9 @@ struct HdfObject *HdfDriverLoaderCreate()
static bool isDriverLoaderInit = false;
static struct HdfDriverLoader driverLoader;
if (!isDriverLoaderInit) {
+ if (HdfDriverEntryConstruct() != HDF_SUCCESS) {
+ return NULL;
+ }
HdfDriverLoaderConstruct(&driverLoader);
isDriverLoaderInit = true;
}
@@ -115,4 +82,3 @@ struct IDriverLoader *HdfDriverLoaderGetInstance()
}
return instance;
}
-
diff --git a/core/host/src/hdf_observer_record.c b/core/host/src/hdf_observer_record.c
index 645d7d54eea0bbd103f29464e079e7b2b15cd13a..e30e7b531c85aa573da0e50171e58e6373b3da4c 100644
--- a/core/host/src/hdf_observer_record.c
+++ b/core/host/src/hdf_observer_record.c
@@ -14,11 +14,6 @@
#define HDF_LOG_TAG observer_record
#define HALF_INT_LEN 16
-uint32_t HdfMakeHardwareId(uint16_t hostId, uint16_t deviceId)
-{
- return ((uint32_t)hostId << HALF_INT_LEN) | deviceId;
-}
-
struct HdfServiceObserverRecord *HdfServiceObserverRecordObtain(uint32_t serviceKey)
{
struct HdfServiceObserverRecord *observerRecord =
@@ -47,10 +42,11 @@ void HdfServiceObserverRecordRecycle(struct HdfServiceObserverRecord *observerRe
bool HdfServiceObserverRecordCompare(struct HdfSListNode *listEntry, uint32_t serviceKey)
{
+ struct HdfServiceObserverRecord *record = NULL;
if (listEntry == NULL) {
return false;
}
- struct HdfServiceObserverRecord *record = (struct HdfServiceObserverRecord *)listEntry;
+ record = (struct HdfServiceObserverRecord *)listEntry;
if (record->serviceKey == serviceKey) {
return true;
}
@@ -58,7 +54,7 @@ bool HdfServiceObserverRecordCompare(struct HdfSListNode *listEntry, uint32_t se
}
void HdfServiceObserverRecordNotifySubscribers(
- struct HdfServiceObserverRecord *record, uint32_t matchId, uint16_t policy)
+ struct HdfServiceObserverRecord *record, uint32_t devId, uint16_t policy)
{
struct HdfSListIterator it;
if (record == NULL) {
@@ -71,7 +67,7 @@ void HdfServiceObserverRecordNotifySubscribers(
while (HdfSListIteratorHasNext(&it)) {
struct HdfServiceSubscriber *subscriber =
(struct HdfServiceSubscriber *)HdfSListIteratorNext(&it);
- if ((matchId == subscriber->matchId) || (policy != SERVICE_POLICY_PRIVATE)) {
+ if (devId == subscriber->devId || policy != SERVICE_POLICY_PRIVATE) {
subscriber->state = HDF_SUBSCRIBER_STATE_READY;
if (subscriber->callback.OnServiceConnected != NULL) {
subscriber->callback.OnServiceConnected(subscriber->callback.deviceObject, record->publisher);
diff --git a/core/host/src/hdf_power_manager.c b/core/host/src/hdf_power_manager.c
new file mode 100755
index 0000000000000000000000000000000000000000..a7f50fd922f6d94725927c6ba882871bd707d0a2
--- /dev/null
+++ b/core/host/src/hdf_power_manager.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 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 "hdf_power_manager.h"
+#include "hdf_log.h"
+#include "hdf_pm_reg.h"
+#include "osal_mem.h"
+#include "power_state_token.h"
+
+#define HDF_LOG_TAG hdf_power_manager
+
+struct PmTaskQueue {
+ struct HdfTaskQueue *taskQueue;
+};
+
+static struct PmTaskQueue *HdfPmTaskQueueInstance()
+{
+ static struct PmTaskQueue pmTaskQueue = {NULL};
+ return &pmTaskQueue;
+}
+
+struct PmTaskQueue *HdfPmTaskQueueInit(HdfTaskFunc func)
+{
+ struct PmTaskQueue *pmTaskQueue = HdfPmTaskQueueInstance();
+
+ if (pmTaskQueue->taskQueue == NULL) {
+ pmTaskQueue->taskQueue = HdfTaskQueueCreate(func, "pm_queue");
+ if (pmTaskQueue->taskQueue != NULL) {
+ HDF_LOGI("%s HdfTaskQueueCreate success", __func__);
+ }
+ }
+
+ return pmTaskQueue;
+}
+
+void HdfPmTaskQueueDestroy(void)
+{
+ struct PmTaskQueue *pmTaskQueue = HdfPmTaskQueueInstance();
+ HdfTaskQueueDestroy(pmTaskQueue->taskQueue);
+ pmTaskQueue->taskQueue = NULL;
+}
+
+static int32_t PmTaskFunc(struct HdfTaskType *para)
+{
+ struct HdfPmRequest *pmRequest = NULL;
+ struct IPowerStateToken *tokenIf = NULL;
+
+ if (para == NULL) {
+ return HDF_FAILURE;
+ }
+
+ pmRequest = CONTAINER_OF(para, struct HdfPmRequest, task);
+ tokenIf = (struct IPowerStateToken *)pmRequest->token;
+ if (pmRequest->pmType == HDF_PM_REQUEST_ACQUIRE) {
+ if ((tokenIf != NULL) && (tokenIf->AcquireWakeLock != NULL)) {
+ tokenIf->AcquireWakeLock(tokenIf);
+ }
+ } else if (pmRequest->pmType == HDF_PM_REQUEST_RELEASE) {
+ if ((tokenIf != NULL) && (tokenIf->ReleaseWakeLock != NULL)) {
+ tokenIf->ReleaseWakeLock(tokenIf);
+ }
+ }
+ OsalMemFree(pmRequest);
+ return HDF_SUCCESS;
+}
+
+void HdfPmTaskPut(struct PowerStateToken *powerToken, HDF_PM_REQUEST_TYPE type)
+{
+ struct HdfPmRequest *pmRequest = NULL;
+ struct PmTaskQueue *pmTaskQueue = NULL;
+
+ if (powerToken == NULL) {
+ return;
+ }
+
+ pmTaskQueue = HdfPmTaskQueueInstance();
+ pmRequest = (struct HdfPmRequest *)OsalMemCalloc(sizeof(*pmRequest));
+ if (pmRequest == NULL) {
+ HDF_LOGI("%s OsalMemCalloc fail", __func__);
+ return;
+ }
+
+ pmRequest->token = powerToken;
+ pmRequest->pmType = type;
+ pmRequest->task.func = PmTaskFunc;
+ HdfTaskEnqueue(pmTaskQueue->taskQueue, &pmRequest->task);
+}
+
+int32_t HdfPowerManagerInit(void)
+{
+ DevMgrPmRegister();
+ HdfPmTaskQueueInit(NULL);
+ return HDF_SUCCESS;
+}
+
+void HdfPowerManagerExit(void)
+{
+ HdfPmTaskQueueDestroy();
+}
\ No newline at end of file
diff --git a/core/host/src/hdf_service_observer.c b/core/host/src/hdf_service_observer.c
index 29aa1555caac16ca9725e77800012546b8c969c7..ed79a96498f733f42641fb52e2cc95cfd34a9d06 100644
--- a/core/host/src/hdf_service_observer.c
+++ b/core/host/src/hdf_service_observer.c
@@ -36,7 +36,7 @@ void HdfServiceObserverDestruct(struct HdfServiceObserver *observer)
}
int HdfServiceObserverSubscribeService(struct HdfServiceObserver *observer,
- const char *svcName, uint32_t matchId, struct SubscriberCallback callback)
+ const char *svcName, devid_t devid, struct SubscriberCallback callback)
{
struct HdfServiceObserverRecord *serviceRecord = NULL;
struct HdfServiceSubscriber *subscriber = NULL;
@@ -53,7 +53,7 @@ int HdfServiceObserverSubscribeService(struct HdfServiceObserver *observer,
HDF_LOGE("failed to subscribe service, serviceRecord is null");
return HDF_FAILURE;
}
- subscriber = HdfServiceSubscriberObtain(callback, matchId);
+ subscriber = HdfServiceSubscriberObtain(callback, devid);
if (subscriber == NULL) {
HDF_LOGE("failed to subscribe service, subscriber is null");
HdfServiceObserverRecordRecycle(serviceRecord);
@@ -63,7 +63,7 @@ int HdfServiceObserverSubscribeService(struct HdfServiceObserver *observer,
HdfSListAdd(&observer->services, &serviceRecord->entry);
OsalMutexUnlock(&observer->observerMutex);
} else {
- subscriber = HdfServiceSubscriberObtain(callback, matchId);
+ subscriber = HdfServiceSubscriberObtain(callback, devid);
if (subscriber == NULL) {
HDF_LOGE("failed to subscribe service, subscriber obtain null");
return HDF_FAILURE;
@@ -72,7 +72,7 @@ int HdfServiceObserverSubscribeService(struct HdfServiceObserver *observer,
if ((serviceRecord->publisher != NULL) &&
(subscriber->callback.OnServiceConnected != NULL) &&
((serviceRecord->policy != SERVICE_POLICY_PRIVATE) ||
- (serviceRecord->matchId == matchId))) {
+ (serviceRecord->devId == devid))) {
subscriber->state = HDF_SUBSCRIBER_STATE_READY;
subscriber->callback.OnServiceConnected(subscriber->callback.deviceObject, serviceRecord->publisher);
}
@@ -83,7 +83,7 @@ int HdfServiceObserverSubscribeService(struct HdfServiceObserver *observer,
}
int HdfServiceObserverPublishService(struct HdfServiceObserver *observer,
- const char *svcName, uint32_t matchId, uint16_t policy, struct HdfObject *service)
+ const char *svcName, uint32_t devId, uint16_t policy, struct HdfObject *service)
{
struct HdfServiceObserverRecord *serviceRecord = NULL;
uint32_t serviceKey = HdfStringMakeHashKey(svcName, 0);
@@ -100,14 +100,14 @@ int HdfServiceObserverPublishService(struct HdfServiceObserver *observer,
return HDF_FAILURE;
}
serviceRecord->publisher = service;
- serviceRecord->matchId = matchId;
+ serviceRecord->devId = devId;
serviceRecord->policy = policy;
OsalMutexLock(&observer->observerMutex);
HdfSListAdd(&observer->services, &serviceRecord->entry);
OsalMutexUnlock(&observer->observerMutex);
} else {
serviceRecord->publisher = service;
- HdfServiceObserverRecordNotifySubscribers(serviceRecord, matchId, policy);
+ HdfServiceObserverRecordNotifySubscribers(serviceRecord, devId, policy);
}
return HDF_SUCCESS;
}
diff --git a/core/host/src/hdf_service_subscriber.c b/core/host/src/hdf_service_subscriber.c
index efcec2f4fc170a09b03684cf88285d6213c06ef4..6aa3ffd2a9a0731cea6079993778ed95f18338b4 100644
--- a/core/host/src/hdf_service_subscriber.c
+++ b/core/host/src/hdf_service_subscriber.c
@@ -7,15 +7,16 @@
*/
#include "hdf_service_subscriber.h"
+#include "hdf_device.h"
#include "osal_mem.h"
-struct HdfServiceSubscriber *HdfServiceSubscriberObtain(struct SubscriberCallback callback, uint32_t matchId)
+struct HdfServiceSubscriber *HdfServiceSubscriberObtain(struct SubscriberCallback callback, devid_t devid)
{
struct HdfServiceSubscriber *serviceSubscriber =
(struct HdfServiceSubscriber *)OsalMemCalloc(sizeof(struct HdfServiceSubscriber));
if (serviceSubscriber != NULL) {
serviceSubscriber->state = HDF_SUBSCRIBER_STATE_PENDING;
- serviceSubscriber->matchId = matchId;
+ serviceSubscriber->devId = devid;
serviceSubscriber->callback = callback;
}
return serviceSubscriber;
diff --git a/core/host/src/power_state_token.c b/core/host/src/power_state_token.c
index f32c21354c7e1ab6939ede7757181575aaaaf319..f4abe072683aa86f776894c5f35acecc9edbaf12 100644
--- a/core/host/src/power_state_token.c
+++ b/core/host/src/power_state_token.c
@@ -15,10 +15,11 @@
static void PowerStateTokenOnFirstAcquire(struct HdfSRef *sref)
{
+ struct PowerStateToken *stateToken = NULL;
if (sref == NULL) {
return;
}
- struct PowerStateToken *stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF(
+ stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF(
struct HdfSRef, sref, struct PowerStateToken, wakeRef);
if (stateToken->psmState == PSM_STATE_ACTIVE) {
@@ -36,17 +37,19 @@ static void PowerStateTokenOnFirstAcquire(struct HdfSRef *sref)
static void PowerStateTokenOnLastRelease(struct HdfSRef *sref)
{
+ struct PowerStateToken *stateToken = NULL;
+ const struct IPowerEventListener *listener = NULL;
if (sref == NULL) {
return;
}
- struct PowerStateToken *stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF(
+ stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF(
struct HdfSRef, sref, struct PowerStateToken, wakeRef);
if (stateToken->psmState != PSM_STATE_ACTIVE && stateToken->psmState != PSM_STATE_IDLE) {
return;
}
- const struct IPowerEventListener *listener = stateToken->listener;
+ listener = stateToken->listener;
if ((listener != NULL) && (listener->Suspend != NULL)) {
listener->Suspend(stateToken->deviceObject);
}
diff --git a/core/manager/include/devhost_service_clnt.h b/core/manager/include/devhost_service_clnt.h
index cbc34d64a598a72e3d30023370749f95b87ca803..44d664ba332333cc9c57c8975e3bc2b0ea2db216 100644
--- a/core/manager/include/devhost_service_clnt.h
+++ b/core/manager/include/devhost_service_clnt.h
@@ -16,7 +16,8 @@
struct DevHostServiceClnt {
struct DListHead node;
struct HdfSList devices;
- struct HdfSList *deviceInfos;
+ struct HdfSList unloadDevInfos;
+ struct HdfSList dynamicDevInfos;
Map *deviceHashMap;
struct IDevHostService *hostService;
uint16_t devCount;
diff --git a/core/manager/include/devmgr_service.h b/core/manager/include/devmgr_service.h
index 56f0e02cc63870819c9b75f9d5c68b7fda9e8727..d45bac619b822f5b22a031424530dbe0f4b0730d 100644
--- a/core/manager/include/devmgr_service.h
+++ b/core/manager/include/devmgr_service.h
@@ -24,8 +24,6 @@ bool DevmgrServiceConstruct(struct DevmgrService *inst);
struct HdfObject *DevmgrServiceCreate(void);
void DevmgrServiceRelease(struct HdfObject *object);
struct IDevmgrService *DevmgrServiceGetInstance(void);
-int DevmgrServiceLoadDevice(const char *svcName);
-int DevmgrServiceUnLoadDevice(const char *svcName);
int32_t DevmgrServiceLoadLeftDriver(struct DevmgrService *devMgrSvc);
#endif /* DEVICE_MANAGER_SERVICE_H */
diff --git a/core/manager/include/devsvc_listener_holder.h b/core/manager/include/devsvc_listener_holder.h
new file mode 100644
index 0000000000000000000000000000000000000000..b39f20895188acb9f5a5d13117a5e46ad57c6bfd
--- /dev/null
+++ b/core/manager/include/devsvc_listener_holder.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef DEVICE_SERVICE_LISTENER_HOLDER_H
+#define DEVICE_SERVICE_LISTENER_HOLDER_H
+
+#include "hdf_service_status.h"
+#include "hdf_dlist.h"
+
+struct ServStatListenerHolder {
+ uint16_t listenClass;
+ struct DListHead node;
+ uint64_t index;
+ void (*NotifyStatus)(struct ServStatListenerHolder *holder, struct ServiceStatus *status);
+};
+
+void ServStatListenerHolderinit(void);
+
+struct ServStatListenerHolder *ServStatListenerHolderCreate(uintptr_t listener, uint16_t listenClass);
+void ServStatListenerHolderRelease(struct ServStatListenerHolder *holder);
+struct ServStatListenerHolder *ServStatListenerHolderGet(uint64_t index);
+
+#endif /* DEVICE_SERVICE_LISTENER_HOLDER_H */
diff --git a/core/manager/include/devsvc_manager.h b/core/manager/include/devsvc_manager.h
index b73731bccef9917257cad7d80d8ece11132e18ef..a1bf6d0cd6a40ecd2388964dc0aabd315216ca18 100644
--- a/core/manager/include/devsvc_manager.h
+++ b/core/manager/include/devsvc_manager.h
@@ -11,23 +11,29 @@
#include "devsvc_manager_if.h"
#include "hdf_service_observer.h"
-#include "hdf_slist.h"
+#include "hdf_dlist.h"
#include "osal_mutex.h"
struct DevSvcManager {
struct IDevSvcManager super;
- struct HdfSList services;
+ struct DListHead services;
struct HdfServiceObserver observer;
+ struct DListHead svcstatListeners;
struct OsalMutex mutex;
};
struct HdfObject *DevSvcManagerCreate(void);
bool DevSvcManagerConstruct(struct DevSvcManager *inst);
-void DevSvcManagerRelease(struct HdfObject *object);
+void DevSvcManagerRelease(struct IDevSvcManager *inst);
struct IDevSvcManager *DevSvcManagerGetInstance(void);
-int DevSvcManagerAddService(struct IDevSvcManager *manager, const char *svcName, struct HdfDeviceObject *service);
+
+int DevSvcManagerStartService(void);
+
+int DevSvcManagerAddService(struct IDevSvcManager *manager, const char *svcName,
+ uint16_t devClass, struct HdfDeviceObject *service, const char *servInfo);
struct HdfObject *DevSvcManagerGetService(struct IDevSvcManager *manager, const char *svcName);
void DevSvcManagerRemoveService(struct IDevSvcManager *manager, const char *svcName);
+void DevSvcManagerListService(struct HdfSBuf *serviecNameSet, DeviceClass deviceClass);
int DevSvcManagerClntSubscribeService(const char *svcName, struct SubscriberCallback callback);
int DevSvcManagerClntUnsubscribeService(const char *svcName);
diff --git a/core/manager/include/devsvc_manager_ext.h b/core/manager/include/devsvc_manager_ext.h
new file mode 100644
index 0000000000000000000000000000000000000000..262b9e50494dc7542b2cfcb28285d8de8f241345
--- /dev/null
+++ b/core/manager/include/devsvc_manager_ext.h
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef DEVICE_SERVICE_MANAGER_EXT_H
+#define DEVICE_SERVICE_MANAGER_EXT_H
+
+struct HdfObject *DevSvcManagerExtCreate(void);
+void DevSvcManagerExtRelease(struct HdfObject *object);
+
+#endif // DEVICE_SERVICE_MANAGER_EXT_H
\ No newline at end of file
diff --git a/core/manager/src/devhost_service_clnt.c b/core/manager/src/devhost_service_clnt.c
index 43b4f1ca901cdcdfa56b3a1e10f6c554954cd04a..cebd88d4a970687dbe2c6c92c8e7eacc3497416a 100644
--- a/core/manager/src/devhost_service_clnt.c
+++ b/core/manager/src/devhost_service_clnt.c
@@ -32,20 +32,26 @@ int DevHostServiceClntInstallDriver(struct DevHostServiceClnt *hostClnt)
HDF_LOGE("devHostSvcIf or devHostSvcIf->AddDevice is null");
return HDF_FAILURE;
}
- HdfSListIteratorInit(&it, hostClnt->deviceInfos);
+ HdfSListIteratorInit(&it, &hostClnt->unloadDevInfos);
while (HdfSListIteratorHasNext(&it)) {
deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&it);
if ((deviceInfo == NULL) || (deviceInfo->preload == DEVICE_PRELOAD_DISABLE)) {
continue;
}
- if ((DeviceManagerIsQuickLoad() == DEV_MGR_QUICK_LOAD) &&
- (deviceInfo->preload == DEVICE_PRELOAD_ENABLE_STEP2)) {
+ /*
+ * If quick start feature enable, the device which 'preload' attribute set as
+ * DEVICE_PRELOAD_ENABLE_STEP2 will be loaded later
+ */
+ if (DeviceManagerIsQuickLoad() == DEV_MGR_QUICK_LOAD &&
+ deviceInfo->preload == DEVICE_PRELOAD_ENABLE_STEP2) {
continue;
}
ret = devHostSvcIf->AddDevice(devHostSvcIf, deviceInfo);
if (ret != HDF_SUCCESS) {
HDF_LOGE("failed to install driver %s, ret = %d", deviceInfo->svcName, ret);
+ continue;
}
+ HdfSListIteratorRemove(&it);
}
return HDF_SUCCESS;
}
@@ -69,6 +75,7 @@ struct DevHostServiceClnt *DevHostServiceClntNewInstance(uint16_t hostId, const
hostClnt->hostId = hostId;
hostClnt->hostName = hostName;
hostClnt->devCount = 0;
+ hostClnt->hostPid = -1;
DevHostServiceClntConstruct(hostClnt);
}
return hostClnt;
@@ -78,7 +85,8 @@ void DevHostServiceClntFreeInstance(struct DevHostServiceClnt *hostClnt)
{
if (hostClnt != NULL) {
HdfSListFlush(&hostClnt->devices, DeviceTokenClntDelete);
- HdfSListFlush(hostClnt->deviceInfos, HdfDeviceInfoDelete);
+ HdfSListFlush(&hostClnt->unloadDevInfos, HdfDeviceInfoDelete);
+ HdfSListFlush(&hostClnt->dynamicDevInfos, HdfDeviceInfoDelete);
OsalMemFree(hostClnt->deviceHashMap);
OsalMemFree(hostClnt);
}
diff --git a/core/manager/src/devmgr_service.c b/core/manager/src/devmgr_service.c
index 36886a9319183985a40a2f640c55153e880872bb..b8b6897a85bf816115ef6079e685d0bdd8dd8193 100644
--- a/core/manager/src/devmgr_service.c
+++ b/core/manager/src/devmgr_service.c
@@ -9,59 +9,123 @@
#include "devmgr_service.h"
#include "devhost_service_clnt.h"
#include "device_token_clnt.h"
+#include "devsvc_manager.h"
#include "hdf_attribute_manager.h"
#include "hdf_base.h"
#include "hdf_driver_installer.h"
#include "hdf_host_info.h"
#include "hdf_log.h"
#include "hdf_object_manager.h"
+#include "osal_time.h"
#define HDF_LOG_TAG devmgr_service
-static int DevmgrServiceActiveDevice(struct DevHostServiceClnt *hostClnt,
- struct HdfDeviceInfo *deviceInfo, bool isLoad)
+static bool DevmgrServiceDynamicDevInfoFound(const char *svcName, struct DevHostServiceClnt **targetHostClnt,
+ struct HdfDeviceInfo **targetDeviceInfo)
{
- struct IDevHostService *devHostSvcIf = (struct IDevHostService *)hostClnt->hostService;
- if (devHostSvcIf == NULL) {
- return HDF_FAILURE;
+ struct HdfSListIterator itDeviceInfo;
+ struct HdfDeviceInfo *deviceInfo = NULL;
+ struct DevHostServiceClnt *hostClnt = NULL;
+ struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
+ if (devMgrSvc == NULL) {
+ return false;
}
- if (isLoad && (deviceInfo->preload != DEVICE_PRELOAD_ENABLE)) {
- int ret = devHostSvcIf->AddDevice(devHostSvcIf, deviceInfo);
- if (ret == HDF_SUCCESS) {
- deviceInfo->preload = DEVICE_PRELOAD_ENABLE;
+ DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) {
+ HdfSListIteratorInit(&itDeviceInfo, &hostClnt->dynamicDevInfos);
+ while (HdfSListIteratorHasNext(&itDeviceInfo)) {
+ deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo);
+ if (strcmp(deviceInfo->svcName, svcName) == 0) {
+ *targetDeviceInfo = deviceInfo;
+ *targetHostClnt = hostClnt;
+ return true;
+ }
}
- return ret;
- } else if (!isLoad && (deviceInfo->preload != DEVICE_PRELOAD_DISABLE)) {
- devHostSvcIf->DelDevice(devHostSvcIf, deviceInfo);
- deviceInfo->preload = DEVICE_PRELOAD_DISABLE;
+ }
+
+ return false;
+}
+
+#define WAIT_HOST_SLEEP_TIME 1 // ms
+#define WAIT_HOST_SLEEP_CNT 100
+static int DevmgrServiceStartHostProcess(struct DevHostServiceClnt *hostClnt, bool sync)
+{
+ int waitCount = WAIT_HOST_SLEEP_CNT;
+ struct IDriverInstaller *installer = DriverInstallerGetInstance();
+ if (installer == NULL || installer->StartDeviceHost == NULL) {
+ HDF_LOGE("invalid installer");
+ return HDF_FAILURE;
+ }
+
+ hostClnt->hostPid = installer->StartDeviceHost(hostClnt->hostId, hostClnt->hostName);
+ if (hostClnt->hostPid == HDF_FAILURE) {
+ HDF_LOGW("failed to start device host(%s, %u)", hostClnt->hostName, hostClnt->hostId);
+ return HDF_FAILURE;
+ }
+ if (!sync) {
return HDF_SUCCESS;
- } else {
+ }
+
+ while (hostClnt->hostService == NULL && waitCount-- > 0) {
+ OsalMSleep(WAIT_HOST_SLEEP_TIME);
+ }
+
+ if (waitCount <= 0) {
+ HDF_LOGE("wait host(%s, %d) attach timeout", hostClnt->hostName, hostClnt->hostId);
+ return HDF_ERR_TIMEOUT;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int DevmgrServiceLoadDevice(struct IDevmgrService *devMgrSvc, const char *serviceName)
+{
+ struct HdfDeviceInfo *deviceInfo = NULL;
+ struct DevHostServiceClnt *hostClnt = NULL;
+ (void)devMgrSvc;
+
+ if (serviceName == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ if (!DevmgrServiceDynamicDevInfoFound(serviceName, &hostClnt, &deviceInfo)) {
+ HDF_LOGE("device %s not in configed device list", serviceName);
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+
+ if (deviceInfo->preload != DEVICE_PRELOAD_DISABLE) {
+ HDF_LOGE("device %s not an dynamic load device", serviceName);
+ return HDF_DEV_ERR_NORANGE;
+ }
+
+ if (hostClnt->hostPid < 0 && DevmgrServiceStartHostProcess(hostClnt, true) != HDF_SUCCESS) {
+ HDF_LOGW("failed to start device host(%s, %u)", hostClnt->hostName, hostClnt->hostId);
return HDF_FAILURE;
}
+
+ return hostClnt->hostService->AddDevice(hostClnt->hostService, deviceInfo);
}
-static int DevmgrServiceFindAndActiveDevice(const char *svcName, bool isLoad)
+static int DevmgrServiceUnloadDevice(struct IDevmgrService *devMgrSvc, const char *serviceName)
{
- struct HdfSListIterator itDeviceInfo;
struct HdfDeviceInfo *deviceInfo = NULL;
struct DevHostServiceClnt *hostClnt = NULL;
- struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
- if (devMgrSvc == NULL || svcName == NULL) {
+ (void)devMgrSvc;
+
+ if (serviceName == NULL) {
return HDF_ERR_INVALID_PARAM;
}
- DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) {
- HdfSListIteratorInit(&itDeviceInfo, hostClnt->deviceInfos);
- while (HdfSListIteratorHasNext(&itDeviceInfo)) {
- deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo);
- if (strcmp(deviceInfo->svcName, svcName) == 0) {
- return DevmgrServiceActiveDevice(hostClnt, deviceInfo, isLoad);
- }
- }
+ if (!DevmgrServiceDynamicDevInfoFound(serviceName, &hostClnt, &deviceInfo) ||
+ deviceInfo->preload != DEVICE_PRELOAD_DISABLE) {
+ HDF_LOGE("device %s not in configed dynamic device list", serviceName);
+ return HDF_DEV_ERR_NO_DEVICE;
}
- return HDF_FAILURE;
+ if (hostClnt->hostService == NULL) {
+ return HDF_FAILURE;
+ }
+ return hostClnt->hostService->DelDevice(hostClnt->hostService, deviceInfo->deviceId);
}
int32_t DevmgrServiceLoadLeftDriver(struct DevmgrService *devMgrSvc)
@@ -75,30 +139,22 @@ int32_t DevmgrServiceLoadLeftDriver(struct DevmgrService *devMgrSvc)
}
DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) {
- HdfSListIteratorInit(&itDeviceInfo, hostClnt->deviceInfos);
+ HdfSListIteratorInit(&itDeviceInfo, &hostClnt->unloadDevInfos);
while (HdfSListIteratorHasNext(&itDeviceInfo)) {
deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo);
if (deviceInfo->preload == DEVICE_PRELOAD_ENABLE_STEP2) {
- ret = DevmgrServiceActiveDevice(hostClnt, deviceInfo, true);
+ ret = hostClnt->hostService->AddDevice(hostClnt->hostService, deviceInfo);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:failed to load driver %s", __func__, deviceInfo->moduleName);
+ continue;
}
+ HdfSListIteratorRemove(&itDeviceInfo);
}
}
}
return HDF_SUCCESS;
}
-int DevmgrServiceLoadDevice(const char *svcName)
-{
- return DevmgrServiceFindAndActiveDevice(svcName, true);
-}
-
-int DevmgrServiceUnLoadDevice(const char *svcName)
-{
- return DevmgrServiceFindAndActiveDevice(svcName, false);
-}
-
static struct DevHostServiceClnt *DevmgrServiceFindDeviceHost(struct IDevmgrService *inst, uint16_t hostId)
{
struct DevHostServiceClnt *hostClnt = NULL;
@@ -113,53 +169,57 @@ static struct DevHostServiceClnt *DevmgrServiceFindDeviceHost(struct IDevmgrServ
return hostClnt;
}
}
- HDF_LOGE("failed to find host, host id is %u", hostId);
+ HDF_LOGE("cannot find host %u", hostId);
return NULL;
}
-static void DevmgrServiceUpdateStatus(struct DevHostServiceClnt *hostClnt, uint16_t deviceId, uint16_t status)
+static int DevmgrServiceAttachDevice(struct IDevmgrService *inst, struct IHdfDeviceToken *token)
{
- struct HdfSListIterator it;
- struct HdfDeviceInfo *deviceInfo = NULL;
-
- HdfSListIteratorInit(&it, hostClnt->deviceInfos);
- while (HdfSListIteratorHasNext(&it)) {
- deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&it);
- if (deviceInfo->deviceId == deviceId) {
- deviceInfo->status = status;
- HDF_LOGD("%s host:%s %u device:%s %u status:%u", __func__, hostClnt->hostName,
- hostClnt->hostId, deviceInfo->svcName, deviceId, deviceInfo->status);
- return;
- }
- }
- HDF_LOGE("%s: not find device %u in host %u", __func__, deviceId, hostClnt->hostId);
- return;
-}
+ struct DevHostServiceClnt *hostClnt = NULL;
+ struct DeviceTokenClnt *tokenClnt = NULL;
-static int DevmgrServiceAttachDevice(
- struct IDevmgrService *inst, const struct HdfDeviceInfo *deviceInfo, struct IHdfDeviceToken *token)
-{
- if (deviceInfo == NULL) {
- HDF_LOGE("failed to attach device, deviceInfo is null");
- return HDF_FAILURE;
- }
- struct DevHostServiceClnt *hostClnt = DevmgrServiceFindDeviceHost(inst, deviceInfo->hostId);
+ hostClnt = DevmgrServiceFindDeviceHost(inst, HOSTID(token->devid));
if (hostClnt == NULL) {
HDF_LOGE("failed to attach device, hostClnt is null");
return HDF_FAILURE;
}
- struct DeviceTokenClnt *tokenClnt = DeviceTokenClntNewInstance(token);
+ tokenClnt = DeviceTokenClntNewInstance(token);
if (tokenClnt == NULL) {
HDF_LOGE("failed to attach device, tokenClnt is null");
return HDF_FAILURE;
}
- tokenClnt->deviceInfo = deviceInfo;
- DevmgrServiceUpdateStatus(hostClnt, deviceInfo->deviceId, HDF_SERVICE_USABLE);
HdfSListAdd(&hostClnt->devices, &tokenClnt->node);
return HDF_SUCCESS;
}
+static bool HdfSListHostSearchDeviceTokenComparer(struct HdfSListNode *tokenNode, uint32_t devid)
+{
+ struct DeviceTokenClnt *tokenClnt = CONTAINER_OF(tokenNode, struct DeviceTokenClnt, node);
+ return tokenClnt->tokenIf->devid == devid;
+}
+
+static int DevmgrServiceDetachDevice(struct IDevmgrService *inst, devid_t devid)
+{
+ struct DevHostServiceClnt *hostClnt = NULL;
+ struct DeviceTokenClnt *tokenClnt = NULL;
+ struct HdfSListNode *tokenClntNode = NULL;
+
+ hostClnt = DevmgrServiceFindDeviceHost(inst, HOSTID(devid));
+ if (hostClnt == NULL) {
+ HDF_LOGE("failed to attach device, hostClnt is null");
+ return HDF_FAILURE;
+ }
+ tokenClntNode = HdfSListSearch(&hostClnt->devices, devid, HdfSListHostSearchDeviceTokenComparer);
+ if (tokenClntNode == NULL) {
+ HDF_LOGE("devmgr detach device %x not found", devid);
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+ tokenClnt = CONTAINER_OF(tokenClntNode, struct DeviceTokenClnt, node);
+ HdfSListRemove(&hostClnt->devices, &tokenClnt->node);
+ return HDF_SUCCESS;
+}
+
static int DevmgrServiceAttachDeviceHost(
struct IDevmgrService *inst, uint16_t hostId, struct IDevHostService *hostService)
{
@@ -174,27 +234,45 @@ static int DevmgrServiceAttachDeviceHost(
}
hostClnt->hostService = hostService;
- hostClnt->deviceInfos = HdfAttributeManagerGetDeviceList(hostClnt->hostId, hostClnt->hostName);
- if (hostClnt->deviceInfos == NULL) {
- HDF_LOGW("failed to get device list ");
+ return DevHostServiceClntInstallDriver(hostClnt);
+}
+
+static int DevmgrServiceStartDeviceHost(struct DevmgrService *devmgr, struct HdfHostInfo *hostAttr)
+{
+ struct DevHostServiceClnt *hostClnt = DevHostServiceClntNewInstance(hostAttr->hostId, hostAttr->hostName);
+ if (hostClnt == NULL) {
+ HDF_LOGW("failed to create new device host client");
+ return HDF_FAILURE;
+ }
+
+ if (HdfAttributeManagerGetDeviceList(hostClnt) != HDF_SUCCESS) {
+ HDF_LOGW("failed to get device list for host %s", hostClnt->hostName);
+ return HDF_FAILURE;
+ }
+
+ DListInsertTail(&hostClnt->node, &devmgr->hosts);
+
+ // not start the host which only have dynamic deivces
+ if (HdfSListIsEmpty(&hostClnt->unloadDevInfos)) {
return HDF_SUCCESS;
}
- hostClnt->devCount = HdfSListCount(hostClnt->deviceInfos);
- return DevHostServiceClntInstallDriver(hostClnt);
+
+ if (DevmgrServiceStartHostProcess(hostClnt, false) != HDF_SUCCESS) {
+ HDF_LOGW("failed to start device host, host id is %u", hostAttr->hostId);
+ DListRemove(&hostClnt->node);
+ DevHostServiceClntFreeInstance(hostClnt);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
}
static int DevmgrServiceStartDeviceHosts(struct DevmgrService *inst)
{
+ uint32_t ret;
struct HdfSList hostList;
struct HdfSListIterator it;
struct HdfHostInfo *hostAttr = NULL;
- struct DevHostServiceClnt *hostClnt = NULL;
- struct IDriverInstaller *installer = NULL;
- installer = DriverInstallerGetInstance();
- if (installer == NULL || installer->StartDeviceHost == NULL) {
- HDF_LOGE("installer or installer->StartDeviceHost is null");
- return HDF_FAILURE;
- }
+
HdfSListInit(&hostList);
if (!HdfAttributeManagerGetHostList(&hostList)) {
HDF_LOGW("%s: host list is null", __func__);
@@ -203,17 +281,10 @@ static int DevmgrServiceStartDeviceHosts(struct DevmgrService *inst)
HdfSListIteratorInit(&it, &hostList);
while (HdfSListIteratorHasNext(&it)) {
hostAttr = (struct HdfHostInfo *)HdfSListIteratorNext(&it);
- hostClnt = DevHostServiceClntNewInstance(hostAttr->hostId, hostAttr->hostName);
- if (hostClnt == NULL) {
- HDF_LOGW("failed to create new device host client");
- continue;
- }
- DListInsertTail(&hostClnt->node, &inst->hosts);
- hostClnt->hostPid = installer->StartDeviceHost(hostAttr->hostId, hostAttr->hostName);
- if (hostClnt->hostPid == HDF_FAILURE) {
- HDF_LOGW("failed to start device host, host id is %u", hostAttr->hostId);
- DListRemove(&hostClnt->node);
- DevHostServiceClntFreeInstance(hostClnt);
+ ret = DevmgrServiceStartDeviceHost(inst, hostAttr);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGW("%s failed to start device host, host id is %u, host name is '%s'",
+ __func__, hostAttr->hostId, hostAttr->hostName);
}
}
HdfSListFlush(&hostList, HdfHostInfoDelete);
@@ -222,11 +293,16 @@ static int DevmgrServiceStartDeviceHosts(struct DevmgrService *inst)
int DevmgrServiceStartService(struct IDevmgrService *inst)
{
+ int ret;
struct DevmgrService *dmService = (struct DevmgrService *)inst;
if (dmService == NULL) {
HDF_LOGE("failed to start device manager service, dmService is null");
return HDF_FAILURE;
}
+
+ ret = DevSvcManagerStartService();
+ HDF_LOGI("start svcmgr result %d", ret);
+
return DevmgrServiceStartDeviceHosts(dmService);
}
@@ -271,13 +347,17 @@ int DevmgrServicePowerStateChange(struct IDevmgrService *devmgrService, enum Hdf
bool DevmgrServiceConstruct(struct DevmgrService *inst)
{
+ struct IDevmgrService *devMgrSvcIf = NULL;
if (OsalMutexInit(&inst->devMgrMutex) != HDF_SUCCESS) {
HDF_LOGE("%s:failed to mutex init ", __func__);
return false;
}
- struct IDevmgrService *devMgrSvcIf = (struct IDevmgrService *)inst;
+ devMgrSvcIf = (struct IDevmgrService *)inst;
if (devMgrSvcIf != NULL) {
devMgrSvcIf->AttachDevice = DevmgrServiceAttachDevice;
+ devMgrSvcIf->DetachDevice = DevmgrServiceDetachDevice;
+ devMgrSvcIf->LoadDevice = DevmgrServiceLoadDevice;
+ devMgrSvcIf->UnloadDevice = DevmgrServiceUnloadDevice;
devMgrSvcIf->AttachDeviceHost = DevmgrServiceAttachDeviceHost;
devMgrSvcIf->StartService = DevmgrServiceStartService;
devMgrSvcIf->PowerStateChange = DevmgrServicePowerStateChange;
@@ -313,14 +393,14 @@ struct IDevmgrService *DevmgrServiceGetInstance()
void DevmgrServiceRelease(struct HdfObject *object)
{
struct DevmgrService *devmgrService = (struct DevmgrService *)object;
+ struct DevHostServiceClnt *hostClnt = NULL;
+ struct DevHostServiceClnt *hostClntTmp = NULL;
if (devmgrService == NULL) {
return;
}
- struct DevHostServiceClnt *hostClnt = NULL;
- struct DevHostServiceClnt *hostClntTmp = NULL;
DLIST_FOR_EACH_ENTRY_SAFE(hostClnt, hostClntTmp, &devmgrService->hosts, struct DevHostServiceClnt, node) {
DListRemove(&hostClnt->node);
- DevHostServiceClntDelete(hostClnt);
+ DevHostServiceClntDelete(hostClnt);
}
OsalMutexDestroy(&devmgrService->devMgrMutex);
diff --git a/core/manager/src/devsvc_manager.c b/core/manager/src/devsvc_manager.c
index 1c7b765acab51ca905a08b1cd7bec17fba2c1fb8..2c3380389a1257641a3788652e48b3e99c573b94 100644
--- a/core/manager/src/devsvc_manager.c
+++ b/core/manager/src/devsvc_manager.c
@@ -13,12 +13,13 @@
#include "hdf_log.h"
#include "hdf_object_manager.h"
#include "hdf_service_record.h"
+#include "hdf_device_node.h"
+#include "osal_mem.h"
#define HDF_LOG_TAG devsvc_manager
static struct DevSvcRecord *DevSvcManagerSearchService(struct IDevSvcManager *inst, uint32_t serviceKey)
{
- struct HdfSListIterator it;
struct DevSvcRecord *record = NULL;
struct DevSvcRecord *searchResult = NULL;
struct DevSvcManager *devSvcManager = (struct DevSvcManager *)inst;
@@ -28,10 +29,8 @@ static struct DevSvcRecord *DevSvcManagerSearchService(struct IDevSvcManager *in
}
OsalMutexLock(&devSvcManager->mutex);
- HdfSListIteratorInit(&it, &devSvcManager->services);
- while (HdfSListIteratorHasNext(&it)) {
- record = (struct DevSvcRecord *)HdfSListIteratorNext(&it);
- if ((record != NULL) && (record->key == serviceKey)) {
+ DLIST_FOR_EACH_ENTRY(record, &devSvcManager->services, struct DevSvcRecord, entry) {
+ if (record->key == serviceKey) {
searchResult = record;
break;
}
@@ -39,38 +38,104 @@ static struct DevSvcRecord *DevSvcManagerSearchService(struct IDevSvcManager *in
OsalMutexUnlock(&devSvcManager->mutex);
return searchResult;
}
+static void NotifyServiceStatusLocked(struct DevSvcManager *devSvcManager,
+ struct DevSvcRecord *record, uint32_t status)
+{
+ struct ServStatListenerHolder *listenerHolder = NULL;
+ struct ServiceStatus svcstat = {
+ .deviceClass = record->devClass,
+ .serviceName = record->servName,
+ .status = status,
+ .info = record->servInfo,
+ };
+
+ DLIST_FOR_EACH_ENTRY(listenerHolder, &devSvcManager->svcstatListeners, struct ServStatListenerHolder, node) {
+ if ((listenerHolder->listenClass & record->devClass) && listenerHolder->NotifyStatus != NULL) {
+ listenerHolder->NotifyStatus(listenerHolder, &svcstat);
+ }
+ }
+}
-int DevSvcManagerAddService(struct IDevSvcManager *inst, const char *svcName, struct HdfDeviceObject *service)
+int DevSvcManagerAddService(struct IDevSvcManager *inst, const char *servName,
+ uint16_t devClass, struct HdfDeviceObject *service, const char *servInfo)
{
struct DevSvcManager *devSvcManager = (struct DevSvcManager *)inst;
- if ((devSvcManager == NULL) || (service == NULL) || (svcName == NULL)) {
+ struct DevSvcRecord *record = NULL;
+ if (devSvcManager == NULL || service == NULL || servName == NULL) {
HDF_LOGE("failed to add service, input param is null");
return HDF_FAILURE;
}
- struct DevSvcRecord *record = DevSvcRecordNewInstance();
+ record = DevSvcRecordNewInstance();
if (record == NULL) {
HDF_LOGE("failed to add service , record is null");
return HDF_FAILURE;
}
- record->key = HdfStringMakeHashKey(svcName, 0);
+ record->key = HdfStringMakeHashKey(servName, 0);
record->value = service;
+ record->devClass = devClass;
+ record->servName = HdfStringCopy(servName);
+ record->servInfo = HdfStringCopy(servInfo);
+ if (record->servName == NULL) {
+ DevSvcRecordFreeInstance(record);
+ return HDF_ERR_MALLOC_FAIL;
+ }
OsalMutexLock(&devSvcManager->mutex);
- HdfSListAdd(&devSvcManager->services, &record->entry);
+ DListInsertTail(&record->entry, &devSvcManager->services);
+ NotifyServiceStatusLocked(devSvcManager, record, SERVIE_STATUS_START);
OsalMutexUnlock(&devSvcManager->mutex);
return HDF_SUCCESS;
}
+int DevSvcManagerUpdateService(struct IDevSvcManager *inst, const char *servName,
+ uint16_t devClass, struct HdfDeviceObject *service, const char *servInfo)
+{
+ struct DevSvcManager *devSvcManager = (struct DevSvcManager *)inst;
+ struct DevSvcRecord *record = NULL;
+ char *servNameStr = NULL;
+ char *servInfoStr = NULL;
+ if (devSvcManager == NULL || service == NULL || servName == NULL) {
+ HDF_LOGE("failed to add service, input param is null");
+ return HDF_FAILURE;
+ }
+
+ record = DevSvcManagerSearchService(inst, HdfStringMakeHashKey(servName, 0));
+ if (record == NULL) {
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+
+ servNameStr = HdfStringCopy(servName);
+ if (servNameStr == NULL) {
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ servInfoStr = HdfStringCopy(servInfo);
+ if (servInfoStr == NULL) {
+ OsalMemFree(servNameStr);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+ OsalMemFree((char *)record->servName);
+ OsalMemFree((char *)record->servInfo);
+
+ record->value = service;
+ record->devClass = devClass;
+ record->servName = servNameStr;
+ record->servInfo = servInfoStr;
+
+ NotifyServiceStatusLocked(devSvcManager, record, SERVIE_STATUS_CHANGE);
+ return HDF_SUCCESS;
+}
+
int DevSvcManagerSubscribeService(struct IDevSvcManager *inst, const char *svcName, struct SubscriberCallback callBack)
{
- int ret = HDF_FAILURE;
- struct DevSvcManager *devSvcMgr = (struct DevSvcManager *)inst;
- if (svcName == NULL || devSvcMgr == NULL) {
- return ret;
+ struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
+ struct HdfObject *deviceService = NULL;
+ if (inst == NULL || svcName == NULL || devMgrSvc == NULL) {
+ return HDF_FAILURE;
}
- struct HdfObject *deviceService = DevSvcManagerGetService(inst, svcName);
+ deviceService = DevSvcManagerGetService(inst, svcName);
if (deviceService != NULL) {
if (callBack.OnServiceConnected != NULL) {
callBack.OnServiceConnected(callBack.deviceObject, deviceService);
@@ -78,39 +143,64 @@ int DevSvcManagerSubscribeService(struct IDevSvcManager *inst, const char *svcNa
return HDF_SUCCESS;
}
- return DevmgrServiceLoadDevice(svcName);
+ return devMgrSvc->super.LoadDevice(&devMgrSvc->super, svcName);
}
void DevSvcManagerRemoveService(struct IDevSvcManager *inst, const char *svcName)
{
struct DevSvcManager *devSvcManager = (struct DevSvcManager *)inst;
+ struct DevSvcRecord *serviceRecord = NULL;
uint32_t serviceKey = HdfStringMakeHashKey(svcName, 0);
+
if (svcName == NULL || devSvcManager == NULL) {
return;
}
- struct DevSvcRecord *serviceRecord = DevSvcManagerSearchService(inst, serviceKey);
- if (serviceRecord != NULL) {
- OsalMutexLock(&devSvcManager->mutex);
- HdfSListRemove(&devSvcManager->services, &serviceRecord->entry);
- OsalMutexUnlock(&devSvcManager->mutex);
+ serviceRecord = DevSvcManagerSearchService(inst, serviceKey);
+ if (serviceRecord == NULL) {
+ return;
}
+ OsalMutexLock(&devSvcManager->mutex);
+ NotifyServiceStatusLocked(devSvcManager, serviceRecord, SERVIE_STATUS_STOP);
+ DListRemove(&serviceRecord->entry);
+ OsalMutexUnlock(&devSvcManager->mutex);
+
DevSvcRecordFreeInstance(serviceRecord);
}
struct HdfDeviceObject *DevSvcManagerGetObject(struct IDevSvcManager *inst, const char *svcName)
{
uint32_t serviceKey = HdfStringMakeHashKey(svcName, 0);
+ struct DevSvcRecord *serviceRecord = NULL;
if (svcName == NULL) {
HDF_LOGE("Get service failed, svcName is null");
return NULL;
}
- struct DevSvcRecord *serviceRecord = DevSvcManagerSearchService(inst, serviceKey);
+ serviceRecord = DevSvcManagerSearchService(inst, serviceKey);
if (serviceRecord != NULL) {
return serviceRecord->value;
}
return NULL;
}
+// only use for kernel space
+void DevSvcManagerListService(struct HdfSBuf *serviecNameSet, DeviceClass deviceClass)
+{
+ struct DevSvcRecord *record = NULL;
+ struct DevSvcManager *devSvcManager = (struct DevSvcManager *)DevSvcManagerGetInstance();
+ if (devSvcManager == NULL) {
+ HDF_LOGE("failed to list service, devSvcManager is null");
+ return;
+ }
+
+ OsalMutexLock(&devSvcManager->mutex);
+ DLIST_FOR_EACH_ENTRY(record, &devSvcManager->services, struct DevSvcRecord, entry) {
+ if (record->devClass == deviceClass) {
+ HdfSbufWriteString(serviecNameSet, record->servName);
+ }
+ }
+ OsalMutexUnlock(&devSvcManager->mutex);
+}
+
struct HdfObject *DevSvcManagerGetService(struct IDevSvcManager *inst, const char *svcName)
{
struct HdfDeviceObject *deviceObject = DevSvcManagerGetObject(inst, svcName);
@@ -120,27 +210,80 @@ struct HdfObject *DevSvcManagerGetService(struct IDevSvcManager *inst, const cha
return (struct HdfObject *)deviceObject->service;
}
+int DevSvcManagerRegsterServListener(struct IDevSvcManager *inst,
+ struct ServStatListenerHolder *listenerHolder)
+{
+ struct DevSvcManager *devSvcManager = (struct DevSvcManager *)inst;
+ if (devSvcManager == NULL || listenerHolder == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ OsalMutexLock(&devSvcManager->mutex);
+ DListInsertTail(&listenerHolder->node, &devSvcManager->svcstatListeners);
+ OsalMutexUnlock(&devSvcManager->mutex);
+
+ return HDF_SUCCESS;
+}
+
+void DevSvcManagerUnregsterServListener(struct IDevSvcManager *inst,
+ struct ServStatListenerHolder *listenerHolder)
+{
+ struct DevSvcManager *devSvcManager = (struct DevSvcManager *)inst;
+ if (devSvcManager == NULL || listenerHolder == NULL) {
+ return;
+ }
+
+ OsalMutexLock(&devSvcManager->mutex);
+ DListRemove(&listenerHolder->node);
+ OsalMutexUnlock(&devSvcManager->mutex);
+}
+
bool DevSvcManagerConstruct(struct DevSvcManager *inst)
{
+ struct IDevSvcManager *devSvcMgrIf = NULL;
if (inst == NULL) {
HDF_LOGE("%s: inst is null!", __func__);
return false;
}
- struct IDevSvcManager *devSvcMgrIf = &inst->super;
+ devSvcMgrIf = &inst->super;
devSvcMgrIf->AddService = DevSvcManagerAddService;
+ devSvcMgrIf->UpdateService = DevSvcManagerUpdateService;
devSvcMgrIf->SubscribeService = DevSvcManagerSubscribeService;
devSvcMgrIf->UnsubscribeService = NULL;
devSvcMgrIf->RemoveService = DevSvcManagerRemoveService;
devSvcMgrIf->GetService = DevSvcManagerGetService;
devSvcMgrIf->GetObject = DevSvcManagerGetObject;
- HdfSListInit(&inst->services);
+ devSvcMgrIf->RegsterServListener = DevSvcManagerRegsterServListener;
+ devSvcMgrIf->UnregsterServListener = DevSvcManagerUnregsterServListener;
if (OsalMutexInit(&inst->mutex) != HDF_SUCCESS) {
HDF_LOGE("failed to create device service manager mutex");
return false;
}
+ DListHeadInit(&inst->services);
+ DListHeadInit(&inst->svcstatListeners);
return true;
}
+int DevSvcManagerStartService(void)
+{
+ int ret;
+ struct IDevSvcManager *svcmgr = DevSvcManagerGetInstance();
+
+ if (svcmgr == NULL) {
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ if (svcmgr->StartService == NULL) {
+ return HDF_SUCCESS;
+ }
+
+ ret = svcmgr->StartService(svcmgr);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("failed to start service manager");
+ }
+
+ return ret;
+}
+
struct HdfObject *DevSvcManagerCreate()
{
static bool isDevSvcManagerInit = false;
@@ -154,13 +297,17 @@ struct HdfObject *DevSvcManagerCreate()
return (struct HdfObject *)&devSvcManagerInstance;
}
-void DevSvcManagerRelease(struct HdfObject *object)
+void DevSvcManagerRelease(struct IDevSvcManager *inst)
{
- struct DevSvcManager *devSvcManager = (struct DevSvcManager *)object;
- if (object == NULL) {
+ struct DevSvcManager *devSvcManager = CONTAINER_OF(inst, struct DevSvcManager, super);
+ if (inst == NULL) {
return;
}
- HdfSListFlush(&devSvcManager->services, DevSvcRecordDelete);
+ struct DevSvcRecord *record = NULL;
+ struct DevSvcRecord *tmp = NULL;
+ DLIST_FOR_EACH_ENTRY_SAFE(record, tmp, &devSvcManager->services, struct DevSvcRecord, entry) {
+ DevSvcRecordFreeInstance(record);
+ }
OsalMutexDestroy(&devSvcManager->mutex);
}
diff --git a/core/manager/src/devsvc_manager_ext.c b/core/manager/src/devsvc_manager_ext.c
new file mode 100644
index 0000000000000000000000000000000000000000..d38b2eea668c0cc07bb85f368c03bb06aae92712
--- /dev/null
+++ b/core/manager/src/devsvc_manager_ext.c
@@ -0,0 +1,209 @@
+/*
+ * Copyright (c) 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 "devsvc_listener_holder.h"
+#include "devsvc_manager.h"
+#include "hdf_base.h"
+#include "hdf_device_node.h"
+#include "hdf_io_service.h"
+#include "hdf_log.h"
+#include "hdf_object_manager.h"
+#include "osal_mem.h"
+#include "svcmgr_ioservice.h"
+#include "osal_mutex.h"
+
+#define HDF_LOG_TAG devsvc_mger
+#define SVC_MGR_NODE_PERM 0660
+
+struct DevSvcManagerExt {
+ struct DevSvcManager super;
+ struct IDeviceIoService ioService;
+ struct HdfIoService *serv;
+ struct OsalMutex mutex;
+ bool started;
+};
+
+int32_t DeviceSvcMgrOpen(struct HdfDeviceIoClient *client)
+{
+ (void)client;
+ return HDF_SUCCESS;
+}
+
+static int32_t DevSvcManagerExtRegisterListener(struct HdfDeviceIoClient *client, struct HdfSBuf *data)
+{
+ struct ServStatListenerHolder *holder = NULL;
+ uint16_t devClass = DEVICE_CLASS_MAX;
+ struct DevSvcManagerExt *svcmgrInst = NULL;
+ if (client->device == NULL || client->device->priv == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ svcmgrInst = (struct DevSvcManagerExt *)DevSvcManagerGetInstance();
+
+ if (!HdfSbufReadUint16(data, &devClass)) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ holder = ServStatListenerHolderGet((uintptr_t)client);
+ if (holder != NULL) {
+ HDF_LOGE("%s:register listener exist, update and return", __func__);
+ holder->listenClass = devClass;
+ return HDF_SUCCESS;
+ }
+
+ holder = ServStatListenerHolderCreate((uintptr_t)client, devClass);
+ if (holder == NULL) {
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ return svcmgrInst->super.super.RegsterServListener(&svcmgrInst->super.super, holder);
+}
+
+static int32_t DevSvcManagerExtUnRegisterListener(struct HdfDeviceIoClient *client)
+{
+ struct ServStatListenerHolder *holder = NULL;
+ struct DevSvcManagerExt *svcmgrInst = NULL;
+
+ if (client->device == NULL || client->device->priv == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ svcmgrInst = (struct DevSvcManagerExt *)client->device->priv;
+ OsalMutexLock(&svcmgrInst->mutex);
+ holder = ServStatListenerHolderGet((uintptr_t)client);
+ if (holder == NULL) {
+ OsalMutexUnlock(&svcmgrInst->mutex);
+ return HDF_DEV_ERR_NO_DEVICE_SERVICE;
+ }
+ if (holder->node.next != NULL) {
+ svcmgrInst->super.super.UnregsterServListener(&svcmgrInst->super.super, holder);
+ }
+ ServStatListenerHolderRelease(holder);
+ OsalMutexUnlock(&svcmgrInst->mutex);
+
+ return HDF_SUCCESS;
+}
+
+int32_t DeviceSvcMgrDispatch(struct HdfObject *service, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ uint64_t ioClientPtr = 0;
+ struct HdfDeviceIoClient *client = NULL;
+ if (service == NULL || data == NULL || reply == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ if (!HdfSbufReadUint64(reply, &ioClientPtr) || ioClientPtr == 0) {
+ HDF_LOGE("device svc dispatch: ioClient is null");
+ return HDF_FAILURE;
+ }
+ HdfSbufFlush(reply);
+ client = (struct HdfDeviceIoClient *)(uintptr_t)ioClientPtr;
+ switch (cmdId) {
+ case SVCMGR_REGISTER_LISTENER:
+ return DevSvcManagerExtRegisterListener(client, data);
+ case SVCMGR_UNREGISTER_LISTENER:
+ return DevSvcManagerExtUnRegisterListener(client);
+ default:
+ break;
+ }
+
+ return HDF_ERR_NOT_SUPPORT;
+}
+
+void DeviceSvcMgrRelease(struct HdfDeviceIoClient *client)
+{
+ if (client == NULL) {
+ return;
+ }
+ DevSvcManagerExtUnRegisterListener(client);
+}
+
+int DevSvcManagerExtStart(struct IDevSvcManager *svcmgr)
+{
+ struct DevSvcManagerExt *inst = (struct DevSvcManagerExt *)svcmgr;
+ static struct HdfDeviceObject svcmgrDevObj = { 0 };
+ static struct IDeviceIoService svcmgrIoService = {
+ .Open = DeviceSvcMgrOpen,
+ .Dispatch = NULL,
+ .Release = DeviceSvcMgrRelease,
+ };
+ if (inst == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ if (inst->started) {
+ return HDF_SUCCESS;
+ }
+
+ svcmgrDevObj.service = &svcmgrIoService;
+ svcmgrDevObj.property = NULL;
+ svcmgrDevObj.deviceClass = DEVICE_CLASS_DEFAULT;
+ svcmgrDevObj.priv = (void *)svcmgr;
+
+ inst->serv = HdfIoServicePublish(DEV_SVCMGR_NODE, SVC_MGR_NODE_PERM);
+ if (inst->serv == NULL) {
+ HDF_LOGE("failed to pushlish svcmgr ioservice");
+ } else {
+ static struct HdfIoDispatcher dispatcher = {
+ .Dispatch = DeviceSvcMgrDispatch,
+ };
+ inst->serv->dispatcher = &dispatcher;
+ inst->serv->target = (struct HdfObject *)&svcmgrDevObj;
+ }
+
+ ServStatListenerHolderinit();
+ inst->started = true;
+ return HDF_SUCCESS;
+}
+
+static bool DevSvcManagerExtConstruct(struct DevSvcManagerExt *inst)
+{
+ if (inst == NULL) {
+ return false;
+ }
+ if (!DevSvcManagerConstruct(&inst->super)) {
+ HDF_LOGE("failed to construct device service manager");
+ return false;
+ }
+ if (OsalMutexInit(&inst->mutex) != HDF_SUCCESS) {
+ HDF_LOGE("failed to create devsvcmgrext mutex");
+ return false;
+ }
+ inst->super.super.StartService = DevSvcManagerExtStart;
+
+ return true;
+}
+
+struct HdfObject *DevSvcManagerExtCreate(void)
+{
+ static struct DevSvcManagerExt *instance;
+ if (instance != NULL) {
+ return (struct HdfObject *)instance;
+ }
+
+ instance = OsalMemCalloc(sizeof(struct DevSvcManagerExt));
+ if (!DevSvcManagerExtConstruct(instance)) {
+ OsalMemFree(instance);
+ instance = NULL;
+ }
+
+ return (struct HdfObject *)instance;
+}
+
+void DevSvcManagerExtRelease(struct IDevSvcManager *inst)
+{
+ struct DevSvcManagerExt *instance = (struct DevSvcManagerExt *)inst;
+ if (instance == NULL) {
+ return;
+ }
+ if (instance->serv != NULL) {
+ HdfIoServiceRemove(instance->serv);
+ instance->serv = NULL;
+ }
+ DevSvcManagerRelease(inst);
+ instance->started = false;
+}
diff --git a/core/manager/src/driver_manager.c b/core/manager/src/driver_manager.c
new file mode 100644
index 0000000000000000000000000000000000000000..548095598b3c239047b1896c644438a99ff45bff
--- /dev/null
+++ b/core/manager/src/driver_manager.c
@@ -0,0 +1,122 @@
+/*
+ * 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 "hdf_dlist.h"
+#include "hdf_driver.h"
+#include "hdf_log.h"
+#include "osal_mem.h"
+
+static struct DListHead *HdfDriverHead()
+{
+ static struct DListHead driverHead = { 0 };
+ if (driverHead.next == NULL) {
+ DListHeadInit(&driverHead);
+ }
+
+ return &driverHead;
+}
+
+int32_t HdfRegisterDriverEntry(const struct HdfDriverEntry *entry)
+{
+ struct HdfDriver *newDriver = NULL;
+
+ if (entry == NULL || entry->moduleName == NULL) {
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ newDriver = OsalMemCalloc(sizeof(struct HdfDriver));
+ if (newDriver == NULL) {
+ return HDF_DEV_ERR_NO_MEMORY;
+ }
+
+ newDriver->entry = entry;
+
+ DListInsertTail(&newDriver->node, HdfDriverHead());
+
+ return HDF_SUCCESS;
+}
+
+int32_t HdfUnregisterDriverEntry(const struct HdfDriverEntry *entry)
+{
+ struct DListHead *driverHead = NULL;
+ struct HdfDriver *driver = NULL;
+ struct HdfDriver *tmp = NULL;
+
+ if (entry == NULL || entry->moduleName == NULL) {
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ driverHead = HdfDriverHead();
+ DLIST_FOR_EACH_ENTRY_SAFE(driver, tmp, driverHead, struct HdfDriver, node)
+ {
+ if (driver->entry == entry) {
+ DListRemove(&driver->node);
+ OsalMemFree(driver);
+ break;
+ }
+ }
+
+ return HDF_SUCCESS;
+}
+
+int32_t HdfRegisterDriver(struct HdfDriver *driver)
+{
+ if (driver == NULL || driver->entry == NULL || driver->entry->moduleName == NULL) {
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ DListInsertTail(&driver->node, HdfDriverHead());
+ return HDF_SUCCESS;
+}
+
+int32_t HdfUnregisterDriver(struct HdfDriver *driver)
+{
+ struct DListHead *driverHead = NULL;
+ struct HdfDriver *it = NULL;
+ struct HdfDriver *tmp = NULL;
+
+ if (driver == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ driverHead = HdfDriverHead();
+ DLIST_FOR_EACH_ENTRY_SAFE(it, tmp, driverHead, struct HdfDriver, node)
+ {
+ if (it == driver) {
+ DListRemove(&it->node);
+ break;
+ }
+ }
+
+ return HDF_SUCCESS;
+}
+
+struct HdfDriver *HdfDriverManagerGetDriver(const char *driverName)
+{
+ struct DListHead *driverHead = NULL;
+ struct HdfDriver *driver = NULL;
+
+ if (driverName == NULL) {
+ return NULL;
+ }
+
+ driverHead = HdfDriverHead();
+ DLIST_FOR_EACH_ENTRY(driver, driverHead, struct HdfDriver, node) {
+ if (driver->entry != NULL && driver->entry->moduleName != NULL &&
+ !strcmp(driver->entry->moduleName, driverName)) {
+ return driver;
+ }
+ }
+ HDF_LOGE("%s:driver %s not found", __func__, driverName);
+ return NULL;
+}
+
+struct DListHead *HdfDriverManagerGetDriverList()
+{
+ return HdfDriverHead();
+}
diff --git a/core/manager/src/hdf_driver_installer.c b/core/manager/src/hdf_driver_installer.c
index 4071b2eec717d74b263b07bf5c4088b1544ad2e1..b972ce74397f8726ca688463f4e17b5a24665b9e 100644
--- a/core/manager/src/hdf_driver_installer.c
+++ b/core/manager/src/hdf_driver_installer.c
@@ -8,7 +8,6 @@
#include "hdf_driver_installer.h"
#include "devhost_service.h"
-#include "hdf_base.h"
#include "hdf_log.h"
#include "hdf_object_manager.h"
@@ -17,11 +16,12 @@
static int DriverInstallerStartDeviceHost(uint32_t devHostId, const char *devHostName)
{
struct IDevHostService *hostServiceIf = DevHostServiceNewInstance(devHostId, devHostName);
+ int ret;
if ((hostServiceIf == NULL) || (hostServiceIf->StartService == NULL)) {
HDF_LOGE("hostServiceIf or hostServiceIf->StartService is null");
return HDF_FAILURE;
}
- int ret = hostServiceIf->StartService(hostServiceIf);
+ ret = hostServiceIf->StartService(hostServiceIf);
if (ret != HDF_SUCCESS) {
HDF_LOGE("failed to start host service, ret: %d", ret);
DevHostServiceFreeInstance(hostServiceIf);
diff --git a/core/manager/src/servstat_listener_holder.c b/core/manager/src/servstat_listener_holder.c
new file mode 100644
index 0000000000000000000000000000000000000000..25f305c39aa0f94ab732752bc10652861b37b26b
--- /dev/null
+++ b/core/manager/src/servstat_listener_holder.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 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 "devsvc_listener_holder.h"
+#include "hdf_base.h"
+#include "hdf_device_desc.h"
+#include "hdf_log.h"
+#include "osal_mutex.h"
+#include "osal_mem.h"
+
+struct KServStatListenerHolder {
+ struct DListHead node;
+ struct ServStatListenerHolder holder;
+ struct HdfDeviceIoClient *listenerClient;
+};
+
+struct SvcStatListenerHolderList {
+ struct OsalMutex mutex;
+ struct DListHead list;
+};
+
+static struct SvcStatListenerHolderList g_holoderList;
+
+static void KServStatListenerHolderListInit()
+{
+ OsalMutexInit(&g_holoderList.mutex);
+ DListHeadInit(&g_holoderList.list);
+}
+
+void ServStatListenerHolderinit(void)
+{
+ KServStatListenerHolderListInit();
+}
+
+void KServStatListenerHolderNotifyStatus(struct ServStatListenerHolder *holder,
+ struct ServiceStatus *status)
+{
+ if (holder == NULL || status == NULL) {
+ return;
+ }
+ struct KServStatListenerHolder *holderInst = CONTAINER_OF(holder, struct KServStatListenerHolder, holder);
+ if (holderInst->listenerClient == NULL) {
+ HDF_LOGE("failed to notify service status, invalid holder");
+ return;
+ }
+
+ struct HdfSBuf *data = HdfSBufObtainDefaultSize();
+ if (data == NULL) {
+ HDF_LOGE("failed to notify service status, oom");
+ return;
+ }
+
+ if (ServiceStatusMarshalling(status, data) != HDF_SUCCESS) {
+ HDF_LOGE("failed to marshalling service status");
+ HdfSBufRecycle(data);
+ return;
+ }
+
+ if (HdfDeviceSendEventToClient(holderInst->listenerClient, 0, data) != HDF_SUCCESS) {
+ HDF_LOGE("failed to notify service status, send error");
+ }
+
+ HdfSBufRecycle(data);
+}
+
+struct ServStatListenerHolder *ServStatListenerHolderCreate(uintptr_t listener, uint16_t listenClass)
+{
+ struct HdfDeviceIoClient *client = (struct HdfDeviceIoClient *)listener;
+ struct KServStatListenerHolder *holder = NULL;
+
+ if (listener == 0) {
+ return NULL;
+ }
+
+ holder = OsalMemCalloc(sizeof(struct KServStatListenerHolder));
+ if (holder == NULL) {
+ return NULL;
+ }
+ holder->listenerClient = client;
+ holder->holder.index = listener;
+ holder->holder.listenClass = listenClass;
+ holder->holder.NotifyStatus = KServStatListenerHolderNotifyStatus;
+
+ OsalMutexLock(&g_holoderList.mutex);
+ DListInsertTail(&holder->node, &g_holoderList.list);
+ OsalMutexUnlock(&g_holoderList.mutex);
+ return &holder->holder;
+}
+
+struct ServStatListenerHolder *ServStatListenerHolderGet(uint64_t index)
+{
+ struct KServStatListenerHolder *it = NULL;
+ struct KServStatListenerHolder *holder = NULL;
+
+ OsalMutexLock(&g_holoderList.mutex);
+ DLIST_FOR_EACH_ENTRY(it, &g_holoderList.list, struct KServStatListenerHolder, node) {
+ if (it->holder.index == index) {
+ holder = it;
+ break;
+ }
+ }
+ OsalMutexUnlock(&g_holoderList.mutex);
+ return holder != NULL ? &holder->holder : NULL;
+}
+
+void ServStatListenerHolderRelease(struct ServStatListenerHolder *holder)
+{
+ struct KServStatListenerHolder *holderInst = NULL;
+ if (holder == NULL) {
+ return;
+ }
+
+ holderInst = CONTAINER_OF(holder, struct KServStatListenerHolder, holder);
+ OsalMutexLock(&g_holoderList.mutex);
+ if (holderInst->node.next != NULL) {
+ DListRemove(&holderInst->node);
+ }
+ OsalMutexUnlock(&g_holoderList.mutex);
+
+ holderInst->listenerClient = NULL;
+ OsalMemFree(holderInst);
+}
+
diff --git a/core/manager/test/unittest/common/hdf_ioservice_test.cpp b/core/manager/test/unittest/common/hdf_ioservice_test.cpp
index 6dd938c08b888b982eae736c6eb797695dd39029..e0dfa25c4ebf94034ab50eccde4ac5d5a2472d4f 100644
--- a/core/manager/test/unittest/common/hdf_ioservice_test.cpp
+++ b/core/manager/test/unittest/common/hdf_ioservice_test.cpp
@@ -6,20 +6,23 @@
* See the LICENSE file in the root of this repository for complete details.
*/
+#include "hdf_io_service.h"
+#include "hdf_log.h"
+#include "hdf_power_state.h"
+#include "hdf_uhdf_test.h"
+#include "osal_time.h"
+#include "sample_driver_test.h"
#include
#include
#include
#include
-#include
+#include
+#include
#include
+#include
+#include
+#include
#include
-#include
-#include "hdf_uhdf_test.h"
-#include "hdf_io_service.h"
-#include "osal_time.h"
-#include "sample_driver_test.h"
-#include "hdf_log.h"
-#include "hdf_power_state.h"
using namespace testing::ext;
@@ -34,14 +37,15 @@ public:
static void TearDownTestCase();
void SetUp();
void TearDown();
- static int OnDevEventReceived(struct HdfDevEventlistener *listener, struct HdfIoService *service, uint32_t id,
- struct HdfSBuf *data);
+ static int OnDevEventReceived(
+ struct HdfDevEventlistener *listener, struct HdfIoService *service, uint32_t id, struct HdfSBuf *data);
static struct Eventlistener listener0;
static struct Eventlistener listener1;
const char *testSvcName = SAMPLE_SERVICE;
const int eventWaitTimeUs = (150 * 1000);
static int eventCount;
+ const int servstatWaitTime = 15; // ms
};
int IoServiceTest::eventCount = 0;
@@ -58,7 +62,9 @@ void IoServiceTest::SetUpTestCase()
listener1.listener.priv = (void *)"listener1";
}
-void IoServiceTest::TearDownTestCase() {}
+void IoServiceTest::TearDownTestCase()
+{
+}
void IoServiceTest::SetUp()
{
@@ -67,15 +73,17 @@ void IoServiceTest::SetUp()
eventCount = 0;
}
-void IoServiceTest::TearDown() {}
+void IoServiceTest::TearDown()
+{
+}
-int IoServiceTest::OnDevEventReceived(struct HdfDevEventlistener *listener, struct HdfIoService *service, uint32_t id,
- struct HdfSBuf *data)
+int IoServiceTest::OnDevEventReceived(
+ struct HdfDevEventlistener *listener, struct HdfIoService *service, uint32_t id, struct HdfSBuf *data)
{
OsalTimespec time;
OsalGetTime(&time);
- HDF_LOGE("%s: received event[%d] from %s at %" PRIu64 ".%" PRIu64 "", (char *)listener->priv, eventCount++, (char *)service->priv,
- time.sec, time.usec);
+ HDF_LOGE("%s: received event[%d] from %s at %" PRIu64 ".%" PRIu64 "", (char *)listener->priv, eventCount++,
+ (char *)service->priv, time.sec, time.usec);
const char *string = HdfSbufReadString(data);
if (string == nullptr) {
@@ -88,7 +96,7 @@ int IoServiceTest::OnDevEventReceived(struct HdfDevEventlistener *listener, stru
return 0;
}
-static int SendEvent(struct HdfIoService *serv, const char *eventData)
+static int SendEvent(struct HdfIoService *serv, const char *eventData, bool broadcast)
{
OsalTimespec time;
OsalGetTime(&time);
@@ -107,6 +115,7 @@ static int SendEvent(struct HdfIoService *serv, const char *eventData)
return HDF_DEV_ERR_NO_MEMORY;
}
+ uint32_t cmdId = broadcast ? SAMPLE_DRIVER_SENDEVENT_BROADCAST_DEVICE : SAMPLE_DRIVER_SENDEVENT_SINGLE_DEVICE;
do {
if (!HdfSbufWriteString(data, eventData)) {
HDF_LOGE("fail to write sbuf");
@@ -114,7 +123,7 @@ static int SendEvent(struct HdfIoService *serv, const char *eventData)
break;
}
- ret = serv->dispatcher->Dispatch(&serv->object, SAMPLE_DRIVER_SENDEVENT_SINGLE_DEVICE, data, reply);
+ ret = serv->dispatcher->Dispatch(&serv->object, cmdId, data, reply);
if (ret != HDF_SUCCESS) {
HDF_LOGE("fail to send service call");
break;
@@ -170,7 +179,7 @@ HWTEST_F(IoServiceTest, HdfIoService002, TestSize.Level0)
ret = HdfIoServiceGroupRegisterListener(group, &listener0.listener);
ASSERT_EQ(ret, HDF_SUCCESS);
- ret = SendEvent(serv, testSvcName);
+ ret = SendEvent(serv, testSvcName, false);
ASSERT_EQ(ret, HDF_SUCCESS);
usleep(eventWaitTimeUs);
@@ -189,7 +198,7 @@ HWTEST_F(IoServiceTest, HdfIoService002, TestSize.Level0)
ret = HdfIoServiceGroupRegisterListener(group, &listener0.listener);
ASSERT_EQ(ret, HDF_SUCCESS);
- ret = SendEvent(serv, testSvcName);
+ ret = SendEvent(serv, testSvcName, false);
ASSERT_EQ(ret, HDF_SUCCESS);
usleep(eventWaitTimeUs);
@@ -224,7 +233,7 @@ HWTEST_F(IoServiceTest, HdfIoService003, TestSize.Level0)
ret = HdfIoServiceGroupRegisterListener(group, &listener0.listener);
ASSERT_EQ(ret, HDF_SUCCESS);
- ret = SendEvent(serv, testSvcName);
+ ret = SendEvent(serv, testSvcName, false);
ASSERT_EQ(ret, HDF_SUCCESS);
usleep(eventWaitTimeUs);
@@ -242,7 +251,7 @@ HWTEST_F(IoServiceTest, HdfIoService003, TestSize.Level0)
ret = HdfDeviceRegisterEventListener(serv, &listener1.listener);
ASSERT_EQ(ret, HDF_SUCCESS);
- ret = SendEvent(serv, testSvcName);
+ ret = SendEvent(serv, testSvcName, false);
ASSERT_EQ(ret, HDF_SUCCESS);
usleep(eventWaitTimeUs);
@@ -268,7 +277,7 @@ HWTEST_F(IoServiceTest, HdfIoService004, TestSize.Level0)
int ret = HdfDeviceRegisterEventListener(serv1, &listener0.listener);
ASSERT_EQ(ret, HDF_SUCCESS);
- ret = SendEvent(serv1, testSvcName);
+ ret = SendEvent(serv1, testSvcName, false);
ASSERT_EQ(ret, HDF_SUCCESS);
usleep(eventWaitTimeUs);
@@ -300,7 +309,7 @@ HWTEST_F(IoServiceTest, HdfIoService005, TestSize.Level0)
ret = HdfIoServiceGroupRegisterListener(group, &listener0.listener);
ASSERT_EQ(ret, HDF_SUCCESS);
- ret = SendEvent(serv, testSvcName);
+ ret = SendEvent(serv, testSvcName, false);
ASSERT_EQ(ret, HDF_SUCCESS);
usleep(eventWaitTimeUs);
@@ -311,7 +320,7 @@ HWTEST_F(IoServiceTest, HdfIoService005, TestSize.Level0)
ret = HdfIoServiceGroupAddService(group, serv);
ASSERT_EQ(ret, HDF_SUCCESS);
- ret = SendEvent(serv, testSvcName);
+ ret = SendEvent(serv, testSvcName, false);
ASSERT_EQ(ret, HDF_SUCCESS);
usleep(eventWaitTimeUs);
@@ -319,7 +328,6 @@ HWTEST_F(IoServiceTest, HdfIoService005, TestSize.Level0)
HdfIoServiceGroupRecycle(group);
}
-
/* *
* @tc.name: HdfIoService006
* @tc.desc: service group add remove listener test
@@ -348,13 +356,13 @@ HWTEST_F(IoServiceTest, HdfIoService006, TestSize.Level0)
ret = HdfIoServiceGroupAddService(group, serv1);
ASSERT_EQ(ret, HDF_SUCCESS);
- ret = SendEvent(serv, testSvcName);
+ ret = SendEvent(serv, testSvcName, false);
ASSERT_EQ(ret, HDF_SUCCESS);
usleep(eventWaitTimeUs);
ASSERT_EQ(1, listener0.eventCount);
- ret = SendEvent(serv1, testSvcName);
+ ret = SendEvent(serv1, testSvcName, false);
ASSERT_EQ(ret, HDF_SUCCESS);
usleep(eventWaitTimeUs);
@@ -362,13 +370,13 @@ HWTEST_F(IoServiceTest, HdfIoService006, TestSize.Level0)
HdfIoServiceGroupRemoveService(group, serv);
- ret = SendEvent(serv, testSvcName);
+ ret = SendEvent(serv, testSvcName, false);
ASSERT_EQ(ret, HDF_SUCCESS);
usleep(eventWaitTimeUs);
ASSERT_EQ(2, listener0.eventCount);
- ret = SendEvent(serv1, testSvcName);
+ ret = SendEvent(serv1, testSvcName, false);
ASSERT_EQ(ret, HDF_SUCCESS);
usleep(eventWaitTimeUs);
@@ -377,7 +385,7 @@ HWTEST_F(IoServiceTest, HdfIoService006, TestSize.Level0)
ret = HdfIoServiceGroupAddService(group, serv);
ASSERT_EQ(ret, HDF_SUCCESS);
- ret = SendEvent(serv, testSvcName);
+ ret = SendEvent(serv, testSvcName, false);
ASSERT_EQ(ret, HDF_SUCCESS);
usleep(eventWaitTimeUs);
@@ -388,7 +396,6 @@ HWTEST_F(IoServiceTest, HdfIoService006, TestSize.Level0)
HdfIoServiceRecycle(serv1);
}
-
/* *
* @tc.name: HdfIoService007
* @tc.desc: duplicate remove group listener
@@ -410,7 +417,7 @@ HWTEST_F(IoServiceTest, HdfIoService007, TestSize.Level0)
ret = HdfIoServiceGroupRegisterListener(group, &listener0.listener);
ASSERT_EQ(ret, HDF_SUCCESS);
- ret = SendEvent(serv, testSvcName);
+ ret = SendEvent(serv, testSvcName, false);
ASSERT_EQ(ret, HDF_SUCCESS);
usleep(eventWaitTimeUs);
@@ -447,7 +454,7 @@ HWTEST_F(IoServiceTest, HdfIoService008, TestSize.Level0)
ret = HdfIoServiceGroupRegisterListener(group, &listener0.listener);
ASSERT_EQ(ret, HDF_SUCCESS);
- ret = SendEvent(serv, testSvcName);
+ ret = SendEvent(serv, testSvcName, false);
ASSERT_EQ(ret, HDF_SUCCESS);
usleep(eventWaitTimeUs);
@@ -487,7 +494,7 @@ HWTEST_F(IoServiceTest, HdfIoService009, TestSize.Level0)
ret = HdfIoServiceGroupRegisterListener(group, &listener0.listener);
ASSERT_EQ(ret, HDF_SUCCESS);
- ret = SendEvent(serv, testSvcName);
+ ret = SendEvent(serv, testSvcName, false);
ASSERT_EQ(ret, HDF_SUCCESS);
usleep(eventWaitTimeUs);
@@ -524,7 +531,7 @@ HWTEST_F(IoServiceTest, HdfIoService010, TestSize.Level0)
ret = HdfIoServiceGroupRegisterListener(group, &listener0.listener);
ASSERT_EQ(ret, HDF_SUCCESS);
- ret = SendEvent(serv, testSvcName);
+ ret = SendEvent(serv, testSvcName, false);
ASSERT_EQ(ret, HDF_SUCCESS);
usleep(eventWaitTimeUs);
@@ -555,7 +562,7 @@ HWTEST_F(IoServiceTest, HdfIoService011, TestSize.Level0)
int ret = HdfDeviceRegisterEventListener(serv, &listener0.listener);
ASSERT_EQ(ret, HDF_SUCCESS);
- ret = SendEvent(serv, testSvcName);
+ ret = SendEvent(serv, testSvcName, false);
ASSERT_EQ(ret, HDF_SUCCESS);
usleep(eventWaitTimeUs);
@@ -584,7 +591,7 @@ HWTEST_F(IoServiceTest, HdfIoService012, TestSize.Level0)
int ret = HdfDeviceRegisterEventListener(serv, &listener0.listener);
ASSERT_EQ(ret, HDF_SUCCESS);
- ret = SendEvent(serv, testSvcName);
+ ret = SendEvent(serv, testSvcName, false);
ASSERT_EQ(ret, HDF_SUCCESS);
usleep(eventWaitTimeUs);
@@ -633,3 +640,269 @@ HWTEST_F(IoServiceTest, HdfIoService013, TestSize.Level0)
HdfIoServiceRecycle(serv);
HdfSBufRecycle(data);
}
+
+/* *
+ * @tc.name: HdfIoService014
+ * @tc.desc: multiple clients listen to a service
+ * @tc.type: FUNC
+ * @tc.require:
+ */
+HWTEST_F(IoServiceTest, HdfIoService014, TestSize.Level0)
+{
+ struct HdfIoServiceGroup *group = HdfIoServiceGroupObtain();
+ ASSERT_NE(group, nullptr);
+
+ struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
+ ASSERT_NE(serv, nullptr);
+ serv->priv = (void *)"serv";
+
+ struct HdfIoService *serv1 = HdfIoServiceBind(testSvcName);
+ ASSERT_NE(serv1, nullptr);
+ serv1->priv = (void *)"serv1";
+
+ int ret = HdfDeviceRegisterEventListener(serv, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = HdfDeviceRegisterEventListener(serv1, &listener1.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = SendEvent(serv, testSvcName, true);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ usleep(eventWaitTimeUs);
+ ASSERT_EQ(1, listener0.eventCount);
+ ASSERT_EQ(1, listener1.eventCount);
+
+ ret = HdfDeviceUnregisterEventListener(serv, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = HdfDeviceUnregisterEventListener(serv, &listener0.listener);
+ EXPECT_NE(ret, HDF_SUCCESS);
+
+ ret = HdfDeviceUnregisterEventListener(serv1, &listener1.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ HdfIoServiceRecycle(serv);
+ HdfIoServiceRecycle(serv1);
+}
+
+struct IoServiceStatusData {
+ IoServiceStatusData()
+ : devClass(0)
+ , servStatus(0)
+ , callbacked(false)
+ {
+ }
+ ~IoServiceStatusData() = default;
+ std::string servName;
+ std::string servInfo;
+ uint16_t devClass;
+ uint16_t servStatus;
+ bool callbacked;
+};
+
+static void TestOnServiceStatusReceived(struct ServiceStatusListener *listener, struct ServiceStatus *servstat)
+{
+ struct IoServiceStatusData *issd = (struct IoServiceStatusData *)listener->priv;
+ if (issd == NULL) {
+ return;
+ }
+ issd->servName = servstat->serviceName;
+ issd->servInfo = servstat->info != NULL ? servstat->info : "";
+ issd->devClass = servstat->deviceClass;
+ issd->servStatus = servstat->status;
+ issd->callbacked = true;
+
+ HDF_LOGI("service status listener callback: %{public}s, %{public}s, %{public}d", servstat->serviceName,
+ issd->servName.data(), issd->servStatus);
+}
+
+/* *
+ * @tc.name: HdfIoService015
+ * @tc.desc: ioservice status listener test
+ * @tc.type: FUNC
+ * @tc.require:
+ */
+HWTEST_F(IoServiceTest, HdfIoService015, TestSize.Level0)
+{
+ struct ISvcMgrIoservice *servmgr = SvcMgrIoserviceGet();
+ ASSERT_NE(servmgr, nullptr);
+
+ struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
+ ASSERT_NE(serv, nullptr);
+ serv->priv = (void *)"serv";
+
+ struct IoServiceStatusData issd;
+ struct ServiceStatusListener *listener = IoServiceStatusListenerNewInstance();
+ listener->callback = TestOnServiceStatusReceived;
+ listener->priv = (void *)&issd;
+
+ int status = servmgr->RegisterServiceStatusListener(servmgr, listener, DEVICE_CLASS_DEFAULT);
+ ASSERT_EQ(status, HDF_SUCCESS);
+
+ struct HdfIoService *testService = HdfIoServiceBind(SAMPLE_SERVICE);
+ ASSERT_TRUE(testService != NULL);
+ struct HdfSBuf *data = HdfSBufObtainDefaultSize();
+ ASSERT_TRUE(data != NULL);
+ const char *newServName = "sample_service1";
+ ASSERT_TRUE(HdfSbufWriteString(data, "sample_driver"));
+ ASSERT_TRUE(HdfSbufWriteString(data, newServName));
+
+ int ret = testService->dispatcher->Dispatch(&testService->object, SAMPLE_DRIVER_REGISTER_DEVICE, data, NULL);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ int count = servstatWaitTime;
+ while (!issd.callbacked && count > 0) {
+ OsalMSleep(1);
+ count--;
+ }
+ ASSERT_TRUE(issd.callbacked);
+ ASSERT_EQ(issd.servName, newServName);
+ ASSERT_EQ(issd.devClass, DEVICE_CLASS_DEFAULT);
+ ASSERT_EQ(issd.servInfo, std::string(SAMPLE_SERVICE));
+ ASSERT_EQ(issd.servStatus, SERVIE_STATUS_START);
+
+ issd.callbacked = false;
+ ret = testService->dispatcher->Dispatch(&testService->object, SAMPLE_DRIVER_UNREGISTER_DEVICE, data, NULL);
+ ASSERT_TRUE(ret == HDF_SUCCESS);
+
+ count = servstatWaitTime;
+ while (!issd.callbacked && count > 0) {
+ OsalMSleep(1);
+ count--;
+ }
+ ASSERT_TRUE(issd.callbacked);
+ ASSERT_EQ(issd.servName, newServName);
+ ASSERT_EQ(issd.devClass, DEVICE_CLASS_DEFAULT);
+ ASSERT_EQ(issd.servInfo, std::string(SAMPLE_SERVICE));
+ ASSERT_EQ(issd.servStatus, SERVIE_STATUS_STOP);
+
+ status = servmgr->UnregisterServiceStatusListener(servmgr, listener);
+ ASSERT_EQ(status, HDF_SUCCESS);
+
+ IoServiceStatusListenerFree(listener);
+ HdfIoServiceRecycle(testService);
+ SvcMgrIoserviceRelease(servmgr);
+ HdfSBufRecycle(data);
+}
+
+/* *
+ * @tc.name: HdfIoService016
+ * @tc.desc: ioservice status listener update info test
+ * @tc.type: FUNC
+ * @tc.require:
+ */
+HWTEST_F(IoServiceTest, HdfIoService016, TestSize.Level0)
+{
+ struct ISvcMgrIoservice *servmgr = SvcMgrIoserviceGet();
+ ASSERT_NE(servmgr, nullptr);
+
+ struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
+ ASSERT_NE(serv, nullptr);
+ serv->priv = (void *)"serv";
+
+ struct IoServiceStatusData issd;
+ struct ServiceStatusListener *listener = IoServiceStatusListenerNewInstance();
+ listener->callback = TestOnServiceStatusReceived;
+ listener->priv = (void *)&issd;
+
+ HDF_LOGI("YDEBUG:%{public}s:%{public}d", __func__, __LINE__);
+ int status = servmgr->RegisterServiceStatusListener(servmgr, listener, DEVICE_CLASS_DEFAULT);
+ ASSERT_EQ(status, HDF_SUCCESS);
+
+ HDF_LOGI("YDEBUG:%{public}s:%{public}d", __func__, __LINE__);
+ struct HdfIoService *testService = HdfIoServiceBind(SAMPLE_SERVICE);
+ ASSERT_TRUE(testService != NULL);
+ HdfSBuf *data = HdfSBufObtainDefaultSize();
+ ASSERT_TRUE(data != NULL);
+
+ HDF_LOGI("YDEBUG:%{public}s:%{public}d", __func__, __LINE__);
+ std::string servinfo = "foo";
+ ASSERT_TRUE(HdfSbufWriteString(data, servinfo.data()));
+ int ret = testService->dispatcher->Dispatch(&testService->object, SAMPLE_DRIVER_UPDATE_SERVICE_INFO, data, NULL);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ HDF_LOGI("YDEBUG:%{public}s:%{public}d", __func__, __LINE__);
+ int count = servstatWaitTime;
+ while (!issd.callbacked && count > 0) {
+ OsalMSleep(1);
+ count--;
+ }
+ HDF_LOGI("YDEBUG:%{public}s:%{public}d", __func__, __LINE__);
+ ASSERT_TRUE(issd.callbacked);
+ ASSERT_EQ(issd.servName, SAMPLE_SERVICE);
+ ASSERT_EQ(issd.devClass, DEVICE_CLASS_DEFAULT);
+ ASSERT_EQ(issd.servInfo, servinfo);
+ ASSERT_EQ(issd.servStatus, SERVIE_STATUS_CHANGE);
+
+ status = servmgr->UnregisterServiceStatusListener(servmgr, listener);
+ ASSERT_EQ(status, HDF_SUCCESS);
+
+ IoServiceStatusListenerFree(listener);
+ HdfIoServiceRecycle(testService);
+ SvcMgrIoserviceRelease(servmgr);
+ HdfSBufRecycle(data);
+}
+
+/* *
+ * @tc.name: HdfIoService017
+ * @tc.desc: ioservice status listener unregister test
+ * @tc.type: FUNC
+ * @tc.require:
+ */
+HWTEST_F(IoServiceTest, HdfIoService017, TestSize.Level0)
+{
+ struct ISvcMgrIoservice *servmgr = SvcMgrIoserviceGet();
+ ASSERT_NE(servmgr, nullptr);
+
+ struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
+ ASSERT_NE(serv, nullptr);
+ serv->priv = (void *)"serv";
+
+ struct IoServiceStatusData issd;
+ struct ServiceStatusListener *listener = IoServiceStatusListenerNewInstance();
+ listener->callback = TestOnServiceStatusReceived;
+ listener->priv = (void *)&issd;
+
+ HDF_LOGI("%{public}s:%{public}d", __func__, __LINE__);
+ int status = servmgr->RegisterServiceStatusListener(servmgr, listener, DEVICE_CLASS_DEFAULT);
+ ASSERT_EQ(status, HDF_SUCCESS);
+
+ struct HdfIoService *testService = HdfIoServiceBind(SAMPLE_SERVICE);
+ ASSERT_TRUE(testService != NULL);
+ HdfSBuf *data = HdfSBufObtainDefaultSize();
+ ASSERT_TRUE(data != NULL);
+ const char *newServName = "sample_service1";
+ ASSERT_TRUE(HdfSbufWriteString(data, "sample_driver"));
+ ASSERT_TRUE(HdfSbufWriteString(data, newServName));
+ int ret = testService->dispatcher->Dispatch(&testService->object, SAMPLE_DRIVER_REGISTER_DEVICE, data, NULL);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ int count = 10;
+ while (!issd.callbacked && count > 0) {
+ OsalMSleep(1);
+ count--;
+ }
+ ASSERT_TRUE(issd.callbacked);
+ ASSERT_EQ(issd.servName, newServName);
+ ASSERT_EQ(issd.devClass, DEVICE_CLASS_DEFAULT);
+ ASSERT_EQ(issd.servInfo, std::string(SAMPLE_SERVICE));
+ ASSERT_EQ(issd.servStatus, SERVIE_STATUS_START);
+
+ status = servmgr->UnregisterServiceStatusListener(servmgr, listener);
+ ASSERT_EQ(status, HDF_SUCCESS);
+
+ issd.callbacked = false;
+ ret = testService->dispatcher->Dispatch(&testService->object, SAMPLE_DRIVER_UNREGISTER_DEVICE, data, NULL);
+ ASSERT_EQ(status, HDF_SUCCESS);
+
+ OsalMSleep(10);
+
+ ASSERT_FALSE(issd.callbacked);
+ status = servmgr->UnregisterServiceStatusListener(servmgr, listener);
+ ASSERT_NE(status, HDF_SUCCESS);
+ IoServiceStatusListenerFree(listener);
+ HdfIoServiceRecycle(testService);
+ SvcMgrIoserviceRelease(servmgr);
+ HdfSBufRecycle(data);
+}
diff --git a/core/manager/test/unittest/common/hdf_lite_manager_test.cpp b/core/manager/test/unittest/common/hdf_lite_manager_test.cpp
index 264a2fd74c1098f7ee271a20fa28bf35d8d16918..b6d2e1cad44a98a9d575d5105d96c8f387730cb4 100644
--- a/core/manager/test/unittest/common/hdf_lite_manager_test.cpp
+++ b/core/manager/test/unittest/common/hdf_lite_manager_test.cpp
@@ -96,7 +96,7 @@ HWTEST_F(HdfManagerTest, HdfRegisterDevice001, TestSize.Level0)
EXPECT_TRUE((timeAfter - timeBefore) < 100);
struct HdfIoService *ioService1 = HdfIoServiceBind("sample_service1");
- EXPECT_TRUE(ioService1 != NULL);
+ ASSERT_TRUE(ioService1 != NULL);
HdfIoServiceRecycle(ioService1);
ret = ioService->dispatcher->Dispatch(&ioService->object, SAMPLE_DRIVER_UNREGISTER_DEVICE, data, NULL);
@@ -117,21 +117,26 @@ HWTEST_F(HdfManagerTest, HdfRegisterDevice001, TestSize.Level0)
*/
HWTEST_F(HdfManagerTest, HdfGetServiceNameByDeviceClass001, TestSize.Level0)
{
- struct HdfSBuf *data = HdfSBufObtain(1000);
+ struct HdfSBuf *data = HdfSBufObtain(2000);
ASSERT_TRUE(data != NULL);
- int32_t ret = HdfGetServiceNameByDeviceClass(DEVICE_CLASS_DEFAULT, data);
- EXPECT_TRUE(ret == HDF_SUCCESS);
+
bool flag = false;
- const char *svcName = NULL;
- while(true) {
- svcName = HdfSbufReadString(data);
- if (svcName == NULL) {
- break;
- }
- if (strcmp(svcName, "sample_service") == 0) {
- flag = true;
- break;
+ for (size_t i = DEVICE_CLASS_DEFAULT; i < DEVICE_CLASS_MAX; i++) {
+ int32_t ret = HdfGetServiceNameByDeviceClass((DeviceClass)i, data);
+ std::cout << "clasee " << i << " device list:" << std::endl;
+ EXPECT_TRUE(ret == HDF_SUCCESS);
+ const char *svcName = NULL;
+ while(true) {
+ svcName = HdfSbufReadString(data);
+ if (svcName == NULL) {
+ break;
+ }
+ std::cout << svcName << std::endl;
+ if (strcmp(svcName, "sample_service") == 0) {
+ flag = true;
+ }
}
+ HdfSbufFlush(data);
}
HdfSBufRecycle(data);
EXPECT_TRUE(flag);
diff --git a/core/manager/test/unittest/common/hdf_pm_test.cpp b/core/manager/test/unittest/common/hdf_pm_test.cpp
new file mode 100755
index 0000000000000000000000000000000000000000..2dc86ac8281a424a824b756f08fb26f440c0771d
--- /dev/null
+++ b/core/manager/test/unittest/common/hdf_pm_test.cpp
@@ -0,0 +1,324 @@
+/*
+ * Copyright (c) 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
+#include
+#include
+#include
+#include
+#include
+#include
+#include "hdf_io_service.h"
+#include "hdf_pm_driver_test.h"
+
+using namespace testing::ext;
+
+class HdfPmTest : public testing::Test {
+public:
+ static void SetUpTestCase();
+ static void TearDownTestCase();
+ void SetUp();
+ void TearDown();
+ static struct HdfIoService *ioService;
+};
+
+struct HdfIoService *HdfPmTest::ioService = NULL;
+
+void HdfPmTest::SetUpTestCase()
+{
+ ioService = HdfIoServiceBind("pm_test_service");
+ ASSERT_TRUE(ioService != NULL);
+ ioService->dispatcher->Dispatch(&ioService->object, HDF_PM_TEST_BEGEN, NULL, NULL);
+}
+
+void HdfPmTest::TearDownTestCase()
+{
+ ASSERT_TRUE(ioService != NULL);
+ ioService->dispatcher->Dispatch(&ioService->object, HDF_PM_TEST_END, NULL, NULL);
+ HdfIoServiceRecycle(ioService);
+}
+
+void HdfPmTest::SetUp()
+{
+}
+
+void HdfPmTest::TearDown()
+{
+}
+
+/**
+ * @tc.name: HdfPmTestOneDriverOnce
+ * @tc.desc: test one driver
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTQF
+ */
+HWTEST_F(HdfPmTest, HdfPmTestOneDriverOnce, TestSize.Level3)
+{
+ int32_t ret = HDF_FAILURE;
+
+ ASSERT_TRUE(ioService != NULL);
+
+ ret = ioService->dispatcher->Dispatch(&ioService->object, HDF_PM_TEST_ONE_DRIVER_ONCE, NULL, NULL);
+ EXPECT_TRUE(ret == HDF_SUCCESS);
+}
+
+/**
+ * @tc.name: HdfPmTestOneDriverTwice
+ * @tc.desc: test one driver
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTQF
+ */
+HWTEST_F(HdfPmTest, HdfPmTestOneDriverTwice, TestSize.Level3)
+{
+ int32_t ret = HDF_FAILURE;
+
+ ASSERT_TRUE(ioService != NULL);
+
+ ret = ioService->dispatcher->Dispatch(&ioService->object, HDF_PM_TEST_ONE_DRIVER_TWICE, NULL, NULL);
+ EXPECT_TRUE(ret == HDF_SUCCESS);
+}
+
+/**
+ * @tc.name: HdfPmTestOneDriverTen
+ * @tc.desc: test one driver
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTQF
+ */
+HWTEST_F(HdfPmTest, HdfPmTestOneDriverTen, TestSize.Level3)
+{
+ int32_t ret = HDF_FAILURE;
+
+ ASSERT_TRUE(ioService != NULL);
+
+ ret = ioService->dispatcher->Dispatch(&ioService->object, HDF_PM_TEST_ONE_DRIVER_TEN, NULL, NULL);
+ EXPECT_TRUE(ret == HDF_SUCCESS);
+}
+
+/**
+ * @tc.name: HdfPmTestOneDriverHundred
+ * @tc.desc: test one driver
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTQF
+ */
+HWTEST_F(HdfPmTest, HdfPmTestOneDriverHundred, TestSize.Level3)
+{
+ int32_t ret = HDF_FAILURE;
+
+ ASSERT_TRUE(ioService != NULL);
+
+ ret = ioService->dispatcher->Dispatch(&ioService->object, HDF_PM_TEST_ONE_DRIVER_HUNDRED, NULL, NULL);
+ EXPECT_TRUE(ret == HDF_SUCCESS);
+}
+
+/**
+ * @tc.name: HdfPmTestOneDriverThousand
+ * @tc.desc: test one driver
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTQF
+ */
+HWTEST_F(HdfPmTest, HdfPmTestOneDriverThousand, TestSize.Level3)
+{
+ int32_t ret = HDF_FAILURE;
+
+ ASSERT_TRUE(ioService != NULL);
+
+ ret = ioService->dispatcher->Dispatch(&ioService->object, HDF_PM_TEST_ONE_DRIVER_THOUSAND, NULL, NULL);
+ EXPECT_TRUE(ret == HDF_SUCCESS);
+}
+
+/**
+ * @tc.name: HdfPmTestTwoDriverOnce
+ * @tc.desc: test two drivers
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTQF
+ */
+HWTEST_F(HdfPmTest, HdfPmTestTwoDriverOnce, TestSize.Level3)
+{
+ int32_t ret = HDF_FAILURE;
+
+ ASSERT_TRUE(ioService != NULL);
+
+ ret = ioService->dispatcher->Dispatch(&ioService->object, HDF_PM_TEST_TWO_DRIVER_ONCE, NULL, NULL);
+ EXPECT_TRUE(ret == HDF_SUCCESS);
+}
+
+/**
+ * @tc.name: HdfPmTestTwoDriverTwice
+ * @tc.desc: test two drivers
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTQF
+ */
+HWTEST_F(HdfPmTest, HdfPmTestTwoDriverTwice, TestSize.Level3)
+{
+ int32_t ret = HDF_FAILURE;
+
+ ASSERT_TRUE(ioService != NULL);
+
+ ret = ioService->dispatcher->Dispatch(&ioService->object, HDF_PM_TEST_TWO_DRIVER_TWICE, NULL, NULL);
+ EXPECT_TRUE(ret == HDF_SUCCESS);
+}
+
+/**
+ * @tc.name: HdfPmTestTwoDriverTen
+ * @tc.desc: test two drivers
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTQF
+ */
+HWTEST_F(HdfPmTest, HdfPmTestTwoDriverTen, TestSize.Level3)
+{
+ int32_t ret = HDF_FAILURE;
+
+ ASSERT_TRUE(ioService != NULL);
+
+ ret = ioService->dispatcher->Dispatch(&ioService->object, HDF_PM_TEST_TWO_DRIVER_TEN, NULL, NULL);
+ EXPECT_TRUE(ret == HDF_SUCCESS);
+}
+
+/**
+ * @tc.name: HdfPmTestTwoDriverHundred
+ * @tc.desc: test two drivers
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTQF
+ */
+HWTEST_F(HdfPmTest, HdfPmTestTwoDriverHundred, TestSize.Level3)
+{
+ int32_t ret = HDF_FAILURE;
+
+ ASSERT_TRUE(ioService != NULL);
+
+ ret = ioService->dispatcher->Dispatch(&ioService->object, HDF_PM_TEST_TWO_DRIVER_HUNDRED, NULL, NULL);
+ EXPECT_TRUE(ret == HDF_SUCCESS);
+}
+
+/**
+ * @tc.name: HdfPmTestTwoDriverThousand
+ * @tc.desc: test two drivers
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTQF
+ */
+HWTEST_F(HdfPmTest, HdfPmTestTwoDriverThousand, TestSize.Level3)
+{
+ int32_t ret = HDF_FAILURE;
+
+ ASSERT_TRUE(ioService != NULL);
+
+ ret = ioService->dispatcher->Dispatch(&ioService->object, HDF_PM_TEST_TWO_DRIVER_THOUSAND, NULL, NULL);
+ EXPECT_TRUE(ret == HDF_SUCCESS);
+}
+
+/**
+ * @tc.name: HdfPmTestThreeDriverOnce
+ * @tc.desc: test three drivers
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTQF
+ */
+HWTEST_F(HdfPmTest, HdfPmTestThreeDriverOnce, TestSize.Level3)
+{
+ int32_t ret = HDF_FAILURE;
+
+ ASSERT_TRUE(ioService != NULL);
+
+ ret = ioService->dispatcher->Dispatch(&ioService->object, HDF_PM_TEST_THREE_DRIVER_ONCE, NULL, NULL);
+ EXPECT_TRUE(ret == HDF_SUCCESS);
+}
+
+/**
+ * @tc.name: HdfPmTestThreeDriverTwice
+ * @tc.desc: test three drivers
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTQF
+ */
+HWTEST_F(HdfPmTest, HdfPmTestThreeDriverTwice, TestSize.Level3)
+{
+ int32_t ret = HDF_FAILURE;
+
+ ASSERT_TRUE(ioService != NULL);
+
+ ret = ioService->dispatcher->Dispatch(&ioService->object, HDF_PM_TEST_THREE_DRIVER_TWICE, NULL, NULL);
+ EXPECT_TRUE(ret == HDF_SUCCESS);
+}
+
+/**
+ * @tc.name: HdfPmTestThreeDriverTen
+ * @tc.desc: test three drivers
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTQF
+ */
+HWTEST_F(HdfPmTest, HdfPmTestThreeDriverTen, TestSize.Level3)
+{
+ int32_t ret = HDF_FAILURE;
+
+ ASSERT_TRUE(ioService != NULL);
+
+ ret = ioService->dispatcher->Dispatch(&ioService->object, HDF_PM_TEST_THREE_DRIVER_TEN, NULL, NULL);
+ EXPECT_TRUE(ret == HDF_SUCCESS);
+}
+
+/**
+ * @tc.name: HdfPmTestThreeDriverHundred
+ * @tc.desc: test three drivers
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTQF
+ */
+HWTEST_F(HdfPmTest, HdfPmTestThreeDriverHundred, TestSize.Level3)
+{
+ int32_t ret = HDF_FAILURE;
+
+ ASSERT_TRUE(ioService != NULL);
+
+ ret = ioService->dispatcher->Dispatch(&ioService->object, HDF_PM_TEST_THREE_DRIVER_HUNDRED, NULL, NULL);
+ EXPECT_TRUE(ret == HDF_SUCCESS);
+}
+
+/**
+ * @tc.name: HdfPmTestThreeDriverThousand
+ * @tc.desc: test three drivers
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTQF
+ */
+HWTEST_F(HdfPmTest, HdfPmTestThreeDriverThousand, TestSize.Level3)
+{
+ int32_t ret = HDF_FAILURE;
+
+ ASSERT_TRUE(ioService != NULL);
+
+ ret = ioService->dispatcher->Dispatch(&ioService->object, HDF_PM_TEST_THREE_DRIVER_THOUSAND, NULL, NULL);
+ EXPECT_TRUE(ret == HDF_SUCCESS);
+}
+
+/**
+ * @tc.name: HdfPmTestThreeDriverSeqHundred
+ * @tc.desc: test three drivers
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTQF
+ */
+HWTEST_F(HdfPmTest, HdfPmTestThreeDriverSeqHundred, TestSize.Level3)
+{
+ int32_t ret = HDF_FAILURE;
+
+ ASSERT_TRUE(ioService != NULL);
+
+ ret = ioService->dispatcher->Dispatch(&ioService->object, HDF_PM_TEST_THREE_DRIVER_SEQ_HUNDRED, NULL, NULL);
+ EXPECT_TRUE(ret == HDF_SUCCESS);
+}
+
+/**
+ * @tc.name: HdfPmTestThreeDriverHundredWithSync
+ * @tc.desc: test three drivers
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTQF
+ */
+HWTEST_F(HdfPmTest, HdfPmTestThreeDriverHundredWithSync, TestSize.Level3)
+{
+ int32_t ret = HDF_FAILURE;
+
+ ASSERT_TRUE(ioService != NULL);
+
+ ret = ioService->dispatcher->Dispatch(&ioService->object, HDF_PM_TEST_THREE_DRIVER_HUNDRED_WITH_SYNC, NULL, NULL);
+ EXPECT_TRUE(ret == HDF_SUCCESS);
+}
diff --git a/core/shared/include/devhost_service_if.h b/core/shared/include/devhost_service_if.h
index a1c22691577c2f837d5629204cda3a4816ca88eb..2a4513e9400cfa8969d3ced9c267cfefa6807d2a 100644
--- a/core/shared/include/devhost_service_if.h
+++ b/core/shared/include/devhost_service_if.h
@@ -9,13 +9,14 @@
#ifndef DEVHOST_SERVICE_IF_H
#define DEVHOST_SERVICE_IF_H
+#include "hdf_device.h"
#include "hdf_device_info.h"
#include "hdf_object.h"
struct IDevHostService {
struct HdfObject object;
int (*AddDevice)(struct IDevHostService *hostService, const struct HdfDeviceInfo *devInfo);
- int (*DelDevice)(struct IDevHostService *hostService, const struct HdfDeviceInfo *devInfo);
+ int (*DelDevice)(struct IDevHostService *hostService, devid_t devId);
int (*StartService)(struct IDevHostService *hostService);
int (*PmNotify)(struct IDevHostService *service, uint32_t powerState);
};
diff --git a/core/shared/include/device_token_if.h b/core/shared/include/device_token_if.h
index c086152ce1ad63ba3f64041fb00e34052d79b016..586f66e9f3e4db94606fff36e3432dfa6244019a 100644
--- a/core/shared/include/device_token_if.h
+++ b/core/shared/include/device_token_if.h
@@ -10,9 +10,11 @@
#define DEVICE_TOKEN_IF_H
#include "hdf_object.h"
+#include "hdf_device.h"
struct IHdfDeviceToken {
struct HdfObject object;
+ devid_t devid;
};
#endif /* DEVICE_TOKEN_IF_H */
diff --git a/core/shared/include/devmgr_service_if.h b/core/shared/include/devmgr_service_if.h
index 55df8e42633eae5438899ab97c318320c6f26978..ee3eb66112262fa4b3677a82251af79e057cf2f0 100644
--- a/core/shared/include/devmgr_service_if.h
+++ b/core/shared/include/devmgr_service_if.h
@@ -19,7 +19,10 @@ struct IDevmgrService {
struct HdfObject base;
struct HdfDeviceObject object;
int (*AttachDeviceHost)(struct IDevmgrService *, uint16_t, struct IDevHostService *);
- int (*AttachDevice)(struct IDevmgrService *, const struct HdfDeviceInfo *, struct IHdfDeviceToken *);
+ int (*AttachDevice)(struct IDevmgrService *, struct IHdfDeviceToken *);
+ int (*DetachDevice)(struct IDevmgrService *, devid_t);
+ int (*LoadDevice)(struct IDevmgrService *, const char *);
+ int (*UnloadDevice)(struct IDevmgrService *, const char *);
int (*StartService)(struct IDevmgrService *);
int (*PowerStateChange)(struct IDevmgrService *, enum HdfPowerState pEvent);
};
diff --git a/core/shared/include/devsvc_manager_if.h b/core/shared/include/devsvc_manager_if.h
index 394f4b507d547ce6b736e4536276b7cfc5496934..805dd43db63e770ffca76f885c6054e0c077d20c 100644
--- a/core/shared/include/devsvc_manager_if.h
+++ b/core/shared/include/devsvc_manager_if.h
@@ -9,17 +9,22 @@
#ifndef DEVSVC_MANAGER_IF_H
#define DEVSVC_MANAGER_IF_H
+#include "devsvc_listener_holder.h"
#include "hdf_device_desc.h"
#include "hdf_object.h"
struct IDevSvcManager {
struct HdfObject object;
- int (*AddService)(struct IDevSvcManager *, const char *, struct HdfDeviceObject *);
+ int (*StartService)(struct IDevSvcManager *);
+ int (*AddService)(struct IDevSvcManager *, const char *, uint16_t, struct HdfDeviceObject *, const char *);
+ int (*UpdateService)(struct IDevSvcManager *, const char *, uint16_t, struct HdfDeviceObject *, const char *);
int (*SubscribeService)(struct IDevSvcManager *, const char *, struct SubscriberCallback);
int (*UnsubscribeService)(struct IDevSvcManager *, const char *);
struct HdfObject *(*GetService)(struct IDevSvcManager *, const char *);
struct HdfDeviceObject *(*GetObject)(struct IDevSvcManager *, const char *);
void (*RemoveService)(struct IDevSvcManager *, const char *);
+ int (*RegsterServListener)(struct IDevSvcManager *, struct ServStatListenerHolder *);
+ void (*UnregsterServListener)(struct IDevSvcManager *, struct ServStatListenerHolder *);
};
#endif /* DEVSVC_MANAGER_IF_H */
diff --git a/core/shared/include/hdf_attribute_manager.h b/core/shared/include/hdf_attribute_manager.h
index 8138a5dbfcd54564f88a28779afb7f766f2b7673..33dab105a68befe49702895ea4c42c71e7ae3e62 100644
--- a/core/shared/include/hdf_attribute_manager.h
+++ b/core/shared/include/hdf_attribute_manager.h
@@ -10,11 +10,10 @@
#define HDF_ATTRIBUTE_MANAGER_H
#include "hdf_slist.h"
+#include "devhost_service_clnt.h"
-const struct DeviceResourceNode *HdfGetRootNode(void);
+const struct DeviceResourceNode *HdfGetHcsRootNode(void);
bool HdfAttributeManagerGetHostList(struct HdfSList *hostList);
-struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *hostName);
-bool HdfDeviceListAdd(const char *moduleName, const char *serviceName, const void *privateData);
-void HdfDeviceListDel(const char *moduleName, const char *serviceName);
+int HdfAttributeManagerGetDeviceList(struct DevHostServiceClnt *hostClnt);
#endif /* HDF_ATTRIBUTE_MANAGER_H */
diff --git a/core/shared/include/hdf_device_info.h b/core/shared/include/hdf_device_info.h
old mode 100755
new mode 100644
index 8852e83062d400b9835400ae40c29be172ed14be..9880181a3328f03c52e54af72b72632d8beafe6b
--- a/core/shared/include/hdf_device_info.h
+++ b/core/shared/include/hdf_device_info.h
@@ -27,8 +27,7 @@ struct HdfDeviceInfo {
bool isDynamic;
uint16_t status;
uint16_t deviceType;
- uint16_t hostId;
- uint16_t deviceId;
+ uint32_t deviceId;
uint16_t policy;
uint16_t priority;
uint16_t preload;
@@ -36,7 +35,6 @@ struct HdfDeviceInfo {
const char *moduleName;
const char *svcName;
const char *deviceMatchAttr;
- const void *private;
};
struct HdfPrivateInfo {
diff --git a/core/shared/include/hdf_driver.h b/core/shared/include/hdf_driver.h
new file mode 100644
index 0000000000000000000000000000000000000000..1190e995ae33694bd4baa3f8348eda2f3ff64ced
--- /dev/null
+++ b/core/shared/include/hdf_driver.h
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+
+#ifndef HDF_DRIVER_H
+#define HDF_DRIVER_H
+
+#include "hdf_device_desc.h"
+#include "hdf_dlist.h"
+
+struct HdfDriver {
+ const struct HdfDriverEntry *entry;
+ uint16_t type;
+ uint16_t bus;
+ struct DListHead node;
+ void *priv;
+};
+
+int32_t HdfRegisterDriverEntry(const struct HdfDriverEntry *entry);
+int32_t HdfUnregisterDriverEntry(const struct HdfDriverEntry *entry);
+int32_t HdfRegisterDriver(struct HdfDriver *driver);
+int32_t HdfUnregisterDriver(struct HdfDriver *driver);
+struct HdfDriver *HdfDriverManagerGetDriver(const char *driverName);
+struct DListHead *HdfDriverManagerGetDriverList(void);
+
+#endif // HDF_DRIVER_H
\ No newline at end of file
diff --git a/core/shared/include/hdf_service_record.h b/core/shared/include/hdf_service_record.h
index 0e8651dc3f5cc51e5fb8630518afa8c68be22980..d3e5ec5aa94f9438485c7d5c5b29051ee6c1112d 100644
--- a/core/shared/include/hdf_service_record.h
+++ b/core/shared/include/hdf_service_record.h
@@ -10,17 +10,19 @@
#define DEVSVC_RECORD_H
#include "hdf_object.h"
-#include "hdf_slist.h"
+#include "hdf_dlist.h"
struct DevSvcRecord {
- struct HdfSListNode entry;
+ struct DListHead entry;
uint32_t key;
struct HdfDeviceObject *value;
+ const char *servName;
+ const char *servInfo;
+ uint16_t devClass;
};
struct DevSvcRecord *DevSvcRecordNewInstance(void);
void DevSvcRecordFreeInstance(struct DevSvcRecord *inst);
-void DevSvcRecordDelete(struct HdfSListNode *listEntry);
#endif /* DEVSVC_RECORD_H */
diff --git a/core/shared/include/hdf_service_status.h b/core/shared/include/hdf_service_status.h
new file mode 100644
index 0000000000000000000000000000000000000000..734c45b3295f5e4e135866ed225f998a77e0008d
--- /dev/null
+++ b/core/shared/include/hdf_service_status.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 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.
+ */
+#ifndef HDF_SERVICE_STATUS_H
+#define HDF_SERVICE_STATUS_H
+
+#include "hdf_types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+struct HdfSBuf;
+struct ServiceStatusListener;
+
+enum ServiceStatusType {
+ SERVIE_STATUS_START,
+ SERVIE_STATUS_CHANGE,
+ SERVIE_STATUS_STOP,
+ SERVIE_STATUS_MAX,
+};
+
+enum ServiceStatusListenerCmd {
+ SERVIE_STATUS_LISTENER_NOTIFY,
+ SERVIE_STATUS_LISTENER_MAX,
+};
+
+struct ServiceStatus {
+ const char* serviceName;
+ uint16_t deviceClass; /* ref to DeviceClass */
+ uint16_t status; /* ref to ServiceStatusType */
+ const char *info;
+};
+
+typedef void (*OnServiceStatusReceived)(struct ServiceStatusListener *, struct ServiceStatus *);
+
+struct ServiceStatusListener {
+ OnServiceStatusReceived callback;
+ void *priv;
+};
+
+int ServiceStatusMarshalling(struct ServiceStatus *status, struct HdfSBuf *buf);
+int ServiceStatusUnMarshalling(struct ServiceStatus *status, struct HdfSBuf *buf);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* HDF_SERVICE_STATUS_H */
\ No newline at end of file
diff --git a/core/shared/include/hdf_usb_pnp_manage.h b/core/shared/include/hdf_usb_pnp_manage.h
old mode 100644
new mode 100755
index e22f7cb1d1978c4f64918920f5d038875df298d2..6a28645102e0667a6d817e0e65a91c1e2468fa76
--- a/core/shared/include/hdf_usb_pnp_manage.h
+++ b/core/shared/include/hdf_usb_pnp_manage.h
@@ -26,6 +26,9 @@ enum UsbPnpNotifyServiceCmd {
#endif
USB_PNP_DRIVER_REGISTER_DEVICE,
USB_PNP_DRIVER_UNREGISTER_DEVICE,
+ USB_PNP_DRIVER_GETDEVICES = 20,
+ USB_PNP_DRIVER_GADGET_ADD = 30,
+ USB_PNP_DRIVER_GADGET_REMOVE,
};
enum UsbPnpNotifyRemoveType {
@@ -78,7 +81,7 @@ struct UsbPnpNotifyDeviceInfo {
};
struct UsbPnpNotifyMatchInfoTable {
- uint32_t usbDevAddr;
+ uintptr_t usbDevAddr;
int32_t devNum;
int32_t busNum;
diff --git a/core/shared/include/ioservstat_listener.h b/core/shared/include/ioservstat_listener.h
new file mode 100644
index 0000000000000000000000000000000000000000..b7b9a8caf9430fdef84a227ce604a48091b3c8cd
--- /dev/null
+++ b/core/shared/include/ioservstat_listener.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef HDF_IOSERVICE_STATUS_LISTENER_H
+#define HDF_IOSERVICE_STATUS_LISTENER_H
+
+#include "hdf_dlist.h"
+#include "hdf_io_service_if.h"
+#include "hdf_service_status.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+struct IoServiceStatusListener {
+ struct ServiceStatusListener svcstatListener;
+ struct HdfDevEventlistener ioservListener;
+ struct DListHead node;
+ uint16_t deviceClass;
+};
+
+struct ServiceStatusListener *IoServiceStatusListenerNewInstance(void);
+void IoServiceStatusListenerFree(struct ServiceStatusListener *listener);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif // HDF_IOSERVICE_STATUS_LISTENER_H
diff --git a/core/shared/include/power_state_token_if.h b/core/shared/include/power_state_token_if.h
index 0e054c01ae1515669e6b829421d6e45363e09800..c1af0b70ed5b38066a95dea16034753bf2e694cb 100644
--- a/core/shared/include/power_state_token_if.h
+++ b/core/shared/include/power_state_token_if.h
@@ -9,6 +9,10 @@
#ifndef POWER_STATE_TOKEN_IF_H
#define POWER_STATE_TOKEN_IF_H
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
typedef enum {
PSM_STATE_IDLE, /* Idle state */
PSM_STATE_ACTIVE, /* Activated state */
@@ -20,4 +24,8 @@ struct IPowerStateToken {
void (*ReleaseWakeLock)(struct IPowerStateToken *);
};
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
#endif /* POWER_STATE_TOKEN_IF_H */
\ No newline at end of file
diff --git a/core/shared/include/svcmgr_ioservice.h b/core/shared/include/svcmgr_ioservice.h
new file mode 100644
index 0000000000000000000000000000000000000000..6886189c5356a69c04e8a2e791e95cda7606c98c
--- /dev/null
+++ b/core/shared/include/svcmgr_ioservice.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef DEVSVC_SVCMGR_IOSERVICE_H
+#define DEVSVC_SVCMGR_IOSERVICE_H
+
+#include "hdf_base.h"
+#include "hdf_service_status.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#define DEV_SVCMGR_NODE "devsvc_mgr"
+
+enum SvcMgrIoCmd {
+ SVCMGR_REGISTER_LISTENER ,
+ SVCMGR_UNREGISTER_LISTENER,
+};
+
+struct ISvcMgrIoservice {
+ int32_t (*RegisterServiceStatusListener)(struct ISvcMgrIoservice *self,
+ struct ServiceStatusListener *listener, uint16_t deviceClass);
+ int32_t (*UnregisterServiceStatusListener)(struct ISvcMgrIoservice *self,
+ struct ServiceStatusListener *listener);
+};
+
+struct ISvcMgrIoservice *SvcMgrIoserviceGet(void);
+void SvcMgrIoserviceRelease(struct ISvcMgrIoservice *svcmgr);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif // DEVSVC_SVCMGR_IOSERVICE_H
\ No newline at end of file
diff --git a/core/shared/src/hdf_device_info.c b/core/shared/src/hdf_device_info.c
old mode 100755
new mode 100644
index 1fc5ac93d3b05acd3206decacc3135904f7cf900..a691edcf8a32e0c7cfe4c90b8c3738da638fb8f4
--- a/core/shared/src/hdf_device_info.c
+++ b/core/shared/src/hdf_device_info.c
@@ -18,7 +18,6 @@ void HdfDeviceInfoConstruct(struct HdfDeviceInfo *deviceInfo)
return;
}
deviceInfo->isDynamic = false;
- deviceInfo->hostId = 0;
deviceInfo->status = HDF_SERVICE_UNUSABLE;
deviceInfo->deviceType = HDF_DEV_LOCAL_SERVICE;
deviceInfo->deviceId = 0;
@@ -29,7 +28,6 @@ void HdfDeviceInfoConstruct(struct HdfDeviceInfo *deviceInfo)
deviceInfo->svcName = NULL;
deviceInfo->moduleName = NULL;
deviceInfo->deviceMatchAttr = NULL;
- deviceInfo->private = NULL;
}
struct HdfDeviceInfo *HdfDeviceInfoNewInstance()
@@ -40,19 +38,13 @@ struct HdfDeviceInfo *HdfDeviceInfoNewInstance()
HdfDeviceInfoConstruct(deviceInfo);
return deviceInfo;
}
- HDF_LOGE("Create device deviceInfo failed");
+ HDF_LOGE("failed to create deviceInfo, oom");
return NULL;
}
void HdfDeviceInfoFreeInstance(struct HdfDeviceInfo *deviceInfo)
{
if (deviceInfo != NULL) {
- if (deviceInfo->isDynamic && deviceInfo->svcName != NULL) {
- OsalMemFree((void *)deviceInfo->svcName);
- }
- if (deviceInfo->private != NULL) {
- OsalMemFree((void *)deviceInfo->private);
- }
OsalMemFree(deviceInfo);
}
}
diff --git a/core/shared/src/hdf_service_record.c b/core/shared/src/hdf_service_record.c
index ebc9c38966eaee8a40a6495ceb6ad79b938851fd..138648b27e9c2d49c999db9b1f4d7c59de863bab 100644
--- a/core/shared/src/hdf_service_record.c
+++ b/core/shared/src/hdf_service_record.c
@@ -17,13 +17,9 @@ struct DevSvcRecord *DevSvcRecordNewInstance(void)
void DevSvcRecordFreeInstance(struct DevSvcRecord *inst)
{
if (inst != NULL) {
+ OsalMemFree((char *)inst->servName);
+ OsalMemFree((char *)inst->servInfo);
OsalMemFree(inst);
}
}
-void DevSvcRecordDelete(struct HdfSListNode *listEntry)
-{
- if (listEntry != NULL) {
- OsalMemFree(listEntry);
- }
-}
diff --git a/core/shared/src/ioserstat_listener.c b/core/shared/src/ioserstat_listener.c
new file mode 100644
index 0000000000000000000000000000000000000000..b592c200dc45ecfd9ece2527d422893e1a7bdb30
--- /dev/null
+++ b/core/shared/src/ioserstat_listener.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 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 "ioservstat_listener.h"
+#include "osal_mem.h"
+
+static int OnIoServiceEventReceive(
+ struct HdfDevEventlistener *listener, struct HdfIoService *service, uint32_t id, struct HdfSBuf *data)
+{
+ if (listener == NULL || service == NULL || data == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ (void)id;
+ struct ServiceStatus status = { 0 };
+ if (ServiceStatusUnMarshalling(&status, data) != HDF_SUCCESS) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ struct IoServiceStatusListener *statusListener = listener->priv;
+ if (statusListener->svcstatListener.callback != NULL &&
+ (statusListener->deviceClass & status.deviceClass)) {
+ statusListener->svcstatListener.callback(&statusListener->svcstatListener, &status);
+ }
+
+ return HDF_SUCCESS;
+}
+
+struct ServiceStatusListener *IoServiceStatusListenerNewInstance(void)
+{
+ struct IoServiceStatusListener *listener = OsalMemCalloc(sizeof(struct IoServiceStatusListener));
+ if (listener == NULL) {
+ return NULL;
+ }
+
+ listener->ioservListener.onReceive = OnIoServiceEventReceive;
+ listener->ioservListener.priv = (void *)listener;
+
+ return &listener->svcstatListener;
+}
+
+void IoServiceStatusListenerFree(struct ServiceStatusListener *listener)
+{
+ if (listener == NULL) {
+ return;
+ }
+ struct IoServiceStatusListener *ioservListener
+ = CONTAINER_OF(listener, struct IoServiceStatusListener, svcstatListener);
+ OsalMemFree(ioservListener);
+}
\ No newline at end of file
diff --git a/core/shared/src/service_status.c b/core/shared/src/service_status.c
new file mode 100644
index 0000000000000000000000000000000000000000..5e6ef8abf39b43ad83d4cb99197a57cb41e09a6c
--- /dev/null
+++ b/core/shared/src/service_status.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 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 "hdf_log.h"
+#include "hdf_sbuf.h"
+#include "hdf_service_status.h"
+
+int ServiceStatusMarshalling(struct ServiceStatus *status, struct HdfSBuf *buf)
+{
+ if (status == NULL || buf == NULL || status->serviceName == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ if (!HdfSbufWriteString(buf, status->serviceName)
+ || !HdfSbufWriteUint16(buf, status->deviceClass)
+ || !HdfSbufWriteUint16(buf, status->status)
+ || !HdfSbufWriteString(buf, status->info != NULL ? status->info : "")) {
+ HDF_LOGI("failed to marshalling service status");
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+int ServiceStatusUnMarshalling(struct ServiceStatus *status, struct HdfSBuf *buf)
+{
+
+ if (status == NULL || buf == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ status->serviceName = HdfSbufReadString(buf);
+ if (status->serviceName == NULL) {
+ HDF_LOGI("failed to unmarshalling service status, service name is null");
+ return HDF_FAILURE;
+ }
+
+ if (!HdfSbufReadUint16(buf, &status->deviceClass) || !HdfSbufReadUint16(buf, &status->status)) {
+ HDF_LOGI("failed to unmarshalling service status, deviceClass or status invalid");
+ return HDF_FAILURE;
+ }
+
+ status->info = HdfSbufReadString(buf);
+ return HDF_SUCCESS;
+}
diff --git a/core/shared/src/svcmgr_ioservice.c b/core/shared/src/svcmgr_ioservice.c
new file mode 100644
index 0000000000000000000000000000000000000000..363dc1bc0e67209260f02cc94e9fc794698edb23
--- /dev/null
+++ b/core/shared/src/svcmgr_ioservice.c
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 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 "svcmgr_ioservice.h"
+#include "hdf_base.h"
+#include "hdf_dlist.h"
+#include "hdf_io_service_if.h"
+#include "hdf_log.h"
+#include "hdf_sbuf.h"
+#include "ioservstat_listener.h"
+#include "osal_mem.h"
+
+struct SvcMgrIoservice {
+ struct ISvcMgrIoservice svcmgr;
+ struct HdfIoService *iosvc;
+ struct DListHead listeners;
+};
+
+static int32_t SetListenClass(struct SvcMgrIoservice *svcmgrInst, uint16_t devClass)
+{
+ struct HdfSBuf *data = HdfSBufObtainDefaultSize();
+ if (data == NULL) {
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ (void)HdfSbufWriteUint16(data, devClass);
+ if (svcmgrInst->iosvc == NULL || svcmgrInst->iosvc->dispatcher == NULL
+ || svcmgrInst->iosvc->dispatcher->Dispatch == NULL) {
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ return svcmgrInst->iosvc->dispatcher->Dispatch(
+ (struct HdfObject *)svcmgrInst->iosvc, SVCMGR_REGISTER_LISTENER, data, NULL);
+}
+
+static int32_t UnSetListenClass(struct SvcMgrIoservice *svcmgrInst, uint16_t devClass)
+{
+ struct HdfSBuf *data = HdfSBufObtainDefaultSize();
+ if (data == NULL) {
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ (void)HdfSbufWriteUint16(data, devClass);
+ if (svcmgrInst->iosvc == NULL || svcmgrInst->iosvc->dispatcher == NULL
+ || svcmgrInst->iosvc->dispatcher->Dispatch == NULL) {
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ return svcmgrInst->iosvc->dispatcher->Dispatch(
+ (struct HdfObject *)svcmgrInst->iosvc, SVCMGR_UNREGISTER_LISTENER, data, NULL);
+}
+
+int32_t SvcMgrIoserviceRegSvcStatListener(
+ struct ISvcMgrIoservice *self, struct ServiceStatusListener *listener, uint16_t deviceClass)
+{
+ if (self == NULL || listener == NULL || deviceClass >= DEVICE_CLASS_MAX) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ struct SvcMgrIoservice *svcmgrInst = CONTAINER_OF(self, struct SvcMgrIoservice, svcmgr);
+ struct IoServiceStatusListener *listenerInst
+ = CONTAINER_OF(listener, struct IoServiceStatusListener, svcstatListener);
+
+ listenerInst->deviceClass = deviceClass;
+ int ret = SetListenClass(svcmgrInst, deviceClass);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("failed to set listen class");
+ return ret;
+ }
+
+ return HdfDeviceRegisterEventListener(svcmgrInst->iosvc, &listenerInst->ioservListener);
+}
+
+int32_t SvcMgrIoserviceUnRegSvcStatListener(struct ISvcMgrIoservice *self, struct ServiceStatusListener *listener)
+{
+ if (self == NULL || listener == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ struct SvcMgrIoservice *svcmgrInst = CONTAINER_OF(self, struct SvcMgrIoservice, svcmgr);
+ struct IoServiceStatusListener *listenerInst
+ = CONTAINER_OF(listener, struct IoServiceStatusListener, svcstatListener);
+
+ int ret = HdfDeviceUnregisterEventListener(svcmgrInst->iosvc, &listenerInst->ioservListener);
+ if (ret != HDF_SUCCESS) {
+ return ret;
+ }
+
+ if (HdfIoserviceGetListenerCount(svcmgrInst->iosvc) == 0) {
+ ret = UnSetListenClass(svcmgrInst, listenerInst->deviceClass);
+ }
+
+ return ret;
+}
+
+static void SvcMgrIoserviceConstruct(struct ISvcMgrIoservice *svcmgrInst)
+{
+ svcmgrInst->RegisterServiceStatusListener = SvcMgrIoserviceRegSvcStatListener;
+ svcmgrInst->UnregisterServiceStatusListener = SvcMgrIoserviceUnRegSvcStatListener;
+}
+
+struct ISvcMgrIoservice *SvcMgrIoserviceGet(void)
+{
+ struct SvcMgrIoservice *svcmgrInst = OsalMemCalloc(sizeof(struct SvcMgrIoservice));
+ if (svcmgrInst == NULL) {
+ return NULL;
+ }
+
+ svcmgrInst->iosvc = HdfIoServiceBind(DEV_SVCMGR_NODE);
+ if (svcmgrInst->iosvc == NULL) {
+ HDF_LOGE("ioserivce %s not exist", DEV_SVCMGR_NODE);
+ OsalMemFree(svcmgrInst);
+ return NULL;
+ }
+ SvcMgrIoserviceConstruct(&svcmgrInst->svcmgr);
+ return &svcmgrInst->svcmgr;
+}
+
+void SvcMgrIoserviceRelease(struct ISvcMgrIoservice *svcmgr)
+{
+ if (svcmgr == NULL) {
+ return;
+ }
+ struct SvcMgrIoservice *svcmgrInst = CONTAINER_OF(svcmgr, struct SvcMgrIoservice, svcmgr);
+ HdfIoServiceRecycle(svcmgrInst->iosvc);
+ OsalMemFree(svcmgrInst);
+}
\ No newline at end of file
diff --git a/include/audio/audio_accessory_if.h b/include/audio/audio_accessory_if.h
index a86532d2d329b26642f974bd2dbb2b48d2df6a4a..6f7ebaf388dc4a49fd86f5914b629d7abb6f6130 100755
--- a/include/audio/audio_accessory_if.h
+++ b/include/audio/audio_accessory_if.h
@@ -18,39 +18,85 @@ extern "C" {
#endif
#endif /* __cplusplus */
+/**
+ * @brief Defines Accessory Codec device name and data.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
struct AccessoryDevice {
- const char *devAccessoryName;
- struct AccessoryData *devData;
- struct HdfDeviceObject *device;
- struct DListHead list;
- struct OsalMutex mutex;
-};
-
-struct AudioAccessoryOps {
- const char *devAccessoryName;
- struct AccessoryData *devData;
- struct HdfDeviceObject *device;
- struct DListHead list;
+ const char *devAccessoryName; /**< Accesssory device name */
+ struct AccessoryData *devData; /**< Accesssory private data */
+ struct HdfDeviceObject *device; /**< HDF device */
+ struct DListHead list; /**< Accesssory list */
+ struct OsalMutex mutex; /**< Accesssory mutex */
};
-/* Accessory host is defined in accessory driver */
+/**
+ * @brief Defines Accessory host in audio driver.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
struct AccessoryHost {
- struct IDeviceIoService service; // accessory service
- struct HdfDeviceObject *device; // accessory deovce
- void *priv; // accessory private data
+ struct IDeviceIoService service; /**< Services provided by Accesssory */
+ struct HdfDeviceObject *device; /**< HDF device */
+ void *priv; /**< Accesssory private data interface */
};
+/**
+ * @brief Defines Accesssory private data.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
struct AccessoryData {
- const char *drvAccessoryName;
- /* Accessory driver callbacks */
- int32_t (*Init)(struct AudioCard *, const struct AccessoryDevice *device);
- int32_t (*Read)(const struct AccessoryDevice *, uint32_t, uint32_t *);
- int32_t (*Write)(const struct AccessoryDevice *, uint32_t, uint32_t);
- int32_t (*AiaoRead)(const struct AccessoryDevice *, uint32_t, uint32_t *);
- int32_t (*AiaoWrite)(const struct AccessoryDevice *, uint32_t, uint32_t);
-
- const struct AudioKcontrol *controls;
- int numControls;
+ const char *drvAccessoryName; /**< Accesssory driver name */
+
+ /**
+ * @brief Defines Accesssory device init.
+ *
+ * @param audioCard Indicates a audio card device.
+ * @param accesssory Indicates a Accesssory device.
+ *
+ * @return Returns 0 if Accesssory device init success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*Init)(struct AudioCard *audioCard, const struct AccessoryDevice *accesssory);
+
+ /**
+ * @brief Defines Accesssory device reg read.
+ *
+ * @param accesssory Indicates a accesssory device.
+ * @param reg Indicates read reg address.
+ * @param value Indicates read reg value.
+ *
+ * @return Returns 0 if accesssory device read reg success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*Read)(const struct AccessoryDevice *accesssory, uint32_t reg, uint32_t *value);
+
+ /**
+ * @brief Defines accesssory device reg write.
+ *
+ * @param accesssory Indicates a accesssory device.
+ * @param reg Indicates write reg address.
+ * @param value Indicates write reg value.
+ *
+ * @return Returns 0 if accesssory device write reg success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*Write)(const struct AccessoryDevice *accesssory, uint32_t reg, uint32_t value);
+
+ const struct AudioKcontrol *controls; /**< Accesssory control structure array pointer */
+ int numControls; /**< Accesssory controls the number of structure array elements */
+ struct AudioRegCfgData* regConfig; /**< Accesssory registers configured in HCS */
};
#ifdef __cplusplus
diff --git a/include/audio/audio_codec_if.h b/include/audio/audio_codec_if.h
index d0636abb4f266dd0f358612267a51dcc5a85ac79..5ebe453bdf63fa329d05982de1fd0c410d25e4e8 100755
--- a/include/audio/audio_codec_if.h
+++ b/include/audio/audio_codec_if.h
@@ -18,70 +18,91 @@ extern "C" {
#endif
#endif /* __cplusplus */
-#define AUDIODRV_CTL_ELEM_IFACE_DAC 0 /* virtual dac device */
-#define AUDIODRV_CTL_ELEM_IFACE_ADC 1 /* virtual adc device */
-#define AUDIODRV_CTL_ELEM_IFACE_GAIN 2 /* virtual adc device */
-#define AUDIODRV_CTL_ELEM_IFACE_MIXER 3 /* virtual mixer device */
-#define AUDIODRV_CTL_ELEM_IFACE_ACODEC 4 /* Acodec device */
-#define AUDIODRV_CTL_ELEM_IFACE_PGA 5 /* PGA device */
-#define AUDIODRV_CTL_ELEM_IFACE_AIAO 6 /* AIAO device */
-
-struct VirtualAddress {
- unsigned long acodecVir;
- unsigned long aiaoVir;
-};
-
+/**
+ * @brief Defines Codec device name and data.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
struct CodecDevice {
- const char *devCodecName;
- struct CodecData *devData;
- struct HdfDeviceObject *device;
- struct DListHead list;
- struct OsalMutex mutex;
+ const char *devCodecName; /**< Codec device name */
+ struct CodecData *devData; /**< Codec module private data */
+ struct HdfDeviceObject *device; /**< HDF device */
+ struct DListHead list; /**< Codec list */
+ struct OsalMutex mutex; /**< Codec mutex */
};
-/* codec related definitions */
+/**
+ * @brief Defines Codec private data.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
struct CodecData {
- const char *drvCodecName;
- /* Codec driver callbacks */
- int32_t (*Init)(struct AudioCard *, struct CodecDevice *);
- int32_t (*Read)(const struct CodecDevice *, uint32_t, uint32_t *);
- int32_t (*Write)(const struct CodecDevice *, uint32_t, uint32_t);
- int32_t (*AiaoRead)(const struct CodecDevice *, uint32_t, uint32_t *);
- int32_t (*AiaoWrite)(const struct CodecDevice *, uint32_t, uint32_t);
- const struct AudioKcontrol *controls;
- int numControls;
- const struct AudioSapmComponent *sapmComponents;
- int numSapmComponent;
- const struct AudioSapmRoute *sapmRoutes;
- int numSapmRoutes;
-};
+ const char *drvCodecName; /**< Codec driver name */
-/* Codec host is defined in codec driver */
-struct CodecHost {
- struct IDeviceIoService service;
- struct HdfDeviceObject *device;
- unsigned long priv;
- unsigned long aiaoPriv;
-};
+ /**
+ * @brief Defines Codec device init.
+ *
+ * @param audioCard Indicates a audio card device.
+ * @param codec Indicates a codec device.
+ *
+ * @return Returns 0 if codec device init success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*Init)(struct AudioCard *audioCard, const struct CodecDevice *codec);
+
+ /**
+ * @brief Defines Codec device reg read.
+ *
+ * @param virtualAddress Indicates base reg IoRemap address.
+ * @param reg Indicates reg offset.
+ * @param value Indicates read reg value.
+ *
+ * @return Returns 0 if codec device read reg success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*Read)(unsigned long virtualAddress, uint32_t reg, uint32_t *value);
+
+ /**
+ * @brief Defines Codec device reg write.
+ *
+ * @param virtualAddress Indicates base reg IoRemap address.
+ * @param reg Indicates reg offset.
+ * @param value Indicates write reg value.
+ *
+ * @return Returns 0 if codec device write reg success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*Write)(unsigned long virtualAddress, uint32_t reg, uint32_t value);
-enum AudioRegParams {
- PLAYBACK_VOLUME = 0,
- CAPTURE_VOLUME,
- PLAYBACK_MUTE,
- CAPTURE_MUTE,
- LEFT_GAIN,
- RIGHT_GAIN,
- EXTERNAL_CODEC_ENABLE,
- INTERNALLY_CODEC_ENABLE,
- RENDER_CHANNEL_MODE,
- CAPTRUE_CHANNEL_MODE,
+ struct AudioKcontrol *controls; /**< Codec control structure array pointer */
+ int numControls; /**< Number of array elements of Codec controls */
+ struct AudioSapmComponent *sapmComponents; /**< Codec power management component array pointer */
+ int numSapmComponent; /**< Number of array elements of codec power management component */
+ const struct AudioSapmRoute *sapmRoutes; /**< Codec power management route array pointer */
+ int numSapmRoutes; /**< Number of power management route array elements */
+ unsigned long virtualAddress; /**< Codec base reg IoRemap address */
+ struct AudioRegCfgData *regConfig; /**< Codec registers configured in HCS */
+ struct AudioRegCfgGroupNode **regCfgGroup; /**< Codec register group configured in HCS */
};
-enum SapmRegParams {
- LPGA_MIC = 0,
- RPGA_MIC,
- DACL2DACR,
- DACR2DACL,
+/**
+ * @brief Defines Codec host in audio driver.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+struct CodecHost {
+ struct IDeviceIoService service; /**< Services provided by codec */
+ struct HdfDeviceObject *device; /**< HDF device */
+ void *priv; /**< Codec private data interface */
};
#ifdef __cplusplus
diff --git a/include/audio/audio_dai_if.h b/include/audio/audio_dai_if.h
index f6e756edf903ea7a95e21f1da0d58a64f11f7561..eae35f2e6fa8454490c4dc232591442982af2aa5 100755
--- a/include/audio/audio_dai_if.h
+++ b/include/audio/audio_dai_if.h
@@ -9,39 +9,148 @@
#ifndef AUDIO_DAI_IF_H
#define AUDIO_DAI_IF_H
+#include "audio_host.h"
+#include "audio_parse.h"
+#include "audio_control.h"
+
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
+/**
+ * @brief Defines Dai device name and data.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
struct DaiDevice {
- const char *devDaiName;
- struct DaiData *devData;
- struct HdfDeviceObject *device;
- struct DListHead list;
+ const char *devDaiName; /**< Dai device name */
+ struct DaiData *devData; /**< Dai module private data */
+ struct HdfDeviceObject *device; /**< HDF device */
+ struct DListHead list; /**< Dai list */
};
+/**
+ * @brief Defines Dai operation function set.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
struct AudioDaiOps {
- int32_t (*Startup)(const struct AudioCard *, const struct DaiDevice *);
- int32_t (*HwParams)(const struct AudioCard *, const struct AudioPcmHwParams *, const struct DaiDevice *);
- int32_t (*Trigger)(const struct AudioCard *, int, const struct DaiDevice *);
+ /**
+ * @brief Defines Dai device start up function.
+ *
+ * @param audioCard Indicates a audio card device.
+ * @param dai Indicates a dai device.
+ *
+ * @return Returns 0 if dai device start up success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*Startup)(const struct AudioCard *audioCard, const struct DaiDevice *dai);
+
+ /**
+ * @brief Defines Dai device hardware param set function.
+ *
+ * @param audioCard Indicates a audio card device.
+ * @param param Indicates pcm param set.
+ *
+ * @return Returns 0 if dai pcm param set success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*HwParams)(const struct AudioCard *audioCard, const struct AudioPcmHwParams *param);
+
+ /**
+ * @brief Defines Dai device trigger function.
+ *
+ * @param audioCard Indicates a audio card device.
+ * @param cmd Indicates a Command id.
+ * @param dai Indicates a dai device.
+ *
+ * @return Returns 0 if dai device trigger success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*Trigger)(const struct AudioCard *audioCard, int cmd, const struct DaiDevice *dai);
};
+/**
+ * @brief Defines dai private data.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
struct DaiData {
- const char *drvDaiName;
- /* DAI driver callbacks */
- int32_t (*DaiInit)(const struct AudioCard *, const struct DaiDevice *);
- /* ops */
- const struct AudioDaiOps *ops;
+ const char *drvDaiName; /**< dai driver name */
+
+ /**
+ * @brief Defines Dai device init.
+ *
+ * @param audioCard Indicates a audio card device.
+ * @param dai Indicates a dai device.
+ *
+ * @return Returns 0 if dai device init success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*DaiInit)(struct AudioCard *audioCard, const struct DaiDevice *dai);
+
+ /**
+ * @brief Defines Dai device reg read.
+ *
+ * @param virtualAddress Indicates base reg IoRemap address.
+ * @param reg Indicates reg offset.
+ * @param value Indicates read reg value.
+ *
+ * @return Returns 0 if dai device read reg success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*Read)(unsigned long virtualAddress, uint32_t reg, uint32_t *value);
+
+ /**
+ * @brief Defines Dai device reg write.
+ *
+ * @param virtualAddress Indicates base reg IoRemap address.
+ * @param reg Indicates reg offset.
+ * @param value Indicates write reg value.
+ *
+ * @return Returns 0 if dai device write reg success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*Write)(unsigned long virtualAddress, uint32_t reg, uint32_t value);
+
+ const struct AudioDaiOps *ops; /**< dai set of operation functions */
+ struct PcmInfo pcmInfo; /**< dai pcm info */
+ struct AudioKcontrol *controls; /**< dai control structure array pointer */
+ int numControls; /**< dai controls the number of structure array elements */
+ bool daiInitFlag; /**< dai init flag */
+ unsigned long regVirtualAddr; /**< dai base reg IoRemap address */
+ struct AudioRegCfgData *regConfig; /**< dai registers configured in HCS */
+ struct AudioRegCfgGroupNode **regCfgGroup; /**< dai register group configured in HCS */
+ struct OsalMutex mutex; /**< dai mutex */
};
-/* Dai host is defined in dai driver */
+/**
+ * @brief Defines Dai host in audio driver.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
struct DaiHost {
- struct IDeviceIoService service;
- struct HdfDeviceObject *device;
- void *priv;
- bool daiInitFlag;
+ struct IDeviceIoService service; /**< Services provided by dai */
+ struct HdfDeviceObject *device; /**< HDF device */
+ void *priv; /**< Dai private data interface */
};
#ifdef __cplusplus
diff --git a/include/audio/audio_dsp_if.h b/include/audio/audio_dsp_if.h
index ae72f096bf03e26d215e471fec74174db336a359..8e39def5d9f1b8ffabbd338841fedf8003e016ca 100755
--- a/include/audio/audio_dsp_if.h
+++ b/include/audio/audio_dsp_if.h
@@ -15,35 +15,168 @@ extern "C" {
#endif
#endif /* __cplusplus */
+/**
+ * @brief Defines Dsp device name and data.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
struct DspDevice {
- const char *devDspName;
- struct DspData *devData;
- struct HdfDeviceObject *device;
- struct DListHead list;
+ const char *devDspName; /**< Dsp device name */
+ struct DspData *devData; /**< Dsp module private data */
+ struct HdfDeviceObject *device; /**< HDF device */
+ struct DListHead list; /**< Dsp list */
};
+/**
+ * @brief Defines Dsp operation function set.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
struct AudioDspOps {
- int32_t (*Startup)(const struct AudioCard *, const struct DspDevice *);
- int32_t (*HwParams)(const struct AudioCard *, const struct AudioPcmHwParams *, const struct DspDevice *);
- int32_t (*Trigger)(struct AudioCard *, int, struct DspDevice *);
+ /**
+ * @brief Defines Dsp device start up function.
+ *
+ * @param audioCard Indicates a audio card device.
+ * @param dsp Indicates a dsp device.
+ *
+ * @return Returns 0 if Dsp device start up success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*Startup)(const struct AudioCard *audioCard, const struct DspDevice *dsp);
+
+ /**
+ * @brief Defines Dsp device hardware param function.
+ *
+ * @param audioCard Indicates a audio card device.
+ * @param param Indicates pcm params set.
+ *
+ * @return Returns 0 if dsp param set success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*HwParams)(const struct AudioCard *audioCard, const struct AudioPcmHwParams *param);
+
+ /**
+ * @brief Defines Dsp device trigger function.
+ *
+ * @param audioCard Indicates a audio card device.
+ * @param dsp Indicates a dsp device.
+ *
+ * @return Returns 0 if dsp device trigger success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*Trigger)(struct AudioCard *audioCard, int, struct DspDevice *dsp);
};
-/* Dsp host is defined in dsp driver */
+/**
+ * @brief Defines Dsp host in audio driver.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
struct DspHost {
- struct IDeviceIoService service; // dsp service
- struct HdfDeviceObject *device; // dsp device
- void *priv; // dsp private data
+ struct IDeviceIoService service; /**< Services provided by dsp */
+ struct HdfDeviceObject *device; /**< HDF device */
+ void *priv; /**< Dsp private data interface */
};
+/**
+ * @brief Defines dsp private data.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
struct DspData {
- const char *drvDspName;
- /* dsp driver callbacks */
- int32_t (*DspInit)(const struct DspDevice *device);
- int32_t (*Read)(struct DspDevice *, uint8_t *, uint32_t);
- int32_t (*Write)(struct DspDevice *, uint8_t *, uint32_t);
- int32_t (*decode)(const struct AudioCard *, const uint8_t *, const struct DspDevice *);
- int32_t (*encode)(const struct AudioCard *, const uint8_t *, const struct DspDevice *);
- int32_t (*Equalizer)(const struct AudioCard *, const uint8_t *, const struct DspDevice *);
+ const char *drvDspName; /**< Dsp driver name */
+
+ /**
+ * @brief Defines Dsp device init.
+ *
+ * @param dsp Indicates a Dsp device.
+ *
+ * @return Returns 0 if dsp device init success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*DspInit)(const struct DspDevice *dsp);
+
+ /**
+ * @brief Defines Dsp device msgs read.
+ *
+ * @param dsp Indicates a dsp device.
+ * @param msgs Indicates transfer msgs data.
+ * @param len Indicates msgs length.
+ *
+ * @return Returns 0 if dsp device read msgs success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*Read)(const struct DspDevice *dsp, const void *msgs, const uint32_t len);
+
+ /**
+ * @brief Defines Dsp device msgs write.
+ *
+ * @param dsp Indicates a dsp device.
+ * @param msgs Indicates transfer msgs data.
+ * @param len Indicates msgs length.
+ *
+ * @return Returns 0 if dsp device write msgs success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*Write)(const struct DspDevice *dsp, const void *msgs, const uint32_t len);
+
+ /**
+ * @brief Defines Dsp device decode.
+ *
+ * @param audioCard Indicates a audio card.
+ * @param buf Indicates decode pcm buffer data.
+ * @param dsp Indicates a dsp device.
+ *
+ * @return Returns 0 if Dsp device decode success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*Decode)(const struct AudioCard *audioCard, const uint8_t *buf, const struct DspDevice *dsp);
+
+ /**
+ * @brief Defines Dsp device encode.
+ *
+ * @param audioCard audioCard Indicates a audio card.
+ * @param buf Indicates encode pcm buffer data.
+ * @param dsp Indicates a dsp device.
+ *
+ * @return Returns 0 if Dsp device encode success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*Encode)(const struct AudioCard *audioCard, const uint8_t *buf, const struct DspDevice *dsp);
+
+ /**
+ * @brief Defines Dsp device equalizer.
+ *
+ * @param audioCard audioCard Indicates a audio card.
+ * @param buf Indicates equalizer pcm buffer data.
+ * @param dsp Indicates a dsp device.
+ *
+ * @return Returns 0 if Dsp device equalizer success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*Equalizer)(const struct AudioCard *audioCard, const uint8_t *buf, const struct DspDevice *dsp);
};
#ifdef __cplusplus
diff --git a/include/audio/audio_platform_if.h b/include/audio/audio_platform_if.h
index 6ac044d686358c1458b922746264d98908d2753b..bb6e09896ff01093c3a67cca8c5311fa7fa882c1 100755
--- a/include/audio/audio_platform_if.h
+++ b/include/audio/audio_platform_if.h
@@ -10,6 +10,7 @@
#define AUDIO_PLATFORM_IF_H
#include "audio_host.h"
+#include "audio_platform_base.h"
#ifdef __cplusplus
#if __cplusplus
@@ -17,121 +18,194 @@ extern "C" {
#endif
#endif /* __cplusplus */
-#define I2S_IOCFG2_BASE1 0x0020
-#define I2S_IOCFG2_BASE2 0x0024
-#define I2S_IOCFG2_BASE3 0x0028
-#define I2S_IOCFG2_BASE4 0x002C
-#define I2S_IOCFG2_BASE5 0x0030
-
-#define I2S_IOCFG2_BASE1_VAL 0x663
-#define I2S_IOCFG2_BASE2_VAL 0x673
-#define I2S_IOCFG2_BASE3_VAL 0x573
-#define I2S_IOCFG2_BASE4_VAL 0x473
-#define I2S_IOCFG2_BASE5_VAL 0x433
-
-#define I2S_IOCFG3_BASE1 0x44
-#define I2S_IOCFG3_BASE1_VAL 0x0600
-
-#define GPIO_BASE1 0x2010
-#define GPIO_BASE2 0x2400
-#define GPIO_BASE3 0x2010
-
-#define GPIO_BASE2_VAL 0x000000ff
-#define GPIO_BASE3_VAL 0x00000000
-
-#define IOCFG2_BASE_ADDR 0x112F0000
-#define IOCFG3_BASE_ADDR 0x10FF0000
-#define GPIO_BASE_ADDR 0x120D0000
-#define BASE_ADDR_REMAP_SIZE 0x10000
-
-struct CircleBufInfo {
- uint32_t cirBufSize;
- uint32_t trafBufSize;
- uint32_t period;
- uint32_t periodSize;
- uint32_t periodCount;
- unsigned long phyAddr;
- uint32_t *virtAddr;
- uint32_t wbufOffSet;
- uint32_t wptrOffSet;
- uint32_t runStatus;
- uint32_t chnId;
- uint32_t enable;
- struct OsalMutex buffMutex;
- uint64_t framesPosition;
-};
-
-struct PcmInfo {
- /* The number of channels in a frame */
- uint32_t channels;
- /* The number of frames per second */
- uint32_t rate;
- uint32_t bitWidth;
- uint32_t frameSize;
- bool isBigEndian;
- bool isSignedData;
- uint32_t startThreshold;
- uint32_t stopThreshold;
- uint32_t silenceThreshold;
- uint32_t totalStreamSize;
+/**
+ * @brief Defines paltform private data.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+struct PlatformData {
+ const char *drvPlatformName; /**< Platform module name */
+
+ /**
+ * @brief Defines platform device init.
+ *
+ * @param audioCard Indicates a audio card device.
+ * @param platform Indicates a platform device.
+ *
+ * @return Returns 0 if Platform device init success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*PlatformInit)(const struct AudioCard *audioCard, const struct PlatformDevice *platform);
+
+ struct AudioDmaOps *ops; /**< Platform module private data */
+ struct CircleBufInfo renderBufInfo; /**< Render pcm stream transfer */
+ struct CircleBufInfo captureBufInfo; /**< Capture pcm stream transfer */
+ struct PcmInfo pcmInfo; /**< Pcm stream info */
+ bool platformInitFlag; /**< Platform init flag */
+ struct AudioMmapData mmapData; /**< Mmap mode transfer data */
+ uint32_t mmapLoopCount; /**< Loop count for mmap mode pcm stream */
+ void *dmaPrv; /**< Platform dma private data */
};
-/* platform related definitions */
-struct AudioPlatformOps {
- int32_t (*HwParams)(const struct AudioCard *, const struct AudioPcmHwParams *);
- int32_t (*RenderTrigger)(struct AudioCard *, int);
- int32_t (*CaptureTrigger)(struct AudioCard *, int);
- uint32_t (*Pointer)(struct AudioCard *);
- int32_t (*Write)(const struct AudioCard *, struct AudioTxData *);
- int32_t (*Read)(const struct AudioCard *, struct AudioRxData *);
- int32_t (*MmapWrite)(const struct AudioCard *, struct AudioTxMmapData *);
- int32_t (*MmapRead)(const struct AudioCard *, struct AudioRxMmapData *);
- int32_t (*RenderPrepare)(const struct AudioCard *);
- int32_t (*CapturePrepare)(const struct AudioCard *);
- int32_t (*RenderStart)(struct AudioCard *);
- int32_t (*CaptureStart)(struct AudioCard *);
- int32_t (*RenderStop)(struct AudioCard *);
- int32_t (*CaptureStop)(struct AudioCard *);
- int32_t (*RenderPause)(struct AudioCard *);
- int32_t (*CapturePause)(struct AudioCard *);
- int32_t (*RenderResume)(struct AudioCard *);
- int32_t (*CaptureResume)(struct AudioCard *);
+/**
+ * @brief Defines Dma operation function set.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+struct AudioDmaOps {
+ /**
+ * @brief Defines Dma buff alloc.
+ *
+ * @param platformData Indicates dma device.
+ * @param streamType Indicates capture or render.
+ *
+ * @return Returns 0 if dma buffer alloc success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*DmaBufAlloc)(struct PlatformData *platformData, const enum AudioStreamType streamType);
+
+ /**
+ * @brief Defines dma buffer free.
+ *
+ * @param platformData Indicates dma device.
+ * @param streamType Indicates capture or render.
+ *
+ * @return Returns 0 if dma buffer free success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*DmaBufFree)(struct PlatformData *platformData, const enum AudioStreamType streamType);
+
+ /**
+ * @brief Defines dma request channel.
+ *
+ * @param platformData Indicates dma device.
+ *
+ * @return Returns 0 if dma request channel success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*DmaRequestChannel)(const struct PlatformData *platformData);
+
+ /**
+ * @brief Defines dma channel config.
+ *
+ * @param platformData Indicates dma device.
+ *
+ * @return Returns 0 if dma channel config set success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*DmaConfigChannel)(const struct PlatformData *platformData);
+
+ /**
+ * @brief Defines dma prepare function.
+ *
+ * @param platformData Indicates dma device.
+ *
+ * @return Returns 0 if dma device prep set success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*DmaPrep)(const struct PlatformData *platformData);
+
+ /**
+ * @brief Defines dma submit function.
+ *
+ * @param platformData Indicates dma device.
+ *
+ * @return Returns 0 if dma device submit succes; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*DmaSubmit)(const struct PlatformData *platformData);
+
+ /**
+ * @brief Defines dma pending function.
+ *
+ * @param platformData Indicates dma device.
+ *
+ * @return Returns 0 if dma pending success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*DmaPending)(struct PlatformData *platformData);
+
+ /**
+ * @brief Defines pcm stream transfer pause.
+ *
+ * @param platformData Indicates dma device.
+ *
+ * @return Returns 0 if pcm stream transfer pause success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*DmaPause)(struct PlatformData *platformData);
+
+ /**
+ * @brief Defines pcm stream transfer resume.
+ *
+ * @param platformData Indicates dma device.
+ *
+ * @return Returns 0 if pcm stream transfer resume success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*DmaResume)(const struct PlatformData *platformData);
+
+ /**
+ * @brief Defines Get the function of the current playback or recording position.
+ *
+ * @param platformData Indicates dma device.
+ * @param pointer Indicates dma pointer.
+ *
+ * @return Returns 0 if dma device pointer position get success; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+ int32_t (*DmaPointer)(struct PlatformData *platformData, uint32_t *pointer);
};
+/**
+ * @brief Defines Dai device name and data.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
struct PlatformDevice {
- const char *devPlatformName;
- struct PlatformData *devData;
- struct HdfDeviceObject *device;
- struct DListHead list;
-};
-
-struct PlatformData {
- const char *drvPlatformName;
- /* platform driver callbacks */
- int32_t (*PlatformInit)(const struct AudioCard *, const struct PlatformDevice *);
- /* pcm creation and destruction */
- int32_t (*PcmNew)(struct PlatformDevice *);
- void (*PcmFree)(struct PlatformDevice *);
- /* platform stream ops */
- struct AudioPlatformOps *ops;
+ const char *devPlatformName; /**< Platform device name */
+ struct PlatformData *devData; /**< Platform module private data */
+ struct HdfDeviceObject *device; /**< HDF device */
+ struct DListHead list; /**< Platform list */
};
-/* Platform host is defined in platform driver */
+/**
+ * @brief Defines Platform host in audio driver.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
struct PlatformHost {
- struct IDeviceIoService service;
- struct HdfDeviceObject *device;
- void *priv;
- bool platformInitFlag;
- struct CircleBufInfo renderBufInfo;
- struct CircleBufInfo captureBufInfo;
- struct PcmInfo pcmInfo;
+ struct IDeviceIoService service; /**< Services provided by patform */
+ struct HdfDeviceObject *device; /**< HDF device */
+ void *priv; /**< Platform private data interface */
};
-static inline struct PlatformHost *PlatformHostFromDevice(struct HdfDeviceObject *device)
-{
- return (device == NULL) ? NULL : (struct PlatformHost *)device->service;
-}
-
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/include/core/hdf_io_service_if.h b/include/core/hdf_io_service_if.h
index 9dc9fd9011d82cd7997ff498a1fd0dcd8a4646b9..16aa780593b171c304b7d62b539bef41de839e3e 100644
--- a/include/core/hdf_io_service_if.h
+++ b/include/core/hdf_io_service_if.h
@@ -47,18 +47,15 @@ struct HdfIoService;
* @since 1.0
*/
typedef enum {
- /** Default device */
- DEVICE_CLASS_DEFAULT = 0,
- /** Platform device */
- DEVICE_CLASS_PAL,
- /** Sensor device */
- DEVICE_CLASS_SENSOR,
- /** Input device */
- DEVICE_CLASS_INPUT,
- /** Display device */
- DEVICE_CLASS_DISPLAY,
- /** Maximum value of a device class */
- DEVICE_CLASS_MAX
+ DEVICE_CLASS_DEFAULT = 0x1 << 0, /** Default device */
+ DEVICE_CLASS_PALT = 0x1 << 1, /** Platform device */
+ DEVICE_CLASS_SENSOR = 0x1 << 2, /** Sensor device */
+ DEVICE_CLASS_INPUT = 0x1 << 3, /** Input device */
+ DEVICE_CLASS_DISPLAY = 0x1 << 4, /** Display device */
+ DEVICE_CLASS_AUDIO = 0x1 << 5, /** Audio device */
+ DEVICE_CLASS_CAMERA = 0x1 << 6, /** Camera device */
+ DEVICE_CLASS_USB = 0x1 << 7, /** USB device */
+ DEVICE_CLASS_MAX = 0x1 << 8, /** Maximum value of a device class */
} DeviceClass;
/**
@@ -88,8 +85,8 @@ typedef int (*OnEventReceived)(void *priv, uint32_t id, struct HdfSBuf *data);
*
* @since 1.0
*/
-typedef int (*OnDevEventReceive)(struct HdfDevEventlistener *listener,
- struct HdfIoService *service, uint32_t id, struct HdfSBuf *data);
+typedef int (*OnDevEventReceive)(
+ struct HdfDevEventlistener *listener, struct HdfIoService *service, uint32_t id, struct HdfSBuf *data);
/**
* @brief Defines a driver event listener object.
@@ -130,9 +127,9 @@ struct HdfIoService {
/** Pointer to the bound service entity, which is used for framework management. You can ignore it. */
struct HdfObject *target;
/** Service call dispatcher */
- struct HdfIoDispatcher* dispatcher;
+ struct HdfIoDispatcher *dispatcher;
/** Private data of the service */
- void* priv;
+ void *priv;
};
/**
@@ -176,7 +173,6 @@ void HdfIoServiceGroupRecycle(struct HdfIoServiceGroup *group);
*/
int32_t HdfIoServiceGroupAddService(struct HdfIoServiceGroup *group, struct HdfIoService *service);
-
/**
* @brief Removes a driver service object from a specified driver service group.
*
diff --git a/include/core/hdf_pm.h b/include/core/hdf_pm.h
index 1c8412fa46b9fc2d16deabedd3b3c03d9cf9f815..6d6ddbb59c3bee5b682677bada5fb4038ae7040a 100644
--- a/include/core/hdf_pm.h
+++ b/include/core/hdf_pm.h
@@ -38,5 +38,7 @@ int HdfPmRegisterPowerListener(struct HdfDeviceObject *deviceObject, const struc
void HdfPmUnregisterPowerListener(struct HdfDeviceObject *deviceObject, const struct IPowerEventListener *listener);
void HdfPmAcquireDevice(struct HdfDeviceObject *deviceObject);
void HdfPmReleaseDevice(struct HdfDeviceObject *deviceObject);
+void HdfPmAcquireDeviceAsync(struct HdfDeviceObject *deviceObject);
+void HdfPmReleaseDeviceAsync(struct HdfDeviceObject *deviceObject);
void HdfPmSetMode(struct HdfDeviceObject *deviceObject, uint32_t mode);
#endif /* HDF_POWER_MANAGEMENT_H */
diff --git a/include/platform/adc_if.h b/include/platform/adc_if.h
index 79c06a0a0e4761a2e9dca1dea5bc59e4c2a4eb89..33b347131e27179a3b0ea352f72e1a2932d9c36d 100644
--- a/include/platform/adc_if.h
+++ b/include/platform/adc_if.h
@@ -22,7 +22,7 @@ struct AdcIoMsg {
uint32_t channel;
};
-DevHandle AdcOpen(uint32_t num);
+DevHandle AdcOpen(uint32_t number);
void AdcClose(DevHandle handle);
diff --git a/include/platform/dac_if.h b/include/platform/dac_if.h
new file mode 100644
index 0000000000000000000000000000000000000000..84dfeb73ae25dff1f096ed8a18c3be58567df3dc
--- /dev/null
+++ b/include/platform/dac_if.h
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 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.
+ */
+/**
+ * @addtogroup DAC
+ * @{
+ *
+ * @brief Provides Digital to analog converter (DAC) interfaces.
+ *
+ * This module allows a driver to perform operations on an DAC controller for accessing devices on the DAC channel,
+ * Including creating and destroying DAC controller handles and writing data
+ *
+ * @since 1.0
+ */
+/**
+ * @file dac_if.h
+ *
+ * @brief Declares the standard DAC interface functions.
+ *
+ * @since 1.0
+ */
+
+#ifndef DAC_IF_H
+#define DAC_IF_H
+
+#include "hdf_platform.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* __cplusplus */
+
+struct DacIoMsg {
+ uint32_t number;
+ uint32_t channel;
+};
+
+ /**
+ * @brief Obtains the handle of an DAC controller.
+ *
+ * You must call this function before accessing the DAC CHANNEL.
+ *
+ * @param number Indicates the DAC controller ID.
+ *
+ * @return Returns the pointer to the {@link DevHandle} of the DAC controller if the operation is successful;
+ * returns NULL otherwise.
+ * @since 1.0
+ */
+DevHandle DacOpen(uint32_t number);
+
+ /**
+ * @brief Releases the handle of an DAC controller.
+ *
+ * If you no longer need to access the DAC controller, you should call this function to close its handle so as
+ * to release unused memory resources.
+ *
+ * @param handle Indicates the pointer to the device handle of the DAC controller.
+ *
+ * @since 1.0
+ */
+void DacClose(DevHandle handle);
+
+ /**
+ * @brief Start the DAC device for transmission and write the target value in the specified DAC channel.
+ *
+ * @param handle Indicates the pointer to the device handle of the DAC controller obtained via {@link DacOpen}.
+ * @param channel represents the channel through which the DAC transmits messages.
+ * @param val represents the set digital target value.
+ *
+ * @return Returns 0 if the operation is successful; Returns a negative value otherwise..
+ *
+ * @since 1.0
+ */
+int32_t DacWrite(DevHandle handle, uint32_t channel, uint32_t val);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* __cplusplus */
+
+#endif /* DAC_IF_H */
diff --git a/include/platform/hdmi_if.h b/include/platform/hdmi_if.h
new file mode 100644
index 0000000000000000000000000000000000000000..a7ad5073e80559bb548276ce7d4355db9daef65d
--- /dev/null
+++ b/include/platform/hdmi_if.h
@@ -0,0 +1,801 @@
+/*
+ * Copyright (c) 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.
+ */
+
+/**
+ * @addtogroup HDMI
+ * @{
+ *
+ * @brief Declares standard APIs of basic High-Definition Multimedia Interface (HDMI) capabilities.
+ *
+ * You can use this module to access the HDMI and enable the driver to operate an HDMI sink device.
+ * These capabilities include start and stop tramnsfer on HDMI, setting some attributes,
+ * and read sink device's EDID data.
+ *
+ * @since 1.0
+ */
+
+/**
+ * @file hdmi_if.h
+ *
+ * @brief Declares the standard HDMI interface functions.
+ *
+ * @since 1.0
+ */
+
+#ifndef HDMI_IF_H
+#define HDMI_IF_H
+
+#include "hdf_platform.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* __cplusplus */
+
+/**
+ * @brief Indicates that maximum length of an HDMI sink device's EDID is 512 bytes.
+ *
+ * @since 1.0
+ */
+#define HDMI_EDID_MAX_LEN 512
+
+/**
+ * @brief Enumerates deep color,
+ * see the section 6.2.4 of HDMI Specification 1.4 for details.
+ *
+ * @since 1.0
+ */
+enum HdmiDeepColor {
+ HDMI_DEEP_COLOR_24BITS = 0,
+ HDMI_DEEP_COLOR_30BITS = 1,
+ HDMI_DEEP_COLOR_36BITS = 2,
+ HDMI_DEEP_COLOR_48BITS = 3,
+ HDMI_DEEP_COLOR_OFF = 0xff,
+ HDMI_DEEP_COLOR_BUTT,
+};
+
+/**
+ * @brief Enumerates video bit depth
+ * see the section 6.6 of HDMI Specification 1.4 for details.
+ *
+ * @since 1.0
+ */
+enum HdmiVideoBitDepth {
+ HDMI_VIDEO_BIT_DEPTH_8 = 0,
+ HDMI_VIDEO_BIT_DEPTH_10 = 1,
+ HDMI_VIDEO_BIT_DEPTH_12 = 2,
+ HDMI_VIDEO_BIT_DEPTH_16 = 3,
+ HDMI_VIDEO_BIT_DEPTH_OFF,
+};
+
+/**
+ * @brief Enumerates color space,
+ * see the section 6 of HDMI Specification 1.4 for details.
+ *
+ * @since 1.0
+ */
+enum HdmiColorSpace {
+ HDMI_COLOR_SPACE_RGB = 0,
+ HDMI_COLOR_SPACE_YCBCR422 = 1,
+ HDMI_COLOR_SPACE_YCBCR444 = 2,
+ HDMI_COLOR_SPACE_YCBCR420 = 3,
+ HDMI_COLOR_SPACE_BUTT,
+};
+
+/**
+ * @brief Enumerates colorimetry, see the section 6.7 of HDMI Specification 1.4 and
+ * the section 7.2 of HDMI Specification 2.0 for details.
+ *
+ * @since 1.0
+ */
+enum HdmiColorimetry {
+ HDMI_COLORIMETRY_NO_DATA = 0,
+ HDMI_COLORIMETRY_ITU601 = 1,
+ HDMI_COLORIMETRY_ITU709 = 2,
+ HDMI_COLORIMETRY_EXTENDED = 3,
+};
+
+/**
+ * @brief Enumerates extended colorimetry, see the section 6.7 of HDMI Specification 1.4 and
+ * the section 7.2 of HDMI Specification 2.0 for details.
+ *
+ * @since 1.0
+ */
+enum HdmiExtendedColorimetry {
+ HDMI_EXTENDED_COLORIMETRY_XV_YCC_601 = 0,
+ HDMI_EXTENDED_COLORIMETRY_XV_YCC_709 = 1,
+ HDMI_EXTENDED_COLORIMETRY_S_YCC_601 = 2,
+ HDMI_EXTENDED_COLORIMETRY_OPYCC_601 = 3,
+ HDMI_EXTENDED_COLORIMETRY_OPRGB = 4,
+ HDMI_EXTENDED_COLORIMETRY_BT2020_CONST_LUM = 5,
+ HDMI_EXTENDED_COLORIMETRY_BT2020 = 6,
+ HDMI_EXTENDED_COLORIMETRY_ADDITIONAL = 7,
+ HDMI_EXTENDED_COLORIMETRY_BUTT,
+};
+
+/**
+ * @brief Enumerates quantization range, see the section 6.6 of HDMI Specification 1.4 and
+ * the section 7.3 of HDMI Specification 2.0 for details.
+ *
+ * @since 1.0
+ */
+enum HdmiQuantizationRange {
+ HDMI_QUANTIZATION_RANGE_DEFAULT = 0,
+ HDMI_QUANTIZATION_RANGE_LIMITED = 1,
+ HDMI_QUANTIZATION_RANGE_FULL = 2,
+ HDMI_QUANTIZATION_RANGE_BUTT,
+};
+
+/**
+ * @brief Enumerates YCC quantization range, see the section 6.6 of HDMI Specification 1.4 and
+ * the section 7.3 of HDMI Specification 2.0 for details.
+ *
+ * @since 1.0
+ */
+enum HdmiYccQuantizationRange {
+ HDMI_YCC_QUANTIZATION_RANGE_LIMITED = 0,
+ HDMI_YCC_QUANTIZATION_RANGE_FULL = 1,
+ HDMI_YCC_QUANTIZATION_RANGE_BUTT,
+};
+
+/**
+ * @brief Enumerates video 3d structure,
+ * see the section 8.2.3 of HDMI Specification 1.4 for details.
+ *
+ * @since 1.0
+ */
+enum HdmiVideo3dStructure {
+ HDMI_VS_VIDEO_3D_FRAME_PACKING = 0,
+ HDMI_VS_VIDEO_3D_FIELD_ALTERNATIVE = 1,
+ HDMI_VS_VIDEO_3D_LINE_ALTERNATIVE = 2,
+ HDMI_VS_VIDEO_3D_SIDE_BY_SIDE_FULL = 3,
+ HDMI_VS_VIDEO_3D_L_DEPTH = 4,
+ HDMI_VS_VIDEO_3D_L_DEPTH_GFX_GFX_DEPTH = 5,
+ HDMI_VS_VIDEO_3D_TOP_AND_BOTTOM = 6,
+ HDMI_VS_VIDEO_3D_SIDE_BY_SIDE_HALF = 8,
+ HDMI_VS_VIDEO_3D_BUTT,
+};
+
+/**
+ * @brief Enumerates video timing,
+ * see the section 8.2.3 of HDMI Specification 1.4 for details.
+ *
+ * @since 1.0
+ */
+enum HdmiVideoTiming {
+ HDMI_VIDEO_TIMING_NONE = 0,
+ HDMI_VIDEO_TIMING_640X480P60 = 1,
+ HDMI_VIDEO_TIMING_720X480P60 = 2,
+ HDMI_VIDEO_TIMING_720X480P120 = 3,
+ HDMI_VIDEO_TIMING_720X480P240 = 4,
+ HDMI_VIDEO_TIMING_720X576P50 = 5,
+ HDMI_VIDEO_TIMING_720X576P100 = 6,
+ HDMI_VIDEO_TIMING_720X576P200 = 7,
+ HDMI_VIDEO_TIMING_1280X720P24 = 8,
+ HDMI_VIDEO_TIMING_1280X720P25 = 9,
+ HDMI_VIDEO_TIMING_1280X720P30 = 10,
+ HDMI_VIDEO_TIMING_1280X720P48 = 11,
+ HDMI_VIDEO_TIMING_1280X720P50 = 12,
+ HDMI_VIDEO_TIMING_1280X720P60 = 13,
+ HDMI_VIDEO_TIMING_1280X720P100 = 14,
+ HDMI_VIDEO_TIMING_1280X720P120 = 15,
+ HDMI_VIDEO_TIMING_1440X240P60 = 16,
+ HDMI_VIDEO_TIMING_1440X288P50 = 17,
+ HDMI_VIDEO_TIMING_1440X480I60 = 18,
+ HDMI_VIDEO_TIMING_1440X480P60 = 19,
+ HDMI_VIDEO_TIMING_1440X480I120 = 20,
+ HDMI_VIDEO_TIMING_1440X480I240 = 21,
+ HDMI_VIDEO_TIMING_1440X576I50 = 22,
+ HDMI_VIDEO_TIMING_1440X576P50 = 23,
+ HDMI_VIDEO_TIMING_1440X576I60 = 24,
+ HDMI_VIDEO_TIMING_1440X576I100 = 25,
+ HDMI_VIDEO_TIMING_1440X576I200 = 26,
+ HDMI_VIDEO_TIMING_2880X288P50 = 27,
+ HDMI_VIDEO_TIMING_2880X480I60 = 28,
+ HDMI_VIDEO_TIMING_2880X480P60 = 29,
+ HDMI_VIDEO_TIMING_2880X240I60 = 30,
+ HDMI_VIDEO_TIMING_2880X576I50 = 31,
+ HDMI_VIDEO_TIMING_2880X576P50 = 32,
+ HDMI_VIDEO_TIMING_1680X720P24 = 33,
+ HDMI_VIDEO_TIMING_1680X720P25 = 34,
+ HDMI_VIDEO_TIMING_1680X720P30 = 35,
+ HDMI_VIDEO_TIMING_1680X720P48 = 36,
+ HDMI_VIDEO_TIMING_1680X720P50 = 37,
+ HDMI_VIDEO_TIMING_1680X720P60 = 38,
+ HDMI_VIDEO_TIMING_1680X720P100 = 39,
+ HDMI_VIDEO_TIMING_1680X720P120 = 40,
+ HDMI_VIDEO_TIMING_2560X1080P24 = 41,
+ HDMI_VIDEO_TIMING_2560X1080P25 = 42,
+ HDMI_VIDEO_TIMING_2560X1080P30 = 43,
+ HDMI_VIDEO_TIMING_2560X1080P48 = 44,
+ HDMI_VIDEO_TIMING_2560X1080P50 = 45,
+ HDMI_VIDEO_TIMING_2560X1080P60 = 46,
+ HDMI_VIDEO_TIMING_2560X1080P100 = 47,
+ HDMI_VIDEO_TIMING_2560X1080P120 = 48,
+ HDMI_VIDEO_TIMING_1920X1080I60 = 49,
+ HDMI_VIDEO_TIMING_1920X1080P60 = 50,
+ HDMI_VIDEO_TIMING_1920X1080I50 = 51,
+ HDMI_VIDEO_TIMING_1920X1080P50 = 52,
+ HDMI_VIDEO_TIMING_1920X1080P24 = 53,
+ HDMI_VIDEO_TIMING_1920X1080P25 = 54,
+ HDMI_VIDEO_TIMING_1920X1080P30 = 55,
+ HDMI_VIDEO_TIMING_1920X1080P48 = 56,
+ HDMI_VIDEO_TIMING_1920X1080I100 = 57,
+ HDMI_VIDEO_TIMING_1920X1080I120 = 58,
+ HDMI_VIDEO_TIMING_1920X1080P120 = 59,
+ HDMI_VIDEO_TIMING_1920X1080P100 = 60,
+ HDMI_VIDEO_TIMING_3840X2160P24 = 61,
+ HDMI_VIDEO_TIMING_3840X2160P25 = 62,
+ HDMI_VIDEO_TIMING_3840X2160P30 = 63,
+ HDMI_VIDEO_TIMING_3840X2160P48 = 64,
+ HDMI_VIDEO_TIMING_3840X2160P50 = 65,
+ HDMI_VIDEO_TIMING_3840X2160P60 = 66,
+ HDMI_VIDEO_TIMING_3840X2160P100 = 67,
+ HDMI_VIDEO_TIMING_3840X2160P120 = 68,
+ HDMI_VIDEO_TIMING_4096X2160P24 = 69,
+ HDMI_VIDEO_TIMING_4096X2160P25 = 70,
+ HDMI_VIDEO_TIMING_4096X2160P30 = 71,
+ HDMI_VIDEO_TIMING_4096X2160P48 = 72,
+ HDMI_VIDEO_TIMING_4096X2160P50 = 73,
+ HDMI_VIDEO_TIMING_4096X2160P60 = 74,
+ HDMI_VIDEO_TIMING_4096X2160P100 = 75,
+ HDMI_VIDEO_TIMING_4096X2160P120 = 76,
+ HDMI_VIDEO_TIMING_5120X2160P24 = 77,
+ HDMI_VIDEO_TIMING_5120X2160P25 = 78,
+ HDMI_VIDEO_TIMING_5120X2160P30 = 79,
+ HDMI_VIDEO_TIMING_5120X2160P48 = 80,
+ HDMI_VIDEO_TIMING_5120X2160P50 = 81,
+ HDMI_VIDEO_TIMING_5120X2160P60 = 82,
+ HDMI_VIDEO_TIMING_5120X2160P100 = 83,
+ HDMI_VIDEO_TIMING_5120X2160P120 = 84,
+ HDMI_VIDEO_TIMING_7680X4320P24 = 85,
+ HDMI_VIDEO_TIMING_7680X4320P25 = 86,
+ HDMI_VIDEO_TIMING_7680X4320P30 = 87,
+ HDMI_VIDEO_TIMING_7680X4320P48 = 88,
+ HDMI_VIDEO_TIMING_7680X4320P50 = 89,
+ HDMI_VIDEO_TIMING_7680X4320P60 = 90,
+ HDMI_VIDEO_TIMING_7680X4320P100 = 91,
+ HDMI_VIDEO_TIMING_7680X4320P120 = 92,
+ HDMI_VIDEO_TIMING_10240X4320P24 = 93,
+ HDMI_VIDEO_TIMING_10240X4320P25 = 94,
+ HDMI_VIDEO_TIMING_10240X4320P30 = 95,
+ HDMI_VIDEO_TIMING_10240X4320P48 = 96,
+ HDMI_VIDEO_TIMING_10240X4320P50 = 97,
+ HDMI_VIDEO_TIMING_10240X4320P60 = 98,
+ HDMI_VIDEO_TIMING_10240X4320P100 = 99,
+ HDMI_VIDEO_TIMING_10240X4320P120 = 100,
+ HDMI_VIDEO_TIMING_VESA_DEFINE = 101,
+ HDMI_VIDEO_TIMING_VESA_800X600_60 = 102,
+ HDMI_VIDEO_TIMING_VESA_848X480_60 = 103,
+ HDMI_VIDEO_TIMING_VESA_1024X768_60 = 104,
+ HDMI_VIDEO_TIMING_VESA_1280X720_60 = 105,
+ HDMI_VIDEO_TIMING_VESA_1280X768_60 = 106,
+ HDMI_VIDEO_TIMING_VESA_1280X768_60_RB = 107,
+ HDMI_VIDEO_TIMING_VESA_1280X800_60 = 108,
+ HDMI_VIDEO_TIMING_VESA_1280X800_60_RB = 109,
+ HDMI_VIDEO_TIMING_VESA_1280X960_60 = 110,
+ HDMI_VIDEO_TIMING_VESA_1280X1024_60 = 111,
+ HDMI_VIDEO_TIMING_VESA_1360X768_60 = 112,
+ HDMI_VIDEO_TIMING_VESA_1366X768_60 = 113,
+ HDMI_VIDEO_TIMING_VESA_1400X1050_60 = 114,
+ HDMI_VIDEO_TIMING_VESA_1440X900_60 = 115,
+ HDMI_VIDEO_TIMING_VESA_1440X900_60_RB = 116,
+ HDMI_VIDEO_TIMING_VESA_1440X1050_60 = 117,
+ HDMI_VIDEO_TIMING_VESA_1440X1050_60_RB = 118,
+ HDMI_VIDEO_TIMING_VESA_1600X900_60_RB = 119,
+ HDMI_VIDEO_TIMING_VESA_1600X1200_60 = 120,
+ HDMI_VIDEO_TIMING_VESA_1680X1050_60 = 113,
+ HDMI_VIDEO_TIMING_VESA_1680X1050_60_RB = 114,
+ HDMI_VIDEO_TIMING_VESA_1792X1344_60 = 115,
+ HDMI_VIDEO_TIMING_VESA_1856X1392_60 = 116,
+ HDMI_VIDEO_TIMING_VESA_1920X1080_60 = 117,
+ HDMI_VIDEO_TIMING_VESA_1920X1200_60 = 118,
+ HDMI_VIDEO_TIMING_VESA_1920X1200_60_RB = 119,
+ HDMI_VIDEO_TIMING_VESA_1920X1440_60 = 120,
+ HDMI_VIDEO_TIMING_VESA_2048X1152_60 = 121,
+ HDMI_VIDEO_TIMING_VESA_2560X1440_60_RB = 122,
+ HDMI_VIDEO_TIMING_VESA_2560X1600_60 = 123,
+ HDMI_VIDEO_TIMING_VESA_2560X1600_60_RB = 124,
+ HDMI_VIDEO_TIMING_USER_DEFINE = 125,
+ HDMI_VIDEO_TIMING_USER_1920X2160_30 = 126,
+ HDMI_VIDEO_TIMING_USER_2560X1440_30 = 127,
+ HDMI_VIDEO_TIMING_USER_2560X1440_60 = 128,
+ HDMI_VIDEO_TIMING_USER_1280X720_60 = 129,
+ HDMI_VIDEO_TIMING_USER_1366X768_60 = 130,
+ HDMI_VIDEO_TIMING_USER_1600X900_60_RB = 131,
+ HDMI_VIDEO_TIMING_USER_1920X1080_60 = 132,
+ HDMI_VIDEO_TIMING_USER_2048X1152_60 = 133,
+ HDMI_VIDEO_TIMING_BUTT,
+};
+
+/**
+ * @brief Enumerates picture aspect ratio,
+ * see the section 8.2.1 of HDMI Specification 1.4 for details.
+ *
+ * @since 1.0
+ */
+enum HdmiPictureAspectRatio {
+ HDMI_PICTURE_ASPECT_NO_DATA = 0,
+ HDMI_PICTURE_ASPECT_4_3 = 1,
+ HDMI_PICTURE_ASPECT_16_9 = 2,
+ HDMI_PICTURE_ASPECT_64_27 = 3,
+ HDMI_PICTURE_ASPECT_256_135 = 4,
+ HDMI_PICTURE_ASPECT_BUTT = 5,
+};
+
+/**
+ * @brief Enumerates active format aspect ratio,
+ * see the section 8.2.1 of HDMI Specification 1.4 for details.
+ *
+ * @since 1.0
+ */
+enum HdmiActiveFormatAspectRatio {
+ HDMI_ACTIVE_FORMAT_ASPECT_16_9_TOP = 2,
+ HDMI_ACTIVE_FORMAT_ASPECT_14_9_TOP = 3,
+ HDMI_ACTIVE_FORMAT_ASPECT_16_9_CENTER = 4,
+ HDMI_ACTIVE_FORMAT_ASPECT_PICTURE = 8,
+ HDMI_ACTIVE_FORMAT_ASPECT_4_3 = 9,
+ HDMI_ACTIVE_FORMAT_ASPECT_16_9 = 10,
+ HDMI_ACTIVE_FORMAT_ASPECT_14_9 = 11,
+ HDMI_ACTIVE_FORMAT_ASPECT_4_3_SP_14_9 = 13,
+ HDMI_ACTIVE_FORMAT_ASPECT_16_9_SP_14_9 = 14,
+ HDMI_ACTIVE_FORMAT_ASPECT_16_9_SP_4_3 = 15,
+ HDMI_ACTIVE_FORMAT_ASPECT_BUTT,
+};
+
+/**
+ * @brief Enumerates Nups(non-uniform picture scaling),
+ * see the section 8.2.1 of HDMI Specification 1.4 for details.
+ *
+ * @since 1.0
+ */
+enum HdmiNups {
+ HDMI_NUPS_UNKNOWN = 0, /* No Known non-uniform scaling */
+ HDMI_NUPS_HORIZONTAL = 1, /* Picture has been scaled horizontally */
+ HDMI_NUPS_VERTICAL = 2, /* Picture has been scaled vertically */
+ HDMI_NUPS_BOTH = 3, /* Picture has been scaled horizontally and vertically */
+};
+
+/**
+ * @brief Defines the video attribute struct.
+ *
+ * @since 1.0
+ */
+struct HdmiVideoAttr {
+ uint32_t tmdsClock; /* unit: KHz */
+ uint32_t pixelClock; /* unit: KHz */
+ uint32_t pixelRepeat;
+ enum HdmiColorSpace colorSpace;
+ enum HdmiColorimetry colorimetry;
+ enum HdmiExtendedColorimetry extColorimetry;
+ enum HdmiQuantizationRange quantization;
+ enum HdmiYccQuantizationRange yccQuantization;
+ enum HdmiDeepColor deepColor;
+ enum HdmiVideo3dStructure _3dStruct;
+ enum HdmiVideoTiming timing;
+ enum HdmiPictureAspectRatio aspect;
+ enum HdmiActiveFormatAspectRatio activeAspect;
+ enum HdmiNups nups;
+ bool xvycc;
+};
+
+/**
+ * @brief Enumerates audio coding type,
+ * see the section 7 of HDMI Specification 1.4 for details.
+ *
+ * @since 1.0
+ */
+enum HdmiAudioCodingType {
+ HDMI_AUDIO_CODING_TYPE_STREAM = 0,
+ HDMI_AUDIO_CODING_TYPE_LPCM = 1,
+ HDMI_AUDIO_CODING_TYPE_AC3 = 2,
+ HDMI_AUDIO_CODING_TYPE_MPEG1 = 3,
+ HDMI_AUDIO_CODING_TYPE_MP3 = 4,
+ HDMI_AUDIO_CODING_TYPE_MPEG2 = 5,
+ HDMI_AUDIO_CODING_TYPE_AAC_LC = 6,
+ HDMI_AUDIO_CODING_TYPE_DTS = 7,
+ HDMI_AUDIO_CODING_TYPE_ATRAC = 8,
+ HDMI_AUDIO_CODING_TYPE_OBA = 9,
+ HDMI_AUDIO_CODING_TYPE_EAC3 = 10,
+ HDMI_AUDIO_CODING_TYPE_DTS_HD = 11,
+ HDMI_AUDIO_CODING_TYPE_MLP = 12,
+ HDMI_AUDIO_CODING_TYPE_DST = 13,
+ HDMI_AUDIO_CODING_TYPE_WMA_PRO = 14,
+ HDMI_AUDIO_CODING_TYPE_CXT = 15,
+};
+
+/**
+ * @brief Enumerates audio interface type.
+ *
+ * @since 1.0
+ */
+enum HdmiAudioInterfaceType {
+ HDMI_AUDIO_IF_TYPE_I2S = 0, /* Inter-IC Sound */
+ HDMI_AUDIO_IF_TYPE_SPDIF = 1, /* Sony/Philips Digital Interface */
+ HDMI_AUDIO_IF_TYPE_OTHER,
+};
+
+/**
+ * @brief Enumerates audio bit depth,
+ * see the section 7 of HDMI Specification 1.4 for details.
+ *
+ * @since 1.0
+ */
+enum HdmiAudioBitDepth {
+ HDMI_ADIO_BIT_DEPTH_UNKNOWN,
+ HDMI_ADIO_BIT_DEPTH_8 = 8,
+ HDMI_ADIO_BIT_DEPTH_16 = 16,
+ HDMI_ADIO_BIT_DEPTH_18 = 18,
+ HDMI_ADIO_BIT_DEPTH_20 = 20,
+ HDMI_ADIO_BIT_DEPTH_24 = 24,
+ HDMI_ADIO_BIT_DEPTH_32 = 32,
+ HDMI_ADIO_BIT_DEPTH_BUTT,
+};
+
+/**
+ * @brief Enumerates sample rate used for audio,
+ * see the section 7.3 of HDMI Specification 1.4 for details.
+ *
+ * @since 1.0
+ */
+enum HdmiSampleRate {
+ HDMI_SAMPLE_RATE_UNKNOWN,
+ HDMI_SAMPLE_RATE_8K = 8000,
+ HDMI_SAMPLE_RATE_11K = 11025,
+ HDMI_SAMPLE_RATE_12K = 12000,
+ HDMI_SAMPLE_RATE_16K = 16000,
+ HDMI_SAMPLE_RATE_22K = 22050,
+ HDMI_SAMPLE_RATE_24K = 24000,
+ HDMI_SAMPLE_RATE_32K = 32000,
+ HDMI_SAMPLE_RATE_44K = 44100,
+ HDMI_SAMPLE_RATE_48K = 48000,
+ HDMI_SAMPLE_RATE_88K = 88200,
+ HDMI_SAMPLE_RATE_96K = 96000,
+ HDMI_SAMPLE_RATE_176K = 176400,
+ HDMI_SAMPLE_RATE_192K = 192000,
+ HDMI_SAMPLE_RATE_768K = 768000,
+ HDMI_SAMPLE_RATE_BUTT,
+};
+
+/**
+ * @brief Enumerates audio format channel,
+ * see the section 7 of HDMI Specification 1.4 for details.
+ *
+ * @since 1.0
+ */
+enum HdmiAudioFormatChannel {
+ HDMI_AUDIO_FORMAT_CHANNEL_2 = 2,
+ HDMI_AUDIO_FORMAT_CHANNEL_3,
+ HDMI_AUDIO_FORMAT_CHANNEL_4,
+ HDMI_AUDIO_FORMAT_CHANNEL_5,
+ HDMI_AUDIO_FORMAT_CHANNEL_6,
+ HDMI_AUDIO_FORMAT_CHANNEL_7,
+ HDMI_AUDIO_FORMAT_CHANNEL_8,
+ HDMI_AUDIO_FORMAT_CHANNEL_BUTT,
+};
+
+/**
+ * @brief Defines the audio attribute struct.
+ *
+ * @since 1.0
+ */
+struct HdmiAudioAttr {
+ enum HdmiAudioCodingType codingType;
+ enum HdmiAudioInterfaceType ifType;
+ enum HdmiAudioBitDepth bitDepth;
+ enum HdmiSampleRate sampleRate;
+ bool downSample;
+ enum HdmiAudioFormatChannel channels;
+};
+
+/**
+ * @brief Enumerates Electro-Optical Transfer Function (EOTF),
+ * see the section 6.9 of CTA-861-G for details.
+ *
+ * @since 1.0
+ */
+enum HdmiEotfType {
+ HDMI_EOTF_SDR_LUMIN = 0, /* Traditional gamma - SDR Luminance Range */
+ HDMI_EOTF_HDR_LUMIN = 1, /* Traditional gamma - HDR Luminance Range */
+ HDMI_EOTF_SMPTE_ST_2048 = 2, /* SMPTE ST 2048 */
+ HDMI_EOTF_HLG = 3, /* Hybrid Log-Gamma (HLG) based on ITU-R BT.2100-0 */
+ HDMI_EOTF_BUTT,
+};
+
+/**
+ * @brief Enumerates hdr colormetry,
+ * see HDMI Specification 2.1 for details.
+ *
+ * @since 1.0
+ */
+enum HdmiHdrColormetry {
+ HDMI_HDR_COLORIMETRY_NONE,
+ HDMI_HDR_COLORIMETRY_ITU_601,
+ HDMI_HDR_COLORIMETRY_ITU_709,
+ HDMI_HDR_COLORIMETRY_EXTENDED,
+ HDMI_HDR_EXTENDED_COLORIMETRY_XV_YCC_601,
+ HDMI_HDR_EXTENDED_COLORIMETRY_XV_YCC_709,
+ HDMI_HDR_EXTENDED_COLORIMETRY_S_YCC_601,
+ HDMI_HDR_EXTENDED_COLORIMETRY_ADOBE_YCC_601,
+ HDMI_HDR_EXTENDED_COLORIMETRY_ADOBE_RGB,
+ HDMI_HDR_EXTENDED_COLORIMETRY_2020_CONST_LUMINOUS, /* BT2020 c_ycc */
+ HDMI_HDR_EXTENDED_COLORIMETRY_2020_NON_CONST_LUMINOUW
+};
+
+/**
+ * @brief Enumerates hdr mode,
+ * see HDMI Specification 2.1 for details.
+ *
+ * @since 1.0
+ */
+enum HdmiHdrMode {
+ HDMI_HDR_MODE_DISABLE, /* HDR & dolby mode disable */
+ HDMI_HDR_MODE_DOLBY_NORMAL, /* dolby normal(ycbcr422-12bit) mode enable */
+ HDMI_HDR_MODE_DOLBY_TUNNELING, /* dolby tunneling(RGB-8bit) mode enable */
+ HDMI_HDR_MODE_CEA_861_3, /* HDR standard mode enable(according to ) */
+ HDMI_HDR_MODE_CEA_861_3_AUTHEN, /* HDR authen mode */
+ HDMI_HDR_MODE_BUTT
+};
+
+/**
+ * @brief Enumerates hdr user mode,
+ * see HDMI Specification 2.1 for details.
+ *
+ * @since 1.0
+ */
+enum HdmiHdrUserMode {
+ HDMI_HDR_USERMODE_SDR,
+ HDMI_HDR_USERMODE_HDR10,
+ HDMI_HDR_USERMODE_DOLBY,
+ HDMI_HDR_USERMODE_BUTT
+};
+
+/**
+ * @brief Enumerates static metadata type,
+ * see the section 6.9 of CTA-861-G for details.
+ *
+ * @since 1.0
+ */
+enum HdmiStaticMetadataType {
+ HDMI_DRM_STATIC_METADATA_TYPE_1 = 0, /* Static Metadata Type 1 */
+ HDMI_DRM_STATIC_METADATA_BUTT,
+};
+
+/**
+ * @brief Enumerates static metadata descriptor1st,
+ * see the section 6.9 of CTA-861-G for details.
+ *
+ * @since 1.0
+ */
+struct HdmiStaticMetadataDescriptor1st {
+ uint16_t displayPrimaries0X; /* display_primaries_x[0], in units of 0.00002 */
+ uint16_t displayPrimaries0Y; /* display_primaries_y[0], in units of 0.00002 */
+ uint16_t displayPrimaries1X; /* display_primaries_x[1], in units of 0.00002 */
+ uint16_t displayPrimaries1Y; /* display_primaries_y[1], in units of 0.00002 */
+ uint16_t displayPrimaries2X; /* display_primaries_x[2], in units of 0.00002 */
+ uint16_t displayPrimaries2Y; /* display_primaries_y[2], in units of 0.00002 */
+ uint16_t whitePointX; /* white_point_x, in units of 0.00002 */
+ uint16_t whitePointY; /* white_point_y, in units of 0.00002 */
+ uint16_t maxDisplayMasteringLuminance; /* max_display_mastering_luminance, in units of 1 cd/m^2 */
+ uint16_t minDisplayMasteringLuminance; /* min_display_mastering_luminance, in units of 0.0001 cd/m^2 */
+ uint16_t maxContentLightLevel; /* Maximum Content Light Level, in units of 1 cd/m^2 */
+ uint16_t maxFrameAverageLightLevel; /* Maximum Frame-average Light Level, in units of 1 cd/m^2 */
+};
+
+/**
+ * @brief Defines the static metadata descriptor,
+ * see the section 6.9 of CTA-861-G for details.
+ *
+ * @since 1.0
+ */
+union HdmiStaticMetadataDescriptor {
+ struct HdmiStaticMetadataDescriptor1st type1;
+};
+
+/**
+ * @brief Defines the hdr attribute struct.
+ *
+ * @since 1.0
+ */
+struct HdmiHdrAttr {
+ enum HdmiHdrMode mode;
+ enum HdmiHdrUserMode userMode;
+ /* The following members are valid, when mode is HDMI_HDR_MODE_CEA_861_3. */
+ enum HdmiEotfType eotfType;
+ enum HdmiStaticMetadataType metadataType;
+ union HdmiStaticMetadataDescriptor descriptor;
+ enum HdmiHdrColormetry colorimetry;
+};
+
+/**
+ * @brief Defines the hdmi HPD(Hot Plug Detect) callback info.
+ *
+ * @since 1.0
+ */
+struct HdmiHpdCallbackInfo {
+ void *data;
+ void (*callbackFunc)(void *data, bool hdp);
+};
+
+/**
+ * @brief Opens an HDMI controller with a specified bus number.
+ *
+ * Before using the HDMI interface, you can obtain the device handle of the HDMI controller
+ * by calling {@link HdmiOpen}. This function is used in pair with {@link HdmiClose}.
+ *
+ * @param busNum Indicates the bus number.
+ *
+ * @return Returns the device handle {@link DevHandle} of the HDMI controller if the operation is successful;
+ * returns NULL otherwise.
+ *
+ * @since 1.0
+ */
+DevHandle HdmiOpen(uint16_t busNum);
+
+/**
+ * @brief HDMI transmission start.
+ *
+ * This function is used in pair with {@link HdmiStop}.
+ *
+ * @param handle Indicates the pointer to the device handle of the HDMI controller.
+ *
+ * @return Returns 0 if the operation is successful; returns a negative value if the operation fails.
+ *
+ * @since 1.0
+ */
+int32_t HdmiStart(DevHandle handle);
+
+/**
+ * @brief HDMI transmission stop.
+ *
+ * This function is used in pair with {@link HdmiStart}.
+ *
+ * @param handle Indicates the pointer to the device handle of the HDMI controller.
+ *
+ * @return Returns 0 if the operation is successful; returns a negative value if the operation fails.
+ *
+ * @since 1.0
+ */
+int32_t HdmiStop(DevHandle handle);
+
+/**
+ * @brief HDMI Avmute set.
+ *
+ * First put the display device into the black screen mute state, waitting for the HDMI output device switch,
+ * and then send a Clear AVMute signal, so that the display device to boot, so that the switching process of
+ * the screen will be shielded.
+ *
+ * @param handle Indicates the pointer to the device handle of the HDMI controller.
+ * @param enable Indicates whether to enable avmute.
+ *
+ * @return Returns 0 if the operation is successful; returns a negative value if the operation fails.
+ *
+ * @since 1.0
+ */
+int32_t HdmiAvmuteSet(DevHandle handle, bool enable);
+
+
+/**
+ * @brief HDMI deep color set.
+ *
+ * @param handle Indicates the pointer to the device handle of the HDMI controller.
+ * @param color Indicates the deep color to be set, see {@link HdmiDeepColor}.
+ *
+ * @return Returns 0 if the operation is successful; returns a negative value if the operation fails.
+ *
+ * @since 1.0
+ */
+int32_t HdmiDeepColorSet(DevHandle handle, enum HdmiDeepColor color);
+
+/**
+ * @brief HDMI deep color get.
+ *
+ * @param handle Indicates the pointer to the device handle of the HDMI controller.
+ * @param color Indicates the pointer to the deep color to read, see {@link HdmiDeepColor}.
+ *
+ * @return Returns 0 if the operation is successful; returns a negative value if the operation fails.
+ *
+ * @since 1.0
+ */
+int32_t HdmiDeepColorGet(DevHandle handle, enum HdmiDeepColor *color);
+
+/**
+ * @brief HDMI set video attribute.
+ *
+ * @param handle Indicates the pointer to the device handle of the HDMI controller.
+ * @param attr Indicates the pointer to the video attribute to set, see {@link HdmiVideoAttr}.
+ *
+ * @return Returns 0 if the operation is successful; returns a negative value if the operation fails.
+ *
+ * @since 1.0
+ */
+int32_t HdmiSetVideoAttribute(DevHandle handle, struct HdmiVideoAttr *attr);
+
+/**
+ * @brief HDMI set audio attribute.
+ *
+ * @param handle Indicates the pointer to the device handle of the HDMI controller.
+ * @param attr Indicates the pointer to the audio attribute to set, see {@link HdmiAudioAttr}.
+ *
+ * @return Returns 0 if the operation is successful; returns a negative value if the operation fails.
+ *
+ * @since 1.0
+ */
+int32_t HdmiSetAudioAttribute(DevHandle handle, struct HdmiAudioAttr *attr);
+
+/**
+ * @brief HDMI set hdr attribute.
+ *
+ * @param handle Indicates the pointer to the device handle of the HDMI controller.
+ * @param attr Indicates the pointer to the hdr attribute to set, see {@link HdmiHdrAttr}.
+ *
+ * @return Returns 0 if the operation is successful; returns a negative value if the operation fails.
+ *
+ * @since 1.0
+ */
+int32_t HdmiSetHdrAttribute(DevHandle handle, struct HdmiHdrAttr *attr);
+
+/**
+ * @brief HDMI read sink device's raw EDID data.
+ *
+ * @param handle Indicates the pointer to the device handle of the HDMI controller.
+ * @param buffer Indicates the pointer to the data to read.
+ * @param len Indicates the length of the data to read.
+ *
+ * @return Returns the length of the data read if the operation is successful;
+ * returns a negative value or 0 if the operation fails.
+ *
+ * @since 1.0
+ */
+int32_t HdmiReadSinkEdid(DevHandle handle, uint8_t *buffer, uint32_t len);
+
+/**
+ * @brief HDMI register HPD(Hot Plug Detect) callback function.
+ *
+ * @param handle Indicates the pointer to the device handle of the HDMI controller.
+ * @param callback Indicates the pointer to the callback info.
+ *
+ * @return Returns the length of the data read if the operation is successful;
+ * returns a negative value or 0 if the operation fails.
+ *
+ * @since 1.0
+ */
+int32_t HdmiRegisterHpdCallbackFunc(DevHandle handle, struct HdmiHpdCallbackInfo *callback);
+
+/**
+ * @brief HDMI unregister HPD(Hot Plug Detect) callback function.
+ *
+ * @param handle Indicates the pointer to the device handle of the HDMI controller.
+ *
+ * @return Returns the length of the data read if the operation is successful;
+ * returns a negative value or 0 if the operation fails.
+ *
+ * @since 1.0
+ */
+int32_t HdmiUnregisterHpdCallbackFunc(DevHandle handle);
+
+/**
+ * @brief Closes an HDMI controller.
+ *
+ * After the HDMI interface is used, you can close the HDMI controller by calling {@link HdmiClose}.
+ * This function is used in pair with {@link HdmiOpen}.
+ *
+ * @param handle Indicates the pointer to the device handle of the HDMI controller.
+ *
+ * @since 1.0
+ */
+void HdmiClose(DevHandle handle);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* __cplusplus */
+
+#endif /* HDMI_IF_H */
diff --git a/include/platform/i2s_if.h b/include/platform/i2s_if.h
old mode 100644
new mode 100755
index a5106c68911062982c678c1799168b1c7a7843e6..bbb67caa82687243426bcfff18794920e567e13a
--- a/include/platform/i2s_if.h
+++ b/include/platform/i2s_if.h
@@ -74,8 +74,8 @@ enum I2sWordWidth {
enum I2sMode {
I2S_MODE_MASTER_TX_MODE,
I2S_MODE_MASTER_RX_MODE,
- I2S_MODE_SLAVE_TX_MODE,
- I2S_MODE_SLAVE_RX_MODE,
+ I2S_MODE_STANDBY_TX_MODE,
+ I2S_MODE_STANDBY_RX_MODE,
};
enum I2sLoopMode {
@@ -142,7 +142,7 @@ enum I2slFsSel {
struct I2sCfg {
enum I2sSampleRate sampleRate; /**< I2S sample rate, 8k,16k,32k... */
enum I2sWordWidth width; /**< I2S word width, 8bit,16bit,20bit,24bit... */
- enum I2sMode mode; /**< I2S mode, master/slave, tx/rx */
+ enum I2sMode mode; /**< I2S mode, master/standby, tx/rx */
enum I2sPcmFscDelay syncMode; /**< pcm mode, FSC starts location */
enum I2sLoopMode loopMode; /**< is loopback */
enum I2sProtocolType type; /**< I2S protocol type */
diff --git a/include/platform/i3c_ccc.h b/include/platform/i3c_ccc.h
new file mode 100644
index 0000000000000000000000000000000000000000..272efa902849fdb6d41f8ca4ecd63bfa7ef4efee
--- /dev/null
+++ b/include/platform/i3c_ccc.h
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef I3C_CCC_H
+#define I3C_CCC_H
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* __cplusplus */
+
+/** CCC(Common Command Code) structure */
+struct I3cCccCmd;
+
+/** Broatcast commands */
+#define I3C_CCC_ENEC_B 0x00
+#define I3C_CCC_DISEC_B 0x01
+#define I3C_CCC_ENTAS0_B 0x02
+#define I3C_CCC_ENTAS1_B 0x03
+#define I3C_CCC_ENTAS2_B 0x04
+#define I3C_CCC_ENTAS3_B 0x05
+#define I3C_CCC_RSTDAA_B 0x06
+#define I3C_CCC_ENTDAA 0x07
+#define I3C_CCC_DEFSLVS 0x08
+#define I3C_CCC_SETMWL_B 0x09
+#define I3C_CCC_SETMRL_B 0x0a
+#define I3C_CCC_ENTTM 0x0b
+#define I3C_CCC_ENDXFER 0X12
+#define I3C_CCC_ENTHDR0 0x20
+#define I3C_CCC_ENTHDR1 0x21
+#define I3C_CCC_ENTHDR2 0x22
+#define I3C_CCC_ENTHDR3 0x23
+#define I3C_CCC_ENTHDR4 0x24
+#define I3C_CCC_ENTHDR5 0x25
+#define I3C_CCC_ENTHDR6 0x26
+#define I3C_CCC_ENTHDR7 0x27
+#define I3C_CCC_SETXTIME_B 0x28
+#define I3C_CCC_SETAASA 0X29
+#define I3C_CCC_VENDOR_B 0x61
+/** Driect commands */
+#define I3C_CCC_ENEC_D 0x80
+#define I3C_CCC_DISEC_D 0x81
+#define I3C_CCC_ENTAS0_D 0x82
+#define I3C_CCC_ENTAS1_D 0x83
+#define I3C_CCC_ENTAS2_D 0x84
+#define I3C_CCC_ENTAS3_D 0x85
+#define I3C_CCC_RSTDAA_D 0x86
+#define I3C_CCC_SETDASA 0x87
+#define I3C_CCC_SETNEWDA 0x88
+#define I3C_CCC_SETMWL_D 0x89
+#define I3C_CCC_SETMRL_D 0x8a
+#define I3C_CCC_GETMWL 0x8b
+#define I3C_CCC_GETMRL 0x8c
+#define I3C_CCC_GETPID 0x8d
+#define I3C_CCC_GETBCR 0x8e
+#define I3C_CCC_GETDCR 0x8f
+#define I3C_CCC_GETSTATUS 0x90
+#define I3C_CCC_GETACCMST 0x91
+#define I3C_CCC_SETBRGTGT 0x93
+#define I3C_CCC_GETMXDS 0x94
+#define I3C_CCC_GETHDRCAP 0x95
+#define I3C_CCC_SETXTIME_D 0x98
+#define I3C_CCC_GETXTIME 0x99
+#define I3C_CCC_VENDOR_D 0xe0
+
+struct I3cCccCmd {
+ /** CCC(Common Command Code) */
+ uint8_t cmd;
+ /** The destination address of the command, valid only if sending a direct CCC. */
+ uint16_t dest;
+ /** When sending a read command, dataLength represents the length of the read data */
+ uint32_t dataLength;
+ /** When sending a read command, buf is address of the buffer for storing transferred data */
+ uint8_t *buf;
+};
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* __cplusplus */
+
+#endif /* I3C_CORE_H */
diff --git a/include/platform/i3c_if.h b/include/platform/i3c_if.h
new file mode 100644
index 0000000000000000000000000000000000000000..4dce31073c6267fc9441bc10774179ccf1af9866
--- /dev/null
+++ b/include/platform/i3c_if.h
@@ -0,0 +1,252 @@
+/*
+ * Copyright (c) 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.
+ */
+
+/**
+ * @addtogroup I3C
+ * @{
+ *
+ * @brief Provides Improved Inter-Integrated Circuit (I3C) interfaces.
+ *
+ * This module allows a driver to perform operations on an I3C controller for accessing devices on the I3C bus,
+ * including creating and destroying I3C controller handles as well as reading and writing data.
+ *
+ * @since 1.0
+ */
+
+/**
+ * @file i3c_if.h
+ *
+ * @brief Declares the standard I3C interface functions.
+ *
+ * @since 1.0
+ */
+
+#ifndef I3C_IF_H
+#define I3C_IF_H
+
+#include "hdf_platform.h"
+#include "i3c_ccc.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* __cplusplus */
+
+enum TransMode {
+ /** I2C transfer mode */
+ I2C_MODE = 0,
+ /** I3C transfer mode */
+ I3C_MODE,
+ /** CCC(Common Command Code) mode */
+ CCC_CMD_MODE,
+};
+
+enum I3cBusMode {
+ /** Single Data Rate mode */
+ I3C_BUS_SDR_MODE = 0,
+ /** High Data Rate mode */
+ I3C_BUS_HDR_MODE,
+};
+
+/**
+ * @brief Defines the configurations of I3C controller.
+ *
+ * @since 1.0
+ */
+struct I3cConfig {
+ /** I3C bus mode */
+ enum I3cBusMode busMode;
+ /** Current master object, its NULL when the controller is the master */
+ struct I3cDevice *curMaster;
+};
+
+/**
+ * @brief Defines the I3C transfer message used during I3C transfer, I2C transfer or sending CCC(Common Command Code).
+ *
+ * @attention This structure does not limit the data transfer length specified by len.
+ * The specific I3C controller determines the maximum length allowed. \n
+ * The device address addr indicates the original device address and does not need to
+ * contain the read/write flag bit.
+ *
+ * @since 1.0
+ */
+struct I3cMsg {
+ /** Address of the target device */
+ uint16_t addr;
+ /** Address of the buffer for storing transferred data */
+ uint8_t *buf;
+ /** Length of the transferred data */
+ uint16_t len;
+ /**
+ * Transfer Mode Flag | Description
+ * ------------| -----------------------
+ * I2C_FLAG_READ | Read flag
+ * I2C_FLAG_READ_NO_ACK | No-ACK read flag
+ * I2C_FLAG_IGNORE_NO_ACK | Ignoring no-ACK flag
+ * I2C_FLAG_NO_START | No START condition flag
+ * I2C_FLAG_STOP | STOP condition flag
+ */
+ uint16_t flags;
+ /** Transfer mode select, using I2C_MODE defalut */
+ enum TransMode mode;
+ /** CCC(Common Command Code) structure, which is used in CCC_CMD_MODE transfer mode */
+ struct I3cCccCmd *ccc;
+ /** I3C error code, update by driver */
+ uint16_t err;
+};
+
+/**
+ * @brief Defines the data of I3C IBI(In-Band Interrupt).
+ *
+ * @attention The data of IBI can be obtained by payload and buf in the IBI function when generate an IBI.
+ *
+ * @since 1.0
+ */
+struct I3cIbiData {
+ /** payload data length. Indicates the length of IBI payload data. It is automatically generated when an
+ * IBI is generated, do not modify while reading.
+ */
+ uint32_t payload;
+ /** data buffer. The pointer of payload data. */
+ uint8_t *buf;
+};
+
+enum I3cFlag {
+ /** Read flag. The value 1 indicates the read operation, and 0 indicates the write operation. */
+ I3C_FLAG_READ = (0x1 << 0),
+ /** Non-ACK read flag. The value 1 indicates that no ACK signal is sent during the read process. */
+ I3C_FLAG_READ_NO_ACK = (0x1 << 11),
+ /** Ignoring no-ACK flag. The value 1 indicates that the non-ACK signal is ignored. */
+ I3C_FLAG_IGNORE_NO_ACK = (0x1 << 12),
+ /**
+ * No START condition flag. The value 1 indicates that there is no START condition for the message
+ * transfer.
+ */
+ I3C_FLAG_NO_START = (0x1 << 14),
+ /** STOP condition flag. The value 1 indicates that the current transfer ends with a STOP condition. */
+ I3C_FLAG_STOP = (0x1 << 15),
+};
+
+/**
+ * @brief IBI(In-Band Interrupt) callback function.
+ *
+ * Use {@link I3cRequestIbi} to attach it to an I3C device.
+ *
+ * @param handle Indicates the pointer to the device handle of the I3C controller obtained via {@link I3cOpen}.
+ * @param addr Indicates the address of device to requeset IBI(In-Band Interrupt).
+ * @param data Indicates the data structure of IBI.
+ *
+ * @return Returns 0 if the operation is successful; Returns a negative value otherwise.
+ * @since 1.0
+ */
+typedef int32_t (*I3cIbiFunc)(DevHandle handle, uint16_t addr, struct I3cIbiData data);
+
+/**
+ * @brief Obtains the handle of an I3C controller.
+ *
+ * You must call this function before accessing the I3C bus.
+ *
+ * @param number Indicates the I3C controller ID.
+ *
+ * @return Returns the pointer to the {@link DevHandle} of the I3C controller if the operation is successful;
+ * returns NULL otherwise.
+ *
+ * @since 1.0
+ */
+DevHandle I3cOpen(int16_t number);
+
+ /**
+ * @brief Releases the handle of an I3C controller.
+ *
+ * If you no longer need to access the I3C controller, you should call this function to close its handle so as
+ * to release unused memory resources.
+ *
+ * @param handle Indicates the pointer to the device handle of the I3C controller obtained via {@link I3cOpen}.
+ *
+ * @since 1.0
+ */
+void I3cClose(DevHandle handle);
+
+ /**
+ * @brief Launches an transfer to an I3C device or a compatible I2C device,
+ * or send a CCC (Common Command Code) to an I3C device which is supported.
+ *
+ * @param handle Indicates the pointer to the device handle of the I3C controller obtained via {@link I3cOpen}.
+ * @param msg Indicates the pointer to the I3C transfer message structure array.
+ * @param count Indicates the length of the message structure array.
+ * @param mode Indicates the transmission mode.
+ *
+ * @return Returns the number of transferred message structures if the operation is successful;
+ * returns a negative value otherwise.
+ * @see I3cMsg
+ * @attention This function does not limit the number of message structures specified by count or the data
+ * length of each message structure. The specific I3C controller determines the maximum number and data length allowed.
+ *
+ * @since 1.0
+ */
+int32_t I3cTransfer(DevHandle handle, struct I3cMsg *msg, int16_t count, enum TransMode mode);
+
+ /**
+ * @brief Requeset an IBI(in-bind interrupt) for an I3C device which is supported.
+ *
+ * @param handle Indicates the pointer to the device handle of the I3C controller obtained via {@link I3cOpen}.
+ * @param addr Indicates the address of device to requeset IBI(In-Band Interrupt).
+ * @param func Indicates the call back function of the IBI.
+ * @param payload Indicates the length of payload data, in bytes.
+ *
+ * @return Returns 0 if the operation is successful; Returns a negative value otherwise.
+ *
+ * @since 1.0
+ */
+int32_t I3cRequestIbi(DevHandle handle, uint16_t addr, I3cIbiFunc func, uint32_t payload);
+
+ /**
+ * @brief Free the IBI(in-bind interrupt) which is Requeseted by {@link I3cRequestIbi}.
+ *
+ * @param handle Indicates the pointer to the device handle of the I3C controller obtained via {@link I3cOpen}.
+ * @param addr Indicates the address of device to free IBI.
+ *
+ * @return Returns 0 if the operation is successful; Returns a negative value otherwise.
+ *
+ * @since 1.0
+ */
+int32_t I3cFreeIbi(DevHandle handle, uint16_t addr);
+
+ /**
+ * @brief Set the config of a I3C controller.
+ *
+ * @param handle Indicates the pointer to the device handle of the I3C controller obtained via {@link I3cOpen}.
+ * @param config Indicates the pointer of a configuration structure to set.
+ *
+ * @return Returns 0 if the operation is successful; Returns a negative value otherwise.
+ *
+ * @since 1.0
+ */
+int32_t I3cSetConfig(DevHandle handle, struct I3cConfig *config);
+
+ /**
+ * @brief Get the config of a I3C controller.
+ *
+ * @param handle Indicates the pointer to the device handle of the I3C controller obtained via {@link I3cOpen}.
+ * @param config Indicates the structure used to store the configuration.
+ *
+ * @return Returns 0 if the operation is successful; Returns a negative value otherwise.
+ *
+ * @since 1.0
+ */
+int32_t I3cGetConfig(DevHandle handle, struct I3cConfig *config);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* __cplusplus */
+
+#endif /* I3C_IF_H */
+/** @} */
diff --git a/include/platform/mipi_csi_if.h b/include/platform/mipi_csi_if.h
new file mode 100755
index 0000000000000000000000000000000000000000..875cac07dda077885639d4bbfe5fa6e7233d1592
--- /dev/null
+++ b/include/platform/mipi_csi_if.h
@@ -0,0 +1,557 @@
+/*
+ * Copyright (c) 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.
+ */
+
+/**
+ * @addtogroup MIPI CSI
+ * @{
+ *
+ * @brief Defines standard MIPI CSI APIs for display driver development.
+ *
+ * This MIPI CSI module abstracts MIPI CSI capabilities of different system platforms to provide stable APIs
+ * for display driver development. You can use this module to obtain/release the MIPI CSI device handle,
+ * initialize the MIPI CSI device, and send/receive commands that interact with display peripherals.
+ *
+ * @since 1.0
+ */
+
+/**
+ * @file mipi_csi_if.h
+ *
+ * @brief Declares standard MIPI CSI APIs for display driver development.
+ *
+ *
+ *
+ * @since 1.0
+ */
+
+#ifndef MIPI_CSI_IF_H
+#define MIPI_CSI_IF_H
+
+#include "hdf_platform.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* __cplusplus */
+
+/**
+ * @brief Maximum number of lanes supported by MIPI RX's Mipi device.
+ *
+ * @since 1.0
+ */
+#define MIPI_LANE_NUM 4
+
+/**
+ * @brief The maximum number of lanes supported by the LVDS device of Mipi Rx.
+ *
+ * @since 1.0
+ */
+#define LVDS_LANE_NUM 4
+
+/**
+ * @brief Defines the maximum number of virtual channels supported.
+ *
+ * @since 1.0
+ */
+#define WDR_VC_NUM 4
+
+/**
+ * @brief Define the number of synchronization codes for each virtual channel of LVDS.
+ *
+ * @since 1.0
+ */
+#define SYNC_CODE_NUM 4
+
+/**
+ * @brief Maximum 3 groups of extended data types.
+ *
+ * @since 1.0
+ */
+#define MAX_EXT_DATA_TYPE_NUM 3
+
+/**
+ * @brief Lane distribution of Mipi Rx.
+ *
+ * @since 1.0
+ */
+typedef enum {
+ LANE_DIVIDE_MODE_0 = 0,
+ LANE_DIVIDE_MODE_1 = 1,
+ LANE_DIVIDE_MODE_BUTT
+} LaneDivideMode;
+
+/**
+ * @brief MIPI RX input interface type.
+ *
+ * @since 1.0
+ */
+typedef enum {
+ /** mipi */
+ INPUT_MODE_MIPI = 0x0,
+ /** SUB_LVDS */
+ INPUT_MODE_SUBLVDS = 0x1,
+ /** LVDS */
+ INPUT_MODE_LVDS = 0x2,
+ /* HISPI */
+ INPUT_MODE_HISPI = 0x3,
+ /** CMOS */
+ INPUT_MODE_CMOS = 0x4,
+ /** BT601 */
+ INPUT_MODE_BT601 = 0x5,
+ /** BT656 */
+ INPUT_MODE_BT656 = 0x6,
+ /** BT1120 */
+ INPUT_MODE_BT1120 = 0x7,
+ /** MIPI Bypass */
+ INPUT_MODE_BYPASS = 0x8,
+ INPUT_MODE_BUTT
+} InputMode;
+
+/**
+ * @brief Mipi Rx, SLVS input rate.
+ *
+ * @since 1.0
+ */
+typedef enum {
+ /** output 1 pixel per clock */
+ MIPI_DATA_RATE_X1 = 0,
+ /** output 2 pixel per clock */
+ MIPI_DATA_RATE_X2 = 1,
+ MIPI_DATA_RATE_BUTT
+} MipiDataRate;
+
+/**
+ * @brief Mipi crop area properties.
+ *
+ * @since 1.0
+ */
+typedef struct {
+ int x;
+ int y;
+ unsigned int width;
+ unsigned int height;
+} ImgRect;
+
+/**
+ * @brief Type of data transmitted.
+ *
+ * @since 1.0
+ */
+typedef enum {
+ DATA_TYPE_RAW_8BIT = 0,
+ DATA_TYPE_RAW_10BIT,
+ DATA_TYPE_RAW_12BIT,
+ DATA_TYPE_RAW_14BIT,
+ DATA_TYPE_RAW_16BIT,
+ DATA_TYPE_YUV420_8BIT_NORMAL,
+ DATA_TYPE_YUV420_8BIT_LEGACY,
+ DATA_TYPE_YUV422_8BIT,
+ /** yuv422 8bit transform user define 16bit raw */
+ DATA_TYPE_YUV422_PACKED,
+ DATA_TYPE_BUTT
+} DataType;
+
+/**
+ * @brief Define YUV and RAW data format and bit depth.
+ *
+ * @since 1.0
+ */
+typedef struct {
+ uint8_t devno;
+ unsigned int num;
+ unsigned int extDataBitWidth[MAX_EXT_DATA_TYPE_NUM];
+ unsigned int extDataType[MAX_EXT_DATA_TYPE_NUM];
+} ExtDataType;
+
+/**
+ * @brief MIPI D-PHY WDR MODE defines
+ *
+ * @since 1.0
+ */
+typedef enum {
+ HI_MIPI_WDR_MODE_NONE = 0x0,
+ /** Virtual Channel */
+ HI_MIPI_WDR_MODE_VC = 0x1,
+ /** Data Type */
+ HI_MIPI_WDR_MODE_DT = 0x2,
+ /** DOL Mode */
+ HI_MIPI_WDR_MODE_DOL = 0x3,
+ HI_MIPI_WDR_MODE_BUTT
+} MipiWdrMode;
+
+/**
+ * @brief Mipi device properties.
+ *
+ * @since 1.0
+ */
+typedef struct {
+ /** data type: 8/10/12/14/16 bit */
+ DataType inputDataType;
+ /** MIPI WDR mode */
+ MipiWdrMode wdrMode;
+ /** laneId: -1 - disable */
+ short laneId[MIPI_LANE_NUM];
+
+ union {
+ /** used by the HI_MIPI_WDR_MODE_DT */
+ short dataType[WDR_VC_NUM];
+ };
+} MipiDevAttr;
+
+/**
+ * @brief LVDS WDR mode.
+ *
+ * @since 1.0
+ */
+typedef enum {
+ HI_WDR_MODE_NONE = 0x0,
+ HI_WDR_MODE_2F = 0x1,
+ HI_WDR_MODE_3F = 0x2,
+ HI_WDR_MODE_4F = 0x3,
+ HI_WDR_MODE_DOL_2F = 0x4,
+ HI_WDR_MODE_DOL_3F = 0x5,
+ HI_WDR_MODE_DOL_4F = 0x6,
+ HI_WDR_MODE_BUTT
+} WdrMode;
+
+/**
+ * @brief LVDS synchronization mode.
+ *
+ * @since 1.0
+ */
+typedef enum {
+ /** sensor SOL, EOL, SOF, EOF */
+ LVDS_SYNC_MODE_SOF = 0,
+ /** SAV, EAV */
+ LVDS_SYNC_MODE_SAV,
+ LVDS_SYNC_MODE_BUTT
+} LvdsSyncMode;
+
+/**
+ * @brief LVDS Vsync type.
+ *
+ * @since 1.0
+ */
+typedef enum {
+ LVDS_VSYNC_NORMAL = 0x00,
+ LVDS_VSYNC_SHARE = 0x01,
+ LVDS_VSYNC_HCONNECT = 0x02,
+ LVDS_VSYNC_BUTT
+} LvdsVsyncType;
+
+/**
+ * @brief LVDS Vsync column synchronization parameters.
+ *
+ * @since 1.0
+ */
+typedef struct {
+ LvdsVsyncType syncType;
+
+ /* hconnect vsync blanking len, valid when the syncType is LVDS_VSYNC_HCONNECT */
+ unsigned short hblank1;
+ unsigned short hblank2;
+} LvdsVsyncAttr;
+
+/**
+ * @brief Frame ID type.
+ *
+ * @since 1.0
+ */
+typedef enum {
+ LVDS_FID_NONE = 0x00,
+ /** frame identification id in SAV 4th */
+ LVDS_FID_IN_SAV = 0x01,
+ /** frame identification id in first data */
+ LVDS_FID_IN_DATA = 0x02,
+ LVDS_FID_BUTT
+} LvdsFidType;
+
+/**
+ * @brief Frame ID configuration information.
+ *
+ * @since 1.0
+ */
+typedef struct {
+ LvdsFidType fidType;
+
+ /** Sony DOL has the Frame Information Line, in DOL H-Connection mode,
+ should configure this flag as false to disable output the Frame Information Line */
+ unsigned char outputFil;
+} LvdsFidAttr;
+
+/**
+ * @brief LVDS bit size end mode.
+ *
+ * @since 1.0
+ */
+typedef enum {
+ LVDS_ENDIAN_LITTLE = 0x0,
+ LVDS_ENDIAN_BIG = 0x1,
+ LVDS_ENDIAN_BUTT
+} LvdsBitEndian;
+
+/**
+ * @brief LVDS / SubLVDS / HiSPi device properties.
+ *
+ * @since 1.0
+ */
+typedef struct {
+ /** data type: 8/10/12/14 bit */
+ DataType inputDataType;
+ /** WDR mode */
+ WdrMode wdrMode;
+
+ /** sync mode: SOF, SAV */
+ LvdsSyncMode syncMode;
+ /** normal, share, hconnect */
+ LvdsVsyncAttr vsyncAttr;
+ /** frame identification code */
+ LvdsFidAttr fidAttr;
+
+ /** data endian: little/big */
+ LvdsBitEndian dataEndian;
+ /** sync code endian: little/big */
+ LvdsBitEndian syncCodeEndian;
+ /** laneId: -1 - disable */
+ short laneId[LVDS_LANE_NUM];
+
+ /** each vc has 4 params, syncCode[i]:
+ syncMode is SYNC_MODE_SOF: SOF, EOF, SOL, EOL
+ syncMode is SYNC_MODE_SAV: invalid sav, invalid eav, valid sav, valid eav */
+ unsigned short syncCode[LVDS_LANE_NUM][WDR_VC_NUM][SYNC_CODE_NUM];
+} LvdsDevAttr;
+
+/**
+ * @brief The attribute of the combo device.
+ *
+ * Since MIPI RX can interface with CSI-2, LVDS, HiSPi and other timing, Mipi Rx is called a combo device.
+ *
+ * @since 1.0
+ */
+typedef struct {
+ /** device number */
+ uint8_t devno;
+ /** input mode: MIPI/LVDS/SUBLVDS/HISPI/DC */
+ InputMode inputMode;
+ MipiDataRate dataRate;
+ /** MIPI Rx device crop area (corresponding to the oringnal sensor input image size) */
+ ImgRect imgRect;
+
+ union {
+ MipiDevAttr mipiAttr;
+ LvdsDevAttr lvdsAttr;
+ };
+} ComboDevAttr;
+
+/**
+ * @brief PHY common mode voltage mode.
+ *
+ * @since 1.0
+ */
+typedef enum {
+ PHY_CMV_GE1200MV = 0x00,
+ PHY_CMV_LT1200MV = 0x01,
+ PHY_CMV_BUTT
+} PhyCmvMode;
+
+/**
+ * @brief Obtains the MIPI CSI device handle with a specified channel ID.
+ *
+ * @param id Indicates the MIPI CSI channel ID.
+ *
+ * @return Returns the MIPI CSI device handle if the operation is successful; returns NULL otherwise.
+ *
+ * @since 1.0
+ */
+DevHandle MipiCsiOpen(uint8_t id);
+
+/**
+ * @brief Releases the MIPI CSI device handle.
+ *
+ * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
+ *
+ * @since 1.0
+ */
+void MipiCsiClose(DevHandle handle);
+
+/**
+ * @brief Set the parameters of Mipi, CMOS or LVDS camera to the controller.
+ *
+ * The parameters including working mode, image area, image depth, data rate and physical channel.
+ *
+ * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
+ * @param pAttr Indicates the pointer to the attribute.
+ *
+ * @return Returns 0 if the operation is successful; returns a negative value otherwise.
+ *
+ * @since 1.0
+ */
+int32_t MipiCsiSetComboDevAttr(DevHandle handle, ComboDevAttr *pAttr);
+
+/**
+ * @brief Set common mode voltage mode.
+ *
+ * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
+ * @param devno There are 2 device numbers in total, pointing to 0 or 1.
+ * @param cmvMode Common mode voltage mode parameters.
+ *
+ * @return Returns 0 if the operation is successful; returns a negative value otherwise.
+ *
+ * @since 1.0
+ */
+int32_t MipiCsiSetPhyCmvmode(DevHandle handle, uint8_t devno, PhyCmvMode cmvMode);
+
+/**
+ * @brief Reset sensor.
+ *
+ * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
+ * @param snsResetSource The reset signal line number of sensor is called the reset source of sensor in software.
+ * sns is the abbreviation of sensor.
+ *
+ * @return Returns 0 if the operation is successful; returns a negative value otherwise.
+ *
+ * @since 1.0
+ */
+int32_t MipiCsiResetSensor(DevHandle handle, uint8_t snsResetSource);
+
+/**
+ * @brief Unreset sensor.
+ *
+ * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
+ * @param snsResetSource The reset signal line number of sensor is called the reset source of sensor in software.
+ * sns is the abbreviation of sensor.
+ *
+ * @return Returns 0 if the operation is successful; returns a negative value otherwise.
+ *
+ * @since 1.0
+ */
+int32_t MipiCsiUnresetSensor(DevHandle handle, uint8_t snsResetSource);
+
+/**
+ * @brief Reset Mipi Rx.
+ *
+ * Different s32WorkingViNum have different enSnsType.
+ *
+ * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
+ * @param comboDev MIPI RX or LVDS device type.
+ *
+ * @return Returns 0 if the operation is successful; returns a negative value otherwise.
+ *
+ * @since 1.0
+ */
+int32_t MipiCsiResetRx(DevHandle handle, uint8_t comboDev);
+
+/**
+ * @brief Uneset MIPI RX.
+ *
+ * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
+ * @param comboDev MIPI RX or LVDS device type.
+ *
+ * @return Returns 0 if the operation is successful; returns a negative value otherwise.
+ *
+ * @since 1.0
+ */
+int32_t MipiCsiUnresetRx(DevHandle handle, uint8_t comboDev);
+
+/**
+ * @brief Set the lane distribution of Mipi Rx.
+ *
+ * Select the specific mode according to the form of hardware connection.
+ *
+ * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
+ * @param laneDivideMode Lane division mode parameters.
+ *
+ * @since 1.0
+ */
+int32_t MipiCsiSetHsMode(DevHandle handle, LaneDivideMode laneDivideMode);
+
+/**
+ * @brief Enable Mipi clock.
+ *
+ * Decide whether to use Mipi or LVDS according to the ensnstype parameter
+ * passed by the upper layer function.
+ *
+ * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
+ * @param comboDev MIPI RX or LVDS device type.
+ *
+ * @return Returns 0 if the operation is successful; returns a negative value otherwise.
+ *
+ * @since 1.0
+ */
+int32_t MipiCsiEnableClock(DevHandle handle, uint8_t comboDev);
+
+/**
+ * @brief Disable the clock of Mipi device.
+ *
+ * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
+ * @param comboDev MIPI RX or LVDS device type.
+ *
+ * @return Returns 0 if the operation is successful; returns a negative value otherwise.
+ *
+ * @since 1.0
+ */
+int32_t MipiCsiDisableClock(DevHandle handle, uint8_t comboDev);
+
+/**
+ * @brief Enable the sensor clock on Mipi.
+ *
+ * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
+ * @param snsClkSource The clock signal line number of sensor, which is called the clock source of sensor in software.
+ * sns is the abbreviation of sensor.
+ *
+ * @return Returns 0 if the operation is successful; returns a negative value otherwise.
+ *
+ * @since 1.0
+ */
+int32_t MipiCsiEnableSensorClock(DevHandle handle, uint8_t snsClkSource);
+
+/**
+ * @brief Disable the sensor clock.
+ *
+ * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
+ * @param snsClkSource The clock signal line number of sensor, which is called the clock source of sensor in software.
+ * sns is the abbreviation of sensor.
+ *
+ * @return Returns 0 if the operation is successful; returns a negative value otherwise.
+ *
+ * @since 1.0
+ */
+int32_t MipiCsiDisableSensorClock(DevHandle handle, uint8_t snsClkSource);
+
+/**
+ * @brief Set YUV and RAW data format and bit depth.
+ *
+ * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
+ * @param dataType Pointer to image data format.
+ *
+ * @return Returns 0 if the operation is successful; returns a negative value otherwise.
+ *
+ * @since 1.0
+ */
+int32_t MipiCsiSetExtDataType(DevHandle handle, ExtDataType* dataType);
+
+/**
+ * @brief Sets additional parameters for a MIPI CSI device.
+ *
+ * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
+ * @param drvData Indicates the pointer to the additional parameters.
+ *
+ * @return Returns 0 if the operation is successful; returns a negative value otherwise.
+ *
+ * @since 1.0
+ */
+int32_t MipiCsiSetDrvData(DevHandle handle, void *drvData);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* __cplusplus */
+
+#endif /* MIPI_CSI_IF_H */
diff --git a/include/platform/mipi_dsi_if.h b/include/platform/mipi_dsi_if.h
index ca6b5d6cb2a7601f1da624ae93a05707c1f830a3..e77b45f3bef7c5d70b4b2c471d92c56f602d62f6 100644
--- a/include/platform/mipi_dsi_if.h
+++ b/include/platform/mipi_dsi_if.h
@@ -291,6 +291,18 @@ int32_t MipiDsiRx(DevHandle handle, struct DsiCmdDesc *cmd, int32_t readLen, uin
*/
int32_t MipiDsiAttach(DevHandle handle, uint8_t *name);
+/**
+ * @brief Sets additional parameters for a MIPI DSI device.
+ *
+ * @param handle Indicates the MIPI DSI device handle obtained via {@link MipiDsiOpen}.
+ * @param panelData Indicates the pointer to the additional parameters.
+ *
+ * @return Returns 0 if the operation is successful; returns a negative value otherwise.
+ *
+ * @since 1.0
+ */
+int32_t MipiDsiSetDrvData(DevHandle handle, void *panelData);
+
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/include/platform/pin_if.h b/include/platform/pin_if.h
new file mode 100644
index 0000000000000000000000000000000000000000..b42e71aa2b48d3c428d0fe6ff2ae96a59e85072b
--- /dev/null
+++ b/include/platform/pin_if.h
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 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.
+ */
+
+/**
+ * @file pin_if.h
+ *
+ * @brief Declares the standard pin interface functions.
+ *
+ * @since 1.0
+ */
+
+#ifndef PIN_IF_H
+#define PIN_IF_H
+
+#include "hdf_platform.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* __cplusplus */
+
+/**
+ * @brief Enumerates pin pull types.
+ *
+ * @since 1.0
+ */
+enum PinPullType {
+ PIN_PULL_NONE = 0, /**< SET PIN SUSPEND. */
+ PIN_PULL_UP = 1, /**< SET PIN RESISTANCE UP. */
+ PIN_PULL_DOWN = 2, /**< SET PIN RESISTANCE DOWN. */
+};
+/**
+ * @brief Obtains the handle of a pin.
+ *
+ * You must call this function before setting a pin properties.
+ *
+ * @param pinName Indicates the pin which you want to setting properties.
+ *
+ * @return Returns the pointer to the {@link DevHandle} of the pin controller which
+ * to get a pin if the operation is successful;
+ * returns NULL otherwise.
+ * @since 1.0
+ */
+DevHandle PinGet(const char *pinName);
+
+/**
+ * @brief Releases the handle of a pin.
+ *
+ * If you no longer need to access the pin, you should call this function to close its handle so as
+ * to release unused memory resources.
+ *
+ * @param handle Indicates the pointer to the device handle of the pin.
+ *
+ * @since 1.0
+ */
+void PinPut(DevHandle handle);
+
+/**
+ * @brief Set the pin pullType configuration.
+ *
+ * You can call this function when you need to set the pin pull configuration.
+ * @param handle Indicates the pointer to the device handle of the pin.
+ * @param pullType Indicates the type of pin pull.
+ *
+ * @return Returns 0 if set the pin Pull configuration operation is successfully;
+ * Returns a negative value otherwise.
+ * @since 1.0
+ */
+int32_t PinSetPull(DevHandle handle, enum PinPullType pullType);
+
+/**
+ * @brief Get the pin pullType configuration.
+ *
+ * You can call this function when you need to get the pin pull configuration.
+ *
+ * @param handle Indicates the pointer to the device handle of the pin.
+ * @param pullType Indicates the pointer of the Pin Pull Type.
+ * @return Returns 0 if get the pin Pull configuration operation is successfully;
+ * Returns a negative value otherwise.
+ * @since 1.0
+ */
+int32_t PinGetPull(DevHandle handle, enum PinPullType *pullType);
+
+/**
+ * @brief Set the pin strength configuration.
+ *
+ * You can call this function when you need to set the pin strength configuration.
+ * @param handle Indicates the pointer to the device handle of the pin.
+ * @param strength Indicates the value of pin strength.
+ *
+ * @return Returns 0 if set the pin strength configuration operation is successfully;
+ * Returns a negative value otherwise.
+ * @since 1.0
+ */
+int32_t PinSetStrength(DevHandle handle, uint32_t strength);
+
+/**
+ * @brief Get the pin strength configuration.
+ *
+ * You can call this function when you need to get the pin strength configuration.
+ *
+ * @param handle Indicates the pointer to the device handle of the pin.
+ * @param strength Indicates the pointer of the Pin strength value.
+ * @return Returns 0 if get the pin strength configuration operation is successfully;
+ * Returns a negative value otherwise.
+ * @since 1.0
+ */
+int32_t PinGetStrength(DevHandle handle, uint32_t *strength);
+
+/**
+ * @brief Set the pin function configuration.
+ *
+ * You can call this function when you need to set the pin function configuration.
+ *
+ * @param handle Indicates the pointer to the device handle of the pin description.
+ * @param funcName Indicates the pointer of the pin function.
+ * @return Returns 0 if set the pin function configuration operation is successfully;
+ * returns a negative value otherwise.
+ * @since 1.0
+ */
+int32_t PinSetFunc(DevHandle handle, const char *funcName);
+
+/**
+ * @brief Get the pin function configuration.
+ *
+ * You can call this function when you need to get the pin function configuration.
+ *
+ * @param handle Indicates the pointer to the device handle of the pin description.
+ * @param funcName Indicates the double pointer of the pin function.
+ * @return Returns 0 if get the pin function configuration operation is successfully;
+ * returns a negative value otherwise.
+ * @since 1.0
+ */
+int32_t PinGetFunc(DevHandle handle, const char **funcName);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* __cplusplus */
+
+#endif /* PIN_IF_H */
diff --git a/include/platform/regulator_if.h b/include/platform/regulator_if.h
new file mode 100755
index 0000000000000000000000000000000000000000..d3d01a9f9945b8b0c9c37f89202dd08611a8627c
--- /dev/null
+++ b/include/platform/regulator_if.h
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 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.
+ */
+
+
+#ifndef REGULATOR_IF_H
+#define REGULATOR_IF_H
+
+#include "hdf_platform.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* __cplusplus */
+
+/* regulator status on or off */
+enum RegulatorStatus {
+ REGULATOR_STATUS_ON = 1,
+ REGULATOR_STATUS_OFF,
+};
+
+/* regulator mode, set voltage or current */
+enum RegulatorChangeMode {
+ REGULATOR_CHANGE_VOLTAGE = 1,
+ REGULATOR_CHANGE_CURRENT,
+};
+/**
+ * @brief Gets a regulator.
+ *
+ * This function must be called to get its device handle before operating the regulator.
+ *
+ * @param name Indicates regulator name.
+ *
+ * @return If the operation is successful, a pointer to the regulator device handle is returned.
+ *
+ * @since 1.0
+ */
+DevHandle RegulatorOpen(const char *name);
+/**
+ * @brief Releases a regulator.
+ *
+ * If you no longer need the regulator, call this function to release it
+ *
+ * @param handle Represents a pointer to the regulator device handle.
+ *
+ * @since 1.0
+ */
+void RegulatorClose(DevHandle handle);
+/**
+ * @brief Enables a regulator.
+ *
+ * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorOpen}.
+ * @return 0 If the regulator enables successfully; Otherwise, a negative value is returned.
+ *
+ * @attention That if the regulator has been enabled before calling this function, calling this function will succeed.
+ *
+ * @since 1.0
+ */
+int32_t RegulatorEnable(DevHandle handle);
+/**
+ * @brief Disable a regulator.
+ *
+ * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorOpen}.
+ * @return 0 If the regulator disable successfully; Otherwise, a negative value is returned.
+ *
+ * @attention If the regulator status alwayson is true or there is regulator child not disable, disabling fail
+ *
+ * @since 1.0
+ */
+int32_t RegulatorDisable(DevHandle handle);
+/**
+ * @brief Force disable a regulator.
+ *
+ * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorOpen}.
+ * @return 0 If the regulator disable successfully; Otherwise, a negative value is returned.
+ *
+ * @attention No matter whether the status of the regulator is alwayson or the status of the child is enable,
+ * the regulator is disabled.
+ *
+ * @since 1.0
+ */
+int32_t RegulatorForceDisable(DevHandle handle);
+/**
+ * @brief Set the output voltage range of a regulator.
+ *
+ * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorOpen}.
+ * @param minUv Represents minimum voltage
+ * @param minUv Represents maximum voltage
+ * @return 0 If the regulator setVoltage successfully; Otherwise, a negative value is returned.
+ *
+ * @attention If the set voltage is not within the contrants, the setting fails.
+ *
+ * @since 1.0
+ */
+int32_t RegulatorSetVoltage(DevHandle handle, uint32_t minUv, uint32_t maxUv);
+/**
+ * @brief Get a regulator voltage.
+ *
+ * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorOpen}.
+ * @param voltage Voltage obtained.
+ * @return 0 If the regulator get voltage successfully; Otherwise, a negative value is returned.
+ *
+ * @since 1.0
+ */
+int32_t RegulatorGetVoltage(DevHandle handle, uint32_t *voltage);
+/**
+ * @brief Set regulator current range
+ *
+ * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorOpen}.
+ * @param minUa Minimum current
+ * @param maxUa Maximum current
+ * @return 0 If the regulator set current range successfully; Otherwise, a negative value is returned.
+ *
+ * @attention If the setting range exceeds the limit, the setting fails
+ *
+ * @since 1.0
+ */
+int32_t RegulatorSetCurrent(DevHandle handle, uint32_t minUa, uint32_t maxUa);
+/**
+ * @brief Get a regulator current
+ *
+ * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorOpen}.
+ * @param voltage Current obtained
+ * @return 0 If the regulator getCurrent successfully; Otherwise, a negative value is returned.
+ *
+ * @since 1.0
+ */
+int32_t RegulatorGetCurrent(DevHandle handle, uint32_t *regCurrent);
+/**
+ * @brief Get a regulator status
+ *
+ * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorOpen}.
+ * @param status Status obtained, enable or disable
+ * @return 0 If the regulator get status successfully; Otherwise, a negative value is returned.
+ *
+ * @since 1.0
+ */
+int32_t RegulatorGetStatus(DevHandle handle, uint32_t *status);
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* __cplusplus */
+
+#endif /* REGULATOR_IF_H */
+/** @} */
\ No newline at end of file
diff --git a/include/platform/watchdog_if.h b/include/platform/watchdog_if.h
index be2682670c31898e5337e58adc5c27dbe8bfe42a..cb443e463fc8ccf86e68ac7d6721c7f9c2086bac 100644
--- a/include/platform/watchdog_if.h
+++ b/include/platform/watchdog_if.h
@@ -63,7 +63,7 @@ enum WatchdogStatus {
*
* @since 1.0
*/
-DevHandle WatchdogOpen(int16_t wdtId);
+int32_t WatchdogOpen(int16_t wdtId, DevHandle *handle);
/**
* @brief Closes a watchdog.
diff --git a/include/config/device_resource_if.h b/include/utils/device_resource_if.h
similarity index 100%
rename from include/config/device_resource_if.h
rename to include/utils/device_resource_if.h
diff --git a/include/utils/hcs_macro.h b/include/utils/hcs_macro.h
new file mode 100755
index 0000000000000000000000000000000000000000..6f0714b8fd3f55328f556abc6ad42c34136a1153
--- /dev/null
+++ b/include/utils/hcs_macro.h
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ */
+
+#ifndef HCS_MACRO_H
+#define HCS_MACRO_H
+
+// define utils macro
+#define HCS_CAT(part1, part2) part1 ## part2
+#define HCS_ROOT root
+
+// define macro for module
+#define HCS_NODE_EXISTS(node) HCS_CAT(node, _exists)
+#define HCS_NODE(parent, node) HCS_CAT(parent, _##node)
+#define HCS_NODE_HAS_PROP(node, prop) HCS_CAT(node, _##prop##_exists)
+#define HCS_PROP(node, prop) HCS_CAT(node, _##prop)
+
+#define HCS_FOREACH_CHILD(node, func) \
+ HCS_CAT(node, _foreach_child)(func)
+
+#define HCS_FOREACH_CHILD_VARGS(node, func, ...) \
+ HCS_CAT(node, _foreach_child_vargs)(func, __VA_ARGS__)
+
+#define HCS_ARRAYS(arrays_node) HCS_CAT(arrays_node, _data)
+
+#define HCS_ARRAYS_SIZE(arrays_node) HCS_CAT(arrays_node, _array_size)
+
+#endif // HCS_MACRO_H
\ No newline at end of file
diff --git a/ability/sbuf/include/hdf_sbuf.h b/include/utils/hdf_sbuf.h
similarity index 100%
rename from ability/sbuf/include/hdf_sbuf.h
rename to include/utils/hdf_sbuf.h
diff --git a/include/wifi/wifi_mac80211_ops.h b/include/wifi/wifi_mac80211_ops.h
index aa26a666d813fd88d0fb34e64104ece6b87fde5c..52c81b50bf89871d880561c912741379e86afe31 100644
--- a/include/wifi/wifi_mac80211_ops.h
+++ b/include/wifi/wifi_mac80211_ops.h
@@ -589,20 +589,6 @@ struct HdfMac80211BaseOps {
*/
int32_t (*GetHwCapability)(NetDevice *netDev, struct WlanHwCapability **capability);
- int32_t (*RemainOnChannel)(NetDevice *netDev, WifiOnChannel *onChannel);
-
- int32_t (*CancelRemainOnChannel)(NetDevice *netDev);
-
- int32_t (*ProbeReqReport)(NetDevice *netDev, int32_t report);
-
- int32_t (*AddIf)(NetDevice *netDev, WifiIfAdd *ifAdd);
-
- int32_t (*RemoveIf)(NetDevice *netDev, WifiIfRemove *ifRemove);
-
- int32_t (*SetApWpsP2pIe)(NetDevice *netDev, WifiAppIe *appIe);
-
- int32_t (*GetDriverFlag)(struct NetDevice *netDev, WifiGetDrvFlags **params);
-
int32_t (*SendAction)(struct NetDevice *netDev, WifiActionData *actionData);
int32_t (*GetIftype)(struct NetDevice *netDev, uint8_t *iftype);
@@ -792,5 +778,21 @@ struct HdfMac80211APOps {
int32_t (*GetAssociatedStasInfo)(NetDevice *netDev, WifiStaInfo *staInfo, uint32_t num);
};
+struct HdfMac80211P2POps {
+ int32_t (*RemainOnChannel)(NetDevice *netDev, WifiOnChannel *onChannel);
+
+ int32_t (*CancelRemainOnChannel)(NetDevice *netDev);
+
+ int32_t (*ProbeReqReport)(NetDevice *netDev, int32_t report);
+
+ int32_t (*AddIf)(NetDevice *netDev, WifiIfAdd *ifAdd);
+
+ int32_t (*RemoveIf)(NetDevice *netDev, WifiIfRemove *ifRemove);
+
+ int32_t (*SetApWpsP2pIe)(NetDevice *netDev, WifiAppIe *appIe);
+
+ int32_t (*GetDriverFlag)(struct NetDevice *netDev, WifiGetDrvFlags **params);
+};
+
#endif // WIFI_MAC80211_OPS_H
/** @} */
diff --git a/include/wifi/wifi_module.h b/include/wifi/wifi_module.h
index 6bb836c2da7979d00566dfba14bba3265fb39acc..bb2d85d96ccea07020ee192112a171feda5fccac 100644
--- a/include/wifi/wifi_module.h
+++ b/include/wifi/wifi_module.h
@@ -163,6 +163,7 @@ struct HdfChipDriver {
struct HdfMac80211BaseOps *ops; /**< MAC address for the basic feature */
struct HdfMac80211STAOps *staOps; /**< MAC address for the STA feature */
struct HdfMac80211APOps *apOps; /**< MAC address for the AP feature */
+ struct HdfMac80211P2POps *p2pOps; /**< MAC address for the P2Pfeature */
void *priv; /**< Private data of the chip driver */
/**
* @brief Initializes a chip driver.
diff --git a/model/audio/common/include/audio_accessory_base.h b/model/audio/common/include/audio_accessory_base.h
index ab0f94a06eb5bef64d733212169221c5fda576c7..2ee01ed99f0ebb7ee18c109d170e00c0c26a58ff 100755
--- a/model/audio/common/include/audio_accessory_base.h
+++ b/model/audio/common/include/audio_accessory_base.h
@@ -8,9 +8,12 @@
#ifndef AUDIO_ACCESSORY_BASE_H
#define AUDIO_ACCESSORY_BASE_H
-
-#include "audio_host.h"
#include "audio_control.h"
+#include "audio_core.h"
+#include "audio_host.h"
+#include "audio_parse.h"
+#include "audio_platform_base.h"
+#include "audio_sapm.h"
#ifdef __cplusplus
#if __cplusplus
@@ -48,17 +51,31 @@ enum I2sFrequencyRegVal {
I2S_SAMPLE_FREQUENCY_REG_VAL_96000 = 0xB /* 96kHz sample_rate */
};
-enum I2sFormatRegVal {
- I2S_SAMPLE_FORMAT_REG_VAL_MSB_24 = 0x2, /* MSB-justified data up to 24 bits */
- I2S_SAMPLE_FORMAT_REG_VAL_24 = 0x3, /* I2S data up to 24 bits */
- I2S_SAMPLE_FORMAT_REG_VAL_LSB_16 = 0x4, /* LSB-justified 16-bit data */
- I2S_SAMPLE_FORMAT_REG_VAL_LSB_18 = 0x5, /* LSB-justified 18-bit data */
- I2S_SAMPLE_FORMAT_REG_VAL_LSB_20 = 0x6, /* LSB-justified 20-bit data */
- I2S_SAMPLE_FORMAT_REG_VAL_LSB_24 = 0x7, /* LSB-justified 24-bit data */
+struct AccessoryTransferData {
+ uint16_t i2cDevAddr;
+ uint16_t i2cBusNumber;
+ uint32_t accessoryCfgCtrlCount;
+ struct AudioRegCfgGroupNode **accessoryRegCfgGroupNode;
+ struct AudioKcontrol *accessoryControls;
};
-int32_t FormatToBitWidth(enum AudioFormat format, uint16_t *bitWidth);
-int32_t RateToFrequency(uint32_t rate, uint16_t *freq);
+struct DaiParamsVal {
+ uint32_t frequencyVal;
+ uint32_t formatVal;
+ uint32_t channelVal;
+};
+
+int32_t AccessoryI2cReadWrite(struct AudioAddrConfig *regAttr, uint16_t rwFlag);
+int32_t AccessoryRegBitsRead(struct AudioMixerControl *regAttr, uint32_t *regValue);
+int32_t AccessoryRegBitsUpdate(struct AudioMixerControl regAttr);
+
+int32_t AcessoryDeviceFrequencyParse(uint32_t rate, uint16_t *freq);
+int32_t AccessoryDaiParamsUpdate(struct DaiParamsVal daiParamsVal);
+int32_t AccessoryDeviceCfgGet(struct AccessoryData *data, struct AccessoryTransferData *transferData);
+int32_t AccessoryDeviceCtrlRegInit(void);
+int32_t AccessoryDeviceRegRead(const struct AccessoryDevice *codec, uint32_t reg, uint32_t *value);
+int32_t AccessoryDeviceRegWrite(const struct AccessoryDevice *codec, uint32_t reg, uint32_t value);
+int32_t AccessoryGetConfigInfo(const struct HdfDeviceObject *device, struct AccessoryData *accessoryData);
#ifdef __cplusplus
#if __cplusplus
diff --git a/model/audio/common/include/audio_codec_base.h b/model/audio/common/include/audio_codec_base.h
index f4d5bf3b30c29715e1a8a722e4e83f3d166f6a5c..984da900edde4187a1c125511bdafe5093b9bb6d 100755
--- a/model/audio/common/include/audio_codec_base.h
+++ b/model/audio/common/include/audio_codec_base.h
@@ -19,12 +19,11 @@ extern "C" {
#endif
#endif /* __cplusplus */
-int32_t CodecDeviceReadReg(const struct CodecDevice *codec, uint32_t reg, uint32_t *value);
-int32_t CodecDeviceWriteReg(const struct CodecDevice *codec, uint32_t reg, uint32_t value);
-int32_t CodecAiaoDeviceReadReg(const struct CodecDevice *codec, uint32_t reg, uint32_t *value);
-int32_t CodecAiaoDeviceWriteReg(const struct CodecDevice *codec, uint32_t reg, uint32_t value);
int32_t CodecGetServiceName(const struct HdfDeviceObject *device, const char **drvCodecName);
int32_t CodecGetDaiName(const struct HdfDeviceObject *device, const char **drvDaiName);
+int32_t CodecGetConfigInfo(const struct HdfDeviceObject *device, struct CodecData *codecData);
+int32_t CodecSetConfigInfo(struct CodecData *codeData, struct DaiData *daiData);
+int32_t CodecSetCtlFunc(struct CodecData *codeData, const void *aiaoGetCtrl, const void *aiaoSetCtrl);
#ifdef __cplusplus
#if __cplusplus
diff --git a/model/audio/common/include/audio_dai_base.h b/model/audio/common/include/audio_dai_base.h
new file mode 100644
index 0000000000000000000000000000000000000000..cf70a793c7b457b5615de7020caeb0961ca4f405
--- /dev/null
+++ b/model/audio/common/include/audio_dai_base.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef AUDIO_DAI_BASE_H
+#define AUDIO_DAI_BASE_H
+
+#include "audio_codec_if.h"
+#include "audio_core.h"
+#include "osal_io.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* __cplusplus */
+
+struct DaiData *DaiDataFromCard(const struct AudioCard *card);
+int32_t DaiGetConfigInfo(const struct HdfDeviceObject *device, struct DaiData *data);
+int32_t DaiCheckSampleRate(unsigned int sampleRates);
+int32_t DaiSetConfigInfo(struct DaiData *data);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* __cplusplus */
+
+#endif
diff --git a/model/audio/common/include/audio_dma_base.h b/model/audio/common/include/audio_dma_base.h
new file mode 100644
index 0000000000000000000000000000000000000000..8bd5013d83f9771b1b25341c312a9c53f615c8fb
--- /dev/null
+++ b/model/audio/common/include/audio_dma_base.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef AUDIO_DMA_BASE_H
+#define AUDIO_DMA_BASE_H
+
+#include "audio_host.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* __cplusplus */
+
+int32_t AudioDmaBufAlloc(struct PlatformData *data, enum AudioStreamType streamType);
+int32_t AudioDmaBufFree(struct PlatformData *data, enum AudioStreamType streamType);
+int32_t AudioDmaRequestChannel(struct PlatformData *data);
+int32_t AudioDmaConfigChannel(struct PlatformData *data);
+int32_t AudioDmaPrep(struct PlatformData *data);
+int32_t AudioDmaSubmit(struct PlatformData *data);
+int32_t AudioDmaPending(struct PlatformData *data);
+int32_t AudioDmaPause(struct PlatformData *data);
+int32_t AudioDmaResume(struct PlatformData *data);
+int32_t AudioDmaPointer(struct PlatformData *data, uint32_t *pointer);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* __cplusplus */
+
+#endif
diff --git a/model/audio/common/include/audio_driver_log.h b/model/audio/common/include/audio_driver_log.h
new file mode 100644
index 0000000000000000000000000000000000000000..73ccacc24d6df9ef358c0f3082c239d311a82c08
--- /dev/null
+++ b/model/audio/common/include/audio_driver_log.h
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef AUDIO_DRIVER_LOG_H
+#define AUDIO_DRIVER_LOG_H
+#include "hdf_log.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* __cplusplus */
+
+// 1 is on; 0 is off
+#define AUDIO_ADM_DEBUG_ON 0
+#define AUDIO_DRIVER_DEBUG_ON 0
+#define AUDIO_DEVICE_DEBUG_ON 0
+
+// audio ADM log define
+#ifdef __LITEOS__
+#define ADM_LOG_DEBUG(fmt, arg...) do { \
+ } while (0)
+#elif AUDIO_ADM_DEBUG_ON
+#define ADM_LOG_DEBUG(fmt, arg...) do { \
+ HDF_LOGD("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
+ } while (0)
+#else
+#define ADM_LOG_DEBUG(fmt, arg...) do { \
+ } while (0)
+#endif
+
+#define ADM_LOG_ERR(fmt, arg...) do { \
+ HDF_LOGE("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
+ } while (0)
+
+#define ADM_LOG_INFO(fmt, arg...) do { \
+ HDF_LOGI("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
+ } while (0)
+
+#define ADM_LOG_WARNING(fmt, arg...) do { \
+ HDF_LOGW("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
+ } while (0)
+
+// audio driver log define
+#ifdef __LITEOS__
+#define AUDIO_DRIVER_LOG_DEBUG(fmt, arg...) do { \
+ } while (0)
+#elif AUDIO_DRIVER_DEBUG_ON
+#define AUDIO_DRIVER_LOG_DEBUG(fmt, arg...) do { \
+ HDF_LOGD("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
+ } while (0)
+#else
+#define AUDIO_DRIVER_LOG_DEBUG(fmt, arg...) do { \
+ } while (0)
+#endif
+
+#define AUDIO_DRIVER_LOG_ERR(fmt, arg...) do { \
+ HDF_LOGE("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
+ } while (0)
+
+#define AUDIO_DRIVER_LOG_INFO(fmt, arg...) do { \
+ HDF_LOGI("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
+ } while (0)
+
+#define AUDIO_DRIVER_LOG_WARNING(fmt, arg...) do { \
+ HDF_LOGW("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
+ } while (0)
+
+// audio device log define
+#ifdef __LITEOS__
+#define AUDIO_DEVICE_LOG_DEBUG(fmt, arg...) do { \
+ } while (0)
+#elif AUDIO_DEVICE_DEBUG_ON
+#define AUDIO_DEVICE_LOG_DEBUG(fmt, arg...) do { \
+ HDF_LOGD("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
+ } while (0)
+#else
+#define AUDIO_DEVICE_LOG_DEBUG(fmt, arg...) do { \
+ } while (0)
+#endif
+
+#define AUDIO_DEVICE_LOG_ERR(fmt, arg...) do { \
+ HDF_LOGE("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
+ } while (0)
+
+#define AUDIO_DEVICE_LOG_INFO(fmt, arg...) do { \
+ HDF_LOGI("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
+ } while (0)
+
+#define AUDIO_DEVICE_LOG_WARNING(fmt, arg...) do { \
+ HDF_LOGW("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
+ } while (0)
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* __cplusplus */
+
+#endif /* AUDIO_DRIVER_LOG_H */
diff --git a/model/audio/common/include/audio_dsp_base.h b/model/audio/common/include/audio_dsp_base.h
new file mode 100644
index 0000000000000000000000000000000000000000..5cf40234586024cc850dd4c72b4fa6614c060d7b
--- /dev/null
+++ b/model/audio/common/include/audio_dsp_base.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef AUDIO_DSP_BASE_H
+#define AUDIO_DSP_BASE_H
+
+#include "audio_host.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* __cplusplus */
+
+int32_t DspGetServiceName(const struct HdfDeviceObject *device, const char **drvDspName);
+int32_t DspGetDaiName(const struct HdfDeviceObject *device, const char **drvDaiName);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* __cplusplus */
+
+#endif /* AUDIO_DSP_BASE_H */
diff --git a/model/audio/common/include/audio_platform_base.h b/model/audio/common/include/audio_platform_base.h
index 72a9608c00157409484e92cef17c85e62537003f..b895710b8397adf192ed78acf676c5f381f74c81 100755
--- a/model/audio/common/include/audio_platform_base.h
+++ b/model/audio/common/include/audio_platform_base.h
@@ -9,7 +9,6 @@
#ifndef AUDIO_PLATFORM_BASE_H
#define AUDIO_PLATFORM_BASE_H
-#include "audio_platform_if.h"
#include "audio_host.h"
#ifdef __cplusplus
@@ -18,6 +17,10 @@ extern "C" {
#endif
#endif /* __cplusplus */
+#define MIN_PERIOD_SIZE 4096
+#define BITSTOBYTE 8
+#define MAX_BUFF_SIZE (64 * 1024)
+
enum DataBitWidth {
DATA_BIT_WIDTH8 = 8, /* 8 bit witdth */
DATA_BIT_WIDTH16 = 16, /* 16 bit witdth */
@@ -27,9 +30,60 @@ enum DataBitWidth {
DATA_BIT_WIDTH32 = 32, /* 32 bit witdth */
};
-struct PlatformData *PlatformDataFromDevice(const struct AudioCard *card);
-int32_t PlatformCreatePlatformHost(const struct AudioCard *card, struct PlatformHost **platformHost);
+enum PcmStatus {
+ PCM_STOP = 0, /* pcm stream stop flag */
+ PCM_PAUSE, /* pcm stream pause flag */
+ PCM_START, /* pcm stream start flag */
+};
+
+struct CircleBufInfo {
+ uint32_t cirBufSize; /* Current DMA cache size */
+ uint32_t trafBufSize; /* PCM data per transmission default size */
+ uint32_t period; /* not used */
+ uint32_t periodSize; /* DMA cache period size */
+ uint32_t periodCount; /* Number of DMA cache periods */
+ unsigned long phyAddr; /* DMA cache physical address */
+ uint32_t *virtAddr; /* DMA cache virtual address */
+ uint32_t wbufOffSet; /* DMA cache write address offset */
+ uint32_t wptrOffSet; /* DMA cache write pointer offset */
+ uint32_t rbufOffSet; /* DMA cache read address offset */
+ uint32_t rptrOffSet; /* DMA cache read pointer offset */
+ enum PcmStatus runStatus; /* PCM status */
+ uint32_t chnId; /* Channel ID */
+ uint32_t enable; /* Enable identification */
+ struct OsalMutex buffMutex; /* mutex */
+ uint32_t framesPosition; /* Frame position */
+ uint32_t pointer; /* Read/write pointer position during playback and recording */
+ uint32_t periodsMax; /* Maximum number of periods */
+ uint32_t periodsMin; /* Minimum number of periods */
+ uint32_t cirBufMax; /* Size of DMA cache requested */
+ uint32_t curTrafSize; /* The size of each actual transmission of PCM data */
+};
+
+unsigned int SysReadl(unsigned long addr);
+void SysWritel(unsigned long addr, unsigned int value);
+
+struct PlatformData *PlatformDataFromCard(const struct AudioCard *card);
+uint32_t AudioBytesToFrames(uint32_t frameBits, uint32_t size);
int32_t AudioDataBigEndianChange(char *srcData, uint32_t audioLen, enum DataBitWidth bitWidth);
+int32_t AudioFramatToBitWidth(enum AudioFormat format, unsigned int *bitWidth);
+int32_t AudioSetPcmInfo(struct PlatformData *platformData, const struct AudioPcmHwParams *param);
+int32_t AudioSetRenderBufInfo(struct PlatformData *data, const struct AudioPcmHwParams *param);
+int32_t AudioSetCaptureBufInfo(struct PlatformData *data, const struct AudioPcmHwParams *param);
+int32_t AudioPcmWrite(const struct AudioCard *card, struct AudioTxData *txData);
+int32_t AudioPcmRead(const struct AudioCard *card, struct AudioRxData *rxData);
+int32_t AudioPcmMmapWrite(const struct AudioCard *card, const struct AudioMmapData *txMmapData);
+int32_t AudioPcmMmapRead(const struct AudioCard *card, const struct AudioMmapData *rxMmapData);
+int32_t AudioRenderOpen(const struct AudioCard *card);
+int32_t AudioCaptureOpen(const struct AudioCard *card);
+int32_t AudioRenderClose(const struct AudioCard *card);
+int32_t AudioPcmPointer(const struct AudioCard *card, uint32_t *pointer);
+int32_t AudioCaptureClose(const struct AudioCard *card);
+int32_t AudioHwParams(const struct AudioCard *card, const struct AudioPcmHwParams *param);
+int32_t AudioRenderPrepare(const struct AudioCard *card);
+int32_t AudioCapturePrepare(const struct AudioCard *card);
+int32_t AudioRenderTrigger(struct AudioCard *card, int cmd);
+int32_t AudioCaptureTrigger(struct AudioCard *card, int cmd);
#ifdef __cplusplus
#if __cplusplus
diff --git a/model/audio/common/src/audio_accessory_base.c b/model/audio/common/src/audio_accessory_base.c
index 715440022f0330ad3440b6501ac106e6e1b1b32a..7e79e56fcbea61a10749d90fcf61872bb9f1bafe 100755
--- a/model/audio/common/src/audio_accessory_base.c
+++ b/model/audio/common/src/audio_accessory_base.c
@@ -7,29 +7,251 @@
*/
#include "audio_accessory_base.h"
-#include "audio_device_log.h"
+#include "audio_driver_log.h"
+#include "i2c_if.h"
+#include "osal_time.h"
-#define HDF_LOG_TAG audio_accessory_base
+#define HDF_LOG_TAG "audio_accessory_base"
-int32_t FormatToBitWidth(enum AudioFormat format, uint16_t *bitWidth)
+#define COMM_SHIFT_8BIT (8)
+#define COMM_MASK_FF (0xFF)
+#define COMM_WAIT_TIMES (10) // ms
+
+#define I2C_REG_LEN (1)
+#define I2C_REG_MSGLEN (3)
+#define I2C_MSG_NUM (2)
+#define I2C_MSG_BUF_SIZE (2)
+
+uint16_t g_i2cDevAddr, g_i2cBusNumber;
+struct AudioRegCfgGroupNode **g_audioRegCfgGroupNode = NULL;
+struct AudioKcontrol *g_audioControls = NULL;
+
+/*
+ * release I2C object public function
+ */
+static void AccessoryI2cRelease(struct I2cMsg *msgs, int16_t msgSize, DevHandle i2cHandle)
{
- // current set default format(standard) for 16/24 bit
- switch (format) {
- case AUDIO_FORMAT_PCM_16_BIT:
- *bitWidth = I2S_SAMPLE_FORMAT_REG_VAL_24;
- break;
- case AUDIO_FORMAT_PCM_24_BIT:
- *bitWidth = I2S_SAMPLE_FORMAT_REG_VAL_24;
- break;
- default:
- AUDIO_DEVICE_LOG_ERR("format: %d is not support.", format);
- return HDF_ERR_NOT_SUPPORT;
+ if (msgs != NULL) {
+ if (msgSize == 0 && msgs->buf != NULL) {
+ OsalMemFree(msgs->buf);
+ msgs->buf = NULL;
+ } else if (msgSize == 1 && msgs[0].buf != NULL) {
+ OsalMemFree(msgs[0].buf);
+ msgs[0].buf = NULL;
+ } else if (msgSize >= I2C_MSG_NUM) {
+ if (msgs[0].buf != NULL) {
+ msgs[0].buf = NULL;
+ }
+ if (msgs[1].buf != NULL) {
+ OsalMemFree(msgs[1].buf);
+ msgs[1].buf = NULL;
+ }
+ }
+ AUDIO_DRIVER_LOG_DEBUG("OsalMemFree msgBuf success.\n");
+ }
+ // close i2c device
+ if (i2cHandle != NULL) {
+ I2cClose(i2cHandle);
+ i2cHandle = NULL;
+ AUDIO_DRIVER_LOG_DEBUG("I2cClose success.\n");
+ }
+}
+
+static int32_t AccessoryI2cMsgFill(const struct AudioAddrConfig *regAttr, uint16_t rwFlag,
+ uint8_t *regs, struct I2cMsg *msgs)
+{
+ uint8_t *msgBuf = NULL;
+ if (rwFlag != 0 && rwFlag != I2C_FLAG_READ) {
+ AUDIO_DRIVER_LOG_ERR("invalid rwFlag value: %d.", rwFlag);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ regs[0] = regAttr->addr;
+ msgs[0].addr = g_i2cDevAddr;
+ msgs[0].flags = 0;
+ msgs[0].len = I2C_REG_MSGLEN;
+ AUDIO_DRIVER_LOG_DEBUG("msgs[0].addr=0x%02x, regs[0]=0x%02x.", msgs[0].addr, regs[0]);
+ if (rwFlag == 0) { // write
+ // S 11011A2A1 0 A ADDR A MS1 A LS1 A <....> P
+ msgBuf = OsalMemCalloc(I2C_REG_MSGLEN);
+ if (msgBuf == NULL) {
+ AUDIO_DRIVER_LOG_ERR("[write]: malloc buf failed!");
+ return HDF_ERR_MALLOC_FAIL;
+ }
+ msgBuf[0] = regs[0];
+ msgBuf[1] = (uint8_t)(regAttr->value >> COMM_SHIFT_8BIT); // High 8 bit
+ msgBuf[I2C_MSG_BUF_SIZE] = (uint8_t)(regAttr->value & COMM_MASK_FF); // Low 8 bit
+ msgs[0].buf = msgBuf;
+ AUDIO_DRIVER_LOG_DEBUG("msgBuf[1]=0x%02x.", msgBuf[1]);
+ AUDIO_DRIVER_LOG_DEBUG("msgBuf[2]=0x%02x.", msgBuf[I2C_MSG_BUF_SIZE]);
+ } else {
+ // S 11011A2A1 0 A ADDR A Sr 11011A2A1 1 A MS1 A LS1 A <....> NA P
+ msgBuf = OsalMemCalloc(I2C_MSG_NUM);
+ if (msgBuf == NULL) {
+ AUDIO_DRIVER_LOG_ERR("[read]: malloc buf failed!");
+ return HDF_ERR_MALLOC_FAIL;
+ }
+ msgs[0].len = 1;
+ msgs[0].buf = regs;
+ msgs[1].addr = g_i2cDevAddr;
+ msgs[1].flags = I2C_FLAG_READ;
+ msgs[1].len = I2C_MSG_NUM;
+ msgs[1].buf = msgBuf;
+ }
+ AUDIO_DRIVER_LOG_DEBUG("success.");
+ return HDF_SUCCESS;
+}
+
+int32_t AccessoryI2cReadWrite(struct AudioAddrConfig *regAttr, uint16_t rwFlag)
+{
+ int32_t ret;
+ DevHandle i2cHandle;
+ int16_t transferMsgCount = 1;
+ uint8_t regs[I2C_REG_LEN];
+ struct I2cMsg msgs[I2C_MSG_NUM];
+ (void)memset_s(msgs, sizeof(struct I2cMsg) * I2C_MSG_NUM, 0, sizeof(struct I2cMsg) * I2C_MSG_NUM);
+
+ AUDIO_DRIVER_LOG_DEBUG("entry.\n");
+ if (regAttr == NULL || rwFlag < 0 || rwFlag > 1) {
+ AUDIO_DRIVER_LOG_ERR("invalid parameter.");
+ return HDF_ERR_INVALID_PARAM;
+ }
+ i2cHandle = I2cOpen(g_i2cBusNumber);
+ if (i2cHandle == NULL) {
+ AUDIO_DRIVER_LOG_ERR("open i2cBus:%u failed! i2cHandle:%p", g_i2cBusNumber, i2cHandle);
+ return HDF_FAILURE;
+ }
+ if (rwFlag == I2C_FLAG_READ) {
+ transferMsgCount = I2C_MSG_NUM;
+ }
+ ret = AccessoryI2cMsgFill(regAttr, rwFlag, regs, msgs);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("AccessoryI2cMsgFill failed!");
+ I2cClose(i2cHandle);
+ return HDF_FAILURE;
+ }
+ ret = I2cTransfer(i2cHandle, msgs, transferMsgCount);
+ if (ret != transferMsgCount) {
+ AUDIO_DRIVER_LOG_ERR("I2cTransfer err:%d", ret);
+ AccessoryI2cRelease(msgs, transferMsgCount, i2cHandle);
+ return HDF_FAILURE;
+ }
+ if (rwFlag == I2C_FLAG_READ) {
+ regAttr->value = (msgs[1].buf[0] << COMM_SHIFT_8BIT) | msgs[1].buf[1]; // result value 16 bit
+ AUDIO_DRIVER_LOG_DEBUG("[read]: regAttr->regValue=0x%04x.\n", regAttr->value);
+ }
+ AccessoryI2cRelease(msgs, transferMsgCount, i2cHandle);
+ return HDF_SUCCESS;
+}
+
+// Read contrl reg bits value
+int32_t AccessoryRegBitsRead(struct AudioMixerControl *regAttr, uint32_t *regValue)
+{
+ int32_t ret;
+ struct AudioAddrConfig regVal;
+ if (regAttr == NULL || regAttr->reg < 0 || regValue == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input invalid parameter.");
+ return HDF_ERR_INVALID_PARAM;
+ }
+ regVal.addr = regAttr->reg;
+ ret = AccessoryI2cReadWrite(®Val, I2C_FLAG_READ);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("AccessoryRegBitsRead failed.");
+ return HDF_FAILURE;
+ }
+ *regValue = regVal.value;
+ regAttr->value = (regVal.value >> regAttr->shift) & regAttr->mask;
+ if (regAttr->value > regAttr->max || regAttr->value < regAttr->min) {
+ AUDIO_DRIVER_LOG_ERR("invalid bitsValue=0x%x", regAttr->value);
+ return HDF_FAILURE;
+ }
+ if (regAttr->invert) {
+ regAttr->value = regAttr->max - regAttr->value;
+ }
+ AUDIO_DRIVER_LOG_DEBUG("regAddr=0x%x, regValue=0x%x, currBitsValue=0x%x",
+ regAttr->reg, regVal.value, regAttr->value);
+ AUDIO_DRIVER_LOG_DEBUG("mask=0x%x, shift=%d, max=0x%x,min=0x%x, invert=%d",
+ regAttr->mask, regAttr->shift, regAttr->max, regAttr->min, regAttr->invert);
+ AUDIO_DRIVER_LOG_DEBUG("success.");
+ return HDF_SUCCESS;
+}
+
+// Update contrl reg bits value
+int32_t AccessoryRegBitsUpdate(struct AudioMixerControl regAttr)
+{
+ int32_t ret;
+ struct AudioAddrConfig regVal;
+ uint32_t newValue, newMask, value;
+ if (regAttr.reg < 0) {
+ AUDIO_DRIVER_LOG_ERR("input invalid parameter.");
+ return HDF_ERR_INVALID_PARAM;
+ }
+ if (regAttr.invert) {
+ regAttr.value = regAttr.max - regAttr.value;
+ }
+ newValue = regAttr.value << regAttr.shift;
+ newMask = regAttr.mask << regAttr.shift;
+ ret = AccessoryRegBitsRead(®Attr, &value);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("AccessoryRegBitsRead faileded, ret=%d.", ret);
+ return HDF_FAILURE;
+ }
+ regVal.value = (value & ~newMask) | (newValue & newMask);
+ regVal.addr = regAttr.reg;
+ ret = AccessoryI2cReadWrite(®Val, 0);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("AccessoryI2cReadWrite faileded.");
+ return HDF_FAILURE;
+ }
+ AUDIO_DRIVER_LOG_DEBUG("regAddr=0x%x, regValue=0x%x, oldValue=0x%x, newValue=0x%x,",
+ regAttr.reg, regVal.value, regAttr.value, newValue);
+ AUDIO_DRIVER_LOG_DEBUG(" mask=0x%x, shift=%d, max=0x%x, min=0x%x, invert=%d",
+ newMask, regAttr.shift, regAttr.max, regAttr.min, regAttr.invert);
+ AUDIO_DRIVER_LOG_DEBUG("success.");
+ return HDF_SUCCESS;
+}
+
+// update external codec I2S frequency
+int32_t AccessoryDaiParamsUpdate(struct DaiParamsVal daiParamsVal)
+{
+ int32_t ret;
+ const int itemNum = 3; // current only 3 items(frequency, format, channel)
+ struct AudioMixerControl *regAttr = NULL;
+ ret = (g_audioRegCfgGroupNode == NULL || g_audioRegCfgGroupNode[AUDIO_DAI_PATAM_GROUP] == NULL
+ || g_audioRegCfgGroupNode[AUDIO_DAI_PATAM_GROUP]->regCfgItem == NULL
+ || g_audioRegCfgGroupNode[AUDIO_DAI_PATAM_GROUP]->itemNum < itemNum);
+ if (ret) {
+ AUDIO_DRIVER_LOG_ERR("g_audioRegCfgGroupNode[AUDIO_DAI_PATAM_GROUP] is NULL.");
+ return HDF_FAILURE;
+ }
+ regAttr = g_audioRegCfgGroupNode[AUDIO_DAI_PATAM_GROUP]->regCfgItem;
+ regAttr[0].value = daiParamsVal.frequencyVal;
+ ret = AccessoryRegBitsUpdate(regAttr[0]);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("set freq failed.");
+ return HDF_FAILURE;
}
+ regAttr[1].value = daiParamsVal.formatVal;
+ ret = AccessoryRegBitsUpdate(regAttr[1]);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("set format failed.");
+ return HDF_FAILURE;
+ }
+ regAttr[itemNum - 1].value = daiParamsVal.channelVal;
+ ret = AccessoryRegBitsUpdate(regAttr[itemNum - 1]);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("set channel failed.");
+ return HDF_FAILURE;
+ }
+ AUDIO_DRIVER_LOG_DEBUG("success.");
return HDF_SUCCESS;
}
-int32_t RateToFrequency(uint32_t rate, uint16_t *freq)
+int32_t AcessoryDeviceFrequencyParse(uint32_t rate, uint16_t *freq)
{
+ if (freq == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input param is NULL");
+ return HDF_FAILURE;
+ }
switch (rate) {
case I2S_SAMPLE_FREQUENCY_8000:
*freq = I2S_SAMPLE_FREQUENCY_REG_VAL_8000;
@@ -68,8 +290,141 @@ int32_t RateToFrequency(uint32_t rate, uint16_t *freq)
*freq = I2S_SAMPLE_FREQUENCY_REG_VAL_96000;
break;
default:
- AUDIO_DEVICE_LOG_ERR("rate: %d is not support.", rate);
+ AUDIO_DRIVER_LOG_ERR("rate: %d is not support.", rate);
return HDF_ERR_NOT_SUPPORT;
}
+ AUDIO_DRIVER_LOG_DEBUG("success.");
+ return HDF_SUCCESS;
+}
+
+int32_t AccessoryDeviceCfgGet(struct AccessoryData *accessoryData,
+ struct AccessoryTransferData *accessoryTransferData)
+{
+ int32_t ret;
+ int32_t index;
+ int32_t audioCfgCtrlCount;
+
+ ret = (accessoryData == NULL || accessoryData->regConfig == NULL || accessoryTransferData == NULL);
+ if (ret) {
+ AUDIO_DRIVER_LOG_ERR("input para is NULL.");
+ return HDF_FAILURE;
+ }
+ g_i2cDevAddr = accessoryTransferData->i2cDevAddr;
+ g_i2cBusNumber = accessoryTransferData->i2cBusNumber;
+ g_audioRegCfgGroupNode = accessoryData->regConfig->audioRegParams;
+ ret = (g_audioRegCfgGroupNode[AUDIO_CTRL_CFG_GROUP] == NULL ||
+ g_audioRegCfgGroupNode[AUDIO_CTRL_CFG_GROUP]->ctrlCfgItem == NULL ||
+ g_audioRegCfgGroupNode[AUDIO_CTRL_PATAM_GROUP] == NULL ||
+ g_audioRegCfgGroupNode[AUDIO_CTRL_PATAM_GROUP]->regCfgItem == NULL);
+ if (ret) {
+ AUDIO_DRIVER_LOG_ERR("parsing params is NULL.");
+ return HDF_FAILURE;
+ }
+ struct AudioControlConfig *ctlcfgItem = g_audioRegCfgGroupNode[AUDIO_CTRL_CFG_GROUP]->ctrlCfgItem;
+ audioCfgCtrlCount = g_audioRegCfgGroupNode[AUDIO_CTRL_CFG_GROUP]->itemNum;
+ g_audioControls = (struct AudioKcontrol *)OsalMemCalloc(audioCfgCtrlCount * sizeof(struct AudioKcontrol));
+ accessoryTransferData->accessoryRegCfgGroupNode = g_audioRegCfgGroupNode;
+ accessoryTransferData->accessoryCfgCtrlCount = audioCfgCtrlCount;
+ accessoryTransferData->accessoryControls = g_audioControls;
+ for (index = 0; index < audioCfgCtrlCount; index++) {
+ g_audioControls[index].iface = ctlcfgItem[index].iface;
+ g_audioControls[index].name = g_audioControlsList[ctlcfgItem[index].arrayIndex];
+ g_audioControls[index].Info = AudioInfoCtrlOps;
+ g_audioControls[index].privateValue =
+ (unsigned long)(uintptr_t)(void*)(&g_audioRegCfgGroupNode[AUDIO_CTRL_PATAM_GROUP]->regCfgItem[index]);
+ g_audioControls[index].Get = AudioAccessoryGetCtrlOps;
+ g_audioControls[index].Set = AudioAccessorySetCtrlOps;
+ }
+ return HDF_SUCCESS;
+}
+
+/*
+ * init control reg to default value
+ */
+int32_t AccessoryDeviceCtrlRegInit(void)
+{
+ int32_t ret, i;
+ // Set codec control register(00h-14h) default value
+ ret = (g_audioRegCfgGroupNode == NULL || g_audioRegCfgGroupNode[AUDIO_INIT_GROUP] == NULL
+ || g_audioRegCfgGroupNode[AUDIO_INIT_GROUP]->addrCfgItem == NULL);
+ if (ret) {
+ AUDIO_DRIVER_LOG_ERR("g_audioRegCfgGroupNode[AUDIO_INIT_GROUP] is NULL.");
+ return HDF_FAILURE;
+ }
+ struct AudioAddrConfig *initCfg = g_audioRegCfgGroupNode[AUDIO_INIT_GROUP]->addrCfgItem;
+ for (i = 0; i < g_audioRegCfgGroupNode[AUDIO_INIT_GROUP]->itemNum; i++) {
+ AUDIO_DRIVER_LOG_DEBUG("i=%d, Addr = [0x%2x]", i, initCfg[i].addr);
+ ret = AccessoryI2cReadWrite(&initCfg[i], 0);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("AccessoryI2cReadWrite(write) err, regAttr.regAddr: 0x%x.\n",
+ initCfg[i].addr);
+ return HDF_FAILURE;
+ }
+ OsalMSleep(COMM_WAIT_TIMES);
+ }
+ AUDIO_DRIVER_LOG_DEBUG("success.");
+ return HDF_SUCCESS;
+}
+
+int32_t AccessoryDeviceRegRead(const struct AccessoryDevice *codec, uint32_t reg, uint32_t *val)
+{
+ int32_t ret;
+ struct AudioAddrConfig regAttr;
+ if (val == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input para is NULL.");
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ (void)codec;
+ regAttr.addr = (uint8_t)reg;
+ regAttr.value = 0;
+ ret = AccessoryI2cReadWrite(®Attr, I2C_FLAG_READ);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("failed.");
+ return HDF_FAILURE;
+ }
+ *val = regAttr.value;
+ AUDIO_DRIVER_LOG_DEBUG("success");
+ return HDF_SUCCESS;
+}
+
+int32_t AccessoryDeviceRegWrite(const struct AccessoryDevice *codec, uint32_t reg, uint32_t value)
+{
+ int32_t ret;
+ struct AudioAddrConfig regAttr;
+ (void)codec;
+ regAttr.addr = (uint8_t)reg;
+ regAttr.value = (uint16_t)value;
+ ret = AccessoryI2cReadWrite(®Attr, 0);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("failed.");
+ return HDF_FAILURE;
+ }
+ AUDIO_DRIVER_LOG_DEBUG("success");
+ return HDF_SUCCESS;
+}
+
+int32_t AccessoryGetConfigInfo(const struct HdfDeviceObject *device, struct AccessoryData *accessoryData)
+{
+ if (device == NULL || accessoryData == NULL) {
+ AUDIO_DRIVER_LOG_ERR("param is null!");
+ return HDF_FAILURE;
+ }
+
+ if (accessoryData->regConfig != NULL) {
+ ADM_LOG_ERR("g_codecData regConfig fail!");
+ return HDF_FAILURE;
+ }
+
+ accessoryData->regConfig = (struct AudioRegCfgData *)OsalMemCalloc(sizeof(*(accessoryData->regConfig)));
+ if (accessoryData->regConfig == NULL) {
+ ADM_LOG_ERR("malloc AudioRegCfgData fail!");
+ return HDF_FAILURE;
+ }
+
+ if (CodecGetRegConfig(device, accessoryData->regConfig) != HDF_SUCCESS) {
+ ADM_LOG_ERR("CodecGetRegConfig fail!");
+ return HDF_FAILURE;
+ }
+
return HDF_SUCCESS;
}
diff --git a/model/audio/common/src/audio_codec_base.c b/model/audio/common/src/audio_codec_base.c
index 6d7d0a46d366e6513635171c35dd88b56748a1e2..ee753581d8c135f6188754a8523407f08b2300fb 100755
--- a/model/audio/common/src/audio_codec_base.c
+++ b/model/audio/common/src/audio_codec_base.c
@@ -7,159 +7,255 @@
*/
#include "audio_codec_base.h"
+#include "audio_driver_log.h"
+#include "audio_parse.h"
+#include "audio_sapm.h"
#define HDF_LOG_TAG audio_codec_base
-int32_t CodecDeviceReadReg(const struct CodecDevice *codec, uint32_t reg, uint32_t *val)
+int32_t CodecGetServiceName(const struct HdfDeviceObject *device, const char **drvCodecName)
{
- unsigned long acodecVir;
- struct VirtualAddress *virtualAdd = NULL;
- AUDIO_DRIVER_LOG_DEBUG("entry");
+ const struct DeviceResourceNode *node = NULL;
+ struct DeviceResourceIface *drsOps = NULL;
+ int32_t ret;
- if ((codec == NULL) || (codec->device == NULL) || (val == NULL)) {
- AUDIO_DRIVER_LOG_ERR("input param codec or codec->device is NULL.");
- return HDF_ERR_INVALID_OBJECT;
+ if (device == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input device para is nullptr.");
+ return HDF_FAILURE;
}
- virtualAdd = (struct VirtualAddress *)((volatile uintptr_t)codec->device->priv);
- if (virtualAdd == NULL) {
- AUDIO_DRIVER_LOG_ERR("virtualAdd is NULL.");
- return HDF_ERR_INVALID_OBJECT;
+
+ node = device->property;
+ if (node == NULL) {
+ AUDIO_DRIVER_LOG_ERR("node instance is nullptr.");
+ return HDF_FAILURE;
+ }
+ drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ if (drsOps == NULL || drsOps->GetString == NULL) {
+ AUDIO_DRIVER_LOG_ERR("from resouce get drsOps fail!");
+ return HDF_FAILURE;
+ }
+
+ ret = drsOps->GetString(node, "serviceName", drvCodecName, 0);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("read codecServiceName fail!");
+ return ret;
}
- acodecVir = virtualAdd->acodecVir;
- *val = OSAL_READL((void *)(acodecVir + reg));
- AUDIO_DRIVER_LOG_DEBUG("success");
return HDF_SUCCESS;
}
-int32_t CodecDeviceWriteReg(const struct CodecDevice *codec, uint32_t reg, uint32_t value)
+int32_t CodecGetDaiName(const struct HdfDeviceObject *device, const char **drvDaiName)
{
- unsigned long acodecVir;
- struct VirtualAddress *virtualAdd = NULL;
- AUDIO_DRIVER_LOG_DEBUG("entry");
+ const struct DeviceResourceNode *node = NULL;
+ struct DeviceResourceIface *drsOps = NULL;
+ int32_t ret;
- if ((codec == NULL) || (codec->device == NULL)) {
- AUDIO_DRIVER_LOG_ERR("param codec or codec->device is NULL.");
- return HDF_ERR_INVALID_OBJECT;
+ if (device == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input para is NULL.");
+ return HDF_FAILURE;
}
- virtualAdd = (struct VirtualAddress *)((volatile uintptr_t)codec->device->priv);
- if (virtualAdd == NULL) {
- AUDIO_DRIVER_LOG_ERR("virtualAdd is NULL.");
- return HDF_ERR_INVALID_OBJECT;
+ node = device->property;
+ if (node == NULL) {
+ AUDIO_DRIVER_LOG_ERR("drs node is NULL.");
+ return HDF_FAILURE;
+ }
+ drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ if (drsOps == NULL || drsOps->GetString == NULL) {
+ AUDIO_DRIVER_LOG_ERR("drs ops failed!");
+ return HDF_FAILURE;
}
- acodecVir = virtualAdd->acodecVir;
- OSAL_WRITEL(value, (void *)(acodecVir + reg));
+ ret = drsOps->GetString(node, "codecDaiName", drvDaiName, 0);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("read codecDaiName fail!");
+ return ret;
+ }
- AUDIO_DRIVER_LOG_DEBUG("success");
return HDF_SUCCESS;
}
-int32_t CodecAiaoDeviceReadReg(const struct CodecDevice *codec, uint32_t reg, uint32_t *val)
+int32_t CodecGetConfigInfo(const struct HdfDeviceObject *device, struct CodecData *codecData)
{
- unsigned long aiaoVir;
- struct VirtualAddress *virtualAdd = NULL;
- AUDIO_DRIVER_LOG_DEBUG("entry");
+ if (device == NULL || codecData == NULL) {
+ AUDIO_DRIVER_LOG_ERR("param is null!");
+ return HDF_FAILURE;
+ }
- if ((codec == NULL) || (codec->device == NULL) || (val == NULL)) {
- AUDIO_DRIVER_LOG_ERR("codec or codec->device is NULL.");
- return HDF_ERR_INVALID_OBJECT;
+ if (codecData->regConfig != NULL) {
+ ADM_LOG_ERR("g_codecData regConfig fail!");
+ return HDF_FAILURE;
}
- virtualAdd = (struct VirtualAddress *)((volatile uintptr_t)codec->device->priv);
- if (virtualAdd == NULL) {
- AUDIO_DRIVER_LOG_ERR("virtualAdd is NULL.");
- return HDF_ERR_INVALID_OBJECT;
+ codecData->regConfig = (struct AudioRegCfgData *)OsalMemCalloc(sizeof(*(codecData->regConfig)));
+ if (codecData->regConfig == NULL) {
+ ADM_LOG_ERR("malloc AudioRegCfgData fail!");
+ return HDF_FAILURE;
}
- aiaoVir = virtualAdd->aiaoVir;
- *val = OSAL_READL((void *)(aiaoVir + reg));
+ if (CodecGetRegConfig(device, codecData->regConfig) != HDF_SUCCESS) {
+ ADM_LOG_ERR("CodecGetRegConfig fail!");
+ return HDF_FAILURE;
+ }
- AUDIO_DRIVER_LOG_DEBUG("success");
return HDF_SUCCESS;
}
-int32_t CodecAiaoDeviceWriteReg(const struct CodecDevice *codec, uint32_t reg, uint32_t value)
+static int32_t SapmCtrlToSapmComp(struct AudioSapmComponent *sapmComponents,
+ const struct AudioSapmCtrlConfig *sapmCompItem, uint16_t index)
{
- unsigned long aiaoVir;
- struct VirtualAddress *virtualAdd = NULL;
- AUDIO_DRIVER_LOG_DEBUG("entry");
-
- if ((codec == NULL) || (codec->device == NULL)) {
- AUDIO_DRIVER_LOG_ERR("codec or codec->device is NULL.");
- return HDF_ERR_INVALID_OBJECT;
- }
- virtualAdd = (struct VirtualAddress *)((volatile uintptr_t)codec->device->priv);
- if (virtualAdd == NULL) {
- AUDIO_DRIVER_LOG_ERR("virtualAdd is NULL.");
- return HDF_ERR_INVALID_OBJECT;
+ if (sapmComponents == NULL || sapmCompItem == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input para is NULL.");
+ return HDF_FAILURE;
}
- aiaoVir = virtualAdd->aiaoVir;
- OSAL_WRITEL(value, (void *)(aiaoVir + reg));
+ sapmComponents[index].componentName =
+ g_audioSapmCompNameList[sapmCompItem[index].compNameIndex];
+ sapmComponents[index].reg = sapmCompItem[index].reg;
+ sapmComponents[index].sapmType = sapmCompItem[index].sapmType;
+ sapmComponents[index].mask = sapmCompItem[index].mask;
+ sapmComponents[index].shift = sapmCompItem[index].shift;
+ sapmComponents[index].invert = sapmCompItem[index].invert;
+ sapmComponents[index].kcontrolsNum = sapmCompItem[index].kcontrolsNum;
- AUDIO_DRIVER_LOG_DEBUG("success");
return HDF_SUCCESS;
}
-int32_t CodecGetServiceName(const struct HdfDeviceObject *device, const char **drvCodecName)
+static int32_t CodecSetSapmConfigInfo(struct CodecData *codeData, struct AudioRegCfgGroupNode **regCfgGroup)
{
- const struct DeviceResourceNode *node = NULL;
- struct DeviceResourceIface *drsOps = NULL;
- int32_t ret;
+ uint16_t index;
- if (device == NULL) {
- AUDIO_DRIVER_LOG_ERR("input device para is nullptr.");
+ if (codeData == NULL || regCfgGroup == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input para is NULL.");
return HDF_FAILURE;
}
- node = device->property;
- if (node == NULL) {
- AUDIO_DRIVER_LOG_ERR("node instance is nullptr.");
+ struct AudioSapmCtrlConfig *sapmCompItem = regCfgGroup[AUDIO_SAPM_COMP_GROUP]->sapmCompItem;
+ struct AudioControlConfig *sapmCtrlItem = regCfgGroup[AUDIO_SAPM_CFG_GROUP]->ctrlCfgItem;
+ struct AudioMixerControl *ctlSapmRegCfgItem = regCfgGroup[AUDIO_CTRL_SAPM_PATAM_GROUP]->regCfgItem;
+
+ if (sapmCompItem == NULL || sapmCtrlItem == NULL || ctlSapmRegCfgItem == NULL) {
+ AUDIO_DRIVER_LOG_ERR("sapmCompItem, sapmCtrlItem, ctlSapmRegCfgItem is NULL.");
return HDF_FAILURE;
}
- drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
- if (drsOps == NULL || drsOps->GetString == NULL) {
- AUDIO_DRIVER_LOG_ERR("from resouce get drsOps fail!");
+
+ struct AudioKcontrol *audioSapmControls = (struct AudioKcontrol *)OsalMemCalloc(
+ regCfgGroup[AUDIO_SAPM_CFG_GROUP]->itemNum * sizeof(struct AudioKcontrol));
+ if (audioSapmControls == NULL) {
+ AUDIO_DRIVER_LOG_ERR("OsalMemCalloc failed.");
return HDF_FAILURE;
}
+ for (index = 0; index < regCfgGroup[AUDIO_SAPM_CFG_GROUP]->itemNum; index++) {
+ audioSapmControls[index].iface = sapmCtrlItem[index].iface;
+ audioSapmControls[index].name = g_audioSapmCfgNameList[sapmCtrlItem[index].arrayIndex];
+ audioSapmControls[index].privateValue = (unsigned long)(uintptr_t)(void*)(&ctlSapmRegCfgItem[index]);
+ audioSapmControls[index].Info = AudioInfoCtrlOps;
+ audioSapmControls[index].Get = AudioCodecSapmGetCtrlOps;
+ audioSapmControls[index].Set = AudioCodecSapmSetCtrlOps;
+ }
- ret = drsOps->GetString(node, "serviceName", drvCodecName, 0);
- if (ret != HDF_SUCCESS) {
- AUDIO_DRIVER_LOG_ERR("read codecServiceName fail!");
- return ret;
+ codeData->numSapmComponent = regCfgGroup[AUDIO_SAPM_COMP_GROUP]->itemNum;
+ codeData->sapmComponents = (struct AudioSapmComponent *)
+ OsalMemCalloc(codeData->numSapmComponent * sizeof(struct AudioSapmComponent));
+ if (codeData->sapmComponents == NULL) {
+ OsalMemFree(audioSapmControls);
+ AUDIO_DRIVER_LOG_ERR("OsalMemCalloc failed.");
+ return HDF_FAILURE;
+ }
+
+ for (index = 0; index < codeData->numSapmComponent; index++) {
+ if (SapmCtrlToSapmComp(codeData->sapmComponents, sapmCompItem, index)) {
+ OsalMemFree(audioSapmControls);
+ return HDF_FAILURE;
+ }
+
+ if (sapmCompItem[index].kcontrolsNum) {
+ codeData->sapmComponents[index].kcontrolNews =
+ &audioSapmControls[sapmCompItem[index].kcontrolNews - 1];
+ }
}
return HDF_SUCCESS;
}
-int32_t CodecGetDaiName(const struct HdfDeviceObject *device, const char **drvDaiName)
+int32_t CodecSetConfigInfo(struct CodecData *codeData, struct DaiData *daiData)
{
- const struct DeviceResourceNode *node = NULL;
- struct DeviceResourceIface *drsOps = NULL;
- int32_t ret;
+ uint16_t index;
- if (device == NULL) {
+ if (codeData == NULL || daiData == NULL || codeData->regConfig == NULL) {
AUDIO_DRIVER_LOG_ERR("input para is NULL.");
return HDF_FAILURE;
}
- node = device->property;
- if (node == NULL) {
- AUDIO_DRIVER_LOG_ERR("drs node is NULL.");
+ struct AudioIdInfo *audioIdInfo = &(codeData->regConfig->audioIdInfo);
+ struct AudioRegCfgGroupNode **regCfgGroup = codeData->regConfig->audioRegParams;
+ daiData->regCfgGroup = regCfgGroup;
+ codeData->regCfgGroup = regCfgGroup;
+ if (audioIdInfo == NULL || regCfgGroup == NULL) {
+ AUDIO_DRIVER_LOG_ERR("audioIdInfo or regCfgGroup is NULL.");
return HDF_FAILURE;
}
- drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
- if (drsOps == NULL || drsOps->GetString == NULL) {
- AUDIO_DRIVER_LOG_ERR("drs ops failed!");
+
+ struct AudioControlConfig *compItem = regCfgGroup[AUDIO_CTRL_CFG_GROUP]->ctrlCfgItem;
+ struct AudioMixerControl *ctlRegCfgItem = regCfgGroup[AUDIO_CTRL_PATAM_GROUP]->regCfgItem;
+ if (compItem == NULL || ctlRegCfgItem == NULL) {
+ AUDIO_DRIVER_LOG_ERR("compItem or ctlRegCfgItem is NULL.");
return HDF_FAILURE;
}
- ret = drsOps->GetString(node, "codecDaiName", drvDaiName, 0);
- if (ret != HDF_SUCCESS) {
- AUDIO_DRIVER_LOG_ERR("read codecDaiName fail!");
- return ret;
+ codeData->numControls = regCfgGroup[AUDIO_CTRL_CFG_GROUP]->itemNum;
+ codeData->controls =
+ (struct AudioKcontrol *)OsalMemCalloc(codeData->numControls * sizeof(struct AudioKcontrol));
+ if (codeData->controls == NULL) {
+ AUDIO_DRIVER_LOG_ERR("OsalMemCalloc failed.");
+ return HDF_FAILURE;
+ }
+
+ for (index = 0; index < codeData->numControls; index++) {
+ codeData->controls[index].iface = compItem[index].iface;
+ codeData->controls[index].name = g_audioControlsList[compItem[index].arrayIndex];
+ codeData->controls[index].Info = AudioInfoCtrlOps;
+ codeData->controls[index].privateValue = (unsigned long)(uintptr_t)(void*)(&ctlRegCfgItem[index]);
+ if (compItem[index].enable) {
+ codeData->controls[index].Get = AudioCodecGetCtrlOps;
+ codeData->controls[index].Set = AudioCodecSetCtrlOps;
+ }
+ }
+
+ codeData->virtualAddress = (uintptr_t)OsalIoRemap(audioIdInfo->chipIdRegister, audioIdInfo->chipIdSize);
+
+ if (CodecSetSapmConfigInfo(codeData, regCfgGroup) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+int32_t CodecSetCtlFunc(struct CodecData *codeData, const void *aiaoGetCtrl, const void *aiaoSetCtrl)
+{
+ uint32_t index;
+ if (codeData == NULL || codeData->regConfig == NULL ||
+ aiaoGetCtrl == NULL || aiaoSetCtrl == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input para is NULL.");
+ return HDF_FAILURE;
+ }
+ struct AudioRegCfgGroupNode **regCfgGroup = codeData->regConfig->audioRegParams;
+ if (regCfgGroup == NULL || regCfgGroup[AUDIO_CTRL_CFG_GROUP] == NULL) {
+ AUDIO_DRIVER_LOG_ERR("regCfgGroup or regCfgGroup[AUDIO_CTRL_CFG_GROUP] is NULL.");
+ return HDF_FAILURE;
+ }
+
+ struct AudioControlConfig *compItem = regCfgGroup[AUDIO_CTRL_CFG_GROUP]->ctrlCfgItem;
+ if (compItem == NULL) {
+ AUDIO_DRIVER_LOG_ERR("compItem is NULL.");
+ return HDF_FAILURE;
+ }
+
+ for (index = 0; index < codeData->numControls; index++) {
+ if (!compItem[index].enable) {
+ codeData->controls[index].Get = aiaoGetCtrl;
+ codeData->controls[index].Set = aiaoSetCtrl;
+ }
}
return HDF_SUCCESS;
diff --git a/model/audio/common/src/audio_dai_base.c b/model/audio/common/src/audio_dai_base.c
new file mode 100644
index 0000000000000000000000000000000000000000..0b9822acd0280bc392dd61e7fdf3c08388f73409
--- /dev/null
+++ b/model/audio/common/src/audio_dai_base.c
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 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 "audio_core.h"
+#include "audio_driver_log.h"
+
+struct DaiData *DaiDataFromCard(const struct AudioCard *card)
+{
+ if (card == NULL || card->rtd == NULL || card->rtd->cpuDai == NULL) {
+ AUDIO_DRIVER_LOG_ERR("param is null.");
+ return NULL;
+ }
+ return card->rtd->cpuDai->devData;
+}
+
+
+int32_t DaiGetConfigInfo(const struct HdfDeviceObject *device, struct DaiData *data)
+{
+ if (device == NULL || data == NULL) {
+ AUDIO_DRIVER_LOG_ERR("param is null!");
+ return HDF_FAILURE;
+ }
+
+ if (data->regConfig != NULL) {
+ ADM_LOG_ERR("g_codecData regConfig fail!");
+ return HDF_FAILURE;
+ }
+
+ data->regConfig = (struct AudioRegCfgData *)OsalMemCalloc(sizeof(*(data->regConfig)));
+ if (data->regConfig == NULL) {
+ ADM_LOG_ERR("malloc AudioRegCfgData fail!");
+ return HDF_FAILURE;
+ }
+
+ if (CodecGetRegConfig(device, data->regConfig) != HDF_SUCCESS) {
+ ADM_LOG_ERR("dai GetRegConfig fail!");
+ OsalMemFree(data->regConfig);
+ data->regConfig = NULL;
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+int32_t DaiCheckSampleRate(unsigned int sampleRates)
+{
+ bool check = (sampleRates == AUDIO_SAMPLE_RATE_8000 || sampleRates == AUDIO_SAMPLE_RATE_12000 ||
+ sampleRates == AUDIO_SAMPLE_RATE_11025 || sampleRates == AUDIO_SAMPLE_RATE_16000 ||
+ sampleRates == AUDIO_SAMPLE_RATE_22050 || sampleRates == AUDIO_SAMPLE_RATE_24000 ||
+ sampleRates == AUDIO_SAMPLE_RATE_32000 || sampleRates == AUDIO_SAMPLE_RATE_44100 ||
+ sampleRates == AUDIO_SAMPLE_RATE_48000 || sampleRates == AUDIO_SAMPLE_RATE_64000 ||
+ sampleRates == AUDIO_SAMPLE_RATE_96000);
+ if (check) {
+ return HDF_SUCCESS;
+ } else {
+ AUDIO_DRIVER_LOG_ERR("FramatToSampleRate fail: Invalid sampling rate: %d.", sampleRates);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+}
+
+int32_t DaiSetConfigInfo(struct DaiData *data)
+{
+ uint16_t index;
+ struct AudioRegCfgGroupNode **regCfgGroup = NULL;
+ struct AudioMixerControl *patRegCfgItemTmp = NULL;
+ struct AudioControlConfig *item = NULL;
+
+ if (data == NULL || data->regConfig == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input para is NULL.");
+ return HDF_FAILURE;
+ }
+
+ regCfgGroup = data->regConfig->audioRegParams;
+ if (regCfgGroup == NULL) {
+ AUDIO_DRIVER_LOG_DEBUG("regCfgGroup is null.");
+ return HDF_SUCCESS;
+ }
+
+ patRegCfgItemTmp = regCfgGroup[AUDIO_CTRL_PATAM_GROUP]->regCfgItem;
+ item = regCfgGroup[AUDIO_CTRL_CFG_GROUP]->ctrlCfgItem;
+
+ if (patRegCfgItemTmp == NULL || item == NULL) {
+ AUDIO_DRIVER_LOG_ERR("patRegCfgItemTmp or item is NULL.");
+ return HDF_FAILURE;
+ }
+
+ data->numControls = regCfgGroup[AUDIO_CTRL_CFG_GROUP]->itemNum;
+ data->controls = (struct AudioKcontrol *)OsalMemCalloc(data->numControls * sizeof(struct AudioKcontrol));
+ if (data->controls == NULL) {
+ AUDIO_DRIVER_LOG_ERR("OsalMemCalloc failed.");
+ return HDF_FAILURE;
+ }
+
+ for (index = 0; index < data->numControls; index++) {
+ data->controls[index].iface = item[index].iface;
+ if (item[index].arrayIndex >= AUDIO_CTRL_LIST_MAX) {
+ AUDIO_DRIVER_LOG_ERR("Array super index.");
+ return HDF_FAILURE;
+ }
+ data->controls[index].name = g_audioControlsList[item[index].arrayIndex];
+ data->controls[index].Info = AudioInfoCtrlOps;
+ data->controls[index].privateValue = (unsigned long)(uintptr_t)(void*)(&patRegCfgItemTmp[index]);
+ data->controls[index].Get = AudioCpuDaiGetCtrlOps;
+ data->controls[index].Set = AudioCpuDaiSetCtrlOps;
+ }
+
+ return HDF_SUCCESS;
+}
+
diff --git a/model/audio/common/src/audio_dma_base.c b/model/audio/common/src/audio_dma_base.c
new file mode 100644
index 0000000000000000000000000000000000000000..214edc6849972fce33b6fecd9443ac1361183d71
--- /dev/null
+++ b/model/audio/common/src/audio_dma_base.c
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 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 "audio_platform_if.h"
+
+int32_t AudioDmaBufAlloc(struct PlatformData *data, enum AudioStreamType streamType)
+{
+ if (data != NULL && data->ops != NULL && data->ops->DmaBufAlloc != NULL) {
+ return data->ops->DmaBufAlloc(data, streamType);
+ }
+ return HDF_FAILURE;
+}
+
+int32_t AudioDmaBufFree(struct PlatformData *data, enum AudioStreamType streamType)
+{
+ if (data != NULL && data->ops != NULL && data->ops->DmaBufFree != NULL) {
+ return data->ops->DmaBufFree(data, streamType);
+ }
+ return HDF_FAILURE;
+}
+
+int32_t AudioDmaRequestChannel(struct PlatformData *data)
+{
+ if (data != NULL && data->ops != NULL && data->ops->DmaConfigChannel != NULL) {
+ return data->ops->DmaRequestChannel(data);
+ }
+ return HDF_FAILURE;
+}
+
+int32_t AudioDmaConfigChannel(struct PlatformData *data)
+{
+ if (data != NULL && data->ops != NULL && data->ops->DmaConfigChannel != NULL) {
+ return data->ops->DmaConfigChannel(data);
+ }
+ return HDF_FAILURE;
+}
+
+int32_t AudioDmaPrep(struct PlatformData *data)
+{
+ if (data != NULL && data->ops != NULL && data->ops->DmaPrep != NULL) {
+ return data->ops->DmaPrep(data);
+ }
+ return HDF_FAILURE;
+}
+
+int32_t AudioDmaSubmit(struct PlatformData *data)
+{
+ if (data != NULL && data->ops != NULL && data->ops->DmaSubmit != NULL) {
+ return data->ops->DmaSubmit(data);
+ }
+ return HDF_FAILURE;
+}
+
+int32_t AudioDmaPending(struct PlatformData *data)
+{
+ if (data != NULL && data->ops != NULL && data->ops->DmaPending != NULL) {
+ return data->ops->DmaPending(data);
+ }
+ return HDF_FAILURE;
+}
+
+int32_t AudioDmaPause(struct PlatformData *data)
+{
+ if (data != NULL && data->ops != NULL && data->ops->DmaPause != NULL) {
+ return data->ops->DmaPause(data);
+ }
+ return HDF_FAILURE;
+}
+
+int32_t AudioDmaResume(struct PlatformData *data)
+{
+ if (data != NULL && data->ops != NULL && data->ops->DmaResume != NULL) {
+ return data->ops->DmaResume(data);
+ }
+ return HDF_FAILURE;
+}
+
+int32_t AudioDmaPointer(struct PlatformData *data, uint32_t *pointer)
+{
+ if (data != NULL && data->ops != NULL && data->ops->DmaPointer != NULL) {
+ return data->ops->DmaPointer(data, pointer);
+ }
+ return HDF_FAILURE;
+}
diff --git a/model/audio/common/src/audio_dsp_base.c b/model/audio/common/src/audio_dsp_base.c
old mode 100755
new mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..3fb0c38cad9fd1fd72cb5e852c3f1e0e71ed39f3
--- a/model/audio/common/src/audio_dsp_base.c
+++ b/model/audio/common/src/audio_dsp_base.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 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 "audio_dsp_base.h"
+#include "audio_driver_log.h"
+
+#define HDF_LOG_TAG audio_dsp_base
+
+int32_t DspGetServiceName(const struct HdfDeviceObject *device, const char **drvDspName)
+{
+ const struct DeviceResourceNode *node = NULL;
+ struct DeviceResourceIface *drsOps = NULL;
+ int32_t ret;
+
+ if (device == NULL || drvDspName == NULL) {
+ AUDIO_DRIVER_LOG_ERR("device is NULL.");
+ return HDF_FAILURE;
+ }
+
+ node = device->property;
+ if (node == NULL) {
+ AUDIO_DRIVER_LOG_ERR("deivce property is NULL.");
+ return HDF_FAILURE;
+ }
+ drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ if (drsOps == NULL || drsOps->GetString == NULL) {
+ AUDIO_DRIVER_LOG_ERR("from resource get drsops failed!");
+ return HDF_FAILURE;
+ }
+
+ ret = drsOps->GetString(node, "serviceName", drvDspName, 0);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("read DspServiceName fail!");
+ return ret;
+ }
+
+ return HDF_SUCCESS;
+}
+
+int32_t DspGetDaiName(const struct HdfDeviceObject *device, const char **drvDaiName)
+{
+ const struct DeviceResourceNode *node = NULL;
+ struct DeviceResourceIface *drsOps = NULL;
+ int32_t ret;
+
+ if (device == NULL || drvDaiName == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input para is null pointer.");
+ return HDF_FAILURE;
+ }
+
+ node = device->property;
+ if (node == NULL) {
+ AUDIO_DRIVER_LOG_ERR("drs node is null pointer.");
+ return HDF_FAILURE;
+ }
+ drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ if (drsOps == NULL || drsOps->GetString == NULL) {
+ AUDIO_DRIVER_LOG_ERR("drs ops fail!");
+ return HDF_FAILURE;
+ }
+
+ ret = drsOps->GetString(node, "dspDaiName", drvDaiName, 0);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("read dspDaiName fail!");
+ return ret;
+ }
+
+ return HDF_SUCCESS;
+}
diff --git a/model/audio/common/src/audio_platform_base.c b/model/audio/common/src/audio_platform_base.c
index 29337f0e476b210301bf8493045be98d9c01256b..f64fe04557c9ecf40c661f6869ab16facf7a2acf 100755
--- a/model/audio/common/src/audio_platform_base.c
+++ b/model/audio/common/src/audio_platform_base.c
@@ -7,11 +7,33 @@
*/
#include "audio_platform_base.h"
-#include "audio_core.h"
+#include "audio_driver_log.h"
+#include "audio_dma_base.h"
+#include "audio_sapm.h"
+#include "audio_stream_dispatch.h"
+#include "osal_time.h"
+#include "osal_uaccess.h"
#define HDF_LOG_TAG audio_platform_base
+const int MAX_PERIOD_SIZE = 1024 * 16;
+const int MAX_PERIOD_COUNT = 32;
+const int MIN_PERIOD_COUNT = 4;
+const int RENDER_TRAF_BUF_SIZE = 1024;
+const int MIN_BUFF_SIZE = 16 * 1024;
+const int TIME_OUT_CONST = 50;
+const int SLEEP_TIME = 5;
-struct PlatformData *PlatformDataFromDevice(const struct AudioCard *card)
+unsigned int SysReadl(unsigned long addr)
+{
+ return *(volatile unsigned int *)(uintptr_t)(addr);
+}
+
+void SysWritel(unsigned long addr, unsigned int value)
+{
+ *(volatile unsigned int *)(uintptr_t)(addr) = value;
+}
+
+struct PlatformData *PlatformDataFromCard(const struct AudioCard *card)
{
if (card == NULL || card->rtd == NULL || card->rtd->platform == NULL) {
AUDIO_DRIVER_LOG_ERR("param is null.");
@@ -20,55 +42,1105 @@ struct PlatformData *PlatformDataFromDevice(const struct AudioCard *card)
return card->rtd->platform->devData;
}
-int32_t PlatformCreatePlatformHost(const struct AudioCard *card, struct PlatformHost **platformHost)
+uint32_t AudioBytesToFrames(uint32_t frameBits, uint32_t size)
+{
+ if (size == 0) {
+ AUDIO_DRIVER_LOG_ERR("size is null.");
+ return 0;
+ } else {
+ return (frameBits / size);
+ }
+}
+
+
+int32_t AudioDataBigEndianChange(char *srcData, uint32_t audioLen, enum DataBitWidth bitWidth)
+{
+ if (srcData == NULL) {
+ AUDIO_DRIVER_LOG_ERR("srcData is NULL.");
+ return HDF_FAILURE;
+ }
+ uint64_t i;
+ uint16_t framesize;
+ char *changeData = srcData;
+ uint32_t *pData = (uint32_t *)changeData;
+
+ switch (bitWidth) {
+ case DATA_BIT_WIDTH8:
+ return HDF_SUCCESS;
+ case DATA_BIT_WIDTH24:
+ framesize = 3; /* 3 byte , convert step is 3 byte */
+ for (i = 0; i < audioLen; i += framesize) {
+ // swap the first and the third byte, second and fourth unchanged
+ *pData = ((((*pData) >> 0x10) & 0x000000FF) |
+ ((*pData) & 0xFF00FF00) |
+ (((*pData) << 0x10) & 0x00FF0000));
+ changeData += framesize;
+ pData = (uint32_t *)changeData;
+ }
+ break;
+ case DATA_BIT_WIDTH16:
+ default:
+ framesize = 4; /* 2 byte, convert step is 4 byte */
+ for (i = 0; i < audioLen; i += framesize) {
+ // swap the first and second byte, swap the third and fourth byte
+ *pData = ((((*pData) << 0x08) & 0xFF00FF00) |
+ (((*pData) >> 0x08) & 0x00FF00FF));
+ pData++;
+ }
+ break;
+ }
+ return HDF_SUCCESS;
+}
+
+int32_t AudioFramatToBitWidth(enum AudioFormat format, unsigned int *bitWidth)
+{
+ if (bitWidth == NULL) {
+ AUDIO_DRIVER_LOG_ERR("bitWidth is null.");
+ return HDF_FAILURE;
+ }
+ switch (format) {
+ case AUDIO_FORMAT_PCM_16_BIT:
+ *bitWidth = DATA_BIT_WIDTH16;
+ break;
+
+ case AUDIO_FORMAT_PCM_24_BIT:
+ *bitWidth = DATA_BIT_WIDTH24;
+ break;
+
+ default:
+ AUDIO_DRIVER_LOG_ERR("format: %d is not define.", format);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+int32_t AudioSetPcmInfo(struct PlatformData *platformData, const struct AudioPcmHwParams *param)
+{
+ if (platformData == NULL || param == NULL) {
+ AUDIO_DRIVER_LOG_ERR("platform is NULL.");
+ return HDF_FAILURE;
+ }
+ platformData->pcmInfo.rate = param->rate;
+ platformData->pcmInfo.frameSize = param->channels * platformData->pcmInfo.bitWidth / BITSTOBYTE;
+ platformData->pcmInfo.channels = param->channels;
+
+ platformData->renderBufInfo.chnId = 0;
+ platformData->captureBufInfo.chnId = 0;
+
+ platformData->pcmInfo.isBigEndian = param->isBigEndian;
+ platformData->pcmInfo.isSignedData = param->isSignedData;
+
+ platformData->pcmInfo.startThreshold = param->startThreshold;
+ platformData->pcmInfo.stopThreshold = param->stopThreshold;
+ platformData->pcmInfo.silenceThreshold = param->silenceThreshold;
+
+ platformData->pcmInfo.interleaved = 1;
+ platformData->pcmInfo.channels = param->channels;
+ platformData->pcmInfo.streamType = param->streamType;
+
+ return HDF_SUCCESS;
+}
+
+int32_t AudioSetRenderBufInfo(struct PlatformData *data, const struct AudioPcmHwParams *param)
{
- if (platformHost == NULL) {
- AUDIO_DRIVER_LOG_ERR("input param platformHost is invalid.");
+ uint32_t size;
+
+ if (data == NULL || param == NULL) {
+ AUDIO_DRIVER_LOG_ERR("platform is NULL.");
+ return HDF_FAILURE;
+ }
+ data->renderBufInfo.period = param->period;
+ if (param->periodSize < MIN_PERIOD_SIZE || param->periodSize > MAX_PERIOD_SIZE) {
+ AUDIO_DRIVER_LOG_ERR("periodSize is invalid.");
+ return HDF_FAILURE;
+ }
+ data->renderBufInfo.periodSize = param->periodSize;
+ if (param->periodCount < MIN_PERIOD_COUNT || param->periodCount > MAX_PERIOD_COUNT) {
+ AUDIO_DRIVER_LOG_ERR("periodCount is invalid.");
+ return HDF_FAILURE;
+ }
+ data->renderBufInfo.periodCount = param->periodCount;
+
+ data->renderBufInfo.trafBufSize = RENDER_TRAF_BUF_SIZE;
+
+ size = data->renderBufInfo.periodCount * data->renderBufInfo.periodSize;
+ if (size < MIN_BUFF_SIZE || size > MAX_BUFF_SIZE) {
+ AUDIO_DRIVER_LOG_ERR("buffSize is invalid.");
+ return HDF_FAILURE;
+ }
+
+ data->renderBufInfo.cirBufSize = size;
+ return HDF_SUCCESS;
+}
+
+int32_t AudioSetCaptureBufInfo(struct PlatformData *data, const struct AudioPcmHwParams *param)
+{
+ if (data == NULL || param == NULL) {
+ AUDIO_DRIVER_LOG_ERR("platform is NULL.");
+ return HDF_FAILURE;
+ }
+
+ data->captureBufInfo.period = param->period;
+ if (param->periodSize < MIN_PERIOD_SIZE || param->periodSize > MAX_PERIOD_SIZE) {
+ AUDIO_DRIVER_LOG_ERR("periodSize is invalid %d.", param->periodSize);
+ return HDF_FAILURE;
+ }
+ data->captureBufInfo.periodSize = param->periodSize;
+ if (param->periodCount < MIN_PERIOD_COUNT || param->periodCount > MAX_PERIOD_COUNT) {
+ AUDIO_DRIVER_LOG_ERR("periodCount is invalid %d.", param->periodCount);
+ return HDF_FAILURE;
+ }
+ data->captureBufInfo.periodCount = param->periodCount;
+
+ if (param->silenceThreshold < MIN_PERIOD_SIZE || param->silenceThreshold > MAX_PERIOD_SIZE) {
+ AUDIO_DRIVER_LOG_ERR("silenceThreshold is invalid %d.", param->silenceThreshold);
+ return HDF_FAILURE;
+ }
+ data->captureBufInfo.trafBufSize = param->silenceThreshold;
+ data->captureBufInfo.cirBufSize = param->periodSize * param->periodCount;
+ if (data->captureBufInfo.cirBufSize > data->captureBufInfo.cirBufMax) {
+ AUDIO_DRIVER_LOG_ERR("cirBufSize is invalid %d.", data->captureBufInfo.cirBufSize);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+int32_t AudioWriteProcBigEndian(const struct PlatformData *data, struct AudioTxData *txData)
+{
+ uint32_t buffSize;
+
+ if (data == NULL || txData == NULL || txData->buf == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input param is null.");
+ return HDF_FAILURE;
+ }
+
+ buffSize = (uint32_t)txData->frames * data->pcmInfo.frameSize;
+ if (data->pcmInfo.isBigEndian) {
+ if (AudioDataBigEndianChange(txData->buf, buffSize, data->pcmInfo.bitWidth) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("AudioDataBigEndianChange: failed.");
+ return HDF_FAILURE;
+ }
+ }
+ return HDF_SUCCESS;
+}
+
+static enum CriBuffStatus AudioDmaBuffStatus(const struct AudioCard *card)
+{
+ uint32_t dataAvailable;
+ uint32_t residual;
+ uint32_t pointer = 0;
+ uint32_t wptr;
+ uint32_t rptr;
+
+ struct PlatformData *data = PlatformDataFromCard(card);
+ if (data == NULL || data->ops == NULL) {
+ AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed.");
+ return HDF_FAILURE;
+ }
+
+ if (AudioPcmPointer(card, &pointer) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("get Pointer failed.");
+ return ENUM_CIR_BUFF_FULL;
+ }
+
+ if (data->pcmInfo.streamType == AUDIO_RENDER_STREAM) {
+ data->renderBufInfo.pointer = pointer;
+ rptr = data->renderBufInfo.pointer * data->pcmInfo.frameSize;
+ dataAvailable = (data->renderBufInfo.wbufOffSet - rptr) % data->renderBufInfo.cirBufSize;
+ residual = data->renderBufInfo.cirBufSize - dataAvailable;
+ if ((residual > data->renderBufInfo.trafBufSize)) {
+ return ENUM_CIR_BUFF_NORMAL;
+ }
+ return ENUM_CIR_BUFF_FULL;
+ } else if (data->pcmInfo.streamType == AUDIO_CAPTURE_STREAM) {
+ rptr = data->captureBufInfo.rptrOffSet;
+ wptr = pointer * data->pcmInfo.frameSize;
+ data->captureBufInfo.pointer = pointer;
+
+ if (wptr >= rptr) {
+ // [S ... R ... W ... E]
+ dataAvailable = wptr - rptr;
+ if (dataAvailable < data->captureBufInfo.trafBufSize) {
+ AUDIO_DRIVER_LOG_DEBUG("empty rptr: %d wptr: %d trafBufSize: %d ", rptr,
+ wptr, data->captureBufInfo.trafBufSize);
+ return ENUM_CIR_BUFF_EMPTY;
+ }
+ }
+ AUDIO_DRIVER_LOG_DEBUG("rptr: %d wptr: %d trafBufSize: %d ", rptr, wptr, data->captureBufInfo.trafBufSize);
+ return ENUM_CIR_BUFF_NORMAL;
+ } else {
+ AUDIO_DRIVER_LOG_ERR("streamType is invalead.");
+ return ENUM_CIR_BUFF_FULL;
+ }
+}
+
+int32_t AudioPcmWrite(const struct AudioCard *card, struct AudioTxData *txData)
+{
+ struct PlatformData *data = NULL;
+ enum CriBuffStatus status;
+ uint32_t wPtr;
+ int ret;
+
+ if (card == NULL || txData == NULL || txData->buf == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input param is null.");
+ return HDF_FAILURE;
+ }
+
+ data = PlatformDataFromCard(card);
+ if (data == NULL) {
+ AUDIO_DRIVER_LOG_ERR("from PlatformDataFromCard get platformData is NULL.");
+ return HDF_FAILURE;
+ }
+
+ // 1. Computed buffer size
+ data->renderBufInfo.trafBufSize = txData->frames * data->pcmInfo.frameSize;
+
+ // 2. Big Small Exchange
+ if (data->pcmInfo.isBigEndian) {
+ if (AudioDataBigEndianChange(txData->buf, data->renderBufInfo.trafBufSize,
+ data->pcmInfo.bitWidth) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("AudioDataBigEndianChange: failed.");
+ return HDF_FAILURE;
+ }
+ }
+ // 3. Buffer state checking
+ status = AudioDmaBuffStatus(card);
+ if (status != ENUM_CIR_BUFF_NORMAL) {
+ txData->status = ENUM_CIR_BUFF_FULL;
+ return HDF_SUCCESS;
+ }
+
+ // 4. write buffer
+ if (data->renderBufInfo.trafBufSize > data->renderBufInfo.cirBufSize) {
+ AUDIO_DRIVER_LOG_ERR("transferFrameSize is tool big.");
+ return HDF_FAILURE;
+ }
+ wPtr = data->renderBufInfo.wbufOffSet % data->renderBufInfo.cirBufSize;
+
+ if (data->renderBufInfo.virtAddr == NULL) {
+ AUDIO_DRIVER_LOG_ERR("render buffer is null.");
+ return HDF_FAILURE;
+ }
+ ret = memcpy_s((char *)(data->renderBufInfo.virtAddr) + wPtr,
+ data->renderBufInfo.trafBufSize, txData->buf, data->renderBufInfo.trafBufSize);
+ if (ret != 0) {
+ AUDIO_DRIVER_LOG_ERR("memcpy_s failed.");
+ return HDF_FAILURE;
+ }
+ txData->status = ENUM_CIR_BUFF_NORMAL;
+ data->renderBufInfo.wptrOffSet = wPtr + data->renderBufInfo.trafBufSize;
+ data->renderBufInfo.wbufOffSet += data->renderBufInfo.trafBufSize;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t PcmReadData(struct PlatformData *data, struct AudioRxData *rxData)
+{
+ uint32_t wptr;
+ uint32_t rptr;
+ uint32_t validDataSize;
+
+ if (data == NULL || rxData == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input param is null.");
+ return HDF_FAILURE;
+ }
+
+ rxData->buf = (char *)(data->captureBufInfo.virtAddr) + data->captureBufInfo.rptrOffSet;
+ wptr = data->captureBufInfo.pointer * data->pcmInfo.frameSize;
+ rptr = data->captureBufInfo.rptrOffSet;
+ data->captureBufInfo.curTrafSize = data->captureBufInfo.trafBufSize;
+ if (rptr > wptr) {
+ validDataSize = data->captureBufInfo.cirBufSize - rptr;
+ if (validDataSize < data->captureBufInfo.trafBufSize) {
+ data->captureBufInfo.curTrafSize = validDataSize;
+ }
+ }
+
+ // 3. Big Small Exchange
+ if (!data->pcmInfo.isBigEndian) {
+ if (rxData->buf == NULL || AudioDataBigEndianChange(rxData->buf,
+ data->captureBufInfo.curTrafSize, data->pcmInfo.bitWidth) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("AudioDataBigEndianChange: failed.");
+ return HDF_FAILURE;
+ }
+ }
+
+ rxData->frames = data->captureBufInfo.curTrafSize / data->pcmInfo.frameSize;
+ rxData->bufSize = data->captureBufInfo.curTrafSize;
+ rxData->status = ENUM_CIR_BUFF_NORMAL;
+
+ return HDF_SUCCESS;
+}
+
+int32_t AudioPcmRead(const struct AudioCard *card, struct AudioRxData *rxData)
+{
+ struct PlatformData *data = NULL;
+ enum CriBuffStatus status;
+
+ if (card == NULL || rxData == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input param is null.");
+ return HDF_FAILURE;
+ }
+
+ data = PlatformDataFromCard(card);
+ if (data == NULL) {
+ AUDIO_DRIVER_LOG_ERR("from PlatformDataFromCard get platformData is NULL.");
+ return HDF_FAILURE;
+ }
+ if (data->captureBufInfo.virtAddr == NULL) {
+ AUDIO_DRIVER_LOG_ERR("capture buffer is null.");
+ return HDF_FAILURE;
+ }
+
+ // 1. Buffer state checking
+ status = AudioDmaBuffStatus(card);
+ if (status != ENUM_CIR_BUFF_NORMAL) {
+ rxData->status = ENUM_CIR_BUFF_EMPTY;
+ rxData->buf = (char *)(data->captureBufInfo.virtAddr) + data->captureBufInfo.rptrOffSet;
+ rxData->frames = 0;
+ rxData->bufSize = 0;
+ AUDIO_DRIVER_LOG_DEBUG("buff is empty.");
+ return HDF_SUCCESS;
+ }
+
+ // 2. read buffer
+ if (PcmReadData(data, rxData) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("Pcm Read Data fail.");
+ return HDF_FAILURE;
+ }
+
+ // 4. update rptr
+ data->captureBufInfo.rptrOffSet += data->captureBufInfo.curTrafSize;
+ if (data->captureBufInfo.rptrOffSet >= data->captureBufInfo.cirBufSize) {
+ data->captureBufInfo.rptrOffSet = 0;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t MmapWriteData(struct PlatformData *data, char *tmpBuf)
+{
+ uint32_t wPtr;
+ int ret;
+
+ if (data->renderBufInfo.trafBufSize > data->renderBufInfo.cirBufSize) {
+ AUDIO_DRIVER_LOG_ERR("transferFrameSize is tool big.");
+ return HDF_FAILURE;
+ }
+
+ wPtr = data->renderBufInfo.wbufOffSet % data->renderBufInfo.cirBufSize;
+ ret = CopyFromUser(tmpBuf, (char *)data->mmapData.memoryAddress + data->mmapData.offset,
+ data->renderBufInfo.trafBufSize);
+ if (ret != EOK) {
+ AUDIO_DRIVER_LOG_ERR("CopyFromUser failed.");
+ return HDF_FAILURE;
+ }
+
+ ret = memcpy_s((char *)(data->renderBufInfo.virtAddr) + wPtr, data->renderBufInfo.trafBufSize,
+ tmpBuf, data->renderBufInfo.trafBufSize);
+ if (ret != 0) {
+ AUDIO_DRIVER_LOG_ERR("memcpy_s failed.");
+ return HDF_FAILURE;
+ }
+
+ data->renderBufInfo.wptrOffSet = wPtr + data->renderBufInfo.trafBufSize;
+ data->renderBufInfo.wbufOffSet += data->renderBufInfo.trafBufSize;
+ data->renderBufInfo.framesPosition += data->renderBufInfo.trafBufSize / data->pcmInfo.frameSize;
+ data->mmapData.offset += data->renderBufInfo.trafBufSize;
+ data->mmapLoopCount++;
+ return HDF_SUCCESS;
+}
+
+static int32_t AudioMmapWriteTransfer(const struct AudioCard *card)
+{
+ uint32_t timeout = 0;
+ struct PlatformData *data = PlatformDataFromCard(card);
+ if (data == NULL) {
+ AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed.");
+ return HDF_FAILURE;
+ }
+ if (data->renderBufInfo.virtAddr == NULL) {
+ AUDIO_DRIVER_LOG_ERR("render buffer is null.");
+ return HDF_FAILURE;
+ }
+
+ uint32_t totalSize = (uint32_t)data->mmapData.totalBufferFrames * data->pcmInfo.frameSize;
+ uint32_t lastBuffSize = ((totalSize % MIN_PERIOD_SIZE) == 0) ? MIN_PERIOD_SIZE : (totalSize % MIN_PERIOD_SIZE);
+ uint32_t loopTimes = (lastBuffSize == MIN_PERIOD_SIZE) ?
+ (totalSize / MIN_PERIOD_SIZE) : (totalSize / MIN_PERIOD_SIZE + 1);
+ data->mmapLoopCount = 0;
+ char *tmpBuf = OsalMemCalloc(MIN_PERIOD_SIZE);
+ if (tmpBuf == NULL) {
+ AUDIO_DRIVER_LOG_ERR("tmpBuf is null.");
+ return HDF_FAILURE;
+ }
+ while (data->mmapLoopCount < loopTimes && data->renderBufInfo.runStatus != PCM_STOP) {
+ if (data->renderBufInfo.runStatus == PCM_PAUSE) {
+ OsalMSleep(5);
+ continue;
+ }
+
+ if (AudioDmaBuffStatus(card) != ENUM_CIR_BUFF_NORMAL) {
+ OsalMSleep(SLEEP_TIME);
+ AUDIO_DRIVER_LOG_DEBUG("dma buff status ENUM_CIR_BUFF_FULL.");
+ timeout++;
+ if (timeout >= TIME_OUT_CONST) {
+ AUDIO_DRIVER_LOG_ERR("timeout failed.");
+ OsalMemFree(tmpBuf);
+ return HDF_FAILURE;
+ }
+ continue;
+ }
+ timeout = 0;
+ data->renderBufInfo.trafBufSize = (data->mmapLoopCount < (loopTimes - 1)) ? MIN_PERIOD_SIZE : lastBuffSize;
+
+ if (MmapWriteData(data, tmpBuf) != HDF_SUCCESS) {
+ OsalMemFree(tmpBuf);
+ return HDF_FAILURE;
+ }
+ }
+
+ if (data->mmapLoopCount > loopTimes) {
+ data->renderBufInfo.runStatus = PCM_STOP;
+ }
+
+ OsalMemFree(tmpBuf);
+ return HDF_SUCCESS;
+}
+
+int32_t AudioPcmMmapWrite(const struct AudioCard *card, const struct AudioMmapData *txMmapData)
+{
+ int32_t ret;
+ struct PlatformData *data = NULL;
+ AUDIO_DRIVER_LOG_DEBUG("entry.");
+
+ data = PlatformDataFromCard(card);
+ if (data == NULL) {
+ AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed.");
+ return HDF_FAILURE;
+ }
+
+ if (txMmapData == NULL || txMmapData->memoryAddress == NULL || txMmapData->transferFrameSize <= 0 ||
+ txMmapData->totalBufferFrames <= 0) {
+ AUDIO_DRIVER_LOG_ERR("param is invalid.");
return HDF_ERR_INVALID_PARAM;
}
- if (card == NULL || card->rtd == NULL || card->rtd->platform == NULL) {
+
+ data->mmapData.offset = txMmapData->offset;
+ data->mmapData.memoryAddress = txMmapData->memoryAddress;
+ data->mmapData.totalBufferFrames = txMmapData->totalBufferFrames;
+ data->mmapData.transferFrameSize = txMmapData->transferFrameSize;
+ data->mmapLoopCount = 0;
+
+ AUDIO_DRIVER_LOG_DEBUG("*******offset=0x%x memoryAddress=0x%x totalBufferFrames=0x%x transferFrameSize=0x%x ",
+ data->mmapData.offset, data->mmapData.memoryAddress, data->mmapData.totalBufferFrames,
+ data->mmapData.transferFrameSize);
+
+ ret = AudioMmapWriteTransfer(card);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("AudioMmapTransfer fail.");
+ return HDF_FAILURE;
+ }
+
+ AUDIO_DRIVER_LOG_DEBUG("render mmap write success.");
+ return HDF_SUCCESS;
+}
+
+static int32_t MmapReadData(struct PlatformData *data, const struct AudioMmapData *rxMmapData, uint32_t offset)
+{
+ uint32_t wPtr;
+ uint32_t rPtr;
+ uint32_t validDataSize;
+
+ if (data == NULL || rxMmapData == NULL) {
+ AUDIO_DRIVER_LOG_ERR("data is null.");
+ return HDF_FAILURE;
+ }
+
+ rPtr = data->captureBufInfo.rptrOffSet;
+ wPtr = data->captureBufInfo.pointer * data->pcmInfo.frameSize;
+ if (rPtr > wPtr) {
+ validDataSize = data->captureBufInfo.cirBufSize - rPtr;
+ if (validDataSize < data->captureBufInfo.trafBufSize) {
+ data->captureBufInfo.curTrafSize = validDataSize;
+ }
+ }
+ if (!data->pcmInfo.isBigEndian) {
+ if (AudioDataBigEndianChange((char *)(data->captureBufInfo.virtAddr) + rPtr,
+ data->captureBufInfo.curTrafSize, data->pcmInfo.bitWidth) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("AudioDataBigEndianChange: failed.");
+ return HDF_FAILURE;
+ }
+ }
+
+ if (CopyToUser((char *)rxMmapData->memoryAddress + offset,
+ (char *)(data->captureBufInfo.virtAddr) + rPtr, data->captureBufInfo.curTrafSize) != 0) {
+ AUDIO_DRIVER_LOG_ERR("CopyToUser failed.");
+ return HDF_FAILURE;
+ }
+
+ // 4. update rptr
+ data->captureBufInfo.rptrOffSet += data->captureBufInfo.curTrafSize;
+ if (data->captureBufInfo.rptrOffSet >= data->captureBufInfo.cirBufSize) {
+ data->captureBufInfo.rptrOffSet = 0;
+ }
+ data->captureBufInfo.framesPosition += data->captureBufInfo.curTrafSize / data->pcmInfo.frameSize;
+
+ return HDF_SUCCESS;
+}
+
+int32_t AudioMmapReadTransfer(const struct AudioCard *card, const struct AudioMmapData *rxMmapData)
+{
+ uint32_t offset = 0;
+ enum CriBuffStatus status;
+ uint32_t timeout = 0;
+
+ if (card == NULL || rxMmapData == NULL || rxMmapData->memoryAddress == NULL ||
+ rxMmapData->totalBufferFrames <= 0) {
+ AUDIO_DRIVER_LOG_ERR("param is invalid.");
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ struct PlatformData *data = PlatformDataFromCard(card);
+ if (data == NULL) {
+ AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed.");
+ return HDF_FAILURE;
+ }
+
+ uint32_t frameSize = data->pcmInfo.frameSize;
+ uint32_t totalSize = (uint32_t)rxMmapData->totalBufferFrames * frameSize;
+ data->captureBufInfo.pointer = 0;
+ data->captureBufInfo.curTrafSize = data->captureBufInfo.trafBufSize;
+ if (data->captureBufInfo.virtAddr == NULL) {
+ AUDIO_DRIVER_LOG_ERR("capture buffer is null.");
+ return HDF_FAILURE;
+ }
+
+ do {
+ if (data->captureBufInfo.runStatus == PCM_PAUSE) {
+ OsalMSleep(5);
+ continue;
+ }
+
+ // 1. get buffer status
+ status = AudioDmaBuffStatus(card);
+ if (status != ENUM_CIR_BUFF_NORMAL) {
+ OsalMSleep(SLEEP_TIME);
+ AUDIO_DRIVER_LOG_DEBUG("dma buff status ENUM_CIR_BUFF_FULL.");
+ timeout++;
+ if (timeout >= TIME_OUT_CONST) {
+ AUDIO_DRIVER_LOG_ERR("timeout failed.");
+ return HDF_FAILURE;
+ }
+ continue;
+ }
+ timeout = 0;
+
+ // 2. read data
+ if (MmapReadData(data, rxMmapData, offset) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("MmapReadData fail.");
+ return HDF_FAILURE;
+ }
+ offset += data->captureBufInfo.curTrafSize;
+ } while (offset < totalSize && data->captureBufInfo.runStatus != 0);
+ return HDF_SUCCESS;
+}
+
+int32_t AudioPcmMmapRead(const struct AudioCard *card, const struct AudioMmapData *rxMmapData)
+{
+ int32_t ret;
+ struct PlatformData *data = NULL;
+ AUDIO_DRIVER_LOG_DEBUG("entry.");
+
+ ret = (card == NULL || rxMmapData == NULL || rxMmapData->memoryAddress == NULL
+ || rxMmapData->totalBufferFrames <= 0);
+ if (ret) {
+ AUDIO_DRIVER_LOG_ERR("param is invalid.");
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ data = PlatformDataFromCard(card);
+ if (data == NULL) {
+ AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed.");
+ return HDF_FAILURE;
+ }
+
+ ret = AudioMmapReadTransfer(card, rxMmapData);
+ if (ret) {
+ AUDIO_DRIVER_LOG_ERR("AudioMmapReadTransfer fail.");
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ AUDIO_DRIVER_LOG_DEBUG("success.");
+ return HDF_SUCCESS;
+}
+
+static int32_t AudioRenderBuffInit(struct PlatformData *platformData)
+{
+ int ret;
+
+ if (platformData == NULL) {
AUDIO_DRIVER_LOG_ERR("input para is NULL.");
return HDF_FAILURE;
}
- *platformHost = PlatformHostFromDevice(card->rtd->platform->device);
- if (*platformHost == NULL) {
- AUDIO_DRIVER_LOG_ERR("PlatformHostFromDevice faile.");
+ if (platformData->renderBufInfo.virtAddr != NULL) {
+ return HDF_SUCCESS;
+ }
+
+ platformData->renderBufInfo.cirBufMax = MAX_BUFF_SIZE;
+ platformData->renderBufInfo.phyAddr = 0;
+
+ ret = AudioDmaBufAlloc(platformData, AUDIO_RENDER_STREAM);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("Dma Buf Alloc fail.");
+ return HDF_FAILURE;
+ }
+
+ if (platformData->renderBufInfo.virtAddr == NULL) {
+ AUDIO_DRIVER_LOG_ERR("mem alloc failed.");
return HDF_FAILURE;
}
+
+ (void)memset_s(platformData->renderBufInfo.virtAddr, platformData->renderBufInfo.cirBufMax,
+ 0, platformData->renderBufInfo.cirBufMax);
+
return HDF_SUCCESS;
}
-int32_t AudioDataBigEndianChange(char *srcData, uint32_t audioLen, enum DataBitWidth bitWidth)
+static int32_t AudioRenderBuffFree(struct PlatformData *platformData)
{
- uint64_t i;
- uint16_t framesize;
- char temp;
- if (srcData == NULL) {
- AUDIO_DRIVER_LOG_ERR("srcData is NULL.");
+ int ret;
+
+ if (platformData == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input param is NULL.");
return HDF_FAILURE;
}
- switch (bitWidth) {
- case DATA_BIT_WIDTH8:
- framesize = 1; /* 1 byte */
+ ret = AudioDmaBufFree(platformData, AUDIO_RENDER_STREAM);
+ if (ret) {
+ AUDIO_DRIVER_LOG_ERR("Dma Buf Alloc fail.");
+ return HDF_FAILURE;
+ }
+
+ platformData->renderBufInfo.virtAddr = NULL;
+ platformData->renderBufInfo.phyAddr = 0;
+ return HDF_SUCCESS;
+}
+
+static int32_t AudioCaptureBuffInit(struct PlatformData *platformData)
+{
+ int ret;
+
+ if (platformData == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input param is NULL.");
+ return HDF_FAILURE;
+ }
+ if (platformData->captureBufInfo.virtAddr != NULL) {
+ return HDF_SUCCESS;
+ }
+
+ platformData->captureBufInfo.cirBufMax = MAX_BUFF_SIZE;
+ platformData->captureBufInfo.phyAddr = 0;
+
+ ret = AudioDmaBufAlloc(platformData, AUDIO_CAPTURE_STREAM);
+ if (ret) {
+ AUDIO_DRIVER_LOG_ERR("Dma Buf Alloc fail.");
+ return HDF_FAILURE;
+ }
+
+ if (platformData->captureBufInfo.virtAddr == NULL) {
+ AUDIO_DRIVER_LOG_ERR("mem alloc failed.");
+ return HDF_FAILURE;
+ }
+
+ (void)memset_s(platformData->captureBufInfo.virtAddr, platformData->captureBufInfo.cirBufMax, 0,
+ platformData->captureBufInfo.cirBufMax);
+
+ return HDF_SUCCESS;
+}
+
+static int32_t AudioCaptureBuffFree(struct PlatformData *platformData)
+{
+ int ret;
+
+ if (platformData == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input param is NULL.");
+ return HDF_FAILURE;
+ }
+
+ ret = AudioDmaBufFree(platformData, AUDIO_CAPTURE_STREAM);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("Dma Buf Alloc fail.");
+ return HDF_FAILURE;
+ }
+
+ platformData->captureBufInfo.virtAddr = NULL;
+ platformData->captureBufInfo.phyAddr = 0;
+ return HDF_SUCCESS;
+}
+
+int32_t AudioRenderOpen(const struct AudioCard *card)
+{
+ struct PlatformData *data = PlatformDataFromCard(card);
+ if (data == NULL) {
+ AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed.");
+ return HDF_FAILURE;
+ }
+
+ if (data->renderBufInfo.virtAddr == NULL) {
+ if (AudioRenderBuffInit(data) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ }
+ return HDF_SUCCESS;
+}
+
+int32_t AudioRenderClose(const struct AudioCard *card)
+{
+ struct PlatformData *data = PlatformDataFromCard(card);
+ if (data == NULL) {
+ AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed.");
+ return HDF_FAILURE;
+ }
+
+ return AudioRenderBuffFree(data);
+}
+
+int32_t AudioCaptureOpen(const struct AudioCard *card)
+{
+ if (card == NULL) {
+ AUDIO_DRIVER_LOG_ERR("param card is NULL.");
+ return HDF_FAILURE;
+ }
+
+ struct PlatformData *platformData = PlatformDataFromCard(card);
+ if (platformData == NULL) {
+ AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed.");
+ return HDF_FAILURE;
+ }
+
+ if (platformData->captureBufInfo.virtAddr == NULL) {
+ if (AudioCaptureBuffInit(platformData) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("AudioCaptureBuffInit: fail.");
+ return HDF_FAILURE;
+ }
+ }
+ return HDF_SUCCESS;
+}
+
+int32_t AudioCaptureClose(const struct AudioCard *card)
+{
+ if (card == NULL) {
+ AUDIO_DRIVER_LOG_ERR("param card is NULL.");
+ return HDF_FAILURE;
+ }
+
+ struct PlatformData *platformData = PlatformDataFromCard(card);
+ if (platformData == NULL) {
+ AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed.");
+ return HDF_FAILURE;
+ }
+ return AudioCaptureBuffFree(platformData);
+}
+
+static int32_t AudioPcmPending(struct AudioCard *card)
+{
+ struct PlatformData *data = PlatformDataFromCard(card);
+ if (data == NULL) {
+ AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed.");
+ return HDF_FAILURE;
+ }
+
+ if (AudioDmaSubmit(data) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("DmaPending fail.");
+ return HDF_FAILURE;
+ }
+
+ if (AudioDmaPending(data) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("DmaPending fail.");
+ return HDF_FAILURE;
+ }
+
+ if (AudioSampSetPowerMonitor(card, false) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t AudioPcmPause(struct AudioCard *card)
+{
+ struct PlatformData *data = PlatformDataFromCard(card);
+ if (data == NULL) {
+ AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed.");
+ return HDF_FAILURE;
+ }
+
+ if (AudioDmaPause(data) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("DmaPause fail.");
+ return HDF_FAILURE;
+ }
+
+ if (AudioSampSetPowerMonitor(card, true) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t AudioPcmResume(struct AudioCard *card)
+{
+ struct PlatformData *data = PlatformDataFromCard(card);
+ if (data == NULL) {
+ AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed.");
+ return HDF_FAILURE;
+ }
+
+ if (AudioDmaResume(data) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("DmaPause fail.");
+ return HDF_FAILURE;
+ }
+
+ if (AudioSampPowerUp(card) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ if (AudioSampSetPowerMonitor(card, false) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+int32_t AudioRenderTrigger(struct AudioCard *card, int cmd)
+{
+ struct PlatformData *data = PlatformDataFromCard(card);
+ if (data == NULL) {
+ AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed.");
+ return HDF_FAILURE;
+ }
+
+ switch (cmd) {
+ case AUDIO_DRV_PCM_IOCTL_RENDER_START:
+ if (AudioPcmPending(card) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("AudioPcmPending fail.");
+ return HDF_FAILURE;
+ }
+
+ data->renderBufInfo.runStatus = PCM_START;
break;
- case DATA_BIT_WIDTH16:
- framesize = 2; /* 2 bytes */
+ case AUDIO_DRV_PCM_IOCTL_RENDER_STOP:
+ if (AudioPcmPause(card) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("AudioPcmPause fail.");
+ return HDF_FAILURE;
+ }
+
+ data->renderBufInfo.runStatus = PCM_STOP;
break;
- case DATA_BIT_WIDTH24:
- framesize = 3; /* 3 bytes */
+ case AUDIO_DRV_PCM_IOCTL_RENDER_PAUSE:
+ if (AudioPcmPause(card) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("AudioPcmPause fail.");
+ return HDF_FAILURE;
+ }
+
+ data->renderBufInfo.runStatus = PCM_PAUSE;
+ break;
+ case AUDIO_DRV_PCM_IOCTL_RENDER_RESUME:
+ if (AudioPcmResume(card) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("AudioPcmResume fail.");
+ return HDF_FAILURE;
+ }
+
+ data->renderBufInfo.runStatus = PCM_START;
break;
default:
- framesize = 2; /* default 2 bytes */
+ AUDIO_DRIVER_LOG_ERR("invalude cmd id: %d.", cmd);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+int32_t AudioCaptureTrigger(struct AudioCard *card, int cmd)
+{
+ struct PlatformData *data = PlatformDataFromCard(card);
+ if (data == NULL) {
+ AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed.");
+ return HDF_FAILURE;
+ }
+
+ switch (cmd) {
+ case AUDIO_DRV_PCM_IOCTL_CAPTURE_START:
+ if (AudioPcmPending(card) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("AudioPcmPending fail.");
+ return HDF_FAILURE;
+ }
+
+ data->captureBufInfo.runStatus = PCM_START;
break;
+ case AUDIO_DRV_PCM_IOCTL_CAPTURE_STOP:
+ if (AudioPcmPause(card) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("AudioPcmPause fail.");
+ return HDF_FAILURE;
+ }
+
+ data->captureBufInfo.runStatus = PCM_STOP;
+ break;
+ case AUDIO_DRV_PCM_IOCTL_CAPTURE_PAUSE:
+ if (AudioPcmPause(card) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("AudioPcmPause fail.");
+ return HDF_FAILURE;
+ }
+
+ data->captureBufInfo.runStatus = PCM_PAUSE;
+ break;
+ case AUDIO_DRV_PCM_IOCTL_CAPTURE_RESUME:
+ if (AudioPcmResume(card) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("AudioPcmResume fail.");
+ return HDF_FAILURE;
+ }
+
+ data->captureBufInfo.runStatus = PCM_START;
+ break;
+ default:
+ AUDIO_DRIVER_LOG_ERR("invalude cmd id: %d.", cmd);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+int32_t AudioHwParams(const struct AudioCard *card, const struct AudioPcmHwParams *param)
+{
+ const int chnlCntMin = 1;
+ const int chnlCntMax = 2;
+
+ if (card == NULL || param == NULL || param->cardServiceName == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input param is NULL.");
+ return HDF_FAILURE;
}
- for (i = 0; i < audioLen; i += framesize) {
- temp = srcData[i];
- srcData[i] = srcData[i + framesize - 1];
- srcData[i + framesize - 1] = temp;
+ if (param->channels < chnlCntMin || param->channels > chnlCntMax) {
+ AUDIO_DRIVER_LOG_ERR("channels param is invalid.");
+ return HDF_FAILURE;
+ }
+
+ struct PlatformData *platformData = PlatformDataFromCard(card);
+ if (platformData == NULL) {
+ AUDIO_DRIVER_LOG_ERR("platformData is null.");
+ return HDF_FAILURE;
+ }
+
+ if (AudioFramatToBitWidth(param->format, &platformData->pcmInfo.bitWidth) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ if (AudioSetPcmInfo(platformData, param) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ if (AudioDmaRequestChannel(platformData) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("Dma Request Channel fail.");
+ return HDF_FAILURE;
+ }
+
+ if (param->streamType == AUDIO_RENDER_STREAM) {
+ if (AudioSetRenderBufInfo(platformData, param) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ } else if (param->streamType == AUDIO_CAPTURE_STREAM) {
+ if (AudioSetCaptureBufInfo(platformData, param) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ } else {
+ AUDIO_DRIVER_LOG_ERR("param streamType is invalid.");
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+int32_t AudioRenderPrepare(const struct AudioCard *card)
+{
+ int ret;
+ if (card == NULL) {
+ AUDIO_DRIVER_LOG_ERR("param card is NULL.");
+ return HDF_FAILURE;
+ }
+
+ struct PlatformData *platformData = PlatformDataFromCard(card);
+ if (platformData == NULL) {
+ AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed.");
+ return HDF_FAILURE;
+ }
+
+ if (platformData->renderBufInfo.virtAddr != NULL) {
+ (void)memset_s(platformData->renderBufInfo.virtAddr, platformData->renderBufInfo.cirBufSize, 0,
+ platformData->renderBufInfo.cirBufSize);
+ }
+ platformData->renderBufInfo.wbufOffSet = 0;
+ platformData->renderBufInfo.wptrOffSet = 0;
+ platformData->pcmInfo.totalStreamSize = 0;
+ platformData->renderBufInfo.framesPosition = 0;
+ platformData->renderBufInfo.pointer = 0;
+
+ ret = AudioDmaConfigChannel(platformData);
+ if (ret) {
+ AUDIO_DRIVER_LOG_ERR("Dma Config Channel fail.");
+ return HDF_FAILURE;
}
- AUDIO_DRIVER_LOG_DEBUG("audioLen = %d\n", audioLen);
+
+ return HDF_SUCCESS;
+}
+
+int32_t AudioCapturePrepare(const struct AudioCard *card)
+{
+ int ret;
+ if (card == NULL) {
+ AUDIO_DRIVER_LOG_ERR("param card is NULL.");
+ return HDF_FAILURE;
+ }
+
+ struct PlatformData *platformData = PlatformDataFromCard(card);
+ if (platformData == NULL) {
+ AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed.");
+ return HDF_FAILURE;
+ }
+
+ if (platformData->captureBufInfo.virtAddr != NULL) {
+ (void)memset_s(platformData->captureBufInfo.virtAddr, platformData->captureBufInfo.cirBufSize, 0,
+ platformData->captureBufInfo.cirBufSize);
+ }
+ platformData->captureBufInfo.rbufOffSet = 0;
+ platformData->captureBufInfo.rptrOffSet = 0;
+ platformData->captureBufInfo.chnId = 0;
+ platformData->pcmInfo.totalStreamSize = 0;
+ platformData->captureBufInfo.framesPosition = 0;
+ platformData->captureBufInfo.pointer = 0;
+
+ ret = AudioDmaConfigChannel(platformData);
+ if (ret) {
+ AUDIO_DRIVER_LOG_ERR("Dma Config Channel fail.");
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+int32_t AudioPcmPointer(const struct AudioCard *card, uint32_t *pointer)
+{
+ int ret;
+ if (card == NULL || pointer == NULL) {
+ AUDIO_DRIVER_LOG_ERR("param card is NULL.");
+ return HDF_FAILURE;
+ }
+
+ struct PlatformData *data = PlatformDataFromCard(card);
+ if (data == NULL) {
+ AUDIO_DRIVER_LOG_ERR("PlatformDataFromCard failed.");
+ return HDF_FAILURE;
+ }
+
+ ret = AudioDmaPointer(data, pointer);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("Dma Pointer fail.");
+ return HDF_FAILURE;
+ }
+
return HDF_SUCCESS;
}
diff --git a/model/audio/common/test/unittest/common/audio_accessory_base_test.cpp b/model/audio/common/test/unittest/common/audio_accessory_base_test.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..159dd09cdb3301ef590d94d917da4dd3007602f3
--- /dev/null
+++ b/model/audio/common/test/unittest/common/audio_accessory_base_test.cpp
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 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 "audio_common_test.h"
+#include
+#include "hdf_uhdf_test.h"
+
+using namespace testing::ext;
+namespace {
+class AudioAccessoryBaseTest : public testing::Test {
+public:
+ static void SetUpTestCase();
+ static void TearDownTestCase();
+ void SetUp();
+ void TearDown();
+};
+
+void AudioAccessoryBaseTest::SetUpTestCase()
+{
+ HdfTestOpenService();
+}
+
+void AudioAccessoryBaseTest::TearDownTestCase()
+{
+ HdfTestCloseService();
+}
+
+void AudioAccessoryBaseTest::SetUp()
+{
+}
+
+void AudioAccessoryBaseTest::TearDown()
+{
+}
+
+HWTEST_F(AudioAccessoryBaseTest, AudioAccessoryBaseTest_I2cReadWrite, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTI2CREADWRITE, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioAccessoryBaseTest, AudioAccessoryBaseTest_RegBitsRead, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTREGBITSREAD, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioAccessoryBaseTest, AudioAccessoryBaseTest_RegBitsUpdate, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTREGBITSUPDATE, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioAccessoryBaseTest, AudioAccessoryBaseTest_DeviceFrequencyParse, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDEVICEFREQUENCYPARSE, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioAccessoryBaseTest, AudioAccessoryBaseTest_DaiParamsUpdate, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDAIPARAMSUPDATE, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioAccessoryBaseTest, AudioAccessoryBaseTest_DeviceCfgGet, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDEVICECFGGET, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioAccessoryBaseTest, AudioAccessoryBaseTest_DeviceCtrlRegInit, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDEVICECTRLREGINIT, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioAccessoryBaseTest, AudioAccessoryBaseTest_DeviceRegRead, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDEVICEREGREAD, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioAccessoryBaseTest, AudioAccessoryBaseTest_DeviceRegWrite, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDEVICEREGWRITE, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioAccessoryBaseTest, AudioAccessoryBaseTest_AccessoryGetConfigInfo, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTAGETCONFIGINFO, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+}
diff --git a/model/audio/common/test/unittest/common/audio_codec_base_test.cpp b/model/audio/common/test/unittest/common/audio_codec_base_test.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..406d6d776bdaaaf06bd4a53a3d9061c0c1c0494d
--- /dev/null
+++ b/model/audio/common/test/unittest/common/audio_codec_base_test.cpp
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 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 "audio_common_test.h"
+#include
+#include "hdf_uhdf_test.h"
+
+using namespace testing::ext;
+
+namespace {
+class AudioCodecBaseTest : public testing::Test {
+public:
+ static void SetUpTestCase();
+ static void TearDownTestCase();
+ void SetUp();
+ void TearDown();
+};
+
+void AudioCodecBaseTest::SetUpTestCase()
+{
+ HdfTestOpenService();
+}
+
+void AudioCodecBaseTest::TearDownTestCase()
+{
+ HdfTestCloseService();
+}
+
+void AudioCodecBaseTest::SetUp()
+{
+}
+
+void AudioCodecBaseTest::TearDown()
+{
+}
+
+HWTEST_F(AudioCodecBaseTest, AudioCodecBaseTest_GetServiceName, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTGETSERVICENAME, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioCodecBaseTest, AudioCodecBaseTest_GetDaiName, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTGETDAINAME, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioCodecBaseTest, AudioCodecBaseTest_GetConfigInfo, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTGETCONFIGINFO, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioCodecBaseTest, AudioCodecBaseTest_SetConfigInfo, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTSETCONFIGINFO, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioCodecBaseTest, AudioCodecBaseTest_SetCtlFunc, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTSETCTLFUNC, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+}
diff --git a/model/audio/common/test/unittest/common/audio_common_test.h b/model/audio/common/test/unittest/common/audio_common_test.h
new file mode 100644
index 0000000000000000000000000000000000000000..26bcd52cc823b291de9c2085e7f442ae13299ce5
--- /dev/null
+++ b/model/audio/common/test/unittest/common/audio_common_test.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef AUDIO_COMMON_TEST_H
+#define AUDIO_COMMON_TEST_H
+
+#include "hdf_types.h"
+
+const int32_t g_testAudioType = 701; // 701 is TEST_AUDIO_TYPE
+
+enum {
+ TESTI2CREADWRITE = 48,
+ TESTREGBITSREAD,
+ TESTREGBITSUPDATE,
+ TESTDEVICEFREQUENCYPARSE,
+ TESTDAIPARAMSUPDATE,
+ TESTDEVICECFGGET,
+ TESTDEVICECTRLREGINIT,
+ TESTDEVICEREGREAD,
+ TESTDEVICEREGWRITE,
+ TESTAGETCONFIGINFO,
+
+ TESTGETSERVICENAME,
+ TESTGETDAINAME,
+ TESTGETCONFIGINFO,
+ TESTSETCONFIGINFO,
+ TESTSETCTLFUNC,
+
+ TESTDAIDATAFROMCARD,
+ TESTDAIGETCONFIGINFO,
+ TESTDAICHECKSAMPLERATE,
+ TESTDAISETCONFIGINFO,
+
+ TESTDMABUFALLOC,
+ TESTDMABUFFREE,
+ TESTDMAREQUESTCHANNEL,
+ TESTDMACONFIGCHANNEL,
+ TESTDMAPREP,
+ TESTDMASUBMIT,
+ TESTDMAPENDING,
+ TESTDMAPAUSE,
+ TESTDMARESUME,
+ TESTDMAPOINTER,
+
+ TESTDSPGETSERVICENAME,
+ TESTDSPGETDAINAME,
+
+ TESTDATAFROMCARD,
+ TESTBYTESTOFRAMES,
+ TESTDATABIGENDIANCHANGE,
+ TESTFRAMATTOBITWIDTH,
+ TESTSETPCMINFO,
+ TESTSETRENDERBUFINFO,
+ TESTSETCAPTUREBUFINFO,
+ TESTPCMWRITE,
+ TESTPCMREAD,
+ TESTPCMMMAPWRITE,
+ TESTPCMMMAPREAD,
+ TESTRENDEROPEN,
+ TESTCAPTUREOPEN,
+ TESTRENDERCLOSE,
+ TESTPCMPOINTER,
+ TESTCAPTURECLOSE,
+ TESTHWPARAMS,
+ TESTRENDERPREPARE,
+ TESTCAPTUREPREPARE,
+ TESTRENDERTRIGGER,
+ TESTCAPTURETRIGGER,
+};
+
+#endif /* AUDIO_COMMON_TEST_H */
diff --git a/model/audio/common/test/unittest/common/audio_dai_base_test.cpp b/model/audio/common/test/unittest/common/audio_dai_base_test.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..d52654186fb75f1d553fa84562a4695a5adaff1f
--- /dev/null
+++ b/model/audio/common/test/unittest/common/audio_dai_base_test.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 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 "audio_common_test.h"
+#include
+#include "hdf_uhdf_test.h"
+
+using namespace testing::ext;
+
+namespace {
+class AudioDaiBaseTest : public testing::Test {
+public:
+ static void SetUpTestCase();
+ static void TearDownTestCase();
+ void SetUp();
+ void TearDown();
+};
+
+void AudioDaiBaseTest::SetUpTestCase()
+{
+ HdfTestOpenService();
+}
+
+void AudioDaiBaseTest::TearDownTestCase()
+{
+ HdfTestCloseService();
+}
+
+void AudioDaiBaseTest::SetUp()
+{
+}
+
+void AudioDaiBaseTest::TearDown()
+{
+}
+
+HWTEST_F(AudioDaiBaseTest, AudioDaiBaseTest_DataFromCard, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDAIDATAFROMCARD, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioDaiBaseTest, AudioDaiBaseTest_GetConfigInfo, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDAIGETCONFIGINFO, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioDaiBaseTest, AudioDaiBaseTest_CheckSampleRate, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDAICHECKSAMPLERATE, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioDaiBaseTest, AudioDaiBaseTest_SetConfigInfo, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDAISETCONFIGINFO, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+}
diff --git a/model/audio/common/test/unittest/common/audio_dma_base_test.cpp b/model/audio/common/test/unittest/common/audio_dma_base_test.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..1cfb5fc12327effedd79e5ee76ffe5486e5cc4e0
--- /dev/null
+++ b/model/audio/common/test/unittest/common/audio_dma_base_test.cpp
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 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 "audio_common_test.h"
+#include
+#include "hdf_uhdf_test.h"
+
+using namespace testing::ext;
+
+namespace {
+class AudioDmaBaseTest : public testing::Test {
+public:
+ static void SetUpTestCase();
+ static void TearDownTestCase();
+ void SetUp();
+ void TearDown();
+};
+
+void AudioDmaBaseTest::SetUpTestCase()
+{
+ HdfTestOpenService();
+}
+
+void AudioDmaBaseTest::TearDownTestCase()
+{
+ HdfTestCloseService();
+}
+
+void AudioDmaBaseTest::SetUp()
+{
+}
+
+void AudioDmaBaseTest::TearDown()
+{
+}
+
+HWTEST_F(AudioDmaBaseTest, AudioDmaBaseTest_DmaBufAlloc, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDMABUFALLOC, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioDmaBaseTest, AudioDmaBaseTest_DmaBufFree, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDMABUFFREE, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioDmaBaseTest, AudioDmaBaseTest_DmaRequestChannel, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDMAREQUESTCHANNEL, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioDmaBaseTest, AudioDmaBaseTest_DmaConfigChannel, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDMACONFIGCHANNEL, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioDmaBaseTest, AudioDmaBaseTest_DmaPrep, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDMAPREP, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioDmaBaseTest, AudioDmaBaseTest_DmaSubmit, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDMASUBMIT, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioDmaBaseTest, AudioDmaBaseTest_DmaPending, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDMAPENDING, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioDmaBaseTest, AudioDmaBaseTest_DmaPause, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDMAPAUSE, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioDmaBaseTest, AudioDmaBaseTest_DmaResume, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDMARESUME, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioDmaBaseTest, AudioDmaBaseTest_DmaPointer, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDMAPOINTER, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+}
diff --git a/model/audio/dispatch/test/unittest/common/audio_stream_dispatch_test.cpp b/model/audio/common/test/unittest/common/audio_dsp_base_test.cpp
old mode 100755
new mode 100644
similarity index 52%
rename from model/audio/dispatch/test/unittest/common/audio_stream_dispatch_test.cpp
rename to model/audio/common/test/unittest/common/audio_dsp_base_test.cpp
index 50bd21dcb33801432d9962cb098caeca6f0cd071..253c23b6db35f9e70f31347651db3683794d8957
--- a/model/audio/dispatch/test/unittest/common/audio_stream_dispatch_test.cpp
+++ b/model/audio/common/test/unittest/common/audio_dsp_base_test.cpp
@@ -12,7 +12,8 @@
using namespace testing::ext;
-class AudioStreamDispatchTest : public testing::Test {
+namespace {
+class AudioDspBaseTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
@@ -20,26 +21,33 @@ public:
void TearDown();
};
-void AudioStreamDispatchTest::SetUpTestCase()
+void AudioDspBaseTest::SetUpTestCase()
{
HdfTestOpenService();
}
-void AudioStreamDispatchTest::TearDownTestCase()
+void AudioDspBaseTest::TearDownTestCase()
{
HdfTestCloseService();
}
-void AudioStreamDispatchTest::SetUp()
+void AudioDspBaseTest::SetUp()
{
}
-void AudioStreamDispatchTest::TearDown()
+void AudioDspBaseTest::TearDown()
{
}
-HWTEST_F(AudioStreamDispatchTest, AudioStreamDispatchTest001, TestSize.Level0)
+HWTEST_F(AudioDspBaseTest, AudioDspBaseTest_DspGetServiceName, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTSTREAMDISPATCH, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TESTDSPGETSERVICENAME, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
+
+HWTEST_F(AudioDspBaseTest, AudioDspBaseTest_DspGetDaiName, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDSPGETDAINAME, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+}
diff --git a/model/audio/common/test/unittest/common/audio_platform_base_test.cpp b/model/audio/common/test/unittest/common/audio_platform_base_test.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5524237630bd67c27c2dd39aeb60dc36add3394a
--- /dev/null
+++ b/model/audio/common/test/unittest/common/audio_platform_base_test.cpp
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 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 "audio_common_test.h"
+#include
+#include "hdf_uhdf_test.h"
+
+using namespace testing::ext;
+
+namespace {
+class AudioPlatformBaseTest : public testing::Test {
+public:
+ static void SetUpTestCase();
+ static void TearDownTestCase();
+ void SetUp();
+ void TearDown();
+};
+
+void AudioPlatformBaseTest::SetUpTestCase()
+{
+ HdfTestOpenService();
+}
+
+void AudioPlatformBaseTest::TearDownTestCase()
+{
+ HdfTestCloseService();
+}
+
+void AudioPlatformBaseTest::SetUp()
+{
+}
+
+void AudioPlatformBaseTest::TearDown()
+{
+}
+
+HWTEST_F(AudioPlatformBaseTest, AudioPlatformBaseTest_PlatformDataFromCardTest, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDATAFROMCARD, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioPlatformBaseTest, AudioPlatformBaseTest_AudioBytesToFramesTest, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTBYTESTOFRAMES, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioPlatformBaseTest, AudioPlatformBaseTest_AudioDataBigEndianChangeTest, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTDATABIGENDIANCHANGE, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioPlatformBaseTest, AudioPlatformBaseTest_AudioFramatToBitWidthTest, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTFRAMATTOBITWIDTH, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioPlatformBaseTest, AudioPlatformBaseTest_AudioSetPcmInfoTest, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTSETPCMINFO, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioPlatformBaseTest, AudioPlatformBaseTest_AudioSetRenderBufInfoTest, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTSETRENDERBUFINFO, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioPlatformBaseTest, AudioPlatformBaseTest_AudioSetCaptureBufInfoTest, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTSETCAPTUREBUFINFO, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioPlatformBaseTest, AudioPlatformBaseTest_AudioPcmWriteTest, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTPCMWRITE, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioPlatformBaseTest, AudioPlatformBaseTest_AudioPcmReadTest, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTPCMREAD, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioPlatformBaseTest, AudioPlatformBaseTest_AudioPcmMmapWriteTest, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTPCMMMAPWRITE, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioPlatformBaseTest, AudioPlatformBaseTest_AudioPcmMmapReadTest, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTPCMMMAPREAD, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioPlatformBaseTest, AudioPlatformBaseTest_AudioRenderOpenTest, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTRENDEROPEN, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioPlatformBaseTest, AudioPlatformBaseTest_AudioCaptureOpenTest, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTCAPTUREOPEN, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioPlatformBaseTest, AudioPlatformBaseTest_AudioRenderCloseTest, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTRENDERCLOSE, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioPlatformBaseTest, AudioPlatformBaseTest_AudioPcmPointerTest, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTPCMPOINTER, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioPlatformBaseTest, AudioPlatformBaseTest_AudioCaptureCloseTest, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTCAPTURECLOSE, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioPlatformBaseTest, AudioPlatformBaseTest_AudioHwParamsTest, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTHWPARAMS, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioPlatformBaseTest, AudioPlatformBaseTest_AudioRenderPrepareTest, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTRENDERPREPARE, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioPlatformBaseTest, AudioPlatformBaseTest_AudioCapturePrepareTest, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTCAPTUREPREPARE, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioPlatformBaseTest, AudioPlatformBaseTest_AudioRenderTriggerTest, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTRENDERTRIGGER, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioPlatformBaseTest, AudioPlatformBaseTest_AudioCaptureTriggerTest, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TESTCAPTURETRIGGER, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+}
diff --git a/model/audio/core/include/audio_control.h b/model/audio/core/include/audio_control.h
index cc674f739729ae8c27eecf8607fb9161d1755f2c..a8fa1034b02c3b1a3a20c2e0ee1e59601c7384a0 100755
--- a/model/audio/core/include/audio_control.h
+++ b/model/audio/core/include/audio_control.h
@@ -11,7 +11,6 @@
#include "hdf_dlist.h"
-
#ifdef __cplusplus
#if __cplusplus
extern "C" {
@@ -37,11 +36,6 @@ struct AudioCtrlElemValue {
uint32_t value[2];
};
-struct AudioKcontrol;
-typedef int32_t (*KconfigInfo_t)(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemInfo *elemInfo);
-typedef int32_t (*KconfigGet_t)(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue);
-typedef int32_t (*KconfigSet_t)(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue);
-
/* mixer control */
struct AudioMixerControl {
int32_t min;
@@ -53,14 +47,15 @@ struct AudioMixerControl {
uint32_t shift;
uint32_t rshift; /* right sound channel reg shift */
uint32_t invert;
+ uint32_t value;
};
struct AudioKcontrol {
const char *name; /* ASCII name of item */
int32_t iface;
- KconfigInfo_t Info;
- KconfigGet_t Get;
- KconfigSet_t Set;
+ int32_t (*Info)(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemInfo *elemInfo);
+ int32_t (*Get)(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue);
+ int32_t (*Set)(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue);
void *privateData;
void *pri;
unsigned long privateValue;
diff --git a/model/audio/core/include/audio_core.h b/model/audio/core/include/audio_core.h
index 6235bbb7a169698ac3bba7f587ffa5dc3918e106..30faa241d6d80f35f49b870f8df0ae0cc088f87b 100755
--- a/model/audio/core/include/audio_core.h
+++ b/model/audio/core/include/audio_core.h
@@ -23,85 +23,58 @@ extern "C" {
#endif
#endif /* __cplusplus */
-#define CHANNEL_MAX_NUM 2
-#define CHANNEL_MIN_NUM 1
+int32_t AudioDeviceReadReg(unsigned long virtualAddress, uint32_t reg, uint32_t *value);
+int32_t AudioDeviceWriteReg(unsigned long virtualAddress, uint32_t reg, uint32_t value);
-#define AUDIO_DAI_LINK_COMPLETE 1
-#define AUDIO_DAI_LINK_UNCOMPLETE 0
-
-#define AUDIO_DRIVER_LOG_ERR(fmt, arg...) do { \
- HDF_LOGE("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
- } while (0)
-
-#define AUDIO_DRIVER_LOG_INFO(fmt, arg...) do { \
- HDF_LOGI("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
- } while (0)
-
-#define AUDIO_DRIVER_LOG_WARNING(fmt, arg...) do { \
- HDF_LOGW("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
- } while (0)
-
-#define AUDIO_DRIVER_LOG_DEBUG(fmt, arg...) do { \
- HDF_LOGD("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
- } while (0)
-
-enum AudioDeviceType {
- AUDIO_DAI_DEVICE,
- AUDIO_DSP_DEVICE,
- AUDIO_PLATFORM_DEVICE,
- AUDIO_CODEC_DEVICE,
- AUDIO_ACCESSORY_DEVICE,
- AUDIO_DEVICE_BUTT,
-};
-
-enum PlayStatus {
- STREAM_START = 4,
- STREAM_STOP,
-};
-
-/* Dai registration interface */
-int32_t AudioSocRegisterDai(struct HdfDeviceObject *device, struct DaiData *data);
-/* Platform registration interface */
-int32_t AudioSocRegisterPlatform(struct HdfDeviceObject *device, struct PlatformData *data);
-/* Codec registration interface */
+int32_t AudioSocRegisterPlatform(struct HdfDeviceObject *device, struct PlatformData *platformData);
+int32_t AudioSocRegisterDai(struct HdfDeviceObject *device, struct DaiData *daiData);
+int32_t AudioRegisterDsp(struct HdfDeviceObject *device, struct DspData *dspData, struct DaiData *DaiData);
int32_t AudioRegisterCodec(struct HdfDeviceObject *device, struct CodecData *codecData, struct DaiData *daiData);
+int32_t AudioRegisterAccessory(struct HdfDeviceObject *device,
+ struct AccessoryData *accessoryData, struct DaiData *daiData);
+
int32_t AudioBindDaiLink(struct AudioCard *audioCard, const struct AudioConfigData *configData);
-int32_t AudioSocDeviceRegister(struct HdfDeviceObject *device, void *data, enum AudioDeviceType deviceType);
-int32_t AudioSocRegisterDsp(struct HdfDeviceObject *device, struct DaiData *data);
-int32_t AudioRegisterAccessory(struct HdfDeviceObject *device, struct AccessoryData *data, struct DaiData *daiData);
+
int32_t AudioUpdateCodecRegBits(struct CodecDevice *codec,
const struct AudioMixerControl *mixerControl, uint32_t value);
int32_t AudioUpdateAccessoryRegBits(struct AccessoryDevice *accessory,
const struct AudioMixerControl *mixerControl, uint32_t value);
-int32_t AudioUpdateCodecAiaoRegBits(struct CodecDevice *codec, const struct AudioMixerControl *mixerControl,
+int32_t AudioUpdateDaiRegBits(const struct DaiDevice *dai, const struct AudioMixerControl *mixerControl,
uint32_t value);
-int32_t AudioUpdateAccessoryAiaoRegBits(struct AccessoryDevice *accessory,
- const struct AudioMixerControl *mixerControl, uint32_t value);
+
+struct DaiDevice *AudioKcontrolGetCpuDai(const struct AudioKcontrol *kcontrol);
struct CodecDevice *AudioKcontrolGetCodec(const struct AudioKcontrol *kcontrol);
struct AccessoryDevice *AudioKcontrolGetAccessory(const struct AudioKcontrol *kcontrol);
+
int32_t AudioAddControls(struct AudioCard *audioCard,
const struct AudioKcontrol *controls, int32_t controlMaxNum);
struct AudioKcontrol *AudioAddControl(const struct AudioCard *audioCard, const struct AudioKcontrol *ctl);
+int32_t AudioGetCtrlOpsRReg(struct AudioCtrlElemValue *elemValue,
+ const struct AudioMixerControl *mixerCtrl, uint32_t rcurValue);
+int32_t AudioGetCtrlOpsReg(struct AudioCtrlElemValue *elemValue,
+ const struct AudioMixerControl *mixerCtrl, uint32_t curValue);
+int32_t AudioSetCtrlOpsReg(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue,
+ const struct AudioMixerControl *mixerCtrl, uint32_t *value);
+int32_t AudioSetCtrlOpsRReg(const struct AudioCtrlElemValue *elemValue,
+ struct AudioMixerControl *mixerCtrl, uint32_t *rvalue, bool *updateRReg);
+int32_t AudioDaiReadReg(const struct DaiDevice *dai, uint32_t reg, uint32_t *val);
+int32_t AudioDaiWriteReg(const struct DaiDevice *dai, uint32_t reg, uint32_t val);
+
int32_t AudioCodecReadReg(const struct CodecDevice *codec, uint32_t reg, uint32_t *val);
int32_t AudioCodecWriteReg(const struct CodecDevice *codec, uint32_t reg, uint32_t val);
int32_t AudioAccessoryReadReg(const struct AccessoryDevice *accessory, uint32_t reg, uint32_t *val);
int32_t AudioAccessoryWriteReg(const struct AccessoryDevice *accessory, uint32_t reg, uint32_t val);
-int32_t AudioCodecAiaoReadReg(const struct CodecDevice *codec, uint32_t reg, uint32_t *val);
-int32_t AudioCodecAiaoWriteReg(struct CodecDevice *codec, uint32_t reg, uint32_t val);
-int32_t AudioAccessoryAiaoReadReg(const struct AccessoryDevice *accessory, uint32_t reg, uint32_t *val);
-int32_t AudioAccessoryAiaoWriteReg(const struct AccessoryDevice *accessory, uint32_t reg, uint32_t val);
int32_t AudioInfoCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemInfo *elemInfo);
int32_t AudioCodecGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue);
int32_t AudioCodecSetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue);
int32_t AudioAccessoryGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue);
int32_t AudioAccessorySetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue);
-int32_t AudioCodecAiaoGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue);
-int32_t AudioCodecAiaoSetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue);
-int32_t AudioAccessoryAiaoGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue);
-int32_t AudioAccessoryAiaoSetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue);
-int32_t AudioRegisterDsp(struct HdfDeviceObject *device, struct DspData *dspData, struct DaiData *DaiData);
+
+int32_t AudioCpuDaiSetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue);
+int32_t AudioCpuDaiGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue);
+
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/model/audio/core/include/audio_host.h b/model/audio/core/include/audio_host.h
index afc51ac34af535b9f5d74fa5d9a2dfc5ac63c1f3..58585e2e7dcac7565c2252d487bd2ffc17633a67 100755
--- a/model/audio/core/include/audio_host.h
+++ b/model/audio/core/include/audio_host.h
@@ -24,29 +24,51 @@ extern "C" {
#endif
#endif /* __cplusplus */
-#define ADM_LOG_ERR(fmt, arg...) do { \
- HDF_LOGE("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
- } while (0)
-
-#define ADM_LOG_INFO(fmt, arg...) do { \
- HDF_LOGI("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
- } while (0)
-
-#define ADM_LOG_WARNING(fmt, arg...) do { \
- HDF_LOGW("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
- } while (0)
-
-#define ADM_LOG_DEBUG(fmt, arg...) do { \
- HDF_LOGD("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
- } while (0)
-
-#define BUFF_SIZE_MAX 64
-
#define AUDIO_LIST_HEAD_INIT(name) { &(name), &(name) }
#define AUDIO_LIST_HEAD(name) \
struct DListHead name = AUDIO_LIST_HEAD_INIT(name)
+enum AudioFormat {
+ AUDIO_FORMAT_PCM_8_BIT = 0x1u, /**< audio 8-bit PCM */
+ AUDIO_FORMAT_PCM_16_BIT = 0x2u, /**< audio16-bit PCM */
+ AUDIO_FORMAT_PCM_24_BIT = 0x3u, /**< audio 24-bit PCM */
+ AUDIO_FORMAT_PCM_32_BIT = 0x4u, /**< audio 32-bit PCM */
+ AUDIO_FORMAT_AAC_MAIN = 0x1000001u, /**< audio AAC main */
+ AUDIO_FORMAT_AAC_LC = 0x1000002u, /**< audio AAC LC */
+ AUDIO_FORMAT_AAC_LD = 0x1000003u, /**< audio AAC LD */
+ AUDIO_FORMAT_AAC_ELD = 0x1000004u, /**< audio AAC ELD */
+ AUDIO_FORMAT_AAC_HE_V1 = 0x1000005u, /**< audio AAC HE_V1 */
+ AUDIO_FORMAT_AAC_HE_V2 = 0x1000006u, /**< audio AAC HE_V2 */
+ AUDIO_FORMAT_G711A = 0x2000001u, /**< audio G711A */
+ AUDIO_FORMAT_G711U = 0x2000002u, /**< audio G711u */
+ AUDIO_FORMAT_G726 = 0x2000003u, /**< audio G726 */
+};
+
+typedef enum {
+ AUDIO_SAMPLE_RATE_8000 = 8000, /* 8kHz sample_rate */
+ AUDIO_SAMPLE_RATE_12000 = 12000, /* 12kHz sample_rate */
+ AUDIO_SAMPLE_RATE_11025 = 11025, /* 11.025kHz sample_rate */
+ AUDIO_SAMPLE_RATE_16000 = 16000, /* 16kHz sample_rate */
+ AUDIO_SAMPLE_RATE_22050 = 22050, /* 22.050kHz sample_rate */
+ AUDIO_SAMPLE_RATE_24000 = 24000, /* 24kHz sample_rate */
+ AUDIO_SAMPLE_RATE_32000 = 32000, /* 32kHz sample_rate */
+ AUDIO_SAMPLE_RATE_44100 = 44100, /* 44.1kHz sample_rate */
+ AUDIO_SAMPLE_RATE_48000 = 48000, /* 48kHz sample_rate */
+ AUDIO_SAMPLE_RATE_64000 = 64000, /* 64kHz sample_rate */
+ AUDIO_SAMPLE_RATE_96000 = 96000, /* 96kHz sample_rate */
+ AUDIO_SAMPLE_RATE_BUTT,
+} AudioSampleRate;
+
+enum AuidoBitWidth {
+ BIT_WIDTH8 = 8, /* 8 bit witdth */
+ BIT_WIDTH16 = 16, /* 16 bit witdth */
+ BIT_WIDTH18 = 18, /* 18 bit witdth */
+ BIT_WIDTH20 = 20, /* 20 bit witdth */
+ BIT_WIDTH24 = 24, /* 24 bit witdth */
+ BIT_WIDTH32 = 32, /* 32 bit witdth */
+};
+
struct AudioConfigData {
const char *cardServiceName;
const char *codecName;
@@ -59,20 +81,10 @@ struct AudioConfigData {
const char *dspDaiName;
};
-enum AudioFormat {
- AUDIO_FORMAT_PCM_8_BIT = 0x1u, /**< 8-bit PCM */
- AUDIO_FORMAT_PCM_16_BIT = 0x2u, /**< 16-bit PCM */
- AUDIO_FORMAT_PCM_24_BIT = 0x3u, /**< 24-bit PCM */
- AUDIO_FORMAT_PCM_32_BIT = 0x4u, /**< 32-bit PCM */
- AUDIO_FORMAT_AAC_MAIN = 0x1000001u, /**< AAC main */
- AUDIO_FORMAT_AAC_LC = 0x1000002u, /**< AAC LC */
- AUDIO_FORMAT_AAC_LD = 0x1000003u, /**< AAC LD */
- AUDIO_FORMAT_AAC_ELD = 0x1000004u, /**< AAC ELD */
- AUDIO_FORMAT_AAC_HE_V1 = 0x1000005u, /**< AAC HE_V1 */
- AUDIO_FORMAT_AAC_HE_V2 = 0x1000006u, /**< AAC HE_V2 */
- AUDIO_FORMAT_G711A = 0x2000001u, /**< G711A */
- AUDIO_FORMAT_G711U = 0x2000002u, /**< G711u */
- AUDIO_FORMAT_G726 = 0x2000003u, /**< G726 */
+enum AudioSapmTurnStandbyMode {
+ AUDIO_SAPM_TURN_STANDBY_LATER = 0,
+ AUDIO_SAPM_TURN_STANDBY_NOW,
+ AUDIO_SAPM_TURN_STANDBY_BUTT,
};
struct AudioCard {
@@ -90,6 +102,7 @@ struct AudioCard {
struct DListHead components; /* all components for this card */
struct DListHead paths; /* all paths for this card */
struct DListHead sapmDirty; /* all dirty for this card */
+ enum AudioSapmTurnStandbyMode standbyMode;
bool sapmSleepState;
bool sapmStandbyState;
bool sapmMonitorState;
@@ -106,6 +119,23 @@ enum AudioStreamType {
AUDIO_RENDER_STREAM,
};
+struct PcmInfo {
+ enum AudioStreamType streamType;
+ /* The number of channels in a frame */
+ uint32_t channels;
+ /* The number of frames per second */
+ uint32_t rate;
+ uint32_t bitWidth;
+ uint32_t frameSize;
+ bool isBigEndian;
+ bool isSignedData;
+ uint32_t startThreshold;
+ uint32_t stopThreshold;
+ uint32_t silenceThreshold;
+ uint32_t totalStreamSize;
+ uint32_t interleaved;
+};
+
struct AudioPcmHwParams {
/* The stream type in a frame */
enum AudioStreamType streamType;
@@ -148,16 +178,7 @@ struct AudioRxData {
unsigned long frames; /* frames number */
};
-struct AudioTxMmapData {
- void *memoryAddress; /**< Pointer to the mmap buffer */
- int32_t memoryFd; /**< File descriptor of the mmap buffer */
- int32_t totalBufferFrames; /**< Total size of the mmap buffer (unit: frame )*/
- int32_t transferFrameSize; /**< Transfer size (unit: frame) */
- int32_t isShareable; /**< Whether the mmap buffer can be shared among processes */
- uint32_t offset;
-};
-
-struct AudioRxMmapData {
+struct AudioMmapData {
void *memoryAddress; /**< Pointer to the mmap buffer */
int32_t memoryFd; /**< File descriptor of the mmap buffer */
int32_t totalBufferFrames; /**< Total size of the mmap buffer (unit: frame )*/
@@ -184,16 +205,6 @@ struct AudioRuntimeDeivces {
struct AudioHost *AudioHostCreateAndBind(struct HdfDeviceObject *device);
-static inline struct HdfDeviceObject *AudioHostToDevice(struct AudioHost *host)
-{
- return (host == NULL) ? NULL : host->device;
-}
-
-static inline struct AudioHost *AudioHostFromDevice(struct HdfDeviceObject *device)
-{
- return (device == NULL) ? NULL : (struct AudioHost *)device->service;
-}
-
/* Get a sound card instance */
struct AudioCard *GetCardInstance(const char *serviceName);
diff --git a/model/audio/core/include/audio_parse.h b/model/audio/core/include/audio_parse.h
index 9ded34ee9e85c0ed6ebd22d760a2f9c27a9e6a9a..e66b3b7e52536da27bd72820ffe0df7a22a38bd8 100755
--- a/model/audio/core/include/audio_parse.h
+++ b/model/audio/core/include/audio_parse.h
@@ -10,6 +10,7 @@
#define AUDIO_PARSE_H
#include "audio_host.h"
+#include "audio_control.h"
#ifdef __cplusplus
#if __cplusplus
@@ -17,8 +18,87 @@ extern "C" {
#endif
#endif /* __cplusplus */
+#define AUDIO_CONFIG_MAX_ITEM 100
+#define AUDIO_CTRL_LIST_MAX 10
+#define AUDIO_SAPM_COMP_NAME_LIST_MAX 9
+#define AUDIO_SAPM_CFG_NAME_LIST_MAX 4
+
+static const char *g_audioControlsList[AUDIO_CTRL_LIST_MAX] = {
+ "Main Playback Volume", "Main Capture Volume",
+ "Playback Mute", "Capture Mute", "Mic Left Gain",
+ "Mic Right Gain", "External Codec Enable",
+ "Internally Codec Enable", "Render Channel Mode", "Captrue Channel Mode"
+};
+
+static char *g_audioSapmCompNameList[AUDIO_SAPM_COMP_NAME_LIST_MAX] = {
+ "ADCL", "ADCR", "DACL", "DACR", "LPGA", "RPGA", "SPKL", "SPKR", "MIC"
+};
+
+static char *g_audioSapmCfgNameList[AUDIO_SAPM_CFG_NAME_LIST_MAX] = {
+ "LPGA MIC Switch", "RPGA MIC Switch", "Dacl enable", "Dacr enable"
+};
+
+enum AudioRegOpsType {
+ AUDIO_RSET_GROUP = 0,
+ AUDIO_INIT_GROUP,
+ AUDIO_CTRL_PATAM_GROUP,
+ AUDIO_CTRL_SAPM_PATAM_GROUP,
+ AUDIO_DAI_STARTUP_PATAM_GROUP,
+ AUDIO_DAI_PATAM_GROUP,
+ AUDIO_DAI_TRIGGER_GROUP,
+ AUDIO_CTRL_CFG_GROUP,
+ AUDIO_SAPM_COMP_GROUP,
+ AUDIO_SAPM_CFG_GROUP,
+ AUDIO_GROUP_MAX
+};
+
+struct AudioIdInfo {
+ const char *chipName;
+ uint32_t chipIdRegister;
+ uint32_t chipIdSize;
+};
+
+struct AudioControlConfig {
+ uint8_t arrayIndex;
+ uint8_t iface;
+ uint8_t enable;
+};
+
+struct AudioAddrConfig {
+ uint32_t addr;
+ uint32_t value;
+};
+
+struct AudioSapmCtrlConfig {
+ uint8_t sapmType;
+ uint8_t compNameIndex;
+ uint8_t reg;
+ uint8_t mask;
+ uint8_t shift;
+ uint8_t invert;
+ uint8_t kcontrolNews;
+ uint8_t kcontrolsNum;
+};
+
+
+struct AudioRegCfgGroupNode {
+ uint8_t itemNum;
+ enum AudioRegOpsType groupIndex;
+ struct AudioAddrConfig *addrCfgItem;
+ struct AudioMixerControl *regCfgItem;
+ struct AudioControlConfig *ctrlCfgItem;
+ struct AudioSapmCtrlConfig *sapmCompItem;
+};
+
+struct AudioRegCfgData {
+ struct AudioIdInfo audioIdInfo;
+ struct AudioRegCfgGroupNode *audioRegParams[AUDIO_GROUP_MAX];
+};
+
int32_t AudioFillConfigData(const struct HdfDeviceObject *device, struct AudioConfigData *configData);
+int32_t CodecGetRegConfig(const struct HdfDeviceObject *device, struct AudioRegCfgData *configData);
+
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/model/audio/core/src/audio_core.c b/model/audio/core/src/audio_core.c
index fb3581ed4ec55c6215e50a6c6763301d69f25085..8115d86892fe99adb6c685d894f0269fa197a7bc 100755
--- a/model/audio/core/src/audio_core.c
+++ b/model/audio/core/src/audio_core.c
@@ -7,45 +7,69 @@
*/
#include "audio_core.h"
+#include "audio_driver_log.h"
+#include "osal_io.h"
#define HDF_LOG_TAG audio_core
+#define CHANNEL_MAX_NUM 2
+#define CHANNEL_MIN_NUM 1
+#define AUDIO_DAI_LINK_COMPLETE 1
+#define AUDIO_DAI_LINK_UNCOMPLETE 0
+
AUDIO_LIST_HEAD(daiController);
AUDIO_LIST_HEAD(platformController);
AUDIO_LIST_HEAD(codecController);
AUDIO_LIST_HEAD(dspController);
AUDIO_LIST_HEAD(accessoryController);
-int32_t AudioSocRegisterPlatform(struct HdfDeviceObject *device, struct PlatformData *data)
+int32_t AudioDeviceReadReg(unsigned long virtualAddress, uint32_t reg, uint32_t *val)
{
- struct PlatformDevice *platform = NULL;
+ if (val == NULL) {
+ AUDIO_DRIVER_LOG_ERR("param val is null.");
+ return HDF_FAILURE;
+ }
+
+ *val = OSAL_READL((void *)((uintptr_t)(virtualAddress + reg)));
+ return HDF_SUCCESS;
+}
- if ((device == NULL) || (data == NULL)) {
- ADM_LOG_ERR("Input params check error: device=%p, data=%p.", device, data);
+int32_t AudioDeviceWriteReg(unsigned long virtualAddress, uint32_t reg, uint32_t value)
+{
+ OSAL_WRITEL(value, (void *)((uintptr_t)(virtualAddress + reg)));
+ return HDF_SUCCESS;
+}
+
+int32_t AudioSocRegisterPlatform(struct HdfDeviceObject *device, struct PlatformData *platformData)
+{
+ struct PlatformDevice *platformDevice = NULL;
+
+ if ((device == NULL) || (platformData == NULL)) {
+ ADM_LOG_ERR("Input params check error: device=%p, platformData=%p.", device, platformData);
return HDF_ERR_INVALID_OBJECT;
}
- platform = (struct PlatformDevice *)OsalMemCalloc(sizeof(*platform));
- if (platform == NULL) {
- ADM_LOG_ERR("Malloc platform device fail!");
+ platformDevice = (struct PlatformDevice *)OsalMemCalloc(sizeof(*platformDevice));
+ if (platformDevice == NULL) {
+ ADM_LOG_ERR("Malloc platformDevice device fail!");
return HDF_ERR_MALLOC_FAIL;
}
- platform->devPlatformName = data->drvPlatformName;
- platform->devData = data;
- platform->device = device;
- DListInsertHead(&platform->list, &platformController);
- ADM_LOG_INFO("Register [%s] success.", platform->devPlatformName);
+ platformDevice->devPlatformName = platformData->drvPlatformName;
+ platformDevice->devData = platformData;
+ platformDevice->device = device;
+ DListInsertHead(&platformDevice->list, &platformController);
+ ADM_LOG_INFO("Register [%s] success.", platformDevice->devPlatformName);
return HDF_SUCCESS;
}
-int32_t AudioSocRegisterDai(struct HdfDeviceObject *device, struct DaiData *data)
+int32_t AudioSocRegisterDai(struct HdfDeviceObject *device, struct DaiData *daiData)
{
struct DaiDevice *dai = NULL;
- if ((device == NULL) || (data == NULL)) {
- ADM_LOG_ERR("Input params check error: device=%p, data=%p.", device, data);
+ if ((device == NULL) || (daiData == NULL)) {
+ ADM_LOG_ERR("Input params check error: device=%p, daiData=%p.", device, daiData);
return HDF_ERR_INVALID_OBJECT;
}
@@ -55,8 +79,8 @@ int32_t AudioSocRegisterDai(struct HdfDeviceObject *device, struct DaiData *data
return HDF_ERR_MALLOC_FAIL;
}
- dai->devDaiName = data->drvDaiName;
- dai->devData = data;
+ dai->devDaiName = daiData->drvDaiName;
+ dai->devData = daiData;
dai->device = device;
DListInsertHead(&dai->list, &daiController);
ADM_LOG_INFO("Register [%s] success.", dai->devDaiName);
@@ -64,13 +88,15 @@ int32_t AudioSocRegisterDai(struct HdfDeviceObject *device, struct DaiData *data
return HDF_SUCCESS;
}
-int32_t AudioRegisterAccessory(struct HdfDeviceObject *device, struct AccessoryData *data, struct DaiData *daiData)
+int32_t AudioRegisterAccessory(struct HdfDeviceObject *device,
+ struct AccessoryData *accessoryData, struct DaiData *daiData)
{
struct AccessoryDevice *accessory = NULL;
int32_t ret;
- if (device == NULL || data == NULL || daiData == NULL) {
- ADM_LOG_ERR("Input params check error: device=%p, data=%p, daiData=%p.", device, data, daiData);
+ if (device == NULL || accessoryData == NULL || daiData == NULL) {
+ ADM_LOG_ERR("Input params check error: device=%p, accessoryData=%p, daiData=%p.",
+ device, accessoryData, daiData);
return HDF_ERR_INVALID_OBJECT;
}
@@ -81,11 +107,11 @@ int32_t AudioRegisterAccessory(struct HdfDeviceObject *device, struct AccessoryD
}
OsalMutexInit(&accessory->mutex);
- accessory->devAccessoryName = data->drvAccessoryName;
- accessory->devData = data;
+ accessory->devAccessoryName = accessoryData->drvAccessoryName;
+ accessory->devData = accessoryData;
accessory->device = device;
- ret = AudioSocDeviceRegister(device, (void *)daiData, AUDIO_DAI_DEVICE);
+ ret = AudioSocRegisterDai(device, daiData);
if (ret != HDF_SUCCESS) {
OsalMemFree(accessory);
ADM_LOG_ERR("Register accessory device fail ret=%d", ret);
@@ -119,8 +145,9 @@ int32_t AudioRegisterCodec(struct HdfDeviceObject *device, struct CodecData *cod
codec->devData = codecData;
codec->device = device;
- ret = AudioSocDeviceRegister(device, (void *)daiData, AUDIO_DAI_DEVICE);
+ ret = AudioSocRegisterDai(device, daiData);
if (ret != HDF_SUCCESS) {
+ OsalIoUnmap((void *)((uintptr_t)(codec->devData->virtualAddress)));
OsalMemFree(codec);
ADM_LOG_ERR("Register dai device fail ret=%d", ret);
return HDF_ERR_IO;
@@ -152,7 +179,7 @@ int32_t AudioRegisterDsp(struct HdfDeviceObject *device, struct DspData *dspData
dspDev->devData = dspData;
dspDev->device = device;
- ret = AudioSocDeviceRegister(device, (void *)DaiData, AUDIO_DAI_DEVICE);
+ ret = AudioSocRegisterDai(device, DaiData);
if (ret != HDF_SUCCESS) {
OsalMemFree(dspDev);
ADM_LOG_ERR("Register dai device fail ret=%d", ret);
@@ -164,47 +191,7 @@ int32_t AudioRegisterDsp(struct HdfDeviceObject *device, struct DspData *dspData
return HDF_SUCCESS;
}
-int32_t AudioSocDeviceRegister(struct HdfDeviceObject *device, void *data, enum AudioDeviceType deviceType)
-{
- struct PlatformData *platformData = NULL;
- struct DaiData *daiData = NULL;
- int32_t ret;
-
- if ((device == NULL) || (data == NULL) || (deviceType >= AUDIO_DEVICE_BUTT) || (deviceType < 0)) {
- ADM_LOG_ERR("Input params check error: device=%p, data=%p, deviceType=%d.",
- device, data, deviceType);
- return HDF_ERR_INVALID_OBJECT;
- }
-
- switch (deviceType) {
- case AUDIO_DAI_DEVICE: {
- daiData = (struct DaiData *)data;
- ret = AudioSocRegisterDai(device, daiData);
- if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("Register dai device fail ret=%d", ret);
- return HDF_FAILURE;
- }
- break;
- }
- case AUDIO_PLATFORM_DEVICE: {
- platformData = (struct PlatformData *)data;
- ret = AudioSocRegisterPlatform(device, platformData);
- if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("Register dma device fail ret=%d", ret);
- return HDF_FAILURE;
- }
- break;
- }
- default: {
- ADM_LOG_ERR("Invalid device type.");
- return HDF_FAILURE;
- }
- }
-
- return HDF_SUCCESS;
-}
-
-int32_t AudioSeekPlatformDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData)
+static int32_t AudioSeekPlatformDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData)
{
struct PlatformDevice *platform = NULL;
if (rtd == NULL || configData == NULL) {
@@ -217,7 +204,7 @@ int32_t AudioSeekPlatformDevice(struct AudioRuntimeDeivces *rtd, const struct Au
}
DLIST_FOR_EACH_ENTRY(platform, &platformController, struct PlatformDevice, list) {
- if (platform != NULL && platform->devPlatformName != NULL &&
+ if (platform->devPlatformName != NULL &&
strcmp(platform->devPlatformName, configData->platformName) == 0) {
rtd->platform = platform;
break;
@@ -227,7 +214,7 @@ int32_t AudioSeekPlatformDevice(struct AudioRuntimeDeivces *rtd, const struct Au
return HDF_SUCCESS;
}
-int32_t AudioSeekCpuDaiDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData)
+static int32_t AudioSeekCpuDaiDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData)
{
struct DaiDevice *cpuDai = NULL;
if (rtd == NULL || configData == NULL) {
@@ -254,7 +241,7 @@ int32_t AudioSeekCpuDaiDevice(struct AudioRuntimeDeivces *rtd, const struct Audi
return HDF_SUCCESS;
}
-int32_t AudioSeekCodecDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData)
+static int32_t AudioSeekCodecDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData)
{
struct CodecDevice *codec = NULL;
struct DaiDevice *codecDai = NULL;
@@ -269,7 +256,7 @@ int32_t AudioSeekCodecDevice(struct AudioRuntimeDeivces *rtd, const struct Audio
}
DLIST_FOR_EACH_ENTRY(codec, &codecController, struct CodecDevice, list) {
- if (codec != NULL && codec->devCodecName != NULL && strcmp(codec->devCodecName, configData->codecName) == 0) {
+ if (codec->devCodecName != NULL && strcmp(codec->devCodecName, configData->codecName) == 0) {
rtd->codec = codec;
DLIST_FOR_EACH_ENTRY(codecDai, &daiController, struct DaiDevice, list) {
if (codecDai != NULL && codecDai->device != NULL && codec->device == codecDai->device &&
@@ -285,7 +272,7 @@ int32_t AudioSeekCodecDevice(struct AudioRuntimeDeivces *rtd, const struct Audio
return HDF_SUCCESS;
}
-int32_t AudioSeekAccessoryDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData)
+static int32_t AudioSeekAccessoryDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData)
{
struct AccessoryDevice *accessory = NULL;
struct DaiDevice *accessoryDai = NULL;
@@ -318,7 +305,7 @@ int32_t AudioSeekAccessoryDevice(struct AudioRuntimeDeivces *rtd, const struct A
return HDF_SUCCESS;
}
-int32_t AudioSeekDspDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData)
+static int32_t AudioSeekDspDevice(struct AudioRuntimeDeivces *rtd, const struct AudioConfigData *configData)
{
struct DspDevice *dsp = NULL;
struct DaiDevice *dspDai = NULL;
@@ -388,7 +375,7 @@ int32_t AudioUpdateCodecRegBits(struct CodecDevice *codec,
const struct AudioMixerControl *mixerControl, uint32_t value)
{
int32_t ret;
- uint32_t curValue;
+ uint32_t curValue = 0;
uint32_t mixerControlMask;
if (codec == NULL || mixerControl == NULL) {
ADM_LOG_ERR("Invalid accessory param.");
@@ -423,7 +410,7 @@ int32_t AudioUpdateAccessoryRegBits(struct AccessoryDevice *accessory,
const struct AudioMixerControl *mixerControl, uint32_t value)
{
int32_t ret;
- uint32_t curValue;
+ uint32_t curValue = 0;
uint32_t mixerControlMask;
if (accessory == NULL || mixerControl == NULL) {
ADM_LOG_ERR("Invalid accessory param.");
@@ -453,78 +440,50 @@ int32_t AudioUpdateAccessoryRegBits(struct AccessoryDevice *accessory,
return HDF_SUCCESS;
}
-int32_t AudioUpdateCodecAiaoRegBits(struct CodecDevice *codec,
- const struct AudioMixerControl *mixerControl, uint32_t value)
+int32_t AudioUpdateDaiRegBits(const struct DaiDevice *dai, const struct AudioMixerControl *mixerControl, uint32_t value)
{
int32_t ret;
- uint32_t curValue;
+ uint32_t curValue = 0;
uint32_t mixerControlMask;
- ADM_LOG_DEBUG("Entry to update AIAO codec reg bits.");
+ struct DaiData *data = NULL;
- if (codec == NULL || mixerControl == NULL) {
- ADM_LOG_ERR("Invalid AIAO codec param.");
+ if (dai == NULL || dai->devData == NULL || mixerControl == NULL) {
+ ADM_LOG_ERR("Invalid accessory param.");
return HDF_ERR_INVALID_OBJECT;
}
+ data = dai->devData;
- value = value << mixerControl->shift;
- mixerControlMask = mixerControl->mask << mixerControl->shift;
-
- OsalMutexLock(&codec->mutex);
- ret = AudioCodecAiaoReadReg(codec, mixerControl->reg, &curValue);
- if (ret != HDF_SUCCESS) {
- OsalMutexUnlock(&codec->mutex);
- ADM_LOG_ERR("Read AIAO codec reg fail ret=%d.", ret);
+ if (value > mixerControl->max || value < mixerControl->min) {
+ ADM_LOG_ERR("value is invalued=%d.", value);
return HDF_FAILURE;
}
- curValue = (curValue & ~mixerControlMask) | (value & mixerControlMask);
- ret = AudioCodecAiaoWriteReg(codec, mixerControl->reg, curValue);
- if (ret != HDF_SUCCESS) {
- OsalMutexUnlock(&codec->mutex);
- ADM_LOG_ERR("Write AIAO codec reg fail ret=%d", ret);
- return HDF_FAILURE;
- }
- OsalMutexUnlock(&codec->mutex);
-
- ADM_LOG_DEBUG("Update AIAO codec reg bits successful.");
- return HDF_SUCCESS;
-}
-
-int32_t AudioUpdateAccessoryAiaoRegBits(struct AccessoryDevice *accessory,
- const struct AudioMixerControl *mixerControl, uint32_t value)
-{
- int32_t ret;
- uint32_t curValue;
- uint32_t mixerControlMask;
- ADM_LOG_DEBUG("Entry to update AIAO accessory reg bits.");
-
- if (accessory == NULL || mixerControl == NULL) {
- ADM_LOG_ERR("Invalid AIAO accessory param.");
- return HDF_ERR_INVALID_OBJECT;
- }
-
value = value << mixerControl->shift;
mixerControlMask = mixerControl->mask << mixerControl->shift;
- OsalMutexLock(&accessory->mutex);
- ret = AudioAccessoryAiaoReadReg(accessory, mixerControl->reg, &curValue);
+ OsalMutexLock(&data->mutex);
+ ret = AudioDaiReadReg(dai, mixerControl->reg, &curValue);
if (ret != HDF_SUCCESS) {
- OsalMutexUnlock(&accessory->mutex);
- ADM_LOG_ERR("Read AIAO accessory reg fail ret=%d.", ret);
+ OsalMutexUnlock(&data->mutex);
+ ADM_LOG_ERR("Read reg fail ret=%d.", ret);
return HDF_FAILURE;
}
+
curValue = (curValue & ~mixerControlMask) | (value & mixerControlMask);
- ret = AudioAccessoryAiaoWriteReg(accessory, mixerControl->reg, curValue);
+
+ ADM_LOG_DEBUG("reg: 0x%x curValue: 0x%x.", mixerControl->reg, curValue);
+ ret = AudioDaiWriteReg(dai, mixerControl->reg, curValue);
if (ret != HDF_SUCCESS) {
- OsalMutexUnlock(&accessory->mutex);
- ADM_LOG_ERR("Write AIAO accessory reg fail ret=%d", ret);
+ OsalMutexUnlock(&data->mutex);
+ ADM_LOG_ERR("Write reg fail ret=%d", ret);
return HDF_FAILURE;
}
- OsalMutexUnlock(&accessory->mutex);
+ OsalMutexUnlock(&data->mutex);
- ADM_LOG_DEBUG("Update AIAO accessory reg bits successful.");
+ ADM_LOG_DEBUG("Success.");
return HDF_SUCCESS;
}
+
struct CodecDevice *AudioKcontrolGetCodec(const struct AudioKcontrol *kcontrol)
{
struct AudioCard *audioCard = NULL;
@@ -559,6 +518,23 @@ struct AccessoryDevice *AudioKcontrolGetAccessory(const struct AudioKcontrol *kc
return audioCard->rtd->accessory;
}
+struct DaiDevice *AudioKcontrolGetCpuDai(const struct AudioKcontrol *kcontrol)
+{
+ struct AudioCard *audioCard = NULL;
+ if (kcontrol == NULL || kcontrol->pri == NULL) {
+ ADM_LOG_ERR("Input param kcontrol is NULL.");
+ return NULL;
+ }
+
+ audioCard = (struct AudioCard *)((volatile uintptr_t)(kcontrol->pri));
+ if (audioCard == NULL || audioCard->rtd == NULL) {
+ ADM_LOG_ERR("Get codec or rtd fail.");
+ return NULL;
+ }
+
+ return audioCard->rtd->cpuDai;
+}
+
struct AudioKcontrol *AudioAddControl(const struct AudioCard *audioCard, const struct AudioKcontrol *ctrl)
{
struct AudioKcontrol *control = NULL;
@@ -608,61 +584,67 @@ int32_t AudioAddControls(struct AudioCard *audioCard, const struct AudioKcontrol
return HDF_SUCCESS;
}
-int32_t AudioCodecReadReg(const struct CodecDevice *codec, uint32_t reg, uint32_t *val)
+int32_t AudioDaiReadReg(const struct DaiDevice *dai, uint32_t reg, uint32_t *val)
{
int32_t ret;
- if (codec == NULL || codec->devData == NULL || codec->devData->Read == NULL || val == NULL) {
- ADM_LOG_ERR("Input param codec is NULL.");
+ unsigned long virtualAddress;
+ if (dai == NULL || dai->devData == NULL || dai->devData->Read == NULL || val == NULL) {
+ ADM_LOG_ERR("Input param is NULL.");
return HDF_FAILURE;
}
- ret = codec->devData->Read(codec, reg, val);
+ virtualAddress = dai->devData->regVirtualAddr;
+ ret = dai->devData->Read(virtualAddress, reg, val);
if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("Codec device read fail.");
+ ADM_LOG_ERR("dai device read fail.");
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
-int32_t AudioAccessoryReadReg(const struct AccessoryDevice *accessory, uint32_t reg, uint32_t *val)
+int32_t AudioDaiWriteReg(const struct DaiDevice *dai, uint32_t reg, uint32_t val)
{
int32_t ret;
- if (accessory == NULL || accessory->devData == NULL || accessory->devData->Read == NULL || val == NULL) {
- ADM_LOG_ERR("Input param accessory is NULL.");
+ unsigned long virtualAddress;
+ if (dai == NULL || dai->devData == NULL || dai->devData->Write == NULL) {
+ ADM_LOG_ERR("Input param codec is NULL.");
return HDF_FAILURE;
}
- ret = accessory->devData->Read(accessory, reg, val);
+ virtualAddress = dai->devData->regVirtualAddr;
+ ret = dai->devData->Write(virtualAddress, reg, val);
if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("Accessory device read fail.");
+ ADM_LOG_ERR("dai device write fail.");
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
-int32_t AudioCodecAiaoReadReg(const struct CodecDevice *codec, uint32_t reg, uint32_t *val)
+int32_t AudioCodecReadReg(const struct CodecDevice *codec, uint32_t reg, uint32_t *val)
{
int32_t ret;
- if (codec == NULL || codec->devData == NULL || codec->devData->AiaoRead == NULL || val == NULL) {
+ unsigned long virtualAddress;
+ if (codec == NULL || codec->devData == NULL || codec->devData->Read == NULL || val == NULL) {
ADM_LOG_ERR("Input param codec is NULL.");
return HDF_FAILURE;
}
- ret = codec->devData->AiaoRead(codec, reg, val);
+ virtualAddress = codec->devData->virtualAddress;
+ ret = codec->devData->Read(virtualAddress, reg, val);
if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("Device read fail.");
+ ADM_LOG_ERR("Codec device read fail.");
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
-int32_t AudioAccessoryAiaoReadReg(const struct AccessoryDevice *accessory, uint32_t reg, uint32_t *val)
+int32_t AudioAccessoryReadReg(const struct AccessoryDevice *accessory, uint32_t reg, uint32_t *val)
{
int32_t ret;
- if (accessory == NULL || accessory->devData == NULL || accessory->devData->AiaoRead == NULL || val == NULL) {
+ if (accessory == NULL || accessory->devData == NULL || accessory->devData->Read == NULL || val == NULL) {
ADM_LOG_ERR("Input param accessory is NULL.");
return HDF_FAILURE;
}
- ret = accessory->devData->AiaoRead(accessory, reg, val);
+ ret = accessory->devData->Read(accessory, reg, val);
if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("Device read fail.");
+ ADM_LOG_ERR("Accessory device read fail.");
return HDF_FAILURE;
}
return HDF_SUCCESS;
@@ -671,11 +653,13 @@ int32_t AudioAccessoryAiaoReadReg(const struct AccessoryDevice *accessory, uint3
int32_t AudioCodecWriteReg(const struct CodecDevice *codec, uint32_t reg, uint32_t val)
{
int32_t ret;
+ unsigned long virtualAddress;
if (codec == NULL || codec->devData == NULL || codec->devData->Write == NULL) {
ADM_LOG_ERR("Input param codec is NULL.");
return HDF_FAILURE;
}
- ret = codec->devData->Write(codec, reg, val);
+ virtualAddress = codec->devData->virtualAddress;
+ ret = codec->devData->Write(virtualAddress, reg, val);
if (ret != HDF_SUCCESS) {
ADM_LOG_ERR("Codec device write fail.");
return HDF_FAILURE;
@@ -698,36 +682,6 @@ int32_t AudioAccessoryWriteReg(const struct AccessoryDevice *accessory, uint32_t
return HDF_SUCCESS;
}
-int32_t AudioCodecAiaoWriteReg(struct CodecDevice *codec, uint32_t reg, uint32_t val)
-{
- int32_t ret;
- if (codec == NULL || codec->devData == NULL || codec->devData->AiaoWrite == NULL) {
- ADM_LOG_ERR("Input param codec aiao is NULL.");
- return HDF_FAILURE;
- }
- ret = codec->devData->AiaoWrite(codec, reg, val);
- if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("Codec aiao device write fail.");
- return HDF_FAILURE;
- }
- return HDF_SUCCESS;
-}
-
-int32_t AudioAccessoryAiaoWriteReg(const struct AccessoryDevice *accessory, uint32_t reg, uint32_t val)
-{
- int32_t ret;
- if (accessory == NULL || accessory->devData == NULL || accessory->devData->AiaoWrite == NULL) {
- ADM_LOG_ERR("Input param accessory aiao is NULL.");
- return HDF_FAILURE;
- }
- ret = accessory->devData->AiaoWrite(accessory, reg, val);
- if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("Accessory aiao device write fail.");
- return HDF_FAILURE;
- }
- return HDF_SUCCESS;
-}
-
int32_t AudioInfoCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemInfo *elemInfo)
{
struct AudioMixerControl *mixerCtrl = NULL;
@@ -750,7 +704,7 @@ int32_t AudioInfoCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlE
return HDF_SUCCESS;
}
-static int32_t AudioGetCtrlOpsRReg(struct AudioCtrlElemValue *elemValue,
+int32_t AudioGetCtrlOpsRReg(struct AudioCtrlElemValue *elemValue,
const struct AudioMixerControl *mixerCtrl, uint32_t rcurValue)
{
if (elemValue == NULL || mixerCtrl == NULL) {
@@ -777,7 +731,7 @@ static int32_t AudioGetCtrlOpsRReg(struct AudioCtrlElemValue *elemValue,
return HDF_SUCCESS;
}
-static int32_t AudioGetCtrlOpsReg(struct AudioCtrlElemValue *elemValue,
+int32_t AudioGetCtrlOpsReg(struct AudioCtrlElemValue *elemValue,
const struct AudioMixerControl *mixerCtrl, uint32_t curValue)
{
if (elemValue == NULL || mixerCtrl == NULL) {
@@ -800,8 +754,8 @@ static int32_t AudioGetCtrlOpsReg(struct AudioCtrlElemValue *elemValue,
int32_t AudioCodecGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue)
{
- uint32_t curValue;
- uint32_t rcurValue;
+ uint32_t curValue = 0;
+ uint32_t rcurValue = 0;
struct AudioMixerControl *mixerCtrl = NULL;
struct CodecDevice *codec = NULL;
if (kcontrol == NULL || kcontrol->privateValue <= 0 || elemValue == NULL) {
@@ -830,8 +784,8 @@ int32_t AudioCodecGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioC
int32_t AudioAccessoryGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue)
{
- uint32_t curValue;
- uint32_t rcurValue;
+ uint32_t curValue = 0;
+ uint32_t rcurValue = 0;
struct AudioMixerControl *mixerCtrl = NULL;
struct AccessoryDevice *accessory = NULL;
if (kcontrol == NULL || kcontrol->privateValue <= 0 || elemValue == NULL) {
@@ -859,71 +813,7 @@ int32_t AudioAccessoryGetCtrlOps(const struct AudioKcontrol *kcontrol, struct Au
return HDF_SUCCESS;
}
-int32_t AudioCodecAiaoGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue)
-{
- uint32_t curValue;
- uint32_t rcurValue;
- struct CodecDevice *codec = NULL;
- struct AudioMixerControl *mixerCtrl = NULL;
- if (kcontrol == NULL || kcontrol->privateValue <= 0 || elemValue == NULL) {
- ADM_LOG_ERR("CODECAIAO input param is NULL.");
- return HDF_ERR_INVALID_OBJECT;
- }
-
- codec = AudioKcontrolGetCodec(kcontrol);
- mixerCtrl = (struct AudioMixerControl *)((volatile uintptr_t)kcontrol->privateValue);
- if (mixerCtrl == NULL || codec == NULL) {
- ADM_LOG_ERR("mixerCtrl and codec is NULL.");
- return HDF_FAILURE;
- }
- if (AudioCodecAiaoReadReg(codec, mixerCtrl->reg, &curValue) != HDF_SUCCESS ||
- AudioCodecAiaoReadReg(codec, mixerCtrl->rreg, &rcurValue) != HDF_SUCCESS) {
- ADM_LOG_ERR("Read Reg fail.");
- return HDF_FAILURE;
- }
- if (AudioGetCtrlOpsReg(elemValue, mixerCtrl, curValue) != HDF_SUCCESS ||
- AudioGetCtrlOpsRReg(elemValue, mixerCtrl, rcurValue) != HDF_SUCCESS) {
- ADM_LOG_ERR("Audio CODECAIAO get kcontrol reg and rreg fail.");
- return HDF_FAILURE;
- }
-
- ADM_LOG_DEBUG("Get CODECAIAO ctrl switch successful.");
- return HDF_SUCCESS;
-}
-
-int32_t AudioAccessoryAiaoGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue)
-{
- uint32_t curValue;
- uint32_t rcurValue;
- struct AccessoryDevice *accessory = NULL;
- struct AudioMixerControl *mixerCtrl = NULL;
- if (kcontrol == NULL || kcontrol->privateValue <= 0 || elemValue == NULL) {
- ADM_LOG_ERR("ACCESSORYCAIAO input param is NULL.");
- return HDF_ERR_INVALID_OBJECT;
- }
-
- accessory = AudioKcontrolGetAccessory(kcontrol);
- mixerCtrl = (struct AudioMixerControl *)((volatile uintptr_t)kcontrol->privateValue);
- if (mixerCtrl == NULL || accessory == NULL) {
- ADM_LOG_ERR("mixerCtrl and accessory is NULL.");
- return HDF_FAILURE;
- }
- if (AudioAccessoryAiaoReadReg(accessory, mixerCtrl->reg, &curValue) != HDF_SUCCESS ||
- AudioAccessoryAiaoReadReg(accessory, mixerCtrl->rreg, &rcurValue) != HDF_SUCCESS) {
- ADM_LOG_ERR("Read Reg fail.");
- return HDF_FAILURE;
- }
- if (AudioGetCtrlOpsReg(elemValue, mixerCtrl, curValue) != HDF_SUCCESS ||
- AudioGetCtrlOpsRReg(elemValue, mixerCtrl, rcurValue) != HDF_SUCCESS) {
- ADM_LOG_ERR("Audio ACCESSORYCAIAO get kcontrol reg and rreg fail.");
- return HDF_FAILURE;
- }
-
- ADM_LOG_DEBUG("Get ACCESSORYCAIAO ctrl switch successful.");
- return HDF_SUCCESS;
-}
-
-static int32_t AudioSetCtrlOpsReg(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue,
+int32_t AudioSetCtrlOpsReg(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue,
const struct AudioMixerControl *mixerCtrl, uint32_t *value)
{
if (kcontrol == NULL || (kcontrol->privateValue <= 0) || elemValue == NULL ||
@@ -944,7 +834,7 @@ static int32_t AudioSetCtrlOpsReg(const struct AudioKcontrol *kcontrol, const st
return HDF_SUCCESS;
}
-static int32_t AudioSetCtrlOpsRReg(const struct AudioCtrlElemValue *elemValue,
+int32_t AudioSetCtrlOpsRReg(const struct AudioCtrlElemValue *elemValue,
struct AudioMixerControl *mixerCtrl, uint32_t *rvalue, bool *updateRReg)
{
uint32_t rshift;
@@ -1054,79 +944,74 @@ int32_t AudioAccessorySetCtrlOps(const struct AudioKcontrol *kcontrol, const str
return HDF_SUCCESS;
}
-int32_t AudioCodecAiaoSetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue)
+int32_t AudioCpuDaiSetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue)
{
uint32_t value;
uint32_t rvalue;
bool updateRReg = false;
- struct CodecDevice *codec = NULL;
+ struct DaiDevice *dai = NULL;
struct AudioMixerControl *mixerCtrl = NULL;
if (kcontrol == NULL || (kcontrol->privateValue <= 0) || elemValue == NULL) {
- ADM_LOG_ERR("Audio codec aiao input param is NULL.");
+ ADM_LOG_ERR("Audio input param is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
mixerCtrl = (struct AudioMixerControl *)((volatile uintptr_t)kcontrol->privateValue);
if (AudioSetCtrlOpsReg(kcontrol, elemValue, mixerCtrl, &value) != HDF_SUCCESS) {
- ADM_LOG_ERR("AudioSetCtrlOpsReg fail.");
- return HDF_FAILURE;
+ ADM_LOG_ERR("AudioSetCtrlOpsReg is fail.");
+ return HDF_ERR_INVALID_OBJECT;
}
-
- codec = AudioKcontrolGetCodec(kcontrol);
- if (AudioUpdateCodecAiaoRegBits(codec, mixerCtrl, value) != HDF_SUCCESS) {
- ADM_LOG_ERR("Audio codec aiao stereo update reg bits fail.");
+ dai = AudioKcontrolGetCpuDai(kcontrol);
+ if (dai == NULL) {
+ ADM_LOG_ERR("AudioKcontrolGetCodec is fail.");
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ if (AudioUpdateDaiRegBits(dai, mixerCtrl, value) != HDF_SUCCESS) {
+ ADM_LOG_ERR("Audio codec stereo update reg bits fail.");
return HDF_FAILURE;
}
if (AudioSetCtrlOpsRReg(elemValue, mixerCtrl, &rvalue, &updateRReg) != HDF_SUCCESS) {
- ADM_LOG_ERR("AudioSetCtrlOpsRReg fail.");
- return HDF_FAILURE;
+ ADM_LOG_ERR("AudioSetCtrlOpsRReg is fail.");
+ return HDF_ERR_INVALID_OBJECT;
}
+
if (updateRReg) {
- if (AudioUpdateCodecAiaoRegBits(codec, mixerCtrl, rvalue) != HDF_SUCCESS) {
- ADM_LOG_ERR("Audio codec aiao stereo update reg bits fail.");
+ if (AudioUpdateDaiRegBits(dai, mixerCtrl, rvalue) != HDF_SUCCESS) {
+ ADM_LOG_ERR("Audio codec stereo update reg bits fail.");
return HDF_FAILURE;
}
}
-
return HDF_SUCCESS;
}
-int32_t AudioAccessoryAiaoSetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue)
+int32_t AudioCpuDaiGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue)
{
- uint32_t value;
- uint32_t rvalue;
- bool updateRReg = false;
- struct AccessoryDevice *accessory = NULL;
+ uint32_t curValue = 0;
+ uint32_t rcurValue = 0;
struct AudioMixerControl *mixerCtrl = NULL;
- if (kcontrol == NULL || (kcontrol->privateValue <= 0) || elemValue == NULL) {
- ADM_LOG_ERR("Audio accessory aiao input param is NULL.");
+ struct DaiDevice *dai = NULL;
+ if (kcontrol == NULL || kcontrol->privateValue <= 0 || elemValue == NULL) {
+ ADM_LOG_ERR("Audio input param is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
-
mixerCtrl = (struct AudioMixerControl *)((volatile uintptr_t)kcontrol->privateValue);
- if (AudioSetCtrlOpsReg(kcontrol, elemValue, mixerCtrl, &value) != HDF_SUCCESS) {
- ADM_LOG_ERR("AudioSetCtrlOpsReg fail.");
+ dai = AudioKcontrolGetCpuDai(kcontrol);
+ if (mixerCtrl == NULL || dai == NULL) {
+ ADM_LOG_ERR("mixerCtrl and codec is NULL.");
return HDF_FAILURE;
}
-
- accessory = AudioKcontrolGetAccessory(kcontrol);
- if (AudioUpdateAccessoryAiaoRegBits(accessory, mixerCtrl, value) != HDF_SUCCESS) {
- ADM_LOG_ERR("Audio accessory aiao stereo update reg bits fail.");
+ if (AudioDaiReadReg(dai, mixerCtrl->reg, &curValue) != HDF_SUCCESS ||
+ AudioDaiReadReg(dai, mixerCtrl->rreg, &rcurValue) != HDF_SUCCESS) {
+ ADM_LOG_ERR("Read Reg fail.");
return HDF_FAILURE;
}
-
- if (AudioSetCtrlOpsRReg(elemValue, mixerCtrl, &rvalue, &updateRReg) != HDF_SUCCESS) {
- ADM_LOG_ERR("AudioSetCtrlOpsRReg fail.");
+ if (AudioGetCtrlOpsReg(elemValue, mixerCtrl, curValue) != HDF_SUCCESS ||
+ AudioGetCtrlOpsRReg(elemValue, mixerCtrl, rcurValue) != HDF_SUCCESS) {
+ ADM_LOG_ERR("Audio codec get kcontrol reg and rreg fail.");
return HDF_FAILURE;
}
- if (updateRReg) {
- if (AudioUpdateAccessoryAiaoRegBits(accessory, mixerCtrl, rvalue) != HDF_SUCCESS) {
- ADM_LOG_ERR("Audio accessory aiao stereo update reg bits fail.");
- return HDF_FAILURE;
- }
- }
-
return HDF_SUCCESS;
}
+
diff --git a/model/audio/core/src/audio_host.c b/model/audio/core/src/audio_host.c
index 61c2434c3cbd7a8619258f2004fb3a340371e5ba..7e426e9727e3a88985bdc3a555c69e19cffd1dc6 100755
--- a/model/audio/core/src/audio_host.c
+++ b/model/audio/core/src/audio_host.c
@@ -9,6 +9,8 @@
#include "audio_host.h"
#include "audio_codec_if.h"
#include "audio_core.h"
+#include "audio_sapm.h"
+#include "audio_driver_log.h"
#include "audio_parse.h"
#define HDF_LOG_TAG audio_host
@@ -40,6 +42,7 @@ struct AudioCard *GetCardInstance(const char *serviceName)
return audioCard;
}
}
+ ADM_LOG_ERR("serviceName is %s.", serviceName);
return NULL;
}
@@ -162,7 +165,7 @@ static int32_t AudioDspDevInit(const struct AudioCard *audioCard)
return HDF_SUCCESS;
}
-static int32_t AudioCodecDaiDevInit(const struct AudioCard *audioCard)
+static int32_t AudioCodecDaiDevInit(struct AudioCard *audioCard)
{
struct AudioRuntimeDeivces *rtd = NULL;
struct DaiDevice *codecDai = NULL;
@@ -192,7 +195,7 @@ static int32_t AudioCodecDaiDevInit(const struct AudioCard *audioCard)
return HDF_SUCCESS;
}
-static int32_t AudioAccessoryDaiDevInit(const struct AudioCard *audioCard)
+static int32_t AudioAccessoryDaiDevInit(struct AudioCard *audioCard)
{
struct AudioRuntimeDeivces *rtd = NULL;
struct DaiDevice *accessoryDai = NULL;
@@ -222,7 +225,7 @@ static int32_t AudioAccessoryDaiDevInit(const struct AudioCard *audioCard)
return HDF_SUCCESS;
}
-static int32_t AudioCpuDaiDevInit(const struct AudioCard *audioCard)
+static int32_t AudioCpuDaiDevInit(struct AudioCard *audioCard)
{
struct AudioRuntimeDeivces *rtd = NULL;
struct DaiDevice *cpuDai = NULL;
@@ -252,11 +255,11 @@ static int32_t AudioCpuDaiDevInit(const struct AudioCard *audioCard)
return HDF_SUCCESS;
}
-static int32_t AudioDspDaiDevInit(const struct AudioCard *audioCard)
+static int32_t AudioDspDaiDevInit(struct AudioCard *audioCard)
{
struct AudioRuntimeDeivces *rtd = NULL;
struct DaiDevice *dspDai = NULL;
- int ret;
+ int ret = HDF_SUCCESS;
if (audioCard == NULL) {
ADM_LOG_ERR("audioCard is NULL.");
@@ -293,22 +296,18 @@ static int32_t AudioInitDaiLink(struct AudioCard *audioCard)
if (AudioPlatformDevInit(audioCard) || AudioCpuDaiDevInit(audioCard)) {
ADM_LOG_ERR("Platform and CpuDai init fail.");
- return HDF_ERR_IO;
}
if ((AudioCodecDevInit(audioCard) || AudioCodecDaiDevInit(audioCard))) {
- ADM_LOG_ERR("codec init fail.");
- return HDF_ERR_IO;
+ ADM_LOG_ERR("codec Device init fail.");
}
if (AudioAccessoryDevInit(audioCard) || AudioAccessoryDaiDevInit(audioCard)) {
- ADM_LOG_ERR("Accessory init fail.");
- return HDF_ERR_IO;
+ ADM_LOG_ERR("Accessory Device init fail.");
}
if (AudioDspDevInit(audioCard) || AudioDspDaiDevInit(audioCard)) {
- ADM_LOG_ERR("Dsp Dai init fail.");
- return HDF_ERR_IO;
+ ADM_LOG_ERR("Dsp Device init fail.");
}
ADM_LOG_DEBUG("success.");
@@ -366,7 +365,7 @@ static int32_t AudioDriverInit(struct HdfDeviceObject *device)
ADM_LOG_ERR("device is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
- audioHost = AudioHostFromDevice(device);
+ audioHost = (struct AudioHost *)device->service;
if (audioHost == NULL) {
ADM_LOG_ERR("audioHost is NULL.");
return HDF_FAILURE;
@@ -385,9 +384,15 @@ static int32_t AudioDriverInit(struct HdfDeviceObject *device)
return HDF_ERR_IO;
}
+ audioCard->standbyMode = AUDIO_SAPM_TURN_STANDBY_LATER;
+
/* Bind specific codecã€platform and dai device */
- AudioBindDaiLink(audioCard, &(audioCard->configData));
- if (!audioCard->rtd->complete) {
+ ret = AudioBindDaiLink(audioCard, &(audioCard->configData));
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("AudioBindDaiLink fail ret=%d", ret);
+ return HDF_FAILURE;
+ }
+ if (audioCard->rtd == NULL || (!audioCard->rtd->complete)) {
ADM_LOG_ERR("AudioBindDaiLink fail!");
return HDF_ERR_IO;
}
@@ -415,13 +420,19 @@ static void AudioDriverRelease(struct HdfDeviceObject *device)
{
struct AudioHost *audioHost = NULL;
struct AudioCard *audioCard = NULL;
+ struct DListHead *componentHead = NULL;
+ struct DListHead *controlHead = NULL;
+ struct AudioSapmComponent *componentReq = NULL;
+ struct AudioSapmComponent *componentTmp = NULL;
+ struct AudioKcontrol *ctrlReq = NULL;
+ struct AudioKcontrol *ctrlTmp = NULL;
ADM_LOG_DEBUG("entry.");
if (device == NULL) {
ADM_LOG_ERR("device is NULL.");
return;
}
- audioHost = AudioHostFromDevice(device);
+ audioHost = (struct AudioHost *)device->service;
if (audioHost == NULL) {
ADM_LOG_ERR("audioHost is NULL.");
return;
@@ -429,9 +440,32 @@ static void AudioDriverRelease(struct HdfDeviceObject *device)
if (audioHost->priv != NULL) {
audioCard = (struct AudioCard *)audioHost->priv;
- if (audioCard->rtd != NULL) {
- OsalMemFree(audioCard->rtd);
+
+ componentHead = &audioCard->components;
+ DLIST_FOR_EACH_ENTRY_SAFE(componentReq, componentTmp, componentHead, struct AudioSapmComponent, list) {
+ DListRemove(&componentReq->list);
+ if (componentReq->componentName != NULL) {
+ OsalMemFree(componentReq->componentName);
}
+ OsalMemFree(componentReq);
+ }
+
+ controlHead = &audioCard->controls;
+ DLIST_FOR_EACH_ENTRY_SAFE(ctrlReq, ctrlTmp, controlHead, struct AudioKcontrol, list) {
+ DListRemove(&ctrlReq->list);
+ if (ctrlReq->pri != NULL) {
+ OsalMemFree(ctrlReq->pri);
+ }
+ if (ctrlReq->privateData != NULL) {
+ OsalMemFree(ctrlReq->privateData);
+ }
+ OsalMemFree(ctrlReq);
+ }
+
+ if (audioCard->rtd != NULL) {
+ OsalMemFree(audioCard->rtd);
+ }
+
OsalMemFree(audioHost->priv);
}
OsalMemFree(audioHost);
diff --git a/model/audio/core/src/audio_parse.c b/model/audio/core/src/audio_parse.c
index b483b3c0b3fc1f329fb2caab4ed23212e8f8ce82..245140705351d996bc33714dad3eb77ccc0aa087 100755
--- a/model/audio/core/src/audio_parse.c
+++ b/model/audio/core/src/audio_parse.c
@@ -7,9 +7,62 @@
*/
#include "audio_parse.h"
+#include "audio_driver_log.h"
#define HDF_LOG_TAG audio_parse
+enum AudioRegCfgIndex {
+ AUDIO_REG_CFG_REG_INDEX = 0,
+ AUDIO_REG_CFG_RREG_INDEX,
+ AUDIO_REG_CFG_SHIFT_INDEX,
+ AUDIO_REG_CFG_RSHIFT_INDEX,
+ AUDIO_REG_CFG_MIN_INDEX,
+ AUDIO_REG_CFG_MAX_INDEX,
+ AUDIO_REG_CFG_MASK_INDEX,
+ AUDIO_REG_CFG_INVERT_INDEX,
+ AUDIO_REG_CFG_VALUE_INDEX,
+ AUDIO_REG_CFG_INDEX_MAX
+};
+
+enum AudioAddrCfgIndex {
+ AUDIO_ADDR_CFG_REG_INDEX = 0,
+ AUDIO_ADDR_CFG_VALUE_INDEX,
+ AUDIO_ADDR_CFG_INDEX_MAX
+};
+
+enum AudioCrtlCfgIndex {
+ AUDIO_CTRL_CFG_INDEX_INDEX = 0,
+ AUDIO_CTRL_CFG_IFACE_INDEX,
+ AUDIO_CTRL_CFG_ENABLE_INDEX,
+ AUDIO_CTRL_CFG_INDEX_MAX
+};
+
+enum AudioSapmComponentIndex {
+ AUDIO_SAPM_COMP_INDEX_TYPE = 0,
+ AUDIO_SAPM_COMP_INDEX_NAME,
+ AUDIO_SAPM_COMP_INDEX_REG,
+ AUDIO_SAPM_COMP_INDEX_MASK,
+ AUDIO_SAPM_COMP_INDEX_SHIFT,
+ AUDIO_SAPM_COMP_INDEX_INVERT,
+ AUDIO_SAPM_COMP_INDEX_KCTL,
+ AUDIO_SAPM_COMP_INDEX_KCTLNUM,
+ AUDIO_SAPM_COMP_INDEX_MAX
+};
+
+
+static char *g_audioRegGroupName[AUDIO_GROUP_MAX] = {
+ "resetSeqConfig",
+ "initSeqConfig",
+ "ctrlParamsSeqConfig",
+ "ctrlSapmParamsSeqConfig",
+ "daiStartupSeqConfig",
+ "daiParamsSeqConfig",
+ "daiTriggerSeqConfig",
+ "controlsConfig",
+ "sapmComponent",
+ "sapmConfig"
+};
+
int32_t AudioFillConfigData(const struct HdfDeviceObject *device, struct AudioConfigData *configData)
{
const struct DeviceResourceNode *node = NULL;
@@ -58,3 +111,370 @@ int32_t AudioFillConfigData(const struct HdfDeviceObject *device, struct AudioCo
return HDF_SUCCESS;
}
+
+static uint32_t GetAudioRegGroupNameIndex(const char *name)
+{
+ uint32_t index;
+
+ if (name == NULL) {
+ return AUDIO_GROUP_MAX;
+ }
+
+ for (index = 0; index < AUDIO_GROUP_MAX; ++index) {
+ if ((g_audioRegGroupName[index] != NULL) && (strcmp(name, g_audioRegGroupName[index]) == 0)) {
+ break;
+ }
+ }
+
+ return index;
+}
+
+static uint32_t* GetRegArray(const struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode,
+ struct AudioRegCfgGroupNode* group, uint32_t indexMax)
+{
+ int32_t ret;
+
+ if (group == NULL || parser == NULL || regNode == NULL || indexMax == 0) {
+ ADM_LOG_ERR("Input para check error");
+ return NULL;
+ }
+
+ int32_t index = group->groupIndex;
+ if (index >= AUDIO_GROUP_MAX) {
+ ADM_LOG_ERR("Input indexMax=%d error", index);
+ return NULL;
+ }
+
+ int32_t num = parser->GetElemNum(regNode, g_audioRegGroupName[index]);
+ if (num <= 0 || num > AUDIO_CONFIG_MAX_ITEM) {
+ ADM_LOG_ERR("parser %s element num failed", g_audioRegGroupName[index]);
+ return NULL;
+ }
+
+ group->itemNum = num / indexMax;
+
+ uint32_t *buf = (uint32_t *)OsalMemCalloc(sizeof(uint32_t) * num);
+ if (buf == NULL) {
+ ADM_LOG_ERR("malloc reg array buf failed!");
+ return NULL;
+ }
+
+ ret = parser->GetUint32Array(regNode, g_audioRegGroupName[index], buf, num, 0);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("parser %s reg array failed", g_audioRegGroupName[index]);
+ OsalMemFree(buf);
+ return NULL;
+ }
+ return buf;
+}
+
+static int32_t ParseAudioRegItem(const struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode,
+ struct AudioRegCfgGroupNode* group)
+{
+ int32_t step;
+ int32_t index;
+
+ if (group == NULL || parser == NULL || regNode == NULL) {
+ ADM_LOG_ERR("Input para check error");
+ return HDF_FAILURE;
+ }
+
+ int32_t *buf = GetRegArray(parser, regNode, group, AUDIO_REG_CFG_INDEX_MAX);
+ if (buf == NULL) {
+ ADM_LOG_ERR("malloc reg array buf failed!");
+ return HDF_FAILURE;
+ }
+
+ group->regCfgItem =
+ (struct AudioMixerControl*)OsalMemCalloc(group->itemNum * sizeof(*(group->regCfgItem)));
+ if (group->regCfgItem == NULL) {
+ OsalMemFree(buf);
+ ADM_LOG_ERR("malloc audio reg config item failed!");
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ for (index = 0; index < group->itemNum; ++index) {
+ step = AUDIO_REG_CFG_INDEX_MAX * index;
+
+ group->regCfgItem[index].reg = buf[step + AUDIO_REG_CFG_REG_INDEX];
+ group->regCfgItem[index].rreg = buf[step + AUDIO_REG_CFG_RREG_INDEX];
+ group->regCfgItem[index].shift = buf[step + AUDIO_REG_CFG_SHIFT_INDEX];
+ group->regCfgItem[index].rshift = buf[step + AUDIO_REG_CFG_RSHIFT_INDEX];
+ group->regCfgItem[index].min = buf[step + AUDIO_REG_CFG_MIN_INDEX];
+ group->regCfgItem[index].max = buf[step + AUDIO_REG_CFG_MAX_INDEX];
+ group->regCfgItem[index].mask = buf[step + AUDIO_REG_CFG_MASK_INDEX];
+ group->regCfgItem[index].invert = buf[step + AUDIO_REG_CFG_INVERT_INDEX];
+ group->regCfgItem[index].value = buf[step + AUDIO_REG_CFG_VALUE_INDEX];
+ }
+ OsalMemFree(buf);
+
+ return HDF_SUCCESS;
+}
+
+static int32_t ParseAudioSapmItem(const struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode,
+ struct AudioRegCfgGroupNode* group)
+{
+ int32_t step;
+ int32_t index;
+
+ if (group == NULL || parser == NULL || regNode == NULL) {
+ ADM_LOG_ERR("Input para check error");
+ return HDF_FAILURE;
+ }
+
+ uint32_t *buf = GetRegArray(parser, regNode, group, AUDIO_SAPM_COMP_INDEX_MAX);
+ if (buf == NULL) {
+ ADM_LOG_ERR("malloc reg array buf failed!");
+ return HDF_FAILURE;
+ }
+
+ group->sapmCompItem =
+ (struct AudioSapmCtrlConfig*)OsalMemCalloc(group->itemNum * sizeof(*(group->sapmCompItem)));
+ if (group->sapmCompItem == NULL) {
+ OsalMemFree(buf);
+ ADM_LOG_ERR("malloc audio reg config item failed!");
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ for (index = 0; index < group->itemNum; ++index) {
+ step = AUDIO_SAPM_COMP_INDEX_MAX * index;
+ group->sapmCompItem[index].sapmType = buf[step + AUDIO_SAPM_COMP_INDEX_TYPE];
+ group->sapmCompItem[index].compNameIndex = buf[step + AUDIO_SAPM_COMP_INDEX_NAME];
+ group->sapmCompItem[index].reg = buf[step + AUDIO_SAPM_COMP_INDEX_REG];
+ group->sapmCompItem[index].mask = buf[step + AUDIO_SAPM_COMP_INDEX_MASK];
+ group->sapmCompItem[index].shift = buf[step + AUDIO_SAPM_COMP_INDEX_SHIFT];
+ group->sapmCompItem[index].invert = buf[step + AUDIO_SAPM_COMP_INDEX_INVERT];
+ group->sapmCompItem[index].kcontrolNews = buf[step + AUDIO_SAPM_COMP_INDEX_KCTL];
+ group->sapmCompItem[index].kcontrolsNum = buf[step + AUDIO_SAPM_COMP_INDEX_KCTLNUM];
+ }
+
+ OsalMemFree(buf);
+ return HDF_SUCCESS;
+}
+
+
+static int32_t ParseAudioCtrlItem(const struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode,
+ struct AudioRegCfgGroupNode* group)
+{
+ int32_t step;
+ int32_t index;
+
+ if (parser == NULL || regNode == NULL || group == NULL) {
+ ADM_LOG_ERR("Input para check error");
+ return HDF_FAILURE;
+ }
+
+ uint32_t *buf = GetRegArray(parser, regNode, group, AUDIO_CTRL_CFG_INDEX_MAX);
+ if (buf == NULL) {
+ ADM_LOG_ERR("malloc reg array buf failed!");
+ return HDF_FAILURE;
+ }
+
+ group->ctrlCfgItem =
+ (struct AudioControlConfig*)OsalMemCalloc(group->itemNum * sizeof(*(group->ctrlCfgItem)));
+ if (group->ctrlCfgItem == NULL) {
+ OsalMemFree(buf);
+ ADM_LOG_ERR("malloc audio ctrl config item failed!");
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ for (index = 0; index < group->itemNum; ++index) {
+ step = AUDIO_CTRL_CFG_INDEX_MAX * index;
+
+ group->ctrlCfgItem[index].arrayIndex = buf[step + AUDIO_CTRL_CFG_INDEX_INDEX];
+ group->ctrlCfgItem[index].iface = buf[step + AUDIO_CTRL_CFG_IFACE_INDEX];
+ group->ctrlCfgItem[index].enable = buf[step + AUDIO_CTRL_CFG_ENABLE_INDEX];
+ }
+ OsalMemFree(buf);
+ return HDF_SUCCESS;
+}
+
+static int32_t ParseAudioAddrItem(const struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode,
+ struct AudioRegCfgGroupNode* group)
+{
+ int32_t step;
+ int32_t index;
+
+ if (parser == NULL || regNode == NULL || group == NULL) {
+ ADM_LOG_ERR("Input para check error.");
+ return HDF_FAILURE;
+ }
+
+ uint32_t *buf = GetRegArray(parser, regNode, group, AUDIO_ADDR_CFG_INDEX_MAX);
+ if (buf == NULL) {
+ ADM_LOG_ERR("malloc reg array buf failed!");
+ return HDF_FAILURE;
+ }
+
+ group->addrCfgItem = (struct AudioAddrConfig*)OsalMemCalloc(group->itemNum * sizeof(*(group->addrCfgItem)));
+ if (group->addrCfgItem == NULL) {
+ OsalMemFree(buf);
+ ADM_LOG_ERR("malloc audio addr config item failed!");
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ for (index = 0; index < group->itemNum; ++index) {
+ step = AUDIO_ADDR_CFG_INDEX_MAX * index;
+ group->addrCfgItem[index].addr = buf[step + AUDIO_ADDR_CFG_REG_INDEX];
+ group->addrCfgItem[index].value = buf[step + AUDIO_ADDR_CFG_VALUE_INDEX];
+ }
+ OsalMemFree(buf);
+ return HDF_SUCCESS;
+}
+
+static int32_t ParseAudioRegGroup(const struct DeviceResourceIface *parser,
+ const struct DeviceResourceNode *regCfgNode, struct AudioRegCfgGroupNode **groupNode, uint32_t index)
+{
+ int32_t ret = HDF_FAILURE;
+ struct AudioRegCfgGroupNode *group = NULL;
+
+ if (parser == NULL || regCfgNode == NULL || groupNode == NULL) {
+ ADM_LOG_ERR("Input para check error: parser=%p, regCfgNode=%p, groupNode=%p.",
+ parser, regCfgNode, groupNode);
+ return HDF_FAILURE;
+ }
+
+ group = (struct AudioRegCfgGroupNode*)OsalMemCalloc(sizeof(*group));
+ if (group == NULL) {
+ ADM_LOG_ERR("malloc audio reg config group failed");
+ return HDF_ERR_MALLOC_FAIL;
+ }
+ *groupNode = group;
+ (*groupNode)->groupIndex = index;
+
+ switch (index) {
+ case AUDIO_CTRL_CFG_GROUP:
+ case AUDIO_SAPM_CFG_GROUP:
+ ret = ParseAudioCtrlItem(parser, regCfgNode, group);
+ break;
+ case AUDIO_RSET_GROUP:
+ case AUDIO_INIT_GROUP:
+ ret = ParseAudioAddrItem(parser, regCfgNode, group);
+ break;
+ case AUDIO_DAI_PATAM_GROUP:
+ case AUDIO_DAI_TRIGGER_GROUP:
+ case AUDIO_CTRL_PATAM_GROUP:
+ case AUDIO_CTRL_SAPM_PATAM_GROUP:
+ case AUDIO_DAI_STARTUP_PATAM_GROUP:
+ ret = ParseAudioRegItem(parser, regCfgNode, group);
+ break;
+ case AUDIO_SAPM_COMP_GROUP:
+ ret = ParseAudioSapmItem(parser, regCfgNode, group);
+ break;
+ default:
+ ADM_LOG_ERR("parse audio config index = %d not found!", index);
+ return HDF_FAILURE;
+ }
+
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("parse audio config item failed!");
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+static void ReleaseAudioAllRegConfig(struct AudioRegCfgData *config)
+{
+ int32_t index;
+
+ if (config == NULL) {
+ return;
+ }
+
+ for (index = 0; index < AUDIO_GROUP_MAX; ++index) {
+ if (config->audioRegParams[index] != NULL) {
+ if (config->audioRegParams[index]->regCfgItem != NULL) {
+ OsalMemFree(config->audioRegParams[index]->regCfgItem);
+ config->audioRegParams[index]->regCfgItem = NULL;
+ }
+ OsalMemFree(config->audioRegParams[index]);
+ config->audioRegParams[index] = NULL;
+ }
+ }
+}
+
+static int32_t ParseAudioAttr(const struct DeviceResourceIface *parser, const struct DeviceResourceNode *attrNode,
+ struct AudioIdInfo *config)
+{
+ int32_t ret;
+ ret = parser->GetString(attrNode, "chipName", &config->chipName, NULL);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("parser chipName reg audioIdInfo failed!");
+ return HDF_SUCCESS;
+ }
+
+ ret = parser->GetUint32(attrNode, "chipIdRegister", &config->chipIdRegister, 0);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("parser chipIdRegister reg audioIdInfo failed!");
+ return HDF_SUCCESS;
+ }
+
+ ret = parser->GetUint32(attrNode, "chipIdSize", &config->chipIdSize, 0);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("parser chipIdSize reg audioIdInfo failed!");
+ return HDF_SUCCESS;
+ }
+ return ret;
+}
+
+int32_t CodecGetRegConfig(const struct HdfDeviceObject *device, struct AudioRegCfgData *configData)
+{
+ uint16_t index;
+ const struct DeviceResourceNode *root = NULL;
+ const struct DeviceResourceNode *regCfgNode = NULL;
+ const struct DeviceResourceAttr *regAttr = NULL;
+ const struct DeviceResourceNode *idNode = NULL;
+ struct DeviceResourceIface *drsOps = NULL;
+
+ ADM_LOG_DEBUG("Entry.");
+
+ if (device == NULL || configData == NULL) {
+ ADM_LOG_ERR("Input para check error: device=%p, configData=%p.", device, configData);
+ return HDF_FAILURE;
+ }
+
+ root = device->property;
+ if (root == NULL) {
+ ADM_LOG_ERR("drs node is NULL.");
+ return HDF_FAILURE;
+ }
+
+ drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ if (drsOps == NULL || drsOps->GetString == NULL) {
+ ADM_LOG_ERR("AudioFillConfigData: invalid drs ops fail!");
+ return HDF_FAILURE;
+ }
+
+ idNode = drsOps->GetChildNode(root, "idInfo");
+ if (idNode != NULL) {
+ if (ParseAudioAttr(drsOps, idNode, &configData->audioIdInfo) != HDF_SUCCESS) {
+ ADM_LOG_ERR("audio reg node attr is null");
+ return HDF_FAILURE;
+ }
+ }
+
+ regCfgNode = drsOps->GetChildNode(root, "regConfig");
+ if (regCfgNode == NULL) {
+ ADM_LOG_ERR("CodecGetRegConfig: Read audioRegConfig fail!");
+ return HDF_FAILURE;
+ }
+
+ DEV_RES_NODE_FOR_EACH_ATTR(regCfgNode, regAttr) {
+ if (regAttr == NULL || regAttr->name == NULL) {
+ ADM_LOG_ERR("audio reg node attr is null");
+ return HDF_FAILURE;
+ }
+
+ index = GetAudioRegGroupNameIndex(regAttr->name);
+ if (index >= AUDIO_GROUP_MAX) {
+ continue;
+ }
+
+ if (ParseAudioRegGroup(drsOps, regCfgNode, &configData->audioRegParams[index], index) != HDF_SUCCESS) {
+ ADM_LOG_ERR("parse audio register group failed");
+ ReleaseAudioAllRegConfig(configData);
+ return HDF_FAILURE;
+ }
+ }
+ return HDF_SUCCESS;
+}
diff --git a/model/audio/core/test/unittest/common/audio_common_test.h b/model/audio/core/test/unittest/common/audio_common_test.h
index 74f213f15efc9be3adc311d3a2d6dc6d6d4f48c3..8b88a63ab99255e17eb827098800ce08e236d41f 100755
--- a/model/audio/core/test/unittest/common/audio_common_test.h
+++ b/model/audio/core/test/unittest/common/audio_common_test.h
@@ -14,49 +14,56 @@
const int32_t g_testAudioType = 701; // 701 is TEST_AUDIO_TYPE
enum {
- TESTGETCODEC,
- TESTGETCARDINSTANCE,
- TESTGETCCNFIGDATA,
-
- TESTREGISTERPLATFORM,
- TESTREGISTERDAI,
- TESTREGISTERACCESSORY,
- TESTREGISTERCODEC,
- TESTREGISTERDSP,
- TESTSOCDEVICEREGISTER,
- TESTBINDDAILINK,
- TESTUPDATECODECREGBITS,
- TESTUPDATEACCESSORYREGBITS,
- TESTUPDATECODECAIAOREGBITS,
- TESTUPDATEACCESSORYAIAOREGBITS,
- TESTKCONTROLGETCODEC,
- TESTKCONTROLGETACCESSORY,
- TESTADDCONTROL,
- TESTADDCONTROLS,
- TESTCODECREADREG,
- TESTACCESSORYREADREG,
- TESTCODECAIAOREADREG,
- TESTACCESSORYAIAOREADREG,
- TESTCODECWRITEREG,
- TESTACCESSORYWRITEREG,
- TESTCODECAIAOWRITEREG,
- TESTACCESSORYAIAOWRITEREG,
- TESTINFOCTRLOPS,
- TESTCODECGETCTRLOPS,
- TESTACCESSORYGETCTRLOPS,
- TESTCODECAIAOGETCTRLOPS,
- TESTACCESSORYAIAOGETCTRLOPS,
- TESTCODECSETCTRLOPS,
- TESTACCESSORYSETCTRLOPS,
- TESTCODECAIAOSETCTRLOPS,
- TESTACCESSORYAIAOSETCTRLOPS,
-
- TESTNEWCOMPONENT,
- TESTADDROUTES,
- TESTNEWCONTROLS,
- TESTPOWERCOMPONET,
- TESTREFRESHTIME,
- TESTSTREAMDISPATCH,
+ TEST_AUDIOHOSTCREATEANDBIND = 1, // audio ADM audio_host
+ TEST_GETCARDINSTANCE = 2, // audio ADM audio_host
+
+ TEST_AUDIOFILLCONFIGDATA = 3, // audio ADM audio_parse
+ TEST_CODECGETREGCONFIG = 4, // audio ADM audio_parse
+
+ TEST_AUDIODEVICEREADREG = 5, // audio ADM audio_core
+ TEST_AUDIODEVICEWRITEREG, // audio ADM audio_core
+ TEST_AUDIOSOCREGISTERPLATFORM, // audio ADM audio_core
+ TEST_AUDIOSOCREGISTERDAI, // audio ADM audio_core
+ TEST_AUDIOREGISTERDSP, // audio ADM audio_core
+ TEST_AUDIOREGISTERCODEC, // audio ADM audio_core
+ TEST_AUDIOREGISTERACCESSORY, // audio ADM audio_core
+ TEST_AUDIOBINDDAILINK, // audio ADM audio_core
+ TEST_AUDIOUPDATECODECREGBITS, // audio ADM audio_core
+ TEST_AUDIOUPDATEACCESSORYREGBITS, // audio ADM audio_core
+ TEST_AUDIOUPDATEDAIREGBITS, // audio ADM audio_core
+ TEST_AUDIOKCONTROLGETCPUDAI, // audio ADM audio_core
+ TEST_AUDIOKCONTROLGETCODEC, // audio ADM audio_core
+ TEST_AUDIOKCONTROLGETACCESSORY, // audio ADM audio_core
+ TEST_AUDIOADDCONTROLS, // audio ADM audio_core
+ TEST_AUDIOADDCONTROL, // audio ADM audio_core
+ TEST_AUDIOGETCTRLOPSRREG, // audio ADM audio_core
+ TEST_AUDIOGETCTRLOPSREG, // audio ADM audio_core
+ TEST_AUDIOSETCTRLOPSREG, // audio ADM audio_core
+ TEST_AUDIOSETCTRLOPSRREG, // audio ADM audio_core
+ TEST_AUDIODAIREADREG, // audio ADM audio_core
+ TEST_AUDIODAIWRITEREG, // audio ADM audio_core
+ TEST_AUDIOCODECREADREG, // audio ADM audio_core
+ TEST_AUDIOCODECWRITEREG, // audio ADM audio_core
+ TEST_AUDIOACCESSORYREADREG, // audio ADM audio_core
+ TEST_AUDIOACCESSORYWRITEREG, // audio ADM audio_core
+ TEST_AUDIOINFOCTRLOPS, // audio ADM audio_core
+ TEST_AUDIOCODECGETCTRLOPS, // audio ADM audio_core
+ TEST_AUDIOCODECSETCTRLOPS, // audio ADM audio_core
+ TEST_AUDIOACCESSORYGETCTRLOPS, // audio ADM audio_core
+ TEST_AUDIOACCESSORYSETCTRLOPS, // audio ADM audio_core
+ TEST_AUDIOCPUDAISETCTRLOPS, // audio ADM audio_core
+ TEST_AUDIOCPUDAIGETCTRLOPS = 37, // audio ADM audio_core
+
+ TEST_AUDIOSAPMNEWCOMPONENTS = 38, // audio ADM audio_sapm
+ TEST_AUDIOSAPMADDROUTES, // audio ADM audio_sapm
+ TEST_AUDIOSAPMNEWCONTROLS, // audio ADM audio_sapm
+ TEST_AUDIOSAPMSLEEP, // audio ADM audio_sapm
+ TEST_AUDIOSAMPPOWERUP, // audio ADM audio_sapm
+ TEST_AUDIOSAMPSETPOWERMONITOR, // audio ADM audio_sapm
+ TEST_AUDIOCODECSAPMSETCTRLOPS, // audio ADM audio_sapm
+ TEST_AUDIOCODECSAPMGETCTRLOPS, // audio ADM audio_sapm
+ TEST_AUDIOACCESSORYSAPMSETCTRLOPS, // audio ADM audio_sapm
+ TEST_AUDIOACCESSORYSAPMGETCTRLOPS = 47, // audio ADM audio_sapm
};
#endif /* AUDIO_COMMON_TEST_H */
diff --git a/model/audio/core/test/unittest/common/audio_core_test.cpp b/model/audio/core/test/unittest/common/audio_core_test.cpp
index 91f8f7900a11b3e70f40f53bb33a25e6333f0059..349feaeb20425069e5f0c6780a54dd32a6446a84 100755
--- a/model/audio/core/test/unittest/common/audio_core_test.cpp
+++ b/model/audio/core/test/unittest/common/audio_core_test.cpp
@@ -38,195 +38,201 @@ void AudioCoreTest::TearDown()
{
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_RegisterPlatform, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioDeviceReadReg, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTREGISTERPLATFORM, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIODEVICEREADREG, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_RegisterDai, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioDeviceWriteReg, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTREGISTERDAI, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIODEVICEWRITEREG, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_RegisterAccessory, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioSocRegisterPlatform, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTREGISTERACCESSORY, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOSOCREGISTERPLATFORM, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_RegisterCodec, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioSocRegisterDai, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTREGISTERCODEC, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOSOCREGISTERDAI, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_SocRegisterDsp, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioRegisterDsp, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTREGISTERDSP, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOREGISTERDSP, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_SocDeviceRegister, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioRegisterCodec, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTSOCDEVICEREGISTER, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOREGISTERCODEC, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_BindDaiLink, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioRegisterAccessory, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTBINDDAILINK, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOREGISTERACCESSORY, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_UpdateCodecRegBits, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioBindDaiLink, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTUPDATECODECREGBITS, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOBINDDAILINK, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_UpdateAccessoryRegBits, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioUpdateCodecRegBits, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTUPDATEACCESSORYREGBITS, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOUPDATECODECREGBITS, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_UpdateCodecAiaoRegBits, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioUpdateAccessoryRegBits, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTUPDATECODECAIAOREGBITS, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOUPDATEACCESSORYREGBITS, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_UpdateAccessoryAiaoRegBits, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioUpdateDaiRegBits, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTUPDATEACCESSORYAIAOREGBITS, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOUPDATEDAIREGBITS, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_KcontrolGetCodec, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioKcontrolGetCpuDai, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTKCONTROLGETCODEC, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOKCONTROLGETCPUDAI, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_KcontrolGetAccessory, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioKcontrolGetCodec, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTKCONTROLGETACCESSORY, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOKCONTROLGETCODEC, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_AddControl, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioKcontrolGetAccessory, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTADDCONTROL, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOKCONTROLGETACCESSORY, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_AddControls, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioAddControls, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTADDCONTROLS, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOADDCONTROLS, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_CodecReadReg, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioAddControl, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTCODECREADREG, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOADDCONTROL, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryReadReg, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioGetCtrlOpsRReg, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYREADREG, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOGETCTRLOPSRREG, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_CodecAiaoReadReg, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioGetCtrlOpsReg, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTCODECAIAOREADREG, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOGETCTRLOPSREG, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryAiaoReadReg, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioSetCtrlOpsReg, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYAIAOREADREG, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOSETCTRLOPSREG, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_CodecWriteReg, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioSetCtrlOpsRReg, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTCODECWRITEREG, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOSETCTRLOPSRREG, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryWriteReg, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioDaiReadReg, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYWRITEREG, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIODAIREADREG, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_CodecAiaoWriteReg, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioDaiWriteReg, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTCODECAIAOWRITEREG, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIODAIWRITEREG, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryAiaoWriteReg, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioCodecReadReg, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYAIAOWRITEREG, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOCODECREADREG, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_InfoCtrlOps, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioCodecWriteReg, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTINFOCTRLOPS, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOCODECWRITEREG, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_CodecGetCtrlOps, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioAccessoryReadReg, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTCODECGETCTRLOPS, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOACCESSORYREADREG, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryGetCtrlOps, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioAccessoryWriteReg, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYGETCTRLOPS, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOACCESSORYWRITEREG, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_CodecAiaoGetCtrlOps, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioInfoCtrlOps, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTCODECAIAOGETCTRLOPS, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOINFOCTRLOPS, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryAiaoGetCtrlOps, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioCodecGetCtrlOps, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYAIAOGETCTRLOPS, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOCODECGETCTRLOPS, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_CodecSetCtrlOps, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioCodecSetCtrlOps, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTCODECSETCTRLOPS, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOCODECSETCTRLOPS, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_AccessorySetCtrlOps, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioAccessoryGetCtrlOps, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYSETCTRLOPS, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOACCESSORYGETCTRLOPS, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_CodecAiaoSetCtrlOps, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioAccessorySetCtrlOpsTset, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTCODECAIAOSETCTRLOPS, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOACCESSORYSETCTRLOPS, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryAiaoSetCtrlOps, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioCpuDaiSetCtrlOps, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYAIAOSETCTRLOPS, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOCPUDAISETCTRLOPS, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioCoreTest, AudioCoreTest_AudioCpuDaiGetCtrlOps, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOCPUDAIGETCTRLOPS, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
}
diff --git a/model/audio/core/test/unittest/common/audio_host_test.cpp b/model/audio/core/test/unittest/common/audio_host_test.cpp
index 6632edb9a58cdf3e970428e231f97aa59db8e79b..56b405a1ec0118eb4f915e1ec07dec0527ad98cd 100755
--- a/model/audio/core/test/unittest/common/audio_host_test.cpp
+++ b/model/audio/core/test/unittest/common/audio_host_test.cpp
@@ -39,15 +39,15 @@ void AudioHostTest::TearDown()
{
}
-HWTEST_F(AudioHostTest, AudioHostTest_GetCodec, TestSize.Level0)
+HWTEST_F(AudioHostTest, AudioHostTest_AudioHostCreateAndBind, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTGETCODEC, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOHOSTCREATEANDBIND, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioHostTest, AudioHostTest_GetAudioServiceName, TestSize.Level0)
+HWTEST_F(AudioHostTest, AudioHostTest_GetCardInstance, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTGETCARDINSTANCE, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_GETCARDINSTANCE, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
}
diff --git a/model/audio/core/test/unittest/common/audio_parse_test.cpp b/model/audio/core/test/unittest/common/audio_parse_test.cpp
index 6b612d03a797fdd6e9103be128b94b2df82c223d..2df866aac4c85745fe43956a82935fa276a81092 100755
--- a/model/audio/core/test/unittest/common/audio_parse_test.cpp
+++ b/model/audio/core/test/unittest/common/audio_parse_test.cpp
@@ -39,9 +39,15 @@ void AudioParseTest::TearDown()
{
}
-HWTEST_F(AudioParseTest, AudioParseTest_GetConfigData, TestSize.Level0)
+HWTEST_F(AudioParseTest, AudioParseTest_AudioFillConfigData, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTGETCCNFIGDATA, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOFILLCONFIGDATA, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioParseTest, AudioParseTest_CodecGetRegConfig, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TEST_CODECGETREGCONFIG, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
}
diff --git a/model/audio/dispatch/include/audio_control_dispatch.h b/model/audio/dispatch/include/audio_control_dispatch.h
index 2d3959316440652bb4535aceb4148b08efbd817b..ec979a667ad78335e252fd8034b5f7fe6eff09ea 100755
--- a/model/audio/dispatch/include/audio_control_dispatch.h
+++ b/model/audio/dispatch/include/audio_control_dispatch.h
@@ -17,9 +17,6 @@ extern "C" {
#endif
#endif /* __cplusplus */
-
-#define AUDIODRV_CTRL_ELEM_TYPE_INTEGER 2 /* integer type */
-
enum ControlDispMethodCmd {
AUDIODRV_CTRL_IOCTRL_ELEM_INFO,
AUDIODRV_CTRL_IOCTRL_ELEM_READ,
@@ -27,12 +24,9 @@ enum ControlDispMethodCmd {
AUDIODRV_CTRL_IOCTRL_ELEM_BUTT,
};
-typedef int32_t (*ControlDispCmdHandle)(const struct HdfDeviceIoClient *client,
- struct HdfSBuf *data, struct HdfSBuf *reply);
-
struct ControlDispCmdHandleList {
enum ControlDispMethodCmd cmd;
- ControlDispCmdHandle func;
+ int32_t (*func)(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply);
};
struct ControlHost {
@@ -41,11 +35,6 @@ struct ControlHost {
void *priv;
};
-static inline struct ControlHost *ControlHostFromDevice(struct HdfDeviceObject *device)
-{
- return (device == NULL) ? NULL : (struct ControlHost *)device->service;
-}
-
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/model/audio/dispatch/include/audio_stream_dispatch.h b/model/audio/dispatch/include/audio_stream_dispatch.h
index b1d4c75298ce9c17b8c283327d1a278eab08c955..b586e1c7299af73024c0ed5ba2bd2b865595ae5b 100755
--- a/model/audio/dispatch/include/audio_stream_dispatch.h
+++ b/model/audio/dispatch/include/audio_stream_dispatch.h
@@ -21,38 +21,37 @@ extern "C" {
#endif
#endif /* __cplusplus */
-#define AUDIO_SERVICE_NAME_MAX_LEN 32
-
enum StreamDispMethodCmd {
- AUDIO_DRV_PCM_IOCTRL_HW_PARAMS,
- AUDIO_DRV_PCM_IOCTRL_RENDER_PREPARE,
- AUDIO_DRV_PCM_IOCTRL_CAPTURE_PREPARE,
- AUDIO_DRV_PCM_IOCTRL_WRITE,
- AUDIO_DRV_PCM_IOCTRL_READ,
- AUDIO_DRV_PCM_IOCTRL_RENDER_START,
- AUDIO_DRV_PCM_IOCTRL_RENDER_STOP,
- AUDIO_DRV_PCM_IOCTRL_CAPTURE_START,
- AUDIO_DRV_PCM_IOCTRL_CAPTURE_STOP,
- AUDIO_DRV_PCM_IOCTRL_RENDER_PAUSE,
- AUDIO_DRV_PCM_IOCTRL_CAPTURE_PAUSE,
- AUDIO_DRV_PCM_IOCTRL_RENDER_RESUME,
- AUDIO_DRV_PCM_IOCTRL_CAPTURE_RESUME,
+ AUDIO_DRV_PCM_IOCTL_HW_PARAMS,
+ AUDIO_DRV_PCM_IOCTL_RENDER_PREPARE,
+ AUDIO_DRV_PCM_IOCTL_CAPTURE_PREPARE,
+ AUDIO_DRV_PCM_IOCTL_WRITE,
+ AUDIO_DRV_PCM_IOCTL_READ,
+ AUDIO_DRV_PCM_IOCTL_RENDER_START,
+ AUDIO_DRV_PCM_IOCTL_RENDER_STOP,
+ AUDIO_DRV_PCM_IOCTL_CAPTURE_START,
+ AUDIO_DRV_PCM_IOCTL_CAPTURE_STOP,
+ AUDIO_DRV_PCM_IOCTL_RENDER_PAUSE,
+ AUDIO_DRV_PCM_IOCTL_CAPTURE_PAUSE,
+ AUDIO_DRV_PCM_IOCTL_RENDER_RESUME,
+ AUDIO_DRV_PCM_IOCTL_CAPTURE_RESUME,
AUDIO_DRV_PCM_IOCTL_MMAP_BUFFER,
AUDIO_DRV_PCM_IOCTL_MMAP_BUFFER_CAPTURE,
AUDIO_DRV_PCM_IOCTL_MMAP_POSITION,
AUDIO_DRV_PCM_IOCTL_MMAP_POSITION_CAPTURE,
- AUDIO_DRV_PCM_IOCTRL_DSP_DECODE,
- AUDIO_DRV_PCM_IOCTRL_DSP_ENCODE,
- AUDIO_DRV_PCM_IOCTRL_DSP_EQUALIZER,
- AUDIO_DRV_PCM_IOCTRL_BUTT,
+ AUDIO_DRV_PCM_IOCTL_RENDER_OPEN,
+ AUDIO_DRV_PCM_IOCTL_RENDER_CLOSE,
+ AUDIO_DRV_PCM_IOCTL_CAPTURE_OPEN,
+ AUDIO_DRV_PCM_IOCTL_CAPTURE_CLOSE,
+ AUDIO_DRV_PCM_IOCTL_DSPDECODE,
+ AUDIO_DRV_PCM_IOCTL_DSPENCODE,
+ AUDIO_DRV_PCM_IOCTL_DSPEQUALIZER,
+ AUDIO_DRV_PCM_IOCTL_BUTT,
};
-typedef int32_t (*StreamDispCmdHandle)(const struct HdfDeviceIoClient *client,
- struct HdfSBuf *data, struct HdfSBuf *reply);
-
struct StreamDispCmdHandleList {
enum StreamDispMethodCmd cmd;
- StreamDispCmdHandle func;
+ int32_t (*func)(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply);
};
struct StreamHost {
@@ -61,14 +60,6 @@ struct StreamHost {
void *priv;
};
-static inline struct StreamHost *StreamHostFromDevice(struct HdfDeviceObject *device)
-{
- return (device == NULL) ? NULL : (struct StreamHost *)device->service;
-}
-
-int32_t StreamDispatch(struct HdfDeviceIoClient *client, int cmdId,
- struct HdfSBuf *data, struct HdfSBuf *reply);
-
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/model/audio/dispatch/src/audio_control_dispatch.c b/model/audio/dispatch/src/audio_control_dispatch.c
index 082e66a35ae88f92ddd44a396ea079d8ba27ce12..075641041b2550e011f1b6cc7a5b329ebb03a0c5 100755
--- a/model/audio/dispatch/src/audio_control_dispatch.c
+++ b/model/audio/dispatch/src/audio_control_dispatch.c
@@ -8,6 +8,7 @@
#include "audio_control_dispatch.h"
#include "audio_control.h"
+#include "audio_driver_log.h"
#define HDF_LOG_TAG audio_control_dispatch
@@ -126,7 +127,6 @@ static int32_t ControlHostElemRead(const struct HdfDeviceIoClient *client, struc
struct AudioCtrlElemValue elemValue;
struct AudioCtrlElemId id;
int32_t result;
- ADM_LOG_DEBUG("entry.");
if ((client == NULL) || (reqData == NULL) || (rspData == NULL)) {
ADM_LOG_ERR("Input ElemRead params check error: client=%p, reqData=%p, rspData=%p.", client, reqData, rspData);
@@ -148,6 +148,7 @@ static int32_t ControlHostElemRead(const struct HdfDeviceIoClient *client, struc
ADM_LOG_ERR("ElemRead request itemName failed!");
return HDF_FAILURE;
}
+ ADM_LOG_DEBUG("itemName: %s cardServiceName: %s iface: %d ", id.itemName, id.cardServiceName, id.iface);
kctrl = AudioGetKctrlInstance(&id);
if (kctrl == NULL || kctrl->Get == NULL) {
@@ -170,7 +171,6 @@ static int32_t ControlHostElemRead(const struct HdfDeviceIoClient *client, struc
ADM_LOG_ERR("Write response data value[1]=%d failed!", elemValue.value[1]);
return HDF_FAILURE;
}
- ADM_LOG_DEBUG("success.");
return HDF_SUCCESS;
}
@@ -180,7 +180,6 @@ static int32_t ControlHostElemWrite(const struct HdfDeviceIoClient *client,
struct AudioKcontrol *kctrl = NULL;
struct AudioCtrlElemValue elemValue;
int32_t result;
- ADM_LOG_DEBUG("entry.");
if ((client == NULL) || (reqData == NULL)) {
ADM_LOG_ERR("Input params check error: client=%p, reqData=%p.", client, reqData);
@@ -209,6 +208,10 @@ static int32_t ControlHostElemWrite(const struct HdfDeviceIoClient *client,
return HDF_FAILURE;
}
+ ADM_LOG_DEBUG("itemName: %s cardServiceName: %s iface: %d value: %d ", elemValue.id.itemName,
+ elemValue.id.cardServiceName,
+ elemValue.id.iface, elemValue.value[0]);
+
kctrl = AudioGetKctrlInstance(&elemValue.id);
if (kctrl == NULL || kctrl->Set == NULL) {
ADM_LOG_ERR("Find kctrl or Set fail!");
@@ -220,7 +223,6 @@ static int32_t ControlHostElemWrite(const struct HdfDeviceIoClient *client,
ADM_LOG_ERR("Get control value fail result=%d", result);
return HDF_FAILURE;
}
- ADM_LOG_DEBUG("success.");
return HDF_SUCCESS;
}
@@ -310,7 +312,7 @@ static void AudioControlRelease(struct HdfDeviceObject *device)
return;
}
- controlHost = ControlHostFromDevice(device);
+ controlHost = (struct ControlHost *)device->service;
if (controlHost == NULL) {
ADM_LOG_ERR("controlHost is NULL.");
return;
diff --git a/model/audio/dispatch/src/audio_stream_dispatch.c b/model/audio/dispatch/src/audio_stream_dispatch.c
index 70e26609a2d607fd7bac995cefe7010d6b6830ef..b871ecccb9416014dc0574f5175d7467403e4065 100755
--- a/model/audio/dispatch/src/audio_stream_dispatch.c
+++ b/model/audio/dispatch/src/audio_stream_dispatch.c
@@ -7,10 +7,19 @@
*/
#include "audio_stream_dispatch.h"
+#include "audio_driver_log.h"
+#include "audio_platform_base.h"
#define HDF_LOG_TAG audio_stream_dispatch
-int32_t HwCpuDaiDispatch(const struct AudioCard *audioCard, const struct AudioPcmHwParams *params)
+#define BUFF_SIZE_MAX 64
+
+static inline struct StreamHost *StreamHostFromDevice(const struct HdfDeviceObject *device)
+{
+ return (device == NULL) ? NULL : (struct StreamHost *)device->service;
+}
+
+static int32_t HwCpuDaiDispatch(const struct AudioCard *audioCard, const struct AudioPcmHwParams *params)
{
if ((audioCard == NULL) || (params == NULL)) {
ADM_LOG_ERR("CpuDai input param is NULL.");
@@ -33,9 +42,9 @@ int32_t HwCpuDaiDispatch(const struct AudioCard *audioCard, const struct AudioPc
* If not, skip the if statement and execute in sequence.
*/
if (cpuDai->devData->ops->HwParams != NULL) {
- int ret = cpuDai->devData->ops->HwParams(audioCard, params, cpuDai);
+ int ret = cpuDai->devData->ops->HwParams(audioCard, params);
if (ret < 0) {
- ADM_LOG_ERR("cpuDai hardware params fail ret=%d", ret);
+ ADM_LOG_ERR("cpuDai hardware params failed ret=%d", ret);
return HDF_ERR_IO;
}
}
@@ -43,7 +52,7 @@ int32_t HwCpuDaiDispatch(const struct AudioCard *audioCard, const struct AudioPc
return HDF_SUCCESS;
}
-int32_t HwCodecDaiDispatch(const struct AudioCard *audioCard, const struct AudioPcmHwParams *params)
+static int32_t HwCodecDaiDispatch(const struct AudioCard *audioCard, const struct AudioPcmHwParams *params)
{
if ((audioCard == NULL) || (params == NULL)) {
ADM_LOG_ERR("CodecDai input param is NULL.");
@@ -68,9 +77,9 @@ int32_t HwCodecDaiDispatch(const struct AudioCard *audioCard, const struct Audio
* If not, skip the if statement and execute in sequence.
*/
if (codecDai->devData->ops->HwParams != NULL) {
- int ret = codecDai->devData->ops->HwParams(audioCard, params, codecDai);
+ int ret = codecDai->devData->ops->HwParams(audioCard, params);
if (ret < 0) {
- ADM_LOG_ERR("codecDai hardware params fail ret=%d", ret);
+ ADM_LOG_ERR("codecDai hardware params failed ret=%d", ret);
return HDF_ERR_IO;
}
}
@@ -78,40 +87,58 @@ int32_t HwCodecDaiDispatch(const struct AudioCard *audioCard, const struct Audio
return HDF_SUCCESS;
}
-int32_t HwPlatfromDispatch(const struct AudioCard *audioCard, const struct AudioPcmHwParams *params)
+static int32_t HwDspDaiDispatch(const struct AudioCard *audioCard, const struct AudioPcmHwParams *params)
{
if ((audioCard == NULL) || (params == NULL)) {
- ADM_LOG_ERR("Platfrom input param is NULL.");
+ ADM_LOG_ERR("DspDai input param is NULL.");
return HDF_FAILURE;
}
-
struct AudioRuntimeDeivces *rtd = audioCard->rtd;
if (rtd == NULL) {
- ADM_LOG_ERR("audioCard rtd is NULL.");
+ ADM_LOG_ERR("DspDai audioCard rtd is NULL.");
+ return HDF_FAILURE;
+ }
+ struct DaiDevice *dspDai = rtd->dspDai;
+ if (dspDai == NULL || dspDai->devData == NULL || dspDai->devData->ops == NULL) {
+ ADM_LOG_ERR("dspDai param is NULL.");
+ return HDF_FAILURE;
+ }
+ if (dspDai->devData->ops->HwParams != NULL) {
+ int ret = dspDai->devData->ops->HwParams(audioCard, params);
+ if (ret < 0) {
+ ADM_LOG_ERR("dspDai hardware params failed ret=%d", ret);
+ return HDF_ERR_IO;
+ }
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t HwPlatfromDispatch(const struct AudioCard *audioCard, const struct AudioPcmHwParams *params)
+{
+ if ((audioCard == NULL) || (params == NULL)) {
+ ADM_LOG_ERR("Platfrom input param is NULL.");
return HDF_FAILURE;
}
- struct PlatformDevice *platform = rtd->platform;
- if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL) {
- ADM_LOG_ERR("platform param is NULL.");
+ struct AudioRuntimeDeivces *rtd = audioCard->rtd;
+ if (rtd == NULL) {
+ ADM_LOG_ERR("audioCard rtd is NULL.");
return HDF_FAILURE;
}
/* If there are HwParams function, it will be executed directly.
* If not, skip the if statement and execute in sequence.
*/
- if (platform->devData->ops->HwParams != NULL) {
- int ret = platform->devData->ops->HwParams(audioCard, params);
- if (ret < 0) {
- ADM_LOG_ERR("platform hardware params fail ret=%d", ret);
- return HDF_ERR_IO;
- }
+ int ret = AudioHwParams(audioCard, params);
+ if (ret < 0) {
+ ADM_LOG_ERR("platform hardware params failed ret=%d", ret);
+ return HDF_ERR_IO;
}
return HDF_SUCCESS;
}
-int32_t HwParamsDispatch(const struct AudioCard *audioCard, const struct AudioPcmHwParams *params)
+static int32_t HwParamsDispatch(const struct AudioCard *audioCard, const struct AudioPcmHwParams *params)
{
if ((audioCard == NULL) || (params == NULL)) {
ADM_LOG_ERR("input param is NULL.");
@@ -119,10 +146,144 @@ int32_t HwParamsDispatch(const struct AudioCard *audioCard, const struct AudioPc
}
/* Traverse through each driver method; Enter if you have, if not, exectue in order */
- if (HwCodecDaiDispatch(audioCard, params) ||
- HwCpuDaiDispatch(audioCard, params) ||
- HwPlatfromDispatch(audioCard, params)) {
- ADM_LOG_ERR("hardware params fail.");
+ if (HwCodecDaiDispatch(audioCard, params) != HDF_SUCCESS) {
+ ADM_LOG_ERR("codec dai hardware params failed.");
+ return HDF_FAILURE;
+ }
+
+ if (HwCpuDaiDispatch(audioCard, params) != HDF_SUCCESS) {
+ ADM_LOG_ERR("cpu dai hardware params failed.");
+ return HDF_FAILURE;
+ }
+
+ if (HwPlatfromDispatch(audioCard, params) != HDF_SUCCESS) {
+ ADM_LOG_ERR("platform dai hardware params failed.");
+ return HDF_FAILURE;
+ }
+
+ if (HwDspDaiDispatch(audioCard, params) != HDF_SUCCESS) {
+ ADM_LOG_ERR("dsp dai hardware params failed.");
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t CpuDaiDevStartup(const struct AudioCard *audioCard, const struct DaiDevice *cpuDai)
+{
+ int32_t ret;
+ if (audioCard == NULL || audioCard->rtd == NULL) {
+ ADM_LOG_ERR("audioCard is null.");
+ return HDF_FAILURE;
+ }
+ if (cpuDai != NULL && cpuDai->devData != NULL && cpuDai->devData->ops != NULL &&
+ cpuDai->devData->ops->Startup != NULL) {
+ ret = cpuDai->devData->ops->Startup(audioCard, cpuDai);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("cpuDai Startup failed.");
+ return HDF_FAILURE;
+ }
+ } else {
+ ADM_LOG_DEBUG("cpu dai startup is null.");
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t CodecDaiDevStartup(const struct AudioCard *audioCard, const struct DaiDevice *codecDai)
+{
+ int32_t ret;
+ if (audioCard == NULL || audioCard->rtd == NULL) {
+ ADM_LOG_ERR("audioCard is null.");
+ return HDF_FAILURE;
+ }
+ if (codecDai != NULL && codecDai->devData != NULL && codecDai->devData->ops != NULL &&
+ codecDai->devData->ops->Startup != NULL) {
+ ret = codecDai->devData->ops->Startup(audioCard, codecDai);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("codecDai Startup failed.");
+ return HDF_FAILURE;
+ }
+ } else {
+ ADM_LOG_DEBUG("codec dai startup is null.");
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t DspDaiDevStartup(const struct AudioCard *audioCard, const struct DaiDevice *dspDai)
+{
+ int32_t ret;
+ if (audioCard == NULL || audioCard->rtd == NULL) {
+ ADM_LOG_ERR("audioCard is null.");
+ return HDF_FAILURE;
+ }
+ if (dspDai != NULL && dspDai->devData != NULL && dspDai->devData->ops != NULL &&
+ dspDai->devData->ops->Startup != NULL) {
+ ret = dspDai->devData->ops->Startup(audioCard, dspDai);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("dspDai Startup failed.");
+ return HDF_FAILURE;
+ }
+ } else {
+ ADM_LOG_DEBUG("dsp dai startup is null.");
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t AccessoryDaiDevStartup(const struct AudioCard *audioCard, const struct DaiDevice *accessoryDai)
+{
+ int32_t ret;
+ if (audioCard == NULL || audioCard->rtd == NULL) {
+ ADM_LOG_ERR("audioCard is null.");
+ return HDF_FAILURE;
+ }
+ if (accessoryDai != NULL && accessoryDai->devData != NULL && accessoryDai->devData->ops != NULL &&
+ accessoryDai->devData->ops->Startup != NULL) {
+ ret = accessoryDai->devData->ops->Startup(audioCard, accessoryDai);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("accessoryDai Startup failed.");
+ return HDF_FAILURE;
+ }
+ } else {
+ ADM_LOG_DEBUG("accessory dai startup is null.");
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t AudioDaiDeviceStartup(const struct AudioCard *audioCard)
+{
+ struct DaiDevice *cpuDai = NULL;
+ struct DaiDevice *codecDai = NULL;
+ struct DaiDevice *dspDai = NULL;
+ struct DaiDevice *accessoryDai = NULL;
+ int32_t ret;
+
+ if (audioCard == NULL || audioCard->rtd == NULL) {
+ ADM_LOG_ERR("audioCard is null.");
+ return HDF_FAILURE;
+ }
+ cpuDai = audioCard->rtd->cpuDai;
+ ret = CpuDaiDevStartup(audioCard, cpuDai);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("CpuDaiDevStartup failed.");
+ return HDF_FAILURE;
+ }
+ codecDai = audioCard->rtd->codecDai;
+ ret = CodecDaiDevStartup(audioCard, codecDai);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("CodecDaiDevStartup failed.");
+ return HDF_FAILURE;
+ }
+ dspDai = audioCard->rtd->dspDai;
+ ret = DspDaiDevStartup(audioCard, dspDai);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("DspDaiDevStartup failed.");
+ return HDF_FAILURE;
+ }
+ accessoryDai = audioCard->rtd->accessoryDai;
+ ret = AccessoryDaiDevStartup(audioCard, accessoryDai);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("AccessoryDaiDevStartup failed.");
return HDF_FAILURE;
}
return HDF_SUCCESS;
@@ -201,13 +362,11 @@ static int32_t HwParamsDataAnalysis(struct HdfSBuf *reqData, struct AudioPcmHwPa
return HDF_SUCCESS;
}
-int32_t StreamHostHwParams(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
+static int32_t StreamHostHwParams(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
struct HdfSBuf *reply)
{
struct AudioPcmHwParams params;
- struct StreamHost *streamHost = NULL;
struct AudioCard *audioCard = NULL;
- char *cardName = NULL;
int ret;
ADM_LOG_DEBUG("entry.");
@@ -217,37 +376,18 @@ int32_t StreamHostHwParams(const struct HdfDeviceIoClient *client, struct HdfSBu
}
(void)reply;
- streamHost = StreamHostFromDevice(client->device);
- if (streamHost == NULL) {
- ADM_LOG_ERR("renderHost is NULL");
- return HDF_FAILURE;
- }
-
- cardName = (char *)OsalMemCalloc(sizeof(char) * BUFF_SIZE_MAX);
- if (cardName == NULL) {
- ADM_LOG_ERR("malloc cardServiceName fail!");
- return HDF_FAILURE;
- }
- streamHost->priv = cardName;
-
(void)memset_s(¶ms, sizeof(struct AudioPcmHwParams), 0, sizeof(struct AudioPcmHwParams));
+
ret = HwParamsDataAnalysis(data, ¶ms);
if (ret != HDF_SUCCESS) {
ADM_LOG_ERR("hwparams data analysis failed ret=%d", ret);
return HDF_FAILURE;
}
-
- if (memcpy_s(cardName, BUFF_SIZE_MAX, params.cardServiceName, BUFF_SIZE_MAX) != EOK) {
- ADM_LOG_ERR("memcpy cardName failed.");
- return HDF_FAILURE;
- }
-
audioCard = GetCardInstance(params.cardServiceName);
if (audioCard == NULL) {
- ADM_LOG_ERR("get card instance fail.");
+ ADM_LOG_ERR("get card instance failed.");
return HDF_FAILURE;
}
-
ret = HwParamsDispatch(audioCard, ¶ms);
if (ret != HDF_SUCCESS) {
ADM_LOG_ERR("hwparams dispatch failed ret=%d", ret);
@@ -282,20 +422,18 @@ static struct AudioCard *StreamHostGetCardInstance(const struct HdfDeviceIoClien
audioCard = GetCardInstance(cardName);
if (audioCard == NULL) {
- ADM_LOG_ERR("get card instance fail.");
+ ADM_LOG_ERR("get card instance failed.");
return NULL;
}
return audioCard;
}
-int32_t StreamHostCapturePrepare(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
+static int32_t StreamHostCapturePrepare(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
struct HdfSBuf *reply)
{
- struct AudioRuntimeDeivces *rtd = NULL;
- struct PlatformDevice *platform = NULL;
struct AudioCard *audioCard = NULL;
- int ret;
+ int ret = HDF_SUCCESS;
ADM_LOG_DEBUG("entry.");
if (client == NULL) {
@@ -307,36 +445,90 @@ int32_t StreamHostCapturePrepare(const struct HdfDeviceIoClient *client, struct
(void)reply;
audioCard = StreamHostGetCardInstance(client);
- if (audioCard == NULL || audioCard->rtd == NULL) {
- ADM_LOG_ERR("CapturePrepare get card instance or rtd fail.");
+ if (audioCard == NULL) {
+ ADM_LOG_ERR("CapturePrepare get card instance or rtd failed.");
return HDF_FAILURE;
}
- rtd = audioCard->rtd;
- platform = rtd->platform;
- if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL ||
- platform->devData->ops->CapturePrepare == NULL) {
- ADM_LOG_ERR("audioCard rtd platform is NULL.");
+ ret = AudioCapturePrepare(audioCard);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("platform CapturePrepare failed ret=%d", ret);
+ return HDF_ERR_IO;
+ }
+
+ ADM_LOG_DEBUG("success.");
+ return HDF_SUCCESS;
+}
+
+static int32_t StreamHostCaptureOpen(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
+ struct HdfSBuf *reply)
+{
+ char *cardName = NULL;
+ const char *carNameTemp = NULL;
+ struct StreamHost *streamHost = NULL;
+ struct AudioCard *audioCard = NULL;
+
+ ADM_LOG_DEBUG("entry.");
+
+ if (client == NULL) {
+ ADM_LOG_ERR("StreamHostCaptureOpen input param is NULL.");
return HDF_FAILURE;
}
- ret = platform->devData->ops->CapturePrepare(audioCard);
- if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("platform CapturePrepare fail ret=%d", ret);
+ (void)reply;
+
+ cardName = (char *)OsalMemCalloc(sizeof(char) * BUFF_SIZE_MAX);
+ if (cardName == NULL) {
+ ADM_LOG_ERR("malloc cardServiceName failed!");
+ return HDF_FAILURE;
+ }
+
+ streamHost = StreamHostFromDevice(client->device);
+ if (streamHost == NULL) {
+ OsalMemFree(cardName);
+ ADM_LOG_ERR("renderHost is NULL");
+ return HDF_FAILURE;
+ }
+
+ if (!(carNameTemp = HdfSbufReadString(data))) {
+ OsalMemFree(cardName);
+ ADM_LOG_ERR("read request cardServiceName failed!");
+ return HDF_FAILURE;
+ }
+
+ if (strncpy_s(cardName, BUFF_SIZE_MAX - 1, carNameTemp, strlen(carNameTemp) + 1) != EOK) {
+ ADM_LOG_ERR("memcpy cardName failed.");
+ OsalMemFree(cardName);
+ return HDF_FAILURE;
+ }
+ ADM_LOG_DEBUG("card name: %s.", cardName);
+ streamHost->priv = cardName;
+
+ audioCard = StreamHostGetCardInstance(client);
+ if (audioCard == NULL) {
+ ADM_LOG_ERR("StreamHostCaptureOpen get card instance or rtd failed.");
+ return HDF_FAILURE;
+ }
+
+ if (AudioCaptureOpen(audioCard) != HDF_SUCCESS) {
+ ADM_LOG_ERR("platform CaptureOpen failed");
return HDF_ERR_IO;
}
+ if (AudioDaiDeviceStartup(audioCard) != HDF_SUCCESS) {
+ ADM_LOG_ERR("Dai Device Startup failed.");
+ return HDF_FAILURE;
+ }
+
ADM_LOG_DEBUG("success.");
return HDF_SUCCESS;
}
-int32_t StreamHostRenderPrepare(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
+static int32_t StreamHostRenderPrepare(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
struct HdfSBuf *reply)
{
- struct AudioRuntimeDeivces *rtd = NULL;
- struct PlatformDevice *platform = NULL;
struct AudioCard *audioCard = NULL;
- int ret;
+ int ret = HDF_SUCCESS;
ADM_LOG_DEBUG("entry.");
if (client == NULL) {
@@ -349,21 +541,13 @@ int32_t StreamHostRenderPrepare(const struct HdfDeviceIoClient *client, struct H
audioCard = StreamHostGetCardInstance(client);
if (audioCard == NULL || audioCard->rtd == NULL) {
- ADM_LOG_ERR("RenderPrepare get card instance or rtd fail.");
+ ADM_LOG_ERR("RenderPrepare get card instance or rtd failed.");
return HDF_FAILURE;
}
- rtd = audioCard->rtd;
- platform = rtd->platform;
- if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL ||
- platform->devData->ops->RenderPrepare == NULL) {
- ADM_LOG_ERR("audioCard rtd platform is NULL.");
- return HDF_FAILURE;
- }
-
- ret = platform->devData->ops->RenderPrepare(audioCard);
+ ret = AudioRenderPrepare(audioCard);
if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("platform RenderPrepare fail ret=%d", ret);
+ ADM_LOG_ERR("platform RenderPrepare failed ret=%d", ret);
return HDF_ERR_IO;
}
@@ -371,53 +555,103 @@ int32_t StreamHostRenderPrepare(const struct HdfDeviceIoClient *client, struct H
return HDF_SUCCESS;
}
-static int32_t StreamTransferWrite(const struct AudioCard *audioCard, struct AudioTxData *transfer)
+static int32_t StreamHostRenderOpen(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
+ struct HdfSBuf *reply)
{
- struct PlatformDevice *platform = NULL;
- int32_t ret;
+ char *cardName = NULL;
+ const char *carNameTemp = NULL;
+ struct StreamHost *streamHost = NULL;
+ struct AudioCard *audioCard = NULL;
- if (audioCard == NULL || audioCard->rtd == NULL || transfer == NULL) {
- ADM_LOG_ERR("input param is NULL.");
+ ADM_LOG_DEBUG("entry.");
+
+ if (client == NULL) {
+ ADM_LOG_ERR("StreamHostRenderOpen input param is NULL.");
return HDF_FAILURE;
}
- platform = audioCard->rtd->platform;
- if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL ||
- platform->devData->ops->Write == NULL) {
- ADM_LOG_ERR("audioCard platform is NULL.");
+ (void)reply;
+
+ cardName = (char *)OsalMemCalloc(sizeof(char) * BUFF_SIZE_MAX);
+ if (cardName == NULL) {
+ ADM_LOG_ERR("malloc cardServiceName failed!");
return HDF_FAILURE;
}
- ret = platform->devData->ops->Write(audioCard, transfer);
- if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("platform write fail ret=%d", ret);
+ streamHost = StreamHostFromDevice(client->device);
+ if (streamHost == NULL) {
+ ADM_LOG_ERR("renderHost is NULL");
+ OsalMemFree(cardName);
+ return HDF_FAILURE;
+ }
+
+ if (!(carNameTemp = HdfSbufReadString(data))) {
+ ADM_LOG_ERR("read request cardServiceName failed!");
+ OsalMemFree(cardName);
+ return HDF_FAILURE;
+ }
+
+ if (strncpy_s(cardName, BUFF_SIZE_MAX - 1, carNameTemp, strlen(carNameTemp) + 1) != EOK) {
+ ADM_LOG_ERR("memcpy cardName failed.");
+ OsalMemFree(cardName);
+ return HDF_FAILURE;
+ }
+
+ ADM_LOG_DEBUG("card name: %s.", cardName);
+
+ streamHost->priv = cardName;
+
+ audioCard = StreamHostGetCardInstance(client);
+ if (audioCard == NULL || audioCard->rtd == NULL) {
+ ADM_LOG_ERR("StreamHostRenderOpen get card instance or rtd failed.");
return HDF_FAILURE;
}
+ if (AudioRenderOpen(audioCard) != HDF_SUCCESS) {
+ ADM_LOG_ERR("platform RenderOpen failed.");
+ return HDF_FAILURE;
+ }
+
+ if (AudioDaiDeviceStartup(audioCard) != HDF_SUCCESS) {
+ ADM_LOG_ERR("Dai Device Startup failed.");
+ return HDF_FAILURE;
+ }
+
+ ADM_LOG_DEBUG("success.");
return HDF_SUCCESS;
}
-static int32_t StreamTransferMmapWrite(const struct AudioCard *audioCard, struct AudioTxMmapData *txMmapData)
+static int32_t StreamTransferWrite(const struct AudioCard *audioCard, struct AudioTxData *transfer)
{
- struct PlatformDevice *platform = NULL;
int32_t ret;
- ADM_LOG_DEBUG("entry.");
- if (audioCard == NULL || audioCard->rtd == NULL || txMmapData == NULL) {
+ if (audioCard == NULL || transfer == NULL) {
ADM_LOG_ERR("input param is NULL.");
return HDF_FAILURE;
}
- platform = audioCard->rtd->platform;
- if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL ||
- platform->devData->ops->Write == NULL) {
- ADM_LOG_ERR("audioCard platform is NULL.");
+ ret = AudioPcmWrite(audioCard, transfer);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("pcm write failed ret=%d", ret);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t StreamTransferMmapWrite(const struct AudioCard *audioCard, const struct AudioMmapData *txMmapData)
+{
+ int32_t ret;
+ ADM_LOG_DEBUG("entry.");
+
+ if (audioCard == NULL || txMmapData == NULL) {
+ ADM_LOG_ERR("input param is NULL.");
return HDF_FAILURE;
}
- ret = platform->devData->ops->MmapWrite(audioCard, txMmapData);
+ ret = AudioPcmMmapWrite(audioCard, txMmapData);
if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("platform write fail ret=%d", ret);
+ ADM_LOG_ERR("platform write failed ret=%d", ret);
return HDF_FAILURE;
}
@@ -425,27 +659,19 @@ static int32_t StreamTransferMmapWrite(const struct AudioCard *audioCard, struct
return HDF_SUCCESS;
}
-static int32_t StreamTransferMmapRead(const struct AudioCard *audioCard, struct AudioRxMmapData *rxMmapData)
+static int32_t StreamTransferMmapRead(const struct AudioCard *audioCard, const struct AudioMmapData *rxMmapData)
{
- struct PlatformDevice *platform = NULL;
int32_t ret;
ADM_LOG_DEBUG("entry.");
- if (audioCard == NULL || audioCard->rtd == NULL || rxMmapData == NULL) {
+ if (audioCard == NULL || rxMmapData == NULL) {
ADM_LOG_ERR("input param is NULL.");
return HDF_FAILURE;
}
- platform = audioCard->rtd->platform;
- if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL ||
- platform->devData->ops->MmapRead == NULL) {
- ADM_LOG_ERR("audioCard platform is NULL.");
- return HDF_FAILURE;
- }
-
- ret = platform->devData->ops->MmapRead(audioCard, rxMmapData);
+ ret = AudioPcmMmapRead(audioCard, rxMmapData);
if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("platform read fail ret=%d", ret);
+ ADM_LOG_ERR("platform read failed ret=%d", ret);
return HDF_FAILURE;
}
@@ -453,11 +679,11 @@ static int32_t StreamTransferMmapRead(const struct AudioCard *audioCard, struct
return HDF_SUCCESS;
}
-int32_t StreamHostWrite(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
+static int32_t StreamHostWrite(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
{
struct AudioTxData transfer;
struct AudioCard *audioCard = NULL;
- int32_t ret;
+ int32_t ret = HDF_SUCCESS;
uint32_t dataSize = 0;
ADM_LOG_DEBUG("entry.");
@@ -465,7 +691,7 @@ int32_t StreamHostWrite(const struct HdfDeviceIoClient *client, struct HdfSBuf *
ADM_LOG_ERR("input param is NULL.");
return HDF_FAILURE;
}
-
+ (void)memset_s(&transfer, sizeof(struct AudioTxData), 0, sizeof(struct AudioTxData));
if (!HdfSbufReadUint32(data, (uint32_t *)&(transfer.frames))) {
ADM_LOG_ERR("read request frames failed!");
return HDF_FAILURE;
@@ -477,13 +703,13 @@ int32_t StreamHostWrite(const struct HdfDeviceIoClient *client, struct HdfSBuf *
audioCard = StreamHostGetCardInstance(client);
if (audioCard == NULL || audioCard->rtd == NULL) {
- ADM_LOG_ERR("get card instance or rtd fail.");
+ ADM_LOG_ERR("get card instance or rtd failed.");
return HDF_FAILURE;
}
ret = StreamTransferWrite(audioCard, &transfer);
if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("write reg value fail ret=%d", ret);
+ ADM_LOG_ERR("write reg value failed ret=%d", ret);
return HDF_FAILURE;
}
@@ -495,13 +721,11 @@ int32_t StreamHostWrite(const struct HdfDeviceIoClient *client, struct HdfSBuf *
return HDF_SUCCESS;
}
-int32_t StreamHostRead(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
+static int32_t StreamHostRead(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
{
- struct AudioRuntimeDeivces *rtd = NULL;
- struct PlatformDevice *platform = NULL;
struct AudioCard *audioCard = NULL;
struct AudioRxData rxData;
- int ret;
+ int ret = HDF_SUCCESS;
ADM_LOG_DEBUG("entry.");
if (client == NULL || reply == NULL) {
@@ -511,22 +735,14 @@ int32_t StreamHostRead(const struct HdfDeviceIoClient *client, struct HdfSBuf *d
(void)data;
audioCard = StreamHostGetCardInstance(client);
- if (audioCard == NULL || audioCard->rtd == NULL) {
- ADM_LOG_ERR("get card instance or rtd fail.");
- return HDF_FAILURE;
- }
- rtd = audioCard->rtd;
-
- platform = rtd->platform;
- if (platform == NULL || platform->devData == NULL ||
- platform->devData->ops == NULL || platform->devData->ops->Read == NULL) {
- ADM_LOG_ERR("audioCard rtd platform is NULL.");
+ if (audioCard == NULL) {
+ ADM_LOG_ERR("get card instance or rtd failed.");
return HDF_FAILURE;
}
- ret = platform->devData->ops->Read(audioCard, &rxData);
+ ret = AudioPcmRead(audioCard, &rxData);
if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("platform read fail ret=%d", ret);
+ ADM_LOG_ERR("pcm read failed ret=%d", ret);
return HDF_FAILURE;
}
@@ -535,23 +751,25 @@ int32_t StreamHostRead(const struct HdfDeviceIoClient *client, struct HdfSBuf *d
return HDF_FAILURE;
}
- if (!HdfSbufWriteBuffer(reply, rxData.buf, (uint32_t)(rxData.bufSize))) {
- ADM_LOG_ERR("write request data buf failed!");
- return HDF_FAILURE;
- }
+ if (rxData.bufSize != 0) {
+ if (!HdfSbufWriteBuffer(reply, rxData.buf, (uint32_t)(rxData.bufSize))) {
+ ADM_LOG_ERR("write request data buf failed!");
+ return HDF_FAILURE;
+ }
- if (!HdfSbufWriteUint32(reply, (uint32_t)(rxData.frames))) {
- ADM_LOG_ERR("write frames failed!");
- return HDF_FAILURE;
+ if (!HdfSbufWriteUint32(reply, (uint32_t)(rxData.frames))) {
+ ADM_LOG_ERR("write frames failed!");
+ return HDF_FAILURE;
+ }
}
ADM_LOG_DEBUG("success.");
return HDF_SUCCESS;
}
-int32_t StreamHostMmapWrite(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
+static int32_t StreamHostMmapWrite(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
{
- struct AudioTxMmapData txMmapData;
+ struct AudioMmapData txMmapData;
struct AudioCard *audioCard = NULL;
uint64_t mAddress = 0;
ADM_LOG_DEBUG("entry.");
@@ -564,7 +782,12 @@ int32_t StreamHostMmapWrite(const struct HdfDeviceIoClient *client, struct HdfSB
return HDF_FAILURE;
}
+ (void)memset_s(&txMmapData, sizeof(struct AudioMmapData), 0, sizeof(struct AudioMmapData));
txMmapData.memoryAddress = (void *)((uintptr_t)mAddress);
+ if (txMmapData.memoryAddress == NULL) {
+ ADM_LOG_ERR("txMmapData.memoryAddress is NULL.");
+ return HDF_FAILURE;
+ }
if (!HdfSbufReadInt32(data, (uint32_t *)&(txMmapData.memoryFd))) {
ADM_LOG_ERR("render mmap read request memory fd failed!");
@@ -588,13 +811,14 @@ int32_t StreamHostMmapWrite(const struct HdfDeviceIoClient *client, struct HdfSB
}
audioCard = StreamHostGetCardInstance(client);
if (StreamTransferMmapWrite(audioCard, &txMmapData) != HDF_SUCCESS) {
- ADM_LOG_ERR("render mmap write reg value fail!");
+ ADM_LOG_ERR("render mmap write reg value failed!");
return HDF_FAILURE;
}
ADM_LOG_DEBUG("success.");
return HDF_SUCCESS;
}
-int32_t StreamHostMmapPositionWrite(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
+static int32_t StreamHostMmapPositionWrite(const struct HdfDeviceIoClient *client,
+ struct HdfSBuf *data, struct HdfSBuf *reply)
{
struct AudioCard *audioCard = NULL;
ADM_LOG_DEBUG("entry.");
@@ -603,28 +827,28 @@ int32_t StreamHostMmapPositionWrite(const struct HdfDeviceIoClient *client, stru
return HDF_FAILURE;
}
audioCard = StreamHostGetCardInstance(client);
- if (audioCard == NULL || audioCard->rtd == NULL || audioCard->rtd->platform == NULL) {
+ if (audioCard == NULL) {
ADM_LOG_ERR("audioCard instance is NULL.");
return HDF_FAILURE;
}
- struct PlatformHost *platformHost = PlatformHostFromDevice(audioCard->rtd->platform->device);
- if (platformHost == NULL) {
+ struct PlatformData *platformData = PlatformDataFromCard(audioCard);
+ if (platformData == NULL) {
ADM_LOG_ERR("platformHost instance is NULL.");
return HDF_FAILURE;
}
- if (!HdfSbufWriteUint64(reply, platformHost->renderBufInfo.framesPosition)) {
- ADM_LOG_ERR("render mmap write position fail!");
+ if (!HdfSbufWriteUint64(reply, platformData->renderBufInfo.framesPosition)) {
+ ADM_LOG_ERR("render mmap write position failed!");
return HDF_FAILURE;
}
ADM_LOG_DEBUG("success.");
return HDF_SUCCESS;
}
-int32_t StreamHostMmapRead(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
+static int32_t StreamHostMmapRead(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
{
uint64_t mAddress = 0;
struct AudioCard *audioCard = NULL;
- struct AudioRxMmapData rxMmapData;
+ struct AudioMmapData rxMmapData;
ADM_LOG_DEBUG("entry.");
if (client == NULL || reply == NULL) {
ADM_LOG_ERR("input param is NULL.");
@@ -634,7 +858,13 @@ int32_t StreamHostMmapRead(const struct HdfDeviceIoClient *client, struct HdfSBu
ADM_LOG_ERR("capture mmap read request memory address failed!");
return HDF_FAILURE;
}
+
+ (void)memset_s(&rxMmapData, sizeof(struct AudioMmapData), 0, sizeof(struct AudioMmapData));
rxMmapData.memoryAddress = (void *)((uintptr_t)mAddress);
+ if (rxMmapData.memoryAddress == NULL) {
+ ADM_LOG_ERR("rxMmapData.memoryAddress is NULL.");
+ return HDF_FAILURE;
+ }
if (!HdfSbufReadInt32(data, (uint32_t *)&(rxMmapData.memoryFd))) {
ADM_LOG_ERR("capture mmap read request memory fd failed!");
@@ -658,14 +888,15 @@ int32_t StreamHostMmapRead(const struct HdfDeviceIoClient *client, struct HdfSBu
}
audioCard = StreamHostGetCardInstance(client);
if (StreamTransferMmapRead(audioCard, &rxMmapData) != HDF_SUCCESS) {
- ADM_LOG_ERR("capture mmap read reg value fail!");
+ ADM_LOG_ERR("capture mmap read reg value failed!");
return HDF_FAILURE;
}
ADM_LOG_DEBUG("success.");
return HDF_SUCCESS;
}
-int32_t StreamHostMmapPositionRead(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
+static int32_t StreamHostMmapPositionRead(const struct HdfDeviceIoClient *client,
+ struct HdfSBuf *data, struct HdfSBuf *reply)
{
struct AudioCard *audioCard = NULL;
ADM_LOG_DEBUG("entry.");
@@ -674,96 +905,136 @@ int32_t StreamHostMmapPositionRead(const struct HdfDeviceIoClient *client, struc
return HDF_FAILURE;
}
audioCard = StreamHostGetCardInstance(client);
- if (audioCard == NULL || audioCard->rtd == NULL || audioCard->rtd->platform == NULL) {
+ if (audioCard == NULL) {
ADM_LOG_ERR("audioCard is NULL.");
return HDF_FAILURE;
}
- struct PlatformHost *platformHost = PlatformHostFromDevice(audioCard->rtd->platform->device);
- if (platformHost == NULL) {
+ struct PlatformData *platformData = PlatformDataFromCard(audioCard);
+ if (platformData == NULL) {
ADM_LOG_ERR("platformHost is NULL.");
return HDF_FAILURE;
}
- if (!HdfSbufWriteUint64(reply, platformHost->captureBufInfo.framesPosition)) {
- ADM_LOG_ERR("render mmap write position fail!");
+ if (!HdfSbufWriteUint64(reply, platformData->captureBufInfo.framesPosition)) {
+ ADM_LOG_ERR("render mmap write position failed!");
return HDF_FAILURE;
}
ADM_LOG_DEBUG("success.");
return HDF_SUCCESS;
}
-int32_t StreamHostRenderStart(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
+static int32_t StreamTriggerRouteImpl(const struct AudioCard *audioCard, const struct AudioRuntimeDeivces *rtd,
+ enum StreamDispMethodCmd methodCmd)
+{
+ int32_t ret = HDF_SUCCESS;
+ struct DaiDevice *cpuDai = NULL;
+ struct DaiDevice *codecDai = NULL;
+ struct DaiDevice *accessoryDai = NULL;
+ struct DaiDevice *dspDai = NULL;
+ if (audioCard == NULL || rtd == NULL) {
+ ADM_LOG_ERR("input param is NULL.");
+ return HDF_FAILURE;
+ }
+ cpuDai = rtd->cpuDai;
+ if (cpuDai != NULL && cpuDai->devData != NULL && cpuDai->devData->ops != NULL &&
+ cpuDai->devData->ops->Trigger != NULL) {
+ ret = cpuDai->devData->ops->Trigger(audioCard, methodCmd, cpuDai);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("cpuDai Trigger failed.");
+ return HDF_FAILURE;
+ }
+ }
+ codecDai = rtd->codecDai;
+ if (codecDai != NULL && codecDai->devData != NULL && codecDai->devData->ops != NULL &&
+ codecDai->devData->ops->Trigger != NULL) {
+ ret = codecDai->devData->ops->Trigger(audioCard, methodCmd, codecDai);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("codecDai Trigger failed.");
+ return HDF_FAILURE;
+ }
+ }
+ accessoryDai = rtd->accessoryDai;
+ if (accessoryDai != NULL && accessoryDai->devData != NULL && accessoryDai->devData->ops != NULL &&
+ accessoryDai->devData->ops->Trigger != NULL) {
+ ret = accessoryDai->devData->ops->Trigger(audioCard, methodCmd, accessoryDai);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("accessoryDai Trigger failed.");
+ return HDF_FAILURE;
+ }
+ }
+ dspDai = rtd->dspDai;
+ if (dspDai != NULL && dspDai->devData != NULL && dspDai->devData->ops != NULL &&
+ dspDai->devData->ops->Trigger != NULL) {
+ ret = dspDai->devData->ops->Trigger(audioCard, methodCmd, dspDai);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("dspDai Trigger failed.");
+ return HDF_FAILURE;
+ }
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t StreamHostRenderStart(const struct HdfDeviceIoClient *client,
+ struct HdfSBuf *data, struct HdfSBuf *reply)
{
struct AudioRuntimeDeivces *rtd = NULL;
- struct PlatformDevice *platform = NULL;
struct AudioCard *audioCard = NULL;
- int ret;
+ int ret = HDF_SUCCESS;
ADM_LOG_DEBUG("entry.");
-
if (client == NULL) {
ADM_LOG_ERR("RenderStart input param is NULL.");
return HDF_FAILURE;
}
-
(void)data;
(void)reply;
-
audioCard = StreamHostGetCardInstance(client);
if (audioCard == NULL || audioCard->rtd == NULL) {
- ADM_LOG_ERR("RenderStart get card instance or rtd fail.");
+ ADM_LOG_ERR("RenderStart get card instance or rtd failed.");
return HDF_FAILURE;
}
rtd = audioCard->rtd;
-
- platform = rtd->platform;
- if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL ||
- platform->devData->ops->RenderStart == NULL) {
- ADM_LOG_ERR("audioCard rtd platform is NULL.");
+ audioCard->standbyMode = AUDIO_SAPM_TURN_STANDBY_LATER;
+ ret = StreamTriggerRouteImpl(audioCard, rtd, AUDIO_DRV_PCM_IOCTL_RENDER_START);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("StreamTriggerRouteImpl failed");
return HDF_FAILURE;
}
-
- ret = platform->devData->ops->RenderStart(audioCard);
+ ret = AudioRenderTrigger(audioCard, AUDIO_DRV_PCM_IOCTL_RENDER_START);
if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("platform render start fail ret=%d", ret);
+ ADM_LOG_ERR("platform render start failed ret=%d", ret);
return HDF_ERR_IO;
}
-
ADM_LOG_DEBUG("success.");
return HDF_SUCCESS;
}
-int32_t StreamHostCaptureStart(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
+static int32_t StreamHostCaptureStart(const struct HdfDeviceIoClient *client,
+ struct HdfSBuf *data, struct HdfSBuf *reply)
{
struct AudioRuntimeDeivces *rtd = NULL;
- struct PlatformDevice *platform = NULL;
struct AudioCard *audioCard = NULL;
- int ret;
+ int ret = HDF_SUCCESS;
ADM_LOG_DEBUG("entry.");
-
if (client == NULL) {
ADM_LOG_ERR("CaptureStart input param is NULL.");
return HDF_FAILURE;
}
-
(void)data;
(void)reply;
-
audioCard = StreamHostGetCardInstance(client);
if (audioCard == NULL || audioCard->rtd == NULL) {
- ADM_LOG_ERR("CaptureStart get card instance or rtd fail.");
+ ADM_LOG_ERR("CaptureStart get card instance or rtd failed.");
return HDF_FAILURE;
}
+ audioCard->standbyMode = AUDIO_SAPM_TURN_STANDBY_LATER;
rtd = audioCard->rtd;
-
- platform = rtd->platform;
- if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL ||
- platform->devData->ops->CaptureStart == NULL) {
- ADM_LOG_ERR("audioCard rtd platform is NULL.");
+ ret = StreamTriggerRouteImpl(audioCard, rtd, AUDIO_DRV_PCM_IOCTL_CAPTURE_START);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("StreamTriggerRouteImpl failed");
return HDF_FAILURE;
}
-
- ret = platform->devData->ops->CaptureStart(audioCard);
+ ret = AudioCaptureTrigger(audioCard, AUDIO_DRV_PCM_IOCTL_CAPTURE_START);
if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("platform capture start fail ret=%d", ret);
+ ADM_LOG_ERR("platform capture start failed ret=%d", ret);
return HDF_ERR_IO;
}
@@ -771,40 +1042,67 @@ int32_t StreamHostCaptureStart(const struct HdfDeviceIoClient *client, struct Hd
return HDF_SUCCESS;
}
-int32_t StreamHostRenderStop(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
+static int32_t StreamHostRenderStop(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
struct HdfSBuf *reply)
{
struct AudioRuntimeDeivces *rtd = NULL;
- struct PlatformDevice *platform = NULL;
struct AudioCard *audioCard = NULL;
- int ret;
+ int ret = HDF_SUCCESS;
ADM_LOG_DEBUG("entry.");
-
if (client == NULL) {
ADM_LOG_ERR("RenderStop input param is NULL.");
return HDF_FAILURE;
}
-
- (void)data;
(void)reply;
-
audioCard = StreamHostGetCardInstance(client);
if (audioCard == NULL || audioCard->rtd == NULL) {
- ADM_LOG_ERR("RenderStop get card instance or rtd fail.");
+ ADM_LOG_ERR("RenderStop get card instance or rtd failed.");
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufReadUint32(data, &audioCard->standbyMode)) {
+ ADM_LOG_ERR("read request streamType failed!");
return HDF_FAILURE;
}
rtd = audioCard->rtd;
+ ret = StreamTriggerRouteImpl(audioCard, rtd, AUDIO_DRV_PCM_IOCTL_RENDER_STOP);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("StreamTriggerRouteImpl failed");
+ return HDF_FAILURE;
+ }
+ ret = AudioRenderTrigger(audioCard, AUDIO_DRV_PCM_IOCTL_RENDER_STOP);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("platform render stop failed ret=%d", ret);
+ return HDF_ERR_IO;
+ }
+
+ ADM_LOG_DEBUG("success.");
+ return HDF_SUCCESS;
+}
+
+static int32_t StreamHostRenderClose(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
+ struct HdfSBuf *reply)
+{
+ struct AudioCard *audioCard = NULL;
+ int ret;
+ ADM_LOG_DEBUG("entry.");
+
+ if (client == NULL) {
+ ADM_LOG_ERR("RenderClose input param is NULL.");
+ return HDF_FAILURE;
+ }
+
+ (void)data;
+ (void)reply;
- platform = rtd->platform;
- if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL ||
- platform->devData->ops->RenderStop == NULL) {
- ADM_LOG_ERR("audioCard rtd platform is NULL.");
+ audioCard = StreamHostGetCardInstance(client);
+ if (audioCard == NULL || audioCard->rtd == NULL) {
+ ADM_LOG_ERR("RenderStop get card instance or rtd failed.");
return HDF_FAILURE;
}
- ret = platform->devData->ops->RenderStop(audioCard);
+ ret = AudioRenderClose(audioCard);
if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("platform render stop fail ret=%d", ret);
+ ADM_LOG_ERR("platform RenderClose failed ret=%d", ret);
return HDF_ERR_IO;
}
@@ -812,12 +1110,13 @@ int32_t StreamHostRenderStop(const struct HdfDeviceIoClient *client, struct HdfS
return HDF_SUCCESS;
}
-int32_t StreamHostCaptureStop(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
+
+static int32_t StreamHostCaptureStop(const struct HdfDeviceIoClient *client,
+ struct HdfSBuf *data, struct HdfSBuf *reply)
{
struct AudioRuntimeDeivces *rtd = NULL;
- struct PlatformDevice *platform = NULL;
struct AudioCard *audioCard = NULL;
- int ret;
+ int ret = HDF_SUCCESS;
ADM_LOG_DEBUG("entry.");
if (client == NULL) {
@@ -825,26 +1124,58 @@ int32_t StreamHostCaptureStop(const struct HdfDeviceIoClient *client, struct Hdf
return HDF_FAILURE;
}
- (void)data;
(void)reply;
audioCard = StreamHostGetCardInstance(client);
if (audioCard == NULL || audioCard->rtd == NULL) {
- ADM_LOG_ERR("CaptureStop get card instance or rtd fail.");
+ ADM_LOG_ERR("CaptureStop get card instance or rtd failed.");
+ return HDF_FAILURE;
+ }
+
+ if (!HdfSbufReadUint32(data, &audioCard->standbyMode)) {
+ ADM_LOG_ERR("read request streamType failed!");
return HDF_FAILURE;
}
rtd = audioCard->rtd;
+ ret = StreamTriggerRouteImpl(audioCard, rtd, AUDIO_DRV_PCM_IOCTL_CAPTURE_STOP);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("StreamTriggerRouteImpl failed");
+ return HDF_FAILURE;
+ }
+ ret = AudioCaptureTrigger(audioCard, AUDIO_DRV_PCM_IOCTL_CAPTURE_STOP);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("platform capture stop failed ret=%d", ret);
+ return HDF_ERR_IO;
+ }
+
+ ADM_LOG_DEBUG("success.");
+ return HDF_SUCCESS;
+}
+
+static int32_t StreamHostCaptureClose(const struct HdfDeviceIoClient *client,
+ struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ struct AudioCard *audioCard = NULL;
+ int ret;
+ ADM_LOG_DEBUG("entry.");
- platform = rtd->platform;
- if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL ||
- platform->devData->ops->CaptureStop == NULL) {
- ADM_LOG_ERR("audioCard rtd platform is NULL.");
+ if (client == NULL) {
+ ADM_LOG_ERR("CaptureClose input param is NULL.");
+ return HDF_FAILURE;
+ }
+
+ (void)data;
+ (void)reply;
+
+ audioCard = StreamHostGetCardInstance(client);
+ if (audioCard == NULL || audioCard->rtd == NULL) {
+ ADM_LOG_ERR("CaptureStop get card instance or rtd failed.");
return HDF_FAILURE;
}
- ret = platform->devData->ops->CaptureStop(audioCard);
+ ret = AudioCaptureClose(audioCard);
if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("platform capture stop fail ret=%d", ret);
+ ADM_LOG_ERR("platform capture close failed ret=%d", ret);
return HDF_ERR_IO;
}
@@ -852,12 +1183,13 @@ int32_t StreamHostCaptureStop(const struct HdfDeviceIoClient *client, struct Hdf
return HDF_SUCCESS;
}
-int32_t StreamHostRenderPause(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
+
+static int32_t StreamHostRenderPause(const struct HdfDeviceIoClient *client,
+ struct HdfSBuf *data, struct HdfSBuf *reply)
{
struct AudioRuntimeDeivces *rtd = NULL;
- struct PlatformDevice *platform = NULL;
struct AudioCard *audioCard = NULL;
- int ret;
+ int ret = HDF_SUCCESS;
ADM_LOG_DEBUG("entry.");
if (client == NULL) {
@@ -870,21 +1202,18 @@ int32_t StreamHostRenderPause(const struct HdfDeviceIoClient *client, struct Hdf
audioCard = StreamHostGetCardInstance(client);
if (audioCard == NULL || audioCard->rtd == NULL) {
- ADM_LOG_ERR("RenderPause get card instance or rtd fail.");
+ ADM_LOG_ERR("RenderPause get card instance or rtd failed.");
return HDF_FAILURE;
}
rtd = audioCard->rtd;
-
- platform = rtd->platform;
- if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL ||
- platform->devData->ops->RenderPause == NULL) {
- ADM_LOG_ERR("audioCard rtd platform is NULL.");
+ ret = StreamTriggerRouteImpl(audioCard, rtd, AUDIO_DRV_PCM_IOCTL_RENDER_PAUSE);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("StreamTriggerRouteImpl failed");
return HDF_FAILURE;
}
-
- ret = platform->devData->ops->RenderPause(audioCard);
+ ret = AudioRenderTrigger(audioCard, AUDIO_DRV_PCM_IOCTL_RENDER_PAUSE);
if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("platform render pause fail ret=%d", ret);
+ ADM_LOG_ERR("platform render pause failed ret=%d", ret);
return HDF_ERR_IO;
}
@@ -892,13 +1221,12 @@ int32_t StreamHostRenderPause(const struct HdfDeviceIoClient *client, struct Hdf
return HDF_SUCCESS;
}
-int32_t StreamHostCapturePause(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
+static int32_t StreamHostCapturePause(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
struct HdfSBuf *reply)
{
struct AudioRuntimeDeivces *rtd = NULL;
- struct PlatformDevice *platform = NULL;
struct AudioCard *audioCard = NULL;
- int ret;
+ int ret = HDF_SUCCESS;
ADM_LOG_DEBUG("entry.");
if (client == NULL) {
@@ -911,21 +1239,18 @@ int32_t StreamHostCapturePause(const struct HdfDeviceIoClient *client, struct Hd
audioCard = StreamHostGetCardInstance(client);
if (audioCard == NULL || audioCard->rtd == NULL) {
- ADM_LOG_ERR("CapturePause get card instance or rtd fail.");
+ ADM_LOG_ERR("CapturePause get card instance or rtd failed.");
return HDF_FAILURE;
}
rtd = audioCard->rtd;
-
- platform = rtd->platform;
- if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL ||
- platform->devData->ops->CapturePause == NULL) {
- ADM_LOG_ERR("audioCard rtd platform is NULL.");
+ ret = StreamTriggerRouteImpl(audioCard, rtd, AUDIO_DRV_PCM_IOCTL_CAPTURE_PAUSE);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("StreamTriggerRouteImpl failed");
return HDF_FAILURE;
}
-
- ret = platform->devData->ops->CapturePause(audioCard);
+ ret = AudioCaptureTrigger(audioCard, AUDIO_DRV_PCM_IOCTL_CAPTURE_PAUSE);
if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("platform captur pause fail ret=%d", ret);
+ ADM_LOG_ERR("platform captur pause failed ret=%d", ret);
return HDF_ERR_IO;
}
@@ -933,11 +1258,10 @@ int32_t StreamHostCapturePause(const struct HdfDeviceIoClient *client, struct Hd
return HDF_SUCCESS;
}
-int32_t StreamHostRenderResume(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
+static int32_t StreamHostRenderResume(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
struct HdfSBuf *reply)
{
struct AudioRuntimeDeivces *rtd = NULL;
- struct PlatformDevice *platform = NULL;
struct AudioCard *audioCard = NULL;
int ret;
ADM_LOG_DEBUG("entry.");
@@ -952,21 +1276,18 @@ int32_t StreamHostRenderResume(const struct HdfDeviceIoClient *client, struct Hd
audioCard = StreamHostGetCardInstance(client);
if (audioCard == NULL || audioCard->rtd == NULL) {
- ADM_LOG_ERR("RenderResume get card instance or rtd fail.");
+ ADM_LOG_ERR("RenderResume get card instance or rtd failed.");
return HDF_FAILURE;
}
rtd = audioCard->rtd;
-
- platform = rtd->platform;
- if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL ||
- platform->devData->ops->RenderResume == NULL) {
- ADM_LOG_ERR("audioCard rtd platform is NULL.");
+ ret = StreamTriggerRouteImpl(audioCard, rtd, AUDIO_DRV_PCM_IOCTL_RENDER_RESUME);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("StreamTriggerRouteImpl failed");
return HDF_FAILURE;
}
-
- ret = platform->devData->ops->RenderResume(audioCard);
+ ret = AudioRenderTrigger(audioCard, AUDIO_DRV_PCM_IOCTL_RENDER_RESUME);
if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("platform RenderResume fail ret=%d", ret);
+ ADM_LOG_ERR("platform RenderResume failed ret=%d", ret);
return HDF_ERR_IO;
}
@@ -974,13 +1295,12 @@ int32_t StreamHostRenderResume(const struct HdfDeviceIoClient *client, struct Hd
return HDF_SUCCESS;
}
-int32_t StreamHostCaptureResume(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
+static int32_t StreamHostCaptureResume(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
struct HdfSBuf *reply)
{
struct AudioRuntimeDeivces *rtd = NULL;
- struct PlatformDevice *platform = NULL;
struct AudioCard *audioCard = NULL;
- int ret;
+ int ret = HDF_SUCCESS;
ADM_LOG_DEBUG("entry.");
if (client == NULL) {
@@ -993,21 +1313,18 @@ int32_t StreamHostCaptureResume(const struct HdfDeviceIoClient *client, struct H
audioCard = StreamHostGetCardInstance(client);
if (audioCard == NULL || audioCard->rtd == NULL) {
- ADM_LOG_ERR("CaptureResume get card instance or rtd fail.");
+ ADM_LOG_ERR("CaptureResume get card instance or rtd failed.");
return HDF_FAILURE;
}
rtd = audioCard->rtd;
-
- platform = rtd->platform;
- if (platform == NULL || platform->devData == NULL || platform->devData->ops == NULL ||
- platform->devData->ops->CaptureResume == NULL) {
- ADM_LOG_ERR("audioCard rtd platform is NULL.");
+ ret = StreamTriggerRouteImpl(audioCard, rtd, AUDIO_DRV_PCM_IOCTL_CAPTURE_RESUME);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("StreamTriggerRouteImpl failed");
return HDF_FAILURE;
}
-
- ret = platform->devData->ops->CaptureResume(audioCard);
+ ret = AudioCaptureTrigger(audioCard, AUDIO_DRV_PCM_IOCTL_CAPTURE_RESUME);
if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("platform CaptureResume fail ret=%d", ret);
+ ADM_LOG_ERR("platform CaptureResume failed ret=%d", ret);
return HDF_ERR_IO;
}
@@ -1015,13 +1332,13 @@ int32_t StreamHostCaptureResume(const struct HdfDeviceIoClient *client, struct H
return HDF_SUCCESS;
}
-int32_t StreamHostDspDecode(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
+static int32_t StreamHostDspDecode(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
struct HdfSBuf *reply)
{
struct AudioRuntimeDeivces *rtd = NULL;
struct DspDevice *dspDev = NULL;
struct AudioCard *audioCard = NULL;
- int ret;
+ int ret = HDF_SUCCESS;
ADM_LOG_DEBUG("Dsp Decode Entry.");
if (client == NULL) {
@@ -1033,20 +1350,20 @@ int32_t StreamHostDspDecode(const struct HdfDeviceIoClient *client, struct HdfSB
audioCard = StreamHostGetCardInstance(client);
if (audioCard == NULL || audioCard->rtd == NULL) {
- ADM_LOG_ERR("DspDecode get card instance or rtd fail.");
+ ADM_LOG_ERR("DspDecode get card instance or rtd failed.");
return HDF_FAILURE;
}
rtd = audioCard->rtd;
dspDev = rtd->dsp;
- if (dspDev == NULL || dspDev->devData == NULL || dspDev->devData->decode == NULL) {
+ if (dspDev == NULL || dspDev->devData == NULL || dspDev->devData->Decode == NULL) {
ADM_LOG_ERR("audioCard rtd dsp is NULL.");
return HDF_FAILURE;
}
- ret = dspDev->devData->decode(audioCard, (void*)data, dspDev);
+ ret = dspDev->devData->Decode(audioCard, (void*)data, dspDev);
if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("DeCode render pause fail ret=%d", ret);
+ ADM_LOG_ERR("DeCode render pause failed ret=%d", ret);
return HDF_ERR_IO;
}
@@ -1054,13 +1371,13 @@ int32_t StreamHostDspDecode(const struct HdfDeviceIoClient *client, struct HdfSB
return HDF_SUCCESS;
}
-int32_t StreamHostDspEncode(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
+static int32_t StreamHostDspEncode(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
struct HdfSBuf *reply)
{
struct AudioRuntimeDeivces *rtd = NULL;
struct DspDevice *dspDev = NULL;
struct AudioCard *audioCard = NULL;
- int ret;
+ int ret = HDF_SUCCESS;
ADM_LOG_DEBUG("Dsp Encode Entry.");
if (client == NULL) {
@@ -1072,20 +1389,20 @@ int32_t StreamHostDspEncode(const struct HdfDeviceIoClient *client, struct HdfSB
audioCard = StreamHostGetCardInstance(client);
if (audioCard == NULL || audioCard->rtd == NULL) {
- ADM_LOG_ERR("DspEncode get card instance or rtd fail.");
+ ADM_LOG_ERR("DspEncode get card instance or rtd failed.");
return HDF_FAILURE;
}
rtd = audioCard->rtd;
dspDev = rtd->dsp;
- if (dspDev == NULL || dspDev->devData == NULL || dspDev->devData->encode == NULL) {
+ if (dspDev == NULL || dspDev->devData == NULL || dspDev->devData->Encode == NULL) {
ADM_LOG_ERR("audioCard rtd dsp is NULL.");
return HDF_FAILURE;
}
- ret = dspDev->devData->encode(audioCard, (void*)data, dspDev);
+ ret = dspDev->devData->Encode(audioCard, (void*)data, dspDev);
if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("EnCode render pause fail ret=%d", ret);
+ ADM_LOG_ERR("EnCode render pause failed ret=%d", ret);
return HDF_ERR_IO;
}
@@ -1093,13 +1410,13 @@ int32_t StreamHostDspEncode(const struct HdfDeviceIoClient *client, struct HdfSB
return HDF_SUCCESS;
}
-int32_t StreamHostDspEqualizer(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
+static int32_t StreamHostDspEqualizer(const struct HdfDeviceIoClient *client, struct HdfSBuf *data,
struct HdfSBuf *reply)
{
struct AudioRuntimeDeivces *rtd = NULL;
struct DspDevice *dspDev = NULL;
struct AudioCard *audioCard = NULL;
- int ret;
+ int ret = HDF_SUCCESS;
ADM_LOG_DEBUG("Dsp Equalizer Entry.");
if (client == NULL) {
@@ -1111,7 +1428,7 @@ int32_t StreamHostDspEqualizer(const struct HdfDeviceIoClient *client, struct Hd
audioCard = StreamHostGetCardInstance(client);
if (audioCard == NULL || audioCard->rtd == NULL) {
- ADM_LOG_ERR("DspEqualizer get card instance or rtd fail.");
+ ADM_LOG_ERR("DspEqualizer get card instance or rtd failed.");
return HDF_FAILURE;
}
rtd = audioCard->rtd;
@@ -1124,7 +1441,7 @@ int32_t StreamHostDspEqualizer(const struct HdfDeviceIoClient *client, struct Hd
ret = dspDev->devData->Equalizer(audioCard, (void*)data, dspDev);
if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("Equalizer render pause fail ret=%d", ret);
+ ADM_LOG_ERR("Equalizer render pause failed ret=%d", ret);
return HDF_ERR_IO;
}
@@ -1133,47 +1450,42 @@ int32_t StreamHostDspEqualizer(const struct HdfDeviceIoClient *client, struct Hd
}
static struct StreamDispCmdHandleList g_streamDispCmdHandle[] = {
- {AUDIO_DRV_PCM_IOCTRL_HW_PARAMS, StreamHostHwParams},
- {AUDIO_DRV_PCM_IOCTRL_RENDER_PREPARE, StreamHostRenderPrepare},
- {AUDIO_DRV_PCM_IOCTRL_CAPTURE_PREPARE, StreamHostCapturePrepare},
- {AUDIO_DRV_PCM_IOCTRL_WRITE, StreamHostWrite},
- {AUDIO_DRV_PCM_IOCTRL_READ, StreamHostRead},
- {AUDIO_DRV_PCM_IOCTRL_RENDER_START, StreamHostRenderStart},
- {AUDIO_DRV_PCM_IOCTRL_RENDER_STOP, StreamHostRenderStop},
- {AUDIO_DRV_PCM_IOCTRL_CAPTURE_START, StreamHostCaptureStart},
- {AUDIO_DRV_PCM_IOCTRL_CAPTURE_STOP, StreamHostCaptureStop},
- {AUDIO_DRV_PCM_IOCTRL_RENDER_PAUSE, StreamHostRenderPause},
- {AUDIO_DRV_PCM_IOCTRL_CAPTURE_PAUSE, StreamHostCapturePause},
- {AUDIO_DRV_PCM_IOCTRL_RENDER_RESUME, StreamHostRenderResume},
- {AUDIO_DRV_PCM_IOCTRL_CAPTURE_RESUME, StreamHostCaptureResume},
+ {AUDIO_DRV_PCM_IOCTL_WRITE, StreamHostWrite},
+ {AUDIO_DRV_PCM_IOCTL_READ, StreamHostRead},
+ {AUDIO_DRV_PCM_IOCTL_HW_PARAMS, StreamHostHwParams},
+ {AUDIO_DRV_PCM_IOCTL_RENDER_PREPARE, StreamHostRenderPrepare},
+ {AUDIO_DRV_PCM_IOCTL_CAPTURE_PREPARE, StreamHostCapturePrepare},
+ {AUDIO_DRV_PCM_IOCTL_RENDER_OPEN, StreamHostRenderOpen},
+ {AUDIO_DRV_PCM_IOCTL_RENDER_CLOSE, StreamHostRenderClose},
+ {AUDIO_DRV_PCM_IOCTL_RENDER_START, StreamHostRenderStart},
+ {AUDIO_DRV_PCM_IOCTL_RENDER_STOP, StreamHostRenderStop},
+ {AUDIO_DRV_PCM_IOCTL_CAPTURE_OPEN, StreamHostCaptureOpen},
+ {AUDIO_DRV_PCM_IOCTL_CAPTURE_CLOSE, StreamHostCaptureClose},
+ {AUDIO_DRV_PCM_IOCTL_CAPTURE_START, StreamHostCaptureStart},
+ {AUDIO_DRV_PCM_IOCTL_CAPTURE_STOP, StreamHostCaptureStop},
+ {AUDIO_DRV_PCM_IOCTL_RENDER_PAUSE, StreamHostRenderPause},
+ {AUDIO_DRV_PCM_IOCTL_CAPTURE_PAUSE, StreamHostCapturePause},
+ {AUDIO_DRV_PCM_IOCTL_RENDER_RESUME, StreamHostRenderResume},
+ {AUDIO_DRV_PCM_IOCTL_CAPTURE_RESUME, StreamHostCaptureResume},
{AUDIO_DRV_PCM_IOCTL_MMAP_BUFFER, StreamHostMmapWrite},
{AUDIO_DRV_PCM_IOCTL_MMAP_BUFFER_CAPTURE, StreamHostMmapRead},
{AUDIO_DRV_PCM_IOCTL_MMAP_POSITION, StreamHostMmapPositionWrite},
{AUDIO_DRV_PCM_IOCTL_MMAP_POSITION_CAPTURE, StreamHostMmapPositionRead},
- {AUDIO_DRV_PCM_IOCTRL_DSP_DECODE, StreamHostDspDecode},
- {AUDIO_DRV_PCM_IOCTRL_DSP_ENCODE, StreamHostDspEncode},
- {AUDIO_DRV_PCM_IOCTRL_DSP_EQUALIZER, StreamHostDspEqualizer},
+ {AUDIO_DRV_PCM_IOCTL_DSPDECODE, StreamHostDspDecode},
+ {AUDIO_DRV_PCM_IOCTL_DSPENCODE, StreamHostDspEncode},
+ {AUDIO_DRV_PCM_IOCTL_DSPEQUALIZER, StreamHostDspEqualizer},
};
-int32_t StreamDispatch(struct HdfDeviceIoClient *client, int cmdId,
- struct HdfSBuf *data, struct HdfSBuf *reply)
+static int32_t StreamDispatch(struct HdfDeviceIoClient *client, int cmdId,
+ struct HdfSBuf *data, struct HdfSBuf *reply)
{
- unsigned int i;
-
- if ((client == NULL) || (data == NULL) || (reply == NULL)) {
- return HDF_ERR_INVALID_PARAM;
- }
-
- if (cmdId >= AUDIO_DRV_PCM_IOCTRL_BUTT || cmdId < 0) {
- ADM_LOG_ERR("invalid [cmdId=%d]", cmdId);
- return HDF_FAILURE;
- }
-
- for (i = 0; i < sizeof(g_streamDispCmdHandle) / sizeof(g_streamDispCmdHandle[0]); ++i) {
+ unsigned int count = sizeof(g_streamDispCmdHandle) / sizeof(g_streamDispCmdHandle[0]);
+ for (unsigned int i = 0; i < count; ++i) {
if ((cmdId == (int)(g_streamDispCmdHandle[i].cmd)) && (g_streamDispCmdHandle[i].func != NULL)) {
return g_streamDispCmdHandle[i].func(client, data, reply);
}
}
+ ADM_LOG_ERR("invalid [cmdId=%d]", cmdId);
return HDF_FAILURE;
}
@@ -1185,7 +1497,7 @@ static struct StreamHost *StreamHostCreateAndBind(struct HdfDeviceObject *device
struct StreamHost *streamHost = (struct StreamHost *)OsalMemCalloc(sizeof(*streamHost));
if (streamHost == NULL) {
- ADM_LOG_ERR("malloc host fail!");
+ ADM_LOG_ERR("malloc host failed!");
return NULL;
}
streamHost->device = device;
diff --git a/model/audio/sapm/include/audio_sapm.h b/model/audio/sapm/include/audio_sapm.h
index 0eaa935cbdd0e776d4d93294158cb72dc3ac1578..20c0f6568a3752ea942221271c8d476ac3804c79 100755
--- a/model/audio/sapm/include/audio_sapm.h
+++ b/model/audio/sapm/include/audio_sapm.h
@@ -17,28 +17,12 @@ extern "C" {
#endif
#endif /* __cplusplus */
-#define SAPM_POLL_TIME 10000 /* 10s */
-#define SAPM_SLEEP_TIME (3 * 60000) /* 3min */
-
-#define MIXER_REG_ADDR 10 /* mixer address -- Temporarily defined as this value */
-
-#define SAPM_POWER_DOWN 0
-#define SAPM_POWER_UP 1
-
-#define CONNECT_CODEC_PIN 1
-#define UNCONNECT_CODEC_PIN 0
-
-#define EXIST_EXTERNAL_WIDGET 1
-#define UNEXIST_EXTERNAL_WIDGET 1
-
-#define CONNECT_SINK_AND_SOURCE 1
-#define UNCONNECT_SINK_AND_SOURCE 0
-
/* sapm widget types */
enum AudioSapmType {
AUDIO_SAPM_INPUT = 0, /* input pin */
AUDIO_SAPM_OUTPUT, /* output pin */
AUDIO_SAPM_MUX, /* selects 1 analog signal from many inputs */
+ AUDIO_SAPM_DEMUX, /* connects the input to one of multiple outputs */
AUDIO_SAPM_VIRT_MUX, /* virtual version of snd_soc_dapm_mux */
AUDIO_SAPM_VALUE_MUX, /* selects 1 analog signal from many inputs */
AUDIO_SAPM_MIXER, /* mixes several analog signals together */
@@ -57,31 +41,14 @@ enum AudioSapmType {
AUDIO_SAPM_PRE, /* machine specific pre component - exec first */
AUDIO_SAPM_POST, /* machine specific post component - exec last */
AUDIO_SAPM_SUPPLY, /* power/clock supply */
+ AUDIO_SAPM_REGULATOR_SUPPLY, /* external regulator */
+ AUDIO_SAPM_CLOCK_SUPPLY, /* external clock */
AUDIO_SAPM_AIF_IN, /* audio interface input */
AUDIO_SAPM_AIF_OUT, /* audio interface output */
+ AUDIO_SAPM_SIGGEN, /* signal generator */
+ AUDIO_SAPM_SINK,
};
-/* component has no PM register bit */
-#define AUDIO_SAPM_NOPM (-1)
-
-/* dapm stream operations */
-#define AUDIO_SAPM_STREAM_NOP 0x0
-#define AUDIO_SAPM_STREAM_START 0x1
-#define AUDIO_SAPM_STREAM_STOP 0x2
-#define AUDIO_SAPM_STREAM_SUSPEND 0x4
-#define AUDIO_SAPM_STREAM_RESUME 0x8
-#define AUDIO_SAPM_STREAM_PAUSE_PUSH 0x10
-#define AUDIO_SAPM_STREAM_PAUSE_RELEASE 0x20
-
-/* sapm event types */
-#define AUDIO_SAPM_PRE_PMU 0x1 /* before component power up */
-#define AUDIO_SAPM_POST_PMU 0x2 /* after component power up */
-#define AUDIO_SAPM_PRE_PMD 0x4 /* before component power down */
-#define AUDIO_SAPM_POST_PMD 0x8 /* after component power down */
-#define AUDIO_SAPM_PRE_REG 0x10 /* before audio path setup */
-#define AUDIO_SAPM_POST_REG 0x20 /* after audio path setup */
-#define AUDIO_SAPM_PRE_POST_PMD (AUDIO_SAPM_PRE_PMD | AUDIO_SAPM_POST_PMD)
-
enum AudioBiasLevel {
AUDIO_BIAS_OFF = 0,
AUDIO_BIAS_STANDBY = 1,
@@ -201,9 +168,7 @@ int32_t AudioSapmNewComponents(struct AudioCard *audioCard,
int32_t AudioSapmAddRoutes(struct AudioCard *audioCard,
const struct AudioSapmRoute *route, int32_t routeMaxNum);
int32_t AudioSapmNewControls(struct AudioCard *audioCard);
-int AudioSapmPowerComponents(struct AudioCard *audioCard);
int32_t AudioSapmSleep(const struct AudioCard *audioCard);
-uint64_t AudioSapmRefreshTime(bool bRefresh);
int32_t AudioSampPowerUp(const struct AudioCard *card);
int32_t AudioSampSetPowerMonitor(struct AudioCard *card, bool powerMonitorState);
diff --git a/model/audio/sapm/src/audio_sapm.c b/model/audio/sapm/src/audio_sapm.c
index b3d60c0176ecbe15b578b331e1d0416eac428b77..605123d1f9ba55d6a5f32d3681297f2f1824e71d 100755
--- a/model/audio/sapm/src/audio_sapm.c
+++ b/model/audio/sapm/src/audio_sapm.c
@@ -7,13 +7,30 @@
*/
#include "audio_sapm.h"
+#include "audio_driver_log.h"
#include "osal_io.h"
#include "osal_time.h"
#include "osal_timer.h"
#define HDF_LOG_TAG audio_sapm
+#define SAPM_POLL_TIME 10000 /* 10s */
+#define SAPM_SLEEP_TIME (3 * 60000) /* 3min */
+
+#define SAPM_POWER_DOWN 0
+#define SAPM_POWER_UP 1
+
+#define CONNECT_CODEC_PIN 1
+#define UNCONNECT_CODEC_PIN 0
+
+#define EXIST_EXTERNAL_WIDGET 1
+#define UNEXIST_EXTERNAL_WIDGET 1
+
+#define CONNECT_SINK_AND_SOURCE 1
+#define UNCONNECT_SINK_AND_SOURCE 0
+
static void AudioSapmEnterSleep(uintptr_t para);
+static uint64_t AudioSapmRefreshTime(bool bRefresh);
/* power up sequences */
static int32_t g_audioSapmPowerUpSeq[] = {
@@ -67,7 +84,7 @@ static int32_t ConnectedInputEndPoint(const struct AudioSapmComponent *sapmCompo
{
struct AudioSapmpath *path = NULL;
int32_t count = 0;
- int32_t endPointVal = 1;
+ const int32_t endPointVal = 1;
if (sapmComponent == NULL) {
ADM_LOG_ERR("input param sapmComponent is NULL.");
@@ -97,7 +114,7 @@ static int32_t ConnectedOutputEndPoint(const struct AudioSapmComponent *sapmComp
{
struct AudioSapmpath *path = NULL;
int32_t count = 0;
- int32_t endPointVal = 1;
+ const int32_t endPointVal = 1;
if (sapmComponent == NULL) {
ADM_LOG_ERR("input param sapmComponent is NULL.");
@@ -152,6 +169,21 @@ static int32_t AudioSapmGenericCheckPower(const struct AudioSapmComponent *sapmC
return SAPM_POWER_UP;
}
+static int32_t AudioSapmAdcPowerClock(struct AudioSapmComponent *sapmComponent)
+{
+ (void)sapmComponent;
+ ADM_LOG_INFO("Adc standby mode entry!");
+ return HDF_SUCCESS;
+}
+
+static int32_t AudioSapmDdcPowerClock(struct AudioSapmComponent *sapmComponent)
+{
+ (void)sapmComponent;
+ ADM_LOG_INFO("Ddc standby mode entry!");
+ return HDF_SUCCESS;
+}
+
+
static int32_t AudioSapmAdcCheckPower(const struct AudioSapmComponent *sapmComponent)
{
int32_t input;
@@ -239,11 +271,56 @@ static void AudioSampCheckPowerCallback(struct AudioSapmComponent *sapmComponent
return;
}
+static void AudioSampPowerClockCallback(struct AudioSapmComponent *sapmComponent)
+{
+ if (sapmComponent == NULL) {
+ ADM_LOG_ERR("input param cpt is NULL.");
+ return;
+ }
+
+ switch (sapmComponent->sapmType) {
+ case AUDIO_SAPM_ANALOG_SWITCH:
+ case AUDIO_SAPM_MIXER:
+ case AUDIO_SAPM_MIXER_NAMED_CTRL:
+ sapmComponent->PowerClockOp = NULL;
+ break;
+ case AUDIO_SAPM_MUX:
+ case AUDIO_SAPM_VIRT_MUX:
+ case AUDIO_SAPM_VALUE_MUX:
+ sapmComponent->PowerClockOp = NULL;
+ break;
+ case AUDIO_SAPM_ADC:
+ case AUDIO_SAPM_AIF_OUT:
+ sapmComponent->PowerClockOp = AudioSapmAdcPowerClock;
+ break;
+ case AUDIO_SAPM_DAC:
+ case AUDIO_SAPM_AIF_IN:
+ sapmComponent->PowerClockOp = AudioSapmDdcPowerClock;
+ break;
+ case AUDIO_SAPM_PGA:
+ case AUDIO_SAPM_OUT_DRV:
+ case AUDIO_SAPM_INPUT:
+ case AUDIO_SAPM_OUTPUT:
+ case AUDIO_SAPM_MICBIAS:
+ case AUDIO_SAPM_SPK:
+ case AUDIO_SAPM_HP:
+ case AUDIO_SAPM_MIC:
+ case AUDIO_SAPM_LINE:
+ sapmComponent->PowerClockOp = NULL;
+ break;
+ default:
+ sapmComponent->PowerClockOp = NULL;
+ break;
+ }
+
+ return;
+}
+
int32_t AudioSapmNewComponent(struct AudioCard *audioCard, const struct AudioSapmComponent *component)
{
struct AudioSapmComponent *sapmComponent = NULL;
- if ((audioCard == NULL || audioCard->rtd == NULL || audioCard->rtd->codec == NULL) || (component == NULL)) {
+ if ((audioCard == NULL || audioCard->rtd == NULL) || (component == NULL)) {
ADM_LOG_ERR("input params check error: audioCard=%p, component=%p.", audioCard, component);
return HDF_FAILURE;
}
@@ -279,11 +356,13 @@ int32_t AudioSapmNewComponent(struct AudioCard *audioCard, const struct AudioSap
OsalMemFree(sapmComponent);
return HDF_FAILURE;
}
+
sapmComponent->codec = audioCard->rtd->codec;
+ sapmComponent->accessory = audioCard->rtd->accessory;
sapmComponent->kcontrolsNum = component->kcontrolsNum;
sapmComponent->active = 0;
AudioSampCheckPowerCallback(sapmComponent);
- sapmComponent->PowerClockOp = NULL;
+ AudioSampPowerClockCallback(sapmComponent);
DListHeadInit(&sapmComponent->sources);
DListHeadInit(&sapmComponent->sinks);
@@ -325,7 +404,7 @@ static void MuxSetPathStatus(const struct AudioSapmComponent *sapmComponent, str
int32_t ret;
uint32_t val = 0;
int32_t item;
- uint32_t reg = 0;
+ const uint32_t reg = 0;
uint32_t shift;
if ((sapmComponent == NULL || sapmComponent->codec == NULL) || (path == NULL || path->name == NULL) ||
@@ -364,7 +443,7 @@ static void MuxValueSetPathStatus(const struct AudioSapmComponent *sapmComponent
int32_t ret;
uint32_t val = 0;
uint32_t item;
- uint32_t reg = 0;
+ const uint32_t reg = 0;
uint32_t shift;
if ((sapmComponent == NULL || sapmComponent->codec == NULL) || (path == NULL || path->name == NULL) ||
(enumKtl == NULL || enumKtl->texts == NULL)) {
@@ -383,8 +462,9 @@ static void MuxValueSetPathStatus(const struct AudioSapmComponent *sapmComponent
val = val >> shift;
for (item = 0; item < enumKtl->max; item++) {
- if (val == enumKtl->values[item])
+ if (val == enumKtl->values[item]) {
break;
+ }
}
path->connect = UNCONNECT_SINK_AND_SOURCE;
@@ -408,9 +488,9 @@ static void MixerSetPathStatus(const struct AudioSapmComponent *sapmComponent, s
uint32_t mask;
uint32_t shift;
uint32_t invert;
- uint32_t curValue;
+ uint32_t curValue = 0;
- if ((sapmComponent == NULL || sapmComponent->codec == NULL) || (path == NULL) || (mixerCtrl == NULL)) {
+ if ((sapmComponent == NULL) || (path == NULL) || (mixerCtrl == NULL)) {
ADM_LOG_ERR("input params check error: sapmComponent=%p, path=%p, mixerCtrl=%p.",
sapmComponent, path, mixerCtrl);
return;
@@ -421,9 +501,20 @@ static void MixerSetPathStatus(const struct AudioSapmComponent *sapmComponent, s
mask = mixerCtrl->mask;
invert = mixerCtrl->invert;
- ret = AudioCodecReadReg(sapmComponent->codec, reg, &curValue);
- if (ret != HDF_SUCCESS) {
- ADM_LOG_ERR("read reg fail!");
+ if (sapmComponent->codec != NULL) {
+ ret = AudioCodecReadReg(sapmComponent->codec, reg, &curValue);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("read reg fail!");
+ return;
+ }
+ } else if (sapmComponent->accessory != NULL) {
+ ret = AudioAccessoryReadReg(sapmComponent->accessory, reg, &curValue);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("read reg fail!");
+ return;
+ }
+ } else {
+ ADM_LOG_ERR("accessory and codec is null!");
return;
}
@@ -447,25 +538,21 @@ static int32_t AudioSapmSetPathStatus(const struct AudioSapmComponent *sapmCompo
switch (sapmComponent->sapmType) {
case AUDIO_SAPM_MIXER:
case AUDIO_SAPM_ANALOG_SWITCH:
- case AUDIO_SAPM_MIXER_NAMED_CTRL: {
+ case AUDIO_SAPM_MIXER_NAMED_CTRL:
MixerSetPathStatus(sapmComponent, path,
(struct AudioMixerControl *)((volatile uintptr_t)sapmComponent->kcontrolNews[i].privateValue));
- }
- break;
- case AUDIO_SAPM_MUX: {
+ break;
+ case AUDIO_SAPM_MUX:
MuxSetPathStatus(sapmComponent, path,
(struct AudioEnumKcontrol *)((volatile uintptr_t)sapmComponent->kcontrolNews[i].privateValue), i);
- }
- break;
- case AUDIO_SAPM_VALUE_MUX: {
+ break;
+ case AUDIO_SAPM_VALUE_MUX:
MuxValueSetPathStatus(sapmComponent, path,
(struct AudioEnumKcontrol *)((volatile uintptr_t)sapmComponent->kcontrolNews[i].privateValue), i);
- }
- break;
- default: {
+ break;
+ default:
path->connect = CONNECT_SINK_AND_SOURCE;
break;
- }
}
return HDF_SUCCESS;
@@ -475,7 +562,7 @@ static int32_t AudioSapmConnectMixer(struct AudioCard *audioCard,
struct AudioSapmComponent *source, struct AudioSapmComponent *sink,
struct AudioSapmpath *path, const char *controlName)
{
- int i;
+ int i = 0;
if ((audioCard == NULL) || (source == NULL) || (sink == NULL) ||
(path == NULL) || (controlName == NULL)) {
@@ -579,13 +666,15 @@ static void AudioSampExtComponentsCheck(struct AudioSapmComponent *cptSource, st
/* check for external components */
if (cptSink->sapmType == AUDIO_SAPM_INPUT) {
if (cptSource->sapmType == AUDIO_SAPM_MICBIAS || cptSource->sapmType == AUDIO_SAPM_MIC ||
- cptSource->sapmType == AUDIO_SAPM_LINE || cptSource->sapmType == AUDIO_SAPM_OUTPUT)
+ cptSource->sapmType == AUDIO_SAPM_LINE || cptSource->sapmType == AUDIO_SAPM_OUTPUT) {
cptSink->external = EXIST_EXTERNAL_WIDGET;
+ }
}
if (cptSource->sapmType == AUDIO_SAPM_OUTPUT) {
if (cptSink->sapmType == AUDIO_SAPM_SPK || cptSink->sapmType == AUDIO_SAPM_HP ||
- cptSink->sapmType == AUDIO_SAPM_LINE || cptSink->sapmType == AUDIO_SAPM_INPUT)
+ cptSink->sapmType == AUDIO_SAPM_LINE || cptSink->sapmType == AUDIO_SAPM_INPUT) {
cptSource->external = EXIST_EXTERNAL_WIDGET;
+ }
}
return;
@@ -598,13 +687,13 @@ static int32_t AudioSapmAddRoute(struct AudioCard *audioCard, const struct Audio
struct AudioSapmComponent *sapmComponent = NULL;
int32_t ret;
- if ((audioCard == NULL) || (route == NULL || route->source == NULL || route->sink == NULL)) {
+ if (audioCard == NULL || route == NULL || route->source == NULL || route->sink == NULL) {
ADM_LOG_ERR("input params check error: audioCard=%p, route=%p.", audioCard, route);
return HDF_FAILURE;
}
DLIST_FOR_EACH_ENTRY(sapmComponent, &audioCard->components, struct AudioSapmComponent, list) {
- if (sapmComponent == NULL || sapmComponent->componentName == NULL) {
+ if (sapmComponent->componentName == NULL) {
continue;
}
if ((cptSource == NULL) && (strcmp(sapmComponent->componentName, route->source) == 0)) {
@@ -667,19 +756,20 @@ int32_t AudioSapmAddRoutes(struct AudioCard *audioCard, const struct AudioSapmRo
return HDF_SUCCESS;
}
-int32_t AudioSapmNewMixerControls(struct AudioSapmComponent *sapmComponent, struct AudioCard *audioCard)
+int32_t AudioSapmNewMixerControls(const struct AudioSapmComponent *sapmComponent, struct AudioCard *audioCard)
{
struct AudioSapmpath *path = NULL;
int32_t i;
- if (sapmComponent == NULL || audioCard == NULL) {
+ if (sapmComponent == NULL || sapmComponent->kcontrols == NULL || audioCard == NULL) {
ADM_LOG_ERR("input params check error: sapmComponent=%p, audioCard=%p.", sapmComponent, audioCard);
return HDF_FAILURE;
}
for (i = 0; i < sapmComponent->kcontrolsNum; i++) {
DLIST_FOR_EACH_ENTRY(path, &sapmComponent->sources, struct AudioSapmpath, listSink) {
- if (path == NULL || path->name == NULL || sapmComponent->kcontrolNews[i].name == NULL) {
+ if (path->name == NULL || sapmComponent->kcontrolNews == NULL
+ || sapmComponent->kcontrolNews[i].name == NULL) {
continue;
}
@@ -719,6 +809,11 @@ int AudioSapmNewMuxControls(struct AudioSapmComponent *sapmComponent, struct Aud
ADM_LOG_ERR("add control fail!");
return HDF_FAILURE;
}
+
+ if (sapmComponent->kcontrols == NULL) {
+ ADM_LOG_ERR("sapmComponent->kcontrols is NULL!");
+ return HDF_FAILURE;
+ }
sapmComponent->kcontrols[0] = kctrl;
DListInsertHead(&sapmComponent->kcontrols[0]->list, &audioCard->controls);
@@ -862,8 +957,9 @@ static void AudioSapmPowerDownSeqRun(const struct DListHead *list)
return;
}
-int AudioSapmPowerComponents(struct AudioCard *audioCard)
+static int AudioSapmPowerComponents(struct AudioCard *audioCard)
{
+ int32_t ret;
struct AudioSapmComponent *sapmComponent = NULL;
struct DListHead upList;
struct DListHead downList;
@@ -884,7 +980,10 @@ int AudioSapmPowerComponents(struct AudioCard *audioCard)
}
if (g_audioSapmIsStandby && sapmComponent->PowerClockOp != NULL) {
- sapmComponent->PowerClockOp(sapmComponent);
+ ret = sapmComponent->PowerClockOp(sapmComponent);
+ if (ret != HDF_SUCCESS) {
+ continue;
+ }
}
AudioSapmSetPower(audioCard, sapmComponent, sapmComponent->newPower, &upList, &downList);
@@ -953,7 +1052,7 @@ int32_t AudioSapmSleep(const struct AudioCard *audioCard)
int32_t AudioSapmNewControls(struct AudioCard *audioCard)
{
struct AudioSapmComponent *sapmComponent = NULL;
- int ret;
+ int ret = HDF_SUCCESS;
if (audioCard == NULL) {
ADM_LOG_ERR("input param audioCard is NULL.");
@@ -983,7 +1082,7 @@ int32_t AudioSapmNewControls(struct AudioCard *audioCard)
case AUDIO_SAPM_MUX:
case AUDIO_SAPM_VIRT_MUX:
case AUDIO_SAPM_VALUE_MUX:
- ret =AudioSapmNewMuxControls(sapmComponent, audioCard);
+ ret = AudioSapmNewMuxControls(sapmComponent, audioCard);
break;
default:
ret = HDF_SUCCESS;
@@ -1013,7 +1112,7 @@ static int32_t MixerUpdatePowerStatus(const struct AudioKcontrol *kcontrol, uint
{
struct AudioCard *audioCard = NULL;
struct AudioSapmpath *path = NULL;
- int ret;
+ int ret = HDF_SUCCESS;
if (kcontrol == NULL || kcontrol->pri == NULL) {
ADM_LOG_ERR("input param kcontrol is NULL.");
@@ -1123,13 +1222,13 @@ int32_t AudioCodecSapmSetCtrlOps(const struct AudioKcontrol *kcontrol, const str
ADM_LOG_ERR("Device read register is failure!");
return HDF_FAILURE;
}
- if (MixerUpdatePowerStatus(kcontrol, pathStatus) != HDF_SUCCESS) {
- ADM_LOG_ERR("update power status is failure!");
- return HDF_FAILURE;
- }
curValue &= mixerCtrl->mask << mixerCtrl->shift;
value = (value & mixerCtrl->mask) << mixerCtrl->shift;
- if (curValue != value) {
+ if (curValue != value || g_audioSapmIsSleep == true) {
+ if (MixerUpdatePowerStatus(kcontrol, pathStatus) != HDF_SUCCESS) {
+ ADM_LOG_ERR("update power status is failure!");
+ return HDF_FAILURE;
+ }
if (AudioUpdateCodecRegBits(codec, mixerCtrl, elemValue->value[0]) != HDF_SUCCESS) {
ADM_LOG_ERR("update reg bits fail!");
return HDF_FAILURE;
@@ -1162,7 +1261,7 @@ int32_t AudioAccessorySapmSetCtrlOps(const struct AudioKcontrol *kcontrol, const
}
curValue &= mixerCtrl->mask << mixerCtrl->shift;
value = (value & mixerCtrl->mask) << mixerCtrl->shift;
- if (curValue != value) {
+ if (curValue != value || g_audioSapmIsSleep == true) {
if (MixerUpdatePowerStatus(kcontrol, pathStatus) != HDF_SUCCESS) {
ADM_LOG_ERR("update power status fail!");
return HDF_FAILURE;
@@ -1176,13 +1275,14 @@ int32_t AudioAccessorySapmSetCtrlOps(const struct AudioKcontrol *kcontrol, const
return HDF_SUCCESS;
}
-uint64_t AudioSapmRefreshTime(bool bRefresh)
+static uint64_t AudioSapmRefreshTime(bool bRefresh)
{
static uint64_t time = 0;
if (bRefresh) {
time = OsalGetSysTimeMs();
g_audioSapmIsSleep = false;
+ g_audioSapmIsStandby = false;
}
return time;
}
@@ -1232,7 +1332,7 @@ int32_t AudioSampSetPowerMonitor(struct AudioCard *card, bool powerMonitorState)
return HDF_SUCCESS;
}
-static void AudioSapmEnterSleepSub(uintptr_t para, struct AudioSapmComponent *sapmComponent)
+static void AudioSapmEnterSleepSub(const uintptr_t para, struct AudioSapmComponent *sapmComponent)
{
struct DListHead downList;
struct AudioCard *audioCard = (struct AudioCard *)para;
@@ -1274,19 +1374,22 @@ static void AudioSapmEnterSleep(uintptr_t para)
return;
}
- if (!AudioSapmCheckTime()) {
- return;
+ if (audioCard->standbyMode != AUDIO_SAPM_TURN_STANDBY_NOW) {
+ if (!AudioSapmCheckTime()) {
+ return;
+ }
}
- DLIST_FOR_EACH_ENTRY(sapmComponent, &audioCard->components, struct AudioSapmComponent, list) {
- if (sapmComponent->PowerClockOp != NULL) {
- if (g_audioSapmIsStandby == false) {
- sapmComponent->PowerClockOp(sapmComponent);
- g_audioSapmIsStandby = true;
- AudioSapmRefreshTime(true);
- }
+ if (g_audioSapmIsStandby == false) {
+ DLIST_FOR_EACH_ENTRY(sapmComponent, &audioCard->components, struct AudioSapmComponent, list) {
+ if (sapmComponent->PowerClockOp != NULL) {
+ sapmComponent->PowerClockOp(sapmComponent);
+ AudioSapmRefreshTime(true);
+ }
}
+ g_audioSapmIsStandby = true;
}
+
if (g_audioSapmIsStandby == true) {
if (!AudioSapmCheckTime()) {
return;
diff --git a/model/audio/sapm/test/unittest/common/audio_sapm_test.cpp b/model/audio/sapm/test/unittest/common/audio_sapm_test.cpp
index 7d700a9daad2029db9bf27da8cd7f4659d900f27..2dcd590d3ebbd950e7f122abc5835a7345b46b35 100755
--- a/model/audio/sapm/test/unittest/common/audio_sapm_test.cpp
+++ b/model/audio/sapm/test/unittest/common/audio_sapm_test.cpp
@@ -11,7 +11,7 @@
#include "hdf_uhdf_test.h"
using namespace testing::ext;
-
+namespace {
class AudioSapmTest : public testing::Test {
public:
static void SetUpTestCase();
@@ -38,32 +38,63 @@ void AudioSapmTest::TearDown()
{
}
-HWTEST_F(AudioSapmTest, AudioSapmTest001, TestSize.Level0)
+HWTEST_F(AudioSapmTest, AudioSapmTest_AudioSapmNewComponents, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOSAPMNEWCOMPONENTS, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioSapmTest, AudioSapmTest_AudioSapmAddRoutes, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOSAPMADDROUTES, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioSapmTest, AudioSapmTest_AudioSapmNewControls, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOSAPMNEWCONTROLS, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioSapmTest, AudioSapmTest_AudioSapmSleep, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOSAPMSLEEP, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+HWTEST_F(AudioSapmTest, AudioSapmTest_AudioSampPowerUp, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTNEWCOMPONENT, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOSAMPPOWERUP, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioSapmTest, AudioSapmTest002, TestSize.Level0)
+HWTEST_F(AudioSapmTest, AudioSapmTest_AudioSampSetPowerMonitor, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTADDROUTES, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOSAMPSETPOWERMONITOR, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioSapmTest, AudioSapmTest003, TestSize.Level0)
+HWTEST_F(AudioSapmTest, AudioSapmTest_AudioCodecSapmSetCtrlOps, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTNEWCONTROLS, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOCODECSAPMSETCTRLOPS, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioSapmTest, AudioSapmTest004, TestSize.Level0)
+HWTEST_F(AudioSapmTest, AudioSapmTest_AudioCodecSapmGetCtrlOps, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTPOWERCOMPONET, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOCODECSAPMGETCTRLOPS, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioSapmTest, AudioSapmTest005, TestSize.Level0)
+HWTEST_F(AudioSapmTest, AudioSapmTest_AudioAccessorySapmSetCtrlOps, TestSize.Level1)
{
- struct HdfTestMsg msg = {g_testAudioType, TESTREFRESHTIME, -1};
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOACCESSORYSAPMSETCTRLOPS, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
+
+HWTEST_F(AudioSapmTest, AudioSapmTest_AudioAccessorySapmGetCtrlOps, TestSize.Level1)
+{
+ struct HdfTestMsg msg = {g_testAudioType, TEST_AUDIOACCESSORYSAPMGETCTRLOPS, -1};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+}
diff --git a/model/display/driver/backlight/hdf_bl.c b/model/display/driver/backlight/hdf_bl.c
index 1f0743961a1944d4fac2476ebf1fbcdc75aca80d..8caa4f59bc8cdce5a3f251591ae1a483c3090383 100644
--- a/model/display/driver/backlight/hdf_bl.c
+++ b/model/display/driver/backlight/hdf_bl.c
@@ -9,7 +9,6 @@
#include "hdf_bl.h"
#include
#include "hdf_base.h"
-#include "hdf_disp.h"
#include "hdf_log.h"
#include "osal.h"
diff --git a/model/display/driver/backlight/pwm_bl.c b/model/display/driver/backlight/pwm_bl.c
index c3710b4ffa994f424d4eabf2fec620648e686211..f2dc3ac7aecabfb6e86fafe4df6057dea2d2373d 100644
--- a/model/display/driver/backlight/pwm_bl.c
+++ b/model/display/driver/backlight/pwm_bl.c
@@ -48,18 +48,16 @@ static int32_t BlPwmUpdateBrightness(struct BacklightDev *blDev, uint32_t bright
HDF_LOGE("%s maxBrightness is 0", __func__);
return HDF_FAILURE;
}
+ if (brightness == 0) {
+ return PwmDisable(blPwmDev->pwmHandle);
+ }
duty = (brightness * blPwmDev->config.period) / blPwmDev->props.maxBrightness;
ret = PwmSetDuty(blPwmDev->pwmHandle, duty);
if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: PwmSetDutyCycle failed, ret %d", __func__, ret);
+ HDF_LOGE("%s: PwmSetDuty failed, ret %d", __func__, ret);
return HDF_FAILURE;
}
- if (brightness != 0) {
- ret = PwmEnable(blPwmDev->pwmHandle);
- } else {
- ret = PwmDisable(blPwmDev->pwmHandle);
- }
- return ret;
+ return PwmEnable(blPwmDev->pwmHandle);
}
static struct BacklightOps g_blDevOps = {
@@ -183,4 +181,4 @@ struct HdfDriverEntry g_pwmBlDevEntry = {
.Init = BlPwmEntryInit,
};
-HDF_INIT(g_pwmBlDevEntry);
\ No newline at end of file
+HDF_INIT(g_pwmBlDevEntry);
diff --git a/model/display/driver/hdf_disp.c b/model/display/driver/hdf_disp.c
index 8d7d2603a0c6382144d80a2801294a02b030d326..c599bc17d20dd406adaed55c3111cd116cb3f772 100644
--- a/model/display/driver/hdf_disp.c
+++ b/model/display/driver/hdf_disp.c
@@ -9,6 +9,7 @@
#include "hdf_disp.h"
#include
#include "hdf_base.h"
+#include "hdf_bl.h"
#include "hdf_log.h"
#include "osal.h"
@@ -109,8 +110,8 @@ static int32_t SetDispBacklight(uint32_t devId, uint32_t level)
if (disp && disp->panelManager && devId < disp->panelManager->panelNum) {
panel = disp->panelManager->panel[devId];
}
- if (UpdateBrightness(panel->blDev, level) != HDF_SUCCESS) {
- HDF_LOGE("%s:UpdateBrightness failed", __func__);
+ if ((panel == NULL) || (UpdateBrightness(panel->blDev, level) != HDF_SUCCESS)) {
+ HDF_LOGE("%s:panel is null or UpdateBrightness failed", __func__);
return HDF_FAILURE;
}
HDF_LOGI("%s:level = %u", __func__, level);
@@ -172,7 +173,7 @@ static int32_t SetDispPower(uint32_t devId, uint32_t powerStatus)
OsalMutexLock(&disp->dispMutex);
if (panel->powerStatus == powerStatus) {
OsalMutexUnlock(&disp->dispMutex);
- HDF_LOGE("%s:devId[%d] already in mode = %d", __func__, devId, powerStatus);
+ HDF_LOGE("%s: panel already in mode = %d", __func__, powerStatus);
return HDF_SUCCESS;
}
switch (powerStatus) {
@@ -289,6 +290,7 @@ static int32_t GetBacklight(struct HdfDeviceObject *device, struct HdfSBuf *reqD
HDF_LOGE("%s: get panel failed", __func__);
return HDF_FAILURE;
}
+ panel = disp->panelManager->panel[devId];
if (GetCurrBrightness(panel->blDev, &currLevel) != HDF_SUCCESS) {
HDF_LOGE("%s: GetCurrBrightness failed", __func__);
return HDF_FAILURE;
@@ -393,6 +395,10 @@ static void EsdTimerHandler(uintptr_t arg)
struct DispManager *disp = NULL;
disp = GetDispManager();
+ if ((disp == NULL) || (disp->esd == NULL)) {
+ HDF_LOGE("%s: disp or esd is null", __func__);
+ return;
+ }
if (devId >= disp->esd->panelNum) {
HDF_LOGE("%s: esd is null", __func__);
return;
@@ -409,14 +415,20 @@ static void EsdWorkHandler(void *arg)
struct DispManager *disp = NULL;
disp = GetDispManager();
+ if ((disp == NULL) || (disp->panelManager == NULL)) {
+ HDF_LOGE("%s: disp or panelManager is null", __func__);
+ return;
+ }
if (devId >= disp->panelManager->panelNum) {
HDF_LOGE("%s: dispCtrl is null or panel is null", __func__);
return;
}
panel = disp->panelManager->panel[devId];
- if ((panel->esd != NULL) && (panel->esd->checkFunc != NULL)) {
- ret = panel->esd->checkFunc(panel);
+ if ((panel->esd == NULL) || (panel->esd->checkFunc == NULL)) {
+ HDF_LOGE("%s: esd or checkFunc is null", __func__);
+ return;
}
+ ret = panel->esd->checkFunc(panel);
if (ret != HDF_SUCCESS) {
OsalMutexLock(&disp->dispMutex);
if (panel->esd->state == ESD_RUNNING) {
@@ -429,7 +441,7 @@ static void EsdWorkHandler(void *arg)
OsalMutexUnlock(&disp->dispMutex);
panel->esd->recoveryNum++;
}
- HDF_LOGD("%s devId[%d] recoveryNum = %d", __func__, devId, panel->esd->recoveryNum);
+ HDF_LOGD("%s recoveryNum = %d", __func__, panel->esd->recoveryNum);
if (panel->esd->recoveryNum >= ESD_MAX_RECOVERY) {
panel->esd->recoveryNum = 0;
OsalMutexLock(&disp->dispMutex);
@@ -459,7 +471,7 @@ static void EsdCheckStartUp(struct DispEsd *esd, uint32_t devId)
EsdTimerHandler, (uintptr_t)devId);
OsalTimerStartLoop(esd->timer[devId]);
esd->panelEsd[devId]->state = ESD_RUNNING;
- HDF_LOGI("%s devId[%d] enable esd check", __func__, devId);
+ HDF_LOGI("%s panel enable esd check", __func__);
}
}
}
@@ -476,7 +488,7 @@ static void EsdCheckEnd(struct DispEsd *esd, uint32_t devId)
if (esd->panelEsd[devId]->state == ESD_RUNNING) {
OsalTimerDelete(esd->timer[devId]);
esd->panelEsd[devId]->state = ESD_READY;
- HDF_LOGI("%s devId[%d], disable esd check", __func__, devId);
+ HDF_LOGI("%s panel disable esd check", __func__);
}
}
}
diff --git a/model/display/driver/hdf_disp.h b/model/display/driver/hdf_disp.h
index d9c6d9de18f0cb962a5fb8aa5cb76df80d37ba86..8f497d59634da7e43f19c63ba2b49476cab7e47a 100644
--- a/model/display/driver/hdf_disp.h
+++ b/model/display/driver/hdf_disp.h
@@ -10,7 +10,6 @@
#define HDF_DISP_H
#include "hdf_base.h"
-#include "hdf_bl.h"
#include "hdf_device_desc.h"
#include "hdf_log.h"
#include "hdf_sbuf.h"
diff --git a/model/display/driver/lcdkit/lite_lcdkit.c b/model/display/driver/lcdkit/lite_lcdkit.c
index 7fdf1fb02372e76a12d823710df43edaf4a51959..b7b3cd4bca4b2f4b305b69b71b1f678f3df219c5 100644
--- a/model/display/driver/lcdkit/lite_lcdkit.c
+++ b/model/display/driver/lcdkit/lite_lcdkit.c
@@ -205,9 +205,9 @@ static int32_t SetBacklightByPwm(uint32_t level)
return HDF_FAILURE;
}
duty = (level * panelCfg->info.pwm.period) / panelCfg->info.blk.maxLevel;
- ret = PwmSetDutyCycle(panelCfg->pwmHandle, duty);
+ ret = PwmSetDuty(panelCfg->pwmHandle, duty);
if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: PwmSetDutyCycle failed", __func__);
+ HDF_LOGE("%s: PwmSetDuty failed", __func__);
return HDF_FAILURE;
}
static uint32_t lastLevel = 0;
diff --git a/model/display/driver/panel/ili9881c_boe.c b/model/display/driver/panel/ili9881c_boe.c
index 96945d70ffa0fbf94c2f1b561cd370e59ae8d298..00a8e47885b0faee21d5edf52c93e4e1e86c7bcc 100644
--- a/model/display/driver/panel/ili9881c_boe.c
+++ b/model/display/driver/panel/ili9881c_boe.c
@@ -8,6 +8,7 @@
#include "ili9881c_boe.h"
#include "gpio_if.h"
+#include "hdf_bl.h"
#include "hdf_disp.h"
#include "osal.h"
diff --git a/model/display/driver/panel/mipi_icn9700.c b/model/display/driver/panel/mipi_icn9700.c
index 59654c6bf9469751f2db0fcd9d335c2a2b8670db..99c1d49d5758bd026713505c3ee40a8170a3a68f 100644
--- a/model/display/driver/panel/mipi_icn9700.c
+++ b/model/display/driver/panel/mipi_icn9700.c
@@ -7,6 +7,7 @@
*/
#include "gpio_if.h"
+#include "hdf_bl.h"
#include "hdf_disp.h"
#include "hdf_log.h"
#include "mipi_dsi_if.h"
@@ -192,6 +193,8 @@ static int32_t Icn9700On(struct PanelData *panel)
/* send mipi init code */
int32_t count = sizeof(g_OnCmd) / sizeof(g_OnCmd[0]);
int32_t i;
+ /* set mipi to lp mode */
+ MipiDsiSetLpMode(icn9700->mipiHandle);
for (i = 0; i < count; i++) {
ret = MipiDsiTx(icn9700->mipiHandle, &(g_OnCmd[i]));
if (ret != HDF_SUCCESS) {
@@ -221,6 +224,8 @@ static int32_t Icn9700Off(struct PanelData *panel)
/* send mipi init code */
int32_t count = sizeof(g_offCmd) / sizeof(g_offCmd[0]);
int32_t i;
+ /* set mipi to lp mode */
+ MipiDsiSetLpMode(icn9700->mipiHandle);
for (i = 0; i < count; i++) {
ret = MipiDsiTx(icn9700->mipiHandle, &(g_offCmd[i]));
if (ret != HDF_SUCCESS) {
@@ -228,8 +233,6 @@ static int32_t Icn9700Off(struct PanelData *panel)
return HDF_FAILURE;
}
}
- /* set mipi to lp mode */
- MipiDsiSetLpMode(icn9700->mipiHandle);
/* lcd reset power off */
ret = LcdResetOff(icn9700);
if (ret != HDF_SUCCESS) {
diff --git a/model/input/driver/event_hub.c b/model/input/driver/event_hub.c
index 3055b95e169a59e6395838d46ca006d2295c07fb..dc2f52a6d19b3ce7a2d0aaf9001d6cd31cc0797a 100644
--- a/model/input/driver/event_hub.c
+++ b/model/input/driver/event_hub.c
@@ -26,12 +26,13 @@ void PushOnePackage(InputDevice *inputDev, uint32_t type, uint32_t code, int32_t
{
OsalTimespec time;
EventPackage package = {0};
+ InputManager *inputManager = GetInputManager();
if (inputDev == NULL) {
HDF_LOGE("%s: parm is null", __func__);
return;
}
- OsalMutexLock(&inputDev->mutex);
+ OsalMutexLock(&inputManager->mutex);
package.type = type;
package.code = code;
package.value = value;
@@ -65,5 +66,5 @@ void PushOnePackage(InputDevice *inputDev, uint32_t type, uint32_t code, int32_t
HdfSbufFlush(inputDev->pkgBuf);
inputDev->errFrameFlag = false;
}
- OsalMutexUnlock(&inputDev->mutex);
+ OsalMutexUnlock(&inputManager->mutex);
}
\ No newline at end of file
diff --git a/model/input/driver/hdf_encoder.c b/model/input/driver/hdf_encoder.c
new file mode 100644
index 0000000000000000000000000000000000000000..2185d5c1dff3555553bb08a28d5e5a5a5e52c189
--- /dev/null
+++ b/model/input/driver/hdf_encoder.c
@@ -0,0 +1,297 @@
+/*
+ * Copyright (c) 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 "hdf_encoder.h"
+#include "event_hub.h"
+#include "gpio_if.h"
+#include "hdf_device_desc.h"
+#include "hdf_log.h"
+#include "osal_mem.h"
+#include "osal_timer.h"
+
+#define TIMER_INTERVAL_ENCODER 5
+
+static void EncoderTimerFunc(uintptr_t arg)
+{
+ int32_t ret;
+ EncoderDriver *encoderDrv = (EncoderDriver *)arg;
+ uint16_t gpioClk = encoderDrv->encoderCfg->gpioClk;
+ uint16_t gpioData = encoderDrv->encoderCfg->gpioData;
+ uint16_t gpioSW = encoderDrv->encoderCfg->gpioSW;
+
+ ret = GpioRead(gpioClk, &encoderDrv->encoderClkNowSta);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: gpio read failed, ret %d", __func__, ret);
+ return;
+ }
+ ret = GpioRead(gpioData, &encoderDrv->encoderDataNowSta);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: gpio read failed, ret %d", __func__, ret);
+ return;
+ }
+ ret = GpioRead(gpioSW, &encoderDrv->encoderSWNowSta);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: gpio read failed, ret %d", __func__, ret);
+ return;
+ }
+
+ if (encoderDrv->encoderClkNowSta != encoderDrv->encoderClkPreSta) {
+ if (encoderDrv->encoderClkNowSta == 0) {
+ if (encoderDrv->encoderDataNowSta == 1) {
+ input_report_rel(encoderDrv->inputDev, REL_WHEEL, 1);
+ } else {
+ input_report_rel(encoderDrv->inputDev, REL_WHEEL, -1);
+ }
+ input_sync(encoderDrv->inputDev);
+ }
+ encoderDrv->encoderClkPreSta = encoderDrv->encoderClkNowSta;
+ encoderDrv->encoderDataPreSta = encoderDrv->encoderDataNowSta;
+ }
+ if (encoderDrv->encoderSWPreSta != encoderDrv->encoderSWNowSta) {
+ if (encoderDrv->encoderSWNowSta == 0) {
+ input_report_key(encoderDrv->inputDev, KEY_OK, 0);
+ } else {
+ input_report_key(encoderDrv->inputDev, KEY_OK, 1);
+ }
+ encoderDrv->encoderSWPreSta = encoderDrv->encoderSWNowSta;
+ input_sync(encoderDrv->inputDev);
+ }
+}
+
+static EncoderCfg *EncoderConfigInstance(struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ EncoderCfg *encoderCfg = (EncoderCfg *)OsalMemAlloc(sizeof(EncoderCfg));
+ if (encoderCfg == NULL) {
+ HDF_LOGE("%s: malloc encoder config failed", __func__);
+ return NULL;
+ }
+ ret = memset_s(encoderCfg, sizeof(EncoderCfg), 0, sizeof(EncoderCfg));
+ if (ret != 0) {
+ HDF_LOGE("%s: memset_s encoder config failed", __func__);
+ OsalMemFree(encoderCfg);
+ return NULL;
+ }
+ encoderCfg->hdfEncoderDev = device;
+
+ if (ParseEncoderConfig(device->property, encoderCfg) != HDF_SUCCESS) {
+ HDF_LOGE("%s: parse encoder config failed", __func__);
+ OsalMemFree(encoderCfg);
+ return NULL;
+ }
+ return encoderCfg;
+}
+
+static EncoderDriver *EncoderDriverInstance(EncoderCfg *encoderCfg)
+{
+ int32_t ret;
+ EncoderDriver *encoderDrv = (EncoderDriver *)OsalMemAlloc(sizeof(EncoderDriver));
+ if (encoderDrv == NULL) {
+ HDF_LOGE("%s: malloc key driver failed", __func__);
+ return NULL;
+ }
+ ret = memset_s(encoderDrv, sizeof(EncoderDriver), 0, sizeof(EncoderDriver));
+ if (ret != 0) {
+ HDF_LOGE("%s: memset encoder driver failed", __func__);
+ OsalMemFree(encoderDrv);
+ return NULL;
+ }
+
+ encoderDrv->devType = encoderCfg->devType;
+ encoderDrv->encoderCfg = encoderCfg;
+
+ return encoderDrv;
+}
+
+static int32_t EncoderInit(EncoderDriver *EncoderDrv)
+{
+ int32_t ret;
+ uint16_t gpioClk = EncoderDrv->encoderCfg->gpioClk;
+ uint16_t gpioData = EncoderDrv->encoderCfg->gpioData;
+ uint16_t gpioSW = EncoderDrv->encoderCfg->gpioSW;
+ GpioSetDir(gpioClk, GPIO_DIR_IN);
+ GpioSetDir(gpioData, GPIO_DIR_IN);
+ GpioSetDir(gpioSW, GPIO_DIR_IN);
+
+ ret = OsalTimerCreate(&EncoderDrv->timer, TIMER_INTERVAL_ENCODER, EncoderTimerFunc, EncoderDrv);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: create timer failed, ret = %d\n", __func__, ret);
+ return HDF_FAILURE;
+ }
+ ret = OsalTimerStartLoop(&EncoderDrv->timer);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: start timer failed, ret = %d\n", __func__, ret);
+ return HDF_FAILURE;
+ }
+
+ ret = GpioRead(gpioClk, &EncoderDrv->encoderClkNowSta);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: gpio read failed, ret %d", __func__, ret);
+ return HDF_FAILURE;
+ }
+ ret = GpioRead(gpioData, &EncoderDrv->encoderDataNowSta);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: gpio read failed, ret %d", __func__, ret);
+ return HDF_FAILURE;
+ }
+ ret = GpioRead(gpioSW, &EncoderDrv->encoderSWNowSta);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: gpio read failed, ret %d", __func__, ret);
+ return HDF_FAILURE;
+ }
+
+ EncoderDrv->encoderClkPreSta = EncoderDrv->encoderClkNowSta;
+ EncoderDrv->encoderDataPreSta = EncoderDrv->encoderDataNowSta;
+
+ return HDF_SUCCESS;
+}
+
+static InputDevice *InputDeviceInstance(EncoderDriver *encoderDrv)
+{
+ int32_t ret;
+ InputDevice *inputDev = (InputDevice *)OsalMemAlloc(sizeof(InputDevice));
+ if (inputDev == NULL) {
+ HDF_LOGE("%s: malloc input device failed", __func__);
+ return NULL;
+ }
+ ret = memset_s(inputDev, sizeof(InputDevice), 0, sizeof(InputDevice));
+ if (ret != 0) {
+ HDF_LOGE("%s: memset encoder driver failed", __func__);
+ OsalMemFree(inputDev);
+ return NULL;
+ }
+
+ ret = OsalMutexInit(&inputDev->mutex);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Init mutex error", __func__);
+ OsalMemFree(inputDev);
+ return NULL;
+ }
+
+ inputDev->pvtData = (void *)encoderDrv;
+ inputDev->devType = encoderDrv->devType;
+ inputDev->hdfDevObj = encoderDrv->encoderCfg->hdfEncoderDev;
+ encoderDrv->inputDev = inputDev;
+
+ return inputDev;
+}
+
+static int32_t RegisterEncoderDevice(EncoderCfg *encoderCfg, struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ EncoderDriver *encoderDrv = EncoderDriverInstance(encoderCfg);
+ if (encoderDrv == NULL) {
+ HDF_LOGE("%s: instance encoder driver failed", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+ device->priv = (void *)encoderDrv;
+
+ ret = EncoderInit(encoderDrv);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: key driver init failed, ret %d", __func__, ret);
+ goto EXIT;
+ }
+
+ InputDevice *inputDev = InputDeviceInstance(encoderDrv);
+ if (inputDev == NULL) {
+ HDF_LOGE("%s: instance input device failed", __func__);
+ goto EXIT;
+ }
+
+ ret = RegisterInputDevice(inputDev);
+ if (ret != HDF_SUCCESS) {
+ goto EXIT1;
+ }
+ return HDF_SUCCESS;
+
+EXIT1:
+ OsalMemFree(inputDev->pkgBuf);
+ OsalMemFree(inputDev);
+EXIT:
+ OsalMemFree(encoderDrv);
+ return HDF_FAILURE;
+}
+
+static int32_t HdfEnCoderDriverInit(struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ if (device == NULL) {
+ HDF_LOGE("%s: param is null", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ EncoderCfg *encoderCfg = EncoderConfigInstance(device);
+ if (encoderCfg == NULL) {
+ HDF_LOGE("%s: instance encoder config failed", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ ret = RegisterEncoderDevice(encoderCfg, device);
+ if (ret != HDF_SUCCESS) {
+ goto EXIT;
+ }
+
+ HDF_LOGI("%s: exit succ!", __func__);
+ return HDF_SUCCESS;
+
+EXIT:
+ OsalMemFree(encoderCfg);
+ return HDF_FAILURE;
+}
+
+static int32_t HdfEnCoderDispatch(struct HdfDeviceIoClient *client, int cmd,
+ struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ (void)cmd;
+ if (client == NULL || data == NULL || reply == NULL) {
+ HDF_LOGE("%s: param is null", __func__);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+static void HdfEncoderDriverRelease(struct HdfDeviceObject *device)
+{
+ EncoderDriver *driver = NULL;
+ InputDevice *inputDev = NULL;
+
+ if (device == NULL || device->priv == NULL) {
+ HDF_LOGE("%s: param is null", __func__);
+ return;
+ }
+ driver = (EncoderDriver *)device->priv;
+ inputDev = driver->inputDev;
+ if (inputDev != NULL) {
+ UnregisterInputDevice(inputDev);
+ driver->inputDev = NULL;
+ }
+ OsalMemFree(driver);
+}
+
+static int32_t HdfEnCoderDriverBind(struct HdfDeviceObject *device)
+{
+ if (device == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ static struct IDeviceIoService enCoderService = {
+ .object.objectId = 1,
+ .Dispatch = HdfEnCoderDispatch,
+ };
+ device->service = &enCoderService;
+ return HDF_SUCCESS;
+}
+
+struct HdfDriverEntry g_hdfEnCoderEntry = {
+ .moduleVersion = 1,
+ .moduleName = "HDF_ENCODER",
+ .Bind = HdfEnCoderDriverBind,
+ .Init = HdfEnCoderDriverInit,
+ .Release = HdfEncoderDriverRelease,
+};
+
+HDF_INIT(g_hdfEnCoderEntry);
diff --git a/model/input/driver/hdf_encoder.h b/model/input/driver/hdf_encoder.h
new file mode 100644
index 0000000000000000000000000000000000000000..9b65f42bcb855589208681f984898b3c77887430
--- /dev/null
+++ b/model/input/driver/hdf_encoder.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 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.
+ */
+#ifndef HDF_ENCODER_H
+#define HDF_ENCODER_H
+
+#include
+#include "hdf_device_object.h"
+#include "hdf_input_device_manager.h"
+#include "input_config.h"
+#include "osal_time.h"
+#include "osal_timer.h"
+
+typedef struct EncoderDriverInfo {
+ struct HdfDeviceObject *hdfEncoderDev;
+ uint8_t devType;
+ EncoderCfg *encoderCfg;
+ InputDevice *inputDev;
+ OsalTimer timer;
+ uint16_t encoderClkPreSta;
+ uint16_t encoderClkNowSta;
+ uint16_t encoderDataPreSta;
+ uint16_t encoderDataNowSta;
+ uint16_t encoderSWPreSta;
+ uint16_t encoderSWNowSta
+} EncoderDriver;
+
+#endif
\ No newline at end of file
diff --git a/model/input/driver/hdf_hid_adapter.c b/model/input/driver/hdf_hid_adapter.c
index 1ab568243f094cd993b56a0bfe06fdfb05d1d81e..b576193d1339dce23349f16674089cc1534b0d25 100644
--- a/model/input/driver/hdf_hid_adapter.c
+++ b/model/input/driver/hdf_hid_adapter.c
@@ -101,7 +101,7 @@ static void FreeCachedInfo(void)
}
}
-static int32_t SetInputDevAbsAttr(InputDevice *inputDev, HidInfo *info)
+static int32_t SetInputDevAbsAttr(InputDevice *inputDev, const HidInfo *info)
{
int32_t ret;
for (int i = 0; i < BITS_TO_LONG(ABS_CNT); i++) {
@@ -114,31 +114,11 @@ static int32_t SetInputDevAbsAttr(InputDevice *inputDev, HidInfo *info)
return HDF_SUCCESS;
}
-static int32_t GetInfoFromCache(InputDevice *inputDev, HidInfo *info)
+static void GetInfoFromCache(InputDevice *inputDev, const HidInfo *info)
{
- int32_t id = 0;
- while (id < MAX_INPUT_DEV_NUM) {
- if (g_cachedInfo[id] != NULL && !strcmp(inputDev->devName, g_cachedInfo[id]->devName)) {
- info = g_cachedInfo[id];
- break;
- }
- id++;
- }
- if (id == MAX_INPUT_DEV_NUM || info == NULL) {
- HDF_LOGE("%s: match cached info failed", __func__);
- return HDF_FAILURE;
- }
- return HDF_SUCCESS;
-}
-
-static void SetInputDevAbility(InputDevice *inputDev)
-{
- HidInfo *info = NULL;
uint32_t len;
int32_t ret;
- ret = GetInfoFromCache(inputDev, info);
- MEMCPY_CHECK_RETURN(ret);
len = sizeof(unsigned long);
ret = memcpy_s(inputDev->abilitySet.devProp, len * BITS_TO_LONG(INPUT_PROP_CNT),
info->devProp, len * BITS_TO_LONG(INPUT_PROP_CNT));
@@ -176,6 +156,26 @@ static void SetInputDevAbility(InputDevice *inputDev)
inputDev->attrSet.id.vendor = info->vendor;
inputDev->attrSet.id.product = info->product;
inputDev->attrSet.id.version = info->version;
+}
+
+static void SetInputDevAbility(InputDevice *inputDev)
+{
+ HidInfo *info = NULL;
+ int32_t id = 0;
+
+ while (id < MAX_INPUT_DEV_NUM) {
+ if (g_cachedInfo[id] != NULL && !strcmp(inputDev->devName, g_cachedInfo[id]->devName)) {
+ info = g_cachedInfo[id];
+ break;
+ }
+ id++;
+ }
+ if (id == MAX_INPUT_DEV_NUM || info == NULL) {
+ HDF_LOGE("%s: match cached info failed", __func__);
+ return;
+ }
+
+ GetInfoFromCache(inputDev, info);
FreeCachedInfo();
}
@@ -188,13 +188,6 @@ static InputDevice* HidConstructInputDev(HidInfo *info)
}
(void)memset_s(inputDev, sizeof(InputDevice), 0, sizeof(InputDevice));
- int32_t ret = OsalMutexInit(&inputDev->mutex);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: Init mutex error", __func__);
- OsalMemFree(inputDev);
- return NULL;
- }
-
inputDev->devType = info->devType;
inputDev->devName = info->devName;
SetInputDevAbility(inputDev);
diff --git a/model/input/driver/hdf_input_device_manager.c b/model/input/driver/hdf_input_device_manager.c
index 9be0cce56e19eaeb8409ae4bc6f32f66e940eada..7f1a02fa0355ed1ae8b927da9a80322c853f4757 100644
--- a/model/input/driver/hdf_input_device_manager.c
+++ b/model/input/driver/hdf_input_device_manager.c
@@ -6,13 +6,13 @@
* See the LICENSE file in the root of this repository for complete details.
*/
-#include
-#include "osal_mem.h"
-#include "devsvc_manager_clnt.h"
+#include "hdf_input_device_manager.h"
+#include "event_hub.h"
#include "hdf_base.h"
+#include "hdf_device_object.h"
#include "hdf_log.h"
-#include "event_hub.h"
-#include "hdf_input_device_manager.h"
+#include "osal_mem.h"
+#include
#define NODE_MODE 0660
#define SERVICE_NAME_LEN 24
@@ -52,10 +52,24 @@ static struct HdfDeviceObject *HidRegisterHdfDevice(InputDevice *inputDev)
return NULL;
}
- hdfDev = HdfRegisterDevice(moduleName, svcName, NULL);
+ hdfDev = HdfDeviceObjectAlloc(g_inputManager->hdfDevObj, moduleName);
if (hdfDev == NULL) {
- HDF_LOGE("%s: HdfRegisterDevice failed", __func__);
+ HDF_LOGE("%s: failed to alloc device object", __func__);
+ return NULL;
+ }
+ ret = HdfDeviceObjectRegister(hdfDev);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: failed to regitst device %s", __func__, moduleName);
+ HdfDeviceObjectRelease(hdfDev);
+ return NULL;
}
+ ret = HdfDeviceObjectPublishService(hdfDev, svcName, SERVICE_POLICY_CAPACITY, 0664); // 0664:permission setting
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: failed to regitst device %s", __func__, moduleName);
+ HdfDeviceObjectRelease(hdfDev);
+ return NULL;
+ }
+ inputDev->hdfDevObj = hdfDev;
HDF_LOGI("%s: svcName is %s, devName = %s", __func__, svcName, inputDev->devName);
return hdfDev;
}
@@ -104,18 +118,8 @@ static int32_t CreateDeviceNode(InputDevice *inputDev)
static void DeleteDeviceNode(InputDevice *inputDev)
{
if (IsHidDevice(inputDev->devType)) {
- char svcName[SERVICE_NAME_LEN] = {0};
- const char *moduleName = "HDF_HID";
-
- int32_t len = (inputDev->devId < PLACEHOLDER_LIMIT) ? 1 : PLACEHOLDER_LENGTH;
- int32_t ret = snprintf_s(svcName, SERVICE_NAME_LEN, strlen("hdf_input_event") + len, "%s%u",
- "hdf_input_event", inputDev->devId);
- if (ret < 0) {
- HDF_LOGE("%s: snprintf_s failed", __func__);
- return;
- }
- HDF_LOGI("%s: svcName is %s, devName = %s", __func__, svcName, inputDev->devName);
- HdfUnregisterDevice(moduleName, svcName);
+ HDF_LOGI("remove input device: hdf_input_event%u", inputDev->devId);
+ HdfDeviceObjectRelease(inputDev->hdfDevObj);
}
HDF_LOGI("%s: delete node succ, devId is %d", __func__, inputDev->devId);
@@ -344,7 +348,6 @@ void UnregisterInputDevice(InputDevice *inputDev)
}
HdfSBufRecycle(inputDev->eventBuf);
inputDev->eventBuf = NULL;
- OsalMutexDestroy(&inputDev->mutex);
OsalMemFree(inputDev);
OsalMutexUnlock(&g_inputManager->mutex);
HDF_LOGI("%s: exit succ, devCount is %d", __func__, g_inputManager->devCount);
diff --git a/model/input/driver/hdf_input_device_manager.h b/model/input/driver/hdf_input_device_manager.h
index 98d247d88b91cef0c54e753daf958bfe448e790e..35f454548cd27ef86554f2c0704ef470b119dd6c 100644
--- a/model/input/driver/hdf_input_device_manager.h
+++ b/model/input/driver/hdf_input_device_manager.h
@@ -112,7 +112,6 @@ typedef struct InputDeviceInfo {
void *pvtData;
DevAttr attrSet;
DevAbility abilitySet;
- struct OsalMutex mutex;
struct InputDeviceInfo *next;
} InputDevice;
diff --git a/model/input/driver/hdf_key.c b/model/input/driver/hdf_key.c
index 7df3cd819bd09b3bd707ae155e2709992a1f17d4..56ba4cb97c40b928f4511818593070c1f57d5119 100644
--- a/model/input/driver/hdf_key.c
+++ b/model/input/driver/hdf_key.c
@@ -23,6 +23,7 @@
int32_t KeyIrqHandle(uint16_t intGpioNum, void *data)
{
+ int32_t ret;
uint16_t gpioValue = 0;
KeyDriver *driver = (KeyDriver *)data;
if (driver == NULL) {
@@ -32,7 +33,7 @@ int32_t KeyIrqHandle(uint16_t intGpioNum, void *data)
if (event == NULL) {
return HDF_FAILURE;
}
- int32_t ret = GpioDisableIrq(intGpioNum);
+ ret = GpioDisableIrq(intGpioNum);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: disable irq failed, ret %d", __func__, ret);
@@ -143,13 +144,14 @@ static InputDevice *InputDeviceInstance(KeyDriver *keyDrv)
static int32_t RegisterKeyDevice(KeyChipCfg *keyCfg)
{
+ int32_t ret;
KeyDriver *keyDrv = KeyDriverInstance(keyCfg);
if (keyDrv == NULL) {
HDF_LOGE("%s: instance key config failed", __func__);
return HDF_ERR_MALLOC_FAIL;
}
- int32_t ret = KeyInit(keyDrv);
+ ret = KeyInit(keyDrv);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: key driver init failed, ret %d", __func__, ret);
goto EXIT;
@@ -178,6 +180,7 @@ EXIT:
static int32_t HdfKeyDriverInit(struct HdfDeviceObject *device)
{
+ int32_t ret;
HDF_LOGI("%s: enter", __func__);
if (device == NULL) {
return HDF_ERR_INVALID_PARAM;
@@ -189,7 +192,7 @@ static int32_t HdfKeyDriverInit(struct HdfDeviceObject *device)
return HDF_ERR_MALLOC_FAIL;
}
- int32_t ret = RegisterKeyDevice(keyCfg);
+ ret = RegisterKeyDevice(keyCfg);
if (ret != HDF_SUCCESS) {
goto EXIT;
}
diff --git a/model/input/driver/hdf_touch.c b/model/input/driver/hdf_touch.c
index 9a1264e393bec4854021d7f5dc36725aee575fba..5d8dd00d628fe5ff9b925324e4f7c1c9863a31ff 100644
--- a/model/input/driver/hdf_touch.c
+++ b/model/input/driver/hdf_touch.c
@@ -294,12 +294,6 @@ static InputDevice *InputDeviceInstance(ChipDevice *chipDev)
inputDev->devType = chipDev->driver->boardCfg->attr.devType;
inputDev->devName = chipDev->driver->devName;
- int32_t ret = OsalMutexInit(&inputDev->mutex);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: Init mutex error", __func__);
- OsalMemFree(inputDev);
- return NULL;
- }
return inputDev;
}
@@ -352,7 +346,7 @@ static int32_t DeviceBindDriver(ChipDevice *chipDev)
return HDF_SUCCESS;
}
-int32_t RegisterChipDevice(ChipDevice *chipDev)
+int32_t RegisterTouchChipDevice(ChipDevice *chipDev)
{
int32_t ret;
InputDevice *inputDev = NULL;
@@ -462,13 +456,14 @@ static int32_t TouchGetDeviceStrInfo(TouchDriver *driver, int32_t cmd, struct Hd
static int32_t TouchGetDeviceAttr(TouchDriver *driver, struct HdfSBuf *reply)
{
+ char *tempStr = "main_touch";
+ int32_t ret;
if (driver->inputDev == NULL) {
return HDF_FAILURE;
}
HDF_LOGE("%s: enter", __func__);
- char *tempStr = "main_touch";
- int32_t ret = strncpy_s(driver->inputDev->attrSet.devName, DEV_NAME_LEN, tempStr, strlen(tempStr));
+ ret = strncpy_s(driver->inputDev->attrSet.devName, DEV_NAME_LEN, tempStr, strlen(tempStr));
if (ret != 0) {
HDF_LOGE("%s: strncpy dev attr failed", __func__);
return HDF_FAILURE;
diff --git a/model/input/driver/hdf_touch.h b/model/input/driver/hdf_touch.h
index f8ed6ce5c094d5f0bb050ea307040d785518b5bd..248273d43cc81a662d9fb9d48f02e09e107e070b 100644
--- a/model/input/driver/hdf_touch.h
+++ b/model/input/driver/hdf_touch.h
@@ -107,6 +107,6 @@ typedef struct {
const char *cmdValue;
} InputExtraCmd;
-int32_t RegisterChipDevice(ChipDevice *chipDev);
+int32_t RegisterTouchChipDevice(ChipDevice *chipDev);
#endif
diff --git a/model/input/driver/input_config.h b/model/input/driver/input_config.h
index e44d400cc9baaa9acdaca5f36ef1e03eed95ce0a..ee25b9f2c503a3d2ba82b59aaf6eb5ff4a8b3f1f 100644
--- a/model/input/driver/input_config.h
+++ b/model/input/driver/input_config.h
@@ -140,8 +140,17 @@ typedef struct {
uint32_t debounceTime;
} KeyChipCfg;
+typedef struct {
+ struct HdfDeviceObject *hdfEncoderDev;
+ uint8_t devType;
+ uint16_t gpioClk;
+ uint16_t gpioData;
+ uint16_t gpioSW;
+} EncoderCfg;
+
int32_t ParseTouchBoardConfig(const struct DeviceResourceNode *node, TouchBoardCfg *config);
int32_t ParseTouchChipConfig(const struct DeviceResourceNode *node, TouchChipCfg *config);
int32_t ParseKeyConfig(const struct DeviceResourceNode *node, KeyChipCfg *config);
+int32_t ParseEncoderConfig(const struct DeviceResourceNode *node, EncoderCfg *config);
#endif
\ No newline at end of file
diff --git a/model/input/driver/input_config_parser.c b/model/input/driver/input_config_parser.c
index f6c49ebab1c2fe2f6cf6ecfd14e5dd36475307bf..17f65dd27edbd23f2d3fbc824b04b6c7f481cef0 100644
--- a/model/input/driver/input_config_parser.c
+++ b/model/input/driver/input_config_parser.c
@@ -25,12 +25,13 @@
int32_t ParseKeyConfig(const struct DeviceResourceNode *node, KeyChipCfg *config)
{
+ int32_t ret;
+ struct DeviceResourceIface *parser = NULL;
if (node == NULL || config == NULL) {
HDF_LOGE("%s: param is null", __func__);
return HDF_FAILURE;
}
- struct DeviceResourceIface *parser = NULL;
parser = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
if (parser == NULL) {
HDF_LOGE("%s: instance parser failed", __func__);
@@ -38,12 +39,12 @@ int32_t ParseKeyConfig(const struct DeviceResourceNode *node, KeyChipCfg *config
}
const struct DeviceResourceNode *keyNode = node;
- int32_t ret = parser->GetString(keyNode, "keyName", &config->keyName, NULL);
+ ret = parser->GetString(keyNode, "keyName", &config->keyName, NULL);
CHECK_PARSER_RET(ret, "GetString");
ret = parser->GetUint8(keyNode, "inputType", &config->devType, 0);
CHECK_PARSER_RET(ret, "GetUint8");
ret = parser->GetUint16(keyNode, "gpioNum", &config->gpioNum, 0);
- CHECK_PARSER_RET(ret, "GetUint32");
+ CHECK_PARSER_RET(ret, "GetUint16");
ret = parser->GetUint16(keyNode, "irqFlag", &config->irqFlag, 0);
CHECK_PARSER_RET(ret, "GetUint8");
ret = parser->GetUint32(keyNode, "debounceTime", &config->debounceTime, 0);
@@ -52,6 +53,33 @@ int32_t ParseKeyConfig(const struct DeviceResourceNode *node, KeyChipCfg *config
return HDF_SUCCESS;
}
+int32_t ParseEncoderConfig(const struct DeviceResourceNode *node, EncoderCfg *config)
+{
+ if (node == NULL || config == NULL) {
+ HDF_LOGE("%s: param is null", __func__);
+ return HDF_FAILURE;
+ }
+
+ struct DeviceResourceIface *parser = NULL;
+ parser = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ if (parser == NULL) {
+ HDF_LOGE("%s: instance parser failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ const struct DeviceResourceNode *encoderNode = node;
+ int32_t ret = parser->GetUint8(encoderNode, "inputType", &config->devType, 0);
+ CHECK_PARSER_RET(ret, "GetUint8");
+ ret = parser->GetUint16(encoderNode, "gpioClk", &config->gpioClk, 0);
+ CHECK_PARSER_RET(ret, "GetUint16");
+ ret = parser->GetUint16(encoderNode, "gpioDT", &config->gpioData, 0);
+ CHECK_PARSER_RET(ret, "GetUint16");
+ ret = parser->GetUint16(encoderNode, "gpioSW", &config->gpioSW, 0);
+ CHECK_PARSER_RET(ret, "GetUint16");
+
+ return HDF_SUCCESS;
+}
+
static int32_t ParseAttr(struct DeviceResourceIface *parser, const struct DeviceResourceNode *attrNode,
BoardAttrCfg *attr)
{
diff --git a/model/input/driver/touchscreen/touch_ft6336.c b/model/input/driver/touchscreen/touch_ft6336.c
index 87a006fbe9ae201821a827a713b1b69753fc0da2..422439d2aabf441a9433f46c5c9b5570c0e38d9a 100644
--- a/model/input/driver/touchscreen/touch_ft6336.c
+++ b/model/input/driver/touchscreen/touch_ft6336.c
@@ -92,10 +92,11 @@ static int32_t ChipDataHandle(ChipDevice *device)
uint8_t buf[POINT_BUFFER_LEN] = {0};
uint8_t reg = 0x0;
uint8_t pointNum;
+ int32_t ret;
InputI2cClient *i2cClient = &device->driver->i2cClient;
FrameData *frame = &device->driver->frameData;
- int32_t ret = InputI2cRead(i2cClient, ®, 1, buf, POINT_BUFFER_LEN);
+ ret = InputI2cRead(i2cClient, ®, 1, buf, POINT_BUFFER_LEN);
CHIP_CHECK_RETURN(ret);
OsalMutexLock(&device->driver->mutex);
@@ -196,7 +197,7 @@ static int32_t HdfFocalChipInit(struct HdfDeviceObject *device)
chipDev->chipName = chipCfg->chipName;
chipDev->vendorName = chipCfg->vendorName;
- if (RegisterChipDevice(chipDev) != HDF_SUCCESS) {
+ if (RegisterTouchChipDevice(chipDev) != HDF_SUCCESS) {
goto EXIT1;
}
HDF_LOGI("%s: exit succ, chipName = %s", __func__, chipCfg->chipName);
diff --git a/model/input/driver/touchscreen/touch_gt911.c b/model/input/driver/touchscreen/touch_gt911.c
index fb3f5e96fd5b5a29ff710d3e0fdc4d825124f4bb..5936d8f333c11ddd23aaccbac8c06387edd09acc 100644
--- a/model/input/driver/touchscreen/touch_gt911.c
+++ b/model/input/driver/touchscreen/touch_gt911.c
@@ -248,6 +248,10 @@ static ChipDevice *ChipDeviceInstance(void)
static void FreeChipConfig(TouchChipCfg *config)
{
+ if (config == NULL) {
+ HDF_LOGE("%s: param is null", __func__);
+ return;
+ }
if (config->pwrSeq.pwrOn.buf != NULL) {
OsalMemFree(config->pwrSeq.pwrOn.buf);
}
@@ -291,8 +295,9 @@ static int32_t HdfGoodixChipInit(struct HdfDeviceObject *device)
chipDev->ops = &g_gt911ChipOps;
chipDev->chipName = chipCfg->chipName;
chipDev->vendorName = chipCfg->vendorName;
+ device->priv = (void *)chipDev;
- if (RegisterChipDevice(chipDev) != HDF_SUCCESS) {
+ if (RegisterTouchChipDevice(chipDev) != HDF_SUCCESS) {
goto EXIT1;
}
HDF_LOGI("%s: exit succ, chipName = %s", __func__, chipCfg->chipName);
@@ -305,10 +310,20 @@ EXIT:
return HDF_FAILURE;
}
+static void HdfGoodixChipRelease(struct HdfDeviceObject *device)
+{
+ if (device == NULL || device->priv == NULL) {
+ HDF_LOGE("%s: param is null", __func__);
+ return;
+ }
+ HDF_LOGI("%s: goodix chip is release", __func__);
+}
+
struct HdfDriverEntry g_touchGoodixChipEntry = {
.moduleVersion = 1,
.moduleName = "HDF_TOUCH_GT911",
.Init = HdfGoodixChipInit,
+ .Release = HdfGoodixChipRelease,
};
HDF_INIT(g_touchGoodixChipEntry);
diff --git a/model/misc/dsoftbus/include/module_manager.h b/model/misc/dsoftbus/include/module_manager.h
index a59ef5fe1b4ab0127010b1ed12b8fee25949efdf..19464c647f9725753221518a8f730890becf4810 100644
--- a/model/misc/dsoftbus/include/module_manager.h
+++ b/model/misc/dsoftbus/include/module_manager.h
@@ -19,6 +19,7 @@ extern "C" {
typedef enum {
SOFTBUS_MODULE_WLAN_PARAM_MONITOR = 0,
+ SOFTBUS_MODULE_LWIP_MONITOR,
SOFTBUS_MODULE_MAX_INDEX,
} SoftbusDriverModuleId;
diff --git a/model/misc/dsoftbus/src/module_manager.c b/model/misc/dsoftbus/src/module_manager.c
index ea9f741bba0f9633582c80784342ca257173b562..6dc8b25e1267a827de6dd5e72f14f6d9d50ff750 100644
--- a/model/misc/dsoftbus/src/module_manager.c
+++ b/model/misc/dsoftbus/src/module_manager.c
@@ -9,6 +9,9 @@
#include "module_manager.h"
#include "hdf_log.h"
+#ifdef ENABLE_LWIP_MONITOR
+#include "softbus_lwip_monitor.h"
+#endif
#ifdef ENABLE_WLAN_PARAM_MONITOR
#include "wlan_param_monitor.h"
#endif
@@ -16,10 +19,17 @@
#define HDF_LOG_TAG "hdf_dsoftbus"
static SoftbusDriverModule g_modules[] = {
+#ifdef ENABLE_LWIP_MONITOR
+ {
+ .init = SoftbusLwipMonitorInit,
+ .deinit = NULL,
+ .process = NULL,
+ },
+#endif
#ifdef ENABLE_WLAN_PARAM_MONITOR
{
.init = SoftbusWlanParamMonitorInit,
- .deinit = SoftbusWlanParamMonitorDeinit,
+ .deinit = NULL,
.process = SoftbusWlanParamMonitorProcess,
},
#endif
@@ -40,7 +50,7 @@ void SoftbusDispatchModuleCommand(int32_t moduleId, const struct HdfSBuf *reqDat
g_modules[i].process(reqData, rspData);
return;
}
- HDF_LOGE("no moduleId: %d registered", moduleId);
+ HDF_LOGE("no moduleId: %d process command", moduleId);
}
int32_t SoftbusModuleManagerInit(struct HdfDeviceObject *device)
diff --git a/model/misc/dsoftbus/src/wlan_param_monitor.c b/model/misc/dsoftbus/src/wlan_param_monitor.c
index 07eeb8309a9ce03cffbda2ab6de49d26dae04e8b..d06fa4fec040b7b70c83d0f9bad941b17594af30 100644
--- a/model/misc/dsoftbus/src/wlan_param_monitor.c
+++ b/model/misc/dsoftbus/src/wlan_param_monitor.c
@@ -12,15 +12,13 @@
#include "hdf_log.h"
#include "module_manager.h"
#include "osal_time.h"
-#include "osal_timer.h"
#define HDF_LOG_TAG "wlan_param_monitor"
#define WLAN_PARAM_REPORT_INTERVAL 1000
typedef enum {
- CMD_START_MONITOR = 0,
- CMD_STOP_MONITOR,
+ CMD_REQUEST_PARAM = 0,
CMD_MAX_INDEX
} Command;
@@ -29,26 +27,16 @@ typedef enum {
EVENT_MAX_INDEX
} Event;
-typedef struct {
- OSAL_DECLARE_TIMER(timer);
- bool isTimerStart;
-} WlanParamMonitorCtrl;
-
typedef struct {
uint32_t event;
uint32_t value;
} ReportInfo;
-static WlanParamMonitorCtrl g_wlanParamMonitorCtrl = {
- .isTimerStart = false,
-};
-
-static void WlanParamReportTimer(uintptr_t arg)
+static void ProcessRequestParam(void)
{
ReportInfo info;
struct HdfSBuf *data = NULL;
- (void)arg;
info.event = EVENT_WLAN_PARAM;
info.value = (uint32_t)OsalGetSysTimeMs();
data = HdfSBufObtainDefaultSize();
@@ -65,38 +53,6 @@ static void WlanParamReportTimer(uintptr_t arg)
HdfSBufRecycle(data);
}
-static void ProcessStartMonitor(void)
-{
- if (g_wlanParamMonitorCtrl.isTimerStart) {
- HDF_LOGE("wlan param monitor timer is already started");
- return;
- }
- if (OsalTimerCreate(&g_wlanParamMonitorCtrl.timer, WLAN_PARAM_REPORT_INTERVAL,
- WlanParamReportTimer, 0) != HDF_SUCCESS) {
- HDF_LOGE("create wlan param monitor timer fail");
- return;
- }
- if (OsalTimerStartLoop(&g_wlanParamMonitorCtrl.timer) != HDF_SUCCESS) {
- OsalTimerDelete(&g_wlanParamMonitorCtrl.timer);
- HDF_LOGE("start wlan param monitor timer fail");
- return;
- }
- g_wlanParamMonitorCtrl.isTimerStart = true;
-}
-
-static void ProcessStopMonitor(void)
-{
- if (!g_wlanParamMonitorCtrl.isTimerStart) {
- HDF_LOGE("wlan param monitor timer is not started");
- return;
- }
- if (OsalTimerDelete(&g_wlanParamMonitorCtrl.timer) != HDF_SUCCESS) {
- HDF_LOGE("delete wlan param monitor timer fail");
- } else {
- g_wlanParamMonitorCtrl.isTimerStart = false;
- }
-}
-
int32_t SoftbusWlanParamMonitorInit(struct HdfDeviceObject *device)
{
(void)device;
@@ -104,13 +60,6 @@ int32_t SoftbusWlanParamMonitorInit(struct HdfDeviceObject *device)
return HDF_SUCCESS;
}
-void SoftbusWlanParamMonitorDeinit(void)
-{
- if (g_wlanParamMonitorCtrl.isTimerStart) {
- ProcessStartMonitor();
- }
-}
-
void SoftbusWlanParamMonitorProcess(const struct HdfSBuf *reqData, struct HdfSBuf *rspData)
{
uint32_t cmd;
@@ -128,14 +77,7 @@ void SoftbusWlanParamMonitorProcess(const struct HdfSBuf *reqData, struct HdfSBu
}
cmd = *((uint32_t *)data);
HDF_LOGI("process command: %d", cmd);
- switch (cmd) {
- case CMD_START_MONITOR:
- ProcessStartMonitor();
- break;
- case CMD_STOP_MONITOR:
- ProcessStopMonitor();
- break;
- default:
- break;
+ if (cmd == CMD_REQUEST_PARAM) {
+ ProcessRequestParam();
}
}
\ No newline at end of file
diff --git a/model/misc/vibrator/driver/chipset/vibrator_linear_driver.c b/model/misc/vibrator/driver/chipset/vibrator_linear_driver.c
index 6f126069ece6d8f5dcfc15bc5e2689d0cc6e7584..b6959fca1960f76259fc71cfc29b166fb24dbe4a 100644
--- a/model/misc/vibrator/driver/chipset/vibrator_linear_driver.c
+++ b/model/misc/vibrator/driver/chipset/vibrator_linear_driver.c
@@ -82,9 +82,11 @@ static int32_t DispatchLinearVibrator(struct HdfDeviceIoClient *client,
int32_t BindLinearVibratorDriver(struct HdfDeviceObject *device)
{
+ struct VibratorLinearDriverData *drvData = NULL;
+
CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(device, HDF_FAILURE);
- struct VibratorLinearDriverData *drvData = (struct VibratorLinearDriverData *)OsalMemCalloc(sizeof(*drvData));
+ drvData = (struct VibratorLinearDriverData *)OsalMemCalloc(sizeof(*drvData));
CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_MALLOC_FAIL);
drvData->ioService.Dispatch = DispatchLinearVibrator;
@@ -99,6 +101,7 @@ static int32_t ParserLinearConfig(const struct DeviceResourceNode *node, struct
{
int32_t ret;
struct DeviceResourceIface *parser = NULL;
+ const struct DeviceResourceNode *configNode = NULL;
CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(node, HDF_FAILURE);
CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_FAILURE);
@@ -107,7 +110,7 @@ static int32_t ParserLinearConfig(const struct DeviceResourceNode *node, struct
CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(parser, HDF_ERR_INVALID_PARAM);
CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(parser->GetChildNode, HDF_ERR_INVALID_PARAM);
- const struct DeviceResourceNode *configNode = parser->GetChildNode(node, "vibratorChipConfig");
+ configNode = parser->GetChildNode(node, "vibratorChipConfig");
ret = parser->GetUint32(configNode, "busType", &drvData->busType, 0);
CHECK_VIBRATOR_PARSER_RESULT_RETURN_VALUE(ret, "busType");
if (drvData->busType == VIBRATOR_BUS_GPIO) {
@@ -128,10 +131,11 @@ static int32_t ParserLinearConfig(const struct DeviceResourceNode *node, struct
int32_t InitLinearVibratorDriver(struct HdfDeviceObject *device)
{
static struct VibratorOps ops;
+ struct VibratorLinearDriverData *drvData = NULL;
CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(device, HDF_FAILURE);
- struct VibratorLinearDriverData *drvData = (struct VibratorLinearDriverData *)device->service;
+ drvData = (struct VibratorLinearDriverData *)device->service;
CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_FAILURE);
ops.Start = StartLinearVibrator;
@@ -157,11 +161,13 @@ int32_t InitLinearVibratorDriver(struct HdfDeviceObject *device)
void ReleaseLinearVibratorDriver(struct HdfDeviceObject *device)
{
+ struct VibratorLinearDriverData *drvData = NULL;
+
if (device == NULL) {
HDF_LOGE("%s: Device is null", __func__);
return;
}
- struct VibratorLinearDriverData *drvData = (struct VibratorLinearDriverData *)device->service;
+ drvData = (struct VibratorLinearDriverData *)device->service;
if (drvData == NULL) {
HDF_LOGE("%s: DrvData pointer is null", __func__);
return;
diff --git a/model/misc/vibrator/driver/include/vibrator_haptic.h b/model/misc/vibrator/driver/include/vibrator_haptic.h
index c6f4b10623a3bff6cbc6575ebc4504b2b5dcb24a..ec1d93d67f6e5468b90db080e99123e5e64c8fff 100644
--- a/model/misc/vibrator/driver/include/vibrator_haptic.h
+++ b/model/misc/vibrator/driver/include/vibrator_haptic.h
@@ -32,7 +32,8 @@ enum VibratorTimeSeqIndex {
struct VibratorEffectNode {
const char *effect;
int32_t num;
- uint32_t *seq; // The first element of seq is preset type referring to enum VibratorEffectType
+ uint32_t type; // preset type
+ uint32_t *seq;
struct DListHead node;
};
diff --git a/model/misc/vibrator/driver/src/vibrator_haptic.c b/model/misc/vibrator/driver/src/vibrator_haptic.c
index 2fba10f7af56abd01a5c37eb7249de63eaaa2021..a4177106440bd8849f819373b1c273e36e1bf0f2 100644
--- a/model/misc/vibrator/driver/src/vibrator_haptic.c
+++ b/model/misc/vibrator/driver/src/vibrator_haptic.c
@@ -60,21 +60,20 @@ static int32_t ParserHapticEffect(struct DeviceResourceIface *parser, const stru
int32_t ret;
int32_t count;
struct VibratorEffectNode *effectNode = NULL;
- const struct DeviceResourceAttr *hapticAttr = NULL;
+ const struct DeviceResourceNode *childNode = NULL;
struct VibratorHapticData *hapticData = GetHapticData();
CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(hapticData, HDF_FAILURE);
(void)OsalMutexLock(&hapticData->mutex);
- DEV_RES_NODE_FOR_EACH_ATTR(hapticNode, hapticAttr) {
- if ((hapticAttr == NULL) || (hapticAttr->name == NULL)) {
+ DEV_RES_NODE_FOR_EACH_CHILD_NODE(hapticNode, childNode) {
+ if ((childNode == NULL) || (childNode->name == NULL)) {
break;
}
- count = parser->GetElemNum(hapticNode, hapticAttr->name);
- // Minimum of two elements, including the type and sequence.
+ count = parser->GetElemNum(childNode, "seq");
if (count <= 1 || count > VIBRATOR_HAPTIC_SEQ_MAX) {
- HDF_LOGE("%s: haptic [%s] parser seq count fail", __func__, hapticAttr->name);
+ HDF_LOGE("%s: haptic [%s] parser seq count fail", __func__, childNode->name);
continue;
}
@@ -83,10 +82,11 @@ static int32_t ParserHapticEffect(struct DeviceResourceIface *parser, const stru
HDF_LOGE("%s: malloc effect effectNode fail", __func__);
continue;
}
- effectNode->effect = hapticAttr->name;
- ret = parser->GetUint32Array(hapticNode, hapticAttr->name, effectNode->seq, count, 0);
- CHECK_VIBRATOR_PARSER_RESULT_RETURN_VALUE(ret, hapticAttr->name);
effectNode->num = count;
+ ret = parser->GetString(childNode, "effectName", &effectNode->effect, NULL);
+ ret = parser->GetUint32(childNode, "type", &effectNode->type, 0);
+ ret = parser->GetUint32Array(childNode, "seq", effectNode->seq, count, 0);
+
DListInsertTail(&effectNode->node, &hapticData->effectSeqHead);
}
(void)OsalMutexUnlock(&hapticData->mutex);
@@ -249,9 +249,10 @@ static int32_t GetHapticSeqByEffect(struct VibratorEffectCfg *effectCfg)
if ((effectCfg->cfgMode == VIBRATOR_MODE_PRESET) && (effectCfg->effect != NULL)) {
DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &hapticData->effectSeqHead, struct VibratorEffectNode, node) {
if (strcmp(effectCfg->effect, pos->effect) == 0 && pos->seq != NULL) {
- hapticData->effectType = pos->seq[0];
- hapticData->seqCount = pos->num - 1;
- hapticData->currentEffectSeq = &(pos->seq[1]);
+ hapticData->effectType = pos->type;
+ HDF_LOGE("%s: pos_num = %d", __func__, pos->num);
+ hapticData->seqCount = pos->num;
+ hapticData->currentEffectSeq = &(pos->seq[0]);
break;
}
}
diff --git a/model/network/wifi/bus/hdf_ibus_intf.c b/model/network/wifi/bus/hdf_ibus_intf.c
index 4139843752a5867966038f35e7cf7e50871b2987..8a0bde671bbb5750afa64e5006508af21f263949 100644
--- a/model/network/wifi/bus/hdf_ibus_intf.c
+++ b/model/network/wifi/bus/hdf_ibus_intf.c
@@ -19,14 +19,14 @@ extern "C" {
struct BusDev *HdfWlanCreateBusManager(const struct HdfConfigWlanBus *busConfig)
{
+ struct BusDev *bus = NULL;
if (busConfig == NULL) {
return NULL;
}
- struct BusDev *bus = (struct BusDev *)OsalMemCalloc(sizeof(struct BusDev));
+ bus = (struct BusDev *)OsalMemCalloc(sizeof(struct BusDev));
if (bus == NULL) {
return NULL;
}
-
switch (busConfig->busType) {
case BUS_SDIO:
if (HdfSdioBusInit(bus, busConfig) != HDF_SUCCESS) {
diff --git a/model/network/wifi/core/components/p2p/p2p.c b/model/network/wifi/core/components/p2p/p2p.c
new file mode 100755
index 0000000000000000000000000000000000000000..279561a04737a130afb8d73160492e8e3d938cf6
--- /dev/null
+++ b/model/network/wifi/core/components/p2p/p2p.c
@@ -0,0 +1,400 @@
+/*
+ * 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 "p2p.h"
+#include "message/message_router.h"
+#include "message/sidecar.h"
+#include "wifi_base.h"
+#include "wifi_mac80211_ops.h"
+#include "hdf_wlan_services.h"
+#include "hdf_wlan_utils.h"
+
+#define HDF_LOG_TAG HDF_WIFI_CORE
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+static int32_t RemainOnChannel(struct NetDevice *netdev, WifiOnChannel *onChannel)
+{
+ struct HdfChipDriver *chipDriver = GetChipDriver(netdev);
+ if (chipDriver == NULL) {
+ HDF_LOGE("%s:bad net device found!", __func__);
+ return HDF_FAILURE;
+ }
+
+ RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->p2pOps, RemainOnChannel);
+ return chipDriver->p2pOps->RemainOnChannel(netdev, onChannel);
+}
+
+static int32_t WifiCmdRemainOnChannel(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
+{
+ int32_t ret;
+ struct NetDevice *netdev = NULL;
+ const char *ifName = NULL;
+ WifiOnChannel wifiOnChannel = {0};
+
+ (void)context;
+ if (reqData == NULL || rspData == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ ifName = HdfSbufReadString(reqData);
+ if (ifName == NULL) {
+ HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
+ return HDF_FAILURE;
+ }
+ netdev = NetDeviceGetInstByName(ifName);
+ if (netdev == NULL) {
+ HDF_LOGE("%s: netdev not found!ifName=%s", __func__, ifName);
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufReadUint32(reqData, &(wifiOnChannel.freq))) {
+ HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "freq");
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufReadUint32(reqData, &(wifiOnChannel.duration))) {
+ HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "duration");
+ return HDF_FAILURE;
+ }
+ ret = RemainOnChannel(netdev, &wifiOnChannel);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: fail to remain on channel,%d", __func__, ret);
+ }
+ return ret;
+}
+
+static int32_t ProbeReqReport(struct NetDevice *netdev, int32_t report)
+{
+ struct HdfChipDriver *chipDriver = GetChipDriver(netdev);
+ if (chipDriver == NULL) {
+ HDF_LOGE("%s:bad net device found!", __func__);
+ return HDF_FAILURE;
+ }
+
+ RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->p2pOps, ProbeReqReport);
+ return chipDriver->p2pOps->ProbeReqReport(netdev, report);
+}
+
+static int32_t WifiCmdProbeReqReport(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
+{
+ int32_t ret;
+ struct NetDevice *netdev = NULL;
+ const char *ifName = NULL;
+ int32_t report;
+
+ (void)context;
+ if (reqData == NULL || rspData == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ ifName = HdfSbufReadString(reqData);
+ if (ifName == NULL) {
+ HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
+ return HDF_FAILURE;
+ }
+ netdev = NetDeviceGetInstByName(ifName);
+ if (netdev == NULL) {
+ HDF_LOGE("%s: netdev not found!ifName=%s", __func__, ifName);
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufReadInt32(reqData, &(report))) {
+ HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "report");
+ return HDF_FAILURE;
+ }
+
+ ret = ProbeReqReport(netdev, report);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: fail to probe req report,%d", __func__, ret);
+ }
+ return ret;
+}
+
+static int32_t CancelRemainOnChannel(struct NetDevice *netdev)
+{
+ struct HdfChipDriver *chipDriver = GetChipDriver(netdev);
+ if (chipDriver == NULL) {
+ HDF_LOGE("%s:bad net device found!", __func__);
+ return HDF_FAILURE;
+ }
+
+ RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->p2pOps, CancelRemainOnChannel);
+ return chipDriver->p2pOps->CancelRemainOnChannel(netdev);
+}
+
+static int32_t WifiCmdCancelRemainOnChannel(const RequestContext *context, struct HdfSBuf *reqData,
+ struct HdfSBuf *rspData)
+{
+ int32_t ret;
+ struct NetDevice *netdev = NULL;
+ const char *ifName = NULL;
+
+ (void)context;
+ if (reqData == NULL || rspData == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ ifName = HdfSbufReadString(reqData);
+ if (ifName == NULL) {
+ HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
+ return HDF_FAILURE;
+ }
+ netdev = NetDeviceGetInstByName(ifName);
+ if (netdev == NULL) {
+ HDF_LOGE("%s: netdev not found!ifName=%s", __func__, ifName);
+ return HDF_FAILURE;
+ }
+
+ ret = CancelRemainOnChannel(netdev);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: fail to cancel remain on channel,%d", __func__, ret);
+ }
+ return ret;
+}
+
+static int32_t AddIf(struct NetDevice *netdev, WifiIfAdd *ifAdd)
+{
+ struct HdfChipDriver *chipDriver = GetChipDriver(netdev);
+ if (chipDriver == NULL) {
+ HDF_LOGE("%s:bad net device found!", __func__);
+ return HDF_FAILURE;
+ }
+
+ RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->p2pOps, AddIf);
+ return chipDriver->p2pOps->AddIf(netdev, ifAdd);
+}
+
+static int32_t WifiCmdAddIf(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
+{
+ int32_t ret;
+ struct NetDevice *netdev = NULL;
+ const char *ifName = NULL;
+ WifiIfAdd ifAdd = {0};
+
+ (void)context;
+ if (reqData == NULL || rspData == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ ifName = HdfSbufReadString(reqData);
+ if (ifName == NULL) {
+ HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
+ return HDF_FAILURE;
+ }
+ netdev = NetDeviceGetInstByName(ifName);
+ if (netdev == NULL) {
+ HDF_LOGE("%s: netdev not found!ifName=%s", __func__, ifName);
+ return HDF_FAILURE;
+ }
+
+ if (!HdfSbufReadUint8(reqData, &(ifAdd.type))) {
+ HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "type");
+ return HDF_FAILURE;
+ }
+
+ ret = AddIf(netdev, &ifAdd);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: fail to cancel remain on channel,%d", __func__, ret);
+ }
+ return ret;
+}
+
+static int32_t RemoveIf(struct NetDevice *netdev, WifiIfRemove *ifRemove)
+{
+ struct HdfChipDriver *chipDriver = GetChipDriver(netdev);
+ if (chipDriver == NULL) {
+ HDF_LOGE("%s:bad net device found!", __func__);
+ return HDF_FAILURE;
+ }
+
+ RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->p2pOps, RemoveIf);
+ return chipDriver->p2pOps->RemoveIf(netdev, ifRemove);
+}
+
+static int32_t WifiCmdRemoveIf(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
+{
+ int32_t ret;
+ struct NetDevice *netdev = NULL;
+ const char *ifName = NULL;
+ WifiIfRemove *ifRemove = NULL;
+ uint32_t dataSize;
+ (void)context;
+ if (reqData == NULL || rspData == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ ifName = HdfSbufReadString(reqData);
+ if (ifName == NULL) {
+ HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
+ return HDF_FAILURE;
+ }
+ netdev = NetDeviceGetInstByName(ifName);
+ if (netdev == NULL) {
+ HDF_LOGE("%s: netdev not found!ifName=%s", __func__, ifName);
+ return HDF_FAILURE;
+ }
+
+ dataSize = 0;
+ if (!HdfSbufReadBuffer(reqData, (const void **)&(ifRemove), &dataSize) || dataSize != sizeof(WifiIfRemove)) {
+ HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
+ return HDF_FAILURE;
+ }
+ ret = RemoveIf(netdev, ifRemove);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: fail to remove interface,%d", __func__, ret);
+ }
+ return ret;
+}
+
+static int32_t SetApWpsP2pIe(struct NetDevice *netdev, WifiAppIe *appIe)
+{
+ struct HdfChipDriver *chipDriver = GetChipDriver(netdev);
+ if (chipDriver == NULL) {
+ HDF_LOGE("%s:bad net device found!", __func__);
+ return HDF_FAILURE;
+ }
+
+ RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->p2pOps, SetApWpsP2pIe);
+ return chipDriver->p2pOps->SetApWpsP2pIe(netdev, appIe);
+}
+
+static int32_t WifiCmdSetApWpsP2pIe(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
+{
+ int32_t ret;
+ struct NetDevice *netdev = NULL;
+ const char *ifName = NULL;
+ WifiAppIe appIe = {0};
+
+ (void)context;
+ if (reqData == NULL || rspData == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ ifName = HdfSbufReadString(reqData);
+ if (ifName == NULL) {
+ HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
+ return HDF_FAILURE;
+ }
+ netdev = NetDeviceGetInstByName(ifName);
+ if (netdev == NULL) {
+ HDF_LOGE("%s: netdev not found!ifName=%s", __func__, ifName);
+ return HDF_FAILURE;
+ }
+
+ if (!HdfSbufReadUint32(reqData, &(appIe.ieLen))) {
+ HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ieLen");
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufReadUint8(reqData, &(appIe.appIeType))) {
+ HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "appIeType");
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufReadBuffer(reqData, (const void**)&(appIe.ie), &(appIe.ieLen))) {
+ HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "appIeType");
+ return HDF_FAILURE;
+ }
+ ret = SetApWpsP2pIe(netdev, &appIe);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: fail to setapwpsp2pie,%d", __func__, ret);
+ }
+ return ret;
+}
+
+int32_t GetDriverFlag (struct NetDevice *netdev, WifiGetDrvFlags **params)
+{
+ struct HdfChipDriver *chipDriver = GetChipDriver(netdev);
+ if (chipDriver == NULL) {
+ HDF_LOGE("%s:bad net device found!", __func__);
+ return HDF_FAILURE;
+ }
+
+ RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->p2pOps, GetDriverFlag);
+ return chipDriver->p2pOps->GetDriverFlag(netdev, params);
+}
+
+static int32_t WifiCmdGetDriverFlag(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
+{
+ int32_t ret;
+ struct NetDevice *netdev = NULL;
+ const char *ifName = NULL;
+ WifiGetDrvFlags *params = NULL;
+
+ (void)context;
+ if (reqData == NULL || rspData == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ ifName = HdfSbufReadString(reqData);
+ if (ifName == NULL) {
+ HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
+ return HDF_FAILURE;
+ }
+ netdev = NetDeviceGetInstByName(ifName);
+ if (netdev == NULL) {
+ HDF_LOGE("%s: netdev not found!ifName=%s", __func__, ifName);
+ return HDF_FAILURE;
+ }
+
+ ret = GetDriverFlag(netdev, ¶ms);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: fail to getdriverflag,%d", __func__, ret);
+ }
+
+ if (!HdfSbufWriteUint64(rspData, params->drvFlags)) {
+ HDF_LOGE("%s:%s!", __func__, ERROR_DESC_WRITE_RSP_FAILED);
+ ret = HDF_ERR_IO;
+ }
+
+ HDF_LOGE("WifiCmdGetDriverFlag:%llx", params->drvFlags);
+ return ret;
+}
+
+static struct MessageDef g_wifiP2pFeatureCmds[] = {
+ DUEMessage(CMD_P2P_PROBE_REQ_REPORT, WifiCmdProbeReqReport, 0),
+ DUEMessage(CMD_P2P_REMAIN_ON_CHANNEL, WifiCmdRemainOnChannel, 0),
+ DUEMessage(CMD_P2P_CANCEL_REMAIN_ON_CHANNEL, WifiCmdCancelRemainOnChannel, 0),
+ DUEMessage(CMD_P2P_ADD_IF, WifiCmdAddIf, 0),
+ DUEMessage(CMD_P2P_REMOVE_IF, WifiCmdRemoveIf, 0),
+ DUEMessage(CMD_P2P_SET_AP_WPS_P2P_IE, WifiCmdSetApWpsP2pIe, 0),
+ DUEMessage(CMD_P2P_GET_DRIVER_FLAGS, WifiCmdGetDriverFlag, 0),
+};
+ServiceDefine(P2PService, P2P_SERVICE_ID, g_wifiP2pFeatureCmds);
+
+static Service *g_p2pService = NULL;
+
+int32_t P2pInit(struct WifiFeature *feature)
+{
+ (void)feature;
+ if (g_p2pService == NULL) {
+ ServiceCfg cfg = {
+ .dispatcherId = DEFAULT_DISPATCHER_ID
+ };
+ g_p2pService = CreateService(P2PService, &cfg);
+ if (g_p2pService == NULL) {
+ return HDF_FAILURE;
+ }
+ }
+ return HDF_SUCCESS;
+}
+
+int32_t P2pDeinit(struct WifiFeature *feature)
+{
+ (void)feature;
+ if (g_p2pService != NULL && g_p2pService->Destroy != NULL) {
+ g_p2pService->Destroy(g_p2pService);
+ g_p2pService = NULL;
+ }
+ return HDF_SUCCESS;
+}
+
+struct WifiFeature g_wifiP2PFeature = {
+ .name = "p2p",
+ .init = P2pInit,
+ .deInit = P2pDeinit
+};
+
+struct WifiFeature *GetWifiP2pFeature(void)
+{
+ return &g_wifiP2PFeature;
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/model/network/wifi/core/components/p2p/p2p.h b/model/network/wifi/core/components/p2p/p2p.h
new file mode 100755
index 0000000000000000000000000000000000000000..be36bc23e9d8f3cc3d066a70693ece2aae075547
--- /dev/null
+++ b/model/network/wifi/core/components/p2p/p2p.h
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+#ifndef HDFLITE_P2P_H
+#define HDFLITE_P2P_H
+
+#include "wifi_module.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct WifiFeature *GetWifiP2pFeature(void);
+
+#ifdef __cplusplus
+}
+#endif
+#endif // HDFLITE_P2P_H
diff --git a/model/network/wifi/core/components/softap/ap.c b/model/network/wifi/core/components/softap/ap.c
index d685abed7f9b77c0cabaf84d50cf994c1743da98..8b15e8e0f87aedca33de1a92a0619166925c3539 100644
--- a/model/network/wifi/core/components/softap/ap.c
+++ b/model/network/wifi/core/components/softap/ap.c
@@ -29,12 +29,10 @@ static uint32_t ChangeBeacon(struct NetDevice *netDev, WifiApSetting *apSettings
HDF_LOGE("%s:bad net device found!", __func__);
return HDF_FAILURE;
}
-
if (netDev == NULL || apSettings == NULL) {
HDF_LOGE("%s: parameter null", __func__);
return HDF_FAILURE;
}
-
beaconConf.interval = apSettings->beaconInterval;
beaconConf.DTIMPeriod = apSettings->dtimPeriod;
beaconConf.hiddenSSID = (apSettings->hiddenSsid == 1);
@@ -42,24 +40,23 @@ static uint32_t ChangeBeacon(struct NetDevice *netDev, WifiApSetting *apSettings
beaconConf.headIEsLength = apSettings->beaconData.headLen;
beaconConf.tailIEs = apSettings->beaconData.tail;
beaconConf.tailIEsLength = apSettings->beaconData.tailLen;
-
RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->apOps, ConfigBeacon);
return chipDriver->apOps->ConfigBeacon(netDev, &beaconConf);
}
static int32_t StartAp(struct NetDevice *netDev, WifiApSetting *apSettings)
{
- HDF_LOGE("%s:starting ap...", __func__);
struct WlanAPConf apConf = { 0 };
int32_t ret;
- struct HdfChipDriver *chipDriver = GetChipDriver(netDev);
+ struct HdfChipDriver *chipDriver = NULL;
+ errno_t err;
+ HDF_LOGI("%s:starting ap...", __func__);
+ chipDriver = GetChipDriver(netDev);
if (chipDriver == NULL) {
HDF_LOGE("%s:bad net device found!", __func__);
return HDF_FAILURE;
}
-
- apConf.band = IEEE80211_BAND_2GHZ;
- errno_t err = memcpy_s(apConf.ssidConf.ssid, IEEE80211_MAX_SSID_LEN, apSettings->ssid, apSettings->ssidLen);
+ err = memcpy_s(apConf.ssidConf.ssid, IEEE80211_MAX_SSID_LEN, apSettings->ssid, apSettings->ssidLen);
if (err != EOK) {
HDF_LOGE("%s: memcpy_s failed!ret=%d", __func__, err);
return HDF_FAILURE;
@@ -68,20 +65,18 @@ static int32_t StartAp(struct NetDevice *netDev, WifiApSetting *apSettings)
apConf.centerFreq1 = apSettings->freqParams.centerFreq1;
apConf.channel = apSettings->freqParams.channel;
apConf.width = apSettings->freqParams.bandwidth;
-
+ apConf.band = apSettings->freqParams.band;
RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->apOps, ConfigAp);
ret = chipDriver->apOps->ConfigAp(netDev, &apConf);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:ConfigAp failed!ret=%d", __func__, ret);
return HDF_FAILURE;
}
-
ret = ChangeBeacon(netDev, apSettings);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:ChangeBeacon failed!ret=%d", __func__, ret);
return HDF_FAILURE;
}
-
RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->apOps, StartAp);
ret = chipDriver->apOps->StartAp(netDev);
if (ret != HDF_SUCCESS) {
@@ -99,14 +94,12 @@ static uint32_t StopAp(struct NetDevice *netDev)
HDF_LOGE("%s:bad net device found!", __func__);
return HDF_FAILURE;
}
-
RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->apOps, StopAp);
ret = chipDriver->apOps->StopAp(netDev);
if (ret != HDF_SUCCESS) {
HDF_LOGE("StopAp:failed, error[%d]", ret);
return ret;
}
-
return NetIfSetStatus(netDev, NETIF_DOWN);
}
@@ -139,7 +132,6 @@ static uint32_t GetAssociatedStasCount(struct NetDevice *netDev, uint32_t *num)
HDF_LOGE("%s:bad net device found!", __func__);
return HDF_FAILURE;
}
-
RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->apOps, GetAssociatedStasCount);
return chipDriver->apOps->GetAssociatedStasCount(netDev, num);
}
@@ -161,7 +153,6 @@ static int32_t WifiCmdSetAp(const RequestContext *context, struct HdfSBuf *reqDa
uint32_t settingLen = 0;
const char *ifName = NULL;
struct NetDevice *netdev = NULL;
-
(void)context;
(void)rspData;
if (reqData == NULL) {
@@ -199,7 +190,6 @@ static int32_t WifiCmdSetAp(const RequestContext *context, struct HdfSBuf *reqDa
HDF_LOGE("%s:netdev not found!ifName=%s", __func__, ifName);
return HDF_FAILURE;
}
-
HDF_LOGI("%s:%s starting AP ...", __func__, ifName);
return StartAp(netdev, apSettings);
}
@@ -208,7 +198,6 @@ static int32_t WifiCmdStopAp(const RequestContext *context, struct HdfSBuf *reqD
{
const char *ifName = NULL;
struct NetDevice *netdev = NULL;
-
(void)context;
(void)rspData;
if (reqData == NULL) {
@@ -220,13 +209,11 @@ static int32_t WifiCmdStopAp(const RequestContext *context, struct HdfSBuf *reqD
HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
return HDF_FAILURE;
}
-
netdev = NetDeviceGetInstByName(ifName);
if (netdev == NULL) {
HDF_LOGE("%s:netdev not found!ifName=%s", __func__, ifName);
return HDF_FAILURE;
}
-
HDF_LOGI("%s:%s stopping AP ...", __func__, ifName);
return StopAp(netdev);
}
@@ -237,7 +224,6 @@ static int32_t WifiCmdChangeBeacon(const RequestContext *context, struct HdfSBuf
WifiApSetting *apSettings = NULL;
uint32_t settingLen = 0;
const char *ifName = NULL;
-
(void)context;
(void)rspData;
if (reqData == NULL) {
@@ -275,7 +261,6 @@ static int32_t WifiCmdChangeBeacon(const RequestContext *context, struct HdfSBuf
HDF_LOGE("%s:netdev not found!ifName=%s", __func__, ifName);
return HDF_FAILURE;
}
-
return ChangeBeacon(netdev, apSettings);
}
@@ -286,7 +271,6 @@ static int32_t WifiCmdStaRemove(const RequestContext *context, struct HdfSBuf *r
const char *ifName = NULL;
uint32_t dataSize = 0;
int32_t ret;
-
(void)context;
(void)rspData;
if (reqData == NULL) {
@@ -298,20 +282,17 @@ static int32_t WifiCmdStaRemove(const RequestContext *context, struct HdfSBuf *r
HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
return HDF_FAILURE;
}
-
netdev = NetDeviceGetInstByName(ifName);
if (netdev == NULL) {
HDF_LOGE("%s:netdev not found!ifName=%s", __func__, ifName);
return HDF_FAILURE;
}
-
params.subtype = 0;
params.reasonCode = 0;
if (!HdfSbufReadBuffer(reqData, (const void **)¶ms.mac, &dataSize) || dataSize != ETH_ADDR_LEN) {
HDF_LOGE("%s: %s!ParamName=%s,readSize=%u", __func__, ERROR_DESC_READ_REQ_FAILED, "mac", dataSize);
return HDF_FAILURE;
}
-
ret = DelStation(netdev, ¶ms);
HDF_LOGI("%s:del station XX:XX:XX:XX:XX:%02X ret=%d", __func__, params.mac[ETH_ADDR_LEN - 1], ret);
return ret;
@@ -321,7 +302,6 @@ static int32_t GetAssociatedStas(struct NetDevice *netdev, uint32_t num, struct
{
int32_t ret;
WifiStaInfo *staInfo = NULL;
-
staInfo = (WifiStaInfo *)OsalMemCalloc(sizeof(WifiStaInfo) * num);
if (staInfo == NULL) {
HDF_LOGE("%s: OsalMemCalloc failed!", __func__);
@@ -348,7 +328,6 @@ static int32_t WifiCmdGetAssociatedStas(const RequestContext *context, struct Hd
struct NetDevice *netdev = NULL;
const char *ifName = NULL;
uint32_t num;
-
(void)context;
if (reqData == NULL || rspData == NULL) {
return HDF_ERR_INVALID_PARAM;
@@ -389,7 +368,6 @@ static int32_t WifiCmdSetCountryCode(const RequestContext *context, struct HdfSB
const char *ifName = NULL;
const char *code = NULL;
uint32_t replayDataSize;
-
(void)context;
if (reqData == NULL || rspData == NULL) {
return HDF_ERR_INVALID_PARAM;
diff --git a/model/network/wifi/core/components/sta/sta.c b/model/network/wifi/core/components/sta/sta.c
index f72abde6bc17b29f11c1217929cabae320de982b..2bd56db640f60838b1068bff5df3865576708279 100644
--- a/model/network/wifi/core/components/sta/sta.c
+++ b/model/network/wifi/core/components/sta/sta.c
@@ -60,7 +60,6 @@ inline static int32_t AbortScan(struct NetDevice *netDev)
HDF_LOGE("%s:bad net device found!", __func__);
return HDF_FAILURE;
}
-
RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->staOps, AbortScan);
return chipDriver->staOps->AbortScan(netDev);
}
@@ -68,24 +67,20 @@ inline static int32_t AbortScan(struct NetDevice *netDev)
static int WifiFillScanParam(struct WlanScanRequest *params, struct HdfSBuf *reqData)
{
uint32_t dataSize = 0;
-
if (!HdfSbufReadBuffer(reqData, (const void **)¶ms->bssid, &dataSize)) {
HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "apSettings");
return HDF_FAILURE;
}
-
if (!HdfSbufReadBuffer(reqData, (const void **)¶ms->ssids, &dataSize)) {
HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ssids");
return HDF_FAILURE;
}
params->ssidCount = dataSize / sizeof(params->ssids[0]);
-
if (!HdfSbufReadBuffer(reqData, (const void **)¶ms->extraIEs, &dataSize)) {
HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "extraIes");
return HDF_FAILURE;
}
params->extraIEsLen = dataSize;
-
if (!HdfSbufReadBuffer(reqData, (const void **)¶ms->freqs, &dataSize)) {
HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "freqs");
return HDF_FAILURE;
@@ -99,17 +94,14 @@ static int WifiFillScanParam(struct WlanScanRequest *params, struct HdfSBuf *req
static uint8_t WifiValidIeAttr(const uint8_t *ie, uint32_t len)
{
uint8_t elemLen;
-
if (ie == NULL) { // ie null is normal
return true;
}
-
while (len != 0) {
if (len < 2) {
return false;
}
len -= 2;
-
elemLen = ie[1];
if (elemLen > len) {
return false;
@@ -117,19 +109,16 @@ static uint8_t WifiValidIeAttr(const uint8_t *ie, uint32_t len)
len -= elemLen;
ie += 2 + elemLen;
}
-
return true;
}
static int WifiFillAssocParams(WifiAssociateParams *assoc, struct HdfSBuf *reqData)
{
uint32_t dataSize = 0;
-
if (!HdfSbufReadBuffer(reqData, (const void **)&assoc->bssid, &dataSize) || dataSize != ETH_ADDR_LEN) {
HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "bssid");
return HDF_FAILURE;
}
-
if (!HdfSbufReadBuffer(reqData, (const void **)&assoc->ssid, &(assoc->ssidLen))) {
HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ssid");
return HDF_FAILURE;
@@ -170,7 +159,6 @@ static int WifiFillAssocParams(WifiAssociateParams *assoc, struct HdfSBuf *reqDa
HDF_LOGE("%s:void ssid", __func__);
return HDF_FAILURE;
}
-
if (WifiValidIeAttr(assoc->ie, assoc->ieLen) == false) {
HDF_LOGE("%s:illegal ie", __func__);
return HDF_FAILURE;
@@ -185,27 +173,23 @@ static int WifiSetAssocParams(const WifiAssociateParams *assoc, const struct Net
params->ssidLen = assoc->ssidLen;
params->ie = assoc->ie;
params->ieLen = assoc->ieLen;
-
if ((assoc->authType > WIFI_AUTHTYPE_AUTOMATIC) || (assoc->authType == WIFI_AUTHTYPE_SAE)) {
HDF_LOGE("%s:illegal authType %u", __func__, assoc->authType);
return HDF_FAILURE;
}
params->authType = assoc->authType;
-
params->bssid = assoc->bssid;
params->privacy = assoc->privacy;
if ((assoc->mfp != WIFI_MFP_REQUIRED) && (assoc->mfp != WIFI_MFP_NO) && (assoc->mfp != WIFI_MFP_OPTIONAL)) {
HDF_LOGE("%s:unexpected mfp.mfp=%u", __func__, assoc->mfp);
return HDF_FAILURE;
}
-
params->mfp = (WifiMfp)assoc->mfp;
if (assoc->key != NULL) {
params->key = assoc->key;
params->keyLen = assoc->keyLen;
params->keyIdx = assoc->keyIdx;
}
-
if (memcpy_s(¶ms->crypto, sizeof(WifiCryptoSetting), assoc->crypto, sizeof(WifiCryptoSetting)) != EOK) {
HDF_LOGE("%s:copy crypto failed!", __func__);
return HDF_FAILURE;
@@ -221,7 +205,6 @@ static int32_t WifiCmdAssoc(const RequestContext *context, struct HdfSBuf *reqDa
struct WlanHwCapability *capability = NULL;
const char *ifName = NULL;
int32_t ret;
-
(void)context;
(void)rspData;
if (reqData == NULL) {
@@ -236,7 +219,6 @@ static int32_t WifiCmdAssoc(const RequestContext *context, struct HdfSBuf *reqDa
if (WifiFillAssocParams(&assoc, reqData) != HDF_SUCCESS) {
return HDF_FAILURE;
}
-
if ((netdev = NetDeviceGetInstByName(ifName)) == NULL) {
HDF_LOGE("%s:netdev not found!ifName=%s", __func__, ifName);
return HDF_FAILURE;
@@ -244,7 +226,6 @@ static int32_t WifiCmdAssoc(const RequestContext *context, struct HdfSBuf *reqDa
if (WifiSetAssocParams(&assoc, netdev, ¶ms) != HDF_SUCCESS) {
return HDF_FAILURE;
}
-
capability = GetHwCapability(netdev);
if (capability == NULL) {
HDF_LOGE("%s:GetHwCapability failed!", __func__);
@@ -259,12 +240,10 @@ static int32_t WifiCmdAssoc(const RequestContext *context, struct HdfSBuf *reqDa
break;
}
} while (false);
-
if (capability->Release != NULL) {
capability->Release(capability);
capability = NULL;
}
-
return ret;
}
@@ -274,7 +253,6 @@ static int32_t WifiCmdDisconnect(const RequestContext *context, struct HdfSBuf *
uint16_t reasonCode;
const char *ifName = NULL;
int ret;
-
(void)context;
(void)rspData;
if (reqData == NULL) {
@@ -286,7 +264,6 @@ static int32_t WifiCmdDisconnect(const RequestContext *context, struct HdfSBuf *
HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
return HDF_FAILURE;
}
-
if (!HdfSbufReadUint16(reqData, &reasonCode)) {
HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "reasonCode");
return HDF_FAILURE;
@@ -296,7 +273,6 @@ static int32_t WifiCmdDisconnect(const RequestContext *context, struct HdfSBuf *
HDF_LOGE("%s:netdev not found!ifName=%s", __func__, ifName);
return HDF_FAILURE;
}
-
HDF_LOGW("%s:%s disconnecting from AP...", __func__, ifName);
ret = Disconnect(netdev, reasonCode);
if (ret != HDF_SUCCESS) {
@@ -311,7 +287,6 @@ static int32_t WifiCmdScan(const RequestContext *context, struct HdfSBuf *reqDat
const char *ifName = NULL;
struct WlanScanRequest params = { 0 };
int32_t ret;
-
(void)context;
(void)rspData;
if (reqData == NULL) {
@@ -332,7 +307,6 @@ static int32_t WifiCmdScan(const RequestContext *context, struct HdfSBuf *reqDat
if (ret != HDF_SUCCESS) {
return ret;
}
-
ret = ScanAll(netdev, ¶ms);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:ScanAll failed!ret=%d", __func__, ret);
@@ -345,10 +319,8 @@ static int32_t WifiCmdAbortScan(const RequestContext *context, struct HdfSBuf *r
struct NetDevice *netdev = NULL;
int32_t ret;
const char *ifName = HdfSbufReadString(reqData);
-
(void)context;
(void)rspData;
-
if (ifName == NULL) {
HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
return HDF_FAILURE;
@@ -362,7 +334,6 @@ static int32_t WifiCmdAbortScan(const RequestContext *context, struct HdfSBuf *r
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:AbortScan failed!ret=%d", __func__, ret);
}
-
// keep return SUCCESS if AbortScan return FAILED
return HDF_SUCCESS;
}
@@ -376,7 +347,7 @@ static int32_t WifiCmdSetScanningMacAddress(const RequestContext *context, struc
const char *ifName = NULL;
unsigned char *mac = NULL;
uint32_t replayDataSize;
-
+ struct HdfChipDriver *chipDriver = NULL;
(void)context;
if (reqData == NULL || rspData == NULL) {
return HDF_ERR_INVALID_PARAM;
@@ -396,14 +367,12 @@ static int32_t WifiCmdSetScanningMacAddress(const RequestContext *context, struc
HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "mac");
return HDF_FAILURE;
}
-
- struct HdfChipDriver *chipDriver = GetChipDriver(netdev);
+ chipDriver = GetChipDriver(netdev);
if (chipDriver == NULL) {
HDF_LOGE("%s:bad net device found!", __func__);
return HDF_FAILURE;
}
RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->staOps, SetScanningMacAddress);
-
ret = chipDriver->staOps->SetScanningMacAddress(netdev, mac, IEEE80211_MAC_ADDR_LEN);
if (ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT) {
HDF_LOGE("%s: fail to do set scanning mac addr!ret=%d", __func__, ret);
diff --git a/model/network/wifi/core/module/wifi_base.c b/model/network/wifi/core/module/wifi_base.c
index 1d19774a23e801cab8d61bd783cd05795ea96ecf..8fc2c09378c51c102d763386d2488bd752e38b55 100644
--- a/model/network/wifi/core/module/wifi_base.c
+++ b/model/network/wifi/core/module/wifi_base.c
@@ -29,6 +29,7 @@
#endif
#define WIFI_24G_CHANNEL_NUM 14
+#define WIFI_MAX_CHANNEL_NUM 24
#define DEFAULT_EAPOL_PACKAGE_SIZE 800
Service *g_baseService = NULL;
@@ -366,13 +367,11 @@ static int32_t WifiCmdEnableEapol(const RequestContext *context, struct HdfSBuf
HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
return HDF_FAILURE;
}
-
netdev = NetDeviceGetInstByName(ifName);
if (netdev == NULL) {
HDF_LOGE("%s:netdev not found!ifName=%s", __func__, ifName);
return HDF_FAILURE;
}
-
eapol.callback = (void *)HdfWifiEventEapolRecv;
eapol.context = NULL;
@@ -383,7 +382,6 @@ static int32_t WifiCmdDisableEapol(const RequestContext *context, struct HdfSBuf
{
struct NetDevice *netdev = NULL;
const char *ifName = NULL;
-
(void)context;
(void)rspData;
if (reqData == NULL) {
@@ -395,7 +393,6 @@ static int32_t WifiCmdDisableEapol(const RequestContext *context, struct HdfSBuf
HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
return HDF_FAILURE;
}
-
netdev = NetDeviceGetInstByName(ifName);
if (netdev == NULL) {
HDF_LOGE("%s:netdev not found!ifName=%s", __func__, ifName);
@@ -410,7 +407,6 @@ static int32_t WifiCmdGetAddr(const RequestContext *context, struct HdfSBuf *req
struct NetDevice *netdev = NULL;
const char *ifName = NULL;
int32_t ret = HDF_SUCCESS;
-
(void)context;
if (reqData == NULL || rspData == NULL) {
HDF_LOGE("%s: reqData or rspData is NULL", __func__);
@@ -421,7 +417,6 @@ static int32_t WifiCmdGetAddr(const RequestContext *context, struct HdfSBuf *req
HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
return HDF_FAILURE;
}
-
netdev = NetDeviceGetInstByName(ifName);
if (netdev == NULL) {
HDF_LOGE("%s: invalid netdev", __func__);
@@ -437,9 +432,7 @@ static int32_t WifiCmdGetAddr(const RequestContext *context, struct HdfSBuf *req
static int32_t WifiCmdSetMode(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
{
struct NetDevice *netdev = NULL;
-
WifiSetMode *mode = NULL;
-
const char *ifName = NULL;
uint32_t dataSize = 0;
int32_t ret;
@@ -465,9 +458,7 @@ static int32_t WifiCmdSetMode(const RequestContext *context, struct HdfSBuf *req
HDF_LOGE("%s: invalid netdev", __func__);
return HDF_FAILURE;
}
-
HDF_LOGW("%s:%s changing mode to %u ...", __func__, ifName, mode->iftype);
-
ret = SetMode(netdev, mode->iftype);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: fail to do change intf,%d", __func__, ret);
@@ -475,6 +466,25 @@ static int32_t WifiCmdSetMode(const RequestContext *context, struct HdfSBuf *req
return ret;
}
+static void WifiGetChannelData(struct WlanBand *band, WifiHwFeatureData **featureData, struct WlanHwCapability *capability, uint32_t iee80211band)
+{
+ uint32_t loop;
+ if (band == NULL || featureData == NULL || *featureData == NULL)
+ {
+ HDF_LOGE("%s: band or featureData is NULL", __func__);
+ return;
+ }
+
+ (*featureData)->bands[iee80211band].channelNum = band->channelCount;
+ (*featureData)->htCapab = capability->htCapability;
+
+ for (loop = 0; loop < band->channelCount; ++loop) {
+ (*featureData)->bands[iee80211band].iee80211Channel[loop].freq = band->channels[loop].centerFreq;
+ (*featureData)->bands[iee80211band].iee80211Channel[loop].flags = band->channels[loop].flags;
+ (*featureData)->bands[iee80211band].iee80211Channel[loop].channel = band->channels[loop].channelId;
+ }
+}
+
static int32_t WifiFillHwFeature(struct NetDevice *netdev, WifiHwFeatureData *featureData)
{
int32_t ret = HDF_SUCCESS;
@@ -502,21 +512,18 @@ static int32_t WifiFillHwFeature(struct NetDevice *netdev, WifiHwFeatureData *fe
ret = HDF_FAILURE;
break;
}
- featureData->channelNum = band->channelCount;
- featureData->htCapab = capability->htCapability;
-
- for (loop = 0; loop < band->channelCount; ++loop) {
- featureData->iee80211Channel[loop].flags = band->channels[loop].flags;
- featureData->iee80211Channel[loop].freq = band->channels[loop].centerFreq;
- featureData->iee80211Channel[loop].channel = band->channels[loop].channelId;
+ WifiGetChannelData(band, &featureData, capability, IEEE80211_BAND_2GHZ);
+ }
+ if (capability->bands[IEEE80211_BAND_5GHZ] != NULL) {
+ struct WlanBand *band = capability->bands[IEEE80211_BAND_5GHZ];
+ if (band->channelCount > WIFI_MAX_CHANNEL_NUM) {
+ HDF_LOGE("%s: channels %u out of range", __func__, band->channelCount);
+ ret = HDF_FAILURE;
+ break;
}
- } else {
- HDF_LOGE("%s: Supportting 2.4G is required by now!", __func__);
- ret = HDF_FAILURE;
- break;
+ WifiGetChannelData(band, &featureData, capability, IEEE80211_BAND_5GHZ);
}
- // 5G not supported
} while (false);
if (capability->Release != NULL) {
@@ -535,7 +542,6 @@ static uint32_t GetDeviceMacAddr(struct NetDevice *netdev, int32_t type, uint8_t
}
RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->ops, GetDeviceMacAddr);
-
return chipDriver->ops->GetDeviceMacAddr(netdev, type, mac, len);
}
@@ -546,7 +552,6 @@ static uint32_t SetMacAddr(struct NetDevice *netdev, uint8_t *mac, uint8_t len)
HDF_LOGE("%s:bad net device found!", __func__);
return HDF_FAILURE;
}
-
RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->ops, SetMacAddr);
return chipDriver->ops->SetMacAddr(netdev, mac, len);
}
@@ -592,19 +597,16 @@ static int32_t WifiCmdGetHwFeature(const RequestContext *context, struct HdfSBuf
HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
return HDF_FAILURE;
}
-
netdev = NetDeviceGetInstByName(ifName);
if (netdev == NULL) {
HDF_LOGE("%s: invalid netdev", __func__);
return HDF_FAILURE;
}
-
ret = WifiFillHwFeature(netdev, &featureData);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: WifiFillHwFeature failed!ret=%d", __func__, ret);
return HDF_FAILURE;
}
-
if (!HdfSbufWriteBuffer(rspData, &featureData, sizeof(featureData))) {
HDF_LOGE("%s: %s!", __func__, ERROR_DESC_WRITE_RSP_FAILED);
ret = HDF_ERR_IO;
@@ -615,7 +617,6 @@ static int32_t WifiCmdGetHwFeature(const RequestContext *context, struct HdfSBuf
static int32_t SetNetIfInfo(struct NetDevice *netdev, uint32_t type)
{
int ret = 0;
-
if (netdev != NULL) {
ret = netdev->netDeviceIf->open(netdev);
(void)NetIfSetStatus(netdev, NETIF_UP);
@@ -641,7 +642,6 @@ static void SetNetworkAddr(struct NetDevice *netdev, uint32_t type)
IpV4Addr ip;
IpV4Addr netmask;
IpV4Addr gw;
-
if (type == WIFI_IFTYPE_STATION) {
ip.addr = 0x00000000UL;
netmask.addr = 0x00000000UL;
@@ -662,7 +662,6 @@ static void UnsetNetworkAddr(struct NetDevice *netdev)
IpV4Addr ip = { 0x00000000UL };
IpV4Addr netmask = { 0x00000000UL };
IpV4Addr gw = { 0x00000000UL };
-
if (netdev != NULL) {
NetIfSetAddr(netdev, &ip, &netmask, &gw);
}
@@ -715,7 +714,6 @@ static int32_t WifiSendMlme(const RequestContext *context, struct HdfSBuf *reqDa
(void)context;
(void)reqData;
(void)rspData;
-
return HDF_SUCCESS;
}
@@ -737,7 +735,7 @@ static int32_t WifiCmdSendAction(const RequestContext *context, struct HdfSBuf *
const char *ifName = NULL;
uint32_t dataSize = 0;
struct NetDevice *netdev = NULL;
-
+ int ret;
(void)context;
(void)rspData;
if (reqData == NULL) {
@@ -778,7 +776,7 @@ static int32_t WifiCmdSendAction(const RequestContext *context, struct HdfSBuf *
return HDF_FAILURE;
}
- int ret = SendAction(netdev, &actionData);
+ ret = SendAction(netdev, &actionData);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: fail to remain on channel,%d", __func__, ret);
}
@@ -787,11 +785,12 @@ static int32_t WifiCmdSendAction(const RequestContext *context, struct HdfSBuf *
static int32_t WifiCmdGetNetworkInfo(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
{
- (void)context;
- (void)reqData;
- uint32_t netDevNum = 1;
+ uint32_t netDevNum;
char *defaultIfName = "wlan0";
uint8_t supportMode[PROTOCOL_80211_IFTYPE_NUM] = {0};
+ netDevNum = 1;
+ (void)context;
+ (void)reqData;
if (!HdfSbufWriteUint32(rspData, netDevNum)) {
HDF_LOGE("%s: %s!", __func__, ERROR_DESC_WRITE_RSP_FAILED);
@@ -813,7 +812,6 @@ static int32_t WifiCmdGetNetworkInfo(const RequestContext *context, struct HdfSB
static int32_t WifiCmdIsSupportCombo(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
{
uint8_t isComboValid;
-
(void)context;
if (reqData == NULL || rspData == NULL) {
return HDF_ERR_INVALID_PARAM;
@@ -828,8 +826,8 @@ static int32_t WifiCmdIsSupportCombo(const RequestContext *context, struct HdfSB
static int32_t WifiCmdGetSupportCombo(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
{
- (void)context;
uint8_t isComboValid;
+ (void)context;
if (reqData == NULL || rspData == NULL) {
return HDF_ERR_INVALID_PARAM;
}
@@ -998,7 +996,7 @@ static int32_t WifiCmdSetTxPower(const RequestContext *context, struct HdfSBuf *
static int32_t WifiCmdSetClient(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
{
uint32_t clientNum = 0;
-
+ struct HdfWifiEventToClientMap *eventToClientMap = NULL;
(void)rspData;
if (reqData == NULL || context == NULL) {
return HDF_ERR_INVALID_PARAM;
@@ -1009,7 +1007,7 @@ static int32_t WifiCmdSetClient(const RequestContext *context, struct HdfSBuf *r
return HDF_FAILURE;
}
- struct HdfWifiEventToClientMap *eventToClientMap = HdfWifiGetEventToClientMap();
+ eventToClientMap = HdfWifiGetEventToClientMap();
if (eventToClientMap == NULL) {
HDF_LOGE("%s:get HdfWifiEventToClientMap failed", __func__);
return HDF_FAILURE;
@@ -1213,9 +1211,7 @@ static int32_t WifiCmdDoResetChip(const RequestContext *context, struct HdfSBuf
HDF_LOGE("%s:power reset failed!", __func__);
return ERR_POWER_RESET_FAIL;
}
-
ret = HdfWifiInitDevice(wlanDevice);
-
return ret;
}
@@ -1223,6 +1219,7 @@ void SendMessageResetDriverCallBack(const RequestContext *context, struct HdfSBu
ErrorCode rspCode)
{
uint8_t chipId;
+ int32_t ret;
const char *ifName = NULL;
(void)context;
@@ -1241,7 +1238,7 @@ void SendMessageResetDriverCallBack(const RequestContext *context, struct HdfSBu
return;
}
- int32_t ret = HdfWifiEventResetResult(chipId, rspCode, ifName);
+ ret = HdfWifiEventResetResult(chipId, rspCode, ifName);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: send resetDriver event fail!", __func__);
}
@@ -1251,13 +1248,13 @@ void SendMessageResetDriverCallBack(const RequestContext *context, struct HdfSBu
static int32_t WifiCmdResetDriver(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
{
int32_t ret;
-
+ struct HdfSBuf *data = NULL;
(void)context;
if (reqData == NULL || rspData == NULL) {
return HDF_ERR_INVALID_PARAM;
}
- struct HdfSBuf *data = HdfSBufCopy(reqData);
+ data = HdfSBufCopy(reqData);
if (data == NULL) {
HDF_LOGE("%s: sbuf copy fail", __func__);
return HDF_FAILURE;
@@ -1286,13 +1283,13 @@ static uint32_t GetIftype(struct NetDevice *netdev, uint8_t *iftype)
#define MAX_NETDEVICE_COUNT 20
static int32_t WifiCmdGetNetDevInfo(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
{
- (void)context;
- (void)reqData;
uint32_t i;
uint32_t netdevNum;
uint8_t iftype;
struct NetDevice *netDev = NULL;
-
+ (void)context;
+ (void)reqData;
+
netdevNum = NetDevGetRegisterCount();
if (!HdfSbufWriteUint32(rspData, netdevNum)) {
HDF_LOGE("%s: %s!", __func__, ERROR_DESC_WRITE_RSP_FAILED);
@@ -1304,7 +1301,8 @@ static int32_t WifiCmdGetNetDevInfo(const RequestContext *context, struct HdfSBu
if (GetIftype(netDev, &iftype) != HDF_SUCCESS) {
iftype = 0;
}
- if (!HdfSbufWriteUint32(rspData, i) || !HdfSbufWriteBuffer(rspData, netDev->name, strlen(netDev->name) + 1) ||
+ if (!HdfSbufWriteUint32(rspData, i) ||
+ !HdfSbufWriteBuffer(rspData, netDev->name, strlen(netDev->name) + 1) ||
!HdfSbufWriteUint8(rspData, iftype) ||
!HdfSbufWriteBuffer(rspData, GET_NET_DEV_MAC_ADDR(netDev), ETH_ADDR_LEN)) {
HDF_LOGE("%s: %s!", __func__, ERROR_DESC_WRITE_RSP_FAILED);
@@ -1315,333 +1313,6 @@ static int32_t WifiCmdGetNetDevInfo(const RequestContext *context, struct HdfSBu
return HDF_SUCCESS;
}
-static int32_t RemainOnChannel(struct NetDevice *netdev, WifiOnChannel *onChannel)
-{
- struct HdfChipDriver *chipDriver = GetChipDriver(netdev);
- if (chipDriver == NULL) {
- HDF_LOGE("%s:bad net device found!", __func__);
- return HDF_FAILURE;
- }
-
- RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->ops, RemainOnChannel);
- return chipDriver->ops->RemainOnChannel(netdev, onChannel);
-}
-
-static int32_t WifiCmdRemainOnChannel(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
-{
- int32_t ret;
- struct NetDevice *netdev = NULL;
- const char *ifName = NULL;
- WifiOnChannel wifiOnChannel = {0};
-
- (void)context;
- if (reqData == NULL || rspData == NULL) {
- return HDF_ERR_INVALID_PARAM;
- }
- ifName = HdfSbufReadString(reqData);
- if (ifName == NULL) {
- HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
- return HDF_FAILURE;
- }
- netdev = NetDeviceGetInstByName(ifName);
- if (netdev == NULL) {
- HDF_LOGE("%s: netdev not found!ifName=%s", __func__, ifName);
- return HDF_FAILURE;
- }
- if (!HdfSbufReadUint32(reqData, &(wifiOnChannel.freq))) {
- HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "freq");
- return HDF_FAILURE;
- }
- if (!HdfSbufReadUint32(reqData, &(wifiOnChannel.duration))) {
- HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "duration");
- return HDF_FAILURE;
- }
- ret = RemainOnChannel(netdev, &wifiOnChannel);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: fail to remain on channel,%d",__func__, ret);
- }
- return ret;
-}
-
-static int32_t ProbeReqReport(struct NetDevice *netdev, int32_t report)
-{
- struct HdfChipDriver *chipDriver = GetChipDriver(netdev);
- if (chipDriver == NULL) {
- HDF_LOGE("%s:bad net device found!", __func__);
- return HDF_FAILURE;
- }
-
- RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->ops, ProbeReqReport);
- return chipDriver->ops->ProbeReqReport(netdev, report);
-}
-
-static int32_t WifiCmdProbeReqReport(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
-{
- int32_t ret;
- struct NetDevice *netdev = NULL;
- const char *ifName = NULL;
- int32_t report;
-
- (void)context;
- if (reqData == NULL || rspData == NULL) {
- return HDF_ERR_INVALID_PARAM;
- }
- ifName = HdfSbufReadString(reqData);
- if (ifName == NULL) {
- HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
- return HDF_FAILURE;
- }
- netdev = NetDeviceGetInstByName(ifName);
- if (netdev == NULL) {
- HDF_LOGE("%s: netdev not found!ifName=%s", __func__, ifName);
- return HDF_FAILURE;
- }
- if (!HdfSbufReadInt32(reqData,&(report))) {
- HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "report");
- return HDF_FAILURE;
- }
-
- ret = ProbeReqReport(netdev, report);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: fail to probe req report,%d",__func__, ret);
- }
- return ret;
-}
-
-static int32_t CancelRemainOnChannel(struct NetDevice *netdev)
-{
- struct HdfChipDriver *chipDriver = GetChipDriver(netdev);
- if (chipDriver == NULL) {
- HDF_LOGE("%s:bad net device found!", __func__);
- return HDF_FAILURE;
- }
-
- RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->ops, CancelRemainOnChannel);
- return chipDriver->ops->CancelRemainOnChannel(netdev);
-}
-
-static int32_t WifiCmdCancelRemainOnChannel(const RequestContext *context, struct HdfSBuf *reqData,
- struct HdfSBuf *rspData)
-{
- int32_t ret;
- struct NetDevice *netdev = NULL;
- const char *ifName = NULL;
-
- (void)context;
- if (reqData == NULL || rspData == NULL) {
- return HDF_ERR_INVALID_PARAM;
- }
- ifName = HdfSbufReadString(reqData);
- if (ifName == NULL) {
- HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
- return HDF_FAILURE;
- }
- netdev = NetDeviceGetInstByName(ifName);
- if (netdev == NULL) {
- HDF_LOGE("%s: netdev not found!ifName=%s", __func__, ifName);
- return HDF_FAILURE;
- }
-
- ret = CancelRemainOnChannel(netdev);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: fail to cancel remain on channel,%d",__func__, ret);
- }
- return ret;
-}
-
-static int32_t AddIf(struct NetDevice *netdev, WifiIfAdd *ifAdd)
-{
- struct HdfChipDriver *chipDriver = GetChipDriver(netdev);
- if (chipDriver == NULL) {
- HDF_LOGE("%s:bad net device found!", __func__);
- return HDF_FAILURE;
- }
-
- RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->ops, AddIf);
- return chipDriver->ops->AddIf(netdev, ifAdd);
-}
-
-static int32_t WifiCmdAddIf(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
-{
- int32_t ret;
- struct NetDevice *netdev = NULL;
- const char *ifName = NULL;
- WifiIfAdd ifAdd = {0};
-
- (void)context;
- if (reqData == NULL || rspData == NULL) {
- return HDF_ERR_INVALID_PARAM;
- }
- ifName = HdfSbufReadString(reqData);
- if (ifName == NULL) {
- HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
- return HDF_FAILURE;
- }
- netdev = NetDeviceGetInstByName(ifName);
- if (netdev == NULL) {
- HDF_LOGE("%s: netdev not found!ifName=%s", __func__, ifName);
- return HDF_FAILURE;
- }
-
- if (!HdfSbufReadUint8(reqData, &(ifAdd.type))) {
- HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "type");
- return HDF_FAILURE;
- }
-
- ret = AddIf(netdev, &ifAdd);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: fail to cancel remain on channel,%d",__func__, ret);
- }
- return ret;
-}
-
-static int32_t RemoveIf(struct NetDevice *netdev, WifiIfRemove *ifRemove)
-{
- struct HdfChipDriver *chipDriver = GetChipDriver(netdev);
- if (chipDriver == NULL) {
- HDF_LOGE("%s:bad net device found!", __func__);
- return HDF_FAILURE;
- }
-
- RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->ops, RemoveIf);
- return chipDriver->ops->RemoveIf(netdev, ifRemove);
-}
-
-static int32_t WifiCmdRemoveIf(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
-{
- int32_t ret;
- struct NetDevice *netdev = NULL;
- const char *ifName = NULL;
- WifiIfRemove *ifRemove = NULL;
-
- (void)context;
- if (reqData == NULL || rspData == NULL) {
- return HDF_ERR_INVALID_PARAM;
- }
- ifName = HdfSbufReadString(reqData);
- if (ifName == NULL) {
- HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
- return HDF_FAILURE;
- }
- netdev = NetDeviceGetInstByName(ifName);
- if (netdev == NULL) {
- HDF_LOGE("%s: netdev not found!ifName=%s", __func__, ifName);
- return HDF_FAILURE;
- }
-
- uint32_t dataSize = 0;
- if (!HdfSbufReadBuffer(reqData, (const void **)&(ifRemove), &dataSize) || dataSize != sizeof(WifiIfRemove)) {
- HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
- return HDF_FAILURE;
- }
- ret = RemoveIf(netdev, ifRemove);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: fail to remove interface,%d",__func__, ret);
- }
- return ret;
-}
-
-static int32_t SetApWpsP2pIe(struct NetDevice *netdev, WifiAppIe *appIe)
-{
- struct HdfChipDriver *chipDriver = GetChipDriver(netdev);
- if (chipDriver == NULL) {
- HDF_LOGE("%s:bad net device found!", __func__);
- return HDF_FAILURE;
- }
-
- RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->ops, SetApWpsP2pIe);
- return chipDriver->ops->SetApWpsP2pIe(netdev, appIe);
-}
-
-static int32_t WifiCmdSetApWpsP2pIe(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
-{
- int32_t ret;
- struct NetDevice *netdev = NULL;
- const char *ifName = NULL;
- WifiAppIe appIe = {0};
-
- (void)context;
- if (reqData == NULL || rspData == NULL) {
- return HDF_ERR_INVALID_PARAM;
- }
- ifName = HdfSbufReadString(reqData);
- if (ifName == NULL) {
- HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
- return HDF_FAILURE;
- }
- netdev = NetDeviceGetInstByName(ifName);
- if (netdev == NULL) {
- HDF_LOGE("%s: netdev not found!ifName=%s", __func__, ifName);
- return HDF_FAILURE;
- }
-
- if (!HdfSbufReadUint32(reqData, &(appIe.ieLen))) {
- HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ieLen");
- return HDF_FAILURE;
- }
- if (!HdfSbufReadUint8(reqData, &(appIe.appIeType))) {
- HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "appIeType");
- return HDF_FAILURE;
- }
- if (!HdfSbufReadBuffer(reqData, (const void**)&(appIe.ie), &(appIe.ieLen))) {
- HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "appIeType");
- return HDF_FAILURE;
- }
- ret = SetApWpsP2pIe(netdev, &appIe);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: fail to setapwpsp2pie,%d",__func__, ret);
- }
- return ret;
-}
-
-int32_t GetDriverFlag (struct NetDevice *netdev, WifiGetDrvFlags **params)
-{
- struct HdfChipDriver *chipDriver = GetChipDriver(netdev);
- if (chipDriver == NULL) {
- HDF_LOGE("%s:bad net device found!", __func__);
- return HDF_FAILURE;
- }
-
- RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->ops, GetDriverFlag);
- return chipDriver->ops->GetDriverFlag(netdev, params);
-}
-
-static int32_t WifiCmdGetDriverFlag(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
-{
- int32_t ret;
- struct NetDevice *netdev = NULL;
- const char *ifName = NULL;
- WifiGetDrvFlags *params = NULL;
-
- (void)context;
- if (reqData == NULL || rspData == NULL) {
- return HDF_ERR_INVALID_PARAM;
- }
- ifName = HdfSbufReadString(reqData);
- if (ifName == NULL) {
- HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
- return HDF_FAILURE;
- }
- netdev = NetDeviceGetInstByName(ifName);
- if (netdev == NULL) {
- HDF_LOGE("%s: netdev not found!ifName=%s", __func__, ifName);
- return HDF_FAILURE;
- }
-
- ret = GetDriverFlag(netdev, ¶ms);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: fail to getdriverflag,%d",__func__, ret);
- }
-
- if (!HdfSbufWriteUint64(rspData, params->drvFlags)) {
- HDF_LOGE("%s:%s!", __func__, ERROR_DESC_WRITE_RSP_FAILED);
- ret = HDF_ERR_IO;
- }
-
- HDF_LOGE("WifiCmdGetDriverFlag:%llx", params->drvFlags);
- return ret;
-}
-
static struct MessageDef g_wifiBaseFeatureCmds[] = {
DUEMessage(CMD_BASE_NEW_KEY, WifiCmdNewKey, 0),
DUEMessage(CMD_BASE_DEL_KEY, WifiCmdDelKey, 0),
@@ -1668,13 +1339,6 @@ static struct MessageDef g_wifiBaseFeatureCmds[] = {
DUEMessage(CMD_BASE_GET_IFNAMES, WifiCmdGetIfNamesByChipId, 0),
DUEMessage(CMD_BASE_RESET_DRIVER, WifiCmdResetDriver, 0),
DUEMessage(CMD_BASE_GET_NETDEV_INFO, WifiCmdGetNetDevInfo, 0),
- DUEMessage(CMD_P2P_PROBE_REQ_REPORT, WifiCmdProbeReqReport, 0),
- DUEMessage(CMD_P2P_REMAIN_ON_CHANNEL, WifiCmdRemainOnChannel, 0),
- DUEMessage(CMD_P2P_CANCEL_REMAIN_ON_CHANNEL, WifiCmdCancelRemainOnChannel, 0),
- DUEMessage(CMD_P2P_ADD_IF, WifiCmdAddIf, 0),
- DUEMessage(CMD_P2P_REMOVE_IF, WifiCmdRemoveIf, 0),
- DUEMessage(CMD_P2P_SET_AP_WPS_P2P_IE, WifiCmdSetApWpsP2pIe, 0),
- DUEMessage(CMD_P2P_GET_DRIVER_FLAGS, WifiCmdGetDriverFlag, 0),
DUEMessage(CMD_BASE_DO_RESET_PRIVATE, WifiCmdDoResetChip, 0),
};
ServiceDefine(BaseService, BASE_SERVICE_ID, g_wifiBaseFeatureCmds);
diff --git a/model/network/wifi/core/module/wifi_module.c b/model/network/wifi/core/module/wifi_module.c
index 061478f05a2f1591499832299f1a5789e87716e4..8f76769a66b1508cb44a3b689e67b61946c84049 100644
--- a/model/network/wifi/core/module/wifi_module.c
+++ b/model/network/wifi/core/module/wifi_module.c
@@ -10,6 +10,7 @@
#include "wifi_base.h"
#include "ap.h"
#include "sta.h"
+#include "p2p.h"
#include "hdf_wlan_config.h"
#include "securec.h"
@@ -39,6 +40,7 @@ static int32_t InitFeatures(struct WifiModule *module)
module->feList.fe[HDF_WIFI_FEATURE_AP] = GetWifiApFeature();
module->feList.fe[HDF_WIFI_FEATURE_STA] = GetWifiStaFeature();
+ module->feList.fe[HDF_WIFI_FEATURE_P2P] = GetWifiP2pFeature();
for (i = 0; i < HDF_WIFI_FEATURE_NUM; i++) {
if ((module->moduleConfig.hslConfig->featureMap & (1 << i)) && module->feList.fe[i] != NULL) {
diff --git a/model/network/wifi/include/hdf_wifi_cmd.h b/model/network/wifi/include/hdf_wifi_cmd.h
index 43a392eadb3f148df3642766ea7117db6e779cd0..611e05d90bcb1a64a2106438f8350d63be519b42 100644
--- a/model/network/wifi/include/hdf_wifi_cmd.h
+++ b/model/network/wifi/include/hdf_wifi_cmd.h
@@ -254,6 +254,7 @@ typedef struct {
int32_t centerFreq1;
int32_t centerFreq2;
int32_t bandwidth;
+ uint8_t band;
} WifiFreqParams;
typedef struct {
@@ -312,13 +313,20 @@ typedef struct {
} WifiIeee80211Channel;
#define MAX_SUPPORTED_RATE 12
+#define WIFI_MAX_CHANNEL_NUM 24
+#define SUPPORTED_NUM_BANDS 2
+
+typedef struct {
+ int32_t channelNum; /**< Number of channels */
+ WifiIeee80211Channel iee80211Channel[WIFI_MAX_CHANNEL_NUM]; /**< WLAN channel structures */
+}WlanBands;
typedef struct {
int32_t channelNum;
uint16_t bitrate[MAX_SUPPORTED_RATE];
uint16_t htCapab;
uint8_t resv[2];
- WifiIeee80211Channel iee80211Channel[14];
+ WlanBands bands[SUPPORTED_NUM_BANDS];
} WifiHwFeatureData;
typedef struct {
diff --git a/model/network/wifi/platform/include/hdf_wlan_services.h b/model/network/wifi/platform/include/hdf_wlan_services.h
index 47fb1b8b5306aa5dab2038c16b370d2c69a7d00f..6e49bfc73f2a8cceb279e7e2726e52aab1b59888 100644
--- a/model/network/wifi/platform/include/hdf_wlan_services.h
+++ b/model/network/wifi/platform/include/hdf_wlan_services.h
@@ -14,6 +14,7 @@ enum PlatformServiceID {
BASE_SERVICE_ID,
AP_SERVICE_ID,
STA_SERVICE_ID,
+ P2P_SERVICE_ID,
AUTO_ALLOC_SERVICE_ID_START = 300
};
@@ -43,13 +44,6 @@ enum BaseCommands {
CMD_BASE_GET_IFNAMES,
CMD_BASE_RESET_DRIVER,
CMD_BASE_GET_NETDEV_INFO = 25,
- CMD_P2P_PROBE_REQ_REPORT = 26,
- CMD_P2P_REMAIN_ON_CHANNEL,
- CMD_P2P_CANCEL_REMAIN_ON_CHANNEL,
- CMD_P2P_ADD_IF,
- CMD_P2P_REMOVE_IF,
- CMD_P2P_SET_AP_WPS_P2P_IE,
- CMD_P2P_GET_DRIVER_FLAGS,
CMD_BASE_DO_RESET_PRIVATE,
};
@@ -70,4 +64,14 @@ enum STACommands {
CMD_STA_SET_SCAN_MAC_ADDR
};
+enum P2PCommands {
+ CMD_P2P_PROBE_REQ_REPORT = 0,
+ CMD_P2P_REMAIN_ON_CHANNEL,
+ CMD_P2P_CANCEL_REMAIN_ON_CHANNEL,
+ CMD_P2P_ADD_IF,
+ CMD_P2P_REMOVE_IF,
+ CMD_P2P_SET_AP_WPS_P2P_IE,
+ CMD_P2P_GET_DRIVER_FLAGS
+};
+
#endif
\ No newline at end of file
diff --git a/model/network/wifi/platform/src/hdf_wlan_config_parser.c b/model/network/wifi/platform/src/hdf_wlan_config_parser.c
index d32facbbb67215f0c6aaa79b82ed88a06a9b65e1..61da15060ef85815ec7b54d0a683661b093aff3b 100644
--- a/model/network/wifi/platform/src/hdf_wlan_config_parser.c
+++ b/model/network/wifi/platform/src/hdf_wlan_config_parser.c
@@ -250,6 +250,8 @@ static int32_t ParseWlanPowerConfig(const struct DeviceResourceNode *node,
static int32_t ParseWlanPowersConfig(const struct DeviceResourceNode *node, struct HdfConfWlanPowers *powersConfig)
{
struct DeviceResourceIface *drsOps = NULL;
+ const struct DeviceResourceNode *fstPowerNode = NULL;
+ const struct DeviceResourceNode *secPowerNode = NULL;
if (node == NULL || powersConfig == NULL) {
HDF_LOGE("%s: at least one of the paras is NULL!", __func__);
return HDF_FAILURE;
@@ -259,8 +261,7 @@ static int32_t ParseWlanPowersConfig(const struct DeviceResourceNode *node, stru
HDF_LOGE("%s: at least one of the paras is NULL!", __func__);
return HDF_FAILURE;
}
-
- const struct DeviceResourceNode *fstPowerNode = drsOps->GetChildNode(node, "power0");
+ fstPowerNode = drsOps->GetChildNode(node, "power0");
if (fstPowerNode == NULL) {
HDF_LOGE("%s: get power0 config fail!", __func__);
return HDF_FAILURE;
@@ -269,7 +270,7 @@ static int32_t ParseWlanPowersConfig(const struct DeviceResourceNode *node, stru
return HDF_FAILURE;
}
- const struct DeviceResourceNode *secPowerNode = drsOps->GetChildNode(node, "power1");
+ secPowerNode = drsOps->GetChildNode(node, "power1");
if (secPowerNode == NULL) {
HDF_LOGE("%s: get power1 config fail!", __func__);
return HDF_FAILURE;
diff --git a/model/network/wifi/platform/src/hdf_wlan_power_manager.c b/model/network/wifi/platform/src/hdf_wlan_power_manager.c
index 50592e734d3d5c9092a774b0dd9707524ea20668..1c7f29c927dcaff06e1c1db12241c8aa5bc5ef36 100644
--- a/model/network/wifi/platform/src/hdf_wlan_power_manager.c
+++ b/model/network/wifi/platform/src/hdf_wlan_power_manager.c
@@ -142,11 +142,11 @@ int32_t HdfWlanPowerMgrRelease(struct PowerManager* powerMgr)
*/
struct PowerManager* HdfWlanCreatePowerManager(const struct HdfConfWlanPowers *configPowers)
{
+ struct PowerManagerImpl *powerMgrimpl = NULL;
if (configPowers == NULL) {
HDF_LOGE("%s: configPowers is NULL", __func__);
return NULL;
}
- struct PowerManagerImpl *powerMgrimpl = NULL;
powerMgrimpl = (struct PowerManagerImpl *)OsalMemCalloc(sizeof(struct PowerManagerImpl));
if (powerMgrimpl == NULL) {
HDF_LOGE("%s: OsalMemCalloc fail! ", __func__);
@@ -157,6 +157,5 @@ struct PowerManager* HdfWlanCreatePowerManager(const struct HdfConfWlanPowers *c
powerMgrimpl->base.Release = HdfWlanPowerMgrRelease;
powerMgrimpl->powerDatas.power0 = configPowers->power0;
powerMgrimpl->powerDatas.power1 = configPowers->power1;
-
return (struct PowerManager *)powerMgrimpl;
}
\ No newline at end of file
diff --git a/model/network/wifi/platform/src/hdf_wlan_priority_queue.c b/model/network/wifi/platform/src/hdf_wlan_priority_queue.c
index e61c904359f86fe9382af711914b8bc256f87d87..76daf48428a0cfe9c23cdfc77998fc56bfe290fa 100644
--- a/model/network/wifi/platform/src/hdf_wlan_priority_queue.c
+++ b/model/network/wifi/platform/src/hdf_wlan_priority_queue.c
@@ -29,6 +29,7 @@ PriorityQueue *CreatePriorityQueue(uint16_t queueSize, uint8_t priorityLevelCoun
uint32_t queueMemSize;
PriorityQueueImpl *priorityQueue = NULL;
uint32_t ret = HDF_SUCCESS;
+ HDF_STATUS status;
if (priorityLevelCount > MAX_PRIORITY_LEVEL || priorityLevelCount == 0) {
HDF_LOGE("%s:priorityLevelCount must in 1 to 8", __func__);
return NULL;
@@ -51,8 +52,7 @@ PriorityQueue *CreatePriorityQueue(uint16_t queueSize, uint8_t priorityLevelCoun
DestroyPriorityQueue((PriorityQueue *)priorityQueue);
return NULL;
}
-
- HDF_STATUS status = OsalSemInit(&priorityQueue->messageSemaphore, 0);
+ status = OsalSemInit(&priorityQueue->messageSemaphore, 0);
if (status != HDF_SUCCESS) {
DestroyPriorityQueue((PriorityQueue *)priorityQueue);
return NULL;
@@ -64,6 +64,7 @@ PriorityQueue *CreatePriorityQueue(uint16_t queueSize, uint8_t priorityLevelCoun
void DestroyPriorityQueue(PriorityQueue *queue)
{
uint8_t i;
+ HDF_STATUS status;
PriorityQueueImpl *queueImpl = (PriorityQueueImpl *)queue;
if (queue == NULL) {
return;
@@ -76,7 +77,7 @@ void DestroyPriorityQueue(PriorityQueue *queue)
DestroyQueue(queueImpl->queues[i]);
queueImpl->queues[i] = NULL;
}
- HDF_STATUS status = OsalSemDestroy(&queueImpl->messageSemaphore);
+ status = OsalSemDestroy(&queueImpl->messageSemaphore);
if (status != HDF_SUCCESS) {
HDF_LOGE("%s:Destroy message queue semaphore failed!status=%d", __func__, status);
}
diff --git a/model/network/wifi/platform/src/hdf_wlan_utils.c b/model/network/wifi/platform/src/hdf_wlan_utils.c
index b7dc9ac2476f57d0d3bc60ca53e61b1b484bd3c5..a6bd35cc242ffdad14539ea96cb9669c9b294ef8 100644
--- a/model/network/wifi/platform/src/hdf_wlan_utils.c
+++ b/model/network/wifi/platform/src/hdf_wlan_utils.c
@@ -1,10 +1,10 @@
-/*
- * 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.
- */
+/*
+ * 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 "hdf_wlan_utils.h"
#include
@@ -45,6 +45,7 @@ struct WlanHwCapability *GetHwCapability(struct NetDevice *netDev)
{
struct HdfChipDriver *chipDriver = GetChipDriver(netDev);
struct WlanHwCapability *capability = NULL;
+ int32_t ret;
if (chipDriver == NULL) {
HDF_LOGE("%s:bad net device found!", __func__);
return NULL;
@@ -53,7 +54,7 @@ struct WlanHwCapability *GetHwCapability(struct NetDevice *netDev)
HDF_LOGE("%s: chipdriver not implemented", __func__);
return NULL;
}
- int32_t ret = chipDriver->ops->GetHwCapability(netDev, &capability);
+ ret = chipDriver->ops->GetHwCapability(netDev, &capability);
if (ret != HDF_SUCCESS || capability == NULL) {
HDF_LOGE("%s:GetHwCapability failed!ifName=%s,ret=%d", __func__, netDev->name, ret);
return NULL;
@@ -222,6 +223,7 @@ char *HdfWlanGetIfNames(const uint8_t chipId, uint8_t *ifNameCount)
char *ifNames = NULL;
uint32_t bufferSize;
uint8_t i, j;
+ int32_t ret;
if (ifNameCount == NULL) {
HDF_LOGE("%s: para is NULL", __func__);
return NULL;
@@ -239,29 +241,25 @@ char *HdfWlanGetIfNames(const uint8_t chipId, uint8_t *ifNameCount)
(*ifNameCount)++;
}
}
-
if (*ifNameCount == 0) {
// Never alloc 0 size
bufferSize = sizeof(char);
} else {
bufferSize = IFNAMSIZ * (uint32_t)(*ifNameCount);
}
-
ifNames = (char *)OsalMemCalloc(bufferSize);
if (ifNames == NULL) {
HDF_LOGE("%s: oom!", __func__);
return NULL;
}
-
if (*ifNameCount == 0) {
return ifNames;
}
-
for (i = 0, j = 0; i < MAX_IF_COUNT; i++) {
if (((netIfMapTemp >> i) & 0x1) == 0) {
continue;
}
- int32_t ret = GetPlatformIfName(i, ifNames + (j * IFNAMSIZ), IFNAMSIZ);
+ ret = GetPlatformIfName(i, ifNames + (j * IFNAMSIZ), IFNAMSIZ);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:Get ifName failed!ret=%d", __func__, ret);
OsalMemFree(ifNames);
diff --git a/model/network/wifi/platform/src/message/message_dispatcher.c b/model/network/wifi/platform/src/message/message_dispatcher.c
index 23056b8000bf8661adb6aaf893df256883eccaa1..9231270ded554e4c8f603bc912c0074811a49d0b 100644
--- a/model/network/wifi/platform/src/message/message_dispatcher.c
+++ b/model/network/wifi/platform/src/message/message_dispatcher.c
@@ -61,6 +61,7 @@ void ReleaseMessageMapper(struct ServiceDef *mapper)
struct MessageDef *GetMsgDef(const struct ServiceDef *serviceDef, uint32_t commandId)
{
+ struct MessageDef *msgDef = NULL;
if (serviceDef == NULL || serviceDef->messages == NULL) {
HDF_LOGE("%s:input is NULL!", __func__);
return NULL;
@@ -70,7 +71,7 @@ struct MessageDef *GetMsgDef(const struct ServiceDef *serviceDef, uint32_t comma
return NULL;
}
- struct MessageDef *msgDef = serviceDef->messages + commandId;
+ msgDef = serviceDef->messages + commandId;
if (msgDef->handler == NULL) {
HDF_LOGE("%s:command has no handler!", __func__);
return NULL;
@@ -103,11 +104,12 @@ ErrorCode AppendToLocalDispatcher(MessageDispatcher *dispatcher, const uint8_t p
void SetToResponse(MessageContext *context)
{
+ ServiceId senderId;
if (context->requestType != MESSAGE_TYPE_ASYNC_REQ && context->requestType != MESSAGE_TYPE_SYNC_REQ) {
HDF_LOGE("Only sync and async message can send response!type=%u", context->requestType);
return;
}
- ServiceId senderId = context->senderId;
+ senderId = context->senderId;
context->senderId = context->receiverId;
context->receiverId = senderId;
context->requestType = MESSAGE_RSP_START + context->requestType - MESSAGE_REQ_START;
@@ -128,11 +130,12 @@ static void HandleAsyncResponse(MessageContext *context)
static void HandleSyncResponse(MessageContext *context)
{
+ HDF_STATUS status;
if (context == NULL) {
HDF_LOGE("Input context is NULL!");
return;
}
- HDF_STATUS status = OsalSemPost(&context->rspSemaphore);
+ status = OsalSemPost(&context->rspSemaphore);
if (status != HDF_SUCCESS) {
HDF_LOGE("Send semaphore failed!CMD=%u,Sender=%u,Receiver=%u", context->commandId, context->senderId,
context->receiverId);
@@ -229,11 +232,13 @@ static void ReleaseAllMessage(MessageDispatcher *dispatcher)
static int RunDispatcher(void *para)
{
+ MessageDispatcher *dispatcher = NULL;
+ MessageContext *context = NULL;
if (para == NULL) {
HDF_LOGE("Start dispatcher failed! cause:%s\n", "input para is NULL");
return ME_ERROR_NULL_PTR;
}
- MessageDispatcher *dispatcher = (MessageDispatcher *)para;
+ dispatcher = (MessageDispatcher *)para;
if (dispatcher->messageQueue == NULL) {
HDF_LOGE("Start dispatcher failed! cause:%s\n", "message queue is NULL");
return ME_ERROR_NULL_PTR;
@@ -253,7 +258,7 @@ static int RunDispatcher(void *para)
dispatcher->status = ME_STATUS_RUNNING;
}
while (dispatcher->status == ME_STATUS_RUNNING) {
- MessageContext *context = PopPriorityQueue(dispatcher->messageQueue, QUEUE_OPER_TIMEOUT);
+ context = PopPriorityQueue(dispatcher->messageQueue, QUEUE_OPER_TIMEOUT);
if (context == NULL) {
continue;
}
@@ -273,26 +278,30 @@ static int RunDispatcher(void *para)
static ErrorCode StartDispatcher(MessageDispatcher *dispatcher)
{
+ HDF_STATUS status;
+ ErrorCode errCode;
+ LocalMessageDispatcher *localDispatcher = NULL;
+ struct OsalThreadParam config;
if (dispatcher == NULL) {
return ME_ERROR_NULL_PTR;
}
- HDF_STATUS status = OsalMutexTimedLock(&dispatcher->mutex, HDF_WAIT_FOREVER);
+
+ status = OsalMutexTimedLock(&dispatcher->mutex, HDF_WAIT_FOREVER);
if (status != HDF_SUCCESS) {
return ME_ERROR_OPER_MUTEX_FAILED;
}
- ErrorCode errCode = ME_SUCCESS;
+
+ errCode = ME_SUCCESS;
do {
if (dispatcher->status != ME_STATUS_STOPPED) {
errCode = ME_ERROR_WRONG_STATUS;
break;
}
dispatcher->status = ME_STATUS_STARTTING;
- struct OsalThreadParam config = {
- .name = "MessageDispatcher",
- .priority = OSAL_THREAD_PRI_DEFAULT,
- .stackSize = 0x2000,
- };
- LocalMessageDispatcher *localDispatcher = (LocalMessageDispatcher *)dispatcher;
+ config.name = "MessageDispatcher";
+ config.priority = OSAL_THREAD_PRI_DEFAULT;
+ config.stackSize = 0x2000;
+ localDispatcher = (LocalMessageDispatcher *)dispatcher;
status = OsalThreadCreate(&localDispatcher->dispatcherThread, RunDispatcher, localDispatcher);
if (status != HDF_SUCCESS) {
HDF_LOGE("%s:OsalThreadCreate failed!status=%d", __func__, status);
@@ -300,6 +309,7 @@ static ErrorCode StartDispatcher(MessageDispatcher *dispatcher)
errCode = ME_ERROR_CREATE_THREAD_FAILED;
break;
}
+
status = OsalThreadStart(&localDispatcher->dispatcherThread, &config);
if (status != HDF_SUCCESS) {
HDF_LOGE("%s:OsalThreadStart failed!status=%d", __func__, status);
@@ -327,11 +337,11 @@ static ErrorCode StartDispatcher(MessageDispatcher *dispatcher)
static void ShutdownDispatcher(MessageDispatcher *dispatcher)
{
+ HDF_STATUS status;
if (dispatcher == NULL) {
return;
}
-
- HDF_STATUS status = OsalMutexTimedLock(&dispatcher->mutex, HDF_WAIT_FOREVER);
+ status = OsalMutexTimedLock(&dispatcher->mutex, HDF_WAIT_FOREVER);
if (status != HDF_SUCCESS) {
HDF_LOGE("Get lock failed!status=%d", status);
return;
@@ -354,6 +364,7 @@ static void ShutdownDispatcher(MessageDispatcher *dispatcher)
IMPLEMENT_SHARED_OBJ(MessageDispatcher);
static void DestroyLocalDispatcher(MessageDispatcher *dispatcher)
{
+ int32_t ret;
if (dispatcher == NULL) {
return;
}
@@ -365,7 +376,7 @@ static void DestroyLocalDispatcher(MessageDispatcher *dispatcher)
dispatcher->messageQueue = NULL;
}
- int32_t ret = OsalMutexDestroy(&dispatcher->mutex);
+ ret = OsalMutexDestroy(&dispatcher->mutex);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:Release mutex failed.ret=%d", __func__, ret);
}
@@ -375,16 +386,17 @@ static void DestroyLocalDispatcher(MessageDispatcher *dispatcher)
ErrorCode CreateLocalDispatcher(MessageDispatcher **dispatcher, const DispatcherConfig *config)
{
+ LocalMessageDispatcher *localDispatcher = NULL;
+ int32_t ret;
+ ErrorCode errCode;
if (dispatcher == NULL || config == NULL) {
return ME_ERROR_NULL_PTR;
}
- LocalMessageDispatcher *localDispatcher = (LocalMessageDispatcher *)OsalMemCalloc(sizeof(LocalMessageDispatcher));
+ localDispatcher = (LocalMessageDispatcher *)OsalMemCalloc(sizeof(LocalMessageDispatcher));
if (localDispatcher == NULL) {
return ME_ERROR_RES_LAKE;
}
-
- ErrorCode errCode;
do {
localDispatcher->status = ME_STATUS_STOPPED;
localDispatcher->AppendMessage = AppendToLocalDispatcher;
@@ -397,7 +409,7 @@ ErrorCode CreateLocalDispatcher(MessageDispatcher **dispatcher, const Dispatcher
break;
}
- int32_t ret = OsalMutexInit(&localDispatcher->mutex);
+ ret = OsalMutexInit(&localDispatcher->mutex);
if (ret != HDF_SUCCESS) {
errCode = ME_ERROR_OPER_MUTEX_FAILED;
break;
diff --git a/model/network/wifi/platform/src/message/message_router.c b/model/network/wifi/platform/src/message/message_router.c
index 3776a3e6639faab4add0ecdd2dbc58a1880e486b..17e295e1c007cda2d88f59ed725279bd87762d93 100644
--- a/model/network/wifi/platform/src/message/message_router.c
+++ b/model/network/wifi/platform/src/message/message_router.c
@@ -70,6 +70,7 @@ static void ReleaseRemoteService(RemoteService *service)
static MessageDispatcher *RefDispatcherInner(const DispatcherId dispatcherId, bool requireLock)
{
+ MessageDispatcher *result = NULL;
if (dispatcherId >= MESSAGE_ENGINE_MAX_DISPATCHER) {
HDF_LOGE("%s:Input ID is too big.input=%u", __func__, dispatcherId);
return NULL;
@@ -82,7 +83,7 @@ static MessageDispatcher *RefDispatcherInner(const DispatcherId dispatcherId, bo
return NULL;
}
}
- MessageDispatcher *result = NULL;
+
do {
if (g_dispatchers[dispatcherId] == NULL) {
break;
@@ -105,17 +106,19 @@ static MessageDispatcher *RefDispatcherInner(const DispatcherId dispatcherId, bo
static ErrorCode RegDispatcher(DispatcherId dispatcherId, MessageDispatcher *dispatcher)
{
+ HDF_STATUS status;
+ ErrorCode errCode;
if (dispatcherId >= MESSAGE_ENGINE_MAX_DISPATCHER) {
HDF_LOGE("%s:dispatcher id is too big!id=%u", __func__, dispatcherId);
return ME_ERROR_PARA_WRONG;
}
- HDF_STATUS status = OsalMutexTimedLock(&g_routerMutex, HDF_WAIT_FOREVER);
+ status = OsalMutexTimedLock(&g_routerMutex, HDF_WAIT_FOREVER);
if (status != HDF_SUCCESS) {
HDF_LOGE("Unable to get lock!status=%d", status);
return ME_ERROR_OPER_MUTEX_FAILED;
}
- ErrorCode errCode = ME_SUCCESS;
+ errCode = ME_SUCCESS;
do {
if (g_routerStatus != ME_STATUS_RUNNING) {
errCode = ME_ERROR_WRONG_STATUS;
@@ -138,11 +141,12 @@ static ErrorCode RegDispatcher(DispatcherId dispatcherId, MessageDispatcher *dis
ErrorCode AddDispatcher(DispatcherConfig *config)
{
+ ErrorCode errCode;
+ MessageDispatcher *dispatcher = NULL;
if (config == NULL) {
return ME_ERROR_NULL_PTR;
}
- MessageDispatcher *dispatcher = NULL;
- ErrorCode errCode = CreateLocalDispatcher(&dispatcher, config);
+ errCode = CreateLocalDispatcher(&dispatcher, config);
if (errCode != ME_SUCCESS) {
return errCode;
}
@@ -190,12 +194,13 @@ static void NotifyAllNodesServiceDel(const NodeId nodeId, ServiceId serviceId)
static ErrorCode NotifyAllNodesServiceAdd(const NodeId nodeId, struct ServiceDef *mapper)
{
uint8_t i;
+ uint8_t notifyNodeIndex;
+ ErrorCode errCode;
if (mapper == NULL) {
return ME_ERROR_NULL_PTR;
}
- ErrorCode errCode = ME_SUCCESS;
- uint8_t notifyNodeIndex;
+ errCode = ME_SUCCESS;
for (notifyNodeIndex = 0; notifyNodeIndex < MAX_NODE_COUNT; notifyNodeIndex++) {
if (notifyNodeIndex == nodeId) {
continue;
@@ -258,6 +263,11 @@ static ErrorCode DoRegistService(const NodeId nodeId, const DispatcherId dispatc
}
static ErrorCode RegistServiceInner(const NodeId nodeId, const DispatcherId dispatcherId, struct ServiceDef *mapper)
{
+ HDF_STATUS status;
+ MessageNode *node = NULL;
+ RemoteService *remoteService = NULL;
+ MessageDispatcher *dispatcher = NULL;
+ ErrorCode errCode;
if (mapper == NULL) {
return ME_ERROR_NULL_PTR;
}
@@ -266,22 +276,18 @@ static ErrorCode RegistServiceInner(const NodeId nodeId, const DispatcherId disp
HDF_LOGE("%s:serviceId exceed max value! ServiceId=%u", __func__, mapper->serviceId);
return ME_ERROR_PARA_WRONG;
}
- HDF_STATUS status = OsalMutexTimedLock(&g_routerMutex, HDF_WAIT_FOREVER);
+ status = OsalMutexTimedLock(&g_routerMutex, HDF_WAIT_FOREVER);
if (status != HDF_SUCCESS) {
HDF_LOGE("Unable to get lock!status=%d", status);
return ME_ERROR_OPER_MUTEX_FAILED;
}
- MessageNode *node = RefMessageNode(nodeId, false);
+ node = RefMessageNode(nodeId, false);
if (node == NULL) {
HDF_LOGE("%s:Node not found!", __func__);
OsalMutexUnlock(&g_routerMutex);
return ME_ERROR_NO_SUCH_NODE;
}
- RemoteService *remoteService = NULL;
- MessageDispatcher *dispatcher = NULL;
-
- ErrorCode errCode;
do {
if (node->CreateRemoteService == NULL) {
HDF_LOGE("%s:Can not reg service to node %d", __func__, nodeId);
@@ -337,6 +343,8 @@ ErrorCode RegistLocalService(const DispatcherId dispatcherId, struct ServiceDef
ErrorCode RegistRemoteService(NodeId nodeId, RemoteService *service)
{
+ HDF_STATUS status;
+ ErrorCode errCode;
if (service == NULL) {
return ME_ERROR_NULL_PTR;
}
@@ -348,13 +356,13 @@ ErrorCode RegistRemoteService(NodeId nodeId, RemoteService *service)
HDF_LOGE("%s:NodeId exceed max value! NodeId=%d", __func__, nodeId);
return ME_ERROR_PARA_WRONG;
}
- HDF_STATUS status = OsalMutexTimedLock(&g_routerMutex, HDF_WAIT_FOREVER);
+ status = OsalMutexTimedLock(&g_routerMutex, HDF_WAIT_FOREVER);
if (status != HDF_SUCCESS) {
HDF_LOGE("Unable to get lock!status=%d", status);
return ME_ERROR_OPER_MUTEX_FAILED;
}
- ErrorCode errCode = DoRegistService(nodeId, BAD_DISPATCHER_ID, service);
+ errCode = DoRegistService(nodeId, BAD_DISPATCHER_ID, service);
if (errCode != ME_SUCCESS) {
HDF_LOGE("%s:RegService failed! errCode=%d", __func__, errCode);
}
@@ -367,16 +375,19 @@ ErrorCode RegistRemoteService(NodeId nodeId, RemoteService *service)
}
static ErrorCode UnregistServiceInner(const NodeId nodeId, const DispatcherId dispatcherId, const ServiceId serviceId)
{
+ RemoteService *service = NULL;
+ HDF_STATUS status;
+ ErrorCode errCode;
if (serviceId >= MESSAGE_ENGINE_MAX_SERVICE) {
return ME_ERROR_PARA_WRONG;
}
- HDF_STATUS status = OsalMutexTimedLock(&g_routerMutex, HDF_WAIT_FOREVER);
+ status = OsalMutexTimedLock(&g_routerMutex, HDF_WAIT_FOREVER);
if (status != HDF_SUCCESS) {
HDF_LOGE("Unable to get lock!status=%d", status);
return ME_ERROR_OPER_MUTEX_FAILED;
}
- ErrorCode errCode = ME_SUCCESS;
+ errCode = ME_SUCCESS;
do {
if (g_servicesIndex[serviceId].nodeIndex != nodeId || g_servicesIndex[serviceId].dispatcherId != dispatcherId) {
errCode = ME_ERROR_NO_SUCH_SERVICE;
@@ -386,7 +397,7 @@ static ErrorCode UnregistServiceInner(const NodeId nodeId, const DispatcherId di
errCode = ME_ERROR_NO_SUCH_SERVICE;
break;
}
- RemoteService *service = g_servicesIndex[serviceId].remoteService;
+ service = g_servicesIndex[serviceId].remoteService;
ReleaseRemoteService(service);
g_servicesIndex[serviceId].remoteService = NULL;
g_servicesIndex[serviceId].nodeIndex = NO_SUCH_NODE_INDEX;
@@ -438,6 +449,9 @@ static bool CheckServiceID(ServiceId serviceId, bool allowSync)
RemoteService *RefRemoteService(ServiceId serviceId)
{
+ HDF_STATUS status;
+ RemoteService *remoteService = NULL;
+ RemoteService *service = NULL;
if (serviceId >= MESSAGE_ENGINE_MAX_SERVICE) {
return NULL;
}
@@ -445,16 +459,14 @@ RemoteService *RefRemoteService(ServiceId serviceId)
if (!CheckServiceID(serviceId, true)) {
return NULL;
}
-
- RemoteService *service = NULL;
- HDF_STATUS status = OsalMutexTimedLock(&g_routerMutex, HDF_WAIT_FOREVER);
+ status = OsalMutexTimedLock(&g_routerMutex, HDF_WAIT_FOREVER);
if (status != HDF_SUCCESS) {
HDF_LOGE("Unable to get lock!status=%d", status);
return NULL;
}
do {
- RemoteService *remoteService = g_servicesIndex[serviceId].remoteService;
+ remoteService = g_servicesIndex[serviceId].remoteService;
if (remoteService != NULL && remoteService->Ref != NULL) {
service = remoteService->Ref(remoteService);
}
@@ -469,11 +481,12 @@ RemoteService *RefRemoteService(ServiceId serviceId)
ErrorCode SendMessage(MessageContext *context)
{
- RemoteService *service = RefRemoteService(context->receiverId);
+ RemoteService *service = NULL;
+ ErrorCode errCode;
+ service = RefRemoteService(context->receiverId);
if (service == NULL) {
return ME_ERROR_NO_SUCH_SERVICE;
}
- ErrorCode errCode;
do {
if (service->SendMessage == NULL) {
errCode = ME_ERROR_NOT_SUPPORTED;
@@ -552,6 +565,7 @@ static void ReleaseNodes(void)
static ErrorCode DoStartMessageRouter(uint8_t nodesConfig)
{
uint8_t i;
+ ErrorCode errCode;
if (g_routerStatus != ME_STATUS_STOPPED) {
HDF_LOGE("Router have already started!");
return ME_ERROR_MUTI_INIT_NOT_ALLOWED;
@@ -562,8 +576,6 @@ static ErrorCode DoStartMessageRouter(uint8_t nodesConfig)
g_servicesIndex[i].nodeIndex = NO_SUCH_NODE_INDEX;
g_servicesIndex[i].dispatcherId = BAD_DISPATCHER_ID;
}
-
- ErrorCode errCode;
do {
HDF_LOGE("%s:Create local node ...", __func__);
errCode = CreateLocalNode(&g_messageNodes[LOCAL_NODE_INDEX]);
@@ -595,13 +607,14 @@ static ErrorCode DoStartMessageRouter(uint8_t nodesConfig)
ErrorCode EnableDefaultDispatcher(void)
{
+ ErrorCode errCode;
DispatcherConfig config = {
.dispatcherId = DEFAULT_DISPATCHER_ID,
.queueSize = DEFAULT_DISPATCHER_QUEUE_SIZE,
.priorityLevelCount = DEFAULT_DISPATCHER_PRIORITY_COUNT
};
HDF_LOGI("Register default dispatcher...");
- ErrorCode errCode = AddDispatcher(&config);
+ errCode = AddDispatcher(&config);
if (errCode != ME_SUCCESS) {
HDF_LOGE("Register default dispatcher failed!ret=%d", errCode);
}
@@ -610,18 +623,20 @@ ErrorCode EnableDefaultDispatcher(void)
ErrorCode StartMessageRouter(uint8_t nodesConfig)
{
+ HDF_STATUS status;
+ ErrorCode errCode;
if (g_routerMutex.realMutex == NULL) {
HDF_STATUS status = OsalMutexInit(&g_routerMutex);
if (status != HDF_SUCCESS) {
return ME_ERROR_OPER_MUTEX_FAILED;
}
}
- HDF_STATUS status = OsalMutexTimedLock(&g_routerMutex, HDF_WAIT_FOREVER);
+ status = OsalMutexTimedLock(&g_routerMutex, HDF_WAIT_FOREVER);
if (status != HDF_SUCCESS) {
HDF_LOGE("Unable to get lock!status=%d", status);
return ME_ERROR_OPER_MUTEX_FAILED;
}
- ErrorCode errCode = DoStartMessageRouter(nodesConfig);
+ errCode = DoStartMessageRouter(nodesConfig);
status = OsalMutexUnlock(&g_routerMutex);
if (status != HDF_SUCCESS) {
HDF_LOGE("Unable to get lock!status=%d", status);
@@ -632,6 +647,7 @@ ErrorCode StartMessageRouter(uint8_t nodesConfig)
static ErrorCode DoShutdownMessageRouter(void)
{
uint8_t i;
+ RemoteService *service = NULL;
if (g_routerStatus == ME_STATUS_STOPPED) {
return ME_SUCCESS;
}
@@ -641,7 +657,7 @@ static ErrorCode DoShutdownMessageRouter(void)
if (g_servicesIndex[i].remoteService == NULL) {
continue;
}
- RemoteService *service = g_servicesIndex[i].remoteService;
+ service = g_servicesIndex[i].remoteService;
g_servicesIndex[i].remoteService = NULL;
g_servicesIndex[i].nodeIndex = NO_SUCH_NODE_INDEX;
g_servicesIndex[i].dispatcherId = BAD_DISPATCHER_ID;
@@ -666,15 +682,15 @@ static ErrorCode DoShutdownMessageRouter(void)
ErrorCode ShutdownMessageRouter()
{
+ HDF_STATUS status;
+ ErrorCode errCode;
HDF_LOGW("%s:Shutdown router...", __func__);
- HDF_STATUS status = OsalMutexTimedLock(&g_routerMutex, HDF_WAIT_FOREVER);
+ status = OsalMutexTimedLock(&g_routerMutex, HDF_WAIT_FOREVER);
if (status != HDF_SUCCESS) {
HDF_LOGE("Unable to get lock!status=%d", status);
return ME_ERROR_OPER_MUTEX_FAILED;
}
-
- ErrorCode errCode = DoShutdownMessageRouter();
-
+ errCode = DoShutdownMessageRouter();
status = OsalMutexUnlock(&g_routerMutex);
if (status != HDF_SUCCESS) {
HDF_LOGE("Unable to get lock!status=%d", status);
@@ -687,13 +703,14 @@ ErrorCode ShutdownMessageRouter()
MessageNode *RefMessageNode(const NodeId nodeId, bool isRequireLock)
{
+ MessageNode *node = NULL;
+ HDF_STATUS status;
if (nodeId >= MAX_NODE_COUNT) {
HDF_LOGE("Input nodeId >= MAX_NODE_COUNT");
return NULL;
}
- MessageNode *node = NULL;
if (isRequireLock) {
- HDF_STATUS status = OsalMutexTimedLock(&g_routerMutex, HDF_WAIT_FOREVER);
+ status = OsalMutexTimedLock(&g_routerMutex, HDF_WAIT_FOREVER);
if (status != HDF_SUCCESS) {
HDF_LOGE("%s:require lock failed!", __func__);
return NULL;
@@ -705,7 +722,7 @@ MessageNode *RefMessageNode(const NodeId nodeId, bool isRequireLock)
}
if (isRequireLock) {
- HDF_STATUS status = OsalMutexUnlock(&g_routerMutex);
+ status = OsalMutexUnlock(&g_routerMutex);
if (status != HDF_SUCCESS) {
HDF_LOGE("%s:Unlock mutex failed!", __func__);
}
diff --git a/model/network/wifi/platform/src/message/nodes/local_node.c b/model/network/wifi/platform/src/message/nodes/local_node.c
index b5b8c89a114ce8d8f986590e1a1fc5aabfd7f385..24b856024f6c57a0a124d6a5229912bc70a3fa6a 100644
--- a/model/network/wifi/platform/src/message/nodes/local_node.c
+++ b/model/network/wifi/platform/src/message/nodes/local_node.c
@@ -31,13 +31,14 @@ typedef struct LocalNodeService {
static void HandleRequestMessage(const RemoteService *service, MessageContext *context)
{
+ LocalNodeService *localNodeService = NULL;
+ localNodeService = (LocalNodeService *)service;
+ struct MessageDef messageDef = { NULL, 0 };
+
if (context == NULL || service == NULL) {
HDF_LOGE("%s:input is NULL", __func__);
return;
}
- LocalNodeService *localNodeService = (LocalNodeService *)service;
-
- struct MessageDef messageDef = { NULL, 0 };
if (localNodeService->mapper != NULL && context->commandId < localNodeService->mapper->messagesLength) {
messageDef = localNodeService->mapper->messages[context->commandId];
}
@@ -50,13 +51,14 @@ static void HandleRequestMessage(const RemoteService *service, MessageContext *c
static void HandleResponseMessage(const RemoteService *service, MessageContext *context)
{
+ HDF_STATUS status;
(void)service;
if (context->requestType < MESSAGE_RSP_START) {
return;
}
if (context->requestType == MESSAGE_TYPE_SYNC_RSP) {
- HDF_STATUS status = OsalSemPost(&context->rspSemaphore);
+ status = OsalSemPost(&context->rspSemaphore);
if (status != HDF_SUCCESS) {
ReleaseMessageContext(context);
}
@@ -73,6 +75,7 @@ static void HandleResponseMessage(const RemoteService *service, MessageContext *
ErrorCode SendMessageLocalNode(const RemoteService *service, MessageContext *context)
{
+ LocalNodeService *localService = NULL;
uint8_t pri = HIGHEST_PRIORITY;
if (service == NULL || context == NULL) {
HDF_LOGE("%s:Input is NULL!", __func__);
@@ -87,7 +90,7 @@ ErrorCode SendMessageLocalNode(const RemoteService *service, MessageContext *con
(void)OsalSemPost(&context->rspSemaphore);
return ME_SUCCESS;
} else {
- LocalNodeService *localService = (LocalNodeService *)service;
+ localService = (LocalNodeService *)service;
if (localService->dispatcher == NULL || localService->dispatcher->AppendMessage == NULL) {
HDF_LOGE("This service has no dispatcher!");
return ME_ERROR_NOT_SUPPORTED;
@@ -117,10 +120,11 @@ static void ShutdownLocalService(RemoteService *service)
static void DestroyLocalNodeRemoteService(RemoteService *service)
{
+ LocalNodeService *localService = NULL;
if (service == NULL) {
return;
}
- LocalNodeService *localService = (LocalNodeService *)service;
+ localService = (LocalNodeService *)service;
if (localService->dispatcher != NULL && localService->dispatcher->Disref != NULL) {
localService->dispatcher->Disref(localService->dispatcher);
}
@@ -131,6 +135,9 @@ static void DestroyLocalNodeRemoteService(RemoteService *service)
RemoteService *CreateLocalNodeService(MessageNode *node, MessageDispatcher *dispatcher, struct ServiceDef *mapper)
{
+ LocalNodeService *service = NULL;
+ ErrorCode errCode;
+ (void)node;
if (mapper == NULL) {
return NULL;
}
@@ -138,14 +145,10 @@ RemoteService *CreateLocalNodeService(MessageNode *node, MessageDispatcher *disp
HDF_LOGE("%s:Bad dispatcher found!", __func__);
return NULL;
}
- (void)node;
-
- LocalNodeService *service = (LocalNodeService *)OsalMemCalloc(sizeof(LocalNodeService));
+ service = (LocalNodeService *)OsalMemCalloc(sizeof(LocalNodeService));
if (service == NULL) {
return NULL;
}
-
- ErrorCode errCode;
do {
service->status = ME_STATUS_RUNNING;
service->ExecRequestMsg = HandleRequestMessage;
@@ -176,16 +179,17 @@ RemoteService *CreateLocalNodeService(MessageNode *node, MessageDispatcher *disp
static ErrorCode InitLocalNode(MessageNode *node)
{
+ HDF_STATUS status;
+ ErrorCode errCode;
if (node == NULL) {
return ME_ERROR_NULL_PTR;
}
- HDF_STATUS status = OsalMutexTimedLock(&node->mutex, HDF_WAIT_FOREVER);
+ status = OsalMutexTimedLock(&node->mutex, HDF_WAIT_FOREVER);
if (status != HDF_SUCCESS) {
return ME_ERROR_OPER_MUTEX_FAILED;
}
-
- ErrorCode errCode = ME_SUCCESS;
+ errCode = ME_SUCCESS;
do {
if (node->status != ME_STATUS_STOPPED) {
HDF_LOGE("%s:unexpected status %d", __func__, node->status);
@@ -224,10 +228,11 @@ static ErrorCode InitLocalNode(MessageNode *node)
static void DestroyLocalNode(MessageNode *node)
{
+ int32_t ret;
if (node == NULL) {
return;
}
- int32_t ret = OsalMutexDestroy(&node->mutex);
+ ret = OsalMutexDestroy(&node->mutex);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:Release mutex failed!ret=%d", __func__, ret);
}
@@ -236,15 +241,17 @@ static void DestroyLocalNode(MessageNode *node)
ErrorCode CreateLocalNode(MessageNode **node)
{
+ int32_t ret;
+ LocalMessageNode *newNode = NULL;
+ ErrorCode errCode;
if (node == NULL) {
return ME_ERROR_NULL_PTR;
}
HDF_LOGI("Creating local node...");
- LocalMessageNode *newNode = (LocalMessageNode *)OsalMemCalloc(sizeof(LocalMessageNode));
+ newNode = (LocalMessageNode *)OsalMemCalloc(sizeof(LocalMessageNode));
if (newNode == NULL) {
return ME_ERROR_RES_LAKE;
}
- ErrorCode errCode;
do {
newNode->status = ME_STATUS_STOPPED;
newNode->Init = InitLocalNode;
@@ -253,7 +260,7 @@ ErrorCode CreateLocalNode(MessageNode **node)
newNode->NotifyServiceAdd = NULL;
newNode->NotifyServiceDel = NULL;
- int32_t ret = OsalMutexInit(&newNode->mutex);
+ ret = OsalMutexInit(&newNode->mutex);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:Init mutex failed!err=%d", __func__, ret);
errCode = ME_ERROR_OPER_MUTEX_FAILED;
diff --git a/model/network/wifi/platform/src/message/sidecar.c b/model/network/wifi/platform/src/message/sidecar.c
index dc8692e93507f1f2ac8fbe159aa901a64fd74e6e..75843c05f0f54c03b5b4b43207c906e7fed198cc 100644
--- a/model/network/wifi/platform/src/message/sidecar.c
+++ b/model/network/wifi/platform/src/message/sidecar.c
@@ -26,12 +26,13 @@ typedef struct {
static ErrorCode MessageInputCheck(const Service *sideCar, ServiceId receiver, struct HdfSBuf *sendData)
{
+ SideCarPrivateData *privateData = NULL;
if (sideCar == NULL || sideCar->privateData == NULL) {
HDF_LOGE("%s:sideCar or sideCar.privateData is NULL", __func__);
return ME_ERROR_NULL_PTR;
}
- SideCarPrivateData *privateData = (SideCarPrivateData *)sideCar->privateData;
+ privateData = (SideCarPrivateData *)sideCar->privateData;
if (receiver >= MESSAGE_ENGINE_MAX_SERVICE || privateData->serviceId >= MESSAGE_ENGINE_MAX_SERVICE) {
return ME_ERROR_NO_SUCH_SERVICE;
}
@@ -74,6 +75,7 @@ int32_t DispatchToMessage(struct HdfDeviceIoClient *client, int id, struct HdfSB
ServiceId serviceId = GetServiceID(id);
uint32_t cmd = GetCmd(id);
MessageContext *context = NULL;
+ RemoteService *targetService = NULL;
if (client == NULL) {
return HDF_ERR_INVALID_PARAM;
@@ -88,7 +90,6 @@ int32_t DispatchToMessage(struct HdfDeviceIoClient *client, int id, struct HdfSB
context->rspData = rspData;
context->requestType = MESSAGE_TYPE_SYNC_REQ;
context->client = client;
- RemoteService *targetService = NULL;
do {
targetService = RefRemoteService(serviceId);
if (targetService == NULL || targetService->SendMessage == NULL) {
@@ -109,18 +110,20 @@ int32_t DispatchToMessage(struct HdfDeviceIoClient *client, int id, struct HdfSB
static ErrorCode SideCarSendSyncMessage(const Service *sideCar, ServiceId receiver, uint32_t commandId,
struct HdfSBuf *sendData, struct HdfSBuf *recvData)
{
+ SideCarPrivateData *privateData = NULL;
+ MessageContext *context = NULL;
+ RemoteService *targetService = NULL;
ErrorCode errCode = MessageInputCheck(sideCar, receiver, sendData);
if (errCode != ME_SUCCESS) {
return errCode;
}
- SideCarPrivateData *privateData = (SideCarPrivateData *)sideCar->privateData;
- MessageContext *context = CreateMessageContext(privateData->serviceId, receiver, commandId, sendData);
+ privateData = (SideCarPrivateData *)sideCar->privateData;
+ context = CreateMessageContext(privateData->serviceId, receiver, commandId, sendData);
if (context == NULL) {
return ME_ERROR_NULL_PTR;
}
context->rspData = recvData;
context->requestType = MESSAGE_TYPE_SYNC_REQ;
- RemoteService *targetService = NULL;
do {
targetService = RefRemoteService(receiver);
if (targetService == NULL || targetService->SendMessage == NULL) {
@@ -141,17 +144,21 @@ static ErrorCode SideCarSendSyncMessage(const Service *sideCar, ServiceId receiv
static ErrorCode SideCarSendAsyncMessageInner(const Service *sideCar, ServiceId receiver, uint32_t commandId,
struct HdfSBuf *reqData, MessageCallBack callback)
{
+ SideCarPrivateData *privateData = NULL;
+ MessageContext *context = NULL;
+ struct HdfSBuf *rspData = NULL;
+ RemoteService *targetService = NULL;
ErrorCode errCode = MessageInputCheck(sideCar, receiver, reqData);
if (errCode != ME_SUCCESS) {
return errCode;
}
- SideCarPrivateData *privateData = (SideCarPrivateData *)sideCar->privateData;
- MessageContext *context = CreateMessageContext(privateData->serviceId, receiver, commandId, reqData);
+ privateData = (SideCarPrivateData *)sideCar->privateData;
+ context = CreateMessageContext(privateData->serviceId, receiver, commandId, reqData);
if (context == NULL) {
return ME_ERROR_NULL_PTR;
}
- struct HdfSBuf *rspData = HdfSBufObtainDefaultSize();
+ rspData = HdfSBufObtainDefaultSize();
if (rspData == NULL) {
OsalMemFree(context);
return HDF_FAILURE;
@@ -159,8 +166,6 @@ static ErrorCode SideCarSendAsyncMessageInner(const Service *sideCar, ServiceId
context->requestType = MESSAGE_TYPE_ASYNC_REQ;
context->callback = callback;
context->rspData = rspData;
-
- RemoteService *targetService = NULL;
do {
targetService = RefRemoteService(receiver);
if (targetService == NULL || targetService->SendMessage == NULL) {
@@ -199,6 +204,8 @@ static ErrorCode SideCarSendOneWayMessage(const struct SideCar_ *sideCar, Servic
static ErrorCode DestroyService(Service *service)
{
+ SideCarPrivateData *data = NULL;
+ ErrorCode errCode;
if (service == NULL) {
return ME_ERROR_NULL_PTR;
}
@@ -207,10 +214,9 @@ static ErrorCode DestroyService(Service *service)
HDF_LOGE("%s:privateData is NULL!", __func__);
return ME_ERROR_PARA_WRONG;
}
- SideCarPrivateData *data = (SideCarPrivateData *)service->privateData;
+ data = (SideCarPrivateData *)service->privateData;
HDF_LOGE("Destroy service! id=%d", data->serviceId);
-
- ErrorCode errCode = UnregistLocalService(data->dispatcherId, data->serviceId);
+ errCode = UnregistLocalService(data->dispatcherId, data->serviceId);
if (errCode != ME_SUCCESS) {
HDF_LOGE("Unregist service failed!ret=%d", errCode);
return errCode;
@@ -224,6 +230,9 @@ static ErrorCode DestroyService(Service *service)
Service *InitService(struct ServiceDef *def, const ServiceCfg *cfg)
{
+ Service *service = NULL;
+ SideCarPrivateData *privateData = NULL;
+ ErrorCode errCode;
if (cfg == NULL || def == NULL) {
return NULL;
}
@@ -233,7 +242,7 @@ Service *InitService(struct ServiceDef *def, const ServiceCfg *cfg)
return NULL;
}
- Service *service = (Service *)OsalMemCalloc(sizeof(Service));
+ service = (Service *)OsalMemCalloc(sizeof(Service));
if (service == NULL) {
HDF_LOGE("%s:OsalMemAlloc return NULL!", __func__);
return NULL;
@@ -243,7 +252,7 @@ Service *InitService(struct ServiceDef *def, const ServiceCfg *cfg)
service->SendOneWayMessage = SideCarSendOneWayMessage;
service->Destroy = DestroyService;
- SideCarPrivateData *privateData = (SideCarPrivateData *)OsalMemCalloc(sizeof(SideCarPrivateData));
+ privateData = (SideCarPrivateData *)OsalMemCalloc(sizeof(SideCarPrivateData));
if (privateData == NULL) {
OsalMemFree(service);
HDF_LOGE("%s:OsalMemAlloc return NULL!", __func__);
@@ -254,7 +263,7 @@ Service *InitService(struct ServiceDef *def, const ServiceCfg *cfg)
service->privateData = (void *)privateData;
privateData = NULL;
- ErrorCode errCode = RegistLocalService(cfg->dispatcherId, def);
+ errCode = RegistLocalService(cfg->dispatcherId, def);
if (errCode != ME_SUCCESS) {
OsalMemFree(service->privateData);
service->privateData = NULL;
diff --git a/model/network/wifi/platform/src/qos/flow_control_task.c b/model/network/wifi/platform/src/qos/flow_control_task.c
index b51209bd83cdb1089f07f27f402248e1e131cb06..a6f3b7a16713458904bc6dea38f33d8d6664c660 100644
--- a/model/network/wifi/platform/src/qos/flow_control_task.c
+++ b/model/network/wifi/platform/src/qos/flow_control_task.c
@@ -171,6 +171,7 @@ static void DestroyTask(struct FlowControlModule *fcm, FlowDir dir)
int32_t CreateFlowControlTask(struct FlowControlModule *fcm)
{
+ int32_t ret;
struct OsalThreadParam config = {
.priority = OSAL_THREAD_PRI_HIGHEST,
.stackSize = 0,
@@ -180,8 +181,7 @@ int32_t CreateFlowControlTask(struct FlowControlModule *fcm)
HDF_LOGE("%s fail: fcm = null!", __func__);
return HDF_ERR_INVALID_PARAM;
}
-
- int32_t ret = CreateTask(&fcm->txTransferThread, RX_THREAD_NAME, RunWiFiTxFlowControl, &config, fcm);
+ ret = CreateTask(&fcm->txTransferThread, RX_THREAD_NAME, RunWiFiTxFlowControl, &config, fcm);
if (ret == HDF_FAILURE) {
fcm->threadStatus[FLOW_TX] = THREAD_INIT_FAIL;
return HDF_FAILURE;
diff --git a/model/sensor/driver/accel/sensor_accel_driver.c b/model/sensor/driver/accel/sensor_accel_driver.c
old mode 100644
new mode 100755
index 7f9a88370b1981c6df87c769e1f84951d23b467d..e63650487078e6856288527a102590f0fb9d6def
--- a/model/sensor/driver/accel/sensor_accel_driver.c
+++ b/model/sensor/driver/accel/sensor_accel_driver.c
@@ -29,6 +29,19 @@ static struct AccelDrvData *AccelGetDrvData(void)
static struct SensorRegCfgGroupNode *g_regCfgGroup[SENSOR_GROUP_MAX] = { NULL };
+int32_t SubscribeAccelDataCallbackFunc(GravitySubscribeAccelCallback cb)
+{
+ CHECK_NULL_PTR_RETURN_VALUE(cb, HDF_ERR_INVALID_PARAM);
+
+ struct AccelDrvData *drvData = AccelGetDrvData();
+
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+
+ drvData->cb = cb;
+
+ return HDF_SUCCESS;
+}
+
int32_t AccelRegisterChipOps(const struct AccelOpsCall *ops)
{
struct AccelDrvData *drvData = AccelGetDrvData();
@@ -44,6 +57,7 @@ int32_t AccelRegisterChipOps(const struct AccelOpsCall *ops)
static void AccelDataWorkEntry(void *arg)
{
struct AccelDrvData *drvData = NULL;
+ struct SensorReportEvent event;
drvData = (struct AccelDrvData *)arg;
CHECK_NULL_PTR_RETURN(drvData);
@@ -52,8 +66,19 @@ static void AccelDataWorkEntry(void *arg)
HDF_LOGI("%s: Accel ReadData function NULl", __func__);
return;
}
- if (drvData->ops.ReadData(drvData->accelCfg) != HDF_SUCCESS) {
+
+ if (drvData->ops.ReadData(drvData->accelCfg, &event) != HDF_SUCCESS) {
HDF_LOGE("%s: Accel read data failed", __func__);
+ return;
+ }
+
+ if (ReportSensorEvent(&event) != HDF_SUCCESS) {
+ HDF_LOGE("%s: report accel data failed", __func__);
+ return;
+ }
+
+ if (drvData->cb != NULL) {
+ drvData->cb((int32_t*)event.data, event.dataLen);
}
}
@@ -246,10 +271,17 @@ static int32_t InitAccelAfterDetected(struct SensorCfgData *config)
return HDF_FAILURE;
}
+ if (ParseSensorDirection(config) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Parse accel direction failed", __func__);
+ (void)DeleteSensorDevice(&config->sensorInfo);
+ return HDF_FAILURE;
+ }
+
if (ParseSensorRegConfig(config) != HDF_SUCCESS) {
HDF_LOGE("%s: Parse sensor register failed", __func__);
(void)DeleteSensorDevice(&config->sensorInfo);
ReleaseSensorAllRegConfig(config);
+ ReleaseSensorDirectionConfig(config);
return HDF_FAILURE;
}
return HDF_SUCCESS;
@@ -299,7 +331,7 @@ BASE_CONFIG_EXIT:
(void)memset_s(&drvData->accelCfg->sensorInfo, sizeof(struct SensorBasicInfo), 0, sizeof(struct SensorBasicInfo));
(void)memset_s(&drvData->accelCfg->busCfg, sizeof(struct SensorBusCfg), 0, sizeof(struct SensorBusCfg));
(void)memset_s(&drvData->accelCfg->sensorAttr, sizeof(struct SensorAttr), 0, sizeof(struct SensorAttr));
- return NULL;
+ return drvData->accelCfg;
}
void AccelReleaseCfgData(struct SensorCfgData *accelCfg)
@@ -309,6 +341,7 @@ void AccelReleaseCfgData(struct SensorCfgData *accelCfg)
(void)DeleteSensorDevice(&accelCfg->sensorInfo);
ReleaseSensorAllRegConfig(accelCfg);
(void)ReleaseSensorBusHandle(&accelCfg->busCfg);
+ ReleaseSensorDirectionConfig(accelCfg);
accelCfg->root = NULL;
(void)memset_s(&accelCfg->sensorInfo, sizeof(struct SensorBasicInfo), 0, sizeof(struct SensorBasicInfo));
@@ -334,6 +367,7 @@ int32_t AccelInitDriver(struct HdfDeviceObject *device)
}
drvData->accelCfg->regCfgGroup = &g_regCfgGroup[0];
+ drvData->cb = NULL;
HDF_LOGI("%s: Init accel driver success", __func__);
return HDF_SUCCESS;
@@ -346,7 +380,7 @@ void AccelReleaseDriver(struct HdfDeviceObject *device)
struct AccelDrvData *drvData = (struct AccelDrvData *)device->service;
CHECK_NULL_PTR_RETURN(drvData);
- if (drvData->detectFlag) {
+ if (drvData->detectFlag && drvData->accelCfg != NULL) {
AccelReleaseCfgData(drvData->accelCfg);
}
diff --git a/model/sensor/driver/accel/sensor_accel_driver.h b/model/sensor/driver/accel/sensor_accel_driver.h
old mode 100644
new mode 100755
index 4162ae0ddb69f7555de72a20481c0d6361c0e900..5a7d00448c0649837b7c712606700ca14395cf03
--- a/model/sensor/driver/accel/sensor_accel_driver.h
+++ b/model/sensor/driver/accel/sensor_accel_driver.h
@@ -32,6 +32,8 @@ enum AccelAxisPart {
ACCEL_AXIS_BUTT,
};
+typedef int32_t (*GravitySubscribeAccelCallback)(int32_t *rawData, int32_t size);
+
struct AccelData {
int32_t x;
int32_t y;
@@ -40,7 +42,7 @@ struct AccelData {
struct AccelOpsCall {
int32_t (*Init)(struct SensorCfgData *data);
- int32_t (*ReadData)(struct SensorCfgData *data);
+ int32_t (*ReadData)(struct SensorCfgData *data, struct SensorReportEvent *event);
};
struct AccelDrvData {
@@ -54,10 +56,11 @@ struct AccelDrvData {
int64_t interval;
struct SensorCfgData *accelCfg;
struct AccelOpsCall ops;
+ GravitySubscribeAccelCallback cb;
};
int32_t AccelRegisterChipOps(const struct AccelOpsCall *ops);
struct SensorCfgData *AccelCreateCfgData(const struct DeviceResourceNode *node);
void AccelReleaseCfgData(struct SensorCfgData *sensorCfgData);
-
+int32_t SubscribeAccelDataCallbackFunc(GravitySubscribeAccelCallback cb);
#endif /* SENSOR_ACCEL_DRIVER_H */
diff --git a/model/sensor/driver/accel/sensor_gravity_driver.c b/model/sensor/driver/accel/sensor_gravity_driver.c
new file mode 100755
index 0000000000000000000000000000000000000000..a697d7d742d2b2989d3c4e88fc48122a1c1396c1
--- /dev/null
+++ b/model/sensor/driver/accel/sensor_gravity_driver.c
@@ -0,0 +1,335 @@
+/*
+ * Copyright (c) 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 "sensor_gravity_driver.h"
+#include "sensor_accel_driver.h"
+#include
+#include "hdf_base.h"
+#include "hdf_device_desc.h"
+#include "osal_math.h"
+#include "osal_mem.h"
+#include "osal_time.h"
+#include "sensor_device_manager.h"
+#include "sensor_platform_if.h"
+
+#define HDF_LOG_TAG sensor_gravity_driver_c
+
+#define HDF_GRAVITY_WORK_QUEUE_NAME "hdf_gravity_work_queue"
+
+static struct GravityDrvData *g_gravityDrvData = NULL;
+static int32_t g_accelRawData[GRAVITY_AXIS_NUM];
+
+static struct GravityDrvData *GravityGetDrvData(void)
+{
+ return g_gravityDrvData;
+}
+
+static int32_t GravitySubscribeAccelData(int32_t *accelData, int32_t size)
+{
+ CHECK_NULL_PTR_RETURN_VALUE(accelData, HDF_ERR_INVALID_PARAM);
+
+ if (size > GRAVITY_AXIS_NUM * sizeof(int32_t)) {
+ HDF_LOGE("%s: size exceed max value", __func__);
+ return HDF_FAILURE;
+ }
+
+ g_accelRawData[GRAVITY_X_AXIS] = accelData[GRAVITY_X_AXIS];
+ g_accelRawData[GRAVITY_Y_AXIS] = accelData[GRAVITY_Y_AXIS];
+ g_accelRawData[GRAVITY_Z_AXIS] = accelData[GRAVITY_Z_AXIS];
+
+ return HDF_SUCCESS;
+}
+
+static void GravityDataWorkEntry(void *arg)
+{
+ struct GravityDrvData *drvData = NULL;
+ static int32_t GravityRawData[GRAVITY_AXIS_NUM];
+ struct SensorReportEvent event;
+ drvData = (struct GravityDrvData *)arg;
+ CHECK_NULL_PTR_RETURN(drvData);
+ OsalTimespec time;
+
+ GravityRawData[GRAVITY_X_AXIS] = (g_accelRawData[GRAVITY_X_AXIS] * GRAVITY_UNITS +
+ GRAVITY_FILTER_UNITS * (GravityRawData[GRAVITY_X_AXIS] - g_accelRawData[GRAVITY_X_AXIS])) / GRAVITY_UNITS;
+ GravityRawData[GRAVITY_Y_AXIS] = (g_accelRawData[GRAVITY_Y_AXIS] * GRAVITY_UNITS +
+ GRAVITY_FILTER_UNITS * (GravityRawData[GRAVITY_Y_AXIS] - g_accelRawData[GRAVITY_Y_AXIS])) / GRAVITY_UNITS;
+ GravityRawData[GRAVITY_Z_AXIS] = (g_accelRawData[GRAVITY_Z_AXIS] * GRAVITY_UNITS +
+ GRAVITY_FILTER_UNITS * (GravityRawData[GRAVITY_Z_AXIS] - g_accelRawData[GRAVITY_Z_AXIS])) / GRAVITY_UNITS;
+
+ if (OsalGetTime(&time) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Get time failed", __func__);
+ return;
+ }
+ event.timestamp = time.sec * SENSOR_SECOND_CONVERT_NANOSECOND + time.usec * SENSOR_CONVERT_UNIT; /* unit nanosecond */
+ event.sensorId = SENSOR_TAG_GRAVITY;
+ event.option = 0;
+ event.mode = SENSOR_WORK_MODE_REALTIME;
+ event.dataLen = sizeof(GravityRawData);
+ event.data = (uint8_t *)&GravityRawData;
+
+ if (ReportSensorEvent(&event) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Report gravity data failed", __func__);
+ }
+}
+
+static void GravityTimerEntry(uintptr_t arg)
+{
+ int32_t ret;
+ struct GravityDrvData *drvData = (struct GravityDrvData *)arg;
+ CHECK_NULL_PTR_RETURN(drvData);
+
+ if (!HdfAddWork(&drvData->gravityWorkQueue, &drvData->gravityWork)) {
+ HDF_LOGE("%s: Gravity add work queue failed", __func__);
+ }
+
+ ret = OsalTimerSetTimeout(&drvData->gravityTimer, drvData->interval);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Gravity modify time failed", __func__);
+ }
+}
+
+static int32_t InitGravityData(struct GravityDrvData *drvData)
+{
+ if (HdfWorkQueueInit(&drvData->gravityWorkQueue, HDF_GRAVITY_WORK_QUEUE_NAME) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Gravity init work queue failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ if (HdfWorkInit(&drvData->gravityWork, GravityDataWorkEntry, drvData) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Gravity create thread failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ drvData->interval = GRAVITY_TIMER_MAX_TIME;
+ drvData->enable = false;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SetGravityEnable(void)
+{
+ int32_t ret;
+ struct GravityDrvData *drvData = GravityGetDrvData();
+
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+ CHECK_NULL_PTR_RETURN_VALUE(drvData->gravityCfg, HDF_ERR_INVALID_PARAM);
+
+ if (drvData->enable) {
+ HDF_LOGE("%s: Gravity sensor is enabled", __func__);
+ return HDF_SUCCESS;
+ }
+
+ ret = OsalTimerCreate(&drvData->gravityTimer, GRAVITY_TIMER_MAX_TIME, GravityTimerEntry, (uintptr_t)drvData);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Gravity create timer failed[%d]", __func__, ret);
+ return ret;
+ }
+
+ ret = OsalTimerStartLoop(&drvData->gravityTimer);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Gravity start timer failed[%d]", __func__, ret);
+ return ret;
+ }
+ drvData->enable = true;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SetGravityDisable(void)
+{
+ int32_t ret;
+ struct GravityDrvData *drvData = GravityGetDrvData();
+
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+ CHECK_NULL_PTR_RETURN_VALUE(drvData->gravityCfg, HDF_ERR_INVALID_PARAM);
+
+ if (!drvData->enable) {
+ HDF_LOGE("%s: Gravity sensor had disable", __func__);
+ return HDF_SUCCESS;
+ }
+
+ ret = OsalTimerDelete(&drvData->gravityTimer);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Gravity delete timer failed", __func__);
+ return ret;
+ }
+ drvData->enable = false;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SetGravityBatch(int64_t samplingInterval, int64_t interval)
+{
+ (void)interval;
+
+ int64_t ms;
+ struct GravityDrvData *drvData = NULL;
+
+ drvData = GravityGetDrvData();
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+
+ ms = OsalDivS64(samplingInterval, (SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT));
+
+ drvData->interval = (ms <= GRAVITY_TIMER_MIN_TIME) ? GRAVITY_TIMER_MIN_TIME : GRAVITY_TIMER_MAX_TIME;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SetGravityMode(int32_t mode)
+{
+ return (mode == SENSOR_WORK_MODE_REALTIME) ? HDF_SUCCESS : HDF_FAILURE;
+}
+
+static int32_t SetGravityOption(uint32_t option)
+{
+ (void)option;
+ return HDF_SUCCESS;
+}
+
+static int32_t DispatchGravity(struct HdfDeviceIoClient *client,
+ int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ (void)client;
+ (void)cmd;
+ (void)data;
+ (void)reply;
+
+ return HDF_SUCCESS;
+}
+
+int32_t GravityBindDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
+
+ struct GravityDrvData *drvData = (struct GravityDrvData *)OsalMemCalloc(sizeof(*drvData));
+ if (drvData == NULL) {
+ HDF_LOGE("%s: Malloc gravity drv data fail!", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ drvData->ioService.Dispatch = DispatchGravity;
+ drvData->device = device;
+ device->service = &drvData->ioService;
+ g_gravityDrvData = drvData;
+ return HDF_SUCCESS;
+}
+
+static int32_t InitGravityOps(struct SensorCfgData *config, struct SensorDeviceInfo *deviceInfo)
+{
+ CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM);
+
+ deviceInfo->ops.Enable = SetGravityEnable;
+ deviceInfo->ops.Disable = SetGravityDisable;
+ deviceInfo->ops.SetBatch = SetGravityBatch;
+ deviceInfo->ops.SetMode = SetGravityMode;
+ deviceInfo->ops.SetOption = SetGravityOption;
+
+ if (memcpy_s(&deviceInfo->sensorInfo, sizeof(deviceInfo->sensorInfo),
+ &config->sensorInfo, sizeof(config->sensorInfo)) != EOK) {
+ HDF_LOGE("%s: Copy sensor info failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ if (SubscribeAccelDataCallbackFunc(GravitySubscribeAccelData) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Gravity register accel failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t InitGravityAfterBase(struct SensorCfgData *config)
+{
+ struct SensorDeviceInfo deviceInfo;
+ CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM);
+
+ if (InitGravityOps(config, &deviceInfo) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Init gravity ops failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ if (AddSensorDevice(&deviceInfo) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Add gravity device failed", __func__);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t GravityCreateCfgData(const struct DeviceResourceNode *node)
+{
+ struct GravityDrvData *drvData = GravityGetDrvData();
+
+ CHECK_NULL_PTR_RETURN_VALUE(node, HDF_ERR_INVALID_PARAM);
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+ CHECK_NULL_PTR_RETURN_VALUE(drvData->gravityCfg, HDF_ERR_INVALID_PARAM);
+
+ if (GetSensorBaseConfigData(node, drvData->gravityCfg) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Get sensor base config failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ if (InitGravityAfterBase(drvData->gravityCfg) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Init gravity sensor device failed", __func__);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+int32_t GravityInitDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
+ struct GravityDrvData *drvData = (struct GravityDrvData *)device->service;
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+
+ if (InitGravityData(drvData) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Init gravity config failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ drvData->gravityCfg = (struct SensorCfgData *)OsalMemCalloc(sizeof(*drvData->gravityCfg));
+ if (drvData->gravityCfg == NULL) {
+ HDF_LOGE("%s: Malloc gravity config data failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ if (GravityCreateCfgData(device->property) != HDF_SUCCESS) {
+ HDF_LOGE("%s: create gravity device failed", __func__);
+ OsalMemFree(drvData->gravityCfg);
+ return HDF_FAILURE;
+ }
+ HDF_LOGI("%s: Init gravity driver success", __func__);
+ return HDF_SUCCESS;
+}
+
+void GravityReleaseDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN(device);
+
+ struct GravityDrvData *drvData = (struct GravityDrvData *)device->service;
+ CHECK_NULL_PTR_RETURN(drvData);
+
+ if (drvData->gravityCfg != NULL) {
+ (void)DeleteSensorDevice(&drvData->gravityCfg->sensorInfo);
+ OsalMemFree(drvData->gravityCfg);
+ drvData->gravityCfg = NULL;
+ }
+
+ HdfWorkDestroy(&drvData->gravityWork);
+ HdfWorkQueueDestroy(&drvData->gravityWorkQueue);
+ OsalMemFree(drvData);
+}
+
+struct HdfDriverEntry g_sensorGravityDevEntry = {
+ .moduleVersion = 1,
+ .moduleName = "HDF_SENSOR_GRAVITY",
+ .Bind = GravityBindDriver,
+ .Init = GravityInitDriver,
+ .Release = GravityReleaseDriver,
+};
+
+HDF_INIT(g_sensorGravityDevEntry);
\ No newline at end of file
diff --git a/model/sensor/driver/accel/sensor_gravity_driver.h b/model/sensor/driver/accel/sensor_gravity_driver.h
new file mode 100755
index 0000000000000000000000000000000000000000..30521c1cda8d208388abe49699ea8f9025a8a4d7
--- /dev/null
+++ b/model/sensor/driver/accel/sensor_gravity_driver.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef SENSOR_GRAVITY_DRIVER_H
+#define SENSOR_GRAVITY_DRIVER_H
+
+#include "hdf_workqueue.h"
+#include "osal_mutex.h"
+#include "osal_timer.h"
+#include "sensor_config_parser.h"
+#include "sensor_platform_if.h"
+
+#define GRAVITY_TIMER_MIN_TIME 10
+#define GRAVITY_TIMER_MAX_TIME 20
+#define GRAVITY_UNITS 100
+#define GRAVITY_FILTER_UNITS 85
+enum GravityAxisNum {
+ GRAVITY_X_AXIS = 0,
+ GRAVITY_Y_AXIS = 1,
+ GRAVITY_Z_AXIS = 2,
+ GRAVITY_AXIS_NUM = 3,
+};
+
+struct GravityData {
+ int32_t x;
+ int32_t y;
+ int32_t z;
+};
+
+struct GravityDrvData {
+ struct IDeviceIoService ioService;
+ struct HdfDeviceObject *device;
+ HdfWorkQueue gravityWorkQueue;
+ HdfWork gravityWork;
+ OsalTimer gravityTimer;
+ struct SensorCfgData *gravityCfg;
+ int64_t interval;
+ bool enable;
+};
+
+#endif /* SENSOR_GRAVITY_DRIVER_H */
\ No newline at end of file
diff --git a/model/sensor/driver/als/sensor_als_driver.c b/model/sensor/driver/als/sensor_als_driver.c
new file mode 100755
index 0000000000000000000000000000000000000000..cd91f4aeba4fc6572070f327981c50dda363d287
--- /dev/null
+++ b/model/sensor/driver/als/sensor_als_driver.c
@@ -0,0 +1,523 @@
+/*
+ * Copyright (c) 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 "sensor_als_driver.h"
+#include
+#include "als_bh1745.h"
+#include "osal_math.h"
+#include "osal_mem.h"
+#include "sensor_config_controller.h"
+#include "sensor_device_manager.h"
+#include "sensor_platform_if.h"
+
+#define HDF_LOG_TAG sensor_als_driver_c
+
+#define HDF_ALS_WORK_QUEUE_NAME "hdf_als_work_queue"
+
+static struct AlsDrvData *g_alsDrvData = NULL;
+
+static struct AlsDrvData *AlsGetDrvData(void)
+{
+ return g_alsDrvData;
+}
+
+static struct SensorRegCfgGroupNode *g_regCfgGroup[SENSOR_GROUP_MAX] = { NULL };
+static struct SensorRegCfgGroupNode *g_extendAlsRegCfgGroup[EXTENDED_ALS_GROUP_MAX] = { NULL };
+static char *g_extendedAlsGroupName[EXTENDED_ALS_GROUP_MAX] = {
+ "time",
+ "gain",
+};
+
+int32_t GetTimeByRegValue(uint8_t regValue, struct TimeMap *table, int32_t itemNum)
+{
+ int32_t i;
+
+ CHECK_NULL_PTR_RETURN_VALUE(table, HDF_FAILURE);
+
+ for (i = 0; i < itemNum; i++) {
+ if (regValue == table[i].timeRegValue) {
+ return table[i].timeValue;
+ }
+ }
+
+ return HDF_FAILURE;
+}
+
+int32_t GetRegValueByTime(uint32_t timeValue, struct TimeMap *table, int32_t itemNum)
+{
+ int32_t i;
+
+ CHECK_NULL_PTR_RETURN_VALUE(table, HDF_FAILURE);
+
+ for (i = 0; i < itemNum; i++) {
+ if (timeValue == table[i].timeValue) {
+ return table[i].timeRegValue;
+ }
+ }
+
+ return HDF_FAILURE;
+}
+
+int32_t GetRegGroupIndexByTime(uint32_t timeValue, struct TimeMap *table, int32_t itemNum)
+{
+ int32_t i;
+
+ CHECK_NULL_PTR_RETURN_VALUE(table, HDF_FAILURE);
+
+ for (i = 0; i < itemNum; i++) {
+ if (timeValue == table[i].timeValue) {
+ return i;
+ }
+ }
+
+ return HDF_FAILURE;
+}
+
+int32_t GetGainByRegValue(uint8_t regValue, struct GainMap *table, int32_t itemNum)
+{
+ int32_t i;
+
+ CHECK_NULL_PTR_RETURN_VALUE(table, HDF_FAILURE);
+
+ for (i = 0; i < itemNum; i++) {
+ if (regValue == table[i].gainRegValue) {
+ return table[i].gainValue;
+ }
+ }
+
+ return HDF_FAILURE;
+}
+
+static int32_t GetExtendedAlsRegGroupNameIndex(const char *name)
+{
+ int32_t index;
+
+ CHECK_NULL_PTR_RETURN_VALUE(name, EXTENDED_ALS_GROUP_MAX);
+
+ for (index = 0; index < EXTENDED_ALS_GROUP_MAX; ++index) {
+ if ((g_extendedAlsGroupName[index] != NULL) && (strcmp(name, g_extendedAlsGroupName[index]) == 0)) {
+ break;
+ }
+ }
+
+ return index;
+}
+
+void ReleaseExtendedAlsRegConfig(struct SensorCfgData *config)
+{
+ int32_t index;
+
+ CHECK_NULL_PTR_RETURN(config);
+ CHECK_NULL_PTR_RETURN(config->extendedRegCfgGroup);
+
+ for (index = 0; index < EXTENDED_ALS_GROUP_MAX; ++index) {
+ if (config->extendedRegCfgGroup[index] != NULL) {
+ if (config->extendedRegCfgGroup[index]->regCfgItem != NULL) {
+ OsalMemFree(config->extendedRegCfgGroup[index]->regCfgItem);
+ config->extendedRegCfgGroup[index]->regCfgItem = NULL;
+ }
+
+ OsalMemFree(config->extendedRegCfgGroup[index]);
+ config->extendedRegCfgGroup[index] = NULL;
+ }
+ }
+}
+
+int32_t ParseExtendedAlsRegConfig(struct SensorCfgData *config)
+{
+ int32_t index;
+ struct DeviceResourceIface *parser = NULL;
+ const struct DeviceResourceNode *extendedRegCfgNode = NULL;
+ const struct DeviceResourceAttr *extendedRegAttr = NULL;
+
+ CHECK_NULL_PTR_RETURN_VALUE(config->root, HDF_ERR_INVALID_PARAM);
+ parser = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ CHECK_NULL_PTR_RETURN_VALUE(parser, HDF_ERR_INVALID_PARAM);
+
+ extendedRegCfgNode = parser->GetChildNode(config->root, "extendAlsRegConfig");
+ CHECK_NULL_PTR_RETURN_VALUE(extendedRegCfgNode, HDF_ERR_INVALID_PARAM);
+
+ DEV_RES_NODE_FOR_EACH_ATTR(extendedRegCfgNode, extendedRegAttr) {
+ if (extendedRegAttr == NULL || extendedRegAttr->name == NULL) {
+ HDF_LOGE("%s:sensor reg node attr is null", __func__);
+ break;
+ }
+
+ index = GetExtendedAlsRegGroupNameIndex(extendedRegAttr->name);
+ if (index >= EXTENDED_ALS_GROUP_MAX) {
+ HDF_LOGE("%s: get sensor register group index failed", __func__);
+ goto ERROR;
+ }
+
+ if (ParseSensorRegGroup(parser, extendedRegCfgNode, extendedRegAttr->name,
+ &config->extendedRegCfgGroup[index]) != HDF_SUCCESS) {
+ HDF_LOGE("%s: parse sensor register group failed", __func__);
+ goto ERROR;
+ }
+ }
+
+ return HDF_SUCCESS;
+
+ERROR:
+ ReleaseExtendedAlsRegConfig(config);
+ HDF_LOGE("%s: parse sensor extend register config failed", __func__);
+
+ return HDF_FAILURE;
+}
+
+int32_t AlsRegisterChipOps(const struct AlsOpsCall *ops)
+{
+ struct AlsDrvData *drvData = AlsGetDrvData();
+
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+ CHECK_NULL_PTR_RETURN_VALUE(ops, HDF_ERR_INVALID_PARAM);
+
+ drvData->ops.Init = ops->Init;
+ drvData->ops.ReadData = ops->ReadData;
+ return HDF_SUCCESS;
+}
+
+static void AlsDataWorkEntry(void *arg)
+{
+ struct AlsDrvData *drvData = NULL;
+
+ drvData = (struct AlsDrvData *)arg;
+ CHECK_NULL_PTR_RETURN(drvData);
+
+ if (drvData->ops.ReadData == NULL) {
+ HDF_LOGI("%s: Als ReadData function NULl", __func__);
+ return;
+ }
+ if (drvData->ops.ReadData(drvData->alsCfg) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Als read data failed", __func__);
+ }
+}
+
+static void AlsTimerEntry(uintptr_t arg)
+{
+ int64_t interval;
+ int32_t ret;
+ struct AlsDrvData *drvData = (struct AlsDrvData *)arg;
+ CHECK_NULL_PTR_RETURN(drvData);
+
+ if (!HdfAddWork(&drvData->alsWorkQueue, &drvData->alsWork)) {
+ HDF_LOGE("%s: Als add work queue failed", __func__);
+ }
+
+ interval = OsalDivS64(drvData->interval, (SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT));
+ interval = (interval < SENSOR_TIMER_MIN_TIME) ? SENSOR_TIMER_MIN_TIME : interval;
+ ret = OsalTimerSetTimeout(&drvData->alsTimer, interval);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Als modify time failed", __func__);
+ }
+}
+
+static int32_t InitAlsData(struct AlsDrvData *drvData)
+{
+ if (HdfWorkQueueInit(&drvData->alsWorkQueue, HDF_ALS_WORK_QUEUE_NAME) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Als init work queue failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ if (HdfWorkInit(&drvData->alsWork, AlsDataWorkEntry, drvData) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Als create thread failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ drvData->interval = SENSOR_TIMER_MIN_TIME;
+ drvData->enable = false;
+ drvData->detectFlag = false;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SetAlsEnable(void)
+{
+ int32_t ret;
+ struct AlsDrvData *drvData = AlsGetDrvData();
+
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+ CHECK_NULL_PTR_RETURN_VALUE(drvData->alsCfg, HDF_ERR_INVALID_PARAM);
+
+ if (drvData->enable) {
+ HDF_LOGE("%s: Als sensor is enabled", __func__);
+ return HDF_SUCCESS;
+ }
+
+ ret = SetSensorRegCfgArray(&drvData->alsCfg->busCfg, drvData->alsCfg->regCfgGroup[SENSOR_ENABLE_GROUP]);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Als sensor enable config failed", __func__);
+ return ret;
+ }
+
+ ret = OsalTimerCreate(&drvData->alsTimer, SENSOR_TIMER_MIN_TIME, AlsTimerEntry, (uintptr_t)drvData);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Als create timer failed[%d]", __func__, ret);
+ return ret;
+ }
+
+ ret = OsalTimerStartLoop(&drvData->alsTimer);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Als start timer failed[%d]", __func__, ret);
+ return ret;
+ }
+ drvData->enable = true;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SetAlsDisable(void)
+{
+ int32_t ret;
+ struct AlsDrvData *drvData = AlsGetDrvData();
+
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+ CHECK_NULL_PTR_RETURN_VALUE(drvData->alsCfg, HDF_ERR_INVALID_PARAM);
+
+ if (!drvData->enable) {
+ HDF_LOGE("%s: Als sensor had disable", __func__);
+ return HDF_SUCCESS;
+ }
+
+ ret = SetSensorRegCfgArray(&drvData->alsCfg->busCfg, drvData->alsCfg->regCfgGroup[SENSOR_DISABLE_GROUP]);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Als sensor disable config failed", __func__);
+ return ret;
+ }
+
+ ret = OsalTimerDelete(&drvData->alsTimer);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Als delete timer failed", __func__);
+ return ret;
+ }
+ drvData->enable = false;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SetAlsBatch(int64_t samplingInterval, int64_t interval)
+{
+ (void)interval;
+
+ struct AlsDrvData *drvData = NULL;
+
+ drvData = AlsGetDrvData();
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+
+ drvData->interval = samplingInterval;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SetAlsMode(int32_t mode)
+{
+ return (mode == SENSOR_WORK_MODE_REALTIME) ? HDF_SUCCESS : HDF_FAILURE;
+}
+
+static int32_t SetAlsOption(uint32_t option)
+{
+ (void)option;
+ return HDF_SUCCESS;
+}
+
+static int32_t DispatchAls(struct HdfDeviceIoClient *client,
+ int32_t cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ (void)client;
+ (void)cmd;
+ (void)data;
+ (void)reply;
+
+ return HDF_SUCCESS;
+}
+
+int32_t AlsBindDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
+
+ struct AlsDrvData *drvData = (struct AlsDrvData *)OsalMemCalloc(sizeof(*drvData));
+ if (drvData == NULL) {
+ HDF_LOGE("%s: Malloc als drv data fail!", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ drvData->ioService.Dispatch = DispatchAls;
+ drvData->device = device;
+ device->service = &drvData->ioService;
+ g_alsDrvData = drvData;
+ return HDF_SUCCESS;
+}
+
+static int32_t InitAlsOps(struct SensorCfgData *config, struct SensorDeviceInfo *deviceInfo)
+{
+ CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM);
+
+ deviceInfo->ops.Enable = SetAlsEnable;
+ deviceInfo->ops.Disable = SetAlsDisable;
+ deviceInfo->ops.SetBatch = SetAlsBatch;
+ deviceInfo->ops.SetMode = SetAlsMode;
+ deviceInfo->ops.SetOption = SetAlsOption;
+
+ if (memcpy_s(&deviceInfo->sensorInfo, sizeof(deviceInfo->sensorInfo),
+ &config->sensorInfo, sizeof(config->sensorInfo)) != EOK) {
+ HDF_LOGE("%s: Copy sensor info failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t InitAlsAfterDetected(struct SensorCfgData *config)
+{
+ struct SensorDeviceInfo deviceInfo;
+ CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM);
+
+ if (InitAlsOps(config, &deviceInfo) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Init als ops failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ if (AddSensorDevice(&deviceInfo) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Add als device failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ if (ParseSensorRegConfig(config) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Parse sensor register failed", __func__);
+ goto SENSOR_REG_CONFIG_EXIT;
+ }
+
+ if (ParseExtendedAlsRegConfig(config) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Parse sensor extendedRegCfgGroup register failed", __func__);
+ goto EXTENDED_ALS_REG_CONFIG_EXIT;
+ }
+
+ return HDF_SUCCESS;
+
+EXTENDED_ALS_REG_CONFIG_EXIT:
+ ReleaseSensorAllRegConfig(config);
+SENSOR_REG_CONFIG_EXIT:
+ (void)DeleteSensorDevice(&config->sensorInfo);
+
+ return HDF_FAILURE;
+}
+
+struct SensorCfgData *AlsCreateCfgData(const struct DeviceResourceNode *node)
+{
+ struct AlsDrvData *drvData = AlsGetDrvData();
+
+ if (drvData == NULL || node == NULL) {
+ HDF_LOGE("%s: Als node pointer NULL", __func__);
+ return NULL;
+ }
+
+ if (drvData->detectFlag) {
+ HDF_LOGE("%s: Als sensor have detected", __func__);
+ return NULL;
+ }
+
+ if (drvData->alsCfg == NULL) {
+ HDF_LOGE("%s: Als alsCfg pointer NULL", __func__);
+ return NULL;
+ }
+
+ if (GetSensorBaseConfigData(node, drvData->alsCfg) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Get sensor base config failed", __func__);
+ goto BASE_CONFIG_EXIT;
+ }
+
+ if (DetectSensorDevice(drvData->alsCfg) != HDF_SUCCESS) {
+ HDF_LOGI("%s: Als sensor detect device no exist", __func__);
+ drvData->detectFlag = false;
+ goto BASE_CONFIG_EXIT;
+ }
+
+ drvData->detectFlag = true;
+ if (InitAlsAfterDetected(drvData->alsCfg) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Als sensor detect device no exist", __func__);
+ goto INIT_EXIT;
+ }
+
+ return drvData->alsCfg;
+
+INIT_EXIT:
+ (void)ReleaseSensorBusHandle(&drvData->alsCfg->busCfg);
+BASE_CONFIG_EXIT:
+ drvData->alsCfg->root = NULL;
+ (void)memset_s(&drvData->alsCfg->sensorInfo, sizeof(struct SensorBasicInfo), 0, sizeof(struct SensorBasicInfo));
+ (void)memset_s(&drvData->alsCfg->busCfg, sizeof(struct SensorBusCfg), 0, sizeof(struct SensorBusCfg));
+ (void)memset_s(&drvData->alsCfg->sensorAttr, sizeof(struct SensorAttr), 0, sizeof(struct SensorAttr));
+ return drvData->alsCfg;
+}
+
+void AlsReleaseCfgData(struct SensorCfgData *alsCfg)
+{
+ CHECK_NULL_PTR_RETURN(alsCfg);
+
+ (void)DeleteSensorDevice(&alsCfg->sensorInfo);
+ ReleaseSensorAllRegConfig(alsCfg);
+ ReleaseExtendedAlsRegConfig(alsCfg);
+ (void)ReleaseSensorBusHandle(&alsCfg->busCfg);
+
+ alsCfg->root = NULL;
+ (void)memset_s(&alsCfg->sensorInfo, sizeof(struct SensorBasicInfo), 0, sizeof(struct SensorBasicInfo));
+ (void)memset_s(&alsCfg->busCfg, sizeof(struct SensorBusCfg), 0, sizeof(struct SensorBusCfg));
+ (void)memset_s(&alsCfg->sensorAttr, sizeof(struct SensorAttr), 0, sizeof(struct SensorAttr));
+}
+
+int32_t AlsInitDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
+ struct AlsDrvData *drvData = (struct AlsDrvData *)device->service;
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+
+ if (InitAlsData(drvData) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Init als config failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ drvData->alsCfg = (struct SensorCfgData *)OsalMemCalloc(sizeof(*drvData->alsCfg));
+ if (drvData->alsCfg == NULL) {
+ HDF_LOGE("%s: Malloc als config data failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ drvData->alsCfg->regCfgGroup = &g_regCfgGroup[0];
+ drvData->alsCfg->extendedRegCfgGroup = &g_extendAlsRegCfgGroup[0];
+
+ return HDF_SUCCESS;
+}
+
+void AlsReleaseDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN(device);
+
+ struct AlsDrvData *drvData = (struct AlsDrvData *)device->service;
+ CHECK_NULL_PTR_RETURN(drvData);
+
+ if (drvData->detectFlag && drvData->alsCfg != NULL) {
+ AlsReleaseCfgData(drvData->alsCfg);
+ }
+
+ OsalMemFree(drvData->alsCfg);
+ drvData->alsCfg = NULL;
+
+ HdfWorkDestroy(&drvData->alsWork);
+ HdfWorkQueueDestroy(&drvData->alsWorkQueue);
+ OsalMemFree(drvData);
+}
+
+struct HdfDriverEntry g_sensorAlsDevEntry = {
+ .moduleVersion = 1,
+ .moduleName = "HDF_SENSOR_ALS",
+ .Bind = AlsBindDriver,
+ .Init = AlsInitDriver,
+ .Release = AlsReleaseDriver,
+};
+
+HDF_INIT(g_sensorAlsDevEntry);
diff --git a/model/sensor/driver/als/sensor_als_driver.h b/model/sensor/driver/als/sensor_als_driver.h
new file mode 100755
index 0000000000000000000000000000000000000000..6f02f9f1536814078a2b1ecae2fdf96a40398c87
--- /dev/null
+++ b/model/sensor/driver/als/sensor_als_driver.h
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef SENSOR_ALS_DRIVER_H
+#define SENSOR_ALS_DRIVER_H
+
+#include "hdf_workqueue.h"
+#include "osal_timer.h"
+#include "sensor_config_parser.h"
+#include "sensor_platform_if.h"
+
+#define ALS_DEFAULT_SAMPLING_200_MS 200000000
+#define ALS_CHIP_NAME_BH1745 "bh1745"
+
+enum ExtendedAlsRegGroupType {
+ EXTENDED_ALS_TIME_GROUP = 0,
+ EXTENDED_ALS_GAIN_GROUP,
+ EXTENDED_ALS_GROUP_MAX,
+};
+
+enum AlsLightNum {
+ ALS_R = 0,
+ ALS_G = 1,
+ ALS_B = 2,
+ ALS_C = 3,
+ ALS_LIGHT_NUM = 4,
+};
+
+enum AlsLightPart {
+ ALS_R_LSB = 0,
+ ALS_R_MSB = 1,
+ ALS_G_LSB = 2,
+ ALS_G_MSB = 3,
+ ALS_B_LSB = 4,
+ ALS_B_MSB = 5,
+ ALS_C_LSB = 6,
+ ALS_C_MSB = 7,
+ ALS_LIGHT_BUTT = 8,
+};
+
+struct AlsReportData {
+ int32_t als;
+ int32_t cct;
+ int32_t irData;
+};
+
+struct TimeMap {
+ uint8_t timeRegValue;
+ uint32_t timeValue;
+};
+
+struct GainMap {
+ uint8_t gainRegValue;
+ uint32_t gainValue;
+};
+
+struct AlsData {
+ int32_t red;
+ int32_t green;
+ int32_t blue;
+ int32_t clear;
+};
+
+struct AlsOpsCall {
+ int32_t (*Init)(struct SensorCfgData *data);
+ int32_t (*ReadData)(struct SensorCfgData *data);
+};
+
+struct AlsDrvData {
+ struct IDeviceIoService ioService;
+ struct HdfDeviceObject *device;
+ HdfWorkQueue alsWorkQueue;
+ HdfWork alsWork;
+ OsalTimer alsTimer;
+ bool detectFlag;
+ bool enable;
+ int64_t interval;
+ struct SensorCfgData *alsCfg;
+ struct AlsOpsCall ops;
+};
+
+int32_t AlsRegisterChipOps(const struct AlsOpsCall *ops);
+struct SensorCfgData *AlsCreateCfgData(const struct DeviceResourceNode *node);
+void AlsReleaseCfgData(struct SensorCfgData *sensorCfgData);
+int32_t GetTimeByRegValue(uint8_t regValue, struct TimeMap *table, int32_t itemNum);
+int32_t GetRegValueByTime(uint32_t timeValue, struct TimeMap *table, int32_t itemNum);
+int32_t GetRegGroupIndexByTime(uint32_t timeValue, struct TimeMap *table, int32_t itemNum);
+int32_t GetGainByRegValue(uint8_t regValue, struct GainMap *table, int32_t itemNum);
+#endif /* SENSOR_ALS_DRIVER_H */
diff --git a/model/sensor/driver/barometer/sensor_barometer_driver.c b/model/sensor/driver/barometer/sensor_barometer_driver.c
index 988ea0333181f33bd0d562ce3e9c26bacec41003..79f5d38f610c3c1cb2a52050e2d0286a02813034 100644
--- a/model/sensor/driver/barometer/sensor_barometer_driver.c
+++ b/model/sensor/driver/barometer/sensor_barometer_driver.c
@@ -1,370 +1,370 @@
-/*
- * Copyright (c) 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 "sensor_barometer_driver.h"
-#include
-#include "hdf_base.h"
-#include "hdf_device_desc.h"
-#include "osal_math.h"
-#include "osal_mem.h"
-#include "sensor_config_controller.h"
-#include "sensor_device_manager.h"
-#include "sensor_platform_if.h"
-
-#define HDF_LOG_TAG sensor_barometer_driver_c
-
-#define HDF_BAROMETER_WORK_QUEUE_NAME "hdf_barometer_work_queue"
-
-static struct BarometerDrvData *g_barometerDrvData = NULL;
-
-static struct BarometerDrvData *BarometerGetDrvData(void)
-{
- return g_barometerDrvData;
-}
-
-static struct SensorRegCfgGroupNode *g_regCfgGroup[SENSOR_GROUP_MAX] = { NULL };
-
-int32_t BarometerRegisterChipOps(const struct BarometerOpsCall *ops)
-{
- struct BarometerDrvData *drvData = BarometerGetDrvData();
-
- CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
- CHECK_NULL_PTR_RETURN_VALUE(ops, HDF_ERR_INVALID_PARAM);
-
- drvData->ops.Init = ops->Init;
- drvData->ops.ReadData = ops->ReadData;
- return HDF_SUCCESS;
-}
-
-static void BarometerDataWorkEntry(void *arg)
-{
- struct BarometerDrvData *drvData = NULL;
-
- drvData = (struct BarometerDrvData *)arg;
- CHECK_NULL_PTR_RETURN(drvData);
-
- if (drvData->ops.ReadData == NULL) {
- HDF_LOGI("%s: Barometer ReadData function NULl", __func__);
- return;
- }
- if (drvData->ops.ReadData(drvData->barometerCfg) != HDF_SUCCESS) {
- HDF_LOGE("%s: Barometer read data failed", __func__);
- }
-}
-
-static void BarometerTimerEntry(uintptr_t arg)
-{
- int64_t interval;
- int32_t ret;
- struct BarometerDrvData *drvData = (struct BarometerDrvData *)arg;
- CHECK_NULL_PTR_RETURN(drvData);
-
- if (!HdfAddWork(&drvData->barometerWorkQueue, &drvData->barometerWork)) {
- HDF_LOGE("%s: barometer add work queue failed", __func__);
- }
-
- interval = OsalDivS64(drvData->interval, (SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT));
- interval = (interval < SENSOR_TIMER_MIN_TIME) ? SENSOR_TIMER_MIN_TIME : interval;
- ret = OsalTimerSetTimeout(&drvData->barometerTimer, interval);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: barometer modify time failed", __func__);
- }
-}
-
-static int32_t InitBarometerData(struct BarometerDrvData *drvData)
-{
- if (HdfWorkQueueInit(&drvData->barometerWorkQueue, HDF_BAROMETER_WORK_QUEUE_NAME) != HDF_SUCCESS) {
- HDF_LOGE("%s: barometer init work queue failed", __func__);
- return HDF_FAILURE;
- }
-
- if (HdfWorkInit(&drvData->barometerWork, BarometerDataWorkEntry, drvData) != HDF_SUCCESS) {
- HDF_LOGE("%s: barometer create thread failed", __func__);
- return HDF_FAILURE;
- }
-
- drvData->interval = SENSOR_TIMER_MIN_TIME;
- drvData->enable = false;
- drvData->detectFlag = false;
-
- return HDF_SUCCESS;
-}
-
-static int32_t SetBarometerEnable(void)
-{
- int32_t ret;
- struct BarometerDrvData *drvData = BarometerGetDrvData();
-
- CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
- CHECK_NULL_PTR_RETURN_VALUE(drvData->barometerCfg, HDF_ERR_INVALID_PARAM);
-
- if (drvData->enable) {
- HDF_LOGE("%s: barometer sensor is enabled", __func__);
- return HDF_SUCCESS;
- }
-
- ret = SetSensorRegCfgArray(&drvData->barometerCfg->busCfg, drvData->barometerCfg->regCfgGroup[SENSOR_ENABLE_GROUP]);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: barometer sensor enable config failed", __func__);
- return ret;
- }
-
- ret = OsalTimerCreate(&drvData->barometerTimer, SENSOR_TIMER_MIN_TIME, BarometerTimerEntry, (uintptr_t)drvData);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: barometer create timer failed[%d]", __func__, ret);
- return ret;
- }
-
- ret = OsalTimerStartLoop(&drvData->barometerTimer);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: barometer start timer failed[%d]", __func__, ret);
- return ret;
- }
- drvData->enable = true;
-
- return HDF_SUCCESS;
-}
-
-static int32_t SetBarometerDisable(void)
-{
- int32_t ret;
- struct BarometerDrvData *drvData = BarometerGetDrvData();
-
- CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
- CHECK_NULL_PTR_RETURN_VALUE(drvData->barometerCfg, HDF_ERR_INVALID_PARAM);
-
- if (!drvData->enable) {
- HDF_LOGE("%s: barometer sensor had disable", __func__);
- return HDF_SUCCESS;
- }
-
- ret = SetSensorRegCfgArray(&drvData->barometerCfg->busCfg,
- drvData->barometerCfg->regCfgGroup[SENSOR_DISABLE_GROUP]);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: barometer sensor disable config failed", __func__);
- return ret;
- }
-
- ret = OsalTimerDelete(&drvData->barometerTimer);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: barometer delete timer failed", __func__);
- return ret;
- }
- drvData->enable = false;
- return HDF_SUCCESS;
-}
-
-static int32_t SetBarometerBatch(int64_t samplingInterval, int64_t interval)
-{
- (void)interval;
-
- struct BarometerDrvData *drvData = NULL;
-
- drvData = BarometerGetDrvData();
- CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
-
- drvData->interval = samplingInterval;
-
- return HDF_SUCCESS;
-}
-
-static int32_t SetBarometerMode(int32_t mode)
-{
- return (mode == SENSOR_WORK_MODE_REALTIME) ? HDF_SUCCESS : HDF_FAILURE;
-}
-
-static int32_t SetBarometerOption(uint32_t option)
-{
- (void)option;
- return HDF_SUCCESS;
-}
-
-static int32_t DispatchBarometer(struct HdfDeviceIoClient *client,
- int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
-{
- (void)client;
- (void)cmd;
- (void)data;
- (void)reply;
-
- return HDF_SUCCESS;
-}
-
-int32_t BarometerBindDriver(struct HdfDeviceObject *device)
-{
- CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
-
- struct BarometerDrvData *drvData = (struct BarometerDrvData *)OsalMemCalloc(sizeof(*drvData));
- if (drvData == NULL) {
- HDF_LOGE("%s: malloc barometer drv data fail!", __func__);
- return HDF_ERR_MALLOC_FAIL;
- }
-
- drvData->ioService.Dispatch = DispatchBarometer;
- drvData->device = device;
- device->service = &drvData->ioService;
- g_barometerDrvData = drvData;
- return HDF_SUCCESS;
-}
-
-static int32_t InitBarometerOps(struct SensorCfgData *config, struct SensorDeviceInfo *deviceInfo)
-{
- CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM);
-
- deviceInfo->ops.Enable = SetBarometerEnable;
- deviceInfo->ops.Disable = SetBarometerDisable;
- deviceInfo->ops.SetBatch = SetBarometerBatch;
- deviceInfo->ops.SetMode = SetBarometerMode;
- deviceInfo->ops.SetOption = SetBarometerOption;
-
- if (memcpy_s(&deviceInfo->sensorInfo, sizeof(deviceInfo->sensorInfo),
- &config->sensorInfo, sizeof(config->sensorInfo)) != EOK) {
- HDF_LOGE("%s: copy sensor info failed", __func__);
- return HDF_FAILURE;
- }
-
- return HDF_SUCCESS;
-}
-
-static int32_t InitBarometerAfterDetected(struct SensorCfgData *config)
-{
- struct SensorDeviceInfo deviceInfo;
- CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM);
-
- if (InitBarometerOps(config, &deviceInfo) != HDF_SUCCESS) {
- HDF_LOGE("%s: Init barometer ops failed", __func__);
- return HDF_FAILURE;
- }
-
- if (AddSensorDevice(&deviceInfo) != HDF_SUCCESS) {
- HDF_LOGE("%s: Add barometer device failed", __func__);
- return HDF_FAILURE;
- }
-
- if (ParseSensorRegConfig(config) != HDF_SUCCESS) {
- HDF_LOGE("%s: Parse sensor register failed", __func__);
- (void)DeleteSensorDevice(&config->sensorInfo);
- ReleaseSensorAllRegConfig(config);
- return HDF_FAILURE;
- }
- return HDF_SUCCESS;
-}
-
-struct SensorCfgData *BarometerCreateCfgData(const struct DeviceResourceNode *node)
-{
- struct BarometerDrvData *drvData = BarometerGetDrvData();
-
- if (drvData == NULL || node == NULL) {
- HDF_LOGE("%s: Barometer node pointer NULL", __func__);
- return NULL;
- }
-
- if (drvData->detectFlag) {
- HDF_LOGE("%s: Barometer sensor have detected", __func__);
- return NULL;
- }
-
- if (drvData->barometerCfg == NULL) {
- HDF_LOGE("%s: Barometer barometerCfg pointer NULL", __func__);
- return NULL;
- }
-
- if (GetSensorBaseConfigData(node, drvData->barometerCfg) != HDF_SUCCESS) {
- HDF_LOGE("%s: Get sensor base config failed", __func__);
- goto BASE_CONFIG_EXIT;
- }
-
- if (DetectSensorDevice(drvData->barometerCfg) != HDF_SUCCESS) {
- HDF_LOGI("%s: Barometer sensor detect device no exist", __func__);
- drvData->detectFlag = false;
- goto BASE_CONFIG_EXIT;
- }
-
- drvData->detectFlag = true;
- if (InitBarometerAfterDetected(drvData->barometerCfg) != HDF_SUCCESS) {
- HDF_LOGE("%s: Barometer sensor detect device no exist", __func__);
- goto INIT_EXIT;
- }
- return drvData->barometerCfg;
-
-INIT_EXIT:
- (void)ReleaseSensorBusHandle(&drvData->barometerCfg->busCfg);
-BASE_CONFIG_EXIT:
- drvData->barometerCfg->root = NULL;
- (void)memset_s(&drvData->barometerCfg->sensorInfo, sizeof(struct SensorBasicInfo), 0,
- sizeof(struct SensorBasicInfo));
- (void)memset_s(&drvData->barometerCfg->busCfg, sizeof(struct SensorBusCfg), 0, sizeof(struct SensorBusCfg));
- (void)memset_s(&drvData->barometerCfg->sensorAttr, sizeof(struct SensorAttr), 0, sizeof(struct SensorAttr));
- return NULL;
-}
-
-void BarometerReleaseCfgData(struct SensorCfgData *barometerCfg)
-{
- CHECK_NULL_PTR_RETURN(barometerCfg);
-
- (void)DeleteSensorDevice(&barometerCfg->sensorInfo);
- ReleaseSensorAllRegConfig(barometerCfg);
- (void)ReleaseSensorBusHandle(&barometerCfg->busCfg);
-
- barometerCfg->root = NULL;
- (void)memset_s(&barometerCfg->sensorInfo, sizeof(struct SensorBasicInfo), 0, sizeof(struct SensorBasicInfo));
- (void)memset_s(&barometerCfg->busCfg, sizeof(struct SensorBusCfg), 0, sizeof(struct SensorBusCfg));
- (void)memset_s(&barometerCfg->sensorAttr, sizeof(struct SensorAttr), 0, sizeof(struct SensorAttr));
-}
-
-int32_t BarometerInitDriver(struct HdfDeviceObject *device)
-{
- CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
- struct BarometerDrvData *drvData = (struct BarometerDrvData *)device->service;
- CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
-
- if (InitBarometerData(drvData) != HDF_SUCCESS) {
- HDF_LOGE("%s: Init barometer config failed", __func__);
- return HDF_FAILURE;
- }
-
- drvData->barometerCfg = (struct SensorCfgData *)OsalMemCalloc(sizeof(*drvData->barometerCfg));
- if (drvData->barometerCfg == NULL) {
- HDF_LOGE("%s: Malloc barometer config data failed", __func__);
- return HDF_FAILURE;
- }
-
- drvData->barometerCfg->regCfgGroup = &g_regCfgGroup[0];
-
- HDF_LOGI("%s: Init barometer driver success", __func__);
- return HDF_SUCCESS;
-}
-
-void BarometerReleaseDriver(struct HdfDeviceObject *device)
-{
- CHECK_NULL_PTR_RETURN(device);
-
- struct BarometerDrvData *drvData = (struct BarometerDrvData *)device->service;
- CHECK_NULL_PTR_RETURN(drvData);
-
- if (drvData->detectFlag) {
- BarometerReleaseCfgData(drvData->barometerCfg);
- }
-
- OsalMemFree(drvData->barometerCfg);
- drvData->barometerCfg = NULL;
-
- HdfWorkDestroy(&drvData->barometerWork);
- HdfWorkQueueDestroy(&drvData->barometerWorkQueue);
- OsalMemFree(drvData);
-}
-
-struct HdfDriverEntry g_sensorBarometerDevEntry = {
- .moduleVersion = 1,
- .moduleName = "HDF_SENSOR_BAROMETER",
- .Bind = BarometerBindDriver,
- .Init = BarometerInitDriver,
- .Release = BarometerReleaseDriver,
-};
-
+/*
+ * Copyright (c) 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 "sensor_barometer_driver.h"
+#include
+#include "hdf_base.h"
+#include "hdf_device_desc.h"
+#include "osal_math.h"
+#include "osal_mem.h"
+#include "sensor_config_controller.h"
+#include "sensor_device_manager.h"
+#include "sensor_platform_if.h"
+
+#define HDF_LOG_TAG sensor_barometer_driver_c
+
+#define HDF_BAROMETER_WORK_QUEUE_NAME "hdf_barometer_work_queue"
+
+static struct BarometerDrvData *g_barometerDrvData = NULL;
+
+static struct BarometerDrvData *BarometerGetDrvData(void)
+{
+ return g_barometerDrvData;
+}
+
+static struct SensorRegCfgGroupNode *g_regCfgGroup[SENSOR_GROUP_MAX] = { NULL };
+
+int32_t BarometerRegisterChipOps(const struct BarometerOpsCall *ops)
+{
+ struct BarometerDrvData *drvData = BarometerGetDrvData();
+
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+ CHECK_NULL_PTR_RETURN_VALUE(ops, HDF_ERR_INVALID_PARAM);
+
+ drvData->ops.Init = ops->Init;
+ drvData->ops.ReadData = ops->ReadData;
+ return HDF_SUCCESS;
+}
+
+static void BarometerDataWorkEntry(void *arg)
+{
+ struct BarometerDrvData *drvData = NULL;
+
+ drvData = (struct BarometerDrvData *)arg;
+ CHECK_NULL_PTR_RETURN(drvData);
+
+ if (drvData->ops.ReadData == NULL) {
+ HDF_LOGI("%s: Barometer ReadData function NULl", __func__);
+ return;
+ }
+ if (drvData->ops.ReadData(drvData->barometerCfg) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Barometer read data failed", __func__);
+ }
+}
+
+static void BarometerTimerEntry(uintptr_t arg)
+{
+ int64_t interval;
+ int32_t ret;
+ struct BarometerDrvData *drvData = (struct BarometerDrvData *)arg;
+ CHECK_NULL_PTR_RETURN(drvData);
+
+ if (!HdfAddWork(&drvData->barometerWorkQueue, &drvData->barometerWork)) {
+ HDF_LOGE("%s: barometer add work queue failed", __func__);
+ }
+
+ interval = OsalDivS64(drvData->interval, (SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT));
+ interval = (interval < SENSOR_TIMER_MIN_TIME) ? SENSOR_TIMER_MIN_TIME : interval;
+ ret = OsalTimerSetTimeout(&drvData->barometerTimer, interval);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: barometer modify time failed", __func__);
+ }
+}
+
+static int32_t InitBarometerData(struct BarometerDrvData *drvData)
+{
+ if (HdfWorkQueueInit(&drvData->barometerWorkQueue, HDF_BAROMETER_WORK_QUEUE_NAME) != HDF_SUCCESS) {
+ HDF_LOGE("%s: barometer init work queue failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ if (HdfWorkInit(&drvData->barometerWork, BarometerDataWorkEntry, drvData) != HDF_SUCCESS) {
+ HDF_LOGE("%s: barometer create thread failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ drvData->interval = SENSOR_TIMER_MIN_TIME;
+ drvData->enable = false;
+ drvData->detectFlag = false;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SetBarometerEnable(void)
+{
+ int32_t ret;
+ struct BarometerDrvData *drvData = BarometerGetDrvData();
+
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+ CHECK_NULL_PTR_RETURN_VALUE(drvData->barometerCfg, HDF_ERR_INVALID_PARAM);
+
+ if (drvData->enable) {
+ HDF_LOGE("%s: barometer sensor is enabled", __func__);
+ return HDF_SUCCESS;
+ }
+
+ ret = SetSensorRegCfgArray(&drvData->barometerCfg->busCfg, drvData->barometerCfg->regCfgGroup[SENSOR_ENABLE_GROUP]);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: barometer sensor enable config failed", __func__);
+ return ret;
+ }
+
+ ret = OsalTimerCreate(&drvData->barometerTimer, SENSOR_TIMER_MIN_TIME, BarometerTimerEntry, (uintptr_t)drvData);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: barometer create timer failed[%d]", __func__, ret);
+ return ret;
+ }
+
+ ret = OsalTimerStartLoop(&drvData->barometerTimer);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: barometer start timer failed[%d]", __func__, ret);
+ return ret;
+ }
+ drvData->enable = true;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SetBarometerDisable(void)
+{
+ int32_t ret;
+ struct BarometerDrvData *drvData = BarometerGetDrvData();
+
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+ CHECK_NULL_PTR_RETURN_VALUE(drvData->barometerCfg, HDF_ERR_INVALID_PARAM);
+
+ if (!drvData->enable) {
+ HDF_LOGE("%s: barometer sensor had disable", __func__);
+ return HDF_SUCCESS;
+ }
+
+ ret = SetSensorRegCfgArray(&drvData->barometerCfg->busCfg,
+ drvData->barometerCfg->regCfgGroup[SENSOR_DISABLE_GROUP]);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: barometer sensor disable config failed", __func__);
+ return ret;
+ }
+
+ ret = OsalTimerDelete(&drvData->barometerTimer);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: barometer delete timer failed", __func__);
+ return ret;
+ }
+ drvData->enable = false;
+ return HDF_SUCCESS;
+}
+
+static int32_t SetBarometerBatch(int64_t samplingInterval, int64_t interval)
+{
+ (void)interval;
+
+ struct BarometerDrvData *drvData = NULL;
+
+ drvData = BarometerGetDrvData();
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+
+ drvData->interval = samplingInterval;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SetBarometerMode(int32_t mode)
+{
+ return (mode == SENSOR_WORK_MODE_REALTIME) ? HDF_SUCCESS : HDF_FAILURE;
+}
+
+static int32_t SetBarometerOption(uint32_t option)
+{
+ (void)option;
+ return HDF_SUCCESS;
+}
+
+static int32_t DispatchBarometer(struct HdfDeviceIoClient *client,
+ int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ (void)client;
+ (void)cmd;
+ (void)data;
+ (void)reply;
+
+ return HDF_SUCCESS;
+}
+
+int32_t BarometerBindDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
+
+ struct BarometerDrvData *drvData = (struct BarometerDrvData *)OsalMemCalloc(sizeof(*drvData));
+ if (drvData == NULL) {
+ HDF_LOGE("%s: malloc barometer drv data fail!", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ drvData->ioService.Dispatch = DispatchBarometer;
+ drvData->device = device;
+ device->service = &drvData->ioService;
+ g_barometerDrvData = drvData;
+ return HDF_SUCCESS;
+}
+
+static int32_t InitBarometerOps(struct SensorCfgData *config, struct SensorDeviceInfo *deviceInfo)
+{
+ CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM);
+
+ deviceInfo->ops.Enable = SetBarometerEnable;
+ deviceInfo->ops.Disable = SetBarometerDisable;
+ deviceInfo->ops.SetBatch = SetBarometerBatch;
+ deviceInfo->ops.SetMode = SetBarometerMode;
+ deviceInfo->ops.SetOption = SetBarometerOption;
+
+ if (memcpy_s(&deviceInfo->sensorInfo, sizeof(deviceInfo->sensorInfo),
+ &config->sensorInfo, sizeof(config->sensorInfo)) != EOK) {
+ HDF_LOGE("%s: copy sensor info failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t InitBarometerAfterDetected(struct SensorCfgData *config)
+{
+ struct SensorDeviceInfo deviceInfo;
+ CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM);
+
+ if (InitBarometerOps(config, &deviceInfo) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Init barometer ops failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ if (AddSensorDevice(&deviceInfo) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Add barometer device failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ if (ParseSensorRegConfig(config) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Parse sensor register failed", __func__);
+ (void)DeleteSensorDevice(&config->sensorInfo);
+ ReleaseSensorAllRegConfig(config);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+struct SensorCfgData *BarometerCreateCfgData(const struct DeviceResourceNode *node)
+{
+ struct BarometerDrvData *drvData = BarometerGetDrvData();
+
+ if (drvData == NULL || node == NULL) {
+ HDF_LOGE("%s: Barometer node pointer NULL", __func__);
+ return NULL;
+ }
+
+ if (drvData->detectFlag) {
+ HDF_LOGE("%s: Barometer sensor have detected", __func__);
+ return NULL;
+ }
+
+ if (drvData->barometerCfg == NULL) {
+ HDF_LOGE("%s: Barometer barometerCfg pointer NULL", __func__);
+ return NULL;
+ }
+
+ if (GetSensorBaseConfigData(node, drvData->barometerCfg) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Get sensor base config failed", __func__);
+ goto BASE_CONFIG_EXIT;
+ }
+
+ if (DetectSensorDevice(drvData->barometerCfg) != HDF_SUCCESS) {
+ HDF_LOGI("%s: Barometer sensor detect device no exist", __func__);
+ drvData->detectFlag = false;
+ goto BASE_CONFIG_EXIT;
+ }
+
+ drvData->detectFlag = true;
+ if (InitBarometerAfterDetected(drvData->barometerCfg) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Barometer sensor detect device no exist", __func__);
+ goto INIT_EXIT;
+ }
+ return drvData->barometerCfg;
+
+INIT_EXIT:
+ (void)ReleaseSensorBusHandle(&drvData->barometerCfg->busCfg);
+BASE_CONFIG_EXIT:
+ drvData->barometerCfg->root = NULL;
+ (void)memset_s(&drvData->barometerCfg->sensorInfo, sizeof(struct SensorBasicInfo), 0,
+ sizeof(struct SensorBasicInfo));
+ (void)memset_s(&drvData->barometerCfg->busCfg, sizeof(struct SensorBusCfg), 0, sizeof(struct SensorBusCfg));
+ (void)memset_s(&drvData->barometerCfg->sensorAttr, sizeof(struct SensorAttr), 0, sizeof(struct SensorAttr));
+ return drvData->barometerCfg;
+}
+
+void BarometerReleaseCfgData(struct SensorCfgData *barometerCfg)
+{
+ CHECK_NULL_PTR_RETURN(barometerCfg);
+
+ (void)DeleteSensorDevice(&barometerCfg->sensorInfo);
+ ReleaseSensorAllRegConfig(barometerCfg);
+ (void)ReleaseSensorBusHandle(&barometerCfg->busCfg);
+
+ barometerCfg->root = NULL;
+ (void)memset_s(&barometerCfg->sensorInfo, sizeof(struct SensorBasicInfo), 0, sizeof(struct SensorBasicInfo));
+ (void)memset_s(&barometerCfg->busCfg, sizeof(struct SensorBusCfg), 0, sizeof(struct SensorBusCfg));
+ (void)memset_s(&barometerCfg->sensorAttr, sizeof(struct SensorAttr), 0, sizeof(struct SensorAttr));
+}
+
+int32_t BarometerInitDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
+ struct BarometerDrvData *drvData = (struct BarometerDrvData *)device->service;
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+
+ if (InitBarometerData(drvData) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Init barometer config failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ drvData->barometerCfg = (struct SensorCfgData *)OsalMemCalloc(sizeof(*drvData->barometerCfg));
+ if (drvData->barometerCfg == NULL) {
+ HDF_LOGE("%s: Malloc barometer config data failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ drvData->barometerCfg->regCfgGroup = &g_regCfgGroup[0];
+
+ HDF_LOGI("%s: Init barometer driver success", __func__);
+ return HDF_SUCCESS;
+}
+
+void BarometerReleaseDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN(device);
+
+ struct BarometerDrvData *drvData = (struct BarometerDrvData *)device->service;
+ CHECK_NULL_PTR_RETURN(drvData);
+
+ if (drvData->detectFlag && drvData->barometerCfg != NULL) {
+ BarometerReleaseCfgData(drvData->barometerCfg);
+ }
+
+ OsalMemFree(drvData->barometerCfg);
+ drvData->barometerCfg = NULL;
+
+ HdfWorkDestroy(&drvData->barometerWork);
+ HdfWorkQueueDestroy(&drvData->barometerWorkQueue);
+ OsalMemFree(drvData);
+}
+
+struct HdfDriverEntry g_sensorBarometerDevEntry = {
+ .moduleVersion = 1,
+ .moduleName = "HDF_SENSOR_BAROMETER",
+ .Bind = BarometerBindDriver,
+ .Init = BarometerInitDriver,
+ .Release = BarometerReleaseDriver,
+};
+
HDF_INIT(g_sensorBarometerDevEntry);
\ No newline at end of file
diff --git a/model/sensor/driver/barometer/sensor_barometer_driver.h b/model/sensor/driver/barometer/sensor_barometer_driver.h
index 0888955f087f48496def8d655dbb27eea56fc331..03ba8234d33b63241cf1a033be30846807a715b3 100644
--- a/model/sensor/driver/barometer/sensor_barometer_driver.h
+++ b/model/sensor/driver/barometer/sensor_barometer_driver.h
@@ -1,120 +1,119 @@
-/*
- * Copyright (c) 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.
- */
-
-#ifndef SENSOR_BAROMETER_DRIVER_H
-#define SENSOR_BAROMETER_DRIVER_H
-
-#include "hdf_workqueue.h"
-#include "osal_mutex.h"
-#include "osal_timer.h"
-#include "sensor_config_parser.h"
-#include "sensor_platform_if.h"
-
-#define BAR_DEFAULT_SAMPLING_200_MS 200000000
-#define BAROMETER_CHIP_NAME_BMP180 "bmp180"
-
-enum BarometerEeprom {
- BAROMETER_AC1_MSB = 0,
- BAROMETER_AC1_LSB = 1,
- BAROMETER_AC2_MSB = 2,
- BAROMETER_AC2_LSB = 3,
- BAROMETER_AC3_MSB = 4,
- BAROMETER_AC3_LSB = 5,
- BAROMETER_AC4_MSB = 6,
- BAROMETER_AC4_LSB = 7,
- BAROMETER_AC5_MSB = 8,
- BAROMETER_AC5_LSB = 9,
- BAROMETER_AC6_MSB = 10,
- BAROMETER_AC6_LSB = 11,
- BAROMETER_B1_MSB = 12,
- BAROMETER_B1_LSB = 13,
- BAROMETER_B2_MSB = 14,
- BAROMETER_B2_LSB = 15,
- BAROMETER_MB_MSB = 16,
- BAROMETER_MB_LSB = 17,
- BAROMETER_MC_MSB = 18,
- BAROMETER_MC_LSB = 19,
- BAROMETER_MD_MSB = 20,
- BAROMETER_MD_LSB = 21,
- BAROMETER_EEPROM_SUM,
-};
-
-struct BarometerEepromData {
- int32_t ac1;
- int32_t ac2;
- int32_t ac3;
- int32_t b1;
- int32_t b2;
- int32_t mb;
- int32_t mc;
- int32_t md;
- uint32_t ac4;
- uint32_t ac5;
- uint32_t ac6;
-};
-
-struct Coefficient {
- int32_t b3;
- int32_t b5;
- int32_t b6;
- int32_t x1;
- int32_t x2;
- int32_t x3;
- int32_t p;
- uint32_t b4;
- uint32_t b7;
-};
-
-enum Temperature {
- BAROMETER_TEM_MSB = 0,
- BAROMETER_TEM_LSB = 1,
- BAROMETER_TEM_SUM,
-};
-
-enum Barometer {
- BAROMETER_BAR_MSB = 0,
- BAROMETER_BAR_LSB = 1,
- BAROMETER_BAR_XLSB = 2,
- BAROMETER_BAR_SUM,
-};
-
-struct BarometerRawData {
- int32_t unpensatePre;
- int32_t unpensateTemp;
-};
-
-enum BarometerData {
- BAROMETER_BAROMETER = 0,
- BAROMETER_TEMPERATURE = 1,
- BAROMETER_ALTITUDE = 2,
- BAROMETER_SUM,
-};
-
-struct BarometerOpsCall {
- int32_t (*Init)(struct SensorCfgData *data);
- int32_t (*ReadData)(struct SensorCfgData *data);
-};
-
-struct BarometerDrvData {
- struct IDeviceIoService ioService;
- struct HdfDeviceObject *device;
- HdfWorkQueue barometerWorkQueue;
- HdfWork barometerWork;
- OsalTimer barometerTimer;
- bool detectFlag;
- bool enable;
- int64_t interval;
- struct SensorCfgData *barometerCfg;
- struct BarometerOpsCall ops;
-};
-
-int32_t BarometerRegisterChipOps(const struct BarometerOpsCall *ops);
-struct SensorCfgData *BarometerCreateCfgData(const struct DeviceResourceNode *node);
-void BarometerReleaseCfgData(struct SensorCfgData *sensorCfgData);
-
-#endif /* SENSOR_BAROMETER_DRIVER_H */
\ No newline at end of file
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef SENSOR_BAROMETER_DRIVER_H
+#define SENSOR_BAROMETER_DRIVER_H
+
+#include "hdf_workqueue.h"
+#include "osal_timer.h"
+#include "sensor_config_parser.h"
+#include "sensor_platform_if.h"
+
+#define BAR_DEFAULT_SAMPLING_200_MS 200000000
+#define BAROMETER_CHIP_NAME_BMP180 "bmp180"
+
+enum BarometerEeprom {
+ BAROMETER_AC1_MSB = 0,
+ BAROMETER_AC1_LSB = 1,
+ BAROMETER_AC2_MSB = 2,
+ BAROMETER_AC2_LSB = 3,
+ BAROMETER_AC3_MSB = 4,
+ BAROMETER_AC3_LSB = 5,
+ BAROMETER_AC4_MSB = 6,
+ BAROMETER_AC4_LSB = 7,
+ BAROMETER_AC5_MSB = 8,
+ BAROMETER_AC5_LSB = 9,
+ BAROMETER_AC6_MSB = 10,
+ BAROMETER_AC6_LSB = 11,
+ BAROMETER_B1_MSB = 12,
+ BAROMETER_B1_LSB = 13,
+ BAROMETER_B2_MSB = 14,
+ BAROMETER_B2_LSB = 15,
+ BAROMETER_MB_MSB = 16,
+ BAROMETER_MB_LSB = 17,
+ BAROMETER_MC_MSB = 18,
+ BAROMETER_MC_LSB = 19,
+ BAROMETER_MD_MSB = 20,
+ BAROMETER_MD_LSB = 21,
+ BAROMETER_EEPROM_SUM,
+};
+
+struct BarometerEepromData {
+ int32_t ac1;
+ int32_t ac2;
+ int32_t ac3;
+ int32_t b1;
+ int32_t b2;
+ int32_t mb;
+ int32_t mc;
+ int32_t md;
+ uint32_t ac4;
+ uint32_t ac5;
+ uint32_t ac6;
+};
+
+struct Coefficient {
+ int32_t b3;
+ int32_t b5;
+ int32_t b6;
+ int32_t x1;
+ int32_t x2;
+ int32_t x3;
+ int32_t p;
+ uint32_t b4;
+ uint32_t b7;
+};
+
+enum Temperature {
+ BAROMETER_TEM_MSB = 0,
+ BAROMETER_TEM_LSB = 1,
+ BAROMETER_TEM_SUM,
+};
+
+enum Barometer {
+ BAROMETER_BAR_MSB = 0,
+ BAROMETER_BAR_LSB = 1,
+ BAROMETER_BAR_XLSB = 2,
+ BAROMETER_BAR_SUM,
+};
+
+struct BarometerRawData {
+ int32_t unpensatePre;
+ int32_t unpensateTemp;
+};
+
+enum BarometerData {
+ BAROMETER_BAROMETER = 0,
+ BAROMETER_TEMPERATURE = 1,
+ BAROMETER_ALTITUDE = 2,
+ BAROMETER_SUM,
+};
+
+struct BarometerOpsCall {
+ int32_t (*Init)(struct SensorCfgData *data);
+ int32_t (*ReadData)(struct SensorCfgData *data);
+};
+
+struct BarometerDrvData {
+ struct IDeviceIoService ioService;
+ struct HdfDeviceObject *device;
+ HdfWorkQueue barometerWorkQueue;
+ HdfWork barometerWork;
+ OsalTimer barometerTimer;
+ bool detectFlag;
+ bool enable;
+ int64_t interval;
+ struct SensorCfgData *barometerCfg;
+ struct BarometerOpsCall ops;
+};
+
+int32_t BarometerRegisterChipOps(const struct BarometerOpsCall *ops);
+struct SensorCfgData *BarometerCreateCfgData(const struct DeviceResourceNode *node);
+void BarometerReleaseCfgData(struct SensorCfgData *sensorCfgData);
+
+#endif /* SENSOR_BAROMETER_DRIVER_H */
diff --git a/model/sensor/driver/chipset/accel/accel_bmi160.c b/model/sensor/driver/chipset/accel/accel_bmi160.c
old mode 100644
new mode 100755
index b39d7bc4c13c3a981e52d25a6fc3fd90abd6972f..33f791e3cfb44c3f965aa129d17dd02cc5c92f27
--- a/model/sensor/driver/chipset/accel/accel_bmi160.c
+++ b/model/sensor/driver/chipset/accel/accel_bmi160.c
@@ -79,24 +79,24 @@ static int32_t ReadBmi160RawData(struct SensorCfgData *data, struct AccelData *r
return HDF_SUCCESS;
}
-int32_t ReadBmi160Data(struct SensorCfgData *data)
+int32_t ReadBmi160Data(struct SensorCfgData *cfg, struct SensorReportEvent *event)
{
int32_t ret;
struct AccelData rawData = { 0, 0, 0 };
- int32_t tmp[ACCEL_AXIS_NUM];
- struct SensorReportEvent event;
+ static int32_t tmp[ACCEL_AXIS_NUM];
- (void)memset_s(&event, sizeof(event), 0, sizeof(event));
+ CHECK_NULL_PTR_RETURN_VALUE(cfg, HDF_ERR_INVALID_PARAM);
+ CHECK_NULL_PTR_RETURN_VALUE(event, HDF_ERR_INVALID_PARAM);
- ret = ReadBmi160RawData(data, &rawData, &event.timestamp);
+ ret = ReadBmi160RawData(cfg, &rawData, &event->timestamp);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: BMI160 read raw data failed", __func__);
return HDF_FAILURE;
}
- event.sensorId = SENSOR_TAG_ACCELEROMETER;
- event.option = 0;
- event.mode = SENSOR_WORK_MODE_REALTIME;
+ event->sensorId = SENSOR_TAG_ACCELEROMETER;
+ event->option = 0;
+ event->mode = SENSOR_WORK_MODE_REALTIME;
rawData.x = rawData.x * BMI160_ACC_SENSITIVITY_2G;
rawData.y = rawData.y * BMI160_ACC_SENSITIVITY_2G;
@@ -106,12 +106,15 @@ int32_t ReadBmi160Data(struct SensorCfgData *data)
tmp[ACCEL_Y_AXIS] = (rawData.y * SENSOR_1K_UNIT) / SENSOR_CONVERT_UNIT;
tmp[ACCEL_Z_AXIS] = (rawData.z * SENSOR_1K_UNIT) / SENSOR_CONVERT_UNIT;
- event.dataLen = sizeof(tmp);
- event.data = (uint8_t *)&tmp;
- ret = ReportSensorEvent(&event);
+ ret = SensorRawDataToRemapData(cfg->direction, tmp, sizeof(tmp) / sizeof(tmp[0]));
if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: BMI160 report data failed", __func__);
+ HDF_LOGE("%s: BMI160 convert raw data failed", __func__);
+ return HDF_FAILURE;
}
+
+ event->dataLen = sizeof(tmp);
+ event->data = (uint8_t *)&tmp;
+
return ret;
}
@@ -187,7 +190,8 @@ int32_t Bmi160InitDriver(struct HdfDeviceObject *device)
}
drvData->sensorCfg = AccelCreateCfgData(device->property);
- if (drvData->sensorCfg == NULL) {
+ if (drvData->sensorCfg == NULL || drvData->sensorCfg->root == NULL) {
+ HDF_LOGD("%s: Creating accelcfg failed because detection failed", __func__);
return HDF_ERR_NOT_SUPPORT;
}
@@ -215,8 +219,10 @@ void Bmi160ReleaseDriver(struct HdfDeviceObject *device)
struct Bmi160DrvData *drvData = (struct Bmi160DrvData *)device->service;
CHECK_NULL_PTR_RETURN(drvData);
- AccelReleaseCfgData(drvData->sensorCfg);
- drvData->sensorCfg = NULL;
+ if (drvData->sensorCfg != NULL) {
+ AccelReleaseCfgData(drvData->sensorCfg);
+ drvData->sensorCfg = NULL;
+ }
OsalMemFree(drvData);
}
diff --git a/model/sensor/driver/chipset/accel/accel_bmi160.h b/model/sensor/driver/chipset/accel/accel_bmi160.h
old mode 100644
new mode 100755
index 1f1fb4de934c6609a58bc33abe768609bf6eef27..49ad6b05d15abc0ff6cc0a94764d2eac4e209ccf
--- a/model/sensor/driver/chipset/accel/accel_bmi160.h
+++ b/model/sensor/driver/chipset/accel/accel_bmi160.h
@@ -59,8 +59,7 @@
#define BMI160_ACCEL_DATA_READY_MASK 0x80
int32_t DetectAccelBim160Chip(struct SensorCfgData *data);
-int32_t ReadBmi160Data(struct SensorCfgData *data);
-
+int32_t ReadBmi160Data(struct SensorCfgData *cfg, struct SensorReportEvent *event);
struct Bmi160DrvData {
struct IDeviceIoService ioService;
struct HdfDeviceObject *device;
diff --git a/model/sensor/driver/chipset/als/als_bh1745.c b/model/sensor/driver/chipset/als/als_bh1745.c
new file mode 100755
index 0000000000000000000000000000000000000000..4555a71b95918d9cfc00423c545b7d46a09a8410
--- /dev/null
+++ b/model/sensor/driver/chipset/als/als_bh1745.c
@@ -0,0 +1,376 @@
+/*
+ * Copyright (c) 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 "als_bh1745.h"
+#include
+#include "osal_mem.h"
+#include "osal_time.h"
+#include "sensor_als_driver.h"
+#include "sensor_config_controller.h"
+#include "sensor_device_manager.h"
+
+/* IO config for int-pin and I2C-pin */
+#define SENSOR_I2C6_DATA_REG_ADDR 0x114f004c
+#define SENSOR_I2C6_CLK_REG_ADDR 0x114f0048
+#define SENSOR_I2C_REG_CFG 0x403
+
+static struct Bh1745DrvData *g_bh1745DrvData = NULL;
+static uint32_t g_timeMap_flag = 1;
+
+static struct TimeMap g_timeMap[EXTENDED_ALS_TIME_GROUP_INDEX_MAX] = {
+ { EXTENDED_ALS_TIME_GROUP_ATTR_VALUE_0, BH1745_TIME_160MSEC },
+ { EXTENDED_ALS_TIME_GROUP_ATTR_VALUE_1, BH1745_TIME_320MSEC },
+ { EXTENDED_ALS_TIME_GROUP_ATTR_VALUE_2, BH1745_TIME_640MSEC },
+ { EXTENDED_ALS_TIME_GROUP_ATTR_VALUE_3, BH1745_TIME_1280MSEC },
+ { EXTENDED_ALS_TIME_GROUP_ATTR_VALUE_4, BH1745_TIME_2560MSEC },
+ { EXTENDED_ALS_TIME_GROUP_ATTR_VALUE_5, BH1745_TIME_5120MSEC }
+};
+
+static struct GainMap g_gainMap[EXTENDED_ALS_GAIN_GROUP_INDEX_MAX] = {
+ { EXTENDED_ALS_GAIN_GROUP_ATTR_VALUE_0, BH1745_GAIN_1X },
+ { EXTENDED_ALS_GAIN_GROUP_ATTR_VALUE_1, BH1745_GAIN_2X },
+ { EXTENDED_ALS_GAIN_GROUP_ATTR_VALUE_2, BH1745_GAIN_16X }
+};
+
+static uint32_t g_red[BH1745_COEFFICIENT_RED] = {
+ BH1745_COEFFICIENT_RED_LEVEL_0,
+ BH1745_COEFFICIENT_RED_LEVEL_1
+};
+
+static uint32_t g_green[BH1745_COEFFICIENT_GREEN] = {
+ BH1745_COEFFICIENT_GREEN_LEVEL_0,
+ BH1745_COEFFICIENT_GREEN_LEVEL_1
+};
+
+struct Bh1745DrvData *Bh1745GetDrvData(void)
+{
+ return g_bh1745DrvData;
+}
+
+static int32_t DynamicRangCovert(struct SensorCfgData *CfgData, uint32_t *rgbcData)
+{
+ uint8_t regValue;
+ uint32_t temp;
+ uint8_t timeItemNum;
+ struct SensorRegCfgGroupNode *timeGroupNode = NULL;
+ int32_t index = EXTENDED_ALS_TIME_GROUP_INDEX_0;
+
+ timeGroupNode = CfgData->extendedRegCfgGroup[EXTENDED_ALS_TIME_GROUP];
+ timeItemNum = timeGroupNode->itemNum;
+ if (timeItemNum > EXTENDED_ALS_TIME_GROUP_INDEX_MAX) {
+ HDF_LOGE("%s: TimeItemNum out of range ", __func__);
+ return HDF_FAILURE;
+ }
+
+ ReadSensorRegCfgArray(&CfgData->busCfg, timeGroupNode, index, ®Value, sizeof(uint8_t));
+ regValue &= timeGroupNode->regCfgItem->mask;
+
+ temp = GetTimeByRegValue(regValue, g_timeMap, timeItemNum);
+ index = GetRegGroupIndexByTime(temp, g_timeMap, timeItemNum);
+ if (index < 0) {
+ HDF_LOGE("%s: Index out of range ", __func__);
+ return HDF_FAILURE;
+ }
+
+ if (((rgbcData[ALS_R] * BH1745_MULTIPLE_100 > BH1745_TIME_MAX) ||
+ (rgbcData[ALS_G] * BH1745_MULTIPLE_100 > BH1745_TIME_MAX)) && (temp >= BH1745_TIME_320MSEC)) {
+ g_timeMap_flag = 1;
+ index = GetRegGroupIndexByTime(temp, g_timeMap, timeItemNum);
+ index--;
+
+ WriteSensorRegCfgArray(&CfgData->busCfg, timeGroupNode, index, sizeof(uint8_t));
+ } else if ((g_timeMap_flag == 1) && ((rgbcData[ALS_R] * BH1745_MULTIPLE_100 < BH1745_TIME_MIN) ||
+ (rgbcData[ALS_G] * BH1745_MULTIPLE_100 < BH1745_TIME_MIN))) {
+ g_timeMap_flag = 0;
+ index = GetRegGroupIndexByTime(temp, g_timeMap, timeItemNum);
+ index++;
+ if (index >= timeItemNum) {
+ HDF_LOGE("%s: Index out of range ", __func__);
+ return HDF_FAILURE;
+ }
+
+ WriteSensorRegCfgArray(&CfgData->busCfg, timeGroupNode, index, sizeof(uint8_t));
+ }
+ return HDF_SUCCESS;
+}
+
+static uint32_t CalLux(struct SensorCfgData *CfgData, uint32_t *rgbcData)
+{
+ uint32_t time;
+ uint32_t gain;
+ uint8_t regValue;
+ uint32_t index = 1;
+ uint32_t luxTemp;
+ uint8_t itemNum;
+ struct SensorRegCfgGroupNode *GroupNode = NULL;
+ int32_t timeIndex = EXTENDED_ALS_TIME_GROUP_INDEX_0;
+ int32_t gainIndex = EXTENDED_ALS_GAIN_GROUP_INDEX_0;
+
+ if (rgbcData[ALS_G] < 1) {
+ return 0;
+ }
+
+ if (BH1745_MULTIPLE_100 * rgbcData[ALS_C] / rgbcData[ALS_G] < BH1745_COEFFICIENT_JUDGE) {
+ index = 0;
+ }
+
+ luxTemp = g_red[index] * rgbcData[ALS_R] + g_green[index] * rgbcData[ALS_G];
+
+ GroupNode = CfgData->extendedRegCfgGroup[EXTENDED_ALS_TIME_GROUP];
+ itemNum = GroupNode->itemNum;
+ if (itemNum > EXTENDED_ALS_TIME_GROUP_INDEX_MAX) {
+ HDF_LOGE("%s: ItemNum out of range ", __func__);
+ return HDF_FAILURE;
+ }
+
+ ReadSensorRegCfgArray(&CfgData->busCfg, GroupNode, timeIndex, ®Value, sizeof(uint8_t));
+ regValue &= GroupNode->regCfgItem->mask;
+ time = GetTimeByRegValue(regValue, g_timeMap, itemNum);
+
+ regValue = 0;
+ GroupNode = CfgData->extendedRegCfgGroup[EXTENDED_ALS_GAIN_GROUP];
+ itemNum = GroupNode->itemNum;
+ if (itemNum > EXTENDED_ALS_GAIN_GROUP_INDEX_MAX) {
+ HDF_LOGE("%s: ItemNum out of range ", __func__);
+ return HDF_FAILURE;
+ }
+
+ ReadSensorRegCfgArray(&CfgData->busCfg, GroupNode, gainIndex, ®Value, sizeof(uint8_t));
+ regValue &= GroupNode->regCfgItem->mask;
+ gain = GetGainByRegValue(regValue, g_gainMap, itemNum);
+
+ return (((luxTemp * BH1745_TIME_160MSEC * BH1745_GAIN_16X) / gain) / time);
+}
+
+static int32_t RawDataConvert(struct SensorCfgData *CfgData, struct AlsReportData *reportData, uint32_t* rgbcData)
+{
+ int ret;
+
+ reportData->als = (uint32_t)CalLux(CfgData, rgbcData);
+ reportData->als = (reportData->als > 0) ? reportData->als : 0;
+
+ ret = DynamicRangCovert(CfgData, rgbcData);
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "DynamicRangCovert");
+
+ return HDF_SUCCESS;
+}
+
+static int32_t ReadBh1745RawData(struct SensorCfgData *data, struct AlsData *rawData, int64_t *timestamp)
+{
+ uint8_t status = 0;
+ uint8_t reg[ALS_LIGHT_BUTT];
+ OsalTimespec time;
+
+ (void)memset_s(&time, sizeof(time), 0, sizeof(time));
+ (void)memset_s(reg, sizeof(reg), 0, sizeof(reg));
+
+ CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
+
+ if (OsalGetTime(&time) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Get time failed", __func__);
+ return HDF_FAILURE;
+ }
+ *timestamp = time.sec * SENSOR_SECOND_CONVERT_NANOSECOND + time.usec * SENSOR_CONVERT_UNIT; /* unit nanosecond */
+
+ int32_t ret = ReadSensor(&data->busCfg, BH1745_MODECONTROL3_ADDR, &status, sizeof(uint8_t));
+ if (!(status & BH1745_ALS_DATA_READY_MASK) || (ret != HDF_SUCCESS)) {
+ HDF_LOGE("%s: data status [%u] ret [%d]", __func__, status, ret);
+ return HDF_FAILURE;
+ }
+
+ ret = ReadSensor(&data->busCfg, BH1745_ALS_R_LSB_ADDR, ®[ALS_R_LSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BH1745_ALS_R_MSB_ADDR, ®[ALS_R_MSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BH1745_ALS_G_LSB_ADDR, ®[ALS_G_LSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BH1745_ALS_G_MSB_ADDR, ®[ALS_G_MSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BH1745_ALS_B_LSB_ADDR, ®[ALS_B_LSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BH1745_ALS_B_MSB_ADDR, ®[ALS_B_MSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BH1745_ALS_C_LSB_ADDR, ®[ALS_C_LSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BH1745_ALS_C_MSB_ADDR, ®[ALS_C_MSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ rawData->red = (uint16_t)(SENSOR_DATA_SHIFT_LEFT(reg[ALS_R_MSB], SENSOR_DATA_WIDTH_8_BIT) |
+ reg[ALS_R_LSB]);
+ rawData->green = (uint16_t)(SENSOR_DATA_SHIFT_LEFT(reg[ALS_G_MSB], SENSOR_DATA_WIDTH_8_BIT) |
+ reg[ALS_G_LSB]);
+ rawData->blue = (uint16_t)(SENSOR_DATA_SHIFT_LEFT(reg[ALS_B_MSB], SENSOR_DATA_WIDTH_8_BIT) |
+ reg[ALS_B_LSB]);
+ rawData->clear = (uint16_t)(SENSOR_DATA_SHIFT_LEFT(reg[ALS_C_MSB], SENSOR_DATA_WIDTH_8_BIT) |
+ reg[ALS_C_LSB]);
+
+ return HDF_SUCCESS;
+}
+
+int32_t ReadBh1745Data(struct SensorCfgData *data)
+{
+ int32_t ret;
+ struct AlsData rawData = { 0, 0, 0, 0 };
+ uint32_t tmp[ALS_LIGHT_NUM];
+ struct SensorReportEvent event;
+ struct AlsReportData reportData;
+
+ (void)memset_s(&event, sizeof(event), 0, sizeof(event));
+ ret = ReadBh1745RawData(data, &rawData, &event.timestamp);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: BH1745 read raw data failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ event.sensorId = SENSOR_TAG_AMBIENT_LIGHT;
+ event.option = 0;
+ event.mode = SENSOR_WORK_MODE_REALTIME;
+
+ tmp[ALS_R] = rawData.red;
+ tmp[ALS_G] = rawData.green;
+ tmp[ALS_B] = rawData.blue;
+ tmp[ALS_C] = rawData.clear;
+
+ ret = RawDataConvert(data, &reportData, tmp);
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "RawDataConvert");
+
+ event.dataLen = sizeof(reportData.als);
+ event.data = (uint8_t *)&reportData.als;
+
+ ret = ReportSensorEvent(&event);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: BH1745 report data failed", __func__);
+ }
+ return ret;
+}
+
+static int32_t InitBh1745(struct SensorCfgData *data)
+{
+ int32_t ret;
+
+ CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
+ ret = SetSensorRegCfgArray(&data->busCfg, data->regCfgGroup[SENSOR_INIT_GROUP]);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: BH1745 sensor init config failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t InitAlsPreConfig(void)
+{
+ if (SetSensorPinMux(SENSOR_I2C6_DATA_REG_ADDR, SENSOR_ADDR_WIDTH_4_BYTE, SENSOR_I2C_REG_CFG) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Data write mux pin failed", __func__);
+ return HDF_FAILURE;
+ }
+ if (SetSensorPinMux(SENSOR_I2C6_CLK_REG_ADDR, SENSOR_ADDR_WIDTH_4_BYTE, SENSOR_I2C_REG_CFG) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Clk write mux pin failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t DispatchBH1745(struct HdfDeviceIoClient *client,
+ int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ (void)client;
+ (void)cmd;
+ (void)data;
+ (void)reply;
+
+ return HDF_SUCCESS;
+}
+
+int32_t Bh1745BindDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
+
+ struct Bh1745DrvData *drvData = (struct Bh1745DrvData *)OsalMemCalloc(sizeof(*drvData));
+ if (drvData == NULL) {
+ HDF_LOGE("%s: Malloc Bh1745 drv data fail", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ drvData->ioService.Dispatch = DispatchBH1745;
+ drvData->device = device;
+ device->service = &drvData->ioService;
+ g_bh1745DrvData = drvData;
+
+ return HDF_SUCCESS;
+}
+
+int32_t Bh1745InitDriver(struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct AlsOpsCall ops;
+
+ CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
+ struct Bh1745DrvData *drvData = (struct Bh1745DrvData *)device->service;
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+
+ ret = InitAlsPreConfig();
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Init BH1745 bus mux config", __func__);
+ return HDF_FAILURE;
+ }
+
+ drvData->sensorCfg = AlsCreateCfgData(device->property);
+ if (drvData->sensorCfg == NULL || drvData->sensorCfg->root == NULL) {
+ HDF_LOGD("%s: Creating alscfg failed because detection failed", __func__);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ ops.Init = NULL;
+ ops.ReadData = ReadBh1745Data;
+ ret = AlsRegisterChipOps(&ops);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Register BH1745 als failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ ret = InitBh1745(drvData->sensorCfg);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Init BH1745 als failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+void Bh1745ReleaseDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN(device);
+
+ struct Bh1745DrvData *drvData = (struct Bh1745DrvData *)device->service;
+ CHECK_NULL_PTR_RETURN(drvData);
+
+ if (drvData->sensorCfg != NULL) {
+ AlsReleaseCfgData(drvData->sensorCfg);
+ drvData->sensorCfg = NULL;
+ }
+ OsalMemFree(drvData);
+}
+
+struct HdfDriverEntry g_alsBh1745DevEntry = {
+ .moduleVersion = 1,
+ .moduleName = "HDF_SENSOR_ALS_BH1745",
+ .Bind = Bh1745BindDriver,
+ .Init = Bh1745InitDriver,
+ .Release = Bh1745ReleaseDriver,
+};
+
+HDF_INIT(g_alsBh1745DevEntry);
diff --git a/model/sensor/driver/chipset/als/als_bh1745.h b/model/sensor/driver/chipset/als/als_bh1745.h
new file mode 100755
index 0000000000000000000000000000000000000000..34105dee4b1a5ff62e9907ead1c853c1af11276c
--- /dev/null
+++ b/model/sensor/driver/chipset/als/als_bh1745.h
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef ALS_BH1745_H
+#define ALS_BH1745_H
+
+#include "sensor_als_driver.h"
+#include "sensor_config_parser.h"
+
+/* ALS DATA REGISTERS ADDR */
+#define BH1745_ALS_R_LSB_ADDR 0X50
+#define BH1745_ALS_R_MSB_ADDR 0X51
+#define BH1745_ALS_G_LSB_ADDR 0X52
+#define BH1745_ALS_G_MSB_ADDR 0X53
+#define BH1745_ALS_B_LSB_ADDR 0X54
+#define BH1745_ALS_B_MSB_ADDR 0X55
+#define BH1745_ALS_C_LSB_ADDR 0X56
+#define BH1745_ALS_C_MSB_ADDR 0X57
+#define BH1745_MODECONTROL3_ADDR 0X44
+
+/* ALS DATA READY */
+#define BH1745_ALS_DATA_READY_MASK 0X02
+
+/* ALS MULTIPLE */
+#define BH1745_MULTIPLE_100 100
+
+/* ALS COEFFICIENT */
+#define BH1745_COEFFICIENT_RED 2
+#define BH1745_COEFFICIENT_GREEN 2
+#define BH1745_COEFFICIENT_RED_LEVEL_0 77300 // 7.73 * 10000
+#define BH1745_COEFFICIENT_RED_LEVEL_1 92715 // 9.2715 * 10000
+#define BH1745_COEFFICIENT_GREEN_LEVEL_0 131920 // 1.3192 * 10000
+#define BH1745_COEFFICIENT_GREEN_LEVEL_1 214770 // 2.1477 * 10000
+#define BH1745_COEFFICIENT_JUDGE 78 // 0.78*100
+
+/* ALS TIME */
+#define BH1745_TIME_160MSEC 160
+#define BH1745_TIME_320MSEC 320
+#define BH1745_TIME_640MSEC 640
+#define BH1745_TIME_1280MSEC 1280
+#define BH1745_TIME_2560MSEC 2560
+#define BH1745_TIME_5120MSEC 5120
+#define BH1745_TIME_MAX 5570475 // 65535*0.85*100
+#define BH1745_TIME_MIN 1638375 // 65535*0.25*100
+
+/* ALS GAIN */
+#define BH1745_GAIN_1X 1
+#define BH1745_GAIN_2X 2
+#define BH1745_GAIN_16X 16
+
+/* ALS TIME REG VALUE */
+#define EXTENDED_ALS_TIME_GROUP_ATTR_VALUE_0 0x00
+#define EXTENDED_ALS_TIME_GROUP_ATTR_VALUE_1 0x01
+#define EXTENDED_ALS_TIME_GROUP_ATTR_VALUE_2 0x02
+#define EXTENDED_ALS_TIME_GROUP_ATTR_VALUE_3 0x03
+#define EXTENDED_ALS_TIME_GROUP_ATTR_VALUE_4 0x04
+#define EXTENDED_ALS_TIME_GROUP_ATTR_VALUE_5 0x05
+
+/* ALS GAIN REG VALUE */
+#define EXTENDED_ALS_GAIN_GROUP_ATTR_VALUE_0 0x00
+#define EXTENDED_ALS_GAIN_GROUP_ATTR_VALUE_1 0x01
+#define EXTENDED_ALS_GAIN_GROUP_ATTR_VALUE_2 0x02
+
+enum ExtendedAlsTimeRegGroupIdex {
+ EXTENDED_ALS_TIME_GROUP_INDEX_0 = 0,
+ EXTENDED_ALS_TIME_GROUP_INDEX_1,
+ EXTENDED_ALS_TIME_GROUP_INDEX_2,
+ EXTENDED_ALS_TIME_GROUP_INDEX_3,
+ EXTENDED_ALS_TIME_GROUP_INDEX_4,
+ EXTENDED_ALS_TIME_GROUP_INDEX_5,
+ EXTENDED_ALS_TIME_GROUP_INDEX_MAX,
+};
+
+enum ExtendedAlsGainRegGroupIdex {
+ EXTENDED_ALS_GAIN_GROUP_INDEX_0 = 0,
+ EXTENDED_ALS_GAIN_GROUP_INDEX_1,
+ EXTENDED_ALS_GAIN_GROUP_INDEX_2,
+ EXTENDED_ALS_GAIN_GROUP_INDEX_MAX,
+};
+
+int32_t DetectAlsBim160Chip(struct SensorCfgData *data);
+int32_t ReadBh1745Data(struct SensorCfgData *data);
+
+struct Bh1745DrvData {
+ struct IDeviceIoService ioService;
+ struct HdfDeviceObject *device;
+ struct SensorCfgData *sensorCfg;
+};
+
+#endif /* ALS_BH1745_H */
diff --git a/model/sensor/driver/chipset/barometer/barometer_bmp180.c b/model/sensor/driver/chipset/barometer/barometer_bmp180.c
index 298684807b3ba09db2e44bb823c81378c0a3bce9..3c5f150e1cd641448bceb1a792416510e856c031 100644
--- a/model/sensor/driver/chipset/barometer/barometer_bmp180.c
+++ b/model/sensor/driver/chipset/barometer/barometer_bmp180.c
@@ -1,411 +1,414 @@
-/*
- * Copyright (c) 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 "barometer_bmp180.h"
-#include
-#include "osal_mem.h"
-#include "osal_time.h"
-#include "sensor_barometer_driver.h"
-#include "sensor_config_controller.h"
-#include "sensor_device_manager.h"
-#include "sensor_platform_if.h"
-
-static struct Bmp180DrvData *g_bmp180DrvData = NULL;
-
-struct Bmp180DrvData *Bmp180GetDrvData(void)
-{
- return g_bmp180DrvData;
-}
-
-/* IO config for int-pin and I2C-pin */
-#define SENSOR_I2C6_DATA_REG_ADDR 0x114f004c
-#define SENSOR_I2C6_CLK_REG_ADDR 0x114f0048
-#define SENSOR_I2C_REG_CFG 0x403
-
-static struct BarometerEepromData g_calibraData = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
-
-static int32_t ReadEepromRawData(struct SensorCfgData *data, uint8_t rfg[BAROMETER_EEPROM_SUM])
-{
- int32_t ret;
-
- ret = ReadSensor(&data->busCfg, BMP180_AC1_MSB_ADDR, &rfg[BAROMETER_AC1_MSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_AC1_LSB_ADDR, &rfg[BAROMETER_AC1_LSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_AC2_MSB_ADDR, &rfg[BAROMETER_AC2_MSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_AC2_LSB_ADDR, &rfg[BAROMETER_AC2_LSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_AC3_MSB_ADDR, &rfg[BAROMETER_AC3_MSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_AC3_LSB_ADDR, &rfg[BAROMETER_AC3_LSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_AC4_MSB_ADDR, &rfg[BAROMETER_AC4_MSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_AC4_LSB_ADDR, &rfg[BAROMETER_AC4_LSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_AC5_MSB_ADDR, &rfg[BAROMETER_AC5_MSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_AC5_LSB_ADDR, &rfg[BAROMETER_AC5_LSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_AC6_MSB_ADDR, &rfg[BAROMETER_AC6_MSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
- ret = ReadSensor(&data->busCfg, BMP180_AC6_LSB_ADDR, &rfg[BAROMETER_AC6_LSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_B1_MSB_ADDR, &rfg[BAROMETER_B1_MSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_B1_LSB_ADDR, &rfg[BAROMETER_B1_LSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_B2_MSB_ADDR, &rfg[BAROMETER_B2_MSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_B2_LSB_ADDR, &rfg[BAROMETER_B2_LSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_MB_MSB_ADDR, &rfg[BAROMETER_MB_MSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_MB_LSB_ADDR, &rfg[BAROMETER_MB_LSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_MC_MSB_ADDR, &rfg[BAROMETER_MC_MSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_MC_LSB_ADDR, &rfg[BAROMETER_MC_LSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_MD_MSB_ADDR, &rfg[BAROMETER_MD_MSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_MD_LSB_ADDR, &rfg[BAROMETER_MD_LSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- return ret;
-}
-
-static int32_t ReadEepromData(struct SensorCfgData *data, struct BarometerEepromData *g_calibraData)
-{
- int32_t ret;
- uint8_t reg[BAROMETER_EEPROM_SUM];
-
- (void)memset_s(reg, sizeof(reg), 0, sizeof(reg));
-
- CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
-
- ret = ReadEepromRawData(data, reg);
- if (ret != HDF_SUCCESS) {
- return HDF_FAILURE;
- }
-
- g_calibraData->ac1 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC1_MSB], SENSOR_DATA_WIDTH_8_BIT) |
- reg[BAROMETER_AC1_LSB]);
- g_calibraData->ac2 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC2_MSB], SENSOR_DATA_WIDTH_8_BIT) |
- reg[BAROMETER_AC2_LSB]);
- g_calibraData->ac3 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC3_MSB], SENSOR_DATA_WIDTH_8_BIT) |
- reg[BAROMETER_AC3_LSB]);
- g_calibraData->ac4 = (uint16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC4_MSB], SENSOR_DATA_WIDTH_8_BIT) |
- reg[BAROMETER_AC4_LSB]);
- g_calibraData->ac5 = (uint16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC5_MSB], SENSOR_DATA_WIDTH_8_BIT) |
- reg[BAROMETER_AC5_LSB]);
- g_calibraData->ac6 = (uint16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC6_MSB], SENSOR_DATA_WIDTH_8_BIT) |
- reg[BAROMETER_AC6_LSB]);
- g_calibraData->b1 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_B1_MSB], SENSOR_DATA_WIDTH_8_BIT) |
- reg[BAROMETER_B1_LSB]);
- g_calibraData->b2 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_B2_MSB], SENSOR_DATA_WIDTH_8_BIT) |
- reg[BAROMETER_B2_LSB]);
- g_calibraData->mb = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_MB_MSB], SENSOR_DATA_WIDTH_8_BIT) |
- reg[BAROMETER_MB_LSB]);
- g_calibraData->mc = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_MC_MSB], SENSOR_DATA_WIDTH_8_BIT) |
- reg[BAROMETER_MC_LSB]);
- g_calibraData->md = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_MD_MSB], SENSOR_DATA_WIDTH_8_BIT) |
- reg[BAROMETER_MD_LSB]);
-
- return ret;
-}
-
-static int32_t ReadTempData(struct SensorCfgData *data, struct BarometerRawData *Temp)
-{
- int32_t ret;
- uint8_t status = 0;
- uint8_t reg[BAROMETER_TEM_SUM];
- uint8_t value[SENSOR_VALUE_BUTT];
- value[SENSOR_ADDR_INDEX] = BMP180_CONTROL_REG_ADDR;
- value[SENSOR_VALUE_INDEX] = BMP180_COVERT_TEMP;
-
- (void)memset_s(reg, sizeof(reg), 0, sizeof(reg));
-
- CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
-
- ret = ReadSensor(&data->busCfg, BMP180_COVERT_PRES_3, &status, sizeof(uint8_t));
- if ((status & BMP180_STATUS_ADDR) == BMP180_STATUS_JUDGE) {
- WriteSensor(&data->busCfg, value, sizeof(value));
- OsalMDelay(DELAY_0);
- ret = ReadSensor(&data->busCfg, BMP180_OUT_MSB_ADDR, ®[BAROMETER_TEM_MSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_OUT_LSB_ADDR, ®[BAROMETER_TEM_LSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- Temp->unpensateTemp = (int32_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_TEM_MSB], SENSOR_DATA_WIDTH_8_BIT) |
- reg[BAROMETER_TEM_LSB]);
- }
- return ret;
-}
-
-static int32_t ReadBarometerData(struct SensorCfgData *data, struct BarometerRawData *Barom)
-{
- int32_t ret;
- uint8_t status = 0;
- uint8_t reg[BAROMETER_BAR_SUM];
- uint8_t value[SENSOR_VALUE_BUTT];
- value[SENSOR_ADDR_INDEX] = BMP180_CONTROL_REG_ADDR;
- value[SENSOR_VALUE_INDEX] = BMP180_COVERT_PRES_1;
-
- (void)memset_s(reg, sizeof(reg), 0, sizeof(reg));
-
- CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
-
- ret = ReadSensor(&data->busCfg, BMP180_COVERT_PRES_3, &status, sizeof(uint8_t));
- if ((status & BMP180_STATUS_ADDR) == BMP180_STATUS_JUDGE) {
- WriteSensor(&data->busCfg, value, sizeof(value));
- OsalMDelay(DELAY_1);
- ret = ReadSensor(&data->busCfg, BMP180_OUT_MSB_ADDR, ®[BAROMETER_BAR_MSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_OUT_LSB_ADDR, ®[BAROMETER_BAR_LSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- ret = ReadSensor(&data->busCfg, BMP180_OUT_XLSB_ADDR, ®[BAROMETER_BAR_XLSB], sizeof(uint8_t));
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
-
- Barom->unpensatePre = (int32_t)(SENSOR_DATA_SHIFT_RIGHT(
- (SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_BAR_MSB], SENSOR_DATA_WIDTH_16_BIT) |
- SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_BAR_LSB], SENSOR_DATA_WIDTH_8_BIT) | reg[BAROMETER_BAR_XLSB]),
- (BMP180_CONSTANT_4 - OSSETTING)));
- }
- return ret;
-}
-
-static int32_t CalcBarometerData(struct BarometerRawData *barometerData, int32_t tnp[BAROMETER_SUM])
-{
- struct Coefficient coefficientData = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-
- // Calculated temperature
-
- coefficientData.x1 = ((barometerData->unpensateTemp - g_calibraData.ac6) * (g_calibraData.ac5))
- >> BMP180_CONSTANT_8;
- coefficientData.x2 = (g_calibraData.mc << BMP180_CONSTANT_5) / (coefficientData.x1 + g_calibraData.md);
- coefficientData.b5 = coefficientData.x1 + coefficientData.x2;
- tnp[BAROMETER_TEMPERATURE] = (coefficientData.b5 + BMP180_CONSTANT_4) >> BMP180_CONSTANT_3;
-
- // Calculated pressure
-
- coefficientData.b6 = coefficientData.b5 - BMP180_CONSTANT_12;
- coefficientData.x1 = (g_calibraData.b2 * ((coefficientData.b6 * coefficientData.b6) >> BMP180_CONSTANT_6))
- >> BMP180_CONSTANT_5;
- coefficientData.x2 = (g_calibraData.ac2 * coefficientData.b6) >> BMP180_CONSTANT_5;
- coefficientData.x3 = coefficientData.x1 + coefficientData.x2;
- coefficientData.b3 = (((((int32_t)g_calibraData.ac1) * BMP180_CONSTANT_3 + coefficientData.x3) << OSSETTING)
- + BMP180_CONSTANT_2) >> BMP180_CONSTANT_2;
- coefficientData.x1 = (g_calibraData.ac3 * coefficientData.b6) >> BMP180_CONSTANT_7;
- coefficientData.x2 = (g_calibraData.b1 * ((coefficientData.b6 * coefficientData.b6) >> BMP180_CONSTANT_6))
- >> BMP180_CONSTANT_9;
- coefficientData.x3 = ((coefficientData.x1 + coefficientData.x2) + BMP180_CONSTANT_2) >> BMP180_CONSTANT_2;
- coefficientData.b4 = (g_calibraData.ac4 * (uint32_t)(coefficientData.x3 + BMP180_CONSTANT_13))
- >> BMP180_CONSTANT_8;
- coefficientData.b7 = ((uint32_t)(barometerData->unpensatePre) - (uint32_t)coefficientData.b3)
- * (BMP180_CONSTANT_14 >> OSSETTING);
- if (coefficientData.b7 < BMP180_CONSTANT_15) {
- coefficientData.p = (coefficientData.b7 << BMP180_CONSTANT_1) / coefficientData.b4;
- } else {
- coefficientData.p = (coefficientData.b7 / coefficientData.b4) << BMP180_CONSTANT_1;
- }
- coefficientData.x1 = (coefficientData.p >> BMP180_CONSTANT_4) * (coefficientData.p >> BMP180_CONSTANT_4);
- coefficientData.x1 = (coefficientData.x1 * BMP180_CONSTANT_10) >> BMP180_CONSTANT_9;
- coefficientData.x2 = (BMP180_CONSTANT_0 * coefficientData.p) >> BMP180_CONSTANT_9;
- tnp[BAROMETER_BAROMETER] = coefficientData.p + ((coefficientData.x1 + coefficientData.x2
- + BMP180_CONSTANT_11) >> BMP180_CONSTANT_3);
-
- return HDF_SUCCESS;
-}
-
-int32_t ReadBmp180Data(struct SensorCfgData *data)
-{
- int32_t ret;
- int32_t tmp[BAROMETER_SUM];
- struct BarometerRawData barometerData = {0, 0};
- OsalTimespec time;
- struct SensorReportEvent event;
-
- (void)memset_s(&time, sizeof(time), 0, sizeof(time));
- (void)memset_s(&event, sizeof(event), 0, sizeof(event));
-
- if (OsalGetTime(&time) != HDF_SUCCESS) {
- HDF_LOGE("%s: Get time failed", __func__);
- return HDF_FAILURE;
- }
- event.timestamp = time.sec * SENSOR_SECOND_CONVERT_NANOSECOND + time.usec * SENSOR_CONVERT_UNIT;
-
- ret = ReadTempData(data, &barometerData);
- if (ret != HDF_SUCCESS) {
- return HDF_FAILURE;
- }
-
- ret = ReadBarometerData(data, &barometerData);
- if (ret != HDF_SUCCESS) {
- return HDF_FAILURE;
- }
-
- ret = CalcBarometerData(&barometerData, tmp);
- if (ret != HDF_SUCCESS) {
- return HDF_FAILURE;
- }
-
- event.sensorId = SENSOR_TAG_BAROMETER;
- event.option = 0;
- event.mode = SENSOR_WORK_MODE_REALTIME;
- event.dataLen = sizeof(tmp);
- event.data = (uint8_t *)&tmp;
- ret = ReportSensorEvent(&event);
- return ret;
-}
-
-static int32_t InitBmp180(struct SensorCfgData *data)
-{
- int32_t ret;
- CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
- struct SensorReportEvent event;
-
- (void)memset_s(&event, sizeof(event), 0, sizeof(event));
-
- ret = ReadEepromData(data, &g_calibraData);
- if (ret != HDF_SUCCESS) {
- return HDF_FAILURE;
- }
- ret = SetSensorRegCfgArray(&data->busCfg, data->regCfgGroup[SENSOR_INIT_GROUP]);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: BMP180 sensor init config failed", __func__);
- return HDF_FAILURE;
- }
- return HDF_SUCCESS;
-}
-
-static int32_t InitBarometerPreConfig(void)
-{
- if (SetSensorPinMux(SENSOR_I2C6_DATA_REG_ADDR, SENSOR_ADDR_WIDTH_4_BYTE, SENSOR_I2C_REG_CFG) != HDF_SUCCESS) {
- HDF_LOGE("%s: Data write mux pin failed", __func__);
- return HDF_FAILURE;
- }
- if (SetSensorPinMux(SENSOR_I2C6_CLK_REG_ADDR, SENSOR_ADDR_WIDTH_4_BYTE, SENSOR_I2C_REG_CFG) != HDF_SUCCESS) {
- HDF_LOGE("%s: Clk write mux pin failed", __func__);
- return HDF_FAILURE;
- }
-
- return HDF_SUCCESS;
-}
-
-static int32_t DispatchBMP180(struct HdfDeviceIoClient *client,
- int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
-{
- (void)client;
- (void)cmd;
- (void)data;
- (void)reply;
-
- return HDF_SUCCESS;
-}
-
-int32_t Bmp180BindDriver(struct HdfDeviceObject *device)
-{
- CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
-
- struct Bmp180DrvData *drvData = (struct Bmp180DrvData *)OsalMemCalloc(sizeof(*drvData));
- if (drvData == NULL) {
- HDF_LOGE("%s: Malloc Bmi160 drv data fail", __func__);
- return HDF_ERR_MALLOC_FAIL;
- }
-
- drvData->ioService.Dispatch = DispatchBMP180;
- drvData->device = device;
- device->service = &drvData->ioService;
- g_bmp180DrvData = drvData;
-
- return HDF_SUCCESS;
-}
-
-int32_t Bmp180InitDriver(struct HdfDeviceObject *device)
-{
- int32_t ret;
- struct BarometerOpsCall ops;
-
- CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
- struct Bmp180DrvData *drvData = (struct Bmp180DrvData *)device->service;
- CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
-
- ret = InitBarometerPreConfig();
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: Init BMp180 bus mux config", __func__);
- return HDF_FAILURE;
- }
-
- drvData->sensorCfg = BarometerCreateCfgData(device->property);
- if (drvData->sensorCfg == NULL) {
- return HDF_ERR_NOT_SUPPORT;
- }
-
- ops.Init = NULL;
- ops.ReadData = ReadBmp180Data;
- ret = BarometerRegisterChipOps(&ops);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: Register BMp180 barometer failed", __func__);
- return HDF_FAILURE;
- }
-
- ret = InitBmp180(drvData->sensorCfg);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: Init BMP180 barometer failed", __func__);
- return HDF_FAILURE;
- }
-
- return HDF_SUCCESS;
-}
-
-void Bmp180ReleaseDriver(struct HdfDeviceObject *device)
-{
- CHECK_NULL_PTR_RETURN(device);
-
- struct Bmp180DrvData *drvData = (struct Bmp180DrvData *)device->service;
- CHECK_NULL_PTR_RETURN(drvData);
-
- BarometerReleaseCfgData(drvData->sensorCfg);
- drvData->sensorCfg = NULL;
- OsalMemFree(drvData);
-}
-
-struct HdfDriverEntry g_barometerBmp180DevEntry = {
- .moduleVersion = 1,
- .moduleName = "HDF_SENSOR_BAROMETER_BMP180",
- .Bind = Bmp180BindDriver,
- .Init = Bmp180InitDriver,
- .Release = Bmp180ReleaseDriver,
-};
-
+/*
+ * Copyright (c) 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 "barometer_bmp180.h"
+#include
+#include "osal_mem.h"
+#include "osal_time.h"
+#include "sensor_barometer_driver.h"
+#include "sensor_config_controller.h"
+#include "sensor_device_manager.h"
+#include "sensor_platform_if.h"
+
+static struct Bmp180DrvData *g_bmp180DrvData = NULL;
+
+struct Bmp180DrvData *Bmp180GetDrvData(void)
+{
+ return g_bmp180DrvData;
+}
+
+/* IO config for int-pin and I2C-pin */
+#define SENSOR_I2C6_DATA_REG_ADDR 0x114f004c
+#define SENSOR_I2C6_CLK_REG_ADDR 0x114f0048
+#define SENSOR_I2C_REG_CFG 0x403
+
+static struct BarometerEepromData g_calibraData = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+
+static int32_t ReadEepromRawData(struct SensorCfgData *data, uint8_t rfg[BAROMETER_EEPROM_SUM])
+{
+ int32_t ret;
+
+ ret = ReadSensor(&data->busCfg, BMP180_AC1_MSB_ADDR, &rfg[BAROMETER_AC1_MSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_AC1_LSB_ADDR, &rfg[BAROMETER_AC1_LSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_AC2_MSB_ADDR, &rfg[BAROMETER_AC2_MSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_AC2_LSB_ADDR, &rfg[BAROMETER_AC2_LSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_AC3_MSB_ADDR, &rfg[BAROMETER_AC3_MSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_AC3_LSB_ADDR, &rfg[BAROMETER_AC3_LSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_AC4_MSB_ADDR, &rfg[BAROMETER_AC4_MSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_AC4_LSB_ADDR, &rfg[BAROMETER_AC4_LSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_AC5_MSB_ADDR, &rfg[BAROMETER_AC5_MSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_AC5_LSB_ADDR, &rfg[BAROMETER_AC5_LSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_AC6_MSB_ADDR, &rfg[BAROMETER_AC6_MSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+ ret = ReadSensor(&data->busCfg, BMP180_AC6_LSB_ADDR, &rfg[BAROMETER_AC6_LSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_B1_MSB_ADDR, &rfg[BAROMETER_B1_MSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_B1_LSB_ADDR, &rfg[BAROMETER_B1_LSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_B2_MSB_ADDR, &rfg[BAROMETER_B2_MSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_B2_LSB_ADDR, &rfg[BAROMETER_B2_LSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_MB_MSB_ADDR, &rfg[BAROMETER_MB_MSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_MB_LSB_ADDR, &rfg[BAROMETER_MB_LSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_MC_MSB_ADDR, &rfg[BAROMETER_MC_MSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_MC_LSB_ADDR, &rfg[BAROMETER_MC_LSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_MD_MSB_ADDR, &rfg[BAROMETER_MD_MSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_MD_LSB_ADDR, &rfg[BAROMETER_MD_LSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ return ret;
+}
+
+static int32_t ReadEepromData(struct SensorCfgData *data, struct BarometerEepromData *g_calibraData)
+{
+ int32_t ret;
+ uint8_t reg[BAROMETER_EEPROM_SUM];
+
+ (void)memset_s(reg, sizeof(reg), 0, sizeof(reg));
+
+ CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
+
+ ret = ReadEepromRawData(data, reg);
+ if (ret != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ g_calibraData->ac1 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC1_MSB], SENSOR_DATA_WIDTH_8_BIT) |
+ reg[BAROMETER_AC1_LSB]);
+ g_calibraData->ac2 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC2_MSB], SENSOR_DATA_WIDTH_8_BIT) |
+ reg[BAROMETER_AC2_LSB]);
+ g_calibraData->ac3 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC3_MSB], SENSOR_DATA_WIDTH_8_BIT) |
+ reg[BAROMETER_AC3_LSB]);
+ g_calibraData->ac4 = (uint16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC4_MSB], SENSOR_DATA_WIDTH_8_BIT) |
+ reg[BAROMETER_AC4_LSB]);
+ g_calibraData->ac5 = (uint16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC5_MSB], SENSOR_DATA_WIDTH_8_BIT) |
+ reg[BAROMETER_AC5_LSB]);
+ g_calibraData->ac6 = (uint16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC6_MSB], SENSOR_DATA_WIDTH_8_BIT) |
+ reg[BAROMETER_AC6_LSB]);
+ g_calibraData->b1 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_B1_MSB], SENSOR_DATA_WIDTH_8_BIT) |
+ reg[BAROMETER_B1_LSB]);
+ g_calibraData->b2 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_B2_MSB], SENSOR_DATA_WIDTH_8_BIT) |
+ reg[BAROMETER_B2_LSB]);
+ g_calibraData->mb = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_MB_MSB], SENSOR_DATA_WIDTH_8_BIT) |
+ reg[BAROMETER_MB_LSB]);
+ g_calibraData->mc = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_MC_MSB], SENSOR_DATA_WIDTH_8_BIT) |
+ reg[BAROMETER_MC_LSB]);
+ g_calibraData->md = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_MD_MSB], SENSOR_DATA_WIDTH_8_BIT) |
+ reg[BAROMETER_MD_LSB]);
+
+ return ret;
+}
+
+static int32_t ReadTempData(struct SensorCfgData *data, struct BarometerRawData *Temp)
+{
+ int32_t ret;
+ uint8_t status = 0;
+ uint8_t reg[BAROMETER_TEM_SUM];
+ uint8_t value[SENSOR_VALUE_BUTT];
+ value[SENSOR_ADDR_INDEX] = BMP180_CONTROL_REG_ADDR;
+ value[SENSOR_VALUE_INDEX] = BMP180_COVERT_TEMP;
+
+ (void)memset_s(reg, sizeof(reg), 0, sizeof(reg));
+
+ CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
+
+ ret = ReadSensor(&data->busCfg, BMP180_COVERT_PRES_3, &status, sizeof(uint8_t));
+ if ((status & BMP180_STATUS_ADDR) == BMP180_STATUS_JUDGE) {
+ WriteSensor(&data->busCfg, value, sizeof(value));
+ OsalMDelay(DELAY_0);
+ ret = ReadSensor(&data->busCfg, BMP180_OUT_MSB_ADDR, ®[BAROMETER_TEM_MSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_OUT_LSB_ADDR, ®[BAROMETER_TEM_LSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ Temp->unpensateTemp = (int32_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_TEM_MSB], SENSOR_DATA_WIDTH_8_BIT) |
+ reg[BAROMETER_TEM_LSB]);
+ }
+ return ret;
+}
+
+static int32_t ReadBarometerData(struct SensorCfgData *data, struct BarometerRawData *Barom)
+{
+ int32_t ret;
+ uint8_t status = 0;
+ uint8_t reg[BAROMETER_BAR_SUM];
+ uint8_t value[SENSOR_VALUE_BUTT];
+ value[SENSOR_ADDR_INDEX] = BMP180_CONTROL_REG_ADDR;
+ value[SENSOR_VALUE_INDEX] = BMP180_COVERT_PRES_1;
+
+ (void)memset_s(reg, sizeof(reg), 0, sizeof(reg));
+
+ CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
+
+ ret = ReadSensor(&data->busCfg, BMP180_COVERT_PRES_3, &status, sizeof(uint8_t));
+ if ((status & BMP180_STATUS_ADDR) == BMP180_STATUS_JUDGE) {
+ WriteSensor(&data->busCfg, value, sizeof(value));
+ OsalMDelay(DELAY_1);
+ ret = ReadSensor(&data->busCfg, BMP180_OUT_MSB_ADDR, ®[BAROMETER_BAR_MSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_OUT_LSB_ADDR, ®[BAROMETER_BAR_LSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, BMP180_OUT_XLSB_ADDR, ®[BAROMETER_BAR_XLSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ Barom->unpensatePre = (int32_t)(SENSOR_DATA_SHIFT_RIGHT(
+ (SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_BAR_MSB], SENSOR_DATA_WIDTH_16_BIT) |
+ SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_BAR_LSB], SENSOR_DATA_WIDTH_8_BIT) | reg[BAROMETER_BAR_XLSB]),
+ (BMP180_CONSTANT_4 - OSSETTING)));
+ }
+ return ret;
+}
+
+static int32_t CalcBarometerData(struct BarometerRawData *barometerData, int32_t tnp[BAROMETER_SUM])
+{
+ struct Coefficient coefficientData = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+
+ // Calculated temperature
+
+ coefficientData.x1 = ((barometerData->unpensateTemp - g_calibraData.ac6) * (g_calibraData.ac5))
+ >> BMP180_CONSTANT_8;
+ coefficientData.x2 = (g_calibraData.mc << BMP180_CONSTANT_5) / (coefficientData.x1 + g_calibraData.md);
+ coefficientData.b5 = coefficientData.x1 + coefficientData.x2;
+ tnp[BAROMETER_TEMPERATURE] = (coefficientData.b5 + BMP180_CONSTANT_4) >> BMP180_CONSTANT_3;
+
+ // Calculated pressure
+
+ coefficientData.b6 = coefficientData.b5 - BMP180_CONSTANT_12;
+ coefficientData.x1 = (g_calibraData.b2 * ((coefficientData.b6 * coefficientData.b6) >> BMP180_CONSTANT_6))
+ >> BMP180_CONSTANT_5;
+ coefficientData.x2 = (g_calibraData.ac2 * coefficientData.b6) >> BMP180_CONSTANT_5;
+ coefficientData.x3 = coefficientData.x1 + coefficientData.x2;
+ coefficientData.b3 = (((((int32_t)g_calibraData.ac1) * BMP180_CONSTANT_3 + coefficientData.x3) << OSSETTING)
+ + BMP180_CONSTANT_2) >> BMP180_CONSTANT_2;
+ coefficientData.x1 = (g_calibraData.ac3 * coefficientData.b6) >> BMP180_CONSTANT_7;
+ coefficientData.x2 = (g_calibraData.b1 * ((coefficientData.b6 * coefficientData.b6) >> BMP180_CONSTANT_6))
+ >> BMP180_CONSTANT_9;
+ coefficientData.x3 = ((coefficientData.x1 + coefficientData.x2) + BMP180_CONSTANT_2) >> BMP180_CONSTANT_2;
+ coefficientData.b4 = (g_calibraData.ac4 * (uint32_t)(coefficientData.x3 + BMP180_CONSTANT_13))
+ >> BMP180_CONSTANT_8;
+ coefficientData.b7 = ((uint32_t)(barometerData->unpensatePre) - (uint32_t)coefficientData.b3)
+ * (BMP180_CONSTANT_14 >> OSSETTING);
+ if (coefficientData.b7 < BMP180_CONSTANT_15) {
+ coefficientData.p = (coefficientData.b7 << BMP180_CONSTANT_1) / coefficientData.b4;
+ } else {
+ coefficientData.p = (coefficientData.b7 / coefficientData.b4) << BMP180_CONSTANT_1;
+ }
+ coefficientData.x1 = (coefficientData.p >> BMP180_CONSTANT_4) * (coefficientData.p >> BMP180_CONSTANT_4);
+ coefficientData.x1 = (coefficientData.x1 * BMP180_CONSTANT_10) >> BMP180_CONSTANT_9;
+ coefficientData.x2 = (BMP180_CONSTANT_0 * coefficientData.p) >> BMP180_CONSTANT_9;
+ tnp[BAROMETER_BAROMETER] = coefficientData.p + ((coefficientData.x1 + coefficientData.x2
+ + BMP180_CONSTANT_11) >> BMP180_CONSTANT_3);
+
+ return HDF_SUCCESS;
+}
+
+int32_t ReadBmp180Data(struct SensorCfgData *data)
+{
+ int32_t ret;
+ int32_t tmp[BAROMETER_SUM];
+ struct BarometerRawData barometerData = {0, 0};
+ OsalTimespec time;
+ struct SensorReportEvent event;
+
+ (void)memset_s(&time, sizeof(time), 0, sizeof(time));
+ (void)memset_s(&event, sizeof(event), 0, sizeof(event));
+
+ if (OsalGetTime(&time) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Get time failed", __func__);
+ return HDF_FAILURE;
+ }
+ event.timestamp = time.sec * SENSOR_SECOND_CONVERT_NANOSECOND + time.usec * SENSOR_CONVERT_UNIT;
+
+ ret = ReadTempData(data, &barometerData);
+ if (ret != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ ret = ReadBarometerData(data, &barometerData);
+ if (ret != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ ret = CalcBarometerData(&barometerData, tmp);
+ if (ret != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ event.sensorId = SENSOR_TAG_BAROMETER;
+ event.option = 0;
+ event.mode = SENSOR_WORK_MODE_REALTIME;
+ event.dataLen = sizeof(tmp);
+ event.data = (uint8_t *)&tmp;
+ ret = ReportSensorEvent(&event);
+ return ret;
+}
+
+static int32_t InitBmp180(struct SensorCfgData *data)
+{
+ int32_t ret;
+ CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
+ struct SensorReportEvent event;
+
+ (void)memset_s(&event, sizeof(event), 0, sizeof(event));
+
+ ret = ReadEepromData(data, &g_calibraData);
+ if (ret != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ ret = SetSensorRegCfgArray(&data->busCfg, data->regCfgGroup[SENSOR_INIT_GROUP]);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: BMP180 sensor init config failed", __func__);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t InitBarometerPreConfig(void)
+{
+ if (SetSensorPinMux(SENSOR_I2C6_DATA_REG_ADDR, SENSOR_ADDR_WIDTH_4_BYTE, SENSOR_I2C_REG_CFG) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Data write mux pin failed", __func__);
+ return HDF_FAILURE;
+ }
+ if (SetSensorPinMux(SENSOR_I2C6_CLK_REG_ADDR, SENSOR_ADDR_WIDTH_4_BYTE, SENSOR_I2C_REG_CFG) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Clk write mux pin failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t DispatchBMP180(struct HdfDeviceIoClient *client,
+ int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ (void)client;
+ (void)cmd;
+ (void)data;
+ (void)reply;
+
+ return HDF_SUCCESS;
+}
+
+int32_t Bmp180BindDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
+
+ struct Bmp180DrvData *drvData = (struct Bmp180DrvData *)OsalMemCalloc(sizeof(*drvData));
+ if (drvData == NULL) {
+ HDF_LOGE("%s: Malloc Bmi160 drv data fail", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ drvData->ioService.Dispatch = DispatchBMP180;
+ drvData->device = device;
+ device->service = &drvData->ioService;
+ g_bmp180DrvData = drvData;
+
+ return HDF_SUCCESS;
+}
+
+int32_t Bmp180InitDriver(struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct BarometerOpsCall ops;
+
+ CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
+ struct Bmp180DrvData *drvData = (struct Bmp180DrvData *)device->service;
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+
+ ret = InitBarometerPreConfig();
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Init BMp180 bus mux config", __func__);
+ return HDF_FAILURE;
+ }
+
+ drvData->sensorCfg = BarometerCreateCfgData(device->property);
+ if (drvData->sensorCfg == NULL || drvData->sensorCfg->root == NULL) {
+ HDF_LOGD("%s: Creating barometercfg failed because detection failed", __func__);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ ops.Init = NULL;
+ ops.ReadData = ReadBmp180Data;
+ ret = BarometerRegisterChipOps(&ops);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Register BMp180 barometer failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ ret = InitBmp180(drvData->sensorCfg);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Init BMP180 barometer failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+void Bmp180ReleaseDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN(device);
+
+ struct Bmp180DrvData *drvData = (struct Bmp180DrvData *)device->service;
+ CHECK_NULL_PTR_RETURN(drvData);
+
+ if (drvData->sensorCfg != NULL) {
+ BarometerReleaseCfgData(drvData->sensorCfg);
+ drvData->sensorCfg = NULL;
+ }
+ OsalMemFree(drvData);
+}
+
+struct HdfDriverEntry g_barometerBmp180DevEntry = {
+ .moduleVersion = 1,
+ .moduleName = "HDF_SENSOR_BAROMETER_BMP180",
+ .Bind = Bmp180BindDriver,
+ .Init = Bmp180InitDriver,
+ .Release = Bmp180ReleaseDriver,
+};
+
HDF_INIT(g_barometerBmp180DevEntry);
\ No newline at end of file
diff --git a/model/sensor/driver/chipset/barometer/barometer_bmp180.h b/model/sensor/driver/chipset/barometer/barometer_bmp180.h
index a361405bfa00f6f941624da4e8b1241d93f480b8..c62e1aa1f3fbf5a4e40843368064cffbc60a0a50 100644
--- a/model/sensor/driver/chipset/barometer/barometer_bmp180.h
+++ b/model/sensor/driver/chipset/barometer/barometer_bmp180.h
@@ -1,96 +1,96 @@
-/*
- * Copyright (c) 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.
- */
-
-#ifndef BAROMETER_BMP180_H
-#define BAROMETER_BMP180_H
-
-#include "sensor_barometer_driver.h"
-#include "sensor_config_parser.h"
-
-#define BMP180_REG_CHIP_ID 0xD0
-
-// i2c slave address
-
-#define BMP180_ADDR 0x77
-
-// Define calibration register address
-
-#define BMP180_AC1_MSB_ADDR 0xAA
-#define BMP180_AC1_LSB_ADDR 0xAB
-#define BMP180_AC2_MSB_ADDR 0xAC
-#define BMP180_AC2_LSB_ADDR 0xAD
-#define BMP180_AC3_MSB_ADDR 0xAE
-#define BMP180_AC3_LSB_ADDR 0xAF
-#define BMP180_AC4_MSB_ADDR 0xB0
-#define BMP180_AC4_LSB_ADDR 0xB1
-#define BMP180_AC5_MSB_ADDR 0xB2
-#define BMP180_AC5_LSB_ADDR 0xB3
-#define BMP180_AC6_MSB_ADDR 0xB4
-#define BMP180_AC6_LSB_ADDR 0xB5
-#define BMP180_B1_MSB_ADDR 0xB6
-#define BMP180_B1_LSB_ADDR 0xB7
-#define BMP180_B2_MSB_ADDR 0xB8
-#define BMP180_B2_LSB_ADDR 0xB9
-#define BMP180_MB_MSB_ADDR 0xBA
-#define BMP180_MB_LSB_ADDR 0xBB
-#define BMP180_MC_MSB_ADDR 0xBC
-#define BMP180_MC_LSB_ADDR 0xBD
-#define BMP180_MD_MSB_ADDR 0xBE
-#define BMP180_MD_LSB_ADDR 0xBf
-
-// Control register
-
-#define BMP180_CONTROL_REG_ADDR 0xF4
-#define BMP180_COVERT_TEMP 0x2E
-#define BMP180_COVERT_PRES_0 0x34
-#define BMP180_COVERT_PRES_1 0x74
-#define BMP180_COVERT_PRES_2 0xB4
-#define BMP180_COVERT_PRES_3 0xF4
-
-#define BMP180_OUT_MSB_ADDR 0xF6
-#define BMP180_OUT_LSB_ADDR 0xF7
-#define BMP180_OUT_XLSB_ADDR 0xF8
-
-#define BMP180_STATUS_ADDR 0X20
-#define BMP180_STATUS_JUDGE 0X00
-
-#define SENSOR_DATA_WIDTH_16_BIT 16
-
-#define OSSETTING 1
-#define DELAY_0 5
-#define DELAY_1 8
-#define OSS_TIME_MS 26
-
-#define BMP180_CONSTANT_0 (-7357)
-#define BMP180_CONSTANT_1 1
-#define BMP180_CONSTANT_2 2
-#define BMP180_CONSTANT_3 4
-#define BMP180_CONSTANT_4 8
-#define BMP180_CONSTANT_5 11
-#define BMP180_CONSTANT_6 12
-#define BMP180_CONSTANT_7 13
-#define BMP180_CONSTANT_8 15
-#define BMP180_CONSTANT_9 16
-#define BMP180_CONSTANT_10 3038
-#define BMP180_CONSTANT_11 3791
-#define BMP180_CONSTANT_12 4000
-#define BMP180_CONSTANT_13 32768
-#define BMP180_CONSTANT_14 50000
-#define BMP180_CONSTANT_15 0x80000000
-
-
-int32_t DetectBarometerBmp180Chip(struct SensorCfgData *data);
-int32_t ReadBmp180Data(struct SensorCfgData *data);
-
-struct Bmp180DrvData {
- struct IDeviceIoService ioService;
- struct HdfDeviceObject *device;
- struct SensorCfgData *sensorCfg;
-};
-
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef BAROMETER_BMP180_H
+#define BAROMETER_BMP180_H
+
+#include "sensor_barometer_driver.h"
+#include "sensor_config_parser.h"
+
+#define BMP180_REG_CHIP_ID 0xD0
+
+// i2c slave address
+
+#define BMP180_ADDR 0x77
+
+// Define calibration register address
+
+#define BMP180_AC1_MSB_ADDR 0xAA
+#define BMP180_AC1_LSB_ADDR 0xAB
+#define BMP180_AC2_MSB_ADDR 0xAC
+#define BMP180_AC2_LSB_ADDR 0xAD
+#define BMP180_AC3_MSB_ADDR 0xAE
+#define BMP180_AC3_LSB_ADDR 0xAF
+#define BMP180_AC4_MSB_ADDR 0xB0
+#define BMP180_AC4_LSB_ADDR 0xB1
+#define BMP180_AC5_MSB_ADDR 0xB2
+#define BMP180_AC5_LSB_ADDR 0xB3
+#define BMP180_AC6_MSB_ADDR 0xB4
+#define BMP180_AC6_LSB_ADDR 0xB5
+#define BMP180_B1_MSB_ADDR 0xB6
+#define BMP180_B1_LSB_ADDR 0xB7
+#define BMP180_B2_MSB_ADDR 0xB8
+#define BMP180_B2_LSB_ADDR 0xB9
+#define BMP180_MB_MSB_ADDR 0xBA
+#define BMP180_MB_LSB_ADDR 0xBB
+#define BMP180_MC_MSB_ADDR 0xBC
+#define BMP180_MC_LSB_ADDR 0xBD
+#define BMP180_MD_MSB_ADDR 0xBE
+#define BMP180_MD_LSB_ADDR 0xBf
+
+// Control register
+
+#define BMP180_CONTROL_REG_ADDR 0xF4
+#define BMP180_COVERT_TEMP 0x2E
+#define BMP180_COVERT_PRES_0 0x34
+#define BMP180_COVERT_PRES_1 0x74
+#define BMP180_COVERT_PRES_2 0xB4
+#define BMP180_COVERT_PRES_3 0xF4
+
+#define BMP180_OUT_MSB_ADDR 0xF6
+#define BMP180_OUT_LSB_ADDR 0xF7
+#define BMP180_OUT_XLSB_ADDR 0xF8
+
+#define BMP180_STATUS_ADDR 0X20
+#define BMP180_STATUS_JUDGE 0X00
+
+#define SENSOR_DATA_WIDTH_16_BIT 16
+
+#define OSSETTING 1
+#define DELAY_0 5
+#define DELAY_1 8
+#define OSS_TIME_MS 26
+
+#define BMP180_CONSTANT_0 (-7357)
+#define BMP180_CONSTANT_1 1
+#define BMP180_CONSTANT_2 2
+#define BMP180_CONSTANT_3 4
+#define BMP180_CONSTANT_4 8
+#define BMP180_CONSTANT_5 11
+#define BMP180_CONSTANT_6 12
+#define BMP180_CONSTANT_7 13
+#define BMP180_CONSTANT_8 15
+#define BMP180_CONSTANT_9 16
+#define BMP180_CONSTANT_10 3038
+#define BMP180_CONSTANT_11 3791
+#define BMP180_CONSTANT_12 4000
+#define BMP180_CONSTANT_13 32768
+#define BMP180_CONSTANT_14 50000
+#define BMP180_CONSTANT_15 0x80000000
+
+
+int32_t DetectBarometerBmp180Chip(struct SensorCfgData *data);
+int32_t ReadBmp180Data(struct SensorCfgData *data);
+
+struct Bmp180DrvData {
+ struct IDeviceIoService ioService;
+ struct HdfDeviceObject *device;
+ struct SensorCfgData *sensorCfg;
+};
+
#endif /* BAROMETER_BMP180_H */
\ No newline at end of file
diff --git a/model/sensor/driver/chipset/gyro/gyro_bmi160.c b/model/sensor/driver/chipset/gyro/gyro_bmi160.c
index e4a8c366509ab6055b0fffc0a81da4741903f480..7f2abdb40a0a97b6acc5cfeda2a57c6916ba3dde 100644
--- a/model/sensor/driver/chipset/gyro/gyro_bmi160.c
+++ b/model/sensor/driver/chipset/gyro/gyro_bmi160.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * 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.
@@ -8,11 +8,21 @@
#include "gyro_bmi160.h"
#include
+#include "osal_mem.h"
#include "osal_time.h"
#include "sensor_gyro_driver.h"
#include "sensor_config_controller.h"
#include "sensor_device_manager.h"
+#define HDF_LOG_TAG gyro_bmi160_c
+
+static struct Bmi160DrvData *g_bmi160DrvData = NULL;
+
+struct Bmi160DrvData *GyroBmi160GetDrvData(void)
+{
+ return g_bmi160DrvData;
+}
+
/* IO config for int-pin and I2C-pin */
#define SENSOR_I2C6_DATA_REG_ADDR 0x114f004c
#define SENSOR_I2C6_CLK_REG_ADDR 0x114f0048
@@ -90,13 +100,18 @@ int32_t ReadBmi160GyroData(struct SensorCfgData *data)
tmp[GYRO_Y_AXIS] = rawData.y * BMI160_GYRO_SENSITIVITY_2000DPS;
tmp[GYRO_Z_AXIS] = rawData.z * BMI160_GYRO_SENSITIVITY_2000DPS;
+ ret = SensorRawDataToRemapData(data->direction, tmp, sizeof(tmp) / sizeof(tmp[0]));
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: BMI160 convert raw data failed", __func__);
+ return HDF_FAILURE;
+ }
+
event.dataLen = sizeof(tmp);
event.data = (uint8_t *)&tmp;
ret = ReportSensorEvent(&event);
return ret;
}
-
-static int32_t InitBmi160Gyro(struct SensorCfgData *data)
+static int32_t InitBmi160(struct SensorCfgData *data)
{
int32_t ret;
@@ -123,30 +138,94 @@ static int32_t InitGyroPreConfig(void)
return HDF_SUCCESS;
}
-int32_t DetectGyroBim160Chip(struct SensorCfgData *data)
+static int32_t DispatchBMI160(struct HdfDeviceIoClient *client,
+ int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ (void)client;
+ (void)cmd;
+ (void)data;
+ (void)reply;
+
+ return HDF_SUCCESS;
+}
+
+int32_t GyroBmi160BindDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
+
+ struct Bmi160DrvData *drvData = (struct Bmi160DrvData *)OsalMemCalloc(sizeof(*drvData));
+ if (drvData == NULL) {
+ HDF_LOGE("%s: Malloc Bmi160 drv data fail", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ drvData->ioService.Dispatch = DispatchBMI160;
+ drvData->device = device;
+ device->service = &drvData->ioService;
+ g_bmi160DrvData = drvData;
+
+ return HDF_SUCCESS;
+}
+
+int32_t GyroBmi160InitDriver(struct HdfDeviceObject *device)
{
int32_t ret;
struct GyroOpsCall ops;
- CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
- if (strcmp(GYRO_CHIP_NAME_BMI160, data->sensorAttr.chipName) != 0) {
- return HDF_SUCCESS;
- }
+ CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
+ struct Bmi160DrvData *drvData = (struct Bmi160DrvData *)device->service;
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+
ret = InitGyroPreConfig();
if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: init BMI160 bus mux config", __func__);
+ HDF_LOGE("%s: Init BMI160 bus mux config", __func__);
return HDF_FAILURE;
}
- if (DetectSensorDevice(data) != HDF_SUCCESS) {
- return HDF_FAILURE;
+
+ drvData->sensorCfg = GyroCreateCfgData(device->property);
+ if (drvData->sensorCfg == NULL || drvData->sensorCfg->root == NULL) {
+ HDF_LOGD("%s: Creating gyrocfg failed because detection failed", __func__);
+ return HDF_ERR_NOT_SUPPORT;
}
- ops.Init = InitBmi160Gyro;
+
+ ops.Init = NULL;
ops.ReadData = ReadBmi160GyroData;
- ret = RegisterGyroChipOps(&ops);
+ ret = GyroRegisterChipOps(&ops);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Register BMI160 gyro failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ ret = InitBmi160(drvData->sensorCfg);
if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: register BMI160 gyro failed", __func__);
- (void)ReleaseSensorBusHandle(&data->busCfg);
+ HDF_LOGE("%s: Init BMI160 gyro failed", __func__);
return HDF_FAILURE;
}
+
return HDF_SUCCESS;
}
+
+void GyroBmi160ReleaseDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN(device);
+
+ struct Bmi160DrvData *drvData = (struct Bmi160DrvData *)device->service;
+ CHECK_NULL_PTR_RETURN(drvData);
+
+ if (drvData->sensorCfg != NULL) {
+ GyroReleaseCfgData(drvData->sensorCfg);
+ drvData->sensorCfg = NULL;
+ }
+
+ OsalMemFree(drvData);
+}
+
+struct HdfDriverEntry g_gyroBmi160DevEntry = {
+ .moduleVersion = 1,
+ .moduleName = "HDF_SENSOR_GYRO_BMI160",
+ .Bind = GyroBmi160BindDriver,
+ .Init = GyroBmi160InitDriver,
+ .Release = GyroBmi160ReleaseDriver,
+};
+
+HDF_INIT(g_gyroBmi160DevEntry);
diff --git a/model/sensor/driver/chipset/gyro/gyro_bmi160.h b/model/sensor/driver/chipset/gyro/gyro_bmi160.h
index 5e71e306f2d6ab772499221421910212ef2461a4..564952c8443808801dc07795da6283e992ffa753 100644
--- a/model/sensor/driver/chipset/gyro/gyro_bmi160.h
+++ b/model/sensor/driver/chipset/gyro/gyro_bmi160.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * 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.
@@ -9,6 +9,7 @@
#ifndef GYRO_BMI160_H
#define GYRO_BMI160_H
+#include "sensor_gyro_driver.h"
#include "sensor_config_parser.h"
/* GYRO DATA REGISTERS ADDR */
@@ -51,4 +52,10 @@
int32_t DetectGyroBim160Chip(struct SensorCfgData *data);
int32_t ReadBmi160Data(struct SensorCfgData *data);
+struct Bmi160DrvData {
+ struct IDeviceIoService ioService;
+ struct HdfDeviceObject *device;
+ struct SensorCfgData *sensorCfg;
+};
+
#endif /* GYRO_BMI160_H */
diff --git a/model/sensor/driver/chipset/hall/hall_ak8789.c b/model/sensor/driver/chipset/hall/hall_ak8789.c
index adbd7838b506f8042219477d9a77f7ea673565aa..ba51bf0eb19bfd820b01a6c0d2389646ff39d10a 100755
--- a/model/sensor/driver/chipset/hall/hall_ak8789.c
+++ b/model/sensor/driver/chipset/hall/hall_ak8789.c
@@ -7,7 +7,6 @@
*/
#include "hall_ak8789.h"
-#include
#include "osal_irq.h"
#include "osal_mem.h"
#include "osal_time.h"
@@ -29,37 +28,6 @@ struct Ak8789DrvData *Ak8789GetDrvData(void)
#define SENSOR_HALL_CLK_REG_ADDR 0x114f0044
#define SENSOR_HALL_REG_CFG 0x400
-int32_t ReadAk8789Data(struct SensorCfgData *data)
-{
- int32_t ret;
- uint8_t tmp = 1;
- OsalTimespec time;
- struct SensorReportEvent event;
-
- CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
-
- (void)memset_s(&event, sizeof(event), 0, sizeof(event));
- (void)memset_s(&time, sizeof(time), 0, sizeof(time));
- if (OsalGetTime(&time) != HDF_SUCCESS) {
- HDF_LOGE("%s: Get time failed", __func__);
- return HDF_FAILURE;
- }
-
- event.timestamp = time.sec * SENSOR_SECOND_CONVERT_NANOSECOND + time.usec *
- SENSOR_CONVERT_UNIT; /* unit nanosecond */
- event.sensorId = SENSOR_TAG_HALL;
- event.version = 0;
- event.option = 0;
- event.mode = SENSOR_WORK_MODE_ON_CHANGE;
- event.dataLen = sizeof(tmp);
- event.data = (uint8_t *)&tmp;
- ret = ReportSensorEvent(&event);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: AK8789 report data failed", __func__);
- }
- return ret;
-}
-
static int32_t InitHallPreConfig(void)
{
if (SetSensorPinMux(SENSOR_HALL_DATA_REG_ADDR, SENSOR_ADDR_WIDTH_4_BYTE, SENSOR_HALL_REG_CFG) != HDF_SUCCESS) {
@@ -122,7 +90,7 @@ int32_t AK8789InitDriver(struct HdfDeviceObject *device)
}
ops.Init = NULL;
- ops.ReadData = ReadAk8789Data;
+ ops.ReadData = NULL;
ret = HallRegisterChipOps(&ops);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: Register AK8789 hall failed", __func__);
diff --git a/model/sensor/driver/chipset/magnetic/magnetic_lsm303.c b/model/sensor/driver/chipset/magnetic/magnetic_lsm303.c
new file mode 100755
index 0000000000000000000000000000000000000000..d006e14e81f3d2c0db02e9ad8255fd7e7f56a8fa
--- /dev/null
+++ b/model/sensor/driver/chipset/magnetic/magnetic_lsm303.c
@@ -0,0 +1,241 @@
+/*
+ * Copyright (c) 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 "magnetic_lsm303.h"
+#include
+#include "osal_mem.h"
+#include "osal_time.h"
+#include "sensor_config_controller.h"
+#include "sensor_device_manager.h"
+#include "sensor_magnetic_driver.h"
+
+static struct Lsm303DrvData *g_lsm303DrvData = NULL;
+
+struct Lsm303DrvData *Lsm303GetDrvData(void)
+{
+ return g_lsm303DrvData;
+}
+
+/* IO config for int-pin and I2C-pin */
+#define SENSOR_I2C6_DATA_REG_ADDR 0x114f004c
+#define SENSOR_I2C6_CLK_REG_ADDR 0x114f0048
+#define SENSOR_I2C_REG_CFG 0x403
+
+static int32_t ReadLsm303RawData(struct SensorCfgData *data, struct MagneticData *rawData, int64_t *timestamp)
+{
+ uint8_t status = 0;
+ uint8_t reg[MAGNETIC_AXIS_BUTT];
+ OsalTimespec time;
+
+ (void)memset_s(&time, sizeof(time), 0, sizeof(time));
+ (void)memset_s(reg, sizeof(reg), 0, sizeof(reg));
+
+ CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
+
+ if (OsalGetTime(&time) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Get time failed", __func__);
+ return HDF_FAILURE;
+ }
+ *timestamp = time.sec * SENSOR_SECOND_CONVERT_NANOSECOND + time.usec * SENSOR_CONVERT_UNIT; /* unit nanosecond */
+
+ int32_t ret = ReadSensor(&data->busCfg, LSM303_STATUS_ADDR, &status, sizeof(uint8_t));
+ if (!(status & LSM303_DATA_READY_MASK) || (ret != HDF_SUCCESS)) {
+ HDF_LOGE("%s: data status [%u] ret [%d]", __func__, status, ret);
+
+ return HDF_FAILURE;
+ }
+
+ ret = ReadSensor(&data->busCfg, LSM303_MAGNETIC_X_MSB_ADDR, ®[MAGNETIC_X_AXIS_MSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, LSM303_MAGNETIC_X_LSB_ADDR, ®[MAGNETIC_X_AXIS_LSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, LSM303_MAGNETIC_Y_MSB_ADDR, ®[MAGNETIC_Y_AXIS_MSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, LSM303_MAGNETIC_Y_LSB_ADDR, ®[MAGNETIC_Y_AXIS_LSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, LSM303_MAGNETIC_Z_MSB_ADDR, ®[MAGNETIC_Z_AXIS_MSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ ret = ReadSensor(&data->busCfg, LSM303_MAGNETIC_Z_LSB_ADDR, ®[MAGNETIC_Z_AXIS_LSB], sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ rawData->x = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[MAGNETIC_X_AXIS_MSB], SENSOR_DATA_WIDTH_8_BIT) |
+ reg[MAGNETIC_X_AXIS_LSB]);
+ rawData->y = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[MAGNETIC_Y_AXIS_MSB], SENSOR_DATA_WIDTH_8_BIT) |
+ reg[MAGNETIC_Y_AXIS_LSB]);
+ rawData->z = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[MAGNETIC_Z_AXIS_MSB], SENSOR_DATA_WIDTH_8_BIT) |
+ reg[MAGNETIC_Z_AXIS_LSB]);
+
+ return HDF_SUCCESS;
+}
+
+int32_t ReadLsm303Data(struct SensorCfgData *data)
+{
+ struct MagneticData rawData = { 0, 0, 0 };
+ int32_t tmp[MAGNETIC_AXIS_NUM];
+ struct SensorReportEvent event;
+
+ (void)memset_s(&event, sizeof(event), 0, sizeof(event));
+ (void)memset_s(tmp, sizeof(tmp), 0, sizeof(tmp));
+
+ CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
+
+ int32_t ret = ReadLsm303RawData(data, &rawData, &event.timestamp);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: LSM303 read raw data failed", __func__);
+
+ return HDF_FAILURE;
+ }
+
+ event.sensorId = SENSOR_TAG_MAGNETIC_FIELD;
+ event.option = 0;
+ event.mode = SENSOR_WORK_MODE_REALTIME;
+
+ tmp[MAGNETIC_X_AXIS] = rawData.x * LSM303_MAGNETIC_GIN / LSM303DLHC_SENSITIVITY_XY47GA;
+ tmp[MAGNETIC_Y_AXIS] = rawData.y * LSM303_MAGNETIC_GIN / LSM303DLHC_SENSITIVITY_XY47GA;
+ tmp[MAGNETIC_Z_AXIS] = rawData.z * LSM303_MAGNETIC_GIN / LSM303DLHC_SENSITIVITY_Z47GA;
+
+ ret = SensorRawDataToRemapData(data->direction, tmp, sizeof(tmp) / sizeof(tmp[0]));
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: LSM303 convert raw data failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ event.dataLen = sizeof(tmp);
+ event.data = (uint8_t *)&tmp;
+ ret = ReportSensorEvent(&event);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: LSM303 report data failed", __func__);
+ }
+
+ return ret;
+}
+
+static int32_t InitLsm303(struct SensorCfgData *data)
+{
+ int32_t ret;
+
+ CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
+
+ ret = SetSensorRegCfgArray(&data->busCfg, data->regCfgGroup[SENSOR_INIT_GROUP]);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Lsm303 sensor init config failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t InitMagneticPreConfig(void)
+{
+ if (SetSensorPinMux(SENSOR_I2C6_DATA_REG_ADDR, SENSOR_ADDR_WIDTH_4_BYTE, SENSOR_I2C_REG_CFG) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Data write mux pin failed", __func__);
+ return HDF_FAILURE;
+ }
+ if (SetSensorPinMux(SENSOR_I2C6_CLK_REG_ADDR, SENSOR_ADDR_WIDTH_4_BYTE, SENSOR_I2C_REG_CFG) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Clk write mux pin failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t DispatchLsm303(struct HdfDeviceIoClient *client,
+ int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ (void)client;
+ (void)cmd;
+ (void)data;
+ (void)reply;
+
+ return HDF_SUCCESS;
+}
+
+int32_t Lsm303BindDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
+
+ struct Lsm303DrvData *drvData = (struct Lsm303DrvData *)OsalMemCalloc(sizeof(*drvData));
+ if (drvData == NULL) {
+ HDF_LOGE("%s: Malloc Lsm303 drv data fail", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ drvData->ioService.Dispatch = DispatchLsm303;
+ drvData->device = device;
+ device->service = &drvData->ioService;
+ g_lsm303DrvData = drvData;
+
+ return HDF_SUCCESS;
+}
+
+int32_t Lsm303InitDriver(struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct MagneticOpsCall ops;
+
+ CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
+ struct Lsm303DrvData *drvData = (struct Lsm303DrvData *)device->service;
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+
+ ret = InitMagneticPreConfig();
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Init Lsm303 bus mux config", __func__);
+ return HDF_FAILURE;
+ }
+
+ drvData->sensorCfg = MagneticCreateCfgData(device->property);
+ if (drvData->sensorCfg == NULL || drvData->sensorCfg->root == NULL) {
+ HDF_LOGD("%s: Creating magneticcfg failed because detection failed", __func__);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ ops.Init = NULL;
+ ops.ReadData = ReadLsm303Data;
+ ret = MagneticRegisterChipOps(&ops);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Register lsm303 magnetic failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ ret = InitLsm303(drvData->sensorCfg);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Init lsm303 magnetic failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+void Lsm303ReleaseDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN(device);
+
+ struct Lsm303DrvData *drvData = (struct Lsm303DrvData *)device->service;
+ CHECK_NULL_PTR_RETURN(drvData);
+
+ if (drvData->sensorCfg != NULL) {
+ MagneticReleaseCfgData(drvData->sensorCfg);
+ drvData->sensorCfg = NULL;
+ }
+ OsalMemFree(drvData);
+}
+
+struct HdfDriverEntry g_magneticLsm303DevEntry = {
+ .moduleVersion = 1,
+ .moduleName = "HDF_SENSOR_MAGNETIC_LSM303",
+ .Bind = Lsm303BindDriver,
+ .Init = Lsm303InitDriver,
+ .Release = Lsm303ReleaseDriver,
+};
+
+HDF_INIT(g_magneticLsm303DevEntry);
\ No newline at end of file
diff --git a/model/sensor/driver/chipset/magnetic/magnetic_lsm303.h b/model/sensor/driver/chipset/magnetic/magnetic_lsm303.h
new file mode 100755
index 0000000000000000000000000000000000000000..6d20e19682b738632ac268446b19dbed5f2f551d
--- /dev/null
+++ b/model/sensor/driver/chipset/magnetic/magnetic_lsm303.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef MAGNETIC_LSM303_H
+#define MAGNETIC_LSM303_H
+
+#include "sensor_config_parser.h"
+#include "sensor_magnetic_driver.h"
+
+#define LSM303_MAGNETIC_GIN 1000
+
+/* MAGNETIC SET RATE AND MODE ADDR */
+#define LSM303_CRA_REG_ADDR 0X00
+#define LSM303_CRB_REG_ADDR 0X01
+#define LSM303_MR_REG_ADDR 0X02
+
+/* MAGNETIC DATA REGISTERS ADDR */
+#define LSM303_MAGNETIC_X_MSB_ADDR 0X03
+#define LSM303_MAGNETIC_X_LSB_ADDR 0X04
+#define LSM303_MAGNETIC_Y_MSB_ADDR 0X05
+#define LSM303_MAGNETIC_Y_LSB_ADDR 0X06
+#define LSM303_MAGNETIC_Z_MSB_ADDR 0X07
+#define LSM303_MAGNETIC_Z_LSB_ADDR 0X08
+#define LSM303_STATUS_ADDR 0X09
+
+/* MAGNETIC DATA RATE CONFIG HZ */
+#define LSM303_DATA_RATE_0 0X00
+#define LSM303_DATA_RATE_1 0X04
+#define LSM303_DATA_RATE_2 0X08
+#define LSM303_DATA_RATE_3 0X0C
+#define LSM303_DATA_RATE_4 0X10
+#define LSM303_DATA_RATE_5 0X14
+#define LSM303_DATA_RATE_6 0X18
+#define LSM303_DATA_RATE_7 0X1C
+
+/* MAGNETIC GAIN CONFIG GAUSS */
+#define LSM303_GAIN_RATE_0 0X20
+#define LSM303_GAIN_RATE_1 0X40
+#define LSM303_GAIN_RATE_2 0X60
+#define LSM303_GAIN_RATE_3 0X80
+#define LSM303_GAIN_RATE_4 0XA0
+#define LSM303_GAIN_RATE_5 0XC0
+#define LSM303_GAIN_RATE_6 0XE0
+
+/* MAGNETIC GAIN SENSITIVITY RANGE */
+#define LSM303DLHC_SENSITIVITY_XY13GA 1100
+#define LSM303DLHC_SENSITIVITY_XY19GA 855
+#define LSM303DLHC_SENSITIVITY_XY25GA 670
+#define LSM303DLHC_SENSITIVITY_XY40GA 450
+#define LSM303DLHC_SENSITIVITY_XY47GA 400
+#define LSM303DLHC_SENSITIVITY_XY56GA 330
+#define LSM303DLHC_SENSITIVITY_XY81GA 230
+#define LSM303DLHC_SENSITIVITY_Z13GA 980
+#define LSM303DLHC_SENSITIVITY_Z19GA 760
+#define LSM303DLHC_SENSITIVITY_Z25GA 600
+#define LSM303DLHC_SENSITIVITY_Z40GA 400
+#define LSM303DLHC_SENSITIVITY_Z47GA 355
+#define LSM303DLHC_SENSITIVITY_Z56GA 295
+#define LSM303DLHC_SENSITIVITY_Z81GA 205
+
+/* MAGNETIC MODE CONFIG */
+#define LSM303_OPERATING_MODE_1 0X00
+#define LSM303_OPERATING_MODE_2 0X01
+#define LSM303_OPERATING_MODE_3 0X02
+#define LSM303_OPERATING_MODE_4 0X03
+
+/* MAGNETIC DATA READY */
+#define LSM303_DATA_READY_MASK 0x01
+
+int32_t DetectMagneticLsm303Chip(struct SensorCfgData *data);
+int32_t ReadLsm303Data(struct SensorCfgData *data);
+
+struct Lsm303DrvData {
+ struct IDeviceIoService ioService;
+ struct HdfDeviceObject *device;
+ struct SensorCfgData *sensorCfg;
+};
+
+#endif /* MAGNETIC_LSM303_H */
\ No newline at end of file
diff --git a/model/sensor/driver/chipset/proximity/proximity_apds9960.c b/model/sensor/driver/chipset/proximity/proximity_apds9960.c
new file mode 100644
index 0000000000000000000000000000000000000000..d3eb9598cca18d72c1dd33e14f9a9cfbe7fd55c8
--- /dev/null
+++ b/model/sensor/driver/chipset/proximity/proximity_apds9960.c
@@ -0,0 +1,205 @@
+/*
+ * Copyright (c) 2021 xu
+ *
+ * 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 "proximity_apds9960.h"
+#include
+#include "osal_mem.h"
+#include "osal_time.h"
+#include "sensor_config_controller.h"
+#include "sensor_device_manager.h"
+#include "sensor_proximity_driver.h"
+
+#define HDF_LOG_TAG proximity_apds9960_c
+
+#define PROXIMITY_STATE_FAR 5
+#define PROXIMITY_STATE_NEAR 0
+
+static struct Apds9960DrvData *g_apds9960DrvData = NULL;
+
+struct Apds9960DrvData *Apds9960GetDrvData(void)
+{
+ return g_apds9960DrvData;
+}
+
+/* IO config for int-pin and I2C-pin */
+#define SENSOR_I2C6_DATA_REG_ADDR 0x114f004c
+#define SENSOR_I2C6_CLK_REG_ADDR 0x114f0048
+#define SENSOR_I2C_REG_CFG 0x403
+
+static int32_t ReadApds9960RawData(struct SensorCfgData *data, struct ProximityData *rawData, int64_t *timestamp)
+{
+ OsalTimespec time;
+
+ (void)memset_s(&time, sizeof(time), 0, sizeof(time));
+
+ CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
+
+ if (OsalGetTime(&time) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Get time failed", __func__);
+ return HDF_FAILURE;
+ }
+ *timestamp = time.sec * SENSOR_SECOND_CONVERT_NANOSECOND + time.usec * SENSOR_CONVERT_UNIT; /* unit nanosecond */
+
+ int32_t ret = ReadSensor(&data->busCfg, APDS9960_PROXIMITY_DATA_ADDR, &rawData->stateFlag, sizeof(uint8_t));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
+
+ return ret;
+}
+
+int32_t ReadApds9960Data(struct SensorCfgData *data)
+{
+ int32_t ret;
+ int32_t tmp;
+ struct ProximityData rawData = { 5 };
+ struct SensorReportEvent event;
+
+ (void)memset_s(&event, sizeof(event), 0, sizeof(event));
+
+ ret = ReadApds9960RawData(data, &rawData, &event.timestamp);
+ if (ret != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ event.sensorId = SENSOR_TAG_PROXIMITY;
+ event.option = 0;
+ event.mode = SENSOR_WORK_MODE_ON_CHANGE;
+
+ if (rawData.stateFlag <= APDS9960_PROXIMITY_THRESHOLD) {
+ tmp = PROXIMITY_STATE_FAR;
+ } else {
+ tmp = PROXIMITY_STATE_NEAR;
+ }
+
+ event.dataLen = sizeof(tmp);
+ event.data = (uint8_t *)&tmp;
+ ret = ReportSensorEvent(&event);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: APDS9960 report data failed", __func__);
+ }
+
+ return ret;
+}
+
+static int32_t InitApda9960(struct SensorCfgData *data)
+{
+ int32_t ret;
+
+ CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
+ ret = SetSensorRegCfgArray(&data->busCfg, data->regCfgGroup[SENSOR_INIT_GROUP]);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: APDS9960 sensor init config failed", __func__);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t InitProximityPreConfig(void)
+{
+ if (SetSensorPinMux(SENSOR_I2C6_DATA_REG_ADDR, SENSOR_ADDR_WIDTH_4_BYTE, SENSOR_I2C_REG_CFG) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Data write mux pin failed", __func__);
+ return HDF_FAILURE;
+ }
+ if (SetSensorPinMux(SENSOR_I2C6_CLK_REG_ADDR, SENSOR_ADDR_WIDTH_4_BYTE, SENSOR_I2C_REG_CFG) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Clk write mux pin failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t DispatchApds9960(struct HdfDeviceIoClient *client,
+ int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ (void)client;
+ (void)cmd;
+ (void)data;
+ (void)reply;
+
+ return HDF_SUCCESS;
+}
+
+int32_t Apds9960BindDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
+
+ struct Apds9960DrvData *drvData = (struct Apds9960DrvData *)OsalMemCalloc(sizeof(*drvData));
+ if (drvData == NULL) {
+ HDF_LOGE("%s: Malloc Apds9960 drv data fail", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ drvData->ioService.Dispatch = DispatchApds9960;
+ drvData->device = device;
+ device->service = &drvData->ioService;
+ g_apds9960DrvData = drvData;
+
+ return HDF_SUCCESS;
+}
+
+int32_t Apds996InitDriver(struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct ProximityOpsCall ops;
+
+ CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
+ struct Apds9960DrvData *drvData = (struct Apds9960DrvData *)device->service;
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+
+ ret = InitProximityPreConfig();
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Init APDS9960 bus mux config", __func__);
+ return HDF_FAILURE;
+ }
+
+ drvData->sensorCfg = ProximityCreateCfgData(device->property);
+ if (drvData->sensorCfg == NULL || drvData->sensorCfg->root == NULL) {
+ HDF_LOGD("%s: Creating proximitycfg failed because detection failed", __func__);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ ops.Init = NULL;
+ ops.ReadData = ReadApds9960Data;
+ ret = ProximityRegisterChipOps(&ops);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Register APDS9960 proximity failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ ret = InitApda9960(drvData->sensorCfg);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Init APDS9960 proximity failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+
+void Apds996ReleaseDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN(device);
+
+ struct Apds9960DrvData *drvData = (struct Apds9960DrvData *)device->service;
+ CHECK_NULL_PTR_RETURN(drvData);
+
+ if (drvData->sensorCfg != NULL) {
+ ProximityReleaseCfgData(drvData->sensorCfg);
+ drvData->sensorCfg = NULL;
+ }
+ OsalMemFree(drvData);
+}
+
+struct HdfDriverEntry g_proximityApds9960DevEntry = {
+ .moduleVersion = 1,
+ .moduleName = "HDF_SENSOR_PROXIMITY_APDS9960",
+ .Bind = Apds9960BindDriver,
+ .Init = Apds996InitDriver,
+ .Release = Apds996ReleaseDriver,
+};
+
+HDF_INIT(g_proximityApds9960DevEntry);
\ No newline at end of file
diff --git a/model/sensor/driver/chipset/proximity/proximity_apds9960.h b/model/sensor/driver/chipset/proximity/proximity_apds9960.h
new file mode 100644
index 0000000000000000000000000000000000000000..d1c1eece5bb4f9168a7006dd0bde6fb1b816902d
--- /dev/null
+++ b/model/sensor/driver/chipset/proximity/proximity_apds9960.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2021 xu
+ *
+ * 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.
+ */
+
+#ifndef PROXIMITY_APDS9960_H
+#define PROXIMITY_APDS9960_H
+
+#include "sensor_config_parser.h"
+#include "sensor_proximity_driver.h"
+
+#define APDS9960_PROXIMITY_DATA_ADDR 0X9C // Proximity Data
+
+#define APDS9960_PROXIMITY_THRESHOLD 7 // threshold
+
+int32_t DetectProximityApds9960Chip(struct SensorCfgData *data);
+int32_t ReadApds9960Data(struct SensorCfgData *data);
+
+struct Apds9960DrvData {
+ struct IDeviceIoService ioService;
+ struct HdfDeviceObject *device;
+ struct SensorCfgData *sensorCfg;
+};
+
+#endif /* PROXIMITY_APDS9960_H */
\ No newline at end of file
diff --git a/model/sensor/driver/common/include/sensor_config_controller.h b/model/sensor/driver/common/include/sensor_config_controller.h
index 9521f7dc5f53391f3da72752b108145ab546a2dd..07165e1971516ba10c63682c25c1d696bc5eaaf1 100644
--- a/model/sensor/driver/common/include/sensor_config_controller.h
+++ b/model/sensor/driver/common/include/sensor_config_controller.h
@@ -11,6 +11,8 @@
#include "sensor_config_parser.h"
+#define LENGTH_NUMBER 32
+
enum SensorCalculateType {
SENSOR_CFG_CALC_TYPE_NONE = 0,
SENSOR_CFG_CALC_TYPE_SET = 1, // To Support:1.Bitwise AND "&" 2.Bitwise OR "|"
@@ -26,6 +28,8 @@ enum SensorOpsType {
SENSOR_OPS_TYPE_WRITE = 2,
SENSOR_OPS_TYPE_READ_CHECK = 3,
SENSOR_OPS_TYPE_UPDATE_BITWISE = 4,
+ SENSOR_OPS_TYPE_EXTBUFF_READ = 5,
+ SENSOR_OPS_TYPE_EXTBUFF_WRITE = 6,
};
struct SensorOpsCall {
@@ -34,5 +38,10 @@ struct SensorOpsCall {
};
int32_t SetSensorRegCfgArray(struct SensorBusCfg *busCfg, const struct SensorRegCfgGroupNode *group);
-
-#endif /* SENSOR_CONFIG_CONTROLLER_H */
+int32_t SetSensorRegCfgArrayByBuff(struct SensorBusCfg *busCfg, const struct SensorRegCfgGroupNode *group,
+ uint8_t *buff, int16_t len);
+int32_t ReadSensorRegCfgArray(struct SensorBusCfg *busCfg, const struct SensorRegCfgGroupNode *group,
+ int32_t index, uint8_t *buf, int32_t len);
+int32_t WriteSensorRegCfgArray(struct SensorBusCfg *busCfg, const struct SensorRegCfgGroupNode *group,
+ int32_t index, int32_t len);
+#endif /* SENSOR_CONFIG_CONTROLLER_H */
\ No newline at end of file
diff --git a/model/sensor/driver/common/include/sensor_config_parser.h b/model/sensor/driver/common/include/sensor_config_parser.h
index 27ff0b1c4a06531e3cb7a2fb0b84fd5a8aebe84e..127add386296cadcd6cb37d66fb931848aff2ec7 100644
--- a/model/sensor/driver/common/include/sensor_config_parser.h
+++ b/model/sensor/driver/common/include/sensor_config_parser.h
@@ -17,6 +17,8 @@
#include "spi_if.h"
#define SENSOR_CONFIG_MAX_ITEM 100
+#define MAX_SENSOR_INDEX_NUM 48
+#define MAX_SENSOR_AXIS_NUM 3
enum SensorRegOpsType {
SENSOR_INIT_GROUP = 0,
@@ -47,7 +49,10 @@ enum SensorRegCfgIndex {
struct SensorRegCfg {
uint16_t regAddr;
- uint16_t value;
+ union {
+ uint16_t value;
+ uint8_t *buff;
+ };
uint16_t mask;
uint16_t len;
uint32_t delay : 12;
@@ -63,12 +68,35 @@ struct SensorRegCfgGroupNode {
struct SensorRegCfg *regCfgItem;
};
+struct SensorDirection {
+ uint32_t sign[MAX_SENSOR_AXIS_NUM];
+ uint32_t map[MAX_SENSOR_AXIS_NUM];
+};
+
+enum SensorDirectionIndex {
+ SIGN_X_INDEX = 0,
+ SIGN_Y_INDEX,
+ SIGN_Z_INDEX,
+ AXIS_X_INDEX,
+ AXIS_Y_INDEX,
+ AXIS_Z_INDEX,
+ AXIS_INDEX_MAX,
+};
+
+enum AxisNum {
+ AXIS_X = 0,
+ AXIS_Y = 1,
+ AXIS_Z = 2,
+};
+
struct SensorCfgData {
struct SensorBusCfg busCfg;
struct SensorBasicInfo sensorInfo;
struct SensorAttr sensorAttr;
struct SensorRegCfgGroupNode **regCfgGroup;
+ struct SensorRegCfgGroupNode **extendedRegCfgGroup;
const struct DeviceResourceNode *root;
+ struct SensorDirection *direction;
};
int32_t GetSensorBaseConfigData(const struct DeviceResourceNode *node, struct SensorCfgData *config);
@@ -77,5 +105,10 @@ void ReleaseSensorAllRegConfig(struct SensorCfgData *config);
int32_t GetSensorBusHandle(struct SensorBusCfg *busCfg);
int32_t ReleaseSensorBusHandle(struct SensorBusCfg *busCfg);
int32_t DetectSensorDevice(struct SensorCfgData *config);
+int32_t SensorRawDataToRemapData(struct SensorDirection *direction, int32_t *remapData, uint32_t num);
+void ReleaseSensorDirectionConfig(struct SensorCfgData *config);
+int32_t ParseSensorDirection(struct SensorCfgData *config);
+int32_t ParseSensorRegGroup(struct DeviceResourceIface *parser, const struct DeviceResourceNode *regCfgNode,
+ const char *groupName, struct SensorRegCfgGroupNode **groupNode);
#endif /* SENSOR_CONFIG_PARSER_H */
diff --git a/model/sensor/driver/common/src/sensor_config_controller.c b/model/sensor/driver/common/src/sensor_config_controller.c
index d0e7c07f8f0e4e065391b5e45e3f9996aef961ad..c70b641a7609e5499fcd2aea19a4ea87753c5864 100644
--- a/model/sensor/driver/common/src/sensor_config_controller.c
+++ b/model/sensor/driver/common/src/sensor_config_controller.c
@@ -52,25 +52,20 @@ static uint32_t GetSensorRegRealValueMask(struct SensorRegCfg *cfgItem, uint32_t
static int32_t SensorOpsWrite(struct SensorBusCfg *busCfg, struct SensorRegCfg *cfgItem)
{
- uint8_t calType = cfgItem->calType;
uint8_t value[SENSOR_VALUE_BUTT];
- int32_t ret = HDF_FAILURE;
+ int32_t ret;
+ uint32_t originValue;
+ uint32_t busMask;
+ uint32_t mask;
+
+ busMask = (busCfg->i2cCfg.regWidth == SENSOR_ADDR_WIDTH_1_BYTE) ? 0x00ff : 0xffff;
+ mask = GetSensorRegRealValueMask(cfgItem, &originValue, busMask);
value[SENSOR_ADDR_INDEX] = cfgItem->regAddr;
- value[SENSOR_VALUE_INDEX] = cfgItem->value;
+ value[SENSOR_VALUE_INDEX] = originValue & mask;
- switch (calType) {
- case SENSOR_CFG_CALC_TYPE_NONE:
- ret = WriteSensor(busCfg, value, sizeof(value));
- break;
- case SENSOR_CFG_CALC_TYPE_SET:
- case SENSOR_CFG_CALC_TYPE_REVERT:
- case SENSOR_CFG_CALC_TYPE_XOR:
- case SENSOR_CFG_CALC_TYPE_LEFT_SHIFT:
- case SENSOR_CFG_CALC_TYPE_RIGHT_SHIFT:
- default:
- break;
- }
+ ret = WriteSensor(busCfg, value, sizeof(value));
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "write i2c reg");
return ret;
}
@@ -106,8 +101,9 @@ static int32_t SensorBitwiseCalculate(struct SensorRegCfg *cfgItem, uint32_t *va
uint32_t tmp;
mask = GetSensorRegRealValueMask(cfgItem, &originValue, valueMask);
- switch ((enum SensorCalculateType)cfgItem->calType)
- {
+ switch ((enum SensorCalculateType)cfgItem->calType) {
+ case SENSOR_CFG_CALC_TYPE_NONE:
+ break;
case SENSOR_CFG_CALC_TYPE_SET:
*value &= ~mask;
*value |= (originValue & mask);
@@ -117,10 +113,18 @@ static int32_t SensorBitwiseCalculate(struct SensorRegCfg *cfgItem, uint32_t *va
*value = ~(*value & mask);
*value = tmp | (*value & mask);
break;
+ case SENSOR_CFG_CALC_TYPE_XOR:
+ tmp = *value & (~mask);
+ originValue = originValue & mask;
+ *value = *value & mask;
+ *value ^= originValue;
+ *value = tmp | (*value);
+ break;
default:
HDF_LOGE("%s: unsupported cal type", __func__);
break;
}
+
return 0;
}
@@ -151,12 +155,63 @@ static int32_t SensorOpsUpdateBitwise(struct SensorBusCfg *busCfg, struct Sensor
return HDF_SUCCESS;
}
+static int32_t SensorOpsExtBuffRead(struct SensorBusCfg *busCfg, struct SensorRegCfg *cfgItem)
+{
+ int32_t ret;
+
+ CHECK_NULL_PTR_RETURN_VALUE(busCfg, HDF_FAILURE);
+ CHECK_NULL_PTR_RETURN_VALUE(cfgItem, HDF_FAILURE);
+ CHECK_NULL_PTR_RETURN_VALUE(cfgItem->buff, HDF_FAILURE);
+
+ if (busCfg->busType == SENSOR_BUS_I2C) {
+ ret = ReadSensor(busCfg, cfgItem->regAddr, cfgItem->buff, cfgItem->len);
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read i2c reg");
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SensorOpsExtBuffWrite(struct SensorBusCfg *busCfg, struct SensorRegCfg *cfgItem)
+{
+ int32_t ret;
+ uint8_t *value = NULL;
+
+ CHECK_NULL_PTR_RETURN_VALUE(busCfg, HDF_FAILURE);
+ CHECK_NULL_PTR_RETURN_VALUE(cfgItem, HDF_FAILURE);
+
+ if (cfgItem->len > LENGTH_NUMBER) {
+ return HDF_FAILURE;
+ }
+ value = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * (cfgItem->len + 1));
+ CHECK_NULL_PTR_RETURN_VALUE(value, HDF_FAILURE);
+
+ value[SENSOR_ADDR_INDEX] = cfgItem->regAddr;
+ if (memcpy_s(&value[SENSOR_VALUE_INDEX], cfgItem->len, cfgItem->buff, cfgItem->len) != EOK) {
+ HDF_LOGE("%s: Cpy value failed", __func__);
+ OsalMemFree(value);
+ return HDF_FAILURE;
+ }
+
+ if (busCfg->busType == SENSOR_BUS_I2C) {
+ ret = WriteSensor(busCfg, value, cfgItem->len);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: write ext register failed", __func__);
+ OsalMemFree(value);
+ return HDF_FAILURE;
+ }
+ }
+ OsalMemFree(value);
+ return HDF_SUCCESS;
+}
+
static struct SensorOpsCall g_doOpsCall[] = {
{ SENSOR_OPS_TYPE_NOP, SensorOpsNop },
{ SENSOR_OPS_TYPE_READ, SensorOpsRead },
{ SENSOR_OPS_TYPE_WRITE, SensorOpsWrite },
{ SENSOR_OPS_TYPE_READ_CHECK, SensorOpsReadCheck },
{ SENSOR_OPS_TYPE_UPDATE_BITWISE, SensorOpsUpdateBitwise },
+ { SENSOR_OPS_TYPE_EXTBUFF_READ, SensorOpsExtBuffRead },
+ { SENSOR_OPS_TYPE_EXTBUFF_WRITE, SensorOpsExtBuffWrite },
};
int32_t SetSensorRegCfgArray(struct SensorBusCfg *busCfg, const struct SensorRegCfgGroupNode *group)
@@ -166,7 +221,12 @@ int32_t SetSensorRegCfgArray(struct SensorBusCfg *busCfg, const struct SensorReg
struct SensorRegCfg *cfgItem = NULL;
CHECK_NULL_PTR_RETURN_VALUE(busCfg, HDF_FAILURE);
- CHECK_NULL_PTR_RETURN_VALUE(group, HDF_FAILURE);
+
+ if (group == NULL) {
+ HDF_LOGI("%s: Pointer group is null", __func__);
+ return HDF_SUCCESS;
+ }
+
CHECK_NULL_PTR_RETURN_VALUE(group->regCfgItem, HDF_FAILURE);
count = sizeof(g_doOpsCall) / sizeof(g_doOpsCall[0]);
@@ -177,7 +237,7 @@ int32_t SetSensorRegCfgArray(struct SensorBusCfg *busCfg, const struct SensorReg
HDF_LOGE("%s: cfg item para invalid", __func__);
break;
}
- if (g_doOpsCall[cfgItem->opsType].ops != NULL) {
+ if ((g_doOpsCall[cfgItem->opsType].ops != NULL) && (cfgItem->opsType <= SENSOR_OPS_TYPE_UPDATE_BITWISE)) {
if (g_doOpsCall[cfgItem->opsType].ops(busCfg, cfgItem) != HDF_SUCCESS) {
HDF_LOGE("%s: malloc sensor reg config item data failed", __func__);
return HDF_FAILURE;
@@ -191,3 +251,94 @@ int32_t SetSensorRegCfgArray(struct SensorBusCfg *busCfg, const struct SensorReg
return HDF_SUCCESS;
}
+
+int32_t SetSensorRegCfgArrayByBuff(struct SensorBusCfg *busCfg, const struct SensorRegCfgGroupNode *group,
+ uint8_t *buff, int16_t len)
+{
+ int32_t num = 0;
+ uint32_t count;
+ uint8_t buffOffset = 0;
+ struct SensorRegCfg *cfgItem = NULL;
+
+ CHECK_NULL_PTR_RETURN_VALUE(busCfg, HDF_FAILURE);
+ CHECK_NULL_PTR_RETURN_VALUE(group, HDF_FAILURE);
+ CHECK_NULL_PTR_RETURN_VALUE(group->regCfgItem, HDF_FAILURE);
+ CHECK_NULL_PTR_RETURN_VALUE(buff, HDF_FAILURE);
+
+ count = sizeof(g_doOpsCall) / sizeof(g_doOpsCall[0]);
+
+ while (num < group->itemNum) {
+ cfgItem = (group->regCfgItem + num);
+ if (cfgItem->opsType >= count) {
+ HDF_LOGE("%s: cfg item para invalid", __func__);
+ return HDF_FAILURE;
+ }
+
+ if ((g_doOpsCall[cfgItem->opsType].ops != NULL) && (cfgItem->opsType >= SENSOR_OPS_TYPE_EXTBUFF_READ)) {
+ cfgItem->buff = buff + buffOffset;
+ len -= (int16_t)cfgItem->len;
+ if (len < 0) {
+ HDF_LOGE("%s: cfg item para invalid", __func__);
+ return HDF_FAILURE;
+ }
+ if (g_doOpsCall[cfgItem->opsType].ops(busCfg, cfgItem) != HDF_SUCCESS) {
+ HDF_LOGE("%s: extbuff is read and write failed", __func__);
+ return HDF_FAILURE;
+ }
+ buffOffset += cfgItem->len;
+ if (cfgItem->delay != 0) {
+ OsalMDelay(cfgItem->delay);
+ }
+ }
+
+ num++;
+ }
+
+ return HDF_SUCCESS;
+}
+
+int32_t ReadSensorRegCfgArray(struct SensorBusCfg *busCfg, const struct SensorRegCfgGroupNode *group,
+ int32_t index, uint8_t *buf, int32_t len)
+{
+ int32_t ret;
+ struct SensorRegCfg *cfgItem = NULL;
+
+ CHECK_NULL_PTR_RETURN_VALUE(busCfg, HDF_FAILURE);
+ CHECK_NULL_PTR_RETURN_VALUE(group, HDF_FAILURE);
+ CHECK_NULL_PTR_RETURN_VALUE(group->regCfgItem, HDF_FAILURE);
+
+ if ((index >= group->itemNum) || index < 0) {
+ HDF_LOGE("%s: Index is invalid parameter", __func__);
+ return HDF_FAILURE;
+ }
+
+ cfgItem = group->regCfgItem + index;
+ len = (cfgItem->len > len) ? len : cfgItem->len;
+
+ ret = ReadSensor(busCfg, cfgItem->regAddr, buf, len);
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read i2c reg");
+
+ return HDF_SUCCESS;
+}
+
+int32_t WriteSensorRegCfgArray(struct SensorBusCfg *busCfg, const struct SensorRegCfgGroupNode *group,
+ int32_t index, int32_t len)
+{
+ struct SensorRegCfg *cfgItem = NULL;
+
+ CHECK_NULL_PTR_RETURN_VALUE(busCfg, HDF_FAILURE);
+ CHECK_NULL_PTR_RETURN_VALUE(group, HDF_FAILURE);
+ CHECK_NULL_PTR_RETURN_VALUE(group->regCfgItem, HDF_FAILURE);
+
+ if ((index >= group->itemNum) || index < 0) {
+ HDF_LOGE("%s: Index is invalid parameter", __func__);
+ return HDF_FAILURE;
+ }
+
+ cfgItem = group->regCfgItem + index;
+
+ int32_t ret = SensorOpsUpdateBitwise(busCfg, cfgItem);
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "Write i2c reg");
+
+ return HDF_SUCCESS;
+}
\ No newline at end of file
diff --git a/model/sensor/driver/common/src/sensor_config_parser.c b/model/sensor/driver/common/src/sensor_config_parser.c
index 31efd2f1361ca2ec98d21c19a5ead6f01489f73a..a5c52e0bdd58e6bf1cd8dd2e72ae6f04c496247f 100644
--- a/model/sensor/driver/common/src/sensor_config_parser.c
+++ b/model/sensor/driver/common/src/sensor_config_parser.c
@@ -63,18 +63,20 @@ static int32_t ParseSensorRegItem(struct DeviceResourceIface *parser, const stru
int32_t ret;
int32_t step;
int32_t index;
+ int32_t num;
int32_t itemNum = group->itemNum;
+ uint16_t *buf = NULL;
CHECK_NULL_PTR_RETURN_VALUE(group->regCfgItem, HDF_ERR_INVALID_PARAM);
CHECK_NULL_PTR_RETURN_VALUE(groupName, HDF_ERR_INVALID_PARAM);
- int32_t num = parser->GetElemNum(regNode, groupName);
+ num = parser->GetElemNum(regNode, groupName);
if (num <= 0 || num > SENSOR_CONFIG_MAX_ITEM) {
HDF_LOGE("%s: parser %s element num failed", __func__, groupName);
return HDF_SUCCESS;
}
- uint16_t *buf = (uint16_t *)OsalMemCalloc(sizeof(uint16_t) * num);
+ buf = (uint16_t *)OsalMemCalloc(sizeof(uint16_t) * num);
CHECK_NULL_PTR_RETURN_VALUE(buf, HDF_ERR_MALLOC_FAIL);
ret = parser->GetUint16Array(regNode, groupName, buf, num, 0);
@@ -105,9 +107,10 @@ static int32_t ParseSensorRegItem(struct DeviceResourceIface *parser, const stru
return HDF_SUCCESS;
}
-static int32_t ParseSensorRegGroup(struct DeviceResourceIface *parser, const struct DeviceResourceNode *regCfgNode,
+int32_t ParseSensorRegGroup(struct DeviceResourceIface *parser, const struct DeviceResourceNode *regCfgNode,
const char *groupName, struct SensorRegCfgGroupNode **groupNode)
{
+ int32_t num;
struct SensorRegCfgGroupNode *group = NULL;
CHECK_NULL_PTR_RETURN_VALUE(parser, HDF_ERR_INVALID_PARAM);
@@ -115,7 +118,7 @@ static int32_t ParseSensorRegGroup(struct DeviceResourceIface *parser, const str
CHECK_NULL_PTR_RETURN_VALUE(groupName, HDF_ERR_INVALID_PARAM);
CHECK_NULL_PTR_RETURN_VALUE(groupNode, HDF_ERR_INVALID_PARAM);
- int32_t num = parser->GetElemNum(regCfgNode, groupName);
+ num = parser->GetElemNum(regCfgNode, groupName);
group = *groupNode;
if (num > 0) {
@@ -246,13 +249,14 @@ int32_t DetectSensorDevice(struct SensorCfgData *config)
uint8_t value = 0;
uint16_t chipIdReg;
uint16_t chipIdValue;
+ int32_t ret;
CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM);
chipIdReg = config->sensorAttr.chipIdReg;
chipIdValue = config->sensorAttr.chipIdValue;
- int32_t ret = GetSensorBusHandle(&config->busCfg);
+ ret = GetSensorBusHandle(&config->busCfg);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: get sensor bus handle failed", __func__);
(void)ReleaseSensorBusHandle(&config->busCfg);
@@ -280,6 +284,8 @@ static int32_t ParseSensorInfo(struct DeviceResourceIface *parser, const struct
struct SensorCfgData *config)
{
int32_t ret;
+ uint16_t id;
+ int32_t value;
const char *name = NULL;
ret = parser->GetString(infoNode, "sensorName", &name, NULL);
@@ -310,7 +316,6 @@ static int32_t ParseSensorInfo(struct DeviceResourceIface *parser, const struct
return HDF_FAILURE;
}
- uint16_t id;
ret = parser->GetUint16(infoNode, "sensorTypeId", &id, 0);
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorTypeId");
config->sensorInfo.sensorTypeId = id;
@@ -318,7 +323,6 @@ static int32_t ParseSensorInfo(struct DeviceResourceIface *parser, const struct
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorId");
config->sensorInfo.sensorId = id;
- int32_t value;
ret = parser->GetUint32(infoNode, "maxRange", (uint32_t *)&value, 0);
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "maxRange");
config->sensorInfo.maxRange = value;
@@ -354,6 +358,11 @@ static int32_t ParseSensorBus(struct DeviceResourceIface *parser, const struct D
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "busNum");
ret = parser->GetUint32(busNode, "busAddr", &config->busCfg.spiCfg.csNum, 0);
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "busAddr");
+ } else if (config->busCfg.busType == SENSOR_BUS_GPIO) {
+ ret = parser->GetUint32(busNode, "gpioIrq1", &config->busCfg.GpioNum[SENSOR_GPIO_NUM1], 0);
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "gpioIrq1");
+ ret = parser->GetUint32(busNode, "gpioIrq2", &config->busCfg.GpioNum[SENSOR_GPIO_NUM2], 0);
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "gpioIrq2");
}
return HDF_SUCCESS;
@@ -373,10 +382,102 @@ static int32_t ParseSensorAttr(struct DeviceResourceIface *parser, const struct
return ret;
}
+void ReleaseSensorDirectionConfig(struct SensorCfgData *config)
+{
+ CHECK_NULL_PTR_RETURN(config);
+
+ if (config->direction != NULL) {
+ OsalMemFree(config->direction);
+ config->direction = NULL;
+ }
+}
+
+int32_t ParseSensorDirection(struct SensorCfgData *config)
+{
+ int32_t num;
+ int32_t ret;
+ uint32_t index;
+ uint32_t *buf = NULL;
+ const struct DeviceResourceNode *directionNode = NULL;
+ struct DeviceResourceIface *parser = NULL;
+
+ CHECK_NULL_PTR_RETURN_VALUE(config->root, HDF_ERR_INVALID_PARAM);
+ parser = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ CHECK_NULL_PTR_RETURN_VALUE(parser, HDF_ERR_INVALID_PARAM);
+
+ directionNode = parser->GetChildNode(config->root, "sensorDirection");
+ CHECK_NULL_PTR_RETURN_VALUE(directionNode, HDF_ERR_INVALID_PARAM);
+
+ num = parser->GetElemNum(directionNode, "convert");
+ ret = parser->GetUint32(directionNode, "direction", &index, 0);
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "direction");
+ if ((num <= 0 || num > MAX_SENSOR_INDEX_NUM) || (index < 0 || index > num / AXIS_INDEX_MAX)) {
+ return HDF_FAILURE;
+ }
+
+ buf = (uint32_t *)OsalMemCalloc(sizeof(uint32_t) * num);
+ CHECK_NULL_PTR_RETURN_VALUE(buf, HDF_ERR_MALLOC_FAIL);
+
+ ret = parser->GetUint32Array(directionNode, "convert", buf, num, 0);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: parser %s convert failed", __func__, "convert");
+ OsalMemFree(buf);
+ return HDF_FAILURE;
+ }
+
+ config->direction = (struct SensorDirection*)OsalMemCalloc(sizeof(struct SensorDirection));
+ if (config->direction == NULL) {
+ HDF_LOGE("%s: malloc sensor direction config item failed", __func__);
+ OsalMemFree(buf);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ index = index * AXIS_INDEX_MAX;
+ config->direction->sign[AXIS_X] = buf[index + SIGN_X_INDEX];
+ config->direction->sign[AXIS_Y] = buf[index + SIGN_Y_INDEX];
+ config->direction->sign[AXIS_Z] = buf[index + SIGN_Z_INDEX];
+ config->direction->map[AXIS_X] = buf[index + AXIS_X_INDEX];
+ config->direction->map[AXIS_Y] = buf[index + AXIS_Y_INDEX];
+ config->direction->map[AXIS_Z] = buf[index + AXIS_Z_INDEX];
+
+ OsalMemFree(buf);
+ return HDF_SUCCESS;
+}
+
+int32_t SensorRawDataToRemapData(struct SensorDirection *direction, int32_t *remapData, uint32_t num)
+{
+ int32_t axis;
+ int32_t directionSign[MAX_SENSOR_AXIS_NUM];
+ int32_t newData[MAX_SENSOR_AXIS_NUM];
+
+ CHECK_NULL_PTR_RETURN_VALUE(direction, HDF_ERR_INVALID_PARAM);
+
+ for (axis = 0; axis < num; axis++) {
+ if (direction->sign[axis] == 0) {
+ directionSign[axis] = 1;
+ } else {
+ directionSign[axis] = -1;
+ }
+ }
+
+ newData[direction->map[AXIS_X]] = directionSign[AXIS_X] * remapData[AXIS_X];
+ newData[direction->map[AXIS_Y]] = directionSign[AXIS_Y] * remapData[AXIS_Y];
+ newData[direction->map[AXIS_Z]] = directionSign[AXIS_Z] * remapData[AXIS_Z];
+
+ remapData[AXIS_X] = newData[direction->map[AXIS_X]];
+ remapData[AXIS_Y] = newData[direction->map[AXIS_Y]];
+ remapData[AXIS_Z] = newData[direction->map[AXIS_Z]];
+
+ return HDF_SUCCESS;
+}
+
int32_t GetSensorBaseConfigData(const struct DeviceResourceNode *node, struct SensorCfgData *config)
{
int32_t ret;
struct DeviceResourceIface *parser = NULL;
+ const struct DeviceResourceNode *infoNode = NULL;
+ const struct DeviceResourceNode *busNode = NULL;
+ const struct DeviceResourceNode *attrNode = NULL;
CHECK_NULL_PTR_RETURN_VALUE(node, HDF_ERR_INVALID_PARAM);
CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM);
@@ -387,19 +488,19 @@ int32_t GetSensorBaseConfigData(const struct DeviceResourceNode *node, struct Se
config->root = node;
CHECK_NULL_PTR_RETURN_VALUE(parser->GetChildNode, HDF_ERR_INVALID_PARAM);
- const struct DeviceResourceNode *infoNode = parser->GetChildNode(node, "sensorInfo");
+ infoNode = parser->GetChildNode(node, "sensorInfo");
if (infoNode != NULL) {
ret = ParseSensorInfo(parser, infoNode, config);
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorInfo");
}
- const struct DeviceResourceNode *busNode = parser->GetChildNode(node, "sensorBusConfig");
+ busNode = parser->GetChildNode(node, "sensorBusConfig");
if (busNode != NULL) {
ret = ParseSensorBus(parser, busNode, config);
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorBusConfig");
}
- const struct DeviceResourceNode *attrNode = parser->GetChildNode(node, "sensorIdAttr");
+ attrNode = parser->GetChildNode(node, "sensorIdAttr");
if (attrNode != NULL) {
ret = ParseSensorAttr(parser, attrNode, config);
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorIdAttr");
diff --git a/model/sensor/driver/common/src/sensor_device_manager.c b/model/sensor/driver/common/src/sensor_device_manager.c
index 8c3389392029b559e09845fdc80652cccd77b259..c38271e7a9a962aac6ccc66126ec970deedb23c9 100644
--- a/model/sensor/driver/common/src/sensor_device_manager.c
+++ b/model/sensor/driver/common/src/sensor_device_manager.c
@@ -88,14 +88,16 @@ int32_t DeleteSensorDevice(const struct SensorBasicInfo *sensorBaseInfo)
int32_t ReportSensorEvent(const struct SensorReportEvent *events)
{
int32_t ret;
+ struct SensorDevMgrData *manager = NULL;
+ struct HdfSBuf *msg = NULL;
CHECK_NULL_PTR_RETURN_VALUE(events, HDF_ERR_INVALID_PARAM);
- struct SensorDevMgrData *manager = GetSensorDeviceManager();
+ manager = GetSensorDeviceManager();
CHECK_NULL_PTR_RETURN_VALUE(manager, HDF_ERR_INVALID_PARAM);
(void)OsalMutexLock(&manager->eventMutex);
- struct HdfSBuf *msg = HdfSBufObtain(HDF_SENSOR_EVENT_MAX_BUF);
+ msg = HdfSBufObtain(HDF_SENSOR_EVENT_MAX_BUF);
if (msg == NULL) {
(void)OsalMutexUnlock(&manager->eventMutex);
return HDF_ERR_INVALID_PARAM;
@@ -128,11 +130,14 @@ EXIT:
static int32_t GetAllSensorInfo(struct HdfSBuf *data, struct HdfSBuf *reply)
{
- (void)data;
+ int32_t count = 0;
struct SensorDevInfoNode *pos = NULL;
struct SensorBasicInfo *sensorInfo = NULL;
- struct SensorDevMgrData *manager = GetSensorDeviceManager();
- int32_t count = 0;
+ struct SensorDevMgrData *manager = NULL;
+
+ (void)data;
+
+ manager = GetSensorDeviceManager();
CHECK_NULL_PTR_RETURN_VALUE(reply, HDF_ERR_INVALID_PARAM);
CHECK_NULL_PTR_RETURN_VALUE(manager, HDF_ERR_INVALID_PARAM);
@@ -303,9 +308,11 @@ static int32_t DispatchSensor(struct HdfDeviceIoClient *client,
int32_t BindSensorDevManager(struct HdfDeviceObject *device)
{
+ struct SensorDevMgrData *manager = NULL;
+
CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
- struct SensorDevMgrData *manager = (struct SensorDevMgrData *)OsalMemCalloc(sizeof(*manager));
+ manager = (struct SensorDevMgrData *)OsalMemCalloc(sizeof(*manager));
if (manager == NULL) {
HDF_LOGE("%s: malloc manager fail!", __func__);
return HDF_ERR_MALLOC_FAIL;
@@ -321,8 +328,10 @@ int32_t BindSensorDevManager(struct HdfDeviceObject *device)
int32_t InitSensorDevManager(struct HdfDeviceObject *device)
{
+ struct SensorDevMgrData *manager = NULL;
+
CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
- struct SensorDevMgrData *manager = (struct SensorDevMgrData *)device->service;
+ manager = (struct SensorDevMgrData *)device->service;
CHECK_NULL_PTR_RETURN_VALUE(manager, HDF_ERR_INVALID_PARAM);
DListHeadInit(&manager->sensorDevInfoHead);
@@ -347,11 +356,13 @@ int32_t InitSensorDevManager(struct HdfDeviceObject *device)
void ReleaseSensorDevManager(struct HdfDeviceObject *device)
{
- CHECK_NULL_PTR_RETURN(device);
-
struct SensorDevInfoNode *pos = NULL;
struct SensorDevInfoNode *tmp = NULL;
- struct SensorDevMgrData *manager = (struct SensorDevMgrData *)device->service;
+ struct SensorDevMgrData *manager = NULL;
+
+ CHECK_NULL_PTR_RETURN(device);
+
+ manager = (struct SensorDevMgrData *)device->service;
CHECK_NULL_PTR_RETURN(manager);
DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &manager->sensorDevInfoHead, struct SensorDevInfoNode, node) {
@@ -360,6 +371,7 @@ void ReleaseSensorDevManager(struct HdfDeviceObject *device)
}
OsalMutexDestroy(&manager->mutex);
+ OsalMutexDestroy(&manager->eventMutex);
OsalMemFree(manager);
g_sensorDeviceManager = NULL;
}
diff --git a/model/sensor/driver/gyro/sensor_gyro_driver.c b/model/sensor/driver/gyro/sensor_gyro_driver.c
index 3e827ae3524d90e8f321a6ad7978c9be1adf5e03..fe3236f9758ea73561735388888667a22b891a13 100644
--- a/model/sensor/driver/gyro/sensor_gyro_driver.c
+++ b/model/sensor/driver/gyro/sensor_gyro_driver.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * 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.
@@ -8,7 +8,6 @@
#include "sensor_gyro_driver.h"
#include
-#include "gyro_bmi160.h"
#include "hdf_base.h"
#include "hdf_device_desc.h"
#include "osal_math.h"
@@ -21,10 +20,6 @@
#define HDF_GYRO_WORK_QUEUE_NAME "hdf_gyro_work_queue"
-static struct GyroDetectIfList g_gyroDetectIfList[] = {
- {GYRO_CHIP_NAME_BMI160, DetectGyroBim160Chip},
-};
-
static struct GyroDrvData *g_gyroDrvData = NULL;
static struct GyroDrvData *GyroGetDrvData(void)
@@ -34,14 +29,13 @@ static struct GyroDrvData *GyroGetDrvData(void)
static struct SensorRegCfgGroupNode *g_regCfgGroup[SENSOR_GROUP_MAX] = { NULL };
-int32_t RegisterGyroChipOps(const struct GyroOpsCall *ops)
+int32_t GyroRegisterChipOps(const struct GyroOpsCall *ops)
{
- struct GyroDrvData *drvData = NULL;
+ struct GyroDrvData *drvData = GyroGetDrvData();
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
CHECK_NULL_PTR_RETURN_VALUE(ops, HDF_ERR_INVALID_PARAM);
- drvData = GyroGetDrvData();
- CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
drvData->ops.Init = ops->Init;
drvData->ops.ReadData = ops->ReadData;
return HDF_SUCCESS;
@@ -49,16 +43,18 @@ int32_t RegisterGyroChipOps(const struct GyroOpsCall *ops)
static void GyroDataWorkEntry(void *arg)
{
- int32_t ret;
- struct GyroDrvData *drvData = (struct GyroDrvData *)arg;
+ struct GyroDrvData *drvData = NULL;
+
+ drvData = (struct GyroDrvData *)arg;
CHECK_NULL_PTR_RETURN(drvData);
- CHECK_NULL_PTR_RETURN(drvData->ops.ReadData);
- ret = drvData->ops.ReadData(drvData->gyroCfg);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: gyro read data failed", __func__);
+ if (drvData->ops.ReadData == NULL) {
+ HDF_LOGI("%s: Gyro ReadData function NULl", __func__);
return;
}
+ if (drvData->ops.ReadData(drvData->gyroCfg) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Gyro read data failed", __func__);
+ }
}
static void GyroTimerEntry(uintptr_t arg)
@@ -69,48 +65,32 @@ static void GyroTimerEntry(uintptr_t arg)
CHECK_NULL_PTR_RETURN(drvData);
if (!HdfAddWork(&drvData->gyroWorkQueue, &drvData->gyroWork)) {
- HDF_LOGE("%s: gyro add work queue failed", __func__);
+ HDF_LOGE("%s: Gyro add work queue failed", __func__);
}
interval = OsalDivS64(drvData->interval, (SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT));
interval = (interval < SENSOR_TIMER_MIN_TIME) ? SENSOR_TIMER_MIN_TIME : interval;
ret = OsalTimerSetTimeout(&drvData->gyroTimer, interval);
if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: gyro modify time failed", __func__);
+ HDF_LOGE("%s: Gyro modify time failed", __func__);
}
}
-static int32_t InitGyroData(void)
+static int32_t InitGyroData(struct GyroDrvData *drvData)
{
- struct GyroDrvData *drvData = GyroGetDrvData();
- int32_t ret;
- CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
-
- if (drvData->initStatus) {
- return HDF_SUCCESS;
- }
-
if (HdfWorkQueueInit(&drvData->gyroWorkQueue, HDF_GYRO_WORK_QUEUE_NAME) != HDF_SUCCESS) {
- HDF_LOGE("%s: gyro init work queue failed", __func__);
+ HDF_LOGE("%s: Gyro init work queue failed", __func__);
return HDF_FAILURE;
}
if (HdfWorkInit(&drvData->gyroWork, GyroDataWorkEntry, drvData) != HDF_SUCCESS) {
- HDF_LOGE("%s: gyro create thread failed", __func__);
- return HDF_FAILURE;
- }
-
- CHECK_NULL_PTR_RETURN_VALUE(drvData->ops.Init, HDF_ERR_INVALID_PARAM);
-
- ret = drvData->ops.Init(drvData->gyroCfg);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: gyro create thread failed", __func__);
+ HDF_LOGE("%s: Gyro create thread failed", __func__);
return HDF_FAILURE;
}
drvData->interval = SENSOR_TIMER_MIN_TIME;
- drvData->initStatus = true;
drvData->enable = false;
+ drvData->detectFlag = false;
return HDF_SUCCESS;
}
@@ -124,25 +104,25 @@ static int32_t SetGyroEnable(void)
CHECK_NULL_PTR_RETURN_VALUE(drvData->gyroCfg, HDF_ERR_INVALID_PARAM);
if (drvData->enable) {
- HDF_LOGE("%s: gyro sensor is enabled", __func__);
+ HDF_LOGE("%s: Gyro sensor is enabled", __func__);
return HDF_SUCCESS;
}
ret = SetSensorRegCfgArray(&drvData->gyroCfg->busCfg, drvData->gyroCfg->regCfgGroup[SENSOR_ENABLE_GROUP]);
if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: gyro sensor enable config failed", __func__);
+ HDF_LOGE("%s: Gyro sensor enable config failed", __func__);
return ret;
}
ret = OsalTimerCreate(&drvData->gyroTimer, SENSOR_TIMER_MIN_TIME, GyroTimerEntry, (uintptr_t)drvData);
if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: gyro create timer failed[%d]", __func__, ret);
+ HDF_LOGE("%s: Gyro create timer failed[%d]", __func__, ret);
return ret;
}
ret = OsalTimerStartLoop(&drvData->gyroTimer);
if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: gyro start timer failed[%d]", __func__, ret);
+ HDF_LOGE("%s: Gyro start timer failed[%d]", __func__, ret);
return ret;
}
drvData->enable = true;
@@ -159,22 +139,23 @@ static int32_t SetGyroDisable(void)
CHECK_NULL_PTR_RETURN_VALUE(drvData->gyroCfg, HDF_ERR_INVALID_PARAM);
if (!drvData->enable) {
- HDF_LOGE("%s: gyro sensor had disable", __func__);
+ HDF_LOGE("%s: Gyro sensor had disable", __func__);
return HDF_SUCCESS;
}
ret = SetSensorRegCfgArray(&drvData->gyroCfg->busCfg, drvData->gyroCfg->regCfgGroup[SENSOR_DISABLE_GROUP]);
if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: gyro sensor disable config failed", __func__);
+ HDF_LOGE("%s: Gyro sensor disable config failed", __func__);
return ret;
}
ret = OsalTimerDelete(&drvData->gyroTimer);
if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: gyro delete timer failed", __func__);
+ HDF_LOGE("%s: Gyro delete timer failed", __func__);
return ret;
}
drvData->enable = false;
+
return HDF_SUCCESS;
}
@@ -214,13 +195,13 @@ static int32_t DispatchGyro(struct HdfDeviceIoClient *client,
return HDF_SUCCESS;
}
-int32_t BindGyroDriver(struct HdfDeviceObject *device)
+int32_t GyroBindDriver(struct HdfDeviceObject *device)
{
CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
struct GyroDrvData *drvData = (struct GyroDrvData *)OsalMemCalloc(sizeof(*drvData));
if (drvData == NULL) {
- HDF_LOGE("%s: malloc gyro drv data fail!", __func__);
+ HDF_LOGE("%s: Malloc gyro drv data fail!", __func__);
return HDF_ERR_MALLOC_FAIL;
}
@@ -231,11 +212,9 @@ int32_t BindGyroDriver(struct HdfDeviceObject *device)
return HDF_SUCCESS;
}
-static int32_t InitGyroOps(struct SensorDeviceInfo *deviceInfo)
+static int32_t InitGyroOps(struct SensorCfgData *config, struct SensorDeviceInfo *deviceInfo)
{
- struct GyroDrvData *drvData = GyroGetDrvData();
-
- CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+ CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM);
deviceInfo->ops.Enable = SetGyroEnable;
deviceInfo->ops.Disable = SetGyroDisable;
@@ -244,149 +223,156 @@ static int32_t InitGyroOps(struct SensorDeviceInfo *deviceInfo)
deviceInfo->ops.SetOption = SetGyroOption;
if (memcpy_s(&deviceInfo->sensorInfo, sizeof(deviceInfo->sensorInfo),
- &drvData->gyroCfg->sensorInfo, sizeof(drvData->gyroCfg->sensorInfo)) != EOK) {
- HDF_LOGE("%s: copy sensor info failed", __func__);
+ &config->sensorInfo, sizeof(config->sensorInfo)) != EOK) {
+ HDF_LOGE("%s: Copy sensor info failed", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
-static int32_t InitGyroAfterConfig(void)
+static int32_t InitGyroAfterDetected(struct SensorCfgData *config)
{
struct SensorDeviceInfo deviceInfo;
+ CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM);
- if (InitGyroData() != HDF_SUCCESS) {
- HDF_LOGE("%s: init gyro config failed", __func__);
+ if (InitGyroOps(config, &deviceInfo) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Init gyro ops failed", __func__);
return HDF_FAILURE;
}
- if (InitGyroOps(&deviceInfo) != HDF_SUCCESS) {
- HDF_LOGE("%s: init gyro ops failed", __func__);
+ if (AddSensorDevice(&deviceInfo) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Add gyro device failed", __func__);
return HDF_FAILURE;
}
- if (AddSensorDevice(&deviceInfo) != HDF_SUCCESS) {
- HDF_LOGE("%s: add gyro device failed", __func__);
+ if (ParseSensorDirection(config) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Parse gyro direction failed", __func__);
+ (void)DeleteSensorDevice(&config->sensorInfo);
return HDF_FAILURE;
}
+ if (ParseSensorRegConfig(config) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Parse sensor register failed", __func__);
+ (void)DeleteSensorDevice(&config->sensorInfo);
+ ReleaseSensorAllRegConfig(config);
+ ReleaseSensorDirectionConfig(config);
+ return HDF_FAILURE;
+ }
return HDF_SUCCESS;
}
-static int32_t DetectGyroChip(void)
+struct SensorCfgData *GyroCreateCfgData(const struct DeviceResourceNode *node)
{
- int32_t num;
- int32_t ret;
- int32_t loop;
struct GyroDrvData *drvData = GyroGetDrvData();
- CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
- CHECK_NULL_PTR_RETURN_VALUE(drvData->gyroCfg, HDF_ERR_INVALID_PARAM);
-
- num = sizeof(g_gyroDetectIfList) / sizeof(g_gyroDetectIfList[0]);
- for (loop = 0; loop < num; ++loop) {
- if (g_gyroDetectIfList[loop].DetectChip != NULL) {
- ret = g_gyroDetectIfList[loop].DetectChip(drvData->gyroCfg);
- if (ret == HDF_SUCCESS) {
- drvData->detectFlag = true;
- return HDF_SUCCESS;
- }
- }
+ if (drvData == NULL || node == NULL) {
+ HDF_LOGE("%s: Gyro node pointer NULL", __func__);
+ return NULL;
}
- HDF_LOGE("%s: detect gyro device failed", __func__);
- drvData->detectFlag = false;
- return HDF_FAILURE;
-}
-
-int32_t InitGyroDriver(struct HdfDeviceObject *device)
-{
- CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
- struct GyroDrvData *drvData = (struct GyroDrvData *)device->service;
- CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
-
if (drvData->detectFlag) {
- HDF_LOGE("%s: gyro sensor have detected", __func__);
- return HDF_SUCCESS;
+ HDF_LOGE("%s: Gyro sensor have detected", __func__);
+ return NULL;
}
- drvData->gyroCfg = (struct SensorCfgData *)OsalMemCalloc(sizeof(*drvData->gyroCfg));
if (drvData->gyroCfg == NULL) {
- HDF_LOGE("%s: malloc sensor config data failed", __func__);
- return HDF_FAILURE;
+ HDF_LOGE("%s: Gyro gyroCfg pointer NULL", __func__);
+ return NULL;
}
- drvData->gyroCfg->regCfgGroup = &g_regCfgGroup[0];
-
- if (GetSensorBaseConfigData(device->property, drvData->gyroCfg) != HDF_SUCCESS) {
- HDF_LOGE("%s: get sensor base config failed", __func__);
+ if (GetSensorBaseConfigData(node, drvData->gyroCfg) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Get sensor base config failed", __func__);
goto BASE_CONFIG_EXIT;
}
- // if return failure, hdf framework go to next detect sensor
- if (DetectGyroChip() != HDF_SUCCESS) {
- HDF_LOGE("%s: gyro sensor detect device no exist", __func__);
- goto DETECT_CHIP_EXIT;
- }
- drvData->detectFlag = true;
-
- if (ParseSensorRegConfig(drvData->gyroCfg) != HDF_SUCCESS) {
- HDF_LOGE("%s: detect sensor device failed", __func__);
- goto REG_CONFIG_EXIT;
+ if (DetectSensorDevice(drvData->gyroCfg) != HDF_SUCCESS) {
+ HDF_LOGI("%s: Gyro sensor detect device no exist", __func__);
+ drvData->detectFlag = false;
+ goto BASE_CONFIG_EXIT;
}
- if (InitGyroAfterConfig() != HDF_SUCCESS) {
- HDF_LOGE("%s: init gyro after config failed", __func__);
+ drvData->detectFlag = true;
+ if (InitGyroAfterDetected(drvData->gyroCfg) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Gyro sensor detect device no exist", __func__);
goto INIT_EXIT;
}
-
- HDF_LOGI("%s: init gyro driver success", __func__);
- return HDF_SUCCESS;
+ return drvData->gyroCfg;
INIT_EXIT:
- (void)DeleteSensorDevice(&drvData->gyroCfg->sensorInfo);
-REG_CONFIG_EXIT:
- ReleaseSensorAllRegConfig(drvData->gyroCfg);
(void)ReleaseSensorBusHandle(&drvData->gyroCfg->busCfg);
-DETECT_CHIP_EXIT:
- drvData->detectFlag = false;
BASE_CONFIG_EXIT:
drvData->gyroCfg->root = NULL;
- drvData->gyroCfg->regCfgGroup = NULL;
- OsalMemFree(drvData->gyroCfg);
- drvData->gyroCfg = NULL;
- return HDF_FAILURE;
+ (void)memset_s(&drvData->gyroCfg->sensorInfo, sizeof(struct SensorBasicInfo), 0, sizeof(struct SensorBasicInfo));
+ (void)memset_s(&drvData->gyroCfg->busCfg, sizeof(struct SensorBusCfg), 0, sizeof(struct SensorBusCfg));
+ (void)memset_s(&drvData->gyroCfg->sensorAttr, sizeof(struct SensorAttr), 0, sizeof(struct SensorAttr));
+ return drvData->gyroCfg;
+}
+
+void GyroReleaseCfgData(struct SensorCfgData *gyroCfg)
+{
+ CHECK_NULL_PTR_RETURN(gyroCfg);
+
+ (void)DeleteSensorDevice(&gyroCfg->sensorInfo);
+ ReleaseSensorAllRegConfig(gyroCfg);
+ (void)ReleaseSensorBusHandle(&gyroCfg->busCfg);
+ ReleaseSensorDirectionConfig(gyroCfg);
+
+ gyroCfg->root = NULL;
+ (void)memset_s(&gyroCfg->sensorInfo, sizeof(struct SensorBasicInfo), 0, sizeof(struct SensorBasicInfo));
+ (void)memset_s(&gyroCfg->busCfg, sizeof(struct SensorBusCfg), 0, sizeof(struct SensorBusCfg));
+ (void)memset_s(&gyroCfg->sensorAttr, sizeof(struct SensorAttr), 0, sizeof(struct SensorAttr));
+}
+
+int32_t GyroInitDriver(struct HdfDeviceObject *device)
+{
+ HDF_LOGE("%s: cclog ----> 1111111111111111 ", __func__);
+ CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
+ struct GyroDrvData *drvData = (struct GyroDrvData *)device->service;
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+
+ if (InitGyroData(drvData) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Init gyro config failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ drvData->gyroCfg = (struct SensorCfgData *)OsalMemCalloc(sizeof(*drvData->gyroCfg));
+ if (drvData->gyroCfg == NULL) {
+ HDF_LOGE("%s: Malloc gyro config data failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ drvData->gyroCfg->regCfgGroup = &g_regCfgGroup[0];
+
+ HDF_LOGI("%s: Init gyro driver success", __func__);
+ return HDF_SUCCESS;
}
-void ReleaseGyroDriver(struct HdfDeviceObject *device)
+void GyroReleaseDriver(struct HdfDeviceObject *device)
{
CHECK_NULL_PTR_RETURN(device);
struct GyroDrvData *drvData = (struct GyroDrvData *)device->service;
CHECK_NULL_PTR_RETURN(drvData);
- (void)DeleteSensorDevice(&drvData->gyroCfg->sensorInfo);
- drvData->detectFlag = false;
-
- if (drvData->gyroCfg != NULL) {
- drvData->gyroCfg->root = NULL;
- drvData->gyroCfg->regCfgGroup = NULL;
- ReleaseSensorAllRegConfig(drvData->gyroCfg);
- (void)ReleaseSensorBusHandle(&drvData->gyroCfg->busCfg);
- OsalMemFree(drvData->gyroCfg);
- drvData->gyroCfg = NULL;
+ if (drvData->detectFlag && drvData->gyroCfg != NULL) {
+ GyroReleaseCfgData(drvData->gyroCfg);
}
- drvData->initStatus = false;
+ OsalMemFree(drvData->gyroCfg);
+ drvData->gyroCfg = NULL;
+
+ HdfWorkDestroy(&drvData->gyroWork);
+ HdfWorkQueueDestroy(&drvData->gyroWorkQueue);
+ OsalMemFree(drvData);
}
struct HdfDriverEntry g_sensorGyroDevEntry = {
.moduleVersion = 1,
.moduleName = "HDF_SENSOR_GYRO",
- .Bind = BindGyroDriver,
- .Init = InitGyroDriver,
- .Release = ReleaseGyroDriver,
+ .Bind = GyroBindDriver,
+ .Init = GyroInitDriver,
+ .Release = GyroReleaseDriver,
};
HDF_INIT(g_sensorGyroDevEntry);
diff --git a/model/sensor/driver/gyro/sensor_gyro_driver.h b/model/sensor/driver/gyro/sensor_gyro_driver.h
index bb63e10d3b332a3f0b91d315e104d607e4ce6385..6e64f96322fe98f87268f4d6491662cc46ed8fcc 100644
--- a/model/sensor/driver/gyro/sensor_gyro_driver.h
+++ b/model/sensor/driver/gyro/sensor_gyro_driver.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * 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.
@@ -15,9 +15,6 @@
#include "sensor_config_parser.h"
#include "sensor_platform_if.h"
-#define GYRO_DEFAULT_SAMPLING_200_MS 200000000
-#define GYRO_CHIP_NAME_BMI160 "bmi160"
-
enum GyroAxisNum {
GYRO_X_AXIS = 0,
GYRO_Y_AXIS = 1,
@@ -41,11 +38,6 @@ struct GyroData {
int32_t z;
};
-struct GyroDetectIfList {
- char *chipName;
- int32_t (*DetectChip)(struct SensorCfgData *data);
-};
-
struct GyroOpsCall {
int32_t (*Init)(struct SensorCfgData *data);
int32_t (*ReadData)(struct SensorCfgData *data);
@@ -59,12 +51,13 @@ struct GyroDrvData {
OsalTimer gyroTimer;
bool detectFlag;
bool enable;
- bool initStatus;
int64_t interval;
struct SensorCfgData *gyroCfg;
struct GyroOpsCall ops;
};
-int32_t RegisterGyroChipOps(const struct GyroOpsCall *ops);
+int32_t GyroRegisterChipOps(const struct GyroOpsCall *ops);
+struct SensorCfgData *GyroCreateCfgData(const struct DeviceResourceNode *node);
+void GyroReleaseCfgData(struct SensorCfgData *sensorCfgData);
#endif /* SENSOR_GYRO_DRIVER_H */
diff --git a/model/sensor/driver/hall/sensor_hall_driver.c b/model/sensor/driver/hall/sensor_hall_driver.c
index f8383e40a370c6f2c4b9f6084aaaa46da846b1d9..2a6a82bb6ebcf4f978e06b0383602d1c857818ed 100755
--- a/model/sensor/driver/hall/sensor_hall_driver.c
+++ b/model/sensor/driver/hall/sensor_hall_driver.c
@@ -13,8 +13,8 @@
#include "hdf_base.h"
#include "hdf_device_desc.h"
#include "osal_irq.h"
-#include "osal_math.h"
#include "osal_mem.h"
+#include "osal_time.h"
#include "sensor_config_controller.h"
#include "sensor_device_manager.h"
#include "sensor_platform_if.h"
@@ -35,37 +35,102 @@ int32_t HallRegisterChipOps(const struct HallOpsCall *ops)
CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
CHECK_NULL_PTR_RETURN_VALUE(ops, HDF_ERR_INVALID_PARAM);
-
+
drvData->ops.Init = ops->Init;
drvData->ops.ReadData = ops->ReadData;
return HDF_SUCCESS;
}
+void ReadGpioData()
+{
+ int32_t ret;
+ uint16_t tmp;
+ OsalTimespec time;
+ struct SensorReportEvent event;
+
+ struct HallDrvData *drvData = HallGetDrvData();
+ CHECK_NULL_PTR_RETURN(drvData);
+
+ (void)memset_s(&event, sizeof(event), 0, sizeof(event));
+ (void)memset_s(&time, sizeof(time), 0, sizeof(time));
+ if (OsalGetTime(&time) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Get time failed", __func__);
+ return;
+ }
+
+ tmp = drvData->status;
+ event.timestamp = time.sec * SENSOR_SECOND_CONVERT_NANOSECOND + time.usec *
+ SENSOR_CONVERT_UNIT; /* unit nanosecond */
+ event.sensorId = SENSOR_TAG_HALL;
+ event.version = 0;
+ event.option = 0;
+ event.mode = SENSOR_WORK_MODE_ON_CHANGE;
+ event.dataLen = sizeof(tmp);
+ event.data = (uint8_t *)&tmp;
+ ret = ReportSensorEvent(&event);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: AK8789 report data failed", __func__);
+ }
+}
+
static void HallDataWorkEntry(void *arg)
{
struct HallDrvData *drvData = NULL;
-
+
drvData = (struct HallDrvData *)arg;
CHECK_NULL_PTR_RETURN(drvData);
if (drvData->ops.ReadData == NULL) {
+ ReadGpioData();
HDF_LOGI("%s: Hall ReadData function NULL", __func__);
- return;
- }
- if (drvData->ops.ReadData(drvData->hallCfg) != HDF_SUCCESS) {
+ } else if (drvData->ops.ReadData(drvData->hallCfg) != HDF_SUCCESS) {
HDF_LOGE("%s: Hall read data failed", __func__);
}
}
+static int32_t ParserHallDelayedConfigData(const struct DeviceResourceNode *node, struct HallDrvData *drvData)
+{
+ int32_t ret;
+ struct DeviceResourceIface *parser = NULL;
+
+ CHECK_NULL_PTR_RETURN_VALUE(node, HDF_ERR_INVALID_PARAM);
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+
+ parser = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ CHECK_NULL_PTR_RETURN_VALUE(parser, HDF_ERR_INVALID_PARAM);
+
+ CHECK_NULL_PTR_RETURN_VALUE(parser->GetChildNode, HDF_ERR_INVALID_PARAM);
+
+ const struct DeviceResourceNode *delayedNode = parser->GetChildNode(node, "hallDelayedConfig");
+ CHECK_NULL_PTR_RETURN_VALUE(delayedNode, HDF_ERR_INVALID_PARAM);
+
+ ret = parser->GetUint32(delayedNode, "delayedTime", (uint32_t *)&drvData->delayTime, 0);
+ CHECK_PARSER_RESULT_RETURN_VALUE(ret, "delayedTime");
+
+ return HDF_SUCCESS;
+}
+
static int32_t HallNorthPolarityIrqFunc(uint16_t gpio, void *data)
{
(void)gpio;
+ int32_t ret;
+ uint16_t valRead;
struct HallDrvData *drvData = (struct HallDrvData *)data;
CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
- if (!HdfAddWork(&drvData->hallWorkQueue, &drvData->hallWork)) {
- HDF_LOGE("%s: Hall add work queue failed", __func__);
+ ret = GpioRead(drvData->hallCfg->busCfg.GpioNum[SENSOR_GPIO_NUM1], (uint16_t *)&valRead);
+ if (ret != 0) {
+ HDF_LOGE("%s: Read hall gpio value failed", __func__);
+ }
+ if (valRead == GPIO_VAL_LOW) {
+ drvData->status = 1;
+ } else if (valRead == GPIO_VAL_HIGH) {
+ drvData->status = 0;
+ }
+
+ if (!HdfAddDelayedWork(&drvData->hallWorkQueue, &drvData->hallWork, drvData->delayTime)) {
+ HDF_LOGE("%s: Hall north add delay work queue failed", __func__);
}
return HDF_SUCCESS;
@@ -74,12 +139,24 @@ static int32_t HallNorthPolarityIrqFunc(uint16_t gpio, void *data)
static int32_t HallSouthPolarityIrqFunc(uint16_t gpio, void *data)
{
(void)gpio;
+ int32_t ret;
+ uint16_t valRead;
struct HallDrvData *drvData = (struct HallDrvData *)data;
CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
- if (!HdfAddWork(&drvData->hallWorkQueue, &drvData->hallWork)) {
- HDF_LOGE("%s: Hall add work queue failed", __func__);
+ ret = GpioRead(drvData->hallCfg->busCfg.GpioNum[SENSOR_GPIO_NUM2], (uint16_t *)&valRead);
+ if (ret != 0) {
+ HDF_LOGE("%s: Read hall gpio value failed", __func__);
+ }
+ if (valRead == GPIO_VAL_LOW) {
+ drvData->status = 1;
+ } else if (valRead == GPIO_VAL_HIGH) {
+ drvData->status = 0;
+ }
+
+ if (!HdfAddDelayedWork(&drvData->hallWorkQueue, &drvData->hallWork, drvData->delayTime)) {
+ HDF_LOGE("%s: Hall south add delay work queue failed", __func__);
}
return HDF_SUCCESS;
@@ -92,7 +169,7 @@ static int32_t InitHallData(struct HallDrvData *drvData)
return HDF_FAILURE;
}
- if (HdfWorkInit(&drvData->hallWork, HallDataWorkEntry, drvData) != HDF_SUCCESS) {
+ if (HdfDelayedWorkInit(&drvData->hallWork, HallDataWorkEntry, drvData) != HDF_SUCCESS) {
HDF_LOGE("%s: Hall create thread failed", __func__);
return HDF_FAILURE;
}
@@ -107,6 +184,7 @@ static int32_t InitHallData(struct HallDrvData *drvData)
static int32_t SetHallEnable(void)
{
int32_t ret;
+ uint16_t mode;
struct HallDrvData *drvData = HallGetDrvData();
CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
@@ -115,25 +193,26 @@ static int32_t SetHallEnable(void)
return HDF_SUCCESS;
}
- if (drvData->GpioIrq[HALL_NORTH_POLARITY_GPIO] >= 0) {
- ret = GpioSetIrq(drvData->GpioIrq[HALL_NORTH_POLARITY_GPIO], OSAL_IRQF_TRIGGER_FALLING,
+ mode = OSAL_IRQF_TRIGGER_RISING | OSAL_IRQF_TRIGGER_FALLING;
+ if (drvData->hallCfg->busCfg.GpioNum[SENSOR_GPIO_NUM1] >= 0) {
+ ret = GpioSetIrq(drvData->hallCfg->busCfg.GpioNum[SENSOR_GPIO_NUM1], mode,
HallNorthPolarityIrqFunc, drvData);
if (ret != 0) {
HDF_LOGE("Gpio set north irq failed: %d", ret);
}
- ret = GpioEnableIrq(drvData->GpioIrq[HALL_NORTH_POLARITY_GPIO]);
+ ret = GpioEnableIrq(drvData->hallCfg->busCfg.GpioNum[SENSOR_GPIO_NUM1]);
if (ret != 0) {
HDF_LOGE("Gpio enable north irq failed: %d", ret);
}
}
- if (drvData->GpioIrq[HALL_SOUTH_POLARITY_GPIO] >= 0) {
- ret = GpioSetIrq(drvData->GpioIrq[HALL_SOUTH_POLARITY_GPIO], OSAL_IRQF_TRIGGER_FALLING,
+ if (drvData->hallCfg->busCfg.GpioNum[SENSOR_GPIO_NUM2] >= 0) {
+ ret = GpioSetIrq(drvData->hallCfg->busCfg.GpioNum[SENSOR_GPIO_NUM2], mode,
HallSouthPolarityIrqFunc, drvData);
if (ret != 0) {
HDF_LOGE("%s: Gpio set south irq failed", __func__);
}
- ret = GpioEnableIrq(drvData->GpioIrq[HALL_SOUTH_POLARITY_GPIO]);
+ ret = GpioEnableIrq(drvData->hallCfg->busCfg.GpioNum[SENSOR_GPIO_NUM2]);
if (ret != 0) {
HDF_LOGE("%s: Gpio enable south irq failed", __func__);
}
@@ -154,25 +233,25 @@ static int32_t SetHallDisable(void)
return HDF_SUCCESS;
}
- if (drvData->GpioIrq[HALL_NORTH_POLARITY_GPIO] >= 0) {
- ret = GpioUnSetIrq(drvData->GpioIrq[HALL_NORTH_POLARITY_GPIO]);
+ if (drvData->hallCfg->busCfg.GpioNum[SENSOR_GPIO_NUM1] >= 0) {
+ ret = GpioUnSetIrq(drvData->hallCfg->busCfg.GpioNum[SENSOR_GPIO_NUM1]);
if (ret != 0) {
HDF_LOGE("%s: Gpio unset north irq failed", __func__);
}
- ret = GpioDisableIrq(drvData->GpioIrq[HALL_NORTH_POLARITY_GPIO]);
+ ret = GpioDisableIrq(drvData->hallCfg->busCfg.GpioNum[SENSOR_GPIO_NUM1]);
if (ret != 0) {
HDF_LOGE("%s: Gpio disable north irq failed", __func__);
}
}
- if (drvData->GpioIrq[HALL_SOUTH_POLARITY_GPIO] >= 0) {
- ret = GpioUnSetIrq(drvData->GpioIrq[HALL_SOUTH_POLARITY_GPIO]);
+ if (drvData->hallCfg->busCfg.GpioNum[SENSOR_GPIO_NUM2] >= 0) {
+ ret = GpioUnSetIrq(drvData->hallCfg->busCfg.GpioNum[SENSOR_GPIO_NUM2]);
if (ret != 0) {
HDF_LOGE("%s: Gpio unset south irq failed", __func__);
}
- ret = GpioDisableIrq(drvData->GpioIrq[HALL_SOUTH_POLARITY_GPIO]);
+ ret = GpioDisableIrq(drvData->hallCfg->busCfg.GpioNum[SENSOR_GPIO_NUM2]);
if (ret != 0) {
HDF_LOGE("%s: Gpio disable south irq failed", __func__);
}
@@ -245,30 +324,6 @@ static int32_t InitHallOps(struct SensorCfgData *config, struct SensorDeviceInfo
return HDF_SUCCESS;
}
-static int32_t ParserHallPinConfigData(const struct DeviceResourceNode *node, struct HallDrvData *drvData)
-{
- int32_t ret;
- struct DeviceResourceIface *parser = NULL;
-
- CHECK_NULL_PTR_RETURN_VALUE(node, HDF_ERR_INVALID_PARAM);
- CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
-
- parser = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
- CHECK_NULL_PTR_RETURN_VALUE(parser, HDF_ERR_INVALID_PARAM);
-
- CHECK_NULL_PTR_RETURN_VALUE(parser->GetChildNode, HDF_ERR_INVALID_PARAM);
-
- const struct DeviceResourceNode *pinNode = parser->GetChildNode(node, "hallPinConfig");
- CHECK_NULL_PTR_RETURN_VALUE(pinNode, HDF_ERR_INVALID_PARAM);
-
- ret = parser->GetUint32(pinNode, "NorthPolarityGpio", (uint32_t *)&drvData->GpioIrq[HALL_NORTH_POLARITY_GPIO], 0);
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "NorthPolarityGpio");
- ret = parser->GetUint32(pinNode, "SouthPolarityGpio", (uint32_t *)&drvData->GpioIrq[HALL_SOUTH_POLARITY_GPIO], 0);
- CHECK_PARSER_RESULT_RETURN_VALUE(ret, "SouthPolarityGpio");
-
- return HDF_SUCCESS;
-}
-
static int32_t InitHallAfterDetected(const struct DeviceResourceNode *node, struct HallDrvData *drvData)
{
struct SensorDeviceInfo deviceInfo;
@@ -285,28 +340,29 @@ static int32_t InitHallAfterDetected(const struct DeviceResourceNode *node, stru
return HDF_FAILURE;
}
- if (ParserHallPinConfigData(node, drvData) != HDF_SUCCESS) {
- HDF_LOGE("%s: get hall pin config failed", __func__);
+ if (ParserHallDelayedConfigData(node, drvData) != HDF_SUCCESS) {
+ HDF_LOGE("%s: get hall delayed config failed", __func__);
(void)DeleteSensorDevice(&drvData->hallCfg->sensorInfo);
return HDF_FAILURE;
}
+
return HDF_SUCCESS;
}
static int32_t SetHallGpioPin(struct HallDrvData *drvData)
{
- if (drvData->GpioIrq[HALL_NORTH_POLARITY_GPIO] >= 0) {
- int ret = GpioSetDir(drvData->GpioIrq[HALL_NORTH_POLARITY_GPIO], GPIO_DIR_IN);
+ if (drvData->hallCfg->busCfg.GpioNum[SENSOR_GPIO_NUM1] >= 0) {
+ int ret = GpioSetDir(drvData->hallCfg->busCfg.GpioNum[SENSOR_GPIO_NUM1], GPIO_DIR_IN);
if (ret != 0) {
- HDF_LOGE("%s:%d set north gpio dir failed", __func__, __LINE__);
+ HDF_LOGE("%s:%d Set north gpio dir failed", __func__, __LINE__);
return HDF_FAILURE;
}
}
- if (drvData->GpioIrq[HALL_SOUTH_POLARITY_GPIO] >= 0) {
- int ret = GpioSetDir(drvData->GpioIrq[HALL_SOUTH_POLARITY_GPIO], GPIO_DIR_IN);
+ if (drvData->hallCfg->busCfg.GpioNum[SENSOR_GPIO_NUM2] >= 0) {
+ int ret = GpioSetDir(drvData->hallCfg->busCfg.GpioNum[SENSOR_GPIO_NUM2], GPIO_DIR_IN);
if (ret != 0) {
- HDF_LOGE("%s:%d south south gpio dir failed", __func__, __LINE__);
+ HDF_LOGE("%s:%d Set south gpio dir failed", __func__, __LINE__);
return HDF_FAILURE;
}
}
diff --git a/model/sensor/driver/hall/sensor_hall_driver.h b/model/sensor/driver/hall/sensor_hall_driver.h
index 3b706dcc3937c62c8c64f5a529b3a0f20d7d0a3c..7766365d430a5638b42db847c86eae7c477cef16 100755
--- a/model/sensor/driver/hall/sensor_hall_driver.h
+++ b/model/sensor/driver/hall/sensor_hall_driver.h
@@ -9,18 +9,12 @@
#ifndef SENSOR_HALL_DRIVER_H
#define SENSOR_HALL_DRIVER_H
-#include "hdf_workqueue.h"
+#include "hdf_workqueue.h"
#include "sensor_config_parser.h"
#include "sensor_platform_if.h"
#define HALL_CHIP_NAME_AK8789 "ak8789"
-enum HallGpioIrq {
- HALL_NORTH_POLARITY_GPIO = 0,
- HALL_SOUTH_POLARITY_GPIO = 1,
- HALL_POLARITY_GPIO_MAX = 2,
-};
-
struct HallOpsCall {
int32_t (*Init)(struct SensorCfgData *data);
int32_t (*ReadData)(struct SensorCfgData *data);
@@ -36,7 +30,8 @@ struct HallDrvData {
int64_t interval;
struct SensorCfgData *hallCfg;
struct HallOpsCall ops;
- int32_t GpioIrq[HALL_POLARITY_GPIO_MAX];
+ uint16_t status;
+ uint32_t delayTime;
};
int32_t HallRegisterChipOps(const struct HallOpsCall *ops);
diff --git a/model/sensor/driver/include/sensor_device_if.h b/model/sensor/driver/include/sensor_device_if.h
index c3315fdc795674a710f29db54c5a160c89e578fa..5a68aa5df54a079d6ba170583b80f1848a4ed945 100644
--- a/model/sensor/driver/include/sensor_device_if.h
+++ b/model/sensor/driver/include/sensor_device_if.h
@@ -1,31 +1,31 @@
-/*
- * 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.
- */
-
-#ifndef SENSOR_DEVICE_IF_H
-#define SENSOR_DEVICE_IF_H
-
-#include "sensor_device_type.h"
-
-struct SensorOps {
- int32_t (*Enable)(void);
- int32_t (*Disable)(void);
- int32_t (*SetBatch)(int64_t samplingInterval, int64_t reportInterval);
- int32_t (*SetMode)(int32_t mode);
- int32_t (*SetOption)(uint32_t option);
-};
-
-struct SensorDeviceInfo {
- struct SensorBasicInfo sensorInfo;
- struct SensorOps ops;
-};
-
-int32_t AddSensorDevice(const struct SensorDeviceInfo *deviceInfo);
-int32_t DeleteSensorDevice(const struct SensorBasicInfo *sensorBaseInfo);
-int32_t ReportSensorEvent(const struct SensorReportEvent *events);
-
-#endif /* SENSOR_DEVICE_IF_H */
+/*
+ * 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.
+ */
+
+#ifndef SENSOR_DEVICE_IF_H
+#define SENSOR_DEVICE_IF_H
+
+#include "sensor_device_type.h"
+
+struct SensorOps {
+ int32_t (*Enable)(void);
+ int32_t (*Disable)(void);
+ int32_t (*SetBatch)(int64_t samplingInterval, int64_t reportInterval);
+ int32_t (*SetMode)(int32_t mode);
+ int32_t (*SetOption)(uint32_t option);
+};
+
+struct SensorDeviceInfo {
+ struct SensorBasicInfo sensorInfo;
+ struct SensorOps ops;
+};
+
+int32_t AddSensorDevice(const struct SensorDeviceInfo *deviceInfo);
+int32_t DeleteSensorDevice(const struct SensorBasicInfo *sensorBaseInfo);
+int32_t ReportSensorEvent(const struct SensorReportEvent *events);
+
+#endif /* SENSOR_DEVICE_IF_H */
diff --git a/model/sensor/driver/include/sensor_platform_if.h b/model/sensor/driver/include/sensor_platform_if.h
index 6bf64210f4623059483eaedc66f2babe86b04d16..6f14893833b7e30fcf3f91566c15bf1a5103c426 100644
--- a/model/sensor/driver/include/sensor_platform_if.h
+++ b/model/sensor/driver/include/sensor_platform_if.h
@@ -52,6 +52,13 @@
enum SensorBusType {
SENSOR_BUS_I2C = 0,
SENSOR_BUS_SPI = 1,
+ SENSOR_BUS_GPIO = 2,
+};
+
+enum SensorGpioNum {
+ SENSOR_GPIO_NUM1 = 0,
+ SENSOR_GPIO_NUM2 = 1,
+ SENSOR_GPIO_NUM_MAX = 2,
};
struct SensorI2cCfg {
@@ -73,6 +80,7 @@ struct SensorBusCfg {
union {
struct SensorI2cCfg i2cCfg;
struct SensorSpiCfg spiCfg;
+ uint32_t GpioNum[SENSOR_GPIO_NUM_MAX];
};
};
diff --git a/model/sensor/driver/magnetic/sensor_magnetic_driver.c b/model/sensor/driver/magnetic/sensor_magnetic_driver.c
new file mode 100755
index 0000000000000000000000000000000000000000..eb831ad1122039190d2eb60a39c8ec4f97c832fd
--- /dev/null
+++ b/model/sensor/driver/magnetic/sensor_magnetic_driver.c
@@ -0,0 +1,386 @@
+/*
+ * Copyright (c) 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 "sensor_magnetic_driver.h"
+#include
+#include "hdf_base.h"
+#include "hdf_device_desc.h"
+#include "osal_math.h"
+#include "osal_mem.h"
+#include "sensor_config_controller.h"
+#include "sensor_device_manager.h"
+#include "sensor_platform_if.h"
+
+#define HDF_LOG_TAG sensor_magnetic_driver_c
+
+#define HDF_MAGNETIC_WORK_QUEUE_NAME "hdf_magnetic_work_queue"
+
+static struct MagneticDrvData *g_magneticDrvData = NULL;
+
+static struct MagneticDrvData *MagneticGetDrvData(void)
+{
+ return g_magneticDrvData;
+}
+
+static struct SensorRegCfgGroupNode *g_regCfgGroup[SENSOR_GROUP_MAX] = { NULL };
+
+int32_t MagneticRegisterChipOps(const struct MagneticOpsCall *ops)
+{
+ struct MagneticDrvData *drvData = MagneticGetDrvData();
+
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+ CHECK_NULL_PTR_RETURN_VALUE(ops, HDF_ERR_INVALID_PARAM);
+
+ drvData->ops.Init = ops->Init;
+ drvData->ops.ReadData = ops->ReadData;
+ return HDF_SUCCESS;
+}
+
+static void MagneticDataWorkEntry(void *arg)
+{
+ struct MagneticDrvData *drvData = NULL;
+
+ drvData = (struct MagneticDrvData *)arg;
+ CHECK_NULL_PTR_RETURN(drvData);
+
+ if (drvData->ops.ReadData == NULL) {
+ HDF_LOGE("%s: Magnetic readdata function NULL", __func__);
+ return;
+ }
+ if (drvData->ops.ReadData(drvData->magneticCfg) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Magnetic read data failed", __func__);
+ }
+}
+
+static void MagneticTimerEntry(uintptr_t arg)
+{
+ int64_t interval;
+ int32_t ret;
+ struct MagneticDrvData *drvData = (struct MagneticDrvData *)arg;
+ CHECK_NULL_PTR_RETURN(drvData);
+
+ if (!HdfAddWork(&drvData->magneticWorkQueue, &drvData->magneticWork)) {
+ HDF_LOGE("%s: Magnetic add work queue failed", __func__);
+ }
+
+ interval = OsalDivS64(drvData->interval, (SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT));
+ interval = (interval < SENSOR_TIMER_MIN_TIME) ? SENSOR_TIMER_MIN_TIME : interval;
+ ret = OsalTimerSetTimeout(&drvData->magneticTimer, interval);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Magnetic modify time failed", __func__);
+ }
+}
+
+static int32_t InitMagneticData(struct MagneticDrvData *drvData)
+{
+ if (HdfWorkQueueInit(&drvData->magneticWorkQueue, HDF_MAGNETIC_WORK_QUEUE_NAME) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Magnetic init work queue failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ if (HdfWorkInit(&drvData->magneticWork, MagneticDataWorkEntry, drvData) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Magnetic create thread failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ drvData->interval = SENSOR_TIMER_MIN_TIME;
+ drvData->enable = false;
+ drvData->detectFlag = false;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SetMagneticEnable(void)
+{
+ int32_t ret;
+ struct MagneticDrvData *drvData = MagneticGetDrvData();
+
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+ CHECK_NULL_PTR_RETURN_VALUE(drvData->magneticCfg, HDF_ERR_INVALID_PARAM);
+
+ if (drvData->enable) {
+ HDF_LOGE("%s: Magnetic sensor is enabled", __func__);
+ return HDF_SUCCESS;
+ }
+
+ ret = SetSensorRegCfgArray(&drvData->magneticCfg->busCfg, drvData->magneticCfg->regCfgGroup[SENSOR_ENABLE_GROUP]);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Magnetic sensor enable config failed", __func__);
+ return ret;
+ }
+
+ ret = OsalTimerCreate(&drvData->magneticTimer, SENSOR_TIMER_MIN_TIME, MagneticTimerEntry, (uintptr_t)drvData);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Magnetic create timer failed[%d]", __func__, ret);
+ return ret;
+ }
+
+ ret = OsalTimerStartLoop(&drvData->magneticTimer);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Magnetic start timer failed[%d]", __func__, ret);
+ return ret;
+ }
+ drvData->enable = true;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SetMagneticDisable(void)
+{
+ int32_t ret;
+ struct MagneticDrvData *drvData = MagneticGetDrvData();
+
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+ CHECK_NULL_PTR_RETURN_VALUE(drvData->magneticCfg, HDF_ERR_INVALID_PARAM);
+
+ if (!drvData->enable) {
+ HDF_LOGE("%s: Magnetic sensor had disable", __func__);
+ return HDF_SUCCESS;
+ }
+
+ ret = SetSensorRegCfgArray(&drvData->magneticCfg->busCfg, drvData->magneticCfg->regCfgGroup[SENSOR_DISABLE_GROUP]);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Magnetic sensor disable config failed", __func__);
+ return ret;
+ }
+
+ ret = OsalTimerDelete(&drvData->magneticTimer);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: Magnetic delete timer failed", __func__);
+ return ret;
+ }
+ drvData->enable = false;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SetMagneticBatch(int64_t samplingInterval, int64_t interval)
+{
+ (void)interval;
+
+ struct MagneticDrvData *drvData = NULL;
+
+ drvData = MagneticGetDrvData();
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+
+ drvData->interval = samplingInterval;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SetMagneticMode(int32_t mode)
+{
+ return (mode == SENSOR_WORK_MODE_REALTIME) ? HDF_SUCCESS : HDF_FAILURE;
+}
+
+static int32_t SetMagneticOption(uint32_t option)
+{
+ (void)option;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t DispatchMagnetic(struct HdfDeviceIoClient *client,
+ int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ (void)client;
+ (void)cmd;
+ (void)data;
+ (void)reply;
+
+ return HDF_SUCCESS;
+}
+
+int32_t MagneticBindDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
+
+ struct MagneticDrvData *drvData = (struct MagneticDrvData *)OsalMemCalloc(sizeof(*drvData));
+ if (drvData == NULL) {
+ HDF_LOGE("%s: Malloc magnetic drv data fail!", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ drvData->ioService.Dispatch = DispatchMagnetic;
+ drvData->device = device;
+ device->service = &drvData->ioService;
+ g_magneticDrvData = drvData;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t InitMagneticOps(struct SensorCfgData *config, struct SensorDeviceInfo *deviceInfo)
+{
+ CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM);
+
+ deviceInfo->ops.Enable = SetMagneticEnable;
+ deviceInfo->ops.Disable = SetMagneticDisable;
+ deviceInfo->ops.SetBatch = SetMagneticBatch;
+ deviceInfo->ops.SetMode = SetMagneticMode;
+ deviceInfo->ops.SetOption = SetMagneticOption;
+
+ if (memcpy_s(&deviceInfo->sensorInfo, sizeof(deviceInfo->sensorInfo),
+ &config->sensorInfo, sizeof(config->sensorInfo)) != EOK) {
+ HDF_LOGE("%s: Copy sensor info failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t InitMagneticAfterDetected(struct SensorCfgData *config)
+{
+ struct SensorDeviceInfo deviceInfo;
+ CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM);
+
+ if (InitMagneticOps(config, &deviceInfo) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Init magnetic ops failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ if (AddSensorDevice(&deviceInfo) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Add magnetic device failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ if (ParseSensorDirection(config) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Parse magnetic direction failed", __func__);
+ (void)DeleteSensorDevice(&config->sensorInfo);
+ return HDF_FAILURE;
+ }
+
+ if (ParseSensorRegConfig(config) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Parse sensor register failed", __func__);
+ (void)DeleteSensorDevice(&config->sensorInfo);
+ ReleaseSensorAllRegConfig(config);
+ ReleaseSensorDirectionConfig(config);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+struct SensorCfgData *MagneticCreateCfgData(const struct DeviceResourceNode *node)
+{
+ struct MagneticDrvData *drvData = MagneticGetDrvData();
+
+ if (drvData == NULL || node == NULL) {
+ HDF_LOGE("%s: Magnetic node pointer NULL", __func__);
+
+ return NULL;
+ }
+
+ if (drvData->detectFlag) {
+ HDF_LOGE("%s: Magnetic sensor have detected", __func__);
+
+ return NULL;
+ }
+
+ if (drvData->magneticCfg == NULL) {
+ HDF_LOGE("%s: Magnetic magneticCfg pointer NULL", __func__);
+
+ return NULL;
+ }
+
+ if (GetSensorBaseConfigData(node, drvData->magneticCfg) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Get sensor base config failed", __func__);
+ goto BASE_CONFIG_EXIT;
+ }
+
+ if (DetectSensorDevice(drvData->magneticCfg) != HDF_SUCCESS) {
+ HDF_LOGI("%s: Magnetic sensor detect device no exist", __func__);
+ drvData->detectFlag = false;
+ goto BASE_CONFIG_EXIT;
+ }
+
+ drvData->detectFlag = true;
+ if (InitMagneticAfterDetected(drvData->magneticCfg) != HDF_SUCCESS) {
+ HDF_LOGI("%s: Magnetic sensor detect device no exist", __func__);
+
+ goto INIT_EXIT;
+ }
+ return drvData->magneticCfg;
+
+INIT_EXIT:
+ (void)ReleaseSensorBusHandle(&drvData->magneticCfg->busCfg);
+BASE_CONFIG_EXIT:
+ drvData->magneticCfg->root = NULL;
+ (void)memset_s(&drvData->magneticCfg->sensorInfo,
+ sizeof(struct SensorBasicInfo), 0, sizeof(struct SensorBasicInfo));
+ (void)memset_s(&drvData->magneticCfg->busCfg, sizeof(struct SensorBusCfg), 0, sizeof(struct SensorBusCfg));
+ (void)memset_s(&drvData->magneticCfg->sensorAttr, sizeof(struct SensorAttr), 0, sizeof(struct SensorAttr));
+
+ return drvData->magneticCfg;
+}
+
+void MagneticReleaseCfgData(struct SensorCfgData *magneticCfg)
+{
+ CHECK_NULL_PTR_RETURN(magneticCfg);
+
+ (void)DeleteSensorDevice(&magneticCfg->sensorInfo);
+ ReleaseSensorAllRegConfig(magneticCfg);
+ (void)ReleaseSensorBusHandle(&magneticCfg->busCfg);
+ ReleaseSensorDirectionConfig(magneticCfg);
+
+ magneticCfg->root = NULL;
+ (void)memset_s(&magneticCfg->sensorInfo, sizeof(struct SensorBasicInfo), 0, sizeof(struct SensorBasicInfo));
+ (void)memset_s(&magneticCfg->busCfg, sizeof(struct SensorBusCfg), 0, sizeof(struct SensorBusCfg));
+ (void)memset_s(&magneticCfg->sensorAttr, sizeof(struct SensorAttr), 0, sizeof(struct SensorAttr));
+}
+
+int32_t MagneticInitDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
+ struct MagneticDrvData *drvData = (struct MagneticDrvData *)device->service;
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+
+ if (InitMagneticData(drvData) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Init magnetic config failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ drvData->magneticCfg = (struct SensorCfgData *)OsalMemCalloc(sizeof(*drvData->magneticCfg));
+ if (drvData->magneticCfg == NULL) {
+ HDF_LOGE("%s: Malloc magnetic config data failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ drvData->magneticCfg->regCfgGroup = &g_regCfgGroup[0];
+
+ HDF_LOGI("%s: Init magnetic driver success", __func__);
+ return HDF_SUCCESS;
+}
+
+void MagneticReleaseDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN(device);
+
+ struct MagneticDrvData *drvData = (struct MagneticDrvData *)device->service;
+ CHECK_NULL_PTR_RETURN(drvData);
+
+ if (drvData->detectFlag && drvData->magneticCfg != NULL) {
+ MagneticReleaseCfgData(drvData->magneticCfg);
+ }
+
+ OsalMemFree(drvData->magneticCfg);
+ drvData->magneticCfg = NULL;
+
+ HdfWorkDestroy(&drvData->magneticWork);
+ HdfWorkQueueDestroy(&drvData->magneticWorkQueue);
+ OsalMemFree(drvData);
+}
+
+struct HdfDriverEntry g_sensorMagneticDevEntry = {
+ .moduleVersion = 1,
+ .moduleName = "HDF_SENSOR_MAGNETIC",
+ .Bind = MagneticBindDriver,
+ .Init = MagneticInitDriver,
+ .Release = MagneticReleaseDriver,
+};
+
+HDF_INIT(g_sensorMagneticDevEntry);
\ No newline at end of file
diff --git a/model/sensor/driver/magnetic/sensor_magnetic_driver.h b/model/sensor/driver/magnetic/sensor_magnetic_driver.h
new file mode 100755
index 0000000000000000000000000000000000000000..14b836e091467d7612f76f6022428fe368c1f408
--- /dev/null
+++ b/model/sensor/driver/magnetic/sensor_magnetic_driver.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef SENSOR_MAGNETIC_DRIVER_H
+#define SENSOR_MAGNETIC_DRIVER_H
+
+#include "hdf_workqueue.h"
+#include "osal_timer.h"
+#include "sensor_config_parser.h"
+#include "sensor_platform_if.h"
+
+#define MAGNETIC_DEFAULT_SAMPLING_200_MS 200000000
+#define MAGNETIC_CHIP_NAME_LSM303 "lsm303"
+
+enum MagneticAxisNum {
+ MAGNETIC_X_AXIS = 0,
+ MAGNETIC_Y_AXIS = 1,
+ MAGNETIC_Z_AXIS = 2,
+ MAGNETIC_AXIS_NUM = 3,
+};
+
+enum MagneticAxisPart {
+ MAGNETIC_X_AXIS_MSB = 0,
+ MAGNETIC_X_AXIS_LSB = 1,
+ MAGNETIC_Y_AXIS_MSB = 2,
+ MAGNETIC_Y_AXIS_LSB = 3,
+ MAGNETIC_Z_AXIS_MSB = 4,
+ MAGNETIC_Z_AXIS_LSB = 5,
+ MAGNETIC_AXIS_BUTT,
+};
+
+struct MagneticData {
+ int32_t x;
+ int32_t y;
+ int32_t z;
+};
+
+struct MagneticOpsCall {
+ int32_t (*Init)(struct SensorCfgData *data);
+ int32_t (*ReadData)(struct SensorCfgData *data);
+};
+
+struct MagneticDrvData {
+ struct IDeviceIoService ioService;
+ struct HdfDeviceObject *device;
+ HdfWorkQueue magneticWorkQueue;
+ HdfWork magneticWork;
+ OsalTimer magneticTimer;
+ bool detectFlag;
+ bool enable;
+ int64_t interval;
+ struct SensorCfgData *magneticCfg;
+ struct MagneticOpsCall ops;
+};
+
+int32_t MagneticRegisterChipOps(const struct MagneticOpsCall *ops);
+struct SensorCfgData *MagneticCreateCfgData(const struct DeviceResourceNode *node);
+void MagneticReleaseCfgData(struct SensorCfgData *sensorCfgData);
+
+#endif /* SENSOR_MAGNETIC_DRIVER_H */
diff --git a/model/sensor/driver/proximity/sensor_proximity_driver.c b/model/sensor/driver/proximity/sensor_proximity_driver.c
new file mode 100644
index 0000000000000000000000000000000000000000..9d4e770c3704ce50b02f263cb3b66fcdf4b71844
--- /dev/null
+++ b/model/sensor/driver/proximity/sensor_proximity_driver.c
@@ -0,0 +1,374 @@
+/*
+ * Copyright (c) 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 "sensor_proximity_driver.h"
+#include
+#include "hdf_base.h"
+#include "hdf_device_desc.h"
+#include "osal_math.h"
+#include "osal_mem.h"
+#include "sensor_config_controller.h"
+#include "sensor_device_manager.h"
+#include "sensor_platform_if.h"
+
+#define HDF_LOG_TAG sensor_proximity_driver_c
+
+#define HDF_PROXIMITY_WORK_QUEUE_NAME "hdf_proximity_work_queue"
+
+static struct ProximityDrvData *g_proximityDrvData = NULL;
+
+static struct ProximityDrvData *ProximityGetDrvData(void)
+{
+ return g_proximityDrvData;
+}
+
+static struct SensorRegCfgGroupNode *g_regCfgGroup[SENSOR_GROUP_MAX] = { NULL };
+
+int32_t ProximityRegisterChipOps(const struct ProximityOpsCall *ops)
+{
+ struct ProximityDrvData *drvData = NULL;
+
+ CHECK_NULL_PTR_RETURN_VALUE(ops, HDF_ERR_INVALID_PARAM);
+
+ drvData = ProximityGetDrvData();
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+ drvData->ops.Init = ops->Init;
+ drvData->ops.ReadData = ops->ReadData;
+ return HDF_SUCCESS;
+}
+
+static void ProximityDataWorkEntry(void *arg)
+{
+ int32_t ret;
+ struct ProximityDrvData *drvData = (struct ProximityDrvData *)arg;
+ CHECK_NULL_PTR_RETURN(drvData);
+ CHECK_NULL_PTR_RETURN(drvData->ops.ReadData);
+
+ ret = drvData->ops.ReadData(drvData->proximityCfg);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: proximity read data failed", __func__);
+ return;
+ }
+}
+
+static void ProximityTimerEntry(uintptr_t arg)
+{
+ int64_t interval;
+ int32_t ret;
+ struct ProximityDrvData *drvData = (struct ProximityDrvData *)arg;
+ CHECK_NULL_PTR_RETURN(drvData);
+
+ if (!HdfAddWork(&drvData->proximityWorkQueue, &drvData->proximityWork)) {
+ HDF_LOGE("%s: proximity add work queue failed", __func__);
+ }
+
+ interval = OsalDivS64(drvData->interval, (SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT));
+ interval = (interval < SENSOR_TIMER_MIN_TIME) ? SENSOR_TIMER_MIN_TIME : interval;
+ ret = OsalTimerSetTimeout(&drvData->proximityTimer, interval);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: proximity modify time failed", __func__);
+ }
+}
+
+static int32_t InitProximityData(struct ProximityDrvData *drvData)
+{
+ if (HdfWorkQueueInit(&drvData->proximityWorkQueue, HDF_PROXIMITY_WORK_QUEUE_NAME) != HDF_SUCCESS) {
+ HDF_LOGE("%s: proximity init work queue failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ if (HdfWorkInit(&drvData->proximityWork, ProximityDataWorkEntry, drvData) != HDF_SUCCESS) {
+ HDF_LOGE("%s: proximity create thread failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ drvData->interval = SENSOR_TIMER_MIN_TIME;
+ drvData->enable = false;
+ drvData->detectFlag = false;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SetProximityEnable(void)
+{
+ int32_t ret;
+ struct ProximityDrvData *drvData = ProximityGetDrvData();
+
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+ CHECK_NULL_PTR_RETURN_VALUE(drvData->proximityCfg, HDF_ERR_INVALID_PARAM);
+
+ if (drvData->enable) {
+ HDF_LOGE("%s: proximity sensor is enabled", __func__);
+ return HDF_SUCCESS;
+ }
+
+ ret = SetSensorRegCfgArray(&drvData->proximityCfg->busCfg, drvData->proximityCfg->regCfgGroup[SENSOR_ENABLE_GROUP]);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: proximity sensor enable config failed", __func__);
+ return ret;
+ }
+
+ ret = OsalTimerCreate(&drvData->proximityTimer, SENSOR_TIMER_MIN_TIME, ProximityTimerEntry, (uintptr_t)drvData);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: proximity create timer failed[%d]", __func__, ret);
+ return ret;
+ }
+
+ ret = OsalTimerStartLoop(&drvData->proximityTimer);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: proximity start timer failed[%d]", __func__, ret);
+ return ret;
+ }
+ drvData->enable = true;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SetProximityDisable(void)
+{
+ int32_t ret;
+ struct ProximityDrvData *drvData = ProximityGetDrvData();
+
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+ CHECK_NULL_PTR_RETURN_VALUE(drvData->proximityCfg, HDF_ERR_INVALID_PARAM);
+
+ if (!drvData->enable) {
+ HDF_LOGE("%s: proximity sensor had disable", __func__);
+ return HDF_SUCCESS;
+ }
+
+ ret = SetSensorRegCfgArray(&drvData->proximityCfg->busCfg,
+ drvData->proximityCfg->regCfgGroup[SENSOR_DISABLE_GROUP]);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: proximity sensor disable config failed", __func__);
+ return ret;
+ }
+
+ ret = OsalTimerDelete(&drvData->proximityTimer);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: proximity delete timer failed", __func__);
+ return ret;
+ }
+ drvData->enable = false;
+ return HDF_SUCCESS;
+}
+
+static int32_t SetProximityBatch(int64_t samplingInterval, int64_t interval)
+{
+ (void)interval;
+
+ struct ProximityDrvData *drvData = NULL;
+
+ drvData = ProximityGetDrvData();
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+
+ drvData->interval = samplingInterval;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SetProximityMode(int32_t mode)
+{
+ return (mode == SENSOR_WORK_MODE_REALTIME) ? HDF_SUCCESS : HDF_FAILURE;
+}
+
+static int32_t SetProximityOption(uint32_t option)
+{
+ (void)option;
+ return HDF_SUCCESS;
+}
+
+static int32_t DispatchProximity(struct HdfDeviceIoClient *client,
+ int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ (void)client;
+ (void)cmd;
+ (void)data;
+ (void)reply;
+
+ return HDF_SUCCESS;
+}
+
+int32_t ProximityBindDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
+
+ HDF_LOGI("%s: enter", __func__);
+ struct ProximityDrvData *drvData = (struct ProximityDrvData *)OsalMemCalloc(sizeof(*drvData));
+ if (drvData == NULL) {
+ HDF_LOGI("%s: malloc proximity drv data fail!", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ drvData->ioService.Dispatch = DispatchProximity;
+ drvData->device = device;
+ device->service = &drvData->ioService;
+ g_proximityDrvData = drvData;
+ HDF_LOGI("%s: success", __func__);
+ return HDF_SUCCESS;
+}
+
+static int32_t InitProximityOps(struct SensorCfgData *config, struct SensorDeviceInfo *deviceInfo)
+{
+ struct ProximityDrvData *drvData = ProximityGetDrvData();
+
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+
+ deviceInfo->ops.Enable = SetProximityEnable;
+ deviceInfo->ops.Disable = SetProximityDisable;
+ deviceInfo->ops.SetBatch = SetProximityBatch;
+ deviceInfo->ops.SetMode = SetProximityMode;
+ deviceInfo->ops.SetOption = SetProximityOption;
+
+ if (memcpy_s(&deviceInfo->sensorInfo, sizeof(deviceInfo->sensorInfo),
+ &config->sensorInfo, sizeof(config->sensorInfo)) != EOK) {
+ HDF_LOGE("%s: Copy sensor info failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t InitProximityAfterDetected(struct SensorCfgData *config)
+{
+ struct SensorDeviceInfo deviceInfo;
+ CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM);
+
+ if (InitProximityOps(config, &deviceInfo) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Init proximity ops failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ if (AddSensorDevice(&deviceInfo) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Add proximity device failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ if (ParseSensorRegConfig(config) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Parse sensor register failed", __func__);
+ (void)DeleteSensorDevice(&config->sensorInfo);
+ ReleaseSensorAllRegConfig(config);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+struct SensorCfgData *ProximityCreateCfgData(const struct DeviceResourceNode *node)
+{
+ struct ProximityDrvData *drvData = ProximityGetDrvData();
+
+ if (drvData == NULL || node == NULL) {
+ HDF_LOGE("%s: Proximity node pointer NULL", __func__);
+ return NULL;
+ }
+
+ if (drvData->detectFlag) {
+ HDF_LOGE("%s: Proximity sensor have detected", __func__);
+ return NULL;
+ }
+
+ if (drvData->proximityCfg == NULL) {
+ HDF_LOGE("%s: Proximity proximityCfg pointer NULL", __func__);
+ return NULL;
+ }
+
+ if (GetSensorBaseConfigData(node, drvData->proximityCfg) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Get sensor base config failed", __func__);
+ goto BASE_CONFIG_EXIT;
+ }
+
+ if (DetectSensorDevice(drvData->proximityCfg) != HDF_SUCCESS) {
+ HDF_LOGI("%s: Proximity sensor detect device no exist", __func__);
+ drvData->detectFlag = false;
+ goto BASE_CONFIG_EXIT;
+ }
+
+ drvData->detectFlag = true;
+ if (InitProximityAfterDetected(drvData->proximityCfg) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Proximity sensor detect device no exist", __func__);
+ goto INIT_EXIT;
+ }
+ return drvData->proximityCfg;
+
+INIT_EXIT:
+ (void)ReleaseSensorBusHandle(&drvData->proximityCfg->busCfg);
+BASE_CONFIG_EXIT:
+ drvData->proximityCfg->root = NULL;
+ (void)memset_s(&drvData->proximityCfg->sensorInfo, sizeof(struct SensorBasicInfo),
+ 0, sizeof(struct SensorBasicInfo));
+ (void)memset_s(&drvData->proximityCfg->busCfg, sizeof(struct SensorBusCfg), 0, sizeof(struct SensorBusCfg));
+ (void)memset_s(&drvData->proximityCfg->sensorAttr, sizeof(struct SensorAttr), 0, sizeof(struct SensorAttr));
+ return drvData->proximityCfg;
+}
+
+void ProximityReleaseCfgData(struct SensorCfgData *proximityCfg)
+{
+ CHECK_NULL_PTR_RETURN(proximityCfg);
+
+ (void)DeleteSensorDevice(&proximityCfg->sensorInfo);
+ ReleaseSensorAllRegConfig(proximityCfg);
+ (void)ReleaseSensorBusHandle(&proximityCfg->busCfg);
+
+ proximityCfg->root = NULL;
+ (void)memset_s(&proximityCfg->sensorInfo, sizeof(struct SensorBasicInfo), 0, sizeof(struct SensorBasicInfo));
+ (void)memset_s(&proximityCfg->busCfg, sizeof(struct SensorBusCfg), 0, sizeof(struct SensorBusCfg));
+ (void)memset_s(&proximityCfg->sensorAttr, sizeof(struct SensorAttr), 0, sizeof(struct SensorAttr));
+}
+
+int32_t ProximityInitDriver(struct HdfDeviceObject *device)
+{
+ CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
+ struct ProximityDrvData *drvData = (struct ProximityDrvData *)device->service;
+ CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
+
+ if (InitProximityData(drvData) != HDF_SUCCESS) {
+ HDF_LOGE("%s: Init accel config failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ drvData->proximityCfg = (struct SensorCfgData *)OsalMemCalloc(sizeof(*drvData->proximityCfg));
+ if (drvData->proximityCfg == NULL) {
+ HDF_LOGE("%s: Malloc proximity config data failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ drvData->proximityCfg->regCfgGroup = &g_regCfgGroup[0];
+
+ HDF_LOGI("%s: Init proximity driver success", __func__);
+ return HDF_SUCCESS;
+}
+
+void ProximityReleaseDriver(struct HdfDeviceObject *device)
+{
+ HDF_LOGI("%s: enter", __func__);
+ CHECK_NULL_PTR_RETURN(device);
+
+ struct ProximityDrvData *drvData = (struct ProximityDrvData *)device->service;
+ CHECK_NULL_PTR_RETURN(drvData);
+
+ if (drvData->detectFlag && drvData->proximityCfg != NULL) {
+ ProximityReleaseCfgData(drvData->proximityCfg);
+ }
+
+ OsalMemFree(drvData->proximityCfg);
+ drvData->proximityCfg = NULL;
+
+ HdfWorkDestroy(&drvData->proximityWork);
+ HdfWorkQueueDestroy(&drvData->proximityWorkQueue);
+ OsalMemFree(drvData);
+}
+
+struct HdfDriverEntry g_sensorProximityDevEntry = {
+ .moduleVersion = 1,
+ .moduleName = "HDF_SENSOR_PROXIMITY",
+ .Bind = ProximityBindDriver,
+ .Init = ProximityInitDriver,
+ .Release = ProximityReleaseDriver,
+};
+
+HDF_INIT(g_sensorProximityDevEntry);
\ No newline at end of file
diff --git a/model/sensor/driver/proximity/sensor_proximity_driver.h b/model/sensor/driver/proximity/sensor_proximity_driver.h
new file mode 100644
index 0000000000000000000000000000000000000000..7a58f4264c38fa82cfd0fcca1365829665d289c0
--- /dev/null
+++ b/model/sensor/driver/proximity/sensor_proximity_driver.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef SENSOR_PROXIMITY_DRIVER_H
+#define SENSOR_PROXIMITY_DRIVER_H
+
+#include "hdf_workqueue.h"
+#include "osal_timer.h"
+#include "sensor_config_parser.h"
+#include "sensor_platform_if.h"
+
+struct ProximityData {
+ uint8_t stateFlag;
+};
+
+struct ProximityOpsCall {
+ int32_t (*Init)(struct SensorCfgData *data);
+ int32_t (*ReadData)(struct SensorCfgData *data);
+};
+
+struct ProximityDrvData {
+ struct IDeviceIoService ioService;
+ struct HdfDeviceObject *device;
+ HdfWorkQueue proximityWorkQueue;
+ HdfWork proximityWork;
+ OsalTimer proximityTimer;
+ bool detectFlag;
+ bool enable;
+ int64_t interval;
+ struct SensorCfgData *proximityCfg;
+ struct ProximityOpsCall ops;
+};
+
+struct SensorCfgData *ProximityCreateCfgData(const struct DeviceResourceNode *node);
+int32_t ProximityRegisterChipOps(const struct ProximityOpsCall *ops);
+void ProximityReleaseCfgData(struct SensorCfgData *proximityCfg);
+
+#endif /* SENSOR_PROXIMITY_DRIVER_H */
diff --git a/model/storage/include/common/storage_block.h b/model/storage/include/common/storage_block.h
deleted file mode 100644
index 726c84d13ad98b64b93fc635b8d3c187b3f57f5e..0000000000000000000000000000000000000000
--- a/model/storage/include/common/storage_block.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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.
- */
-
-#ifndef STORAGE_BLOCK_H
-#define STORAGE_BLOCK_H
-
-#include "storage.h"
-
-#ifdef __cplusplus
-#if __cplusplus
-extern "C" {
-#endif
-#endif /* __cplusplus */
-
-#define STORAGE_SEC_SIZE 512
-#define STORAGE_SEC_SHIFT 9
-#define STORAGE_MAX_SEC_NR (STORAGE_MAX_BYTES >> STORAGE_SEC_SHIFT)
-
-#define STORAGE_SEC_PARAM_INVALID(s, n) \
- (s >= STORAGE_MAX_SEC_NR || \
- n >= STORAGE_MAX_SEC_NR || \
- (STORAGE_MAX_SEC_NR - n) <= s)
-
-#define BLOCK_NAME_LEN 32
-
-struct StorageBlock {
- char name[BLOCK_NAME_LEN]; /* name of the block device */
- int32_t index;
- enum StorageType type; /* indicate which type of media is used */
- bool removeable;
- void *media; /* media device of the block */
- size_t capacity; /* sized by sector */
- size_t secSize; /* sized by bytes */
- uint32_t errCnt; /* err count on io transfer */
- struct StorageBlockMethod *ops; /* storage oparations provided by specific media */
- void *bops; /* block operations of specific os */
-};
-
-struct StorageBlockMethod {
- ssize_t (*read)(struct StorageBlock *sb, uint8_t *buf, size_t secStart, size_t secNr);
- ssize_t (*write)(struct StorageBlock *sb, const uint8_t *buf, size_t secStart, size_t secNr);
- ssize_t (*erase)(struct StorageBlock *sb, size_t secStart, size_t secNr);
- size_t (*getCapacity)(struct StorageBlock *sb);
- bool (*isPresent)(struct StorageBlock *sb);
- uint32_t (*getAuSize)(struct StorageBlock *sb);
-};
-
-ssize_t StorageBlockRead(struct StorageBlock *sb, uint8_t *buf, size_t secStart, size_t secNr);
-ssize_t StorageBlockWrite(struct StorageBlock *sb, const uint8_t *buf, size_t secStart, size_t secNr);
-ssize_t StorageBlockErase(struct StorageBlock *sb, size_t secStart, size_t secNr);
-size_t StorageBlockGetCapacity(struct StorageBlock *sb);
-bool StorageBlockIsPresent(struct StorageBlock *sb);
-int32_t StorageBlockGetAuSize(struct StorageBlock *sb, uint32_t *auSize);
-
-int32_t StorageBlockAdd(struct StorageBlock *sb);
-void StorageBlockDel(struct StorageBlock *sb);
-
-/* these two functions gona implemented by specific os */
-int32_t StorageBlockOsInit(struct StorageBlock *sb);
-void StorageBlockOsUninit(struct StorageBlock *sb);
-
-ssize_t StorageBlockMmcErase(uint32_t blockId, size_t secStart, size_t secNr);
-struct StorageBlock *StorageBlockFromNumber(uint32_t number);
-
-
-#ifdef __cplusplus
-#if __cplusplus
-}
-#endif
-#endif /* __cplusplus */
-
-#endif /* STORAGE_BLOCK_H */
diff --git a/model/storage/include/mmc/mmc_block.h b/model/storage/include/mmc/mmc_block.h
new file mode 100644
index 0000000000000000000000000000000000000000..a1c91c16f79887b510900df38ee81624a9d599ee
--- /dev/null
+++ b/model/storage/include/mmc/mmc_block.h
@@ -0,0 +1,113 @@
+/*
+ * 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.
+ */
+
+#ifndef MMC_BLOCK_H
+#define MMC_BLOCK_H
+
+#include "mmc_corex.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* __cplusplus */
+
+/**
+ * @Defines the default mmc sector size
+ *
+ */
+#define MMC_SEC_SIZE 512
+
+/**
+ * @Defines the default mmc sector size shift
+ *
+ */
+#define MMC_SEC_SHIFT 9
+
+/**
+ * @Defines the help macro for getting sector number
+ *
+ */
+#define MMC_MAX_SEC_NR (MMC_MAX_BYTES >> MMC_SEC_SHIFT)
+
+#define MMC_SEC_PARAM_INVALID(s, n) \
+ (s >= MMC_MAX_SEC_NR || \
+ n >= MMC_MAX_SEC_NR || \
+ (MMC_MAX_SEC_NR - n) <= s)
+
+/**
+ * @Defines the max length of mmc block device name
+ *
+ */
+#define MMC_BLOCK_NAME_LEN 32
+
+/**
+ * @Defines the structure used to identify a general block device.
+ *
+ */
+struct MmcBlock {
+ char name[MMC_BLOCK_NAME_LEN]; /* name of the block device */
+ int32_t index;
+ bool removeable;
+ size_t capacity; /* sized by sector */
+ size_t secSize; /* sized by bytes */
+ uint32_t errCnt; /* err count on io transfer */
+ void *bops; /* block operations of specific os */
+ void *osData; /* os specific data */
+ struct MmcDevice *mmc;
+};
+
+/**
+ * @brief Block device init for the mmc device.
+ *
+ * This function behaves differently in different OS
+ *
+ * @param mmcDevice Indicates the pointer to the mmc device.
+ *
+ * @return Returns 0 if init successfully; returns a negative value otherwise.
+ */
+int32_t MmcBlockInit(struct MmcDevice *mmcDevice);
+
+/**
+ * @brief Block device uninit for the mmc device.
+ *
+ * This function behaves differently in different OS
+ *
+ * @param mmcDevice Indicates the pointer to the mmc device.
+ *
+ */
+void MmcBlockUninit(struct MmcDevice *mmcDevice);
+
+/**
+ * @brief Block device init for the mmc device in specific os.
+ *
+ * These function gona be implemented by specific os
+ *
+ * @param mmcDevice Indicates the pointer to the mmc device.
+ *
+ * @return Returns 0 if init successfully; returns a negative value otherwise.
+ */
+int32_t MmcBlockOsInit(struct MmcDevice *mmcDevice);
+
+/**
+ * @brief Block device uninit for the mmc device in specific os.
+ *
+ * These function gona be implemented by specific os
+ *
+ * @param mmcDevice Indicates the pointer to the mmc device.
+ *
+ */
+void MmcBlockOsUninit(struct MmcDevice *mmcDevice);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* __cplusplus */
+
+#endif /* MMC_BLOCK_H */
diff --git a/support/platform/include/mmc/mmc_caps.h b/model/storage/include/mmc/mmc_caps.h
similarity index 100%
rename from support/platform/include/mmc/mmc_caps.h
rename to model/storage/include/mmc/mmc_caps.h
diff --git a/support/platform/include/mmc/mmc_corex.h b/model/storage/include/mmc/mmc_corex.h
similarity index 98%
rename from support/platform/include/mmc/mmc_corex.h
rename to model/storage/include/mmc/mmc_corex.h
index f3c2afdaf9b541f6dc16fd57e0b1883d7e6f5790..4cd5f319c4fa453f0a1fcf49d8f2af74ef1c5604 100644
--- a/support/platform/include/mmc/mmc_corex.h
+++ b/model/storage/include/mmc/mmc_corex.h
@@ -110,7 +110,7 @@ static inline struct MmcCntlr *MmcCntlrGet(struct MmcCntlr *cntlr)
static inline struct MmcCntlr *MmcCntlrGetByNr(uint16_t number)
{
- struct PlatformDevice *device = PlatformManagerGetDeviceByMagic(PlatformManagerGet(PLATFORM_MODULE_MMC), number);
+ struct PlatformDevice *device = PlatformManagerGetDeviceByNumber(PlatformManagerGet(PLATFORM_MODULE_MMC), number);
if (device == NULL) {
return NULL;
@@ -224,7 +224,7 @@ struct MmcDevice {
size_t secSize; // by bytes
size_t capacity; // by sectors
size_t eraseSize; // by sectors
- struct StorageBlock *sb;
+ struct MmcBlock *mb;
void *priv;
};
diff --git a/support/platform/include/mmc/mmc_dispatch.h b/model/storage/include/mmc/mmc_dispatch.h
similarity index 100%
rename from support/platform/include/mmc/mmc_dispatch.h
rename to model/storage/include/mmc/mmc_dispatch.h
diff --git a/support/platform/include/mmc/mmc_emmc.h b/model/storage/include/mmc/mmc_emmc.h
similarity index 100%
rename from support/platform/include/mmc/mmc_emmc.h
rename to model/storage/include/mmc/mmc_emmc.h
diff --git a/support/platform/include/mmc/mmc_protocol.h b/model/storage/include/mmc/mmc_protocol.h
similarity index 100%
rename from support/platform/include/mmc/mmc_protocol.h
rename to model/storage/include/mmc/mmc_protocol.h
diff --git a/support/platform/include/mmc/mmc_sd.h b/model/storage/include/mmc/mmc_sd.h
similarity index 100%
rename from support/platform/include/mmc/mmc_sd.h
rename to model/storage/include/mmc/mmc_sd.h
diff --git a/support/platform/include/mmc/mmc_sdio.h b/model/storage/include/mmc/mmc_sdio.h
similarity index 100%
rename from support/platform/include/mmc/mmc_sdio.h
rename to model/storage/include/mmc/mmc_sdio.h
diff --git a/model/storage/include/mtd/mtd_block.h b/model/storage/include/mtd/mtd_block.h
index c1dc005ac9aff0d48ab0fa1c85f0e986725896ed..9d82c4db0b32a22a7f600b1a72d87f34e8bcf423 100644
--- a/model/storage/include/mtd/mtd_block.h
+++ b/model/storage/include/mtd/mtd_block.h
@@ -17,12 +17,47 @@ extern "C" {
#endif
#endif /* __cplusplus */
-int32_t MtdBlockInit(struct MtdDevice *mtd);
-void MtdBlockUninit(struct MtdDevice *mtd);
+/**
+ * @brief Block device init for the mtd device.
+ *
+ * This function behaves differently in different OS
+ *
+ * @param mtdDevice Indicates the pointer to the mtd device.
+ *
+ * @return Returns 0 if init successfully; returns a negative value otherwise.
+ */
+int32_t MtdBlockInit(struct MtdDevice *mtdDevice);
+
+/**
+ * @brief Block device uninit for the mtd device.
+ *
+ * This function behaves differently in different OS
+ *
+ * @param mtdDevice Indicates the pointer to the mtd device.
+ *
+ */
+void MtdBlockUninit(struct MtdDevice *mtdDevice);
-/* these too functions gona implemented by specific os */
-extern int32_t MtdBlockOsInit(struct MtdDevice *mtd);
-extern void MtdBlockOsUninit(struct MtdDevice *mtd);
+/**
+ * @brief Block device init for the mtd device in specific os.
+ *
+ * These function gona be implemented by specific os
+ *
+ * @param mtdDevice Indicates the pointer to the mtd device.
+ *
+ * @return Returns 0 if init successfully; returns a negative value otherwise.
+ */
+int32_t MtdBlockOsInit(struct MtdDevice *mtd);
+
+/**
+ * @brief Block device uninit for the mtd device in specific os.
+ *
+ * These function gona be implemented by specific os
+ *
+ * @param mtdDevice Indicates the pointer to the mtd device.
+ *
+ */
+void MtdBlockOsUninit(struct MtdDevice *mtd);
#ifdef __cplusplus
#if __cplusplus
diff --git a/model/storage/include/mtd/mtd_char.h b/model/storage/include/mtd/mtd_char.h
index 3d32a273680778869c23b50151435844a0a492c8..80b8ff4ff6d2535ee2ac59ac6924d8557dcc2b70 100644
--- a/model/storage/include/mtd/mtd_char.h
+++ b/model/storage/include/mtd/mtd_char.h
@@ -19,12 +19,47 @@ extern "C" {
#define CHAR_NAME_LEN 32
+/**
+ * @brief Char device init for the mtd device.
+ *
+ * This function behaves differently in different OS
+ *
+ * @param mtdDevice Indicates the pointer to the mtd device.
+ *
+ * @return Returns 0 if init successfully; returns a negative value otherwise.
+ */
int32_t MtdCharInit(struct MtdDevice *mtdDevice);
+
+/**
+ * @brief Char device uninit for the mtd device.
+ *
+ * This function behaves differently in different OS
+ *
+ * @param mtdDevice Indicates the pointer to the mtd device.
+ *
+ */
void MtdCharUninit(struct MtdDevice *mtdDevice);
-/* these too functions gona implemented by specific os */
-extern int32_t MtdCharOsInit(struct MtdDevice *mtdDevice);
-extern void MtdCharOsUninit(struct MtdDevice *mtdDevice);
+/**
+ * @brief Char device init for the mtd device in specific OS.
+ *
+ * These function gona be implemented by specific os
+ *
+ * @param mtdDevice Indicates the pointer to the mtd device.
+ *
+ * @return Returns 0 if init successfully; returns a negative value otherwise.
+ */
+int32_t MtdCharOsInit(struct MtdDevice *mtdDevice);
+
+/**
+ * @brief Char device uninit for the mtd device in specific OS.
+ *
+ * These function gona be implemented by specific os
+ *
+ * @param mtdDevice Indicates the pointer to the mtd device.
+ *
+ */
+void MtdCharOsUninit(struct MtdDevice *mtdDevice);
#ifdef __cplusplus
#if __cplusplus
diff --git a/model/storage/include/mtd/mtd_core.h b/model/storage/include/mtd/mtd_core.h
index 4b1f311903fbec7402e618b24f55a48b4bfc5009..6a384ecf3ce14815a6f8aac5d38ade0d1fc0a17c 100644
--- a/model/storage/include/mtd/mtd_core.h
+++ b/model/storage/include/mtd/mtd_core.h
@@ -13,15 +13,20 @@
#include "hdf_base.h"
#include "osal_mutex.h"
-#include "platform_device.h"
+#include "platform_core.h"
#define MTD_FLASH_ID_LEN_MAX 8
+#define MTD_DEVICE_NUM_MAX 3
-// #define MTD_DEBUG /* open this macro for debug */
+// #define MTD_DEBUG /* open this macro for debug
struct MtdDevice;
struct MtdDeviceMethod;
+/**
+ * @brief Enumerates the types of mtd devices.
+ *
+ */
enum MtdDevType {
MTD_TYPE_NOR,
MTD_TYPE_NAND,
@@ -30,32 +35,68 @@ enum MtdDevType {
MTD_TYPE_MAX,
};
+/**
+ * @brief Enumerates the types of mtd message.
+ *
+ */
enum MtdMsgType {
MTD_MSG_TYPE_WRITE,
MTD_MSG_TYPE_READ,
MTD_MSG_TYPE_ERASE,
};
+/**
+ * @Defines the mtd request message used during request.
+ *
+ * This struct describes a custom access request typed by MtdMsgType
+ *
+ */
struct MtdMsg {
+ /** Type of the mtd message */
enum MtdMsgType type;
+ /** Start address of the mtd device to access */
off_t addr;
+ /** Indicates the failed address if request failed */
off_t faddr;
+ /** Pointer to the buffer for storing request data */
uint8_t *buf;
+ /** Length of the data */
size_t len;
+ /** Indicates whether request with oob data */
bool withOob;
+ /** Indicates whether skip on bad block */
bool skipBad;
};
+/**
+ * @Defines the mtd page struct used during page transfer.
+ *
+ * This struct describes a page transfer request typed by MtdMsgType
+ *
+ */
struct MtdPage {
+ /** Page transfer type */
enum MtdMsgType type;
+ /** Start address of the mtd device to transfer from */
off_t addr;
+ /** Indicates the failed address if transfer failed */
off_t failAddr;
+ /** Pointer to the data buffer */
uint8_t *dataBuf;
+ /** Length of the data */
size_t dataLen;
+ /** Pointer to the oob data buffer */
uint8_t *oobBuf;
+ /** Length of the oob data */
size_t oobLen;
};
+/**
+ * @Defines the callback method set of a mtd device.
+ *
+ * The methods defined in this struct expected to be implemented by drivers
+ *
+ */
struct MtdDeviceMethod {
int32_t (*read)(struct MtdDevice *mtdDevice, off_t from, size_t len, uint8_t *buf);
int32_t (*write)(struct MtdDevice *mtdDevice, off_t to, size_t len, const uint8_t *buf);
@@ -68,58 +109,244 @@ struct MtdDeviceMethod {
void (*unlock)(struct MtdDevice *mtdDevice);
};
+/**
+ * @Defines the structure used to identify a physical mtd chip.
+ *
+ */
struct MtdDevice {
+ /** The parent device */
struct PlatformDevice device;
+ /** Number of the mtd device */
int16_t index;
+ /** Name of the mtd device */
const char *name;
+ /** Chip name of the mtd device */
const char *chipName;
+ /** Type of the mtd device */
enum MtdDevType type;
union {
+ /** Vendor id of the mtd device */
uint8_t id[MTD_FLASH_ID_LEN_MAX];
struct {
uint8_t mfrId; // id[0]: Manufacture ID
uint8_t devId; // id[0]: Device ID
};
};
+ /** Length of the vendor id */
uint16_t idLen;
- size_t capacity; // by bytes
- size_t eraseSize; // by bytes
- size_t writeSize; // by bytes
- size_t readSize; // by bytes
- size_t oobSize; // for nand only
+ /** Length of the vendor id */
+ size_t capacity;
+ /** Erase size of the mtd device */
+ size_t eraseSize;
+ /** Write size of the mtd device */
+ size_t writeSize;
+ /** Read size of the mtd device */
+ size_t readSize;
+ /** Oob size of the mtd device */
+ size_t oobSize;
+ /** Write size shift bits of the mtd device */
unsigned int writeSizeShift;
+ /** Mutex lock for accessing protection */
struct OsalMutex lock;
+ /** The callback method set to access the device */
struct MtdDeviceMethod *ops;
+ /** Os specific data */
void *osData;
+ /** Flash memory controller specific data */
void *cntlr;
+ /** Private data of the mtd device */
void *priv;
};
+/**
+ * @brief Get the manager of mtd
+ *
+ * @return Returns the pointer to the manager if success;
+ * returns NULL otherwise.
+ */
+struct PlatformManager *MtdManagerGet(void);
+
+/**
+ * @brief Add a mtd device.
+ *
+ * do not call in irq context cause it may sleep
+ *
+ * @param mtdDevice Indicates the pointer to the mtd device.
+ *
+ * @return Returns 0 if add successfully; returns a negative value otherwise.
+ */
int32_t MtdDeviceAdd(struct MtdDevice *mtdDevice);
+
+/**
+ * @brief Delete a mtd device.
+ *
+ * do not call in irq context cause it may sleep
+ *
+ * @param mtdDevice Indicates the pointer to the mtd device.
+ */
void MtdDeviceDel(struct MtdDevice *mtdDevice);
+/**
+ * @brief Increase reference count for a mtd device.
+ *
+ * @param mtdDevice Indicates the pointer to the mtd device.
+ *
+ * @return Returns the pointer to the mtd device on success; returns NULL otherwise.
+ */
+static inline struct MtdDevice *MtdDeviceGet(struct MtdDevice *mtdDevice)
+{
+ if (mtdDevice != NULL && PlatformDeviceGet(&mtdDevice->device) != NULL) {
+ return mtdDevice;
+ }
+ return NULL;
+}
+
+/**
+ * @brief Increase reference count for a mtd device by number.
+ *
+ * @param mtdDevice Indicates the pointer to the mtd device.
+ *
+ * @return Returns the pointer to the mtd device on success; returns NULL otherwise.
+ */
+static inline struct MtdDevice *MtdDeviceGetByNum(int16_t num)
+{
+ struct PlatformDevice *device = PlatformManagerGetDeviceByNumber(MtdManagerGet(), num);
+
+ if (device != NULL) {
+ return CONTAINER_OF(device, struct MtdDevice, device);
+ }
+ return NULL;
+}
+
+/**
+ * @brief Decrease reference count for a mtd device.
+ *
+ * @param mtdDevice Indicates the pointer to the mtd device.
+ */
+static inline void MtdDevicePut(struct MtdDevice *mtdDevice)
+{
+ if (mtdDevice != NULL) {
+ PlatformDevicePut(&mtdDevice->device);
+ }
+}
+
+/**
+ * @brief Lock the mtd device exclusivly.
+ *
+ * do not call in irq context cause it may sleep
+ *
+ * @param mtdDevice Indicates the pointer to the mtd device.
+ *
+ * @return Returns 0 on success; returns a negative value otherwise.
+ */
int32_t MtdDeviceLock(struct MtdDevice *mtdDevice);
+
+/**
+ * @brief Unlock the mtd device.
+ *
+ * do not call in irq context cause it may sleep
+ *
+ * @param mtdDevice Indicates the pointer to the mtd device.
+ */
void MtdDeviceUnlock(struct MtdDevice *mtdDevice);
+/**
+ * @brief Reads data of a specified size from a mtd device.
+ *
+ * do not call in irq context cause it may sleep
+ *
+ * @param mtdDevice Indicates the pointer to the mtd device.
+ * @param from Indicates the start address to read from.
+ * @param len Indicates the size of the data to read.
+ * @param buf Indicates the pointer to the buffer for receiving the data.
+ *
+ * @return Returns the size of the data read on success; returns a negative value otherwise.
+ */
ssize_t MtdDeviceRead(struct MtdDevice *mtdDevice, off_t from, size_t len, uint8_t *buf);
+
+/**
+ * @brief Writes data of a specified size to a mtd device.
+ *
+ * do not call in irq context cause it may sleep
+ *
+ * @param mtdDevice Indicates the pointer to the mtd device.
+ * @param to Indicates the start address to write to.
+ * @param len Indicates the size of the data to write.
+ * @param buf Indicates the pointer to the buffer which provide the data.
+ *
+ * @return Returns the size of the data written on success; returns a negative value otherwise.
+ */
ssize_t MtdDeviceWrite(struct MtdDevice *mtdDevice, off_t to, size_t len, const uint8_t *buf);
-ssize_t MtdDeviceErase(struct MtdDevice *mtdDevice, off_t from, size_t len, off_t *failAddr);
+/**
+ * @brief Erases data of a specified size to a mtd device.
+ *
+ * do not call in irq context cause it may sleep
+ *
+ * @param mtdDevice Indicates the pointer to the mtd device.
+ * @param from Indicates the start address to erase from.
+ * @param len Indicates the size of the data to erase.
+ * @param faddr Indicates the pointer for receiving the address when erasing failed.
+ *
+ * @return Returns the size of the data erased on success; returns a negative value otherwise.
+ */
+ssize_t MtdDeviceErase(struct MtdDevice *mtdDevice, off_t from, size_t len, off_t *faddr);
+
+/**
+ * @brief Reads data of a specified size from a mtd device including oob data.
+ *
+ * It is similar to MtdDeviceRead but read oob data together.
+ *
+ * @param mtdDevice Indicates the pointer to the mtd device.
+ * @param from Indicates the start address to read from.
+ * @param len Indicates the size of the data, including oob, to read.
+ * @param buf Indicates the pointer to the buffer for receiving the data, including oob data.
+ *
+ * @return Returns the size of the data read on success; returns a negative value otherwise.
+ */
ssize_t MtdDeviceReadWithOob(struct MtdDevice *mtdDevice, off_t from, size_t len, uint8_t *buf);
+
+/**
+ * @brief Writes data of a specified size to a mtd device including oob data.
+ *
+ * It is similar to MtdDeviceWrite but write oob data together.
+ *
+ * @param mtdDevice Indicates the pointer to the mtd device.
+ * @param to Indicates the start address to write to.
+ * @param len Indicates the size of the data, including oob, to .
+ * @param buf Indicates the pointer to the buffer which provide the data including oob.
+ *
+ * @return Returns the size of the data read on success; returns a negative value otherwise.
+ */
ssize_t MtdDeviceWriteWithOob(struct MtdDevice *mtdDevice, off_t to, size_t len, const uint8_t *buf);
+
+/**
+ * @brief Judge whether the block where the specified address is located is a bad block
+ *
+ * @param mtdDevice Indicates the pointer to the mtd device.
+ * @param addr Indicates the address to judge, which is not neccessary to align by block size.
+ *
+ * @return Returns true is the specified address falls into a bad block; returns false otherwise.
+ */
bool MtdDeviceIsBadBlock(struct MtdDevice *mtdDevice, off_t addr);
+
+/**
+ * @brief Mark the block where the specified address is located as a bad block
+ *
+ * @param mtdDevice Indicates the pointer to the mtd device.
+ * @param addr Indicates the address to mark, which is not neccessary to align by block size.
+ *
+ * @return Returns 0 on success; returns a negative value otherwise.
+ */
int32_t MtdDeviceMarkBadBlock(struct MtdDevice *mtdDevice, off_t addr);
-static inline bool MtdDeviceIsPageAligned(struct MtdDevice *mtdDevice, off_t addr)
-{
- return ((addr & (mtdDevice->writeSize - 1)) == 0);
-}
-static inline size_t MtdDeviceAddrToPage(struct MtdDevice *mtdDevice, off_t addr)
-{
- return (size_t)(addr >> mtdDevice->writeSizeShift);
-}
+/***************************** Other Utils *******************************************/
+/**
+ * @brief A debugging macro which an dump all the attributes of a mtd device
+ *
+ */
#define MTD_DEVICE_DUMP(mtd) \
do { \
uint16_t i; \
@@ -134,9 +361,28 @@ static inline size_t MtdDeviceAddrToPage(struct MtdDevice *mtdDevice, off_t addr
HDF_LOGI("%s: oobSize: %zu", __func__, mtd->oobSize); \
} while (0)
+/**
+ * @brief Judge whether the specified address is aligned by page size
+ *
+ */
+static inline bool MtdDeviceIsPageAligned(struct MtdDevice *mtdDevice, off_t addr)
+{
+ return ((addr & (mtdDevice->writeSize - 1)) == 0);
+}
-/***************************** Other Utils *******************************************/
+/**
+ * @brief Transfer the specified address to page number
+ *
+ */
+static inline size_t MtdDeviceAddrToPage(struct MtdDevice *mtdDevice, off_t addr)
+{
+ return (size_t)(addr >> mtdDevice->writeSizeShift);
+}
+/**
+ * @brief Flush the cache for dma transfer
+ *
+ */
static inline void MtdDmaCacheClean(void *addr, size_t size)
{
uintptr_t start = (uintptr_t)addr & ~(CACHE_ALIGNED_SIZE - 1);
@@ -147,6 +393,10 @@ static inline void MtdDmaCacheClean(void *addr, size_t size)
return;
}
+/**
+ * @brief Invalid the cache for dma transfer
+ *
+ */
static inline void MtdDmaCacheInv(void *addr, size_t size)
{
uintptr_t start = (uintptr_t)addr & ~(CACHE_ALIGNED_SIZE - 1);
@@ -157,6 +407,11 @@ static inline void MtdDmaCacheInv(void *addr, size_t size)
return;
}
+/**
+ * @brief Find the first bit set in word
+ *
+ * @return Returns the position of first bit set; returns 0 if all zero.
+ */
int MtdFfs(int x);
#endif /* MTD_CORE_H */
diff --git a/model/storage/include/mtd/mtd_nand.h b/model/storage/include/mtd/mtd_nand.h
index 055f7c88b1451435163f02ceeb62ebd39d9cddba..01101da644ef3a3a63508d93a4e928b37a4782bf 100644
--- a/model/storage/include/mtd/mtd_nand.h
+++ b/model/storage/include/mtd/mtd_nand.h
@@ -18,6 +18,10 @@ extern "C" {
#endif
#endif /* __cplusplus */
+/**
+ * @brief Enumerates the page size type of a nand flash memory.
+ *
+ */
enum MtdNandPageSize {
MTD_NAND_PAGE_SIZE_512 = 512,
MTD_NAND_PAGE_SIZE_2K = 2048,
@@ -26,6 +30,10 @@ enum MtdNandPageSize {
MTD_NAND_PAGE_SIZE_16K = 16384,
};
+/**
+ * @brief Enumerates the ECC type of a nand flash memory.
+ *
+ */
enum MtdNandEccTYpe {
MTD_NAND_ECC_0BIT = 0,
MTD_NAND_ECC_8BIT_1K = 1,
@@ -36,6 +44,10 @@ enum MtdNandEccTYpe {
MTD_NAND_ECC_64BIT_1K = 6,
};
+/**
+ * @brief Defines the bad block area size of a nand flash memory.
+ *
+ */
#define MTD_NAND_BB_SIZE 2
#ifdef __cplusplus
diff --git a/model/storage/include/mtd/mtd_spi_common.h b/model/storage/include/mtd/mtd_spi_common.h
index cf46b3a5795229bc6d899e9abc713a6065ecf4b7..a55e1f099c65447babbc531b874f4d99f31ae144 100644
--- a/model/storage/include/mtd/mtd_spi_common.h
+++ b/model/storage/include/mtd/mtd_spi_common.h
@@ -19,14 +19,39 @@ extern "C" {
struct SpiFlash;
+/**
+ * @Defines the spi configuration of a specific operation
+ *
+ */
struct MtdSpiConfig {
+ /** spi interface type */
uint8_t ifType;
+ /** the operation command */
uint8_t cmd;
+ /** dummy cycles */
uint8_t dummy;
+ /** not used now */
uint32_t size;
+ /** system clock used */
uint32_t clock;
};
+/**
+ * @brief Enumerates the type of spi interface.
+ *
+ */
+enum SpiIfType {
+ MTD_SPI_IF_STD = 0,
+ MTD_SPI_IF_DUAL = 1,
+ MTD_SPI_IF_DIO = 2,
+ MTD_SPI_IF_QUAD = 3,
+ MTD_SPI_IF_QIO = 4,
+};
+
+/**
+ * @Defines the spi oepration set of a mtd device.
+ *
+ */
struct MtdSpiOps {
int32_t (*waitReady)(struct SpiFlash *spi);
int32_t (*writeEnable)(struct SpiFlash *spi);
@@ -34,38 +59,91 @@ struct MtdSpiOps {
int32_t (*entry4Addr)(struct SpiFlash *spi, int enable);
};
+/**
+ * @Defines the info structure which contains vendor id and spi operations
+ *
+ */
struct SpiOpsInfo {
uint8_t id[MTD_FLASH_ID_LEN_MAX];
uint8_t idLen;
struct MtdSpiOps spiOps;
};
-enum SpiIfType {
- MTD_SPI_IF_STD = 0,
- MTD_SPI_IF_DUAL = 1,
- MTD_SPI_IF_DIO = 2,
- MTD_SPI_IF_QUAD = 3,
- MTD_SPI_IF_QIO = 4,
-};
-
+/**
+ * @Defines the structure used to identify a physical spi flash.
+ *
+ */
struct SpiFlash {
+ /** The parent device */
struct MtdDevice mtd;
+ /** chip select number */
uint8_t cs;
- uint8_t qeEnable;
- uint8_t qeSupport;
+ /** address cycle */
uint32_t addrCycle;
+ /** spi configuration of erase */
struct MtdSpiConfig eraseCfg;
+ /** spi configuration of write */
struct MtdSpiConfig writeCfg;
+ /** spi configuration of read */
struct MtdSpiConfig readCfg;
+ /** spi operation set of the device */
struct MtdSpiOps spiOps;
};
+/**
+ * @brief Wait for a spi flash to be ready.
+ *
+ * @param spi Indicates the pointer to the spi flash.
+ *
+ * @return Returns 0 on success; returns a negative value otherwise.
+ */
int32_t SpiFlashWaitReady(struct SpiFlash *spi);
+
+/**
+ * @brief Enable write operation to a spi falsh.
+ *
+ * @param spi Indicates the pointer to the spi flash.
+ *
+ * @return Returns 0 on success; returns a negative value otherwise.
+ */
int32_t SpiFlashWriteEnable(struct SpiFlash *spi);
+
+/**
+ * @brief Enable QUAD I/O mode of a spi falsh if it supports.
+ *
+ * @param spi Indicates the pointer to the spi flash.
+ *
+ * @return Returns 0 on success; returns a negative value otherwise.
+ */
int32_t SpiFlashQeEnable(struct SpiFlash *spi);
+
+/**
+ * @brief Enable 4 byte address mode of a spi falsh if it supports.
+ *
+ * @param spi Indicates the pointer to the spi flash.
+ *
+ * @return Returns 0 on success; returns a negative value otherwise.
+ */
int32_t SpiFlashEntry4Addr(struct SpiFlash *spi, int enable);
+/**
+ * @brief Add a spi flash device.
+ *
+ * do not call in irq context cause it may sleep
+ *
+ * @param spi Indicates the pointer to the spi flash device.
+ *
+ * @return Returns 0 if add successfully; returns a negative value otherwise.
+ */
int32_t SpiFlashAdd(struct SpiFlash *spi);
+
+/**
+ * @brief Delete a spi flash device.
+ *
+ * do not call in irq context cause it may sleep
+ *
+ * @param spi Indicates the pointer to the spi flash device.
+ */
void SpiFlashDel(struct SpiFlash *spi);
/****************************Spi Common Command Set **************************************/
@@ -117,7 +195,6 @@ void SpiFlashDel(struct SpiFlash *spi);
#ifdef __cplusplus
#if __cplusplus
-
}
#endif
#endif /* __cplusplus */
diff --git a/model/storage/include/mtd/mtd_spi_nand.h b/model/storage/include/mtd/mtd_spi_nand.h
index 76b3e7ecb8ea366ed7bd76935e764d1f8d030c41..eb8a3dce0505243cbf73411a04719d47a2aa971a 100644
--- a/model/storage/include/mtd/mtd_spi_nand.h
+++ b/model/storage/include/mtd/mtd_spi_nand.h
@@ -41,6 +41,10 @@ extern "C" {
#define MTD_SPI_NAND_ERASE_FAIL 0x04
#define MTD_SPI_NAND_PROG_FAIL 0x08
+/**
+ * @Defines the structure used to describe a spi nand flash.
+ *
+ */
struct SpinandInfo {
const char *name;
uint8_t id[MTD_FLASH_ID_LEN_MAX];
diff --git a/model/storage/include/mtd/mtd_spi_nor.h b/model/storage/include/mtd/mtd_spi_nor.h
index fd1e210eb313cdac659fef6c2e6593a781614276..cab675bb1da1914845de13da23931a132f022f62 100644
--- a/model/storage/include/mtd/mtd_spi_nor.h
+++ b/model/storage/include/mtd/mtd_spi_nor.h
@@ -23,6 +23,10 @@ extern "C" {
#define MTD_SPI_ADDR_3BYTE 3
#define MTD_SPI_ADDR_4BYTE 4
+/**
+ * @Defines the structure used to describe a spi nor flash.
+ *
+ */
struct SpinorInfo {
const char *name;
uint8_t id[MTD_FLASH_ID_LEN_MAX];
diff --git a/model/storage/src/common/storage_block.c b/model/storage/src/common/storage_block.c
deleted file mode 100644
index 54733351e5e9899bc54e35d91473f2f9c5847f05..0000000000000000000000000000000000000000
--- a/model/storage/src/common/storage_block.c
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * 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 "hdf_base.h"
-#include "hdf_log.h"
-#include "platform_core.h"
-#include "storage_block.h"
-
-#define HDF_LOG_TAG storage_block_c
-
-#define MAX_BLOCK_COUNT 3
-
-static struct StorageBlock *g_blocks[MAX_BLOCK_COUNT];
-
-ssize_t StorageBlockErase(struct StorageBlock *sb, size_t secStart, size_t secNr)
-{
- if (sb == NULL) {
- return HDF_ERR_INVALID_OBJECT;
- }
- if (sb->ops == NULL || sb->ops->erase == NULL) {
- return HDF_ERR_NOT_SUPPORT;
- }
- return sb->ops->erase(sb, secStart, secNr);
-}
-
-ssize_t StorageBlockWrite(struct StorageBlock *sb, const uint8_t *buf, size_t secStart, size_t secNr)
-{
- if (sb == NULL) {
- return HDF_ERR_INVALID_OBJECT;
- }
- if (sb->ops == NULL || sb->ops->write == NULL) {
- return HDF_ERR_NOT_SUPPORT;
- }
- return sb->ops->write(sb, buf, secStart, secNr);
-}
-
-ssize_t StorageBlockRead(struct StorageBlock *sb, uint8_t *buf, size_t secStart, size_t secNr)
-{
- if (sb == NULL) {
- return HDF_ERR_INVALID_OBJECT;
- }
- if (sb->ops == NULL || sb->ops->read == NULL) {
- return HDF_ERR_NOT_SUPPORT;
- }
- return sb->ops->read(sb, buf, secStart, secNr);
-}
-
-int32_t StorageBlockGetAuSize(struct StorageBlock *sb, uint32_t *auSize)
-{
- if (sb == NULL) {
- return HDF_ERR_INVALID_OBJECT;
- }
- if (sb->ops == NULL || sb->ops->getAuSize == NULL) {
- return HDF_ERR_NOT_SUPPORT;
- }
- *auSize = sb->ops->getAuSize(sb);
- return HDF_SUCCESS;
-}
-
-size_t StorageBlockGetCapacity(struct StorageBlock *sb)
-{
- return (sb == NULL) ? 0 : sb->capacity;
-}
-
-bool StorageBlockIsPresent(struct StorageBlock *sb)
-{
- return (sb != NULL && sb->ops != NULL &&
- sb->ops->isPresent != NULL && sb->ops->isPresent(sb));
-}
-
-int32_t StorageBlockAdd(struct StorageBlock *sb)
-{
- int i;
- int32_t ret;
-
- if (sb == NULL) {
- return HDF_ERR_INVALID_OBJECT;
- }
-
- for (i = 0; i < MAX_BLOCK_COUNT; i++) {
- if (g_blocks[i] == NULL) {
- g_blocks[i] = sb;
- sb->index = i;
- break;
- }
- }
- if (i >= MAX_BLOCK_COUNT) {
- return HDF_PLT_ERR_DEV_FULL;
- }
-
- if (sb->secSize == 0) {
- sb->secSize = STORAGE_SEC_SIZE;
- }
-
- ret = StorageBlockOsInit(sb);
- if (ret != HDF_SUCCESS) {
- g_blocks[i] = NULL;
- return ret;
- }
-
- return HDF_SUCCESS;
-}
-
-void StorageBlockDel(struct StorageBlock *sb)
-{
- int i;
-
- if (sb == NULL) {
- return;
- }
-
- for (i = 0; i < MAX_BLOCK_COUNT; i++) {
- if (g_blocks[i] == sb) {
- g_blocks[i] = NULL;
- }
- }
-
- StorageBlockOsUninit(sb);
-}
-
-struct StorageBlock *StorageBlockFromNumber(uint32_t number)
-{
- if (number >= MAX_BLOCK_COUNT) {
- HDF_LOGE("StorageBlockFromNumber: invalid number:%d", number);
- return NULL;
- }
- return g_blocks[number];
-}
diff --git a/support/platform/src/mmc/emmc_if.c b/model/storage/src/mmc/emmc_if.c
similarity index 98%
rename from support/platform/src/mmc/emmc_if.c
rename to model/storage/src/mmc/emmc_if.c
index b3c9f206143032da4de12d4fbfdb59868ef6955f..1086295a9938f9f3b2dfe99dd19099e78b864c9d 100644
--- a/support/platform/src/mmc/emmc_if.c
+++ b/model/storage/src/mmc/emmc_if.c
@@ -11,12 +11,10 @@
#include "mmc_emmc.h"
#endif
#include "emmc_if.h"
-#include "hdf_base.h"
#ifdef __USER__
#include "hdf_io_service_if.h"
#endif
#include "hdf_log.h"
-#include "osal_mem.h"
#include "securec.h"
#define HDF_LOG_TAG emmc_if_c
@@ -112,6 +110,10 @@ static int32_t EmmcDeviceGetFromHandle(DevHandle handle, struct EmmcDevice **emm
int32_t EmmcGetCid(DevHandle handle, uint8_t *cid, uint32_t size)
{
+#ifndef __USER__
+ struct EmmcDevice *emmc = NULL;
+ int32_t ret;
+#endif
if (handle == NULL) {
HDF_LOGE("EmmcGetCid: handle is NULL!");
return HDF_ERR_INVALID_OBJECT;
@@ -124,9 +126,6 @@ int32_t EmmcGetCid(DevHandle handle, uint8_t *cid, uint32_t size)
#ifdef __USER__
return EmmcServiceGetCid((struct HdfIoService *)handle, cid, size);
#else
- struct EmmcDevice *emmc = NULL;
- int32_t ret;
-
if (EmmcDeviceGetFromHandle(handle, &emmc) != HDF_SUCCESS) {
return HDF_ERR_INVALID_OBJECT;
}
diff --git a/model/storage/src/mmc/mmc_block.c b/model/storage/src/mmc/mmc_block.c
new file mode 100644
index 0000000000000000000000000000000000000000..19a0949ab5e0c9e96d65639caf228391fec7c652
--- /dev/null
+++ b/model/storage/src/mmc/mmc_block.c
@@ -0,0 +1,69 @@
+/*
+ * 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 "securec.h"
+
+#include "hdf_base.h"
+#include "hdf_log.h"
+#include "mmc_block.h"
+
+#define HDF_LOG_TAG mmc_block_c
+
+int32_t MmcBlockInit(struct MmcDevice *mmcDevice)
+{
+ int32_t ret;
+ size_t nameSize;
+ struct MmcBlock *mb = NULL;
+
+ if (mmcDevice == NULL) {
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ if (PlatformDeviceGet(&mmcDevice->device) == NULL) {
+ return HDF_PLT_ERR_DEV_GET;
+ }
+
+ mb = (struct MmcBlock *)OsalMemCalloc(sizeof(*mb));
+ if (mb == NULL) {
+ PlatformDevicePut(&mmcDevice->device);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ mmcDevice->mb = mb;
+ mb->mmc = mmcDevice;
+ mb->secSize = mmcDevice->secSize;
+ mb->capacity = mmcDevice->capacity;
+ mb->removeable = (mmcDevice->state.bits.removeable == 0) ? false : true;
+ nameSize = sizeof(mb->name);
+ ret = snprintf_s(mb->name, nameSize, nameSize - 1, "/dev/mmcblk%0d", mmcDevice->cntlr->index);
+ if (ret <= 0) {
+ OsalMemFree(mb);
+ PlatformDevicePut(&mmcDevice->device);
+ HDF_LOGE("%s: format block dev name failed, ret = %d", __func__, ret);
+ return HDF_PLT_ERR_OS_API;
+ }
+
+ ret = MmcBlockOsInit(mmcDevice);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: mmc block os init failed, ret = %d", __func__, ret);
+ OsalMemFree(mb);
+ PlatformDevicePut(&mmcDevice->device);
+ return ret;
+ }
+ return HDF_SUCCESS;
+}
+
+void MmcBlockUninit(struct MmcDevice *mmcDevice)
+{
+ if (mmcDevice != NULL) {
+ MmcBlockOsUninit(mmcDevice);
+ OsalMemFree(mmcDevice->mb);
+ mmcDevice->mb = NULL;
+ PlatformDevicePut(&mmcDevice->device);
+ }
+}
diff --git a/support/platform/src/mmc/mmc_core.c b/model/storage/src/mmc/mmc_core.c
similarity index 99%
rename from support/platform/src/mmc/mmc_core.c
rename to model/storage/src/mmc/mmc_core.c
index 6d2670b1ae9f4f8d171de83141be8718afb98999..2b377d2e0c19ed5f792f1a14df43db1806f8beee 100644
--- a/support/platform/src/mmc/mmc_core.c
+++ b/model/storage/src/mmc/mmc_core.c
@@ -7,15 +7,10 @@
*/
#include "device_resource_if.h"
-#include "hdf_dlist.h"
-#include "hdf_log.h"
#include "mmc_block.h"
-#include "mmc_corex.h"
#include "mmc_dispatch.h"
#include "mmc_emmc.h"
#include "mmc_sdio.h"
-#include "osal_mem.h"
-#include "osal_time.h"
#define HDF_LOG_TAG mmc_core_c
@@ -235,7 +230,7 @@ static int32_t MmcCntlrInit(struct MmcCntlr *cntlr)
cntlr->service.Dispatch = MmcIoDispatch;
cntlr->hdfDevObj->service = &(cntlr->service);
- cntlr->device.magic = cntlr->index;
+ cntlr->device.number = cntlr->index;
cntlr->device.hdfDev = cntlr->hdfDevObj;
return HDF_SUCCESS;
}
@@ -990,7 +985,7 @@ int32_t MmcDeviceAdd(struct MmcDevice *mmc)
HDF_LOGE("MmcDeviceAdd: invalid erase size:%u", mmc->eraseSize);
return HDF_ERR_INVALID_PARAM;
}
- mmc->device.magic = mmc->cntlr->device.magic + MMC_CNTLR_NR_MAX;
+ mmc->device.number = mmc->cntlr->device.number + MMC_CNTLR_NR_MAX;
if (MmcCntlrGet(mmc->cntlr) == NULL) {
return HDF_PLT_ERR_DEV_GET;
@@ -1005,7 +1000,7 @@ int32_t MmcDeviceAdd(struct MmcDevice *mmc)
}
if (mmc->type == MMC_DEV_EMMC || mmc->type == MMC_DEV_SD || mmc->type == MMC_DEV_COMBO) {
- ret = MmcBlockAdd(mmc);
+ ret = MmcBlockInit(mmc);
if (ret != HDF_SUCCESS) {
MmcCntlrPut(mmc->cntlr);
PlatformDeviceDel(&mmc->device);
@@ -1021,7 +1016,7 @@ void MmcDeviceRemove(struct MmcDevice *mmc)
return;
}
if (mmc->type == MMC_DEV_EMMC || mmc->type == MMC_DEV_SD || mmc->type == MMC_DEV_COMBO) {
- MmcBlockDel(mmc);
+ MmcBlockUninit(mmc);
}
PlatformDeviceDel(&mmc->device);
MmcCntlrPut(mmc->cntlr);
@@ -1101,6 +1096,7 @@ ssize_t MmcDeviceRead(struct MmcDevice *mmc, uint8_t *buf, size_t startSec, size
}
MmcDeviceFillRwInfo(&info, buf, false, curStartSec, readSec);
if (mmc->cntlr->detecting == true) {
+ /* In SD device detecting, VFS will read/write SD. */
ret = MmcSendReadWriteBlocks(mmc->cntlr, &info);
} else {
cmd.data = &data;
@@ -1146,6 +1142,7 @@ ssize_t MmcDeviceWrite(struct MmcDevice *mmc, uint8_t *buf, size_t startSec, siz
}
MmcDeviceFillRwInfo(&info, buf, true, curStartSec, writeSec);
if (mmc->cntlr->detecting == true) {
+ /* In SD device detecting, VFS will read/write SD. */
ret = MmcSendReadWriteBlocks(mmc->cntlr, &info);
} else {
cmd.data = &data;
diff --git a/support/platform/src/mmc/mmc_dispatch.c b/model/storage/src/mmc/mmc_dispatch.c
similarity index 100%
rename from support/platform/src/mmc/mmc_dispatch.c
rename to model/storage/src/mmc/mmc_dispatch.c
diff --git a/support/platform/src/mmc/mmc_emmc.c b/model/storage/src/mmc/mmc_emmc.c
similarity index 100%
rename from support/platform/src/mmc/mmc_emmc.c
rename to model/storage/src/mmc/mmc_emmc.c
diff --git a/support/platform/src/mmc/mmc_if.c b/model/storage/src/mmc/mmc_if.c
similarity index 100%
rename from support/platform/src/mmc/mmc_if.c
rename to model/storage/src/mmc/mmc_if.c
diff --git a/support/platform/src/mmc/mmc_protocol.c b/model/storage/src/mmc/mmc_protocol.c
similarity index 100%
rename from support/platform/src/mmc/mmc_protocol.c
rename to model/storage/src/mmc/mmc_protocol.c
diff --git a/support/platform/src/mmc/mmc_sdio.c b/model/storage/src/mmc/mmc_sdio.c
similarity index 100%
rename from support/platform/src/mmc/mmc_sdio.c
rename to model/storage/src/mmc/mmc_sdio.c
diff --git a/support/platform/src/mmc/sdio_if.c b/model/storage/src/mmc/sdio_if.c
similarity index 100%
rename from support/platform/src/mmc/sdio_if.c
rename to model/storage/src/mmc/sdio_if.c
diff --git a/model/storage/src/mtd/mtd_block.c b/model/storage/src/mtd/mtd_block.c
index fb3c39f305c3b782bf7d6cb1689ee551516a6d51..069172b2c196116f63184b5f8f82c71d439afa09 100644
--- a/model/storage/src/mtd/mtd_block.c
+++ b/model/storage/src/mtd/mtd_block.c
@@ -6,6 +6,7 @@
* See the LICENSE file in the root of this repository for complete details.
*/
+#include "hdf_log.h"
#include "mtd_core.h"
__attribute__((weak)) int32_t MtdBlockOsInit(struct MtdDevice *mtdDevice)
@@ -21,10 +22,31 @@ __attribute__ ((weak)) void MtdBlockOsUninit(struct MtdDevice *mtdDevice)
int32_t MtdBlockInit(struct MtdDevice *mtdDevice)
{
- return MtdBlockOsInit(mtdDevice);
+ int32_t ret;
+
+ if (mtdDevice == NULL) {
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ if (MtdDeviceGet(mtdDevice) == NULL) {
+ HDF_LOGE("%s: get mtd device failed", __func__);
+ return HDF_PLT_ERR_DEV_GET;
+ }
+
+ ret = MtdBlockOsInit(mtdDevice);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: os init failed, ret = %d", __func__, ret);
+ MtdDevicePut(mtdDevice);
+ return ret;
+ }
+
+ return HDF_SUCCESS;
}
void MtdBlockUninit(struct MtdDevice *mtdDevice)
{
- MtdBlockOsUninit(mtdDevice);
+ if (mtdDevice != NULL) {
+ MtdBlockOsUninit(mtdDevice);
+ MtdDevicePut(mtdDevice);
+ }
}
diff --git a/model/storage/src/mtd/mtd_core.c b/model/storage/src/mtd/mtd_core.c
index 051e55efb0aa35dde9d64b87374fa3aba8cc98a4..dbb047a0d2a549471379b3c730f6991000cdfbd4 100644
--- a/model/storage/src/mtd/mtd_core.c
+++ b/model/storage/src/mtd/mtd_core.c
@@ -16,7 +16,7 @@
static int32_t MtdDeviceCheckParms(struct MtdDevice *mtdDevice)
{
- if (mtdDevice->index < 0) {
+ if (mtdDevice->index < 0 || mtdDevice->index >= MTD_DEVICE_NUM_MAX) {
HDF_LOGE("%s: invalid index: %d", __func__, mtdDevice->index);
return HDF_ERR_INVALID_OBJECT;
}
@@ -96,6 +96,16 @@ static void MtdDeviceUnlockDefault(struct MtdDevice *mtdDevice)
return;
}
+struct PlatformManager *MtdManagerGet(void)
+{
+ static struct PlatformManager *g_mtdManager = NULL;
+
+ if (g_mtdManager == NULL) {
+ g_mtdManager = PlatformManagerCreate("STORAGE_MTD");
+ }
+ return g_mtdManager;
+}
+
int32_t MtdDeviceAdd(struct MtdDevice *mtdDevice)
{
int32_t ret;
@@ -124,15 +134,25 @@ int32_t MtdDeviceAdd(struct MtdDevice *mtdDevice)
mtdDevice->ops->unlock = MtdDeviceUnlockDefault;
}
+ mtdDevice->device.manager = MtdManagerGet();
+ mtdDevice->device.number = mtdDevice->index;
+ ret = PlatformDeviceAdd(&mtdDevice->device);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: mtd device add fail", __func__);
+ return ret;
+ }
+
MtdDeviceDump(mtdDevice);
ret = MtdCharInit(mtdDevice);
if (ret != HDF_SUCCESS) {
+ PlatformDeviceDel(&mtdDevice->device);
return ret;
}
ret = MtdBlockInit(mtdDevice);
if (ret != HDF_SUCCESS) {
+ PlatformDeviceDel(&mtdDevice->device);
return ret;
}
@@ -144,6 +164,7 @@ void MtdDeviceDel(struct MtdDevice *mtdDevice)
if (mtdDevice != NULL) {
MtdCharUninit(mtdDevice);
MtdBlockUninit(mtdDevice);
+ PlatformDeviceDel(&mtdDevice->device);
(void)OsalMutexDestroy(&mtdDevice->lock);
}
}
@@ -186,9 +207,9 @@ static void MtdDumpBuf(uint8_t *buf, size_t len)
#define MTD_DUMP_LINE_LEN 32
#define MTD_DUMP_BUF_LEN (MTD_DUMP_LINE_LEN * MTD_DUMP_SIGLE_WIDTH + 1)
char lineBuf[MTD_DUMP_BUF_LEN];
-
- for (idx = 0; idx < len; ) {
- line = (MTD_DUMP_LINE_LEN <= (len - idx)) ? MTD_DUMP_LINE_LEN : len - idx;
+ idx = 0;
+ while (idx < len) {
+ line = (MTD_DUMP_LINE_LEN <= (len - idx)) ? MTD_DUMP_LINE_LEN : (len - idx);
for (i = 0, lidx = 0; i < line; i++, lidx += MTD_DUMP_SIGLE_WIDTH, buf++) {
ret = snprintf_s(lineBuf + lidx, MTD_DUMP_SIGLE_WIDTH + 1, MTD_DUMP_SIGLE_WIDTH, "%02x", *buf);
if (ret < 0) {
@@ -359,15 +380,9 @@ static int32_t MtdDeviceWriteReadByPageUnlock(struct MtdDevice *mtdDevice, struc
off_t eraseOffset;
struct MtdPage mtdPage;
-#ifdef MTD_DEBUG
- HDF_LOGD("%s: addr=0x%jd, len=%zu, buf=%p, type:%d, withoob:%d, skipbad:%d", __func__,
- msg->addr, msg->len, msg->buf, msg->type, msg->withOob, msg->skipBad);
-#endif
-
dataLenLeft = msg->withOob ?
(msg->len / (mtdDevice->writeSize + mtdDevice->oobSize)) * mtdDevice->writeSize : msg->len;
-
- for (addr = msg->addr, buf = msg->buf; (dataLenLeft > 0) && addr < mtdDevice->capacity; ) {
+ for (addr = msg->addr, buf = msg->buf; (dataLenLeft > 0) && addr < mtdDevice->capacity;) {
if (MtdDeviceIsBadBlockUnlocked(mtdDevice, addr)) {
if (!msg->skipBad) {
HDF_LOGE("%s: failed on bad block @0x%jx", __func__, addr);
@@ -378,7 +393,7 @@ static int32_t MtdDeviceWriteReadByPageUnlock(struct MtdDevice *mtdDevice, struc
continue;
}
eraseOffset = addr & (mtdDevice->eraseSize - 1);
- blockSize = dataLenLeft < (mtdDevice->eraseSize - eraseOffset) ?
+ blockSize = (dataLenLeft < (mtdDevice->eraseSize - eraseOffset)) ?
dataLenLeft : (mtdDevice->eraseSize - eraseOffset);
// no more than one block at once
mtdPage.type = msg->type;
@@ -389,7 +404,7 @@ static int32_t MtdDeviceWriteReadByPageUnlock(struct MtdDevice *mtdDevice, struc
if (mtdPage.dataLen > blockSize) {
mtdPage.dataLen = blockSize;
}
- mtdPage.oobBuf = msg->withOob ? buf + mtdPage.dataLen : NULL;
+ mtdPage.oobBuf = msg->withOob ? (buf + mtdPage.dataLen) : NULL;
mtdPage.oobLen = msg->withOob ? mtdDevice->oobSize : 0;
ret = MtdDevicePageTransferUnlocked(mtdDevice, &mtdPage);
if (ret != HDF_SUCCESS) {
diff --git a/model/storage/src/mtd/mtd_spi_common.c b/model/storage/src/mtd/mtd_spi_common.c
index 7561507e388790518153ee56346a60de888a68b5..cf2176e564e76e173264c2b716d4d57194dbfa6c 100644
--- a/model/storage/src/mtd/mtd_spi_common.c
+++ b/model/storage/src/mtd/mtd_spi_common.c
@@ -20,8 +20,7 @@ static void SpiFlashDumpDefualt(struct MtdDevice *mtdDevice)
MTD_DEVICE_DUMP(mtdDevice);
spi = CONTAINER_OF(mtdDevice, struct SpiFlash, mtd);
- HDF_LOGD("%s: cs = %u, qe = %u, addrCycle = %u", __func__,
- spi->cs, spi->qeEnable, spi->addrCycle);
+ HDF_LOGD("%s: cs = %u, addrCycle = %u", __func__, spi->cs, spi->addrCycle);
cfg = &spi->readCfg;
HDF_LOGD("%s: readCfg -> ifType:%u, cmd:0x%x, dummy:%u, size:%u, clock:%u",
diff --git a/model/usb/include/usb_ddk_pnp_loader.h b/model/usb/include/usb_ddk_pnp_loader.h
old mode 100755
new mode 100644
index 7915fe89e86e77d37b350325c08970061c3cc1ad..e7accbf3229ff97d10ba4270ecf2097826c06842
--- a/model/usb/include/usb_ddk_pnp_loader.h
+++ b/model/usb/include/usb_ddk_pnp_loader.h
@@ -78,7 +78,7 @@ struct UsbPnpRemoveInfo {
uint8_t interfaceNum;
};
-int UsbDdkPnpLoaderEventReceived(void *priv, uint32_t id, struct HdfSBuf *data);
+int UsbDdkPnpLoaderEventReceived(void *usbPnpManagerPtr, uint32_t id, struct HdfSBuf *data);
int UsbDdkPnpLoaderEventHandle(void);
#endif /* USB_DDK_PNP_LOADER_H */
diff --git a/model/usb/include/usb_pnp_manager.h b/model/usb/include/usb_pnp_manager.h
new file mode 100644
index 0000000000000000000000000000000000000000..2a7cb5b43048b734da9157ad63986bc9c64364e7
--- /dev/null
+++ b/model/usb/include/usb_pnp_manager.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef USB_PNP_MANAGE_H
+#define USB_PNP_MANAGE_H
+
+#include "hdf_base.h"
+#include "hdf_sbuf.h"
+
+struct UsbPnpManagerDeviceInfo {
+ struct HdfDeviceObject *usbPnpManager;
+ const char *moduleName;
+ const char *serviceName;
+ const char *deviceMatchAttr;
+ const void *privateData;
+ bool isReg;
+};
+
+bool UsbPnpManagerWriteModuleName(struct HdfSBuf *sbuf, const char *moduleName);
+int32_t UsbPnpManagerRegisterOrUnregisterDevice(struct UsbPnpManagerDeviceInfo *managerInfo);
+
+#endif /* USB_PNP_MANAGE_H */
diff --git a/model/usb/src/usb_ddk_pnp_loader.c b/model/usb/src/usb_ddk_pnp_loader.c
old mode 100755
new mode 100644
index affbd048951f2c0d09ede05a25c10cc6b8791d27..49aace587dfa32fa178bae655633cd1c372e5eb8
--- a/model/usb/src/usb_ddk_pnp_loader.c
+++ b/model/usb/src/usb_ddk_pnp_loader.c
@@ -7,13 +7,16 @@
*/
#include "usb_ddk_pnp_loader.h"
+#include
#include "devhost_service_clnt.h"
#include "device_resource_if.h"
#include "hcs_tree_if.h"
#include "hdf_attribute_manager.h"
#include "hdf_base.h"
+#include "hdf_device_object.h"
#include "hdf_log.h"
#include "hdf_sbuf.h"
+#include "osal_file.h"
#include "osal_mem.h"
#include "osal_time.h"
#include "securec.h"
@@ -39,27 +42,27 @@ static struct HdfSBuf *UsbDdkPnpLoaderBufCreate(const char *moduleName,
if (!UsbPnpManagerWriteModuleName(pnpData, moduleName)) {
HDF_LOGE("%s: write moduleName failed!", __func__);
- goto out;
+ goto OUT;
}
if (!HdfSbufWriteString(pnpData, serviceName)) {
HDF_LOGE("%s: write service name failed!", __func__);
- goto out;
+ goto OUT;
}
if (!HdfSbufWriteString(pnpData, deviceMatchAttr)) {
HDF_LOGE("%s: write deviceMatchAttr failed!", __func__);
- goto out;
+ goto OUT;
}
if (!HdfSbufWriteBuffer(pnpData, (const void *)(&serviceInfo), serviceInfo.length)) {
HDF_LOGE("%s: write privateData failed!", __func__);
- goto out;
+ goto OUT;
}
return pnpData;
-out:
+OUT:
HdfSBufRecycle(pnpData);
return NULL;
@@ -106,10 +109,89 @@ static bool UsbDdkPnpLoaderMatchDevice(const struct UsbPnpNotifyMatchInfoTable *
return true;
}
+// Need optimize this device object array later, should bind device object to usb deivce
+#define REGISTER_DEV_MAX 16
+static struct HdfDeviceObject *g_resistedDevice[REGISTER_DEV_MAX] = {0};
+static int SaveRegistedDevice(struct HdfDeviceObject *dev)
+{
+ for (size_t i = 0; i < REGISTER_DEV_MAX; i++) {
+ if (g_resistedDevice[i] == NULL) {
+ g_resistedDevice[i] = dev;
+ return HDF_SUCCESS;
+ }
+ }
+
+ return HDF_FAILURE;
+}
+
+static struct HdfDeviceObject *GetRegistedDevice(const char *serviceName)
+{
+ struct HdfDeviceObject *dev = NULL;
+ for (size_t i = 0; i < REGISTER_DEV_MAX; i++) {
+ if (g_resistedDevice[i] == NULL) {
+ continue;
+ }
+ if (!strcmp(HdfDeviceGetServiceName(g_resistedDevice[i]), serviceName)) {
+ dev = g_resistedDevice[i];
+ g_resistedDevice[i] = NULL;
+ break;
+ }
+ }
+
+ return dev;
+}
+
+int32_t UsbPnpManagerRegisterDevice(struct UsbPnpManagerDeviceInfo *managerInfo)
+{
+ int ret = HDF_FAILURE;
+ struct HdfDeviceObject *devObj = HdfDeviceObjectAlloc(managerInfo->usbPnpManager, managerInfo->moduleName);
+ if (devObj == NULL) {
+ HDF_LOGE("%s: failed to alloc device object", __func__);
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+
+ devObj->priv = (void *)managerInfo->privateData;
+ ret = HdfDeviceObjectRegister(devObj);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: failed to regitst device %s", __func__, managerInfo->serviceName);
+ HdfDeviceObjectRelease(devObj);
+ return ret;
+ }
+ ret = HdfDeviceObjectPublishService(devObj, managerInfo->serviceName, SERVICE_POLICY_CAPACITY,
+ OSAL_S_IREAD | OSAL_S_IWRITE | OSAL_S_IRGRP | OSAL_S_IWGRP | OSAL_S_IROTH);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: failed to regitst device %s", __func__, managerInfo->serviceName);
+ HdfDeviceObjectRelease(devObj);
+ return ret;
+ }
+ // need optimize this code to remove SaveRegistedDevice function later
+ return SaveRegistedDevice(devObj);
+}
+
+int32_t UsbPnpManagerUnregisterDevice(struct UsbPnpManagerDeviceInfo *managerInfo)
+{
+ // need optimize this code to remove GetRegistedDevice function later
+ struct HdfDeviceObject *devObj = GetRegistedDevice(managerInfo->serviceName);
+ if (devObj == NULL) {
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+ HdfDeviceObjectRelease(devObj);
+ return HDF_SUCCESS;
+}
+
+int32_t UsbPnpManagerRegisterOrUnregisterDevice(struct UsbPnpManagerDeviceInfo *managerInfo)
+{
+ if (managerInfo == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ return managerInfo->isReg ? UsbPnpManagerRegisterDevice(managerInfo) : UsbPnpManagerUnregisterDevice(managerInfo);
+}
+
static void UsbDdkPnpLoaderMatchHandle(const struct UsbPnpNotifyMatchInfoTable *dev,
int8_t index, struct UsbPnpMatchIdTable *id, bool flag)
{
- if ((id->pnpMatchFlag == false) && (flag == true)) {
+ if ((!id->pnpMatchFlag) && flag) {
if (!(id->matchFlag & USB_PNP_NOTIFY_MATCH_INT_CLASS)) {
id->interfaceClass[id->interfaceClassLength++] = dev->interfaceInfo[index].interfaceClass;
}
@@ -125,63 +207,85 @@ static void UsbDdkPnpLoaderMatchHandle(const struct UsbPnpNotifyMatchInfoTable *
}
}
-static bool UsbDdkPnpLoaderMatchFlag(const struct UsbPnpNotifyMatchInfoTable *dev,
- int8_t index, struct UsbPnpMatchIdTable *id, bool flag)
+static bool UsbDdkPnpLoaderMatchFlagFirst(struct UsbPnpMatchIdTable *id)
{
int32_t i;
bool ret = true;
+ uint32_t offset;
if (id->matchFlag & USB_PNP_NOTIFY_MATCH_INT_CLASS) {
for (i = 0; i < id->interfaceClassLength; i++) {
- if (!((id->interfaceClassMask >> i) & 0x01)) {
+ offset = i;
+ if (!((id->interfaceClassMask >> offset) & 0x01)) {
break;
}
}
if (i < id->interfaceClassLength) {
ret = false;
- goto out;
+ goto OUT;
}
}
if (id->matchFlag & USB_PNP_NOTIFY_MATCH_INT_SUBCLASS) {
for (i = 0; i < id->interfaceSubClassLength; i++) {
- if (!((id->interfaceSubClassMask >> i) & 0x01)) {
+ offset = i;
+ if (!((id->interfaceSubClassMask >> offset) & 0x01)) {
break;
}
}
if (i < id->interfaceSubClassLength) {
ret = false;
- goto out;
+ goto OUT;
}
}
+ ret = true;
+
+OUT:
+ return ret;
+}
+
+static bool UsbDdkPnpLoaderMatchFlag(const struct UsbPnpNotifyMatchInfoTable *dev,
+ int8_t index, struct UsbPnpMatchIdTable *id, bool flag)
+{
+ int32_t i;
+ bool ret = true;
+ uint32_t offset;
+
+ if (!UsbDdkPnpLoaderMatchFlagFirst(id)) {
+ ret = false;
+ goto OUT;
+ }
+
if (id->matchFlag & USB_PNP_NOTIFY_MATCH_INT_PROTOCOL) {
for (i = 0; i < id->interfaceProtocolLength; i++) {
- if (!((id->interfaceProtocolMask >> i) & 0x01)) {
+ offset = i;
+ if (!((id->interfaceProtocolMask >> offset) & 0x01)) {
break;
}
}
if (i < id->interfaceProtocolLength) {
ret = false;
- goto out;
+ goto OUT;
}
}
if (id->matchFlag & USB_PNP_NOTIFY_MATCH_INT_NUMBER) {
for (i = 0; i < id->interfaceLength; i++) {
- if (!((id->interfaceMask >> i) & 0x01)) {
+ offset = i;
+ if (!((id->interfaceMask >> offset) & 0x01)) {
break;
}
}
if (i < id->interfaceLength) {
ret = false;
- goto out;
+ goto OUT;
}
}
ret = true;
-out:
+OUT:
UsbDdkPnpLoaderMatchHandle(dev, index, id, flag);
return ret;
@@ -190,13 +294,13 @@ out:
static bool UsbDdkPnpLoaderMatchInterface(const struct UsbPnpNotifyMatchInfoTable *dev,
int8_t index, struct UsbPnpMatchIdTable *id)
{
- uint32_t i;
+ int32_t i;
bool maskFlag = true;
if (id->matchFlag & USB_PNP_NOTIFY_MATCH_INT_CLASS) {
for (i = 0; i < id->interfaceClassLength; i++) {
if (id->interfaceClass[i] == dev->interfaceInfo[index].interfaceClass) {
- id->interfaceClassMask |= (1 << i);
+ id->interfaceClassMask |= (1 << (uint32_t)i);
break;
}
}
@@ -209,7 +313,7 @@ static bool UsbDdkPnpLoaderMatchInterface(const struct UsbPnpNotifyMatchInfoTabl
if (id->matchFlag & USB_PNP_NOTIFY_MATCH_INT_SUBCLASS) {
for (i = 0; i < id->interfaceSubClassLength; i++) {
if (id->interfaceSubClass[i] == dev->interfaceInfo[index].interfaceSubClass) {
- id->interfaceSubClassMask |= (1 << i);
+ id->interfaceSubClassMask |= (1 << (uint32_t)i);
break;
}
}
@@ -222,7 +326,7 @@ static bool UsbDdkPnpLoaderMatchInterface(const struct UsbPnpNotifyMatchInfoTabl
if (id->matchFlag & USB_PNP_NOTIFY_MATCH_INT_PROTOCOL) {
for (i = 0; i < id->interfaceProtocolLength; i++) {
if (id->interfaceProtocol[i] == dev->interfaceInfo[index].interfaceProtocol) {
- id->interfaceProtocolMask |= (1 << i);
+ id->interfaceProtocolMask |= (1 << (uint32_t)i);
break;
}
}
@@ -235,7 +339,7 @@ static bool UsbDdkPnpLoaderMatchInterface(const struct UsbPnpNotifyMatchInfoTabl
if (id->matchFlag & USB_PNP_NOTIFY_MATCH_INT_NUMBER) {
for (i = 0; i < id->interfaceLength; i++) {
if (id->interfaceNumber[i] == dev->interfaceInfo[index].interfaceNumber) {
- id->interfaceMask |= (1 << i);
+ id->interfaceMask |= (1 << (uint32_t)i);
break;
}
}
@@ -261,11 +365,11 @@ static bool UsbDdkPnpLoaderMatchOneIdIntf(const struct UsbPnpNotifyMatchInfoTabl
}
maskFlag = UsbDdkPnpLoaderMatchInterface(dev, index, id);
- if (UsbDdkPnpLoaderMatchFlag(dev, index, id, maskFlag) != true) {
+ if (!UsbDdkPnpLoaderMatchFlag(dev, index, id, maskFlag)) {
return false;
}
- if (id->pnpMatchFlag == false) {
+ if (!id->pnpMatchFlag) {
id->pnpMatchFlag = true;
} else {
return false;
@@ -453,26 +557,26 @@ static struct UsbPnpMatchIdTable **UsbDdkPnpLoaderParseTableList(
idTable[count] = (struct UsbPnpMatchIdTable *)OsalMemCalloc(sizeof(struct UsbPnpMatchIdTable));
if (idTable[count] == NULL) {
HDF_LOGE("%s: OsalMemCalloc failure!", __func__);
- goto out;
+ goto OUT;
}
ret = devResIface->GetStringArrayElem(node, "idTableList", count, &idTableName, NULL);
if (ret != HDF_SUCCESS) {
- goto out;
+ goto OUT;
}
tableNode = devResIface->GetChildNode(node, idTableName);
if (tableNode == NULL) {
HDF_LOGE("%s: tableNode is NULL!", __func__);
- goto out;
+ goto OUT;
}
if (UsbDdkPnpLoaderParseIdTable(tableNode, devResIface, idTable[count]) != HDF_SUCCESS) {
HDF_LOGE("%s: UsbDdkPnpLoaderParseIdTable failure!", __func__);
- goto out;
+ goto OUT;
}
}
return idTable;
-out:
+OUT:
while ((--count) >= 0) {
OsalMemFree(idTable[count]);
}
@@ -563,8 +667,8 @@ static struct UsbPnpMatchIdTable **UsbDdkPnpLoaderPnpMatch(void)
return UsbDdkPnpLoaderParseDeviceId(usbPnpNode);
}
-static int32_t UsbDdkPnpLoaderDispatchPnpDevice(
- const struct IDevmgrService *devmgrSvc, struct HdfSBuf *data, bool isReg)
+static int32_t UsbDdkPnpLoaderDispatchPnpDevice(struct HdfDeviceObject *usbPnpManagerDevice,
+ struct HdfSBuf *data, bool isReg)
{
uint32_t infoSize = 0;
struct UsbPnpNotifyServiceInfo *privateData = NULL;
@@ -589,14 +693,14 @@ static int32_t UsbDdkPnpLoaderDispatchPnpDevice(
privateData = NULL;
}
- managerInfo.devmgrSvc = (struct IDevmgrService *)devmgrSvc;
+ managerInfo.usbPnpManager = usbPnpManagerDevice;
managerInfo.moduleName = moduleName;
managerInfo.serviceName = serviceName;
managerInfo.deviceMatchAttr = deviceMatchAttr;
managerInfo.privateData = privateData;
managerInfo.isReg = isReg;
- return UsbPnpManagerRegisterOrUnregisterDevice(managerInfo);
+ return UsbPnpManagerRegisterOrUnregisterDevice(&managerInfo);
}
static int UsbDdkPnpLoaderDeviceListAdd(const struct UsbPnpNotifyMatchInfoTable *info,
@@ -663,7 +767,7 @@ static struct UsbPnpDeviceListTable *UsbDdkPnpLoaderAddInterface(
return NULL;
}
-static int UsbDdkPnpLoaderrAddPnpDevice(const struct IDevmgrService *devmgrSvc,
+static int UsbDdkPnpLoaderrAddPnpDevice(struct HdfDeviceObject *usbPnpManagerDevice,
const struct UsbPnpNotifyMatchInfoTable *infoTable, const struct UsbPnpMatchIdTable *idTable, uint32_t cmdId)
{
int ret;
@@ -678,8 +782,8 @@ static int UsbDdkPnpLoaderrAddPnpDevice(const struct IDevmgrService *devmgrSvc,
return HDF_SUCCESS;
}
- serviceInfo.length = sizeof(struct UsbPnpNotifyServiceInfo) - (USB_PNP_INFO_MAX_INTERFACES
- - idTable->interfaceLength);
+ serviceInfo.length = sizeof(struct UsbPnpNotifyServiceInfo) -
+ (USB_PNP_INFO_MAX_INTERFACES - idTable->interfaceLength);
serviceInfo.devNum = infoTable->devNum;
serviceInfo.busNum = infoTable->busNum;
serviceInfo.interfaceLength = idTable->interfaceLength;
@@ -690,10 +794,10 @@ static int UsbDdkPnpLoaderrAddPnpDevice(const struct IDevmgrService *devmgrSvc,
if (pnpData == NULL) {
ret = HDF_FAILURE;
HDF_LOGE("%s: UsbDdkPnpLoaderBufCreate faile", __func__);
- goto error;
+ goto ERROR;
}
- ret = UsbDdkPnpLoaderDispatchPnpDevice(devmgrSvc, pnpData, true);
+ ret = UsbDdkPnpLoaderDispatchPnpDevice(usbPnpManagerDevice, pnpData, true);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:%d handle failed, %s-%s cmdId is %d, ret=%d",
__func__, __LINE__, idTable->moduleName, idTable->serviceName, cmdId, ret);
@@ -702,26 +806,26 @@ static int UsbDdkPnpLoaderrAddPnpDevice(const struct IDevmgrService *devmgrSvc,
if (deviceListTable == NULL) {
ret = HDF_ERR_INVALID_OBJECT;
HDF_LOGE("%s:%d UsbDdkPnpLoaderAddInterface faile", __func__, __LINE__);
- goto error;
+ goto ERROR;
}
deviceListTable->status = USB_PNP_ADD_STATUS;
} else {
ret = UsbDdkPnpLoaderDeviceListAdd(infoTable, idTable);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:%d UsbDdkPnpLoaderDeviceListAdd faile", __func__, __LINE__);
- goto error;
+ goto ERROR;
}
}
}
-error:
+ERROR:
HdfSBufRecycle(pnpData);
return ret;
}
-static void UsbDdkPnpLoaderAddDevice(uint32_t cmdId, uint8_t index, const struct IDevmgrService *devmgrSvc,
+static void UsbDdkPnpLoaderAddDevice(uint32_t cmdId, uint8_t index, struct HdfDeviceObject *usbPnpManagerDevice,
const struct UsbPnpNotifyMatchInfoTable *infoTable, struct UsbPnpMatchIdTable **matchIdTable)
{
- int ret = HDF_FAILURE;
+ int ret;
struct UsbPnpMatchIdTable *idTable = NULL;
int32_t tableCount;
@@ -738,16 +842,14 @@ static void UsbDdkPnpLoaderAddDevice(uint32_t cmdId, uint8_t index, const struct
idTable=%p, moduleName=%s, serviceName=%s",
__func__, __LINE__, index, tableCount, idTable, idTable->moduleName, idTable->serviceName);
- ret = UsbDdkPnpLoaderrAddPnpDevice(devmgrSvc, infoTable, idTable, cmdId);
+ ret = UsbDdkPnpLoaderrAddPnpDevice(usbPnpManagerDevice, infoTable, idTable, cmdId);
if (ret != HDF_SUCCESS) {
continue;
}
}
-
- HDF_LOGD("%s:%d AddDevice end, index=%d, ret=%d", __func__, __LINE__, index, ret);
}
-static int UsbDdkPnpLoaderRemoveHandle(const struct IDevmgrService *devmgrSvc,
+static int UsbDdkPnpLoaderRemoveHandle(struct HdfDeviceObject *usbPnpManager,
struct UsbPnpDeviceListTable *deviceListTablePos)
{
struct UsbPnpNotifyServiceInfo serviceInfo;
@@ -769,21 +871,21 @@ static int UsbDdkPnpLoaderRemoveHandle(const struct IDevmgrService *devmgrSvc,
}
if (deviceListTablePos->status != USB_PNP_REMOVE_STATUS) {
- ret = UsbDdkPnpLoaderDispatchPnpDevice(devmgrSvc, pnpData, false);
+ ret = UsbDdkPnpLoaderDispatchPnpDevice(usbPnpManager, pnpData, false);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:%d UsbDdkPnpLoaderDispatchPnpDevice faile ret=%d",
__func__, __LINE__, ret);
- goto error;
+ goto ERROR;
}
deviceListTablePos->status = USB_PNP_REMOVE_STATUS;
}
-error:
+ERROR:
HdfSBufRecycle(pnpData);
return ret;
}
-static int UsbDdkPnpLoaderRemoveDevice(const struct IDevmgrService *devmgrSvc,
+static int UsbDdkPnpLoaderRemoveDevice(struct HdfDeviceObject *usbPnpManager,
struct UsbPnpRemoveInfo removeInfo, uint32_t cmdId)
{
int ret = HDF_SUCCESS;
@@ -813,7 +915,7 @@ static int UsbDdkPnpLoaderRemoveDevice(const struct IDevmgrService *devmgrSvc,
}
findFlag = true;
- ret = UsbDdkPnpLoaderRemoveHandle(devmgrSvc, deviceListTablePos);
+ ret = UsbDdkPnpLoaderRemoveHandle(usbPnpManager, deviceListTablePos);
if (ret != HDF_SUCCESS) {
break;
}
@@ -835,8 +937,8 @@ static int UsbDdkPnpLoaderRemoveDevice(const struct IDevmgrService *devmgrSvc,
return ret;
}
-static int UsbDdkPnpLoaderDevice(const struct UsbPnpNotifyMatchInfoTable *infoTable,
- const struct IDevmgrService *super, uint32_t id)
+static int UsbDdkPnpLoaderDevice(struct HdfDeviceObject *usbPnpManagerDevice,
+ const struct UsbPnpNotifyMatchInfoTable *infoTable, uint32_t id)
{
int8_t i;
int32_t tableCount;
@@ -848,7 +950,7 @@ static int UsbDdkPnpLoaderDevice(const struct UsbPnpNotifyMatchInfoTable *infoTa
}
for (i = 0; i < infoTable->numInfos; i++) {
- UsbDdkPnpLoaderAddDevice(id, i, super, infoTable, g_usbPnpMatchIdTable);
+ UsbDdkPnpLoaderAddDevice(id, i, usbPnpManagerDevice, infoTable, g_usbPnpMatchIdTable);
}
for (tableCount = 0, idTable = g_usbPnpMatchIdTable[0]; idTable != NULL;
@@ -892,44 +994,44 @@ static int UsbDdkPnpLoaderEventSend(const struct HdfIoService *serv, const char
if (reply == NULL) {
ret = HDF_DEV_ERR_NO_MEMORY;
HDF_LOGE("%s: fail to obtain sbuf reply", __func__);
- goto out;
+ goto OUT;
}
if (!HdfSbufWriteString(data, eventData)) {
ret = HDF_FAILURE;
HDF_LOGE("%s: fail to write sbuf", __func__);
- goto out;
+ goto OUT;
}
ret = serv->dispatcher->Dispatch((struct HdfObject *)&serv->object, USB_PNP_NOTIFY_REPORT_INTERFACE, data, reply);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: fail to send serivice call, ret=%d", __func__, ret);
- goto out;
+ goto OUT;
}
if (!HdfSbufReadInt32(reply, &replyData)) {
ret = HDF_ERR_INVALID_OBJECT;
HDF_LOGE("%s: fail to get service call reply", __func__);
- goto out;
+ goto OUT;
}
HDF_LOGI("%s:%d get reply is 0x%x", __func__, __LINE__, replyData);
-out:
+OUT:
HdfSBufRecycle(data);
HdfSBufRecycle(reply);
return ret;
}
-int UsbDdkPnpLoaderEventReceived(void *priv, uint32_t id, struct HdfSBuf *data)
+int UsbDdkPnpLoaderEventReceived(void *usbPnpManagerPtr, uint32_t id, struct HdfSBuf *data)
{
int ret;
bool flag = false;
uint32_t infoSize;
struct UsbPnpNotifyMatchInfoTable *infoTable = NULL;
- struct IDevmgrService *super = (struct IDevmgrService *)priv;
struct UsbPnpRemoveInfo removeInfo;
+ struct HdfDeviceObject *usbPnpManagerDevice = (struct HdfDeviceObject *)usbPnpManagerPtr;
flag = HdfSbufReadBuffer(data, (const void **)(&infoTable), &infoSize);
if ((flag == false) || (infoTable == NULL)) {
@@ -951,7 +1053,7 @@ int UsbDdkPnpLoaderEventReceived(void *priv, uint32_t id, struct HdfSBuf *data)
#if USB_PNP_NOTIFY_TEST_MODE == true
case USB_PNP_NOTIFY_ADD_TEST:
#endif
- ret = UsbDdkPnpLoaderDevice(infoTable, super, id);
+ ret = UsbDdkPnpLoaderDevice(usbPnpManagerDevice, infoTable, id);
break;
case USB_PNP_NOTIFY_REMOVE_INTERFACE:
case USB_PNP_NOTIFY_REMOVE_DEVICE:
@@ -963,7 +1065,7 @@ int UsbDdkPnpLoaderEventReceived(void *priv, uint32_t id, struct HdfSBuf *data)
removeInfo.devNum = infoTable->devNum;
removeInfo.busNum = infoTable->busNum;
removeInfo.interfaceNum = infoTable->interfaceInfo[0].interfaceNumber;
- ret = UsbDdkPnpLoaderRemoveDevice(super, removeInfo, id);
+ ret = UsbDdkPnpLoaderRemoveDevice(usbPnpManagerDevice, removeInfo, id);
break;
default:
ret = HDF_ERR_INVALID_PARAM;
@@ -1004,11 +1106,12 @@ int UsbDdkPnpLoaderEventHandle(void)
status = UsbDdkPnpLoaderEventSend(usbPnpServ, "USB PNP Handle Info");
if (status != HDF_SUCCESS) {
HDF_LOGE("UsbDdkPnpLoaderEventSend faile status=%d", status);
- goto error;
+ goto ERROR;
}
return status;
-error:
- for (idTable = g_usbPnpMatchIdTable[0]; idTable != NULL; ) {
+ERROR:
+ idTable = g_usbPnpMatchIdTable[0];
+ while (idTable != NULL) {
tableCount++;
idTable = g_usbPnpMatchIdTable[tableCount];
}
diff --git a/sample/config/device_info/device_info.hcs b/sample/config/device_info/device_info.hcs
new file mode 100755
index 0000000000000000000000000000000000000000..f3cd30a2aa8613ef4dbf358be80c3fc9db452d9c
--- /dev/null
+++ b/sample/config/device_info/device_info.hcs
@@ -0,0 +1,18 @@
+root {
+ device_info {
+ platform :: host {
+ hostName = "platform_host";
+ priority = 50;
+ device_uart :: device {
+ device5 :: deviceNode {
+ policy = 2;
+ priority = 10;
+ permission = 0660;
+ moduleName = "UART_SAMPLE";
+ serviceName = "HDF_PLATFORM_UART_5";
+ deviceMatchAttr = "sample_uart_5";
+ }
+ }
+ }
+ }
+}
diff --git a/sample/config/uart/uart_config.hcs b/sample/config/uart/uart_config.hcs
new file mode 100755
index 0000000000000000000000000000000000000000..2ea8900bbb5b142c50bfb3c7a0351e9cfc34edfc
--- /dev/null
+++ b/sample/config/uart/uart_config.hcs
@@ -0,0 +1,15 @@
+root {
+ platform {
+ uart_sample {
+ num = 5;
+ base = 0x120a0000; // UART base register address
+ irqNum = 38;
+ baudrate = 115200;
+ uartClk = 24000000; // 24 M
+ wlen = 0x60; // 8 bit width
+ parity = 0;
+ stopBit = 0;
+ match_attr = "sample_uart_5";
+ }
+ }
+}
diff --git a/sample/platform/uart/BUILD.gn b/sample/platform/uart/BUILD.gn
new file mode 100755
index 0000000000000000000000000000000000000000..9404df09728c324edd198ee2bd04a0042774d991
--- /dev/null
+++ b/sample/platform/uart/BUILD.gn
@@ -0,0 +1,14 @@
+# Copyright (c) 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.
+
+import("//build/lite/config/component/lite_component.gni")
+
+lite_component("hello_uart_sample") {
+ features = [
+ "dev:hello_uart",
+ "dispatch:hello_uart_dispatch",
+ ]
+}
diff --git a/sample/platform/uart/Kconfig b/sample/platform/uart/Kconfig
new file mode 100755
index 0000000000000000000000000000000000000000..2a317abf38a3c218d39cf81d81df0bf7c2119864
--- /dev/null
+++ b/sample/platform/uart/Kconfig
@@ -0,0 +1,12 @@
+# Copyright (c) 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.
+
+config DRIVERS_HDF_PLATFORM_UART_SAMPLE
+ bool "Enable HDF platform uart sample driver"
+ default n
+ depends on DRIVERS_HDF_PLATFORM
+ help
+ Answer Y to enable HDF platform uart sample driver.
diff --git a/sample/platform/uart/dev/BUILD.gn b/sample/platform/uart/dev/BUILD.gn
new file mode 100755
index 0000000000000000000000000000000000000000..25f7815c0730d58f1f7f1f5556245de282ae95fe
--- /dev/null
+++ b/sample/platform/uart/dev/BUILD.gn
@@ -0,0 +1,41 @@
+# Copyright (c) 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.
+
+HDF_FRAMEWORKS = "//drivers/framework"
+
+executable("hello_uart") {
+ sources = [ "hello_uart_dev.c" ]
+
+ include_dirs = [
+ "$HDF_FRAMEWORKS/ability/sbuf/include",
+ "$HDF_FRAMEWORKS/core/shared/include",
+ "$HDF_FRAMEWORKS/core/host/include",
+ "$HDF_FRAMEWORKS/core/master/include",
+ "$HDF_FRAMEWORKS/include/core",
+ "$HDF_FRAMEWORKS/include/utils",
+ "$HDF_FRAMEWORKS/utils/include",
+ "$HDF_FRAMEWORKS/include/osal",
+ "//drivers/adapter/uhdf/posix/include",
+ "//third_party/bounds_checking_function/include",
+ "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits",
+ ]
+
+ deps = [
+ "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
+ "//drivers/adapter/uhdf/manager:hdf_core",
+ "//drivers/adapter/uhdf/posix:hdf_posix_osal",
+ ]
+
+ public_deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
+ defines = [ "__USER__" ]
+
+ cflags = [
+ "-Wall",
+ "-Wextra",
+ "-Wno-format",
+ "-Wno-format-extra-args",
+ ]
+}
diff --git a/sample/platform/uart/dev/hello_uart_dev.c b/sample/platform/uart/dev/hello_uart_dev.c
new file mode 100755
index 0000000000000000000000000000000000000000..ffacc5df0f3e2e1ca6deecbfbe08388d44644c5e
--- /dev/null
+++ b/sample/platform/uart/dev/hello_uart_dev.c
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 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
+#include
+#include
+#include "hdf_log.h"
+
+#define HDF_LOG_TAG hello_uart
+#define INFO_SIZE 16
+
+int main(void)
+{
+ int ret;
+ int fd;
+ const char info[INFO_SIZE] = {" HELLO UART! "};
+
+ fd = open("/dev/uartdev-5", O_RDWR);
+ if (fd < 0) {
+ HDF_LOGE("uartdev-5 open failed %d", fd);
+ return -1;
+ }
+ ret = write(fd, info, INFO_SIZE);
+ if (ret != 0) {
+ HDF_LOGE("write uartdev-5 ret is %d", ret);
+ }
+ ret = close(fd);
+ if (ret != 0) {
+ HDF_LOGE("uartdev-5 close failed %d", fd);
+ return -1;
+ }
+ return ret;
+}
\ No newline at end of file
diff --git a/sample/platform/uart/dispatch/BUILD.gn b/sample/platform/uart/dispatch/BUILD.gn
new file mode 100755
index 0000000000000000000000000000000000000000..6813ed10cfa389b8c9ef57acc95f5e88f2a4e88e
--- /dev/null
+++ b/sample/platform/uart/dispatch/BUILD.gn
@@ -0,0 +1,44 @@
+# Copyright (c) 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.
+
+HDF_FRAMEWORKS = "//drivers/framework"
+
+executable("hello_uart_dispatch") {
+ sources = [
+ "hello_uart_dispatch.c",
+ "uart_if.c",
+ ]
+
+ include_dirs = [
+ "$HDF_FRAMEWORKS/ability/sbuf/include",
+ "$HDF_FRAMEWORKS/core/shared/include",
+ "$HDF_FRAMEWORKS/core/host/include",
+ "$HDF_FRAMEWORKS/core/master/include",
+ "$HDF_FRAMEWORKS/include/core",
+ "$HDF_FRAMEWORKS/include/utils",
+ "$HDF_FRAMEWORKS/utils/include",
+ "$HDF_FRAMEWORKS/include/osal",
+ "//drivers/adapter/uhdf/posix/include",
+ "//third_party/bounds_checking_function/include",
+ "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits",
+ ]
+
+ deps = [
+ "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
+ "//drivers/adapter/uhdf/manager:hdf_core",
+ "//drivers/adapter/uhdf/posix:hdf_posix_osal",
+ ]
+
+ public_deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
+ defines = [ "__USER__" ]
+
+ cflags = [
+ "-Wall",
+ "-Wextra",
+ "-Wno-format",
+ "-Wno-format-extra-args",
+ ]
+}
diff --git a/sample/platform/uart/dispatch/hello_uart_dispatch.c b/sample/platform/uart/dispatch/hello_uart_dispatch.c
new file mode 100755
index 0000000000000000000000000000000000000000..ea123de111c8caaf2b20d0e80191baee63cccb57
--- /dev/null
+++ b/sample/platform/uart/dispatch/hello_uart_dispatch.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 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
+#include "hdf_log.h"
+#include "osal_mem.h"
+#include "uart_if.h"
+
+#define HDF_LOG_TAG hello_uart_dispatch
+#define UART_PORT 5
+
+int main()
+{
+ const char *info = " HELLO UART! ";
+
+ struct DevHandle *handle = UartOpen(UART_PORT);
+ if (handle == NULL) {
+ HDF_LOGE("Failed to open uart %d", UART_PORT);
+ return HDF_FAILURE;
+ }
+
+ int ret = UartWrite(handle, (uint8_t *)info, strlen(info));
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("Failed to send data to uart");
+ }
+
+ UartClose(handle);
+ return ret;
+}
\ No newline at end of file
diff --git a/sample/platform/uart/dispatch/uart_if.c b/sample/platform/uart/dispatch/uart_if.c
new file mode 100755
index 0000000000000000000000000000000000000000..9fdb158c67dbeb36bc3a98d59d2dd3f5ae845f48
--- /dev/null
+++ b/sample/platform/uart/dispatch/uart_if.c
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 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 "uart_if.h"
+#include "hdf_log.h"
+#include "osal_mem.h"
+#include "hdf_io_service_if.h"
+
+#define HDF_LOG_TAG uart_if
+
+struct DevHandle *UartOpen(uint32_t port)
+{
+ int32_t ret;
+ struct DevHandle *handle = NULL;
+ char *serviceName = NULL;
+
+ handle = (struct DevHandle *)OsalMemCalloc(sizeof(struct DevHandle));
+ if (handle == NULL) {
+ HDF_LOGE("Failed to OsalMemCalloc handle");
+ return NULL;
+ }
+
+ serviceName = (char *)OsalMemCalloc(sizeof(char) * (MAX_DEV_NAME_SIZE + 1));
+ if (serviceName == NULL) {
+ HDF_LOGE("Failed to OsalMemCalloc serviceName");
+ OsalMemFree(handle);
+ return NULL;
+ }
+ ret = snprintf_s(serviceName, MAX_DEV_NAME_SIZE + 1, MAX_DEV_NAME_SIZE, UART_DEV_SERVICE_NAME_PREFIX, port);
+ if (ret < 0) {
+ HDF_LOGE("Failed to snprintf_s");
+ OsalMemFree(handle);
+ OsalMemFree(serviceName);
+ return NULL;
+ }
+
+ struct HdfIoService *service = HdfIoServiceBind(serviceName);
+ if (service == NULL) {
+ HDF_LOGE("Failed to get service %s", serviceName);
+ OsalMemFree(handle);
+ OsalMemFree(serviceName);
+ return NULL;
+ }
+ OsalMemFree(serviceName);
+ handle->object = service;
+ return handle;
+}
+
+int32_t UartWrite(struct DevHandle *handle, uint8_t *data, uint32_t size)
+{
+ int ret;
+ struct HdfIoService *service = NULL;
+
+ if (handle == NULL || handle->object == NULL) {
+ HDF_LOGE("handle or handle->object is NULL");
+ return HDF_FAILURE;
+ }
+
+ struct HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
+ if (sBuf == NULL) {
+ HDF_LOGE("Failed to obtain sBuf");
+ return HDF_FAILURE;
+ }
+
+ if (!HdfSbufWriteBuffer(sBuf, data, size)) {
+ HDF_LOGE("Failed to write sbuf");
+ HdfSBufRecycle(sBuf);
+ return HDF_FAILURE;
+ }
+
+ service = (struct HdfIoService *)handle->object;
+ ret = service->dispatcher->Dispatch(&service->object, UART_WRITE, sBuf, NULL);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("Failed to send service call");
+ }
+ HdfSBufRecycle(sBuf);
+ return ret;
+}
+
+void UartClose(struct DevHandle *handle)
+{
+ struct HdfIoService *service = NULL;
+
+ if (handle == NULL || handle->object == NULL) {
+ HDF_LOGE("handle or handle->object is NULL");
+ return;
+ }
+ service = (struct HdfIoService *)handle->object;
+ HdfIoServiceRecycle(service);
+ OsalMemFree(handle);
+}
diff --git a/sample/platform/uart/dispatch/uart_if.h b/sample/platform/uart/dispatch/uart_if.h
new file mode 100755
index 0000000000000000000000000000000000000000..61ca0ad3aadca076cf91e3138f64ed11edaf4a9b
--- /dev/null
+++ b/sample/platform/uart/dispatch/uart_if.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef UART_IF_H
+#define UART_IF_H
+
+#include
+
+#define UART_DEV_SERVICE_NAME_PREFIX "HDF_PLATFORM_UART_%d"
+#define MAX_DEV_NAME_SIZE 32
+
+enum {
+ UART_WRITE = 1
+};
+
+struct DevHandle {
+ void *object;
+};
+
+struct DevHandle *UartOpen(uint32_t port);
+int32_t UartWrite(struct DevHandle *handle, uint8_t *data, uint32_t size);
+void UartClose(struct DevHandle *handle);
+
+#endif // UART_IF_H
\ No newline at end of file
diff --git a/sample/platform/uart/include/buf_fifo.h b/sample/platform/uart/include/buf_fifo.h
new file mode 100755
index 0000000000000000000000000000000000000000..ba9dab7d7e7c68246a2004cb35e0b4294afdc2fa
--- /dev/null
+++ b/sample/platform/uart/include/buf_fifo.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef BUF_FIFO_H
+#define BUF_FIFO_H
+
+#include
+#include
+#include
+
+struct BufferFifo {
+ volatile uint32_t readPosition;
+ volatile uint32_t writePosition;
+ uint16_t bufSizeMask;
+ uint8_t *buffer;
+};
+
+static inline uint16_t BufferFifoGetDataSize(struct BufferFifo *fifo)
+{
+ return (fifo->writePosition - fifo->readPosition);
+}
+
+static inline bool IsPowerOfTwo(int num)
+{
+ return (num > 0) && (num & (num - 1)) == 0;
+}
+
+bool BufferFifoInit(struct BufferFifo *fifo, uint8_t *buf, uint16_t bufSize);
+
+#endif // BUF_FIFO_H
+
diff --git a/sample/platform/uart/include/uart_dev_sample.h b/sample/platform/uart/include/uart_dev_sample.h
new file mode 100755
index 0000000000000000000000000000000000000000..87150de3a37271c85d9cd0ab504e5106ca620f27
--- /dev/null
+++ b/sample/platform/uart/include/uart_dev_sample.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef UART_DEV_SAMPLE_H
+#define UART_DEV_SAMPLE_H
+
+#include "sys/ioctl.h"
+#include "uart_core.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#define UART_IOC_MAGIC 'u'
+
+/* baudrate config */
+#define UART_CFG_BAUDRATE _IO(UART_IOC_MAGIC, 1)
+
+void AddUartDevice(struct UartHost *host);
+void RemoveUartDevice(struct UartHost *host);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#endif /* UART_DEV_SAMPLE_H */
diff --git a/tools/hdi-gen/codegen/generator_factory.h b/sample/platform/uart/include/uart_dispatch_sample.h
similarity index 42%
rename from tools/hdi-gen/codegen/generator_factory.h
rename to sample/platform/uart/include/uart_dispatch_sample.h
index 8b99621fbb6ce3af842405c67ac60f5e19c837d5..42ca3c5bc78fb52c5011b7ee283009c2743a3094 100755
--- a/tools/hdi-gen/codegen/generator_factory.h
+++ b/sample/platform/uart/include/uart_dispatch_sample.h
@@ -1,23 +1,20 @@
-/*
- * Copyright (c) 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.
- */
-
-#ifndef OHOS_HDI_GENERATORFACTORY_H
-#define OHOS_HDI_GENERATORFACTORY_H
-
-#include "codegen/code_generator.h"
-
-namespace OHOS {
-namespace HDI {
-class GeneratorFactory {
-public:
- AutoPtr GetCodeGenerator(const String& targetLanuage);
-};
-} // namespace HDI
-} // namespace OHOS
-
-#endif // OHOS_HDI_GENERATORFACTORY_H
\ No newline at end of file
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef UART_DISPATCH_SAMPLE_H
+#define UART_DISPATCH_SAMPLE_H
+
+#include "uart_pl011_sample.h"
+
+enum {
+ UART_WRITE = 1
+};
+
+int32_t SampleDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply);
+
+#endif // UART_DISPATCH_SAMPLE_H
diff --git a/sample/platform/uart/include/uart_pl011_sample.h b/sample/platform/uart/include/uart_pl011_sample.h
new file mode 100755
index 0000000000000000000000000000000000000000..ae2f612645aed627ffb23f103ca01ebaee5f88f9
--- /dev/null
+++ b/sample/platform/uart/include/uart_pl011_sample.h
@@ -0,0 +1,242 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef UART_PL011_SAMPLE_H
+#define UART_PL011_SAMPLE_H
+
+#include
+#include
+#include "hdf_device_desc.h"
+#include "buf_fifo.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct UartRegisterMap {
+ volatile uint32_t dr; /* Offset: 0x000 TYPE: (RW) Data register */
+ union {
+ volatile uint32_t rsr; /* Offset: 0x004 TYPE: (RO) Receive status register */
+ volatile uint32_t ecr; /* Offset: 0x004 TYPE: (WO) Error clear register */
+ };
+ volatile uint32_t reserved0[4]; /* Offset: 0x008-0x014 Reserved */
+ volatile uint32_t fr; /* Offset: 0x018 TYPE: (RO) Flag register */
+ volatile uint32_t reserved1; /* Offset: 0x01C Reserved */
+ volatile uint32_t ilpr; /* Offset: 0x020 TYPE: (RW) IrDA low-power counter register */
+ volatile uint32_t ibrd; /* Offset: 0x024 TYPE: (RW) Integer baud rate register */
+ volatile uint32_t fbrd; /* Offset: 0x028 TYPE: (RW) Fractional baud rate register */
+ volatile uint32_t lcr; /* Offset: 0x02C TYPE: (RW) Line control register */
+ volatile uint32_t cr; /* Offset: 0x030 TYPE: (RW) Control register */
+ volatile uint32_t ifls; /* Offset: 0x034 TYPE: (RW) Interrupt FIFO level select register */
+ volatile uint32_t imsc; /* Offset: 0x038 TYPE: (RW) Interrupt mask set/clear register */
+ volatile uint32_t ris; /* Offset: 0x03C TYPE: (RO) Raw interrupt status register */
+ volatile uint32_t mis; /* Offset: 0x040 TYPE: (RO) Masked interrupt status register */
+ volatile uint32_t icr; /* Offset: 0x044 TYPE: (WO) Interrupt clear register */
+ volatile uint32_t dmacr; /* Offset: 0x048 TYPE: (RW) DMA control register */
+};
+
+struct UartResource {
+ uint32_t num; /* UART port num */
+ uint32_t base; /* UART PL011 base address */
+ uint32_t irqNum; /* UART PL011 IRQ num */
+ uint32_t baudrate; /* Default baudrate */
+ uint32_t wlen; /* Default word length */
+ uint32_t parity; /* Default parity */
+ uint32_t stopBit; /* Default stop bits */
+ uint32_t uartClk; /* UART clock */
+ unsigned long physBase;
+};
+
+enum UartDeviceState {
+ UART_DEVICE_UNINITIALIZED = 0x0u,
+ UART_DEVICE_INITIALIZED = 0x1u,
+};
+
+struct UartDevice {
+ struct IDeviceIoService ioService;
+ struct UartResource resource;
+ enum UartDeviceState state; /* UART State */
+ uint32_t uartClk; /* UART clock */
+ uint32_t baudrate; /* Baudrate */
+ struct BufferFifo rxFifo;
+};
+
+/* Receive Status Register/Error Clear Register data */
+#define UART_PL011_RSR_FRAMING_ERROR_MASK (1 << 0x0u) /* Framing error bit mask */
+#define UART_PL011_RSR_PARITY_ERROR_MASK (1 << 0x1u) /* Parity error bit mask */
+#define UART_PL011_RSR_BREAK_ERROR_MASK (1 << 0x2u) /* Break error bit mask */
+#define UART_PL011_RSR_OVERRUN_ERROR_MASK (1 << 0x3u) /* Overrun error bit mask */
+
+/* Receive Status Register Error Mask */
+#define UART_PL011_RSR_RX_ERROR_MASK ( \
+ UART_PL011_RSR_FRAMING_ERROR_MASK \
+ | UART_PL011_RSR_PARITY_ERROR_MASK \
+ | UART_PL011_RSR_BREAK_ERROR_MASK \
+ | UART_PL011_RSR_OVERRUN_ERROR_MASK)
+
+#define UART_PL011_FR_CTS_MASK (1 << 0x0u) /* Clear to send bit mask */
+#define UART_PL011_FR_DSR_MASK (1 << 0x1u) /* Data set ready bit mask */
+#define UART_PL011_FR_DCD_MASK (1 << 0x2u) /* Data carrier detect bit mask */
+#define UART_PL011_FR_BUSY_MASK (1 << 0x3u) /* UART busy bit mask */
+#define UART_PL011_FR_RX_FIFO_EMPTY_MASK (1 << 0x4u) /* Receive FIFO empty bit mask */
+#define UART_PL011_FR_TX_FIFO_FULL_MASK (1 << 0x5u) /* Transmit FIFO full bit mask */
+#define UART_PL011_FR_RX_FIFO_FULL_MASK (1 << 0x6u) /* Receive FIFO full bit mask */
+#define UART_PL011_FR_TX_FIFO_EMPTY_MASK (1 << 0x7u) /* Transmit FIFO empty. bit mask */
+#define UART_PL011_FR_RI_MASK (1 << 0x8u) /* Ring indicator bit mask */
+
+/* PL011 Line Control Register Data bits */
+#define UART_PL011_LCR_H_BRK_MASK (1 << 0x0u) /* Send Break bit mask */
+#define UART_PL011_LCR_H_PEN_MASK (1 << 0x1u) /* Parity enable bit mask */
+#define UART_PL011_LCR_H_EPS_MASK (1 << 0x2u) /* Even parity select bit mask . */
+#define UART_PL011_LCR_H_FEN_MASK (1 << 0x4u) /* Enable FIFOs bit mask */
+#define UART_PL011_LCR_H_SPS_MASK (1 << 0x7u) /* Stick parity select bit mask */
+
+#define UART_PL011_LCR_H_WLEN_BIT_OFFSET 0x5u /* Word length bit offset */
+#define UART_PL011_LCR_H_WLEN_MASK ( \
+ 0x3u << UART_PL011_LCR_H_WLEN_BIT_OFFSET)
+
+#define UART_PL011_WLEN_5BITS (0x0u << UART_PL011_LCR_H_WLEN_BIT_OFFSET)
+#define UART_PL011_WLEN_6BITS (0x1u << UART_PL011_LCR_H_WLEN_BIT_OFFSET)
+#define UART_PL011_WLEN_7BITS (0x2u << UART_PL011_LCR_H_WLEN_BIT_OFFSET)
+#define UART_PL011_WLEN_8BITS (0x3u << UART_PL011_LCR_H_WLEN_BIT_OFFSET)
+
+#define UART_PL011_NONE_PARITY_CHECKED 0
+
+#define UART_PL011_LCR_H_STP2_BIT_OFFSET 0x3u /* Two stop bits select */
+
+#define UART_PL011_STOPBIT_1 (0x0u << UART_PL011_LCR_H_STP2_BIT_OFFSET)
+#define UART_PL011_STOPBIT_2 (0x1u << UART_PL011_LCR_H_STP2_BIT_OFFSET)
+
+#define UART_PL011_LCR_H_PARITY_MASK ( \
+ UART_PL011_LCR_H_PEN_MASK \
+ | UART_PL011_LCR_H_EPS_MASK \
+ | UART_PL011_LCR_H_SPS_MASK)
+
+#define UART_PL011_LCR_H_STOPBIT_MASK (0x1u << UART_PL011_LCR_H_STP2_BIT_OFFSET)
+
+#define UART_PL011_DATA_FORMAT_MASK ( \
+ UART_PL011_LCR_H_PARITY_MASK \
+ | UART_PL011_LCR_H_STOPBIT_MASK \
+ | UART_PL011_LCR_H_WLEN_MASK)
+
+/* Control Register */
+#define UART_PL011_CR_UARTEN_MASK (0x1u << 0x0u) /* Uart enable bit mask */
+#define UART_PL011_CR_SIREN_MASK (0x1u << 0x1u) /* Sir enable bit mask */
+#define UART_PL011_CR_SIRLP_MASK (0x1u << 0x2u) /* SIR low-power IrDA mode bit mask */
+#define UART_PL011_CR_LBE_MASK (0x1u << 0x7u) /* Loopback enable bit mask */
+#define UART_PL011_CR_TXE_MASK (0x1u << 0x8u) /* Transmit enable bit mask */
+#define UART_PL011_CR_RXE_MASK (0x1u << 0x9u) /* Receive enable bit mask */
+#define UART_PL011_CR_DTR_MASK (0x1u << 0xAu) /* Data transmit ready.bit mask */
+#define UART_PL011_CR_RTS_MASK (0x1u << 0xBu) /* Request to send bit mask */
+#define UART_PL011_CR_OUT1_MASK (0x1u << 0xCu) /* Out1 bit field mask */
+#define UART_PL011_CR_OUT2_MASK (0x1u << 0xDu) /* Out2 bit field mask */
+#define UART_PL011_CR_RTSE_MASK (0x1u << 0xEu) /* RTS hardware flow control enable bit mask */
+#define UART_PL011_CR_CTSE_MASK (0x1u << 0xFu) /* CTS hardware flow control enable bit mask */
+
+
+/* Interrupt FIFO Level Select Register Transmit bit offset */
+#define UART_PL011_IFLS_TX_BIT_OFFSET 0x0u
+/* Interrupt FIFO Level Select Register Receive bit offset */
+#define UART_PL011_IFLS_RX_BIT_OFFSET 0x3u
+
+#define UART_PL011_RX_FIFO_LVL_1_8 (0x0u << UART_PL011_IFLS_RX_BIT_OFFSET)
+#define UART_PL011_RX_FIFO_LVL_1_4 (0x1u << UART_PL011_IFLS_RX_BIT_OFFSET)
+#define UART_PL011_RX_FIFO_LVL_1_2 (0x2u << UART_PL011_IFLS_RX_BIT_OFFSET)
+#define UART_PL011_RX_FIFO_LVL_3_4 (0x3u << UART_PL011_IFLS_RX_BIT_OFFSET)
+#define UART_PL011_RX_FIFO_LVL_7_8 (0x4u << UART_PL011_IFLS_RX_BIT_OFFSET)
+
+#define UART_PL011_TX_FIFO_LVL_1_8 (0x0u << UART_PL011_IFLS_TX_BIT_OFFSET)
+#define UART_PL011_TX_FIFO_LVL_1_4 (0x1u << UART_PL011_IFLS_TX_BIT_OFFSET)
+#define UART_PL011_TX_FIFO_LVL_1_2 (0x2u << UART_PL011_IFLS_TX_BIT_OFFSET)
+#define UART_PL011_TX_FIFO_LVL_3_4 (0x3u << UART_PL011_IFLS_TX_BIT_OFFSET)
+#define UART_PL011_TX_FIFO_LVL_7_8 (0x4u << UART_PL011_IFLS_TX_BIT_OFFSET)
+
+/* Default register values of UART PL011 */
+#define UART_PL011_DEFAULT_DATA_REG_VALUE (0x0u)
+#define UART_PL011_DEFAULT_ECR_VALUE (0xFFu)
+#define UART_PL011_DEFAULT_ILPR_VALUE (0x0u)
+#define UART_PL011_DEFAULT_IBRD_REG_VALUE (0x0u)
+#define UART_PL011_DEFAULT_FBRD_REG_VALUE (0x0u)
+/* Clear UARTLCR */
+#define UART_PL011_DEFAULT_LCR_H_VALUE (0x0u)
+#define UART_PL011_DEFAULT_CTRL_REG_VALUE (0x0300u)
+
+#define UART_PL011_DEFAULT_IFLS_REG_VALUE ( \
+ UART_PL011_RX_FIFO_LVL_1_2 \
+ | UART_PL011_TX_FIFO_LVL_7_8)
+
+/* Clear interrupt mask */
+#define UART_PL011_DEFAULT_IMSC_REG_VALUE (0x0u)
+/* Clear interrupt */
+#define UART_PL011_DEFAULT_ICR_VALUE (0x7FFu)
+#define UART_PL011_DEFAULT_DMACR_VALUE (0x0u)
+
+#define FREQ_IRLPBAUD16_MIN (1420000u) /* 1.42 MHz */
+#define FREQ_IRLPBAUD16_MAX (2120000u) /* 2.12 MHz */
+#define SAMPLING_FACTOR (16u)
+#define UART_PL011_FBRD_WIDTH (6u)
+
+/**
+ * \brief ARM UART PL011 error enumeration types
+ */
+typedef enum UartPl011Error {
+ UART_PL011_ERR_NONE = (0x0u),
+ UART_PL011_ERR_RX_FRAME = UART_PL011_RSR_FRAMING_ERROR_MASK,
+ UART_PL011_ERR_RX_PARITY = UART_PL011_RSR_PARITY_ERROR_MASK,
+ UART_PL011_ERR_RX_BREAK = UART_PL011_RSR_BREAK_ERROR_MASK,
+ UART_PL011_ERR_RX_OVERFLOW = UART_PL011_RSR_OVERRUN_ERROR_MASK,
+ UART_PL011_ERR_INVALID_ARG = (UART_PL011_RSR_RX_ERROR_MASK + 1),
+ UART_PL011_ERR_NOT_READY,
+ UART_PL011_ERR_INVALID_BAUD,
+ UART_PL011_ERR_NOT_INIT,
+} UartPl011Error;
+
+static inline void UartPl011Enable(struct UartRegisterMap *regMap)
+{
+ regMap->cr |= UART_PL011_CR_UARTEN_MASK;
+}
+
+static inline void UartPl011Disable(struct UartRegisterMap *regMap)
+{
+ regMap->cr &= ~UART_PL011_CR_UARTEN_MASK;
+}
+
+static inline bool UartPl011IsEnabled(struct UartRegisterMap *regMap)
+{
+ return (bool)(regMap->cr & UART_PL011_CR_UARTEN_MASK);
+}
+
+static inline bool UartPl011IsBusy(struct UartRegisterMap *regMap)
+{
+ return (bool)(regMap->fr & UART_PL011_FR_BUSY_MASK);
+}
+
+void UartPl011SetLcrBits(struct UartRegisterMap *regMap, uint32_t bits);
+
+static inline void UartPl011Write(struct UartRegisterMap *regMap, uint8_t byte)
+{
+ while (UartPl011IsBusy(regMap));
+ regMap->dr = byte;
+}
+
+UartPl011Error UartPl011SetBaudrate(struct UartRegisterMap *regMap, uint32_t clk, uint32_t baudrate);
+
+void UartPl011SetDataFormat(struct UartRegisterMap *regMap, uint32_t wordLen, uint32_t parity, uint32_t stopBits);
+
+void UartPl011ResetRegisters(struct UartRegisterMap *regMap);
+
+static inline void UartPl011EnableFifo(struct UartRegisterMap *regMap)
+{
+ UartPl011SetLcrBits(regMap, UART_PL011_LCR_H_FEN_MASK);
+}
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* UART_PL011_SAMPLE_H */
+
diff --git a/sample/platform/uart/src/BUILD.gn b/sample/platform/uart/src/BUILD.gn
new file mode 100755
index 0000000000000000000000000000000000000000..a979792d487d743e696372112dc53e89a28d0820
--- /dev/null
+++ b/sample/platform/uart/src/BUILD.gn
@@ -0,0 +1,22 @@
+# Copyright (c) 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.
+
+import("//drivers/adapter/khdf/liteos/hdf.gni")
+
+module_switch = defined(LOSCFG_DRIVERS_HDF_PLATFORM_UART_SAMPLE)
+module_name = "hdf_uart_sample"
+hdf_driver(module_name) {
+ FRAMEWORK_UART_ROOT = "//drivers/framework/sample/platform/uart/src"
+ sources = [
+ "$FRAMEWORK_UART_ROOT/buf_fifo.c",
+ "$FRAMEWORK_UART_ROOT/uart_dev_sample.c",
+ "$FRAMEWORK_UART_ROOT/uart_dispatch_sample.c",
+ "$FRAMEWORK_UART_ROOT/uart_pl011_sample.c",
+ "$FRAMEWORK_UART_ROOT/uart_sample.c",
+ ]
+
+ include_dirs = [ "//drivers/framework/sample/platform/uart/include/" ]
+}
diff --git a/sample/platform/uart/src/buf_fifo.c b/sample/platform/uart/src/buf_fifo.c
new file mode 100755
index 0000000000000000000000000000000000000000..19da2dff6dc1e1b53face0fdfc17a8fed5421109
--- /dev/null
+++ b/sample/platform/uart/src/buf_fifo.c
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 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 "buf_fifo.h"
+
+bool BufferFifoInit(struct BufferFifo *fifo, uint8_t *fifoBuffer, uint16_t fifoSize)
+{
+ if (fifoBuffer == NULL) {
+ return false;
+ }
+ if (!IsPowerOfTwo(fifoSize)) {
+ return false;
+ }
+ fifo->buffer = fifoBuffer;
+ fifo->bufSizeMask = fifoSize - 1;
+ fifo->readPosition = 0;
+ fifo->writePosition = 0;
+ return true;
+}
\ No newline at end of file
diff --git a/sample/platform/uart/src/uart_dev_sample.c b/sample/platform/uart/src/uart_dev_sample.c
new file mode 100755
index 0000000000000000000000000000000000000000..1369188fe2a69999ccfa39e935bb4f2b182386bf
--- /dev/null
+++ b/sample/platform/uart/src/uart_dev_sample.c
@@ -0,0 +1,192 @@
+/*
+ * Copyright (c) 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 "uart_dev_sample.h"
+#include "fs/fs.h"
+#include "securec.h"
+#include "user_copy.h"
+#include "hdf_log.h"
+#include "osal_mem.h"
+#include "uart_pl011_sample.h"
+
+#define HDF_LOG_TAG uart_dev_sample
+#define HDF_UART_FS_MODE 0660
+
+static int32_t UartSampleDevOpen(struct file *filep)
+{
+ struct UartHost *host = NULL;
+
+ if (filep == NULL || filep->f_vnode == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ struct drv_data *drv = (struct drv_data *)filep->f_vnode->data;
+ host = (struct UartHost *)drv->priv;
+ if (host == NULL) {
+ HDF_LOGE("%s: host is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ HDF_LOGI("%s: open uart%d success", __func__, host->num);
+ return HDF_SUCCESS;
+}
+static int32_t UartSampleRelease(struct file *filep)
+{
+ struct UartHost *host = NULL;
+
+ if (filep == NULL || filep->f_vnode == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ struct drv_data *drv = (struct drv_data *)filep->f_vnode->data;
+ host = (struct UartHost *)drv->priv;
+ if (host == NULL) {
+ HDF_LOGE("%s: host is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ HDF_LOGI("%s: close uart%d success", __func__, host->num);
+ return HDF_SUCCESS;
+}
+
+static ssize_t UartSampleRead(struct file *filep, char *buf, size_t count)
+{
+ int32_t ret;
+ uint8_t *tmpBuf = NULL;
+ struct UartHost *host = NULL;
+
+ if (filep == NULL || filep->f_vnode == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ struct drv_data *drv = (struct drv_data *)filep->f_vnode->data;
+ host = (struct UartHost *)drv->priv;
+
+ if (LOS_IsUserAddressRange((vaddr_t)(uintptr_t)buf, count)) {
+ tmpBuf = (uint8_t *)OsalMemCalloc(count);
+ if (tmpBuf == NULL) {
+ HDF_LOGE("%s: OsalMemCalloc error", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+ ret = UartHostRead(host, tmpBuf, count);
+ if (ret == HDF_SUCCESS) {
+ ret = LOS_ArchCopyToUser(buf, tmpBuf, count);
+ }
+ OsalMemFree(tmpBuf);
+ return ret;
+ } else {
+ return UartHostRead(host, (uint8_t *)buf, count);
+ }
+}
+
+static ssize_t UartSampleWrite(struct file *filep, const char *buf, size_t count)
+{
+ int32_t ret;
+ uint8_t *tmpBuf = NULL;
+ struct UartHost *host = NULL;
+
+ if (filep == NULL || filep->f_vnode == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ struct drv_data *drv = (struct drv_data *)filep->f_vnode->data;
+ host = (struct UartHost *)drv->priv;
+
+ if (LOS_IsUserAddressRange((vaddr_t)(uintptr_t)buf, count)) {
+ tmpBuf = (uint8_t *)OsalMemCalloc(count);
+ if (tmpBuf == NULL) {
+ HDF_LOGE("%s: OsalMemCalloc error", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+ ret = LOS_ArchCopyFromUser(tmpBuf, buf, count);
+ if (ret != LOS_OK) {
+ OsalMemFree(tmpBuf);
+ return ret;
+ }
+ ret = UartHostWrite(host, tmpBuf, count);
+ OsalMemFree(tmpBuf);
+ return ret;
+ } else {
+ return UartHostWrite(host, (uint8_t *)buf, count);
+ }
+}
+
+static int32_t UartSampleDevIoctl(struct file *filep, int32_t cmd, unsigned long arg)
+{
+ int32_t ret;
+ struct UartHost *host = NULL;
+ if (filep == NULL || filep->f_vnode == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ struct drv_data *drv = (struct drv_data *)filep->f_vnode->data;
+ host = (struct UartHost *)drv->priv;
+ if (host->priv == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ ret = HDF_FAILURE;
+ switch (cmd) {
+ case UART_CFG_BAUDRATE:
+ ret = UartHostSetBaud(host, arg);
+ break;
+ default:
+ HDF_LOGE("%s cmd %d not support", __func__, cmd);
+ ret = HDF_ERR_NOT_SUPPORT;
+ break;
+ }
+ return ret;
+}
+
+const struct file_operations_vfs g_uartSampleDevFops = {
+ .open = UartSampleDevOpen,
+ .close = UartSampleRelease,
+ .read = UartSampleRead,
+ .write = UartSampleWrite,
+ .ioctl = UartSampleDevIoctl,
+};
+
+#define MAX_DEV_NAME_SIZE 32
+static void AddRemoveUartDev(struct UartHost *host, bool add)
+{
+ int32_t ret;
+ char *devName = NULL;
+
+ if (host == NULL || host->priv == NULL) {
+ HDF_LOGW("%s: invalid parameter", __func__);
+ return;
+ }
+ devName = (char *)OsalMemCalloc(sizeof(char) * (MAX_DEV_NAME_SIZE + 1));
+ if (devName == NULL) {
+ HDF_LOGE("%s: OsalMemCalloc error", __func__);
+ return;
+ }
+ ret = snprintf_s(devName, MAX_DEV_NAME_SIZE + 1, MAX_DEV_NAME_SIZE, "/dev/uartdev-%d", host->num);
+ if (ret < 0) {
+ HDF_LOGE("%s: snprintf_s failed", __func__);
+ OsalMemFree(devName);
+ return;
+ }
+ if (add) {
+ if (register_driver(devName, &g_uartSampleDevFops, HDF_UART_FS_MODE, host)) {
+ HDF_LOGE("%s: gen /dev/uartdev-%d fail!", __func__, host->num);
+ OsalMemFree(devName);
+ return;
+ }
+ } else {
+ if (unregister_driver(devName)) {
+ HDF_LOGE("%s: remove /dev/uartdev-%d fail!", __func__, host->num);
+ OsalMemFree(devName);
+ return;
+ }
+ }
+ OsalMemFree(devName);
+}
+
+void AddUartDevice(struct UartHost *host)
+{
+ AddRemoveUartDev(host, true);
+}
+
+void RemoveUartDevice(struct UartHost *host)
+{
+ AddRemoveUartDev(host, false);
+}
diff --git a/sample/platform/uart/src/uart_dispatch_sample.c b/sample/platform/uart/src/uart_dispatch_sample.c
new file mode 100755
index 0000000000000000000000000000000000000000..6817896f769203333cb57522318060c8af5e86a3
--- /dev/null
+++ b/sample/platform/uart/src/uart_dispatch_sample.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 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 "uart_core.h"
+#include "uart_dispatch_sample.h"
+#include "hdf_log.h"
+#include "hdf_sbuf.h"
+#include "uart_pl011_sample.h"
+
+#define HDF_LOG_TAG uart_dispatch_sample
+
+static int32_t SampleDispatchWrite(struct UartDevice *device, struct HdfSBuf *txBuf)
+{
+ uint32_t idx;
+ uint32_t dataSize = 0;
+ const uint8_t *data = NULL;
+ struct UartRegisterMap *regMap = (struct UartRegisterMap *)device->resource.physBase;
+
+ if (regMap == NULL) {
+ HDF_LOGE("%s: regMap is NULL", __func__);
+ return HDF_FAILURE;
+ }
+
+ if (!HdfSbufReadBuffer(txBuf, (const void **)&data, &dataSize)) {
+ HDF_LOGE("%s: Failed to read sbuf", __func__);
+ return HDF_FAILURE;
+ }
+ regMap = (struct UartRegisterMap *)device->resource.physBase;
+ for (idx = 0; idx < dataSize; idx++) {
+ UartPl011Write(regMap, data[idx]);
+ }
+ return HDF_SUCCESS;
+}
+
+int32_t SampleDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ int32_t result = HDF_FAILURE;
+ if (client == NULL || client->device == NULL) {
+ HDF_LOGE("%s: client or client->device is NULL", __func__);
+ return result;
+ }
+ struct UartHost *uartHost = (struct UartHost *)client->device->service;
+ if (uartHost == NULL) {
+ HDF_LOGE("%s: uartHost is NULL", __func__);
+ return result;
+ }
+ struct UartDevice *uartDevice = (struct UartDevice *)uartHost->priv;
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: uartDevice is NULL", __func__);
+ return result;
+ }
+ switch (cmdId) {
+ case UART_WRITE: {
+ result = SampleDispatchWrite(uartDevice, data);
+ break;
+ }
+ default:
+ break;
+ }
+ return result;
+}
diff --git a/sample/platform/uart/src/uart_pl011_sample.c b/sample/platform/uart/src/uart_pl011_sample.c
new file mode 100755
index 0000000000000000000000000000000000000000..12f2c6cf305efbfc1c914dfd686809bf1e17734e
--- /dev/null
+++ b/sample/platform/uart/src/uart_pl011_sample.c
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 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 "uart_pl011_sample.h"
+
+void UartPl011SetLcrBits(struct UartRegisterMap *regMap, uint32_t bits)
+{
+ bool uartEnabled = UartPl011IsEnabled(regMap);
+ /* UART must be disabled before UARTLCR_H are reprogrammed */
+ UartPl011Disable(regMap);
+ regMap->lcr |= (bits);
+ /* Restore uart enable state */
+ if (uartEnabled) {
+ UartPl011Enable(regMap);
+ }
+}
+
+void UartPl011UpdateLcr(struct UartRegisterMap *regMap)
+{
+ bool uartEnabled = UartPl011IsEnabled(regMap);
+ /* UART must be disabled before UARTLCR_H are reprogrammed */
+ UartPl011Disable(regMap);
+ regMap->lcr = regMap->lcr;
+ /* restore uart enable state */
+ if (uartEnabled) {
+ UartPl011Enable(regMap);
+ }
+}
+
+UartPl011Error UartPl011SetBaudrate(struct UartRegisterMap *regMap, uint32_t clk, uint32_t baudrate)
+{
+ if (baudrate == 0) {
+ return UART_PL011_ERR_INVALID_ARG;
+ }
+
+ uint32_t value = SAMPLING_FACTOR * baudrate;
+ uint32_t divider = clk / value;
+ uint32_t remainder = clk % value;
+ uint32_t fraction;
+ value = (SAMPLING_FACTOR * remainder) / baudrate;
+ fraction = (value >> 1) + (value & 1);
+
+ regMap->ibrd = divider;
+ regMap->fbrd = fraction;
+ /* to internally update the contents of UARTIBRD or
+ * UARTFBRD, a UARTLCR_H write must always be performed at the end.
+ */
+ UartPl011UpdateLcr(regMap);
+ return UART_PL011_ERR_NONE;
+}
+
+void UartPl011SetDataFormat(
+ struct UartRegisterMap *regMap, uint32_t wordLen, uint32_t parity, uint32_t stopBits)
+{
+ bool uartEnabled = UartPl011IsEnabled(regMap);
+ uint32_t lcr = regMap->lcr & (~UART_PL011_DATA_FORMAT_MASK);
+ lcr |= wordLen & UART_PL011_LCR_H_WLEN_MASK;
+ lcr |= parity & UART_PL011_LCR_H_PARITY_MASK;
+ lcr |= stopBits & UART_PL011_LCR_H_STOPBIT_MASK;
+ /* UART must be disabled before UARTLCR_H are reprogrammed */
+ UartPl011Disable(regMap);
+ regMap->lcr = lcr;
+ if (uartEnabled) {
+ UartPl011Enable(regMap);
+ }
+}
+
+void UartPl011ResetRegisters(struct UartRegisterMap *regMap)
+{
+ regMap->cr = UART_PL011_DEFAULT_CTRL_REG_VALUE;
+ regMap->dr = UART_PL011_DEFAULT_DATA_REG_VALUE;
+ /* Clear all the errors */
+ regMap->ecr = UART_PL011_DEFAULT_ECR_VALUE;
+ regMap->ilpr = UART_PL011_DEFAULT_ILPR_VALUE;
+ regMap->ibrd = UART_PL011_DEFAULT_IBRD_REG_VALUE;
+ regMap->fbrd = UART_PL011_DEFAULT_FBRD_REG_VALUE;
+ regMap->lcr = UART_PL011_DEFAULT_LCR_H_VALUE;
+ regMap->ifls = UART_PL011_DEFAULT_IFLS_REG_VALUE;
+ /* Clear all interrupt mask */
+ regMap->imsc = UART_PL011_DEFAULT_IMSC_REG_VALUE;
+ /* Clear all interrupts */
+ regMap->icr = UART_PL011_DEFAULT_ICR_VALUE;
+ regMap->dmacr = UART_PL011_DEFAULT_DMACR_VALUE;
+}
+
diff --git a/sample/platform/uart/src/uart_sample.c b/sample/platform/uart/src/uart_sample.c
new file mode 100755
index 0000000000000000000000000000000000000000..19678890d6475acc62cd5b9d9ddea20e34119a96
--- /dev/null
+++ b/sample/platform/uart/src/uart_sample.c
@@ -0,0 +1,344 @@
+/*
+ * Copyright (c) 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 "device_resource_if.h"
+#include "buf_fifo.h"
+#include "hdf_device_desc.h"
+#include "hdf_log.h"
+#include "hisoc/uart.h"
+#include "osal_io.h"
+#include "osal_mem.h"
+#include "uart_core.h"
+#include "uart_dev_sample.h"
+#include "uart_dispatch_sample.h"
+#include "uart_pl011_sample.h"
+
+#define HDF_LOG_TAG uart_sample
+#define UART_RX_FIFO_SIZE 128
+
+static uint8_t g_fifoBuffer[UART_RX_FIFO_SIZE] = {0};
+
+/* HdfDriverEntry method definitions */
+static int32_t SampleUartDriverBind(struct HdfDeviceObject *device);
+static int32_t SampleUartDriverInit(struct HdfDeviceObject *device);
+static void SampleUartDriverRelease(struct HdfDeviceObject *device);
+
+/* HdfDriverEntry definitions */
+struct HdfDriverEntry g_sampleUartDriverEntry = {
+ .moduleVersion = 1,
+ .moduleName = "UART_SAMPLE",
+ .Bind = SampleUartDriverBind,
+ .Init = SampleUartDriverInit,
+ .Release = SampleUartDriverRelease,
+};
+
+// Initialize HdfDriverEntry
+HDF_INIT(g_sampleUartDriverEntry);
+
+/* UartHostMethod method definitions */
+static int32_t SampleUartHostInit(struct UartHost *host);
+static int32_t SampleUartHostDeinit(struct UartHost *host);
+static int32_t SampleUartHostWrite(struct UartHost *host, uint8_t *data, uint32_t size);
+static int32_t SampleUartHostSetBaud(struct UartHost *host, uint32_t baudRate);
+static int32_t SampleUartHostGetBaud(struct UartHost *host, uint32_t *baudRate);
+
+/* UartHostMethod definitions */
+struct UartHostMethod g_sampleUartHostMethod = {
+ .Init = SampleUartHostInit,
+ .Deinit = SampleUartHostDeinit,
+ .Read = NULL,
+ .Write = SampleUartHostWrite,
+ .SetBaud = SampleUartHostSetBaud,
+ .GetBaud = SampleUartHostGetBaud,
+ .SetAttribute = NULL,
+ .GetAttribute = NULL,
+ .SetTransMode = NULL,
+};
+
+/* UartHostMethod implementations */
+static int32_t SampleUartHostInit(struct UartHost *host)
+{
+ HDF_LOGD("%s: Enter", __func__);
+ if (host == NULL) {
+ HDF_LOGW("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t SampleUartHostDeinit(struct UartHost *host)
+{
+ HDF_LOGD("%s: Enter", __func__);
+ if (host == NULL) {
+ HDF_LOGW("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t SampleUartHostWrite(struct UartHost *host, uint8_t *data, uint32_t size)
+{
+ uint32_t idx;
+ struct UartRegisterMap *regMap = NULL;
+ struct UartDevice *device = NULL;
+ HDF_LOGD("%s: Enter", __func__);
+
+ if (host == NULL || data == NULL || size == 0) {
+ HDF_LOGW("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ device = (struct UartDevice *)host->priv;
+ if (device == NULL) {
+ HDF_LOGW("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ regMap = (struct UartRegisterMap *)device->resource.physBase;
+ for (idx = 0; idx < size; idx++) {
+ UartPl011Write(regMap, data[idx]);
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t SampleUartHostSetBaud(struct UartHost *host, uint32_t baudRate)
+{
+ struct UartDevice *device = NULL;
+ struct UartRegisterMap *regMap = NULL;
+ UartPl011Error err;
+ HDF_LOGD("%s: Enter", __func__);
+
+ if (host == NULL) {
+ HDF_LOGW("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ device = (struct UartDevice *)host->priv;
+ if (device == NULL) {
+ HDF_LOGW("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ regMap = (struct UartRegisterMap *)device->resource.physBase;
+ if (device->state != UART_DEVICE_INITIALIZED) {
+ return UART_PL011_ERR_NOT_INIT;
+ }
+ if (baudRate == 0) {
+ return UART_PL011_ERR_INVALID_BAUD;
+ }
+ err = UartPl011SetBaudrate(regMap, device->uartClk, baudRate);
+ if (err == UART_PL011_ERR_NONE) {
+ device->baudrate = baudRate;
+ }
+ return err;
+}
+
+static int32_t SampleUartHostGetBaud(struct UartHost *host, uint32_t *baudRate)
+{
+ struct UartDevice *device = NULL;
+ HDF_LOGD("%s: Enter", __func__);
+
+ if (host == NULL) {
+ HDF_LOGW("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ device = (struct UartDevice *)host->priv;
+ if (device == NULL) {
+ HDF_LOGW("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ *baudRate = device->baudrate;
+ return HDF_SUCCESS;
+}
+
+static int InitUartDevice(struct UartDevice *device)
+{
+ UartPl011Error err;
+ struct UartResource *resource = &device->resource;
+ struct UartRegisterMap *regMap = (struct UartRegisterMap *)resource->physBase;
+ if ((resource->uartClk == 0) || (resource->baudrate == 0)) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ /* Updating the system clock */
+ device->uartClk = resource->uartClk;
+ uart_clk_cfg(0, true);
+ /* clear and reset registers. */
+ UartPl011ResetRegisters(regMap);
+ /* set baud rate as device config */
+ err = UartPl011SetBaudrate(regMap, resource->uartClk, resource->baudrate);
+ if (err != UART_PL011_ERR_NONE) {
+ return HDF_FAILURE;
+ }
+ /* set the data format as device config */
+ UartPl011SetDataFormat(regMap, resource->wlen, resource->parity, resource->stopBit);
+ /* Enabling the FIFOs */
+ UartPl011EnableFifo(regMap);
+ UartPl011Enable(regMap);
+ BufferFifoInit(&device->rxFifo, g_fifoBuffer, UART_RX_FIFO_SIZE);
+ device->state = UART_DEVICE_INITIALIZED;
+ return HDF_SUCCESS;
+}
+
+static uint32_t GetUartDeviceResource(
+ struct UartDevice *device, const struct DeviceResourceNode *resourceNode)
+{
+ struct UartResource *resource = &device->resource;
+ struct DeviceResourceIface *dri = NULL;
+ dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ if (dri == NULL || dri->GetUint32 == NULL) {
+ HDF_LOGE("DeviceResourceIface is invalid");
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint32(resourceNode, "num", &resource->num, 0) != HDF_SUCCESS) {
+ HDF_LOGE("uart config read num fail");
+ return HDF_FAILURE;
+ }
+ if (dri->GetUint32(resourceNode, "base", &resource->base, 0) != HDF_SUCCESS) {
+ HDF_LOGE("uart config read base fail");
+ return HDF_FAILURE;
+ }
+ resource->physBase = (unsigned long)OsalIoRemap(resource->base, 0x48);
+ if (resource->physBase == 0) {
+ HDF_LOGE("uart config fail to remap physBase");
+ return HDF_FAILURE;
+ }
+ if (dri->GetUint32(resourceNode, "irqNum", &resource->irqNum, 0) != HDF_SUCCESS) {
+ HDF_LOGE("uart config read irqNum fail");
+ return HDF_FAILURE;
+ }
+ if (dri->GetUint32(resourceNode, "baudrate", &resource->baudrate, 0) != HDF_SUCCESS) {
+ HDF_LOGE("uart config read baudrate fail");
+ return HDF_FAILURE;
+ }
+ if (dri->GetUint32(resourceNode, "wlen", &resource->wlen, 0) != HDF_SUCCESS) {
+ HDF_LOGE("uart config read wlen fail");
+ return HDF_FAILURE;
+ }
+ if (dri->GetUint32(resourceNode, "parity", &resource->parity, 0) != HDF_SUCCESS) {
+ HDF_LOGE("uart config read parity fail");
+ return HDF_FAILURE;
+ }
+ if (dri->GetUint32(resourceNode, "stopBit", &resource->stopBit, 0) != HDF_SUCCESS) {
+ HDF_LOGE("uart config read stopBit fail");
+ return HDF_FAILURE;
+ }
+ if (dri->GetUint32(resourceNode, "uartClk", &resource->uartClk, 0) != HDF_SUCCESS) {
+ HDF_LOGE("uart config read uartClk fail");
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t AttachUartDevice(struct UartHost *host, struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct UartDevice *uartDevice = NULL;
+ if (device->property == NULL) {
+ HDF_LOGW("%s: property is NULL", __func__);
+ return HDF_FAILURE;
+ }
+ uartDevice = (struct UartDevice *)OsalMemCalloc(sizeof(struct UartDevice));
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: OsalMemCalloc uartDevice error", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+ ret = GetUartDeviceResource(uartDevice, device->property);
+ if (ret != HDF_SUCCESS) {
+ (void)OsalMemFree(uartDevice);
+ return HDF_FAILURE;
+ }
+ host->num = uartDevice->resource.num;
+ host->priv = uartDevice;
+ AddUartDevice(host);
+ return InitUartDevice(uartDevice);
+}
+
+static void DeinitUartDevice(struct UartDevice *device)
+{
+ struct UartRegisterMap *regMap = (struct UartRegisterMap *)device->resource.physBase;
+ /* wait for uart enter idle. */
+ while (UartPl011IsBusy(regMap)) { }
+ UartPl011ResetRegisters(regMap);
+ uart_clk_cfg(0, false);
+ OsalIoUnmap((void *)device->resource.physBase);
+ device->state = UART_DEVICE_UNINITIALIZED;
+}
+
+static void DetachUartDevice(struct UartHost *host)
+{
+ struct UartDevice *uartDevice = NULL;
+
+ if (host->priv == NULL) {
+ HDF_LOGW("%s: invalid parameter", __func__);
+ return;
+ }
+ uartDevice = host->priv;
+ DeinitUartDevice(uartDevice);
+ (void)OsalMemFree(uartDevice);
+ host->priv = NULL;
+}
+
+/* HdfDriverEntry implementations */
+static int32_t SampleUartDriverBind(struct HdfDeviceObject *device)
+{
+ struct UartHost *uartHost = NULL;
+ HDF_LOGD("%s: Enter", __func__);
+
+ if (device == NULL) {
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ uartHost = UartHostCreate(device);
+ if (uartHost == NULL) {
+ HDF_LOGE("%s: UartHostCreate failed", __func__);
+ return HDF_FAILURE;
+ }
+ uartHost->service.Dispatch = SampleDispatch;
+ return HDF_SUCCESS;
+}
+
+static int32_t SampleUartDriverInit(struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct UartHost *host = NULL;
+ HDF_LOGD("%s: Enter", __func__);
+
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ host = UartHostFromDevice(device);
+ if (host == NULL) {
+ HDF_LOGE("%s: host is NULL", __func__);
+ return HDF_FAILURE;
+ }
+ ret = AttachUartDevice(host, device);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: attach error", __func__);
+ return HDF_FAILURE;
+ }
+ host->method = &g_sampleUartHostMethod;
+ return ret;
+}
+
+static void SampleUartDriverRelease(struct HdfDeviceObject *device)
+{
+ struct UartHost *host = NULL;
+ HDF_LOGD("%s: Enter", __func__);
+
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return;
+ }
+ host = UartHostFromDevice(device);
+ if (host == NULL) {
+ HDF_LOGE("%s: host is NULL", __func__);
+ return;
+ }
+ if (host->priv != NULL) {
+ DetachUartDevice(host);
+ }
+ UartHostDestroy(host);
+}
diff --git a/support/platform/include/adc_core.h b/support/platform/include/adc/adc_core.h
similarity index 98%
rename from support/platform/include/adc_core.h
rename to support/platform/include/adc/adc_core.h
index e0e47b521eacdc4161320e5ccde8e123f1eed8ae..c6890dfddbeea13c5f0993bec62517d3e06c363b 100644
--- a/support/platform/include/adc_core.h
+++ b/support/platform/include/adc/adc_core.h
@@ -12,6 +12,7 @@
#include "osal_spinlock.h"
#include "hdf_base.h"
#include "adc_if.h"
+#include "platform_core.h"
#ifdef __cplusplus
#if __cplusplus
diff --git a/support/platform/include/dac/dac_core.h b/support/platform/include/dac/dac_core.h
new file mode 100644
index 0000000000000000000000000000000000000000..8c04f35cdb8293b026592a42739ade7bbbc892d8
--- /dev/null
+++ b/support/platform/include/dac/dac_core.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef DAC_CORE_H
+#define DAC_CORE_H
+
+#include "osal_spinlock.h"
+#include "hdf_base.h"
+#include "dac_if.h"
+#include "platform_core.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* __cplusplus */
+
+#define DAC_DEVICES_MAX 15
+
+struct DacDevice;
+struct DacMethod;
+struct DacLockMethod;
+
+struct DacDevice {
+ const struct DacMethod *ops;
+ OsalSpinlock spin;
+ uint32_t devNum;
+ uint32_t chanNum;
+ const struct DacLockMethod *lockOps;
+ void *priv;
+};
+
+struct DacMethod {
+ int32_t (*write)(struct DacDevice *device, uint32_t channel, uint32_t val);
+ int32_t (*start)(struct DacDevice *device);
+ int32_t (*stop)(struct DacDevice *device);
+};
+
+struct DacLockMethod {
+ int32_t (*lock)(struct DacDevice *device);
+ void (*unlock)(struct DacDevice *device);
+};
+
+enum DacIoCmd {
+ DAC_IO_READ = 0,
+ DAC_IO_OPEN,
+ DAC_IO_CLOSE,
+};
+
+int32_t DacDeviceAdd(struct DacDevice *device);
+
+void DacDeviceRemove(struct DacDevice *device);
+
+struct DacDevice *DacDeviceGet(uint32_t number);
+
+void DacDevicePut(struct DacDevice *device);
+
+int32_t DacDeviceWrite(struct DacDevice *device, uint32_t channel, uint32_t val);
+
+int32_t DacDeviceStart(struct DacDevice *device);
+
+int32_t DacDeviceStop(struct DacDevice *device);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* __cplusplus */
+
+#endif /* DAC_CORE_H */
diff --git a/support/platform/include/dmac_core.h b/support/platform/include/dma/dmac_core.h
similarity index 100%
rename from support/platform/include/dmac_core.h
rename to support/platform/include/dma/dmac_core.h
diff --git a/support/platform/include/common/platform_core.h b/support/platform/include/fwk/platform_core.h
similarity index 95%
rename from support/platform/include/common/platform_core.h
rename to support/platform/include/fwk/platform_core.h
index 08e5770dd8224fa5827d337b3156372d327c3cd5..669d65cb21270c635df9707c4063e034f82821f5 100644
--- a/support/platform/include/common/platform_core.h
+++ b/support/platform/include/fwk/platform_core.h
@@ -11,10 +11,13 @@
#include "hdf_base.h"
-#include "platform_device.h"
+#include "platform_log.h"
#include "platform_errno.h"
-#include "platform_manager.h"
#include "platform_queue.h"
+#ifndef __USER__
+#include "platform_device.h"
+#include "platform_manager.h"
+#endif
#ifdef __cplusplus
#if __cplusplus
@@ -30,6 +33,7 @@ enum PlatformModuleType {
PLATFORM_MODULE_CLOCK,
PLATFORM_MODULE_REGULATOR,
PLATFORM_MODULE_MIPI_DSI,
+ PLATFORM_MODULE_MIPI_CSI,
PLATFORM_MODULE_UART,
PLATFORM_MODULE_SDIO,
PLATFORM_MODULE_MDIO,
diff --git a/support/platform/include/common/platform_device.h b/support/platform/include/fwk/platform_device.h
similarity index 58%
rename from support/platform/include/common/platform_device.h
rename to support/platform/include/fwk/platform_device.h
index 3b25cea81e709b0f9b25eb528c83c2733ce24456..f25d11053974040e422ee63929b2cbf2eae5a25a 100644
--- a/support/platform/include/common/platform_device.h
+++ b/support/platform/include/fwk/platform_device.h
@@ -10,6 +10,7 @@
#define PLATFORM_DEVICE_H
#include "hdf_base.h"
+#include "hdf_device_desc.h"
#include "hdf_dlist.h"
#include "hdf_sref.h"
#include "osal_sem.h"
@@ -24,20 +25,24 @@ extern "C" {
struct PlatformManager;
struct PlatformDevice {
- struct HdfDeviceObject *hdfDev; /* releated to an hdf device object */
- struct PlatformManager *manager; /* the platform manager it belongs to */
- uint32_t magic; /* magic number of the device instance */
- const char *name; /* name of the device instance */
- struct HdfSRef ref; /* used for reference count */
- struct DListHead node; /* linked to the list of a manager */
- struct DListHead notifiers; /* list of notifier nodes */
- bool ready; /* indicates whether initialized */
- OsalSpinlock spin; /* for member protection */
- struct OsalSem released; /* for death notification */
+ struct HdfDeviceObject *hdfDev; /* releated to a hdf device object */
+ struct IDeviceIoService *service; /* releated to a hdf io service object */
+ struct PlatformManager *manager; /* the platform manager it belongs to */
+ int32_t number; /* number of the device instance */
+ const char *name; /* name of the device instance */
+ struct HdfSRef ref; /* used for reference count */
+ struct DListHead node; /* linked to the list of a manager */
+ struct DListHead notifiers; /* list of notifier nodes */
+ bool ready; /* indicates whether initialized */
+ OsalSpinlock spin; /* for member protection */
+ struct OsalSem released; /* for death notification */
+ void *priv; /* private data of the device */
};
enum PlatformEventType {
- PLAT_EVENT_DEAD = 0, /* a platform device going to die */
+ PLAT_EVENT_INIT = 0, /* a platform device already initialized */
+ PLAT_EVENT_DEAD = 1, /* a platform device going to die */
+ PLAT_EVENT_MAX = 2,
};
struct PlatformNotifier {
@@ -114,6 +119,17 @@ void PlatformDevicePut(struct PlatformDevice *device);
*/
int32_t PlatformDeviceRegNotifier(struct PlatformDevice *device, struct PlatformNotifier *notifier);
+/**
+ * @brief Notify a platform event.
+ *
+ * @param device Indicates the pointer to the platform device.
+ * @param event The platform event to notify.
+ *
+ * @return Returns 0 if the notify successfully; returns a negative value otherwise.
+ * @since 1.0
+ */
+int32_t PlatformDeviceNotify(struct PlatformDevice *device, int32_t event);
+
/**
* @brief Unregister a notifier to a platform device.
*
@@ -160,6 +176,64 @@ int32_t PlatformDeviceAdd(struct PlatformDevice *device);
*/
void PlatformDeviceDel(struct PlatformDevice *device);
+/**
+ * @brief Get device resource node of the device.
+ *
+ * @param device Indicates the pointer to the platform device.
+ *
+ * @since 1.0
+ */
+struct DeviceResourceNode *PlatformDeviceGetDrs(struct PlatformDevice *device);
+
+/**
+ * @brief Create a hdf device service for the platform device.
+ *
+ * @param device Indicates the pointer to the platform device.
+ * @param dispatch Dispatch function for the service.
+ *
+ * @since 1.0
+ */
+int32_t PlatformDeviceCreateService(struct PlatformDevice *device,
+ int32_t (*dispatch)(struct HdfDeviceIoClient *client, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply));
+
+/**
+ * @brief Destroy the hdf device service for the platform device.
+ *
+ * @param device Indicates the pointer to the platform device.
+ *
+ * @since 1.0
+ */
+int32_t PlatformDeviceDestroyService(struct PlatformDevice *device);
+
+/**
+ * @brief Bind to a hdf device object.
+ *
+ * @param device Indicates the pointer to the platform device.
+ * @param hdfDevice Indicates the pointer to the hdf device object.
+ *
+ * @since 1.0
+ */
+int32_t PlatformDeviceBind(struct PlatformDevice *device, struct HdfDeviceObject *hdfDevice);
+
+/**
+ * @brief Unbind from a hdf device object.
+ *
+ * @param device Indicates the pointer to the platform device.
+ *
+ * @since 1.0
+ */
+int32_t PlatformDeviceUnbind(struct PlatformDevice *device);
+
+
+/**
+ * @brief Get the platform device from a hdf device object.
+ *
+ * @param device Indicates the pointer to the platform device.
+ *
+ * @since 1.0
+ */
+struct PlatformDevice *PlatformDeviceFromHdf(struct HdfDeviceObject *device);
+
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/support/platform/include/common/platform_errno.h b/support/platform/include/fwk/platform_errno.h
similarity index 100%
rename from support/platform/include/common/platform_errno.h
rename to support/platform/include/fwk/platform_errno.h
diff --git a/support/platform/include/plat_log.h b/support/platform/include/fwk/platform_log.h
similarity index 70%
rename from support/platform/include/plat_log.h
rename to support/platform/include/fwk/platform_log.h
index d3b4c6f2927a21d6ea01aae030d04daa99cfbb95..ab097fb147dba1610ec41d1a11da1fb1534afaeb 100644
--- a/support/platform/include/plat_log.h
+++ b/support/platform/include/fwk/platform_log.h
@@ -17,4 +17,9 @@
#define PLAT_LOGV(fmt, arg...) HDF_LOGV(fmt, ##arg)
#endif
+#define PLAT_LOGD(fmt, arg...) HDF_LOGD(fmt, ##arg)
+#define PLAT_LOGI(fmt, arg...) HDF_LOGI(fmt, ##arg)
+#define PLAT_LOGW(fmt, arg...) HDF_LOGW(fmt, ##arg)
+#define PLAT_LOGE(fmt, arg...) HDF_LOGE(fmt, ##arg)
+
#endif /* PLATFORM_LOG_H */
diff --git a/support/platform/include/common/platform_manager.h b/support/platform/include/fwk/platform_manager.h
similarity index 88%
rename from support/platform/include/common/platform_manager.h
rename to support/platform/include/fwk/platform_manager.h
index fa4c9d198088602d949211dd6d13e043cf48f424..0faa1944f02e4aa34b54b31a4be6112ad6ea8823 100644
--- a/support/platform/include/common/platform_manager.h
+++ b/support/platform/include/fwk/platform_manager.h
@@ -22,9 +22,12 @@ extern "C" {
enum PlatformModuleType;
struct PlatformManager {
+ struct PlatformDevice device;
const char *name; /* name of the manager */
struct DListHead devices; /* list to keep all it's device instances */
OsalSpinlock spin; /* for member protection */
+ int32_t (*add)(struct PlatformManager *manager, struct PlatformDevice *device);
+ int32_t (*del)(struct PlatformManager *manager, struct PlatformDevice *device);
};
/**
@@ -92,17 +95,17 @@ struct PlatformDevice *PlatformManagerFindDevice(struct PlatformManager *manager
bool (*match)(struct PlatformDevice *pdevice, void *data));
/**
- * @brief Get a platform device from the manager by magic.
+ * @brief Get a platform device from the manager by number.
*
* The device got will be returned with reference count increased.
*
* @param manager Indicates the pointer to the platform manager.
- * @param magic Indicates the magic number of the target platform device.
+ * @param number Indicates the number number of the target platform device.
*
* @return Returns the pointer to the paltform device on success; returns NULL otherwise.
* @since 1.0
*/
-struct PlatformDevice *PlatformManagerGetDeviceByMagic(struct PlatformManager *manager, uint32_t magic);
+struct PlatformDevice *PlatformManagerGetDeviceByNumber(struct PlatformManager *manager, uint32_t number);
#ifdef __cplusplus
#if __cplusplus
diff --git a/support/platform/include/common/platform_queue.h b/support/platform/include/fwk/platform_queue.h
similarity index 100%
rename from support/platform/include/common/platform_queue.h
rename to support/platform/include/fwk/platform_queue.h
diff --git a/support/platform/include/gpio_core.h b/support/platform/include/gpio/gpio_core.h
similarity index 97%
rename from support/platform/include/gpio_core.h
rename to support/platform/include/gpio/gpio_core.h
index 4f8fbdd6f4caf1963ba7c07a21ca6f8127dd9563..720fd237d97e177dc068e651af6518ac411e43ee 100644
--- a/support/platform/include/gpio_core.h
+++ b/support/platform/include/gpio/gpio_core.h
@@ -14,6 +14,7 @@
#include "hdf_dlist.h"
#include "gpio_if.h"
#include "osal_spinlock.h"
+#include "platform_core.h"
#ifdef __cplusplus
#if __cplusplus
@@ -33,11 +34,8 @@ struct GpioInfo;
* @since 1.0
*/
struct GpioCntlr {
- struct IDeviceIoService service;
- struct HdfDeviceObject *device;
+ struct PlatformDevice device;
struct GpioMethod *ops;
- struct DListHead list;
- OsalSpinlock spin;
uint16_t start;
uint16_t count;
struct GpioInfo *ginfos;
@@ -136,6 +134,8 @@ int32_t GpioCntlrDisableIrq(struct GpioCntlr *cntlr, uint16_t local);
void GpioCntlrIrqCallback(struct GpioCntlr *cntlr, uint16_t local);
+struct PlatformManager *GpioManagerGet(void);
+
struct GpioCntlr *GpioGetCntlr(uint16_t gpio);
static inline uint16_t GpioToLocal(uint16_t gpio)
diff --git a/support/platform/include/mmc/mmc_block.h b/support/platform/include/gpio/gpio_service.h
similarity index 60%
rename from support/platform/include/mmc/mmc_block.h
rename to support/platform/include/gpio/gpio_service.h
index bec2bb785c3e1b8a73fb816c99ca64dd5193e679..80e2b4dcfbc5f813a22c129b9efbdd3599d8e2c3 100644
--- a/support/platform/include/mmc/mmc_block.h
+++ b/support/platform/include/gpio/gpio_service.h
@@ -1,15 +1,13 @@
/*
- * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ * Copyright (c) 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.
*/
-#ifndef MMC_BLOCK_H
-#define MMC_BLOCK_H
-
-#include "mmc_corex.h"
+#ifndef GPIO_SERVICE_H
+#define GPIO_SERVICE_H
#ifdef __cplusplus
#if __cplusplus
@@ -17,8 +15,12 @@ extern "C" {
#endif
#endif /* __cplusplus */
-int32_t MmcBlockAdd(struct MmcDevice *mmc);
-void MmcBlockDel(struct MmcDevice *mmc);
+enum GpioIoCmd {
+ GPIO_IO_READ = 0,
+ GPIO_IO_WRITE = 1,
+ GPIO_IO_GETDIR = 2,
+ GPIO_IO_SETDIR = 3,
+};
#ifdef __cplusplus
#if __cplusplus
@@ -26,4 +28,4 @@ void MmcBlockDel(struct MmcDevice *mmc);
#endif
#endif /* __cplusplus */
-#endif /* MMC_BLOCK_H */
+#endif /* GPIO_SERVICE_H */
diff --git a/support/platform/include/hdmi/hdmi_cec.h b/support/platform/include/hdmi/hdmi_cec.h
new file mode 100644
index 0000000000000000000000000000000000000000..838547c4fd84f8197cb4b116b293cafcca43cd59
--- /dev/null
+++ b/support/platform/include/hdmi/hdmi_cec.h
@@ -0,0 +1,1735 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef HDMI_CEC_H
+#define HDMI_CEC_H
+
+#include "hdf_base.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* __cplusplus */
+
+/*
+ * CEC(Consumer Electronics Control).
+ * CEC is a protocol that provides high-level control functions between all of the various audiovisual products
+ * in a user's environment.
+ */
+
+/*
+ * One Touch Play Feature/Routing Control Feature.
+ * Used by a new source to indicate that it has started to transmit a stream OR
+ * used in response to a .
+ * Param: [Physical Address], 2 bytes.
+ * Broadcast message.
+ */
+#define HDMI_CEC_OPCODE_ACTIVE_SOURCE 0x82
+
+#define HDMI_CEC_ACTIVE_SOURCE_MSG_PARAM_LEN 2
+
+/*
+ * One Touch Play Feature.
+ * Sent by a source device to the TV whenever it enters the
+ * active state(alternatively it may send ).
+ * Param: None.
+ */
+#define HDMI_CEC_OPCODE_IMAGE_VIEW_ON 0x04
+
+/*
+ * One Touch Play Feature.
+ * As , but should also remove any text, menus and PIP windows from the TV's display.
+ * Param: None.
+ */
+#define HDMI_CEC_OPCODE_TEXT_VIEW_ON 0x0D
+
+/*
+ * Routing Control Feature.
+ * Used by currently active source to inform the TV that it has no video to be presented to the user,
+ * or is going into the Standby state as the result of a local user command on the device.
+ * Param: [Physical Address], 2 bytes.
+ */
+#define HDMI_CEC_OPCODE_INACTIVE_SOURCE 0x9D
+
+#define HDMI_CEC_INACTIVE_SOURCE_MSG_PARAM_LEN 2
+
+/*
+ * Routing Control Feature.
+ * Used by a new device to discover the status of the system.
+ * Param: None.
+ * Broadcast message.
+ */
+#define HDMI_CEC_OPCODE_REQUEST_ACTIVE_SOURCE 0x85
+
+/*
+ * Routing Control Feature.
+ * Sent By CEC Switch when it is manually switched to inform all other devices on the network that
+ * the active route below the switch has changed.
+ * Param: [Original(Physical) Address], 2 bytes. [New(Physical) Address], 2 bytes.
+ * Broadcast message.
+ */
+#define HDMI_CEC_OPCODE_ROUTING_CHANGE 0x80
+
+#define HDMI_CEC_ROUTING_CHANGE_MSG_PARAM_LEN 4
+
+/*
+ * Routing Control Feature.
+ * Sent By a CEC Switch to indicate the active route below the switch.
+ * Param: [Physical Address], 2 bytes.
+ * Broadcast message.
+ */
+#define HDMI_CEC_OPCODE_ROUTING_INFORMATION 0x81
+
+#define HDMI_CEC_ROUTING_INFORMATIO_MSG_PARAM_LEN 2
+
+/*
+ * Routing Control Feature.
+ * Used by the TV to request a streaming path from the specified Physical Address.
+ * Param: [Physical Address], 2 bytes.
+ * Broadcast message.
+ */
+#define HDMI_CEC_OPCODE_SET_STREAM_PATH 0x86
+
+#define HDMI_CEC_SET_STREAM_PATH_MSG_PARAM_LEN 2
+
+/*
+ * Routing Control Feature.
+ * Switches one or all devices into the Standby state.
+ * Can be used as a broadcast message or be addressed to a specific device.
+ * Param: None.
+ */
+#define HDMI_CEC_OPCODE_STANDBY 0x36
+
+/*
+ * One Touch Record Feature.
+ * Request a device stop a recording.
+ * Param: None.
+ */
+#define HDMI_CEC_OPCODE_RECORD_OFF 0x0B
+
+/*
+ * One Touch Record Feature.
+ * Attempt to record the specified source.
+ * Param: [Record Source], 1~8 bytes.
+ */
+#define HDMI_CEC_OPCODE_RECORD_ON 0x09
+
+/* Record Source Type, 1 byte. */
+#define HDMI_CEC_RECORD_SOURCE_TYPE_LEN 1
+enum HdmiCecRecordSourceType {
+ HDMI_CEC_RECORD_SRC_OWN = 1,
+ HDMI_CEC_RECORD_SRC_DIGITAL = 2,
+ HDMI_CEC_RECORD_SRC_ANALOG = 3,
+ HDMI_CEC_RECORD_SRC_EXT_PLUG = 4,
+ HDMI_CEC_RECORD_SRC_EXT_PHY_ADDR = 5,
+};
+
+/*
+ * Digital Service Identification. 7 bytes.
+ * [Service Identification Method] 1 bit
+ * [Digital Broadcast System] 7 bits
+ * [Service Identification] 6 bytes
+ */
+#define HDMI_CEC_DIGITAL_SERVICE_ID_LEN 7
+#define HDMI_CEC_SERVICE_ID_METHOD_BY_DIGITAL_IDS 0
+#define HDMI_CEC_SERVICE_ID_METHOD_BY_CHANNEL 1
+
+enum HdmiCecDigitalBroadcastSystem {
+ HDMI_CEC_DIG_SERVICE_BCAST_SYSTEM_ARIB_GEN = 0x00,
+ HDMI_CEC_DIG_SERVICE_BCAST_SYSTEM_ATSC_GEN = 0x01,
+ HDMI_CEC_DIG_SERVICE_BCAST_SYSTEM_DVB_GEN = 0x02,
+ HDMI_CEC_DIG_SERVICE_BCAST_SYSTEM_ARIB_BS = 0x08,
+ HDMI_CEC_DIG_SERVICE_BCAST_SYSTEM_ARIB_CS = 0x09,
+ HDMI_CEC_DIG_SERVICE_BCAST_SYSTEM_ARIB_T = 0x0A,
+ HDMI_CEC_DIG_SERVICE_BCAST_SYSTEM_ATSC_CABLE = 0x10,
+ HDMI_CEC_DIG_SERVICE_BCAST_SYSTEM_ATSC_SATELLITE = 0x11,
+ HDMI_CEC_DIG_SERVICE_BCAST_SYSTEM_ATSC_TERRESTRIAL = 0x12,
+ HDMI_CEC_DIG_SERVICE_BCAST_SYSTEM_DVB_C = 0x18,
+ HDMI_CEC_DIG_SERVICE_BCAST_SYSTEM_DVB_S = 0x19,
+ HDMI_CEC_DIG_SERVICE_BCAST_SYSTEM_DVB_S2 = 0x1A,
+ HDMI_CEC_DIG_SERVICE_BCAST_SYSTEM_DVB_T = 0x1B,
+};
+
+/*
+ * Service Identification, 6 bytes.
+ * [ARIB Data] | [ATSC Data] | [DVB Data] | [Channel Data]
+ * Channel Data, 6 bytes.
+ * [Channel Identifier] 4 bytes, [Reserved] 2 bytes.
+ * Channel Identifier, 4 bytes.
+ * [Channel Number Format] 6 bits.
+ * [Major Channel Number] 10 bits.
+ * [Minor Channel Number] 16 bits
+ */
+#define HDMI_CEC_CHANNEL_NUMBER_FORMAT_1_PART 0x01
+#define HDMI_CEC_CHANNEL_NUMBER_FORMAT_2_PART 0x02
+#define HDMI_CEC_CHANNEL_NUMBER_FORMAT_SHIFT 2
+
+struct HdmiCecDigitalServiceAribData {
+ uint16_t transportId;
+ uint16_t serviceId;
+ uint16_t orgNetworkId;
+};
+
+struct HdmiCecDigitalServiceAtscData {
+ uint16_t transportId;
+ uint16_t programNumber;
+};
+
+struct HdmiCecDigitalServiceDvbData {
+ uint16_t transportId;
+ uint16_t serviceId;
+ uint16_t orgNetworkId;
+};
+
+#define HDMI_CEC_CHANNEL_IDENTIFIER_LEN 4
+struct HdmiCecChannelIdentifier {
+ uint8_t format;
+ uint16_t major;
+ uint16_t minor;
+};
+
+#define HDMI_CEC_DIGITAL_SERVICE_ID_METHOD_SHIFT 7
+
+struct HdmiCecDigitalServiceId {
+ uint8_t method;
+ uint8_t system;
+ union {
+ struct HdmiCecDigitalServiceAribData arib;
+ struct HdmiCecDigitalServiceAtscData atsc;
+ struct HdmiCecDigitalServiceDvbData dvb;
+ struct HdmiCecChannelIdentifier channel;
+ } systemData;
+};
+
+/*
+ * Record Source.
+ * {[Record Source Type]} | {[Record Source Type] [Digital Service Identification]} |
+ * {[Record Source Type] [Analogue Broadcast Type] [Analogue Frequency] [Broadcast System]} |
+ * {[Record Source Type] [External Plug]} | {[Record Source Type] [External Physical Address]}
+ */
+#define HDMI_CEC_ANALOGUE_BROADCAST_TYPE_LEN 1
+#define HDMI_CEC_ANALOGUE_FREQ_LEN 2
+#define HDMI_CEC_BROADCAST_SYSTEM_LEN 1
+#define HDMI_CEC_EXT_PLUG_LEN 1
+#define HDMI_CEC_EXT_PHY_ADDRESS_LEN 2
+#define HDMI_CEC_RECORD_ON_OWN_MSG_PARAM_LEN HDMI_CEC_RECORD_SOURCE_TYPE_LEN
+#define HDMI_CEC_RECORD_ON_DIGITAL_MSG_PARAM_LEN (HDMI_CEC_RECORD_SOURCE_TYPE_LEN + HDMI_CEC_DIGITAL_SERVICE_ID_LEN)
+#define HDMI_CEC_RECORD_ON_ANALOG_MSG_PARAM_LEN (HDMI_CEC_RECORD_SOURCE_TYPE_LEN + \
+ HDMI_CEC_ANALOGUE_BROADCAST_TYPE_LEN + HDMI_CEC_ANALOGUE_FREQ_LEN + HDMI_CEC_BROADCAST_SYSTEM_LEN)
+#define HDMI_CEC_RECORD_ON_EXT_PLUG_MSG_PARAM_LEN (HDMI_CEC_RECORD_SOURCE_TYPE_LEN + HDMI_CEC_EXT_PLUG_LEN)
+#define HDMI_CEC_RECORD_ON_EXT_PHY_ADDR_MSG_PARAM_LEN (HDMI_CEC_RECORD_SOURCE_TYPE_LEN + HDMI_CEC_EXT_PHY_ADDRESS_LEN)
+
+struct HdmiCecRecordSource {
+ uint8_t type;
+ union {
+ struct HdmiCecDigitalServiceId id;
+ struct {
+ uint8_t anaBcastType;
+ uint16_t anaFreq;
+ uint8_t bcstSystem;
+ } analog;
+ uint8_t extPlug;
+ uint16_t extPhyAddr;
+ } data;
+};
+
+/*
+ * One Touch Record Feature.
+ * Used by a Recording Device to inform the Initiator of the message about its status.
+ * Param: [Record Status Info], 1 byte.
+ */
+#define HDMI_CEC_OPCODE_RECORD_STATUS 0x0A
+
+#define HDMI_CEC_RECORD_STATUS_MSG_PARAM_LEN 1
+
+/* Record Status Info */
+enum HdmiCecRecordStatusInfo {
+ HDMI_CEC_RECORD_STATUS_CUR_SRC = 0x01,
+ HDMI_CEC_RECORD_STATUS_DIG_SERVICE = 0x02,
+ HDMI_CEC_RECORD_STATUS_ANA_SERVICE = 0x03,
+ HDMI_CEC_RECORD_STATUS_EXT_INPUT = 0x04,
+ HDMI_CEC_RECORD_STATUS_NO_DIG_SERVICE = 0x05,
+ HDMI_CEC_RECORD_STATUS_NO_ANA_SERVICE = 0x06,
+ HDMI_CEC_RECORD_STATUS_NO_SERVICE = 0x07,
+ HDMI_CEC_RECORD_STATUS_INVALID_EXT_PLUG = 0x09,
+ HDMI_CEC_RECORD_STATUS_INVALID_EXT_PHYS_ADDR = 0x0A,
+ HDMI_CEC_RECORD_STATUS_UNSUP_CA = 0x0B,
+ HDMI_CEC_RECORD_STATUS_NO_CA_ENTITLEMENTS = 0x0C,
+ HDMI_CEC_RECORD_STATUS_NO_COPY_SRC = 0x0D,
+ HDMI_CEC_RECORD_STATUS_NO_MORE_COPIES = 0x0E,
+ HDMI_CEC_RECORD_STATUS_NO_MEDIA = 0x10,
+ HDMI_CEC_RECORD_STATUS_PLAYING = 0x11,
+ HDMI_CEC_RECORD_STATUS_ALREADY_RECORDING = 0x12,
+ HDMI_CEC_RECORD_STATUS_MEDIA_PROTECTED = 0x13,
+ HDMI_CEC_RECORD_STATUS_NO_SRC_SIGNAL = 0x14,
+ HDMI_CEC_RECORD_STATUS_MEDIA_PROBLEM = 0x15,
+ HDMI_CEC_RECORD_STATUS_NO_SPACE = 0x16,
+ HDMI_CEC_RECORD_STATUS_PARENTAL_LOCK = 0x17,
+ HDMI_CEC_RECORD_STATUS_TERMINATED_OK = 0x1A,
+ HDMI_CEC_RECORD_STATUS_ALREADY_TERMINATED = 0x1B,
+ HDMI_CEC_RECORD_STATUS_OTHER = 0x1F,
+};
+
+/*
+ * One Touch Record Feature.
+ * Request by The Recording Device to record the presently displayed source.
+ */
+#define HDMI_CEC_OPCODE_RECORD_TV_SCREEN 0x0F
+
+/*
+ * Timer Programming Feature.
+ * Used to clear an Analogue timer block of a device.
+ * Param: see param.
+ */
+#define HDMI_CEC_OPCODE_CLEAR_ANALOGUE_TIMER 0x33
+
+/*
+ * Timer Programming Feature.
+ * Used to clear a Digital timer block of a device.
+ * Param: see param.
+ */
+#define HDMI_CEC_OPCODE_CLEAR_DIGITAL_TIMER 0x99
+
+/*
+ * Timer Programming Feature.
+ * Used to clear a External timer block of a device.
+ * Param: see param.
+ */
+#define HDMI_CEC_OPCODE_CLEAR_EXTERNAL_TIMER 0xA1
+
+/*
+ * Timer Programming Feature.
+ * Used to set a single timer block on an Analogue Recording device.
+ * Param: [Day of Month], 1 byte; [Month of Year], 1 byte; [Start Time], 2 byte; [Duration], 2 byte;
+ * [Recording Sequence], 1 byte; [Analogue Broadcast Type], 1 byte; [Analogue Frequency], 2 byte;
+ * [Broadcast System], 1 byte.
+ */
+#define HDMI_CEC_OPCODE_SET_ANALOGUE_TIMER 0x34
+
+/* Analogue Broadcast Type, 1 byte. */
+enum HdmiCecAnalogueBroadcastType {
+ HDMI_CEC_ANALOGUE_BROADCAST_CABLE = 0,
+ HDMI_CEC_ANALOGUE_BROADCAST_SATELITE = 1,
+ HDMI_CEC_ANALOGUE_BROADCAST_TERRESTRIAL = 2,
+};
+
+/* Recording Sequence, 8 bits. */
+enum HdmiCecRecordingSequence {
+ HDMI_CEC_RECORDING_SEQ_ONCE_ONLY = 0x00,
+ HDMI_CEC_RECORDING_SEQ_SUNDAY = 0x01,
+ HDMI_CEC_RECORDING_SEQ_MONDAY = 0x02,
+ HDMI_CEC_RECORDING_SEQ_TUESDAY = 0x04,
+ HDMI_CEC_RECORDING_SEQ_WEDNESDAY = 0x08,
+ HDMI_CEC_RECORDING_SEQ_THURSDAY = 0x10,
+ HDMI_CEC_RECORDING_SEQ_FRIDAY = 0x20,
+ HDMI_CEC_RECORDING_SEQ_SATERDAY = 0x40,
+};
+
+#define HDMI_CEC_ANALOGUE_TIMER_INFO_LEN 11
+/* Hour and Minute are in BCD format. */
+#define HDMI_CEC_BCD_FORMAT_TIME(time) (((time / 10) << 4) | (time % 10))
+
+#define HDMI_CEC_COMM_TIMER_INFO_LEN 7
+struct HdmiCecCommTimerInfo {
+ uint8_t data;
+ uint8_t month;
+ uint8_t startHour;
+ uint8_t startMinute;
+ uint8_t durationHour;
+ uint8_t durationMinute;
+ uint8_t recordingSeq;
+};
+
+struct HdmiCecAnalogueTimerInfo {
+ struct HdmiCecCommTimerInfo commInfo;
+ uint8_t anaBcastType;
+ uint16_t anaFreq;
+ uint8_t bcstSystem;
+};
+
+/*
+ * Timer Programming Feature.
+ * Used to set a single timer block on a Digital Recording device.
+ * Param: [Day of Month], 1 byte; [Month of Year], 1 byte; [Start Time], 2 byte; [Duration], 2 byte;
+ * [Recording Sequence], 1 byte; [Digtial Service Identification], 7 byte.
+ */
+#define HDMI_CEC_OPCODE_SET_DIGITAL_TIMER 0x97
+
+#define HDMI_CEC_DIGITAL_TIMER_INFO_LEN 14
+struct HdmiCecDigitalTimerInfo {
+ struct HdmiCecCommTimerInfo commInfo;
+ struct HdmiCecDigitalServiceId id;
+};
+
+/*
+ * Timer Programming Feature.
+ * Used to set a single timer block to record from an External device.
+ * Param: [Day of Month], 1 byte; [Month of Year], 1 byte; [Start Time], 2 byte; [Duration], 2 byte;
+ * [Recording Sequence], 1 byte; [External Source Specifier], 1 byte; [External Plug], 1 byte;
+ * [External Physical address], 2 byte.
+ */
+#define HDMI_CEC_OPCODE_SET_EXTERNAL_TIMER 0xA2
+
+#define HDMI_CEC_EXTERNAL_TIMER_INFO_LEN 11
+
+/* External Source Specifier */
+#define HDMI_CEC_EXT_PLUG 4
+#define HDMI_CEC_EXT_PHYS_ADDR 5
+
+struct HdmiCecExternalTimerInfo {
+ struct HdmiCecCommTimerInfo commInfo;
+ uint8_t extSrcSpec;
+ uint8_t extPlug;
+ uint16_t extPhyAddr;
+};
+
+/*
+ * Timer Programming Feature.
+ * Used to set the name of a program associate with a timer block.
+ * Sent directly after sending a or message.
+ * The name is then associated with that timer block.
+ * Param: [Program Title String], 1~14 bytes.
+ */
+#define HDMI_CEC_OPCODE_SET_TIMER_PROGRAM_TITLE 0x67
+
+#define HDMI_CEC_PROGRAM_TITLE_STR_MIN_LEN 1
+#define HDMI_CEC_PROGRAM_TITLE_STR_MAX_LEN 14
+
+/*
+ * Timer Programming Feature.
+ * Used to give the status of a ,
+ * or message.
+ * Param: [Timer Cleared Status Data], 1 byte.
+ */
+#define HDMI_CEC_OPCODE_TIMER_CLEARED_STATUS 0x43
+
+#define HDMI_CEC_TIMER_CLEARED_STATUS_MSG_PARAM_LEN 1
+
+/* Timer Cleared Status Data */
+enum HdmiCecTimerClearedStatus {
+ HDMI_CEC_TIMER_CLR_STAT_NO_CLEARED_RECORDING = 0x00,
+ HDMI_CEC_TIMER_CLR_STAT_NO_CLEARED_NO_MATCHING = 0x01,
+ HDMI_CEC_TIMER_CLR_STAT_NO_CLEARED_NO_INFO = 0x02,
+ HDMI_CEC_TIMER_CLR_STAT_CLEARED = 0x80,
+};
+
+/*
+ * Timer Programming Feature.
+ * Used to send timer status to the Initiator of a message.
+ * Param: [Timer Status Data], 1 byte or 3 bytes.
+ */
+#define HDMI_CEC_OPCODE_TIMER_STATUS 0x35
+
+#define HDMI_CEC_TIMER_STATUS_DATA_MIN_LEN 1
+#define HDMI_CEC_TIMER_STATUS_DATA_MAX_LEN 3
+
+/*
+ * Timer Status Data. 1 byte or 3 bytes.
+ * [Timer overlap warning] 1bit.
+ * [Media Info] 2 bits.
+ * [Timer Progremmed Info] 5 bits or 21 bits.
+ */
+#define HDMI_CEC_TIMER_OVERLAP_WARNING_NO_OVERLAP 0
+#define HDMI_CEC_TIMER_OVERLAP_WARNING_TIMER_BLOCK_OVERLAP 1
+
+enum HdmiCecMediaInfo {
+ HDMI_CEC_MEDIA_PRESENT_NOT_POTECTED = 0,
+ HDMI_CEC_MEDIA_PRESENT_POTECTED = 1,
+ HDMI_CEC_MEDIA_NOT_PRESENT = 2,
+ HDMI_CEC_MEDIA_BUTT,
+};
+
+/*
+ * Timer Progremmed Info, 5 bits or 21 bits.
+ * [Progremmed Indicator], 1 bit.
+ * {[Progremmed Info], 4 bits. [Duration Available], 2bytes.} |
+ * {[Not Progremmed Error Info], 4 bits. [Duration Available], 2bytes.}
+ */
+/* Progremmed Indicator, 1 bit */
+#define HDMI_CEC_PROG_IND_NOT_PROGRAMMED 0
+#define HDMI_CEC_PROG_IND_PROGRAMMED 1
+
+/* Progremmed Info, 4 bits */
+enum HdmiCecProgremmedInfo {
+ HDMI_CEC_PROGRAMMED_INFO_ENOUGH_SPAC = 0x08,
+ HDMI_CEC_PROGRAMMED_INFO_NOT_ENOUGH_SPAC = 0x09,
+ HDMI_CEC_PROGRAMMED_INFO_NO_MEDIA_INFO = 0x0A,
+ HDMI_CEC_PROGRAMMED_INFO_MIGHT_NOT_BE_ENOUGH_SPACE = 0x0B,
+};
+
+/* Not Progremmed Error Info */
+enum HdmiCecNotProgremmedErrorInfo {
+ HDMI_CEC_NOT_PROG_ERR_NO_FREE_TIMER = 0x01,
+ HDMI_CEC_NOT_PROG_ERR_DATE_OUT_OF_RANGE = 0x02,
+ HDMI_CEC_NOT_PROG_ERR_RECORDING_SEQ_ERROR = 0x03,
+ HDMI_CEC_NOT_PROG_ERR_INVALID_EXT_PLUG = 0x04,
+ HDMI_CEC_NOT_PROG_ERR_INVALID_EXT_PHYS_ADDR = 0x05,
+ HDMI_CEC_NOT_PROG_ERR_CA_UNSUPP = 0x06,
+ HDMI_CEC_NOT_PROG_ERR_INSUF_CA_ENTITLEMENTS = 0x07,
+ HDMI_CEC_NOT_PROG_ERR_RESOLUTION_UNSUPP = 0x08,
+ HDMI_CEC_NOT_PROG_ERR_PARENTAL_LOCK = 0x09,
+ HDMI_CEC_NOT_PROG_ERR_CLOCK_FAILURE = 0x0A,
+ HDMI_CEC_NOT_PROG_ERR_DUPLICATE = 0x0E,
+};
+
+struct HdmiCecTimerProgremmedInfo {
+ uint8_t indicator;
+ uint8_t info; /* Progremmed Info/Not Progremmed Error Info */
+ uint8_t durationHour;
+ uint8_t durationMinute;
+};
+
+struct HdmiCecTimerStatusData {
+ uint8_t timerOverlap;
+ uint8_t mediaInfo;
+ struct HdmiCecTimerProgremmedInfo progInfo;
+};
+
+/*
+ * System Information Feature/Vendor Specific Commands Feature.
+ * Used to indicate the version number of the CEC Specification which was used to design the device,
+ * in response to a .
+ * Param: [CEC Version], 1 byte.
+ */
+#define HDMI_CEC_OPCODE_CEC_VERSION 0x9E
+
+#define HDMI_CEC_CEC_VERSION_MSG_PARAM_LEN 1
+
+/* CEC Version */
+#define HDMI_CEC_VERSION_1_3A 4
+#define HDMI_CEC_VERSION_1_4 5
+#define HDMI_CEC_VERSION_2_0 6
+
+/*
+ * System Information Feature/Vendor Specific Commands Feature.
+ * Used by a device to enquire which version number of the CEC Specification
+ * was used to design the Follwer device.
+ * Param: None.
+ */
+#define HDMI_CEC_OPCODE_GET_CEC_VERSION 0x9F
+
+/*
+ * System Information Feature.
+ * A request to a device return its Physical Address.
+ * Param: None.
+ */
+#define HDMI_CEC_OPCODE_GIVE_PHYSICAL_ADDRESS 0x83
+
+/*
+ * System Information Feature.
+ * Sent by a device capable of character generation(for OSD and Menus) to a TV in order to
+ * discover the currently selected Menu language on the TV.
+ * Param: None.
+ */
+#define HDMI_CEC_OPCODE_GET_MENU_LANGUAGE 0x91
+
+/*
+ * System Information Feature.
+ * Used to inform all other devices of the mapping between
+ * physical and Logical address of the Initiator.
+ * Param: [Physical Address], 2 bytes. [Device Type], 1 byte.
+ * Broadcast message.
+ */
+#define HDMI_CEC_OPCODE_REPORT_PHYSICAL_ADDRESS 0x84
+
+#define HDMI_CEC_REPORT_PHYSICAL_ADDRESS_MSG_PARAM_LEN 3
+
+/*
+ * Device Type/Primary Device Type.
+ * The HDMI 1.4b operand [Device Type] has been extended as [Primary Device Type].
+ */
+enum HdmiCecDeviceType {
+ HDMI_CEC_DEVICE_TYPE_TV = 0,
+ HDMI_CEC_DEVICE_TYPE_RECORDING_DEVICE = 1,
+ HDMI_CEC_DEVICE_TYPE_RESERVED = 2,
+ HDMI_CEC_DEVICE_TYPE_TUNER = 3,
+ HDMI_CEC_DEVICE_TYPE_PLAYBACK_DEVICE = 4,
+ HDMI_CEC_DEVICE_TYPE_AUDIO_SYSTEM = 5,
+ HDMI_CEC_DEVICE_TYPE_PURE_CEC_SWITCH = 6,
+ HDMI_CEC_DEVICE_TYPE_PROCESSOR = 7,
+};
+
+/*
+ * System Information Feature.
+ * Used by a TV to indicate its currently selected menu language.
+ * Param: [Language], 3 bytes.
+ * Broadcast message.
+ */
+#define HDMI_CEC_OPCODE_SET_MENU_LANGUAGE 0x32
+
+#define HDMI_CEC_SET_MENU_LANGUAGE_MSG_PARAM_LEN 3
+
+/*
+ * System Information Feature.
+ * Used by a device to announce its version, features and device type.
+ * Param: [CEC Version], 1 byte. [All Device Types], 1 byte. [RC Profile], 1..N bytes. [Device Features], 1..N bytes.
+ */
+#define HDMI_CEC_OPCODE_REPORT_FEATURES 0xA6
+
+#define HDMI_CEC_REPORT_FEATURES_MSG_PARAM_MIN_LEN 4
+
+/* All Device Types */
+enum HdmiCecAllDevType {
+ HDMI_CEC_ALL_DEV_TYPE_CEC_SWITCH = 0x04,
+ HDMI_CEC_ALL_DEV_TYPE_AUDIO_SYSTEM = 0x08,
+ HDMI_CEC_ALL_DEV_TYPE_PLAYBACK = 0x10,
+ HDMI_CEC_ALL_DEV_TYPE_TUNER = 0x20,
+ HDMI_CEC_ALL_DEV_TYPE_RECORD = 0x40,
+ HDMI_CEC_ALL_DEV_TYPE_TV = 0x80,
+};
+
+/*
+ * RC Profile, 1..N bytes.
+ * [RC Profile 1]; or [RC Profile 1]..[RC Profile N](where N >= 2)
+ * RC Profile 1, 1 byte.
+ * [RC Profile Externsion], bit 7
+ * if bit6 is 0, [RC Profile TV] in bit5-0; if bit6 is 1, [RC Profile Source] in bit5-0.
+ */
+#define HDMI_CEC_RC_PROFILE_MAX_NUM 6
+#define HDMI_CEC_RC_PROFILE_EXTERNSION_MARK (1 << 7)
+#define HDMI_CEC_RC_PROFILE_TV_OR_SOURCE_MARK (1 << 6)
+
+/* RC Profile Source, 6 bits. */
+#define HDMI_CEC_RC_PROFILE_SOURCE_ROOT_MENU (1 << 4)
+#define HDMI_CEC_RC_PROFILE_SOURCE_SETUP_MENU (1 << 3)
+#define HDMI_CEC_RC_PROFILE_SOURCE_CONTENTS_MENU (1 << 2)
+#define HDMI_CEC_RC_PROFILE_SOURCE_MEDIA_TOP_MENU (1 << 1)
+#define HDMI_CEC_RC_PROFILE_SOURCE_MEDIA_CONTEXT_SENSITIVE_MENU (1 << 0)
+
+/*
+ * RC Profile TV, 6 bits.
+ * [RC Profile ID], Bit3-0.
+ */
+enum HdmiCecRcProfileId {
+ HDMI_CEC_RC_PROFILE_NONE = 0x00,
+ HDMI_CEC_RC_PROFILE_1 = 0x02,
+ HDMI_CEC_RC_PROFILE_2 = 0x06,
+ HDMI_CEC_RC_PROFILE_3 = 0x0A,
+ HDMI_CEC_RC_PROFILE_4 = 0x0E,
+ HDMI_CEC_RC_PROFILE_BUTT,
+};
+
+/*
+ * Device Features, 1..N bytes.
+ * [Device Features 1], 1 byte.
+ */
+#define HDMI_CEC_DEVICE_FEATURES_MAX_NUM 6
+#define HDMI_CEC_DEVICE_FEATURES_EXTERNSION_MARK (1 << 7) /* 0 the last; 1 continues. */
+#define HDMI_CEC_DEVICE_FEATURES_TV_SUPP_RECORD_TV_SCREEN (1 << 6)
+#define HDMI_CEC_DEVICE_FEATURES_TV_SUPP_SET_OSD_STRING (1 << 5)
+#define HDMI_CEC_DEVICE_FEATURES_DECK_SUPP_CONTROL (1 << 4)
+#define HDMI_CEC_DEVICE_FEATURES_SRC_SUPP_SET_AUDIO_RATE (1 << 3)
+#define HDMI_CEC_DEVICE_FEATURES_SINK_SUPP_ARC_TX (1 << 2)
+#define HDMI_CEC_DEVICE_FEATURES_SRC_SUPP_ARC_RX (1 << 1)
+
+/*
+ * System Information Feature.
+ * Used by a device to request another device's features.
+ * Param: None.
+ */
+#define HDMI_CEC_OPCODE_GIVE_FEATURES 0xA5
+
+/*
+ * Deck Control Feature.
+ * Used to control a device's media functions.
+ * Param: [Deck Control Mode], 1 byte.
+ */
+#define HDMI_CEC_OPCODE_DECK_CONTROL 0x42
+
+#define HDMI_CEC_DECK_CONTROL_MSG_PARAM_LEN 1
+
+/* Deck Control Mode */
+enum HdmiCecDeckControlMode {
+ HDMI_CEC_DECK_CONTROL_MODE_SKIP_FWD = 1,
+ HDMI_CEC_DECK_CONTROL_MODE_SKIP_REV = 2,
+ HDMI_CEC_DECK_CONTROL_MODE_STOP = 3,
+ HDMI_CEC_DECK_CONTROL_MODE_EJECT = 4,
+};
+
+/*
+ * Deck Control Feature.
+ * Used to provide a deck's status to the indicate of the message.
+ * Param: [Deck Info], 1 byte.
+ */
+#define HDMI_CEC_OPCODE_DECK_STATUS 0x1B
+
+#define HDMI_CEC_DECK_STATUS_MSG_PARAM_LEN 1
+
+/* Deck Info. Indicate the current status of a tape or disk deck. */
+enum HdmiCecDeckInfo {
+ HDMI_CEC_DECK_PLAY = 0x11,
+ HDMI_CEC_DECK_RECORD = 0x12,
+ HDMI_CEC_DECK_PLAY_REVERSE = 0x13,
+ HDMI_CEC_DECK_STILL = 0x14,
+ HDMI_CEC_DECK_SLOW = 0x15,
+ HDMI_CEC_DECK_SLOW_REVERSE = 0x16,
+ HDMI_CEC_DECK_FAST_FORWARD = 0x17,
+ HDMI_CEC_DECK_FAST_REVERSE = 0x18,
+ HDMI_CEC_DECK_NO_MEDIA = 0x19,
+ HDMI_CEC_DECK_STOP = 0x1A,
+ HDMI_CEC_DECK_SKIP_FORWARD = 0x1B,
+ HDMI_CEC_DECK_SKIP_REVERSE = 0x1C,
+ HDMI_CEC_DECK_INDEX_SEARCH_FORWARD = 0x1D,
+ HDMI_CEC_DECK_INDEX_SEARCH_REVERSE = 0x1E,
+ HDMI_CEC_DECK_OTHER_STATUS = 0x1F,
+};
+
+/*
+ * Deck Control Feature.
+ * Used to request the status of a device,
+ * regardless of whether or not it is the current active source.
+ * Param: [Status Request], 1 byte.
+ */
+#define HDMI_CEC_OPCODE_GIVE_DECK_STATUS 0x1A
+
+#define HDMI_CEC_GIVE_DECK_STATUS_MSG_PARAM_LEN 1
+
+/* Status Request */
+enum HdmiCecStatusRequest {
+ HDMI_CEC_STATUS_REQUEST_ON = 1,
+ HDMI_CEC_STATUS_REQUEST_OFF = 2,
+ HDMI_CEC_STATUS_REQUEST_ONCE = 3,
+};
+
+/*
+ * Deck Control Feature.
+ * Used to control the playback bahavior of a source device.
+ * Param: [Play Mode], 1 byte.
+ */
+#define HDMI_CEC_OPCODE_PLAY 0x41
+
+#define HDMI_CEC_PLAY_MSG_PARAM_LEN 1
+
+/* Play Mode */
+enum HdmiCecPlayMode {
+ HDMI_CEC_PLAY_MODE_PLAY_FAST_FWD_MIN = 0x05,
+ HDMI_CEC_PLAY_MODE_PLAY_FAST_FWD_MED = 0x06,
+ HDMI_CEC_PLAY_MODE_PLAY_FAST_FWD_MAX = 0x07,
+ HDMI_CEC_PLAY_MODE_PLAY_FAST_REV_MIN = 0x09,
+ HDMI_CEC_PLAY_MODE_PLAY_FAST_REV_MED = 0x0A,
+ HDMI_CEC_PLAY_MODE_PLAY_FAST_REV_MAX = 0x0B,
+ HDMI_CEC_PLAY_MODE_PLAY_SLOW_FWD_MIN = 0x15,
+ HDMI_CEC_PLAY_MODE_PLAY_SLOW_FWD_MED = 0x16,
+ HDMI_CEC_PLAY_MODE_PLAY_SLOW_FWD_MAX = 0x17,
+ HDMI_CEC_PLAY_MODE_PLAY_SLOW_REV_MIN = 0x19,
+ HDMI_CEC_PLAY_MODE_PLAY_SLOW_REV_MED = 0x1A,
+ HDMI_CEC_PLAY_MODE_PLAY_SLOW_REV_MAX = 0x1B,
+ HDMI_CEC_PLAY_MODE_PLAY_REV = 0x20,
+ HDMI_CEC_PLAY_MODE_PLAY_FWD = 0x24,
+ HDMI_CEC_PLAY_MODE_PLAY_STILL = 0x25,
+};
+
+/*
+ * Tuner Control Feature.
+ * Used to request the status of a tuner device.
+ * Param: [Status Request], 1 byte.
+ */
+#define HDMI_CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS 0x08
+
+#define HDMI_CEC_GIVE_TUNER_DEVICE_STATU_MSG_PARAM_LEN 1
+
+/*
+ * Tuner Control Feature.
+ *