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/vnode/src/hdf_vnode_adapter.c b/core/adapter/vnode/src/hdf_vnode_adapter.c
index dab5a350ee3c6535b231d291604c205f5a650603..340054fb397e49eecaf521783d497e00e8b67b5a 100644
--- a/core/adapter/vnode/src/hdf_vnode_adapter.c
+++ b/core/adapter/vnode/src/hdf_vnode_adapter.c
@@ -545,8 +545,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);
diff --git a/core/common/src/devmgr_service_start.c b/core/common/src/devmgr_service_start.c
index a7d27eb9c3d596b8d1e6db7e9fa7b0bc94fd805d..a1ceba2eee5530107605b2490cad53e48d7d5c58 100644
--- a/core/common/src/devmgr_service_start.c
+++ b/core/common/src/devmgr_service_start.c
@@ -53,6 +53,10 @@ int DeviceManagerDispatch(struct HdfObject *stub, int code, struct HdfSBuf *data
int32_t deviceClass = 0;
const char *svcName = NULL;
struct DevmgrService *devMgrSvc = (struct DevmgrService *)stub;
+ 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 +69,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:
@@ -107,13 +107,14 @@ int DeviceManagerIsQuickLoad(void)
int DeviceManagerStart(void)
{
+ struct HdfIoService *ioService = NULL;
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,
@@ -126,11 +127,12 @@ int DeviceManagerStart(void)
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..b6af3fe7c35a15b3492f2b2690572ffebe62c8c7 100644
--- a/core/common/src/hdf_attribute.c
+++ b/core/common/src/hdf_attribute.c
@@ -66,11 +66,13 @@ const struct DeviceResourceNode *HdfGetRootNode(void)
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;
}
@@ -138,11 +140,13 @@ bool HdfAttributeManagerGetHostList(struct HdfSList *hostList)
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;
}
@@ -244,14 +248,16 @@ struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *h
{
uint16_t deviceIdx = 0;
const struct DeviceResourceNode *hostNode = GetHostNode(hostName);
+ struct HdfSList *deviceList = NULL;
+ const struct DeviceResourceNode *device = NULL;
if (hostNode == NULL) {
return NULL;
}
- struct HdfSList *deviceList = (struct HdfSList *)OsalMemCalloc(sizeof(struct HdfSList));
+ deviceList = (struct HdfSList *)OsalMemCalloc(sizeof(struct HdfSList));
if (deviceList == NULL) {
return NULL;
}
- const struct DeviceResourceNode *device = hostNode->child;
+ device = hostNode->child;
while (device != NULL) {
const struct DeviceResourceNode *deviceNode = device->child;
while (deviceNode != NULL) {
@@ -276,11 +282,10 @@ struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *h
deviceNode = deviceNode->sibling;
continue;
}
- deviceNodeInfo->deviceId = deviceIdx;
+ deviceNodeInfo->deviceId = deviceIdx++;
deviceNode = deviceNode->sibling;
}
device = device->sibling;
- deviceIdx++;
}
if (HdfSListCount(deviceList) == 0) {
OsalMemFree(deviceList);
@@ -295,11 +300,13 @@ bool HdfDeviceListAdd(const char *moduleName, const char *serviceName, const voi
struct HdfDeviceInfo *deviceInfo = NULL;
struct DevHostServiceClnt *hostClnt = NULL;
struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
+ struct HdfDeviceInfo *deviceNodeInfo = NULL;
+ char *svcName = NULL;
if (devMgrSvc == NULL || moduleName == NULL || serviceName == NULL) {
return false;
}
- struct HdfDeviceInfo *deviceNodeInfo = HdfDeviceInfoNewInstance();
+ deviceNodeInfo = HdfDeviceInfoNewInstance();
if (deviceNodeInfo == NULL) {
return false;
}
@@ -320,7 +327,7 @@ bool HdfDeviceListAdd(const char *moduleName, const char *serviceName, const voi
deviceNodeInfo->permission = deviceInfo->permission;
deviceNodeInfo->deviceMatchAttr = deviceInfo->deviceMatchAttr;
deviceNodeInfo->moduleName = deviceInfo->moduleName;
- char *svcName = OsalMemCalloc(strlen(serviceName) + 1);
+ svcName = OsalMemCalloc(strlen(serviceName) + 1);
if (svcName == NULL) {
break;
}
diff --git a/core/common/src/hdf_device_node_ext.c b/core/common/src/hdf_device_node_ext.c
index a8143a44132b635657c5d68af71a6a559c725c79..c0eab0d70f701da1a424a29224a7e3189f191db2 100644
--- a/core/common/src/hdf_device_node_ext.c
+++ b/core/common/src/hdf_device_node_ext.c
@@ -22,12 +22,12 @@ static int DeviceNodeExtDispatch(struct HdfObject *stub, int code, struct HdfSBu
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;
@@ -59,10 +59,11 @@ static int DeviceNodeExtPublishService(struct HdfDeviceNode *inst, const char *s
const struct HdfDeviceInfo *deviceInfo = NULL;
struct HdfDeviceObject *deviceObject = NULL;
struct DeviceNodeExt *devNodeExt = (struct DeviceNodeExt *)inst;
+ int ret;
if (devNodeExt == NULL) {
return HDF_FAILURE;
}
- int ret = HdfDeviceNodePublishPublicService(inst, serviceName);
+ ret = HdfDeviceNodePublishPublicService(inst, serviceName);
if (ret != HDF_SUCCESS) {
HDF_LOGE("failed to publish device service, ret is %d", ret);
return HDF_FAILURE;
@@ -77,10 +78,10 @@ static int DeviceNodeExtPublishService(struct HdfDeviceNode *inst, const char *s
if (deviceInfo->policy == SERVICE_POLICY_CAPACITY) {
devNodeExt->ioService = HdfIoServicePublish(serviceName, deviceInfo->permission);
if (devNodeExt->ioService != NULL) {
- devNodeExt->ioService->target = (struct HdfObject*)(&inst->deviceObject);
static struct HdfIoDispatcher dispatcher = {
.Dispatch = DeviceNodeExtDispatch
};
+ devNodeExt->ioService->target = (struct HdfObject*)(&inst->deviceObject);
devNodeExt->ioService->dispatcher = &dispatcher;
} else {
HDF_LOGE("Device remote service bind failed");
diff --git a/core/common/src/load_driver_entry.c b/core/common/src/load_driver_entry.c
index 9a42ecbdc2b7c98342481ec1d0f2758be1c5f73d..165a7840fa00fff5c551e2c3dbf934cddb8797ec 100644
--- a/core/common/src/load_driver_entry.c
+++ b/core/common/src/load_driver_entry.c
@@ -13,18 +13,20 @@
static struct HdfDriverEntry *HdfDriverEntryConstruct(int32_t *driverCount)
{
int i;
+ struct HdfDriverEntry *driverEntry = NULL;
+ size_t *addrBegin = NULL;
*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));
+ 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());
+ addrBegin = (size_t *)(HDF_DRIVER_BEGIN());
for (i = 0; i < *driverCount; i++) {
driverEntry[i] = *(struct HdfDriverEntry *)(*addrBegin);
addrBegin++;
@@ -35,12 +37,12 @@ static struct HdfDriverEntry *HdfDriverEntryConstruct(int32_t *driverCount)
struct HdfDriverEntry *HdfDriverLoaderGetDriverEntry(const struct HdfDeviceInfo *deviceInfo)
{
int i;
+ static struct HdfDriverEntry *driverEntry = NULL;
+ static int32_t driverCount = 0;
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) {
diff --git a/core/host/src/devhost_service.c b/core/host/src/devhost_service.c
index bd0c84135221790a15807a06461559078de79168..984f6e6c2b64bc9802c139d70c41bcb56f998d8d 100644
--- a/core/host/src/devhost_service.c
+++ b/core/host/src/devhost_service.c
@@ -114,6 +114,7 @@ int DevHostServiceDelDevice(struct IDevHostService *inst, const struct HdfDevice
struct HdfDevice *device = NULL;
struct DevHostService *hostService = (struct DevHostService *)inst;
struct IDriverLoader *driverLoader = HdfDriverLoaderGetInstance();
+ struct HdfDeviceNode *devNode = NULL;
if ((deviceInfo == NULL) || (driverLoader == NULL) || (driverLoader->UnLoadNode == NULL)) {
HDF_LOGE("failed to del device, input param is null");
@@ -127,7 +128,7 @@ int DevHostServiceDelDevice(struct IDevHostService *inst, const struct HdfDevice
}
driverLoader->UnLoadNode(driverLoader, deviceInfo);
- struct HdfDeviceNode *devNode = DevHostServiceSeparateDeviceNode(&device->devNodes, deviceInfo);
+ devNode = DevHostServiceSeparateDeviceNode(&device->devNodes, deviceInfo);
if (device->super.Detach != NULL) {
device->super.Detach(&device->super, devNode);
} else {
@@ -223,12 +224,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/devsvc_manager_clnt.c b/core/host/src/devsvc_manager_clnt.c
index 479839b941d54aa39ac819bcdb3383c98ad39033..3cce4a59c66d4f008b12e92fb629adeb7a1c890c 100644
--- a/core/host/src/devsvc_manager_clnt.c
+++ b/core/host/src/devsvc_manager_clnt.c
@@ -19,12 +19,13 @@
int DevSvcManagerClntAddService(const char *svcName, struct HdfDeviceObject *service)
{
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
+ struct IDevSvcManager *serviceManager = NULL;
if (devSvcMgrClnt == NULL) {
HDF_LOGE("failed to add service, client is null");
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;
@@ -35,12 +36,13 @@ int DevSvcManagerClntAddService(const char *svcName, struct HdfDeviceObject *ser
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 +53,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;
@@ -91,12 +94,13 @@ void HdfUnregisterDevice(const char *moduleName, const char *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 +111,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,12 +128,13 @@ 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;
diff --git a/core/host/src/hdf_device.c b/core/host/src/hdf_device.c
index d61036007dacfdc41726ca361f5187fb5182b04a..451faf9923d029edcbb12753d76a4824074ebfc7 100644
--- a/core/host/src/hdf_device.c
+++ b/core/host/src/hdf_device.c
@@ -39,7 +39,8 @@ void HdfDeviceConstruct(struct HdfDevice *device)
void HdfDeviceDestruct(struct HdfDevice *device)
{
struct HdfDeviceNode *devNode = NULL;
- DLIST_FOR_EACH_ENTRY(devNode, &device->devNodes, struct HdfDeviceNode, entry) {
+ struct HdfDeviceNode *devNodeTmp = NULL;
+ DLIST_FOR_EACH_ENTRY_SAFE(devNode, devNodeTmp, &device->devNodes, struct HdfDeviceNode, entry) {
HdfDeviceNodeDelete(devNode);
}
DListHeadInit(&device->devNodes);
diff --git a/core/host/src/hdf_device_node.c b/core/host/src/hdf_device_node.c
index 06f46b43651fa723daeaa9ecb2733d8797743249..f08c2539410b908cd71d08ad90d7fc24b9133706 100644
--- a/core/host/src/hdf_device_node.c
+++ b/core/host/src/hdf_device_node.c
@@ -25,11 +25,12 @@ static int HdfDeviceNodePublishLocalService(
struct HdfDeviceNode *devNode, const struct HdfDeviceInfo *deviceInfo)
{
uint32_t matchId;
+ struct DevHostService *hostService = NULL;
if ((devNode == NULL) || (deviceInfo == NULL)) {
HDF_LOGE("failed to publish local service, device is null");
return HDF_FAILURE;
}
- struct DevHostService *hostService = devNode->hostService;
+ hostService = devNode->hostService;
if (hostService == NULL) {
HDF_LOGE("failed to publish local service, host service is null");
return HDF_FAILURE;
@@ -42,15 +43,16 @@ static int HdfDeviceNodePublishLocalService(
static int HdfDeviceNodePublishService(
struct HdfDeviceNode *devNode, const struct HdfDeviceInfo *deviceInfo, struct IHdfDevice *device)
{
- (void)device;
int status = HDF_SUCCESS;
+ struct IDeviceNode *nodeIf = NULL;
+ (void)device;
if ((deviceInfo->policy == SERVICE_POLICY_NONE) ||
((deviceInfo->svcName != NULL) && (strlen(deviceInfo->svcName) == 0))) {
HDF_LOGI("policy is %d", SERVICE_POLICY_NONE);
return status;
}
- struct IDeviceNode *nodeIf = &devNode->super;
+ nodeIf = &devNode->super;
if ((deviceInfo->policy == SERVICE_POLICY_PUBLIC) ||
(deviceInfo->policy == SERVICE_POLICY_CAPACITY)) {
if (nodeIf->PublishService != NULL) {
@@ -66,15 +68,17 @@ static int HdfDeviceNodePublishService(
int HdfDeviceLaunchNode(struct HdfDeviceNode *devNode, struct IHdfDevice *devInst)
{
struct HdfDevice *device = (struct HdfDevice *)devInst;
+ struct HdfDriverEntry *driverEntry = NULL;
+ const struct HdfDeviceInfo *deviceInfo = NULL;
+ struct IHdfDeviceToken *deviceToken = NULL;
+ int ret;
if (device == NULL || devNode == NULL) {
HDF_LOGE("failed to launch service, device or service is null");
return HDF_ERR_INVALID_PARAM;
}
- struct HdfDriverEntry *driverEntry = devNode->driverEntry;
- const struct HdfDeviceInfo *deviceInfo = devNode->deviceInfo;
- struct IHdfDeviceToken *deviceToken = NULL;
-
+ driverEntry = devNode->driverEntry;
+ deviceInfo = devNode->deviceInfo;
if (deviceInfo == NULL) {
HDF_LOGE("failed to launch service, deviceInfo is null");
return HDF_ERR_INVALID_PARAM;
@@ -84,7 +88,7 @@ int HdfDeviceLaunchNode(struct HdfDeviceNode *devNode, struct IHdfDevice *devIns
HDF_LOGE("failed to launch service, deviceEntry invalid");
return HDF_ERR_INVALID_PARAM;
}
- int ret = driverEntry->Init(&devNode->deviceObject);
+ ret = driverEntry->Init(&devNode->deviceObject);
if (ret != HDF_SUCCESS) {
return HDF_DEV_ERR_DEV_INIT_FAIL;
}
diff --git a/core/host/src/hdf_device_object.c b/core/host/src/hdf_device_object.c
index 832b11d8e9fb2e308f928e40d1cca6df3a5d9baa..6ab710031a9dd1093ad659f23f67a2f6934f483b 100644
--- a/core/host/src/hdf_device_object.c
+++ b/core/host/src/hdf_device_object.c
@@ -22,11 +22,12 @@ int32_t HdfDeviceSubscribeService(
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");
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) {
@@ -44,13 +45,15 @@ int32_t HdfDeviceSubscribeService(
const char *HdfDeviceGetServiceName(const struct HdfDeviceObject *deviceObject)
{
+ struct HdfDeviceNode *devNode = NULL;
+ const struct HdfDeviceInfo *deviceInfo = 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;
+ deviceInfo = devNode->deviceInfo;
if (deviceInfo == NULL) {
HDF_LOGE("failed to get service name, deviceInfo is null");
return NULL;
@@ -60,33 +63,37 @@ const char *HdfDeviceGetServiceName(const struct HdfDeviceObject *deviceObject)
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,13 +101,15 @@ 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);
}
@@ -108,13 +117,15 @@ void HdfPmReleaseDevice(struct HdfDeviceObject *deviceObject)
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;
}
diff --git a/core/host/src/hdf_observer_record.c b/core/host/src/hdf_observer_record.c
index 645d7d54eea0bbd103f29464e079e7b2b15cd13a..574afecddf69fe60b94bd17cacb070750b7c7077 100644
--- a/core/host/src/hdf_observer_record.c
+++ b/core/host/src/hdf_observer_record.c
@@ -47,10 +47,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;
}
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/src/devmgr_service.c b/core/manager/src/devmgr_service.c
index 36886a9319183985a40a2f640c55153e880872bb..e11da3ed778c12901b77ff6965524efdcf17ddf2 100644
--- a/core/manager/src/devmgr_service.c
+++ b/core/manager/src/devmgr_service.c
@@ -139,16 +139,18 @@ static void DevmgrServiceUpdateStatus(struct DevHostServiceClnt *hostClnt, uint1
static int DevmgrServiceAttachDevice(
struct IDevmgrService *inst, const struct HdfDeviceInfo *deviceInfo, struct IHdfDeviceToken *token)
{
+ struct DevHostServiceClnt *hostClnt = NULL;
+ struct DeviceTokenClnt *tokenClnt = NULL;
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, deviceInfo->hostId);
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;
@@ -271,11 +273,12 @@ 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->AttachDeviceHost = DevmgrServiceAttachDeviceHost;
@@ -313,11 +316,11 @@ 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);
diff --git a/core/manager/src/devsvc_manager.c b/core/manager/src/devsvc_manager.c
index 1c7b765acab51ca905a08b1cd7bec17fba2c1fb8..d3f377bb0e8b32067375aa5a4338eb8e9af124fe 100644
--- a/core/manager/src/devsvc_manager.c
+++ b/core/manager/src/devsvc_manager.c
@@ -43,12 +43,13 @@ static struct DevSvcRecord *DevSvcManagerSearchService(struct IDevSvcManager *in
int DevSvcManagerAddService(struct IDevSvcManager *inst, const char *svcName, struct HdfDeviceObject *service)
{
struct DevSvcManager *devSvcManager = (struct DevSvcManager *)inst;
+ struct DevSvcRecord *record = NULL;
if ((devSvcManager == NULL) || (service == NULL) || (svcName == 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;
@@ -66,11 +67,12 @@ int DevSvcManagerSubscribeService(struct IDevSvcManager *inst, const char *svcNa
{
int ret = HDF_FAILURE;
struct DevSvcManager *devSvcMgr = (struct DevSvcManager *)inst;
+ struct HdfObject *deviceService = NULL;
if (svcName == NULL || devSvcMgr == NULL) {
return ret;
}
- struct HdfObject *deviceService = DevSvcManagerGetService(inst, svcName);
+ deviceService = DevSvcManagerGetService(inst, svcName);
if (deviceService != NULL) {
if (callBack.OnServiceConnected != NULL) {
callBack.OnServiceConnected(callBack.deviceObject, deviceService);
@@ -85,10 +87,11 @@ void DevSvcManagerRemoveService(struct IDevSvcManager *inst, const char *svcName
{
struct DevSvcManager *devSvcManager = (struct DevSvcManager *)inst;
uint32_t serviceKey = HdfStringMakeHashKey(svcName, 0);
+ struct DevSvcRecord *serviceRecord = NULL;
if (svcName == NULL || devSvcManager == NULL) {
return;
}
- struct DevSvcRecord *serviceRecord = DevSvcManagerSearchService(inst, serviceKey);
+ serviceRecord = DevSvcManagerSearchService(inst, serviceKey);
if (serviceRecord != NULL) {
OsalMutexLock(&devSvcManager->mutex);
HdfSListRemove(&devSvcManager->services, &serviceRecord->entry);
@@ -100,11 +103,12 @@ void DevSvcManagerRemoveService(struct IDevSvcManager *inst, const char *svcName
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;
}
@@ -122,11 +126,12 @@ struct HdfObject *DevSvcManagerGetService(struct IDevSvcManager *inst, const cha
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->SubscribeService = DevSvcManagerSubscribeService;
devSvcMgrIf->UnsubscribeService = NULL;
diff --git a/core/manager/src/hdf_driver_installer.c b/core/manager/src/hdf_driver_installer.c
index 4071b2eec717d74b263b07bf5c4088b1544ad2e1..0ed60f47f292f9a6ab4f5609a322638f44ccbac9 100644
--- a/core/manager/src/hdf_driver_installer.c
+++ b/core/manager/src/hdf_driver_installer.c
@@ -17,11 +17,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/shared/include/hdf_usb_pnp_manage.h b/core/shared/include/hdf_usb_pnp_manage.h
old mode 100644
new mode 100755
index e22f7cb1d1978c4f64918920f5d038875df298d2..62ba214aad04bd5944dccd3065478ae5a0c02d19
--- a/core/shared/include/hdf_usb_pnp_manage.h
+++ b/core/shared/include/hdf_usb_pnp_manage.h
@@ -78,7 +78,7 @@ struct UsbPnpNotifyDeviceInfo {
};
struct UsbPnpNotifyMatchInfoTable {
- uint32_t usbDevAddr;
+ uintptr_t usbDevAddr;
int32_t devNum;
int32_t busNum;
diff --git a/include/audio/audio_accessory_if.h b/include/audio/audio_accessory_if.h
index a86532d2d329b26642f974bd2dbb2b48d2df6a4a..bd753a630a8c5155361e8212ee887a4797e2bea2 100755
--- a/include/audio/audio_accessory_if.h
+++ b/include/audio/audio_accessory_if.h
@@ -46,11 +46,9 @@ struct AccessoryData {
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;
+ struct AudioRegCfgData* regConfig;
};
#ifdef __cplusplus
diff --git a/include/audio/audio_codec_if.h b/include/audio/audio_codec_if.h
index d0636abb4f266dd0f358612267a51dcc5a85ac79..d18d99da6b550ca97fa95d91b7aded7ccfa02ce2 100755
--- a/include/audio/audio_codec_if.h
+++ b/include/audio/audio_codec_if.h
@@ -26,11 +26,6 @@ extern "C" {
#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;
-};
-
struct CodecDevice {
const char *devCodecName;
struct CodecData *devData;
@@ -44,16 +39,17 @@ 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;
+ int32_t (*Read)(unsigned long, uint32_t, uint32_t *);
+ int32_t (*Write)(unsigned long, uint32_t, uint32_t);
+ struct AudioKcontrol *controls;
int numControls;
- const struct AudioSapmComponent *sapmComponents;
+ struct AudioSapmComponent *sapmComponents;
int numSapmComponent;
const struct AudioSapmRoute *sapmRoutes;
int numSapmRoutes;
+ unsigned long virtualAddress; // IoRemap Address
+ struct AudioRegCfgData *regConfig;
+ struct AudioRegCfgGroupNode **regCfgGroup;
};
/* Codec host is defined in codec driver */
@@ -75,6 +71,7 @@ enum AudioRegParams {
INTERNALLY_CODEC_ENABLE,
RENDER_CHANNEL_MODE,
CAPTRUE_CHANNEL_MODE,
+ S_NORMAL_AP01_P_HIFI,
};
enum SapmRegParams {
diff --git a/include/audio/audio_dai_if.h b/include/audio/audio_dai_if.h
index f6e756edf903ea7a95e21f1da0d58a64f11f7561..603e938a5d9a2bd3b623bc60ab84990b73fb6e4e 100755
--- a/include/audio/audio_dai_if.h
+++ b/include/audio/audio_dai_if.h
@@ -15,6 +15,10 @@ extern "C" {
#endif
#endif /* __cplusplus */
+#include "audio_host.h"
+#include "audio_parse.h"
+#include "audio_control.h"
+
struct DaiDevice {
const char *devDaiName;
struct DaiData *devData;
@@ -24,16 +28,27 @@ struct DaiDevice {
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 (*HwParams)(const struct AudioCard *, const struct AudioPcmHwParams *);
int32_t (*Trigger)(const struct AudioCard *, int, const struct DaiDevice *);
};
struct DaiData {
const char *drvDaiName;
/* DAI driver callbacks */
- int32_t (*DaiInit)(const struct AudioCard *, const struct DaiDevice *);
+ int32_t (*DaiInit)(struct AudioCard *, const struct DaiDevice *);
+ int32_t (*Read)(unsigned long, uint32_t, uint32_t *);
+ int32_t (*Write)(unsigned long, uint32_t, uint32_t);
/* ops */
const struct AudioDaiOps *ops;
+ /* DAI DMA data */
+ struct PcmInfo pcmInfo;
+ struct AudioKcontrol *controls;
+ int numControls;
+ bool daiInitFlag;
+ uint32_t regDaiBase;
+ struct AudioRegCfgData *regConfig;
+ struct AudioRegCfgGroupNode **regCfgGroup;
+ struct OsalMutex mutex;
};
/* Dai host is defined in dai driver */
@@ -41,7 +56,6 @@ struct DaiHost {
struct IDeviceIoService service;
struct HdfDeviceObject *device;
void *priv;
- bool daiInitFlag;
};
#ifdef __cplusplus
diff --git a/include/audio/audio_dsp_if.h b/include/audio/audio_dsp_if.h
index ae72f096bf03e26d215e471fec74174db336a359..31d42a88e88890a3428a642d962fe0984959cbd8 100755
--- a/include/audio/audio_dsp_if.h
+++ b/include/audio/audio_dsp_if.h
@@ -39,8 +39,8 @@ 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 (*Read)(const struct DspDevice *, uint8_t *, uint32_t);
+ int32_t (*Write)(const 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 *);
diff --git a/include/audio/audio_platform_if.h b/include/audio/audio_platform_if.h
index 6ac044d686358c1458b922746264d98908d2753b..586a57cd9825d27b954e9a2bfd9eedd9ef9213e7 100755
--- a/include/audio/audio_platform_if.h
+++ b/include/audio/audio_platform_if.h
@@ -44,6 +44,12 @@ extern "C" {
#define GPIO_BASE_ADDR 0x120D0000
#define BASE_ADDR_REMAP_SIZE 0x10000
+enum PcmStatus {
+ PCM_STOP = 0,
+ PCM_PAUSE,
+ PCM_START,
+};
+
struct CircleBufInfo {
uint32_t cirBufSize;
uint32_t trafBufSize;
@@ -54,48 +60,47 @@ struct CircleBufInfo {
uint32_t *virtAddr;
uint32_t wbufOffSet;
uint32_t wptrOffSet;
- uint32_t runStatus;
+ uint32_t rbufOffSet;
+ uint32_t rptrOffSet;
+ enum PcmStatus runStatus;
uint32_t chnId;
uint32_t enable;
struct OsalMutex buffMutex;
- uint64_t framesPosition;
+ uint32_t framesPosition;
+ uint32_t pointer;
+ uint32_t periodsMax;
+ uint32_t periodsMin;
+ uint32_t cirBufMax;
+ uint32_t curTrafSize;
};
-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;
+struct PlatformData {
+ const char *drvPlatformName;
+ /* platform driver callbacks */
+ int32_t (*PlatformInit)(const struct AudioCard *, const struct PlatformDevice *);
+ /* platform stream ops */
+ struct AudioDmaOps *ops;
+ struct CircleBufInfo renderBufInfo;
+ struct CircleBufInfo captureBufInfo;
+ struct PcmInfo pcmInfo;
+ bool platformInitFlag;
+ struct AudioMmapData mmapData;
+ uint32_t mmapLoopCount;
+ void *dmaPrv;
};
-/* 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 *);
+/* dma related definitions */
+struct AudioDmaOps {
+ int32_t (*DmaBufAlloc)(struct PlatformData *, enum AudioStreamType);
+ int32_t (*DmaBufFree)(struct PlatformData *, enum AudioStreamType);
+ int32_t (*DmaRequestChannel)(struct PlatformData *);
+ int32_t (*DmaConfigChannel)(struct PlatformData *);
+ int32_t (*DmaPrep)(struct PlatformData *);
+ int32_t (*DmaSubmit)(struct PlatformData *);
+ int32_t (*DmaPending)(struct PlatformData *);
+ int32_t (*DmaPause)(struct PlatformData *);
+ int32_t (*DmaResume)(struct PlatformData *);
+ int32_t (*DmaPointer)(struct PlatformData *, uint32_t *);
};
struct PlatformDevice {
@@ -105,26 +110,11 @@ struct PlatformDevice {
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;
-};
-
/* Platform host is defined in platform driver */
struct PlatformHost {
struct IDeviceIoService service;
struct HdfDeviceObject *device;
void *priv;
- bool platformInitFlag;
- struct CircleBufInfo renderBufInfo;
- struct CircleBufInfo captureBufInfo;
- struct PcmInfo pcmInfo;
};
static inline struct PlatformHost *PlatformHostFromDevice(struct HdfDeviceObject *device)
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/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..8562842923d7b321b3ece761ae04b572eae2f2db
--- /dev/null
+++ b/include/platform/mipi_csi_if.h
@@ -0,0 +1,545 @@
+/*
+ * 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);
+
+#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..f3c3e646764b5a86420cb1b103dcb724bdfc5675 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, DevHandle *panelData);
+
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/include/platform/regulator_if.h b/include/platform/regulator_if.h
new file mode 100755
index 0000000000000000000000000000000000000000..cb27846903423f708945d5577220d88d538d6619
--- /dev/null
+++ b/include/platform/regulator_if.h
@@ -0,0 +1,207 @@
+/*
+ * 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 REGULATOR
+ * @{
+ *
+ * @Brief Provides regulator APIs, such as enabling and setting voltage / current.
+ *
+ * The REGULATOR module abstracts the regulator functions of different system platforms and provides stable APIs for drivers.
+ * You can use this module to create / release the regulator device handle, enable regulator, set voltage, current, disable, etc.
+ *
+ * @since 1.0
+ */
+
+/**
+ * @file regulator_if.h
+ *
+ * @brief Declares standard regulator APIs.
+ *
+ * @since 1.0
+ */
+
+#ifndef REGULATOR_IF_H
+#define REGULATOR_IF_H
+
+#include "hdf_platform.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif /* __cplusplus */
+
+/**
+ * @brief Enumerates regulator disableMode.
+ *
+ * To disable the mode using the regulator, call the {@ link RegulatorDisable} function.
+ *
+ * @since 1.0
+ */
+
+enum RegulatorDisableMode {
+ NORMAL_DISABLE,
+ DEFERRED_DISABLE,
+ FORCE_DISABLE,
+ MAX_DISABLE_MODE,
+};
+
+/**
+ * @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 RegulatorGet(const char *name);
+
+/**
+ * @brief Releases a regulator.
+ *
+ * If you no longer need the regulator, call this function to turn it off and release its device handle to prevent.
+ * Use memory resources unnecessarily.
+ *
+ * @param handle Represents a pointer to the regulator device handle.
+ *
+ * @since 1.0
+ */
+void RegulatorPut(DevHandle handle);
+
+/**
+ * @brief Enables a regulator.
+ *
+ * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorGet}.
+ * @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 RegulatorGet}.
+ * @param disableMode There are three disabled modes.
+ * @return 0 If the regulator disable successfully; Otherwise, a negative value is returned.
+ *
+ * @attention If the regulator device AlwaysOn is true, disabling may fail, depending on the specific mode.
+ *
+ * @since 1.0
+ */
+int32_t RegulatorDisable(DevHandle handle,int32_t disableMode);
+
+/**
+ * @brief Determine whether a regulator is enabled.
+ *
+ * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorGet}.
+ * @return 0 If the regulator isEnabled successfully; Otherwise, a negative value is returned.
+ *
+ * @since 1.0
+ */
+int32_t RegulatorIsEnabled(DevHandle handle);
+
+/**
+ * @brief Set the voltage value of a regulator.
+ *
+ * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorGet}.
+ * @return 0 If the regulator setVoltage successfully; Otherwise, a negative value is returned.
+ *
+ * @attention If the set voltage is not within the range, the setting fails.
+ *
+ * @since 1.0
+ */
+int32_t RegulatorSetVoltage(DevHandle handle, int32_t voltage);
+
+/**
+ * @brief Get a regulator voltage.
+ *
+ * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorGet}.
+ * @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, int32_t *voltage);
+
+/**
+ * @brief Set regulator voltage range
+ *
+ * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorGet}.
+ * @param vmin Minimum value of regulator voltage
+ * @param vmax Maximum regulator voltage
+ * @return 0 If the regulator set voltage range successfully; Otherwise, a negative value is returned.
+ *
+ * @attention If the setting range exceeds the limit, the setting fails
+ *
+ * @since 1.0
+ */
+int32_t RegulatorSetVoltageRange(DevHandle handle, int32_t vmin, int32_t vmax);
+
+/**
+ * @brief Set the current value of a regulator
+ *
+ * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorGet}.
+ * @return 0 If the regulator setCurrent successfully; Otherwise, a negative value is returned.
+ *
+ * @attention If the set current is not within the range, the setting fails
+ *
+ * @since 1.0
+ */
+int32_t RegulatorSetCurrent(DevHandle handle, int32_t current);
+
+/**
+ * @brief Get a regulator current
+ *
+ * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorGet}.
+ * @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, int32_t *current);
+
+/**
+ * @brief Set regulator current range
+ *
+ * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorGet}.
+ * @param cmin Minimum value of regulator current
+ * @param cmax Maximum regulator 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 RegulatorSetCurrentRange(DevHandle handle, int32_t cmin, int32_t cmax);
+
+/**
+ * @brief Get a regulator status
+ *
+ * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorGet}.
+ * @param status Status obtained
+ * @return 0 If the regulator get status successfully; Otherwise, a negative value is returned.
+ *
+ * @since 1.0
+ */
+int32_t RegulatorGetStatus(DevHandle handle, int32_t *status);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif /* __cplusplus */
+
+#endif /* REGULATOR_IF_H */
+/** @} */
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/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/model/audio/common/include/audio_accessory_base.h b/model/audio/common/include/audio_accessory_base.h
index ab0f94a06eb5bef64d733212169221c5fda576c7..76ccc892c5b1bffd1bc41e0522b2e70de49d2e39 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,30 @@ 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);
#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..712a2b73ead88c176105a1f92b7e2f7007159f16 100755
--- a/model/audio/common/include/audio_codec_base.h
+++ b/model/audio/common/include/audio_codec_base.h
@@ -19,12 +19,16 @@ 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 CodecDeviceReadReg(unsigned long virtualAddress, uint32_t reg, uint32_t *value);
+int32_t CodecDeviceWriteReg(unsigned long virtualAddress, 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, void *aiaoGetCtrl, void *aiaoSetCtrl);
+
+
+int32_t AccessoryGetConfigInfo(const struct HdfDeviceObject *device, struct AccessoryData *codecData);
#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..535cffdd066af8be38753ced21fe080d49939f8e
--- /dev/null
+++ b/model/audio/common/include/audio_dsp_base.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 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);
+int32_t DspLinkDeviceInit(struct AudioCard *card, const struct DaiDevice *device);
+int32_t DspDeviceInit(const struct DspDevice *device);
+int32_t DspDeviceReadReg(const struct DspDevice *device, uint8_t *buf, uint32_t len);
+int32_t DspDeviceWriteReg(const struct DspDevice *device, uint8_t *buf, uint32_t len);
+int32_t DspLinkStartup(const struct AudioCard *card, const struct DaiDevice *device);
+int32_t DspLinkHwParams(const struct AudioCard *card, const struct AudioPcmHwParams *param);
+int32_t DspDecodeAudioStream(const struct AudioCard *card, const uint8_t *buf, const struct DspDevice *device);
+int32_t DspEncodeAudioStream(const struct AudioCard *card, const uint8_t *buf, const struct DspDevice *device);
+int32_t DspEqualizerActive(const struct AudioCard *card, const uint8_t *buf, const struct DspDevice *device);
+
+#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..0a6215ccd359191ea042e555bb258bbecfb99e42 100755
--- a/model/audio/common/include/audio_platform_base.h
+++ b/model/audio/common/include/audio_platform_base.h
@@ -18,6 +18,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 +31,30 @@ 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);
+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..0c02a7366b9339a471224fbaf6873880fb9e4be3 100755
--- a/model/audio/common/src/audio_accessory_base.c
+++ b/model/audio/common/src/audio_accessory_base.c
@@ -7,29 +7,249 @@
*/
#include "audio_accessory_base.h"
-#include "audio_device_log.h"
+#include "audio_driver_log.h"
+#include "osal_time.h"
+#include "i2c_if.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];
+ 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) {
+ 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;
}
-int32_t RateToFrequency(uint32_t rate, uint16_t *freq)
+// 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 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 +288,114 @@ 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, index;
+ struct AudioControlConfig *ctlcfgItem = NULL;
+ uint32_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;
+ }
+ 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)&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;
}
diff --git a/model/audio/common/src/audio_codec_base.c b/model/audio/common/src/audio_codec_base.c
index 6d7d0a46d366e6513635171c35dd88b56748a1e2..40626ab282e7e601212d8492df9ae5c3796bc222 100755
--- a/model/audio/common/src/audio_codec_base.c
+++ b/model/audio/common/src/audio_codec_base.c
@@ -7,99 +7,26 @@
*/
#include "audio_codec_base.h"
+#include "audio_parse.h"
+#include "audio_driver_log.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 CodecDeviceReadReg(unsigned long virtualAddress, uint32_t reg, uint32_t *val)
{
- unsigned long acodecVir;
- struct VirtualAddress *virtualAdd = NULL;
- AUDIO_DRIVER_LOG_DEBUG("entry");
-
- 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;
- }
- virtualAdd = (struct VirtualAddress *)((volatile uintptr_t)codec->device->priv);
- if (virtualAdd == NULL) {
- AUDIO_DRIVER_LOG_ERR("virtualAdd is NULL.");
- return HDF_ERR_INVALID_OBJECT;
- }
- 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)
-{
- unsigned long acodecVir;
- struct VirtualAddress *virtualAdd = NULL;
- AUDIO_DRIVER_LOG_DEBUG("entry");
-
- if ((codec == NULL) || (codec->device == NULL)) {
- AUDIO_DRIVER_LOG_ERR("param 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;
- }
-
- acodecVir = virtualAdd->acodecVir;
- OSAL_WRITEL(value, (void *)(acodecVir + reg));
-
- AUDIO_DRIVER_LOG_DEBUG("success");
- return HDF_SUCCESS;
-}
-
-int32_t CodecAiaoDeviceReadReg(const struct CodecDevice *codec, uint32_t reg, uint32_t *val)
-{
- unsigned long aiaoVir;
- struct VirtualAddress *virtualAdd = NULL;
- AUDIO_DRIVER_LOG_DEBUG("entry");
-
- if ((codec == NULL) || (codec->device == NULL) || (val == 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 (val == NULL) {
+ AUDIO_DRIVER_LOG_ERR("param val is null.");
+ return HDF_FAILURE;
}
- aiaoVir = virtualAdd->aiaoVir;
- *val = OSAL_READL((void *)(aiaoVir + reg));
-
- AUDIO_DRIVER_LOG_DEBUG("success");
+ *val = OSAL_READL((void *)((uintptr_t)(virtualAddress + reg)));
return HDF_SUCCESS;
}
-int32_t CodecAiaoDeviceWriteReg(const struct CodecDevice *codec, uint32_t reg, uint32_t value)
+int32_t CodecDeviceWriteReg(unsigned long virtualAddress, uint32_t reg, uint32_t value)
{
- 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;
- }
-
- aiaoVir = virtualAdd->aiaoVir;
- OSAL_WRITEL(value, (void *)(aiaoVir + reg));
-
- AUDIO_DRIVER_LOG_DEBUG("success");
+ OSAL_WRITEL(value, (void *)((uintptr_t)(virtualAddress + reg)));
return HDF_SUCCESS;
}
@@ -164,3 +91,210 @@ int32_t CodecGetDaiName(const struct HdfDeviceObject *device, const char **drvDa
return HDF_SUCCESS;
}
+
+int32_t CodecGetConfigInfo(const struct HdfDeviceObject *device, struct CodecData *codecData)
+{
+ if (device == NULL || codecData == NULL) {
+ AUDIO_DRIVER_LOG_ERR("param is null!");
+ return HDF_FAILURE;
+ }
+
+ if (codecData->regConfig != NULL) {
+ ADM_LOG_ERR("g_codecData regConfig fail!");
+ return HDF_FAILURE;
+ }
+
+ codecData->regConfig = (struct AudioRegCfgData *)OsalMemCalloc(sizeof(*(codecData->regConfig)));
+ if (codecData->regConfig == NULL) {
+ ADM_LOG_ERR("malloc AudioRegCfgData fail!");
+ return HDF_FAILURE;
+ }
+
+ if (CodecGetRegConfig(device, codecData->regConfig) != HDF_SUCCESS) {
+ ADM_LOG_ERR("CodecGetRegConfig fail!");
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SapmCtrlToSapmComp(struct AudioSapmComponent *sapmComponents,
+ struct AudioSapmCtrlConfig *sapmCompItem, uint16_t index)
+{
+ if (sapmComponents == NULL || sapmCompItem == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input para is NULL.");
+ return HDF_FAILURE;
+ }
+
+ 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;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t CodecSetSapmConfigInfo(struct CodecData *codeData,struct AudioRegCfgGroupNode ** regCfgGroup)
+{
+ uint16_t index;
+
+ if (codeData == NULL || regCfgGroup == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input para is NULL.");
+ return HDF_FAILURE;
+ }
+
+ 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;
+ }
+
+ 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)&ctlSapmRegCfgItem[index];
+ audioSapmControls[index].Info = AudioInfoCtrlOps;
+ audioSapmControls[index].Get = AudioCodecSapmGetCtrlOps;
+ audioSapmControls[index].Set = AudioCodecSapmSetCtrlOps;
+ }
+
+ 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 CodecSetConfigInfo(struct CodecData *codeData, struct DaiData *daiData)
+{
+ uint16_t index;
+
+ if (codeData == NULL || daiData == NULL || codeData->regConfig == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input para is NULL.");
+ return HDF_FAILURE;
+ }
+
+ 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;
+ }
+
+ 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;
+ }
+
+ 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)&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, void *aiaoGetCtrl, void *aiaoSetCtrl)
+{
+ uint32_t index = 0;
+ 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;
+ struct AudioControlConfig *compItem = regCfgGroup[AUDIO_CTRL_CFG_GROUP]->ctrlCfgItem;
+ if (regCfgGroup == NULL || compItem == NULL) {
+ AUDIO_DRIVER_LOG_ERR("regCfgGroup or 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;
+}
+
+int32_t AccessoryGetConfigInfo(const struct HdfDeviceObject *device, struct AccessoryData *codecData)
+{
+ if (device == NULL) {
+ AUDIO_DRIVER_LOG_ERR("param is null!");
+ return HDF_FAILURE;
+ }
+
+ if (codecData->regConfig != NULL) {
+ ADM_LOG_ERR("g_codecData regConfig fail!");
+ return HDF_FAILURE;
+ }
+
+ codecData->regConfig = (struct AudioRegCfgData *)OsalMemCalloc(sizeof(*(codecData->regConfig)));
+ if (codecData->regConfig == NULL) {
+ ADM_LOG_ERR("malloc AudioRegCfgData fail!");
+ return HDF_FAILURE;
+ }
+
+ if (CodecGetRegConfig(device, codecData->regConfig) != HDF_SUCCESS) {
+ ADM_LOG_ERR("CodecGetRegConfig fail!");
+ return HDF_FAILURE;
+ }
+
+ 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..bdface250859e930613dcb82ec2eb72af9c7a588
--- /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_host.h"
+#include "audio_core.h"
+#include "audio_parse.h"
+#include "audio_driver_log.h"
+#include "audio_dai_if.h"
+#include "osal_io.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;
+ data->controls[index].name = g_audioControlsList[item[index].arrayIndex];
+ data->controls[index].Info = AudioInfoCtrlOps;
+ data->controls[index].privateValue = (unsigned long)&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..a1e77af480f8613143853c7969fca1d0ed92f51b
--- /dev/null
+++ b/model/audio/common/src/audio_dma_base.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 "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..fb472fa87f2fef65b3c1ebe8d9bbe93a6e534f51
--- a/model/audio/common/src/audio_dsp_base.c
+++ b/model/audio/common/src/audio_dsp_base.c
@@ -0,0 +1,383 @@
+/*
+ * 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_accessory_base.h"
+#include "audio_dsp_if.h"
+#include "osal_io.h"
+#include "spi_if.h"
+#include "audio_driver_log.h"
+
+#define DEFAULT_SPEED 2000000
+#define BITS_PER_WORD_EIGHT 8
+#define DSP_CS_NUM 1
+#define DSP_SPI_BUS_NUM 1
+
+enum DspI2sFormatRegVal {
+ 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 SpiDevInfo g_devInfo = {
+ .busNum = DSP_SPI_BUS_NUM,
+ .csNum = DSP_CS_NUM,
+};
+
+int32_t DspLinkStartup(const struct AudioCard *card, const struct DaiDevice *device)
+{
+ (void)card;
+ (void)device;
+ return HDF_SUCCESS;
+}
+
+static int32_t DspCfgI2sFrequency(uint32_t rate, uint16_t *frequency)
+{
+ switch (rate) {
+ case I2S_SAMPLE_FREQUENCY_8000:
+ *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_8000;
+ break;
+ case I2S_SAMPLE_FREQUENCY_11025:
+ *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_11025;
+ break;
+ case I2S_SAMPLE_FREQUENCY_12000:
+ *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_12000;
+ break;
+ case I2S_SAMPLE_FREQUENCY_16000:
+ *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_16000;
+ break;
+ case I2S_SAMPLE_FREQUENCY_22050:
+ *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_22050;
+ break;
+ case I2S_SAMPLE_FREQUENCY_24000:
+ *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_24000;
+ break;
+ case I2S_SAMPLE_FREQUENCY_32000:
+ *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_32000;
+ break;
+ case I2S_SAMPLE_FREQUENCY_44100:
+ *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_44100;
+ break;
+ case I2S_SAMPLE_FREQUENCY_48000:
+ *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_48000;
+ break;
+ case I2S_SAMPLE_FREQUENCY_64000:
+ *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_64000;
+ break;
+ case I2S_SAMPLE_FREQUENCY_88200:
+ *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_88200;
+ break;
+ case I2S_SAMPLE_FREQUENCY_96000:
+ *frequency = I2S_SAMPLE_FREQUENCY_REG_VAL_96000;
+ break;
+ default:
+ AUDIO_DRIVER_LOG_ERR("rate: %d is not support.", rate);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t DspSetI2sBitWidth(enum AudioFormat format, uint16_t *bitWidth)
+{
+ switch (format) {
+ case AUDIO_FORMAT_PCM_8_BIT:
+ *bitWidth = I2S_SAMPLE_FORMAT_REG_VAL_24;
+ break;
+ 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_DRIVER_LOG_ERR("format: %d is not support.", format);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+ return HDF_SUCCESS;
+}
+
+static int DspSetI2sFrequency(uint16_t frequencyVal)
+{
+ return HDF_SUCCESS;
+}
+
+static int DspSetI2sFormat(uint16_t formatVal)
+{
+ return HDF_SUCCESS;
+}
+
+int32_t DspLinkHwParams(const struct AudioCard *card, const struct AudioPcmHwParams *param)
+{
+ int ret;
+ uint16_t frequency, bitWidth;
+ (void)card;
+
+ AUDIO_DRIVER_LOG_DEBUG("entry.");
+ if (param == NULL || param->cardServiceName == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input param is nullptr.");
+ return HDF_ERR_INVALID_PARAM;
+ }
+ ret = DspCfgI2sFrequency(param->rate, &frequency);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("RateToFrequency fail.");
+ return HDF_ERR_NOT_SUPPORT;
+ }
+ ret = DspSetI2sBitWidth(param->format, &bitWidth);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("FormatToBitWidth fail.");
+ return HDF_ERR_NOT_SUPPORT;
+ }
+ ret = DspSetI2sFrequency(frequency);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("SetDspI2sFs fail.");
+ return HDF_FAILURE;
+ }
+ ret = DspSetI2sFormat(bitWidth);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("SetDspI2sFormat fail.");
+ return HDF_FAILURE;
+ }
+ AUDIO_DRIVER_LOG_DEBUG("DspLinkHwParams: channels = %d, rate = %d, periodSize = %d, \
+ periodCount = %d, format = %d, cardServiceName = %s \n",
+ param->channels, param->rate, param->periodSize,
+ param->periodCount, (uint32_t)param->format, param->cardServiceName);
+ AUDIO_DRIVER_LOG_DEBUG("success.");
+ return HDF_SUCCESS;
+}
+
+static int DspPowerEnable(void)
+{
+ return HDF_SUCCESS;
+}
+
+static int DspGpioPinInit(void)
+{
+ return HDF_SUCCESS;
+}
+
+static int DspI2cPinInit(void)
+{
+ return HDF_SUCCESS;
+}
+
+static int DspI2sInit(void)
+{
+ return HDF_SUCCESS;
+}
+
+static int DspI2cInit(void)
+{
+ return HDF_SUCCESS;
+}
+
+/* not init dsp gpio */
+static int DspSpiPinInit(void)
+{
+ return HDF_FAILURE;
+}
+
+int32_t DspDeviceInit(const struct DspDevice *device)
+{
+ DevHandle devHandle;
+ struct SpiCfg devCfg = {
+ .maxSpeedHz = DEFAULT_SPEED,
+ .mode = SPI_CLK_POLARITY,
+ .transferMode = SPI_DMA_TRANSFER,
+ .bitsPerWord = BITS_PER_WORD_EIGHT,
+ };
+
+ if (DspPowerEnable() != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("DspPowerEnable: return Error!");
+ return HDF_FAILURE;
+ }
+
+ if (DspGpioPinInit() != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("DspGpioPinInit: return Error!");
+ return HDF_FAILURE;
+ }
+
+ if (DspI2cPinInit() != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("DspI2cPinInit: return Error!");
+ return HDF_FAILURE;
+ }
+
+ if (DspSpiPinInit() == HDF_SUCCESS) {
+ devHandle = SpiOpen(&g_devInfo);
+ if (devHandle == NULL) {
+ AUDIO_DRIVER_LOG_ERR("DspDeviceOpen: Spi failed!");
+ return HDF_FAILURE;
+ }
+
+ if (SpiSetCfg(devHandle, &devCfg) != HDF_SUCCESS) {
+ SpiClose(devHandle);
+ AUDIO_DRIVER_LOG_ERR("DspDeviceCfg: spi failed!");
+ return HDF_FAILURE;
+ }
+ SpiClose(devHandle);
+ } else {
+ AUDIO_DRIVER_LOG_ERR("Dsp Gpio Pin: not init!");
+ }
+
+ if (DspI2cInit() != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ if (DspI2sInit() != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+int32_t DspDeviceReadReg(const struct DspDevice *device, uint8_t *buf, uint32_t len)
+{
+ int32_t ret;
+
+ DevHandle devHandle = SpiOpen(&g_devInfo);
+ if (devHandle == NULL) {
+ AUDIO_DRIVER_LOG_ERR("DspDeviceOpen: Spi failed!");
+ return HDF_FAILURE;
+ }
+
+ ret = SpiRead(devHandle, buf, len);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("DspDeviceRead: spi failed!");
+ SpiClose(devHandle);
+ return HDF_FAILURE;
+ }
+
+ SpiClose(devHandle);
+
+ return HDF_SUCCESS;
+}
+
+int32_t DspDeviceWriteReg(const struct DspDevice *device, uint8_t *buf, uint32_t len)
+{
+ int32_t ret;
+
+ DevHandle devHandle = SpiOpen(&g_devInfo);
+ if (devHandle == NULL) {
+ AUDIO_DRIVER_LOG_ERR("DspDeviceOpen: Spi failed!");
+ return HDF_FAILURE;
+ }
+
+ ret = SpiWrite(devHandle, buf, len);
+ if (ret != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("DspDeviceRead: spi failed!");
+ SpiClose(devHandle);
+ return HDF_FAILURE;
+ }
+
+ SpiClose(devHandle);
+
+ return HDF_SUCCESS;
+}
+
+int32_t DspLinkDeviceInit(struct AudioCard *card, const struct DaiDevice *device)
+{
+ if (device == NULL || device->devDaiName == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input para is nullptr.");
+ return HDF_FAILURE;
+ }
+ AUDIO_DRIVER_LOG_DEBUG("dsp Link device name: %s\n", device->devDaiName);
+ (void)card;
+ return HDF_SUCCESS;
+}
+
+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) {
+ 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) {
+ 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;
+}
+
+
+int32_t DspDecodeAudioStream(const struct AudioCard *card, const uint8_t *buf, const struct DspDevice *device)
+{
+ (void)card;
+ (void)buf;
+ (void)device;
+ AUDIO_DRIVER_LOG_DEBUG("decode run!!!");
+ return HDF_SUCCESS;
+}
+
+int32_t DspEncodeAudioStream(const struct AudioCard *card, const uint8_t *buf, const struct DspDevice *device)
+{
+ (void)card;
+ (void)buf;
+ (void)device;
+ AUDIO_DRIVER_LOG_DEBUG("encode run!!!");
+ return HDF_SUCCESS;
+}
+
+
+int32_t DspEqualizerActive(const struct AudioCard *card, const uint8_t *buf, const struct DspDevice *device)
+{
+ (void)card;
+ (void)buf;
+ (void)device;
+ AUDIO_DRIVER_LOG_DEBUG("equalizer run!!!");
+ 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..ea0e242f291fa816b53c316a20540af383e785b7 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 "osal_time.h"
+#include "osal_uaccess.h"
+#include "audio_driver_log.h"
+#include "audio_dma_base.h"
+#include "audio_sapm.h"
+#include "audio_stream_dispatch.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 *)(addr);
+}
+
+void SysWritel(unsigned long addr, unsigned int value)
+{
+ *(volatile unsigned int *)(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,1102 @@ 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)
+{
+ uint64_t buffSize;
+
+ if (data == NULL || txData == NULL || txData->buf == NULL) {
+ AUDIO_DRIVER_LOG_ERR("input param is null.");
+ return HDF_FAILURE;
+ }
+
+ buffSize = 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;
+ struct PlatformData *data = NULL;
+ uint32_t wptr;
+ uint32_t rptr;
+
+ 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.");
+ OsalMemFree(tmpBuf);
+ 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.");
+ OsalMemFree(tmpBuf);
+ 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.");
+ OsalMemFree(tmpBuf);
+ 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)
+{
+ struct PlatformData *data = NULL;
+ enum CriBuffStatus status;
+ uint32_t timeout = 0;
+
+ 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 = 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);
+
+ while (data->mmapLoopCount < loopTimes && data->renderBufInfo.runStatus != PCM_STOP) {
+ if (data->renderBufInfo.runStatus == PCM_PAUSE) {
+ OsalMSleep(5);
+ continue;
+ }
+ 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.");
+ 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) {
+ AUDIO_DRIVER_LOG_ERR("MmapWriteData fail.");
+ 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;
+ struct PlatformData *data = NULL;
+
+ if (!card || !rxMmapData || !rxMmapData->memoryAddress || rxMmapData->totalBufferFrames <= 0) {
+ 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;
+ }
+
+ uint32_t frameSize = data->pcmInfo.frameSize;
+ uint32_t totalSize = 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);
+}
+
+int32_t AudioRenderTrigger(struct AudioCard *card, int cmd)
+{
+ if (card == NULL) {
+ 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;
+ }
+
+ switch (cmd) {
+ case AUDIO_DRV_PCM_IOCTRL_RENDER_START:
+ 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;
+ }
+
+ data->renderBufInfo.runStatus = PCM_START;
break;
- case DATA_BIT_WIDTH16:
- framesize = 2; /* 2 bytes */
+ case AUDIO_DRV_PCM_IOCTRL_RENDER_STOP:
+ if (AudioDmaPause(data) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("DmaPause fail.");
+ return HDF_FAILURE;
+ }
+
+ if (AudioSampSetPowerMonitor(card, true) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ data->renderBufInfo.runStatus = PCM_STOP;
break;
- case DATA_BIT_WIDTH24:
- framesize = 3; /* 3 bytes */
+ case AUDIO_DRV_PCM_IOCTRL_RENDER_PAUSE:
+ if (AudioDmaPause(data) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("DmaPause fail.");
+ return HDF_FAILURE;
+ }
+
+ if (AudioSampSetPowerMonitor(card, true) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ data->renderBufInfo.runStatus = PCM_PAUSE;
+ break;
+ case AUDIO_DRV_PCM_IOCTRL_RENDER_RESUME:
+ 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;
+ }
+
+ 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)
+{
+ if (card == NULL) {
+ 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;
+ }
+
+ switch (cmd) {
+ case AUDIO_DRV_PCM_IOCTRL_CAPTURE_START:
+ 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;
+ }
+
+ data->captureBufInfo.runStatus = PCM_START;
+ break;
+ case AUDIO_DRV_PCM_IOCTRL_CAPTURE_STOP:
+ if (AudioDmaPause(data) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("DmaPause fail.");
+ return HDF_FAILURE;
+ }
+
+ if (AudioSampSetPowerMonitor(card, true) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ data->captureBufInfo.runStatus = PCM_STOP;
+ break;
+ case AUDIO_DRV_PCM_IOCTRL_CAPTURE_PAUSE:
+ if (AudioDmaPause(data) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("DmaPause fail.");
+ return HDF_FAILURE;
+ }
+
+ if (AudioSampSetPowerMonitor(card, true) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ data->captureBufInfo.runStatus = PCM_PAUSE;
break;
+ case AUDIO_DRV_PCM_IOCTRL_CAPTURE_RESUME:
+ 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;
+ }
+ 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;
+ }
+
+ 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;
}
- for (i = 0; i < audioLen; i += framesize) {
- temp = srcData[i];
- srcData[i] = srcData[i + framesize - 1];
- srcData[i + framesize - 1] = temp;
+ if (AudioDmaRequestChannel(platformData) != HDF_SUCCESS) {
+ AUDIO_DRIVER_LOG_ERR("Dma Request Channel fail.");
+ 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 (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);
}
- AUDIO_DRIVER_LOG_DEBUG("audioLen = %d\n", audioLen);
+ 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;
+ }
+
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/core/include/audio_control.h b/model/audio/core/include/audio_control.h
index cc674f739729ae8c27eecf8607fb9161d1755f2c..fe418c87e032389fafe9dfe1f3a818152cff29fb 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" {
@@ -53,6 +52,7 @@ struct AudioMixerControl {
uint32_t shift;
uint32_t rshift; /* right sound channel reg shift */
uint32_t invert;
+ uint32_t value;
};
struct AudioKcontrol {
diff --git a/model/audio/core/include/audio_core.h b/model/audio/core/include/audio_core.h
index 6235bbb7a169698ac3bba7f587ffa5dc3918e106..762e56be16d44a194aa2456a471c3d735f38ae7b 100755
--- a/model/audio/core/include/audio_core.h
+++ b/model/audio/core/include/audio_core.h
@@ -29,22 +29,6 @@ extern "C" {
#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,
@@ -73,35 +57,39 @@ 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,
- uint32_t value);
-int32_t AudioUpdateAccessoryAiaoRegBits(struct AccessoryDevice *accessory,
- const struct AudioMixerControl *mixerControl, uint32_t value);
+int32_t AudioUpdateDaiRegBits(const struct DaiDevice *dai, struct AudioMixerControl *mixerControl, uint32_t value);
struct CodecDevice *AudioKcontrolGetCodec(const struct AudioKcontrol *kcontrol);
struct AccessoryDevice *AudioKcontrolGetAccessory(const struct AudioKcontrol *kcontrol);
+struct DaiDevice *AudioKcontrolGetCpuDai(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..b4d1aa276ce236d1ee8ed04a7a8185b7ca41acb8 100755
--- a/model/audio/core/include/audio_host.h
+++ b/model/audio/core/include/audio_host.h
@@ -24,22 +24,6 @@ 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) }
@@ -47,6 +31,46 @@ extern "C" {
#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 +83,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 +104,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 +121,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 +180,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 )*/
diff --git a/model/audio/core/include/audio_parse.h b/model/audio/core/include/audio_parse.h
index 9ded34ee9e85c0ed6ebd22d760a2f9c27a9e6a9a..cd7c96f0613acf21d3fcb10ceee6c7e95b3c51d8 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,83 @@ extern "C" {
#endif
#endif /* __cplusplus */
+#define AUDIO_CONFIG_MAX_ITEM 100
+
+static const char *g_audioControlsList[] = {
+ "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[] = {
+ "ADCL", "ADCR", "DACL", "DACR", "LPGA", "RPGA", "SPKL", "SPKR", "MIC"
+};
+
+static char *g_audioSapmCfgNameList[] = {
+ "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_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..fa6c5f00f4192554c00ee49ebbb837a06cd17dc8 100755
--- a/model/audio/core/src/audio_core.c
+++ b/model/audio/core/src/audio_core.c
@@ -7,6 +7,8 @@
*/
#include "audio_core.h"
+#include "osal_io.h"
+#include "audio_driver_log.h"
#define HDF_LOG_TAG audio_core
@@ -16,27 +18,27 @@ AUDIO_LIST_HEAD(codecController);
AUDIO_LIST_HEAD(dspController);
AUDIO_LIST_HEAD(accessoryController);
-int32_t AudioSocRegisterPlatform(struct HdfDeviceObject *device, struct PlatformData *data)
+int32_t AudioSocRegisterPlatform(struct HdfDeviceObject *device, struct PlatformData *platformData)
{
- struct PlatformDevice *platform = NULL;
+ struct PlatformDevice *platformDevice = NULL;
- if ((device == NULL) || (data == NULL)) {
- ADM_LOG_ERR("Input params check error: device=%p, data=%p.", device, data);
+ 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;
}
@@ -121,6 +123,7 @@ int32_t AudioRegisterCodec(struct HdfDeviceObject *device, struct CodecData *cod
ret = AudioSocDeviceRegister(device, (void *)daiData, AUDIO_DAI_DEVICE);
if (ret != HDF_SUCCESS) {
+ OsalIoUnmap((void *)((uintptr_t)(void*)&(codec->devData->virtualAddress)));
OsalMemFree(codec);
ADM_LOG_ERR("Register dai device fail ret=%d", ret);
return HDF_ERR_IO;
@@ -217,7 +220,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;
@@ -269,7 +272,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 &&
@@ -388,7 +391,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 +426,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 +456,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, 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 +534,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 +600,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->regDaiBase;
+ 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->regDaiBase;
+ 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 +669,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 +698,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 +720,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 +747,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 +770,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 +800,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 +829,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 +850,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 +960,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..22f5235cfcd4da234af67881ac3feaa382da73ae 100755
--- a/model/audio/core/src/audio_host.c
+++ b/model/audio/core/src/audio_host.c
@@ -10,6 +10,8 @@
#include "audio_codec_if.h"
#include "audio_core.h"
#include "audio_parse.h"
+#include "audio_sapm.h"
+#include "audio_driver_log.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.");
@@ -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,6 +420,12 @@ 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) {
@@ -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..751b9af2bb80e9cd80a62a193a42e45cfb9374f4 100755
--- a/model/audio/core/src/audio_parse.c
+++ b/model/audio/core/src/audio_parse.c
@@ -7,9 +7,61 @@
*/
#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",
+ "controlsConfig",
+ "sapmComponent",
+ "sapmConfig"
+};
+
int32_t AudioFillConfigData(const struct HdfDeviceObject *device, struct AudioConfigData *configData)
{
const struct DeviceResourceNode *node = NULL;
@@ -58,3 +110,382 @@ 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(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 + 1) / 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(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(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(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(struct DeviceResourceIface *parser, const struct DeviceResourceNode *regNode,
+ struct AudioRegCfgGroupNode* group)
+{
+ int32_t step;
+ int32_t index = group->groupIndex;
+
+ if (parser == NULL || regNode == NULL || g_audioRegGroupName[index] == NULL || group == NULL) {
+ ADM_LOG_ERR("Input para check error: groupName=%p", g_audioRegGroupName[index]);
+ 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(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 = *groupNode;
+ if (group != NULL) {
+ if (group->regCfgItem != NULL) {
+ OsalMemFree(group->regCfgItem);
+ }
+
+ if (group->ctrlCfgItem != NULL) {
+ OsalMemFree(group->ctrlCfgItem);
+ }
+ OsalMemFree(group);
+ }
+
+ 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_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(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..99441c5b440744803c938d4fc4c215dd7a367313 100755
--- a/model/audio/core/test/unittest/common/audio_common_test.h
+++ b/model/audio/core/test/unittest/common/audio_common_test.h
@@ -27,29 +27,19 @@ enum {
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,
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..6d653820a22dc9056f6664f4700d7eff6b0bb13d 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,135 @@ void AudioCoreTest::TearDown()
{
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_RegisterPlatform, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_RegisterPlatform, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTREGISTERPLATFORM, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_RegisterDai, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_RegisterDai, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTREGISTERDAI, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_RegisterAccessory, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_RegisterAccessory, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTREGISTERACCESSORY, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_RegisterCodec, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_RegisterCodec, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTREGISTERCODEC, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_SocRegisterDsp, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_SocRegisterDsp, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTREGISTERDSP, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_SocDeviceRegister, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_SocDeviceRegister, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTSOCDEVICEREGISTER, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_BindDaiLink, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_BindDaiLink, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTBINDDAILINK, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_UpdateCodecRegBits, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_UpdateCodecRegBits, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTUPDATECODECREGBITS, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_UpdateAccessoryRegBits, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_UpdateAccessoryRegBits, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTUPDATEACCESSORYREGBITS, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_UpdateCodecAiaoRegBits, TestSize.Level0)
-{
- struct HdfTestMsg msg = {g_testAudioType, TESTUPDATECODECAIAOREGBITS, -1};
- EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
-}
-
-HWTEST_F(AudioCoreTest, AudioCoreTest_UpdateAccessoryAiaoRegBits, TestSize.Level0)
-{
- struct HdfTestMsg msg = {g_testAudioType, TESTUPDATEACCESSORYAIAOREGBITS, -1};
- EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
-}
-
-HWTEST_F(AudioCoreTest, AudioCoreTest_KcontrolGetCodec, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_KcontrolGetCodec, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTKCONTROLGETCODEC, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_KcontrolGetAccessory, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_KcontrolGetAccessory, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTKCONTROLGETACCESSORY, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_AddControl, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AddControl, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTADDCONTROL, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_AddControls, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AddControls, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTADDCONTROLS, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_CodecReadReg, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_CodecReadReg, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTCODECREADREG, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryReadReg, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryReadReg, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYREADREG, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_CodecAiaoReadReg, TestSize.Level0)
-{
- struct HdfTestMsg msg = {g_testAudioType, TESTCODECAIAOREADREG, -1};
- EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
-}
-
-HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryAiaoReadReg, TestSize.Level0)
-{
- struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYAIAOREADREG, -1};
- EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
-}
-
-HWTEST_F(AudioCoreTest, AudioCoreTest_CodecWriteReg, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_CodecWriteReg, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTCODECWRITEREG, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryWriteReg, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryWriteReg, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYWRITEREG, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_CodecAiaoWriteReg, TestSize.Level0)
-{
- struct HdfTestMsg msg = {g_testAudioType, TESTCODECAIAOWRITEREG, -1};
- EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
-}
-
-HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryAiaoWriteReg, TestSize.Level0)
-{
- struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYAIAOWRITEREG, -1};
- EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
-}
-
-HWTEST_F(AudioCoreTest, AudioCoreTest_InfoCtrlOps, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_InfoCtrlOps, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTINFOCTRLOPS, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_CodecGetCtrlOps, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_CodecGetCtrlOps, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTCODECGETCTRLOPS, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryGetCtrlOps, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryGetCtrlOps, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYGETCTRLOPS, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_CodecAiaoGetCtrlOps, TestSize.Level0)
-{
- struct HdfTestMsg msg = {g_testAudioType, TESTCODECAIAOGETCTRLOPS, -1};
- EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
-}
-
-HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryAiaoGetCtrlOps, TestSize.Level0)
-{
- struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYAIAOGETCTRLOPS, -1};
- EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
-}
-
-HWTEST_F(AudioCoreTest, AudioCoreTest_CodecSetCtrlOps, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_CodecSetCtrlOps, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTCODECSETCTRLOPS, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioCoreTest, AudioCoreTest_AccessorySetCtrlOps, TestSize.Level0)
+HWTEST_F(AudioCoreTest, AudioCoreTest_AccessorySetCtrlOps, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYSETCTRLOPS, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-
-HWTEST_F(AudioCoreTest, AudioCoreTest_CodecAiaoSetCtrlOps, TestSize.Level0)
-{
- struct HdfTestMsg msg = {g_testAudioType, TESTCODECAIAOSETCTRLOPS, -1};
- EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
-}
-
-HWTEST_F(AudioCoreTest, AudioCoreTest_AccessoryAiaoSetCtrlOps, TestSize.Level0)
-{
- struct HdfTestMsg msg = {g_testAudioType, TESTACCESSORYAIAOSETCTRLOPS, -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..119ab6d6cd6dbf67e5705d8135e0157d930c4ea0 100755
--- a/model/audio/core/test/unittest/common/audio_host_test.cpp
+++ b/model/audio/core/test/unittest/common/audio_host_test.cpp
@@ -39,13 +39,13 @@ void AudioHostTest::TearDown()
{
}
-HWTEST_F(AudioHostTest, AudioHostTest_GetCodec, TestSize.Level0)
+HWTEST_F(AudioHostTest, AudioHostTest_GetCodec, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTGETCODEC, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioHostTest, AudioHostTest_GetAudioServiceName, TestSize.Level0)
+HWTEST_F(AudioHostTest, AudioHostTest_GetAudioServiceName, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTGETCARDINSTANCE, -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..dd0e5bf7abdf46c7aaa377b99f01994c4adc12be 100755
--- a/model/audio/core/test/unittest/common/audio_parse_test.cpp
+++ b/model/audio/core/test/unittest/common/audio_parse_test.cpp
@@ -39,7 +39,7 @@ void AudioParseTest::TearDown()
{
}
-HWTEST_F(AudioParseTest, AudioParseTest_GetConfigData, TestSize.Level0)
+HWTEST_F(AudioParseTest, AudioParseTest_GetConfigData, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTGETCCNFIGDATA, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
diff --git a/model/audio/dispatch/include/audio_stream_dispatch.h b/model/audio/dispatch/include/audio_stream_dispatch.h
index b1d4c75298ce9c17b8c283327d1a278eab08c955..3e9a2c65468c3b9dd8f123475ffaf7274f1d67cd 100755
--- a/model/audio/dispatch/include/audio_stream_dispatch.h
+++ b/model/audio/dispatch/include/audio_stream_dispatch.h
@@ -41,9 +41,10 @@ enum StreamDispMethodCmd {
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_RENDER_OPEN,
+ AUDIO_DRV_PCM_IOCTRL_RENDER_CLOSE,
+ AUDIO_DRV_PCM_IOCTRL_CAPTURE_OPEN,
+ AUDIO_DRV_PCM_IOCTRL_CAPTURE_CLOSE,
AUDIO_DRV_PCM_IOCTRL_BUTT,
};
diff --git a/model/audio/dispatch/src/audio_control_dispatch.c b/model/audio/dispatch/src/audio_control_dispatch.c
index 082e66a35ae88f92ddd44a396ea079d8ba27ce12..3f8d5fa99ed2af03c35d2e9554cb3b4b60d6fffd 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;
}
diff --git a/model/audio/dispatch/src/audio_stream_dispatch.c b/model/audio/dispatch/src/audio_stream_dispatch.c
index 70e26609a2d607fd7bac995cefe7010d6b6830ef..db6375b5e477cace8170896012ecdd54c313782d 100755
--- a/model/audio/dispatch/src/audio_stream_dispatch.c
+++ b/model/audio/dispatch/src/audio_stream_dispatch.c
@@ -7,6 +7,8 @@
*/
#include "audio_stream_dispatch.h"
+#include "audio_platform_base.h"
+#include "audio_driver_log.h"
#define HDF_LOG_TAG audio_stream_dispatch
@@ -33,7 +35,7 @@ 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);
return HDF_ERR_IO;
@@ -68,7 +70,7 @@ 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);
return HDF_ERR_IO;
@@ -91,21 +93,13 @@ int32_t HwPlatfromDispatch(const struct AudioCard *audioCard, const struct Audio
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.");
- 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 fail ret=%d", ret);
+ return HDF_ERR_IO;
}
return HDF_SUCCESS;
@@ -119,12 +113,69 @@ 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 fail.");
+ return HDF_FAILURE;
+ }
+
+ if (HwCpuDaiDispatch(audioCard, params) != HDF_SUCCESS) {
+ ADM_LOG_ERR("cpu dai hardware params fail.");
+ return HDF_FAILURE;
+ }
+
+ if (HwPlatfromDispatch(audioCard, params) != HDF_SUCCESS) {
+ ADM_LOG_ERR("platform dai hardware params fail.");
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t AudioDaiDeviceStartup(struct AudioCard *audioCard)
+{
+ struct DaiDevice *cpuDai = NULL;
+ struct DaiDevice *codecDai = NULL;
+ struct DaiDevice *accessoryDai = NULL;
+ int ret;
+
+ if (audioCard == NULL || audioCard->rtd == NULL) {
+ ADM_LOG_ERR("audioCard is null.");
return HDF_FAILURE;
}
+ cpuDai = audioCard->rtd->cpuDai;
+ 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 fail.");
+ return HDF_FAILURE;
+ }
+ } else {
+ ADM_LOG_DEBUG("cpu dai startup is null.");
+ }
+
+ codecDai = audioCard->rtd->codecDai;
+ 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 fail.");
+ return HDF_FAILURE;
+ }
+ } else {
+ ADM_LOG_DEBUG("codec dai startup is null.");
+ }
+
+ accessoryDai = audioCard->rtd->accessoryDai;
+ 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 fail.");
+ return HDF_FAILURE;
+ }
+ } else {
+ ADM_LOG_DEBUG("accessory dai startup is null.");
+ }
return HDF_SUCCESS;
}
@@ -205,9 +256,7 @@ int32_t StreamHostHwParams(const struct HdfDeviceIoClient *client, struct HdfSBu
struct HdfSBuf *reply)
{
struct AudioPcmHwParams params;
- struct StreamHost *streamHost = NULL;
struct AudioCard *audioCard = NULL;
- char *cardName = NULL;
int ret;
ADM_LOG_DEBUG("entry.");
@@ -217,31 +266,14 @@ 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.");
@@ -292,10 +324,8 @@ static struct AudioCard *StreamHostGetCardInstance(const struct HdfDeviceIoClien
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,25 +337,81 @@ int32_t StreamHostCapturePrepare(const struct HdfDeviceIoClient *client, struct
(void)reply;
audioCard = StreamHostGetCardInstance(client);
- if (audioCard == NULL || audioCard->rtd == NULL) {
+ if (audioCard == NULL) {
ADM_LOG_ERR("CapturePrepare 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->CapturePrepare == NULL) {
- ADM_LOG_ERR("audioCard rtd platform is NULL.");
+ ret = AudioCapturePrepare(audioCard);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("platform CapturePrepare fail ret=%d", ret);
+ return HDF_ERR_IO;
+ }
+
+ ADM_LOG_DEBUG("success.");
+ return HDF_SUCCESS;
+}
+
+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 fail!");
+ 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 fail.");
+ return HDF_FAILURE;
+ }
+
+ if (AudioCaptureOpen(audioCard) != HDF_SUCCESS) {
+ ADM_LOG_ERR("platform CaptureOpen fail");
return HDF_ERR_IO;
}
+ if (AudioDaiDeviceStartup(audioCard) != HDF_SUCCESS) {
+ ADM_LOG_ERR("Dai Device Startup fail.");
+ return HDF_FAILURE;
+ }
+
ADM_LOG_DEBUG("success.");
return HDF_SUCCESS;
}
@@ -333,10 +419,8 @@ int32_t StreamHostCapturePrepare(const struct HdfDeviceIoClient *client, struct
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) {
@@ -352,16 +436,8 @@ int32_t StreamHostRenderPrepare(const struct HdfDeviceIoClient *client, struct H
ADM_LOG_ERR("RenderPrepare 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->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);
return HDF_ERR_IO;
@@ -371,51 +447,101 @@ int32_t StreamHostRenderPrepare(const struct HdfDeviceIoClient *client, struct H
return HDF_SUCCESS;
}
-static int32_t StreamTransferWrite(const struct AudioCard *audioCard, struct AudioTxData *transfer)
+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 fail!");
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 fail.");
+ return HDF_FAILURE;
+ }
+
+ if (AudioRenderOpen(audioCard) != HDF_SUCCESS) {
+ ADM_LOG_ERR("platform RenderOpen fail.");
return HDF_FAILURE;
}
+ if (AudioDaiDeviceStartup(audioCard) != HDF_SUCCESS) {
+ ADM_LOG_ERR("Dai Device Startup fail.");
+ 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 fail 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);
return HDF_FAILURE;
@@ -425,25 +551,17 @@ 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);
return HDF_FAILURE;
@@ -457,7 +575,7 @@ int32_t StreamHostWrite(const struct HdfDeviceIoClient *client, struct HdfSBuf *
{
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 +583,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;
@@ -497,11 +615,9 @@ int32_t StreamHostWrite(const struct HdfDeviceIoClient *client, struct HdfSBuf *
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 +627,14 @@ int32_t StreamHostRead(const struct HdfDeviceIoClient *client, struct HdfSBuf *d
(void)data;
audioCard = StreamHostGetCardInstance(client);
- if (audioCard == NULL || audioCard->rtd == NULL) {
+ if (audioCard == 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.");
- 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 fail ret=%d", ret);
return HDF_FAILURE;
}
@@ -551,7 +659,7 @@ int32_t StreamHostRead(const struct HdfDeviceIoClient *client, struct HdfSBuf *d
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.");
@@ -603,16 +711,16 @@ 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)) {
+ if (!HdfSbufWriteUint64(reply, platformData->renderBufInfo.framesPosition)) {
ADM_LOG_ERR("render mmap write position fail!");
return HDF_FAILURE;
}
@@ -624,7 +732,7 @@ int32_t StreamHostMmapRead(const struct HdfDeviceIoClient *client, struct HdfSBu
{
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.");
@@ -674,16 +782,16 @@ 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)) {
+ if (!HdfSbufWriteUint64(reply, platformData->captureBufInfo.framesPosition)) {
ADM_LOG_ERR("render mmap write position fail!");
return HDF_FAILURE;
}
@@ -694,9 +802,10 @@ int32_t StreamHostMmapPositionRead(const struct HdfDeviceIoClient *client, struc
int32_t StreamHostRenderStart(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
{
struct AudioRuntimeDeivces *rtd = NULL;
- struct PlatformDevice *platform = NULL;
+ struct DaiDevice *cpuDai = NULL;
+ struct DaiDevice *codecDai = NULL;
struct AudioCard *audioCard = NULL;
- int ret;
+ int ret = HDF_SUCCESS;
ADM_LOG_DEBUG("entry.");
if (client == NULL) {
@@ -713,15 +822,21 @@ int32_t StreamHostRenderStart(const struct HdfDeviceIoClient *client, struct Hdf
return HDF_FAILURE;
}
rtd = audioCard->rtd;
+ audioCard->standbyMode = AUDIO_SAPM_TURN_STANDBY_LATER;
- 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.");
- return HDF_FAILURE;
+ cpuDai = rtd->cpuDai;
+ if (cpuDai != NULL && cpuDai->devData != NULL && cpuDai->devData->ops != NULL &&
+ cpuDai->devData->ops->Trigger != NULL) {
+ cpuDai->devData->ops->Trigger(audioCard, AUDIO_DRV_PCM_IOCTRL_RENDER_START, cpuDai);
}
- ret = platform->devData->ops->RenderStart(audioCard);
+ codecDai = rtd->codecDai;
+ if (codecDai != NULL && codecDai->devData != NULL && codecDai->devData->ops != NULL &&
+ codecDai->devData->ops->Trigger != NULL) {
+ codecDai->devData->ops->Trigger(audioCard, AUDIO_DRV_PCM_IOCTRL_RENDER_START, codecDai);
+ }
+
+ ret = AudioRenderTrigger(audioCard, AUDIO_DRV_PCM_IOCTRL_RENDER_START);
if (ret != HDF_SUCCESS) {
ADM_LOG_ERR("platform render start fail ret=%d", ret);
return HDF_ERR_IO;
@@ -733,10 +848,8 @@ int32_t StreamHostRenderStart(const struct HdfDeviceIoClient *client, struct Hdf
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) {
@@ -752,16 +865,9 @@ int32_t StreamHostCaptureStart(const struct HdfDeviceIoClient *client, struct Hd
ADM_LOG_ERR("CaptureStart get card instance or rtd fail.");
return HDF_FAILURE;
}
- rtd = audioCard->rtd;
+ audioCard->standbyMode = AUDIO_SAPM_TURN_STANDBY_LATER;
- 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.");
- return HDF_FAILURE;
- }
-
- ret = platform->devData->ops->CaptureStart(audioCard);
+ ret = AudioCaptureTrigger(audioCard, AUDIO_DRV_PCM_IOCTRL_CAPTURE_START);
if (ret != HDF_SUCCESS) {
ADM_LOG_ERR("platform capture start fail ret=%d", ret);
return HDF_ERR_IO;
@@ -774,10 +880,8 @@ int32_t StreamHostCaptureStart(const struct HdfDeviceIoClient *client, struct Hd
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) {
@@ -785,7 +889,6 @@ int32_t StreamHostRenderStop(const struct HdfDeviceIoClient *client, struct HdfS
return HDF_FAILURE;
}
- (void)data;
(void)reply;
audioCard = StreamHostGetCardInstance(client);
@@ -793,16 +896,13 @@ int32_t StreamHostRenderStop(const struct HdfDeviceIoClient *client, struct HdfS
ADM_LOG_ERR("RenderStop 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->RenderStop == NULL) {
- ADM_LOG_ERR("audioCard rtd platform is NULL.");
+ if (!HdfSbufReadUint32(data, &audioCard->standbyMode)) {
+ ADM_LOG_ERR("read request streamType failed!");
return HDF_FAILURE;
}
- ret = platform->devData->ops->RenderStop(audioCard);
+ ret = AudioRenderTrigger(audioCard, AUDIO_DRV_PCM_IOCTRL_RENDER_STOP);
if (ret != HDF_SUCCESS) {
ADM_LOG_ERR("platform render stop fail ret=%d", ret);
return HDF_ERR_IO;
@@ -812,37 +912,63 @@ 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)
+int32_t StreamHostRenderClose(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.");
if (client == NULL) {
- ADM_LOG_ERR("CaptureStop input param is NULL.");
+ ADM_LOG_ERR("RenderClose 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.");
+ return HDF_FAILURE;
+ }
+
+ ret = AudioRenderClose(audioCard);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("platform RenderClose fail ret=%d", ret);
+ return HDF_ERR_IO;
+ }
+
+ ADM_LOG_DEBUG("success.");
+ return HDF_SUCCESS;
+}
+
+
+int32_t StreamHostCaptureStop(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ struct AudioCard *audioCard = NULL;
+ int ret = HDF_SUCCESS;
+ ADM_LOG_DEBUG("entry.");
+
+ if (client == NULL) {
+ ADM_LOG_ERR("CaptureStop input param is NULL.");
+ return HDF_FAILURE;
+ }
+
+ (void)reply;
+
audioCard = StreamHostGetCardInstance(client);
if (audioCard == NULL || audioCard->rtd == NULL) {
ADM_LOG_ERR("CaptureStop 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->CaptureStop == NULL) {
- ADM_LOG_ERR("audioCard rtd platform is NULL.");
+ if (!HdfSbufReadUint32(data, &audioCard->standbyMode)) {
+ ADM_LOG_ERR("read request streamType failed!");
return HDF_FAILURE;
}
- ret = platform->devData->ops->CaptureStop(audioCard);
+ ret = AudioCaptureTrigger(audioCard, AUDIO_DRV_PCM_IOCTRL_CAPTURE_STOP);
if (ret != HDF_SUCCESS) {
ADM_LOG_ERR("platform capture stop fail ret=%d", ret);
return HDF_ERR_IO;
@@ -852,16 +978,14 @@ 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)
+int32_t StreamHostCaptureClose(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.");
if (client == NULL) {
- ADM_LOG_ERR("RenderPause input param is NULL.");
+ ADM_LOG_ERR("CaptureClose input param is NULL.");
return HDF_FAILURE;
}
@@ -870,19 +994,42 @@ 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("CaptureStop 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->RenderPause == NULL) {
- ADM_LOG_ERR("audioCard rtd platform is NULL.");
+ ret = AudioCaptureClose(audioCard);
+ if (ret != HDF_SUCCESS) {
+ ADM_LOG_ERR("platform capture close fail ret=%d", ret);
+ return HDF_ERR_IO;
+ }
+
+ ADM_LOG_DEBUG("success.");
+ return HDF_SUCCESS;
+}
+
+
+int32_t StreamHostRenderPause(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ struct AudioCard *audioCard = NULL;
+ int ret = HDF_SUCCESS;
+ ADM_LOG_DEBUG("entry.");
+
+ if (client == NULL) {
+ ADM_LOG_ERR("RenderPause input param is NULL.");
+ return HDF_FAILURE;
+ }
+
+ (void)data;
+ (void)reply;
+
+ audioCard = StreamHostGetCardInstance(client);
+ if (audioCard == NULL || audioCard->rtd == NULL) {
+ ADM_LOG_ERR("RenderPause get card instance or rtd fail.");
return HDF_FAILURE;
}
- ret = platform->devData->ops->RenderPause(audioCard);
+ ret = AudioRenderTrigger(audioCard, AUDIO_DRV_PCM_IOCTRL_RENDER_PAUSE);
if (ret != HDF_SUCCESS) {
ADM_LOG_ERR("platform render pause fail ret=%d", ret);
return HDF_ERR_IO;
@@ -895,10 +1042,8 @@ int32_t StreamHostRenderPause(const struct HdfDeviceIoClient *client, struct Hdf
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) {
@@ -914,16 +1059,8 @@ int32_t StreamHostCapturePause(const struct HdfDeviceIoClient *client, struct Hd
ADM_LOG_ERR("CapturePause 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->CapturePause == NULL) {
- ADM_LOG_ERR("audioCard rtd platform is NULL.");
- return HDF_FAILURE;
- }
-
- ret = platform->devData->ops->CapturePause(audioCard);
+ ret = AudioCaptureTrigger(audioCard, AUDIO_DRV_PCM_IOCTRL_CAPTURE_PAUSE);
if (ret != HDF_SUCCESS) {
ADM_LOG_ERR("platform captur pause fail ret=%d", ret);
return HDF_ERR_IO;
@@ -936,8 +1073,6 @@ int32_t StreamHostCapturePause(const struct HdfDeviceIoClient *client, struct Hd
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.");
@@ -955,16 +1090,8 @@ int32_t StreamHostRenderResume(const struct HdfDeviceIoClient *client, struct Hd
ADM_LOG_ERR("RenderResume 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->RenderResume == NULL) {
- ADM_LOG_ERR("audioCard rtd platform is NULL.");
- return HDF_FAILURE;
- }
-
- ret = platform->devData->ops->RenderResume(audioCard);
+ ret = AudioRenderTrigger(audioCard, AUDIO_DRV_PCM_IOCTRL_RENDER_RESUME);
if (ret != HDF_SUCCESS) {
ADM_LOG_ERR("platform RenderResume fail ret=%d", ret);
return HDF_ERR_IO;
@@ -977,10 +1104,8 @@ int32_t StreamHostRenderResume(const struct HdfDeviceIoClient *client, struct Hd
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) {
@@ -996,16 +1121,8 @@ int32_t StreamHostCaptureResume(const struct HdfDeviceIoClient *client, struct H
ADM_LOG_ERR("CaptureResume 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->CaptureResume == NULL) {
- ADM_LOG_ERR("audioCard rtd platform is NULL.");
- return HDF_FAILURE;
- }
- ret = platform->devData->ops->CaptureResume(audioCard);
+ ret = AudioCaptureTrigger(audioCard, AUDIO_DRV_PCM_IOCTRL_CAPTURE_RESUME);
if (ret != HDF_SUCCESS) {
ADM_LOG_ERR("platform CaptureResume fail ret=%d", ret);
return HDF_ERR_IO;
@@ -1021,7 +1138,7 @@ int32_t StreamHostDspDecode(const struct HdfDeviceIoClient *client, struct HdfSB
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) {
@@ -1060,7 +1177,7 @@ int32_t StreamHostDspEncode(const struct HdfDeviceIoClient *client, struct HdfSB
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) {
@@ -1099,7 +1216,7 @@ int32_t StreamHostDspEqualizer(const struct HdfDeviceIoClient *client, struct Hd
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) {
@@ -1136,10 +1253,14 @@ 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_RENDER_OPEN, StreamHostRenderOpen},
+ {AUDIO_DRV_PCM_IOCTRL_RENDER_CLOSE, StreamHostRenderClose},
{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_OPEN, StreamHostCaptureOpen},
+ {AUDIO_DRV_PCM_IOCTRL_CAPTURE_CLOSE, StreamHostCaptureClose},
{AUDIO_DRV_PCM_IOCTRL_CAPTURE_START, StreamHostCaptureStart},
{AUDIO_DRV_PCM_IOCTRL_CAPTURE_STOP, StreamHostCaptureStop},
{AUDIO_DRV_PCM_IOCTRL_RENDER_PAUSE, StreamHostRenderPause},
@@ -1150,15 +1271,12 @@ static struct StreamDispCmdHandleList g_streamDispCmdHandle[] = {
{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},
};
int32_t StreamDispatch(struct HdfDeviceIoClient *client, int cmdId,
struct HdfSBuf *data, struct HdfSBuf *reply)
{
- unsigned int i;
+ unsigned int i = 0;
if ((client == NULL) || (data == NULL) || (reply == NULL)) {
return HDF_ERR_INVALID_PARAM;
diff --git a/model/audio/dispatch/test/unittest/common/audio_stream_dispatch_test.cpp b/model/audio/dispatch/test/unittest/common/audio_stream_dispatch_test.cpp
index 50bd21dcb33801432d9962cb098caeca6f0cd071..68b4156422ee6c0ad39abf087bea6f82dc027b0b 100755
--- a/model/audio/dispatch/test/unittest/common/audio_stream_dispatch_test.cpp
+++ b/model/audio/dispatch/test/unittest/common/audio_stream_dispatch_test.cpp
@@ -11,7 +11,7 @@
#include "hdf_uhdf_test.h"
using namespace testing::ext;
-
+namespace {
class AudioStreamDispatchTest : public testing::Test {
public:
static void SetUpTestCase();
@@ -38,8 +38,9 @@ void AudioStreamDispatchTest::TearDown()
{
}
-HWTEST_F(AudioStreamDispatchTest, AudioStreamDispatchTest001, TestSize.Level0)
+HWTEST_F(AudioStreamDispatchTest, AudioStreamDispatchTest001, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTSTREAMDISPATCH, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
+}
diff --git a/model/audio/sapm/include/audio_sapm.h b/model/audio/sapm/include/audio_sapm.h
index 0eaa935cbdd0e776d4d93294158cb72dc3ac1578..7d39f43e9974bd4f7a5a3818ebfe51690051a784 100755
--- a/model/audio/sapm/include/audio_sapm.h
+++ b/model/audio/sapm/include/audio_sapm.h
@@ -39,6 +39,7 @@ 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,8 +58,12 @@ 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 */
diff --git a/model/audio/sapm/src/audio_sapm.c b/model/audio/sapm/src/audio_sapm.c
index b3d60c0176ecbe15b578b331e1d0416eac428b77..a0d26e327afc9519188febbdbbf6c7cc9547554e 100755
--- a/model/audio/sapm/src/audio_sapm.c
+++ b/model/audio/sapm/src/audio_sapm.c
@@ -10,6 +10,7 @@
#include "osal_io.h"
#include "osal_time.h"
#include "osal_timer.h"
+#include "audio_driver_log.h"
#define HDF_LOG_TAG audio_sapm
@@ -152,6 +153,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 +255,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 +340,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);
@@ -383,8 +446,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 +472,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 +485,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 +522,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 +546,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 +650,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 +671,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)) {
@@ -672,14 +745,14 @@ int32_t AudioSapmNewMixerControls(struct AudioSapmComponent *sapmComponent, stru
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[i].name == NULL) {
continue;
}
@@ -719,6 +792,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);
@@ -953,7 +1031,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 +1061,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 +1091,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 +1201,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 +1240,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;
@@ -1274,19 +1352,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..d56b40374a5b0cd66fd8a917e6dd6112b89822a6 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,33 @@ void AudioSapmTest::TearDown()
{
}
-HWTEST_F(AudioSapmTest, AudioSapmTest001, TestSize.Level0)
+HWTEST_F(AudioSapmTest, AudioSapmTest001, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTNEWCOMPONENT, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioSapmTest, AudioSapmTest002, TestSize.Level0)
+HWTEST_F(AudioSapmTest, AudioSapmTest002, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTADDROUTES, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioSapmTest, AudioSapmTest003, TestSize.Level0)
+HWTEST_F(AudioSapmTest, AudioSapmTest003, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTNEWCONTROLS, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioSapmTest, AudioSapmTest004, TestSize.Level0)
+HWTEST_F(AudioSapmTest, AudioSapmTest004, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTPOWERCOMPONET, -1};
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
}
-HWTEST_F(AudioSapmTest, AudioSapmTest005, TestSize.Level0)
+HWTEST_F(AudioSapmTest, AudioSapmTest005, TestSize.Level1)
{
struct HdfTestMsg msg = {g_testAudioType, TESTREFRESHTIME, -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..2532e0f4a5be89ed3e158bc2b23f4ebfe1b8fecf 100644
--- a/model/display/driver/backlight/pwm_bl.c
+++ b/model/display/driver/backlight/pwm_bl.c
@@ -51,7 +51,7 @@ static int32_t BlPwmUpdateBrightness(struct BacklightDev *blDev, uint32_t bright
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) {
@@ -183,4 +183,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..8fd3233692db2ff1b578f22e3d9ddd3d2eabc5be 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 *g_inputManager = GetInputManager();
if (inputDev == NULL) {
HDF_LOGE("%s: parm is null", __func__);
return;
}
- OsalMutexLock(&inputDev->mutex);
+ OsalMutexLock(&g_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(&g_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..85ddcb7822e1e5089134259bcc8a7c5170b59bae
--- /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 "osal_mem.h"
+#include "osal_timer.h"
+#include "hdf_log.h"
+#include "hdf_device_desc.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..0456fcfc4efb6cfb63dcb42d718f837e273bd22f
--- /dev/null
+++ b/model/input/driver/hdf_encoder.h
@@ -0,0 +1,31 @@
+/*
+ * 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_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..91f95697c45f536557623243babd8cce3d934ff5 100644
--- a/model/input/driver/hdf_hid_adapter.c
+++ b/model/input/driver/hdf_hid_adapter.c
@@ -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, 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..365313745303bc7da3f4efe8892cbda70a3988d8 100644
--- a/model/input/driver/hdf_input_device_manager.c
+++ b/model/input/driver/hdf_input_device_manager.c
@@ -103,12 +103,14 @@ static int32_t CreateDeviceNode(InputDevice *inputDev)
static void DeleteDeviceNode(InputDevice *inputDev)
{
+ int32_t len;
+ int32_t ret;
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",
+ len = (inputDev->devId < PLACEHOLDER_LIMIT) ? 1 : PLACEHOLDER_LENGTH;
+ 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__);
@@ -344,7 +346,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..b12ebcf9edd06ca1ea5e8ece91647b7435c90b44 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;
}
@@ -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/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..8742debaba3ba7290d4fae59f3b342010a066abf 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);
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/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..bfa6e612fb42c71b05780d389648c999149379f1 100644
--- a/model/network/wifi/core/module/wifi_base.c
+++ b/model/network/wifi/core/module/wifi_base.c
@@ -366,13 +366,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 +381,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 +392,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 +406,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 +416,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 +431,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 +457,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);
@@ -535,7 +525,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 +535,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 +580,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 +600,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 +625,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 +645,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 +697,6 @@ static int32_t WifiSendMlme(const RequestContext *context, struct HdfSBuf *reqDa
(void)context;
(void)reqData;
(void)rspData;
-
return HDF_SUCCESS;
}
@@ -737,7 +718,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 +759,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 +768,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 +795,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 +809,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 +979,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 +990,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 +1194,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 +1202,7 @@ void SendMessageResetDriverCallBack(const RequestContext *context, struct HdfSBu
ErrorCode rspCode)
{
uint8_t chipId;
+ int32_t ret;
const char *ifName = NULL;
(void)context;
@@ -1241,7 +1221,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 +1231,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 +1266,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 +1284,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);
@@ -1358,7 +1339,7 @@ static int32_t WifiCmdRemainOnChannel(const RequestContext *context, struct Hdf
}
ret = RemainOnChannel(netdev, &wifiOnChannel);
if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: fail to remain on channel,%d",__func__, ret);
+ HDF_LOGE("%s: fail to remain on channel,%d", __func__, ret);
}
return ret;
}
@@ -1396,14 +1377,14 @@ static int32_t WifiCmdProbeReqReport(const RequestContext *context, struct HdfSB
HDF_LOGE("%s: netdev not found!ifName=%s", __func__, ifName);
return HDF_FAILURE;
}
- if (!HdfSbufReadInt32(reqData,&(report))) {
+ 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);
+ HDF_LOGE("%s: fail to probe req report,%d", __func__, ret);
}
return ret;
}
@@ -1444,7 +1425,7 @@ static int32_t WifiCmdCancelRemainOnChannel(const RequestContext *context, struc
ret = CancelRemainOnChannel(netdev);
if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: fail to cancel remain on channel,%d",__func__, ret);
+ HDF_LOGE("%s: fail to cancel remain on channel,%d", __func__, ret);
}
return ret;
}
@@ -1490,7 +1471,7 @@ static int32_t WifiCmdAddIf(const RequestContext *context, struct HdfSBuf *reqDa
ret = AddIf(netdev, &ifAdd);
if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: fail to cancel remain on channel,%d",__func__, ret);
+ HDF_LOGE("%s: fail to cancel remain on channel,%d", __func__, ret);
}
return ret;
}
@@ -1513,7 +1494,7 @@ static int32_t WifiCmdRemoveIf(const RequestContext *context, struct HdfSBuf *re
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;
@@ -1529,14 +1510,14 @@ static int32_t WifiCmdRemoveIf(const RequestContext *context, struct HdfSBuf *re
return HDF_FAILURE;
}
- uint32_t dataSize = 0;
+ 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);
+ HDF_LOGE("%s: fail to remove interface,%d", __func__, ret);
}
return ret;
}
@@ -1589,7 +1570,7 @@ static int32_t WifiCmdSetApWpsP2pIe(const RequestContext *context, struct HdfSBu
}
ret = SetApWpsP2pIe(netdev, &appIe);
if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: fail to setapwpsp2pie,%d",__func__, ret);
+ HDF_LOGE("%s: fail to setapwpsp2pie,%d", __func__, ret);
}
return ret;
}
@@ -1630,7 +1611,7 @@ static int32_t WifiCmdGetDriverFlag(const RequestContext *context, struct HdfSBu
ret = GetDriverFlag(netdev, ¶ms);
if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: fail to getdriverflag,%d",__func__, ret);
+ HDF_LOGE("%s: fail to getdriverflag,%d", __func__, ret);
}
if (!HdfSbufWriteUint64(rspData, params->drvFlags)) {
diff --git a/model/network/wifi/include/hdf_wifi_cmd.h b/model/network/wifi/include/hdf_wifi_cmd.h
index 43a392eadb3f148df3642766ea7117db6e779cd0..5a89f2feca39e3ca4d60464366563e890fe13fa8 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 {
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/als/sensor_als_driver.c b/model/sensor/driver/als/sensor_als_driver.c
new file mode 100755
index 0000000000000000000000000000000000000000..5208a28e4730924f8418f69d4ccbcb4bba24dc42
--- /dev/null
+++ b/model/sensor/driver/als/sensor_als_driver.c
@@ -0,0 +1,369 @@
+/*
+ * 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 };
+
+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,
+ int 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__);
+ (void)DeleteSensorDevice(&config->sensorInfo);
+ ReleaseSensorAllRegConfig(config);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+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 NULL;
+}
+
+void AlsReleaseCfgData(struct SensorCfgData *alsCfg)
+{
+ CHECK_NULL_PTR_RETURN(alsCfg);
+
+ (void)DeleteSensorDevice(&alsCfg->sensorInfo);
+ ReleaseSensorAllRegConfig(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];
+
+ 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) {
+ 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..3ca5d7d37163ca676978c545991184dca8edf9f1
--- /dev/null
+++ b/model/sensor/driver/als/sensor_als_driver.h
@@ -0,0 +1,69 @@
+/*
+ * 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 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 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);
+
+#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..5712c3651ab8265ebdc95e6d36848a4cd5c7f793 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 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,
+};
+
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/als/als_bh1745.c b/model/sensor/driver/chipset/als/als_bh1745.c
new file mode 100755
index 0000000000000000000000000000000000000000..b1fc82fc68194fd67edee31961c726f06f49d610
--- /dev/null
+++ b/model/sensor/driver/chipset/als/als_bh1745.c
@@ -0,0 +1,234 @@
+/*
+ * 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"
+
+static struct Bh1745DrvData *g_bh1745DrvData = NULL;
+
+struct Bh1745DrvData *Bh1745GetDrvData(void)
+{
+ return g_bh1745DrvData;
+}
+
+/* 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 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 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[ALS_R_MSB], SENSOR_DATA_WIDTH_8_BIT) |
+ reg[ALS_R_LSB]);
+ rawData->green = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[ALS_G_MSB], SENSOR_DATA_WIDTH_8_BIT) |
+ reg[ALS_G_LSB]);
+ rawData->blue = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[ALS_B_MSB], SENSOR_DATA_WIDTH_8_BIT) |
+ reg[ALS_B_LSB]);
+ rawData->clear = (int16_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 };
+ int32_t tmp[ALS_LIGHT_NUM];
+ struct SensorReportEvent event;
+
+ (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;
+
+ event.dataLen = sizeof(tmp);
+ event.data = (uint8_t *)&tmp;
+ 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) {
+ 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);
+
+ 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..41ac6de46ca74b1285e64e1035e6db9bdcaf1722
--- /dev/null
+++ b/model/sensor/driver/chipset/als/als_bh1745.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 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
+
+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..947c51a28ea6afac01ca416fb999774c757c4a1c 100644
--- a/model/sensor/driver/chipset/barometer/barometer_bmp180.c
+++ b/model/sensor/driver/chipset/barometer/barometer_bmp180.c
@@ -1,411 +1,411 @@
-/*
- * 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) {
+ 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,
+};
+
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/hall/hall_ak8789.c b/model/sensor/driver/chipset/hall/hall_ak8789.c
index adbd7838b506f8042219477d9a77f7ea673565aa..8d96ccd879fd9e227107a47bceb886b6401ed805 100755
--- a/model/sensor/driver/chipset/hall/hall_ak8789.c
+++ b/model/sensor/driver/chipset/hall/hall_ak8789.c
@@ -29,37 +29,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 +91,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..4726b7671174271ce819f39683a38f9e8823b416
--- /dev/null
+++ b/model/sensor/driver/chipset/magnetic/magnetic_lsm303.c
@@ -0,0 +1,232 @@
+/*
+ * 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;
+
+ 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) {
+ 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);
+
+ 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..955e4024e9bc48735099a0db53c54fe94d26b222
--- /dev/null
+++ b/model/sensor/driver/chipset/proximity/proximity_apds9960.c
@@ -0,0 +1,201 @@
+/*
+ * 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
+
+
+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 = 5; //far state
+ } else {
+ tmp = 0; //near state
+ }
+
+ 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) {
+ 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);
+
+ 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/src/sensor_config_controller.c b/model/sensor/driver/common/src/sensor_config_controller.c
index d0e7c07f8f0e4e065391b5e45e3f9996aef961ad..e2f3689dd871d813aa7750acc340f5657001df8e 100644
--- a/model/sensor/driver/common/src/sensor_config_controller.c
+++ b/model/sensor/driver/common/src/sensor_config_controller.c
@@ -106,8 +106,7 @@ 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_SET:
*value &= ~mask;
*value |= (originValue & mask);
@@ -190,4 +189,4 @@ int32_t SetSensorRegCfgArray(struct SensorBusCfg *busCfg, const struct SensorReg
}
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..9f0f3d4dd207e980066ebbc72df7db44f5a8465b 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);
@@ -108,6 +110,7 @@ static int32_t ParseSensorRegItem(struct DeviceResourceIface *parser, const stru
static 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;
@@ -377,6 +386,9 @@ int32_t GetSensorBaseConfigData(const struct DeviceResourceNode *node, struct Se
{
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 +399,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..e72dd5db2e4a56d6930abd200adacc4c2669bfaa 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) {
diff --git a/model/sensor/driver/hall/sensor_hall_driver.c b/model/sensor/driver/hall/sensor_hall_driver.c
index f8383e40a370c6f2c4b9f6084aaaa46da846b1d9..61b2bbe0ba9703c6ed89d66a82ec93985438f525 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,24 +35,55 @@ 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__);
}
}
@@ -60,12 +91,24 @@ static void HallDataWorkEntry(void *arg)
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);
+ 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 (!HdfAddWork(&drvData->hallWorkQueue, &drvData->hallWork)) {
- HDF_LOGE("%s: Hall add work queue failed", __func__);
+ HDF_LOGE("%s: Hall north add work queue failed", __func__);
}
return HDF_SUCCESS;
@@ -74,12 +117,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);
+ 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 (!HdfAddWork(&drvData->hallWorkQueue, &drvData->hallWork)) {
- HDF_LOGE("%s: Hall add work queue failed", __func__);
+ HDF_LOGE("%s: Hall south add work queue failed", __func__);
}
return HDF_SUCCESS;
@@ -107,6 +162,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 +171,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 +211,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 +302,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 +318,23 @@ 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__);
- (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..29071bb2bec2cfb50378b09da37ff75f1b325ee7 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,7 @@ struct HallDrvData {
int64_t interval;
struct SensorCfgData *hallCfg;
struct HallOpsCall ops;
- int32_t GpioIrq[HALL_POLARITY_GPIO_MAX];
+ uint16_t status;
};
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..c614ba33bdda2d5169399c2b05ad36ac6b4f6330
--- /dev/null
+++ b/model/sensor/driver/magnetic/sensor_magnetic_driver.c
@@ -0,0 +1,378 @@
+/*
+ * 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 (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 *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 NULL;
+}
+
+void MagneticReleaseCfgData(struct SensorCfgData *magneticCfg)
+{
+ CHECK_NULL_PTR_RETURN(magneticCfg);
+
+ (void)DeleteSensorDevice(&magneticCfg->sensorInfo);
+ ReleaseSensorAllRegConfig(magneticCfg);
+ (void)ReleaseSensorBusHandle(&magneticCfg->busCfg);
+
+ 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) {
+ 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..14de5729186e83f7cbc1eeb6539803cd70fd4ad4
--- /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 NULL;
+}
+
+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) {
+ 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 99%
rename from support/platform/include/mmc/mmc_corex.h
rename to model/storage/include/mmc/mmc_corex.h
index f3c2afdaf9b541f6dc16fd57e0b1883d7e6f5790..fbf927522d2a7c1db53d8801e38e7defb331aa88 100644
--- a/support/platform/include/mmc/mmc_corex.h
+++ b/model/storage/include/mmc/mmc_corex.h
@@ -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..1e8fd726cb30b1b9300b9822d63523f54845ae5c 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 = PlatformManagerGetDeviceByMagic(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 99%
rename from support/platform/src/mmc/emmc_if.c
rename to model/storage/src/mmc/emmc_if.c
index b3c9f206143032da4de12d4fbfdb59868ef6955f..02bfe8c1cb1cfb61b02b1af0846d8dea3db85299 100644
--- a/support/platform/src/mmc/emmc_if.c
+++ b/model/storage/src/mmc/emmc_if.c
@@ -112,6 +112,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 +128,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..68493eb6c83c5d9857a191e129eab33c16353f96 100644
--- a/support/platform/src/mmc/mmc_core.c
+++ b/model/storage/src/mmc/mmc_core.c
@@ -1005,7 +1005,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 +1021,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);
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..7b60d843a82ae92a41e1d17197a8f06d6ea8bb90 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.magic = 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,8 @@ 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;
+ for (idx = 0; 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 +379,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 +392,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 +403,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/src/usb_ddk_pnp_loader.c b/model/usb/src/usb_ddk_pnp_loader.c
index affbd048951f2c0d09ede05a25c10cc6b8791d27..65e39e7a7d401591a8f62356dafe8a64f9fdf88b 100755
--- a/model/usb/src/usb_ddk_pnp_loader.c
+++ b/model/usb/src/usb_ddk_pnp_loader.c
@@ -39,27 +39,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;
@@ -125,63 +125,84 @@ 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) == 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;
@@ -453,26 +474,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]);
}
@@ -690,7 +711,7 @@ 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);
@@ -702,18 +723,18 @@ 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;
}
@@ -721,7 +742,7 @@ error:
static void UsbDdkPnpLoaderAddDevice(uint32_t cmdId, uint8_t index, const struct IDevmgrService *devmgrSvc,
const struct UsbPnpNotifyMatchInfoTable *infoTable, struct UsbPnpMatchIdTable **matchIdTable)
{
- int ret = HDF_FAILURE;
+ int ret;
struct UsbPnpMatchIdTable *idTable = NULL;
int32_t tableCount;
@@ -743,8 +764,6 @@ static void UsbDdkPnpLoaderAddDevice(uint32_t cmdId, uint8_t index, const struct
continue;
}
}
-
- HDF_LOGD("%s:%d AddDevice end, index=%d, ret=%d", __func__, __LINE__, index, ret);
}
static int UsbDdkPnpLoaderRemoveHandle(const struct IDevmgrService *devmgrSvc,
@@ -773,12 +792,12 @@ static int UsbDdkPnpLoaderRemoveHandle(const struct IDevmgrService *devmgrSvc,
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;
}
@@ -892,30 +911,30 @@ 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);
@@ -1004,11 +1023,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/support/platform/include/adc_core.h b/support/platform/include/adc/adc_core.h
similarity index 100%
rename from support/platform/include/adc_core.h
rename to support/platform/include/adc/adc_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/plat_log.h b/support/platform/include/fwk/plat_log.h
similarity index 100%
rename from support/platform/include/plat_log.h
rename to support/platform/include/fwk/plat_log.h
diff --git a/support/platform/include/common/platform_core.h b/support/platform/include/fwk/platform_core.h
similarity index 98%
rename from support/platform/include/common/platform_core.h
rename to support/platform/include/fwk/platform_core.h
index 08e5770dd8224fa5827d337b3156372d327c3cd5..bd1203ea8ba6a13ed169f555a2a885cce1dc71eb 100644
--- a/support/platform/include/common/platform_core.h
+++ b/support/platform/include/fwk/platform_core.h
@@ -30,6 +30,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 100%
rename from support/platform/include/common/platform_device.h
rename to support/platform/include/fwk/platform_device.h
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/common/platform_manager.h b/support/platform/include/fwk/platform_manager.h
similarity index 100%
rename from support/platform/include/common/platform_manager.h
rename to support/platform/include/fwk/platform_manager.h
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 95%
rename from support/platform/include/gpio_core.h
rename to support/platform/include/gpio/gpio_core.h
index 4f8fbdd6f4caf1963ba7c07a21ca6f8127dd9563..823df7187357dfc4871c0d8a0e3af06ffdb995a5 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
@@ -149,6 +150,15 @@ static inline uint16_t GpioGetLocalNumber(struct GpioCntlr *cntlr, uint16_t gpio
return (cntlr == NULL) ? gpio : (gpio - cntlr->start);
}
+struct GpioManager {
+ struct IDeviceIoService service;
+ struct PlatformDevice device;
+ struct PlatformManager manager;
+ struct DListHead cntlrList;
+};
+
+struct GpioManager *GpioManagerGet(void);
+
#ifdef __cplusplus
#if __cplusplus
}
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.
+ *