From b99255dca2b1e569ac3b67f3ef93f6dc7bb2f8f8 Mon Sep 17 00:00:00 2001 From: laokz <2653412+laokz@user.noreply.gitee.com> Date: Sat, 22 Jan 2022 08:43:16 +0000 Subject: [PATCH 001/102] =?UTF-8?q?fix(khdf/liteos)=EF=BC=9A=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3NetBufAlloc=E6=9C=AA=E6=AD=A3=E7=A1=AE=E6=B8=85?= =?UTF-8?q?=E9=9B=B6=E5=86=85=E5=AD=98=E9=97=AE=E9=A2=98=20data=E5=86=85?= =?UTF-8?q?=E5=AD=98=E6=8C=89=E5=AE=9E=E9=99=85=E7=94=B3=E8=AF=B7=E5=92=8C?= =?UTF-8?q?=E5=88=86=E9=85=8D=E7=9A=84=E5=A4=A7=E5=B0=8F=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E6=B8=85=E9=9B=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laokz --- khdf/liteos/network/src/netbuf_adapter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/khdf/liteos/network/src/netbuf_adapter.c b/khdf/liteos/network/src/netbuf_adapter.c index 6d9d2fe..176251b 100644 --- a/khdf/liteos/network/src/netbuf_adapter.c +++ b/khdf/liteos/network/src/netbuf_adapter.c @@ -307,7 +307,7 @@ NetBuf *NetBufAlloc(uint32_t size) } (void)memset_s(nb, sizeof(NetBuf), 0, sizeof(NetBuf)); - (void)memset_s(data, sizeof(uint8_t), 0, sizeof(uint8_t)); + (void)memset_s(data, size, 0, size); nb->mem = data; nb->len = size; -- Gitee From 2b12822615079eed2446aa301995de6f7ad82feb Mon Sep 17 00:00:00 2001 From: zhang Date: Tue, 1 Mar 2022 14:25:15 +0800 Subject: [PATCH 002/102] =?UTF-8?q?fix=EF=BC=9Aadd=20hdf=20host=20service?= =?UTF-8?q?=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhang --- uhdf2/host/hdf_devhost.cfg | 28 ++++++++++++++++++++++++++++ uhdf2/manager/BUILD.gn | 6 +----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/uhdf2/host/hdf_devhost.cfg b/uhdf2/host/hdf_devhost.cfg index 7cadf0e..7f8ee61 100755 --- a/uhdf2/host/hdf_devhost.cfg +++ b/uhdf2/host/hdf_devhost.cfg @@ -125,6 +125,34 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "root", "gid" : ["system"] + }, + { + "name" : "dcamera_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "root", + "gid" : ["system"] + }, + { + "name" : "hwc_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "root", + "gid" : ["system"] + }, + { + "name" : "gralloc_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "root", + "gid" : ["system"] + }, + { + "name" : "sensor_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "root", + "gid" : ["system"] } ] } diff --git a/uhdf2/manager/BUILD.gn b/uhdf2/manager/BUILD.gn index 3d55e5e..5ac195c 100644 --- a/uhdf2/manager/BUILD.gn +++ b/uhdf2/manager/BUILD.gn @@ -87,11 +87,7 @@ ohos_executable("hdf_devmgr") { } ohos_prebuilt_etc("hdf_devmgr.rc") { - if (use_musl) { - source = "hdf_devmgr.cfg" - } else { - source = "hdf_devmgr.rc" - } + source = "hdf_devmgr.cfg" relative_install_dir = "init" install_images = [ chipset_base_dir ] subsystem_name = "hdf" -- Gitee From 90774b33cd86907e5948fa971d5cc564757b4952 Mon Sep 17 00:00:00 2001 From: jiaziyang Date: Thu, 3 Mar 2022 16:02:29 +0800 Subject: [PATCH 003/102] fix: rename function name in uart_dev.c Signed-off-by: jiaziyang --- khdf/liteos/platform/src/uart_dev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/khdf/liteos/platform/src/uart_dev.c b/khdf/liteos/platform/src/uart_dev.c index d727fb6..30c7b0c 100755 --- a/khdf/liteos/platform/src/uart_dev.c +++ b/khdf/liteos/platform/src/uart_dev.c @@ -47,7 +47,7 @@ static int32_t UartDevOpen(struct file *filep) } struct drv_data *drv = (struct drv_data *)filep->f_vnode->data; host = (struct UartHost *)drv->priv; - return UartHostInit(host); + return UartHostRequest(host); } static int32_t UartDevRelease(struct file *filep) { @@ -59,7 +59,7 @@ static int32_t UartDevRelease(struct file *filep) struct drv_data *drv = (struct drv_data *)filep->f_vnode->data; host = (struct UartHost *)drv->priv; - return UartHostDeinit(host); + return UartHostRelease(host); } static ssize_t UartDevRead(struct file *filep, char *buf, size_t count) -- Gitee From 17813599a2938a889d96a4a0e685055d76833559 Mon Sep 17 00:00:00 2001 From: yuanbo Date: Thu, 3 Mar 2022 17:38:40 +0800 Subject: [PATCH 004/102] fix: add interface token checking Signed-off-by: yuanbo --- uhdf2/hdi/src/devmgr_client.c | 43 +++++--- uhdf2/hdi/src/idevmgr_client.cpp | 6 ++ uhdf2/hdi/src/iservmgr_client.cpp | 8 +- uhdf2/hdi/src/servmgr_client.c | 17 ++- uhdf2/hdi/src/servstat_listener.c | 13 ++- uhdf2/hdi/src/servstat_listener_stub.cpp | 7 +- .../servmgr/service_manager_hdi_c_test.cpp | 63 ++++++++--- .../test/servmgr/service_manager_hdi_test.cpp | 69 +++++++----- uhdf2/host/src/devhost_service_full.c | 1 + uhdf2/host/src/device_service_stub.c | 14 +++ uhdf2/host/src/devmgr_service_proxy.c | 101 ++++++++++-------- uhdf2/host/src/devsvc_manager_proxy.c | 85 +++++++++------ .../unittest/sample_driver/sample_driver.cpp | 5 + .../sample_driver/sample_hdi_service_stub.cpp | 31 +++++- uhdf2/ipc/include/hdf_remote_adapter.h | 7 +- uhdf2/ipc/include/hdf_remote_adapter_if.h | 7 ++ uhdf2/ipc/src/hdf_remote_adapter.cpp | 81 +++++++++++++- uhdf2/ipc/src/hdf_remote_service.c | 16 +++ uhdf2/manager/src/devmgr_service_stub.c | 32 +++--- uhdf2/manager/src/devsvc_manager_stub.c | 37 ++++++- uhdf2/manager/src/servstat_listener_holder.c | 10 ++ uhdf2/shared/include/hdf_remote_service.h | 7 ++ 22 files changed, 493 insertions(+), 167 deletions(-) diff --git a/uhdf2/hdi/src/devmgr_client.c b/uhdf2/hdi/src/devmgr_client.c index d505a11..319fefc 100644 --- a/uhdf2/hdi/src/devmgr_client.c +++ b/uhdf2/hdi/src/devmgr_client.c @@ -94,23 +94,26 @@ static int32_t DevmgrQueryDeviceInfo(struct HDIDeviceManager *iDevMgr, struct De HdfSbufRecycle(reply); return HDF_ERR_MALLOC_FAIL; } + do { + if (!HdfRemoteServiceWriteInterfaceToken(iDevMgr->remote, data)) { + ret = HDF_FAILURE; + break; + } + list->deviceCnt = 0; + DListHeadInit(&list->list); - list->deviceCnt = 0; - DListHeadInit(&list->list); - - HdfSbufWriteInt32(data, type); - ret = DeviceManagerHdiCall(iDevMgr, DEVMGR_SERVICE_QUERY_DEVICE, data, reply); - if (ret != HDF_SUCCESS) { - HDF_LOGE("DevmgrProxyQueryDevice failed"); - goto FINISHED; - } + HdfSbufWriteInt32(data, type); + ret = DeviceManagerHdiCall(iDevMgr, DEVMGR_SERVICE_QUERY_DEVICE, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("DevmgrProxyQueryDevice failed"); + break; + } - ret = HdfObtainDeviceInfo(list, reply); + ret = HdfObtainDeviceInfo(list, reply); + } while (0); -FINISHED: HdfSbufRecycle(reply); HdfSbufRecycle(data); - return ret; } @@ -165,7 +168,10 @@ int32_t DevmgrLoadDevice(struct HDIDeviceManager *iDevMgr, const char *serviceNa status = HDF_ERR_MALLOC_FAIL; break; } - + if (!HdfRemoteServiceWriteInterfaceToken(iDevMgr->remote, data)) { + status = HDF_FAILURE; + break; + } if (!HdfSbufWriteString(data, serviceName)) { HDF_LOGE("%{public}s: writing service name failed!", __func__); break; @@ -194,7 +200,10 @@ int32_t DevmgrUnloadDevice(struct HDIDeviceManager *iDevMgr, const char *service status = HDF_ERR_MALLOC_FAIL; break; } - + if (!HdfRemoteServiceWriteInterfaceToken(iDevMgr->remote, data)) { + status = HDF_FAILURE; + break; + } if (!HdfSbufWriteString(data, serviceName)) { HDF_LOGE("%{public}s: writing service name failed!", __func__); break; @@ -237,7 +246,11 @@ struct HDIDeviceManager *HDIDeviceManagerGet(void) HdfRemoteServiceRecycle(remote); return NULL; } - + if (!HdfRemoteServiceSetInterfaceDesc(remote, "HDI.IDeviceManager.V1_0")) { + HDF_LOGE("%{public}s: failed to init interface desc", __func__); + HdfRemoteServiceRecycle(remote); + return NULL; + } iDevMgr->remote = remote; HDIDeviceManagerConstruct(iDevMgr); return iDevMgr; diff --git a/uhdf2/hdi/src/idevmgr_client.cpp b/uhdf2/hdi/src/idevmgr_client.cpp index 6b7c21a..902755e 100644 --- a/uhdf2/hdi/src/idevmgr_client.cpp +++ b/uhdf2/hdi/src/idevmgr_client.cpp @@ -50,6 +50,9 @@ int32_t DeviceManagerProxy::LoadDevice(const std::string &serviceName) MessageParcel reply; MessageOption option; HDF_LOGI("load device: %{public}s", serviceName.data()); + if (!data.WriteInterfaceToken(DeviceManagerProxy::GetDescriptor())) { + return HDF_FAILURE; + } if (!data.WriteCString(serviceName.data())) { return HDF_FAILURE; } @@ -67,6 +70,9 @@ int32_t DeviceManagerProxy::UnloadDevice(const std::string &serviceName) MessageParcel reply; MessageOption option; HDF_LOGI("unload device: %{public}s", serviceName.data()); + if (!data.WriteInterfaceToken(DeviceManagerProxy::GetDescriptor())) { + return HDF_FAILURE; + } if (!data.WriteCString(serviceName.data())) { return HDF_FAILURE; } diff --git a/uhdf2/hdi/src/iservmgr_client.cpp b/uhdf2/hdi/src/iservmgr_client.cpp index 4dde8c5..6af2b51 100644 --- a/uhdf2/hdi/src/iservmgr_client.cpp +++ b/uhdf2/hdi/src/iservmgr_client.cpp @@ -64,7 +64,8 @@ int32_t ServiceManagerProxy::RegisterServiceStatusListener(::OHOS::sptrAsObject())) { return HDF_FAILURE; } @@ -82,7 +83,8 @@ int32_t ServiceManagerProxy::UnregisterServiceStatusListener(::OHOS::sptrAsObject())) { + if (!data.WriteInterfaceToken(ServiceManagerProxy::GetDescriptor()) || + !data.WriteRemoteObject(listener->AsObject())) { return HDF_FAILURE; } @@ -97,7 +99,7 @@ sptr ServiceManagerProxy::GetService(const char* serviceName) { MessageParcel data; MessageParcel reply; - if (!data.WriteCString(serviceName)) { + if (!data.WriteInterfaceToken(ServiceManagerProxy::GetDescriptor()) || !data.WriteCString(serviceName)) { return nullptr; } diff --git a/uhdf2/hdi/src/servmgr_client.c b/uhdf2/hdi/src/servmgr_client.c index 457185b..04afe98 100644 --- a/uhdf2/hdi/src/servmgr_client.c +++ b/uhdf2/hdi/src/servmgr_client.c @@ -55,7 +55,8 @@ struct HdfRemoteService *HDIServMgrGetService(struct HDIServiceManager *iServMgr break; } - if (!HdfSbufWriteString(data, serviceName)) { + if (!HdfRemoteServiceWriteInterfaceToken(servMgrClient->remote, data) || + !HdfSbufWriteString(data, serviceName)) { break; } int status = ServiceManagerHdiCall(servMgrClient, DEVSVC_MANAGER_GET_SERVICE, data, reply); @@ -72,6 +73,7 @@ struct HdfRemoteService *HDIServMgrGetService(struct HDIServiceManager *iServMgr if (data != NULL) { HdfSbufRecycle(data); } + return service; } @@ -88,7 +90,8 @@ int32_t HDIServMgrRegisterServiceStatusListener(struct HDIServiceManager *self, return HDF_ERR_MALLOC_FAIL; } - if (!HdfSbufWriteUint16(data, deviceClass) || + if (!HdfRemoteServiceWriteInterfaceToken(servMgrClient->remote, data) || + !HdfSbufWriteUint16(data, deviceClass) || ServiceStatusListenerMarshalling(listener, data) != HDF_SUCCESS) { return HDF_FAILURE; } @@ -113,7 +116,8 @@ int32_t HDIServMgrUnregisterServiceStatusListener(struct HDIServiceManager *self return HDF_ERR_MALLOC_FAIL; } - if (ServiceStatusListenerMarshalling(listener, data) != HDF_SUCCESS) { + if (!HdfRemoteServiceWriteInterfaceToken(servMgrClient->remote, data) || + ServiceStatusListenerMarshalling(listener, data) != HDF_SUCCESS) { return HDF_FAILURE; } @@ -146,8 +150,13 @@ struct HDIServiceManager *HDIServiceManagerGet(void) HdfRemoteServiceRecycle(remote); return NULL; } - + if (!HdfRemoteServiceSetInterfaceDesc(remote, "HDI.IServiceManager.V1_0")) { + HDF_LOGE("%{public}s: failed to init interface desc", __func__); + HdfRemoteServiceRecycle(remote); + return NULL; + } iServMgrClient->remote = remote; + HDIServiceManagerConstruct(&iServMgrClient->iservmgr); return &iServMgrClient->iservmgr; } diff --git a/uhdf2/hdi/src/servstat_listener.c b/uhdf2/hdi/src/servstat_listener.c index 3fade05..116e64f 100644 --- a/uhdf2/hdi/src/servstat_listener.c +++ b/uhdf2/hdi/src/servstat_listener.c @@ -18,7 +18,7 @@ #include #include #include - +#define SERVSTAT_LISTENER_INTERFACE_DESCRIPTOR "HDI.IServiceStatusListener.V1_0" struct ServstatListenerStub { struct ServiceStatusListener listener; struct HdfRemoteService *remote; @@ -34,7 +34,10 @@ int ServstatListenerStubRemoteDispatch( if (cmdid != SERVIE_STATUS_LISTENER_NOTIFY) { return HDF_ERR_NOT_SUPPORT; } - + if (!HdfRemoteServiceCheckInterfaceToken(stub->remote, data)) { + HDF_LOGE("failed to check interface"); + return HDF_ERR_INVALID_PARAM; + } if (ServiceStatusUnMarshalling(&status, data) != HDF_SUCCESS) { return HDF_ERR_INVALID_PARAM; } @@ -75,6 +78,12 @@ struct ServiceStatusListener *HdiServiceStatusListenerNewInstance(void) OsalMemFree(stub); return NULL; } + if (!HdfRemoteServiceSetInterfaceDesc(stub->remote, SERVSTAT_LISTENER_INTERFACE_DESCRIPTOR)) { + HdfRemoteServiceRecycle(stub->remote); + stub->remote = NULL; + OsalMemFree(stub); + return NULL; + } return &stub->listener; } diff --git a/uhdf2/hdi/src/servstat_listener_stub.cpp b/uhdf2/hdi/src/servstat_listener_stub.cpp index 65096b6..ab014a2 100644 --- a/uhdf2/hdi/src/servstat_listener_stub.cpp +++ b/uhdf2/hdi/src/servstat_listener_stub.cpp @@ -17,7 +17,7 @@ #include "hdf_base.h" #include "hdf_log.h" #include "iservmgr_hdi.h" - +#define HDF_LOG_TAG servstat_listener namespace OHOS { namespace HDI { namespace ServiceManager { @@ -39,7 +39,10 @@ int32_t ServStatListenerStub::ServStatListenerStubOnReceive(MessageParcel& data, MessageParcel& reply, MessageOption& option) { ServiceStatus status; - + if (data.ReadInterfaceToken() != GetDescriptor()) { + HDF_LOGI("failed to check interface token"); + return HDF_FAILURE; + } status.serviceName = data.ReadCString(); if (status.serviceName.empty()) { HDF_LOGI("failed to read serviceName in ServiceStatus"); diff --git a/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp b/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp index d620383..8a854b1 100644 --- a/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp +++ b/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp @@ -22,18 +22,20 @@ #include #include #include -#include #include +#include #include + #include "sample_hdi.h" #define HDF_LOG_TAG service_manager_test using namespace testing::ext; -constexpr const char *TEST_SERVICE_NAME = "sample_driver_service"; -constexpr int PAYLOAD_NUM = 1234; -constexpr int WAIT_LOAD_UNLOAD_TIME = 300; +static constexpr const char *TEST_SERVICE_NAME = "sample_driver_service"; +static constexpr const char *TEST_SERVICE_INTERFACE_DESC = "hdf.test.sampele_service"; +static constexpr int PAYLOAD_NUM = 1234; +static constexpr int WAIT_LOAD_UNLOAD_TIME = 300; class HdfServiceMangerHdiCTest : public testing::Test { public: static void SetUpTestCase() @@ -70,12 +72,17 @@ HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest002, TestSize.Level1) HDIServiceManagerRelease(servmgr); ASSERT_TRUE(sampleService != nullptr); + bool ret = HdfRemoteServiceSetInterfaceDesc(sampleService, TEST_SERVICE_INTERFACE_DESC); + ASSERT_EQ(ret, true); + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); ASSERT_TRUE(data != nullptr); ASSERT_TRUE(reply != nullptr); + ret = HdfRemoteServiceWriteInterfaceToken(sampleService, data); + ASSERT_EQ(ret, true); - bool ret = HdfSbufWriteString(data, "sample_service test call"); + ret = HdfSbufWriteString(data, "sample_service test call"); ASSERT_EQ(ret, true); int status = sampleService->dispatcher->Dispatch(sampleService, SAMPLE_SERVICE_PING, data, reply); @@ -107,6 +114,8 @@ HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest003, TestSize.Level1) struct HdfRemoteService *sampleService = servmgr->GetService(servmgr, TEST_SERVICE_NAME); HDIServiceManagerRelease(servmgr); ASSERT_TRUE(sampleService != nullptr); + bool ret = HdfRemoteServiceSetInterfaceDesc(sampleService, TEST_SERVICE_INTERFACE_DESC); + ASSERT_EQ(ret, true); struct HdfRemoteService *callback = HdfRemoteServiceObtain(nullptr, &g_callbackDispatcher); ASSERT_NE(callback, nullptr); @@ -114,7 +123,8 @@ HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest003, TestSize.Level1) struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); ASSERT_TRUE(data != nullptr); ASSERT_TRUE(reply != nullptr); - + ret = HdfRemoteServiceWriteInterfaceToken(sampleService, data); + ASSERT_EQ(ret, true); int32_t payload = PAYLOAD_NUM; HdfSbufWriteInt32(data, payload); HdfSbufWriteRemoteService(data, callback); @@ -135,18 +145,22 @@ HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest004, TestSize.Level1) struct HdfRemoteService *sampleService = servmgr->GetService(servmgr, TEST_SERVICE_NAME); HDIServiceManagerRelease(servmgr); ASSERT_TRUE(sampleService != nullptr); + bool ret = HdfRemoteServiceSetInterfaceDesc(sampleService, TEST_SERVICE_INTERFACE_DESC); + ASSERT_EQ(ret, true); struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); ASSERT_TRUE(data != nullptr); ASSERT_TRUE(reply != nullptr); + ret = HdfRemoteServiceWriteInterfaceToken(sampleService, data); + ASSERT_EQ(ret, true); HdfSbufWriteInt32(data, PAYLOAD_NUM); HdfSbufWriteInt32(data, PAYLOAD_NUM); int status = sampleService->dispatcher->Dispatch(sampleService, SAMPLE_SERVICE_SUM, data, reply); ASSERT_EQ(status, 0); int32_t result; - bool ret = HdfSbufReadInt32(reply, &result); + ret = HdfSbufReadInt32(reply, &result); ASSERT_TRUE(ret); int32_t expRes = PAYLOAD_NUM + PAYLOAD_NUM; @@ -164,14 +178,17 @@ HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest005, TestSize.Level1) struct HdfRemoteService *sampleService = servmgr->GetService(servmgr, TEST_SERVICE_NAME); HDIServiceManagerRelease(servmgr); ASSERT_TRUE(sampleService != nullptr); + bool ret = HdfRemoteServiceSetInterfaceDesc(sampleService, TEST_SERVICE_INTERFACE_DESC); + ASSERT_EQ(ret, true); struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); ASSERT_TRUE(data != nullptr); ASSERT_TRUE(reply != nullptr); - - struct DataBlock dataBlock = { 1, 2, "dataBolck", 3 }; - bool ret = DataBlockBlockMarshalling(&dataBlock, data); + ret = HdfRemoteServiceWriteInterfaceToken(sampleService, data); + ASSERT_EQ(ret, true); + struct DataBlock dataBlock = {1, 2, "dataBolck", 3}; + ret = DataBlockBlockMarshalling(&dataBlock, data); ASSERT_TRUE(ret); int status = sampleService->dispatcher->Dispatch(sampleService, SAMPLE_STRUCT_TRANS, data, reply); @@ -198,6 +215,8 @@ HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest006, TestSize.Level1) struct HdfRemoteService *sampleService = servmgr->GetService(servmgr, TEST_SERVICE_NAME); HDIServiceManagerRelease(servmgr); ASSERT_TRUE(sampleService != nullptr); + bool ret = HdfRemoteServiceSetInterfaceDesc(sampleService, TEST_SERVICE_INTERFACE_DESC); + ASSERT_EQ(ret, true); struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); @@ -209,8 +228,9 @@ HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest006, TestSize.Level1) for (int i = 0; i < buffersize; i++) { dataBuffer[i] = i; } - - bool ret = HdfSbufWriteUnpadBuffer(data, dataBuffer, sizeof(dataBuffer)); + ret = HdfRemoteServiceWriteInterfaceToken(sampleService, data); + ASSERT_EQ(ret, true); + ret = HdfSbufWriteUnpadBuffer(data, dataBuffer, sizeof(dataBuffer)); ASSERT_TRUE(ret); int status = sampleService->dispatcher->Dispatch(sampleService, SAMPLE_BUFFER_TRANS, data, reply); @@ -244,12 +264,16 @@ HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest007, TestSize.Level1) OsalMSleep(WAIT_LOAD_UNLOAD_TIME); sampleService = servmgr->GetService(servmgr, TEST_SERVICE_NAME); ASSERT_TRUE(sampleService != nullptr); + ret = HdfRemoteServiceSetInterfaceDesc(sampleService, TEST_SERVICE_INTERFACE_DESC); + ASSERT_EQ(ret, true); struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); ASSERT_TRUE(data != nullptr); ASSERT_TRUE(reply != nullptr); + ret = HdfRemoteServiceWriteInterfaceToken(sampleService, data); + ASSERT_EQ(ret, true); const char *newServName = "sample_driver_service2"; ret = HdfSbufWriteString(data, newServName); ASSERT_TRUE(ret); @@ -259,9 +283,13 @@ HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest007, TestSize.Level1) struct HdfRemoteService *sampleService2 = servmgr->GetService(servmgr, newServName); ASSERT_TRUE(sampleService != nullptr); + ret = HdfRemoteServiceSetInterfaceDesc(sampleService, TEST_SERVICE_INTERFACE_DESC); + ASSERT_EQ(ret, true); HdfSbufFlush(data); HdfSbufFlush(reply); + ret = HdfRemoteServiceWriteInterfaceToken(sampleService, data); + ASSERT_EQ(ret, true); HdfSbufWriteInt32(data, PAYLOAD_NUM); HdfSbufWriteInt32(data, PAYLOAD_NUM); @@ -276,6 +304,8 @@ HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest007, TestSize.Level1) HdfRemoteServiceRecycle(sampleService2); HdfSbufFlush(data); + ret = HdfRemoteServiceWriteInterfaceToken(sampleService, data); + ASSERT_EQ(ret, true); ret = HdfSbufWriteString(data, newServName); ASSERT_TRUE(ret); @@ -406,6 +436,8 @@ HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest009, TestSize.Level1) OsalMSleep(WAIT_LOAD_UNLOAD_TIME); sampleService = servmgr->GetService(servmgr, TEST_SERVICE_NAME); ASSERT_TRUE(sampleService != nullptr); + bool res = HdfRemoteServiceSetInterfaceDesc(sampleService, TEST_SERVICE_INTERFACE_DESC); + ASSERT_EQ(res, true); struct ServiceStatusData ssd; struct ServiceStatusListener *listener = HdiServiceStatusListenerNewInstance(); @@ -422,9 +454,10 @@ HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest009, TestSize.Level1) struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); ASSERT_TRUE(data != nullptr); ASSERT_TRUE(reply != nullptr); - - ret = HdfSbufWriteString(data, info.data()); - ASSERT_TRUE(ret); + res = HdfRemoteServiceWriteInterfaceToken(sampleService, data); + ASSERT_EQ(res, true); + res = HdfSbufWriteString(data, info.data()); + ASSERT_TRUE(res); ssd.callbacked = false; ssd.waitStatus = SERVIE_STATUS_CHANGE; diff --git a/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp b/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp index 15b2e95..3a648db 100644 --- a/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp +++ b/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp @@ -22,8 +22,9 @@ #include #include #include +#include #include -#include "osal_time.h" + #include "sample_hdi.h" #define HDF_LOG_TAG service_manager_test_cpp @@ -39,11 +40,12 @@ using OHOS::HDI::ServiceManager::V1_0::IServiceManager; using OHOS::HDI::ServiceManager::V1_0::IServStatListener; using OHOS::HDI::ServiceManager::V1_0::ServiceStatus; using OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub; -constexpr const char *TEST_SERVICE_NAME = "sample_driver_service"; -constexpr int PAYLOAD_NUM = 1234; -constexpr int SMQ_TEST_QUEUE_SIZE = 10; -constexpr int SMQ_TEST_WAIT_TIME = 100; -constexpr int WAIT_LOAD_UNLOAD_TIME = 300; +static constexpr const char *TEST_SERVICE_NAME = "sample_driver_service"; +static constexpr const char16_t *TEST_SERVICE_INTERFACE_DESC = u"hdf.test.sampele_service"; +static constexpr int PAYLOAD_NUM = 1234; +static constexpr int SMQ_TEST_QUEUE_SIZE = 10; +static constexpr int SMQ_TEST_WAIT_TIME = 100; +static constexpr int WAIT_LOAD_UNLOAD_TIME = 300; class HdfServiceMangerHdiTest : public testing::Test { public: @@ -87,6 +89,8 @@ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest002, TestSize.Level1) OHOS::MessageParcel data; OHOS::MessageParcel reply; + bool ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC); + ASSERT_EQ(ret, true); data.WriteCString("sample_service test call"); OHOS::MessageOption option; @@ -124,6 +128,8 @@ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest003, TestSize.Level1) OHOS::MessageParcel data; OHOS::MessageParcel reply; int32_t payload = PAYLOAD_NUM; + bool ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC); + ASSERT_EQ(ret, true); data.WriteInt32(payload); data.WriteRemoteObject(callback); @@ -143,6 +149,8 @@ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest004, TestSize.Level1) OHOS::MessageParcel data; OHOS::MessageParcel reply; + bool ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC); + ASSERT_EQ(ret, true); data.WriteInt32(PAYLOAD_NUM); data.WriteInt32(PAYLOAD_NUM); @@ -170,8 +178,9 @@ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest006, TestSize.Level1) for (int i = 0; i < buffersize; i++) { dataBuffer[i] = i; } - - bool ret = data.WriteUnpadBuffer(dataBuffer, sizeof(dataBuffer)); + bool ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC); + ASSERT_EQ(ret, true); + ret = data.WriteUnpadBuffer(dataBuffer, sizeof(dataBuffer)); ASSERT_TRUE(ret); OHOS::MessageOption option; @@ -210,7 +219,8 @@ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest007, TestSize.Level1) OHOS::MessageParcel data; OHOS::MessageParcel reply; OHOS::MessageOption option; - + ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC); + ASSERT_EQ(ret, true); const char *newServName = "sample_driver_service2"; ret = data.WriteCString(newServName); ASSERT_TRUE(ret); @@ -223,6 +233,8 @@ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest007, TestSize.Level1) data.FlushBuffer(); reply.FlushBuffer(); + ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC); + ASSERT_EQ(ret, true); data.WriteInt32(PAYLOAD_NUM); data.WriteInt32(PAYLOAD_NUM); @@ -236,6 +248,8 @@ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest007, TestSize.Level1) data.FlushBuffer(); reply.FlushBuffer(); + ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC); + ASSERT_EQ(ret, true); data.WriteCString(newServName); status = sampleService->SendRequest(SAMPLE_UNREGISTER_DEVICE, data, reply, option); @@ -254,9 +268,7 @@ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest007, TestSize.Level1) class ServStatListener : public OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub { public: using StatusCallback = std::function; - explicit ServStatListener(StatusCallback callback) : callback_(std::move(callback)) - { - } + explicit ServStatListener(StatusCallback callback) : callback_(std::move(callback)) {} ~ServStatListener() = default; void OnReceive(const ServiceStatus &status) override { @@ -367,6 +379,8 @@ void HdfServiceMangerHdiTest::TestSampleService(sptr& sampleServi OHOS::MessageParcel data; OHOS::MessageParcel reply; OHOS::MessageOption option; + bool res = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC); + ASSERT_EQ(res, true); std::string info = "foo"; data.WriteCString(info.data()); callbacked = false; @@ -489,11 +503,12 @@ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest011, TestSize.Level1) OHOS::MessageParcel data; OHOS::MessageParcel reply; OHOS::MessageOption option; - std::unique_ptr> smq - = std::make_unique>(SMQ_TEST_QUEUE_SIZE, SmqType::SYNCED_SMQ); + std::unique_ptr> smq = + std::make_unique>(SMQ_TEST_QUEUE_SIZE, SmqType::SYNCED_SMQ); ASSERT_TRUE(smq->IsGood()); - - auto ret = smq->GetMeta()->Marshalling(data); + bool ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC); + ASSERT_EQ(ret, true); + ret = smq->GetMeta()->Marshalling(data); ASSERT_TRUE(ret); data.WriteUint32(1); @@ -502,7 +517,7 @@ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest011, TestSize.Level1) constexpr int SEND_TIMES = 20; for (size_t i = 0; i < SEND_TIMES; i++) { - SampleSmqElement t = { 0 }; + SampleSmqElement t = {0}; t.data32 = i; t.data64 = i + 1; @@ -526,13 +541,13 @@ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest012, TestSize.Level1) OHOS::MessageParcel data; OHOS::MessageParcel reply; OHOS::MessageOption option; - std::unique_ptr> smq - = std::make_unique>(SMQ_TEST_QUEUE_SIZE, SmqType::SYNCED_SMQ); + std::unique_ptr> smq = + std::make_unique>(SMQ_TEST_QUEUE_SIZE, SmqType::SYNCED_SMQ); ASSERT_TRUE(smq->IsGood()); - + bool ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC); + ASSERT_EQ(ret, true); constexpr uint32_t ELEMENT_SIZE = 2; - - auto ret = smq->GetMeta()->Marshalling(data); + ret = smq->GetMeta()->Marshalling(data); ASSERT_TRUE(ret); data.WriteUint32(ELEMENT_SIZE); @@ -567,13 +582,13 @@ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest013, TestSize.Level1) OHOS::MessageParcel reply; OHOS::MessageOption option; - std::unique_ptr> smq - = std::make_unique>(SMQ_TEST_QUEUE_SIZE, SmqType::UNSYNC_SMQ); + std::unique_ptr> smq = + std::make_unique>(SMQ_TEST_QUEUE_SIZE, SmqType::UNSYNC_SMQ); ASSERT_TRUE(smq->IsGood()); - + bool ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC); + ASSERT_EQ(ret, true); constexpr uint32_t ELEMENT_SIZE = 2; - - auto ret = smq->GetMeta()->Marshalling(data); + ret = smq->GetMeta()->Marshalling(data); ASSERT_TRUE(ret); data.WriteUint32(ELEMENT_SIZE); auto status = sampleService->SendRequest(SAMPLE_TRANS_SMQ, data, reply, option); diff --git a/uhdf2/host/src/devhost_service_full.c b/uhdf2/host/src/devhost_service_full.c index 4d0f1a2..a01ab4b 100644 --- a/uhdf2/host/src/devhost_service_full.c +++ b/uhdf2/host/src/devhost_service_full.c @@ -158,6 +158,7 @@ static int DevHostServiceFullStartService(struct IDevHostService *service) int ret = DevmgrServiceClntAttachDeviceHost(hostService->hostId, service); if (ret != HDF_SUCCESS) { + HDF_LOGE("failed to start host service, attach host error %{public}d", ret); return ret; } diff --git a/uhdf2/host/src/device_service_stub.c b/uhdf2/host/src/device_service_stub.c index 78267aa..9f39a5e 100644 --- a/uhdf2/host/src/device_service_stub.c +++ b/uhdf2/host/src/device_service_stub.c @@ -71,6 +71,11 @@ int DeviceServiceStubPublishService(struct HdfDeviceNode *service) } do { + if (service->interfaceDesc != NULL && + !HdfRemoteServiceSetInterfaceDesc(fullService->remote, service->interfaceDesc)) { + HDF_LOGE("failed to set device service interface desc"); + break; + } struct DevSvcManagerClnt *serviceManager = DevSvcManagerClntGetInstance(); if (serviceManager == NULL) { HDF_LOGE("device service stub failed to publish, svcmgr clnt invalid"); @@ -138,3 +143,12 @@ void DeviceServiceStubRelease(struct HdfObject *object) } } +bool HdfDeviceObjectCheckInterfaceDesc(struct HdfDeviceObject *dev, struct HdfSBuf *data) +{ + if (dev == NULL || data == NULL) { + return false; + } + struct HdfDeviceNode *devNode = CONTAINER_OF(dev, struct HdfDeviceNode, deviceObject); + struct DeviceServiceStub *instance = (struct DeviceServiceStub *)devNode; + return HdfRemoteServiceCheckInterfaceToken(instance->remote, data); +} \ No newline at end of file diff --git a/uhdf2/host/src/devmgr_service_proxy.c b/uhdf2/host/src/devmgr_service_proxy.c index 49def50..23af0b7 100644 --- a/uhdf2/host/src/devmgr_service_proxy.c +++ b/uhdf2/host/src/devmgr_service_proxy.c @@ -15,9 +15,9 @@ #include "devmgr_service_proxy.h" #include "devhost_service_stub.h" -#include "devmgr_service_stub.h" #include "device_token_stub.h" #include "devmgr_service.h" +#include "devmgr_service_stub.h" #include "devsvc_manager_clnt.h" #include "hdf_base.h" #include "hdf_log.h" @@ -26,8 +26,7 @@ #define HDF_LOG_TAG devmgr_service_proxy -int DevmgrServiceProxyAttachDeviceHost( - struct IDevmgrService *inst, uint16_t hostId, struct IDevHostService *service) +int DevmgrServiceProxyAttachDeviceHost(struct IDevmgrService *inst, uint16_t hostId, struct IDevHostService *service) { int status = HDF_FAILURE; struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); @@ -38,15 +37,19 @@ int DevmgrServiceProxyAttachDeviceHost( struct DevHostServiceStub *hostStub = (struct DevHostServiceStub *)service; if ((serviceProxy->remote == NULL) || (data == NULL) || (reply == NULL)) { HDF_LOGE("DevmgrServiceProxyAttachDeviceHost failed, host id is %{public}u", hostId); - goto finished; + goto FINISHED; } remoteService = serviceProxy->remote; dipatcher = remoteService->dispatcher; - HdfSbufWriteInt32(data, hostId); - HdfSbufWriteRemoteService(data, hostStub->remote); + if (!HdfRemoteServiceWriteInterfaceToken(remoteService, data) || + !HdfSbufWriteInt32(data, hostId) || + HdfSbufWriteRemoteService(data, hostStub->remote) != HDF_SUCCESS) { + HDF_LOGE("failed to attach host, write sbuf error"); + goto FINISHED; + } status = dipatcher->Dispatch(remoteService, DEVMGR_SERVICE_ATTACH_DEVICE_HOST, data, reply); HDF_LOGI("Attach device host dispatch finish, status is %{public}d", status); -finished: +FINISHED: if (reply != NULL) { HdfSbufRecycle(reply); } @@ -56,22 +59,23 @@ finished: return status; } -int DevmgrServiceProxyAttachDevice( - struct IDevmgrService *inst, struct IHdfDeviceToken *token) +int DevmgrServiceProxyAttachDevice(struct IDevmgrService *inst, struct IHdfDeviceToken *token) { int status = HDF_FAILURE; struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); struct DevmgrServiceProxy *serviceProxy = (struct DevmgrServiceProxy *)inst; - if (serviceProxy == NULL || serviceProxy->remote == NULL || data == NULL || - reply == NULL || token == NULL) { + if (serviceProxy == NULL || serviceProxy->remote == NULL || data == NULL || reply == NULL || token == NULL) { HDF_LOGE("DevmgrServiceProxyAttachDevice failed"); - goto finished; + goto FINISHED; } struct HdfRemoteService *remoteService = serviceProxy->remote; - HdfSbufWriteInt32(data, token->devid); + if (!HdfRemoteServiceWriteInterfaceToken(remoteService, data) || !HdfSbufWriteInt32(data, token->devid)) { + goto FINISHED; + } + status = remoteService->dispatcher->Dispatch(remoteService, DEVMGR_SERVICE_ATTACH_DEVICE, data, reply); -finished: +FINISHED: if (reply != NULL) { HdfSbufRecycle(reply); } @@ -89,12 +93,15 @@ int DevmgrServiceProxyDetachDevice(struct IDevmgrService *inst, devid_t devid) struct DevmgrServiceProxy *serviceProxy = (struct DevmgrServiceProxy *)inst; if (serviceProxy == NULL || serviceProxy->remote == NULL || data == NULL || reply == NULL) { HDF_LOGE("DevmgrServiceProxyDetachDevice failed"); - goto finished; + goto FINISHED; } struct HdfRemoteService *remoteService = serviceProxy->remote; - HdfSbufWriteInt32(data, devid); + if (!HdfRemoteServiceWriteInterfaceToken(remoteService, data) || !HdfSbufWriteInt32(data, devid)) { + goto FINISHED; + } + status = remoteService->dispatcher->Dispatch(remoteService, DEVMGR_SERVICE_DETACH_DEVICE, data, reply); -finished: +FINISHED: if (reply != NULL) { HdfSbufRecycle(reply); } @@ -103,9 +110,8 @@ finished: } return status; } -int DevmgrServiceProxyLoadDevice(struct IDevmgrService *inst, const char *svcName) +int DevmgrServiceProxyLoadDevice(struct IDevmgrService *inst, const char *svcName) { - int status = HDF_FAILURE; struct DevmgrServiceProxy *serviceProxy = (struct DevmgrServiceProxy *)inst; if (serviceProxy == NULL || serviceProxy->remote == NULL || svcName == NULL) { HDF_LOGE("DevmgrServiceProxyLoadDevice failed"); @@ -114,17 +120,18 @@ int DevmgrServiceProxyLoadDevice(struct IDevmgrService *inst, const char *svcNa struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); struct HdfRemoteService *remoteService = serviceProxy->remote; - HdfSbufWriteString(data, svcName); - - status = remoteService->dispatcher->Dispatch(remoteService, DEVMGR_SERVICE_LOAD_DEVICE, data, NULL); + if (!HdfRemoteServiceWriteInterfaceToken(remoteService, data) || !HdfSbufWriteString(data, svcName)) { + HdfSbufRecycle(data); + return HDF_FAILURE; + } + int status = remoteService->dispatcher->Dispatch(remoteService, DEVMGR_SERVICE_LOAD_DEVICE, data, NULL); HdfSbufRecycle(data); return status; } -int DevmgrServiceProxyUnLoadDevice(struct IDevmgrService *inst, const char *svcName) +int DevmgrServiceProxyUnLoadDevice(struct IDevmgrService *inst, const char *svcName) { - int status = HDF_FAILURE; struct DevmgrServiceProxy *serviceProxy = (struct DevmgrServiceProxy *)inst; if (serviceProxy == NULL || serviceProxy->remote == NULL || svcName == NULL) { HDF_LOGE("DevmgrServiceProxyLoadDevice failed"); @@ -133,9 +140,12 @@ int DevmgrServiceProxyUnLoadDevice(struct IDevmgrService *inst, const char *svc struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); struct HdfRemoteService *remoteService = serviceProxy->remote; - HdfSbufWriteString(data, svcName); + if (!HdfRemoteServiceWriteInterfaceToken(remoteService, data) || !HdfSbufWriteString(data, svcName)) { + HdfSbufRecycle(data); + return HDF_FAILURE; + } - status = remoteService->dispatcher->Dispatch(remoteService, DEVMGR_SERVICE_UNLOAD_DEVICE, data, NULL); + int status = remoteService->dispatcher->Dispatch(remoteService, DEVMGR_SERVICE_UNLOAD_DEVICE, data, NULL); HdfSbufRecycle(data); return status; @@ -152,7 +162,6 @@ static void DevmgrServiceProxyConstruct(struct DevmgrServiceProxy *inst) pvtbl->StartService = NULL; } - static struct IDevmgrService *DevmgrServiceProxyObtain(struct HdfRemoteService *service) { if (service != NULL) { @@ -171,25 +180,31 @@ static struct IDevmgrService *DevmgrServiceProxyObtain(struct HdfRemoteService * struct HdfObject *DevmgrServiceProxyCreate(void) { static struct IDevmgrService *instance = NULL; - if (instance == NULL) { - struct IDevSvcManager *serviceManagerIf = NULL; - struct DevSvcManagerClnt *serviceManager = (struct DevSvcManagerClnt *)DevSvcManagerClntGetInstance(); - if ((serviceManager == NULL) || (serviceManager->devSvcMgrIf == NULL)) { - HDF_LOGE("Fail to Create Service Manager Client"); - return NULL; - } - serviceManagerIf = serviceManager->devSvcMgrIf; - if (serviceManagerIf->GetService == NULL) { - HDF_LOGE("Get Service is not implement!!!"); + if (instance != NULL) { + return (struct HdfObject *)instance; + } + struct IDevSvcManager *serviceManagerIf = NULL; + struct DevSvcManagerClnt *serviceManager = (struct DevSvcManagerClnt *)DevSvcManagerClntGetInstance(); + if ((serviceManager == NULL) || (serviceManager->devSvcMgrIf == NULL)) { + HDF_LOGE("Fail to Create Service Manager Client"); + return NULL; + } + serviceManagerIf = serviceManager->devSvcMgrIf; + if (serviceManagerIf->GetService == NULL) { + HDF_LOGE("Get Service is not implement!!!"); + return NULL; + } + struct HdfRemoteService *remote = + (struct HdfRemoteService *)serviceManagerIf->GetService(serviceManagerIf, DEVICE_MANAGER_SERVICE); + if (remote != NULL) { + if (!HdfRemoteServiceSetInterfaceDesc(remote, "HDI.IDeviceManager.V1_0")) { + HDF_LOGE("%{public}s: failed to init interface desc", __func__); + HdfRemoteServiceRecycle(remote); return NULL; - } else { - struct HdfRemoteService *remote = (struct HdfRemoteService *) - serviceManagerIf->GetService(serviceManagerIf, DEVICE_MANAGER_SERVICE); - if (remote != NULL) { - instance = DevmgrServiceProxyObtain(remote); - } } + instance = DevmgrServiceProxyObtain(remote); } + return (struct HdfObject *)instance; } diff --git a/uhdf2/host/src/devsvc_manager_proxy.c b/uhdf2/host/src/devsvc_manager_proxy.c index 9779693..35b08a7 100644 --- a/uhdf2/host/src/devsvc_manager_proxy.c +++ b/uhdf2/host/src/devsvc_manager_proxy.c @@ -23,8 +23,8 @@ #define HDF_LOG_TAG devsvc_manager_proxy -static int WriteServiceInfo(struct HdfSBuf *data, const char *svcName, - uint16_t devClass, struct HdfDeviceObject *service, const char *servInfo) +static int WriteServiceInfo( + struct HdfSBuf *data, const char *svcName, uint16_t devClass, struct HdfDeviceObject *service, const char *servInfo) { int ret = HDF_FAILURE; if (!HdfSbufWriteString(data, svcName)) { @@ -37,8 +37,8 @@ static int WriteServiceInfo(struct HdfSBuf *data, const char *svcName, return ret; } - struct HdfDeviceNode *devNode = HDF_SLIST_CONTAINER_OF( - struct HdfDeviceObject, service, struct HdfDeviceNode, deviceObject); + struct HdfDeviceNode *devNode = + HDF_SLIST_CONTAINER_OF(struct HdfDeviceObject, service, struct HdfDeviceNode, deviceObject); struct DeviceServiceStub *deviceFullService = (struct DeviceServiceStub *)devNode; if (deviceFullService->remote == NULL) { HDF_LOGE("%{public}s: device service is broken", __func__); @@ -58,8 +58,8 @@ static int WriteServiceInfo(struct HdfSBuf *data, const char *svcName, return HDF_SUCCESS; } -static int DevSvcManagerProxyAddService( struct IDevSvcManager *inst, const char *svcName, - uint16_t devClass, struct HdfDeviceObject *service, const char *servInfo) +static int DevSvcManagerProxyAddService(struct IDevSvcManager *inst, const char *svcName, uint16_t devClass, + struct HdfDeviceObject *service, const char *servInfo) { struct DevSvcManagerProxy *serviceProxy = (struct DevSvcManagerProxy *)inst; if (service == NULL || svcName == NULL) { @@ -84,11 +84,12 @@ static int DevSvcManagerProxyAddService( struct IDevSvcManager *inst, const c HDF_LOGE("Add service failed, failed to obtain sbuf"); break; } - if (WriteServiceInfo(data, svcName, devClass, service, servInfo) != HDF_SUCCESS) { + if (!HdfRemoteServiceWriteInterfaceToken(serviceProxy->remote, data) || + WriteServiceInfo(data, svcName, devClass, service, servInfo) != HDF_SUCCESS) { break; } - status = serviceProxy->remote->dispatcher->Dispatch( - serviceProxy->remote, DEVSVC_MANAGER_ADD_SERVICE, data, reply); + status = + serviceProxy->remote->dispatcher->Dispatch(serviceProxy->remote, DEVSVC_MANAGER_ADD_SERVICE, data, reply); HDF_LOGI("servmgr add service %{public}s, result is %{public}d", svcName, status); } while (0); @@ -101,8 +102,8 @@ static int DevSvcManagerProxyAddService( struct IDevSvcManager *inst, const c return status; } -static int DevSvcManagerProxyUpdateService( struct IDevSvcManager *inst, const char *svcName, - uint16_t devClass, struct HdfDeviceObject *service, const char *servInfo) +static int DevSvcManagerProxyUpdateService(struct IDevSvcManager *inst, const char *svcName, uint16_t devClass, + struct HdfDeviceObject *service, const char *servInfo) { struct DevSvcManagerProxy *serviceProxy = (struct DevSvcManagerProxy *)inst; if (service == NULL || svcName == NULL) { @@ -127,7 +128,8 @@ static int DevSvcManagerProxyUpdateService( struct IDevSvcManager *inst, cons HDF_LOGE("Add service failed, failed to obtain sbuf"); break; } - if (WriteServiceInfo(data, svcName, devClass, service, servInfo) != HDF_SUCCESS) { + if (!HdfRemoteServiceWriteInterfaceToken(serviceProxy->remote, data) || + WriteServiceInfo(data, svcName, devClass, service, servInfo) != HDF_SUCCESS) { break; } status = serviceProxy->remote->dispatcher->Dispatch( @@ -152,17 +154,21 @@ struct HdfObject *DevSvcManagerProxyGetService(struct IDevSvcManager *inst, cons struct HdfRemoteDispatcher *dispatcher = NULL; struct HdfRemoteService *remoteService = NULL; struct DevSvcManagerProxy *serviceProxy = (struct DevSvcManagerProxy *)inst; - if ((serviceProxy->remote == NULL) || (data == NULL) || (reply == NULL)) { - HDF_LOGE("Get service failed, serviceProxy->remote or data or reply is null"); - goto FINISHED; - } - dispatcher = serviceProxy->remote->dispatcher; - HdfSbufWriteString(data, svcName); - status = dispatcher->Dispatch(serviceProxy->remote, DEVSVC_MANAGER_GET_SERVICE, data, reply); - if (status == HDF_SUCCESS) { - remoteService = HdfSbufReadRemoteService(reply); - } -FINISHED: + do { + if ((serviceProxy->remote == NULL) || (data == NULL) || (reply == NULL)) { + HDF_LOGE("Get service failed, serviceProxy->remote or data or reply is null"); + break; + } + dispatcher = serviceProxy->remote->dispatcher; + if (!HdfRemoteServiceWriteInterfaceToken(serviceProxy->remote, data) || !HdfSbufWriteString(data, svcName)) { + break; + } + status = dispatcher->Dispatch(serviceProxy->remote, DEVSVC_MANAGER_GET_SERVICE, data, reply); + if (status == HDF_SUCCESS) { + remoteService = HdfSbufReadRemoteService(reply); + } + } while (0); + if (reply != NULL) { HdfSbufRecycle(reply); } @@ -183,16 +189,21 @@ void DevSvcManagerProxyRemoveService(struct IDevSvcManager *inst, const char *sv struct HdfRemoteDispatcher *dispatcher = NULL; struct HdfRemoteService *remoteService = NULL; struct DevSvcManagerProxy *serviceProxy = (struct DevSvcManagerProxy *)inst; - if ((serviceProxy->remote == NULL) || (data == NULL) || (reply == NULL)) { - HDF_LOGE("Remove service failed, serviceProxy->remote or data or reply is null"); - goto FINISHED; - } - remoteService = serviceProxy->remote; - dispatcher = remoteService->dispatcher; - HdfSbufWriteString(data, svcName); - int status = dispatcher->Dispatch(remoteService, DEVSVC_MANAGER_REMOVE_SERVICE, data, reply); - HDF_LOGD("Device service manager proxy remove service status is %{public}d", status); -FINISHED: + + do { + if ((serviceProxy->remote == NULL) || (data == NULL) || (reply == NULL)) { + HDF_LOGE("Remove service failed, serviceProxy->remote or data or reply is null"); + break; + } + remoteService = serviceProxy->remote; + dispatcher = remoteService->dispatcher; + if (!HdfRemoteServiceWriteInterfaceToken(serviceProxy->remote, data) || !HdfSbufWriteString(data, svcName)) { + break; + } + int status = dispatcher->Dispatch(remoteService, DEVSVC_MANAGER_REMOVE_SERVICE, data, reply); + HDF_LOGD("Device service manager proxy remove service status is %{public}d", status); + } while (0); + if (reply != NULL) { HdfSbufRecycle(reply); } @@ -212,8 +223,7 @@ void DevSvcManagerProxyConstruct(struct DevSvcManagerProxy *inst, struct HdfRemo static struct IDevSvcManager *DevSvcManagerProxyObtain(struct HdfRemoteService *remote) { - struct DevSvcManagerProxy *instance = - (struct DevSvcManagerProxy *)OsalMemCalloc(sizeof(struct DevSvcManagerProxy)); + struct DevSvcManagerProxy *instance = (struct DevSvcManagerProxy *)OsalMemCalloc(sizeof(struct DevSvcManagerProxy)); if (instance != NULL) { DevSvcManagerProxyConstruct(instance, remote); } @@ -226,6 +236,11 @@ struct HdfObject *DevSvcManagerProxyCreate() if (instance == NULL) { struct HdfRemoteService *remote = HdfRemoteServiceGet(DEVICE_SERVICE_MANAGER_SA_ID); if (remote != NULL) { + if (!HdfRemoteServiceSetInterfaceDesc(remote, "HDI.IServiceManager.V1_0")) { + HDF_LOGE("%{public}s: failed to init interface desc", __func__); + HdfRemoteServiceRecycle(remote); + return NULL; + } instance = DevSvcManagerProxyObtain(remote); } } diff --git a/uhdf2/host/test/unittest/sample_driver/sample_driver.cpp b/uhdf2/host/test/unittest/sample_driver/sample_driver.cpp index 410429d..d0f535f 100644 --- a/uhdf2/host/test/unittest/sample_driver/sample_driver.cpp +++ b/uhdf2/host/test/unittest/sample_driver/sample_driver.cpp @@ -40,6 +40,11 @@ static int HdfSampleDriverBind(struct HdfDeviceObject *deviceObject) .Dispatch = SampleServiceDispatch, .Release = nullptr, }; + int ret = HdfDeviceObjectSetInterfaceDesc(deviceObject, "hdf.test.sampele_service"); + if (ret != HDF_SUCCESS) { + HDF_LOGE("failed to set interface desc"); + return ret; + } deviceObject->service = &testService; return HDF_SUCCESS; } diff --git a/uhdf2/host/test/unittest/sample_driver/sample_hdi_service_stub.cpp b/uhdf2/host/test/unittest/sample_driver/sample_hdi_service_stub.cpp index fa59a49..355d937 100644 --- a/uhdf2/host/test/unittest/sample_driver/sample_hdi_service_stub.cpp +++ b/uhdf2/host/test/unittest/sample_driver/sample_hdi_service_stub.cpp @@ -14,9 +14,11 @@ */ #include +#include #include #include #include + #include "hdf_sbuf_ipc.h" #include "sample_hdi.h" @@ -24,6 +26,9 @@ using OHOS::HDI::Base::SharedMemQueueMeta; static int32_t SampleServiceStubPing(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { + if (!HdfDeviceObjectCheckInterfaceDesc(client->device, data)) { + return HDF_ERR_INVALID_PARAM; + } char *outInfo = NULL; const char *info = HdfSbufReadString(data); @@ -39,7 +44,9 @@ static int32_t SampleServiceStubSum(struct HdfDeviceIoClient *client, struct Hdf int32_t parm0; int32_t parm1; int32_t result; - + if (!HdfDeviceObjectCheckInterfaceDesc(client->device, data)) { + return HDF_ERR_INVALID_PARAM; + } if (!HdfSbufReadInt32(data, &parm0)) { HDF_LOGE("SampleHdi.sum: miss parm0"); return HDF_ERR_INVALID_PARAM; @@ -64,6 +71,9 @@ static int32_t SampleServiceStubSum(struct HdfDeviceIoClient *client, struct Hdf static int32_t SampleServiceStubCallback(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { int32_t code; + if (!HdfDeviceObjectCheckInterfaceDesc(client->device, data)) { + return HDF_ERR_INVALID_PARAM; + } if (!HdfSbufReadInt32(data, &code)) { HDF_LOGE("SampleHdi.callback: miss parameter code"); return HDF_ERR_INVALID_PARAM; @@ -81,6 +91,9 @@ static int32_t SampleServiceStubStructTrans( struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { HDF_LOGI("SampleServiceStubStructTrans: in"); + if (!HdfDeviceObjectCheckInterfaceDesc(client->device, data)) { + return HDF_ERR_INVALID_PARAM; + } struct DataBlock *dataBlock = DataBlockBlockUnmarshalling(data); if (dataBlock == NULL) { HDF_LOGE("SampleServiceStubStructTrans: failed to read dataBlock"); @@ -102,7 +115,9 @@ static int32_t SampleServiceStubBufferTrans( struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { HDF_LOGI("SampleServiceStubBufferTrans: in"); - + if (!HdfDeviceObjectCheckInterfaceDesc(client->device, data)) { + return HDF_ERR_INVALID_PARAM; + } constexpr int SAMPLE_TEST_BUFFER_SIZE = 10; const uint8_t *buffer = HdfSbufReadUnpadBuffer(data, SAMPLE_TEST_BUFFER_SIZE); if (buffer == NULL) { @@ -123,6 +138,9 @@ static int32_t SampleServiceStubBufferTrans( static int32_t SampleServiceRegisterDevice( struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { + if (!HdfDeviceObjectCheckInterfaceDesc(client->device, data)) { + return HDF_ERR_INVALID_PARAM; + } (void)reply; const char *deviceName = HdfSbufReadString(data); if (deviceName == NULL) { @@ -136,6 +154,9 @@ static int32_t SampleServiceUnregisterDevice( struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { (void)reply; + if (!HdfDeviceObjectCheckInterfaceDesc(client->device, data)) { + return HDF_ERR_INVALID_PARAM; + } const char *deviceName = HdfSbufReadString(data); if (deviceName == NULL) { return HDF_ERR_INVALID_PARAM; @@ -146,6 +167,9 @@ static int32_t SampleServiceUnregisterDevice( static int32_t SampleServiceUpdateDevice(struct HdfDeviceIoClient *client, struct HdfSBuf *data) { + if (!HdfDeviceObjectCheckInterfaceDesc(client->device, data)) { + return HDF_ERR_INVALID_PARAM; + } const char *servInfo = HdfSbufReadString(data); if (servInfo == NULL) { return HDF_ERR_INVALID_PARAM; @@ -156,6 +180,9 @@ static int32_t SampleServiceUpdateDevice(struct HdfDeviceIoClient *client, struc static int32_t SampleServiceSmqTrans(struct HdfDeviceIoClient *client, struct HdfSBuf *data) { + if (!HdfDeviceObjectCheckInterfaceDesc(client->device, data)) { + return HDF_ERR_INVALID_PARAM; + } OHOS::MessageParcel *parcel = nullptr; if (SbufToParcel(data, &parcel) != HDF_SUCCESS) { return HDF_FAILURE; diff --git a/uhdf2/ipc/include/hdf_remote_adapter.h b/uhdf2/ipc/include/hdf_remote_adapter.h index 1931539..2be3b4c 100644 --- a/uhdf2/ipc/include/hdf_remote_adapter.h +++ b/uhdf2/ipc/include/hdf_remote_adapter.h @@ -18,8 +18,10 @@ #include #include -#include "hdf_remote_service.h" +#include + #include "hdf_remote_adapter_if.h" +#include "hdf_remote_service.h" #ifdef __cplusplus extern "C" { @@ -48,6 +50,9 @@ private: struct HdfRemoteServiceHolder { HdfRemoteServiceHolder(); + ~HdfRemoteServiceHolder() = default; + + bool SetInterfaceDescriptor(const char *desc); struct HdfRemoteService service_; OHOS::sptr remote_; OHOS::sptr deathRecipient_; diff --git a/uhdf2/ipc/include/hdf_remote_adapter_if.h b/uhdf2/ipc/include/hdf_remote_adapter_if.h index 742c584..979faf0 100644 --- a/uhdf2/ipc/include/hdf_remote_adapter_if.h +++ b/uhdf2/ipc/include/hdf_remote_adapter_if.h @@ -38,6 +38,13 @@ void HdfRemoteAdapterAddDeathRecipient(struct HdfRemoteService *service, struct void HdfRemoteAdapterRemoveDeathRecipient(struct HdfRemoteService *service, struct HdfDeathRecipient *recipient); +bool HdfRemoteAdapterSetInterfaceDesc(struct HdfRemoteService *service, const char *descriptor); + +bool HdfRemoteAdapterWriteInterfaceToken(struct HdfRemoteService *service, struct HdfSBuf *data); + +bool HdfRemoteAdapterCheckInterfaceToken(struct HdfRemoteService *service, struct HdfSBuf *data); + + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/uhdf2/ipc/src/hdf_remote_adapter.cpp b/uhdf2/ipc/src/hdf_remote_adapter.cpp index 3533a95..1d6bb21 100644 --- a/uhdf2/ipc/src/hdf_remote_adapter.cpp +++ b/uhdf2/ipc/src/hdf_remote_adapter.cpp @@ -13,14 +13,17 @@ * limitations under the License. */ -#include "hdf_remote_adapter.h" #include #include #include #include + #include "hdf_log.h" #include "hdf_object_manager.h" #include "hdf_sbuf_ipc.h" +#include "hdf_remote_adapter.h" + +#define HDF_LOG_TAG hdf_remote_adapter static constexpr int32_t THREAD_POOL_BASE_THREAD_COUNT = 1; static int32_t g_remoteThreadMax = THREAD_POOL_BASE_THREAD_COUNT; @@ -128,6 +131,21 @@ HdfRemoteServiceHolder::HdfRemoteServiceHolder() : remote_(nullptr), deathRecipi service_.target = nullptr; } +bool HdfRemoteServiceHolder::SetInterfaceDescriptor(const char *desc) +{ + if (remote_ == nullptr || desc == nullptr) { + return false; + } + std::u16string newDesc = OHOS::Str8ToStr16(std::string(desc)); + if (newDesc.empty()) { + HDF_LOGE("failed to set interface des, error on cover str8 to str16, %{public}s", desc); + return false; + } + (const_cast(&remote_->descriptor_))->assign(newDesc); + + return true; +} + void HdfRemoteAdapterAddDeathRecipient( struct HdfRemoteService *service, struct HdfDeathRecipient *recipient) { @@ -280,3 +298,64 @@ struct HdfRemoteService *HdfRemoteAdapterGetSa(int32_t saId) } return nullptr; } + +bool HdfRemoteAdapterSetInterfaceDesc(struct HdfRemoteService *service, const char *desc) +{ + if (service == nullptr || desc == nullptr) { + return false; + } + struct HdfRemoteServiceHolder *holder = reinterpret_cast(service); + return holder->SetInterfaceDescriptor(desc); +} + +bool HdfRemoteAdapterWriteInterfaceToken(struct HdfRemoteService *service, struct HdfSBuf *data) +{ + if (service == nullptr || data == nullptr) { + return false; + } + struct HdfRemoteServiceHolder *holder = reinterpret_cast(service); + OHOS::MessageParcel *parcel = nullptr; + + if (SbufToParcel(data, &parcel) != HDF_SUCCESS) { + HDF_LOGE("failed to write interface token, SbufToParcel error"); + return false; + } + + if (holder->remote_ == nullptr) { + HDF_LOGE("failed to write interface token, holder->remote is nullptr"); + return false; + } + if (holder->remote_->GetObjectDescriptor().empty()) { + HDF_LOGE("failed to write interface token, empty token"); + return false; + } + return parcel->WriteInterfaceToken(holder->remote_->GetObjectDescriptor()); +} + +bool HdfRemoteAdapterCheckInterfaceToken(struct HdfRemoteService *service, struct HdfSBuf *data) +{ + if (service == nullptr || data == nullptr) { + return false; + } + struct HdfRemoteServiceHolder *holder = reinterpret_cast(service); + if (holder == nullptr || holder->remote_ == nullptr) { + return false; + } + OHOS::MessageParcel *parcel = nullptr; + + if (SbufToParcel(data, &parcel) != HDF_SUCCESS) { + return false; + } + auto desc = parcel->ReadInterfaceToken(); + if (desc.empty()) { + HDF_LOGE("failed to check interface, empty token"); + return false; + } + if (holder->remote_->GetObjectDescriptor() != desc) { + std::string descStr8 = OHOS::Str16ToStr8(desc); + HDF_LOGE("calling unknown interface: %{public}s", descStr8.c_str()); + return false; + } + + return true; +} diff --git a/uhdf2/ipc/src/hdf_remote_service.c b/uhdf2/ipc/src/hdf_remote_service.c index acb2fd4..952eec7 100644 --- a/uhdf2/ipc/src/hdf_remote_service.c +++ b/uhdf2/ipc/src/hdf_remote_service.c @@ -52,3 +52,19 @@ int HdfRemoteServiceRegister(int32_t serviceId, struct HdfRemoteService *service { return HdfRemoteAdapterAddSa(serviceId, service); } + +bool HdfRemoteServiceSetInterfaceDesc(struct HdfRemoteService *service, const char *descriptor) +{ + return HdfRemoteAdapterSetInterfaceDesc(service, descriptor); +} + +bool HdfRemoteServiceWriteInterfaceToken(struct HdfRemoteService *service, struct HdfSBuf *data) +{ + return HdfRemoteAdapterWriteInterfaceToken(service, data); +} + +bool HdfRemoteServiceCheckInterfaceToken(struct HdfRemoteService *service, struct HdfSBuf *data) +{ + return HdfRemoteAdapterCheckInterfaceToken(service, data); +} + diff --git a/uhdf2/manager/src/devmgr_service_stub.c b/uhdf2/manager/src/devmgr_service_stub.c index ba1c239..38abb5b 100644 --- a/uhdf2/manager/src/devmgr_service_stub.c +++ b/uhdf2/manager/src/devmgr_service_stub.c @@ -90,10 +90,13 @@ int32_t DevmgrServiceStubDispatch(struct HdfRemoteService *stub, int code, struc return HDF_ERR_INVALID_PARAM; } struct IDevmgrService *super = (struct IDevmgrService *)&serviceStub->super; - HDF_LOGE("%{public}s devmgr service stub dispatch cmd %{public}d", __func__, code); + if (!HdfRemoteServiceCheckInterfaceToken(serviceStub->remote, data)) { + HDF_LOGE("%{public}s: invalid interface token, code=%{public}d", __func__, code); + return HDF_ERR_INVALID_PARAM; + } + uint32_t hostId = 0; switch (code) { - case DEVMGR_SERVICE_ATTACH_DEVICE_HOST: { - uint32_t hostId = 0; + case DEVMGR_SERVICE_ATTACH_DEVICE_HOST: if (!HdfSbufReadUint32(data, &hostId)) { HDF_LOGE("invalid host id"); return HDF_FAILURE; @@ -102,27 +105,21 @@ int32_t DevmgrServiceStubDispatch(struct HdfRemoteService *stub, int code, struc struct IDevHostService *hostIf = DevHostServiceProxyObtain(hostId, service); ret = super->AttachDeviceHost(super, hostId, hostIf); break; - } - case DEVMGR_SERVICE_ATTACH_DEVICE: { + case DEVMGR_SERVICE_ATTACH_DEVICE: ret = DevmgrServiceStubDispatchAttachDevice(super, data); break; - } - case DEVMGR_SERVICE_DETACH_DEVICE: { + case DEVMGR_SERVICE_DETACH_DEVICE: ret = DevmgrServiceStubDispatchDetachDevice(super, data); break; - } - case DEVMGR_SERVICE_LOAD_DEVICE: { + case DEVMGR_SERVICE_LOAD_DEVICE: ret = DevmgrServiceStubDispatchLoadDevice(super, data); break; - } - case DEVMGR_SERVICE_UNLOAD_DEVICE: { + case DEVMGR_SERVICE_UNLOAD_DEVICE: ret = DevmgrServiceStubDispatchUnloadDevice(super, data); break; - } - case DEVMGR_SERVICE_QUERY_DEVICE: { + case DEVMGR_SERVICE_QUERY_DEVICE: ret = DevFillQueryDeviceInfo(super, data, reply); break; - } default: break; } @@ -172,7 +169,7 @@ static int32_t MakeModulePath(char *buffer, const char *moduleName) char *path = realpath(temp, buffer); if (path == NULL || strncmp(path, HDF_MODULE_DIR, strlen(HDF_MODULE_DIR)) != 0) { - HDF_LOGI("driver module file is invalud: %{public}s", temp); + HDF_LOGE("driver module file is invalud: %{public}s", temp); return HDF_ERR_INVALID_PARAM; } @@ -248,6 +245,11 @@ int DevmgrServiceStubStartService(struct IDevmgrService *inst) HDF_LOGI("failed to start devmgr, remoteService obtain err"); return HDF_ERR_MALLOC_FAIL; } + if (!HdfRemoteServiceSetInterfaceDesc(remoteService, "HDI.IDeviceManager.V1_0")) { + HDF_LOGE("%{public}s: failed to init interface desc", __func__); + HdfRemoteServiceRecycle(remoteService); + return HDF_FAILURE; + } struct HdfDeviceObject *deviceObject = OsalMemCalloc(sizeof(struct HdfDeviceObject)); if (deviceObject == NULL) { HdfRemoteServiceRecycle(remoteService); diff --git a/uhdf2/manager/src/devsvc_manager_stub.c b/uhdf2/manager/src/devsvc_manager_stub.c index 1b42f96..362a073 100644 --- a/uhdf2/manager/src/devsvc_manager_stub.c +++ b/uhdf2/manager/src/devsvc_manager_stub.c @@ -67,6 +67,10 @@ static int32_t DevSvcManagerStubAddService(struct IDevSvcManager *super, struct { int ret = HDF_FAILURE; struct DevSvcManagerStub *stub = (struct DevSvcManagerStub *)super; + if (!HdfRemoteServiceCheckInterfaceToken(stub->remote, data)) { + HDF_LOGE("%{public}s: invalid interface token", __func__); + return HDF_ERR_INVALID_PARAM; + } const char *name = HdfSbufReadString(data); if (name == NULL) { HDF_LOGE("%{public}s failed, name is null", __func__); @@ -104,6 +108,10 @@ static int32_t DevSvcManagerStubUpdateService(struct IDevSvcManager *super, stru { int ret = HDF_FAILURE; struct DevSvcManagerStub *stub = (struct DevSvcManagerStub *)super; + if (!HdfRemoteServiceCheckInterfaceToken(stub->remote, data)) { + HDF_LOGE("%{public}s: invalid interface token", __func__); + return HDF_ERR_INVALID_PARAM; + } const char *name = HdfSbufReadString(data); if (name == NULL) { HDF_LOGE("%{public}s failed, name is null", __func__); @@ -146,6 +154,11 @@ static int32_t DevSvcManagerStubUpdateService(struct IDevSvcManager *super, stru static int32_t DevSvcManagerStubGetService(struct IDevSvcManager *super, struct HdfSBuf *data, struct HdfSBuf *reply) { int ret = HDF_FAILURE; + struct DevSvcManagerStub *stub = (struct DevSvcManagerStub *)super; + if (!HdfRemoteServiceCheckInterfaceToken(stub->remote, data)) { + HDF_LOGE("%{public}s: invalid interface token", __func__); + return HDF_ERR_INVALID_PARAM; + } const char *name = HdfSbufReadString(data); if (name == NULL) { HDF_LOGE("%{public}s failed, name is null", __func__); @@ -165,6 +178,11 @@ static int32_t DevSvcManagerStubGetService(struct IDevSvcManager *super, struct static int32_t DevSvcManagerStubRemoveService(struct IDevSvcManager *super, struct HdfSBuf *data) { + struct DevSvcManagerStub *stub = (struct DevSvcManagerStub *)super; + if (!HdfRemoteServiceCheckInterfaceToken(stub->remote, data)) { + HDF_LOGE("%{public}s: invalid interface token", __func__); + return HDF_ERR_INVALID_PARAM; + } const char *name = HdfSbufReadString(data); if (name == NULL) { HDF_LOGE("%{public}s failed, name is null", __func__); @@ -190,12 +208,16 @@ static int32_t DevSvcManagerStubRemoveService(struct IDevSvcManager *super, stru super->RemoveService(super, name); HDF_LOGI("service %{public}s removed", name); - struct DevSvcManagerStub *stub = (struct DevSvcManagerStub *)super; ReleaseServiceObject(stub, serviceObject); return HDF_SUCCESS; } static int32_t DevSvcManagerStubRegisterServListener(struct IDevSvcManager *super, struct HdfSBuf *data) { + struct DevSvcManagerStub *stub = (struct DevSvcManagerStub *)super; + if (!HdfRemoteServiceCheckInterfaceToken(stub->remote, data)) { + HDF_LOGE("%{public}s: invalid interface token", __func__); + return HDF_ERR_INVALID_PARAM; + } uint16_t listenClass = DEVICE_CLASS_DEFAULT; if (!HdfSbufReadUint16(data, &listenClass)) { return HDF_ERR_INVALID_PARAM; @@ -223,6 +245,11 @@ static int32_t DevSvcManagerStubRegisterServListener(struct IDevSvcManager *supe static int32_t DevSvcManagerStubUnregisterServListener(struct IDevSvcManager *super, struct HdfSBuf *data) { + struct DevSvcManagerStub *stub = (struct DevSvcManagerStub *)super; + if (!HdfRemoteServiceCheckInterfaceToken(stub->remote, data)) { + HDF_LOGE("%{public}s: invalid interface token", __func__); + return HDF_ERR_INVALID_PARAM; + } struct HdfRemoteService *listenerRemote = HdfSbufReadRemoteService(data); if (listenerRemote == NULL) { return HDF_ERR_INVALID_PARAM; @@ -249,6 +276,7 @@ int DevSvcManagerStubDispatch(struct HdfRemoteService *service, int code, struct return ret; } struct IDevSvcManager *super = (struct IDevSvcManager *)&stub->super; + HDF_LOGD("DevSvcManagerStubDispatch called: code=%{public}d", code); switch (code) { case DEVSVC_MANAGER_ADD_SERVICE: ret = DevSvcManagerStubAddService(super, data); @@ -324,7 +352,11 @@ int DevSvcManagerStubStart(struct IDevSvcManager *svcmgr) inst->remote = HdfRemoteServiceObtain((struct HdfObject *)inst, &dispatcher); if (inst->remote == NULL) { HDF_LOGE("failed to obtain device service manager remote service"); - return false; + return HDF_ERR_MALLOC_FAIL; + } + if (!HdfRemoteServiceSetInterfaceDesc(inst->remote, "HDI.IServiceManager.V1_0")) { + HDF_LOGE("%{public}s: failed to init interface desc", __func__); + return HDF_ERR_INVALID_OBJECT; } inst->recipient.OnRemoteDied = DevSvcManagerOnServiceDied; @@ -337,6 +369,7 @@ int DevSvcManagerStubStart(struct IDevSvcManager *svcmgr) HDF_LOGI("publish device service manager success"); inst->started = true; } + return ret; } diff --git a/uhdf2/manager/src/servstat_listener_holder.c b/uhdf2/manager/src/servstat_listener_holder.c index 16dd5d2..52928d5 100644 --- a/uhdf2/manager/src/servstat_listener_holder.c +++ b/uhdf2/manager/src/servstat_listener_holder.c @@ -71,6 +71,11 @@ int32_t UServStatListenerHolderNotifyStatus(struct ServStatListenerHolder *holde return HDF_ERR_MALLOC_FAIL; } + if (!HdfRemoteServiceWriteInterfaceToken(holderInst->listenerRemote, data)) { + HDF_LOGE("failed to write interface token"); + HdfSbufRecycle(data); + return HDF_FAILURE; + } if (ServiceStatusMarshalling(status, data) != HDF_SUCCESS) { HDF_LOGE("failed to marshalling service status"); HdfSbufRecycle(data); @@ -129,6 +134,11 @@ struct ServStatListenerHolder *ServStatListenerHolderCreate(uintptr_t listener, return NULL; } struct HdfRemoteService *listenerRemote = (struct HdfRemoteService *)listener; + if (!HdfRemoteServiceSetInterfaceDesc(listenerRemote, "HDI.IServiceStatusListener.V1_0")) { + HDF_LOGE("failed to set interface desc to listener"); + OsalMemFree(holder); + return NULL; + } holder->holder.listenClass = listenClass; holder->holder.NotifyStatus = UServStatListenerHolderNotifyStatus; holder->holder.Recycle = UServStatListenerHolderRecycle; diff --git a/uhdf2/shared/include/hdf_remote_service.h b/uhdf2/shared/include/hdf_remote_service.h index cb191ca..db7f079 100644 --- a/uhdf2/shared/include/hdf_remote_service.h +++ b/uhdf2/shared/include/hdf_remote_service.h @@ -52,6 +52,13 @@ int HdfRemoteServiceRegister(int32_t serviceId, struct HdfRemoteService *service struct HdfRemoteService *HdfRemoteServiceGet(int32_t serviceId); +bool HdfRemoteServiceSetInterfaceDesc(struct HdfRemoteService *service, const char *descriptor); + +bool HdfRemoteServiceWriteInterfaceToken(struct HdfRemoteService *service, struct HdfSBuf *data); + +bool HdfRemoteServiceCheckInterfaceToken(struct HdfRemoteService *service, struct HdfSBuf *data); + + #ifdef __cplusplus } #endif /* __cplusplus */ -- Gitee From e451fa7bacb53788e19579fb8a36ad7e0817a724 Mon Sep 17 00:00:00 2001 From: zhang Date: Fri, 4 Mar 2022 16:46:26 +0800 Subject: [PATCH 005/102] =?UTF-8?q?fix=EF=BC=9Aadd=20hdf=20host=20service?= =?UTF-8?q?=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhang --- uhdf2/host/hdf_devhost.cfg | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/uhdf2/host/hdf_devhost.cfg b/uhdf2/host/hdf_devhost.cfg index 7f8ee61..8f39da0 100755 --- a/uhdf2/host/hdf_devhost.cfg +++ b/uhdf2/host/hdf_devhost.cfg @@ -153,6 +153,20 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "root", "gid" : ["system"] + }, + { + "name" : "nfc_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "root", + "gid" : ["system"] + }, + { + "name" : "a2dp_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "root", + "gid" : ["system"] } ] } -- Gitee From 47fda689e4cf889153327fbfb6026e8a22b1221b Mon Sep 17 00:00:00 2001 From: fanxiaoyu Date: Wed, 9 Mar 2022 06:37:31 +0000 Subject: [PATCH 006/102] Description:Delete redundant assign Feature or Bugfix:Bugfix Binary Source: No Signed-off-by: fanxiaoyu --- khdf/liteos/model/misc/dsoftbus/src/softbus_lwip_monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/khdf/liteos/model/misc/dsoftbus/src/softbus_lwip_monitor.c b/khdf/liteos/model/misc/dsoftbus/src/softbus_lwip_monitor.c index 807d9d4..4dc2b97 100644 --- a/khdf/liteos/model/misc/dsoftbus/src/softbus_lwip_monitor.c +++ b/khdf/liteos/model/misc/dsoftbus/src/softbus_lwip_monitor.c @@ -56,7 +56,7 @@ typedef struct { static void ReportEvent(const LwipMonitorReportInfo *reportInfo) { - struct HdfSBuf *data = data = HdfSbufObtainDefaultSize(); + struct HdfSBuf *data = HdfSbufObtainDefaultSize(); if (data == NULL) { dprintf("get sbuf fail\n"); -- Gitee From 400eb7afd914aff524b287faf23d9a098d398b2e Mon Sep 17 00:00:00 2001 From: longxingkai Date: Wed, 9 Mar 2022 15:45:50 +0800 Subject: [PATCH 007/102] fix:hdf pwm compiler failed Signed-off-by: longxingkai --- khdf/liteos_m/platform/BUILD.gn | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/khdf/liteos_m/platform/BUILD.gn b/khdf/liteos_m/platform/BUILD.gn index 6228cc0..7a33e4c 100755 --- a/khdf/liteos_m/platform/BUILD.gn +++ b/khdf/liteos_m/platform/BUILD.gn @@ -64,7 +64,10 @@ hdf_driver("hdf_platform_lite") { } if (defined(LOSCFG_DRIVERS_HDF_PLATFORM_PWM)) { - sources += [ "$HDF_FRAMEWORKS_PATH/support/platform/src/pwm/pwm_core.c" ] + sources += [ + "$HDF_FRAMEWORKS_PATH/support/platform/src/pwm/pwm_core.c", + "$HDF_FRAMEWORKS_PATH/support/platform/src/pwm/pwm_if.c", + ] } if (defined(LOSCFG_DRIVERS_HDF_PLATFORM_RTC)) { -- Gitee From a630b29fc973e3384f91f2bc7d0f8ed3e66134e4 Mon Sep 17 00:00:00 2001 From: lvxuzhou Date: Wed, 9 Mar 2022 23:56:32 -0800 Subject: [PATCH 008/102] modify drivers_adapter/khdf/liteos/model/audio/BUILD.gn Copyright information time Signed-off-by: lvxuzhou --- khdf/liteos/model/audio/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/khdf/liteos/model/audio/BUILD.gn b/khdf/liteos/model/audio/BUILD.gn index 1aa7f9b..0fa972b 100644 --- a/khdf/liteos/model/audio/BUILD.gn +++ b/khdf/liteos/model/audio/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2021 Huawei Device Co., Ltd. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: -- Gitee From d9cb774e7fbddb45ea4b81b503b8dfc5501413c1 Mon Sep 17 00:00:00 2001 From: guodongqi Date: Thu, 10 Mar 2022 15:49:16 +0800 Subject: [PATCH 009/102] fix: clear code warnings of master Signed-off-by: guodongqi --- .../sample_service_c/sample_service_stub.c | 32 +++++++++---------- uhdf2/manager/src/devhost_service_proxy.c | 8 ++--- uhdf2/manager/src/devsvc_manager_stub.c | 16 +++++----- uhdf2/shared/src/dev_attribute_serialize.c | 1 + 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_c/sample_service_stub.c b/uhdf2/hdi/test/hdi_sample/sample_service_c/sample_service_stub.c index d64ec8b..e6afc49 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_service_c/sample_service_stub.c +++ b/uhdf2/hdi/test/hdi_sample/sample_service_c/sample_service_stub.c @@ -307,31 +307,31 @@ static int32_t SerStubListTypeTest(struct HdfDeviceIoClient *client, struct HdfS if (!HdfSbufReadInt8(data, (input + i))) { HDF_LOGE("%{public}s: read data size failed!", __func__); ec = HDF_ERR_INVALID_PARAM; - goto finished; + goto FINISHED; } } ec = HdiSampleImplInstance()->ArrayTypeTest(client->device, input, inSize, &output, &outSize); if (ec != HDF_SUCCESS) { HDF_LOGE("%{public}s: call failed!", __func__); - goto finished; + goto FINISHED; } if (!HdfSbufWriteUint32(reply, outSize)) { HDF_LOGE("%{public}s: write output size failed!", __func__); ec = HDF_ERR_INVALID_PARAM; - goto finished; + goto FINISHED; } - for (uint8_t i = 0; i < outSize; i++) { + for (uint32_t i = 0; i < outSize; i++) { if (!HdfSbufWriteInt8(reply, output[i])) { HDF_LOGE("%{public}s: write output failed!", __func__); ec = HDF_ERR_INVALID_PARAM; - goto finished; + goto FINISHED; } } -finished: +FINISHED: if (input != NULL) { (void)OsalMemFree(input); } @@ -360,31 +360,31 @@ static int32_t SerStubArrayTypeTest(struct HdfDeviceIoClient *client, struct Hdf if (!HdfSbufReadInt8(data, (input + i))) { HDF_LOGE("%{public}s: read data size failed!", __func__); ec = HDF_ERR_INVALID_PARAM; - goto finished; + goto FINISHED; } } ec = HdiSampleImplInstance()->ArrayTypeTest(client->device, input, inSize, &output, &outSize); if (ec != HDF_SUCCESS) { HDF_LOGE("%{public}s: call failed!", __func__); - goto finished; + goto FINISHED; } if (!HdfSbufWriteUint32(reply, outSize)) { HDF_LOGE("%{public}s: write output size failed!", __func__); ec = HDF_ERR_INVALID_PARAM; - goto finished; + goto FINISHED; } - for (uint8_t i = 0; i < outSize; i++) { + for (uint32_t i = 0; i < outSize; i++) { if (!HdfSbufWriteInt8(reply, output[i])) { HDF_LOGE("%{public}s: write output failed!", __func__); ec = HDF_ERR_INVALID_PARAM; - goto finished; + goto FINISHED; } } -finished: +FINISHED: if (input != NULL) { (void)OsalMemFree(input); } @@ -404,20 +404,20 @@ static int32_t SerStubStructTypeTest(struct HdfDeviceIoClient *client, struct Hd if (!HdfSbufReadBuffer(data, (const void **)&input, &dataSize)) { HDF_LOGE("%{public}s: read struct data failed!", __func__); ec = HDF_ERR_INVALID_PARAM; - goto finished; + goto FINISHED; } ec = HdiSampleImplInstance()->StructTypeTest(client->device, input, &output); if (ec != HDF_SUCCESS) { HDF_LOGE("%{public}s: call StructTypeTest failed! error code is %{public}d", __func__, ec); - goto finished; + goto FINISHED; } if (!HdfSbufWriteBuffer(reply, (const void *)&output, sizeof(output))) { HDF_LOGE("%{public}s: struct result write failed", __func__); - goto finished; + goto FINISHED; } -finished: +FINISHED: return ec; } diff --git a/uhdf2/manager/src/devhost_service_proxy.c b/uhdf2/manager/src/devhost_service_proxy.c index ca4f50b..4e2a087 100644 --- a/uhdf2/manager/src/devhost_service_proxy.c +++ b/uhdf2/manager/src/devhost_service_proxy.c @@ -32,12 +32,12 @@ static int32_t DevHostServiceProxyOpsDevice( struct DevHostServiceProxy *hostClnt = (struct DevHostServiceProxy *)inst; if (hostClnt->remote == NULL || data == NULL) { HDF_LOGE("Adding device failed, hostClnt->remote or data or reply is null"); - goto finished; + goto FINISHED; } DeviceAttributeSerialize(attribute, data); status = hostClnt->remote->dispatcher->Dispatch(hostClnt->remote, DEVHOST_SERVICE_ADD_DEVICE, data, NULL); -finished: +FINISHED: if (data != NULL) { HdfSbufRecycle(data); } @@ -58,13 +58,13 @@ static int32_t DevHostServiceProxyDelDevice( struct DevHostServiceProxy *hostClnt = (struct DevHostServiceProxy *)inst; if (hostClnt->remote == NULL || data == NULL) { HDF_LOGE("Del device failed, hostClnt->remote or data is null"); - goto finished; + goto FINISHED; } HdfSbufWriteUint32(data, devid); status = hostClnt->remote->dispatcher->Dispatch(hostClnt->remote, DEVHOST_SERVICE_DEL_DEVICE, data, NULL); -finished: +FINISHED: if (data != NULL) { HdfSbufRecycle(data); } diff --git a/uhdf2/manager/src/devsvc_manager_stub.c b/uhdf2/manager/src/devsvc_manager_stub.c index 362a073..7ad16d8 100644 --- a/uhdf2/manager/src/devsvc_manager_stub.c +++ b/uhdf2/manager/src/devsvc_manager_stub.c @@ -26,8 +26,8 @@ #define HDF_LOG_TAG devsvc_manager_stub -static struct HdfDeviceObject *ObtainServiceObject(struct DevSvcManagerStub *stub, - const char *name, struct HdfRemoteService *service) +static struct HdfDeviceObject *ObtainServiceObject( + struct DevSvcManagerStub *stub, const char *name, struct HdfRemoteService *service) { struct HdfDeviceObject *serviceObject = OsalMemCalloc(sizeof(struct HdfDeviceObject)); if (serviceObject == NULL) { @@ -54,7 +54,7 @@ static void ReleaseServiceObject(struct DevSvcManagerStub *stub, struct HdfDevic HDF_LOGW("release service object has empty name, may broken object"); return; } - struct HdfRemoteService *serviceRemote = (struct HdfRemoteService *) serviceObject->service; + struct HdfRemoteService *serviceRemote = (struct HdfRemoteService *)serviceObject->service; HdfRemoteServiceRemoveDeathRecipient(serviceRemote, &stub->recipient); HdfRemoteServiceRecycle((struct HdfRemoteService *)serviceObject->service); OsalMemFree(serviceObject->priv); @@ -227,8 +227,8 @@ static int32_t DevSvcManagerStubRegisterServListener(struct IDevSvcManager *supe return HDF_ERR_INVALID_PARAM; } - struct ServStatListenerHolder *listenerHolder - = ServStatListenerHolderCreate((uintptr_t)listenerRemote, listenClass); + struct ServStatListenerHolder *listenerHolder = + ServStatListenerHolderCreate((uintptr_t)listenerRemote, listenClass); if (listenerHolder == NULL) { return HDF_ERR_MALLOC_FAIL; } @@ -305,8 +305,8 @@ int DevSvcManagerStubDispatch(struct HdfRemoteService *service, int code, struct void DevSvcManagerOnServiceDied(struct HdfDeathRecipient *recipient, struct HdfRemoteService *remote) { - struct DevSvcManagerStub *stub - = HDF_SLIST_CONTAINER_OF(struct HdfDeathRecipient, recipient, struct DevSvcManagerStub, recipient); + struct DevSvcManagerStub *stub = + HDF_SLIST_CONTAINER_OF(struct HdfDeathRecipient, recipient, struct DevSvcManagerStub, recipient); if (stub == NULL) { return; } @@ -348,7 +348,7 @@ int DevSvcManagerStubStart(struct IDevSvcManager *svcmgr) ServStatListenerHolderinit(); - static struct HdfRemoteDispatcher dispatcher = { .Dispatch = DevSvcManagerStubDispatch }; + static struct HdfRemoteDispatcher dispatcher = {.Dispatch = DevSvcManagerStubDispatch}; inst->remote = HdfRemoteServiceObtain((struct HdfObject *)inst, &dispatcher); if (inst->remote == NULL) { HDF_LOGE("failed to obtain device service manager remote service"); diff --git a/uhdf2/shared/src/dev_attribute_serialize.c b/uhdf2/shared/src/dev_attribute_serialize.c index 65fb021..a57565c 100644 --- a/uhdf2/shared/src/dev_attribute_serialize.c +++ b/uhdf2/shared/src/dev_attribute_serialize.c @@ -66,6 +66,7 @@ struct HdfDeviceInfo *DeviceAttributeDeserialize(struct HdfSBuf *sbuf) if (!HdfSbufReadUint32(sbuf, &attribute->deviceId) || !HdfSbufReadUint16(sbuf, &attribute->policy)) { HDF_LOGE("invalid deviceId or policy"); + DeviceSerializedAttributeRelease(attribute); return NULL; } -- Gitee From 7b5f65a45b22ba2eb98226faf4abbc76766d4d58 Mon Sep 17 00:00:00 2001 From: s00442234 Date: Thu, 10 Mar 2022 19:14:15 +0800 Subject: [PATCH 010/102] fix file permissiom and md info Signed-off-by: s00442234 --- BUILD.gn | 0 README.md | 2 +- README_zh.md | 2 +- bundle.json | 0 khdf/liteos/Kconfig | 0 khdf/liteos/README.md | 4 ++-- khdf/liteos/README_zh.md | 4 ++-- khdf/liteos/hdf_lite.mk | 0 khdf/liteos/model/bus/usb/Kconfig | 0 khdf/liteos/model/bus/usb/Makefile | 0 khdf/liteos/model/display/Kconfig | 0 khdf/liteos/model/display/Makefile | 0 khdf/liteos/model/input/Kconfig | 0 khdf/liteos/model/input/Makefile | 0 khdf/liteos/model/network/ethernet/BUILD.gn | 0 khdf/liteos/model/network/ethernet/Kconfig | 0 khdf/liteos/model/network/ethernet/Makefile | 0 khdf/liteos/model/network/wifi/Makefile | 0 khdf/liteos/model/sensor/Kconfig | 0 khdf/liteos/model/usb/device/BUILD.gn | 0 khdf/liteos/model/usb/device/Kconfig | 0 khdf/liteos/model/usb/device/Makefile | 0 khdf/liteos/model/usb/host/src/usb_pnp_manager.c | 0 khdf/liteos/model/usb/host/src/usb_pnp_notify.c | 0 .../liteos/model/usb/host/src/usb_test_pnp_notify.c | 0 khdf/liteos/ndk/BUILD.gn | 0 khdf/liteos/platform/src/uart_dev.c | 0 uhdf/README.md | 4 ++-- uhdf/README_zh.md | 4 ++-- uhdf/platform/BUILD.gn | 0 uhdf/posix/BUILD.gn | 0 uhdf2/README.md | 2 +- uhdf2/README_zh.md | 2 +- .../hal/mpp/hispark_taurus/driver/mpp_config.hcs | 0 .../hispark_taurus/hdi_impl/camera_host_config.hcs | 0 .../hdi_impl/stream_supported_config.hcs | 0 .../hal/mpp/hispark_taurus/pipeline_core/config.hcs | 0 .../pipeline_core/ipp_algo_config.hcs | 0 .../hal/mpp/hispark_taurus/pipeline_core/params.hcs | 0 .../hal/v4l2/rpi4b/hdi_impl/camera_host_config.hcs | 0 .../v4l2/rpi4b/hdi_impl/stream_supported_config.hcs | 0 .../camera/hal/v4l2/rpi4b/pipeline_core/config.hcs | 0 .../v4l2/rpi4b/pipeline_core/ipp_algo_config.hcs | 0 .../camera/hal/v4l2/rpi4b/pipeline_core/params.hcs | 0 uhdf2/hcs/default/device_info.hcs | 0 uhdf2/hcs/default/hdf.hcs | 0 uhdf2/host/hdf_devhost.cfg | 0 uhdf2/host/include/devhost_service_full.h | 0 uhdf2/host/include/devhost_service_stub.h | 0 uhdf2/host/src/device_token_stub.c | 0 uhdf2/host/src/driver_loader_full.c | 0 uhdf2/host/src/hdf_pm_reg.c | 0 uhdf2/host/test/BUILD.gn | 0 uhdf2/manager/include/devhost_service_proxy.h | 0 uhdf2/manager/include/devmgr_service_stub.h | 0 uhdf2/manager/src/device_token_proxy.c | 0 .../resource/audio/audiofile/audiorendertest.wav | Bin 57 files changed, 12 insertions(+), 12 deletions(-) mode change 100755 => 100644 BUILD.gn mode change 100755 => 100644 bundle.json mode change 100755 => 100644 khdf/liteos/Kconfig mode change 100755 => 100644 khdf/liteos/hdf_lite.mk mode change 100755 => 100644 khdf/liteos/model/bus/usb/Kconfig mode change 100755 => 100644 khdf/liteos/model/bus/usb/Makefile mode change 100755 => 100644 khdf/liteos/model/display/Kconfig mode change 100755 => 100644 khdf/liteos/model/display/Makefile mode change 100755 => 100644 khdf/liteos/model/input/Kconfig mode change 100755 => 100644 khdf/liteos/model/input/Makefile mode change 100755 => 100644 khdf/liteos/model/network/ethernet/BUILD.gn mode change 100755 => 100644 khdf/liteos/model/network/ethernet/Kconfig mode change 100755 => 100644 khdf/liteos/model/network/ethernet/Makefile mode change 100755 => 100644 khdf/liteos/model/network/wifi/Makefile mode change 100755 => 100644 khdf/liteos/model/sensor/Kconfig mode change 100755 => 100644 khdf/liteos/model/usb/device/BUILD.gn mode change 100755 => 100644 khdf/liteos/model/usb/device/Kconfig mode change 100755 => 100644 khdf/liteos/model/usb/device/Makefile mode change 100755 => 100644 khdf/liteos/model/usb/host/src/usb_pnp_manager.c mode change 100755 => 100644 khdf/liteos/model/usb/host/src/usb_pnp_notify.c mode change 100755 => 100644 khdf/liteos/model/usb/host/src/usb_test_pnp_notify.c mode change 100755 => 100644 khdf/liteos/ndk/BUILD.gn mode change 100755 => 100644 khdf/liteos/platform/src/uart_dev.c mode change 100755 => 100644 uhdf/platform/BUILD.gn mode change 100755 => 100644 uhdf/posix/BUILD.gn mode change 100755 => 100644 uhdf2/hcs/camera/hal/mpp/hispark_taurus/driver/mpp_config.hcs mode change 100755 => 100644 uhdf2/hcs/camera/hal/mpp/hispark_taurus/hdi_impl/camera_host_config.hcs mode change 100755 => 100644 uhdf2/hcs/camera/hal/mpp/hispark_taurus/hdi_impl/stream_supported_config.hcs mode change 100755 => 100644 uhdf2/hcs/camera/hal/mpp/hispark_taurus/pipeline_core/config.hcs mode change 100755 => 100644 uhdf2/hcs/camera/hal/mpp/hispark_taurus/pipeline_core/ipp_algo_config.hcs mode change 100755 => 100644 uhdf2/hcs/camera/hal/mpp/hispark_taurus/pipeline_core/params.hcs mode change 100755 => 100644 uhdf2/hcs/camera/hal/v4l2/rpi4b/hdi_impl/camera_host_config.hcs mode change 100755 => 100644 uhdf2/hcs/camera/hal/v4l2/rpi4b/hdi_impl/stream_supported_config.hcs mode change 100755 => 100644 uhdf2/hcs/camera/hal/v4l2/rpi4b/pipeline_core/config.hcs mode change 100755 => 100644 uhdf2/hcs/camera/hal/v4l2/rpi4b/pipeline_core/ipp_algo_config.hcs mode change 100755 => 100644 uhdf2/hcs/camera/hal/v4l2/rpi4b/pipeline_core/params.hcs mode change 100755 => 100644 uhdf2/hcs/default/device_info.hcs mode change 100755 => 100644 uhdf2/hcs/default/hdf.hcs mode change 100755 => 100644 uhdf2/host/hdf_devhost.cfg mode change 100755 => 100644 uhdf2/host/include/devhost_service_full.h mode change 100755 => 100644 uhdf2/host/include/devhost_service_stub.h mode change 100755 => 100644 uhdf2/host/src/device_token_stub.c mode change 100755 => 100644 uhdf2/host/src/driver_loader_full.c mode change 100755 => 100644 uhdf2/host/src/hdf_pm_reg.c mode change 100755 => 100644 uhdf2/host/test/BUILD.gn mode change 100755 => 100644 uhdf2/manager/include/devhost_service_proxy.h mode change 100755 => 100644 uhdf2/manager/include/devmgr_service_stub.h mode change 100755 => 100644 uhdf2/manager/src/device_token_proxy.c mode change 100755 => 100644 uhdf2/test/resource/audio/audiofile/audiorendertest.wav diff --git a/BUILD.gn b/BUILD.gn old mode 100755 new mode 100644 diff --git a/README.md b/README.md index c4b773b..b3cce18 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ This repository stores the code and compilation scripts for the kerner or user-m [drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README.md) -drivers\_adapter +[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README.md) [drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README.md) diff --git a/README_zh.md b/README_zh.md index d70dade..ebb4d89 100644 --- a/README_zh.md +++ b/README_zh.md @@ -24,7 +24,7 @@ [drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README_zh.md) -drivers\_adapter +[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README_zh.md) [drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README_zh.md) diff --git a/bundle.json b/bundle.json old mode 100755 new mode 100644 diff --git a/khdf/liteos/Kconfig b/khdf/liteos/Kconfig old mode 100755 new mode 100644 diff --git a/khdf/liteos/README.md b/khdf/liteos/README.md index 5ec1664..c7b2f65 100644 --- a/khdf/liteos/README.md +++ b/khdf/liteos/README.md @@ -31,8 +31,8 @@ This repository stores the code and compilation scripts for the OpenHarmony driv [drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README.md) -[drivers\_adapter\_uhdf](https://gitee.com/openharmony/drivers_adapter_uhdf/blob/master/README.md) +[drivers\_adapter\_uhdf](https://gitee.com/openharmony/drivers_adapter/blob/master/uhdf/README.md) [drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_uhdf/blob/master/README.md) -drivers\_adapter\_khdf\_liteos +[drivers\_adapter\_khdf\_liteos](https://gitee.com/openharmony/drivers_adapter/blob/master/khdf/liteos/README.md) diff --git a/khdf/liteos/README_zh.md b/khdf/liteos/README_zh.md index 3a6f453..357d7cf 100644 --- a/khdf/liteos/README_zh.md +++ b/khdf/liteos/README_zh.md @@ -31,8 +31,8 @@ [drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README_zh.md) -[drivers\_adapter\_uhdf](https://gitee.com/openharmony/drivers_adapter_uhdf/blob/master/README_zh.md) +[drivers\_adapter\_uhdf](https://gitee.com/openharmony/drivers_adapter/blob/master/uhdf/README_zh.md) [drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README_zh.md) -drivers\_adapter\_khdf\_liteos +[drivers\_adapter\_khdf\_liteos](https://gitee.com/openharmony/drivers_adapter/blob/master/khdf/liteos/README_zh.md) diff --git a/khdf/liteos/hdf_lite.mk b/khdf/liteos/hdf_lite.mk old mode 100755 new mode 100644 diff --git a/khdf/liteos/model/bus/usb/Kconfig b/khdf/liteos/model/bus/usb/Kconfig old mode 100755 new mode 100644 diff --git a/khdf/liteos/model/bus/usb/Makefile b/khdf/liteos/model/bus/usb/Makefile old mode 100755 new mode 100644 diff --git a/khdf/liteos/model/display/Kconfig b/khdf/liteos/model/display/Kconfig old mode 100755 new mode 100644 diff --git a/khdf/liteos/model/display/Makefile b/khdf/liteos/model/display/Makefile old mode 100755 new mode 100644 diff --git a/khdf/liteos/model/input/Kconfig b/khdf/liteos/model/input/Kconfig old mode 100755 new mode 100644 diff --git a/khdf/liteos/model/input/Makefile b/khdf/liteos/model/input/Makefile old mode 100755 new mode 100644 diff --git a/khdf/liteos/model/network/ethernet/BUILD.gn b/khdf/liteos/model/network/ethernet/BUILD.gn old mode 100755 new mode 100644 diff --git a/khdf/liteos/model/network/ethernet/Kconfig b/khdf/liteos/model/network/ethernet/Kconfig old mode 100755 new mode 100644 diff --git a/khdf/liteos/model/network/ethernet/Makefile b/khdf/liteos/model/network/ethernet/Makefile old mode 100755 new mode 100644 diff --git a/khdf/liteos/model/network/wifi/Makefile b/khdf/liteos/model/network/wifi/Makefile old mode 100755 new mode 100644 diff --git a/khdf/liteos/model/sensor/Kconfig b/khdf/liteos/model/sensor/Kconfig old mode 100755 new mode 100644 diff --git a/khdf/liteos/model/usb/device/BUILD.gn b/khdf/liteos/model/usb/device/BUILD.gn old mode 100755 new mode 100644 diff --git a/khdf/liteos/model/usb/device/Kconfig b/khdf/liteos/model/usb/device/Kconfig old mode 100755 new mode 100644 diff --git a/khdf/liteos/model/usb/device/Makefile b/khdf/liteos/model/usb/device/Makefile old mode 100755 new mode 100644 diff --git a/khdf/liteos/model/usb/host/src/usb_pnp_manager.c b/khdf/liteos/model/usb/host/src/usb_pnp_manager.c old mode 100755 new mode 100644 diff --git a/khdf/liteos/model/usb/host/src/usb_pnp_notify.c b/khdf/liteos/model/usb/host/src/usb_pnp_notify.c old mode 100755 new mode 100644 diff --git a/khdf/liteos/model/usb/host/src/usb_test_pnp_notify.c b/khdf/liteos/model/usb/host/src/usb_test_pnp_notify.c old mode 100755 new mode 100644 diff --git a/khdf/liteos/ndk/BUILD.gn b/khdf/liteos/ndk/BUILD.gn old mode 100755 new mode 100644 diff --git a/khdf/liteos/platform/src/uart_dev.c b/khdf/liteos/platform/src/uart_dev.c old mode 100755 new mode 100644 diff --git a/uhdf/README.md b/uhdf/README.md index 7b5c972..3187078 100644 --- a/uhdf/README.md +++ b/uhdf/README.md @@ -24,9 +24,9 @@ This repository stores the code and compilation scripts for the OpenHarmony driv [drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README.md) -drivers\_adapter\_uhdf +[drivers\_adapter\_uhdf](https://gitee.com/openharmony/drivers_adapter/blob/master/uhdf/README_zh.md) [drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README.md) -[drivers\_adapter\_khdf\_liteos](https://gitee.com/openharmony/drivers_adapter_khdf_liteos/blob/master/README.md) +[drivers\_adapter\_khdf\_liteos](https://gitee.com/openharmony/drivers_adapter/blob/master/khdf/liteos/README.md) diff --git a/uhdf/README_zh.md b/uhdf/README_zh.md index 8e9d52f..3ea6ec1 100644 --- a/uhdf/README_zh.md +++ b/uhdf/README_zh.md @@ -24,9 +24,9 @@ [drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README_zh.md) -drivers\_adapter\_uhdf +[drivers\_adapter\_uhdf](https://gitee.com/openharmony/drivers_adapter/blob/master/uhdf/README_zh.md) [drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README_zh.md) -[drivers\_adapter\_khdf\_liteos](https://gitee.com/openharmony/drivers_adapter_khdf_liteos/blob/master/README_zh.md) +[drivers\_adapter\_khdf\_liteos](https://gitee.com/openharmony/drivers_adapter/blob/master/khdf/liteos/README_zh.md) diff --git a/uhdf/platform/BUILD.gn b/uhdf/platform/BUILD.gn old mode 100755 new mode 100644 diff --git a/uhdf/posix/BUILD.gn b/uhdf/posix/BUILD.gn old mode 100755 new mode 100644 diff --git a/uhdf2/README.md b/uhdf2/README.md index c8efe7f..ce6dca9 100644 --- a/uhdf2/README.md +++ b/uhdf2/README.md @@ -29,7 +29,7 @@ This repository stores the code and compilation scripts for the user-mode Hardwa [drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README.md) -drivers\_adapter +[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README.md) [drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README.md) diff --git a/uhdf2/README_zh.md b/uhdf2/README_zh.md index 67a3d90..fff6ba7 100644 --- a/uhdf2/README_zh.md +++ b/uhdf2/README_zh.md @@ -29,7 +29,7 @@ [drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README_zh.md) -drivers\_adapter +[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README_zh.md) [drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README_zh.md) diff --git a/uhdf2/hcs/camera/hal/mpp/hispark_taurus/driver/mpp_config.hcs b/uhdf2/hcs/camera/hal/mpp/hispark_taurus/driver/mpp_config.hcs old mode 100755 new mode 100644 diff --git a/uhdf2/hcs/camera/hal/mpp/hispark_taurus/hdi_impl/camera_host_config.hcs b/uhdf2/hcs/camera/hal/mpp/hispark_taurus/hdi_impl/camera_host_config.hcs old mode 100755 new mode 100644 diff --git a/uhdf2/hcs/camera/hal/mpp/hispark_taurus/hdi_impl/stream_supported_config.hcs b/uhdf2/hcs/camera/hal/mpp/hispark_taurus/hdi_impl/stream_supported_config.hcs old mode 100755 new mode 100644 diff --git a/uhdf2/hcs/camera/hal/mpp/hispark_taurus/pipeline_core/config.hcs b/uhdf2/hcs/camera/hal/mpp/hispark_taurus/pipeline_core/config.hcs old mode 100755 new mode 100644 diff --git a/uhdf2/hcs/camera/hal/mpp/hispark_taurus/pipeline_core/ipp_algo_config.hcs b/uhdf2/hcs/camera/hal/mpp/hispark_taurus/pipeline_core/ipp_algo_config.hcs old mode 100755 new mode 100644 diff --git a/uhdf2/hcs/camera/hal/mpp/hispark_taurus/pipeline_core/params.hcs b/uhdf2/hcs/camera/hal/mpp/hispark_taurus/pipeline_core/params.hcs old mode 100755 new mode 100644 diff --git a/uhdf2/hcs/camera/hal/v4l2/rpi4b/hdi_impl/camera_host_config.hcs b/uhdf2/hcs/camera/hal/v4l2/rpi4b/hdi_impl/camera_host_config.hcs old mode 100755 new mode 100644 diff --git a/uhdf2/hcs/camera/hal/v4l2/rpi4b/hdi_impl/stream_supported_config.hcs b/uhdf2/hcs/camera/hal/v4l2/rpi4b/hdi_impl/stream_supported_config.hcs old mode 100755 new mode 100644 diff --git a/uhdf2/hcs/camera/hal/v4l2/rpi4b/pipeline_core/config.hcs b/uhdf2/hcs/camera/hal/v4l2/rpi4b/pipeline_core/config.hcs old mode 100755 new mode 100644 diff --git a/uhdf2/hcs/camera/hal/v4l2/rpi4b/pipeline_core/ipp_algo_config.hcs b/uhdf2/hcs/camera/hal/v4l2/rpi4b/pipeline_core/ipp_algo_config.hcs old mode 100755 new mode 100644 diff --git a/uhdf2/hcs/camera/hal/v4l2/rpi4b/pipeline_core/params.hcs b/uhdf2/hcs/camera/hal/v4l2/rpi4b/pipeline_core/params.hcs old mode 100755 new mode 100644 diff --git a/uhdf2/hcs/default/device_info.hcs b/uhdf2/hcs/default/device_info.hcs old mode 100755 new mode 100644 diff --git a/uhdf2/hcs/default/hdf.hcs b/uhdf2/hcs/default/hdf.hcs old mode 100755 new mode 100644 diff --git a/uhdf2/host/hdf_devhost.cfg b/uhdf2/host/hdf_devhost.cfg old mode 100755 new mode 100644 diff --git a/uhdf2/host/include/devhost_service_full.h b/uhdf2/host/include/devhost_service_full.h old mode 100755 new mode 100644 diff --git a/uhdf2/host/include/devhost_service_stub.h b/uhdf2/host/include/devhost_service_stub.h old mode 100755 new mode 100644 diff --git a/uhdf2/host/src/device_token_stub.c b/uhdf2/host/src/device_token_stub.c old mode 100755 new mode 100644 diff --git a/uhdf2/host/src/driver_loader_full.c b/uhdf2/host/src/driver_loader_full.c old mode 100755 new mode 100644 diff --git a/uhdf2/host/src/hdf_pm_reg.c b/uhdf2/host/src/hdf_pm_reg.c old mode 100755 new mode 100644 diff --git a/uhdf2/host/test/BUILD.gn b/uhdf2/host/test/BUILD.gn old mode 100755 new mode 100644 diff --git a/uhdf2/manager/include/devhost_service_proxy.h b/uhdf2/manager/include/devhost_service_proxy.h old mode 100755 new mode 100644 diff --git a/uhdf2/manager/include/devmgr_service_stub.h b/uhdf2/manager/include/devmgr_service_stub.h old mode 100755 new mode 100644 diff --git a/uhdf2/manager/src/device_token_proxy.c b/uhdf2/manager/src/device_token_proxy.c old mode 100755 new mode 100644 diff --git a/uhdf2/test/resource/audio/audiofile/audiorendertest.wav b/uhdf2/test/resource/audio/audiofile/audiorendertest.wav old mode 100755 new mode 100644 -- Gitee From 275e5b9d2efba1c8e93ad19ec47f59a1eab16e5b Mon Sep 17 00:00:00 2001 From: yue Date: Thu, 10 Mar 2022 19:30:00 +0800 Subject: [PATCH 011/102] fix:clean drivers adapter codex Signed-off-by: yue --- uhdf2/include/hdi/base/hdi_smq.h | 1 + 1 file changed, 1 insertion(+) diff --git a/uhdf2/include/hdi/base/hdi_smq.h b/uhdf2/include/hdi/base/hdi_smq.h index 9fe894d..5c1f417 100644 --- a/uhdf2/include/hdi/base/hdi_smq.h +++ b/uhdf2/include/hdi/base/hdi_smq.h @@ -124,6 +124,7 @@ SharedMemQueue::~SharedMemQueue() UnMapMemZone(readOffset_, SharedMemQueueMeta::MemZoneType::MEMZONE_RPTR); } else { delete readOffset_; + readOffset_ = nullptr; } if (writeOffset_ != nullptr) { -- Gitee From 0cba0f021fc8aa27d612b90c540ef516f6499769 Mon Sep 17 00:00:00 2001 From: "weidongwang@bestechnic.com" Date: Thu, 10 Mar 2022 22:28:43 +0800 Subject: [PATCH 012/102] fix hdf coding style Signed-off-by: weidongwang@bestechnic.com --- platform/gpio/gpio_bes.c | 1 - platform/i2c/i2c_bes.c | 49 ++++++++----- platform/pwm/pwm_bes.c | 2 + platform/spi/spi_bes.c | 26 +++---- platform/uart/uart_bes.c | 155 ++++++++++++++++++++++++--------------- 5 files changed, 138 insertions(+), 95 deletions(-) diff --git a/platform/gpio/gpio_bes.c b/platform/gpio/gpio_bes.c index 4d1cc8f..e2a4465 100644 --- a/platform/gpio/gpio_bes.c +++ b/platform/gpio/gpio_bes.c @@ -277,7 +277,6 @@ static uint32_t GetGpioDeviceResource( return HDF_FAILURE; } } - return HDF_SUCCESS; } #endif diff --git a/platform/i2c/i2c_bes.c b/platform/i2c/i2c_bes.c index 9ffa5b1..9303c97 100755 --- a/platform/i2c/i2c_bes.c +++ b/platform/i2c/i2c_bes.c @@ -54,9 +54,33 @@ struct I2cMethod g_i2cHostMethod = { .transfer = i2cHostTransfer, }; +static void I2cDeviceIomuxInit(uint32_t i2cId, struct I2cResource *resource) +{ + if (i2cId > HAL_I2C_ID_NUM || resource == NULL) { + HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__); + return HDF_ERR_INVALID_PARAM; + } + + struct HAL_IOMUX_PIN_FUNCTION_MAP pinMuxI2c[] = { + {0, 0, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}, + {0, 0, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}, + }; + + if (i2cId == 0) { + pinMuxI2c[0].function = HAL_IOMUX_FUNC_I2C_M0_SCL; + pinMuxI2c[1].function = HAL_IOMUX_FUNC_I2C_M0_SDA; + } else { + pinMuxI2c[0].function = HAL_IOMUX_FUNC_I2C_M1_SCL; + pinMuxI2c[1].function = HAL_IOMUX_FUNC_I2C_M1_SDA; + } + pinMuxI2c[0].pin = resource->sclPin; + pinMuxI2c[1].pin = resource->sdaPin; + hal_iomux_init(pinMuxI2c, ARRAY_SIZE(pinMuxI2c)); +} + int32_t InitI2cDevice(struct I2cDevice *device) { - int32_t ret = -1; + int32_t ret; uint32_t i2cPort; struct I2cResource *resource = NULL; struct HAL_I2C_CONFIG_T *i2cConfig = NULL; @@ -77,11 +101,6 @@ int32_t InitI2cDevice(struct I2cDevice *device) return HDF_ERR_INVALID_PARAM; } - struct HAL_IOMUX_PIN_FUNCTION_MAP pinMuxI2c[] = { - {0, 0, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}, - {0, 0, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}, - }; - device->port = resource->port; i2cPort = device->port; if (i2cPort > HAL_I2C_ID_NUM) { @@ -89,14 +108,6 @@ int32_t InitI2cDevice(struct I2cDevice *device) return HDF_ERR_NOT_SUPPORT; } - if (i2cPort == 0) { - pinMuxI2c[0].function = HAL_IOMUX_FUNC_I2C_M0_SCL; - pinMuxI2c[1].function = HAL_IOMUX_FUNC_I2C_M0_SDA; - } else { - pinMuxI2c[0].function = HAL_IOMUX_FUNC_I2C_M1_SCL; - pinMuxI2c[1].function = HAL_IOMUX_FUNC_I2C_M1_SDA; - } - if (OsalMutexInit(&device->mutex) != HDF_SUCCESS) { HDF_LOGE("%s %d OsalMutexInit fail\r\n", __func__, __LINE__); return HDF_FAILURE; @@ -107,9 +118,7 @@ int32_t InitI2cDevice(struct I2cDevice *device) return HDF_ERR_TIMEOUT; } - pinMuxI2c[0].pin = resource->sclPin; - pinMuxI2c[1].pin = resource->sdaPin; - hal_iomux_init(pinMuxI2c, ARRAY_SIZE(pinMuxI2c)); + I2cDeviceIomuxInit(i2cPort, resource); ret = hal_i2c_open(i2cPort, i2cConfig); if (ret == HDF_SUCCESS) { @@ -121,7 +130,7 @@ int32_t InitI2cDevice(struct I2cDevice *device) static int32_t HostRestI2cDevice(struct I2cDevice *device) { - int32_t ret = -1; + int32_t ret; struct I2cResource *resource = NULL; struct HAL_I2C_CONFIG_T *i2cConfig = NULL; uint32_t i2cPort; @@ -175,7 +184,7 @@ static int32_t HostRestI2cDevice(struct I2cDevice *device) static uint32_t GetI2cDeviceResource(struct I2cDevice *device, const char *deviceMatchAttr) { - uint32_t tempPin = 0; + uint32_t tempPin; struct I2cResource *resource = NULL; if (device == NULL) { HDF_LOGE("device or resourceNode is NULL\r\n"); @@ -194,7 +203,7 @@ static uint32_t GetI2cDeviceResource(struct I2cDevice *device, static uint32_t GetI2cDeviceResource(struct I2cDevice *device, const struct DeviceResourceNode *resourceNode) { - uint32_t tempPin = 0; + uint32_t tempPin; struct I2cResource *resource = NULL; struct DeviceResourceIface *dri = NULL; if (device == NULL || resourceNode == NULL) { diff --git a/platform/pwm/pwm_bes.c b/platform/pwm/pwm_bes.c index 4352981..5b6824a 100755 --- a/platform/pwm/pwm_bes.c +++ b/platform/pwm/pwm_bes.c @@ -90,6 +90,8 @@ static int InitPwmDevice(struct PwmDev *host) #ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO static uint32_t GetPwmDeviceResource(struct PwmDevice *device) { + (void)device; + return HDF_SUCCESS; } #else static uint32_t GetPwmDeviceResource( diff --git a/platform/spi/spi_bes.c b/platform/spi/spi_bes.c index b1e9277..9111269 100755 --- a/platform/spi/spi_bes.c +++ b/platform/spi/spi_bes.c @@ -113,12 +113,12 @@ static void SpiIomuxInit(struct SpiDevice *spiDevice) resource = &spiDevice->resource; if (resource == NULL) { HDF_LOGE("resource is null\r\n"); - return HDF_ERR_INVALID_OBJECT; + return; } spiDevCfg = &spiDevice->spiDevCfg; if (spiDevCfg == NULL) { HDF_LOGE("resource is null\r\n"); - return HDF_ERR_INVALID_OBJECT; + return; } spiDevCfg->rate = resource->speed; @@ -166,7 +166,7 @@ static void SpiIomuxInit(struct SpiDevice *spiDevice) #endif int32_t HalSpiSend(struct SpiDevice *spiDevice, const uint8_t *data, uint16_t size, uint32_t timeOut) { - int32_t ret = 0; + int32_t ret; uint32_t spiId; uint32_t len = size; struct SpiResource *resource = NULL; @@ -223,11 +223,11 @@ OUT: * * @return 0 : on success, EIO : if the SPI device could not be initialised */ -int32_t HalSpiRecv(struct SpiDevice *spiDevice, uint8_t *data, uint16_t size, uint32_t timeOut) +static int32_t HalSpiRecv(struct SpiDevice *spiDevice, uint8_t *data, uint16_t size, uint32_t timeOut) { - int32_t ret = 0; + int32_t ret; uint32_t len = size; - uint32_t remainder = 0; + uint32_t remainder; int32_t status = HDF_FAILURE; uint8_t *cmd = NULL; uint32_t spiId; @@ -257,7 +257,7 @@ int32_t HalSpiRecv(struct SpiDevice *spiDevice, uint8_t *data, uint16_t size, ui OsalMemFree(cmd); return HDF_ERR_TIMEOUT; } - remainder = len <= SPI_DMA_MAX ? len : SPI_DMA_MAX; + remainder = ((len <= SPI_DMA_MAX) ? len : SPI_DMA_MAX); if (resource->transmode == SPI_TRANSFER_DMA) { ret = spiCtx[spiId].SpiDmaRecv(cmd, data, remainder, spiCtx[spiId].SpiDmaIrq); @@ -285,8 +285,8 @@ OUT: #ifdef HalSpiSendRecv #undef HalSpiSendRecv #endif -int32_t HalSpiSendRecv(struct SpiDevice *spiDevice, uint8_t *txData, uint16_t txSize, uint8_t *rxData, - uint16_t rxSize, uint32_t timeOut) +static int32_t HalSpiSendRecv(struct SpiDevice *spiDevice, uint8_t *txData, uint16_t txSize, uint8_t *rxData, + uint16_t rxSize) { int32_t ret; int32_t status; @@ -306,7 +306,7 @@ int32_t HalSpiSendRecv(struct SpiDevice *spiDevice, uint8_t *txData, uint16_t tx if (resource->transmode == SPI_TRANSFER_DMA) { ret = spiCtx[spiId].SpiDmaRecv(txData, rxData, rxSize, spiCtx[spiId].SpiDmaIrq); - if (OsalSemWait(&spiCtx[spiId].sem, timeOut) <= 0) { + if (OsalSemWait(&spiCtx[spiId].sem, TIMEOUT) <= 0) { HDF_LOGE("%s:SPI Read timeOut!\r\n", __func__); goto OUT; } @@ -395,7 +395,7 @@ static int32_t InitSpiDevice(struct SpiDevice *spiDevice) /* get spi config from hcs file */ #ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO -static int32_t GetSpiDeviceResource(struct SpiDevice *spiDevice) +static int32_t GetSpiDeviceResource(struct SpiDevice *spiDevice, const char *deviceMatchAttr) { } #else @@ -508,7 +508,7 @@ int32_t AttachSpiDevice(struct SpiCntlr *spiCntlr, struct HdfDeviceObject *devic return HDF_ERR_MALLOC_FAIL; } #ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO - ret = GetSpiDeviceResource(spiDevice); + ret = GetSpiDeviceResource(spiDevice, device->deviceMatchAttr); #else ret = GetSpiDeviceResource(spiDevice, device->property); #endif @@ -744,7 +744,7 @@ static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg, HalSpiRecv(spiDevice, msg->rbuf, msg->len, TIMEOUT); } if ((msg->wbuf != NULL) && (msg->rbuf != NULL)) { - HalSpiSendRecv(spiDevice, msg->wbuf, msg->len, msg->rbuf, msg->len, TIMEOUT); + HalSpiSendRecv(spiDevice, msg->wbuf, msg->len, msg->rbuf, msg->len); } /* pull pull up cs at the end */ diff --git a/platform/uart/uart_bes.c b/platform/uart/uart_bes.c index b17ad54..7371125 100755 --- a/platform/uart/uart_bes.c +++ b/platform/uart/uart_bes.c @@ -17,7 +17,12 @@ #include #include "hal_iomux.h" #include "hal_timer.h" +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO +#include "hcs_macro.h" +#include "hdf_config_macro.h" +#else #include "device_resource_if.h" +#endif #include "hal_trace.h" #include "hal_cache.h" #include "hdf_log.h" @@ -64,7 +69,7 @@ static void HalSetUartIomux(enum HAL_UART_ID_T uartId) static void HalUartRxStart(uint32_t uartId) { struct HAL_DMA_DESC_T dmaDescRx; - unsigned int descCnt = 1; + uint32_t descCnt; union HAL_UART_IRQ_T mask; mask.reg = 0; @@ -73,7 +78,7 @@ static void HalUartRxStart(uint32_t uartId) mask.OE = 0; mask.PE = 0; mask.RT = 1; - + descCnt = 1; hal_uart_dma_recv_mask(uartId, g_uartCtx[uartId].buffer, UART_DMA_RING_BUFFER_SIZE, &dmaDescRx, &descCnt, &mask); } @@ -94,37 +99,34 @@ static void UartRxHandler(enum HAL_UART_ID_T id, union HAL_UART_IRQ_T status) static void UartDmaRxHandler(uint32_t xferSize, int dmaError, union HAL_UART_IRQ_T status) { - uint32_t len = 0; - uint32_t uartid = 0; - - len = kfifo_put(&g_uartCtx[uartid].fifo, g_uartCtx[uartid].buffer, xferSize); + uint32_t len; + len = kfifo_put(&g_uartCtx[HAL_UART_ID_0].fifo, g_uartCtx[HAL_UART_ID_0].buffer, xferSize); if (len < xferSize) { HDF_LOGE("%s ringbuf is full have %d need %d\r", __FUNCTION__, (int)len, (int)xferSize); return; } - memset_s(g_uartCtx[uartid].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE); - OsalSemPost(&g_uartCtx[uartid].rxSem); - HalUartRxStart(uartid); + memset_s(g_uartCtx[HAL_UART_ID_0].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE); + OsalSemPost(&g_uartCtx[HAL_UART_ID_0].rxSem); + HalUartRxStart(HAL_UART_ID_0); } static void UartDmaTxHandler(uint32_t xferSize, int dmaError) { - OsalSemPost(&g_uartCtx[0].txSem); + OsalSemPost(&g_uartCtx[HAL_UART_ID_0].txSem); } static void Uart1DmaRxHandler(uint32_t xferSize, int dmaError, union HAL_UART_IRQ_T status) { - uint32_t len = 0; - uint32_t uartid = HAL_UART_ID_1; - len = kfifo_put(&g_uartCtx[uartid].fifo, g_uartCtx[uartid].buffer, xferSize); + uint32_t len; + len = kfifo_put(&g_uartCtx[HAL_UART_ID_1].fifo, g_uartCtx[HAL_UART_ID_1].buffer, xferSize); if (len < xferSize) { HDF_LOGE("%s ringbuf is full have %d need %d\r", __FUNCTION__, (int)len, (int)xferSize); return; } - memset_s(g_uartCtx[uartid].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE); - OsalSemPost(&g_uartCtx[uartid].rxSem); - HalUartRxStart(uartid); + memset_s(g_uartCtx[HAL_UART_ID_1].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE); + OsalSemPost(&g_uartCtx[HAL_UART_ID_1].rxSem); + HalUartRxStart(HAL_UART_ID_1); } static void Uart1DmaTxHandler(uint32_t xferSize, int dmaError) @@ -135,17 +137,16 @@ static void Uart1DmaTxHandler(uint32_t xferSize, int dmaError) /* uart2 */ static void Uart2DmaRxHandler(uint32_t xferSize, int dmaError, union HAL_UART_IRQ_T status) { - uint32_t len = 0; - uint32_t uartid = HAL_UART_ID_2; - len = kfifo_put(&g_uartCtx[uartid].fifo, g_uartCtx[uartid].buffer, xferSize); + uint32_t len ; + len = kfifo_put(&g_uartCtx[HAL_UART_ID_2].fifo, g_uartCtx[HAL_UART_ID_2].buffer, xferSize); if (len < xferSize) { HDF_LOGE("%s ringbuf is full have %d need %d\r", __FUNCTION__, (int)len, (int)xferSize); return; } - memset_s(g_uartCtx[uartid].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE); - OsalSemPost(&g_uartCtx[uartid].rxSem); - HalUartRxStart(uartid); + memset_s(g_uartCtx[HAL_UART_ID_2].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE); + OsalSemPost(&g_uartCtx[HAL_UART_ID_2].rxSem); + HalUartRxStart(HAL_UART_ID_2); } static void Uart2DmaTxHandler(uint32_t xferSize, int dmaError) @@ -166,9 +167,9 @@ static void HalUartStartRx(uint32_t uartId) static int32_t HalUartSend(uint32_t uartId, const void *data, uint32_t size, uint32_t timeOut) { - int32_t ret = HDF_FAILURE; + int32_t ret; struct HAL_DMA_DESC_T dmaSescTx; - unsigned int descCnt = 1; + uint32_t descCnt; if (data == NULL || size == 0) { HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__); @@ -179,7 +180,7 @@ static int32_t HalUartSend(uint32_t uartId, const void *data, uint32_t size, uin HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__); return HDF_ERR_NOT_SUPPORT; } - + descCnt = 1; hal_uart_dma_send(uartId, data, size, &dmaSescTx, &descCnt); OsalSemWait(&g_uartCtx[uartId].txSem, timeOut); @@ -189,14 +190,13 @@ static int32_t HalUartSend(uint32_t uartId, const void *data, uint32_t size, uin static int32_t HalUartRecv(uint8_t uartId, void *data, uint32_t expectSize, uint32_t *recvSize, uint32_t timeOut) { - int32_t ret = HDF_FAILURE; - uint32_t beginTime = 0; - uint32_t nowTime = 0; - uint32_t fifoPopLen = 0; + uint32_t beginTime; + uint32_t nowTime; + uint32_t fifoPopLen; uint32_t recvedLen = 0; uint32_t expectLen = expectSize; - if (data == NULL || expectSize == 0 || recvSize == NULL) { + if (data == NULL || expectLen == 0 || recvSize == NULL) { HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__); return HDF_ERR_INVALID_PARAM; } @@ -238,7 +238,7 @@ static void HalUartHandlerInit(struct UartDevice *device) uint32_t uartId; if (device == NULL) { HDF_LOGE("%s: INVALID PARAM", __func__); - return HDF_ERR_INVALID_PARAM; + return; } uartId = device->uartId; HDF_LOGI("%s %ld\r\n", __func__, uartId); @@ -388,10 +388,16 @@ static int InitUartDevice(struct UartHost *host) UartStart(uartDevice); uartDevice->initFlag = true; } - return HDF_SUCCESS; } - +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO +static uint32_t GetUartDeviceResource(struct UartDevice *device, const char *deviceMatchAttr) +{ + (void)device; + (void)deviceMatchAttr; + return HDF_SUCCESS; +} +#else static uint32_t GetUartDeviceResource( struct UartDevice *device, const struct DeviceResourceNode *resourceNode) { @@ -446,13 +452,16 @@ static uint32_t GetUartDeviceResource( device->config.dma_tx = resource->txDMA; return HDF_SUCCESS; } - +#endif static int32_t AttachUartDevice(struct UartHost *uartHost, struct HdfDeviceObject *device) { int32_t ret; struct UartDevice *uartDevice = NULL; - +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO + if (device == NULL || uartHost == NULL) { +#else if (uartHost == NULL || device == NULL || device->property == NULL) { +#endif HDF_LOGE("%s: property is NULL", __func__); return HDF_ERR_INVALID_PARAM; } @@ -462,8 +471,11 @@ static int32_t AttachUartDevice(struct UartHost *uartHost, struct HdfDeviceObjec HDF_LOGE("%s: OsalMemCalloc uartDevice error", __func__); return HDF_ERR_MALLOC_FAIL; } - +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO + ret = GetUartDeviceResource(uartDevice, device->deviceMatchAttr); +#else ret = GetUartDeviceResource(uartDevice, device->property); +#endif if (ret != HDF_SUCCESS) { (void)OsalMemFree(uartDevice); return HDF_FAILURE; @@ -476,7 +488,7 @@ static int32_t AttachUartDevice(struct UartHost *uartHost, struct HdfDeviceObjec static int32_t UartDriverBind(struct HdfDeviceObject *device) { - struct UartHost *devService; + struct UartHost *devService = NULL; if (device == NULL) { HDF_LOGE("%s: invalid parameter", __func__); return HDF_ERR_INVALID_PARAM; @@ -621,7 +633,7 @@ static int32_t UartHostDevWrite(struct UartHost *host, uint8_t *data, uint32_t s static int32_t UartHostDevRead(struct UartHost *host, uint8_t *data, uint32_t size) { - uint32_t recvSize = 0; + uint32_t recvSize; int32_t ret; uint32_t uartId; struct UartDevice *uartDevice = NULL; @@ -715,29 +727,12 @@ static int32_t UartHostDevGetBaud(struct UartHost *host, uint32_t *baudRate) return HDF_SUCCESS; } -static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribute *attribute) +static int32_t SetUartDevConfig(struct UartAttribute *attribute, struct HAL_UART_CFG_T *uartCfg) { - HDF_LOGI("%s: Enter", __func__); - struct UartDevice *uartDevice = NULL; - struct HAL_UART_CFG_T *uartCfg = NULL; - uint32_t uartId; - if (host == NULL || attribute == NULL || host->priv == NULL) { + if (attribute == NULL || uartCfg == NULL) { HDF_LOGE("%s: invalid parameter", __func__); return HDF_ERR_INVALID_PARAM; } - - uartDevice = (struct UartDevice *)host->priv; - if (uartDevice == NULL) { - HDF_LOGE("%s: device is NULL", __func__); - return HDF_ERR_INVALID_OBJECT; - } - uartId = uartDevice->uartId; - uartCfg = &uartDevice->config; - if (uartCfg == NULL) { - HDF_LOGE("%s: config is NULL", __func__); - return HDF_ERR_INVALID_OBJECT; - } - switch (attribute->dataBits) { case UART_ATTR_DATABIT_8: uartCfg->data = HAL_UART_DATA_BITS_8; @@ -778,16 +773,16 @@ static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribu uartCfg->flow = HAL_UART_FLOW_CONTROL_NONE; } - hal_uart_reopen(uartId, uartCfg); - return HDF_SUCCESS; } -static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribute *attribute) +static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribute *attribute) { HDF_LOGI("%s: Enter", __func__); struct UartDevice *uartDevice = NULL; struct HAL_UART_CFG_T *uartCfg = NULL; + uint32_t uartId; + int ret; if (host == NULL || attribute == NULL || host->priv == NULL) { HDF_LOGE("%s: invalid parameter", __func__); return HDF_ERR_INVALID_PARAM; @@ -798,12 +793,27 @@ static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribu HDF_LOGE("%s: device is NULL", __func__); return HDF_ERR_INVALID_OBJECT; } + uartId = uartDevice->uartId; uartCfg = &uartDevice->config; if (uartCfg == NULL) { HDF_LOGE("%s: config is NULL", __func__); return HDF_ERR_INVALID_OBJECT; } + ret = SetUartDevConfig(attribute, uartCfg); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: SetUartDevConfig error", __func__); + return HDF_FAILURE; + } + hal_uart_reopen(uartId, uartCfg); + return HDF_SUCCESS; +} +static int32_t GetUartDevConfig(struct UartAttribute *attribute, struct HAL_UART_CFG_T *uartCfg) +{ + if (attribute == NULL || uartCfg == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } switch (uartCfg->data) { case HAL_UART_DATA_BITS_8: attribute->dataBits = UART_ATTR_DATABIT_8; @@ -847,10 +857,33 @@ static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribu attribute->cts = 0; break; } - return HDF_SUCCESS; } +static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribute *attribute) +{ + HDF_LOGI("%s: Enter", __func__); + struct UartDevice *uartDevice = NULL; + struct HAL_UART_CFG_T *uartCfg = NULL; + if (host == NULL || attribute == NULL || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + uartDevice = (struct UartDevice *)host->priv; + if (uartDevice == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + uartCfg = &uartDevice->config; + if (uartCfg == NULL) { + HDF_LOGE("%s: config is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + return GetUartDevConfig(attribute, uartCfg); +} + static int32_t UartHostDevSetTransMode(struct UartHost *host, enum UartTransMode mode) { HDF_LOGI("%s: Enter", __func__); -- Gitee From 7311c9bbc01903d5ae22961ed3b0e43aa6165053 Mon Sep 17 00:00:00 2001 From: zhang Date: Fri, 11 Mar 2022 14:39:31 +0800 Subject: [PATCH 013/102] fix: modify config name of liteos_m about hdf macro parser Signed-off-by: zhang --- khdf/liteos_m/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/khdf/liteos_m/Kconfig b/khdf/liteos_m/Kconfig index b6adead..80ba928 100644 --- a/khdf/liteos_m/Kconfig +++ b/khdf/liteos_m/Kconfig @@ -35,7 +35,7 @@ config DRIVERS_HDF Answer Y to enable LiteOS support HDF. if DRIVERS_HDF config DRIVERS_HDF_CONFIG_MACRO - bool "Enable HDF platform driver" + bool "Enable HDF config macro parser" default n depends on DRIVERS_HDF help -- Gitee From 05848f62a2b568b83e9c301a6ce3c66197399bed Mon Sep 17 00:00:00 2001 From: zhangxiuping Date: Fri, 11 Mar 2022 16:39:37 +0800 Subject: [PATCH 014/102] connected tag host for hdf adapter. Signed-off-by: zhangxiuping --- uhdf2/host/hdf_devhost.cfg | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/uhdf2/host/hdf_devhost.cfg b/uhdf2/host/hdf_devhost.cfg index 8f39da0..78b4663 100644 --- a/uhdf2/host/hdf_devhost.cfg +++ b/uhdf2/host/hdf_devhost.cfg @@ -161,6 +161,13 @@ "uid" : "root", "gid" : ["system"] }, + { + "name" : "connected_tag_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "root", + "gid" : ["system"] + }, { "name" : "a2dp_host", "dynamic" : true, -- Gitee From 05c8a9c9268731eab1d76bbd2b12e7694bedf09e Mon Sep 17 00:00:00 2001 From: "weidongwang@bestechnic.com" Date: Fri, 11 Mar 2022 14:58:23 +0800 Subject: [PATCH 015/102] hdf support bes chip2700 Signed-off-by: weidongwang@bestechnic.com --- platform/gpio/gpio_bes.c | 10 +- platform/i2c/i2c_bes.c | 10 ++ platform/i2c/i2c_bes.h | 2 + platform/pwm/pwm_bes.c | 9 +- platform/pwm/pwm_bes.h | 2 + platform/spi/spi_bes.c | 164 ++++++++++++++++------------ platform/spi/spi_bes.h | 2 + platform/uart/uart_bes.c | 228 +++++++++++++++++++++++++++------------ 8 files changed, 284 insertions(+), 143 deletions(-) diff --git a/platform/gpio/gpio_bes.c b/platform/gpio/gpio_bes.c index e2a4465..45b85bf 100644 --- a/platform/gpio/gpio_bes.c +++ b/platform/gpio/gpio_bes.c @@ -75,13 +75,9 @@ typedef int32_t (*oem_gpio_irq_handler_t)(uint16_t gpio, void *data); #define OCTALNUM 8 static struct GpioCntlr g_gpioCntlr; -struct OemGpioIrqHandler { - uint8_t port; - GpioIrqFunc func; - void *arg; -}; enum HAL_GPIO_PIN_T g_gpioPinReflectionMap[HAL_GPIO_PIN_LED_NUM] = {0}; + static struct HAL_GPIO_IRQ_CFG_T g_gpioIrqCfg[HAL_GPIO_PIN_LED_NUM] = {0}; static struct HAL_GPIO_IRQ_CFG_T HalGpioGetIrqConfig(enum HAL_GPIO_PIN_T pin) @@ -281,7 +277,6 @@ static uint32_t GetGpioDeviceResource( } #endif - static int32_t AttachGpioDevice(struct GpioCntlr *gpioCntlr, struct HdfDeviceObject *device) { int32_t ret; @@ -312,7 +307,7 @@ static int32_t AttachGpioDevice(struct GpioCntlr *gpioCntlr, struct HdfDeviceObj } gpioCntlr->count = gpioDevice->resource.pinNum; - + gpioCntlr->priv = (void *)gpioDevice; return HDF_SUCCESS; } @@ -368,6 +363,7 @@ static void GpioDriverRelease(struct HdfDeviceObject *device) return HDF_DEV_ERR_NO_DEVICE_SERVICE; } + gpioCntlr->ops = NULL; (void)OsalMemFree(gpioCntlr->priv); gpioCntlr->count = 0; } diff --git a/platform/i2c/i2c_bes.c b/platform/i2c/i2c_bes.c index 9303c97..e178c8a 100755 --- a/platform/i2c/i2c_bes.c +++ b/platform/i2c/i2c_bes.c @@ -66,6 +66,7 @@ static void I2cDeviceIomuxInit(uint32_t i2cId, struct I2cResource *resource) {0, 0, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}, }; +#ifdef CHIP_BEST2003 if (i2cId == 0) { pinMuxI2c[0].function = HAL_IOMUX_FUNC_I2C_M0_SCL; pinMuxI2c[1].function = HAL_IOMUX_FUNC_I2C_M0_SDA; @@ -73,6 +74,15 @@ static void I2cDeviceIomuxInit(uint32_t i2cId, struct I2cResource *resource) pinMuxI2c[0].function = HAL_IOMUX_FUNC_I2C_M1_SCL; pinMuxI2c[1].function = HAL_IOMUX_FUNC_I2C_M1_SDA; } +#elif defined (CHIP_BEST1600) + if (i2cId == 0) { + pinMuxI2c[0].function = HAL_IOMUX_FUNC_SYS_I2C_M0_SCL; + pinMuxI2c[1].function = HAL_IOMUX_FUNC_SYS_I2C_M0_SDA; + } else { + pinMuxI2c[0].function = HAL_IOMUX_FUNC_SYS_I2C_M1_SCL; + pinMuxI2c[1].function = HAL_IOMUX_FUNC_SYS_I2C_M1_SDA; + } +#endif pinMuxI2c[0].pin = resource->sclPin; pinMuxI2c[1].pin = resource->sdaPin; hal_iomux_init(pinMuxI2c, ARRAY_SIZE(pinMuxI2c)); diff --git a/platform/i2c/i2c_bes.h b/platform/i2c/i2c_bes.h index b4c5945..bc228d8 100755 --- a/platform/i2c/i2c_bes.h +++ b/platform/i2c/i2c_bes.h @@ -18,7 +18,9 @@ #include "hal_i2c.h" #include "hal_iomux.h" +#ifdef CHIP_BEST2003 #include "hal_iomux_best2003.h" +#endif #include "device_resource_if.h" #include "osal_mutex.h" #ifdef __cplusplus diff --git a/platform/pwm/pwm_bes.c b/platform/pwm/pwm_bes.c index 5b6824a..eb6ec82 100755 --- a/platform/pwm/pwm_bes.c +++ b/platform/pwm/pwm_bes.c @@ -18,7 +18,6 @@ #include "hdf_device_desc.h" #include "hal_trace.h" #include "hal_timer.h" -#include "hal_iomux.h" #include "pwm_core.h" #include "hdf_log.h" #ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO @@ -28,7 +27,13 @@ #include "device_resource_if.h" #endif +#if defined (CHIP_BEST1600) +#define PWM_MAX_FUNCTION 4 +#elif defined (CHIP_BEST2003) +#include "hal_iomux.h" #define PWM_MAX_FUNCTION 8 +#endif + #define UNTIL_NAN0SECONDS 1000000000 #define PERCENT 100 #define DEC_TEN 10 @@ -39,10 +44,12 @@ static uint32_t g_pwmFunction[PWM_MAX_FUNCTION] = { HAL_IOMUX_FUNC_PWM1, HAL_IOMUX_FUNC_PWM2, HAL_IOMUX_FUNC_PWM3, +#if defined (CHIP_BEST2003) HAL_IOMUX_FUNC_PWM4, HAL_IOMUX_FUNC_PWM5, HAL_IOMUX_FUNC_PWM6, HAL_IOMUX_FUNC_PWM7, +#endif }; static int32_t PwmDevSetConfig(struct PwmDev *pwm, struct PwmConfig *config); diff --git a/platform/pwm/pwm_bes.h b/platform/pwm/pwm_bes.h index 0bc76f9..83bbe82 100755 --- a/platform/pwm/pwm_bes.h +++ b/platform/pwm/pwm_bes.h @@ -17,7 +17,9 @@ #include "hal_pwm.h" #include "hal_gpio.h" +#ifdef CHIP_BEST2003 #include "hal_iomux.h" +#endif #include "pwm_core.h" #ifdef __cplusplus diff --git a/platform/spi/spi_bes.c b/platform/spi/spi_bes.c index 9111269..2477f4f 100755 --- a/platform/spi/spi_bes.c +++ b/platform/spi/spi_bes.c @@ -43,10 +43,17 @@ static void Spi1DmaIrq(int error); static struct SPI_CTX_OBJ_T spiCtx[MAX_SPI_NUMBER] = { { .spiPinCS0 = 0, +#if defined (CHIP_BEST1600) + .spiFunDI0 = HAL_IOMUX_FUNC_SYS_SPI_DI0, + .spiFunCLK = HAL_IOMUX_FUNC_SYS_SPI_CLK, + .spiFunCS0 = HAL_IOMUX_FUNC_SYS_SPI_CS0, + .spiFunDIO = HAL_IOMUX_FUNC_SYS_SPI_DIO, +#elif defined (CHIP_BEST2003) .spiFunDI0 = HAL_IOMUX_FUNC_SPI_DI0, .spiFunCLK = HAL_IOMUX_FUNC_SPI_CLK, .spiFunCS0 = HAL_IOMUX_FUNC_SPI_CS0, .spiFunDIO = HAL_IOMUX_FUNC_SPI_DIO, +#endif .sem = { NULL }, .mutex = { NULL }, .SpiOpen = hal_spi_open, @@ -59,10 +66,17 @@ static struct SPI_CTX_OBJ_T spiCtx[MAX_SPI_NUMBER] = { }, { .spiPinCS0 = 0, +#if defined (CHIP_BEST1600) + .spiFunDI0 = HAL_IOMUX_FUNC_SYS_SPILCD_DI0, + .spiFunCLK = HAL_IOMUX_FUNC_SYS_SPILCD_CLK, + .spiFunCS0 = HAL_IOMUX_FUNC_SYS_SPILCD_CS0, + .spiFunDIO = HAL_IOMUX_FUNC_SYS_SPILCD_DIO, +#elif defined (CHIP_BEST2003) .spiFunDI0 = HAL_IOMUX_FUNC_SPILCD_DI0, .spiFunCLK = HAL_IOMUX_FUNC_SPILCD_CLK, .spiFunCS0 = HAL_IOMUX_FUNC_SPILCD_CS0, .spiFunDIO = HAL_IOMUX_FUNC_SPILCD_DIO, +#endif .sem = { NULL }, .mutex = { NULL }, .SpiOpen = hal_spilcd_open, @@ -141,14 +155,55 @@ static void SpiIomuxInit(struct SpiDevice *spiDevice) pinMuxSpi[SPI_PIN_2].function = spiCtx[spiPort].spiFunCS0; pinMuxSpi[SPI_PIN_3].function = spiCtx[spiPort].spiFunDIO; - if (spiDevCfg->rate > MAX_SPI_SPEED) { - hal_iomux_set_io_drv(pinMuxSpi[SPI_PIN_1].pin, DRIVER_LEVEL); - hal_iomux_set_io_drv(pinMuxSpi[SPI_PIN_3].pin, DRIVER_LEVEL); - } + hal_iomux_set_io_drv(pinMuxSpi[SPI_PIN_0].pin, DRIVER_LEVEL); + hal_iomux_set_io_drv(pinMuxSpi[SPI_PIN_1].pin, DRIVER_LEVEL); + hal_iomux_set_io_drv(pinMuxSpi[SPI_PIN_2].pin, DRIVER_LEVEL); + hal_iomux_set_io_drv(pinMuxSpi[SPI_PIN_3].pin, DRIVER_LEVEL); hal_iomux_init(pinMuxSpi, ARRAY_SIZE(pinMuxSpi)); } +static int32_t SpiDevCfgInit(struct HAL_SPI_CFG_T *spiDevCfg, struct SpiResource *resource) +{ + if (spiDevCfg == NULL || resource == NULL) { + HDF_LOGE("spi input para err\r\n"); + return HDF_ERR_INVALID_PARAM; + } + switch (resource->mode) { + case SPI_WORK_MODE_0: + spiDevCfg->clk_delay_half = false; + spiDevCfg->clk_polarity = false; + break; + case SPI_WORK_MODE_1: + spiDevCfg->clk_delay_half = true; + spiDevCfg->clk_polarity = false; + break; + case SPI_WORK_MODE_2: + spiDevCfg->clk_delay_half = false; + spiDevCfg->clk_polarity = true; + break; + case SPI_WORK_MODE_3: + spiDevCfg->clk_delay_half = true; + spiDevCfg->clk_polarity = true; + break; + default: + spiDevCfg->clk_delay_half = true; + spiDevCfg->clk_polarity = true; + } + spiDevCfg->slave = 0; + if (resource->transmode == SPI_TRANSFER_DMA) { + spiDevCfg->dma_rx = true; + spiDevCfg->dma_tx = true; + } else { + spiDevCfg->dma_rx = false; + spiDevCfg->dma_tx = false; + } + spiDevCfg->cs = 0; + spiDevCfg->rx_bits = resource->dataSize; + spiDevCfg->tx_bits = resource->dataSize; + spiDevCfg->rx_frame_bits = 0; + return HDF_SUCCESS; +} /** * Spi send * @@ -188,7 +243,9 @@ int32_t HalSpiSend(struct SpiDevice *spiDevice, const uint8_t *data, uint16_t si HDF_LOGE("%s spi_mutex wait error = 0x%X!\r\n", __func__, status); return HDF_ERR_TIMEOUT; } - +#ifdef CHIP_BEST1600 + hal_cache_sync_all(HAL_CACHE_ID_D_CACHE); +#endif if (resource->transmode == SPI_TRANSFER_DMA) { ret = spiCtx[spiId].SpiDmaSend(data, len, spiCtx[spiId].SpiDmaIrq); if (OsalSemWait(&spiCtx[spiId].sem, timeOut) != HDF_SUCCESS) { @@ -243,42 +300,38 @@ static int32_t HalSpiRecv(struct SpiDevice *spiDevice, uint8_t *data, uint16_t s HDF_LOGE("resource is null\r\n"); return HDF_ERR_INVALID_OBJECT; } - cmd = (uint8_t *)OsalMemAlloc(len); - if (cmd == NULL) { - HDF_LOGE("%s OsalMemAlloc size %ld error\r\n", __FUNCTION__, len); - return HDF_ERR_MALLOC_FAIL; - } - - memset_s(cmd, len, 0, len); + cmd = (uint8_t *)0x20020000; // 0x20020000 : non secure sram base. tx buf is useless, use sram instead of malloc. status = OsalMutexLock(&spiCtx[spiId].mutex); if (HDF_SUCCESS != status) { HDF_LOGE("%s spi_mutex wait error = 0x%X!\r\n", __func__, status); - OsalMemFree(cmd); return HDF_ERR_TIMEOUT; } - remainder = ((len <= SPI_DMA_MAX) ? len : SPI_DMA_MAX); - - if (resource->transmode == SPI_TRANSFER_DMA) { - ret = spiCtx[spiId].SpiDmaRecv(cmd, data, remainder, spiCtx[spiId].SpiDmaIrq); - if (OsalSemWait(&spiCtx[spiId].sem, timeOut) <= 0) { - HDF_LOGE("SPI Read timeOut!\r\n"); - goto OUT; +#ifdef CHIP_BEST1600 + hal_cache_sync_all(HAL_CACHE_ID_D_CACHE); +#endif + do { + remainder = len <= SPI_DMA_MAX ? len : SPI_DMA_MAX; + if (resource->transmode == SPI_TRANSFER_DMA) { + ret = spiCtx[spiId].SpiDmaRecv(cmd, data, remainder, spiCtx[spiId].SpiDmaIrq); + if (OsalSemWait(&spiCtx[spiId].sem, timeOut) <= 0) { + HDF_LOGE("SPI Read timeOut!\r\n"); + goto OUT; + } + } else { + ret = spiCtx[spiId].SpiRecv(cmd, data, remainder); } - } else { - ret = spiCtx[spiId].SpiRecv(cmd, data, remainder); - } - len -= remainder; - data += remainder; + len -= remainder; + data += remainder; - if (ret) { - HDF_LOGE("spi tail fail %ld, size %ld\r\n", ret, len); - goto OUT; - } + if (ret != 0) { + HDF_LOGE("spi tail fail %ld, size %ld\r\n", ret, len); + goto OUT; + } + } while (len); OUT: OsalMutexUnlock(&spiCtx[spiId].mutex); - OsalMemFree(cmd); return ret; } @@ -300,10 +353,12 @@ static int32_t HalSpiSendRecv(struct SpiDevice *spiDevice, uint8_t *txData, uint resource = &spiDevice->resource; status = OsalMutexLock(&spiCtx[spiId].mutex); if (HDF_SUCCESS != status) { - HDF_LOGE("%s spi_mutex wait error = 0x%X!\r\n", __func__, status); + HDF_LOGE("%s OsalMutexLock error = 0x%X!\r\n", __func__, status); return HDF_ERR_TIMEOUT; } - +#ifdef CHIP_BEST1600 + hal_cache_sync_all(HAL_CACHE_ID_D_CACHE); +#endif if (resource->transmode == SPI_TRANSFER_DMA) { ret = spiCtx[spiId].SpiDmaRecv(txData, rxData, rxSize, spiCtx[spiId].SpiDmaIrq); if (OsalSemWait(&spiCtx[spiId].sem, TIMEOUT) <= 0) { @@ -315,7 +370,6 @@ static int32_t HalSpiSendRecv(struct SpiDevice *spiDevice, uint8_t *txData, uint } if (ret) { HDF_LOGE("spi dma tail fail %d\r\n", ret); - goto OUT; } OUT: OsalMutexUnlock(&spiCtx[spiId].mutex); @@ -325,6 +379,7 @@ OUT: static int32_t InitSpiDevice(struct SpiDevice *spiDevice) { uint32_t spiPort; + int32_t ret; struct HAL_SPI_CFG_T *spiDevCfg = NULL; struct SpiResource *resource = NULL; if (spiDevice == NULL) { @@ -337,40 +392,11 @@ static int32_t InitSpiDevice(struct SpiDevice *spiDevice) spiPort = spiDevice->spiId; SpiIomuxInit(spiDevice); - - switch (resource->mode) { - case SPI_WORK_MODE_0: - spiDevCfg->clk_delay_half = false; - spiDevCfg->clk_polarity = false; - break; - case SPI_WORK_MODE_1: - spiDevCfg->clk_delay_half = true; - spiDevCfg->clk_polarity = false; - break; - case SPI_WORK_MODE_2: - spiDevCfg->clk_delay_half = false; - spiDevCfg->clk_polarity = true; - break; - case SPI_WORK_MODE_3: - spiDevCfg->clk_delay_half = true; - spiDevCfg->clk_polarity = true; - break; - default: - spiDevCfg->clk_delay_half = true; - spiDevCfg->clk_polarity = true; - } - spiDevCfg->slave = 0; - if (resource->transmode == SPI_TRANSFER_DMA) { - spiDevCfg->dma_rx = true; - spiDevCfg->dma_tx = true; - } else { - spiDevCfg->dma_rx = false; - spiDevCfg->dma_tx = false; + ret = SpiDevCfgInit(spiDevCfg, resource); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: SPI config init failed\r\n", __func__); + return HDF_FAILURE; } - spiDevCfg->cs = 0; - spiDevCfg->rx_bits = resource->dataSize; - spiDevCfg->tx_bits = resource->dataSize; - spiDevCfg->rx_frame_bits = 0; /* spi open move to hdf open api */ /* if cs use as gpio ,pull up at first */ if (spiCtx[spiPort].spiFunCS0 == HAL_IOMUX_FUNC_AS_GPIO) { @@ -397,6 +423,9 @@ static int32_t InitSpiDevice(struct SpiDevice *spiDevice) #ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO static int32_t GetSpiDeviceResource(struct SpiDevice *spiDevice, const char *deviceMatchAttr) { + (void)spiDevice; + (void)deviceMatchAttr; + return HDF_SUCCESS; } #else static int32_t GetSpiDeviceResource(struct SpiDevice *spiDevice, const struct DeviceResourceNode *resourceNode) @@ -489,6 +518,7 @@ static int32_t GetSpiDeviceResource(struct SpiDevice *spiDevice, const struct De return HDF_SUCCESS; } #endif + int32_t AttachSpiDevice(struct SpiCntlr *spiCntlr, struct HdfDeviceObject *device) { int32_t ret; @@ -693,6 +723,7 @@ static int32_t SpiDevGetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg) return HDF_SUCCESS; } + static int32_t SpiDevSetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg) { struct SpiDevice *spiDevice = NULL; @@ -727,7 +758,6 @@ static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg, HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__); return HDF_ERR_INVALID_PARAM; } - HDF_LOGI("%s: %u Enter\r\n", __func__, spiId); spiDevice = (struct SpiDevice *)spiCntlr->priv; spiId = spiDevice->spiId; for (size_t i = 0; i < count; i++) { diff --git a/platform/spi/spi_bes.h b/platform/spi/spi_bes.h index c274f10..aef33e8 100755 --- a/platform/spi/spi_bes.h +++ b/platform/spi/spi_bes.h @@ -18,7 +18,9 @@ #include "hal_spi.h" #include "hal_gpio.h" #include "hal_iomux.h" +#ifdef CHIP_BEST2003 #include "hal_iomux_best2003.h" +#endif #include "osal_mutex.h" #include "osal_sem.h" diff --git a/platform/uart/uart_bes.c b/platform/uart/uart_bes.c index 7371125..2f08f7e 100755 --- a/platform/uart/uart_bes.c +++ b/platform/uart/uart_bes.c @@ -27,18 +27,29 @@ #include "hal_cache.h" #include "hdf_log.h" -#define HDF_UART_TMO 1000 + +#define HDF_UART_TMO OSAL_WAIT_FOREVER #define HDF_LOG_TAG uartDev #define UART_FIFO_MAX_BUFFER 2048 #define UART_DMA_RING_BUFFER_SIZE 256 // mast be 2^n - +#ifdef CHIP_BEST1600 +#include "hal_location.h" +#define MAX_UART_NUMBER 2 +#define MAX_UART_ID HAL_UART_ID_1 +static SRAM_BSS_LOC unsigned char g_halUartBuf[UART_DMA_RING_BUFFER_SIZE]; +static SRAM_BSS_LOC unsigned char g_halUart1Buf[UART_DMA_RING_BUFFER_SIZE]; +static unsigned char *g_uartKfifoBuffer[MAX_UART_NUMBER] = { NULL, NULL }; +#elif defined (CHIP_BEST2003) +#define MAX_UART_NUMBER 3 +#define MAX_UART_ID HAL_UART_ID_2 static __SRAMBSS unsigned char g_halUartBuf[UART_DMA_RING_BUFFER_SIZE]; static __SRAMBSS unsigned char g_halUart1Buf[UART_DMA_RING_BUFFER_SIZE]; static __SRAMBSS unsigned char g_halUart2Buf[UART_DMA_RING_BUFFER_SIZE]; +static unsigned char *g_uartKfifoBuffer[MAX_UART_NUMBER] = {NULL, NULL, NULL}; +#endif -static struct UART_CTX_OBJ g_uartCtx[4] = {0}; -static unsigned char *g_uartKfifoBuffer[4] = {NULL, NULL, NULL, NULL}; +static struct UART_CTX_OBJ g_uartCtx[MAX_UART_NUMBER] = {0}; struct HAL_UART_CFG_T g_lowUartCfg = { // used for tgdb cli console .parity = HAL_UART_PARITY_NONE, @@ -55,19 +66,29 @@ struct HAL_UART_CFG_T g_lowUartCfg = { static void HalSetUartIomux(enum HAL_UART_ID_T uartId) { + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %d not support!\r\n", __func__, uartId); + return; + } if (uartId == HAL_UART_ID_0) { hal_iomux_set_uart0(); - } else if (uartId == HAL_UART_ID_1) { + } + if (uartId == HAL_UART_ID_1) { hal_iomux_set_uart1(); - } else if (uartId == HAL_UART_ID_2) { + } +#ifdef CHIP_BEST2003 + if (uartId == HAL_UART_ID_2) { hal_iomux_set_uart2(); - } else { - hal_iomux_set_uart3(); } +#endif } -static void HalUartRxStart(uint32_t uartId) +static void HalUartStartDmaRx(uint32_t uartId) { + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %d not support!\r\n", __func__, uartId); + return; + } struct HAL_DMA_DESC_T dmaDescRx; uint32_t descCnt; union HAL_UART_IRQ_T mask; @@ -82,18 +103,24 @@ static void HalUartRxStart(uint32_t uartId) hal_uart_dma_recv_mask(uartId, g_uartCtx[uartId].buffer, UART_DMA_RING_BUFFER_SIZE, &dmaDescRx, &descCnt, &mask); } -static void UartRxHandler(enum HAL_UART_ID_T id, union HAL_UART_IRQ_T status) +static void UartRxHandler(enum HAL_UART_ID_T uartId, union HAL_UART_IRQ_T status) { - int32_t ret; - + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %d not support!\r\n", __func__, uartId); + return; + } if (status.TX) { - ret = OsalSemPost(&g_uartCtx[id].txSem); - ASSERT(ret == HDF_SUCCESS, "%s: Failed to release write_sem: %d", __func__, ret); + if (OsalSemPost(&g_uartCtx[uartId].txSem != HDF_SUCCESS)) { + HDF_LOGE("%s OsalSemPost txSem failed!\r\n", __func__); + return; + } } if (status.RX || status.RT) { - ret = OsalSemPost(&g_uartCtx[id].rxSem); - ASSERT(ret == HDF_SUCCESS, "%s: Failed to release read_sem: %d", __func__, ret); + if (OsalSemPost(&g_uartCtx[uartId].rxSem != HDF_SUCCESS)) { + HDF_LOGE("%s OsalSemPost rxSem failed!\r\n", __func__); + return; + } } } @@ -108,7 +135,7 @@ static void UartDmaRxHandler(uint32_t xferSize, int dmaError, union HAL_UART_IRQ memset_s(g_uartCtx[HAL_UART_ID_0].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE); OsalSemPost(&g_uartCtx[HAL_UART_ID_0].rxSem); - HalUartRxStart(HAL_UART_ID_0); + HalUartStartDmaRx(HAL_UART_ID_0); } static void UartDmaTxHandler(uint32_t xferSize, int dmaError) @@ -126,7 +153,7 @@ static void Uart1DmaRxHandler(uint32_t xferSize, int dmaError, union HAL_UART_IR } memset_s(g_uartCtx[HAL_UART_ID_1].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE); OsalSemPost(&g_uartCtx[HAL_UART_ID_1].rxSem); - HalUartRxStart(HAL_UART_ID_1); + HalUartStartDmaRx(HAL_UART_ID_1); } static void Uart1DmaTxHandler(uint32_t xferSize, int dmaError) @@ -134,6 +161,7 @@ static void Uart1DmaTxHandler(uint32_t xferSize, int dmaError) OsalSemPost(&g_uartCtx[HAL_UART_ID_1].txSem); } +#ifdef CHIP_BEST2003 /* uart2 */ static void Uart2DmaRxHandler(uint32_t xferSize, int dmaError, union HAL_UART_IRQ_T status) { @@ -146,16 +174,21 @@ static void Uart2DmaRxHandler(uint32_t xferSize, int dmaError, union HAL_UART_IR memset_s(g_uartCtx[HAL_UART_ID_2].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE); OsalSemPost(&g_uartCtx[HAL_UART_ID_2].rxSem); - HalUartRxStart(HAL_UART_ID_2); + HalUartStartDmaRx(HAL_UART_ID_2); } static void Uart2DmaTxHandler(uint32_t xferSize, int dmaError) { OsalSemPost(&g_uartCtx[HAL_UART_ID_2].txSem); } +#endif static void HalUartStartRx(uint32_t uartId) { + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__); + return; + } union HAL_UART_IRQ_T mask; mask.reg = 0; mask.RT = 1; @@ -170,17 +203,19 @@ static int32_t HalUartSend(uint32_t uartId, const void *data, uint32_t size, uin int32_t ret; struct HAL_DMA_DESC_T dmaSescTx; uint32_t descCnt; - if (data == NULL || size == 0) { HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__); return HDF_ERR_INVALID_PARAM; } - if (uartId > HAL_UART_ID_2) { + if (uartId > MAX_UART_ID) { HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__); return HDF_ERR_NOT_SUPPORT; } descCnt = 1; +#ifdef CHIP_BEST1600 + hal_cache_sync_all(HAL_CACHE_ID_D_CACHE); +#endif hal_uart_dma_send(uartId, data, size, &dmaSescTx, &descCnt); OsalSemWait(&g_uartCtx[uartId].txSem, timeOut); @@ -201,7 +236,7 @@ static int32_t HalUartRecv(uint8_t uartId, void *data, uint32_t expectSize, return HDF_ERR_INVALID_PARAM; } - if (uartId > HAL_UART_ID_2) { + if (uartId > MAX_UART_ID) { HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__); return HDF_ERR_NOT_SUPPORT; } @@ -229,19 +264,31 @@ static int32_t HalUartRecv(uint8_t uartId, void *data, uint32_t expectSize, if (recvSize != NULL) { *recvSize = recvedLen; } - return HDF_SUCCESS; } -static void HalUartHandlerInit(struct UartDevice *device) +static int32_t InitUartCtxCfg(struct UartDevice *device) { uint32_t uartId; + struct HAL_UART_CFG_T *uartCfg = NULL; if (device == NULL) { HDF_LOGE("%s: INVALID PARAM", __func__); - return; + return HDF_ERR_INVALID_OBJECT; + } + uartCfg = &device->config; + if (uartCfg == NULL) { + HDF_LOGE("%s: INVALID OBJECT", __func__); + return HDF_ERR_INVALID_OBJECT; } uartId = device->uartId; - HDF_LOGI("%s %ld\r\n", __func__, uartId); + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %d NOT SUPPORT \r\n", __FILE__, __LINE__); + return HDF_ERR_NOT_SUPPORT; + } + memset_s(&g_uartCtx[uartId], sizeof(struct UART_CTX_OBJ), 0, sizeof(struct UART_CTX_OBJ)); + g_uartCtx[uartId].txDMA = uartCfg->dma_tx; + g_uartCtx[uartId].rxDMA = uartCfg->dma_rx; + if (uartId == HAL_UART_ID_0) { g_uartCtx[uartId].UartDmaRxHandler = UartDmaRxHandler; g_uartCtx[uartId].UartDmaTxHandler = UartDmaTxHandler; @@ -253,13 +300,36 @@ static void HalUartHandlerInit(struct UartDevice *device) g_uartCtx[uartId].UartDmaTxHandler = Uart1DmaTxHandler; g_uartCtx[uartId].buffer = g_halUart1Buf; } - +#ifdef CHIP_BEST2003 if (uartId == HAL_UART_ID_2) { g_uartCtx[uartId].UartDmaRxHandler = Uart2DmaRxHandler; g_uartCtx[uartId].UartDmaTxHandler = Uart2DmaTxHandler; g_uartCtx[uartId].buffer = g_halUart2Buf; } +#endif + return HDF_SUCCESS; +} + +static void HalUartHandlerInit(struct UartDevice *device) +{ + uint32_t uartId; + int32_t ret; + struct HAL_UART_CFG_T *uartCfg = NULL; + if (device == NULL) { + HDF_LOGE("%s: INVALID PARAM!\r\n", __func__); + return; + } + uartId = device->uartId; + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %d NOT SUPPORT!\r\n", __FILE__, __LINE__); + return; + } + ret = InitUartCtxCfg(device); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s %d InitUartCtxCfg failed\r\n", __FILE__, __LINE__); + return; + } if (!g_uartKfifoBuffer[uartId]) { g_uartKfifoBuffer[uartId] = (char *)OsalMemAlloc(UART_FIFO_MAX_BUFFER); if (!g_uartKfifoBuffer[uartId]) { @@ -269,13 +339,19 @@ static void HalUartHandlerInit(struct UartDevice *device) kfifo_init(&g_uartCtx[uartId].fifo, g_uartKfifoBuffer[uartId], UART_FIFO_MAX_BUFFER); } - OsalSemInit(&g_uartCtx[uartId].rxSem, 0); - OsalSemInit(&g_uartCtx[uartId].txSem, 0); + if (OsalSemInit(&g_uartCtx[uartId].rxSem, 0) != HDF_SUCCESS) { + HDF_LOGE("UART rxsem init failed!"); + return; + } + if (OsalSemInit(&g_uartCtx[uartId].txSem, 0) != HDF_SUCCESS) { + HDF_LOGE("UART txsem init failed!"); + return; + } - if (g_uartCtx[uartId].rxDMA) { - HDF_LOGE("uart %ld start dma rx\r\n", uartId); + if (g_uartCtx[uartId].rxDMA == true) { + HDF_LOGI("uart %ld start dma rx\r\n", uartId); hal_uart_irq_set_dma_handler(uartId, g_uartCtx[uartId].UartDmaRxHandler, g_uartCtx[uartId].UartDmaTxHandler); - HalUartRxStart(uartId); + HalUartStartDmaRx(uartId); } else { HalUartStartRx(uartId); } @@ -290,13 +366,16 @@ static void UartStart(struct UartDevice *device) return; } uartId = device->uartId; + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %d NOT SUPPORT \r\n", __FILE__, __LINE__); + return HDF_ERR_NOT_SUPPORT; + } uartCfg = &device->config; if (uartCfg == NULL) { HDF_LOGE("%s: INVALID OBJECT", __func__); return; } hal_uart_open(uartId, uartCfg); - HDF_LOGI("%s %ld\r\n", __FUNCTION__, uartId); HalUartHandlerInit(device); } @@ -367,20 +446,15 @@ static int InitUartDevice(struct UartHost *host) HDF_LOGE("%s: INVALID OBJECT", __func__); return HDF_ERR_INVALID_OBJECT; } - uartDevice->uartId = resource->num; - uartCfg->parity = resource->parity; - uartCfg->stop = resource->stopBit; - uartCfg->data = resource->wLen; + uint32_t uartId = resource->num; + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %d NOT SUPPORT \r\n", __FILE__, __LINE__); + return HDF_ERR_NOT_SUPPORT; + } uartCfg->flow = HAL_UART_FLOW_CONTROL_NONE; - uartCfg->tx_level = HAL_UART_FIFO_LEVEL_1_2; + uartCfg->tx_level = HAL_UART_FIFO_LEVEL_1_8; uartCfg->rx_level = HAL_UART_FIFO_LEVEL_1_2; - uartCfg->baud = resource->baudRate; uartCfg->dma_rx_stop_on_err = false; - uartCfg->dma_rx = resource->rxDMA; - uartCfg->dma_tx = resource->txDMA; - - g_uartCtx[uartDevice->uartId].txDMA = resource->txDMA; - g_uartCtx[uartDevice->uartId].rxDMA = resource->rxDMA; if (!uartDevice->initFlag) { HDF_LOGE("uart %ld device init\r\n", uartDevice->uartId); @@ -443,6 +517,7 @@ static uint32_t GetUartDeviceResource( resource->rxDMA = dri->GetBool(resourceNode, "rxDMA"); // copy config + device->initFlag = false; device->uartId = resource->num; device->config.baud = resource->baudRate; device->config.parity = resource->parity; @@ -602,7 +677,7 @@ static int32_t UartHostDevDeinit(struct UartHost *host) static int32_t UartHostDevWrite(struct UartHost *host, uint8_t *data, uint32_t size) { struct UartDevice *device = NULL; - uint32_t portId; + uint32_t uartId; if (host == NULL || data == NULL || size == 0 || host->priv == NULL) { HDF_LOGE("%s: invalid parameter", __func__); @@ -615,15 +690,19 @@ static int32_t UartHostDevWrite(struct UartHost *host, uint8_t *data, uint32_t s return HDF_ERR_INVALID_OBJECT; } - portId = device->uartId; - if (g_uartCtx[portId].txDMA) { - HalUartSend(portId, data, size, HDF_UART_TMO); + uartId = device->uartId; + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %d NOT SUPPORT \r\n", __FILE__, __LINE__); + return HDF_ERR_NOT_SUPPORT; + } + if (g_uartCtx[uartId].txDMA) { + HalUartSend(uartId, data, size, HDF_UART_TMO); } else { for (uint32_t idx = 0; idx < size; idx++) { - if (g_uartCtx[portId].isBlock) { - hal_uart_blocked_putc(portId, data[idx]); + if (g_uartCtx[uartId].isBlock) { + hal_uart_blocked_putc(uartId, data[idx]); } else { - hal_uart_putc(portId, data[idx]); + hal_uart_putc(uartId, data[idx]); } } } @@ -660,7 +739,9 @@ static int32_t UartHostDevRead(struct UartHost *host, uint8_t *data, uint32_t si if (g_uartCtx[uartId].isBlock) { data[0] = hal_uart_blocked_getc(uartId); } else { - data[0] = hal_uart_getc(uartId); + if (hal_uart_readable(uartId) > 0) { + data[0] = hal_uart_getc(uartId); + } } ret = 1; } @@ -685,7 +766,10 @@ static int32_t UartHostDevSetBaud(struct UartHost *host, uint32_t baudRate) return HDF_ERR_INVALID_OBJECT; } uartId = uartDevice->uartId; - + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %d NOT SUPPORT \r\n", __FILE__, __LINE__); + return HDF_ERR_NOT_SUPPORT; + } uartCfg = &uartDevice->config; if (uartCfg == NULL) { HDF_LOGE("%s: device config is NULL", __func__); @@ -693,7 +777,7 @@ static int32_t UartHostDevSetBaud(struct UartHost *host, uint32_t baudRate) } uartCfg->baud = baudRate; - hal_uart_reopen(uartId, uartCfg); + hal_uart_open(uartId, uartCfg); return HDF_SUCCESS; } @@ -714,6 +798,10 @@ static int32_t UartHostDevGetBaud(struct UartHost *host, uint32_t *baudRate) return HDF_ERR_INVALID_OBJECT; } uartId = uartDevice->uartId; + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %d NOT SUPPORT \r\n", __FILE__, __LINE__); + return HDF_ERR_NOT_SUPPORT; + } uartCfg = &uartDevice->config; if (uartCfg == NULL) { HDF_LOGE("%s: device is NULL", __func__); @@ -727,12 +815,21 @@ static int32_t UartHostDevGetBaud(struct UartHost *host, uint32_t *baudRate) return HDF_SUCCESS; } -static int32_t SetUartDevConfig(struct UartAttribute *attribute, struct HAL_UART_CFG_T *uartCfg) +static int32_t SetUartDevConfig(struct UartAttribute *attribute, struct UartDevice *uartDevice) { - if (attribute == NULL || uartCfg == NULL) { + struct HAL_UART_CFG_T *uartCfg = NULL; + uint32_t uartId; + if (attribute == NULL || uartDevice == NULL) { HDF_LOGE("%s: invalid parameter", __func__); return HDF_ERR_INVALID_PARAM; } + uartId = uartDevice->uartId; + uartCfg = &uartDevice->config; + if (uartCfg == NULL) { + HDF_LOGE("%s: config is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + switch (attribute->dataBits) { case UART_ATTR_DATABIT_8: uartCfg->data = HAL_UART_DATA_BITS_8; @@ -772,7 +869,7 @@ static int32_t SetUartDevConfig(struct UartAttribute *attribute, struct HAL_UART } else { uartCfg->flow = HAL_UART_FLOW_CONTROL_NONE; } - + hal_uart_open(uartId, uartCfg); return HDF_SUCCESS; } @@ -780,8 +877,6 @@ static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribu { HDF_LOGI("%s: Enter", __func__); struct UartDevice *uartDevice = NULL; - struct HAL_UART_CFG_T *uartCfg = NULL; - uint32_t uartId; int ret; if (host == NULL || attribute == NULL || host->priv == NULL) { HDF_LOGE("%s: invalid parameter", __func__); @@ -793,18 +888,12 @@ static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribu HDF_LOGE("%s: device is NULL", __func__); return HDF_ERR_INVALID_OBJECT; } - uartId = uartDevice->uartId; - uartCfg = &uartDevice->config; - if (uartCfg == NULL) { - HDF_LOGE("%s: config is NULL", __func__); - return HDF_ERR_INVALID_OBJECT; - } - ret = SetUartDevConfig(attribute, uartCfg); + + ret = SetUartDevConfig(attribute, uartDevice); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: SetUartDevConfig error", __func__); return HDF_FAILURE; } - hal_uart_reopen(uartId, uartCfg); return HDF_SUCCESS; } @@ -900,7 +989,10 @@ static int32_t UartHostDevSetTransMode(struct UartHost *host, enum UartTransMode return HDF_ERR_INVALID_OBJECT; } uartId = uartDevice->uartId; - + if (uartId > MAX_UART_ID) { + HDF_LOGE("%s %d NOT SUPPORT \r\n", __FILE__, __LINE__); + return HDF_ERR_NOT_SUPPORT; + } switch (mode) { case UART_MODE_RD_BLOCK: g_uartCtx[uartId].isBlock = true; -- Gitee From d9b9971b3ef86eb14e31fe71338991108ec8476c Mon Sep 17 00:00:00 2001 From: yanghaizhou Date: Sat, 12 Mar 2022 12:09:10 +0800 Subject: [PATCH 016/102] using dual license for platform drivers Signed-off-by: yanghaizhou --- platform/BUILD.gn | 29 ++++------------------------- platform/gpio/BUILD.gn | 29 ++++------------------------- platform/gpio/gpio_bes.c | 16 +++++----------- platform/gpio/gpio_gr5xx.c | 16 +++++----------- platform/i2c/BUILD.gn | 29 ++++------------------------- platform/i2c/i2c_bes.c | 16 +++++----------- platform/i2c/i2c_bes.h | 17 +++++------------ platform/pwm/BUILD.gn | 29 ++++------------------------- platform/pwm/pwm_bes.c | 16 +++++----------- platform/pwm/pwm_bes.h | 18 ++++++------------ platform/spi/BUILD.gn | 29 ++++------------------------- platform/spi/spi_bes.c | 18 ++++++------------ platform/spi/spi_bes.h | 18 ++++++------------ platform/uart/BUILD.gn | 29 ++++------------------------- platform/uart/uart_bes.c | 16 +++++----------- platform/uart/uart_bes.h | 18 ++++++------------ platform/uart/uart_gr5xx.c | 16 +++++----------- platform/watchdog/BUILD.gn | 29 ++++------------------------- platform/watchdog/watchdog_bes.c | 18 ++++++------------ platform/watchdog/watchdog_bes.h | 18 ++++++------------ 20 files changed, 99 insertions(+), 325 deletions(-) mode change 100755 => 100644 platform/i2c/i2c_bes.c mode change 100755 => 100644 platform/i2c/i2c_bes.h mode change 100755 => 100644 platform/pwm/pwm_bes.c mode change 100755 => 100644 platform/pwm/pwm_bes.h mode change 100755 => 100644 platform/spi/spi_bes.c mode change 100755 => 100644 platform/spi/spi_bes.h mode change 100755 => 100644 platform/uart/uart_bes.c mode change 100755 => 100644 platform/uart/uart_bes.h mode change 100755 => 100644 platform/uart/uart_gr5xx.c mode change 100755 => 100644 platform/watchdog/watchdog_bes.c mode change 100755 => 100644 platform/watchdog/watchdog_bes.h diff --git a/platform/BUILD.gn b/platform/BUILD.gn index 4b20294..3aff798 100644 --- a/platform/BUILD.gn +++ b/platform/BUILD.gn @@ -1,31 +1,10 @@ # -# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2021-2022 Huawei Device Co., Ltd. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# This file 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. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import("//drivers/adapter/khdf/liteos_m/hdf.gni") diff --git a/platform/gpio/BUILD.gn b/platform/gpio/BUILD.gn index 31b7bbf..043e367 100644 --- a/platform/gpio/BUILD.gn +++ b/platform/gpio/BUILD.gn @@ -1,31 +1,10 @@ # -# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2021-2022 Huawei Device Co., Ltd. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# This file 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. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import("//drivers/adapter/khdf/liteos_m/hdf.gni") diff --git a/platform/gpio/gpio_bes.c b/platform/gpio/gpio_bes.c index e2a4465..054d75e 100644 --- a/platform/gpio/gpio_bes.c +++ b/platform/gpio/gpio_bes.c @@ -1,17 +1,11 @@ /* - * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * This file is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. */ + #include #include "gpio_core.h" #include "hal_gpio.h" diff --git a/platform/gpio/gpio_gr5xx.c b/platform/gpio/gpio_gr5xx.c index 1ce446e..57463a4 100644 --- a/platform/gpio/gpio_gr5xx.c +++ b/platform/gpio/gpio_gr5xx.c @@ -1,17 +1,11 @@ /* - * Copyright (c) 2021 GOODIX. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2021-2022 GOODIX. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * This file 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 "app_io.h" #include "app_gpiote.h" #include "gpio/gpio_core.h" diff --git a/platform/i2c/BUILD.gn b/platform/i2c/BUILD.gn index 9db0f78..25d6112 100644 --- a/platform/i2c/BUILD.gn +++ b/platform/i2c/BUILD.gn @@ -1,31 +1,10 @@ # -# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2021-2022 Huawei Device Co., Ltd. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# This file 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. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import("//drivers/adapter/khdf/liteos_m/hdf.gni") diff --git a/platform/i2c/i2c_bes.c b/platform/i2c/i2c_bes.c old mode 100755 new mode 100644 index 9303c97..0565646 --- a/platform/i2c/i2c_bes.c +++ b/platform/i2c/i2c_bes.c @@ -1,17 +1,11 @@ /* - * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * This file 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 "i2c_bes.h" #include #include diff --git a/platform/i2c/i2c_bes.h b/platform/i2c/i2c_bes.h old mode 100755 new mode 100644 index b4c5945..aa62df7 --- a/platform/i2c/i2c_bes.h +++ b/platform/i2c/i2c_bes.h @@ -1,16 +1,9 @@ /* - * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * This file 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 _I2C_BES_H__ @@ -51,4 +44,4 @@ struct I2cDevice { } #endif -#endif \ No newline at end of file +#endif diff --git a/platform/pwm/BUILD.gn b/platform/pwm/BUILD.gn index a9ce954..aad1fff 100644 --- a/platform/pwm/BUILD.gn +++ b/platform/pwm/BUILD.gn @@ -1,31 +1,10 @@ # -# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2021-2022 Huawei Device Co., Ltd. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# This file 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. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import("//drivers/adapter/khdf/liteos_m/hdf.gni") diff --git a/platform/pwm/pwm_bes.c b/platform/pwm/pwm_bes.c old mode 100755 new mode 100644 index 5b6824a..930a993 --- a/platform/pwm/pwm_bes.c +++ b/platform/pwm/pwm_bes.c @@ -1,17 +1,11 @@ /* - * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * This file 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 "pwm_bes.h" #include #include diff --git a/platform/pwm/pwm_bes.h b/platform/pwm/pwm_bes.h old mode 100755 new mode 100644 index 0bc76f9..fedef7e --- a/platform/pwm/pwm_bes.h +++ b/platform/pwm/pwm_bes.h @@ -1,17 +1,11 @@ /* - * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * This file 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 __PWM_BES_H__ #define __PWM_BES_H__ @@ -39,4 +33,4 @@ struct PwmDevice { #ifdef __cplusplus } #endif -#endif \ No newline at end of file +#endif diff --git a/platform/spi/BUILD.gn b/platform/spi/BUILD.gn index 49ec290..9f32525 100644 --- a/platform/spi/BUILD.gn +++ b/platform/spi/BUILD.gn @@ -1,31 +1,10 @@ # -# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2021-2022 Huawei Device Co., Ltd. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# This file 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. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import("//drivers/adapter/khdf/liteos_m/hdf.gni") diff --git a/platform/spi/spi_bes.c b/platform/spi/spi_bes.c old mode 100755 new mode 100644 index 9111269..2f26091 --- a/platform/spi/spi_bes.c +++ b/platform/spi/spi_bes.c @@ -1,17 +1,11 @@ /* - * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * This file 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 "spi_bes.h" #include #include @@ -754,4 +748,4 @@ static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg, DelayUs(msg->delayUs); } return HDF_SUCCESS; -} \ No newline at end of file +} diff --git a/platform/spi/spi_bes.h b/platform/spi/spi_bes.h old mode 100755 new mode 100644 index c274f10..5242cfa --- a/platform/spi/spi_bes.h +++ b/platform/spi/spi_bes.h @@ -1,17 +1,11 @@ /* - * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * This file 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 __SPI_BES_H__ #define __SPI_BES_H__ @@ -79,4 +73,4 @@ struct SpiDevice { } #endif -#endif \ No newline at end of file +#endif diff --git a/platform/uart/BUILD.gn b/platform/uart/BUILD.gn index e755856..9a3845c 100644 --- a/platform/uart/BUILD.gn +++ b/platform/uart/BUILD.gn @@ -1,31 +1,10 @@ # -# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2021-2022 Huawei Device Co., Ltd. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# This file 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. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import("//drivers/adapter/khdf/liteos_m/hdf.gni") diff --git a/platform/uart/uart_bes.c b/platform/uart/uart_bes.c old mode 100755 new mode 100644 index 7371125..ce86fd5 --- a/platform/uart/uart_bes.c +++ b/platform/uart/uart_bes.c @@ -1,17 +1,11 @@ /* - * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * This file is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. */ + #include "uart_bes.h" #include #include diff --git a/platform/uart/uart_bes.h b/platform/uart/uart_bes.h old mode 100755 new mode 100644 index 454e101..98a9bfe --- a/platform/uart/uart_bes.h +++ b/platform/uart/uart_bes.h @@ -1,17 +1,11 @@ /* - * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * This file is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. */ + #ifndef __UART_BES_H__ #define __UART_BES_H__ @@ -74,4 +68,4 @@ int32_t UartDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf } #endif -#endif \ No newline at end of file +#endif diff --git a/platform/uart/uart_gr5xx.c b/platform/uart/uart_gr5xx.c old mode 100755 new mode 100644 index 8962106..9c8005f --- a/platform/uart/uart_gr5xx.c +++ b/platform/uart/uart_gr5xx.c @@ -1,17 +1,11 @@ /* - * Copyright (c) 2021 GOODIX. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2021-2022 GOODIX. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * This file 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 "app_uart.h" #include "uart/uart_core.h" #include "uart_if.h" diff --git a/platform/watchdog/BUILD.gn b/platform/watchdog/BUILD.gn index 9dd31cf..a32577e 100644 --- a/platform/watchdog/BUILD.gn +++ b/platform/watchdog/BUILD.gn @@ -1,31 +1,10 @@ # -# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2021-2022 Huawei Device Co., Ltd. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# This file 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. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import("//drivers/adapter/khdf/liteos_m/hdf.gni") diff --git a/platform/watchdog/watchdog_bes.c b/platform/watchdog/watchdog_bes.c old mode 100755 new mode 100644 index d0e22d6..e70f336 --- a/platform/watchdog/watchdog_bes.c +++ b/platform/watchdog/watchdog_bes.c @@ -1,17 +1,11 @@ /* - * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * This file 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 "watchdog_bes.h" #include #include @@ -326,4 +320,4 @@ static int32_t WatchdogDevReleasePriv(struct WatchdogCntlr *watchdogCntlr) { (void)watchdogCntlr; return HDF_SUCCESS; -} \ No newline at end of file +} diff --git a/platform/watchdog/watchdog_bes.h b/platform/watchdog/watchdog_bes.h old mode 100755 new mode 100644 index 2f08bd2..32dbe98 --- a/platform/watchdog/watchdog_bes.h +++ b/platform/watchdog/watchdog_bes.h @@ -1,17 +1,11 @@ /* - * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * This file 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 BES_WATCHDOG_H #define BES_WATCHDOG_H @@ -33,4 +27,4 @@ struct WatchdogDevice { #ifdef __cplusplus } #endif -#endif \ No newline at end of file +#endif -- Gitee From 9dabc521166dfd3b1edaaedd4039099b2916e3b6 Mon Sep 17 00:00:00 2001 From: zhang Date: Wed, 9 Mar 2022 20:16:20 +0800 Subject: [PATCH 017/102] fix: modify hdf host uid and gid name Signed-off-by: zhang --- uhdf2/host/BUILD.gn | 6 +- uhdf2/host/hdf_devhost.cfg | 0 uhdf2/host/hdf_devhostmusl.cfg | 195 +++++++++++++++++++++++++++++++ uhdf2/manager/BUILD.gn | 6 +- uhdf2/manager/hdf_devmgrmusl.cfg | 11 ++ 5 files changed, 216 insertions(+), 2 deletions(-) mode change 100755 => 100644 uhdf2/host/hdf_devhost.cfg create mode 100644 uhdf2/host/hdf_devhostmusl.cfg create mode 100644 uhdf2/manager/hdf_devmgrmusl.cfg diff --git a/uhdf2/host/BUILD.gn b/uhdf2/host/BUILD.gn index a18c2ef..4deb605 100644 --- a/uhdf2/host/BUILD.gn +++ b/uhdf2/host/BUILD.gn @@ -154,7 +154,11 @@ if (defined(ohos_lite)) { } ohos_prebuilt_etc("hdf_devhost.rc") { - source = "hdf_devhost.cfg" + if (use_musl) { + source = "hdf_devhostmusl.cfg" + } else { + source = "hdf_devhost.cfg" + } relative_install_dir = "init" install_images = [ chipset_base_dir ] subsystem_name = "hdf" diff --git a/uhdf2/host/hdf_devhost.cfg b/uhdf2/host/hdf_devhost.cfg old mode 100755 new mode 100644 diff --git a/uhdf2/host/hdf_devhostmusl.cfg b/uhdf2/host/hdf_devhostmusl.cfg new file mode 100644 index 0000000..66148e3 --- /dev/null +++ b/uhdf2/host/hdf_devhostmusl.cfg @@ -0,0 +1,195 @@ +{ + "jobs" : [{ + "name" : "post-fs-data", + "cmds" : [ + "start hdf_devhost" + ] + } + ], + "services" : [ + { + "name" : "blue_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "blue_host", + "gid" : ["blue_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + }, + { + "name" : "sample_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "sample_host", + "gid" : ["sample_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + }, + { + "name" : "usb_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "usb_host", + "gid" : ["usb_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + }, + { + "name" : "usbfnMaster_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "usbfnMaster_host", + "gid" : ["usbfnMaster_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + }, + { + "name" : "power_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "power_host", + "gid" : ["power_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + }, + { + "name" : "wifi_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "wifi_host", + "gid" : ["wifi_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + }, + { + "name" : "audio_hdi_server_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "audio_hdi_server_host", + "gid" : ["audio_hdi_server_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + }, + { + "name" : "camera_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "camera_host", + "gid" : ["camera_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + }, + { + "name" : "input_user_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "input_user_host", + "gid" : ["input_user_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + }, + { + "name" : "display_gralloc_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "display_gralloc_host", + "gid" : ["display_gralloc_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + }, + { + "name" : "codec_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "codec_host", + "gid" : ["codec_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + }, + { + "name" : "riladapter_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "riladapter_host", + "gid" : ["riladapter_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + }, + { + "name" : "sensor_dal_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "sensor_dal_host", + "gid" : ["sensor_dal_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + }, + { + "name" : "vibrator_dal_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "vibrator_dal_host", + "gid" : ["vibrator_dal_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + }, + { + "name" : "light_dal_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "light_dal_host", + "gid" : ["light_dal_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + }, + { + "name" : "wifi_c_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "wifi_c_host", + "gid" : ["wifi_c_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + }, + { + "name" : "disp_gralloc_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "disp_gralloc_host", + "gid" : ["disp_gralloc_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + }, + { + "name" : "dcamera_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "dcamera_host", + "gid" : ["dcamera_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + }, + { + "name" : "hwc_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "hwc_host", + "gid" : ["hwc_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + }, + { + "name" : "gralloc_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "gralloc_host", + "gid" : ["gralloc_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + }, + { + "name" : "sensor_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "sensor_host", + "gid" : ["sensor_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + }, + { + "name" : "nfc_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "nfc_host", + "gid" : ["nfc_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + }, + { + "name" : "a2dp_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "a2dp_host", + "gid" : ["a2dp_host"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + } + ] +} diff --git a/uhdf2/manager/BUILD.gn b/uhdf2/manager/BUILD.gn index 5ac195c..749f903 100644 --- a/uhdf2/manager/BUILD.gn +++ b/uhdf2/manager/BUILD.gn @@ -87,7 +87,11 @@ ohos_executable("hdf_devmgr") { } ohos_prebuilt_etc("hdf_devmgr.rc") { - source = "hdf_devmgr.cfg" + if (use_musl) { + source = "hdf_devmgrmusl.cfg" + } else { + source = "hdf_devmgr.cfg" + } relative_install_dir = "init" install_images = [ chipset_base_dir ] subsystem_name = "hdf" diff --git a/uhdf2/manager/hdf_devmgrmusl.cfg b/uhdf2/manager/hdf_devmgrmusl.cfg new file mode 100644 index 0000000..e30359c --- /dev/null +++ b/uhdf2/manager/hdf_devmgrmusl.cfg @@ -0,0 +1,11 @@ +{ + "services" : [{ + "name" : "hdf_devmgr", + "path" : ["/vendor/bin/hdf_devmgr"], + "uid" : "hdf_devmgr", + "gid" : ["hdf_devmgr"], + "start-mode" : "boot", + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + } + ] +} -- Gitee From ed15212a0e2ada08312c9170f4aeef241c594c4a Mon Sep 17 00:00:00 2001 From: fangye Date: Thu, 10 Mar 2022 15:29:53 +0800 Subject: [PATCH 018/102] feat: add hdf watchdog Support of stm32f4xx Signed-off-by: fangye --- OAT.xml | 1 + platform/watchdog/BUILD.gn | 4 + platform/watchdog/watchdog_stm32f4xx.c | 329 +++++++++++++++++++++++++ platform/watchdog/watchdog_stm32f4xx.h | 30 +++ 4 files changed, 364 insertions(+) create mode 100755 platform/watchdog/watchdog_stm32f4xx.c create mode 100755 platform/watchdog/watchdog_stm32f4xx.h diff --git a/OAT.xml b/OAT.xml index 5cb0caf..790e94c 100644 --- a/OAT.xml +++ b/OAT.xml @@ -59,6 +59,7 @@ Note:If the text contains special characters, please escape them according to th + diff --git a/platform/watchdog/BUILD.gn b/platform/watchdog/BUILD.gn index 9dd31cf..bad7fcb 100644 --- a/platform/watchdog/BUILD.gn +++ b/platform/watchdog/BUILD.gn @@ -38,5 +38,9 @@ hdf_driver(module_name) { sources += [ "watchdog_bes.c" ] } + if (defined(LOSCFG_SOC_COMPANY_STMICROELECTRONICS)) { + sources += [ "watchdog_stm32f4xx.c" ] + } + include_dirs = [ "." ] } diff --git a/platform/watchdog/watchdog_stm32f4xx.c b/platform/watchdog/watchdog_stm32f4xx.c new file mode 100755 index 0000000..be461dd --- /dev/null +++ b/platform/watchdog/watchdog_stm32f4xx.c @@ -0,0 +1,329 @@ +/* + * Copyright (c) 2022 Talkweb Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include +#include +#include "device_resource_if.h" +#include "hdf_device_desc.h" +#include "hdf_log.h" +#include "watchdog_core.h" +#include "watchdog_if.h" +#include "watchdog_stm32f4xx.h" + +static IWDG_TypeDef *hdf_iwdg = NULL; + +static int g_watchdogStart = 0; +static int g_watchdogTimeout = 0; + +static int32_t WatchdogDevStart(struct WatchdogCntlr *watchdogCntlr); +static int32_t WatchdogDevStop(struct WatchdogCntlr *watchdogCntlr); +static int32_t WatchdogDevSetTimeout(struct WatchdogCntlr *watchdogCntlr, uint32_t seconds); +static int32_t WatchdogDevGetTimeout(struct WatchdogCntlr *watchdogCntlr, uint32_t *seconds); +static int32_t WatchdogDevGetStatus(struct WatchdogCntlr *watchdogCntlr, uint32_t *status); +static int32_t WatchdogDevFeed(struct WatchdogCntlr *watchdogCntlr); + +struct WatchdogMethod g_WatchdogCntlrMethod = { + .getStatus = WatchdogDevGetStatus, + .setTimeout = WatchdogDevSetTimeout, + .getTimeout = WatchdogDevGetTimeout, + .start = WatchdogDevStart, + .stop = WatchdogDevStop, + .feed = WatchdogDevFeed, + .getPriv = NULL, + .releasePriv = NULL, +}; + +static int InitWatchdogDeviceInfo(WatchdogDeviceInfo *watchdogdeviceinfo) +{ + if (watchdogdeviceinfo == NULL) { + HDF_LOGE("%s: invaild parameter\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + return HDF_SUCCESS; +} + +static uint32_t GetWatchdogDeviceInfoResource(WatchdogDeviceInfo *device, const struct DeviceResourceNode *resourceNode) +{ + struct DeviceResourceIface *dri = NULL; + if (device == NULL || resourceNode == NULL) { + HDF_LOGE("resource or device is NULL\r\n"); + return HDF_ERR_INVALID_PARAM; + } + + dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (dri == NULL || dri->GetUint32 == NULL) { + HDF_LOGE("DeviceResourceIface is invalid\r\n"); + return HDF_ERR_INVALID_OBJECT; + } + + if (dri->GetUint32(resourceNode, "id", &device->watchdogId, 0) != HDF_SUCCESS) { + HDF_LOGE("read watchdogId fail\r\n"); + return HDF_FAILURE; + } + if (dri->GetUint32(resourceNode, "timeout", &device->timeout, 0) != HDF_SUCCESS) { + HDF_LOGE("read watchdogId fail\r\n"); + return HDF_FAILURE; + } + + HDF_LOGI("watchdogId = %d\n", device->watchdogId); + HDF_LOGI("timeout = %dms\n", device->timeout); + + return HDF_SUCCESS; +} + +static int32_t AttachWatchdogDeviceInfo(struct WatchdogCntlr *watchdogCntlr, struct HdfDeviceObject *device) +{ + int32_t ret; + WatchdogDeviceInfo *watchdogdeviceinfo = NULL; + + if (device == NULL || device->property == NULL) { + HDF_LOGE("%s: param is NULL\r\n", __func__); + return HDF_FAILURE; + } + + watchdogdeviceinfo = (WatchdogDeviceInfo *)OsalMemAlloc(sizeof(WatchdogDeviceInfo)); + if (watchdogdeviceinfo == NULL) { + HDF_LOGE("%s: OsalMemAlloc WatchdogDeviceInfo error\r\n", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + ret = GetWatchdogDeviceInfoResource(watchdogdeviceinfo, device->property); + if (ret != HDF_SUCCESS) { + (void)OsalMemFree(watchdogdeviceinfo); + return HDF_FAILURE; + } + + (void)OsalMutexInit(&watchdogCntlr->lock); + + watchdogCntlr->priv = watchdogdeviceinfo; + watchdogCntlr->wdtId = watchdogdeviceinfo->watchdogId; + + return InitWatchdogDeviceInfo(watchdogdeviceinfo); +} +/* HdfDriverEntry method definitions */ +static int32_t WatchdogDriverBind(struct HdfDeviceObject *device); +static int32_t WatchdogDriverInit(struct HdfDeviceObject *device); +static void WatchdogDriverRelease(struct HdfDeviceObject *device); + +/* HdfDriverEntry definitions */ +struct HdfDriverEntry g_watchdogDriverEntry = { + .moduleVersion = 1, + .moduleName = "ST_WATCHDOG_MODULE_HDF", + .Bind = WatchdogDriverBind, + .Init = WatchdogDriverInit, + .Release = WatchdogDriverRelease, +}; + +// Initialize HdfDriverEntry +HDF_INIT(g_watchdogDriverEntry); + +static int32_t WatchdogDriverBind(struct HdfDeviceObject *device) +{ + struct WatchdogCntlr *watchdogCntlr = NULL; + + if (device == NULL) { + HDF_LOGE("hdfDevice object is null!\r\n"); + return HDF_FAILURE; + } + + watchdogCntlr = (struct WatchdogCntlr *)OsalMemAlloc(sizeof(struct WatchdogCntlr)); + if (watchdogCntlr == NULL) { + HDF_LOGE("%s: OsalMemAlloc watchdogCntlr error\r\n", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + HDF_LOGI("Enter %s\r\n", __func__); + device->service = &watchdogCntlr->service; + watchdogCntlr->device = device; + watchdogCntlr->priv = NULL; + return HDF_SUCCESS; +} + +static int32_t WatchdogDriverInit(struct HdfDeviceObject *device) +{ + int32_t ret; + struct WatchdogCntlr *watchdogCntlr = NULL; + + if (device == NULL) { + HDF_LOGE("%s: device is NULL\r\n", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + HDF_LOGI("Enter %s:\r\n", __func__); + + watchdogCntlr = WatchdogCntlrFromDevice(device); + if (watchdogCntlr == NULL) { + HDF_LOGE("%s: watchdogCntlr is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + ret = AttachWatchdogDeviceInfo(watchdogCntlr, device); + if (ret != HDF_SUCCESS) { + OsalMemFree(watchdogCntlr); + HDF_LOGE("%s:attach error\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + watchdogCntlr->ops = &g_WatchdogCntlrMethod; + + HDF_LOGI("WatchdogDriverInit success!\r\n"); + return ret; +} + +static void WatchdogDriverRelease(struct HdfDeviceObject *device) +{ + struct WatchdogCntlr *watchdogCntlr = NULL; + WatchdogDeviceInfo *watchdogdeviceinfo = NULL; + + if (device == NULL) { + HDF_LOGE("device is null\r\n"); + return; + } + + watchdogCntlr = WatchdogCntlrFromDevice(device); + if (watchdogCntlr == NULL || watchdogCntlr->priv == NULL) { + HDF_LOGE("%s: watchdogCntlr is NULL\r\n", __func__); + return; + } + + watchdogdeviceinfo = (WatchdogDeviceInfo *)watchdogCntlr->priv; + if (watchdogdeviceinfo != NULL) { + OsalMemFree(watchdogdeviceinfo); + } + return; +} + +static int32_t WatchdogDevStart(struct WatchdogCntlr *watchdogCntlr) +{ + WatchdogDeviceInfo *watchdogdeviceinfo = NULL; + int32_t watchdogId = 0; + int32_t timeout = 0; + unsigned long long tickstart = 0; + + if (watchdogCntlr == NULL || watchdogCntlr->priv == NULL) { + HDF_LOGE("%s: watchdogCntlr is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + watchdogdeviceinfo = (WatchdogDeviceInfo *)watchdogCntlr->priv; + if (watchdogdeviceinfo == NULL) { + HDF_LOGE("%s: OBJECT is NULL\r\n", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + watchdogId = watchdogdeviceinfo->watchdogId; + timeout = watchdogdeviceinfo->timeout; + + if (timeout < WATCHDOG_MIN_TIMEOUT) { + HDF_LOGW("%s: watchdog timeout must >= 1, set the timeout to 1ms\r\n", __func__); + timeout = WATCHDOG_MIN_TIMEOUT; + } + if (timeout > WATCHDOG_MAX_TIMEOUT) { + HDF_LOGW("%s: watchdog timeout must <= 1, set the timeout to 4096ms\r\n", __func__); + timeout = WATCHDOG_MAX_TIMEOUT; + } + + HDF_LOGI("%s: watchdog Started! timeout: %dms\r\n", __func__, timeout); + + hdf_iwdg = IWDG; // Point to watchdog register + hdf_iwdg->KR = IWDG_KEY_ENABLE; + hdf_iwdg->KR = IWDG_KEY_WRITE_ACCESS_ENABLE; + hdf_iwdg->PR = IWDG_PRESCALER_32; // 32 frequency division + hdf_iwdg->RLR = timeout - 1; // 32K crystal oscillator corresponds to 1-4096ms under 32 prescaled frequency + + tickstart = LOS_TickCountGet(); + // Wait for the register value to be updated and confirm that the watchdog is started successfully + while ((hdf_iwdg->SR & (IWDG_SR_RVU | IWDG_SR_PVU)) != 0x00u) { + if ((LOS_TickCountGet() - tickstart) > WATCHDOG_UPDATE_TIME) { + if ((hdf_iwdg->SR & (IWDG_SR_RVU | IWDG_SR_PVU)) != 0x00u) { + return HDF_FAILURE; + } + } + } + hdf_iwdg->KR = IWDG_KEY_RELOAD; // Reload initial value + + g_watchdogStart = 1; + return HDF_SUCCESS; +} + +static int32_t WatchdogDevStop(struct WatchdogCntlr *watchdogCntlr) +{ + HDF_LOGW("%s: WatchdogDevStop fail,because of soc not support!!\r\n", __func__); + return HDF_FAILURE; +} + +static int32_t WatchdogDevSetTimeout(struct WatchdogCntlr *watchdogCntlr, uint32_t seconds) +{ + WatchdogDeviceInfo *watchdogdeviceinfo = NULL; + if (watchdogCntlr == NULL || watchdogCntlr->priv == NULL) { + HDF_LOGE("%s: watchdogCntlr is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + watchdogdeviceinfo = (WatchdogDeviceInfo *)watchdogCntlr->priv; + if (watchdogdeviceinfo == NULL) { + HDF_LOGE("%s: OBJECT is NULL\r\n", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + watchdogdeviceinfo->timeout = seconds; + + return HDF_SUCCESS; +} + +static int32_t WatchdogDevGetTimeout(struct WatchdogCntlr *watchdogCntlr, uint32_t *seconds) +{ + WatchdogDeviceInfo *watchdogdeviceinfo = NULL; + if (watchdogCntlr == NULL || seconds == NULL) { + HDF_LOGE("%s: PARAM is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + watchdogdeviceinfo = (WatchdogDeviceInfo *)watchdogCntlr->priv; + if (watchdogdeviceinfo == NULL) { + HDF_LOGE("%s: OBJECT is NULL\r\n", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + *seconds = watchdogdeviceinfo->timeout; + return HDF_SUCCESS; +} + +static int32_t WatchdogDevGetStatus(struct WatchdogCntlr *watchdogCntlr, uint32_t *status) +{ + if (watchdogCntlr == NULL || status == NULL) { + HDF_LOGE("%s: PARAM is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (g_watchdogStart == 1) { + *status = WATCHDOG_START; + } else { + *status = WATCHDOG_STOP; + } + return HDF_SUCCESS; +} + +static int32_t WatchdogDevFeed(struct WatchdogCntlr *watchdogCntlr) +{ + (void)watchdogCntlr; + if (hdf_iwdg != NULL) + hdf_iwdg->KR = IWDG_KEY_RELOAD; // Reload initial value + return HDF_SUCCESS; +} + +static int32_t WatchdogDevGetPriv(struct WatchdogCntlr *watchdogCntlr) +{ + (void)watchdogCntlr; + return HDF_SUCCESS; +} + +static int32_t WatchdogDevReleasePriv(struct WatchdogCntlr *watchdogCntlr) +{ + (void)watchdogCntlr; + return HDF_SUCCESS; +} \ No newline at end of file diff --git a/platform/watchdog/watchdog_stm32f4xx.h b/platform/watchdog/watchdog_stm32f4xx.h new file mode 100755 index 0000000..9d037c9 --- /dev/null +++ b/platform/watchdog/watchdog_stm32f4xx.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022 Talkweb 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 __WATCHDOG_STM32F4XX_H__ +#define __WATCHDOG_STM32F4XX_H__ + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#define WATCHDOG_MIN_TIMEOUT 1 +#define WATCHDOG_MAX_TIMEOUT 4096 + +#define WATCHDOG_UPDATE_TIME (((6UL * 256UL * 1000UL) / LSI_VALUE) + ((LSI_STARTUP_TIME / 1000UL) + 1UL)) + +typedef struct { + int watchdogId; + int timeout; // Maximum interval between watchdog feeding, unit: ms +} WatchdogDeviceInfo; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif \ No newline at end of file -- Gitee From 6255ae15ea44139c975fccbeb11396c4b1f997d8 Mon Sep 17 00:00:00 2001 From: fangye Date: Tue, 15 Mar 2022 11:35:30 +0800 Subject: [PATCH 019/102] Remove header file of stm32f4xx hdf watchdog Signed-off-by: fangye Change-Id: I8587955ddccedfe1ef11ba9fc937a7798c1507cd --- platform/watchdog/watchdog_stm32f4xx.c | 11 ++++++++-- platform/watchdog/watchdog_stm32f4xx.h | 30 -------------------------- 2 files changed, 9 insertions(+), 32 deletions(-) delete mode 100755 platform/watchdog/watchdog_stm32f4xx.h diff --git a/platform/watchdog/watchdog_stm32f4xx.c b/platform/watchdog/watchdog_stm32f4xx.c index be461dd..9fb1d73 100755 --- a/platform/watchdog/watchdog_stm32f4xx.c +++ b/platform/watchdog/watchdog_stm32f4xx.c @@ -13,10 +13,17 @@ #include "hdf_log.h" #include "watchdog_core.h" #include "watchdog_if.h" -#include "watchdog_stm32f4xx.h" -static IWDG_TypeDef *hdf_iwdg = NULL; +#define WATCHDOG_MIN_TIMEOUT 1 +#define WATCHDOG_MAX_TIMEOUT 4096 +#define WATCHDOG_UPDATE_TIME (((6UL * 256UL * 1000UL) / LSI_VALUE) + ((LSI_STARTUP_TIME / 1000UL) + 1UL)) + +typedef struct { + int watchdogId; + int timeout; // Maximum interval between watchdog feeding, unit: ms +} WatchdogDeviceInfo; +static IWDG_TypeDef *hdf_iwdg = NULL; static int g_watchdogStart = 0; static int g_watchdogTimeout = 0; diff --git a/platform/watchdog/watchdog_stm32f4xx.h b/platform/watchdog/watchdog_stm32f4xx.h deleted file mode 100755 index 9d037c9..0000000 --- a/platform/watchdog/watchdog_stm32f4xx.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2022 Talkweb 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 __WATCHDOG_STM32F4XX_H__ -#define __WATCHDOG_STM32F4XX_H__ - - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define WATCHDOG_MIN_TIMEOUT 1 -#define WATCHDOG_MAX_TIMEOUT 4096 - -#define WATCHDOG_UPDATE_TIME (((6UL * 256UL * 1000UL) / LSI_VALUE) + ((LSI_STARTUP_TIME / 1000UL) + 1UL)) - -typedef struct { - int watchdogId; - int timeout; // Maximum interval between watchdog feeding, unit: ms -} WatchdogDeviceInfo; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif \ No newline at end of file -- Gitee From 2affd49af5189de95e7899b896517eb43b9b055b Mon Sep 17 00:00:00 2001 From: peizhu Date: Tue, 15 Mar 2022 10:06:25 +0800 Subject: [PATCH 020/102] feat: add HDF GPIO and UART driver of ASR5822 platform Signed-off-by: zipper1956 --- OAT.xml | 1 + platform/gpio/BUILD.gn | 3 + platform/gpio/gpio_asr.c | 477 +++++++++++++++++++++++++++ platform/uart/BUILD.gn | 3 + platform/uart/uart_asr.c | 695 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 1179 insertions(+) create mode 100644 platform/gpio/gpio_asr.c create mode 100644 platform/uart/uart_asr.c diff --git a/OAT.xml b/OAT.xml index 790e94c..5b54ec9 100644 --- a/OAT.xml +++ b/OAT.xml @@ -59,6 +59,7 @@ Note:If the text contains special characters, please escape them according to th + diff --git a/platform/gpio/BUILD.gn b/platform/gpio/BUILD.gn index 043e367..1a16f0b 100644 --- a/platform/gpio/BUILD.gn +++ b/platform/gpio/BUILD.gn @@ -19,6 +19,9 @@ hdf_driver(module_name) { if (defined(LOSCFG_SOC_COMPANY_GOODIX)) { sources += [ "gpio_gr5xx.c" ] } + if (defined(LOSCFG_SOC_COMPANY_ASRMICRO)) { + sources += [ "gpio_asr.c" ] + } include_dirs = [ "." ] if (defined(LOSCFG_SHIELD_V200ZR_EVB_T1)) { diff --git a/platform/gpio/gpio_asr.c b/platform/gpio/gpio_asr.c new file mode 100644 index 0000000..24fe2b2 --- /dev/null +++ b/platform/gpio/gpio_asr.c @@ -0,0 +1,477 @@ +/* + * Copyright (c) 2022 ASR Microelectronics (Shanghai) Co., Ltd. All rights reserved. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include +#include "gpio_core.h" +#include "hdf_log.h" +#include "osal_irq.h" +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO +#include "hcs_macro.h" +#include "hdf_config_macro.h" +#else +#include "device_resource_if.h" +#endif +#include "duet_gpio.h" + +#define ASR_GPIO_TOTAL_NUM DUET_GPIO_TOTAL_NUM +#define asr_gpio_config_t duet_gpio_config_t +#define ASR_ANALOG_MODE DUET_ANALOG_MODE +#define ASR_IRQ_MODE DUET_IRQ_MODE +#define ASR_INPUT_PULL_UP DUET_INPUT_PULL_UP +#define ASR_INPUT_PULL_DOWN DUET_INPUT_PULL_DOWN +#define ASR_INPUT_HIGH_IMPEDANCE DUET_INPUT_HIGH_IMPEDANCE +#define ASR_OUTPUT_PUSH_PULL DUET_OUTPUT_PUSH_PULL +#define ASR_OUTPUT_OPEN_DRAIN_NO_PULL DUET_OUTPUT_OPEN_DRAIN_NO_PULL +#define ASR_OUTPUT_OPEN_DRAIN_PULL_UP DUET_OUTPUT_OPEN_DRAIN_PULL_UP + +#define asr_gpio_dev_t duet_gpio_dev_t +#define asr_gpio_irq_trigger_t duet_gpio_irq_trigger_t +#define asr_gpio_irq_handler_t duet_gpio_irq_handler_t +#define asr_gpio_cb_t duet_gpio_cb_t +#define asr_gpio_init duet_gpio_init +#define asr_gpio_output_high duet_gpio_output_high +#define asr_gpio_output_low duet_gpio_output_low +#define asr_gpio_output_toggle duet_gpio_output_toggle +#define asr_gpio_input_get duet_gpio_input_get +#define asr_gpio_enable_irq duet_gpio_enable_irq +#define asr_gpio_disable_irq duet_gpio_disable_irq +#define asr_gpio_clear_irq duet_gpio_clear_irq +#define asr_gpio_finalize duet_gpio_finalize + +#define HDF_LOG_TAG GPIO_ASR + +struct GpioResource { + uint32_t pin; + uint32_t realPin; + uint32_t config; + uint32_t pinNum; + uint32_t type; /**< Type of the input event EV_KEY */ + uint32_t code; /**< Specific code item of the input event KEY_POWER*/ + unsigned long physBase; +}; + +enum GpioDeviceState { + GPIO_DEVICE_UNINITIALIZED = 0x0u, + GPIO_DEVICE_INITIALIZED = 0x1u, +}; + +struct GpioDevice { + asr_gpio_dev_t dev; + struct GpioResource resource; +}; + +static struct GpioCntlr g_gpioCntlr; +struct OemGpioIrqHandler { + uint8_t port; + GpioIrqFunc func; + void *arg; +}; + +static asr_gpio_dev_t g_gpioPinMap[ASR_GPIO_TOTAL_NUM] = {0}; +static asr_gpio_irq_trigger_t g_gpioIrqCfg[ASR_GPIO_TOTAL_NUM] = {0}; + +static void OemGpioIrqHdl(uint16_t *arg) +{ + asr_gpio_dev_t *dev = NULL; + uint16_t gpio = (uint16_t)arg; + + dev = &g_gpioPinMap[gpio]; + if ((uint16_t)dev->port >= ASR_GPIO_TOTAL_NUM) { + HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, (uint16_t)dev->port); + return; + } + GpioCntlrIrqCallback(&g_gpioCntlr, gpio); +} + +/* dispatch */ +int32_t GpioDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + if (client == NULL || client->device == NULL || data == NULL || reply == NULL) { + HDF_LOGE("%s: client or client->device is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + return HDF_SUCCESS; +} + +/* dev api */ +static int32_t GpioDevWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val) +{ + (void)cntlr; + uint32_t ret = 0; + asr_gpio_dev_t *dev = &g_gpioPinMap[gpio]; + + if (val) { + ret = asr_gpio_output_high(dev); + } else { + ret = asr_gpio_output_low(dev); + } + if (EIO == ret) { + HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, dev->port); + return HDF_ERR_NOT_SUPPORT; + } + + return HDF_SUCCESS; +} + +static int32_t GpioDevRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val) +{ + (void)cntlr; + uint32_t ret = 0; + asr_gpio_dev_t *dev = &g_gpioPinMap[gpio]; + + if ((cntlr == NULL) || (val == NULL)) { + return HDF_ERR_INVALID_PARAM; + } + ret = asr_gpio_input_get(dev, val); + if (EIO == ret) { + HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, dev->port); + return HDF_ERR_NOT_SUPPORT; + } + + return HDF_SUCCESS; +} + +static int32_t GpioDevSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t dir) +{ + (void)cntlr; + uint32_t ret = 0; + asr_gpio_dev_t *dev = &g_gpioPinMap[gpio]; + + if (cntlr == NULL) { + return HDF_ERR_INVALID_PARAM; + } + dev->config = (asr_gpio_config_t)dir; + ret = asr_gpio_init(dev); + if (EIO == ret) { + HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, dev->port); + return HDF_ERR_NOT_SUPPORT; + } + + return HDF_SUCCESS; +} + +static int32_t GpioDevGetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *dir) +{ + (void)cntlr; + uint32_t ret = 0; + asr_gpio_dev_t *dev = &g_gpioPinMap[gpio]; + + if ((cntlr == NULL) || (dir == NULL)) { + return HDF_ERR_INVALID_PARAM; + } + if (dev->port >= ASR_GPIO_TOTAL_NUM) { + HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, dev->port); + return HDF_ERR_NOT_SUPPORT; + } + *dir = (uint16_t)dev->config; + + return HDF_SUCCESS; +} + +static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mode) +{ + (void)cntlr; + asr_gpio_dev_t *dev = &g_gpioPinMap[gpio]; + + HDF_LOGE("%s %d, pin:%d", __func__, __LINE__, (uint16_t)dev->port); + if (dev->port >= ASR_GPIO_TOTAL_NUM) { + HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, dev->port); + return HDF_ERR_NOT_SUPPORT; + } + + if ((mode == OSAL_IRQF_TRIGGER_RISING) || (mode == OSAL_IRQF_TRIGGER_FALLING) + || (mode == (OSAL_IRQF_TRIGGER_RISING | OSAL_IRQF_TRIGGER_FALLING))) { + g_gpioIrqCfg[gpio] = (asr_gpio_config_t)mode; + } else { + HDF_LOGE("%s %d, error mode:%d", __func__, __LINE__, mode); + return HDF_ERR_NOT_SUPPORT; + } + + return HDF_SUCCESS; +} + +static int32_t GpioDevUnSetIrq(struct GpioCntlr *cntlr, uint16_t gpio) +{ + (void)cntlr; + asr_gpio_dev_t *dev = &g_gpioPinMap[gpio]; + + if (dev->port >= ASR_GPIO_TOTAL_NUM) { + HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, dev->port); + return HDF_ERR_NOT_SUPPORT; + } + + return HDF_SUCCESS; +} + +static int32_t GpioDevEnableIrq(struct GpioCntlr *cntlr, uint16_t gpio) +{ + (void)cntlr; + asr_gpio_dev_t *dev = &g_gpioPinMap[gpio]; + + if ((uint16_t)dev->port >= ASR_GPIO_TOTAL_NUM) { + HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, (uint16_t)dev->port); + return HDF_ERR_NOT_SUPPORT; + } + + dev->config = ASR_IRQ_MODE; + asr_gpio_init(dev); + asr_gpio_enable_irq(dev, g_gpioIrqCfg[gpio], OemGpioIrqHdl, (void *)gpio); + HDF_LOGE("%s %d, pin:%d", __func__, __LINE__, (uint16_t)dev->port); + + return HDF_SUCCESS; +} + +static int32_t GpioDevDisableIrq(struct GpioCntlr *cntlr, uint16_t gpio) +{ + (void)cntlr; + asr_gpio_dev_t *dev = &g_gpioPinMap[gpio]; + + if ((uint16_t)dev->port >= ASR_GPIO_TOTAL_NUM) { + HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, (uint16_t)dev->port); + return HDF_ERR_NOT_SUPPORT; + } + asr_gpio_disable_irq(dev); + + return HDF_SUCCESS; +} + +struct GpioMethod g_GpioCntlrMethod = { + .request = NULL, + .release = NULL, + .write = GpioDevWrite, + .read = GpioDevRead, + .setDir = GpioDevSetDir, + .getDir = GpioDevGetDir, + .toIrq = NULL, + .setIrq = GpioDevSetIrq, + .unsetIrq = GpioDevUnSetIrq, + .enableIrq = GpioDevEnableIrq, + .disableIrq = GpioDevDisableIrq, +}; + +static int InitGpioDevice(struct GpioDevice *device) +{ + uint32_t ret = 0; + + if (device == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + + HDF_LOGE("%s %d, pin:%d, mode:%d", __func__, __LINE__, device->dev.port, device->dev.config); + ret = asr_gpio_init(&device->dev); + if (EIO == ret) { + HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, device->dev.port); + return HDF_ERR_NOT_SUPPORT; + } + + return HDF_SUCCESS; +} +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO +#define PLATFORM_GPIO_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), gpio_config) +static uint32_t GetGpioDeviceResource(struct GpioDevice *device) +{ + uint32_t relPin; + int32_t ret; + struct GpioResource *resource = NULL; + if (device == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + resource = &device->resource; + if (resource == NULL) { + HDF_LOGE("%s: resource is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + resource->pinNum = HCS_PROP(PLATFORM_GPIO_CONFIG, pinNum); + uint32_t pins[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, pin)); + uint32_t realPins[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, realPin)); + uint32_t configs[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, config)); + for (size_t i = 0; i < resource->pinNum; i++) { + resource->pin = pins[i]; + resource->realPin = realPins[i]; + resource->config = configs[i]; + + relPin = resource->realPin;// / DECIMALNUM * OCTALNUM + resource->realPin % DECIMALNUM; + g_gpioPinMap[resource->pin].port = (uint8_t)relPin; + g_gpioPinMap[resource->pin].config = (asr_gpio_config_t)resource->config; + device->dev.config = (asr_gpio_config_t)resource->config; + resource->pin = relPin; + device->dev.port = relPin; + + ret = InitGpioDevice(device); + if (ret != HDF_SUCCESS) { + HDF_LOGE("InitGpioDevice FAIL\r\n"); + return HDF_FAILURE; + } + } + + return HDF_SUCCESS; +} +#else +static uint32_t GetGpioDeviceResource( + struct GpioDevice *device, const struct DeviceResourceNode *resourceNode) +{ + uint32_t relPin; + int32_t ret; + struct GpioResource *resource = NULL; + struct DeviceResourceIface *dri = NULL; + if (device == NULL || resourceNode == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + resource = &device->resource; + if (resource == NULL) { + HDF_LOGE("%s: resource is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (dri == NULL || dri->GetUint32 == NULL) { + HDF_LOGE("DeviceResourceIface is invalid"); + return HDF_ERR_INVALID_OBJECT; + } + + if (dri->GetUint32(resourceNode, "pinNum", &resource->pinNum, 0) != HDF_SUCCESS) { + HDF_LOGE("gpio config read pinNum fail"); + return HDF_FAILURE; + } + + for (size_t i = 0; i < resource->pinNum; i++) { + if (dri->GetUint32ArrayElem(resourceNode, "pin", i, &resource->pin, 0) != HDF_SUCCESS) { + HDF_LOGE("gpio config read pin fail"); + return HDF_FAILURE; + } + + if (dri->GetUint32ArrayElem(resourceNode, "realPin", i, &resource->realPin, 0) != HDF_SUCCESS) { + HDF_LOGE("gpio config read realPin fail"); + return HDF_FAILURE; + } + + if (dri->GetUint32ArrayElem(resourceNode, "config", i, &resource->config, 0) != HDF_SUCCESS) { + HDF_LOGE("gpio config read config fail"); + return HDF_FAILURE; + } + + relPin = resource->realPin;// / DECIMALNUM * OCTALNUM + resource->realPin % DECIMALNUM; + g_gpioPinMap[resource->pin].port = (uint8_t)relPin; + g_gpioPinMap[resource->pin].config = (asr_gpio_config_t)resource->config; + device->dev.config = (asr_gpio_config_t)resource->config; + device->dev.port = relPin; + resource->pin = relPin; + + ret = InitGpioDevice(device); + if (ret != HDF_SUCCESS) { + HDF_LOGE("InitGpioDevice FAIL\r\n"); + return HDF_FAILURE; + } + } + + return HDF_SUCCESS; +} +#endif + + +static int32_t AttachGpioDevice(struct GpioCntlr *gpioCntlr, struct HdfDeviceObject *device) +{ + int32_t ret; + + struct GpioDevice *gpioDevice = NULL; +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO + if (device == NULL) { +#else + if (device == NULL || device->property == NULL) { +#endif + HDF_LOGE("%s: param is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + + gpioDevice = (struct GpioDevice *)OsalMemAlloc(sizeof(struct GpioDevice)); + if (gpioDevice == NULL) { + HDF_LOGE("%s: OsalMemAlloc gpioDevice error", __func__); + return HDF_ERR_MALLOC_FAIL; + } +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO + ret = GetGpioDeviceResource(gpioDevice); +#else + ret = GetGpioDeviceResource(gpioDevice, device->property); +#endif + if (ret != HDF_SUCCESS) { + (void)OsalMemFree(gpioDevice); + return HDF_FAILURE; + } + + (void)OsalMemFree(gpioDevice); + gpioCntlr->count = gpioDevice->resource.pinNum; + + return HDF_SUCCESS; +} + +static int32_t GpioDriverInit(struct HdfDeviceObject *device) +{ + int32_t ret; + struct GpioCntlr *gpioCntlr = NULL; + + if (device == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + + ret = PlatformDeviceBind(&g_gpioCntlr.device, device); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: bind hdf device failed:%d", __func__, ret); + return ret; + } + + gpioCntlr = GpioCntlrFromHdfDev(device); + if (gpioCntlr == NULL) { + HDF_LOGE("GpioCntlrFromHdfDev fail\r\n"); + return HDF_DEV_ERR_NO_DEVICE_SERVICE; + } + + ret = AttachGpioDevice(gpioCntlr, device); // GpioCntlr add GpioDevice to priv + if (ret != HDF_SUCCESS) { + HDF_LOGE("AttachGpioDevice fail\r\n"); + return HDF_DEV_ERR_ATTACHDEV_FAIL; + } + + gpioCntlr->ops = &g_GpioCntlrMethod; // register callback + ret = GpioCntlrAdd(gpioCntlr); + if (ret != HDF_SUCCESS) { + HDF_LOGE("GpioCntlrAdd fail %d\r\n", gpioCntlr->start); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +static void GpioDriverRelease(struct HdfDeviceObject *device) +{ + struct GpioCntlr *gpioCntlr = NULL; + + if (device == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return; + } + + gpioCntlr = GpioCntlrFromHdfDev(device); + if (gpioCntlr == NULL) { + HDF_LOGE("GpioCntlrFromHdfDev fail\r\n"); + return HDF_DEV_ERR_NO_DEVICE_SERVICE; + } + + (void)OsalMemFree(gpioCntlr->priv); + gpioCntlr->count = 0; +} + +/* HdfDriverEntry definitions */ +struct HdfDriverEntry g_GpioDriverEntry = { + .moduleVersion = 1, + .moduleName = "ASR_GPIO_MODULE_HDF", + .Init = GpioDriverInit, + .Release = GpioDriverRelease, +}; +HDF_INIT(g_GpioDriverEntry); diff --git a/platform/uart/BUILD.gn b/platform/uart/BUILD.gn index 9a3845c..19becc7 100644 --- a/platform/uart/BUILD.gn +++ b/platform/uart/BUILD.gn @@ -19,6 +19,9 @@ hdf_driver(module_name) { if (defined(LOSCFG_SOC_COMPANY_GOODIX)) { sources += [ "uart_gr5xx.c" ] } + if (defined(LOSCFG_SOC_COMPANY_ASRMICRO)) { + sources += [ "uart_asr.c" ] + } include_dirs = [ "." ] } diff --git a/platform/uart/uart_asr.c b/platform/uart/uart_asr.c new file mode 100644 index 0000000..d97ec44 --- /dev/null +++ b/platform/uart/uart_asr.c @@ -0,0 +1,695 @@ +/* + * Copyright (c) 2022 ASR Microelectronics (Shanghai) Co., Ltd. All rights reserved. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include "uart/uart_core.h" +#include "device_resource_if.h" +#include "hdf_base.h" +#include "hdf_log.h" +#include "los_sem.h" +#include "osal_mem.h" +#include "duet_pinmux.h" +#include "duet_uart.h" + +#define ASR_UART_NUM DUET_UART_NUM +#define asr_uart_config_t duet_uart_config_t +#define asr_uart_dev_t duet_uart_dev_t +#define asr_uart_struct_init duet_uart_struct_init +#define asr_uart_dma_config duet_uart_dma_config +#define asr_uart_init duet_uart_init +#define asr_uart_send duet_uart_send +#define asr_uart_finalize duet_uart_finalize +#define asr_uart_start duet_uart_start +#define asr_uart_stop duet_uart_stop +#define asr_uart_set_callback duet_uart_set_callback +#define asr_uart_calc_baud duet_uart_calc_baud +#define asr_uart_interrupt_config duet_uart_interrupt_config +#define asr_uart_clear_interrupt duet_uart_clear_interrupt +#define asr_uart_get_raw_interrupt_status duet_uart_get_raw_interrupt_status +#define asr_uart_get_interrupt_status duet_uart_get_interrupt_status +#define asr_uart_get_flag_status duet_uart_get_flag_status +#define asr_uart_callback_func duet_uart_callback_func +#define asr_pinmux_config duet_pinmux_config + +#define HDF_LOG_TAG uart_asr + +#define DEFAULT_BAUDRATE 115200 +#define DEFAULT_DATABITS UART_ATTR_DATABIT_8 +#define DEFAULT_STOPBITS UART_ATTR_STOPBIT_1 +#define DEFAULT_PARITY UART_ATTR_PARITY_NONE +#define CONFIG_MAX_BAUDRATE 921600 +#define UART_STATE_NOT_OPENED 0 +#define UART_STATE_OPENING 1 +#define UART_STATE_USEABLE 2 +#define UART_STATE_SUSPENED 3 +#define UART_FLG_DMA_RX (1 << 0) +#define UART_FLG_DMA_TX (1 << 1) +#define UART_FLG_RD_BLOCK (1 << 2) +#define UART_TRANS_TIMEOUT 1000 +#define UART_RX_BUF_LEN 512 + +typedef int32_t (*app_uart_cfg_handler_t)(struct UartDriverData *udd); +struct UartResource { + uint32_t port; + uint32_t pin_tx_pin; + uint32_t pin_tx_mux; + uint32_t pin_rx_pin; + uint32_t pin_rx_mux; + uint32_t tx_rx; +}; + +struct UartDriverData { + asr_uart_dev_t params; + struct UartAttribute attr; + struct UartResource resource; + app_uart_cfg_handler_t config; + int32_t count; + int32_t state; + uint32_t flags; +}; + +static uint32_t g_uartTxMutex[ASR_UART_NUM]; +static uint32_t g_uartRxMutex[ASR_UART_NUM]; +static uint8_t *rx_buf[ASR_UART_NUM]; +static uint16_t rx_head[ASR_UART_NUM]; +static uint16_t rx_tail[ASR_UART_NUM]; + +static void Uart0Callback(char data); +static void Uart1Callback(char data); +static void Uart2Callback(char data); + +static const asr_uart_callback_func g_evtHandler[ASR_UART_NUM] = { + Uart0Callback, + Uart1Callback, + Uart2Callback +}; + +static void Uart0Callback(char data) +{ + uint8_t *dst = rx_buf[UART0_INDEX]; + if (dst) { + dst[rx_head[UART0_INDEX]++] = (uint8_t)data; + rx_head[UART0_INDEX] %= UART_RX_BUF_LEN; + } +} + +static void Uart1Callback(char data) +{ + uint8_t *dst = rx_buf[UART1_INDEX]; + if (dst) { + dst[rx_head[UART1_INDEX]++] = (uint8_t)data; + rx_head[UART1_INDEX] %= UART_RX_BUF_LEN; + } +} +static void Uart2Callback(char data) +{ + uint8_t *dst = rx_buf[UART2_INDEX]; + if (dst) { + dst[rx_head[UART2_INDEX]++] = (uint8_t)data; + rx_head[UART2_INDEX] %= UART_RX_BUF_LEN; + } +} + +static uint32_t GetUartDataBits(uint32_t attrDataBits) +{ + uint32_t dataBits; + + switch (attrDataBits) { + case UART_ATTR_DATABIT_5: + dataBits = DATA_5BIT; + break; + case UART_ATTR_DATABIT_6: + dataBits = DATA_6BIT; + break; + case UART_ATTR_DATABIT_7: + dataBits = DATA_7BIT; + break; + case UART_ATTR_DATABIT_8: + dataBits = DATA_8BIT; + break; + default: + dataBits = DATA_8BIT; + break; + } + + return dataBits; +} + +static uint32_t GetUartStopBits(uint32_t attrStopBits) +{ + uint32_t stopBits; + + switch (attrStopBits) { + case UART_ATTR_STOPBIT_1: + stopBits = STOP_1BIT; + break; + case UART_ATTR_STOPBIT_2: + stopBits = STOP_2BITS; + break; + default: + stopBits = STOP_1BIT; + break; + } + + return stopBits; +} + +static uint32_t GetUartParity(uint32_t attrParity) +{ + uint32_t parity; + + switch (attrParity) { + case UART_ATTR_PARITY_NONE: + parity = PARITY_NO; + break; + case UART_ATTR_PARITY_ODD: + parity = PARITY_ODD; + break; + case UART_ATTR_PARITY_EVEN: + parity = PARITY_EVEN; + break; + default: + parity = PARITY_NO; + break; + } + + return parity; +} + +static uint32_t GetUartFlowControl(uint32_t rts, uint32_t cts) +{ + uint32_t flow_control; + + if (!rts && !cts) { + flow_control = FLOW_CTRL_DISABLED; + } else if (rts && cts) { + flow_control = FLOW_CTRL_CTS_RTS; + } else if (rts) { + flow_control = FLOW_CTRL_RTS; + } else { + flow_control = FLOW_CTRL_CTS; + } + + return flow_control; +} + +static int32_t Asr582xUartConfig(struct UartDriverData *udd) +{ + uint32_t ret; + asr_uart_dev_t *params = NULL; + + if (udd == NULL) { + return HDF_FAILURE; + } + asr_pinmux_config(udd->resource.pin_tx_pin, udd->resource.pin_tx_mux); + asr_pinmux_config(udd->resource.pin_rx_pin, udd->resource.pin_rx_mux); + params = &udd->params; + params->port = udd->resource.port; + params->config.data_width = GetUartDataBits(udd->attr.dataBits); + params->config.stop_bits = GetUartStopBits(udd->attr.stopBits); + params->config.parity = GetUartParity(udd->attr.parity); + params->config.flow_control = GetUartFlowControl(udd->attr.rts, udd->attr.cts); + params->config.mode = udd->resource.tx_rx; + params->priv = (void *)g_evtHandler[udd->resource.port]; + + ret = asr_uart_init(params); + if (ret != 0) { + HDF_LOGE("%s , app uart init failed\r\n", __func__); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +static int32_t UartHostDevRead(struct UartHost *host, uint8_t *data, uint32_t size) +{ + int32_t ret; + uint32_t uwRet = 0; + uint32_t recv_len = 0; + struct UartDriverData *udd = NULL; + uint8_t port = 0; + uint8_t *src = NULL; + + if ((host == NULL) || (host->priv == NULL) || (data == NULL)) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + udd = (struct UartDriverData *)host->priv; + port = udd->resource.port; + src = rx_buf[port]; + if (udd->state != UART_STATE_USEABLE) { + HDF_LOGE("%s: uart_%d not useable", __func__, port); + return HDF_FAILURE; + } + + LOS_MuxPend(g_uartRxMutex[port], LOS_WAIT_FOREVER); + if (udd->flags & UART_FLG_RD_BLOCK) { + while (recv_len != size) { + if (rx_head[port] != rx_tail[port]) { + data[recv_len++] = src[rx_tail[port]++]; + rx_tail[port] %= UART_RX_BUF_LEN; + } + } + } else { + while ((recv_len != size) && (rx_head[port] != rx_tail[port])) { + data[recv_len++] = src[rx_tail[port]++]; + rx_tail[port] %= UART_RX_BUF_LEN; + } + } + LOS_MuxPost(g_uartRxMutex[port]); + + return recv_len; +} + +static int32_t UartHostDevWrite(struct UartHost *host, uint8_t *data, uint32_t size) +{ + int32_t ret; + struct UartDriverData *udd = NULL; + + if ((host == NULL) || (host->priv == NULL) || (data == NULL)) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + udd = (struct UartDriverData *)host->priv; + if (udd->state != UART_STATE_USEABLE) { + HDF_LOGE("%s: uart_%d not useable", __func__, udd->resource.port); + return HDF_FAILURE; + } + + LOS_MuxPend(g_uartTxMutex[udd->resource.port], LOS_WAIT_FOREVER); + ret = asr_uart_send(&udd->params, data, size, UART_TRANS_TIMEOUT); + if (ret != 0) { + LOS_MuxPost(g_uartTxMutex[udd->resource.port]); + HDF_LOGE("%s: uart_%d send %d data failed", __func__, udd->resource.port, size); + return HDF_FAILURE; + } + LOS_MuxPost(g_uartTxMutex[udd->resource.port]); + + return HDF_SUCCESS; +} + +static int32_t UartHostDevGetBaud(struct UartHost *host, uint32_t *baudRate) +{ + struct UartDriverData *udd = NULL; + + if (host == NULL || host->priv == NULL || baudRate == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + udd = (struct UartDriverData *)host->priv; + if (udd->state != UART_STATE_USEABLE) { + HDF_LOGE("%s: uart_%d not useable", __func__, udd->resource.port); + return HDF_FAILURE; + } + *baudRate = udd->params.config.baud_rate; + + return HDF_SUCCESS; +} + +static int32_t UartHostDevSetBaud(struct UartHost *host, uint32_t baudRate) +{ + struct UartDriverData *udd = NULL; + + if (host == NULL || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + udd = (struct UartDriverData *)host->priv; + if (udd->state != UART_STATE_USEABLE) { + HDF_LOGE("%s: uart_%d not useable", __func__, udd->resource.port); + return HDF_FAILURE; + } + if ((baudRate > 0) && (baudRate <= CONFIG_MAX_BAUDRATE)) { + udd->params.config.baud_rate = baudRate; + if (udd->config == NULL) { + HDF_LOGE("%s: not support", __func__); + return HDF_ERR_NOT_SUPPORT; + } + if (udd->config(udd) != HDF_SUCCESS) { + HDF_LOGE("%s: config baudrate %d failed", __func__, baudRate); + return HDF_FAILURE; + } + } else { + HDF_LOGE("%s: invalid baudrate, which is:%d", __func__, baudRate); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribute *attribute) +{ + struct UartDriverData *udd = NULL; + + if (host == NULL || host->priv == NULL || attribute == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + udd = (struct UartDriverData *)host->priv; + if (udd->state != UART_STATE_USEABLE) { + return HDF_FAILURE; + } + + *attribute = udd->attr; + + return HDF_SUCCESS; +} + +static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribute *attribute) +{ + struct UartDriverData *udd = NULL; + + if (host == NULL || host->priv == NULL || attribute == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + udd = (struct UartDriverData *)host->priv; + if (udd->state != UART_STATE_USEABLE) { + HDF_LOGE("%s: uart_%d not useable", __func__, udd->resource.port); + return HDF_FAILURE; + } + + udd->attr = *attribute; + if (udd->config == NULL) { + HDF_LOGE("%s: not support", __func__); + return HDF_ERR_NOT_SUPPORT; + } + if (udd->config(udd) != HDF_SUCCESS) { + HDF_LOGE("%s: config failed", __func__); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +static int32_t UartHostDevSetTransMode(struct UartHost *host, enum UartTransMode mode) +{ + struct UartDriverData *udd = NULL; + + if (host == NULL || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + udd = (struct UartDriverData *)host->priv; + if (udd->state != UART_STATE_USEABLE) { + HDF_LOGE("%s: uart_%d not useable", __func__, udd->resource.port); + return HDF_FAILURE; + } + if (UART_MODE_RD_BLOCK == mode) { + udd->flags |= UART_FLG_RD_BLOCK; + } else if (UART_MODE_RD_NONBLOCK == mode) { + udd->flags &= (~UART_FLG_RD_BLOCK); + } else { + HDF_LOGE("%s: uart_%d not support mode:%d", __func__, udd->resource.port, mode); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +static int32_t UartDevSemInit(uint32_t id) +{ + uint32_t uwRet = 0; + + uwRet = LOS_MuxCreate(&g_uartTxMutex[id]); + if (uwRet != LOS_OK) { + return HDF_FAILURE; + } + + uwRet = LOS_MuxCreate(&g_uartRxMutex[id]); + if (uwRet != LOS_OK) { + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +static void UartDevSemDeinit(uint32_t id) +{ + if (g_uartTxMutex[id] != 0) { + LOS_MuxDelete(g_uartTxMutex[id]); + } + + if (g_uartRxMutex[id] != 0) { + LOS_MuxDelete(g_uartRxMutex[id]); + } + + g_uartTxMutex[id] = 0; + g_uartRxMutex[id] = 0; +} + +static int32_t UartHostDevInit(struct UartHost *host) +{ + struct UartDriverData *udd = NULL; + uint32_t ret = 0; + uint8_t *ptxBuf = NULL; + + if (host == NULL || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + udd = (struct UartDriverData *)host->priv; + if (udd->resource.port >= ASR_UART_NUM) { + HDF_LOGE("%s: uart id is greater than the maximum", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (udd->state == UART_STATE_NOT_OPENED) { + udd->state = UART_STATE_OPENING; + + ptxBuf = (uint8_t *)OsalMemCalloc(UART_RX_BUF_LEN); + if (ptxBuf == NULL) { + HDF_LOGE("%s: alloc tx buffer failed", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + ret = UartDevSemInit(udd->resource.port); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: uart semaphor init failed", __func__); + UartDevSemDeinit(udd->resource.port); + return HDF_FAILURE; + } + + rx_buf[udd->resource.port] = ptxBuf; + udd->config = Asr582xUartConfig; + + if (udd->config(udd) != HDF_SUCCESS) { + UartDevSemDeinit(udd->resource.port); + (void)OsalMemFree(rx_buf[udd->resource.port]); + rx_buf[udd->resource.port] = NULL; + return HDF_FAILURE; + } + } + + udd->state = UART_STATE_USEABLE; + udd->count++; + return HDF_SUCCESS; +} + +static int32_t UartHostDevDeinit(struct UartHost *host) +{ + struct UartDriverData *udd = NULL; + if (host == NULL || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + udd = (struct UartDriverData *)host->priv; + if ((--udd->count) != 0) { + return HDF_SUCCESS; + } + asr_uart_finalize(&udd->params); + UartDevSemDeinit(udd->resource.port); + if (rx_buf[udd->resource.port] != NULL) { + (void)OsalMemFree(rx_buf[udd->resource.port]); + rx_buf[udd->resource.port] = NULL; + } + + udd->state = UART_STATE_NOT_OPENED; + return HDF_SUCCESS; +} + +struct UartHostMethod g_uartHostMethod = { + .Init = UartHostDevInit, + .Deinit = UartHostDevDeinit, + .Read = UartHostDevRead, + .Write = UartHostDevWrite, + .SetBaud = UartHostDevSetBaud, + .GetBaud = UartHostDevGetBaud, + .SetAttribute = UartHostDevSetAttribute, + .GetAttribute = UartHostDevGetAttribute, + .SetTransMode = UartHostDevSetTransMode, +}; + +static int32_t UartGetPinConfigFromHcs(struct UartDriverData *udd, const struct DeviceResourceNode *node) +{ + uint32_t resourceData; + struct DeviceResourceIface *iface = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + + if (iface == NULL || iface->GetUint32 == NULL) { + HDF_LOGE("%s: face is invalid", __func__); + return HDF_FAILURE; + } + + if (iface->GetUint32(node, "port", &resourceData, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: read port fail", __func__); + return HDF_FAILURE; + } + udd->resource.port = resourceData; + + if (iface->GetUint32(node, "pin_tx_pin", &resourceData, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: read pin_tx_pin fail", __func__); + return HDF_FAILURE; + } + udd->resource.pin_tx_pin = resourceData; + + if (iface->GetUint32(node, "pin_tx_mux", &resourceData, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: read pin_tx_pin fail", __func__); + return HDF_FAILURE; + } + udd->resource.pin_tx_mux = resourceData; + + if (iface->GetUint32(node, "pin_rx_pin", &resourceData, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: read pin_rx_pin fail", __func__); + return HDF_FAILURE; + } + udd->resource.pin_rx_pin = resourceData; + + if (iface->GetUint32(node, "pin_rx_mux", &resourceData, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: read pin_rx_pin fail", __func__); + return HDF_FAILURE; + } + udd->resource.pin_rx_mux = resourceData; + + if (iface->GetUint32(node, "tx_rx", &resourceData, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: read tx_rx fail", __func__); + return HDF_FAILURE; + } + udd->resource.tx_rx = resourceData; + + return HDF_SUCCESS; +} + +static int32_t UartDevAttach(struct UartHost *host, struct HdfDeviceObject *device) +{ + int32_t ret; + struct UartDriverData *udd = NULL; + + if (device->property == NULL) { + HDF_LOGE("%s: property is null", __func__); + return HDF_FAILURE; + } + udd = (struct UartDriverData *)OsalMemCalloc(sizeof(*udd)); + if (udd == NULL) { + HDF_LOGE("%s: OsalMemCalloc udd error", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + ret = UartGetPinConfigFromHcs(udd, device->property); + if (ret != HDF_SUCCESS) { + (void)OsalMemFree(udd); + return HDF_FAILURE; + } + + udd->state = UART_STATE_NOT_OPENED; + udd->config = NULL; + udd->count = 0; + + asr_uart_struct_init(&udd->params); + udd->params.port = udd->resource.port; + udd->params.config.baud_rate = DEFAULT_BAUDRATE; + udd->attr.dataBits = DEFAULT_DATABITS; + udd->attr.stopBits = DEFAULT_STOPBITS; + udd->attr.parity = DEFAULT_PARITY; + + host->priv = udd; + host->num = udd->resource.port; + + return HDF_SUCCESS; +} + +static void UartDevDetach(struct UartHost *host) +{ + struct UartDriverData *udd = NULL; + + if (host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return; + } + udd = (struct UartDriverData *)host->priv; + if (udd->state != UART_STATE_NOT_OPENED) { + HDF_LOGE("%s: uart driver data state invalid", __func__); + return; + } + + (void)OsalMemFree(udd); + host->priv = NULL; +} + +static int32_t HdfUartDeviceBind(struct HdfDeviceObject *device) +{ + if (device == NULL) { + return HDF_ERR_INVALID_OBJECT; + } + return (UartHostCreate(device) == NULL) ? HDF_FAILURE : HDF_SUCCESS; +} + +int32_t HdfUartDeviceInit(struct HdfDeviceObject *device) +{ + int32_t ret; + struct UartHost *host = NULL; + + if (device == NULL) { + HDF_LOGE("%s: device is null", __func__); + return HDF_ERR_INVALID_OBJECT; + } + host = UartHostFromDevice(device); + if (host == NULL) { + HDF_LOGE("%s: host is null", __func__); + return HDF_FAILURE; + } + ret = UartDevAttach(host, device); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: attach error", __func__); + return HDF_FAILURE; + } + host->method = &g_uartHostMethod; + return ret; +} + +void HdfUartDeviceRelease(struct HdfDeviceObject *device) +{ + struct UartHost *host = NULL; + + if (device == NULL) { + HDF_LOGE("%s: device is null", __func__); + return; + } + host = UartHostFromDevice(device); + if (host == NULL) { + HDF_LOGE("%s: host is null", __func__); + return; + } + if (host->priv != NULL) { + UartDevDetach(host); + } + UartHostDestroy(host); +} + +struct HdfDriverEntry g_hdfUartDevice = { + .moduleVersion = 1, + .moduleName = "HDF_PLATFORM_UART", + .Bind = HdfUartDeviceBind, + .Init = HdfUartDeviceInit, + .Release = HdfUartDeviceRelease, +}; + +HDF_INIT(g_hdfUartDevice); -- Gitee From 0ea221fff98c2b6d4dc5e3e99fac120c2495830e Mon Sep 17 00:00:00 2001 From: bob_qu Date: Tue, 15 Mar 2022 21:05:20 +0800 Subject: [PATCH 021/102] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0winnermicro?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0HDF=E9=A9=B1=E5=8A=A8=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bob_qu --- OAT.xml | 2 + platform/gpio/BUILD.gn | 3 + platform/gpio/gpio_wm.c | 336 ++++++++++++++++ platform/gpio/gpio_wm.h | 67 ++++ platform/i2c/BUILD.gn | 3 + platform/i2c/i2c_wm.c | 333 ++++++++++++++++ platform/i2c/i2c_wm.h | 46 +++ platform/pwm/BUILD.gn | 3 + platform/pwm/pwm_wm.c | 209 ++++++++++ platform/pwm/pwm_wm.h | 40 ++ platform/spi/BUILD.gn | 3 + platform/spi/spi_wm.c | 492 +++++++++++++++++++++++ platform/spi/spi_wm.h | 50 +++ platform/uart/BUILD.gn | 3 + platform/uart/uart_wm.c | 673 ++++++++++++++++++++++++++++++++ platform/uart/uart_wm.h | 72 ++++ platform/watchdog/BUILD.gn | 4 + platform/watchdog/watchdog_wm.c | 258 ++++++++++++ platform/watchdog/watchdog_wm.h | 36 ++ 19 files changed, 2633 insertions(+) create mode 100755 platform/gpio/gpio_wm.c create mode 100755 platform/gpio/gpio_wm.h create mode 100755 platform/i2c/i2c_wm.c create mode 100755 platform/i2c/i2c_wm.h create mode 100755 platform/pwm/pwm_wm.c create mode 100755 platform/pwm/pwm_wm.h create mode 100755 platform/spi/spi_wm.c create mode 100755 platform/spi/spi_wm.h create mode 100755 platform/uart/uart_wm.c create mode 100755 platform/uart/uart_wm.h create mode 100755 platform/watchdog/watchdog_wm.c create mode 100755 platform/watchdog/watchdog_wm.h diff --git a/OAT.xml b/OAT.xml index 790e94c..93fb38b 100644 --- a/OAT.xml +++ b/OAT.xml @@ -60,6 +60,8 @@ Note:If the text contains special characters, please escape them according to th + + diff --git a/platform/gpio/BUILD.gn b/platform/gpio/BUILD.gn index 043e367..1a8d54d 100644 --- a/platform/gpio/BUILD.gn +++ b/platform/gpio/BUILD.gn @@ -19,6 +19,9 @@ hdf_driver(module_name) { if (defined(LOSCFG_SOC_COMPANY_GOODIX)) { sources += [ "gpio_gr5xx.c" ] } + if (defined(LOSCFG_SOC_COMPANY_WINNERMICRO)) { + sources += [ "gpio_wm.c" ] + } include_dirs = [ "." ] if (defined(LOSCFG_SHIELD_V200ZR_EVB_T1)) { diff --git a/platform/gpio/gpio_wm.c b/platform/gpio/gpio_wm.c new file mode 100755 index 0000000..7fe5f84 --- /dev/null +++ b/platform/gpio/gpio_wm.c @@ -0,0 +1,336 @@ +/* + * Copyright (C) 2022 HiHope Open Source Organization . + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gpio_wm.h" +#include +#include "gpio_if.h" +#include "device_resource_if.h" +#include "osal_irq.h" +#include "hdf_log.h" +#include "wm_io.h" +#include "wm_gpio.h" + +#define HDF_LOG_TAG gpioDriver +#define WM_IO_MAX_GPIO_PIN_NUM 48 + +static struct GpioCntlr gpioCntlr; +struct wmGpioIrqHandler { + uint8_t port; +}; + +enum tls_io_name g_gpioPinReflectionMap[WM_IO_MAX_GPIO_PIN_NUM] = {0}; +static struct wmGpioIrqHandler g_wmGpioIrqHandler[WM_IO_MAX_GPIO_PIN_NUM] = {0}; +enum tls_gpio_irq_trig g_gpioIrqCfg[WM_IO_MAX_GPIO_PIN_NUM] = {0}; + + +GpioIrqFunc GpioIrqHdl() +{ + uint16_t ret; + + for (size_t i = 0; i < WM_IO_MAX_GPIO_PIN_NUM; i++) { + ret = tls_get_gpio_irq_status(g_wmGpioIrqHandler[i].port); + if ((enum tls_io_name)g_gpioPinReflectionMap[i] && (ret != 0)) { + GpioCntlrIrqCallback(&gpioCntlr, i); + return; + } + } +} + +/* dispatch */ +int32_t GpioDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + if (client == NULL || client->device == NULL || data == NULL || reply == NULL) { + HDF_LOGE("%s: client or client->device is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + return HDF_SUCCESS; +} + +/* dev api */ +static int32_t GpioDevWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val) +{ + (void)cntlr; + uint16_t wmGpio = g_gpioPinReflectionMap[gpio]; + if ((enum tls_io_name)wmGpio > WM_IO_MAX_GPIO_PIN_NUM) { + HDF_LOGE("%s %d, error wmGpio:%d", __func__, __LINE__, wmGpio); + return HDF_ERR_NOT_SUPPORT; + } + + tls_gpio_write((enum tls_io_name)wmGpio, val); + return HDF_SUCCESS; +} + +static int32_t GpioDevRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val) +{ + (void)cntlr; + uint16_t value; + uint16_t wmGpio = g_gpioPinReflectionMap[gpio]; + if ((enum tls_io_name)wmGpio > WM_IO_MAX_GPIO_PIN_NUM) { + HDF_LOGE("%s %d, error wmGpio:%d", __func__, __LINE__, wmGpio); + return HDF_ERR_NOT_SUPPORT; + } + + value = tls_gpio_read((enum tls_io_name)wmGpio); + *val = value; + return HDF_SUCCESS; +} + +static int32_t GpioDevSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t dir) +{ + (void)cntlr; + uint16_t wmGpio = g_gpioPinReflectionMap[gpio]; + if ((enum tls_io_name)wmGpio > WM_IO_MAX_GPIO_PIN_NUM) { + HDF_LOGE("%s %d, error wmGpio:%d", __func__, __LINE__, wmGpio); + return HDF_ERR_NOT_SUPPORT; + } + + switch (dir) { + case GPIO_DIR_OUT: + dir = WM_GPIO_DIR_OUTPUT; + break; + case GPIO_DIR_IN: + dir = WM_GPIO_DIR_INPUT; + break; + } + + tls_gpio_cfg((enum tls_io_name)wmGpio, (enum tls_gpio_dir)dir, WM_GPIO_ATTR_FLOATING); + + return HDF_SUCCESS; +} + +static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mode) +{ + (void)cntlr; + uint16_t wmGpio = g_gpioPinReflectionMap[gpio]; + if ((enum tls_io_name)wmGpio > WM_IO_MAX_GPIO_PIN_NUM) { + HDF_LOGE("%s %d, error wmGpio:%d", __func__, __LINE__, wmGpio); + return HDF_ERR_NOT_SUPPORT; + } + + g_wmGpioIrqHandler[wmGpio].port = gpio; + tls_gpio_isr_register((enum tls_io_name)wmGpio, (tls_gpio_irq_callback)GpioIrqHdl, NULL); + + switch (mode) { + case OSAL_IRQF_TRIGGER_RISING: + g_gpioIrqCfg[wmGpio] = WM_GPIO_IRQ_TRIG_RISING_EDGE; + break; + case OSAL_IRQF_TRIGGER_FALLING: + g_gpioIrqCfg[wmGpio] = WM_GPIO_IRQ_TRIG_FALLING_EDGE; + break; + case OSAL_IRQF_TRIGGER_HIGH: + g_gpioIrqCfg[wmGpio] = WM_GPIO_IRQ_TRIG_HIGH_LEVEL; + break; + case OSAL_IRQF_TRIGGER_LOW: + g_gpioIrqCfg[wmGpio] = WM_GPIO_IRQ_TRIG_LOW_LEVEL; + break; + } + + return HDF_SUCCESS; +} + +static int32_t GpioDevUnSetIrq(struct GpioCntlr *cntlr, uint16_t gpio) +{ + (void)cntlr; + uint16_t wmGpio = g_gpioPinReflectionMap[gpio]; + if ((enum tls_io_name)wmGpio > WM_IO_MAX_GPIO_PIN_NUM) { + HDF_LOGE("%s %d, error wmGpio:%d", __func__, __LINE__, wmGpio); + return HDF_ERR_NOT_SUPPORT; + } + return HDF_SUCCESS; +} + +static int32_t GpioDevEnableIrq(struct GpioCntlr *cntlr, uint16_t gpio) +{ + (void)cntlr; + uint16_t wmGpio = g_gpioPinReflectionMap[gpio]; + if ((enum tls_io_name)wmGpio > WM_IO_MAX_GPIO_PIN_NUM) { + HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, wmGpio); + return HDF_ERR_NOT_SUPPORT; + } + + // config gpio interrupt + tls_gpio_irq_enable((enum tls_io_name)wmGpio, g_gpioIrqCfg[wmGpio]); + return HDF_SUCCESS; +} + +static int32_t GpioDevDisableIrq(struct GpioCntlr *cntlr, uint16_t gpio) +{ + (void)cntlr; + uint16_t wmGpio = g_gpioPinReflectionMap[gpio]; + if ((enum tls_io_name)wmGpio > WM_IO_MAX_GPIO_PIN_NUM) { + HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, wmGpio); + return HDF_ERR_NOT_SUPPORT; + } + + tls_gpio_irq_disable((enum tls_io_name)wmGpio); + return HDF_SUCCESS; +} + +/* GpioMethod definitions */ +struct GpioMethod g_GpioCntlrMethod = { + .request = NULL, + .release = NULL, + .write = GpioDevWrite, + .read = GpioDevRead, + .setDir = GpioDevSetDir, + .getDir = NULL, + .toIrq = NULL, + .setIrq = GpioDevSetIrq, + .unsetIrq = GpioDevUnSetIrq, + .enableIrq = GpioDevEnableIrq, + .disableIrq = GpioDevDisableIrq, +}; + +static uint32_t GetGpioDeviceResource(struct GpioDevice *device, + const struct DeviceResourceNode *resourceNode) +{ + uint32_t relPin; + int32_t ret; + struct GpioResource *resource = NULL; + struct DeviceResourceIface *dri = NULL; + if (device == NULL || resourceNode == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + resource = &device->resource; + if (resource == NULL) { + HDF_LOGE("%s: resource is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (dri == NULL || dri->GetUint32 == NULL) { + HDF_LOGE("DeviceResourceIface is invalid"); + return HDF_ERR_INVALID_OBJECT; + } + + if (dri->GetUint32(resourceNode, "groupNum", &resource->groupNum, 0) != HDF_SUCCESS) { + HDF_LOGE("gpio config read groupNum fail"); + return HDF_FAILURE; + } + + if (dri->GetUint32(resourceNode, "pinNum", &resource->pinNum, 0) != HDF_SUCCESS) { + HDF_LOGE("gpio config read pinNum fail"); + return HDF_FAILURE; + } + + for (size_t i = 0; i < resource->groupNum; i++) { + if (dri->GetUint32ArrayElem(resourceNode, "config", i, &resource->config, 0) != HDF_SUCCESS) { + HDF_LOGE("gpio config read config fail"); + return HDF_FAILURE; + } + } + device->config = resource->config; + return HDF_SUCCESS; +} + +static int32_t AttachGpioDevice(struct GpioCntlr *gpioCntlr, struct HdfDeviceObject *device) +{ + int32_t ret; + + struct GpioDevice *gpioDevice = NULL; + if (device == NULL || device->property == NULL) { + HDF_LOGE("%s: property is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + + gpioDevice = (struct GpioDevice *)OsalMemAlloc(sizeof(struct GpioDevice)); + if (gpioDevice == NULL) { + HDF_LOGE("%s: OsalMemAlloc gpioDevice error", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + ret = GetGpioDeviceResource(gpioDevice, device->property); + if (ret != HDF_SUCCESS) { + (void)OsalMemFree(gpioDevice); + return HDF_FAILURE; + } + + gpioCntlr->count = gpioDevice->resource.pinNum; + + return HDF_SUCCESS; +} + +static int32_t GpioDriverInit(struct HdfDeviceObject *device) +{ + int32_t ret; + struct GpioCntlr *gpioCntlr = NULL; + + if (device == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + + gpioCntlr = GpioCntlrFromHdfDev(device); + if (gpioCntlr == NULL) { + HDF_LOGE("GpioCntlrFromHdfDev fail\r\n"); + return HDF_DEV_ERR_NO_DEVICE_SERVICE; + } + + ret = AttachGpioDevice(gpioCntlr, device); // GpioCntlr add GpioDevice to priv + if (ret != HDF_SUCCESS) { + HDF_LOGE("AttachGpioDevice fail\r\n"); + return HDF_DEV_ERR_ATTACHDEV_FAIL; + } + + gpioCntlr->ops = &g_GpioCntlrMethod; // register callback + ret = GpioCntlrAdd(gpioCntlr); + if (ret != HDF_SUCCESS) { + HDF_LOGE("GpioCntlrAdd fail %d\r\n", gpioCntlr->start); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +static int32_t GpioDriverBind(struct HdfDeviceObject *device) +{ + if (device == NULL) { + HDF_LOGE("Sample device object is null!"); + return HDF_ERR_INVALID_PARAM; + } + + gpioCntlr.device.hdfDev = device; + device->service = gpioCntlr.device.hdfDev; + + return HDF_SUCCESS; +} + +static void GpioDriverRelease(struct HdfDeviceObject *device) +{ + struct GpioCntlr *gpioCntlr = NULL; + + if (device == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return; + } + + gpioCntlr = GpioCntlrFromHdfDev(device); + if (gpioCntlr == NULL) { + HDF_LOGE("%s: host is NULL", __func__); + return; + } + + gpioCntlr->ops = NULL; + OsalMemFree(gpioCntlr); +} + +/* HdfDriverEntry definitions */ +struct HdfDriverEntry g_GpioDriverEntry = { + .moduleVersion = 1, + .moduleName = "WM_GPIO_MODULE_HDF", + .Bind = GpioDriverBind, + .Init = GpioDriverInit, + .Release = GpioDriverRelease, +}; +HDF_INIT(g_GpioDriverEntry); diff --git a/platform/gpio/gpio_wm.h b/platform/gpio/gpio_wm.h new file mode 100755 index 0000000..e183278 --- /dev/null +++ b/platform/gpio/gpio_wm.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2022 HiHope Open Source Organization . + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef GPIO_WINNERMICRO_H +#define GPIO_WINNERMICRO_H + +#include "gpio_core.h" +#include "gpio_if.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Pin configuration + */ +enum GPIO_CONFIG { + ANALOG_MODE, /* Used as a function pin, input and output analog */ + IRQ_MODE, /* Used to trigger interrupt */ + INPUT_PULL_UP, /* Input with an internal pull-up resistor - use with devices + that actively drive the signal low - e.g. button connected to ground */ + INPUT_PULL_DOWN, /* Input with an internal pull-down resistor - use with devices + that actively drive the signal high - e.g. button connected to a power rail */ + INPUT_HIGH_IMPEDANCE, /* Input - must always be driven, either actively or by an external pullup resistor */ + OUTPUT_PUSH_PULL, /* Output actively driven high and actively driven low - + must not be connected to other active outputs - e.g. LED output */ + OUTPUT_OPEN_DRAIN_NO_PULL, /* Output actively driven low but is high-impedance when set high - + can be connected to other open-drain/open-collector outputs. + Needs an external pull-up resistor */ + OUTPUT_OPEN_DRAIN_PULL_UP, /* Output actively driven low and is pulled high + with an internal resistor when set high - + can be connected to other open-drain/open-collector outputs. */ +}; + +struct GpioResource { + uint32_t groupNum; + uint32_t realPin; + uint32_t config; + uint32_t pinNum; +}; + +struct GpioDevice { + uint8_t port; /* gpio port */ + struct GpioResource resource; + enum GPIO_CONFIG config; /* gpio config */ +}; + +typedef void (* tls_gpio_pin_orq_handler)(enum tls_io_name pin); + +#define DECIMALNUM 10 +#define OCTALNUM 8 +#ifdef __cplusplus +} +#endif + +#endif /* __GPIO_H__ */ \ No newline at end of file diff --git a/platform/i2c/BUILD.gn b/platform/i2c/BUILD.gn index 25d6112..491883c 100644 --- a/platform/i2c/BUILD.gn +++ b/platform/i2c/BUILD.gn @@ -16,6 +16,9 @@ hdf_driver(module_name) { if (defined(LOSCFG_SOC_COMPANY_BESTECHNIC)) { sources += [ "i2c_bes.c" ] } + if (defined(LOSCFG_SOC_COMPANY_WINNERMICRO)) { + sources += [ "i2c_wm.c" ] + } include_dirs = [ "." ] if (defined(LOSCFG_SHIELD_V200ZR_EVB_T1) && diff --git a/platform/i2c/i2c_wm.c b/platform/i2c/i2c_wm.c new file mode 100755 index 0000000..dc2a959 --- /dev/null +++ b/platform/i2c/i2c_wm.c @@ -0,0 +1,333 @@ +/* + * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "i2c_wm.h" +#include +#include +#include "i2c_core.h" +#include "i2c_if.h" +#include "wm_i2c.h" +#include "wm_gpio_afsel.h" + +#define DEC_NUM 10 +#define GROUP_PIN_NUM 8 +#define I2C_INVALID_ADDR 0xFFFF + +/* HdfDriverEntry method definitions */ +static int32_t i2cDriverBind(struct HdfDeviceObject *device); +static int32_t i2cDriverInit(struct HdfDeviceObject *device); +static void i2cDriverRelease(struct HdfDeviceObject *device); + +/* HdfDriverEntry definitions */ +struct HdfDriverEntry g_i2cDriverEntry = { + .moduleVersion = 1, + .moduleName = "W800_I2C_MODULE_HDF", + .Bind = i2cDriverBind, + .Init = i2cDriverInit, + .Release = i2cDriverRelease, +}; + +// Initialize HdfDriverEntry +HDF_INIT(g_i2cDriverEntry); + +/* I2cHostMethod method definitions */ +static int32_t i2cHostTransfer(struct I2cCntlr *cntlr, struct I2cMsg *msgs, int16_t count); + +struct I2cMethod g_i2cHostMethod = { + .transfer = i2cHostTransfer, +}; + +int32_t InitI2cDevice(struct I2cDevice *device) +{ + int32_t ret = -1; + uint32_t i2cPort; + struct I2cResource *resource = NULL; + + if (device == NULL) { + HDF_LOGE("device is NULL\r\n"); + return HDF_ERR_INVALID_PARAM; + } + + resource = &device->resource; + device->port = resource->port; + i2cPort = device->port; + if (i2cPort >= HAL_I2C_ID_NUM) { + HDF_LOGE("i2c port %u not support\r\n", i2cPort); + return HDF_ERR_NOT_SUPPORT; + } + + if (OsalMutexInit(&device->mutex) != HDF_SUCCESS) { + HDF_LOGE("%s %d OsalMutexInit fail\r\n", __func__, __LINE__); + return HDF_FAILURE; + } + + if (HDF_SUCCESS != OsalMutexLock(&device->mutex)) { + HDF_LOGE("%s %d osMutexWait fail\r\n", __func__, __LINE__); + return HDF_ERR_TIMEOUT; + } + + if ((resource->sclPin == WM_IO_PA_01) && (resource->sdaPin == WM_IO_PA_04)) { + wm_i2c_scl_config(WM_IO_PA_01); + wm_i2c_sda_config(WM_IO_PA_04); + } else { + HDF_LOGE("%s %d scl sda pin fail\r\n", __func__, __LINE__); + OsalMutexUnlock(&device->mutex); + return HDF_ERR_INVALID_PARAM; + } + + tls_i2c_init(resource->speed); + OsalMutexUnlock(&device->mutex); + return HDF_SUCCESS; +} + +static int32_t HostRestI2cDevice(struct I2cDevice *device) +{ + int32_t ret = -1; + struct I2cResource *resource = NULL; + uint32_t i2cPort; + + if (device == NULL) { + HDF_LOGE("%s %d device is null\r\n", __func__, __LINE__); + return HDF_ERR_INVALID_PARAM; + } + resource = &device->resource; + if (resource == NULL) { + HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__); + return HDF_ERR_INVALID_OBJECT; + } + device->port = resource->port; + i2cPort = device->port; + if (i2cPort > HAL_I2C_ID_NUM) { + HDF_LOGE("i2c port %u not support\r\n", i2cPort); + return HDF_ERR_NOT_SUPPORT; + } + + return HDF_SUCCESS; +} + +static uint32_t GetI2cDeviceResource(struct I2cDevice *device, + const struct DeviceResourceNode *resourceNode) +{ + uint32_t tempPin = 0; + struct I2cResource *resource = NULL; + struct DeviceResourceIface *dri = NULL; + if (device == NULL || resourceNode == NULL) { + HDF_LOGE("device or resourceNode is NULL\r\n"); + return HDF_ERR_INVALID_PARAM; + } + resource = &device->resource; + if (resource == NULL) { + HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__); + return HDF_ERR_INVALID_OBJECT; + } + dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (dri == NULL || dri->GetUint32 == NULL) { + HDF_LOGE("DeviceResourceIface is invalid\r\n"); + return HDF_ERR_INVALID_OBJECT; + } + + if (dri->GetUint32(resourceNode, "port", &resource->port, 0) != HDF_SUCCESS) { + HDF_LOGE("i2c config port fail\r\n"); + return HDF_FAILURE; + } + + if (dri->GetUint32(resourceNode, "sclPin", &tempPin, 0) != HDF_SUCCESS) { + HDF_LOGE("i2c config sclPin fail\r\n"); + return HDF_FAILURE; + } + resource->sclPin = ((tempPin / DEC_NUM) * GROUP_PIN_NUM) + (tempPin % DEC_NUM); + + if (dri->GetUint32(resourceNode, "sdaPin", &tempPin, 0) != HDF_SUCCESS) { + HDF_LOGE("i2c config sdaPin fail\r\n"); + return HDF_FAILURE; + } + resource->sdaPin = ((tempPin / DEC_NUM) * GROUP_PIN_NUM) + (tempPin % DEC_NUM); + + if (dri->GetUint32(resourceNode, "speed", &resource->speed, 0) != HDF_SUCCESS) { + HDF_LOGE("i2c config speed fail\r\n"); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +static int32_t AttachI2cDevice(struct I2cCntlr *host, struct HdfDeviceObject *device) +{ + int32_t ret; + struct I2cDevice *i2cDevice = NULL; + struct I2cResource *resource = NULL; + + if (device == NULL || host == NULL) { + HDF_LOGE("%s: device or host is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + i2cDevice = (struct I2cDevice *)OsalMemAlloc(sizeof(struct I2cDevice)); + if (i2cDevice == NULL) { + HDF_LOGE("%s: OsalMemAlloc i2cDevice error\r\n", __func__); + return HDF_ERR_MALLOC_FAIL; + } + (void)memset_s(i2cDevice, sizeof(struct I2cDevice), 0, sizeof(struct I2cDevice)); + ret = GetI2cDeviceResource(i2cDevice, device->property); + if (ret != HDF_SUCCESS) { + OsalMemFree(i2cDevice); + return HDF_FAILURE; + } + resource = &i2cDevice->resource; + if (resource == NULL) { + HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__); + return HDF_ERR_INVALID_OBJECT; + } + + host->priv = i2cDevice; + host->busId = i2cDevice->port; + + return InitI2cDevice(i2cDevice); +} + +static int32_t i2cDriverInit(struct HdfDeviceObject *device) +{ + int32_t ret; + struct I2cCntlr *host = NULL; + if (device == NULL) { + HDF_LOGE("%s: device is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + host = (struct I2cCntlr *)OsalMemAlloc(sizeof(struct I2cCntlr)); + if (host == NULL) { + HDF_LOGE("%s: host is NULL\r\n", __func__); + return HDF_ERR_MALLOC_FAIL; + } + (void)memset_s(host, sizeof(struct I2cCntlr), 0, sizeof(struct I2cCntlr)); + host->ops = &g_i2cHostMethod; + device->priv = (void *)host; + ret = AttachI2cDevice(host, device); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: attach error\r\n", __func__); + i2cDriverRelease(device); + return HDF_DEV_ERR_ATTACHDEV_FAIL; + } + ret = I2cCntlrAdd(host); + if (ret != HDF_SUCCESS) { + i2cDriverRelease(device); + return HDF_FAILURE; + } + return ret; +} + +static int32_t i2cDriverBind(struct HdfDeviceObject *device) +{ + if (device == NULL) { + HDF_LOGE("%s: I2c device object is NULL\r\n", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +static void i2cDriverRelease(struct HdfDeviceObject *device) +{ + struct I2cCntlr *i2cCntrl = NULL; + struct I2cDevice *i2cDevice = NULL; + + if (device == NULL) { + HDF_LOGE("%s: device is NULL\r\n", __func__); + return; + } + i2cCntrl = device->priv; + if (i2cCntrl == NULL || i2cCntrl->priv == NULL) { + HDF_LOGE("%s: i2cCntrl is NULL\r\n", __func__); + return; + } + i2cCntrl->ops = NULL; + i2cDevice = (struct I2cDevice *)i2cCntrl->priv; + OsalMemFree(i2cCntrl); + + if (i2cDevice != NULL) { + OsalMutexDestroy(&i2cDevice->mutex); + OsalMemFree(i2cDevice); + } +} + +static int32_t i2c_send(struct I2cMsg *msg) +{ + uint16_t len; + uint8_t ifack, ifstop, ifstart; + + len = msg->len; + ifstop = 0; + if (msg->flags & I2C_FLAG_READ) { + ifack = msg->flags & I2C_FLAG_READ_NO_ACK ? 0 : 1; + for (int32_t j = 0; j < len; j++) { + if (((msg->flags & I2C_FLAG_STOP) && j) == (len - 1)) { + ifstop = 1; + } + msg->buf[j] = tls_i2c_read_byte(ifack, ifstop); + } + } else { + ifack = msg->flags & I2C_FLAG_IGNORE_NO_ACK ? 0 : 1; + for (int32_t j = 0; j < len; j++) { + if (((msg->flags & I2C_FLAG_NO_START) == 0) && (j == 0)) { + ifstart = 1; + } + tls_i2c_write_byte(msg->buf[j], ifstart); + if (ifack) { + tls_i2c_wait_ack(); + } + } + } +} + +static int32_t i2c_transfer(struct I2cDevice *device, struct I2cMsg *msgs, int16_t count) +{ + int ret; + struct I2cMsg *msg = NULL; + + uint32_t i2cPort; + if (device == NULL || msgs == NULL) { + HDF_LOGE("%s: device or msgs is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + i2cPort = (uint32_t)device->port; + if (i2cPort > HAL_I2C_ID_NUM) { + HDF_LOGE("i2c port %u not support\r\n", i2cPort); + return HDF_ERR_NOT_SUPPORT; + } + if (HDF_SUCCESS != OsalMutexLock(&device->mutex)) { + HDF_LOGE("%s %d OsalMutexTimedLock fail\r\n", __func__, __LINE__); + return HDF_ERR_TIMEOUT; + } + for (int32_t i = 0; i < count; i++) { + msg = &msgs[i]; + i2c_send(msg); + } + OsalMutexUnlock(&device->mutex); + return count; +} + +static int32_t i2cHostTransfer(struct I2cCntlr *cntlr, struct I2cMsg *msgs, int16_t count) +{ + struct I2cDevice *device = NULL; + if (cntlr == NULL || msgs == NULL || cntlr->priv == NULL) { + HDF_LOGE("%s: I2cCntlr or msgs is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + device = (struct I2cDevice *)cntlr->priv; + if (device == NULL) { + HDF_LOGE("%s: I2cDevice is NULL\r\n", __func__); + return HDF_DEV_ERR_NO_DEVICE; + } + + return i2c_transfer(device, msgs, count); +} diff --git a/platform/i2c/i2c_wm.h b/platform/i2c/i2c_wm.h new file mode 100755 index 0000000..b24c716 --- /dev/null +++ b/platform/i2c/i2c_wm.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef I2C_WINNERMICRO_H +#define I2C_WINNERMICRO_H + +#include "device_resource_if.h" +#include "osal_mutex.h" +#ifdef __cplusplus +extern "C" { +#endif + +#define HAL_I2C_ID_NUM 1 + +struct I2cResource { + uint32_t port; + uint32_t sclPin; + uint32_t sdaPin; + uint32_t speed; +}; + +struct I2cDevice { + uint16_t devAddr; /**< slave device addr */ + uint32_t addressWidth; /**< Addressing mode: 7 bit or 10 bit */ + struct OsalMutex mutex; + uint32_t port; + struct I2cResource resource; +}; + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/platform/pwm/BUILD.gn b/platform/pwm/BUILD.gn index aad1fff..d7bbac6 100644 --- a/platform/pwm/BUILD.gn +++ b/platform/pwm/BUILD.gn @@ -16,6 +16,9 @@ hdf_driver(module_name) { if (defined(LOSCFG_SOC_COMPANY_BESTECHNIC)) { sources += [ "pwm_bes.c" ] } + if (defined(LOSCFG_SOC_COMPANY_WINNERMICRO)) { + sources += [ "pwm_wm.c" ] + } include_dirs = [ "." ] if (defined(LOSCFG_SHIELD_V200ZR_EVB_T1) && diff --git a/platform/pwm/pwm_wm.c b/platform/pwm/pwm_wm.c new file mode 100755 index 0000000..fbe1de9 --- /dev/null +++ b/platform/pwm/pwm_wm.c @@ -0,0 +1,209 @@ +/* + * Copyright (C) 2022 HiHope Open Source Organization . + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "pwm_wm.h" +#include +#include +#include "device_resource_if.h" +#include "hdf_device_desc.h" +#include "pwm_core.h" +#include "hdf_log.h" +#include "wm_pwm.h" + +static int32_t PwmDevSetConfig(struct PwmDev *pwm, struct PwmConfig *config); + +struct PwmMethod g_pwmmethod = { + .setConfig = PwmDevSetConfig, +}; + +static int32_t PwmDevSetConfig(struct PwmDev *pwm, struct PwmConfig *config) +{ + struct PwmDevice *prvPwm = NULL; + pwm_init_param *pwmCfg = NULL; + uint32_t freq; + + if (pwm == NULL || config == NULL) { + HDF_LOGE("%s\r\n", __FUNCTION__); + return HDF_FAILURE; + } + + prvPwm = (struct PwmDevice *)PwmGetPriv(pwm); + if (prvPwm == NULL) { + return HDF_FAILURE; + } + pwmCfg = &prvPwm->pwmCfg; + pwmCfg->period = config->period; + pwmCfg->duty = config->duty; + pwmCfg->pnum = config->number; + pwmCfg->channel = prvPwm->resource.channel; + freq = prvPwm->resource.freq; + + if (config->status == PWM_ENABLE_STATUS) { + tls_pwm_init(pwmCfg->channel, freq, pwmCfg->duty, pwmCfg->pnum); + } + + return HDF_SUCCESS; +} + +static uint32_t GetPwmDeviceResource( + struct PwmDevice *device, const struct DeviceResourceNode *resourceNode) +{ + uint32_t tempPin = 0; + struct DeviceResourceIface *dri = NULL; + struct PwmResource *resource = NULL; + if (device == NULL || resourceNode == NULL) { + HDF_LOGE("resource or device is NULL\r\n"); + return HDF_ERR_INVALID_PARAM; + } + + resource = &device->resource; + if (resource == NULL) { + HDF_LOGE("resource is NULL\r\n"); + return HDF_ERR_INVALID_OBJECT; + } + + dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (dri == NULL || dri->GetUint32 == NULL) { + HDF_LOGE("DeviceResourceIface is invalid\r\n"); + return HDF_ERR_INVALID_PARAM; + } + + if (dri->GetUint32(resourceNode, "channel", &resource->channel, 0) != HDF_SUCCESS) { + HDF_LOGE("read channel fail\r\n"); + return HDF_FAILURE; + } + + if (dri->GetUint32(resourceNode, "freq", &resource->freq, 0) != HDF_SUCCESS) { + HDF_LOGE("read freq fail\r\n"); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +static int32_t AttachPwmDevice(struct PwmDev *host, struct HdfDeviceObject *device) +{ + int32_t ret; + struct PwmDevice *pwmDevice = NULL; + if (device == NULL || device->property == NULL || host == NULL) { + HDF_LOGE("%s: param is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + pwmDevice = (struct PwmDevice *)OsalMemAlloc(sizeof(struct PwmDevice)); + if (pwmDevice == NULL) { + HDF_LOGE("%s: OsalMemAlloc pwmDevice error\r\n", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + ret = GetPwmDeviceResource(pwmDevice, device->property); + if (ret != HDF_SUCCESS) { + (void)OsalMemFree(pwmDevice); + return HDF_FAILURE; + } + + host->priv = pwmDevice; + + return HDF_SUCCESS; +} + +static int32_t PwmDriverBind(struct HdfDeviceObject *device) +{ + static struct PwmDev devService; + + if (device == NULL) { + HDF_LOGE("hdfDevice object is null!\r\n"); + return HDF_FAILURE; + } + + device->service = &devService.service; + devService.device = device; + HDF_LOGI("Enter %s\r\n", __func__); + + return HDF_SUCCESS; +} + +static int32_t PwmDriverInit(struct HdfDeviceObject *device) +{ + int32_t ret; + struct PwmDev *host = NULL; + + if (device == NULL) { + HDF_LOGE("%s: device is NULL\r\n", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + HDF_LOGI("Enter %s:\r\n", __func__); + + host = (struct PwmDev *)OsalMemAlloc(sizeof(struct PwmDev)); + if (host == NULL) { + HDF_LOGE("%s: host is NULL\r\n", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + ret = AttachPwmDevice(host, device); + if (ret != HDF_SUCCESS) { + OsalMemFree(host); + HDF_LOGE("%s:attach error\r\n", __func__); + return HDF_DEV_ERR_ATTACHDEV_FAIL; + } + + host->method = &g_pwmmethod; + ret = PwmDeviceAdd(device, host); + if (ret != HDF_SUCCESS) { + PwmDeviceRemove(device, host); + OsalMemFree(host->device); + OsalMemFree(host); + return HDF_DEV_ERR_NO_DEVICE; + } + + HDF_LOGI("PwmDriverInit success!\r\n"); + return HDF_SUCCESS; +} + +static void PwmDriverRelease(struct HdfDeviceObject *device) +{ + struct PwmDev *host = NULL; + + if (device == NULL || device->service == NULL) { + HDF_LOGE("device is null\r\n"); + return; + } + + host = (struct PwmDev *)device->service; + if (host != NULL && host->device != NULL) { + host->method = NULL; + OsalMemFree(host->device); + OsalMemFree(host); + host->device = NULL; + host = NULL; + } + + device->service = NULL; + HDF_LOGI("PwmDriverRelease finish!!\r\n"); + return; +} + +/* HdfDriverEntry definitions */ +struct HdfDriverEntry g_pwmDriverEntry = { + .moduleVersion = 1, + .moduleName = "WM_PWM_MODULE_HDF", + .Bind = PwmDriverBind, + .Init = PwmDriverInit, + .Release = PwmDriverRelease, +}; + +// Initialize HdfDriverEntry +HDF_INIT(g_pwmDriverEntry); diff --git a/platform/pwm/pwm_wm.h b/platform/pwm/pwm_wm.h new file mode 100755 index 0000000..feff07b --- /dev/null +++ b/platform/pwm/pwm_wm.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2022 HiHope Open Source Organization . + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef PWM_WINNERMICRO_H +#define PWM_WINNERMICRO_H + +#include "pwm_core.h" +#include "wm_pwm.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct PwmResource { + uint32_t channel; + uint32_t freq; +}; + +struct PwmDevice { + struct IDeviceIoService ioService; + pwm_init_param pwmCfg; + struct PwmConfig *cfg; + struct PwmResource resource; +}; + +#ifdef __cplusplus +} +#endif +#endif diff --git a/platform/spi/BUILD.gn b/platform/spi/BUILD.gn index 9f32525..f2bb81d 100644 --- a/platform/spi/BUILD.gn +++ b/platform/spi/BUILD.gn @@ -16,6 +16,9 @@ hdf_driver(module_name) { if (defined(LOSCFG_SOC_COMPANY_BESTECHNIC)) { sources += [ "spi_bes.c" ] } + if (defined(LOSCFG_SOC_COMPANY_WINNERMICRO)) { + sources += [ "spi_wm.c" ] + } include_dirs = [ "." ] if (defined(LOSCFG_SHIELD_V200ZR_EVB_T1) && diff --git a/platform/spi/spi_wm.c b/platform/spi/spi_wm.c new file mode 100755 index 0000000..bd21e3b --- /dev/null +++ b/platform/spi/spi_wm.c @@ -0,0 +1,492 @@ +/* + * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "spi_wm.h" +#include +#include +#include "hdf_log.h" +#include "spi_core.h" +#include "device_resource_if.h" +#include "wm_gpio_afsel.h" + +#define SPI_DMA_MAX 4095 +#define MAX_SPI_NUMBER 1 +#define TIMEOUT 1000 + +static void SpiIomuxInit(struct SpiDevice *spiDevice) +{ + struct SpiResource *resource = NULL; + uint32_t spiPort; + HDF_LOGI("%s: Enter\r\n", __func__); + + if (spiDevice == NULL) { + HDF_LOGE("%s: invalid parameter\r\n", __func__); + return; + } + + resource = &spiDevice->resource; + if (resource == NULL) { + HDF_LOGE("resource is null\r\n"); + return HDF_ERR_INVALID_OBJECT; + } + + spiPort = spiDevice->spiId; + + if (resource->spiCsSoft) { + tls_gpio_cfg(WM_IO_PB_00 + resource->spiCsPin, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH); + } + wm_spi_cs_config(WM_IO_PB_04); + wm_spi_ck_config(WM_IO_PB_02); + wm_spi_di_config(WM_IO_PB_03); + wm_spi_do_config(WM_IO_PB_05); +} + +/** + * Spi send + * + * @param[in] spiId the spi bus id + * @param[in] data spi send data + * @param[in] size spi send data size + * @param[in] timeOut timeOut in milisecond, set this value to HAL_WAIT_FOREVER + * if you want to wait forever + * + * @return 0 : on success, EIO : if the SPI device could not be initialised + */ +int32_t HalSpiSend(struct SpiDevice *spiDevice, const uint8_t *data, uint16_t size, uint32_t timeOut) +{ + int32_t ret = 0; + uint32_t spiId; + uint32_t len = size; + struct SpiResource *resource = NULL; + int32_t status = HDF_FAILURE; + + if (spiDevice == NULL || data == NULL || size == 0) { + HDF_LOGE("spi input para err\r\n"); + return HDF_ERR_INVALID_PARAM; + } + + spiId = spiDevice->spiId; + resource = &spiDevice->resource; + if (resource == NULL) { + HDF_LOGE("resource is null\r\n"); + return HDF_ERR_INVALID_OBJECT; + } + status = OsalMutexLock(&spiDevice->mutex); + if (HDF_SUCCESS != status) { + HDF_LOGE("%s spi_mutex wait error = 0x%X!\r\n", __func__, status); + return HDF_ERR_TIMEOUT; + } + ret = tls_spi_write(data, (uint32_t)size); + if (ret) { + HDF_LOGE("spi tail send fail %ld, size %ld\r\n", ret, len); + } + OsalMutexUnlock(&spiDevice->mutex); + return ret; +} + +/** + * SpiRecv + * + * @param[in] spiId the spi bus id + * @param[out] data spi recv data + * @param[in] size spi recv data size + * @param[in] timeOut timeOut in milisecond, set this value to HAL_WAIT_FOREVER + * if you want to wait forever + * + * @return 0 : on success, EIO : if the SPI device could not be initialised + */ +int32_t HalSpiRecv(struct SpiDevice *spiDevice, uint8_t *data, uint16_t size, uint32_t timeOut) +{ + int32_t ret = 0; + uint32_t len = size; + uint32_t remainder = 0; + int32_t status = HDF_FAILURE; + uint8_t *cmd = NULL; + uint32_t spiId; + struct SpiResource *resource = NULL; + if (spiDevice == NULL || data == NULL || size == 0) { + HDF_LOGE("spi input para err\r\n"); + return HDF_ERR_INVALID_PARAM; + } + + spiId = spiDevice->spiId; + resource = &spiDevice->resource; + if (resource == NULL) { + HDF_LOGE("resource is null\r\n"); + return HDF_ERR_INVALID_OBJECT; + } + cmd = (uint8_t *)OsalMemAlloc(len); + if (cmd == NULL) { + HDF_LOGE("%s OsalMemAlloc size %ld error\r\n", __FUNCTION__, len); + return HDF_ERR_MALLOC_FAIL; + } + + memset_s(cmd, len, 0, len); + + status = OsalMutexLock(&spiDevice->mutex); + if (HDF_SUCCESS != status) { + HDF_LOGE("%s spi_mutex wait error = 0x%X!\r\n", __func__, status); + OsalMemFree(cmd); + return HDF_ERR_TIMEOUT; + } + remainder = len <= SPI_DMA_MAX ? len : SPI_DMA_MAX; + + ret = tls_spi_read(data, remainder); + + len -= remainder; + data += remainder; + + if (ret) { + HDF_LOGE("spi tail fail %ld, size %ld\r\n", ret, len); + } + OsalMutexUnlock(&spiDevice->mutex); + OsalMemFree(cmd); + return ret; +} + +int32_t HalSpiSendRecv(struct SpiDevice *spiDevice, uint8_t *txData, uint16_t txSize, uint8_t *rxData, + uint16_t rxSize) +{ + int32_t ret; + int32_t status; + uint32_t spiId; + struct SpiResource *resource = NULL; + if (spiDevice == NULL || txData == NULL || txSize == 0 || rxData == NULL || rxSize == 0) { + HDF_LOGE("spi input para err\r\n"); + return HDF_ERR_INVALID_PARAM; + } + spiId = spiDevice->spiId; + resource = &spiDevice->resource; + status = OsalMutexLock(&spiDevice->mutex); + if (HDF_SUCCESS != status) { + HDF_LOGE("%s spi_mutex wait error = 0x%X!\r\n", __func__, status); + return HDF_ERR_TIMEOUT; + } + ret = tls_spi_xfer(txData, rxData, txSize, rxSize); + if (ret) { + HDF_LOGE("spi dma tail fail %d\r\n", ret); + } + OsalMutexUnlock(&spiDevice->mutex); + return ret; +} + +static int32_t InitSpiDevice(struct SpiDevice *spiDevice) +{ + uint32_t spiPort; + struct SpiResource *resource = NULL; + if (spiDevice == NULL) { + HDF_LOGE("%s: invalid parameter\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + resource = &spiDevice->resource; + spiPort = spiDevice->spiId; + + SpiIomuxInit(spiDevice); + + if (spiDevice->mutex.realMutex == NULL) { + if (OsalMutexInit(&spiDevice->mutex) != HDF_SUCCESS) { + HDF_LOGE("spi Mutex create failed!\r\n"); + return HDF_FAILURE; + } + } + tls_spi_init(); + return HDF_SUCCESS; +} + +/* get spi config from hcs file */ +static int32_t GetSpiDeviceResource(struct SpiDevice *spiDevice, const struct DeviceResourceNode *resourceNode) +{ + uint32_t relPin; + struct SpiResource *resource = NULL; + struct DeviceResourceIface *dri = NULL; + if (spiDevice == NULL || resourceNode == NULL) { + HDF_LOGE("%s: PARAM is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + resource = &spiDevice->resource; + if (resource == NULL) { + HDF_LOGE("%s: resource is NULL\r\n", __func__); + return HDF_ERR_INVALID_OBJECT; + } + dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); // open HDF + if (dri == NULL || dri->GetUint32 == NULL) { + HDF_LOGE("DeviceResourceIface is invalid\r\n"); + return HDF_ERR_INVALID_PARAM; + } + + if (dri->GetUint32(resourceNode, "num", &resource->num, 0) != HDF_SUCCESS) { + HDF_LOGE("spi config read num fail\r\n"); + return HDF_FAILURE; + } + spiDevice->spiId = resource->num; + + if (dri->GetUint32(resourceNode, "speed", &resource->speed, 0) != HDF_SUCCESS) { + HDF_LOGE("spi config read base fail\r\n"); + return HDF_FAILURE; + } + + if (dri->GetUint32(resourceNode, "transmode", &resource->transmode, 0) != HDF_SUCCESS) { + HDF_LOGE("spi config read transmode fail\r\n"); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +int32_t AttachSpiDevice(struct SpiCntlr *spiCntlr, struct HdfDeviceObject *device) +{ + int32_t ret; + struct SpiDevice *spiDevice = NULL; + + if (spiCntlr == NULL || device == NULL || device->property == NULL) { + HDF_LOGE("%s: property is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + spiDevice = (struct SpiDevice *)OsalMemAlloc(sizeof(struct SpiDevice)); + if (spiDevice == NULL) { + HDF_LOGE("%s: OsalMemAlloc spiDevice error\r\n", __func__); + return HDF_ERR_MALLOC_FAIL; + } + spiDevice->mutex.realMutex = NULL; + + ret = GetSpiDeviceResource(spiDevice, device->property); + if (ret != HDF_SUCCESS) { + (void)OsalMemFree(spiDevice); + return HDF_FAILURE; + } + + spiCntlr->priv = spiDevice; + spiCntlr->busNum = spiDevice->spiId; + return InitSpiDevice(spiDevice); +} +/* SPI Method */ +static int32_t SpiDevGetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg); +static int32_t SpiDevSetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg); +static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg, uint32_t count); +static int32_t SpiDevOpen(struct SpiCntlr *spiCntlr); +static int32_t SpiDevClose(struct SpiCntlr *spiCntlr); + +struct SpiCntlrMethod g_SpiCntlrMethod = { + .GetCfg = SpiDevGetCfg, + .SetCfg = SpiDevSetCfg, + .Transfer = SpiDevTransfer, + .Open = SpiDevOpen, + .Close = SpiDevClose, +}; + +/* HdfDriverEntry method definitions */ +static int32_t SpiDriverBind(struct HdfDeviceObject *device); +static int32_t SpiDriverInit(struct HdfDeviceObject *device); +static void SpiDriverRelease(struct HdfDeviceObject *device); + +/* HdfDriverEntry definitions */ +struct HdfDriverEntry g_SpiDriverEntry = { + .moduleVersion = 1, + .moduleName = "W800_SPI_MODULE_HDF", + .Bind = SpiDriverBind, + .Init = SpiDriverInit, + .Release = SpiDriverRelease, +}; + +HDF_INIT(g_SpiDriverEntry); + +static int32_t SpiDriverBind(struct HdfDeviceObject *device) +{ + struct SpiCntlr *spiCntlr = NULL; + if (device == NULL) { + HDF_LOGE("Sample device object is null!\r\n"); + return HDF_ERR_INVALID_PARAM; + } + HDF_LOGI("Enter %s:\r\n", __func__); + spiCntlr = (struct SpiCntlr *)OsalMemAlloc(sizeof(struct SpiCntlr)); + if (spiCntlr == NULL) { + HDF_LOGE("%s: host is NULL\r\n", __func__); + return HDF_FAILURE; + } + device->service = &spiCntlr->service; + spiCntlr->device = device; + spiCntlr->priv = NULL; + return HDF_SUCCESS; +} + +static int32_t SpiDriverInit(struct HdfDeviceObject *device) +{ + int32_t ret; + struct SpiCntlr *spiCntlr = NULL; + + if (device == NULL) { + HDF_LOGE("%s: device is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + HDF_LOGI("Enter %s:", __func__); + spiCntlr = SpiCntlrFromDevice(device); + if (spiCntlr == NULL) { + HDF_LOGE("%s: spiCntlr is NULL", __func__); + return HDF_DEV_ERR_NO_DEVICE; + } + + ret = AttachSpiDevice(spiCntlr, device); // SpiCntlr add SpiDevice to priv + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: attach error\r\n", __func__); + return HDF_DEV_ERR_ATTACHDEV_FAIL; + } + + spiCntlr->method = &g_SpiCntlrMethod; // register callback + + return ret; +} + +static void SpiDriverRelease(struct HdfDeviceObject *device) +{ + struct SpiCntlr *spiCntlr = NULL; + struct SpiDevice *spiDevice = NULL; + + HDF_LOGI("Enter %s\r\n", __func__); + + if (device == NULL) { + HDF_LOGE("%s: device is NULL\r\n", __func__); + return; + } + + spiCntlr = SpiCntlrFromDevice(device); + if (spiCntlr == NULL || spiCntlr->priv == NULL) { + HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__); + return; + } + + spiDevice = (struct SpiDevice *)spiCntlr->priv; + if (spiDevice != NULL) { + OsalMemFree(spiDevice); + } + return; +} + +static int32_t SpiDevOpen(struct SpiCntlr *spiCntlr) +{ + HDF_LOGI("Enter %s\r\n", __func__); + int ret; + struct SpiDevice *spiDevice = NULL; + struct SpiResource *resource = NULL; + if (spiCntlr == NULL || spiCntlr->priv == NULL) { + HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + spiDevice = (struct SpiDevice *)spiCntlr->priv; + if (spiDevice == NULL) { + HDF_LOGE("spi device is NULL\r\n"); + return HDF_DEV_ERR_NO_DEVICE; + } + resource = &spiDevice->resource; + + if (resource->transmode == SPI_DMA_TRANSFER) { + tls_spi_trans_type(SPI_USE_DMA_TRANSFER); + } + if (resource->dataSize == SPI_MASTER_FIFO_SIZE) { + tls_spi_trans_type(SPI_WORD_TRANSFER); + } + tls_spi_setup(resource->mode, TLS_SPI_CS_LOW, resource->speed); + return HDF_SUCCESS; +} + +static int32_t SpiDevClose(struct SpiCntlr *spiCntlr) +{ + int ret; + struct SpiDevice *spiDevice = NULL; + if (spiCntlr == NULL || spiCntlr->priv == NULL) { + HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + spiDevice = (struct SpiDevice *)spiCntlr->priv; + if (spiDevice == NULL) { + HDF_LOGE("spi device is NULL\r\n"); + return HDF_DEV_ERR_NO_DEVICE; + } + return HDF_SUCCESS; +} + +static int32_t SpiDevGetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg) +{ + struct SpiDevice *spiDevice = NULL; + if (spiCntlr == NULL || spiCfg == NULL || spiCntlr->priv == NULL) { + HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + spiDevice = (struct SpiDevice *)spiCntlr->priv; + if (spiDevice == NULL) { + return HDF_DEV_ERR_NO_DEVICE; + } + spiCfg->maxSpeedHz = spiDevice->resource.speed; + spiCfg->mode = spiDevice->resource.mode; + spiCfg->transferMode = spiDevice->resource.transmode; + spiCfg->bitsPerWord = spiDevice->resource.dataSize; + + return HDF_SUCCESS; +} +static int32_t SpiDevSetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg) +{ + struct SpiDevice *spiDevice = NULL; + if (spiCntlr == NULL || spiCfg == NULL || spiCntlr->priv == NULL) { + HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + spiDevice = (struct SpiDevice *)spiCntlr->priv; + if (spiDevice == NULL) { + return HDF_DEV_ERR_NO_DEVICE; + } + spiDevice->resource.speed = spiCfg->maxSpeedHz; + spiDevice->resource.mode = spiCfg->mode; + spiDevice->resource.transmode = spiCfg->transferMode; + spiDevice->resource.dataSize = spiCfg->bitsPerWord; + return SpiDevOpen(spiCntlr); +} + +static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg, uint32_t count) +{ + uint32_t spiId; + struct SpiDevice *spiDevice = NULL; + struct SpiMsg *msg = NULL; + if (spiCntlr == NULL || spiCntlr->priv == NULL) { + HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + HDF_LOGI("%s: %u Enter\r\n", __func__, spiId); + spiDevice = (struct SpiDevice *)spiCntlr->priv; + spiId = spiDevice->spiId; + for (size_t i = 0; i < count; i++) { + msg = &spiMsg[i]; + /* pull down cs at first */ + if (spiDevice->resource.spiCsSoft) { + tls_gpio_write(WM_IO_PB_00 + spiDevice->resource.spiCsPin, 0); + } + + if ((msg->wbuf != NULL) && (msg->rbuf == NULL)) { + HalSpiSend(spiDevice, msg->wbuf, msg->len, TIMEOUT); + } + if ((msg->rbuf != NULL) && (msg->wbuf == NULL)) { + HalSpiRecv(spiDevice, msg->rbuf, msg->len, TIMEOUT); + } + if ((msg->wbuf != NULL) && (msg->rbuf != NULL)) { + HalSpiSendRecv(spiDevice, msg->wbuf, msg->len, msg->rbuf, msg->len); + } + + /* pull pull up cs at the end */ + if (msg->csChange && spiDevice->resource.spiCsSoft) { + tls_gpio_write(WM_IO_PB_00 + spiDevice->resource.spiCsPin, 1); + } + } + return HDF_SUCCESS; +} \ No newline at end of file diff --git a/platform/spi/spi_wm.h b/platform/spi/spi_wm.h new file mode 100755 index 0000000..2f424dd --- /dev/null +++ b/platform/spi/spi_wm.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef SPI_WINNERMICRO_H +#define SPI_WINNERMICRO_H + +#include "osal_mutex.h" +#include "osal_sem.h" +#include "wm_hostspi.h" +#include "spi_if.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct SpiResource { + uint32_t num; + uint32_t speed; + enum SpiTransferMode transmode; + uint32_t mode; // TLS_SPI_MODE_x + uint32_t dataSize; + uint32_t spiCsSoft; + uint32_t spiClkPin; + uint32_t spiMosiPin; + uint32_t spiMisoPin; + uint32_t spiCsPin; +}; + +struct SpiDevice { + uint32_t spiId; + struct SpiResource resource; + struct OsalMutex mutex; +}; + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/platform/uart/BUILD.gn b/platform/uart/BUILD.gn index 9a3845c..c7b566a 100644 --- a/platform/uart/BUILD.gn +++ b/platform/uart/BUILD.gn @@ -19,6 +19,9 @@ hdf_driver(module_name) { if (defined(LOSCFG_SOC_COMPANY_GOODIX)) { sources += [ "uart_gr5xx.c" ] } + if (defined(LOSCFG_SOC_COMPANY_WINNERMICRO)) { + sources += [ "uart_wm.c" ] + } include_dirs = [ "." ] } diff --git a/platform/uart/uart_wm.c b/platform/uart/uart_wm.c new file mode 100755 index 0000000..52fad38 --- /dev/null +++ b/platform/uart/uart_wm.c @@ -0,0 +1,673 @@ +/* + * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "uart_wm.h" +#include +#include +#include "osal_time.h" +#include "device_resource_if.h" +#include "hdf_log.h" +#include "wm_gpio_afsel.h" + +#define HDF_UART_TMO 1000 +#define TMO_MS_UNIT_CONV (1000) +#define HDF_LOG_TAG uartDev + +#define UART_CHSIZE_5BIT 5 +#define UART_CHSIZE_6BIT 6 +#define UART_CHSIZE_7BIT 7 +#define UART_CHSIZE_8BIT 8 + +static struct UART_CTX_OBJ g_uartCtx[4] = {0}; +static unsigned char *g_uartKfifoBuffer[4] = {NULL, NULL, NULL, NULL}; + +static void HalSetUartIomux(int uartId) +{ + switch (uartId) { + case TLS_UART_0: + wm_uart0_tx_config(WM_IO_PB_19); + wm_uart0_rx_config(WM_IO_PB_20); + break; + case TLS_UART_1: + wm_uart1_tx_config(WM_IO_PB_06); + wm_uart1_rx_config(WM_IO_PB_07); + break; + case TLS_UART_2: + wm_uart2_tx_scio_config(WM_IO_PB_02); + wm_uart2_rx_config(WM_IO_PB_03); + break; + case TLS_UART_3: + wm_uart3_tx_config(WM_IO_PB_00); + wm_uart3_rx_config(WM_IO_PB_01); + break; + case TLS_UART_4: + wm_uart4_tx_config(WM_IO_PB_04); + wm_uart4_rx_config(WM_IO_PB_05); + break; + default: + HDF_LOGE("%s: uartId(%d) invalid", __func__, uartId); + break; + } +} + +static void dma_tx_cmpl_callback(uint32_t arg) +{ + uint32_t uartId = arg; + OsalSemPost(&g_uartCtx[uartId].txSem); +} + +static int32_t HalUartSend(uint32_t uartId, const uint8_t *data, uint32_t size, uint32_t timeOut) +{ + int32_t ret = HDF_FAILURE; + + if (data == NULL || size == 0) { + HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__); + return HDF_ERR_INVALID_PARAM; + } + + tls_uart_dma_write(data, (uint16_t)size, dma_tx_cmpl_callback, (uint16_t)uartId); + ret = OsalSemWait(&g_uartCtx[uartId].txSem, timeOut); + + return ret; +} + +static int32_t HalUartRecv(uint8_t uartId, uint8_t *data, uint32_t expectSize, + uint32_t *recvSize, uint32_t timeOut) +{ + int32_t ret = HDF_FAILURE; + uint32_t fifoPopLen = 0; + uint32_t recvedLen = 0; + uint32_t expectLen = expectSize; + OsalTimespec hdfTs1 = { 0, 0 }; + OsalTimespec hdfTs2 = { 0, 0 }; + OsalTimespec hdfTsDiff = { 0, 0 }; + + if (data == NULL || expectSize == 0 || recvSize == NULL) { + HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__); + return HDF_ERR_INVALID_PARAM; + } + OsalGetTime(&hdfTs1); + do { + fifoPopLen = tls_uart_read(uartId, (uint8_t *)data + recvedLen, expectLen); + recvedLen += fifoPopLen; + expectLen -= fifoPopLen; + if (recvedLen >= expectSize) { + break; + } + /* haven't get any data from fifo */ + if (recvedLen == 0) { + break; + } + /* if reaches here, it means need to wait for more data come */ + OsalMSleep(1); + /* time out break */ + OsalGetTime(&hdfTs2); + OsalDiffTime(&hdfTs1, &hdfTs2, &hdfTsDiff); + if ((uint32_t)(hdfTsDiff.sec * TMO_MS_UNIT_CONV + hdfTsDiff.usec / TMO_MS_UNIT_CONV) >= timeOut) { + break; + } + } while (1); + + if (recvSize != NULL) { + *recvSize = recvedLen; + } + return HDF_SUCCESS; +} + +static void HalUartHandlerInit(struct UartDevice *device) +{ + uint32_t uartId; + + if (device == NULL) { + HDF_LOGE("%s: INVALID PARAM", __func__); + return; + } + + uartId = device->uartId; + OsalSemInit(&g_uartCtx[uartId].rxSem, 0); + OsalSemInit(&g_uartCtx[uartId].txSem, 0); +} + +static void UartStart(struct UartDevice *device) +{ + uint32_t uartId; + tls_uart_options_t *uartCfg = NULL; + if (device == NULL) { + HDF_LOGE("%s: INVALID PARAM", __func__); + return; + } + uartId = device->uartId; + uartCfg = &device->config; + if (uartCfg == NULL) { + HDF_LOGE("%s: INVALID OBJECT", __func__); + return; + } + if (WM_SUCCESS != tls_uart_port_init(uartId, uartCfg, 0)) { + HDF_LOGE("uart %d init error", uartId); + } + HDF_LOGI("%s %ld\r\n", __FUNCTION__, uartId); + HalUartHandlerInit(device); +} + +/* HdfDriverEntry method definitions */ +static int32_t UartDriverBind(struct HdfDeviceObject *device); +static int32_t UartDriverInit(struct HdfDeviceObject *device); +static void UartDriverRelease(struct HdfDeviceObject *device); + +/* HdfDriverEntry definitions */ +struct HdfDriverEntry g_UartDriverEntry = { + .moduleVersion = 1, + .moduleName = "W800_UART_MODULE_HDF", + .Bind = UartDriverBind, + .Init = UartDriverInit, + .Release = UartDriverRelease, +}; + +/* Initialize HdfDriverEntry */ +HDF_INIT(g_UartDriverEntry); + +/* UartHostMethod method definitions */ +static int32_t UartHostDevInit(struct UartHost *host); +static int32_t UartHostDevDeinit(struct UartHost *host); +static int32_t UartHostDevWrite(struct UartHost *host, uint8_t *data, uint32_t size); +static int32_t UartHostDevSetBaud(struct UartHost *host, uint32_t baudRate); +static int32_t UartHostDevGetBaud(struct UartHost *host, uint32_t *baudRate); +static int32_t UartHostDevRead(struct UartHost *host, uint8_t *data, uint32_t size); +static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribute *attribute); +static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribute *attribute); +static int32_t UartHostDevSetTransMode(struct UartHost *host, enum UartTransMode mode); + +/* UartHostMethod definitions */ +struct UartHostMethod g_uartHostMethod = { + .Init = UartHostDevInit, + .Deinit = UartHostDevDeinit, + .Read = UartHostDevRead, + .Write = UartHostDevWrite, + .SetBaud = UartHostDevSetBaud, + .GetBaud = UartHostDevGetBaud, + .SetAttribute = UartHostDevSetAttribute, + .GetAttribute = UartHostDevGetAttribute, + .SetTransMode = UartHostDevSetTransMode, +}; + +static int InitUartDevice(struct UartHost *host) +{ + HDF_LOGI("%s: Enter", __func__); + struct UartDevice *uartDevice = NULL; + + if (host == NULL || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + uartDevice = (struct UartDevice *)host->priv; + if (uartDevice == NULL) { + HDF_LOGE("%s: INVALID OBJECT", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + if (!uartDevice->initFlag) { + HDF_LOGI("uart %ld device init", uartDevice->uartId); + HalSetUartIomux(uartDevice->uartId); + UartStart(uartDevice); + uartDevice->initFlag = true; + } + + return HDF_SUCCESS; +} + +static uint32_t GetUartDeviceResource(struct UartDevice *device, const struct DeviceResourceNode *resourceNode) +{ + struct DeviceResourceIface *dri = NULL; + struct UartResource *resource = NULL; + if (device == NULL || resourceNode == NULL) { + HDF_LOGE("%s: INVALID PARAM", __func__); + return HDF_ERR_INVALID_PARAM; + } + resource = &device->resource; + if (resource == NULL) { + HDF_LOGE("%s: INVALID OBJECT", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (dri == NULL || dri->GetUint32 == NULL) { + HDF_LOGE("DeviceResourceIface is invalid"); + return HDF_ERR_INVALID_PARAM; + } + if (dri->GetUint32(resourceNode, "num", &resource->num, 0) != HDF_SUCCESS) { + HDF_LOGE("uart config read num fail"); + return HDF_FAILURE; + } + if (dri->GetUint32(resourceNode, "baudrate", &resource->baudRate, 0) != HDF_SUCCESS) { + HDF_LOGE("uart config read baudrate fail"); + return HDF_FAILURE; + } + if (dri->GetUint32(resourceNode, "parity", &resource->parity, 0) != HDF_SUCCESS) { + HDF_LOGE("uart config read parity fail"); + return HDF_FAILURE; + } + if (dri->GetUint32(resourceNode, "stopBit", &resource->stopBit, 0) != HDF_SUCCESS) { + HDF_LOGE("uart config read stopBit fail"); + return HDF_FAILURE; + } + + HDF_LOGI("%d, %d, %d, %d", resource->num, resource->baudRate, resource->parity); + + // copy config + device->uartId = resource->num; + device->config.baudrate = resource->baudRate; + device->config.paritytype = (TLS_UART_PMODE_T)resource->parity; + device->config.stopbits = (TLS_UART_STOPBITS_T)resource->stopBit; + device->config.charlength = TLS_UART_CHSIZE_8BIT; + device->config.flow_ctrl = TLS_UART_FLOW_CTRL_NONE; + return HDF_SUCCESS; +} + +static int32_t AttachUartDevice(struct UartHost *uartHost, struct HdfDeviceObject *device) +{ + int32_t ret; + struct UartDevice *uartDevice = NULL; + + if (uartHost == NULL || device == NULL || device->property == NULL) { + HDF_LOGE("%s: property is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + + uartDevice = (struct UartDevice *)OsalMemAlloc(sizeof(struct UartDevice)); + if (uartDevice == NULL) { + HDF_LOGE("%s: OsalMemCalloc uartDevice error", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + ret = GetUartDeviceResource(uartDevice, device->property); + if (ret != HDF_SUCCESS) { + (void)OsalMemFree(uartDevice); + return HDF_FAILURE; + } + + uartHost->priv = uartDevice; + + return InitUartDevice(uartHost); +} + +static int32_t UartDriverBind(struct HdfDeviceObject *device) +{ + struct UartHost *devService; + if (device == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + devService = (struct UartHost *)OsalMemAlloc(sizeof(*devService)); + if (devService == NULL) { + HDF_LOGE("%s: OsalMemCalloc error", __func__); + return HDF_ERR_INVALID_OBJECT; + } + devService->device = device; + device->service = &(devService->service); + devService->priv = NULL; + devService->method = NULL; + return HDF_SUCCESS; +} + +static void UartDriverRelease(struct HdfDeviceObject *device) +{ + HDF_LOGI("Enter %s:", __func__); + uint32_t uartId; + struct UartHost *host = NULL; + struct UartDevice *uartDevice = NULL; + if (device == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return; + } + + host = UartHostFromDevice(device); + if (host == NULL || host->priv == NULL) { + HDF_LOGE("%s: host is NULL", __func__); + return; + } + + uartDevice = (struct UartDevice *)host->priv; + if (uartDevice == NULL) { + HDF_LOGE("%s: INVALID OBJECT", __func__); + return; + } + uartId = uartDevice->uartId; + host->method = NULL; + + OsalSemDestroy(&g_uartCtx[uartId].rxSem); + OsalSemDestroy(&g_uartCtx[uartId].txSem); + OsalMemFree(uartDevice); + OsalMemFree(host); +} + +static int32_t UartDriverInit(struct HdfDeviceObject *device) +{ + HDF_LOGI("Enter %s:", __func__); + int32_t ret; + struct UartHost *host = NULL; + + if (device == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + host = UartHostFromDevice(device); + if (host == NULL) { + HDF_LOGE("%s: host is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + ret = AttachUartDevice(host, device); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: attach error", __func__); + return HDF_FAILURE; + } + + host->method = &g_uartHostMethod; + + return ret; +} + +/* UartHostMethod implementations */ +static int32_t UartHostDevInit(struct UartHost *host) +{ + HDF_LOGI("%s: Enter\r\n", __func__); + if (host == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + InitUartDevice(host); + return HDF_SUCCESS; +} + +static int32_t UartHostDevDeinit(struct UartHost *host) +{ + HDF_LOGI("%s: Enter", __func__); + uint32_t uartId; + struct UartDevice *uartDevice = NULL; + if (host == NULL || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + uartDevice = (struct UartDevice *)host->priv; + if (uartDevice == NULL) { + HDF_LOGE("%s: INVALID OBJECT", __func__); + return HDF_ERR_INVALID_OBJECT; + } + uartId = uartDevice->uartId; + uartDevice->initFlag = false; + + return HDF_SUCCESS; +} +static int32_t UartHostDevWrite(struct UartHost *host, uint8_t *data, uint32_t size) +{ + struct UartDevice *device = NULL; + uint32_t portId; + + if (host == NULL || data == NULL || size == 0 || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + device = (struct UartDevice *)host->priv; + if (device == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + portId = device->uartId; + + if (g_uartCtx[portId].txDMA) { + return HalUartSend(portId, data, size, HDF_UART_TMO); + } else { + if (tls_uart_write(portId, data, size) < 0) { + return HDF_FAILURE; + } + } + + return HDF_SUCCESS; +} + +static int32_t UartHostDevRead(struct UartHost *host, uint8_t *data, uint32_t size) +{ + uint32_t recvSize = 0; + int32_t ret; + uint32_t uartId; + struct UartDevice *uartDevice = NULL; + if (host == NULL || data == NULL || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + uartDevice = (struct UartDevice *)host->priv; + if (uartDevice == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + uartId = uartDevice->uartId; + if (g_uartCtx[uartId].rxDMA) { + ret = HalUartRecv(uartId, data, size, &recvSize, HDF_UART_TMO); + if (ret != HDF_SUCCESS) { + HDF_LOGE("uart %ld recev error\r\n", uartId); + return ret; + } + ret = recvSize; + } else { + if (g_uartCtx[uartId].isBlock) { + while (tls_uart_try_read(uartId, 1) == 0); + ret = tls_uart_read(uartId, data, 1); + } else { + ret = tls_uart_read(uartId, data, 1); + } + ret = 1; + } + return ret; +} + +static int32_t UartHostDevSetBaud(struct UartHost *host, uint32_t baudRate) +{ + HDF_LOGI("%s: Enter", __func__); + struct UartDevice *uartDevice = NULL; + tls_uart_options_t *uartCfg = NULL; + uint32_t uartId; + if (host == NULL || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + uartDevice = (struct UartDevice *)host->priv; + if (uartDevice == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + uartId = uartDevice->uartId; + + uartCfg = &uartDevice->config; + if (uartCfg == NULL) { + HDF_LOGE("%s: device config is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + uartCfg->baudrate = baudRate; + + tls_uart_set_baud_rate(uartId, uartCfg->baudrate); + + return HDF_SUCCESS; +} + +static int32_t UartHostDevGetBaud(struct UartHost *host, uint32_t *baudRate) +{ + HDF_LOGI("%s: Enter", __func__); + struct UartDevice *uartDevice = NULL; + tls_uart_options_t *uartCfg = NULL; + uint32_t uartId; + if (host == NULL || baudRate == NULL || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + uartDevice = (struct UartDevice *)host->priv; + if (uartDevice == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + uartId = uartDevice->uartId; + + uartCfg = &uartDevice->config; + if (uartCfg == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + *baudRate = uartCfg->baudrate; + return HDF_SUCCESS; +} + +static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribute *attribute) +{ + struct UartDevice *uartDevice = NULL; + tls_uart_options_t *uartCfg = NULL; + uint32_t uartId; + if (host == NULL || attribute == NULL || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + uartDevice = (struct UartDevice *)host->priv; + if (uartDevice == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + uartId = uartDevice->uartId; + uartCfg = &uartDevice->config; + if (uartCfg == NULL) { + HDF_LOGE("%s: config is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + uartCfg->paritytype = attribute->parity; + tls_uart_set_parity(uartId, uartCfg->paritytype); + + switch (attribute->stopBits) { + case UART_ATTR_STOPBIT_1: + uartCfg->stopbits = TLS_UART_ONE_STOPBITS; + break; + case UART_ATTR_STOPBIT_2: + uartCfg->stopbits = TLS_UART_TWO_STOPBITS; + break; + default: + uartCfg->stopbits = TLS_UART_ONE_STOPBITS; + break; + } + tls_uart_set_stop_bits(uartId, uartCfg->stopbits); + + if (attribute->rts && attribute->cts) { + uartCfg->flow_ctrl = TLS_UART_FLOW_CTRL_HARDWARE; + } else { + uartCfg->flow_ctrl = TLS_UART_FLOW_CTRL_NONE; + } + tls_uart_set_fc_status(uartId, uartCfg->flow_ctrl); + return HDF_SUCCESS; +} + +static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribute *attribute) +{ + HDF_LOGI("%s: Enter", __func__); + struct UartDevice *uartDevice = NULL; + tls_uart_options_t *uartCfg = NULL; + if (host == NULL || attribute == NULL || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + uartDevice = (struct UartDevice *)host->priv; + if (uartDevice == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + uartCfg = &uartDevice->config; + if (uartCfg == NULL) { + HDF_LOGE("%s: config is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + attribute->parity = uartCfg->paritytype; + + switch (uartCfg->stopbits) { + case TLS_UART_ONE_STOPBITS: + attribute->stopBits = UART_ATTR_STOPBIT_1; + break; + case TLS_UART_TWO_STOPBITS: + attribute->stopBits = UART_ATTR_STOPBIT_2; + break; + default: + attribute->stopBits = UART_ATTR_STOPBIT_1; + break; + } + + switch (uartCfg->flow_ctrl) { + case TLS_UART_FLOW_CTRL_HARDWARE: + attribute->rts = 1; + attribute->cts = 1; + break; + default: + attribute->rts = 0; + attribute->cts = 0; + break; + } + + return HDF_SUCCESS; +} + +static int32_t UartHostDevSetTransMode(struct UartHost *host, enum UartTransMode mode) +{ + HDF_LOGI("%s: Enter", __func__); + struct UartDevice *uartDevice = NULL; + uint32_t uartId; + if (host == NULL || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + uartDevice = (struct UartDevice *)host->priv; + if (uartDevice == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + uartId = uartDevice->uartId; + + switch (mode) { + case UART_MODE_RD_BLOCK: + g_uartCtx[uartId].isBlock = true; + break; + case UART_MODE_RD_NONBLOCK: + g_uartCtx[uartId].isBlock = false; + break; + case UART_MODE_DMA_RX_EN: + g_uartCtx[uartId].rxDMA = true; + break; + case UART_MODE_DMA_RX_DIS: + g_uartCtx[uartId].rxDMA = false; + break; + case UART_MODE_DMA_TX_EN: + g_uartCtx[uartId].txDMA = true; + break; + case UART_MODE_DMA_TX_DIS: + g_uartCtx[uartId].txDMA = false; + break; + default: + HDF_LOGE("%s: UartTransMode(%d) invalid", __func__, mode); + break; + } + return HDF_SUCCESS; +} diff --git a/platform/uart/uart_wm.h b/platform/uart/uart_wm.h new file mode 100755 index 0000000..2823db2 --- /dev/null +++ b/platform/uart/uart_wm.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef UART_WINNERMICRO_H +#define UART_WINNERMICRO_H + +#include "uart_if.h" +#include "uart_core.h" +#include "osal_sem.h" +#include "wm_uart.h" +#ifdef __cplusplus +extern "C" { +#endif + +#define UART_DEV_SERVICE_NAME_PREFIX "HDF_PLATFORM_UART%d" +#define MAX_DEV_NAME_SIZE 32 + +struct UartResource { + uint32_t num; /* UART port num */ + uint32_t baudRate; /* Default baudrate */ + uint32_t wLen; /* Default word length */ + uint32_t parity; /* Default parity */ + uint32_t stopBit; /* Default stop bits */ + bool txDMA; + bool rxDMA; +}; + +enum UartDeviceState { + UART_DEVICE_UNINITIALIZED = 0x0u, + UART_DEVICE_INITIALIZED = 0x1u, +}; + +struct UART_CTX_OBJ { + bool txDMA; + bool rxDMA; + bool isBlock; + struct OsalSem rxSem; + struct OsalSem txSem; +}; + +struct UartDevice { + struct IDeviceIoService ioService; + struct UartResource resource; + tls_uart_options_t config; + uint32_t uartId; + bool initFlag; + uint32_t transMode; +}; + +enum { + UART_READ = 0, + UART_WRITE +}; + +int32_t UartDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/platform/watchdog/BUILD.gn b/platform/watchdog/BUILD.gn index f03a7bf..9f2fc02 100644 --- a/platform/watchdog/BUILD.gn +++ b/platform/watchdog/BUILD.gn @@ -21,5 +21,9 @@ hdf_driver(module_name) { sources += [ "watchdog_stm32f4xx.c" ] } + if (defined(LOSCFG_SOC_COMPANY_WINNERMICRO)) { + sources += [ "watchdog_wm.c" ] + } + include_dirs = [ "." ] } diff --git a/platform/watchdog/watchdog_wm.c b/platform/watchdog/watchdog_wm.c new file mode 100755 index 0000000..c90a4a2 --- /dev/null +++ b/platform/watchdog/watchdog_wm.c @@ -0,0 +1,258 @@ +/* + * Copyright (C) 2022 HiHope Open Source Organization . + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "watchdog_wm.h" +#include +#include +#include "device_resource_if.h" +#include "hdf_device_desc.h" +#include "hdf_log.h" +#include "watchdog_if.h" +#include "wm_regs.h" +#include "wm_cpu.h" + +static int g_watchdogStart; +static int g_watchdogTimeout; + +static int32_t WatchdogDevStart(struct WatchdogCntlr *watchdogCntlr); +static int32_t WatchdogDevSetTimeout(struct WatchdogCntlr *watchdogCntlr, uint32_t seconds); +static int32_t WatchdogDevGetTimeout(struct WatchdogCntlr *watchdogCntlr, uint32_t *seconds); +static int32_t WatchdogDevGetStatus(struct WatchdogCntlr *watchdogCntlr, uint32_t *status); +static int32_t WatchdogDevFeed(struct WatchdogCntlr *watchdogCntlr); + +struct WatchdogMethod g_WatchdogCntlrMethod = { + .getStatus = WatchdogDevGetStatus, + .setTimeout = WatchdogDevSetTimeout, + .getTimeout = WatchdogDevGetTimeout, + .start = WatchdogDevStart, + .stop = NULL, // WatchdogDevStop + .feed = WatchdogDevFeed, + .getPriv = NULL, // WatchdogDevGetPriv + .releasePriv = NULL, // WatchdogDevReleasePriv +}; + + +static int32_t WatchdogDevStart(struct WatchdogCntlr *watchdogCntlr) +{ + tls_watchdog_start_cal_elapsed_time(); + g_watchdogStart = 1; + return HDF_SUCCESS; +} + +static int32_t WatchdogDevSetTimeout(struct WatchdogCntlr *watchdogCntlr, uint32_t seconds) +{ + g_watchdogTimeout = seconds; + tls_watchdog_init(seconds); + return HDF_SUCCESS; +} + +static int32_t WatchdogDevGetTimeout(struct WatchdogCntlr *watchdogCntlr, uint32_t *seconds) +{ + if (watchdogCntlr == NULL || seconds == NULL) { + HDF_LOGE("%s: PARAM is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + g_watchdogTimeout = tls_watchdog_stop_cal_elapsed_time(); + + *seconds = g_watchdogTimeout; + return HDF_SUCCESS; +} + +static int32_t WatchdogDevGetStatus(struct WatchdogCntlr *watchdogCntlr, uint32_t *status) +{ + if (watchdogCntlr == NULL || status == NULL) { + HDF_LOGE("%s: PARAM is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (g_watchdogStart == 1) { + *status = WATCHDOG_START; + } else { + *status = WATCHDOG_STOP; + } + return HDF_SUCCESS; +} + +static int32_t WatchdogDevFeed(struct WatchdogCntlr *watchdogCntlr) +{ + tls_sys_clk sysclk; + + tls_sys_clk_get(&sysclk); + if (g_watchdogStart == 1) { + tls_sys_reset(); + } + return HDF_SUCCESS; +} + +static int InitWatchdogDevice(struct WatchdogDevice *watchdogDevice) +{ + struct WatchdogResource *resource = NULL; + if (watchdogDevice == NULL) { + HDF_LOGE("%s: invaild parameter\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + resource = &watchdogDevice->resource; + if (resource == NULL) { + HDF_LOGE("resource is NULL\r\n"); + return HDF_ERR_INVALID_OBJECT; + } + + return HDF_SUCCESS; +} + +static uint32_t GetWatchdogDeviceResource( + struct WatchdogDevice *device, const struct DeviceResourceNode *resourceNode) +{ + struct WatchdogResource *resource = NULL; + struct DeviceResourceIface *dri = NULL; + if (device == NULL || resourceNode == NULL) { + HDF_LOGE("resource or device is NULL\r\n"); + return HDF_ERR_INVALID_PARAM; + } + + resource = &device->resource; + if (resource == NULL) { + HDF_LOGE("resource is NULL\r\n"); + return HDF_ERR_INVALID_OBJECT; + } + + dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (dri == NULL || dri->GetUint32 == NULL) { + HDF_LOGE("DeviceResourceIface is invalid\r\n"); + return HDF_ERR_INVALID_OBJECT; + } + + return HDF_SUCCESS; +} + +static int32_t AttachWatchdogDevice(struct WatchdogCntlr *watchdogCntlr, struct HdfDeviceObject *device) +{ + int32_t ret; + struct WatchdogDevice *watchdogDevice = NULL; + + if (device == NULL || device->property == NULL) { + HDF_LOGE("%s: param is NULL\r\n", __func__); + return HDF_FAILURE; + } + + watchdogDevice = (struct WatchdogDevice *)OsalMemAlloc(sizeof(struct WatchdogDevice)); + if (watchdogDevice == NULL) { + HDF_LOGE("%s: OsalMemAlloc watchdogDevice error\r\n", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + ret = GetWatchdogDeviceResource(watchdogDevice, device->property); + if (ret != HDF_SUCCESS) { + (void)OsalMemFree(watchdogDevice); + return HDF_FAILURE; + } + + watchdogCntlr->priv = watchdogDevice; + + return InitWatchdogDevice(watchdogDevice); +} + +/* HdfDriverEntry method definitions */ +static int32_t WatchdogDriverBind(struct HdfDeviceObject *device); +static int32_t WatchdogDriverInit(struct HdfDeviceObject *device); +static void WatchdogDriverRelease(struct HdfDeviceObject *device); + +static int32_t WatchdogDriverBind(struct HdfDeviceObject *device) +{ + struct WatchdogCntlr *watchdogCntlr = NULL; + + if (device == NULL) { + HDF_LOGE("hdfDevice object is null!\r\n"); + return HDF_FAILURE; + } + + watchdogCntlr = (struct WatchdogCntlr *)OsalMemAlloc(sizeof(struct WatchdogCntlr)); + if (watchdogCntlr == NULL) { + HDF_LOGE("%s: OsalMemAlloc watchdogCntlr error\r\n", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + HDF_LOGI("Enter %s\r\n", __func__); + device->service = &watchdogCntlr->service; + watchdogCntlr->device = device; + watchdogCntlr->priv = NULL; + return HDF_SUCCESS; +} + +static int32_t WatchdogDriverInit(struct HdfDeviceObject *device) +{ + int32_t ret; + struct WatchdogCntlr *watchdogCntlr = NULL; + + if (device == NULL) { + HDF_LOGE("%s: device is NULL\r\n", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + HDF_LOGI("Enter %s:\r\n", __func__); + + watchdogCntlr = WatchdogCntlrFromDevice(device); + if (watchdogCntlr == NULL) { + HDF_LOGE("%s: watchdogCntlr is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + ret = AttachWatchdogDevice(watchdogCntlr, device); + if (ret != HDF_SUCCESS) { + OsalMemFree(watchdogCntlr); + HDF_LOGE("%s:attach error\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + watchdogCntlr->ops = &g_WatchdogCntlrMethod; + + HDF_LOGE("WatchdogDriverInit success!\r\n"); + return ret; +} + +static void WatchdogDriverRelease(struct HdfDeviceObject *device) +{ + struct WatchdogCntlr *watchdogCntlr = NULL; + struct WatchdogDevice *watchdogDevice = NULL; + + if (device == NULL) { + HDF_LOGE("device is null\r\n"); + return; + } + + watchdogCntlr = WatchdogCntlrFromDevice(device); + if (watchdogCntlr == NULL || watchdogCntlr->priv == NULL) { + HDF_LOGE("%s: watchdogCntlr is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + watchdogDevice = (struct WatchdogDevice *)watchdogCntlr->priv; + if (watchdogDevice != NULL) { + OsalMemFree(watchdogDevice); + } + return; +} + +/* HdfDriverEntry definitions */ +struct HdfDriverEntry g_watchdogDriverEntry = { + .moduleVersion = 1, + .moduleName = "WM_WATCHDOG_MODULE_HDF", + .Bind = WatchdogDriverBind, + .Init = WatchdogDriverInit, + .Release = WatchdogDriverRelease, +}; + +// Initialize HdfDriverEntry +HDF_INIT(g_watchdogDriverEntry); \ No newline at end of file diff --git a/platform/watchdog/watchdog_wm.h b/platform/watchdog/watchdog_wm.h new file mode 100755 index 0000000..3a4e15e --- /dev/null +++ b/platform/watchdog/watchdog_wm.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2022 HiHope Open Source Organization . + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WDG_WINNERMICRO_H +#define WDG_WINNERMICRO_H + +#include "watchdog_core.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct WatchdogResource { + int32_t watchdogId; +}; + +struct WatchdogDevice { + struct WatchdogResource resource; +}; + +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file -- Gitee From 9879c7b0fef782a7ae2d6b210518f38d88add011 Mon Sep 17 00:00:00 2001 From: yue Date: Wed, 16 Mar 2022 20:27:02 +0800 Subject: [PATCH 022/102] fix:modify HDI-C compile Signed-off-by: yue --- uhdf2/hdi.gni | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/uhdf2/hdi.gni b/uhdf2/hdi.gni index d664368..5868103 100755 --- a/uhdf2/hdi.gni +++ b/uhdf2/hdi.gni @@ -180,7 +180,9 @@ template("hdi") { external_deps = [ "hilog:libhilog" ] } - if (invoker.language == "cpp") { + if (invoker.language == "c") { + deps += [ "$hdf_uhdf_path/host:libhdf_host" ] + } else if (invoker.language == "cpp") { external_deps += [ "ipc:ipc_single" ] } -- Gitee From 1d7cc05fb1ad4bd958e2f77f9f1ded7d85cecf52 Mon Sep 17 00:00:00 2001 From: bob_qu Date: Thu, 17 Mar 2022 17:54:00 +0800 Subject: [PATCH 023/102] fix:deleted .h file and update license. Signed-off-by: bob_qu --- platform/gpio/gpio_wm.c | 96 +++++++++++++++++++++++---------- platform/gpio/gpio_wm.h | 67 ----------------------- platform/i2c/i2c_wm.c | 35 +++++++----- platform/i2c/i2c_wm.h | 46 ---------------- platform/pwm/pwm_wm.c | 28 +++++----- platform/pwm/pwm_wm.h | 40 -------------- platform/spi/spi_wm.c | 40 +++++++++----- platform/spi/spi_wm.h | 50 ----------------- platform/uart/uart_wm.c | 63 ++++++++++++++++------ platform/uart/uart_wm.h | 72 ------------------------- platform/watchdog/watchdog_wm.c | 27 +++++----- platform/watchdog/watchdog_wm.h | 36 ------------- 12 files changed, 196 insertions(+), 404 deletions(-) delete mode 100755 platform/gpio/gpio_wm.h delete mode 100755 platform/i2c/i2c_wm.h delete mode 100755 platform/pwm/pwm_wm.h delete mode 100755 platform/spi/spi_wm.h delete mode 100755 platform/uart/uart_wm.h delete mode 100755 platform/watchdog/watchdog_wm.h diff --git a/platform/gpio/gpio_wm.c b/platform/gpio/gpio_wm.c index 7fe5f84..4161e74 100755 --- a/platform/gpio/gpio_wm.c +++ b/platform/gpio/gpio_wm.c @@ -1,20 +1,13 @@ /* - * Copyright (C) 2022 HiHope Open Source Organization . - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2022 Jiangsu Hoperun Software Co., Ltd. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * This file 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 "gpio_wm.h" #include +#include "gpio_core.h" #include "gpio_if.h" #include "device_resource_if.h" #include "osal_irq.h" @@ -22,9 +15,48 @@ #include "wm_io.h" #include "wm_gpio.h" +#define DECIMALNUM 10 +#define OCTALNUM 8 + #define HDF_LOG_TAG gpioDriver #define WM_IO_MAX_GPIO_PIN_NUM 48 +/* + * Pin configuration + */ +enum GPIO_CONFIG { + ANALOG_MODE, /* Used as a function pin, input and output analog */ + IRQ_MODE, /* Used to trigger interrupt */ + INPUT_PULL_UP, /* Input with an internal pull-up resistor - use with devices + that actively drive the signal low - e.g. button connected to ground */ + INPUT_PULL_DOWN, /* Input with an internal pull-down resistor - use with devices + that actively drive the signal high - e.g. button connected to a power rail */ + INPUT_HIGH_IMPEDANCE, /* Input - must always be driven, either actively or by an external pullup resistor */ + OUTPUT_PUSH_PULL, /* Output actively driven high and actively driven low - + must not be connected to other active outputs - e.g. LED output */ + OUTPUT_OPEN_DRAIN_NO_PULL, /* Output actively driven low but is high-impedance when set high - + can be connected to other open-drain/open-collector outputs. + Needs an external pull-up resistor */ + OUTPUT_OPEN_DRAIN_PULL_UP, /* Output actively driven low and is pulled high + with an internal resistor when set high - + can be connected to other open-drain/open-collector outputs. */ +}; + +struct GpioResource { + uint32_t groupNum; + uint32_t realPin; + uint32_t config; + uint32_t pinNum; +}; + +struct GpioDevice { + uint8_t port; /* gpio port */ + struct GpioResource resource; + enum GPIO_CONFIG config; /* gpio config */ +}; + +typedef void (* tls_gpio_pin_orq_handler)(enum tls_io_name pin); + static struct GpioCntlr gpioCntlr; struct wmGpioIrqHandler { uint8_t port; @@ -43,7 +75,7 @@ GpioIrqFunc GpioIrqHdl() ret = tls_get_gpio_irq_status(g_wmGpioIrqHandler[i].port); if ((enum tls_io_name)g_gpioPinReflectionMap[i] && (ret != 0)) { GpioCntlrIrqCallback(&gpioCntlr, i); - return; + return HDF_SUCCESS; } } } @@ -58,6 +90,29 @@ int32_t GpioDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf return HDF_SUCCESS; } +/* GpioMethod method definitions */ +static int32_t GpioDevWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val); +static int32_t GpioDevRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val); +static int32_t GpioDevSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t dir); +static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mode); +static int32_t GpioDevUnSetIrq(struct GpioCntlr *cntlr, uint16_t gpio); +static int32_t GpioDevEnableIrq(struct GpioCntlr *cntlr, uint16_t gpio); +static int32_t GpioDevDisableIrq(struct GpioCntlr *cntlr, uint16_t gpio); +/* GpioMethod definitions */ +struct GpioMethod g_GpioCntlrMethod = { + .request = NULL, + .release = NULL, + .write = GpioDevWrite, + .read = GpioDevRead, + .setDir = GpioDevSetDir, + .getDir = NULL, + .toIrq = NULL, + .setIrq = GpioDevSetIrq, + .unsetIrq = GpioDevUnSetIrq, + .enableIrq = GpioDevEnableIrq, + .disableIrq = GpioDevDisableIrq, +}; + /* dev api */ static int32_t GpioDevWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val) { @@ -178,21 +233,6 @@ static int32_t GpioDevDisableIrq(struct GpioCntlr *cntlr, uint16_t gpio) return HDF_SUCCESS; } -/* GpioMethod definitions */ -struct GpioMethod g_GpioCntlrMethod = { - .request = NULL, - .release = NULL, - .write = GpioDevWrite, - .read = GpioDevRead, - .setDir = GpioDevSetDir, - .getDir = NULL, - .toIrq = NULL, - .setIrq = GpioDevSetIrq, - .unsetIrq = GpioDevUnSetIrq, - .enableIrq = GpioDevEnableIrq, - .disableIrq = GpioDevDisableIrq, -}; - static uint32_t GetGpioDeviceResource(struct GpioDevice *device, const struct DeviceResourceNode *resourceNode) { diff --git a/platform/gpio/gpio_wm.h b/platform/gpio/gpio_wm.h deleted file mode 100755 index e183278..0000000 --- a/platform/gpio/gpio_wm.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2022 HiHope Open Source Organization . - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef GPIO_WINNERMICRO_H -#define GPIO_WINNERMICRO_H - -#include "gpio_core.h" -#include "gpio_if.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Pin configuration - */ -enum GPIO_CONFIG { - ANALOG_MODE, /* Used as a function pin, input and output analog */ - IRQ_MODE, /* Used to trigger interrupt */ - INPUT_PULL_UP, /* Input with an internal pull-up resistor - use with devices - that actively drive the signal low - e.g. button connected to ground */ - INPUT_PULL_DOWN, /* Input with an internal pull-down resistor - use with devices - that actively drive the signal high - e.g. button connected to a power rail */ - INPUT_HIGH_IMPEDANCE, /* Input - must always be driven, either actively or by an external pullup resistor */ - OUTPUT_PUSH_PULL, /* Output actively driven high and actively driven low - - must not be connected to other active outputs - e.g. LED output */ - OUTPUT_OPEN_DRAIN_NO_PULL, /* Output actively driven low but is high-impedance when set high - - can be connected to other open-drain/open-collector outputs. - Needs an external pull-up resistor */ - OUTPUT_OPEN_DRAIN_PULL_UP, /* Output actively driven low and is pulled high - with an internal resistor when set high - - can be connected to other open-drain/open-collector outputs. */ -}; - -struct GpioResource { - uint32_t groupNum; - uint32_t realPin; - uint32_t config; - uint32_t pinNum; -}; - -struct GpioDevice { - uint8_t port; /* gpio port */ - struct GpioResource resource; - enum GPIO_CONFIG config; /* gpio config */ -}; - -typedef void (* tls_gpio_pin_orq_handler)(enum tls_io_name pin); - -#define DECIMALNUM 10 -#define OCTALNUM 8 -#ifdef __cplusplus -} -#endif - -#endif /* __GPIO_H__ */ \ No newline at end of file diff --git a/platform/i2c/i2c_wm.c b/platform/i2c/i2c_wm.c index dc2a959..e87dd77 100755 --- a/platform/i2c/i2c_wm.c +++ b/platform/i2c/i2c_wm.c @@ -1,28 +1,39 @@ /* - * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2022 Jiangsu Hoperun Software Co., Ltd. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * This file 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 "i2c_wm.h" + #include #include #include "i2c_core.h" #include "i2c_if.h" #include "wm_i2c.h" #include "wm_gpio_afsel.h" +#include "device_resource_if.h" +#include "osal_mutex.h" #define DEC_NUM 10 #define GROUP_PIN_NUM 8 #define I2C_INVALID_ADDR 0xFFFF +#define HAL_I2C_ID_NUM 1 + +struct I2cResource { + uint32_t port; + uint32_t sclPin; + uint32_t sdaPin; + uint32_t speed; +}; + +struct I2cDevice { + uint16_t devAddr; /**< slave device addr */ + uint32_t addressWidth; /**< Addressing mode: 7 bit or 10 bit */ + struct OsalMutex mutex; + uint32_t port; + struct I2cResource resource; +}; /* HdfDriverEntry method definitions */ static int32_t i2cDriverBind(struct HdfDeviceObject *device); diff --git a/platform/i2c/i2c_wm.h b/platform/i2c/i2c_wm.h deleted file mode 100755 index b24c716..0000000 --- a/platform/i2c/i2c_wm.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef I2C_WINNERMICRO_H -#define I2C_WINNERMICRO_H - -#include "device_resource_if.h" -#include "osal_mutex.h" -#ifdef __cplusplus -extern "C" { -#endif - -#define HAL_I2C_ID_NUM 1 - -struct I2cResource { - uint32_t port; - uint32_t sclPin; - uint32_t sdaPin; - uint32_t speed; -}; - -struct I2cDevice { - uint16_t devAddr; /**< slave device addr */ - uint32_t addressWidth; /**< Addressing mode: 7 bit or 10 bit */ - struct OsalMutex mutex; - uint32_t port; - struct I2cResource resource; -}; - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/platform/pwm/pwm_wm.c b/platform/pwm/pwm_wm.c index fbe1de9..1c45381 100755 --- a/platform/pwm/pwm_wm.c +++ b/platform/pwm/pwm_wm.c @@ -1,19 +1,11 @@ /* - * Copyright (C) 2022 HiHope Open Source Organization . - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2022 Jiangsu Hoperun Software Co., Ltd. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * This file 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 "pwm_wm.h" #include #include #include "device_resource_if.h" @@ -22,6 +14,18 @@ #include "hdf_log.h" #include "wm_pwm.h" +struct PwmResource { + uint32_t channel; + uint32_t freq; +}; + +struct PwmDevice { + struct IDeviceIoService ioService; + pwm_init_param pwmCfg; + struct PwmConfig *cfg; + struct PwmResource resource; +}; + static int32_t PwmDevSetConfig(struct PwmDev *pwm, struct PwmConfig *config); struct PwmMethod g_pwmmethod = { diff --git a/platform/pwm/pwm_wm.h b/platform/pwm/pwm_wm.h deleted file mode 100755 index feff07b..0000000 --- a/platform/pwm/pwm_wm.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2022 HiHope Open Source Organization . - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef PWM_WINNERMICRO_H -#define PWM_WINNERMICRO_H - -#include "pwm_core.h" -#include "wm_pwm.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct PwmResource { - uint32_t channel; - uint32_t freq; -}; - -struct PwmDevice { - struct IDeviceIoService ioService; - pwm_init_param pwmCfg; - struct PwmConfig *cfg; - struct PwmResource resource; -}; - -#ifdef __cplusplus -} -#endif -#endif diff --git a/platform/spi/spi_wm.c b/platform/spi/spi_wm.c index bd21e3b..fb79fe2 100755 --- a/platform/spi/spi_wm.c +++ b/platform/spi/spi_wm.c @@ -1,29 +1,45 @@ /* - * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2022 Jiangsu Hoperun Software Co., Ltd. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * This file 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 "spi_wm.h" + #include #include #include "hdf_log.h" #include "spi_core.h" +#include "spi_if.h" #include "device_resource_if.h" #include "wm_gpio_afsel.h" +#include "osal_mutex.h" +#include "osal_sem.h" +#include "wm_hostspi.h" #define SPI_DMA_MAX 4095 #define MAX_SPI_NUMBER 1 #define TIMEOUT 1000 +struct SpiResource { + uint32_t num; + uint32_t speed; + enum SpiTransferMode transmode; + uint32_t mode; // TLS_SPI_MODE_x + uint32_t dataSize; + uint32_t spiCsSoft; + uint32_t spiClkPin; + uint32_t spiMosiPin; + uint32_t spiMisoPin; + uint32_t spiCsPin; +}; + +struct SpiDevice { + uint32_t spiId; + struct SpiResource resource; + struct OsalMutex mutex; +}; + static void SpiIomuxInit(struct SpiDevice *spiDevice) { struct SpiResource *resource = NULL; diff --git a/platform/spi/spi_wm.h b/platform/spi/spi_wm.h deleted file mode 100755 index 2f424dd..0000000 --- a/platform/spi/spi_wm.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef SPI_WINNERMICRO_H -#define SPI_WINNERMICRO_H - -#include "osal_mutex.h" -#include "osal_sem.h" -#include "wm_hostspi.h" -#include "spi_if.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct SpiResource { - uint32_t num; - uint32_t speed; - enum SpiTransferMode transmode; - uint32_t mode; // TLS_SPI_MODE_x - uint32_t dataSize; - uint32_t spiCsSoft; - uint32_t spiClkPin; - uint32_t spiMosiPin; - uint32_t spiMisoPin; - uint32_t spiCsPin; -}; - -struct SpiDevice { - uint32_t spiId; - struct SpiResource resource; - struct OsalMutex mutex; -}; - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/platform/uart/uart_wm.c b/platform/uart/uart_wm.c index 52fad38..5a9ce8b 100755 --- a/platform/uart/uart_wm.c +++ b/platform/uart/uart_wm.c @@ -1,33 +1,64 @@ /* - * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2022 Jiangsu Hoperun Software Co., Ltd. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * This file is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. */ -#include "uart_wm.h" #include #include #include "osal_time.h" +#include "osal_sem.h" #include "device_resource_if.h" #include "hdf_log.h" #include "wm_gpio_afsel.h" +#include "uart_if.h" +#include "uart_core.h" +#include "wm_uart.h" #define HDF_UART_TMO 1000 #define TMO_MS_UNIT_CONV (1000) #define HDF_LOG_TAG uartDev -#define UART_CHSIZE_5BIT 5 -#define UART_CHSIZE_6BIT 6 -#define UART_CHSIZE_7BIT 7 -#define UART_CHSIZE_8BIT 8 +#define UART_DEV_SERVICE_NAME_PREFIX "HDF_PLATFORM_UART%d" +#define MAX_DEV_NAME_SIZE 32 + +struct UartResource { + uint32_t num; /* UART port num */ + uint32_t baudRate; /* Default baudrate */ + uint32_t wLen; /* Default word length */ + uint32_t parity; /* Default parity */ + uint32_t stopBit; /* Default stop bits */ + bool txDMA; + bool rxDMA; +}; + +enum UartDeviceState { + UART_DEVICE_UNINITIALIZED = 0x0u, + UART_DEVICE_INITIALIZED = 0x1u, +}; + +struct UART_CTX_OBJ { + bool txDMA; + bool rxDMA; + bool isBlock; + struct OsalSem rxSem; + struct OsalSem txSem; +}; + +struct UartDevice { + struct IDeviceIoService ioService; + struct UartResource resource; + tls_uart_options_t config; + uint32_t uartId; + bool initFlag; + uint32_t transMode; +}; + +enum { + UART_READ = 0, + UART_WRITE +}; static struct UART_CTX_OBJ g_uartCtx[4] = {0}; static unsigned char *g_uartKfifoBuffer[4] = {NULL, NULL, NULL, NULL}; diff --git a/platform/uart/uart_wm.h b/platform/uart/uart_wm.h deleted file mode 100755 index 2823db2..0000000 --- a/platform/uart/uart_wm.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef UART_WINNERMICRO_H -#define UART_WINNERMICRO_H - -#include "uart_if.h" -#include "uart_core.h" -#include "osal_sem.h" -#include "wm_uart.h" -#ifdef __cplusplus -extern "C" { -#endif - -#define UART_DEV_SERVICE_NAME_PREFIX "HDF_PLATFORM_UART%d" -#define MAX_DEV_NAME_SIZE 32 - -struct UartResource { - uint32_t num; /* UART port num */ - uint32_t baudRate; /* Default baudrate */ - uint32_t wLen; /* Default word length */ - uint32_t parity; /* Default parity */ - uint32_t stopBit; /* Default stop bits */ - bool txDMA; - bool rxDMA; -}; - -enum UartDeviceState { - UART_DEVICE_UNINITIALIZED = 0x0u, - UART_DEVICE_INITIALIZED = 0x1u, -}; - -struct UART_CTX_OBJ { - bool txDMA; - bool rxDMA; - bool isBlock; - struct OsalSem rxSem; - struct OsalSem txSem; -}; - -struct UartDevice { - struct IDeviceIoService ioService; - struct UartResource resource; - tls_uart_options_t config; - uint32_t uartId; - bool initFlag; - uint32_t transMode; -}; - -enum { - UART_READ = 0, - UART_WRITE -}; - -int32_t UartDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/platform/watchdog/watchdog_wm.c b/platform/watchdog/watchdog_wm.c index c90a4a2..8d97769 100755 --- a/platform/watchdog/watchdog_wm.c +++ b/platform/watchdog/watchdog_wm.c @@ -1,27 +1,29 @@ /* - * Copyright (C) 2022 HiHope Open Source Organization . - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2022 Jiangsu Hoperun Software Co., Ltd. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * This file 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 "watchdog_wm.h" + #include #include #include "device_resource_if.h" #include "hdf_device_desc.h" #include "hdf_log.h" #include "watchdog_if.h" +#include "watchdog_core.h" #include "wm_regs.h" #include "wm_cpu.h" +struct WatchdogResource { + int32_t watchdogId; +}; + +struct WatchdogDevice { + struct WatchdogResource resource; +}; + static int g_watchdogStart; static int g_watchdogTimeout; @@ -42,7 +44,6 @@ struct WatchdogMethod g_WatchdogCntlrMethod = { .releasePriv = NULL, // WatchdogDevReleasePriv }; - static int32_t WatchdogDevStart(struct WatchdogCntlr *watchdogCntlr) { tls_watchdog_start_cal_elapsed_time(); diff --git a/platform/watchdog/watchdog_wm.h b/platform/watchdog/watchdog_wm.h deleted file mode 100755 index 3a4e15e..0000000 --- a/platform/watchdog/watchdog_wm.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2022 HiHope Open Source Organization . - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef WDG_WINNERMICRO_H -#define WDG_WINNERMICRO_H - -#include "watchdog_core.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct WatchdogResource { - int32_t watchdogId; -}; - -struct WatchdogDevice { - struct WatchdogResource resource; -}; - -#ifdef __cplusplus -} -#endif -#endif \ No newline at end of file -- Gitee From 9c5be8c2e3a6ff67cea110bd87fc7b5fc142dfc2 Mon Sep 17 00:00:00 2001 From: bob_qu Date: Thu, 17 Mar 2022 19:54:05 +0800 Subject: [PATCH 024/102] fix:update OAT file Signed-off-by: bob_qu --- OAT.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/OAT.xml b/OAT.xml index 93fb38b..592f47e 100644 --- a/OAT.xml +++ b/OAT.xml @@ -60,8 +60,7 @@ Note:If the text contains special characters, please escape them according to th - - + -- Gitee From a35501445526bfc78563b88589efc842db8eb803 Mon Sep 17 00:00:00 2001 From: wu Date: Sat, 12 Mar 2022 00:26:46 -0800 Subject: [PATCH 025/102] fix usb security function verification Signed-off-by: wu --- khdf/liteos/model/bus/usb/include/hdf_usb.h | 2 +- .../model/usb/host/src/usb_pnp_notify.c | 46 +++++++++++-------- uhdf2/hcs/BUILD.gn | 3 +- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/khdf/liteos/model/bus/usb/include/hdf_usb.h b/khdf/liteos/model/bus/usb/include/hdf_usb.h index 0497365..b8e6044 100644 --- a/khdf/liteos/model/bus/usb/include/hdf_usb.h +++ b/khdf/liteos/model/bus/usb/include/hdf_usb.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: diff --git a/khdf/liteos/model/usb/host/src/usb_pnp_notify.c b/khdf/liteos/model/usb/host/src/usb_pnp_notify.c index f7982e9..0063808 100644 --- a/khdf/liteos/model/usb/host/src/usb_pnp_notify.c +++ b/khdf/liteos/model/usb/host/src/usb_pnp_notify.c @@ -98,27 +98,33 @@ static struct UsbPnpDeviceInfo *UsbPnpNotifyCreateInfo(void) struct UsbPnpDeviceInfo *infoTemp = NULL; unsigned char *ptr = NULL; static int32_t idNum = 0; + int32_t ret; ptr = OsalMemCalloc(sizeof(struct UsbPnpDeviceInfo)); if (ptr == NULL) { HDF_LOGE("%s:%d OsalMemAlloc faile ", __func__, __LINE__); return NULL; - } else { - infoTemp = (struct UsbPnpDeviceInfo *)ptr; - - if (idNum++ >= INT32_MAX) { - idNum = 0; - } - infoTemp->id = idNum; - OsalMutexInit(&infoTemp->lock); - infoTemp->status = USB_PNP_DEVICE_INIT_STATUS; - DListHeadInit(&infoTemp->list); - memset_s(infoTemp->interfaceRemoveStatus, USB_PNP_INFO_MAX_INTERFACES, - 0, sizeof(infoTemp->interfaceRemoveStatus)); - DListInsertTail(&infoTemp->list, &g_usbPnpInfoListHead); + } + infoTemp = (struct UsbPnpDeviceInfo *)ptr; - return infoTemp; + if (idNum++ >= INT32_MAX) { + idNum = 0; } + infoTemp->id = idNum; + OsalMutexInit(&infoTemp->lock); + infoTemp->status = USB_PNP_DEVICE_INIT_STATUS; + DListHeadInit(&infoTemp->list); + ret = memset_s(infoTemp->interfaceRemoveStatus, USB_PNP_INFO_MAX_INTERFACES, + 0, sizeof(infoTemp->interfaceRemoveStatus)); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s:%{public}d memset_s failed", __func__, __LINE__); + OsalMemFree(ptr); + return NULL; + } + + DListInsertTail(&infoTemp->list, &g_usbPnpInfoListHead); + + return infoTemp; } static struct UsbPnpDeviceInfo *UsbPnpNotifyFindInfo(struct UsbInfoQueryPara queryPara) @@ -967,7 +973,7 @@ static int32_t UsbPnpNotifyBind(struct HdfDeviceObject *device) static int32_t UsbPnpNotifyInit(struct HdfDeviceObject *device) { static bool firstInitFlag = true; - HDF_STATUS ret; + int32_t ret; struct OsalThreadParam threadCfg; dprintf("%s:%d enter!\n", __func__, __LINE__); @@ -988,10 +994,14 @@ static int32_t UsbPnpNotifyInit(struct HdfDeviceObject *device) OsalMutexInit(&g_usbSendEventLock); - g_usbPnpThreadRunningFlag = true; - /* Creat thread to handle send usb interface information. */ - (void)memset_s(&threadCfg, sizeof(threadCfg), 0, sizeof(threadCfg)); + ret = memset_s(&threadCfg, sizeof(threadCfg), 0, sizeof(threadCfg)); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s:%{public}d memset_s failed", __func__, __LINE__); + return ret; + } + + g_usbPnpThreadRunningFlag = true; threadCfg.name = "LiteOS usb pnp notify handle kthread"; threadCfg.priority = OSAL_THREAD_PRI_HIGH; threadCfg.stackSize = USB_PNP_NOTIFY_REPORT_STACK_SIZE; diff --git a/uhdf2/hcs/BUILD.gn b/uhdf2/hcs/BUILD.gn index 077f2c9..d9cfb5f 100644 --- a/uhdf2/hcs/BUILD.gn +++ b/uhdf2/hcs/BUILD.gn @@ -17,7 +17,8 @@ import("$hdf_framework_path/tools/hc-gen/hc_gen.gni") hc_gen("build_hcs") { gadget = "acm" - if (product_name == "Hi3516DV300" || product_name == "watchos") { + if (product_name == "Hi3516DV300" || product_name == "watchos" || + product_name == "rk3568") { gadget = "ecm_acm" } hcs_source = "/hdf.hcs" -- Gitee From ba100f1e08ff190cc83efda658f1f11f544b3f15 Mon Sep 17 00:00:00 2001 From: bob_qu Date: Thu, 17 Mar 2022 21:44:58 +0800 Subject: [PATCH 026/102] fix:modify uart and watchdog file Signed-off-by: bob_qu --- platform/spi/spi_wm.c | 2 +- platform/watchdog/watchdog_wm.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/spi/spi_wm.c b/platform/spi/spi_wm.c index fb79fe2..e317bff 100755 --- a/platform/spi/spi_wm.c +++ b/platform/spi/spi_wm.c @@ -505,4 +505,4 @@ static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg, } } return HDF_SUCCESS; -} \ No newline at end of file +} diff --git a/platform/watchdog/watchdog_wm.c b/platform/watchdog/watchdog_wm.c index 8d97769..6a381a2 100755 --- a/platform/watchdog/watchdog_wm.c +++ b/platform/watchdog/watchdog_wm.c @@ -256,4 +256,4 @@ struct HdfDriverEntry g_watchdogDriverEntry = { }; // Initialize HdfDriverEntry -HDF_INIT(g_watchdogDriverEntry); \ No newline at end of file +HDF_INIT(g_watchdogDriverEntry); -- Gitee From 9279b491dbffd6358fff1ac94613bd14cb0b0172 Mon Sep 17 00:00:00 2001 From: "weidongwang@bestechnic.com" Date: Thu, 17 Mar 2022 21:43:32 +0800 Subject: [PATCH 027/102] fix new hcs api build error Signed-off-by: weidongwang@bestechnic.com Change-Id: Ifb10e37d6899b0ad49dac05e0bd74c2d98ce6c07 Signed-off-by: weidongwang@bestechnic.com --- platform/gpio/BUILD.gn | 3 ++- platform/pwm/pwm_bes.c | 28 +++++++++++++++++++++++++--- platform/spi/spi_bes.c | 40 +++++++++++++++++++++++++++++++++++++--- platform/uart/BUILD.gn | 4 ++++ platform/uart/uart_bes.c | 40 +++++++++++++++++++++++++++++++++++++--- 5 files changed, 105 insertions(+), 10 deletions(-) diff --git a/platform/gpio/BUILD.gn b/platform/gpio/BUILD.gn index 043e367..fe0562f 100644 --- a/platform/gpio/BUILD.gn +++ b/platform/gpio/BUILD.gn @@ -21,7 +21,8 @@ hdf_driver(module_name) { } include_dirs = [ "." ] - if (defined(LOSCFG_SHIELD_V200ZR_EVB_T1)) { + if (defined(LOSCFG_SHIELD_V200ZR_EVB_T1) && + defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { deps = [ "//device/board/fnlink/shields" ] } } diff --git a/platform/pwm/pwm_bes.c b/platform/pwm/pwm_bes.c index 724f518..3caaffa 100644 --- a/platform/pwm/pwm_bes.c +++ b/platform/pwm/pwm_bes.c @@ -89,9 +89,31 @@ static int InitPwmDevice(struct PwmDev *host) } #ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO -static uint32_t GetPwmDeviceResource(struct PwmDevice *device) +#define PWM_FIND_CONFIG(node, name, resource) \ + do { \ + if (strcmp(HCS_PROP(node, match_attr), name) == 0) { \ + tempPin = HCS_PROP(node, pwmPin); \ + resource->pwmPin = ((tempPin / DEC_TEN) * PIN_GROUP_NUM) + (tempPin % DEC_TEN); \ + resource->pwmId = HCS_PROP(node, pwmId); \ + break; \ + } \ + } while (0) +#define PLATFORM_PWM_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), pwm_config) +static uint32_t GetPwmDeviceResource(struct PwmDevice *device, const char *deviceMatchAttr) { - (void)device; + uint32_t tempPin; + struct PwmResource *resource = NULL; + if (device == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + resource = &device->resource; + if (resource == NULL) { + HDF_LOGE("%s: resource is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + HCS_FOREACH_CHILD_VARGS(PLATFORM_PWM_CONFIG, PWM_FIND_CONFIG, deviceMatchAttr, resource); return HDF_SUCCESS; } #else @@ -151,7 +173,7 @@ static int32_t AttachPwmDevice(struct PwmDev *host, struct HdfDeviceObject *devi return HDF_ERR_MALLOC_FAIL; } #ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO - ret = GetPwmDeviceResource(pwmDevice); + ret = GetPwmDeviceResource(pwmDevice, device->deviceMatchAttr); #else ret = GetPwmDeviceResource(pwmDevice, device->property); #endif diff --git a/platform/spi/spi_bes.c b/platform/spi/spi_bes.c index e5afea8..886de57 100644 --- a/platform/spi/spi_bes.c +++ b/platform/spi/spi_bes.c @@ -277,7 +277,7 @@ OUT: static int32_t HalSpiRecv(struct SpiDevice *spiDevice, uint8_t *data, uint16_t size, uint32_t timeOut) { int32_t ret; - uint32_t len = size; + int32_t len = (int32_t)size; uint32_t remainder; int32_t status = HDF_FAILURE; uint8_t *cmd = NULL; @@ -415,10 +415,44 @@ static int32_t InitSpiDevice(struct SpiDevice *spiDevice) /* get spi config from hcs file */ #ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO +#define SPI_FIND_CONFIG(node, name, resource) \ + do { \ + if (strcmp(HCS_PROP(node, match_attr), name) == 0) { \ + resource->num = HCS_PROP(node, busNum); \ + resource->speed = HCS_PROP(node, speed); \ + resource->transmode = HCS_PROP(node, transmode); \ + resource->spiCsSoft = HCS_PROP(node, spiCsSoft); \ + resource->mode = HCS_PROP(node, mode); \ + resource->dataSize = HCS_PROP(node, dataSize); \ + resource->csNum = HCS_PROP(node, csNum); \ + tempPin = HCS_PROP(node, spiClkPin); \ + resource->spiClkPin = ((tempPin / DEC_NUM) * GROUP_PIN_NUM) + (tempPin % DEC_NUM); \ + tempPin = HCS_PROP(node, spiMosiPin); \ + resource->spiMosiPin = ((tempPin / DEC_NUM) * GROUP_PIN_NUM) + (tempPin % DEC_NUM); \ + tempPin = HCS_PROP(node, spiMisoPin); \ + resource->spiMisoPin = ((tempPin / DEC_NUM) * GROUP_PIN_NUM) + (tempPin % DEC_NUM); \ + tempPin = HCS_PROP(node, spiCsPin); \ + resource->spiCsPin = ((tempPin / DEC_NUM) * GROUP_PIN_NUM) + (tempPin % DEC_NUM); \ + break; \ + } \ + } while (0) + +#define PLATFORM_SPI_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), spi_config) static int32_t GetSpiDeviceResource(struct SpiDevice *spiDevice, const char *deviceMatchAttr) { - (void)spiDevice; - (void)deviceMatchAttr; + uint32_t tempPin; + struct SpiResource *resource = NULL; + if (spiDevice == NULL) { + HDF_LOGE("device or resourceNode is NULL\r\n"); + return HDF_ERR_INVALID_PARAM; + } + resource = &spiDevice->resource; + if (resource == NULL) { + HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__); + return HDF_ERR_INVALID_OBJECT; + } + + HCS_FOREACH_CHILD_VARGS(PLATFORM_SPI_CONFIG, SPI_FIND_CONFIG, deviceMatchAttr, resource); return HDF_SUCCESS; } #else diff --git a/platform/uart/BUILD.gn b/platform/uart/BUILD.gn index 9a3845c..7b96723 100644 --- a/platform/uart/BUILD.gn +++ b/platform/uart/BUILD.gn @@ -21,4 +21,8 @@ hdf_driver(module_name) { } include_dirs = [ "." ] + if (defined(LOSCFG_SHIELD_V200ZR_EVB_T1) && + defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { + deps = [ "//device/board/fnlink/shields" ] + } } diff --git a/platform/uart/uart_bes.c b/platform/uart/uart_bes.c index 5045d26..736c3d5 100644 --- a/platform/uart/uart_bes.c +++ b/platform/uart/uart_bes.c @@ -223,7 +223,7 @@ static int32_t HalUartRecv(uint8_t uartId, void *data, uint32_t expectSize, uint32_t nowTime; uint32_t fifoPopLen; uint32_t recvedLen = 0; - uint32_t expectLen = expectSize; + int32_t expectLen = (int32_t)expectSize; if (data == NULL || expectLen == 0 || recvSize == NULL) { HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__); @@ -459,10 +459,44 @@ static int InitUartDevice(struct UartHost *host) return HDF_SUCCESS; } #ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO +#define UART_FIND_CONFIG(node, name, resource) \ + do { \ + if (strcmp(HCS_PROP(node, match_attr), name) == 0) { \ + resource->num = HCS_PROP(node, num); \ + resource->baudRate = HCS_PROP(node, baudRate); \ + resource->parity = HCS_PROP(node, parity); \ + resource->stopBit = HCS_PROP(node, stopBit); \ + resource->wLen = HCS_PROP(node, data); \ + resource->rxDMA = HCS_PROP(node, rxDMA); \ + resource->txDMA = HCS_PROP(node, txDMA); \ + break; \ + } \ + } while (0) + +#define PLATFORM_UART_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), uart_config) static uint32_t GetUartDeviceResource(struct UartDevice *device, const char *deviceMatchAttr) { - (void)device; - (void)deviceMatchAttr; + struct UartResource *resource = NULL; + if (device == NULL || deviceMatchAttr == NULL) { + HDF_LOGE("device or resourceNode is NULL\r\n"); + return HDF_ERR_INVALID_PARAM; + } + resource = &device->resource; + if (resource == NULL) { + HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__); + return HDF_ERR_INVALID_OBJECT; + } + + HCS_FOREACH_CHILD_VARGS(PLATFORM_UART_CONFIG, UART_FIND_CONFIG, deviceMatchAttr, resource); + // copy config + device->initFlag = false; + device->uartId = resource->num; + device->config.baud = resource->baudRate; + device->config.parity = resource->parity; + device->config.stop = resource->stopBit; + device->config.data = resource->wLen; + device->config.dma_rx = (resource->rxDMA == true) ? true : false; + device->config.dma_tx = (resource->txDMA == true) ? true : false; return HDF_SUCCESS; } #else -- Gitee From 89aafd65ffe5b7f5f486e1ff2a6497e88996defd Mon Sep 17 00:00:00 2001 From: bob_qu Date: Sat, 19 Mar 2022 09:46:23 +0800 Subject: [PATCH 028/102] fix:Resolve code conflicts and modify compiled scripts Signed-off-by: bob_qu --- platform/gpio/BUILD.gn | 6 +++++- platform/uart/BUILD.gn | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/platform/gpio/BUILD.gn b/platform/gpio/BUILD.gn index 1a8d54d..bf7e7ab 100644 --- a/platform/gpio/BUILD.gn +++ b/platform/gpio/BUILD.gn @@ -19,12 +19,16 @@ hdf_driver(module_name) { if (defined(LOSCFG_SOC_COMPANY_GOODIX)) { sources += [ "gpio_gr5xx.c" ] } + if (defined(LOSCFG_SOC_COMPANY_ASRMICRO)) { + sources += [ "gpio_asr.c" ] + } if (defined(LOSCFG_SOC_COMPANY_WINNERMICRO)) { sources += [ "gpio_wm.c" ] } include_dirs = [ "." ] - if (defined(LOSCFG_SHIELD_V200ZR_EVB_T1)) { + if (defined(LOSCFG_SHIELD_V200ZR_EVB_T1) && + defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { deps = [ "//device/board/fnlink/shields" ] } } diff --git a/platform/uart/BUILD.gn b/platform/uart/BUILD.gn index c7b566a..f1c1a1e 100644 --- a/platform/uart/BUILD.gn +++ b/platform/uart/BUILD.gn @@ -19,9 +19,16 @@ hdf_driver(module_name) { if (defined(LOSCFG_SOC_COMPANY_GOODIX)) { sources += [ "uart_gr5xx.c" ] } + if (defined(LOSCFG_SOC_COMPANY_ASRMICRO)) { + sources += [ "uart_asr.c" ] + } if (defined(LOSCFG_SOC_COMPANY_WINNERMICRO)) { sources += [ "uart_wm.c" ] } include_dirs = [ "." ] + if (defined(LOSCFG_SHIELD_V200ZR_EVB_T1) && + defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { + deps = [ "//device/board/fnlink/shields" ] + } } -- Gitee From e5b6445550a8095d4b18e7d05d70bbf12553d669 Mon Sep 17 00:00:00 2001 From: zhang Date: Sat, 19 Mar 2022 12:59:16 +0800 Subject: [PATCH 029/102] fix: delete no use capabilities of hdf process Signed-off-by: zhang --- uhdf2/host/hdf_devhostmusl.cfg | 61 ++++++++++++++++++-------------- uhdf2/manager/hdf_devmgrmusl.cfg | 2 +- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/uhdf2/host/hdf_devhostmusl.cfg b/uhdf2/host/hdf_devhostmusl.cfg index 66148e3..28a1c74 100644 --- a/uhdf2/host/hdf_devhostmusl.cfg +++ b/uhdf2/host/hdf_devhostmusl.cfg @@ -11,9 +11,9 @@ "name" : "blue_host", "dynamic" : true, "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "blue_host", - "gid" : ["blue_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "uid" : "root", + "gid" : ["system"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] }, { "name" : "sample_host", @@ -21,7 +21,7 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "sample_host", "gid" : ["sample_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] }, { "name" : "usb_host", @@ -29,7 +29,7 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "usb_host", "gid" : ["usb_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] }, { "name" : "usbfnMaster_host", @@ -37,7 +37,7 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "usbfnMaster_host", "gid" : ["usbfnMaster_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] }, { "name" : "power_host", @@ -45,7 +45,7 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "power_host", "gid" : ["power_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] }, { "name" : "wifi_host", @@ -53,7 +53,7 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "wifi_host", "gid" : ["wifi_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] }, { "name" : "audio_hdi_server_host", @@ -61,7 +61,14 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "audio_hdi_server_host", "gid" : ["audio_hdi_server_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] + }, + { + "name" : "camera_mpp_host", + "dynamic" : true, + "path" : ["/vendor/bin/hdf_devhost"], + "uid" : "root", + "gid" : ["system"] }, { "name" : "camera_host", @@ -69,7 +76,7 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "camera_host", "gid" : ["camera_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] }, { "name" : "input_user_host", @@ -77,7 +84,7 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "input_user_host", "gid" : ["input_user_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] }, { "name" : "display_gralloc_host", @@ -85,7 +92,7 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "display_gralloc_host", "gid" : ["display_gralloc_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] }, { "name" : "codec_host", @@ -93,7 +100,7 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "codec_host", "gid" : ["codec_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] }, { "name" : "riladapter_host", @@ -101,7 +108,7 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "riladapter_host", "gid" : ["riladapter_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] }, { "name" : "sensor_dal_host", @@ -109,7 +116,7 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "sensor_dal_host", "gid" : ["sensor_dal_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] }, { "name" : "vibrator_dal_host", @@ -117,7 +124,7 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "vibrator_dal_host", "gid" : ["vibrator_dal_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] }, { "name" : "light_dal_host", @@ -125,7 +132,7 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "light_dal_host", "gid" : ["light_dal_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] }, { "name" : "wifi_c_host", @@ -133,7 +140,7 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "wifi_c_host", "gid" : ["wifi_c_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] }, { "name" : "disp_gralloc_host", @@ -141,7 +148,7 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "disp_gralloc_host", "gid" : ["disp_gralloc_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] }, { "name" : "dcamera_host", @@ -149,7 +156,7 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "dcamera_host", "gid" : ["dcamera_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] }, { "name" : "hwc_host", @@ -157,7 +164,7 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "hwc_host", "gid" : ["hwc_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] }, { "name" : "gralloc_host", @@ -165,7 +172,7 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "gralloc_host", "gid" : ["gralloc_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] }, { "name" : "sensor_host", @@ -173,7 +180,7 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "sensor_host", "gid" : ["sensor_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] }, { "name" : "nfc_host", @@ -181,15 +188,15 @@ "path" : ["/vendor/bin/hdf_devhost"], "uid" : "nfc_host", "gid" : ["nfc_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] }, { "name" : "a2dp_host", "dynamic" : true, "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "a2dp_host", - "gid" : ["a2dp_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "uid" : "root", + "gid" : ["system"], + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] } ] } diff --git a/uhdf2/manager/hdf_devmgrmusl.cfg b/uhdf2/manager/hdf_devmgrmusl.cfg index e30359c..c54809e 100644 --- a/uhdf2/manager/hdf_devmgrmusl.cfg +++ b/uhdf2/manager/hdf_devmgrmusl.cfg @@ -5,7 +5,7 @@ "uid" : "hdf_devmgr", "gid" : ["hdf_devmgr"], "start-mode" : "boot", - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] } ] } -- Gitee From 131f7919d21f7289551dd1d7a5ccc5fd8c7c1300 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cwangyougang=E2=80=9D?= Date: Mon, 21 Mar 2022 02:12:03 +0000 Subject: [PATCH 030/102] fix:clear codex adapter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: “wangyougang” --- khdf/liteos_m/network/src/netbuf_adapter.c | 1 + 1 file changed, 1 insertion(+) diff --git a/khdf/liteos_m/network/src/netbuf_adapter.c b/khdf/liteos_m/network/src/netbuf_adapter.c index 75bcc4b..c833083 100644 --- a/khdf/liteos_m/network/src/netbuf_adapter.c +++ b/khdf/liteos_m/network/src/netbuf_adapter.c @@ -28,6 +28,7 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "netbuf_adapter.h" #include "hdf_netbuf.h" #include "los_memory.h" #include "lwip/prot/ethernet.h" -- Gitee From 8bf450f4b21a7e2550e74ace11bcd108ed082cf8 Mon Sep 17 00:00:00 2001 From: rtos_lover Date: Mon, 21 Mar 2022 15:02:12 +0800 Subject: [PATCH 031/102] fix warning: 'HostRestI2cDevice' defined but not used [-Wunused-function] fix #I4YHKU Signed-off-by: rtos_lover --- platform/i2c/i2c_bes.c | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/platform/i2c/i2c_bes.c b/platform/i2c/i2c_bes.c index 742589d..8ad7826 100644 --- a/platform/i2c/i2c_bes.c +++ b/platform/i2c/i2c_bes.c @@ -132,40 +132,6 @@ int32_t InitI2cDevice(struct I2cDevice *device) return ret; } -static int32_t HostRestI2cDevice(struct I2cDevice *device) -{ - int32_t ret; - struct I2cResource *resource = NULL; - struct HAL_I2C_CONFIG_T *i2cConfig = NULL; - uint32_t i2cPort; - if (device == NULL) { - HDF_LOGE("%s %d device is null\r\n", __func__, __LINE__); - return HDF_ERR_INVALID_PARAM; - } - resource = &device->resource; - if (resource == NULL) { - HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__); - return HDF_ERR_INVALID_OBJECT; - } - i2cConfig = &device->i2cCfg; - if (i2cConfig == NULL) { - HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__); - return HDF_ERR_INVALID_OBJECT; - } - device->port = resource->port; - i2cPort = device->port; - if (i2cPort > HAL_I2C_ID_NUM) { - HDF_LOGE("i2c port %u not support\r\n", i2cPort); - return HDF_ERR_NOT_SUPPORT; - } - - hal_i2c_close(i2cPort); - ret = hal_i2c_open(i2cPort, i2cConfig); - if (ret == HDF_SUCCESS) { - HDF_LOGD("open %u i2c succ.\r\n", i2cPort); - } - return ret; -} #ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO #define I2C_FIND_CONFIG(node, name, resource) \ do { \ -- Gitee From 9e7c5cdbe30637d2313538961ff5bfabf7e5c46c Mon Sep 17 00:00:00 2001 From: rtos_lover Date: Mon, 21 Mar 2022 14:56:26 +0800 Subject: [PATCH 032/102] fix warning: 'HalGpioGetIrqConfig' defined but not used [-Wunused-function] fix #I4YHJL Signed-off-by: rtos_lover --- platform/gpio/gpio_bes.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/platform/gpio/gpio_bes.c b/platform/gpio/gpio_bes.c index ba110a6..e1188a4 100644 --- a/platform/gpio/gpio_bes.c +++ b/platform/gpio/gpio_bes.c @@ -74,18 +74,6 @@ enum HAL_GPIO_PIN_T g_gpioPinReflectionMap[HAL_GPIO_PIN_LED_NUM] = {0}; static struct HAL_GPIO_IRQ_CFG_T g_gpioIrqCfg[HAL_GPIO_PIN_LED_NUM] = {0}; -static struct HAL_GPIO_IRQ_CFG_T HalGpioGetIrqConfig(enum HAL_GPIO_PIN_T pin) -{ - struct HAL_GPIO_IRQ_CFG_T irqCfg; - - irqCfg.irq_enable = g_gpioIrqCfg[pin].irq_enable; - irqCfg.irq_debounce = g_gpioIrqCfg[pin].irq_debounce; - irqCfg.irq_type = g_gpioIrqCfg[pin].irq_type; - irqCfg.irq_polarity = g_gpioIrqCfg[pin].irq_polarity; - - return irqCfg; -} - static void OemGpioIrqHdl(enum HAL_GPIO_PIN_T pin) { if (pin >= HAL_GPIO_PIN_LED_NUM) { @@ -296,7 +284,7 @@ static int32_t AttachGpioDevice(struct GpioCntlr *gpioCntlr, struct HdfDeviceObj ret = GetGpioDeviceResource(gpioDevice, device->property); #endif if (ret != HDF_SUCCESS) { - (void)OsalMemFree(gpioDevice); + OsalMemFree(gpioDevice); return HDF_FAILURE; } @@ -358,7 +346,7 @@ static void GpioDriverRelease(struct HdfDeviceObject *device) } gpioCntlr->ops = NULL; - (void)OsalMemFree(gpioCntlr->priv); + OsalMemFree(gpioCntlr->priv); gpioCntlr->count = 0; } -- Gitee From 2ca8bab5edf3374954627e2f7f48094a924293ec Mon Sep 17 00:00:00 2001 From: ShiJie Date: Tue, 22 Mar 2022 01:12:04 -0700 Subject: [PATCH 033/102] fix: Uid causes authentication failure Signed-off-by: ShiJie Change-Id: I632195513a4de7cd4690e624846bdda4a8d6b573 --- uhdf2/host/hdf_devhostmusl.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uhdf2/host/hdf_devhostmusl.cfg b/uhdf2/host/hdf_devhostmusl.cfg index 28a1c74..0b476a9 100644 --- a/uhdf2/host/hdf_devhostmusl.cfg +++ b/uhdf2/host/hdf_devhostmusl.cfg @@ -43,8 +43,8 @@ "name" : "power_host", "dynamic" : true, "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "power_host", - "gid" : ["power_host"], + "uid" : "system", + "gid" : ["system"], "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] }, { -- Gitee From b783fa3fe2b8f31a9f4da29d6d6c1dfb4dc90e82 Mon Sep 17 00:00:00 2001 From: guodongqi Date: Wed, 23 Mar 2022 10:31:28 +0800 Subject: [PATCH 034/102] fix: clear bugs of code view Signed-off-by: guodongqi --- .../hdi_sample/sample_service_c/sample_service_stub.c | 8 ++++---- uhdf2/ipc/include/hdf_remote_adapter.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_c/sample_service_stub.c b/uhdf2/hdi/test/hdi_sample/sample_service_c/sample_service_stub.c index e6afc49..b9e37c9 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_service_c/sample_service_stub.c +++ b/uhdf2/hdi/test/hdi_sample/sample_service_c/sample_service_stub.c @@ -333,10 +333,10 @@ static int32_t SerStubListTypeTest(struct HdfDeviceIoClient *client, struct HdfS FINISHED: if (input != NULL) { - (void)OsalMemFree(input); + OsalMemFree(input); } if (output != NULL) { - (void)OsalMemFree(output); + OsalMemFree(output); } return ec; } @@ -386,10 +386,10 @@ static int32_t SerStubArrayTypeTest(struct HdfDeviceIoClient *client, struct Hdf FINISHED: if (input != NULL) { - (void)OsalMemFree(input); + OsalMemFree(input); } if (output != NULL) { - (void)OsalMemFree(output); + OsalMemFree(output); } return ec; } diff --git a/uhdf2/ipc/include/hdf_remote_adapter.h b/uhdf2/ipc/include/hdf_remote_adapter.h index 2be3b4c..e5153dc 100644 --- a/uhdf2/ipc/include/hdf_remote_adapter.h +++ b/uhdf2/ipc/include/hdf_remote_adapter.h @@ -29,7 +29,7 @@ extern "C" { class HdfRemoteServiceStub : public OHOS::IPCObjectStub { public: - HdfRemoteServiceStub(struct HdfRemoteService *service); + explicit HdfRemoteServiceStub(struct HdfRemoteService *service); int OnRemoteRequest(uint32_t code, OHOS::MessageParcel &data, OHOS::MessageParcel &reply, OHOS::MessageOption &option) override; ~HdfRemoteServiceStub(); -- Gitee From 0da035eda6a85b7bf8dfe2b6c840da242a3599dc Mon Sep 17 00:00:00 2001 From: zhang Date: Wed, 23 Mar 2022 15:36:53 +0800 Subject: [PATCH 035/102] fix: modify the review problem of osal Signed-off-by: zhang --- khdf/liteos/osal/src/osal_firmware.c | 2 +- khdf/liteos/osal/src/osal_thread.c | 6 +++--- khdf/liteos/osal/src/osal_workqueue.c | 2 +- khdf/liteos_m/osal/src/osal_thread.c | 6 +++--- uhdf2/hdi/test/reg_pnp_device/hdf_dev_reg_pnp_test.c | 4 ++-- .../hdi/test/reg_virtual_device/hdf_dev_reg_virtual_test.c | 2 +- uhdf2/manager/src/devmgr_query_device.c | 4 ++-- uhdf2/manager/src/devmgr_service_stub.c | 2 +- uhdf2/osal/src/osal_sysevent.c | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/khdf/liteos/osal/src/osal_firmware.c b/khdf/liteos/osal/src/osal_firmware.c index 9b578fa..b7a3d55 100644 --- a/khdf/liteos/osal/src/osal_firmware.c +++ b/khdf/liteos/osal/src/osal_firmware.c @@ -127,7 +127,7 @@ int32_t OsalReadFirmware(struct OsalFirmware *fwPara, struct OsalFwBlock *block) } fw = (struct OsalFwDesc *)fwPara->para; - if (fw->openFlag == false) { + if (!fw->openFlag) { HDF_LOGE("%s file do not open", __func__); return HDF_ERR_INVALID_PARAM; } diff --git a/khdf/liteos/osal/src/osal_thread.c b/khdf/liteos/osal/src/osal_thread.c index 7897c58..b3e37f4 100644 --- a/khdf/liteos/osal/src/osal_thread.c +++ b/khdf/liteos/osal/src/osal_thread.c @@ -174,7 +174,7 @@ int32_t OsalThreadSuspend(struct OsalThread *thread) bool flag = false; flag = OsalCheckPara(thread); - if (flag == false) { + if (!flag) { HDF_LOGE("%s invalid parameter %d\n", __func__, __LINE__); return HDF_ERR_INVALID_PARAM; } @@ -193,7 +193,7 @@ int32_t OsalThreadDestroy(struct OsalThread *thread) bool flag = false; flag = OsalCheckPara(thread); - if (flag == false) { + if (!flag) { HDF_LOGE("%s invalid parameter %d\n", __func__, __LINE__); return HDF_ERR_INVALID_PARAM; } @@ -210,7 +210,7 @@ int32_t OsalThreadResume(struct OsalThread *thread) bool flag = false; flag = OsalCheckPara(thread); - if (flag == false) { + if (!flag) { HDF_LOGE("%s invalid parameter %d\n", __func__, __LINE__); return HDF_ERR_INVALID_PARAM; } diff --git a/khdf/liteos/osal/src/osal_workqueue.c b/khdf/liteos/osal/src/osal_workqueue.c index e39c23c..22348b0 100644 --- a/khdf/liteos/osal/src/osal_workqueue.c +++ b/khdf/liteos/osal/src/osal_workqueue.c @@ -170,7 +170,7 @@ bool HdfAddWork(HdfWorkQueue *queue, HdfWork *work) return queue_work(queue->realWorkQueue, &((struct WorkWrapper *)work->realWork)->work.work); } -bool HdfAddDelayedWork(HdfWorkQueue *queue, HdfWork *work, unsigned long ms) +bool HdfAddDelayedWork(HdfWorkQueue *queue, HdfWork *work, uint32_t ms) { if (queue == NULL || queue->realWorkQueue == NULL || work == NULL || work->realWork == NULL) { HDF_LOGE("%s invalid para", __func__); diff --git a/khdf/liteos_m/osal/src/osal_thread.c b/khdf/liteos_m/osal/src/osal_thread.c index af025da..d84b29f 100644 --- a/khdf/liteos_m/osal/src/osal_thread.c +++ b/khdf/liteos_m/osal/src/osal_thread.c @@ -167,7 +167,7 @@ int32_t OsalThreadSuspend(struct OsalThread *thread) bool flag = false; flag = OsalCheckPara(thread); - if (flag == false) { + if (!flag) { HDF_LOGE("%s invalid parameter %d", __func__, __LINE__); return HDF_ERR_INVALID_PARAM; } @@ -186,7 +186,7 @@ int32_t OsalThreadDestroy(struct OsalThread *thread) bool flag = false; flag = OsalCheckPara(thread); - if (flag == false) { + if (!flag) { HDF_LOGE("%s invalid parameter %d", __func__, __LINE__); return HDF_ERR_INVALID_PARAM; } @@ -203,7 +203,7 @@ int32_t OsalThreadResume(struct OsalThread *thread) bool flag = false; flag = OsalCheckPara(thread); - if (flag == false) { + if (!flag) { HDF_LOGE("%s invalid parameter %d", __func__, __LINE__); return HDF_ERR_INVALID_PARAM; } diff --git a/uhdf2/hdi/test/reg_pnp_device/hdf_dev_reg_pnp_test.c b/uhdf2/hdi/test/reg_pnp_device/hdf_dev_reg_pnp_test.c index e8dcac0..bf486f0 100644 --- a/uhdf2/hdi/test/reg_pnp_device/hdf_dev_reg_pnp_test.c +++ b/uhdf2/hdi/test/reg_pnp_device/hdf_dev_reg_pnp_test.c @@ -202,7 +202,7 @@ static void HdfRegPnpDriverTest_005() struct HdfRemoteService *remote = HdfRemoteServiceGet("pnp_driver_service_1"); UT_TEST_CHECK_RET(remote == NULL); if (ret == HDF_SUCCESS) { - HdfUnRegPnpDevice("libpnp_driver1.so", "pnp_driver_service1"); + (void)HdfUnRegPnpDevice("libpnp_driver1.so", "pnp_driver_service1"); } } @@ -230,7 +230,7 @@ static void HdfRegPnpDriverTest_006() uint64_t timeAfter = OsalGetSysTimeMs(); totalTime += timeAfter - timeBefor; } - printf("total time is %ld \n", totalTime); + printf("total time is %lu \n", totalTime); UT_TEST_CHECK_RET((totalTime / 1000) < 20); } diff --git a/uhdf2/hdi/test/reg_virtual_device/hdf_dev_reg_virtual_test.c b/uhdf2/hdi/test/reg_virtual_device/hdf_dev_reg_virtual_test.c index a7b00ec..c6b08eb 100644 --- a/uhdf2/hdi/test/reg_virtual_device/hdf_dev_reg_virtual_test.c +++ b/uhdf2/hdi/test/reg_virtual_device/hdf_dev_reg_virtual_test.c @@ -77,7 +77,7 @@ void PrintTestResult() static void CalcAverageTime(int index, bool type, const OsalTimespec *diff, const char *func, int line) { - if (type == true) { + if (type) { HDF_LOGD("[HDF_TEST] %{public}s line:%{public}d test 1 time use time:%{public}lu s %{public}lu us", func, line, diff->sec, diff->usec); printf("[HDF_TEST] %s line:%d test 1 time use time:%lu s %lu us\r\n", func, line, diff->sec, diff->usec); diff --git a/uhdf2/manager/src/devmgr_query_device.c b/uhdf2/manager/src/devmgr_query_device.c index eaf3a8f..7231d23 100644 --- a/uhdf2/manager/src/devmgr_query_device.c +++ b/uhdf2/manager/src/devmgr_query_device.c @@ -52,12 +52,12 @@ int DevFillQueryDeviceInfo(struct IDevmgrService *inst, struct HdfSBuf *data, st if ((deviceInfo->policy == SERVICE_POLICY_CAPACITY || deviceInfo->policy == SERVICE_POLICY_PUBLIC) && deviceInfo->status == status) { flag = HdfSbufWriteString(reply, deviceInfo->svcName); - if (flag == false) { + if (!flag) { HDF_LOGE("%{public}s writing string failed %{public}s", __func__, deviceInfo->svcName); return HDF_FAILURE; } flag = HdfSbufWriteInt32(reply, deviceInfo->deviceType); - if (flag == false) { + if (!flag) { HDF_LOGE("%{public}s writing int32 failed %{public}d", __func__, deviceInfo->deviceType); return HDF_FAILURE; } diff --git a/uhdf2/manager/src/devmgr_service_stub.c b/uhdf2/manager/src/devmgr_service_stub.c index 38abb5b..25f8ed2 100644 --- a/uhdf2/manager/src/devmgr_service_stub.c +++ b/uhdf2/manager/src/devmgr_service_stub.c @@ -264,7 +264,7 @@ int DevmgrServiceStubStartService(struct IDevmgrService *inst) } fullService->remote = remoteService; - DriverModuleLoadHelperInit(); + (void)DriverModuleLoadHelperInit(); return DevmgrServiceStartService((struct IDevmgrService *)&fullService->super); } diff --git a/uhdf2/osal/src/osal_sysevent.c b/uhdf2/osal/src/osal_sysevent.c index 74e2555..9b9d0d8 100644 --- a/uhdf2/osal/src/osal_sysevent.c +++ b/uhdf2/osal/src/osal_sysevent.c @@ -115,7 +115,7 @@ static int OnKEventReceived( } if (receivedEvent->syncToken != 0) { - FinishEvent(service, receivedEvent); + (void)FinishEvent(service, receivedEvent); } OsalMutexUnlock(¬ifier->mutex); -- Gitee From b26bd0e57725829abdbc622a2d4c5a1493f629c7 Mon Sep 17 00:00:00 2001 From: yuanbo Date: Thu, 24 Mar 2022 16:11:20 +0800 Subject: [PATCH 036/102] fix: remove redundant test code Signed-off-by: yuanbo --- .../sample_client_c/sample_client_c_test.cpp | 335 ------- .../sample_client_c/unittest/BUILD.gn | 44 - .../sample_client_c/unittest/isample.h | 101 --- .../sample_client_c/unittest/sample_proxy.c | 844 ------------------ .../sample_client_cpp_test.cpp | 300 ------- .../sample_client_cpp/unittest/BUILD.gn | 51 -- .../sample_client_cpp/unittest/isample.h | 127 --- .../unittest/sample_proxy.cpp | 421 --------- .../sample_client_cpp/unittest/sample_proxy.h | 72 -- .../test/hdi_sample/sample_service_c/BUILD.gn | 45 - .../hdi_sample/sample_service_c/isample.h | 95 -- .../sample_service_c/sample_driver.c | 69 -- .../sample_service_c/sample_service.c | 167 ---- .../sample_service_c/sample_service_stub.c | 488 ---------- .../hdi_sample/sample_service_cpp/BUILD.gn | 49 - .../hdi_sample/sample_service_cpp/isample.h | 102 --- .../sample_service_cpp/sample_driver.cpp | 87 -- .../sample_service_cpp/sample_service.cpp | 128 --- .../sample_service_cpp/sample_service.h | 69 -- .../sample_service_stub.cpp | 484 ---------- .../sample_service_cpp/sample_service_stub.h | 67 -- .../reg_pnp_device/hdf_dev_reg_pnp_test.c | 326 ------- .../unittest/sample_driver/hdf_pnp_driver.c | 111 --- .../unittest/sample_driver/hdf_pnp_driver.h | 37 - .../hdf_dev_reg_virtual_test.c | 344 ------- .../sample_driver/hdf_virtual_driver.c | 54 -- 26 files changed, 5017 deletions(-) delete mode 100644 uhdf2/hdi/test/hdi_sample/sample_client_c/sample_client_c_test.cpp delete mode 100644 uhdf2/hdi/test/hdi_sample/sample_client_c/unittest/BUILD.gn delete mode 100644 uhdf2/hdi/test/hdi_sample/sample_client_c/unittest/isample.h delete mode 100644 uhdf2/hdi/test/hdi_sample/sample_client_c/unittest/sample_proxy.c delete mode 100644 uhdf2/hdi/test/hdi_sample/sample_client_cpp/sample_client_cpp_test.cpp delete mode 100644 uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/BUILD.gn delete mode 100644 uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/isample.h delete mode 100644 uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.cpp delete mode 100644 uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.h delete mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_c/BUILD.gn delete mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_c/isample.h delete mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_c/sample_driver.c delete mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_c/sample_service.c delete mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_c/sample_service_stub.c delete mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_cpp/BUILD.gn delete mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_cpp/isample.h delete mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_driver.cpp delete mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service.cpp delete mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service.h delete mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.cpp delete mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.h delete mode 100644 uhdf2/hdi/test/reg_pnp_device/hdf_dev_reg_pnp_test.c delete mode 100644 uhdf2/hdi/test/reg_pnp_device/unittest/sample_driver/hdf_pnp_driver.c delete mode 100644 uhdf2/hdi/test/reg_pnp_device/unittest/sample_driver/hdf_pnp_driver.h delete mode 100644 uhdf2/hdi/test/reg_virtual_device/hdf_dev_reg_virtual_test.c delete mode 100644 uhdf2/hdi/test/reg_virtual_device/unittest/sample_driver/hdf_virtual_driver.c diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_c/sample_client_c_test.cpp b/uhdf2/hdi/test/hdi_sample/sample_client_c/sample_client_c_test.cpp deleted file mode 100644 index 481b28f..0000000 --- a/uhdf2/hdi/test/hdi_sample/sample_client_c/sample_client_c_test.cpp +++ /dev/null @@ -1,335 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include "securec.h" -#include "isample.h" - -using namespace OHOS; -using namespace testing::ext; - -#define HDF_LOG_TAG sample_client_c_test - -constexpr const char *TEST_SERVICE_NAME = "sample_service_c"; - -class SampleObjCTest : public testing::Test { -public: - static void SetUpTestCase(){} - static void TearDownTestCase(){} - void SetUp(){} - void TearDown(){} -}; - -HWTEST_F(SampleObjCTest, SampleObjCTest_001, TestSize.Level1) -{ - struct ISample *sampleObj = HdiSampleGet(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - bool input = true; - bool output = false; - - int32_t ec = sampleObj->BooleanTypeTest(sampleObj, input, &output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_TRUE(output); - - HdiSampleRelease(sampleObj); -} - -HWTEST_F(SampleObjCTest, SampleObjCTest_002, TestSize.Level1) -{ - struct ISample *sampleObj = HdiSampleGet(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - int8_t input = 10; - int8_t output; - - int32_t ec = sampleObj->ByteTypeTest(sampleObj, input, &output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input, output); - - HdiSampleRelease(sampleObj); -} - -HWTEST_F(SampleObjCTest, SampleObjCTest_003, TestSize.Level1) -{ - struct ISample *sampleObj = HdiSampleGet(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - int16_t input = 10; - int16_t output; - - int32_t ec = sampleObj->ShortTypeTest(sampleObj, input, &output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input, output); - - HdiSampleRelease(sampleObj); -} - -HWTEST_F(SampleObjCTest, SampleObjCTest_004, TestSize.Level1) -{ - struct ISample *sampleObj = HdiSampleGet(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - int32_t input = 10; - int32_t output; - - int32_t ec = sampleObj->IntTypeTest(sampleObj, input, &output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input, output); - - HdiSampleRelease(sampleObj); -} - -HWTEST_F(SampleObjCTest, SampleObjCTest_005, TestSize.Level1) -{ - struct ISample *sampleObj = HdiSampleGet(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - int64_t input = 10; - int64_t output; - - int32_t ec = sampleObj->LongTypeTest(sampleObj, input, &output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input, output); - - HdiSampleRelease(sampleObj); -} - -HWTEST_F(SampleObjCTest, SampleObjCTest_006, TestSize.Level1) -{ - struct ISample *sampleObj = HdiSampleGet(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - float input = 10; - float output; - - int32_t ec = sampleObj->FloatTypeTest(sampleObj, input, &output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input, output); - - HdiSampleRelease(sampleObj); -} - -HWTEST_F(SampleObjCTest, SampleObjCTest_007, TestSize.Level1) -{ - struct ISample *sampleObj = HdiSampleGet(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - double input = 10; - double output; - - int32_t ec = sampleObj->DoubleTypeTest(sampleObj, input, &output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input, output); - - HdiSampleRelease(sampleObj); -} - -HWTEST_F(SampleObjCTest, SampleObjCTest_008, TestSize.Level1) -{ - struct ISample *sampleObj = HdiSampleGet(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - const char *input = "c sample client test"; - char *output = nullptr; - - int32_t ec = sampleObj->StringTypeTest(sampleObj, input, &output); - - ASSERT_EQ(ec, HDF_SUCCESS); - EXPECT_STREQ(input, output); - - HdiSampleRelease(sampleObj); -} - -HWTEST_F(SampleObjCTest, SampleObjCTest_009, TestSize.Level1) -{ - struct ISample *sampleObj = HdiSampleGet(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - uint8_t input = 10; - uint8_t output; - - int32_t ec = sampleObj->UcharTypeTest(sampleObj, input, &output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input, output); - - HdiSampleRelease(sampleObj); -} - -HWTEST_F(SampleObjCTest, SampleObjCTest_010, TestSize.Level1) -{ - struct ISample *sampleObj = HdiSampleGet(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - uint16_t input = 10; - uint16_t output; - - int32_t ec = sampleObj->UshortTypeTest(sampleObj, input, &output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input, output); - - HdiSampleRelease(sampleObj); -} - -HWTEST_F(SampleObjCTest, SampleObjCTest_011, TestSize.Level1) -{ - struct ISample *sampleObj = HdiSampleGet(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - uint32_t input = 10; - uint32_t output; - - int32_t ec = sampleObj->UintTypeTest(sampleObj, input, &output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input, output); - - HdiSampleRelease(sampleObj); -} - -HWTEST_F(SampleObjCTest, SampleObjCTest_012, TestSize.Level1) -{ - struct ISample *sampleObj = HdiSampleGet(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - uint64_t input = 10; - uint64_t output; - - int32_t ec = sampleObj->UlongTypeTest(sampleObj, input, &output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input, output); - - HdiSampleRelease(sampleObj); -} - -HWTEST_F(SampleObjCTest, SampleObjCTest_013, TestSize.Level1) -{ - struct ISample *sampleObj = HdiSampleGet(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - uint32_t inSize = 5; - int8_t *input = (int8_t *)OsalMemAlloc(sizeof(int8_t) * inSize); - ASSERT_TRUE(input != nullptr); - - for (uint32_t i = 0; i < inSize; i++) { - input[i] = static_cast(i); - } - - uint32_t outSize = 0; - int8_t *output = nullptr; - - int32_t ec = sampleObj->ListTypeTest(sampleObj, input, inSize, &output, &outSize); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_TRUE(output != nullptr); - ASSERT_EQ(outSize, inSize); - - for (uint32_t i = 0; i < outSize; i++) { - ASSERT_EQ(output[i], input[i]); - } - - if (input != nullptr) { - OsalMemFree(input); - } - if (output != nullptr) { - OsalMemFree(output); - } -} - -HWTEST_F(SampleObjCTest, SampleObjCTest_014, TestSize.Level1) -{ - struct ISample *sampleObj = HdiSampleGet(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - uint32_t inSize = 5; - int8_t *input = (int8_t *)OsalMemAlloc(sizeof(int8_t) * inSize); - ASSERT_TRUE(input != nullptr); - - for (uint32_t i = 0; i < inSize; i++) { - input[i] = static_cast(i); - } - - uint32_t outSize = 0; - int8_t *output = nullptr; - - int32_t ec = sampleObj->ArrayTypeTest(sampleObj, input, inSize, &output, &outSize); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_TRUE(output != nullptr); - ASSERT_EQ(outSize, inSize); - - for (uint32_t i = 0; i < outSize; i++) { - ASSERT_EQ(output[i], input[i]); - } - - if (input != nullptr) { - OsalMemFree(input); - } - if (output != nullptr) { - OsalMemFree(output); - } -} - -HWTEST_F(SampleObjCTest, SampleObjCTest_015, TestSize.Level1) -{ - struct ISample *sampleObj = HdiSampleGet(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - struct StructSample input = { - .first = 1, - .second = 2, - }; - - struct StructSample output; - int32_t ec = sampleObj->StructTypeTest(sampleObj, &input, &output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(output.first, input.first); - ASSERT_EQ(output.second, input.second); - - HdiSampleRelease(sampleObj); -} - -HWTEST_F(SampleObjCTest, SampleObjCTest_016, TestSize.Level1) -{ - struct ISample *sampleObj = HdiSampleGet(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - enum EnumSample input = MEM_SECOND; - enum EnumSample output; - - int32_t ec = sampleObj->EnumTypeTest(sampleObj, input, &output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input, output); - - HdiSampleRelease(sampleObj); -} - diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_c/unittest/BUILD.gn b/uhdf2/hdi/test/hdi_sample/sample_client_c/unittest/BUILD.gn deleted file mode 100644 index d470c79..0000000 --- a/uhdf2/hdi/test/hdi_sample/sample_client_c/unittest/BUILD.gn +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//drivers/adapter/uhdf2/uhdf.gni") -group("sample_client_c") { - deps = [ ":libsample_client_c" ] -} - -ohos_shared_library("libsample_client_c") { - include_dirs = [ - "$hdf_uhdf_path/manager/include", - "$hdf_uhdf_path/include/hdi", - ] - - sources = [ "sample_proxy.c" ] - - deps = [ - "$hdf_uhdf_path/hdi:libhdi", - "//drivers/adapter/uhdf2/host:libhdf_host", - "//drivers/adapter/uhdf2/ipc:libhdf_ipc_adapter", - "//drivers/adapter/uhdf2/utils:libhdf_utils", - ] - - if (is_standard_system) { - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] - } else { - external_deps = [ "hilog:libhilog" ] - } - - install_images = [ chipset_base_dir ] - subsystem_name = "hdf" - part_name = "device_driver_framework" -} diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_c/unittest/isample.h b/uhdf2/hdi/test/hdi_sample/sample_client_c/unittest/isample.h deleted file mode 100644 index 6aef4c0..0000000 --- a/uhdf2/hdi/test/hdi_sample/sample_client_c/unittest/isample.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef HDI_SAMPLE_CLIENT_C_INF_H -#define HDI_SAMPLE_CLIENT_C_INF_H - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -struct HdfRemoteService; - -struct StructSample { - int8_t first; - int16_t second; -}; - -enum EnumSample { - MEM_FIRST, - MEM_SECOND, - MEM_THIRD, -}; - -enum { - CMD_BOOLEAN_TYPE_TEST, - CMD_BYTE_TYPE_TEST, - CMD_SHORT_TYPE_TEST, - CMD_INT_TYPE_TEST, - CMD_LONG_TYPE_TEST, - CMD_FLOAT_TYPE_TEST, - CMD_DOUBLE_TYPE_TEST, - CMD_STRING_TYPE_TEST, - CMD_UCHAR_TYPE_TEST, - CMD_USHORT_TYPE_TEST, - CMD_UINT_TYPE_TEST, - CMD_ULONG_TYPE_TEST, - CMD_LIST_TYPE_TEST, - CMD_ARRAY_TYPE_TEST, - CMD_STRUCT_TYPE_TEST, - CMD_ENUM_TYPE_TEST, -}; - -struct ISample { - struct HdfRemoteService *remote; - - int32_t (*BooleanTypeTest)(struct ISample *self, const bool input, bool *output); - - int32_t (*ByteTypeTest)(struct ISample *self, const int8_t input, int8_t *output); - - int32_t (*ShortTypeTest)(struct ISample *self, const int16_t input, int16_t *output); - - int32_t (*IntTypeTest)(struct ISample *self, const int32_t input, int32_t *output); - - int32_t (*LongTypeTest)(struct ISample *self, const int64_t input, int64_t *output); - - int32_t (*FloatTypeTest)(struct ISample *self, const float input, float *output); - - int32_t (*DoubleTypeTest)(struct ISample *self, const double input, double *output); - - int32_t (*StringTypeTest)(struct ISample *self, const char* input, char **output); - - int32_t (*UcharTypeTest)(struct ISample *self, const uint8_t input, uint8_t *output); - - int32_t (*UshortTypeTest)(struct ISample *self, const uint16_t input, uint16_t *output); - - int32_t (*UintTypeTest)(struct ISample *self, const uint32_t input, uint32_t *output); - - int32_t (*UlongTypeTest)(struct ISample *self, const uint64_t input, uint64_t *output); - - int32_t (*ListTypeTest)(struct ISample *self, const int8_t *input, const uint32_t inSize, - int8_t **output, uint32_t *outSize); - - int32_t (*ArrayTypeTest)(struct ISample *self, const int8_t *input, const uint32_t inSize, - int8_t **output, uint32_t *outSize); - - int32_t (*StructTypeTest)(struct ISample *self, const struct StructSample *input, struct StructSample *output); - - int32_t (*EnumTypeTest)(struct ISample *self, const enum EnumSample input, enum EnumSample *output); -}; - -struct ISample *HdiSampleGet(const char *serviceName); - -void HdiSampleRelease(struct ISample *instance); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif // HDI_SAMPLE_CLIENT_C_INF_H \ No newline at end of file diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_c/unittest/sample_proxy.c b/uhdf2/hdi/test/hdi_sample/sample_client_c/unittest/sample_proxy.c deleted file mode 100644 index 68384d5..0000000 --- a/uhdf2/hdi/test/hdi_sample/sample_client_c/unittest/sample_proxy.c +++ /dev/null @@ -1,844 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include -#include -#include -#include -#include - -#include "isample.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -static int32_t SampleProxyCall(struct ISample *self, - int32_t id, struct HdfSBuf *data, struct HdfSBuf *reply) -{ - if (self->remote == NULL || self->remote->dispatcher == NULL || - self->remote->dispatcher->Dispatch == NULL) { - HDF_LOGE("%{public}s: obj is null", __func__); - return HDF_ERR_INVALID_OBJECT; - } - return self->remote->dispatcher->Dispatch(self->remote, id, data, reply); -} - -static int32_t SampleProxyBooleanTypeTest(struct ISample *self, const bool input, bool *output) -{ - int32_t ec = HDF_FAILURE; - if (self == NULL) { - return HDF_ERR_INVALID_PARAM; - } - - struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); - struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); - - if (data == NULL || reply == NULL) { - HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); - ec = HDF_ERR_MALLOC_FAIL; - goto finished; - } - - if (!HdfSbufWriteUint32(data, (uint32_t)input)) { - HDF_LOGE("%{public}s: write bool input failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto finished; - } - - ec = SampleProxyCall(self, CMD_BOOLEAN_TYPE_TEST, data, reply); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec); - goto finished; - } - - if (!HdfSbufReadUint32(reply, (uint32_t *)output)) { - HDF_LOGE("%{public}s: read result failed!", __func__); - goto finished; - } - -finished: - if (data != NULL) { - HdfSbufRecycle(data); - } - if (reply != NULL) { - HdfSbufRecycle(reply); - } - return ec; -} - -static int32_t SampleProxyByteTypeTest(struct ISample *self, const int8_t input, int8_t *output) -{ - int32_t ec = HDF_FAILURE; - if (self == NULL) { - return HDF_ERR_INVALID_PARAM; - } - - struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); - struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); - - if (data == NULL || reply == NULL) { - ec = HDF_ERR_MALLOC_FAIL; - goto finished; - } - - if (!HdfSbufWriteInt8(data, input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto finished; - } - - ec = SampleProxyCall(self, CMD_BYTE_TYPE_TEST, data, reply); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec); - goto finished; - } - - if (!HdfSbufReadInt8(reply, output)) { - HDF_LOGE("%{public}s: read result failed!", __func__); - goto finished; - } - -finished: - if (data != NULL) { - HdfSbufRecycle(data); - } - if (reply != NULL) { - HdfSbufRecycle(reply); - } - return ec; -} - -static int32_t SampleProxyShortTypeTest(struct ISample *self, const int16_t input, int16_t *output) -{ - int32_t ec = HDF_FAILURE; - if (self == NULL) { - return HDF_ERR_INVALID_PARAM; - } - - struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); - struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); - - if (data == NULL || reply == NULL) { - ec = HDF_ERR_MALLOC_FAIL; - goto finished; - } - - if (!HdfSbufWriteInt16(data, input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto finished; - } - - ec = SampleProxyCall(self, CMD_SHORT_TYPE_TEST, data, reply); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec); - goto finished; - } - - if (!HdfSbufReadInt16(reply, output)) { - HDF_LOGE("%{public}s: read result failed!", __func__); - goto finished; - } - -finished: - if (data != NULL) { - HdfSbufRecycle(data); - } - if (reply != NULL) { - HdfSbufRecycle(reply); - } - return ec; -} - -static int32_t SampleProxyIntTypeTest(struct ISample *self, const int32_t input, int32_t *output) -{ - int32_t ec = HDF_FAILURE; - if (self == NULL) { - return HDF_ERR_INVALID_PARAM; - } - - struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); - struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); - - if (data == NULL || reply == NULL) { - ec = HDF_ERR_MALLOC_FAIL; - goto finished; - } - - if (!HdfSbufWriteInt32(data, input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto finished; - } - - ec = SampleProxyCall(self, CMD_INT_TYPE_TEST, data, reply); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec); - goto finished; - } - - if (!HdfSbufReadInt32(reply, output)) { - HDF_LOGE("%{public}s: read result failed!", __func__); - goto finished; - } - -finished: - if (data != NULL) { - HdfSbufRecycle(data); - } - if (reply != NULL) { - HdfSbufRecycle(reply); - } - return ec; -} - -static int32_t SampleProxyLongTypeTest(struct ISample *self, const int64_t input, int64_t *output) -{ - int32_t ec = HDF_FAILURE; - if (self == NULL) { - return HDF_ERR_INVALID_PARAM; - } - - struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); - struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); - - if (data == NULL || reply == NULL) { - ec = HDF_ERR_MALLOC_FAIL; - goto finished; - } - - if (!HdfSbufWriteInt64(data, input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto finished; - } - - ec = SampleProxyCall(self, CMD_LONG_TYPE_TEST, data, reply); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec); - goto finished; - } - - if (!HdfSbufReadInt64(reply, output)) { - HDF_LOGE("%{public}s: read result failed!", __func__); - goto finished; - } - -finished: - if (data != NULL) { - HdfSbufRecycle(data); - } - if (reply != NULL) { - HdfSbufRecycle(reply); - } - return ec; -} - -static int32_t SampleProxyFloatTypeTest(struct ISample *self, const float input, float *output) -{ - int32_t ec = HDF_FAILURE; - if (self == NULL) { - return HDF_ERR_INVALID_PARAM; - } - - struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); - struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); - - if (data == NULL || reply == NULL) { - ec = HDF_ERR_MALLOC_FAIL; - goto finished; - } - - if (!HdfSbufWriteFloat(data, input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto finished; - } - - ec = SampleProxyCall(self, CMD_FLOAT_TYPE_TEST, data, reply); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec); - goto finished; - } - - if (!HdfSbufReadFloat(reply, output)) { - HDF_LOGE("%{public}s: read result failed!", __func__); - goto finished; - } - -finished: - if (data != NULL) { - HdfSbufRecycle(data); - } - if (reply != NULL) { - HdfSbufRecycle(reply); - } - - return ec; -} - -static int32_t SampleProxyDoubleTypeTest(struct ISample *self, const double input, double *output) -{ - int32_t ec = HDF_FAILURE; - if (self == NULL) { - return HDF_ERR_INVALID_PARAM; - } - - struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); - struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); - - if (data == NULL || reply == NULL) { - ec = HDF_ERR_MALLOC_FAIL; - goto finished; - } - - if (!HdfSbufWriteDouble(data, input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto finished; - } - - ec = SampleProxyCall(self, CMD_DOUBLE_TYPE_TEST, data, reply); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec); - goto finished; - } - - if (!HdfSbufReadDouble(reply, output)) { - HDF_LOGE("%{public}s: read result failed!", __func__); - goto finished; - } - -finished: - if (data != NULL) { - HdfSbufRecycle(data); - } - if (reply != NULL) { - HdfSbufRecycle(reply); - } - - return ec; -} - -static int32_t SampleProxyStringTypeTest(struct ISample *self, const char* input, char **output) -{ - int32_t ec = HDF_FAILURE; - if (self == NULL || input == NULL) { - return HDF_ERR_INVALID_PARAM; - } - - struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); - struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); - - if (data == NULL || reply == NULL) { - ec = HDF_ERR_MALLOC_FAIL; - goto finished; - } - - if (!HdfSbufWriteString(data, input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto finished; - } - - ec = SampleProxyCall(self, CMD_STRING_TYPE_TEST, data, reply); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec); - goto finished; - } - - const char *result = HdfSbufReadString(reply); - if (result == NULL) { - HDF_LOGE("%{public}s: read result failed!", __func__); - goto finished; - } - *output = strdup(result); - -finished: - if (data != NULL) { - HdfSbufRecycle(data); - } - if (reply != NULL) { - HdfSbufRecycle(reply); - } - return ec; -} - -static int32_t SampleProxyUcharTypeTest(struct ISample *self, const uint8_t input, uint8_t *output) -{ - int32_t ec = HDF_FAILURE; - if (self == NULL) { - return HDF_ERR_INVALID_PARAM; - } - - struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); - struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); - - if (data == NULL || reply == NULL) { - ec = HDF_ERR_MALLOC_FAIL; - goto finished; - } - - if (!HdfSbufWriteUint8(data, input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto finished; - } - - ec = SampleProxyCall(self, CMD_UCHAR_TYPE_TEST, data, reply); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec); - goto finished; - } - - if (!HdfSbufReadUint8(reply, output)) { - HDF_LOGE("%{public}s: read result failed!", __func__); - goto finished; - } - -finished: - if (data != NULL) { - HdfSbufRecycle(data); - } - if (reply != NULL) { - HdfSbufRecycle(reply); - } - return ec; -} - -static int32_t SampleProxyUshortTypeTest(struct ISample *self, const uint16_t input, uint16_t *output) -{ - int32_t ec = HDF_FAILURE; - if (self == NULL) { - return HDF_ERR_INVALID_PARAM; - } - - struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); - struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); - - if (data == NULL || reply == NULL) { - ec = HDF_ERR_MALLOC_FAIL; - goto finished; - } - - if (!HdfSbufWriteUint16(data, input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto finished; - } - - ec = SampleProxyCall(self, CMD_USHORT_TYPE_TEST, data, reply); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec); - goto finished; - } - - if (!HdfSbufReadUint16(reply, output)) { - HDF_LOGE("%{public}s: read result failed!", __func__); - goto finished; - } - -finished: - if (data != NULL) { - HdfSbufRecycle(data); - } - if (reply != NULL) { - HdfSbufRecycle(reply); - } - return ec; -} - -static int32_t SampleProxyUintTypeTest(struct ISample *self, const uint32_t input, uint32_t *output) -{ - int32_t ec = HDF_FAILURE; - if (self == NULL) { - return HDF_ERR_INVALID_PARAM; - } - - struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); - struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); - - if (data == NULL || reply == NULL) { - ec = HDF_ERR_MALLOC_FAIL; - goto finished; - } - - if (!HdfSbufWriteUint32(data, input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto finished; - } - - ec = SampleProxyCall(self, CMD_UINT_TYPE_TEST, data, reply); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec); - goto finished; - } - - if (!HdfSbufReadUint32(reply, output)) { - HDF_LOGE("%{public}s: read result failed!", __func__); - goto finished; - } - -finished: - if (data != NULL) { - HdfSbufRecycle(data); - } - if (reply != NULL) { - HdfSbufRecycle(reply); - } - return ec; -} - -static int32_t SampleProxyUlongTypeTest(struct ISample *self, const uint64_t input, uint64_t *output) -{ - int32_t ec = HDF_FAILURE; - if (self == NULL) { - return HDF_ERR_INVALID_PARAM; - } - - struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); - struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); - - if (data == NULL || reply == NULL) { - ec = HDF_ERR_MALLOC_FAIL; - goto finished; - } - - if (!HdfSbufWriteUint64(data, input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto finished; - } - - ec = SampleProxyCall(self, CMD_ULONG_TYPE_TEST, data, reply); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec); - goto finished; - } - - if (!HdfSbufReadUint64(reply, output)) { - HDF_LOGE("%{public}s: read result failed!", __func__); - goto finished; - } - -finished: - if (data != NULL) { - HdfSbufRecycle(data); - } - if (reply != NULL) { - HdfSbufRecycle(reply); - } - return ec; -} - -static int32_t SampleProxyListTypeTest(struct ISample *self, const int8_t *input, const uint32_t inSize, - int8_t **output, uint32_t *outSize) -{ - int32_t ec = HDF_FAILURE; - if (self == NULL || input == NULL) { - return HDF_ERR_INVALID_PARAM; - } - - struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); - struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); - - if (data == NULL || reply == NULL) { - ec = HDF_ERR_MALLOC_FAIL; - goto finished; - } - - if (!HdfSbufWriteUint32(data, inSize)) { - HDF_LOGE("%{public}s: write input size failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto finished; - } - - for (uint32_t i = 0; i < inSize; i++) { - if (!HdfSbufWriteInt8(data, input[i])) { - HDF_LOGE("%{public}s: write input[%{public}d] failed!", __func__, i); - ec = HDF_ERR_INVALID_PARAM; - goto finished; - } - } - - ec = SampleProxyCall(self, CMD_LIST_TYPE_TEST, data, reply); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec); - goto finished; - } - - if (!HdfSbufReadUint32(reply, outSize)) { - HDF_LOGE("%{public}s: read output size failed!", __func__); - goto finished; - } - - if (*outSize == 0) { - HDF_LOGE("%{public}s: read outSize = %{public}d", __func__, *outSize); - goto finished; - } - - int8_t *result = (int8_t *)OsalMemAlloc(sizeof(int8_t) * (*outSize)); - if (result == NULL) { - HDF_LOGE("%{public}s: malloc output failed!", __func__); - goto finished; - } - - for (uint32_t i = 0; i < *outSize; i++) { - if (!HdfSbufReadInt8(reply, &(result[i]))) { - HDF_LOGE("%{public}s: read output[%{public}d] failed!", __func__, i); - OsalMemFree(result); - goto finished; - } - } - *output = result; - -finished: - if (data != NULL) { - HdfSbufRecycle(data); - } - if (reply != NULL) { - HdfSbufRecycle(reply); - } - return ec; -} - -static int32_t SampleProxyArrayTypeTest(struct ISample *self, const int8_t *input, const uint32_t inSize, - int8_t **output, uint32_t *outSize) -{ - int32_t ec = HDF_FAILURE; - if (self == NULL || input == NULL) { - return HDF_ERR_INVALID_PARAM; - } - - struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); - struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); - - if (data == NULL || reply == NULL) { - ec = HDF_ERR_MALLOC_FAIL; - goto finished; - } - - if (!HdfSbufWriteUint32(data, inSize)) { - HDF_LOGE("%{public}s: write input size failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto finished; - } - - for (uint32_t i = 0; i < inSize; i++) { - if (!HdfSbufWriteInt8(data, input[i])) { - HDF_LOGE("%{public}s: write input[%{public}d] failed!", __func__, i); - ec = HDF_ERR_INVALID_PARAM; - goto finished; - } - } - - ec = SampleProxyCall(self, CMD_ARRAY_TYPE_TEST, data, reply); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec); - goto finished; - } - - if (!HdfSbufReadUint32(reply, outSize)) { - HDF_LOGE("%{public}s: read output size failed!", __func__); - goto finished; - } - - if (*outSize == 0) { - HDF_LOGE("%{public}s: read outSize = %{public}d", __func__, *outSize); - goto finished; - } - - int8_t *result = (int8_t *)OsalMemAlloc(sizeof(int8_t) * (*outSize)); - if (result == NULL) { - HDF_LOGE("%{public}s: malloc output failed!", __func__); - goto finished; - } - - for (uint32_t i = 0; i < *outSize; i++) { - if (!HdfSbufReadInt8(reply, &(result[i]))) { - HDF_LOGE("%{public}s: read output[%{public}d] failed!", __func__, i); - OsalMemFree(result); - goto finished; - } - } - *output = result; - -finished: - if (data != NULL) { - HdfSbufRecycle(data); - } - if (reply != NULL) { - HdfSbufRecycle(reply); - } - return ec; -} - -static int32_t SampleProxyStructTypeTest(struct ISample *self, const struct StructSample *input, - struct StructSample *output) -{ - int32_t ec = HDF_FAILURE; - if (self == NULL) { - return HDF_ERR_INVALID_PARAM; - } - - struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); - struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); - if (data == NULL || reply == NULL) { - ec = HDF_ERR_MALLOC_FAIL; - goto finished; - } - - if (!HdfSbufWriteBuffer(data, (const void *)input, sizeof(struct StructSample))) { - HDF_LOGE("%{public}s: write struct StructSample input failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto finished; - } - - ec = SampleProxyCall(self, CMD_STRUCT_TYPE_TEST, data, reply); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec); - goto finished; - } - - struct StructSample *result = NULL; - uint32_t outSize = 0; - if (!HdfSbufReadBuffer(reply, (const void **)&result, &outSize)) { - HDF_LOGE("%{public}s: read struct StructSample result failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto finished; - } - - if (result == NULL || outSize != sizeof(struct StructSample)) { - HDF_LOGE("%{public}s: result is error", __func__); - ec = HDF_ERR_INVALID_PARAM; - } - output->first = result->first; - output->second = result->second; - -finished: - if (data != NULL) { - HdfSbufRecycle(data); - } - if (reply != NULL) { - HdfSbufRecycle(reply); - } - return ec; -} - -static int32_t SampleProxyEnumTypeTest(struct ISample *self, const enum EnumSample input, enum EnumSample *output) -{ - int32_t ec = HDF_FAILURE; - if (self == NULL) { - return HDF_ERR_INVALID_PARAM; - } - - struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); - struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); - - if (data == NULL || reply == NULL) { - ec = HDF_ERR_MALLOC_FAIL; - goto finished; - } - - if (!HdfSbufWriteUint32(data, (uint32_t)input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto finished; - } - - ec = SampleProxyCall(self, CMD_ENUM_TYPE_TEST, data, reply); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec); - goto finished; - } - - if (!HdfSbufReadUint32(reply, (uint32_t *)output)) { - HDF_LOGE("%{public}s: read result failed!", __func__); - goto finished; - } - -finished: - if (data != NULL) { - HdfSbufRecycle(data); - } - if (reply != NULL) { - HdfSbufRecycle(reply); - } - return ec; -} - -static void SampleConstruct(struct ISample *inst) -{ - inst->BooleanTypeTest = SampleProxyBooleanTypeTest; - inst->ByteTypeTest = SampleProxyByteTypeTest; - inst->ShortTypeTest = SampleProxyShortTypeTest; - inst->IntTypeTest = SampleProxyIntTypeTest; - inst->LongTypeTest = SampleProxyLongTypeTest; - inst->FloatTypeTest = SampleProxyFloatTypeTest; - inst->DoubleTypeTest = SampleProxyDoubleTypeTest; - inst->StringTypeTest = SampleProxyStringTypeTest; - inst->UcharTypeTest = SampleProxyUcharTypeTest; - inst->UshortTypeTest = SampleProxyUshortTypeTest; - inst->UintTypeTest = SampleProxyUintTypeTest; - inst->UlongTypeTest = SampleProxyUlongTypeTest; - inst->ListTypeTest = SampleProxyListTypeTest; - inst->ArrayTypeTest = SampleProxyArrayTypeTest; - inst->StructTypeTest = SampleProxyStructTypeTest; - inst->EnumTypeTest = SampleProxyEnumTypeTest; -} - -struct ISample *HdiSampleGet(const char *serviceName) -{ - struct HDIServiceManager *serviceMgr = HDIServiceManagerGet(); - if (serviceMgr == NULL) { - HDF_LOGE("%{public}s: HDIServiceManager not found!", __func__); - return NULL; - } - - struct HdfRemoteService *remote = serviceMgr->GetService(serviceMgr, serviceName); - if (remote == NULL) { - HDF_LOGE("%{public}s: HdfRemoteService not found!", __func__); - return NULL; - } - - struct ISample *sampleClient = (struct ISample *)OsalMemAlloc(sizeof(struct ISample)); - if (sampleClient == NULL) { - HDF_LOGE("%{public}s: malloc sample instance failed!", __func__); - HdfRemoteServiceRecycle(remote); - return NULL; - } - - sampleClient->remote = remote; - SampleConstruct(sampleClient); - return sampleClient; -} - -void HdiSampleRelease(struct ISample *instance) -{ - if (instance == NULL) { - return; - } - - HdfRemoteServiceRecycle(instance->remote); - OsalMemFree(instance); -} - -#ifdef __cplusplus -} -#endif /* __cplusplus */ \ No newline at end of file diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/sample_client_cpp_test.cpp b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/sample_client_cpp_test.cpp deleted file mode 100644 index 030eb93..0000000 --- a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/sample_client_cpp_test.cpp +++ /dev/null @@ -1,300 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include -#include -#include -#include -#include -#include -#include "securec.h" -#include "sample_proxy.h" - -using namespace OHOS; -using namespace testing::ext; -using namespace OHOS::HDI::Sample::V1_0; - -#define HDF_LOG_TAG sample_client_cpp_test - -constexpr const char *TEST_SERVICE_NAME = "sample_service_cpp"; - -class SampleObjCPPTest : public testing::Test { -public: - static void SetUpTestCase(){} - static void TearDownTestCase(){} - void SetUp(){} - void TearDown(){} -}; - -HWTEST_F(SampleObjCPPTest, SampleObjCPPTest_001, TestSize.Level1) -{ - sptr sampleObj = ISample::Get(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - bool input = true; - bool output = false; - - int32_t ec = sampleObj->BooleanTypeTest(input, output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(output, input); -} - -HWTEST_F(SampleObjCPPTest, SampleObjCPPTest_002, TestSize.Level1) -{ - sptr sampleObj = ISample::Get(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - int8_t input = 5; - int8_t output; - - int32_t ec = sampleObj->ByteTypeTest(input, output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input, output); -} - -HWTEST_F(SampleObjCPPTest, SampleObjCPPTest_003, TestSize.Level1) -{ - sptr sampleObj = ISample::Get(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - int16_t input = 5; - int16_t output; - - int32_t ec = sampleObj->ShortTypeTest(input, output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input, output); -} - -HWTEST_F(SampleObjCPPTest, SampleObjCPPTest_004, TestSize.Level1) -{ - sptr sampleObj = ISample::Get(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - int32_t input = 5; - int32_t output; - - int32_t ec = sampleObj->IntTypeTest(input, output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input, output); -} - -HWTEST_F(SampleObjCPPTest, SampleObjCPPTest_005, TestSize.Level1) -{ - sptr sampleObj = ISample::Get(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - int64_t input = 5; - int64_t output; - - int32_t ec = sampleObj->LongTypeTest(input, output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input, output); -} - -HWTEST_F(SampleObjCPPTest, SampleObjCPPTest_006, TestSize.Level1) -{ - sptr sampleObj = ISample::Get(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - float input = 5; - float output; - - int32_t ec = sampleObj->FloatTypeTest(input, output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input, output); -} - -HWTEST_F(SampleObjCPPTest, SampleObjCPPTest_007, TestSize.Level1) -{ - sptr sampleObj = ISample::Get(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - double input = 5; - double output; - - int32_t ec = sampleObj->DoubleTypeTest(input, output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input, output); -} - -HWTEST_F(SampleObjCPPTest, SampleObjCPPTest_008, TestSize.Level1) -{ - sptr sampleObj = ISample::Get(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - std::string input("cpp sample client test"); - std::string output; - - int32_t ec = sampleObj->StringTypeTest(input, output); - - ASSERT_EQ(ec, HDF_SUCCESS); - EXPECT_EQ(input, output); -} - -HWTEST_F(SampleObjCPPTest, SampleObjCPPTest_009, TestSize.Level1) -{ - sptr sampleObj = ISample::Get(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - uint8_t input = 5; - uint8_t output; - - int32_t ec = sampleObj->UcharTypeTest(input, output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input, output); -} - -HWTEST_F(SampleObjCPPTest, SampleObjCPPTest_010, TestSize.Level1) -{ - sptr sampleObj = ISample::Get(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - uint16_t input = 5; - uint16_t output; - - int32_t ec = sampleObj->UshortTypeTest(input, output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input, output); -} - -HWTEST_F(SampleObjCPPTest, SampleObjCPPTest_011, TestSize.Level1) -{ - sptr sampleObj = ISample::Get(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - uint32_t input = 5; - uint32_t output; - - int32_t ec = sampleObj->UintTypeTest(input, output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input, output); -} -HWTEST_F(SampleObjCPPTest, SampleObjCPPTest_012, TestSize.Level1) -{ - sptr sampleObj = ISample::Get(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - uint64_t input = 5; - uint64_t output; - - int32_t ec = sampleObj->UlongTypeTest(input, output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input, output); -} - -HWTEST_F(SampleObjCPPTest, SampleObjCPPTest_013, TestSize.Level1) -{ - sptr sampleObj = ISample::Get(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - std::list input{1, 2, 3, 4, 5}; - std::list output; - - int32_t ec = sampleObj->ListTypeTest(input, output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(output.size(), input.size()); - - auto inIter = input.begin(); - auto outIter = output.begin(); - while (inIter != input.end() && outIter != output.end()) { - ASSERT_EQ(*(inIter++), *(outIter++)); - } -} - -HWTEST_F(SampleObjCPPTest, SampleObjCPPTest_014, TestSize.Level1) -{ - sptr sampleObj = ISample::Get(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - std::map input; - for (int8_t i = 0; i < 10; i++) { - input[i] = i; - } - std::map output; - - int32_t ec = sampleObj->MapTypeTest(input, output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input.size(), output.size()); - - std::map::iterator inIter = input.begin(); - for (; inIter != input.begin(); inIter++) { - std::map::iterator outIter = output.find(inIter->first); - - ASSERT_TRUE(outIter != output.end()); - ASSERT_EQ(outIter->second, inIter->second); - } -} - -HWTEST_F(SampleObjCPPTest, SampleObjCPPTest_015, TestSize.Level1) -{ - sptr sampleObj = ISample::Get(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - std::vector input; - std::vector output; - - int32_t ec = sampleObj->ArrayTypeTest(input, output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(input.size(), output.size()); - - for (uint32_t i = 0; i < output.size(); i++) { - ASSERT_EQ(output[i], input[i]); - } -} - -HWTEST_F(SampleObjCPPTest, SampleObjCPPTest_016, TestSize.Level1) -{ - sptr sampleObj = ISample::Get(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - StructSample input = { - .first = 5, - .second = 10, - }; - - StructSample output; - int32_t ec = sampleObj->StructTypeTest(input, output); - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(output.first, input.first); - ASSERT_EQ(output.second, input.second); -} - -HWTEST_F(SampleObjCPPTest, SampleObjCPPTest_017, TestSize.Level1) -{ - sptr sampleObj = ISample::Get(TEST_SERVICE_NAME); - ASSERT_TRUE(sampleObj != nullptr); - - EnumSample input = EnumSample::MEM_SECOND; - EnumSample output; - - int32_t ec = sampleObj->EnumTypeTest(input, output); - - ASSERT_EQ(ec, HDF_SUCCESS); - ASSERT_EQ(output, input); -} diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/BUILD.gn b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/BUILD.gn deleted file mode 100644 index bcd6a51..0000000 --- a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/BUILD.gn +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//drivers/adapter/uhdf2/uhdf.gni") -group("sample_client_cpp") { - deps = [ ":libsample_client_cpp" ] -} - -ohos_shared_library("libsample_client_cpp") { - include_dirs = [ - "$hdf_uhdf_path/manager/include", - "$hdf_uhdf_path/include/hdi", - ] - - sources = [ "sample_proxy.cpp" ] - - deps = [ - "$hdf_uhdf_path/hdi:libhdi", - "//drivers/adapter/uhdf2/host:libhdf_host", - "//drivers/adapter/uhdf2/ipc:libhdf_ipc_adapter", - "//drivers/adapter/uhdf2/utils:libhdf_utils", - ] - - if (is_standard_system) { - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_single", - "utils_base:utils", - ] - } else { - external_deps = [ - "hilog:libhilog", - "ipc:ipc_single", - ] - } - - install_images = [ chipset_base_dir ] - subsystem_name = "hdf" - part_name = "device_driver_framework" -} diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/isample.h b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/isample.h deleted file mode 100644 index 95733d8..0000000 --- a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/isample.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef HDI_SAMPLE_CLIENT_CPP_INF_H -#define HDI_SAMPLE_CLIENT_CPP_INF_H - -#include -#include -#include -#include -#include - -namespace OHOS { -namespace HDI { -namespace Sample { -namespace V1_0 { -struct StructSample { - int8_t first; - int16_t second; -}; - -enum EnumSample { - MEM_FIRST, - MEM_SECOND, - MEM_THIRD, -}; - - -enum { - CMD_BOOLEAN_TYPE_TEST, - CMD_BYTE_TYPE_TEST, - CMD_SHORT_TYPE_TEST, - CMD_INT_TYPE_TEST, - CMD_LONG_TYPE_TEST, - CMD_FLOAT_TYPE_TEST, - CMD_DOUBLE_TYPE_TEST, - CMD_STRING_TYPE_TEST, - CMD_UCHAR_TYPE_TEST, - CMD_USHORT_TYPE_TEST, - CMD_UINT_TYPE_TEST, - CMD_ULONG_TYPE_TEST, - CMD_LIST_TYPE_TEST, - CMD_MAP_TYPE_TEST, - CMD_ARRAY_TYPE_TEST, - CMD_STRUCT_TYPE_TEST, - CMD_ENUM_TYPE_TEST, -}; - -class ISample : public IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"HDI.Sample.V1_0"); - - virtual ~ISample(){} - - static sptr Get(const std::string& serviceName); - - virtual int32_t BooleanTypeTest(const bool input, bool& output) = 0; - - virtual int32_t ByteTypeTest(const int8_t input, int8_t& output) = 0; - - virtual int32_t ShortTypeTest(const int16_t input, int16_t& output) = 0; - - virtual int32_t IntTypeTest(const int32_t input, int32_t& output) = 0; - - virtual int32_t LongTypeTest(const int64_t input, int64_t& output) = 0; - - virtual int32_t FloatTypeTest(const float input, float& output) = 0; - - virtual int32_t DoubleTypeTest(const double input, double& output) = 0; - - virtual int32_t StringTypeTest(const std::string& input, std::string& output) = 0; - - virtual int32_t UcharTypeTest(const uint8_t input, uint8_t& output) = 0; - - virtual int32_t UshortTypeTest(const uint16_t input, uint16_t& output) = 0; - - virtual int32_t UintTypeTest(const uint32_t input, uint32_t& output) = 0; - - virtual int32_t UlongTypeTest(const uint64_t input, uint64_t& output) = 0; - - virtual int32_t ListTypeTest(const std::list& input, std::list& output) = 0; - - virtual int32_t MapTypeTest(const std::map& input, std::map& output) = 0; - - virtual int32_t ArrayTypeTest(const std::vector& input, std::vector& output) = 0; - - virtual int32_t StructTypeTest(const StructSample& input, StructSample& output) = 0; - - virtual int32_t EnumTypeTest(const EnumSample& input, EnumSample& output) = 0; -}; - -sptr ISample::Get(const std::string& serviceName) -{ - do { - using namespace OHOS::HDI::ServiceManager::V1_0; - auto servMgr = IServiceManager::Get(); - if (servMgr == nullptr) { - break; - } - - sptr remote = servMgr->GetService(serviceName.c_str()); - if (remote != nullptr) { - return iface_cast(remote); - } - } while(false); - - HDF_LOGE("%{public}s: get %{public}s failed!", __func__, serviceName.c_str()); - return nullptr; -} -} // namespace V1_0 -} // namespace Sample -} // namespace HDI -} // namespace OHOS - -#endif // HDI_SAMPLE_CLIENT_CPP_INF_H \ No newline at end of file diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.cpp b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.cpp deleted file mode 100644 index 7fd2e3d..0000000 --- a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.cpp +++ /dev/null @@ -1,421 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "sample_proxy.h" -#include -#include - -namespace OHOS { -namespace HDI { -namespace Sample { -namespace V1_0 { -int32_t SampleProxy::BooleanTypeTest(const bool input, bool& output) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteBool(input)) { - HDF_LOGE("%{public}s: write bool input failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = Remote()->SendRequest(CMD_BOOLEAN_TYPE_TEST, data, reply, option); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ec); - return ec; - } - output = reply.ReadBool(); - - return HDF_SUCCESS; -} - -int32_t SampleProxy::ByteTypeTest(const int8_t input, int8_t& output) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInt8(input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = Remote()->SendRequest(CMD_BYTE_TYPE_TEST, data, reply, option); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ec); - return ec; - } - output = reply.ReadInt8(); - - return HDF_SUCCESS; -} - -int32_t SampleProxy::ShortTypeTest(const int16_t input, int16_t& output) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInt16(input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = Remote()->SendRequest(CMD_SHORT_TYPE_TEST, data, reply, option); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ec); - return ec; - } - output = reply.ReadInt16(); - - return HDF_SUCCESS; -} - -int32_t SampleProxy::IntTypeTest(const int32_t input, int32_t& output) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInt32(input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = Remote()->SendRequest(CMD_INT_TYPE_TEST, data, reply, option); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ec); - return ec; - } - output = reply.ReadInt32(); - - return HDF_SUCCESS; -} - -int32_t SampleProxy::LongTypeTest(const int64_t input, int64_t& output) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInt64(input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = Remote()->SendRequest(CMD_LONG_TYPE_TEST, data, reply, option); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ec); - return ec; - } - output = reply.ReadInt64(); - - return HDF_SUCCESS; -} - -int32_t SampleProxy::FloatTypeTest(const float input, float& output) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteFloat(input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = Remote()->SendRequest(CMD_FLOAT_TYPE_TEST, data, reply, option); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ec); - return ec; - } - output = reply.ReadFloat(); - - return HDF_SUCCESS; -} - -int32_t SampleProxy::DoubleTypeTest(const double input, double& output) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteDouble(input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = Remote()->SendRequest(CMD_DOUBLE_TYPE_TEST, data, reply, option); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ec); - return ec; - } - output = reply.ReadDouble(); - - return HDF_SUCCESS; -} - -int32_t SampleProxy::StringTypeTest(const std::string& input, std::string& output) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteString(input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = Remote()->SendRequest(CMD_STRING_TYPE_TEST, data, reply, option); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ec); - return ec; - } - output = reply.ReadString(); - - return HDF_SUCCESS; -} - -int32_t SampleProxy::UcharTypeTest(const uint8_t input, uint8_t& output) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteUint8(input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = Remote()->SendRequest(CMD_UCHAR_TYPE_TEST, data, reply, option); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ec); - return ec; - } - output = reply.ReadUint8(); - - return HDF_SUCCESS; -} - -int32_t SampleProxy::UshortTypeTest(const uint16_t input, uint16_t& output) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteUint16(input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = Remote()->SendRequest(CMD_UCHAR_TYPE_TEST, data, reply, option); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ec); - return ec; - } - output = reply.ReadUint16(); - - return HDF_SUCCESS; -} - -int32_t SampleProxy::UintTypeTest(const uint32_t input, uint32_t& output) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteUint32(input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = Remote()->SendRequest(CMD_UINT_TYPE_TEST, data, reply, option); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ec); - return ec; - } - output = reply.ReadUint32(); - - return HDF_SUCCESS; -} - -int32_t SampleProxy::UlongTypeTest(const uint64_t input, uint64_t& output) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteUint64(input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = Remote()->SendRequest(CMD_ULONG_TYPE_TEST, data, reply, option); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ec); - return ec; - } - output = reply.ReadUint64(); - - return HDF_SUCCESS; -} - -int32_t SampleProxy::ListTypeTest(const std::list& input, std::list& output) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteUint32(input.size())) { - HDF_LOGE("%{public}s: write input size failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - for (auto it : input) { - if (!data.WriteUint8(it)) { - HDF_LOGE("%{public}s: write input data failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - } - - int32_t ec = Remote()->SendRequest(CMD_LIST_TYPE_TEST, data, reply, option); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ec); - return ec; - } - - uint32_t outSize = reply.ReadUint32(); - for (uint32_t i = 0; i < outSize; i++) { - uint8_t curData = reply.ReadUint8(); - output.push_back(curData); - } - - return HDF_SUCCESS; -} - -int32_t SampleProxy::MapTypeTest(const std::map& input, std::map& output) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteUint32(input.size())) { - HDF_LOGE("%{public}s: write input size failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - for (auto it : input) { - if (!data.WriteUint8(it.first)) { - HDF_LOGE("%{public}s: write input data->first failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!data.WriteUint8(it.second)) { - HDF_LOGE("%{public}s: write input data->second failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - } - - int32_t ec = Remote()->SendRequest(CMD_MAP_TYPE_TEST, data, reply, option); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ec); - return ec; - } - - uint32_t outSize = reply.ReadUint32(); - for (uint32_t i = 0; i < outSize; i++) { - uint8_t key = reply.ReadUint8(); - uint8_t val = reply.ReadUint8(); - output[key] = val; - } - - return HDF_SUCCESS; -} - - -int32_t SampleProxy::ArrayTypeTest(const std::vector& input, std::vector& output) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInt8Vector(input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = Remote()->SendRequest(CMD_ARRAY_TYPE_TEST, data, reply, option); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ec); - return ec; - } - reply.ReadInt8Vector(&output); - - return HDF_SUCCESS; -} - -int32_t SampleProxy::StructTypeTest(const StructSample& input, StructSample& output) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteBuffer((void *)&input, sizeof(StructSample))) { - HDF_LOGE("%{public}s: write input data failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = Remote()->SendRequest(CMD_STRUCT_TYPE_TEST, data, reply, option); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ec); - return ec; - } - - StructSample *result = (StructSample *)data.ReadBuffer(sizeof(StructSample)); - if (result == nullptr) { - HDF_LOGE("%{public}s: read output failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - output.first = result->first; - output.second = result->second; - return HDF_SUCCESS; -} - -int32_t SampleProxy::EnumTypeTest(const EnumSample& input, EnumSample& output) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteUint32((uint32_t)input)) { - HDF_LOGE("%{public}s: write input failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = Remote()->SendRequest(CMD_ENUM_TYPE_TEST, data, reply, option); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ec); - return ec; - } - output = (EnumSample)reply.ReadUint32(); - - return HDF_SUCCESS; -} -} // namespace V1_0 -} // namespace Sample -} // namespace HDI -} // namespace OHOS \ No newline at end of file diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.h b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.h deleted file mode 100644 index 4ddc29f..0000000 --- a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef HDI_SAMPLE_CLIENT_PROXY_CPP_INF_H -#define HDI_SAMPLE_CLIENT_PROXY_CPP_INF_H - -#include -#include "isample.h" - -namespace OHOS { -namespace HDI { -namespace Sample { -namespace V1_0 { -class SampleProxy : public IRemoteProxy { -public: - explicit SampleProxy(const sptr& impl) : IRemoteProxy(impl) {} - virtual ~SampleProxy() override {} - - virtual int32_t BooleanTypeTest(const bool input, bool& output) override; - - virtual int32_t ByteTypeTest(const int8_t input, int8_t& output) override; - - virtual int32_t ShortTypeTest(const int16_t input, int16_t& output) override; - - virtual int32_t IntTypeTest(const int32_t input, int32_t& output) override; - - virtual int32_t LongTypeTest(const int64_t input, int64_t& output) override; - - virtual int32_t FloatTypeTest(const float input, float& output) override; - - virtual int32_t DoubleTypeTest(const double input, double& output) override; - - virtual int32_t StringTypeTest(const std::string& input, std::string& output) override; - - virtual int32_t UcharTypeTest(const uint8_t input, uint8_t& output) override; - - virtual int32_t UshortTypeTest(const uint16_t input, uint16_t& output) override; - - virtual int32_t UintTypeTest(const uint32_t input, uint32_t& output) override; - - virtual int32_t UlongTypeTest(const uint64_t input, uint64_t& output) override; - - virtual int32_t ListTypeTest(const std::list& input, std::list& output) override; - - virtual int32_t MapTypeTest(const std::map& input, std::map& output) override; - - virtual int32_t ArrayTypeTest(const std::vector& input, std::vector& output) override; - - virtual int32_t StructTypeTest(const StructSample& input, StructSample& output) override; - - virtual int32_t EnumTypeTest(const EnumSample& input, EnumSample& output) override; - -private: - static inline BrokerDelegator delegator_; -}; -} // namespace V1_0 -} // namespace Sample -} // namespace HDI -} // namespace OHOS - -#endif // HDI_SAMPLE_CLIENT_PROXY_CPP_INF_H \ No newline at end of file diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_c/BUILD.gn b/uhdf2/hdi/test/hdi_sample/sample_service_c/BUILD.gn deleted file mode 100644 index ea2da6b..0000000 --- a/uhdf2/hdi/test/hdi_sample/sample_service_c/BUILD.gn +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//drivers/adapter/uhdf2/uhdf.gni") -group("sample_service_c") { - deps = [ ":libsample_service_c" ] -} - -ohos_shared_library("libsample_service_c") { - sources = [ - "sample_driver.c", - "sample_service.c", - "sample_service_stub.c", - ] - - deps = [ - "//drivers/adapter/uhdf2/host:libhdf_host", - "//drivers/adapter/uhdf2/ipc:libhdf_ipc_adapter", - "//drivers/adapter/uhdf2/utils:libhdf_utils", - ] - - if (is_standard_system) { - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "utils_base:utils", - ] - } else { - external_deps = [ "hilog:libhilog" ] - } - - install_images = [ chipset_base_dir ] - subsystem_name = "hdf" - part_name = "device_driver_framework" -} diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_c/isample.h b/uhdf2/hdi/test/hdi_sample/sample_service_c/isample.h deleted file mode 100644 index 5842145..0000000 --- a/uhdf2/hdi/test/hdi_sample/sample_service_c/isample.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef HDI_SAMPLE_C_INF_H -#define HDI_SAMPLE_C_INF_H - -struct HdfSBuf; -struct HdfDeviceObject; -struct HdfDeviceIoClient; - -struct StructSample { - int8_t first; - int16_t second; -}; - -enum EnumSample { - MEM_FIRST, - MEM_SECOND, - MEM_THIRD, -}; - -enum { - CMD_BOOLEAN_TYPE_TEST, - CMD_BYTE_TYPE_TEST, - CMD_SHORT_TYPE_TEST, - CMD_INT_TYPE_TEST, - CMD_LONG_TYPE_TEST, - CMD_FLOAT_TYPE_TEST, - CMD_DOUBLE_TYPE_TEST, - CMD_STRING_TYPE_TEST, - CMD_UCHAR_TYPE_TEST, - CMD_USHORT_TYPE_TEST, - CMD_UINT_TYPE_TEST, - CMD_ULONG_TYPE_TEST, - CMD_LIST_TYPE_TEST, - CMD_ARRAY_TYPE_TEST, - CMD_STRUCT_TYPE_TEST, - CMD_ENUM_TYPE_TEST, -}; - -struct ISample { - int32_t (*BooleanTypeTest)(struct HdfDeviceObject *device, const bool input, bool *output); - - int32_t (*ByteTypeTest)(struct HdfDeviceObject *device, const int8_t input, int8_t *output); - - int32_t (*ShortTypeTest)(struct HdfDeviceObject *device, const int16_t input, int16_t *output); - - int32_t (*IntTypeTest)(struct HdfDeviceObject *device, const int32_t input, int32_t *output); - - int32_t (*LongTypeTest)(struct HdfDeviceObject *device, const int64_t input, int64_t *output); - - int32_t (*FloatTypeTest)(struct HdfDeviceObject *device, const float input, float *output); - - int32_t (*DoubleTypeTest)(struct HdfDeviceObject *device, const double input, double *output); - - int32_t (*StringTypeTest)(struct HdfDeviceObject *device, const char *input, char **output); - - int32_t (*UcharTypeTest)(struct HdfDeviceObject *device, const uint8_t input, uint8_t *output); - - int32_t (*UshortTypeTest)(struct HdfDeviceObject *device, const uint16_t input, uint16_t *output); - - int32_t (*UintTypeTest)(struct HdfDeviceObject *device, const uint32_t input, uint32_t *output); - - int32_t (*UlongTypeTest)(struct HdfDeviceObject *device, const uint64_t input, uint64_t *output); - - int32_t (*ListTypeTest)(struct HdfDeviceObject *device, const int8_t *input, const uint32_t inSize, - int8_t **output, uint32_t *outSize); - - int32_t (*ArrayTypeTest)(struct HdfDeviceObject *device, const int8_t *input, const uint32_t inSize, - int8_t **output, uint32_t *outSize); - - int32_t (*StructTypeTest)(struct HdfDeviceObject *device, const struct StructSample *input, - struct StructSample *output); - - int32_t (*EnumTypeTest)(struct HdfDeviceObject *device, const enum EnumSample input, enum EnumSample *output); -}; - -const struct ISample *HdiSampleImplInstance(); - -int32_t SampleServiceOnRemoteRequest(struct HdfDeviceIoClient *client, int cmdId, - struct HdfSBuf *data, struct HdfSBuf *reply); - -#endif // HDI_SAMPLE_C_INF_H \ No newline at end of file diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_c/sample_driver.c b/uhdf2/hdi/test/hdi_sample/sample_service_c/sample_driver.c deleted file mode 100644 index 3b64cf1..0000000 --- a/uhdf2/hdi/test/hdi_sample/sample_service_c/sample_driver.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -#include "isample.h" - -#define HDF_LOG_TAG sample_service_c - -static int32_t SampleServiceDispatch(struct HdfDeviceIoClient *client, int cmdId, - struct HdfSBuf *data, struct HdfSBuf *reply) -{ - return SampleServiceOnRemoteRequest(client, cmdId, data, reply); -} - -void HdfSampleDriverRelease(struct HdfDeviceObject *deviceObject) -{ - struct IDeviceIoService *testService = deviceObject->service; - OsalMemFree(testService); -} - -int HdfSampleDriverBind(struct HdfDeviceObject *deviceObject) -{ - HDF_LOGE("HdfSampleDriverBind enter!"); - - struct IDeviceIoService *ioService = (struct IDeviceIoService *)OsalMemAlloc(sizeof(struct IDeviceIoService)); - if (ioService == NULL) { - HDF_LOGE("HdfSampleDriverBind OsalMemAlloc IDeviceIoService failed!"); - return HDF_FAILURE; - } - - ioService->Dispatch = SampleServiceDispatch; - ioService->Open = NULL; - ioService->Release = NULL; - - deviceObject->service = ioService; - return HDF_SUCCESS; -} - -int HdfSampleDriverInit(struct HdfDeviceObject *deviceObject) -{ - HDF_LOGE("HdfSampleDriverCInit enter, new hdi impl"); - return HDF_SUCCESS; -} - -struct HdfDriverEntry g_sampleDriverEntry = { - .moduleVersion = 1, - .moduleName = "sample_service_c", - .Bind = HdfSampleDriverBind, - .Init = HdfSampleDriverInit, - .Release = HdfSampleDriverRelease, -}; - -HDF_INIT(g_sampleDriverEntry); \ No newline at end of file diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_c/sample_service.c b/uhdf2/hdi/test/hdi_sample/sample_service_c/sample_service.c deleted file mode 100644 index 332585b..0000000 --- a/uhdf2/hdi/test/hdi_sample/sample_service_c/sample_service.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -#include "isample.h" - -static int32_t HdiBooleanTypeTestImpl(struct HdfDeviceObject *device, const bool input, bool *output) -{ - *output = input; - return HDF_SUCCESS; -} - -static int32_t HdiByteTypeTestImpl(struct HdfDeviceObject *device, const int8_t input, int8_t *output) -{ - *output = input; - return HDF_SUCCESS; -} - -static int32_t HdiShortTypeTestImpl(struct HdfDeviceObject *device, const int16_t input, int16_t *output) -{ - *output = input; - return HDF_SUCCESS; -} - -static int32_t HdiIntTypeTestImpl(struct HdfDeviceObject *device, const int32_t input, int32_t *output) -{ - *output = input; - return HDF_SUCCESS; -} - -static int32_t HdiLongTypeTestImpl(struct HdfDeviceObject *device, const int64_t input, int64_t *output) -{ - *output = input; - return HDF_SUCCESS; -} - -static int32_t HdiFloatTypeTestImpl(struct HdfDeviceObject *device, const float input, float *output) -{ - *output = input; - return HDF_SUCCESS; -} - -static int32_t HdiDoubleTypeTestImpl(struct HdfDeviceObject *device, const double input, double *output) -{ - *output = input; - return HDF_SUCCESS; -} - -static int32_t HdiStringTypeTestImpl(struct HdfDeviceObject *device, const char *input, char **output) -{ - *output = strdup(input); - return HDF_SUCCESS; -} - -static int32_t HdiUcharTypeTestImpl(struct HdfDeviceObject *device, const uint8_t input, uint8_t *output) -{ - *output = input; - return HDF_SUCCESS; -} - -static int32_t HdiUshortTypeTestImpl(struct HdfDeviceObject *device, const uint16_t input, uint16_t *output) -{ - *output = input; - return HDF_SUCCESS; -} - -static int32_t HdiUintTypeTestImpl(struct HdfDeviceObject *device, const uint32_t input, uint32_t *output) -{ - *output = input; - return HDF_SUCCESS; -} - -static int32_t HdiUlongTypeTestImpl(struct HdfDeviceObject *device, const uint64_t input, uint64_t *output) -{ - *output = input; - return HDF_SUCCESS; -} - -static int32_t HdiListTypeTestImpl(struct HdfDeviceObject *device, const int8_t *input, const uint32_t inSize, - int8_t **output, uint32_t *outSize) -{ - int8_t *result = (int8_t*)OsalMemAlloc(sizeof(int8_t) * inSize); - if (result == NULL) { - HDF_LOGE("%{public}s: result OsalMemAlloc failed", __func__); - return HDF_ERR_MALLOC_FAIL; - } - - for (uint32_t i = 0; i < inSize; i++) { - result[i] = input[i]; - } - - *output = result; - *outSize = inSize; - return HDF_SUCCESS; -} - -static int32_t HdiArrayTypeTestImpl(struct HdfDeviceObject *device, const int8_t *input, const uint32_t inSize, - int8_t **output, uint32_t *outSize) -{ - int8_t *result = (int8_t*)OsalMemAlloc(sizeof(int8_t) * inSize); - if (result == NULL) { - HDF_LOGE("%{public}s: result OsalMemAlloc failed", __func__); - return HDF_ERR_MALLOC_FAIL; - } - - for (uint32_t i = 0; i < inSize; i++) { - result[i] = input[i]; - } - - *output = result; - *outSize = inSize; - return HDF_SUCCESS; -} - -static int32_t HdiStructTypeTestImpl(struct HdfDeviceObject *device, const struct StructSample *input, - struct StructSample *output) -{ - output->first = input->first; - output->second = input->second; - return HDF_SUCCESS; -} - -static int32_t HdiEnumTypeTestImpl(struct HdfDeviceObject *device, const enum EnumSample input, enum EnumSample *output) -{ - *output = input; - return HDF_SUCCESS; -} - -static const struct ISample g_hdiSampleImpl = { - .BooleanTypeTest = HdiBooleanTypeTestImpl, - .ByteTypeTest = HdiByteTypeTestImpl, - .ShortTypeTest = HdiShortTypeTestImpl, - .IntTypeTest = HdiIntTypeTestImpl, - .LongTypeTest = HdiLongTypeTestImpl, - .FloatTypeTest = HdiFloatTypeTestImpl, - .DoubleTypeTest = HdiDoubleTypeTestImpl, - .StringTypeTest = HdiStringTypeTestImpl, - .UcharTypeTest = HdiUcharTypeTestImpl, - .UshortTypeTest = HdiUshortTypeTestImpl, - .UintTypeTest = HdiUintTypeTestImpl, - .UlongTypeTest = HdiUlongTypeTestImpl, - .ListTypeTest = HdiListTypeTestImpl, - .ArrayTypeTest = HdiArrayTypeTestImpl, - .StructTypeTest = HdiStructTypeTestImpl, - .EnumTypeTest = HdiEnumTypeTestImpl, -}; - -const struct ISample *HdiSampleImplInstance() -{ - return &g_hdiSampleImpl; -} diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_c/sample_service_stub.c b/uhdf2/hdi/test/hdi_sample/sample_service_c/sample_service_stub.c deleted file mode 100644 index b9e37c9..0000000 --- a/uhdf2/hdi/test/hdi_sample/sample_service_c/sample_service_stub.c +++ /dev/null @@ -1,488 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -#include "isample.h" - - -static int32_t SerStubBooleanTypeTest(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) -{ - bool input = false; - bool output = false; - if (!HdfSbufReadUint32(data, (uint32_t *)&input)) { - HDF_LOGE("%{public}s: read bool data failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = HdiSampleImplInstance()->BooleanTypeTest(client->device, input, &output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call BooleanTypeTest fuc failed!", __func__); - return ec; - } - - if (!HdfSbufWriteUint32(reply, (uint32_t)&output)) { - HDF_LOGE("%{public}s: write bool output failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return ec; -} - -static int32_t SerStubByteTypeTest(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) -{ - int8_t input; - int8_t output; - if (!HdfSbufReadInt8(data, &input)) { - HDF_LOGE("%{public}s: read int8_t data failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = HdiSampleImplInstance()->ByteTypeTest(client->device, input, &output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call ByteTypeTest failed!", __func__); - return ec; - } - - if (!HdfSbufWriteInt8(reply, output)) { - HDF_LOGE("%{public}s: write int8_t output failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - return ec; -} - -static int32_t SerStubShortTypeTest(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) -{ - int16_t input; - int16_t output; - if (!HdfSbufReadInt16(data, &input)) { - HDF_LOGE("%{public}s: read int16_t data failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = HdiSampleImplInstance()->ShortTypeTest(client->device, input, &output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call ShortTypeTest failed!", __func__); - return ec; - } - - if (!HdfSbufWriteInt16(reply, output)) { - HDF_LOGE("%{public}s: write int16_t output failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - return ec; -} - -static int32_t SerStubIntTypeTest(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) -{ - int32_t input; - int32_t output; - if (!HdfSbufReadInt32(data, &input)) { - HDF_LOGE("%{public}s: read int32_t data failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = HdiSampleImplInstance()->IntTypeTest(client->device, input, &output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call IntTypeTest failed!", __func__); - return ec; - } - - if (!HdfSbufWriteInt32(reply, output)) { - HDF_LOGE("%{public}s: write int32_t output failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - return ec; -} - -static int32_t SerStubLongTypeTest(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) -{ - int64_t input; - int64_t output; - if (!HdfSbufReadInt64(data, &input)) { - HDF_LOGE("%{public}s: read int64_t data failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = HdiSampleImplInstance()->LongTypeTest(client->device, input, &output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call LongTypeTest failed!", __func__); - return ec; - } - - if (!HdfSbufWriteInt64(reply, output)) { - HDF_LOGE("%{public}s: write int64_t output failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return ec; -} - -static int32_t SerStubFloatTypeTest(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) -{ - float input; - float output; - if (!HdfSbufReadFloat(data, &input)) { - HDF_LOGE("%{public}s: read float data failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = HdiSampleImplInstance()->FloatTypeTest(client->device, input, &output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call FloatTypeTest failed!", __func__); - return ec; - } - - if (!HdfSbufWriteFloat(reply, output)) { - HDF_LOGE("%{public}s: write float output failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - return ec; -} - -static int32_t SerStubDoubleTypeTest(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) -{ - double input; - double output; - if (!HdfSbufReadDouble(data, &input)) { - HDF_LOGE("%{public}s: read double data failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = HdiSampleImplInstance()->DoubleTypeTest(client->device, input, &output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call DoubleTypeTest failed!", __func__); - return ec; - } - - if (!HdfSbufWriteDouble(reply, output)) { - HDF_LOGE("%{public}s: write double output failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - return ec; -} - -static int32_t SerStubStringTypeTest(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) -{ - const char *input = HdfSbufReadString(data); - if (input == NULL) { - HDF_LOGE("%{public}s: read string data failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - char *output = NULL; - - int32_t ec = HdiSampleImplInstance()->StringTypeTest(client->device, input, &output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call StringTypeTest failed!", __func__); - return ec; - } - - if (!HdfSbufWriteString(reply, output)) { - HDF_LOGE("%{public}s: write string output failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - return ec; -} - -static int32_t SerStubUcharTypeTest(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) -{ - uint8_t input; - uint8_t output; - if (!HdfSbufReadUint8(data, &input)) { - HDF_LOGE("%{public}s: read data failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = HdiSampleImplInstance()->UcharTypeTest(client->device, input, &output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call UcharTypeTest failed!", __func__); - return ec; - } - - if (!HdfSbufWriteUint8(reply, output)) { - HDF_LOGE("%{public}s: write output failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - return ec; -} - -static int32_t SerStubUshortTypeTest(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) -{ - uint16_t input; - uint16_t output; - if (!HdfSbufReadUint16(data, &input)) { - HDF_LOGE("%{public}s: read data failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = HdiSampleImplInstance()->UshortTypeTest(client->device, input, &output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call UshortTypeTest failed!", __func__); - return ec; - } - - if (!HdfSbufWriteUint16(reply, output)) { - HDF_LOGE("%{public}s: write output failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - return ec; -} - -static int32_t SerStubUintTypeTest(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) -{ - uint32_t input; - uint32_t output; - if (!HdfSbufReadUint32(data, &input)) { - HDF_LOGE("%{public}s: read data failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = HdiSampleImplInstance()->UintTypeTest(client->device, input, &output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call UintTypeTest failed!", __func__); - return ec; - } - - if (!HdfSbufWriteUint32(reply, output)) { - HDF_LOGE("%{public}s: write output failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - return ec; -} - -static int32_t SerStubUlongTypeTest(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) -{ - uint64_t input; - uint64_t output; - if (!HdfSbufReadUint64(data, &input)) { - HDF_LOGE("%{public}s: read data failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = HdiSampleImplInstance()->UlongTypeTest(client->device, input, &output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call UlongTypeTest failed!", __func__); - return ec; - } - - if (!HdfSbufWriteUint64(reply, output)) { - HDF_LOGE("%{public}s: write output failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - return ec; -} - -static int32_t SerStubListTypeTest(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) -{ - int32_t ec = HDF_FAILURE; - uint32_t inSize = 0; - int8_t *input = NULL; - uint32_t outSize = 0; - int8_t *output = NULL; - - if (!HdfSbufReadUint32(data, &inSize)) { - HDF_LOGE("%{public}s: read data size failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - return ec; - } - - input = (int8_t *)OsalMemAlloc(sizeof(int8_t) * inSize); - for (uint32_t i = 0; i < inSize; i++) { - if (!HdfSbufReadInt8(data, (input + i))) { - HDF_LOGE("%{public}s: read data size failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto FINISHED; - } - } - - ec = HdiSampleImplInstance()->ArrayTypeTest(client->device, input, inSize, &output, &outSize); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed!", __func__); - goto FINISHED; - } - - if (!HdfSbufWriteUint32(reply, outSize)) { - HDF_LOGE("%{public}s: write output size failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto FINISHED; - } - - for (uint32_t i = 0; i < outSize; i++) { - if (!HdfSbufWriteInt8(reply, output[i])) { - HDF_LOGE("%{public}s: write output failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto FINISHED; - } - } - -FINISHED: - if (input != NULL) { - OsalMemFree(input); - } - if (output != NULL) { - OsalMemFree(output); - } - return ec; -} - -static int32_t SerStubArrayTypeTest(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) -{ - int32_t ec = HDF_FAILURE; - uint32_t inSize = 0; - int8_t *input = NULL; - uint32_t outSize = 0; - int8_t *output = NULL; - - if (!HdfSbufReadUint32(data, &inSize)) { - HDF_LOGE("%{public}s: read data size failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - return ec; - } - - input = (int8_t *)OsalMemAlloc(sizeof(int8_t) * inSize); - for (uint32_t i = 0; i < inSize; i++) { - if (!HdfSbufReadInt8(data, (input + i))) { - HDF_LOGE("%{public}s: read data size failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto FINISHED; - } - } - - ec = HdiSampleImplInstance()->ArrayTypeTest(client->device, input, inSize, &output, &outSize); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed!", __func__); - goto FINISHED; - } - - if (!HdfSbufWriteUint32(reply, outSize)) { - HDF_LOGE("%{public}s: write output size failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto FINISHED; - } - - for (uint32_t i = 0; i < outSize; i++) { - if (!HdfSbufWriteInt8(reply, output[i])) { - HDF_LOGE("%{public}s: write output failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto FINISHED; - } - } - -FINISHED: - if (input != NULL) { - OsalMemFree(input); - } - if (output != NULL) { - OsalMemFree(output); - } - return ec; -} - -static int32_t SerStubStructTypeTest(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) -{ - int32_t ec = HDF_FAILURE; - uint32_t dataSize = 0; - struct StructSample *input = NULL; - struct StructSample output; - - if (!HdfSbufReadBuffer(data, (const void **)&input, &dataSize)) { - HDF_LOGE("%{public}s: read struct data failed!", __func__); - ec = HDF_ERR_INVALID_PARAM; - goto FINISHED; - } - - ec = HdiSampleImplInstance()->StructTypeTest(client->device, input, &output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call StructTypeTest failed! error code is %{public}d", __func__, ec); - goto FINISHED; - } - - if (!HdfSbufWriteBuffer(reply, (const void *)&output, sizeof(output))) { - HDF_LOGE("%{public}s: struct result write failed", __func__); - goto FINISHED; - } -FINISHED: - return ec; -} - -static int32_t SerStubEnumTypeTest(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) -{ - enum EnumSample input; - enum EnumSample output; - - if (!HdfSbufReadUint32(data, (uint32_t *)&input)) { - HDF_LOGE("%{public}s: read EnumSample data failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - int32_t ec = HdiSampleImplInstance()->EnumTypeTest(client->device, input, &output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call EnumTypeTest failed!", __func__); - return ec; - } - - if (!HdfSbufWriteUint32(reply, (uint32_t)output)) { - HDF_LOGE("%{public}s: write EnumSample output failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - return ec; -} - -int32_t SampleServiceOnRemoteRequest(struct HdfDeviceIoClient *client, int cmdId, - struct HdfSBuf *data, struct HdfSBuf *reply) -{ - switch (cmdId) { - case CMD_BOOLEAN_TYPE_TEST: - return SerStubBooleanTypeTest(client, data, reply); - case CMD_BYTE_TYPE_TEST: - return SerStubByteTypeTest(client, data, reply); - case CMD_SHORT_TYPE_TEST: - return SerStubShortTypeTest(client, data, reply); - case CMD_INT_TYPE_TEST: - return SerStubIntTypeTest(client, data, reply); - case CMD_LONG_TYPE_TEST: - return SerStubLongTypeTest(client, data, reply); - case CMD_FLOAT_TYPE_TEST: - return SerStubFloatTypeTest(client, data, reply); - case CMD_DOUBLE_TYPE_TEST: - return SerStubDoubleTypeTest(client, data, reply); - case CMD_STRING_TYPE_TEST: - return SerStubStringTypeTest(client, data, reply); - case CMD_UCHAR_TYPE_TEST: - return SerStubUcharTypeTest(client, data, reply); - case CMD_USHORT_TYPE_TEST: - return SerStubUshortTypeTest(client, data, reply); - case CMD_UINT_TYPE_TEST: - return SerStubUintTypeTest(client, data, reply); - case CMD_ULONG_TYPE_TEST: - return SerStubUlongTypeTest(client, data, reply); - case CMD_LIST_TYPE_TEST: - return SerStubListTypeTest(client, data, reply); - case CMD_ARRAY_TYPE_TEST: - return SerStubArrayTypeTest(client, data, reply); - case CMD_STRUCT_TYPE_TEST: - return SerStubStructTypeTest(client, data, reply); - case CMD_ENUM_TYPE_TEST: - return SerStubEnumTypeTest(client, data, reply); - default: { - HDF_LOGE("%{public}s: not support cmd %{public}d", __func__, cmdId); - return HDF_ERR_INVALID_PARAM; - } - } -} diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/BUILD.gn b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/BUILD.gn deleted file mode 100644 index ce5aef4..0000000 --- a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/BUILD.gn +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//drivers/adapter/uhdf2/uhdf.gni") -group("sample_service_cpp") { - deps = [ ":libsample_service_cpp" ] -} - -ohos_shared_library("libsample_service_cpp") { - sources = [ - "sample_driver.cpp", - "sample_service.cpp", - "sample_service_stub.cpp", - ] - - deps = [ - "//drivers/adapter/uhdf2/host:libhdf_host", - "//drivers/adapter/uhdf2/ipc:libhdf_ipc_adapter", - "//drivers/adapter/uhdf2/utils:libhdf_utils", - ] - - if (is_standard_system) { - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_single", - "utils_base:utils", - ] - } else { - external_deps = [ - "hilog:libhilog", - "ipc:ipc_single", - ] - } - - install_images = [ chipset_base_dir ] - subsystem_name = "hdf" - part_name = "device_driver_framework" -} diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/isample.h b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/isample.h deleted file mode 100644 index c53b838..0000000 --- a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/isample.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef HDI_SAMPLE_CPP_INF_H -#define HDI_SAMPLE_CPP_INF_H - -#include -#include -#include -#include - -namespace OHOS { -namespace HDI { -namespace Sample { -namespace V1_0 { -struct StructSample { - int8_t first; - int16_t second; -}; - -enum EnumSample { - MEM_FIRST, - MEM_SECOND, - MEM_THIRD, -}; - -enum { - CMD_BOOLEAN_TYPE_TEST, - CMD_BYTE_TYPE_TEST, - CMD_SHORT_TYPE_TEST, - CMD_INT_TYPE_TEST, - CMD_LONG_TYPE_TEST, - CMD_FLOAT_TYPE_TEST, - CMD_DOUBLE_TYPE_TEST, - CMD_STRING_TYPE_TEST, - CMD_UCHAR_TYPE_TEST, - CMD_USHORT_TYPE_TEST, - CMD_UINT_TYPE_TEST, - CMD_ULONG_TYPE_TEST, - CMD_LIST_TYPE_TEST, - CMD_MAP_TYPE_TEST, - CMD_ARRAY_TYPE_TEST, - CMD_STRUCT_TYPE_TEST, - CMD_ENUM_TYPE_TEST, -}; - -class ISample { -public: - virtual ~ISample(){} - - virtual int32_t BooleanTypeTest(const bool input, bool& output) const = 0; - - virtual int32_t ByteTypeTest(const int8_t input, int8_t& output) const = 0; - - virtual int32_t ShortTypeTest(const int16_t input, int16_t& output) const = 0; - - virtual int32_t IntTypeTest(const int32_t input, int32_t& output) const = 0; - - virtual int32_t LongTypeTest(const int64_t input, int64_t& output) const = 0; - - virtual int32_t FloatTypeTest(const float input, float& output) const = 0; - - virtual int32_t DoubleTypeTest(const double input, double& output) const = 0; - - virtual int32_t StringTypeTest(const std::string& input, std::string& output) const = 0; - - virtual int32_t UcharTypeTest(const uint8_t input, uint8_t& output) const = 0; - - virtual int32_t UshortTypeTest(const uint16_t input, uint16_t& output) const = 0; - - virtual int32_t UintTypeTest(const uint32_t input, uint32_t& output) const = 0; - - virtual int32_t UlongTypeTest(const uint64_t input, uint64_t& output) const = 0; - - virtual int32_t ListTypeTest(const std::list& input, std::list& output) const = 0; - - virtual int32_t MapTypeTest(const std::map& input, std::map& output) const = 0; - - virtual int32_t ArrayTypeTest(const std::vector& input, std::vector& output) const = 0; - - virtual int32_t StructTypeTest(const StructSample& input, StructSample& output) const = 0; - - virtual int32_t EnumTypeTest(const EnumSample& input, EnumSample& output) const = 0; -}; -} // namespace V1_0 -} // namespace Sample -} // namespace HDI -} // namespace OHOS - -#endif // HDI_SAMPLE_CPP_INF_H \ No newline at end of file diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_driver.cpp b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_driver.cpp deleted file mode 100644 index f12acad..0000000 --- a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_driver.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include -#include -#include -#include "sample_service_stub.h" - -#define HDF_LOG_TAG sample_service_cpp - -using namespace OHOS::HDI::Sample::V1_0; - -struct HdfSampleService { - struct IDeviceIoService ioservice; - void *instance; -}; - -static int32_t SampleServiceDispatch(struct HdfDeviceIoClient *client, int cmdId, - struct HdfSBuf *data, struct HdfSBuf *reply) -{ - struct HdfSampleService *hdfSampleService = CONTAINER_OF( - client->device->service, struct HdfSampleService, ioservice); - return SampleServiceOnRemoteRequest(hdfSampleService->instance, cmdId, *data, *reply); -} - -int HdfSampleDriverInit(struct HdfDeviceObject *deviceObject) -{ - HDF_LOGE("HdfSampleDriverInit enter, new hdi impl"); - return HDF_SUCCESS; -} - -int HdfSampleDriverBind(struct HdfDeviceObject *deviceObject) -{ - HDF_LOGI("HdfSampleDriverBind enter!"); - - struct HdfSampleService *hdfSampleService = (struct HdfSampleService *)OsalMemAlloc( - sizeof(struct HdfSampleService)); - if (hdfSampleService == nullptr) { - HDF_LOGE("HdfSampleDriverBind OsalMemAlloc HdfSampleService failed!"); - return HDF_FAILURE; - } - - hdfSampleService->ioservice.Dispatch = SampleServiceDispatch; - hdfSampleService->ioservice.Open = NULL; - hdfSampleService->ioservice.Release = NULL; - hdfSampleService->instance = SampleStubInstance(); - - deviceObject->service = &hdfSampleService->ioservice; - return HDF_SUCCESS; -} - -void HdfSampleDriverRelease(struct HdfDeviceObject *deviceObject) -{ - struct HdfSampleService *hdfSampleService = CONTAINER_OF(deviceObject->service, struct HdfSampleService, ioservice); - SampleStubRelease(hdfSampleService->instance); - OsalMemFree(hdfSampleService); -} - -struct HdfDriverEntry g_sampleDriverEntry = { - .moduleVersion = 1, - .moduleName = "sample_service_cpp", - .Bind = HdfSampleDriverBind, - .Init = HdfSampleDriverInit, - .Release = HdfSampleDriverRelease, -}; - -#ifndef __cplusplus -extern "C" { -#endif - -HDF_INIT(g_sampleDriverEntry); - -#ifndef __cplusplus -} -#endif \ No newline at end of file diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service.cpp b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service.cpp deleted file mode 100644 index c947695..0000000 --- a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "sample_service.h" -#include - -namespace OHOS { -namespace HDI { -namespace Sample { -namespace V1_0 { -int32_t SampleService::BooleanTypeTest(const bool input, bool& output) const -{ - output = input; - return 0; -} - -int32_t SampleService::ByteTypeTest(const int8_t input, int8_t& output) const -{ - output = input; - return 0; -} - -int32_t SampleService::ShortTypeTest(const int16_t input, int16_t& output) const -{ - output = input; - return 0; -} - -int32_t SampleService::IntTypeTest(const int32_t input, int32_t& output) const -{ - output = input; - return 0; -} - -int32_t SampleService::LongTypeTest(const int64_t input, int64_t& output) const -{ - output = input; - return 0; -} - -int32_t SampleService::FloatTypeTest(const float input, float& output) const -{ - output = input; - return 0; -} - -int32_t SampleService::DoubleTypeTest(const double input, double& output) const -{ - output = input; - return 0; -} - -int32_t SampleService::StringTypeTest(const std::string& input, std::string& output) const -{ - output = input; - return 0; -} - -int32_t SampleService::UcharTypeTest(const uint8_t input, uint8_t& output) const -{ - output = input; - return 0; -} - -int32_t SampleService::UshortTypeTest(const uint16_t input, uint16_t& output) const -{ - output = input; - return 0; -} - -int32_t SampleService::UintTypeTest(const uint32_t input, uint32_t& output) const -{ - output = input; - return 0; -} - -int32_t SampleService::UlongTypeTest(const uint64_t input, uint64_t& output) const -{ - output = input; - return 0; -} - -int32_t SampleService::ListTypeTest(const std::list& input, std::list& output) const -{ - output = input; - return 0; -} - -int32_t SampleService::MapTypeTest(const std::map& input, std::map& output) const -{ - output = input; - return 0; -} - -int32_t SampleService::ArrayTypeTest(const std::vector& input, std::vector& output) const -{ - output = input; - return 0; -} - -int32_t SampleService::StructTypeTest(const StructSample& input, StructSample& output) const -{ - output.first = input.first; - output.second = input.second; - return 0; -} - -int32_t SampleService::EnumTypeTest(const EnumSample& input, EnumSample& output) const -{ - output = input; - return 0; -} -} // namespace V1_0 -} // namespace Sample -} // namespace HDI -} // namespace OHOS \ No newline at end of file diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service.h b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service.h deleted file mode 100644 index 6accfc2..0000000 --- a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef HDI_SAMPLE_SERVICE_CPP_INF_H -#define HDI_SAMPLE_SERVICE_CPP_INF_H - -#include "isample.h" - -namespace OHOS { -namespace HDI { -namespace Sample { -namespace V1_0 { -class SampleService : public ISample { -public: - SampleService(){} - virtual ~SampleService() override {} - - virtual int32_t BooleanTypeTest(const bool input, bool& output) const override; - - virtual int32_t ByteTypeTest(const int8_t input, int8_t& output) const override; - - virtual int32_t ShortTypeTest(const int16_t input, int16_t& output) const override; - - virtual int32_t IntTypeTest(const int32_t input, int32_t& output) const override; - - virtual int32_t LongTypeTest(const int64_t input, int64_t& output) const override; - - virtual int32_t FloatTypeTest(const float input, float& output) const override; - - virtual int32_t DoubleTypeTest(const double input, double& output) const override; - - virtual int32_t StringTypeTest(const std::string& input, std::string& output) const override; - - virtual int32_t UcharTypeTest(const uint8_t input, uint8_t& output) const override; - - virtual int32_t UshortTypeTest(const uint16_t input, uint16_t& output) const override; - - virtual int32_t UintTypeTest(const uint32_t input, uint32_t& output) const override; - - virtual int32_t UlongTypeTest(const uint64_t input, uint64_t& output) const override; - - virtual int32_t ListTypeTest(const std::list& input, std::list& output) const override; - - virtual int32_t MapTypeTest(const std::map& input, std::map& output) const override; - - virtual int32_t ArrayTypeTest(const std::vector& input, std::vector& output) const override; - - virtual int32_t StructTypeTest(const StructSample& input, StructSample& output) const override; - - virtual int32_t EnumTypeTest(const EnumSample& input, EnumSample& output) const override; -}; -} // namespace V1_0 -} // namespace Sample -} // namespace HDI -} // namespace OHOS - -#endif // HDI_SAMPLE_SERVICE_CPP_INF_H diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.cpp b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.cpp deleted file mode 100644 index fbd84b4..0000000 --- a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.cpp +++ /dev/null @@ -1,484 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "sample_service_stub.h" -#include -#include -#include - -namespace OHOS { -namespace HDI { -namespace Sample { -namespace V1_0 { -int32_t SampleServiceStub::SampleStubBooleanTypeTest(MessageParcel& data, - MessageParcel& reply, MessageOption& option) const -{ - const bool input = data.ReadBool(); - bool output = false; - - int32_t ec = service.BooleanTypeTest(input, output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed, error code is %{public}d", __func__, ec); - return ec; - } - - if (!reply.WriteBool(output)) { - HDF_LOGE("%{public}s: write result failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return HDF_SUCCESS; -} - -int32_t SampleServiceStub::SampleStubByteTypeTest(MessageParcel& data, - MessageParcel& reply, MessageOption& option) const -{ - const int8_t input = data.ReadInt8(); - int8_t output; - - int32_t ec = service.ByteTypeTest(input, output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed, error code is %{public}d", __func__, ec); - return ec; - } - - if (!reply.WriteInt8(output)) { - HDF_LOGE("%{public}s: write result failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return HDF_SUCCESS; -} - -int32_t SampleServiceStub::SampleStubShortTypeTest(MessageParcel& data, - MessageParcel& reply, MessageOption& option) const -{ - const int16_t input = data.ReadInt16(); - int16_t output; - - int32_t ec = service.ShortTypeTest(input, output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed, error code is %{public}d", __func__, ec); - return ec; - } - - if (!reply.WriteInt16(output)) { - HDF_LOGE("%{public}s: write result failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return HDF_SUCCESS; -} - -int32_t SampleServiceStub::SampleStubIntTypeTest(MessageParcel& data, - MessageParcel& reply, MessageOption& option) const -{ - const int32_t input = data.ReadInt32(); - int32_t output; - - int32_t ec = service.IntTypeTest(input, output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed, error code is %{public}d", __func__, ec); - return ec; - } - - if (!reply.WriteInt32(output)) { - HDF_LOGE("%{public}s: write result failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return HDF_SUCCESS; -} - -int32_t SampleServiceStub::SampleStubLongTypeTest(MessageParcel& data, - MessageParcel& reply, MessageOption& option) const -{ - const int64_t input = data.ReadInt64(); - int64_t output; - - int32_t ec = service.LongTypeTest(input, output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed, error code is %{public}d", __func__, ec); - return ec; - } - - if (!reply.WriteInt64(output)) { - HDF_LOGE("%{public}s: write result failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return HDF_SUCCESS; -} - -int32_t SampleServiceStub::SampleStubFloatTypeTest(MessageParcel& data, - MessageParcel& reply, MessageOption& option) const -{ - const float input = data.ReadFloat(); - float output; - - int32_t ec = service.FloatTypeTest(input, output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed, error code is %{public}d", __func__, ec); - return ec; - } - - if (!reply.WriteFloat(output)) { - HDF_LOGE("%{public}s: write result failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return HDF_SUCCESS; -} - -int32_t SampleServiceStub::SampleStubDoubleTypeTest(MessageParcel& data, - MessageParcel& reply, MessageOption& option) const -{ - const double input = data.ReadDouble(); - double output; - - int32_t ec = service.DoubleTypeTest(input, output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed, error code is %{public}d", __func__, ec); - return ec; - } - - if (!reply.WriteDouble(output)) { - HDF_LOGE("%{public}s: write result failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return HDF_SUCCESS; -} - -int32_t SampleServiceStub::SampleStubStringTypeTest(MessageParcel& data, - MessageParcel& reply, MessageOption& option) const -{ - const std::string input = data.ReadString(); - std::string output; - - int32_t ec = service.StringTypeTest(input, output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed, error code is %{public}d", __func__, ec); - return ec; - } - - if (!reply.WriteString(output)) { - HDF_LOGE("%{public}s: write result failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return HDF_SUCCESS; -} - -int32_t SampleServiceStub::SampleStubUcharTypeTest(MessageParcel& data, - MessageParcel& reply, MessageOption& option) const -{ - const uint8_t input = data.ReadUint8(); - uint8_t output; - - int32_t ec = service.UcharTypeTest(input, output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed, error code is %{public}d", __func__, ec); - return ec; - } - - if (!reply.WriteUint8(output)) { - HDF_LOGE("%{public}s: write result failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return HDF_SUCCESS; -} - -int32_t SampleServiceStub::SampleStubUshortTypeTest(MessageParcel& data, - MessageParcel& reply, MessageOption& option) const -{ - const uint16_t input = data.ReadUint16(); - uint16_t output; - - int32_t ec = service.UshortTypeTest(input, output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed, error code is %{public}d", __func__, ec); - return ec; - } - - if (!reply.WriteUint16(output)) { - HDF_LOGE("%{public}s: write result failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return HDF_SUCCESS; -} - -int32_t SampleServiceStub::SampleStubUintTypeTest(MessageParcel& data, - MessageParcel& reply, MessageOption& option) const -{ - const uint32_t input = data.ReadUint32(); - uint32_t output; - - int32_t ec = service.UintTypeTest(input, output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed, error code is %{public}d", __func__, ec); - return ec; - } - - if (!reply.WriteUint32(output)) { - HDF_LOGE("%{public}s: write result failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return HDF_SUCCESS; -} - -int32_t SampleServiceStub::SampleStubUlongTypeTest(MessageParcel& data, - MessageParcel& reply, MessageOption& option) const -{ - const uint64_t input = data.ReadUint64(); - uint64_t output; - - int32_t ec = service.UlongTypeTest(input, output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed, error code is %{public}d", __func__, ec); - return ec; - } - - if (!reply.WriteUint64(output)) { - HDF_LOGE("%{public}s: write result failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return HDF_SUCCESS; -} - -int32_t SampleServiceStub::SampleStubListTypeTest(MessageParcel& data, - MessageParcel& reply, MessageOption& option) const -{ - const uint32_t inSize = data.ReadUint32(); - std::list input; - std::list output; - - for (uint32_t i = 0; i < inSize; i++) { - input.push_back(data.ReadInt8()); - } - - int32_t ec = service.ListTypeTest(input, output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed, error code is %{public}d", __func__, ec); - return ec; - } - - if (!reply.WriteUint32(output.size())) { - HDF_LOGE("%{public}s: write result size failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - - for (auto it : output) { - if (!reply.WriteInt8(it)) { - HDF_LOGE("%{public}s: write result failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - } - - return HDF_SUCCESS; -} - -int32_t SampleServiceStub::SampleStubMapTypeTest(MessageParcel& data, - MessageParcel& reply, MessageOption& option) const -{ - const uint32_t inSize = data.ReadUint32(); - std::map input; - std::map output; - - for (uint32_t i = 0; i < inSize; i++) { - int8_t key = data.ReadInt8(); - int8_t val = data.ReadInt8(); - input[key] = val; - } - - int32_t ec = service.MapTypeTest(input, output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed, error code is %{public}d", __func__, ec); - return ec; - } - - if (!reply.WriteUint32(output.size())) { - HDF_LOGE("%{public}s: write result size failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - - for (auto it : output) { - if (!reply.WriteInt8(it.first) || !reply.WriteInt8(it.second)) { - HDF_LOGE("%{public}s: write result size failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - } - - return HDF_SUCCESS; -} - -int32_t SampleServiceStub::SampleStubArrayTypeTest(MessageParcel& data, - MessageParcel& reply, MessageOption& option) const -{ - const uint32_t inSize = data.ReadUint32(); - std::vector input; - std::vector output; - - for (uint32_t i = 0; i < inSize; i++) { - input.push_back(data.ReadInt8()); - } - - int32_t ec = service.ArrayTypeTest(input, output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed, error code is %{public}d", __func__, ec); - return ec; - } - - if (!reply.WriteUint32(output.size())) { - HDF_LOGE("%{public}s: write result size failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - - for (auto it : output) { - if (!reply.WriteInt8(it)) { - HDF_LOGE("%{public}s: write result failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - } - - return HDF_SUCCESS; -} - -int32_t SampleServiceStub::SampleStubStructTypeTest(MessageParcel& data, - MessageParcel& reply, MessageOption& option) const -{ - StructSample *input = (StructSample *)data.ReadBuffer(sizeof(StructSample)); - if (input == nullptr) { - HDF_LOGE("%{public}s: read struct data failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - StructSample output; - - int32_t ec = service.StructTypeTest(*input, output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed, error code is %{public}d", __func__, ec); - return ec; - } - - if (!reply.WriteBuffer((void *)&output, sizeof(StructSample))) { - HDF_LOGE("%{public}s: write output data failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return HDF_SUCCESS; -} - -int32_t SampleServiceStub::SampleStubEnumTypeTest(MessageParcel& data, - MessageParcel& reply, MessageOption& option) const -{ - EnumSample input = (EnumSample)data.ReadUint32(); - EnumSample output; - - int32_t ec = service.EnumTypeTest(input, output); - if (ec != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call failed, error code is %{public}d", __func__, ec); - return ec; - } - - if (!reply.WriteUint32((uint32_t)output)) { - HDF_LOGE("%{public}s: write result failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return HDF_SUCCESS; -} - -int32_t SampleServiceStub::SampleServiceStubOnRemoteRequest(int cmdId, - MessageParcel& data, MessageParcel& reply, MessageOption& option) const -{ - switch (cmdId) { - case CMD_BOOLEAN_TYPE_TEST: - return SampleStubBooleanTypeTest(data, reply, option); - case CMD_BYTE_TYPE_TEST: - return SampleStubByteTypeTest(data, reply, option); - case CMD_SHORT_TYPE_TEST: - return SampleStubShortTypeTest(data, reply, option); - case CMD_INT_TYPE_TEST: - return SampleStubIntTypeTest(data, reply, option); - case CMD_LONG_TYPE_TEST: - return SampleStubLongTypeTest(data, reply, option); - case CMD_FLOAT_TYPE_TEST: - return SampleStubFloatTypeTest(data, reply, option); - case CMD_DOUBLE_TYPE_TEST: - return SampleStubDoubleTypeTest(data, reply, option); - case CMD_STRING_TYPE_TEST: - return SampleStubStringTypeTest(data, reply, option); - case CMD_UCHAR_TYPE_TEST: - return SampleStubUcharTypeTest(data, reply, option); - case CMD_USHORT_TYPE_TEST: - return SampleStubUshortTypeTest(data, reply, option); - case CMD_UINT_TYPE_TEST: - return SampleStubUintTypeTest(data, reply, option); - case CMD_ULONG_TYPE_TEST: - return SampleStubUlongTypeTest(data, reply, option); - case CMD_LIST_TYPE_TEST: - return SampleStubListTypeTest(data, reply, option); - case CMD_MAP_TYPE_TEST: - return SampleStubMapTypeTest(data, reply, option); - case CMD_ARRAY_TYPE_TEST: - return SampleStubArrayTypeTest(data, reply, option); - case CMD_STRUCT_TYPE_TEST: - return SampleStubStructTypeTest(data, reply, option); - case CMD_ENUM_TYPE_TEST: - return SampleStubEnumTypeTest(data, reply, option); - default: { - HDF_LOGE("%{public}s: not support cmd %{public}d", __func__, cmdId); - return HDF_ERR_INVALID_PARAM; - } - } - return HDF_SUCCESS; -} -} // namespace V1_0 -} // namespace Sample -} // namespace HDI -} // namespace OHOS - -void *SampleStubInstance() -{ - using namespace OHOS::HDI::Sample::V1_0; - return reinterpret_cast(new SampleServiceStub()); -} - -void SampleStubRelease(void *obj) -{ - using namespace OHOS::HDI::Sample::V1_0; - delete reinterpret_cast(obj); -} - -int32_t SampleServiceOnRemoteRequest(void *stub, int cmdId, struct HdfSBuf& data, struct HdfSBuf& reply) -{ - using namespace OHOS::HDI::Sample::V1_0; - SampleServiceStub *sampleStub = reinterpret_cast(stub); - OHOS::MessageParcel *dataParcel = nullptr; - OHOS::MessageParcel *replyParcel = nullptr; - - (void)SbufToParcel(&reply, &replyParcel); - if (SbufToParcel(&data, &dataParcel) != HDF_SUCCESS) { - HDF_LOGE("%{public}s:invalid data sbuf object to dispatch", __func__); - return HDF_ERR_INVALID_PARAM; - } - - OHOS::MessageOption option; - return sampleStub->SampleServiceStubOnRemoteRequest(cmdId, *dataParcel, *replyParcel, option); -} diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.h b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.h deleted file mode 100644 index 8d76a63..0000000 --- a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef HDI_SAMPLE_SERVICE_STUB_CPP_INF_H -#define HDI_SAMPLE_SERVICE_STUB_CPP_INF_H - -#include -#include -#include -#include "sample_service.h" - -namespace OHOS { -namespace HDI { -namespace Sample { -namespace V1_0 { -class SampleServiceStub { -public: - SampleServiceStub(){} - virtual ~SampleServiceStub(){} - - int32_t SampleStubBooleanTypeTest(MessageParcel& data, MessageParcel& reply, MessageOption& option) const; - int32_t SampleStubByteTypeTest(MessageParcel& data, MessageParcel& reply, MessageOption& option) const; - int32_t SampleStubShortTypeTest(MessageParcel& data, MessageParcel& reply, MessageOption& option) const; - int32_t SampleStubIntTypeTest(MessageParcel& data, MessageParcel& reply, MessageOption& option) const; - int32_t SampleStubLongTypeTest(MessageParcel& data, MessageParcel& reply, MessageOption& option) const; - int32_t SampleStubFloatTypeTest(MessageParcel& data, MessageParcel& reply, MessageOption& option) const; - int32_t SampleStubDoubleTypeTest(MessageParcel& data, MessageParcel& reply, MessageOption& option) const; - int32_t SampleStubStringTypeTest(MessageParcel& data, MessageParcel& reply, MessageOption& option) const; - int32_t SampleStubUcharTypeTest(MessageParcel& data, MessageParcel& reply, MessageOption& option) const; - int32_t SampleStubUshortTypeTest(MessageParcel& data, MessageParcel& reply, MessageOption& option) const; - int32_t SampleStubUintTypeTest(MessageParcel& data, MessageParcel& reply, MessageOption& option) const; - int32_t SampleStubUlongTypeTest(MessageParcel& data, MessageParcel& reply, MessageOption& option) const; - int32_t SampleStubListTypeTest(MessageParcel& data, MessageParcel& reply, MessageOption& option) const; - int32_t SampleStubMapTypeTest(MessageParcel& data, MessageParcel& reply, MessageOption& option) const; - int32_t SampleStubArrayTypeTest(MessageParcel& data, MessageParcel& reply, MessageOption& option) const; - int32_t SampleStubStructTypeTest(MessageParcel& data, MessageParcel& reply, MessageOption& option) const; - int32_t SampleStubEnumTypeTest(MessageParcel& data, MessageParcel& reply, MessageOption& option) const; - - int32_t SampleServiceStubOnRemoteRequest(int cmdId, MessageParcel& data, MessageParcel& reply, - MessageOption& option) const; -private: - SampleService service; -}; -} // namespace V1_0 -} // namespace Sample -} // namespace HDI -} // namespace OHOS - -void *SampleStubInstance(); - -void SampleStubRelease(void *obj); - -int32_t SampleServiceOnRemoteRequest(void *stub, int cmdId, struct HdfSBuf& data, struct HdfSBuf& reply); - -#endif // HDI_SAMPLE_SERVICE_STUB_CPP_INF_H \ No newline at end of file diff --git a/uhdf2/hdi/test/reg_pnp_device/hdf_dev_reg_pnp_test.c b/uhdf2/hdi/test/reg_pnp_device/hdf_dev_reg_pnp_test.c deleted file mode 100644 index bf486f0..0000000 --- a/uhdf2/hdi/test/reg_pnp_device/hdf_dev_reg_pnp_test.c +++ /dev/null @@ -1,326 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "hdf_log.h" -#include "devmgr_hdi.h" -#include "hdf_remote_service.h" -#include "osal_time.h" -#include "securec.h" - -static int32_t g_testItemCnt = 0; -static int32_t g_testItemFailCnt = 0; - -#ifdef __VND__ -#define IS_HDI 0 -#else -#define IS_HDI 1 -#endif - -#define UT_TEST_CHECK_RET(val) do { \ - if (!(val)) { \ - printf("[HDF_TEST] %s line:%d HDF_TEST_FAIL\r\n", __func__, __LINE__); \ - g_testItemFailCnt++; \ - } else { \ - printf("[HDF_TEST] %s line:%d HDF_TEST_PASS\r\n", __func__, __LINE__); \ - } \ - g_testItemCnt++; \ -} while (0) - -#define HDF_LOG_TAG hdf_reg_pnp_test - -#define PNP_MODULE_NAME "libpnp_driver.so" -#define PNP_SERVICE_NAME "pnp_driver_service" - -void PrintTestResult() -{ - printf("[HDF_TEST] %s test items: %d\r\n", __func__, g_testItemCnt); - printf("[HDF_TEST] %s test PASS: %d\r\n", __func__, g_testItemCnt - g_testItemFailCnt); - printf("[HDF_TEST] %s test FAIL: %d\r\n", __func__, g_testItemFailCnt); -} - -int32_t GetProcessId(const char *processName) -{ - FILE *fp = NULL; - char buffer[80] = {0}; - char cmd[100] = "ps -ef |grep "; - if (strcat_s(cmd, sizeof(cmd) - strlen(cmd), processName) != 0) { - return 0; - } - if (strcat_s(cmd, sizeof(cmd) - strlen(cmd), " | grep -v grep | awk '{print $2}'") != 0) { - return 0; - } - fp = popen(cmd, "r"); - if (fp == NULL) { - return 0; - } - fgets(buffer, sizeof(buffer), fp); - pclose(fp); - return atoi(buffer); -} - -void KillProcessById(int32_t procssId) -{ - char cmd[100] = "kill "; - char buf[10] = {0}; - if (sprintf_s(buf, sizeof(buf) - 1, "%d", procssId) < 0) { - return; - } - if (strcat_s(cmd, sizeof(cmd) - strlen(cmd), buf) != 0) { - return; - } - system(cmd); -} - - -static int32_t HdfRegPnpDevice(const char *moduleName, const char *serviceName) -{ - struct HDIDeviceManager *iDevmgr = HDIDeviceManagerGet(); - if (iDevmgr == NULL) { - return HDF_DEV_ERR_NO_DEVICE_SERVICE; - } - - int32_t ret = iDevmgr->RegPnpDevice(iDevmgr, moduleName, serviceName); - - HDIDeviceManagerRelease(iDevmgr); - return ret; -} - -static int32_t HdfUnRegPnpDevice(const char *moduleName, const char *serviceName) -{ - struct HDIDeviceManager *iDevmgr = HDIDeviceManagerGet(); - if (iDevmgr == NULL) { - return HDF_DEV_ERR_NO_DEVICE_SERVICE; - } - - int32_t ret = iDevmgr->UnRegPnpDevice(iDevmgr, moduleName, serviceName); - - HDIDeviceManagerRelease(iDevmgr); - return ret; -} - -/* -* @tc.name: HDF_PNP_DEVICE_BaseFunction_AR_001 -* @tc.desc: reg pnp driver -* @tc.type: FUNC -* @tc.require: SR000F86A5 -*/ -static void HdfRegPnpDriverTest_001() -{ - int32_t ret; - ret = HdfRegPnpDevice(PNP_MODULE_NAME, PNP_SERVICE_NAME); - UT_TEST_CHECK_RET(ret == HDF_SUCCESS); - ret = HdfRegPnpDevice(PNP_MODULE_NAME, PNP_SERVICE_NAME); - UT_TEST_CHECK_RET(ret != HDF_SUCCESS); -} - -/* -* @tc.name: HDF_PNP_DEVICE_BaseFunction_AR_002 -* @tc.desc: unreg pnp driver -* @tc.type: FUNC -* @tc.require: SR000F86A5 -*/ -static void HdfRegPnpDriverTest_002() -{ - int32_t ret; - ret = HdfUnRegPnpDevice(PNP_MODULE_NAME, PNP_SERVICE_NAME); - UT_TEST_CHECK_RET(ret == HDF_SUCCESS); - ret = HdfUnRegPnpDevice(PNP_MODULE_NAME, PNP_SERVICE_NAME); - UT_TEST_CHECK_RET(ret != HDF_SUCCESS); -} - -/* -* @tc.name: HDF__PNP_DEVICE_BaseFunction_AR_003 -* @tc.desc: reg pnp driver -* @tc.type: FUNC -* @tc.require: AR000F86A6 AR000F86A7 AR000F86A8 AR000F86A9 -*/ -static void HdfRegPnpDriverTest_003() -{ - int32_t ret; - ret = HdfRegPnpDevice(PNP_MODULE_NAME, PNP_SERVICE_NAME); - UT_TEST_CHECK_RET(ret == HDF_SUCCESS); - struct HDIServiceManager *hdiServMgr = HDIServiceManagerGet(); - UT_TEST_CHECK_RET(hdiServMgr != NULL); - - struct HdfRemoteService *remote = hdiServMgr->GetService(hdiServMgr, PNP_SERVICE_NAME); - UT_TEST_CHECK_RET(remote != NULL); - if (remote != NULL) { - struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); - struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); - HdfSbufWriteString(data, "test for pnp dispatch!"); - int32_t processIdBefor = GetProcessId("pnp_host"); - ret = remote->dispatcher->Dispatch(remote, 0, data, reply); - int32_t processIdAfter = GetProcessId("pnp_host"); - UT_TEST_CHECK_RET(processIdBefor == processIdAfter); - int32_t result = 0; - HdfParcelReadInt(reply, &result); - UT_TEST_CHECK_RET(result == 1); - HdfSbufRecycle(data); - HdfSbufRecycle(reply); - } - UT_TEST_CHECK_RET(ret == HDF_SUCCESS); - HDIServiceManagerRelease(hdiServMgr); -} - -/* -* @tc.name: HDF__PNP_DEVICE_BaseFunction_AR_004 -* @tc.desc: unreg pnp driver -* @tc.type: FUNC -* @tc.require: AR000F86A6 AR000F86A7 AR000F86A8 AR000F86A9 -*/ -static void HdfRegPnpDriverTest_004() -{ - int ret = HdfUnRegPnpDevice(PNP_MODULE_NAME, PNP_SERVICE_NAME); - UT_TEST_CHECK_RET(ret == HDF_SUCCESS); - struct HdfRemoteService *remote = HdfRemoteServiceGet(PNP_SERVICE_NAME); - UT_TEST_CHECK_RET(remote == NULL); -} - -/* -* @tc.name: HDF__PNP_DEVICE_BaseFunction_AR_005 -* @tc.desc: reg fault pnp driver -* @tc.type: FUNC -* @tc.require: AR000F86A6 AR000F86A7 AR000F86A8 AR000F86A9 -*/ -static void HdfRegPnpDriverTest_005() -{ - int ret = HdfRegPnpDevice("libpnp_driver1.so", "pnp_driver_service_1"); - struct HdfRemoteService *remote = HdfRemoteServiceGet("pnp_driver_service_1"); - UT_TEST_CHECK_RET(remote == NULL); - if (ret == HDF_SUCCESS) { - (void)HdfUnRegPnpDevice("libpnp_driver1.so", "pnp_driver_service1"); - } -} - -/* -* @tc.name: HDF__PNP_DEVICE_BaseFunction_AR_006 -* @tc.desc: reg fault pnp driver -* @tc.type: FUNC -* @tc.require: AR000F86A6 AR000F86A7 AR000F86A8 AR000F86A9 -*/ -static void HdfRegPnpDriverTest_006() -{ - int32_t ret; - uint64_t totalTime = 0; - for (int i = 0; i < 1000; i++) { - uint64_t timeBefor = OsalGetSysTimeMs(); - char svcName[128] = {0}; - if (sprintf_s(svcName, sizeof(svcName) - 1, "%s%d", PNP_SERVICE_NAME, i) < 0) { - continue; - } - const char *serviceName = svcName; - ret = HdfRegPnpDevice(PNP_MODULE_NAME, serviceName); - UT_TEST_CHECK_RET(ret == HDF_SUCCESS); - ret = HdfUnRegPnpDevice(PNP_MODULE_NAME, serviceName); - UT_TEST_CHECK_RET(ret == HDF_SUCCESS); - uint64_t timeAfter = OsalGetSysTimeMs(); - totalTime += timeAfter - timeBefor; - } - printf("total time is %lu \n", totalTime); - UT_TEST_CHECK_RET((totalTime / 1000) < 20); -} - -/* -* @tc.name: HdfRestore_001 -* @tc.desc: restore host process -* @tc.type: FUNC -* @tc.require: AR000F86AL AR000F86AM -*/ -static void HdfRestore_001() -{ - int32_t ret; - ret = HdfRegPnpDevice(PNP_MODULE_NAME, PNP_SERVICE_NAME); - UT_TEST_CHECK_RET(ret == HDF_SUCCESS); - struct HDIServiceManager *hdiServMgr = HDIServiceManagerGet(); - UT_TEST_CHECK_RET(hdiServMgr != NULL); - - struct HdfRemoteService *remote = hdiServMgr->GetService(hdiServMgr, PNP_SERVICE_NAME); - UT_TEST_CHECK_RET(remote != NULL); - if (remote != NULL) { - struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); - struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); - HdfSbufWriteString(data, "test for pnp dispatch!"); - int32_t processIdBefor = GetProcessId("pnp_host"); - ret = remote->dispatcher->Dispatch(remote, 1, data, reply); - int32_t processIdAfter = GetProcessId("pnp_host"); - UT_TEST_CHECK_RET(processIdBefor != processIdAfter); - HdfSbufRecycle(data); - HdfSbufRecycle(reply); - } - UT_TEST_CHECK_RET(ret != HDF_SUCCESS); - HDIServiceManagerRelease(hdiServMgr); - ret = HdfUnRegPnpDevice(PNP_MODULE_NAME, PNP_SERVICE_NAME); - UT_TEST_CHECK_RET(ret == HDF_SUCCESS); -} - -/* -* @tc.name: HdfRestore_002 -* @tc.desc: restore host process -* @tc.type: FUNC -* @tc.require: AR000F86AL AR000F86AM -*/ -static void HdfRestore_002() -{ - int32_t ret; - ret = HdfRegPnpDevice(PNP_MODULE_NAME, PNP_SERVICE_NAME); - UT_TEST_CHECK_RET(ret == HDF_SUCCESS); - struct HDIServiceManager *hdiServMgr = HDIServiceManagerGet(); - UT_TEST_CHECK_RET(hdiServMgr != NULL); - - struct HdfRemoteService *remote = hdiServMgr->GetService(hdiServMgr, PNP_SERVICE_NAME); - UT_TEST_CHECK_RET(remote != NULL); - - int32_t processIdBefor = GetProcessId("pnp_host"); - KillProcessById(processIdBefor); - int32_t processIdAfter = GetProcessId("pnp_host"); - UT_TEST_CHECK_RET(processIdBefor != processIdAfter); - remote = hdiServMgr->GetService(hdiServMgr, PNP_SERVICE_NAME); - UT_TEST_CHECK_RET(remote != NULL); - HDIServiceManagerRelease(hdiServMgr); - ret = HdfUnRegPnpDevice(PNP_MODULE_NAME, PNP_SERVICE_NAME); - UT_TEST_CHECK_RET(ret == HDF_SUCCESS); -} - -/* -* @tc.name: HdfRestore_003 -* @tc.desc: restore manager process -* @tc.type: FUNC -* @tc.require: SR000F86AK -*/ -static void HdfRestore_003() -{ - int32_t processIdBefor = GetProcessId("hdf_devmgr"); - KillProcessById(processIdBefor); - int32_t processIdAfter = GetProcessId("hdf_devmgr"); - UT_TEST_CHECK_RET((processIdAfter != 0) && (processIdBefor != processIdAfter)); -} - -int main(void) -{ - HdfRegPnpDriverTest_001(); - HdfRegPnpDriverTest_002(); - HdfRegPnpDriverTest_003(); - HdfRegPnpDriverTest_004(); - HdfRegPnpDriverTest_005(); - HdfRegPnpDriverTest_006(); - HdfRestore_001(); - HdfRestore_002(); - HdfRestore_003(); - PrintTestResult(); - return 0; -} - diff --git a/uhdf2/hdi/test/reg_pnp_device/unittest/sample_driver/hdf_pnp_driver.c b/uhdf2/hdi/test/reg_pnp_device/unittest/sample_driver/hdf_pnp_driver.c deleted file mode 100644 index 1e56a14..0000000 --- a/uhdf2/hdi/test/reg_pnp_device/unittest/sample_driver/hdf_pnp_driver.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "hdf_log.h" -#include "hdf_base.h" -#include "hdf_device_desc.h" -#include "hdf_pnp_driver.h" -#include "pal_if.h" - -#define HDF_LOG_TAG hdf_pnp_driver - -static int g_gpioFlg = 0; - -int32_t PnpDriverDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply) -{ - (void)client; - if (data == NULL || reply == NULL) { - HDF_LOGE("%{public}s failed, input is null", __func__); - return HDF_FAILURE; - } - int32_t ret = HDF_SUCCESS; - switch (cmdId) { - case HDF_PNP_MES_TEST: { - const char *str = HdfSbufReadString(data); - HDF_LOGE("%{public}s pnp get str is %{public}s", __func__, str); - HdfSbufWriteInt32(reply, 1); - break; - } - case HDF_PNP_MES_FAULT: { - // test to crash process - const char *str = NULL; - HDF_LOGE("%{public}s test to crash procss is %{public}c", __func__, str[1]); - break; - } - case HDF_PNP_MES_SECUREC: { - if (g_gpioFlg == 0) { - ret = HDF_FAILURE; - } else { - ret = HDF_SUCCESS; - } - break; - } - default: { - HDF_LOGE("%{public}s failed, cmd id is %{public}d", __func__, cmdId); - break; - } - } - return ret; -} - -int32_t HdfPnpDriverBind(struct HdfDeviceObject *para) -{ - HDF_LOGE("%{public}s", __func__); - static struct IDeviceIoService virtualService = { - .object.objectId = 1, - .Dispatch = PnpDriverDispatch, - }; - para->service = &virtualService; - return 0; -} - -int32_t HdfPnpDriverInit(struct HdfDeviceObject *para) -{ - HDF_LOGE("%{public}s enter!", __func__); - if (para == NULL) { - HDF_LOGE("%{public}s init failed, input is null", __func__); - return HDF_FAILURE; - } - DeviceHandle *palHandle = DeviceHandleCreate(PAL_GPIO_TYPE, NULL); - if (palHandle == NULL) { - HDF_LOGE("%{public}s %{public}d open gpio failed", __func__, __LINE__); - g_gpioFlg = 0; - } else { - HDF_LOGE("%{public}s %{public}d open gpio success", __func__, __LINE__); - DeviceHandleDestroy(palHandle); - g_gpioFlg = 1; - } - return 0; -} - -void HdfPnpDriverRelease(struct HdfDeviceObject *para) -{ - HDF_LOGE("%{public}s enter!", __func__); - if (para == NULL) { - HDF_LOGE("%{public}s release failed, input is null", __func__); - return; - } - para->service = NULL; -} - -struct HdfDriverEntry g_sampleDriverEntry = { - .moduleVersion = 1, - .Bind = HdfPnpDriverBind, - .Init = HdfPnpDriverInit, - .Release = HdfPnpDriverRelease, - .moduleName = "pnp_driver", -}; - -HDF_INIT(g_sampleDriverEntry); \ No newline at end of file diff --git a/uhdf2/hdi/test/reg_pnp_device/unittest/sample_driver/hdf_pnp_driver.h b/uhdf2/hdi/test/reg_pnp_device/unittest/sample_driver/hdf_pnp_driver.h deleted file mode 100644 index b5c3cc8..0000000 --- a/uhdf2/hdi/test/reg_pnp_device/unittest/sample_driver/hdf_pnp_driver.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef HDF_PNP_DRIVER_H -#define HDF_PNP_DRIVER_H - -#include "hdf_base.h" -#include "hdf_dlist.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -enum HDF_PNP_DRIVER_CODE { - HDF_PNP_MES_TEST = 0, - HDF_PNP_MES_FAULT, - HDF_PNP_MES_SECUREC, -}; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* HDF_PNP_DRIVER_H */ - diff --git a/uhdf2/hdi/test/reg_virtual_device/hdf_dev_reg_virtual_test.c b/uhdf2/hdi/test/reg_virtual_device/hdf_dev_reg_virtual_test.c deleted file mode 100644 index c6b08eb..0000000 --- a/uhdf2/hdi/test/reg_virtual_device/hdf_dev_reg_virtual_test.c +++ /dev/null @@ -1,344 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "hdf_log.h" -#include "devmgr_hdi.h" -#include "osal_time.h" - -static int32_t g_testItemCnt = 0; -static int32_t g_testItemFailCnt = 0; - -#define UT_TEST_CHECK_RET(val, flag) do { \ - if (!(val)) { \ - HDF_LOGE("[HDF_TEST] %{public}s line:%{public}d HDF_TEST_FAIL", __func__, __LINE__); \ - printf("[HDF_TEST] %s line:%d HDF_TEST_FAIL\r\n", __func__, __LINE__); \ - g_testItemFailCnt++; \ - } else if ((flag)) { \ - HDF_LOGD("[HDF_TEST] %{public}s line:%{public}d HDF_TEST_PASS", __func__, __LINE__); \ - printf("[HDF_TEST] %s line:%d HDF_TEST_PASS\r\n", __func__, __LINE__); \ - } \ - g_testItemCnt++; \ -} while (0) - -#define GET_TIME_BEGIN(time) OsalGetTime(time) -#define GET_TIME_END(incex, type, time1, time2, diff, func, line) do { \ - OsalGetTime(time2); \ - OsalDiffTime(time1, time2, diff); \ - CalcAverageTime(index, type, diff, func, line); \ -} while (0) - -#define HDF_LOG_TAG hdf_reg_virtual_test - -#define VIRTUAL_MODULE_NAME "hdf_test_virtual_driver.so" -#define VIRTUAL_MODULE_NAME_NO "hdf_test_virtual_driver1.so" -#define VIRTUAL_SERVICE_NAME "hdf_test_virtual_driver" -#define VIRTUAL_SERVICE_NAME1 "hdf_test_virtual_driver1" -#define VIRTUAL_SERVICE_NAME2 "hdf_test_virtual_driver2" -#define VIRTUAL_SERVICE_NO_DRIVER "hdf_test_virtual_driver3" - -#define SERVICE_CNT 3 -#define SERVICE_NO_DRIVER_CNT 1 - -#define REGISTER_WAIT_TIME 100 -static char *g_testServiceName[SERVICE_CNT] = { VIRTUAL_SERVICE_NAME, VIRTUAL_SERVICE_NAME1, VIRTUAL_SERVICE_NAME2 }; -static char *g_testServiceNameNoDrv[SERVICE_NO_DRIVER_CNT] = { VIRTUAL_SERVICE_NO_DRIVER }; -#define HDF_REG_DEVICE_ONE 0xffff -#define HDF_REG_TIME_RANGE 10 -#define HDF_REG_DEVICE_MORE 200 -#define HDF_MICRO_UNIT 1000000 -#define TEST_ITEM_CNT 2 -#define ITEM_REG 0 -#define ITEM_UNREG 1 - -static int g_index[TEST_ITEM_CNT]; -static uint64_t g_totalUsec[TEST_ITEM_CNT]; - -void PrintTestResult() -{ - HDF_LOGE("[HDF_TEST] %{public}s test items: %{public}d", __func__, g_testItemCnt); - HDF_LOGE("[HDF_TEST] %{public}s test PASS: %{public}d", __func__, g_testItemCnt - g_testItemFailCnt); - HDF_LOGE("[HDF_TEST] %{public}s test FAIL: %{public}d", __func__, g_testItemFailCnt); - printf("[HDF_TEST] %s test items: %d\r\n", __func__, g_testItemCnt); - printf("[HDF_TEST] %s test PASS: %d\r\n", __func__, g_testItemCnt - g_testItemFailCnt); - printf("[HDF_TEST] %s test FAIL: %d\r\n", __func__, g_testItemFailCnt); -} - -static void CalcAverageTime(int index, bool type, const OsalTimespec *diff, const char *func, int line) -{ - if (type) { - HDF_LOGD("[HDF_TEST] %{public}s line:%{public}d test 1 time use time:%{public}lu s %{public}lu us", - func, line, diff->sec, diff->usec); - printf("[HDF_TEST] %s line:%d test 1 time use time:%lu s %lu us\r\n", func, line, diff->sec, diff->usec); - g_totalUsec[index] += diff->sec * HDF_MICRO_UNIT + diff->usec; - } else { - g_totalUsec[index] += diff->sec * HDF_MICRO_UNIT + diff->usec; - } - g_index[index]++; -} - -static void CheckAverageTime() -{ - HDF_LOGD("[HDF_TEST] %{public}s line:%{public}d test reg %{public}d time use time:%{public}lu us", - __func__, __LINE__, g_index[ITEM_REG], g_totalUsec[ITEM_REG]); - printf("[HDF_TEST] %s line:%d test reg %d time use time: %lu us\r\n", - __func__, __LINE__, g_index[ITEM_REG], g_totalUsec[ITEM_REG]); - - HDF_LOGD("[HDF_TEST] %{public}s line:%{public}d test unreg %{public}d time use time:%{public}lu us", - __func__, __LINE__, g_index[ITEM_UNREG], g_totalUsec[ITEM_UNREG]); - printf("[HDF_TEST] %s line:%d test unreg %d time use time: %lu us\r\n", - __func__, __LINE__, g_index[ITEM_UNREG], g_totalUsec[ITEM_UNREG]); - - UT_TEST_CHECK_RET((g_totalUsec[ITEM_REG] / HDF_KILO_UNIT / g_index[ITEM_REG]) <= HDF_REG_TIME_RANGE, true); - UT_TEST_CHECK_RET((g_totalUsec[ITEM_UNREG] / HDF_KILO_UNIT / g_index[ITEM_UNREG]) <= HDF_REG_TIME_RANGE, true); -} - -static int32_t HdfRegVirtualDevice(const char *moduleName, const char *serviceName) -{ - struct HDIDeviceManager *iDevmgr = HDIDeviceManagerGet(); - if (iDevmgr == NULL) { - return HDF_DEV_ERR_NO_DEVICE_SERVICE; - } - - int32_t ret = iDevmgr->RegVirtualDevice(iDevmgr, moduleName, serviceName); - - HDIDeviceManagerRelease(iDevmgr); - return ret; -} - -static int32_t HdfUnRegVirtualDevice(const char *moduleName, const char *serviceName) -{ - struct HDIDeviceManager *iDevmgr = HDIDeviceManagerGet(); - if (iDevmgr == NULL) { - return HDF_DEV_ERR_NO_DEVICE_SERVICE; - } - - int32_t ret = iDevmgr->UnRegVirtualDevice(iDevmgr, moduleName, serviceName); - - HDIDeviceManagerRelease(iDevmgr); - return ret; -} - -static void HdfRegOneVirtualTest( - int index, bool type, const char *moduleName, const char *serviceName, const char *func, int line, int result) -{ - int32_t ret; - OsalTimespec time1 = { 0, 0 }; - OsalTimespec time2 = { 0, 0 }; - OsalTimespec diff = { 0, 0 }; - GET_TIME_BEGIN(&time1); - ret = HdfRegVirtualDevice(moduleName, serviceName); - if (ret != HDF_SUCCESS) { - ret = HDF_FAILURE; - } - GET_TIME_END(index, type, &time1, &time2, &diff, func, line); - UT_TEST_CHECK_RET(ret == result, type); - if (ret == result) { - HDF_LOGE("[HDF_TEST] %{public}s line:%{public}d", func, line); - } else { - HDF_LOGE("[HDF_TEST] %{public}s line:%{public}d %{public}d", func, line, ret); - printf("[HDF_TEST] %s line:%d %d\r\n", func, line, ret); - } -} - -static void HdfUnRegOneVirtualTest( - int index, bool type, const char *moduleName, const char *serviceName, const char *func, int line, int result) -{ - int32_t ret; - OsalTimespec time1 = { 0, 0 }; - OsalTimespec time2 = { 0, 0 }; - OsalTimespec diff = { 0, 0 }; - GET_TIME_BEGIN(&time1); - ret = HdfUnRegVirtualDevice(moduleName, serviceName); - GET_TIME_END(index, type, &time1, &time2, &diff, func, line); - if (ret != HDF_SUCCESS) { - ret = HDF_FAILURE; - } - - UT_TEST_CHECK_RET(ret == result, type); - if (ret == result) { - HDF_LOGE("[HDF_TEST] %{public}s line:%{public}d", __func__, __LINE__); - } else { - HDF_LOGE("[HDF_TEST] %{public}s line:%{public}d %{public}d", __func__, __LINE__, ret); - } -} - -/* - * HDF_VIRTUAL_DEVICE_BaseFunction_AR_001 HDF_VIRTUAL_DEVICE_BaseFunction_AR_002 - * HDF_VIRTUAL_DEVICE_BaseFunction_AR_007 - */ -static void HdfRegVirtualTest(bool type) -{ - /* HDF_VIRTUAL_DEVICE_BaseFunction_AR_005 */ - HdfRegOneVirtualTest(ITEM_REG, type, VIRTUAL_MODULE_NAME, VIRTUAL_SERVICE_NAME, __func__, __LINE__, HDF_SUCCESS); - HdfRegOneVirtualTest(ITEM_REG, type, VIRTUAL_MODULE_NAME, VIRTUAL_SERVICE_NAME, __func__, __LINE__, HDF_FAILURE); - HdfRegOneVirtualTest(ITEM_REG, type, VIRTUAL_MODULE_NAME, VIRTUAL_SERVICE_NAME1, __func__, __LINE__, HDF_SUCCESS); - HdfRegOneVirtualTest(ITEM_REG, type, VIRTUAL_MODULE_NAME, VIRTUAL_SERVICE_NAME2, __func__, __LINE__, HDF_SUCCESS); - HdfRegOneVirtualTest(ITEM_REG, type, VIRTUAL_MODULE_NAME_NO, VIRTUAL_SERVICE_NO_DRIVER, - __func__, __LINE__, HDF_FAILURE); -} - -/* - * HDF__VIRTUAL_DEVICE_BaseFunction_AR_003 HDF__VIRTUAL_DEVICE_BaseFunction_AR_004 - * HDF_VIRTUAL_DEVICE_BaseFunction_AR_008 - */ -static void HdfUnRegVirtualTest(bool type) -{ - HdfUnRegOneVirtualTest(ITEM_UNREG, type, VIRTUAL_MODULE_NAME, VIRTUAL_SERVICE_NAME, - __func__, __LINE__, HDF_SUCCESS); - HdfUnRegOneVirtualTest(ITEM_UNREG, type, VIRTUAL_MODULE_NAME, VIRTUAL_SERVICE_NAME1, - __func__, __LINE__, HDF_SUCCESS); - HdfUnRegOneVirtualTest(ITEM_UNREG, type, VIRTUAL_MODULE_NAME, VIRTUAL_SERVICE_NAME2, - __func__, __LINE__, HDF_SUCCESS); - HdfUnRegOneVirtualTest(ITEM_UNREG, type, VIRTUAL_MODULE_NAME, VIRTUAL_SERVICE_NAME2, - __func__, __LINE__, HDF_FAILURE); - /* HDF_VIRTUAL_DEVICE_BaseFunction_AR_006 */ - HdfUnRegOneVirtualTest(ITEM_UNREG, type, VIRTUAL_MODULE_NAME, "test_no_unregister_123", - __func__, __LINE__, HDF_FAILURE); - HdfUnRegOneVirtualTest(ITEM_UNREG, type, VIRTUAL_MODULE_NAME_NO, VIRTUAL_SERVICE_NO_DRIVER, - __func__, __LINE__, HDF_FAILURE); -} - -static bool CheckAllService(const char *name, bool usable) -{ - char **arr = NULL; - int32_t serviceCnt; - if (usable) { - arr = g_testServiceName; - serviceCnt = SERVICE_CNT; - } else { - arr = g_testServiceNameNoDrv; - serviceCnt = SERVICE_NO_DRIVER_CNT; - } - for (int i = 0; i < serviceCnt; i++) { - if (strcmp(name, arr[i]) == 0) { - return true; - } - } - return false; -} - - -void HdfFreeQueryDeviceList(struct DeviceInfoList *list) -{ - struct HDIDeviceManager *iDevmgr = HDIDeviceManagerGet(); - if (iDevmgr == NULL) { - return; - } - - iDevmgr->FreeQueryDeviceList(iDevmgr, list); - - HDIDeviceManagerRelease(iDevmgr); -} - -int32_t HdfQueryUsableDeviceInfo(struct DeviceInfoList *list) -{ - struct HDIDeviceManager *iDevmgr = HDIDeviceManagerGet(); - if (iDevmgr == NULL) { - return HDF_DEV_ERR_NO_DEVICE_SERVICE; - } - - int32_t ret = iDevmgr->QueryUsableDeviceInfo(iDevmgr, list); - - HDIDeviceManagerRelease(iDevmgr); - return ret; -} - -int32_t HdfQueryUnusableDeviceInfo(struct DeviceInfoList *list) -{ - struct HDIDeviceManager *iDevmgr = HDIDeviceManagerGet(); - if (iDevmgr == NULL) { - return HDF_DEV_ERR_NO_DEVICE_SERVICE; - } - - int32_t ret = iDevmgr->QueryUnusableDeviceInfo(iDevmgr, list); - - HDIDeviceManagerRelease(iDevmgr); - return ret; -} - - -static void RegQueryDevice(bool printFlag, bool flag, bool usable) -{ - int32_t ret; - int32_t serviceCnt; - struct DeviceInfoList list; - struct DeviceInfoNode *devNode = NULL; - int cnt = 0; - char *debugInfo = NULL; - if (usable) { - ret = HdfQueryUsableDeviceInfo(&list); - serviceCnt = SERVICE_CNT; - debugInfo = "usable"; - } else { - ret = HdfQueryUnusableDeviceInfo(&list); - serviceCnt = 0; - debugInfo = "un usable"; - } - UT_TEST_CHECK_RET(ret == HDF_SUCCESS, printFlag); - if (ret == HDF_SUCCESS) { - HDF_LOGD("[HDF_TEST] %{public}s %{public}s:%{public}d line:%{public}d", - __func__, debugInfo, list.deviceCnt, __LINE__); - DLIST_FOR_EACH_ENTRY(devNode, &list.list, struct DeviceInfoNode, node) { - HDF_LOGD("[HDF_TEST] %{public}s: %{public}s %{public}d", debugInfo, devNode->svcName, devNode->deviceType); - if (CheckAllService(devNode->svcName, usable)) { - cnt++; - } - } - if (flag) { - UT_TEST_CHECK_RET(cnt == serviceCnt, printFlag); - if (cnt != serviceCnt) { - HDF_LOGE("[HDF_TEST] %{public}s find usable service failed %{public}d != %{public}d", - __func__, cnt, serviceCnt); - printf("[HDF_TEST] %s find usable service failed %d != %d\r\n", __func__, cnt, serviceCnt); - } - } else { - UT_TEST_CHECK_RET(cnt == 0, printFlag); - if (cnt != 0) { - HDF_LOGE("[HDF_TEST] %{public}s find unusable service failed %{public}d != %{public}d", - __func__, cnt, 0); - printf("[HDF_TEST] %s find unusable service failed %d != %d\r\n", __func__, cnt, 0); - } - } - } else { - HDF_LOGE("[HDF_TEST] %{public}s line:%{public}d", __func__, __LINE__); - UT_TEST_CHECK_RET(false, true); - } - HdfFreeQueryDeviceList(&list); -} - -int main(int argc, char **argv) -{ - int testCnt = 1; - bool printFlag = true; - (void)argv; - if (argc != 1) { - testCnt = HDF_REG_DEVICE_MORE; - printFlag = false; - } - for (int i = 0; i < testCnt; i++) { - HdfRegVirtualTest(printFlag); - RegQueryDevice(printFlag, true, true); - RegQueryDevice(printFlag, true, false); - HdfUnRegVirtualTest(printFlag); - RegQueryDevice(printFlag, false, true); - RegQueryDevice(printFlag, false, false); - } - if (argc != 1) { - CheckAverageTime(); - } - PrintTestResult(); - return 0; -} - diff --git a/uhdf2/hdi/test/reg_virtual_device/unittest/sample_driver/hdf_virtual_driver.c b/uhdf2/hdi/test/reg_virtual_device/unittest/sample_driver/hdf_virtual_driver.c deleted file mode 100644 index f7920dd..0000000 --- a/uhdf2/hdi/test/reg_virtual_device/unittest/sample_driver/hdf_virtual_driver.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "hdf_log.h" -#include "hdf_base.h" -#include "hdf_device_desc.h" - -#define HDF_LOG_TAG hdf_virtual_driver - -int32_t HdfVirtualDriverBind(struct HdfDeviceObject *para) -{ - HDF_LOGE("%{public}s", __func__); - static struct IDeviceIoService virtualService = { - .object.objectId = 1, - .Dispatch = NULL, - }; - para->service = &virtualService; - return 0; -} - -int32_t HdfVirtualDriverInit(struct HdfDeviceObject *para) -{ - (void)para; - HDF_LOGE("%{public}s", __func__); - return 0; -} - -void HdfVirtualDriverRelease(struct HdfDeviceObject *para) -{ - (void)para; - - HDF_LOGE("%{public}s", __func__); -} - -struct HdfDriverEntry g_sampleDriverEntry = { - .moduleVersion = 1, - .Bind = HdfVirtualDriverBind, - .Init = HdfVirtualDriverInit, - .Release = HdfVirtualDriverRelease, - .moduleName = "virtual_driver", -}; -HDF_INIT(g_sampleDriverEntry); \ No newline at end of file -- Gitee From ec5020f4b1d40dfe9a2d06daa6596801b883c0cf Mon Sep 17 00:00:00 2001 From: wu Date: Sat, 19 Mar 2022 01:56:51 -0700 Subject: [PATCH 037/102] fixed c79fadc from https://gitee.com/zhiminwu123/drivers_adapter/pulls/498 check the return value of the function Signed-off-by: wu --- khdf/liteos/model/usb/host/src/usb_pnp_notify.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/khdf/liteos/model/usb/host/src/usb_pnp_notify.c b/khdf/liteos/model/usb/host/src/usb_pnp_notify.c index 0063808..712e83b 100644 --- a/khdf/liteos/model/usb/host/src/usb_pnp_notify.c +++ b/khdf/liteos/model/usb/host/src/usb_pnp_notify.c @@ -565,6 +565,7 @@ static int32_t UsbPnpNotifyFirstReportDevice(struct HdfDeviceIoClient *client) { struct UsbPnpNotifyDeviceList *pnpNotifyDevicePos = NULL; struct UsbPnpNotifyDeviceList *pnpNotifyDeviceTemp = NULL; + int32_t ret; dprintf("%s:%d Enter!\n", __func__, __LINE__); @@ -576,7 +577,10 @@ static int32_t UsbPnpNotifyFirstReportDevice(struct HdfDeviceIoClient *client) OsalMutexLock(&g_usbPnpNotifyDevicelistLock); DLIST_FOR_EACH_ENTRY_SAFE(pnpNotifyDevicePos, pnpNotifyDeviceTemp, &g_usbPnpDeviceListHead, struct UsbPnpNotifyDeviceList, deviceList) { - UsbPnpNotifyHdfSendEvent(client->device, pnpNotifyDevicePos->device); + ret = UsbPnpNotifyHdfSendEvent(client->device, pnpNotifyDevicePos->device); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s:%{public}d UsbPnpNotifyHdfSendEvent failed, ret=%{public}d", __func__, __LINE__, ret); + } } OsalMutexUnlock(&g_usbPnpNotifyDevicelistLock); -- Gitee From 1c4b734eed661d066e7a90e92f920bd5d22bb3d9 Mon Sep 17 00:00:00 2001 From: guodongqi Date: Fri, 25 Mar 2022 11:29:08 +0800 Subject: [PATCH 038/102] fix: clear warnings of framework Signed-off-by: guodongqi --- khdf/liteos/manager/src/devmgr_pm_reg.c | 2 +- khdf/liteos/osal/include/osal_uaccess.h | 4 ++-- khdf/liteos/osal/src/osal_file.c | 4 ++-- khdf/liteos/osal/src/osal_firmware.c | 2 +- khdf/liteos/osal/src/osal_irq.c | 10 +++++----- .../hdi/test/servmgr/service_manager_hdi_test.cpp | 2 +- .../sample_driver/sample_hdi_service_stub.cpp | 14 +++++++------- uhdf2/manager/src/devmgr_service_stub.c | 2 +- uhdf2/manager/src/driver_installer_full.c | 4 ++-- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/khdf/liteos/manager/src/devmgr_pm_reg.c b/khdf/liteos/manager/src/devmgr_pm_reg.c index 5ffd3a8..c7d66a0 100755 --- a/khdf/liteos/manager/src/devmgr_pm_reg.c +++ b/khdf/liteos/manager/src/devmgr_pm_reg.c @@ -38,7 +38,7 @@ UINT32 DevmgrPmSuspend(UINT32 mode) { if (mode != LOS_SYS_LIGHT_SLEEP) { - HDF_LOGI("%s: hdf Suspend %d", __func__, mode); + HDF_LOGI("%s: hdf Suspend %u", __func__, mode); } HDF_LOGI("%s hdf suspend start", __func__); diff --git a/khdf/liteos/osal/include/osal_uaccess.h b/khdf/liteos/osal/include/osal_uaccess.h index f8a69a6..dee3510 100644 --- a/khdf/liteos/osal/include/osal_uaccess.h +++ b/khdf/liteos/osal/include/osal_uaccess.h @@ -38,12 +38,12 @@ extern "C" { #endif /* __cplusplus */ -static inline size_t CopyToUser (void* to, const void* from, size_t len) +static inline size_t CopyToUser(void* to, const void* from, size_t len) { return LOS_ArchCopyToUser(to, from, len); } -static inline size_t CopyFromUser (void* to, const void* from, size_t len) +static inline size_t CopyFromUser(void* to, const void* from, size_t len) { return LOS_ArchCopyFromUser(to, from, len); } diff --git a/khdf/liteos/osal/src/osal_file.c b/khdf/liteos/osal/src/osal_file.c index 86bf118..d5da1a1 100644 --- a/khdf/liteos/osal/src/osal_file.c +++ b/khdf/liteos/osal/src/osal_file.c @@ -56,7 +56,7 @@ int32_t OsalFileOpen(OsalFile *file, const char *path, int flags, uint32_t right fd = open(pathName, flags, rights); if (fd < 0) { - HDF_LOGE("%s open file fail %d %d %d", __func__, flags, rights, errno); + HDF_LOGE("%s open file fail %d %u %d", __func__, flags, rights, errno); return HDF_FAILURE; } @@ -104,7 +104,7 @@ ssize_t OsalFileRead(OsalFile *file, void *buf, uint32_t length) ret = read((int32_t)(uintptr_t)file->realFile, buf, length); if (ret < 0) { - HDF_LOGE("%s read file fail %d %d", __func__, length, errno); + HDF_LOGE("%s read file fail %u %d", __func__, length, errno); return HDF_FAILURE; } diff --git a/khdf/liteos/osal/src/osal_firmware.c b/khdf/liteos/osal/src/osal_firmware.c index b7a3d55..3b90f7f 100644 --- a/khdf/liteos/osal/src/osal_firmware.c +++ b/khdf/liteos/osal/src/osal_firmware.c @@ -153,7 +153,7 @@ int32_t OsalReadFirmware(struct OsalFirmware *fwPara, struct OsalFwBlock *block) readOffset = (uint32_t)lseek(fw->fd, fw->offset, SEEK_SET); if (readOffset != fw->offset) { - HDF_LOGE("%s seek offset fail %d %d", __func__, readOffset, fw->offset); + HDF_LOGE("%s seek offset fail %u %d", __func__, readOffset, fw->offset); return HDF_FAILURE; } readSize = (uint32_t)read(fw->fd, block->data, block->dataSize); diff --git a/khdf/liteos/osal/src/osal_irq.c b/khdf/liteos/osal/src/osal_irq.c index e2a19c6..33f53ed 100644 --- a/khdf/liteos/osal/src/osal_irq.c +++ b/khdf/liteos/osal/src/osal_irq.c @@ -49,7 +49,7 @@ int32_t OsalRegisterIrq(uint32_t irqId, uint32_t config, OsalIRQHandle handle, c irqParam.pName = name; ret = LOS_HwiCreate(irqId, 0, (HWI_MODE_T)config, (HWI_PROC_FUNC)handle, &irqParam); if (ret != LOS_OK) { - HDF_LOGE("%s %d register fail 0x%x", __func__, irqId, ret); + HDF_LOGE("%s %u register fail 0x%x", __func__, irqId, ret); return HDF_FAILURE; } HalIrqUnmask(irqId); @@ -63,7 +63,7 @@ int32_t OsalUnregisterIrq(uint32_t irqId, void *dev) HwiIrqParam irqParam; if (irqId >= OS_HWI_MAX_NUM) { - HDF_LOGE("invalid irq number %d\n", irqId); + HDF_LOGE("invalid irq number %u\n", irqId); return HDF_ERR_INVALID_PARAM; } @@ -71,7 +71,7 @@ int32_t OsalUnregisterIrq(uint32_t irqId, void *dev) irqParam.pDevId = dev; ret = LOS_HwiDelete(irqId, &irqParam); if (ret != LOS_OK) { - HDF_LOGE("irq %d unregister fail %d\n", irqId, ret); + HDF_LOGE("irq %u unregister fail %u\n", irqId, ret); return HDF_FAILURE; } @@ -81,7 +81,7 @@ int32_t OsalUnregisterIrq(uint32_t irqId, void *dev) int32_t OsalEnableIrq(uint32_t irqId) { if (irqId >= OS_HWI_MAX_NUM) { - HDF_LOGE("invalid irq number %d\n", irqId); + HDF_LOGE("invalid irq number %u\n", irqId); return HDF_ERR_INVALID_PARAM; } @@ -93,7 +93,7 @@ int32_t OsalEnableIrq(uint32_t irqId) int32_t OsalDisableIrq(uint32_t irqId) { if (irqId >= OS_HWI_MAX_NUM) { - HDF_LOGE("invalid irq number %d\n", irqId); + HDF_LOGE("invalid irq number %u\n", irqId); return HDF_ERR_INVALID_PARAM; } diff --git a/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp b/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp index 3a648db..03acd0d 100644 --- a/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp +++ b/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp @@ -196,7 +196,7 @@ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest006, TestSize.Level1) } /* - * Test device manager Load/UnLoad deivce and driver dynamic register device + * Test device manager Load/UnLoad device and driver dynamic register device */ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest007, TestSize.Level1) { diff --git a/uhdf2/host/test/unittest/sample_driver/sample_hdi_service_stub.cpp b/uhdf2/host/test/unittest/sample_driver/sample_hdi_service_stub.cpp index 355d937..48fb083 100644 --- a/uhdf2/host/test/unittest/sample_driver/sample_hdi_service_stub.cpp +++ b/uhdf2/host/test/unittest/sample_driver/sample_hdi_service_stub.cpp @@ -29,7 +29,7 @@ static int32_t SampleServiceStubPing(struct HdfDeviceIoClient *client, struct Hd if (!HdfDeviceObjectCheckInterfaceDesc(client->device, data)) { return HDF_ERR_INVALID_PARAM; } - char *outInfo = NULL; + char *outInfo = nullptr; const char *info = HdfSbufReadString(data); int32_t ret = SampleHdiImplInstance()->ping(client->device, info, &outInfo); @@ -80,7 +80,7 @@ static int32_t SampleServiceStubCallback(struct HdfDeviceIoClient *client, struc } struct HdfRemoteService *callback = HdfSbufReadRemoteService(data); - if (callback == NULL) { + if (callback == nullptr) { HDF_LOGE("SampleHdi.callback: miss parameter callback"); return HDF_ERR_INVALID_PARAM; } @@ -95,7 +95,7 @@ static int32_t SampleServiceStubStructTrans( return HDF_ERR_INVALID_PARAM; } struct DataBlock *dataBlock = DataBlockBlockUnmarshalling(data); - if (dataBlock == NULL) { + if (dataBlock == nullptr) { HDF_LOGE("SampleServiceStubStructTrans: failed to read dataBlock"); return HDF_ERR_INVALID_PARAM; } @@ -120,7 +120,7 @@ static int32_t SampleServiceStubBufferTrans( } constexpr int SAMPLE_TEST_BUFFER_SIZE = 10; const uint8_t *buffer = HdfSbufReadUnpadBuffer(data, SAMPLE_TEST_BUFFER_SIZE); - if (buffer == NULL) { + if (buffer == nullptr) { HDF_LOGI("SampleServiceStubBufferTrans: read buffer failed"); return HDF_ERR_INVALID_PARAM; } @@ -143,7 +143,7 @@ static int32_t SampleServiceRegisterDevice( } (void)reply; const char *deviceName = HdfSbufReadString(data); - if (deviceName == NULL) { + if (deviceName == nullptr) { return HDF_ERR_INVALID_PARAM; } @@ -158,7 +158,7 @@ static int32_t SampleServiceUnregisterDevice( return HDF_ERR_INVALID_PARAM; } const char *deviceName = HdfSbufReadString(data); - if (deviceName == NULL) { + if (deviceName == nullptr) { return HDF_ERR_INVALID_PARAM; } @@ -171,7 +171,7 @@ static int32_t SampleServiceUpdateDevice(struct HdfDeviceIoClient *client, struc return HDF_ERR_INVALID_PARAM; } const char *servInfo = HdfSbufReadString(data); - if (servInfo == NULL) { + if (servInfo == nullptr) { return HDF_ERR_INVALID_PARAM; } diff --git a/uhdf2/manager/src/devmgr_service_stub.c b/uhdf2/manager/src/devmgr_service_stub.c index 25f8ed2..be0ecdf 100644 --- a/uhdf2/manager/src/devmgr_service_stub.c +++ b/uhdf2/manager/src/devmgr_service_stub.c @@ -169,7 +169,7 @@ static int32_t MakeModulePath(char *buffer, const char *moduleName) char *path = realpath(temp, buffer); if (path == NULL || strncmp(path, HDF_MODULE_DIR, strlen(HDF_MODULE_DIR)) != 0) { - HDF_LOGE("driver module file is invalud: %{public}s", temp); + HDF_LOGE("driver module file is invalid: %{public}s", temp); return HDF_ERR_INVALID_PARAM; } diff --git a/uhdf2/manager/src/driver_installer_full.c b/uhdf2/manager/src/driver_installer_full.c index af1bbfa..4f56e04 100644 --- a/uhdf2/manager/src/driver_installer_full.c +++ b/uhdf2/manager/src/driver_installer_full.c @@ -35,13 +35,13 @@ int DriverInstallerFullStartDeviceHost(uint32_t devHostId, const char* devHostNa char hostIdStr[MAX_CMD_LEN] = {0}; int ret; - if (snprintf_s(hostIdStr, sizeof(hostIdStr), sizeof(hostIdStr) - 1, " %d", devHostId) < 0) { + if (snprintf_s(hostIdStr, sizeof(hostIdStr), sizeof(hostIdStr) - 1, " %u", devHostId) < 0) { HDF_LOGE("starting device host, snprintf_s failed"); return HDF_FAILURE; } const char *args[] = { hostIdStr, devHostName }; ret = ServiceControlWithExtra(devHostName, START, args, PARAM_CNT); - HDF_LOGI("%{public}s %{public}s %{public}d %{public}d", __func__, devHostName, devHostId, ret); + HDF_LOGI("%{public}s %{public}s %{public}u %{public}d", __func__, devHostName, devHostId, ret); return HDF_SUCCESS; } -- Gitee From 14aa05d9fd677a469889757f0258f5fc6417e656 Mon Sep 17 00:00:00 2001 From: mahai Date: Fri, 25 Mar 2022 10:52:23 +0800 Subject: [PATCH 039/102] fix:Modify the build script Signed-off-by: mahai --- uhdf/test/unittest/platform/BUILD.gn | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/uhdf/test/unittest/platform/BUILD.gn b/uhdf/test/unittest/platform/BUILD.gn index 487859f..12781ec 100644 --- a/uhdf/test/unittest/platform/BUILD.gn +++ b/uhdf/test/unittest/platform/BUILD.gn @@ -45,14 +45,10 @@ if (board_name == "hi3516dv300" || board_name == "hispark_taurus") { "//drivers/framework/support/platform/test/unittest/common/hdf_regulator_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_rtc_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_spi_test.cpp", - "//drivers/framework/support/platform/test/unittest/common/hdf_uart_test.cpp", - "//drivers/framework/support/platform/test/unittest/common/hdf_watchdog_test.cpp", "//drivers/framework/test/unittest/platform/common/gpio_test.c", "//drivers/framework/test/unittest/platform/common/pwm_test.c", "//drivers/framework/test/unittest/platform/common/rtc_test.c", "//drivers/framework/test/unittest/platform/common/spi_test.c", - "//drivers/framework/test/unittest/platform/common/uart_test.c", - "//drivers/framework/test/unittest/platform/common/watchdog_test.c", ] if (ohos_kernel_type == "liteos_a") { sources += [ @@ -64,9 +60,13 @@ if (board_name == "hi3516dv300" || board_name == "hispark_taurus") { "//drivers/framework/support/platform/test/unittest/common/hdf_pcie_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_pin_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_timer_test.cpp", + "//drivers/framework/support/platform/test/unittest/common/hdf_uart_test.cpp", + "//drivers/framework/support/platform/test/unittest/common/hdf_watchdog_test.cpp", "//drivers/framework/test/unittest/platform/common/adc_test.c", "//drivers/framework/test/unittest/platform/common/dac_test.c", "//drivers/framework/test/unittest/platform/common/timer_test.c", + "//drivers/framework/test/unittest/platform/common/uart_test.c", + "//drivers/framework/test/unittest/platform/common/watchdog_test.c", ] } if (storage_type == "emmc") { -- Gitee From b80b4b07cf19bf53327c1362b2092339b6b75942 Mon Sep 17 00:00:00 2001 From: wu-chengwen Date: Sat, 12 Mar 2022 09:39:06 +0800 Subject: [PATCH 040/102] fix(usb):change uintptr_t to uint64,fix usb hcs bug Signed-off-by: wu-chengwen --- khdf/liteos/model/usb/host/include/usb_pnp_notify.h | 2 +- khdf/liteos/model/usb/host/src/usb_pnp_notify.c | 10 +++++----- uhdf2/hcs/BUILD.gn | 11 ----------- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/khdf/liteos/model/usb/host/include/usb_pnp_notify.h b/khdf/liteos/model/usb/host/include/usb_pnp_notify.h index 82661d7..242123f 100755 --- a/khdf/liteos/model/usb/host/include/usb_pnp_notify.h +++ b/khdf/liteos/model/usb/host/include/usb_pnp_notify.h @@ -83,7 +83,7 @@ struct UsbInfoQueryPara { UsbInfoQueryParaType type; union { int32_t id; - uintptr_t usbDevAddr; + uint64_t usbDevAddr; struct { int32_t devNum; int32_t busNum; diff --git a/khdf/liteos/model/usb/host/src/usb_pnp_notify.c b/khdf/liteos/model/usb/host/src/usb_pnp_notify.c index f7982e9..7a0775f 100644 --- a/khdf/liteos/model/usb/host/src/usb_pnp_notify.c +++ b/khdf/liteos/model/usb/host/src/usb_pnp_notify.c @@ -206,7 +206,7 @@ static int32_t UsbPnpNotifyAddInitInfo(struct UsbPnpDeviceInfo *deviceInfo, unio { int32_t ret = HDF_SUCCESS; - deviceInfo->info.usbDevAddr = (uintptr_t)infoData.usbDev; + deviceInfo->info.usbDevAddr = (uint64_t)infoData.usbDev; deviceInfo->info.devNum = infoData.usbDev->address; deviceInfo->info.busNum = (int32_t)infoData.usbDev->port_no; @@ -387,7 +387,7 @@ static int32_t UsbPnpNotifyGetDeviceInfo(void *eventData, union UsbPnpDeviceInfo } else if ((g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_ADD_DEVICE) || (g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_REMOVE_DEVICE)) { infoQueryPara.type = USB_INFO_DEVICE_ADDRESS_TYPE; - infoQueryPara.usbDevAddr = (uintptr_t)pnpInfoData->usbDev; + infoQueryPara.usbDevAddr = (uint64_t)pnpInfoData->usbDev; *deviceInfo = UsbPnpNotifyFindInfo(infoQueryPara); } else { *deviceInfo = UsbPnpNotifyCreateInfo(); @@ -536,8 +536,8 @@ static int32_t TestPnpNotifyHdfSendEvent(const struct HdfDeviceObject *deviceObj goto OUT; } - HDF_LOGI("%s: report one device information, %d usbDev=0x%x, devNum=%d, busNum=%d, infoTable=%d-0x%x-0x%x!", \ - __func__, g_usbPnpNotifyCmdType, (uint32_t)infoTable.usbDevAddr, infoTable.devNum, infoTable.busNum, \ + HDF_LOGI("%s: report one device information, %d usbDev=%llu, devNum=%d, busNum=%d, infoTable=%d-0x%x-0x%x!", \ + __func__, g_usbPnpNotifyCmdType, infoTable.usbDevAddr, infoTable.devNum, infoTable.busNum, \ infoTable.numInfos, infoTable.deviceInfo.vendorId, infoTable.deviceInfo.productId); ret = UsbPnpNotifySendEventLoader(data); @@ -710,7 +710,7 @@ static void UsbPnpNotifyDetachDevice(struct usb_device *udev) if (UsbPnpNotifyFindDeviceList(udev, true) == true) { infoQueryPara.type = USB_INFO_DEVICE_ADDRESS_TYPE; - infoQueryPara.usbDevAddr = (uintptr_t)udev; + infoQueryPara.usbDevAddr = (uint64_t)udev; deviceInfo = UsbPnpNotifyFindInfo(infoQueryPara); if (deviceInfo == NULL) { PRINTK("%s:%d USB_DEVICE_REMOVE find info failed", __func__, __LINE__); diff --git a/uhdf2/hcs/BUILD.gn b/uhdf2/hcs/BUILD.gn index 077f2c9..5c988c8 100644 --- a/uhdf2/hcs/BUILD.gn +++ b/uhdf2/hcs/BUILD.gn @@ -16,18 +16,7 @@ import("//drivers/adapter/uhdf2/uhdf.gni") import("$hdf_framework_path/tools/hc-gen/hc_gen.gni") hc_gen("build_hcs") { - gadget = "acm" - if (product_name == "Hi3516DV300" || product_name == "watchos") { - gadget = "ecm_acm" - } hcs_source = "/hdf.hcs" - if (gadget == "acm") { - hcs_source = "/hdf.hcs" - } else if (gadget == "ecm") { - hcs_source = "/hdf_ecm.hcs" - } else if (gadget == "ecm_acm") { - hcs_source = "/hdf_ecm_acm.hcs" - } if (product_company == "openharmony") { hcs_config_path = "default" -- Gitee From b34ba99f795a60172543c685909bdb95dc859cdb Mon Sep 17 00:00:00 2001 From: fanxiaoyu Date: Sat, 26 Mar 2022 06:07:03 +0000 Subject: [PATCH 041/102] Description:Add check null pointer. Feature or Bugfix:Bugfix Binary Source: No Signed-off-by: fanxiaoyu --- khdf/liteos/model/misc/dsoftbus/src/softbus_lwip_monitor.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/khdf/liteos/model/misc/dsoftbus/src/softbus_lwip_monitor.c b/khdf/liteos/model/misc/dsoftbus/src/softbus_lwip_monitor.c index 4dc2b97..9330256 100644 --- a/khdf/liteos/model/misc/dsoftbus/src/softbus_lwip_monitor.c +++ b/khdf/liteos/model/misc/dsoftbus/src/softbus_lwip_monitor.c @@ -77,9 +77,8 @@ static void NetifStatusCallback(struct netif *netif, netif_nsc_reason_t reason, LwipMonitorReportInfo reportInfo; bool needReport = true; - (void)args; - if (netif == NULL) { - dprintf("NetifStatusCallback: input netif is NULL\n"); + if (netif == NULL || args == NULL) { + dprintf("NetifStatusCallback: input args is NULL\n"); return; } dprintf("NetifStatusCallback(%s): nsc event: 0x%x\n", netif->full_name, (uint32_t)reason); -- Gitee From e8f4bcc79cc65afba306b9375b1c2947fc54f6e8 Mon Sep 17 00:00:00 2001 From: guodongqi Date: Mon, 28 Mar 2022 15:08:07 +0800 Subject: [PATCH 042/102] fix: delete virtual Signed-off-by: guodongqi --- uhdf2/hdi/src/iservmgr_client.cpp | 6 +++--- uhdf2/ipc/src/hdf_sbuf_impl_hipc.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/uhdf2/hdi/src/iservmgr_client.cpp b/uhdf2/hdi/src/iservmgr_client.cpp index 6af2b51..6977b65 100644 --- a/uhdf2/hdi/src/iservmgr_client.cpp +++ b/uhdf2/hdi/src/iservmgr_client.cpp @@ -33,10 +33,10 @@ public: explicit ServiceManagerProxy(const sptr& impl) : IRemoteProxy(impl) {} ~ServiceManagerProxy() {} - virtual sptr GetService(const char* serviceName) override; - virtual int32_t RegisterServiceStatusListener(::OHOS::sptr listener, + sptr GetService(const char* serviceName) override; + int32_t RegisterServiceStatusListener(::OHOS::sptr listener, uint16_t deviceClass) override; - virtual int32_t UnregisterServiceStatusListener(::OHOS::sptr listener) override; + int32_t UnregisterServiceStatusListener(::OHOS::sptr listener) override; private: static inline BrokerDelegator delegator_; }; diff --git a/uhdf2/ipc/src/hdf_sbuf_impl_hipc.cpp b/uhdf2/ipc/src/hdf_sbuf_impl_hipc.cpp index 4babc24..f6d0c06 100644 --- a/uhdf2/ipc/src/hdf_sbuf_impl_hipc.cpp +++ b/uhdf2/ipc/src/hdf_sbuf_impl_hipc.cpp @@ -457,20 +457,20 @@ extern "C" struct HdfSBufImpl *SbufObtainIpc(size_t capacity) class SbufAllocator : public Allocator { public: - virtual void *Realloc(void *data, size_t newSize) override + void *Realloc(void *data, size_t newSize) override { (void)data; (void)newSize; return nullptr; } - virtual void *Alloc(size_t size) override + void *Alloc(size_t size) override { (void)size; return nullptr; } - virtual void Dealloc(void *data) override + void Dealloc(void *data) override { (void)data; } -- Gitee From d154084638f6c24a4a860aa4b2dbd7ff0d5bd15d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cwangyougang=E2=80=9D?= Date: Mon, 28 Mar 2022 07:49:23 +0000 Subject: [PATCH 043/102] fix:clear codex wifi adapter drivers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: “wangyougang” --- khdf/liteos/model/network/wifi/platform/src/hdf_wlan_queue.c | 4 ++-- khdf/liteos_m/network/src/net_device_adapter.c | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/khdf/liteos/model/network/wifi/platform/src/hdf_wlan_queue.c b/khdf/liteos/model/network/wifi/platform/src/hdf_wlan_queue.c index 153f946..f383401 100644 --- a/khdf/liteos/model/network/wifi/platform/src/hdf_wlan_queue.c +++ b/khdf/liteos/model/network/wifi/platform/src/hdf_wlan_queue.c @@ -61,7 +61,7 @@ void DestroyQueue(HdfWlanQueue *queue) HdfWlanQueueImpl *queueImpl = (HdfWlanQueueImpl *)queue; uint32_t status = LOS_QueueDelete(queueImpl->queueID); if (status != LOS_OK) { - HDF_LOGE("Destroy message queue failed!err=%d", status); + HDF_LOGE("Destroy message queue failed!err=%u", status); } OsalMemFree(queue); } @@ -93,7 +93,7 @@ int32_t PushQueue(HdfWlanQueue *queue, void *context) uint32_t ret = LOS_QueueWriteCopy(queueImpl->queueID, &context, sizeof(void *), LOS_WAIT_FOREVER); if (ret != LOS_OK) { - HDF_LOGE("%s:Write queue failed!ret=%d", __func__, ret); + HDF_LOGE("%s:Write queue failed!ret=%u", __func__, ret); return HDF_FAILURE; } return HDF_SUCCESS; diff --git a/khdf/liteos_m/network/src/net_device_adapter.c b/khdf/liteos_m/network/src/net_device_adapter.c index 7888835..55ab63e 100644 --- a/khdf/liteos_m/network/src/net_device_adapter.c +++ b/khdf/liteos_m/network/src/net_device_adapter.c @@ -71,6 +71,7 @@ static int32_t LiteNetDevInit(struct NetDeviceImpl *netDeviceImpl) HDF_LOGI("%s Success!", __func__); return HDF_SUCCESS; } + static int32_t LiteNetDevDeInit(struct NetDeviceImpl *netDeviceImpl) { if (netDeviceImpl == NULL) { -- Gitee From b85a0bb9583b2c724e535a946ad8da35099cdec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cwangyipeng=E2=80=9D?= Date: Mon, 28 Mar 2022 09:50:47 +0800 Subject: [PATCH 044/102] Fix:Clear the USB module alarm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: “wangyipeng” --- .../model/usb/host/src/usb_pnp_notify.c | 62 ++++++++----------- 1 file changed, 25 insertions(+), 37 deletions(-) diff --git a/khdf/liteos/model/usb/host/src/usb_pnp_notify.c b/khdf/liteos/model/usb/host/src/usb_pnp_notify.c index 2b916d5..9c15f7c 100644 --- a/khdf/liteos/model/usb/host/src/usb_pnp_notify.c +++ b/khdf/liteos/model/usb/host/src/usb_pnp_notify.c @@ -80,7 +80,7 @@ static bool UsbPnpNotifyFindDeviceList(struct usb_device *deviceObj, bool freeFl struct UsbPnpNotifyDeviceList, deviceList) { if (pnpNotifyDevicePos->device == deviceObj) { findFlag = true; - if (freeFlag == true) { + if (freeFlag) { DListRemove(&pnpNotifyDevicePos->deviceList); OsalMemFree(&pnpNotifyDevicePos); } @@ -96,32 +96,21 @@ static bool UsbPnpNotifyFindDeviceList(struct usb_device *deviceObj, bool freeFl static struct UsbPnpDeviceInfo *UsbPnpNotifyCreateInfo(void) { struct UsbPnpDeviceInfo *infoTemp = NULL; - unsigned char *ptr = NULL; static int32_t idNum = 0; - int32_t ret; - ptr = OsalMemCalloc(sizeof(struct UsbPnpDeviceInfo)); - if (ptr == NULL) { - HDF_LOGE("%s:%d OsalMemAlloc faile ", __func__, __LINE__); + infoTemp = (struct UsbPnpDeviceInfo *)OsalMemCalloc(sizeof(struct UsbPnpDeviceInfo)); + if (infoTemp == NULL) { + HDF_LOGE("%s:%d OsalMemAlloc failed ", __func__, __LINE__); return NULL; } - infoTemp = (struct UsbPnpDeviceInfo *)ptr; - if (idNum++ >= INT32_MAX) { + if (idNum++ == INT32_MAX) { idNum = 0; } infoTemp->id = idNum; OsalMutexInit(&infoTemp->lock); infoTemp->status = USB_PNP_DEVICE_INIT_STATUS; DListHeadInit(&infoTemp->list); - ret = memset_s(infoTemp->interfaceRemoveStatus, USB_PNP_INFO_MAX_INTERFACES, - 0, sizeof(infoTemp->interfaceRemoveStatus)); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%{public}s:%{public}d memset_s failed", __func__, __LINE__); - OsalMemFree(ptr); - return NULL; - } - DListInsertTail(&infoTemp->list, &g_usbPnpInfoListHead); return infoTemp; @@ -134,7 +123,7 @@ static struct UsbPnpDeviceInfo *UsbPnpNotifyFindInfo(struct UsbInfoQueryPara que bool findFlag = false; if (DListIsEmpty(&g_usbPnpInfoListHead)) { - HDF_LOGE("%s:%d usb pnp list head is empty. ", __func__, __LINE__); + HDF_LOGE("%s:%d usb pnp list head is empty.", __func__, __LINE__); return NULL; } @@ -159,13 +148,13 @@ static struct UsbPnpDeviceInfo *UsbPnpNotifyFindInfo(struct UsbInfoQueryPara que break; } - if (findFlag == true) { + if (findFlag) { break; } } - if (findFlag == false) { - HDF_LOGE("%s:%d the usb pnp info to be find does not exist. ", __func__, __LINE__); + if (!findFlag) { + HDF_LOGE("%s:%d the usb pnp info to be find does not exist.", __func__, __LINE__); return NULL; } else { return infoPos; @@ -181,7 +170,7 @@ static HDF_STATUS UsbPnpNotifyDestroyInfo(struct UsbPnpDeviceInfo *deviceInfo) if (deviceInfo == NULL) { ret = HDF_FAILURE; - HDF_LOGE("%s:%d the deviceInfo is NULL, ret=%d ", __func__, __LINE__, ret); + HDF_LOGE("%s:%d the deviceInfo is NULL, ret = %d ", __func__, __LINE__, ret); return ret; } @@ -200,9 +189,9 @@ static HDF_STATUS UsbPnpNotifyDestroyInfo(struct UsbPnpDeviceInfo *deviceInfo) } } - if (findFlag == false) { + if (!findFlag) { ret = HDF_FAILURE; - HDF_LOGE("%s:%d the deviceInfoto be destroyed does not exist, ret=%d ", __func__, __LINE__, ret); + HDF_LOGE("%s:%d the deviceInfoto be destroyed does not exist, ret = %d ", __func__, __LINE__, ret); } return ret; @@ -232,8 +221,7 @@ static int32_t UsbPnpNotifyAddInitInfo(struct UsbPnpDeviceInfo *deviceInfo, unio deviceInfo->info.numInfos = infoData.usbDev->cdesc->bNumInterface; for (uint8_t i = 0; i < deviceInfo->info.numInfos; i++) { if (infoData.usbDev->ifaces[i].idesc == NULL) { - HDF_LOGE("%s:%d interface[%d].idesc is NULL", - __func__, __LINE__, i); + HDF_LOGE("%s:%d interface[%hhu].idesc is NULL", __func__, __LINE__, i); ret = HDF_ERR_INVALID_PARAM; goto OUT; } @@ -246,7 +234,7 @@ static int32_t UsbPnpNotifyAddInitInfo(struct UsbPnpDeviceInfo *deviceInfo, unio deviceInfo->info.interfaceInfo[i].interfaceNumber = infoData.usbDev->ifaces[i].idesc->bInterfaceNumber; - HDF_LOGI("%s:%d i=%d, interfaceInfo=0x%x-0x%x-0x%x-0x%x", + HDF_LOGI("%s:%d i = %hhu, interfaceInfo=0x%x-0x%x-0x%x-0x%x", __func__, __LINE__, i, deviceInfo->info.interfaceInfo[i].interfaceClass, deviceInfo->info.interfaceInfo[i].interfaceSubClass, deviceInfo->info.interfaceInfo[i].interfaceProtocol, @@ -285,7 +273,7 @@ static void UsbPnpNotifyAddInterfaceInitInfo(struct UsbPnpDeviceInfo *deviceInfo } else { for (i = 0, j = 0; i < deviceInfo->info.numInfos; i++) { if (deviceInfo->interfaceRemoveStatus[i] == true) { - HDF_LOGI("%s:%d j=%d deviceInfo->interfaceRemoveStatus[%d] is true!", __func__, __LINE__, j, i); + HDF_LOGI("%s:%d j = %hhu deviceInfo->interfaceRemoveStatus[%hhu] is true!", __func__, __LINE__, j, i); continue; } infoTable->interfaceInfo[j].interfaceClass = deviceInfo->info.interfaceInfo[i].interfaceClass; @@ -294,7 +282,7 @@ static void UsbPnpNotifyAddInterfaceInitInfo(struct UsbPnpDeviceInfo *deviceInfo infoTable->interfaceInfo[j].interfaceNumber = deviceInfo->info.interfaceInfo[i].interfaceNumber; j++; - HDF_LOGI("%s:%d i=%d, j=%d, interfaceInfo=0x%x-0x%x-0x%x-0x%x", + HDF_LOGI("%s:%d i = %d, j = %d, interfaceInfo=0x%x-0x%x-0x%x-0x%x", __func__, __LINE__, i, j - 1, infoTable->interfaceInfo[j - 1].interfaceClass, infoTable->interfaceInfo[j - 1].interfaceSubClass, infoTable->interfaceInfo[j - 1].interfaceProtocol, @@ -310,8 +298,8 @@ static int32_t UsbPnpNotifyInitInfo( int32_t ret = HDF_SUCCESS; const void *data = NULL; - if ((g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_ADD_INTERFACE) - || (g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_REMOVE_INTERFACE)) { + if ((g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_ADD_INTERFACE) || + (g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_REMOVE_INTERFACE)) { static struct UsbPnpNotifyMatchInfoTable infoTable; infoTable.usbDevAddr = deviceInfo->info.usbDevAddr; @@ -476,7 +464,7 @@ static void TestReadPnpInfo(struct HdfSBuf *data) bool flag; flag = HdfSbufReadBuffer(data, (const void **)(&g_testUsbPnpInfo), &infoSize); - if ((flag == false) || (g_testUsbPnpInfo == NULL)) { + if ((!flag) || (g_testUsbPnpInfo == NULL)) { HDF_LOGE("%s: fail to read g_testUsbPnpInfo, flag=%d, g_testUsbPnpInfo=%px", \ __func__, flag, g_testUsbPnpInfo); return; @@ -687,12 +675,12 @@ static void UsbPnpNotifyAttachDevice(struct usb_device *udev) int32_t error; static int32_t listLockInit = 0; - if ((udev->ddesc.bDeviceClass == UICLASS_HUB) || UsbPnpNotifyFindDeviceList(udev, false) == true) { + if ((udev->ddesc.bDeviceClass == UICLASS_HUB) || UsbPnpNotifyFindDeviceList(udev, false)) { PRINTK("%s:%d findDeviceList is true!\n", __func__, __LINE__); return; } - if (0 == listLockInit) { + if (listLockInit == 0) { error = OsalMutexInit(&g_usbPnpNotifyDevicelistLock); if (error != HDF_SUCCESS) { HDF_LOGE("%s:%d error=%d!", __func__, __LINE__, error); @@ -718,7 +706,7 @@ static void UsbPnpNotifyDetachDevice(struct usb_device *udev) struct UsbInfoQueryPara infoQueryPara; struct UsbPnpDeviceInfo *deviceInfo = NULL; - if (UsbPnpNotifyFindDeviceList(udev, true) == true) { + if (UsbPnpNotifyFindDeviceList(udev, true)) { infoQueryPara.type = USB_INFO_DEVICE_ADDRESS_TYPE; infoQueryPara.usbDevAddr = (uint64_t)udev; deviceInfo = UsbPnpNotifyFindInfo(infoQueryPara); @@ -780,7 +768,7 @@ struct usb_device *UsbPnpNotifyGetUsbDevice(struct UsbGetDevicePara paraData) break; } - if (findFlag == true) { + if (findFlag) { usbPnpDevice = pnpNotifyDevicePos->device; break; } @@ -799,7 +787,7 @@ static void UsbPnpNotifyReadPnpInfo(struct HdfSBuf *data) bool flag; flag = HdfSbufReadBuffer(data, (const void **)(&usbPnpInfo), &infoSize); - if ((flag == false) || (usbPnpInfo == NULL)) { + if ((!flag) || (usbPnpInfo == NULL)) { HDF_LOGE("%s:%d fail to read g_usbPnpInfo, flag=%d", __func__, __LINE__, flag); return; } @@ -987,7 +975,7 @@ static int32_t UsbPnpNotifyInit(struct HdfDeviceObject *device) return HDF_ERR_INVALID_OBJECT; } - if (firstInitFlag == true) { + if (firstInitFlag) { firstInitFlag = false; DListHeadInit(&g_usbPnpInfoListHead); -- Gitee From 80d8f87596d608d57befc56ffea63c8850664287 Mon Sep 17 00:00:00 2001 From: yafeng_wang Date: Mon, 28 Mar 2022 22:05:10 +0800 Subject: [PATCH 045/102] fix: delete extra whitespaces, and change switch logic in mtd_char_lite.c. Signed-off-by: yafeng_wang --- khdf/liteos/model/storage/src/mtd/mtd_char_lite.c | 6 +++++- khdf/liteos/platform/src/gpio_dev.c | 2 +- khdf/liteos/platform/src/i2c_dev.c | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/khdf/liteos/model/storage/src/mtd/mtd_char_lite.c b/khdf/liteos/model/storage/src/mtd/mtd_char_lite.c index e8fadcc..398f44a 100644 --- a/khdf/liteos/model/storage/src/mtd/mtd_char_lite.c +++ b/khdf/liteos/model/storage/src/mtd/mtd_char_lite.c @@ -283,7 +283,7 @@ static int MtdCharIoctlGetInfo(const mtd_partition *part, const struct MtdDevice (void)cmd; - MtdCharGetMtdInfo(mtdDevice, &mtdInfo); + MtdCharGetMtdInfo(mtdDevice, &mtdInfo); startAddr = part->start_block * mtdDevice->eraseSize; endAddr = (part->end_block + 1) * mtdDevice->eraseSize; ret = LOS_CopyFromKernel((void *)(uintptr_t)arg, sizeof(mtdInfo), (void *)&mtdInfo, sizeof(mtdInfo)); @@ -361,16 +361,20 @@ static int MtdCharIoctl(FAR struct file *filep, int cmd, unsigned long arg) switch (cmd) { case MTD_IOC_GETINFO: { ret = MtdCharIoctlGetInfo(partition, mtdDevice, cmd, arg); + break; } case MTD_IOC_ERASE: case MTD_IOC_ERASE64: { ret = MtdCharIoctlErase(partition, mtdDevice, cmd, arg); + break; } case MTD_IOC_GETBADBLOCK: { ret = MtdCharIoctlGetBadBlock(partition, mtdDevice, cmd, arg); + break; } case MTD_IOC_SETBADBLOCK: { ret = MtdCharIoctlSetBadBlock(partition, mtdDevice, cmd, arg); + break; } case MTD_IOC_SETFILEMODE: mfi->mode = 0; diff --git a/khdf/liteos/platform/src/gpio_dev.c b/khdf/liteos/platform/src/gpio_dev.c index dd9f605..f105890 100644 --- a/khdf/liteos/platform/src/gpio_dev.c +++ b/khdf/liteos/platform/src/gpio_dev.c @@ -102,7 +102,7 @@ static int GpioIoctl(struct file *filep, int cmd, unsigned long arg) uint16_t bitNum; uint16_t gpio; struct GpioBitInfo info = {0}; - struct drv_data* drvData = (struct drv_data* )filep->f_vnode->data; + struct drv_data *drvData = (struct drv_data *)filep->f_vnode->data; bitNum = (uint16_t)(uintptr_t)drvData->priv; ret = LOS_CopyToKernel(&info, sizeof(struct GpioBitInfo), diff --git a/khdf/liteos/platform/src/i2c_dev.c b/khdf/liteos/platform/src/i2c_dev.c index cf01a94..8de5ecf 100644 --- a/khdf/liteos/platform/src/i2c_dev.c +++ b/khdf/liteos/platform/src/i2c_dev.c @@ -348,7 +348,7 @@ static int I2cFsOpen(struct file *filep) { DevHandle handle = NULL; struct I2cClient *client = NULL; - struct drv_data* drvData = (struct drv_data* )filep->f_vnode->data; + struct drv_data *drvData = (struct drv_data *)filep->f_vnode->data; int16_t id = (int16_t)(uintptr_t)drvData->priv; handle = I2cOpen(id); -- Gitee From 22b9a2b3df81ac3249d8007fe47ddb3b7b88e18a Mon Sep 17 00:00:00 2001 From: zhang Date: Mon, 28 Mar 2022 19:46:30 +0800 Subject: [PATCH 046/102] fix: modify hdf host start mechanismy Signed-off-by: zhang --- BUILD.gn | 6 +- uhdf2/hcs/BUILD.gn | 26 +++ uhdf2/host/BUILD.gn | 13 -- uhdf2/host/devhost.c | 2 +- uhdf2/host/hdf_devhost.cfg | 179 ------------------- uhdf2/host/hdf_devhostmusl.cfg | 202 ---------------------- uhdf2/host/src/devhost_service_stub.c | 7 +- uhdf2/host/src/devsvc_manager_proxy.c | 21 +++ uhdf2/ipc/src/hdf_remote_adapter.cpp | 8 + uhdf2/manager/BUILD.gn | 2 +- uhdf2/manager/src/devmgr_service_full.c | 6 +- uhdf2/manager/src/devmgr_service_stub.c | 15 +- uhdf2/manager/src/driver_installer_full.c | 15 +- 13 files changed, 83 insertions(+), 419 deletions(-) delete mode 100644 uhdf2/host/hdf_devhost.cfg delete mode 100644 uhdf2/host/hdf_devhostmusl.cfg diff --git a/BUILD.gn b/BUILD.gn index d937682..3154017 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -30,17 +30,17 @@ if (defined(ohos_lite)) { group("uhdf_entry") { deps = [ "//drivers/adapter/uhdf2/hcs:hdf_default.hcb", + "//drivers/adapter/uhdf2/hcs:hdf_devhost.cfg", "//drivers/adapter/uhdf2/hdi:libhdi", "//drivers/adapter/uhdf2/host:hdf_devhost", - "//drivers/adapter/uhdf2/host:hdf_devhost.rc", "//drivers/adapter/uhdf2/host:libhdf_host", "//drivers/adapter/uhdf2/host/test/unittest/sample_driver:libsample_driver", "//drivers/adapter/uhdf2/ipc:libhdf_ipc_adapter", "//drivers/adapter/uhdf2/manager:hdf_devmgr", - "//drivers/adapter/uhdf2/manager:hdf_devmgr.rc", + "//drivers/adapter/uhdf2/manager:hdf_devmgr.cfg", "//drivers/adapter/uhdf2/platform:libhdf_platform", "//drivers/adapter/uhdf2/utils:libhdf_utils", - "//drivers/peripheral/base:hdf_peripheral.rc", + "//drivers/peripheral/base:hdf_peripheral.cfg", ] } group("uhdf_test_entry") { diff --git a/uhdf2/hcs/BUILD.gn b/uhdf2/hcs/BUILD.gn index 5c988c8..003d78b 100644 --- a/uhdf2/hcs/BUILD.gn +++ b/uhdf2/hcs/BUILD.gn @@ -36,3 +36,29 @@ ohos_prebuilt_etc("hdf_default.hcb") { subsystem_name = "hdf" part_name = "device_driver_framework" } + +hc_gen_start_cfg("gen_start_cfg") { + hcs_source = "/hdf.hcs" + + if (product_company == "openharmony") { + hcs_config_path = "default" + } else { + hcs_config_path = "//vendor/$product_company/$product_name/hdf_config/uhdf/" + } + sources = [ rebase_path(hcs_config_path + hcs_source) ] + if (use_musl) { + outputs = [ "$target_gen_dir/hdf_devhostmusl.cfg" ] + } else { + outputs = [ "$target_gen_dir/hdf_devhost.cfg" ] + } +} + +ohos_prebuilt_etc("hdf_devhost.cfg") { + deps = [ ":gen_start_cfg" ] + outputs = get_target_outputs(":gen_start_cfg") + source = outputs[0] + relative_install_dir = "init" + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "device_driver_framework" +} diff --git a/uhdf2/host/BUILD.gn b/uhdf2/host/BUILD.gn index 4deb605..5a86414 100644 --- a/uhdf2/host/BUILD.gn +++ b/uhdf2/host/BUILD.gn @@ -13,7 +13,6 @@ import("//build/ohos.gni") import("//drivers/adapter/uhdf2/uhdf.gni") - config("libhdf_host_pub_config") { visibility = [ ":*" ] @@ -152,15 +151,3 @@ if (defined(ohos_lite)) { part_name = "device_driver_framework" } } - -ohos_prebuilt_etc("hdf_devhost.rc") { - if (use_musl) { - source = "hdf_devhostmusl.cfg" - } else { - source = "hdf_devhost.cfg" - } - relative_install_dir = "init" - install_images = [ chipset_base_dir ] - subsystem_name = "hdf" - part_name = "device_driver_framework" -} diff --git a/uhdf2/host/devhost.c b/uhdf2/host/devhost.c index cdd021e..fbebfa4 100644 --- a/uhdf2/host/devhost.c +++ b/uhdf2/host/devhost.c @@ -99,7 +99,7 @@ int main(int argc, char **argv) DevHostServiceFreeInstance(instance); HdfPowerManagerExit(); - + HDF_LOGD("hdf device host %{public}s %{public}d exit", hostName, hostId); return status; } diff --git a/uhdf2/host/hdf_devhost.cfg b/uhdf2/host/hdf_devhost.cfg deleted file mode 100644 index 78b4663..0000000 --- a/uhdf2/host/hdf_devhost.cfg +++ /dev/null @@ -1,179 +0,0 @@ -{ - "jobs" : [{ - "name" : "post-fs-data", - "cmds" : [ - "start hdf_devhost" - ] - } - ], - "services" : [ - { - "name" : "blue_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "sample_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "system", - "gid" : ["system"] - }, - { - "name" : "usb_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "usbfnMaster_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "power_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "wifi_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "audio_hdi_server_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "camera_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "input_user_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "display_gralloc_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "codec_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "riladapter_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "sensor_dal_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "vibrator_dal_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "light_dal_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "wifi_c_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "disp_gralloc_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "dcamera_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "hwc_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "gralloc_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "sensor_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "nfc_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "connected_tag_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "a2dp_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - } - ] -} diff --git a/uhdf2/host/hdf_devhostmusl.cfg b/uhdf2/host/hdf_devhostmusl.cfg deleted file mode 100644 index 0b476a9..0000000 --- a/uhdf2/host/hdf_devhostmusl.cfg +++ /dev/null @@ -1,202 +0,0 @@ -{ - "jobs" : [{ - "name" : "post-fs-data", - "cmds" : [ - "start hdf_devhost" - ] - } - ], - "services" : [ - { - "name" : "blue_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - }, - { - "name" : "sample_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "sample_host", - "gid" : ["sample_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - }, - { - "name" : "usb_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "usb_host", - "gid" : ["usb_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - }, - { - "name" : "usbfnMaster_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "usbfnMaster_host", - "gid" : ["usbfnMaster_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - }, - { - "name" : "power_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "system", - "gid" : ["system"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - }, - { - "name" : "wifi_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "wifi_host", - "gid" : ["wifi_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - }, - { - "name" : "audio_hdi_server_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "audio_hdi_server_host", - "gid" : ["audio_hdi_server_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - }, - { - "name" : "camera_mpp_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"] - }, - { - "name" : "camera_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "camera_host", - "gid" : ["camera_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - }, - { - "name" : "input_user_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "input_user_host", - "gid" : ["input_user_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - }, - { - "name" : "display_gralloc_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "display_gralloc_host", - "gid" : ["display_gralloc_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - }, - { - "name" : "codec_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "codec_host", - "gid" : ["codec_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - }, - { - "name" : "riladapter_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "riladapter_host", - "gid" : ["riladapter_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - }, - { - "name" : "sensor_dal_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "sensor_dal_host", - "gid" : ["sensor_dal_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - }, - { - "name" : "vibrator_dal_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "vibrator_dal_host", - "gid" : ["vibrator_dal_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - }, - { - "name" : "light_dal_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "light_dal_host", - "gid" : ["light_dal_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - }, - { - "name" : "wifi_c_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "wifi_c_host", - "gid" : ["wifi_c_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - }, - { - "name" : "disp_gralloc_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "disp_gralloc_host", - "gid" : ["disp_gralloc_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - }, - { - "name" : "dcamera_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "dcamera_host", - "gid" : ["dcamera_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - }, - { - "name" : "hwc_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "hwc_host", - "gid" : ["hwc_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - }, - { - "name" : "gralloc_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "gralloc_host", - "gid" : ["gralloc_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - }, - { - "name" : "sensor_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "sensor_host", - "gid" : ["sensor_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - }, - { - "name" : "nfc_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "nfc_host", - "gid" : ["nfc_host"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - }, - { - "name" : "a2dp_host", - "dynamic" : true, - "path" : ["/vendor/bin/hdf_devhost"], - "uid" : "root", - "gid" : ["system"], - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] - } - ] -} diff --git a/uhdf2/host/src/devhost_service_stub.c b/uhdf2/host/src/devhost_service_stub.c index f71c4f6..a5f6797 100644 --- a/uhdf2/host/src/devhost_service_stub.c +++ b/uhdf2/host/src/devhost_service_stub.c @@ -103,8 +103,11 @@ static void DevHostServiceStubConstruct(struct DevHostServiceStub *inst) struct HdfObject *DevHostServiceStubCreate(void) { - struct DevHostServiceStub *instance = - (struct DevHostServiceStub *)OsalMemCalloc(sizeof(struct DevHostServiceStub)); + static struct DevHostServiceStub *instance = NULL; + if (instance != NULL) { + return (struct HdfObject *)&instance->super; + } + instance = (struct DevHostServiceStub *)OsalMemCalloc(sizeof(struct DevHostServiceStub)); if (instance != NULL) { DevHostServiceStubConstruct(instance); return (struct HdfObject *)&instance->super; diff --git a/uhdf2/host/src/devsvc_manager_proxy.c b/uhdf2/host/src/devsvc_manager_proxy.c index 35b08a7..bc472f9 100644 --- a/uhdf2/host/src/devsvc_manager_proxy.c +++ b/uhdf2/host/src/devsvc_manager_proxy.c @@ -14,6 +14,8 @@ */ #include "devsvc_manager_proxy.h" +#include "devhost_service.h" +#include "devhost_service_full.h" #include "device_service_stub.h" #include "devsvc_manager_stub.h" #include "hdf_base.h" @@ -212,6 +214,23 @@ void DevSvcManagerProxyRemoveService(struct IDevSvcManager *inst, const char *sv } } +static void DevSvcManagerProxyOnRemoteDied(struct HdfDeathRecipient *recipient, struct HdfRemoteService *service) +{ + struct IDevHostService *instance = DevHostServiceNewInstance(0, NULL); + + if (recipient == NULL || service == NULL || instance == NULL) { + HDF_LOGE("%{public}s parameter is null", __func__); + return; + } + + struct DevHostServiceFull *fullService = (struct DevHostServiceFull *)instance; + struct HdfMessageLooper *looper = &fullService->looper; + HDF_LOGD("%{public}s: DevSvcManager dead, host %{public}d stop", __func__, fullService->super.hostId); + if ((looper != NULL) && (looper->Stop != NULL)) { + looper->Stop(looper); + } +} + void DevSvcManagerProxyConstruct(struct DevSvcManagerProxy *inst, struct HdfRemoteService *remote) { inst->pvtbl.AddService = DevSvcManagerProxyAddService; @@ -219,6 +238,8 @@ void DevSvcManagerProxyConstruct(struct DevSvcManagerProxy *inst, struct HdfRemo inst->pvtbl.GetService = DevSvcManagerProxyGetService; inst->pvtbl.RemoveService = DevSvcManagerProxyRemoveService; inst->remote = remote; + inst->recipient.OnRemoteDied = DevSvcManagerProxyOnRemoteDied; + HdfRemoteServiceAddDeathRecipient(remote, &inst->recipient); } static struct IDevSvcManager *DevSvcManagerProxyObtain(struct HdfRemoteService *remote) diff --git a/uhdf2/ipc/src/hdf_remote_adapter.cpp b/uhdf2/ipc/src/hdf_remote_adapter.cpp index 1d6bb21..a728680 100644 --- a/uhdf2/ipc/src/hdf_remote_adapter.cpp +++ b/uhdf2/ipc/src/hdf_remote_adapter.cpp @@ -291,6 +291,14 @@ struct HdfRemoteService *HdfRemoteAdapterGetSa(int32_t saId) return nullptr; } OHOS::sptr remote = saManager->GetSystemAbility(saId); + constexpr int32_t waitTimes = 50; + constexpr int32_t sleepInterval = 20000; + int32_t timeout = waitTimes; + while (remote == nullptr && (timeout-- > 0)) { + HDF_LOGD("waiting for saId %{public}d", saId); + usleep(sleepInterval); + remote = saManager->GetSystemAbility(saId); + } if (remote != nullptr) { return HdfRemoteAdapterBind(remote); } else { diff --git a/uhdf2/manager/BUILD.gn b/uhdf2/manager/BUILD.gn index 749f903..f77e366 100644 --- a/uhdf2/manager/BUILD.gn +++ b/uhdf2/manager/BUILD.gn @@ -86,7 +86,7 @@ ohos_executable("hdf_devmgr") { part_name = "device_driver_framework" } -ohos_prebuilt_etc("hdf_devmgr.rc") { +ohos_prebuilt_etc("hdf_devmgr.cfg") { if (use_musl) { source = "hdf_devmgrmusl.cfg" } else { diff --git a/uhdf2/manager/src/devmgr_service_full.c b/uhdf2/manager/src/devmgr_service_full.c index 4c9aeb7..45157ef 100644 --- a/uhdf2/manager/src/devmgr_service_full.c +++ b/uhdf2/manager/src/devmgr_service_full.c @@ -56,6 +56,10 @@ static int32_t DevmgrServiceFullHandleDeviceHostDied(struct DevHostServiceClnt * if (g_hostMap.nodeSize == 0) { MapInit(&g_hostMap); } + // host is started at init phase by init module, and it respawn by init module + if (!HdfSListIsEmpty(&hostClnt->unloadDevInfos)) { + return 0; + } int *hostDieValue = (int *)MapGet(&g_hostMap, hostClnt->hostName); if (hostDieValue == NULL) { int hostDieNum = HOST_INIT_DIE_NUM; @@ -73,7 +77,7 @@ static int32_t DevmgrServiceFullHandleDeviceHostDied(struct DevHostServiceClnt * struct IDriverInstaller *installer = DriverInstallerGetInstance(); if (installer != NULL && installer->StartDeviceHost != NULL) { HDF_LOGI("%{public}s:%{public}d", __func__, __LINE__); - hostClnt->hostPid = installer->StartDeviceHost(hostClnt->hostId, hostClnt->hostName); + hostClnt->hostPid = installer->StartDeviceHost(hostClnt->hostId, hostClnt->hostName, true); return hostClnt->hostPid; } return INVALID_PID; diff --git a/uhdf2/manager/src/devmgr_service_stub.c b/uhdf2/manager/src/devmgr_service_stub.c index be0ecdf..9c33da0 100644 --- a/uhdf2/manager/src/devmgr_service_stub.c +++ b/uhdf2/manager/src/devmgr_service_stub.c @@ -225,6 +225,7 @@ static struct HdfRemoteDispatcher g_devmgrDispatcher = { int DevmgrServiceStubStartService(struct IDevmgrService *inst) { struct DevmgrServiceStub *fullService = (struct DevmgrServiceStub *)inst; + int status; if (fullService == NULL) { return HDF_ERR_INVALID_PARAM; } @@ -235,11 +236,6 @@ int DevmgrServiceStubStartService(struct IDevmgrService *inst) return HDF_ERR_INVALID_OBJECT; } - int status = DevSvcManagerStartService(); - if (status != HDF_SUCCESS) { - return status; - } - struct HdfRemoteService *remoteService = HdfRemoteServiceObtain((struct HdfObject *)inst, &g_devmgrDispatcher); if (remoteService == NULL) { HDF_LOGI("failed to start devmgr, remoteService obtain err"); @@ -265,8 +261,13 @@ int DevmgrServiceStubStartService(struct IDevmgrService *inst) fullService->remote = remoteService; (void)DriverModuleLoadHelperInit(); - - return DevmgrServiceStartService((struct IDevmgrService *)&fullService->super); + status = DevmgrServiceStartService((struct IDevmgrService *)&fullService->super); + if (status != HDF_SUCCESS) { + HdfRemoteServiceRecycle(remoteService); + OsalMemFree(deviceObject); + return status; + } + return DevSvcManagerStartService(); } static void DevmgrServiceStubConstruct(struct DevmgrServiceStub *inst) diff --git a/uhdf2/manager/src/driver_installer_full.c b/uhdf2/manager/src/driver_installer_full.c index 4f56e04..c234a54 100644 --- a/uhdf2/manager/src/driver_installer_full.c +++ b/uhdf2/manager/src/driver_installer_full.c @@ -30,18 +30,13 @@ #define PARAM_CNT 2 static struct DriverInstaller *g_fullInstaller = NULL; -int DriverInstallerFullStartDeviceHost(uint32_t devHostId, const char* devHostName) +int DriverInstallerFullStartDeviceHost(uint32_t devHostId, const char* devHostName, bool dynamic) { - char hostIdStr[MAX_CMD_LEN] = {0}; - int ret; - - if (snprintf_s(hostIdStr, sizeof(hostIdStr), sizeof(hostIdStr) - 1, " %u", devHostId) < 0) { - HDF_LOGE("starting device host, snprintf_s failed"); - return HDF_FAILURE; + if (dynamic) { + int ret = ServiceControlWithExtra(devHostName, START, NULL, 0); + HDF_LOGD("%{public}s %{public}s %{public}d %{public}d", __func__, devHostName, devHostId, ret); } - const char *args[] = { hostIdStr, devHostName }; - ret = ServiceControlWithExtra(devHostName, START, args, PARAM_CNT); - HDF_LOGI("%{public}s %{public}s %{public}u %{public}d", __func__, devHostName, devHostId, ret); + return HDF_SUCCESS; } -- Gitee From a97112d338d419948db78071fba101a9c5f47620 Mon Sep 17 00:00:00 2001 From: zhangyalei Date: Tue, 29 Mar 2022 02:46:10 -0700 Subject: [PATCH 047/102] fix:code issues clean Signed-off-by: zhangyalei --- .../model/storage/src/mmc/mmc_block_lite.c | 39 ++++++++++++++++--- .../model/storage/src/mtd/mtd_char_lite.c | 31 ++++++++++++++- .../model/storage/src/mtd/mtd_legacy_lite.c | 12 ++++-- khdf/liteos/platform/src/gpio_dev.c | 9 ++++- khdf/liteos/platform/src/i2c_dev.c | 11 +++++- 5 files changed, 88 insertions(+), 14 deletions(-) diff --git a/khdf/liteos/model/storage/src/mmc/mmc_block_lite.c b/khdf/liteos/model/storage/src/mmc/mmc_block_lite.c index f986201..e2eb25b 100644 --- a/khdf/liteos/model/storage/src/mmc/mmc_block_lite.c +++ b/khdf/liteos/model/storage/src/mmc/mmc_block_lite.c @@ -91,8 +91,15 @@ static int LiteosBlockClose(FAR struct Vnode *vnode) static ssize_t LiteosBlockRead(FAR struct Vnode *vnode, FAR unsigned char *buf, unsigned long long secStart, unsigned int nSecs) { - size_t max = (size_t)(-1); - struct MmcBlock *mb = (struct MmcBlock *)((struct drv_data*)vnode->data)->priv; + size_t max; + struct MmcBlock *mb = NULL; + + if (vnode == NULL || vnode->data == NULL) { + HDF_LOGE("%s: vnode is NULL or data of vnode is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + max = (size_t)(-1); + mb = (struct MmcBlock *)((struct drv_data*)vnode->data)->priv; if (secStart >= max || nSecs >= max) { return HDF_ERR_INVALID_PARAM; @@ -108,8 +115,15 @@ static ssize_t LiteosBlockRead(FAR struct Vnode *vnode, FAR unsigned char *buf, static ssize_t LiteosBlockWrite(FAR struct Vnode *vnode, FAR const unsigned char *buf, unsigned long long secStart, unsigned int nSecs) { - size_t max = (size_t)(-1); - struct MmcBlock *mb = (struct MmcBlock *)((struct drv_data*)vnode->data)->priv; + size_t max; + struct MmcBlock *mb = NULL; + + if (vnode == NULL || vnode->data == NULL) { + HDF_LOGE("%s: vnode is NULL or data of vnode is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + max = (size_t)(-1); + mb = (struct MmcBlock *)((struct drv_data*)vnode->data)->priv; if (secStart >= max || nSecs >= max) { return HDF_ERR_INVALID_PARAM; @@ -124,8 +138,13 @@ static ssize_t LiteosBlockWrite(FAR struct Vnode *vnode, FAR const unsigned char static int LiteosBlockGeometry(FAR struct Vnode *vnode, FAR struct geometry *geometry) { - struct MmcBlock *mb = (struct MmcBlock *)((struct drv_data*)vnode->data)->priv; + struct MmcBlock *mb = NULL; + if (vnode == NULL || vnode->data == NULL) { + HDF_LOGE("%s: vnode is NULL or data of vnode is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + mb = (struct MmcBlock *)((struct drv_data*)vnode->data)->priv; if (mb == NULL) { return HDF_ERR_INVALID_OBJECT; } @@ -146,6 +165,11 @@ static int32_t LiteosBlockSaveGeometry(FAR struct Vnode *vnode, unsigned long ar struct geometry gm; struct RtDeviceBlkGeometry rtGeo = {0}; + if (vnode == NULL || vnode->data == NULL) { + HDF_LOGE("%s: vnode is NULL or data of vnode is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + ret = LiteosBlockGeometry(vnode, &gm); if (ret != HDF_SUCCESS) { return ret; @@ -190,6 +214,11 @@ static int32_t LiteosBlockIoctl(FAR struct Vnode *vnode, int cmd, unsigned long uint32_t auSize; struct MmcBlock *mb = NULL; + if (vnode == NULL || vnode->data == NULL) { + HDF_LOGE("%s: vnode is NULL or data of vnode is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + mb = (struct MmcBlock *)((struct drv_data*)vnode->data)->priv; switch (cmd) { diff --git a/khdf/liteos/model/storage/src/mtd/mtd_char_lite.c b/khdf/liteos/model/storage/src/mtd/mtd_char_lite.c index 398f44a..ba4eb9f 100644 --- a/khdf/liteos/model/storage/src/mtd/mtd_char_lite.c +++ b/khdf/liteos/model/storage/src/mtd/mtd_char_lite.c @@ -54,8 +54,18 @@ struct MtdFileInfo { */ static int MtdCharOpen(FAR struct file *filep) { - struct drv_data *drv = (struct drv_data *)filep->f_vnode->data; + struct drv_data *drv = NULL; + + if (filep == NULL || filep->f_vnode == NULL || filep->f_vnode->data == NULL) { + HDF_LOGE("%s: filep is NULL or f_vnode of filep is NULL or data of f_vnode is NULL", __func__); + return -EINVAL; + } + drv = (struct drv_data *)filep->f_vnode->data; mtd_partition *partition = (mtd_partition *)drv->priv; + if (partition == NULL) { + HDF_LOGE("%s: partition is NULL", __func__); + return -EINVAL; + } struct MtdFileInfo *mfi = NULL; if (partition->user_num != 0) { // be opened @@ -117,6 +127,11 @@ static ssize_t MtdCharRead(FAR struct file *filep, FAR char *buffer, size_t bufl size_t partSize = (partition->end_block + 1 - partition->start_block) * blockSize; size_t partOobSize = (partSize >> mtdDevice->writeSizeShift) * mtdDevice->oobSize; + if (buffer == NULL) { + HDF_LOGE("%s: buffer is NULL", __func__); + return -EINVAL; + } + (void)LOS_MuxLock(&partition->lock, LOS_WAIT_FOREVER); if (ppos < 0 || ppos > partSize) { PRINTK("%s: current file offset:0x%x invalid\n", __func__, ppos); @@ -172,6 +187,10 @@ static ssize_t MtdCharWrite(FAR struct file *filep, FAR const char *buffer, size size_t partSize = (partition->end_block + 1 - partition->start_block) * blockSize; size_t partOobSize = (partSize >> mtdDevice->writeSizeShift) * mtdDevice->oobSize; + if (buffer == NULL) { + HDF_LOGE("%s: buffer is NULL", __func__); + return -EINVAL; + } (void)LOS_MuxLock(&partition->lock, LOS_WAIT_FOREVER); if (ppos < 0 || ppos > partSize) { @@ -282,7 +301,6 @@ static int MtdCharIoctlGetInfo(const mtd_partition *part, const struct MtdDevice size_t endAddr; (void)cmd; - MtdCharGetMtdInfo(mtdDevice, &mtdInfo); startAddr = part->start_block * mtdDevice->eraseSize; endAddr = (part->end_block + 1) * mtdDevice->eraseSize; @@ -356,6 +374,11 @@ static int MtdCharIoctl(FAR struct file *filep, int cmd, unsigned long arg) struct MtdDev *mtdDev = (struct MtdDev *)(partition->mtd_info); struct MtdDevice *mtdDevice = (struct MtdDevice *)mtdDev->priv; + if (mtdDevice == NULL || arg == 0) { + HDF_LOGE("%s: mtdDevice is NULL or arg is 0", __func__); + return -EINVAL; + } + (void)LOS_MuxLock(&partition->lock, LOS_WAIT_FOREVER); switch (cmd) { @@ -442,6 +465,10 @@ int HdfMtdDevErase(struct MtdDev *mtdDev, UINT64 start, UINT64 len, UINT64 *fail if (mtdDev == NULL) { return HDF_ERR_INVALID_OBJECT; } + if (failAddr == NULL) { + HDF_LOGE("%s: failAddr is NULL", __func__); + return -EINVAL; + } ret = MtdDeviceErase((struct MtdDevice *)mtdDev->priv, start, len, &failPos); if (ret != HDF_SUCCESS) { *failAddr = failPos; diff --git a/khdf/liteos/model/storage/src/mtd/mtd_legacy_lite.c b/khdf/liteos/model/storage/src/mtd/mtd_legacy_lite.c index 2bd0b76..616b7e3 100644 --- a/khdf/liteos/model/storage/src/mtd/mtd_legacy_lite.c +++ b/khdf/liteos/model/storage/src/mtd/mtd_legacy_lite.c @@ -264,7 +264,8 @@ static int MtdDeviceLegacyNandRead(MtdInfoLegacy *mtd, off_t addr, size_t len, s { int ret; - if (mtd == NULL) { + if (mtd == NULL || mtd->priv == NULL || retlen == NULL || buf == NULL) { + HDF_LOGE("%s: function parameter is null", __func__); return -EINVAL; } @@ -277,7 +278,8 @@ static int MtdDeviceLegacyNandWrite(MtdInfoLegacy *mtd, off_t addr, size_t len, { int ret; - if (mtd == NULL) { + if (mtd == NULL || retlen == NULL) { + HDF_LOGE("%s: function parameter is null", __func__); return -EINVAL; } @@ -290,7 +292,8 @@ static int MtdDeviceLegacyNandReadOob(MtdInfoLegacy *mtd, off_t addr, size_t len { int ret; - if (mtd == NULL) { + if (mtd == NULL || retlen == NULL) { + HDF_LOGE("%s: function parameter is null", __func__); return -EINVAL; } @@ -303,7 +306,8 @@ static int MtdDeviceLegacyNandWriteOob(MtdInfoLegacy *mtd, off_t addr, size_t le { int ret; - if (mtd == NULL) { + if (mtd == NULL || retlen == NULL) { + HDF_LOGE("%s: function parameter is null", __func__); return -EINVAL; } diff --git a/khdf/liteos/platform/src/gpio_dev.c b/khdf/liteos/platform/src/gpio_dev.c index f105890..5d345cd 100644 --- a/khdf/liteos/platform/src/gpio_dev.c +++ b/khdf/liteos/platform/src/gpio_dev.c @@ -102,7 +102,14 @@ static int GpioIoctl(struct file *filep, int cmd, unsigned long arg) uint16_t bitNum; uint16_t gpio; struct GpioBitInfo info = {0}; - struct drv_data *drvData = (struct drv_data *)filep->f_vnode->data; + struct drv_data *drvData = NULL; + + if (filep == NULL || filep->f_vnode == NULL || filep->f_vnode->data == NULL) { + HDF_LOGE("%s: function parameter is null", __func__); + return HDF_ERR_INVALID_PARAM; + } + + drvData = (struct drv_data *)filep->f_vnode->data; bitNum = (uint16_t)(uintptr_t)drvData->priv; ret = LOS_CopyToKernel(&info, sizeof(struct GpioBitInfo), diff --git a/khdf/liteos/platform/src/i2c_dev.c b/khdf/liteos/platform/src/i2c_dev.c index 8de5ecf..dd1506d 100644 --- a/khdf/liteos/platform/src/i2c_dev.c +++ b/khdf/liteos/platform/src/i2c_dev.c @@ -348,8 +348,15 @@ static int I2cFsOpen(struct file *filep) { DevHandle handle = NULL; struct I2cClient *client = NULL; - struct drv_data *drvData = (struct drv_data *)filep->f_vnode->data; - int16_t id = (int16_t)(uintptr_t)drvData->priv; + struct drv_data *drvData = NULL; + int16_t id; + + if (filep == NULL || filep->f_vnode == NULL || filep->f_vnode->data == NULL) { + HDF_LOGE("%s: function parameter is null", __func__); + return -EINVAL; + } + drvData = (struct drv_data *)filep->f_vnode->data; + id = (int16_t)(uintptr_t)drvData->priv; handle = I2cOpen(id); if (handle == NULL) { -- Gitee From f58964510fb29d27a7738336fc60be9a938ad615 Mon Sep 17 00:00:00 2001 From: Laowang-BearPi Date: Wed, 30 Mar 2022 10:36:20 +0800 Subject: [PATCH 048/102] add stm32mp157 development board Signed-off-by: Laowang-BearPi --- khdf/liteos/hdf_lite.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/khdf/liteos/hdf_lite.mk b/khdf/liteos/hdf_lite.mk index 7b203de..58f1bc1 100644 --- a/khdf/liteos/hdf_lite.mk +++ b/khdf/liteos/hdf_lite.mk @@ -172,6 +172,8 @@ endif COMPANY_OF_SOC := $(patsubst "%",%,$(LOSCFG_DEVICE_COMPANY)) ifeq ($(COMPANY_OF_SOC), hisilicon) -include $(LITEOSTOPDIR)/../../device/soc/$(COMPANY_OF_SOC)/common/platform/lite.mk +else ifeq ($(COMPANY_OF_SOC), st) +-include $(LITEOSTOPDIR)/../../device/soc/$(COMPANY_OF_SOC)/common/platform/lite.mk else -include $(LITEOSTOPDIR)/../../device/$(COMPANY_OF_SOC)/drivers/lite.mk endif -- Gitee From 721f43cdd1be49b0e1820c4ba51a180d1aebf299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cwangyipeng=E2=80=9D?= Date: Wed, 30 Mar 2022 10:28:32 +0800 Subject: [PATCH 049/102] Fix:USB module alarms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: “wangyipeng” --- khdf/liteos/model/usb/host/src/usb_pnp_notify.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/khdf/liteos/model/usb/host/src/usb_pnp_notify.c b/khdf/liteos/model/usb/host/src/usb_pnp_notify.c index 9c15f7c..33ccfba 100644 --- a/khdf/liteos/model/usb/host/src/usb_pnp_notify.c +++ b/khdf/liteos/model/usb/host/src/usb_pnp_notify.c @@ -96,7 +96,7 @@ static bool UsbPnpNotifyFindDeviceList(struct usb_device *deviceObj, bool freeFl static struct UsbPnpDeviceInfo *UsbPnpNotifyCreateInfo(void) { struct UsbPnpDeviceInfo *infoTemp = NULL; - static int32_t idNum = 0; + static int32_t idNum = 1; infoTemp = (struct UsbPnpDeviceInfo *)OsalMemCalloc(sizeof(struct UsbPnpDeviceInfo)); if (infoTemp == NULL) { @@ -104,14 +104,15 @@ static struct UsbPnpDeviceInfo *UsbPnpNotifyCreateInfo(void) return NULL; } - if (idNum++ == INT32_MAX) { - idNum = 0; + if (idNum == INT32_MAX) { + idNum = 1; } infoTemp->id = idNum; OsalMutexInit(&infoTemp->lock); infoTemp->status = USB_PNP_DEVICE_INIT_STATUS; DListHeadInit(&infoTemp->list); DListInsertTail(&infoTemp->list, &g_usbPnpInfoListHead); + idNum++; return infoTemp; } -- Gitee From a2da970fd860cf128345c0e276055969ea50287f Mon Sep 17 00:00:00 2001 From: yue Date: Wed, 30 Mar 2022 18:35:43 +0800 Subject: [PATCH 050/102] fix:modify problem of using string pointer initialize string class Signed-off-by: yue --- uhdf2/hdi/src/servstat_listener_stub.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/uhdf2/hdi/src/servstat_listener_stub.cpp b/uhdf2/hdi/src/servstat_listener_stub.cpp index ab014a2..0974e96 100644 --- a/uhdf2/hdi/src/servstat_listener_stub.cpp +++ b/uhdf2/hdi/src/servstat_listener_stub.cpp @@ -43,18 +43,22 @@ int32_t ServStatListenerStub::ServStatListenerStubOnReceive(MessageParcel& data, HDF_LOGI("failed to check interface token"); return HDF_FAILURE; } - status.serviceName = data.ReadCString(); + + const char* name = data.ReadCString(); + status.serviceName = (name == nullptr) ? "" : name; if (status.serviceName.empty()) { HDF_LOGI("failed to read serviceName in ServiceStatus"); return HDF_FAILURE; } + if (!data.ReadUint16(status.deviceClass) || !data.ReadUint16(status.status)) { HDF_LOGI("failed to read deviceClass or status in ServiceStatus"); return HDF_FAILURE; } - status.info = data.ReadCString(); + const char* info = data.ReadCString(); + status.info = (info == nullptr) ? "" : info; OnReceive(status); return HDF_SUCCESS; -- Gitee From 95f753cbab4361487b69b71e16caf6ac94e32d7b Mon Sep 17 00:00:00 2001 From: zhang Date: Thu, 31 Mar 2022 10:18:13 +0800 Subject: [PATCH 051/102] fix: add macro parsing mechanism to protect the reading of unconfigured nodes Signed-off-by: zhang --- khdf/liteos_m/{hdf_macro.gni => hdf_hcs.gni} | 33 +++++++++++++++----- platform/i2c/i2c_bes.c | 20 ++++++------ platform/pwm/pwm_bes.c | 19 ++++++----- platform/spi/spi_bes.c | 19 ++++++----- platform/uart/uart_bes.c | 16 ++++++---- 5 files changed, 68 insertions(+), 39 deletions(-) rename khdf/liteos_m/{hdf_macro.gni => hdf_hcs.gni} (75%) diff --git a/khdf/liteos_m/hdf_macro.gni b/khdf/liteos_m/hdf_hcs.gni similarity index 75% rename from khdf/liteos_m/hdf_macro.gni rename to khdf/liteos_m/hdf_hcs.gni index 6d6ee4b..95ac84e 100755 --- a/khdf/liteos_m/hdf_macro.gni +++ b/khdf/liteos_m/hdf_hcs.gni @@ -41,10 +41,18 @@ template("hdf_driver") { module_switch = true } - if (module_switch && defined(invoker.hcs_sources)) { + if (defined(invoker.macro_switch)) { + forward_variables_from(invoker, [ "macro_switch" ]) + } + if (module_switch && !macro_switch && defined(invoker.hcs_sources)) { + hc_gen_hex("${target_name}_hc_gen_hex") { + sources = invoker.hcs_sources + } + } + if (module_switch && macro_switch && defined(invoker.hcs_sources)) { hc_gen_macro("${target_name}_hc_gen_macro") { sources = invoker.hcs_sources - outputs = invoker.outputs + outputs = [ "$target_gen_dir/hdf_config_macro.h" ] } } kernel_module(target_name) { @@ -60,14 +68,23 @@ template("hdf_driver") { if (defined(invoker.visibility)) { visibility += invoker.visibility } - if (module_switch && defined(invoker.hcs_sources)) { - hc_gen_macro = ":${target_name}_hc_gen_macro" - generated_include = get_path_info(get_target_outputs(hc_gen_macro), "dir") - if (defined(invoker.include_dirs)) { - include_dirs += generated_include + if (module_switch && !macro_switch && defined(invoker.hcs_sources)) { + hc_gen = ":${target_name}_hc_gen_hex" + generated_sources = get_target_outputs(hc_gen) + set_sources_assignment_filter([ "*.hcb" ]) + if (defined(invoker.sources)) { + sources += generated_sources } else { - include_dirs = generated_include + sources = generated_sources } + if (defined(invoker.deps)) { + deps += [ hc_gen ] + } else { + deps = [ hc_gen ] + } + } + if (module_switch && macro_switch && defined(invoker.hcs_sources)) { + hc_gen_macro = ":${target_name}_hc_gen_macro" if (defined(invoker.deps)) { deps += [ hc_gen_macro ] } else { diff --git a/platform/i2c/i2c_bes.c b/platform/i2c/i2c_bes.c index 8ad7826..e2bfb43 100644 --- a/platform/i2c/i2c_bes.c +++ b/platform/i2c/i2c_bes.c @@ -146,28 +146,30 @@ int32_t InitI2cDevice(struct I2cDevice *device) resource->useDma = HCS_PROP(node, useDma); \ resource->useSync = HCS_PROP(node, useSync); \ resource->asMaster = HCS_PROP(node, asMaster); \ + result = HDF_SUCCESS; \ break; \ } \ } while (0) - +#define PLATFORM_CONFIG HCS_NODE(HCS_ROOT, platform) #define PLATFORM_I2C_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), i2c_config) static uint32_t GetI2cDeviceResource(struct I2cDevice *device, const char *deviceMatchAttr) { uint32_t tempPin; + int32_t result = HDF_FAILURE; struct I2cResource *resource = NULL; - if (device == NULL) { - HDF_LOGE("device or resourceNode is NULL\r\n"); + if (device == NULL || deviceMatchAttr == NULL) { + HDF_LOGE("device or deviceMatchAttr is NULL\r\n"); return HDF_ERR_INVALID_PARAM; } resource = &device->resource; - if (resource == NULL) { - HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__); - return HDF_ERR_INVALID_OBJECT; - } - +#if HCS_NODE_HAS_PROP(PLATFORM_CONFIG, i2c_config) HCS_FOREACH_CHILD_VARGS(PLATFORM_I2C_CONFIG, I2C_FIND_CONFIG, deviceMatchAttr, resource); - return HDF_SUCCESS; +#endif + if (result != HDF_SUCCESS) { + HDF_LOGE("resourceNode %s is NULL\r\n", deviceMatchAttr); + } + return result; } #else static uint32_t GetI2cDeviceResource(struct I2cDevice *device, diff --git a/platform/pwm/pwm_bes.c b/platform/pwm/pwm_bes.c index 3caaffa..efb202e 100644 --- a/platform/pwm/pwm_bes.c +++ b/platform/pwm/pwm_bes.c @@ -95,26 +95,29 @@ static int InitPwmDevice(struct PwmDev *host) tempPin = HCS_PROP(node, pwmPin); \ resource->pwmPin = ((tempPin / DEC_TEN) * PIN_GROUP_NUM) + (tempPin % DEC_TEN); \ resource->pwmId = HCS_PROP(node, pwmId); \ + result = HDF_SUCCESS; \ break; \ } \ } while (0) +#define PLATFORM_CONFIG HCS_NODE(HCS_ROOT, platform) #define PLATFORM_PWM_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), pwm_config) static uint32_t GetPwmDeviceResource(struct PwmDevice *device, const char *deviceMatchAttr) { uint32_t tempPin; + int32_t result = HDF_FAILURE; struct PwmResource *resource = NULL; - if (device == NULL) { - HDF_LOGE("%s: device is NULL", __func__); + if (device == NULL || deviceMatchAttr == NULL) { + HDF_LOGE("%s: device or deviceMatchAttr is NULL", __func__); return HDF_ERR_INVALID_PARAM; } resource = &device->resource; - if (resource == NULL) { - HDF_LOGE("%s: resource is NULL", __func__); - return HDF_ERR_INVALID_OBJECT; - } - +#if HCS_NODE_HAS_PROP(PLATFORM_CONFIG, pwm_config) HCS_FOREACH_CHILD_VARGS(PLATFORM_PWM_CONFIG, PWM_FIND_CONFIG, deviceMatchAttr, resource); - return HDF_SUCCESS; +#endif + if (result != HDF_SUCCESS) { + HDF_LOGE("resourceNode %s is NULL\r\n", deviceMatchAttr); + } + return result; } #else static uint32_t GetPwmDeviceResource( diff --git a/platform/spi/spi_bes.c b/platform/spi/spi_bes.c index 886de57..9d317c5 100644 --- a/platform/spi/spi_bes.c +++ b/platform/spi/spi_bes.c @@ -433,27 +433,30 @@ static int32_t InitSpiDevice(struct SpiDevice *spiDevice) resource->spiMisoPin = ((tempPin / DEC_NUM) * GROUP_PIN_NUM) + (tempPin % DEC_NUM); \ tempPin = HCS_PROP(node, spiCsPin); \ resource->spiCsPin = ((tempPin / DEC_NUM) * GROUP_PIN_NUM) + (tempPin % DEC_NUM); \ + result = HDF_SUCCESS; \ break; \ } \ } while (0) +#define PLATFORM_CONFIG HCS_NODE(HCS_ROOT, platform) #define PLATFORM_SPI_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), spi_config) static int32_t GetSpiDeviceResource(struct SpiDevice *spiDevice, const char *deviceMatchAttr) { uint32_t tempPin; + int32_t result = HDF_FAILURE; struct SpiResource *resource = NULL; - if (spiDevice == NULL) { - HDF_LOGE("device or resourceNode is NULL\r\n"); + if (spiDevice == NULL || deviceMatchAttr == NULL) { + HDF_LOGE("device or deviceMatchAttr is NULL\r\n"); return HDF_ERR_INVALID_PARAM; } resource = &spiDevice->resource; - if (resource == NULL) { - HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__); - return HDF_ERR_INVALID_OBJECT; - } - +#if HCS_NODE_HAS_PROP(PLATFORM_CONFIG, spi_config) HCS_FOREACH_CHILD_VARGS(PLATFORM_SPI_CONFIG, SPI_FIND_CONFIG, deviceMatchAttr, resource); - return HDF_SUCCESS; +#endif + if (result != HDF_SUCCESS) { + HDF_LOGE("resourceNode %s is NULL\r\n", deviceMatchAttr); + } + return result; } #else static int32_t GetSpiDeviceResource(struct SpiDevice *spiDevice, const struct DeviceResourceNode *resourceNode) diff --git a/platform/uart/uart_bes.c b/platform/uart/uart_bes.c index 736c3d5..32c2161 100644 --- a/platform/uart/uart_bes.c +++ b/platform/uart/uart_bes.c @@ -469,25 +469,29 @@ static int InitUartDevice(struct UartHost *host) resource->wLen = HCS_PROP(node, data); \ resource->rxDMA = HCS_PROP(node, rxDMA); \ resource->txDMA = HCS_PROP(node, txDMA); \ + result = HDF_SUCCESS; \ break; \ } \ } while (0) +#define PLATFORM_CONFIG HCS_NODE(HCS_ROOT, platform) #define PLATFORM_UART_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), uart_config) static uint32_t GetUartDeviceResource(struct UartDevice *device, const char *deviceMatchAttr) { struct UartResource *resource = NULL; + int32_t result = HDF_FAILURE; if (device == NULL || deviceMatchAttr == NULL) { - HDF_LOGE("device or resourceNode is NULL\r\n"); + HDF_LOGE("device or deviceMatchAttr is NULL\r\n"); return HDF_ERR_INVALID_PARAM; } resource = &device->resource; - if (resource == NULL) { - HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__); - return HDF_ERR_INVALID_OBJECT; - } - +#if HCS_NODE_HAS_PROP(PLATFORM_CONFIG, uart_config) HCS_FOREACH_CHILD_VARGS(PLATFORM_UART_CONFIG, UART_FIND_CONFIG, deviceMatchAttr, resource); +#endif + if (result != HDF_SUCCESS) { + HDF_LOGE("resourceNode %s is NULL\r\n", deviceMatchAttr); + return result; + } // copy config device->initFlag = false; device->uartId = resource->num; -- Gitee From 09a35c2a65450b4561277ecdb99b41fe64301859 Mon Sep 17 00:00:00 2001 From: mahai Date: Thu, 31 Mar 2022 14:14:47 +0800 Subject: [PATCH 052/102] fix:clear code alarm in platform driver source files Signed-off-by: mahai --- khdf/liteos/model/storage/src/mmc/mmc_block_lite.c | 2 +- khdf/liteos/model/storage/src/mtd/mtd_char_lite.c | 3 +++ khdf/liteos/platform/src/gpio_dev.c | 10 +++++----- khdf/liteos/platform/src/spi_dev.c | 6 +++--- khdf/liteos/platform/src/uart_dev.c | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/khdf/liteos/model/storage/src/mmc/mmc_block_lite.c b/khdf/liteos/model/storage/src/mmc/mmc_block_lite.c index e2eb25b..95ce058 100644 --- a/khdf/liteos/model/storage/src/mmc/mmc_block_lite.c +++ b/khdf/liteos/model/storage/src/mmc/mmc_block_lite.c @@ -292,7 +292,7 @@ int32_t MmcBlockOsInit(struct MmcDevice *mmcDevice) } diskId = los_alloc_diskid_byname(mb->name); - if (!mb->removeable) { + if (!mb->removable) { info = &g_emmcInfo; info->sector_count = mb->capacity; } diff --git a/khdf/liteos/model/storage/src/mtd/mtd_char_lite.c b/khdf/liteos/model/storage/src/mtd/mtd_char_lite.c index ba4eb9f..df9ed3e 100644 --- a/khdf/liteos/model/storage/src/mtd/mtd_char_lite.c +++ b/khdf/liteos/model/storage/src/mtd/mtd_char_lite.c @@ -419,6 +419,9 @@ static int MtdCharIoctl(FAR struct file *filep, int cmd, unsigned long arg) static ssize_t MtdCharMap(FAR struct file* filep, FAR LosVmMapRegion *region) { + (void)filep; + (void)region; + PRINTK("%s %d, mmap is not support\n", __FUNCTION__, __LINE__); return 0; } diff --git a/khdf/liteos/platform/src/gpio_dev.c b/khdf/liteos/platform/src/gpio_dev.c index 5d345cd..196efc0 100644 --- a/khdf/liteos/platform/src/gpio_dev.c +++ b/khdf/liteos/platform/src/gpio_dev.c @@ -62,7 +62,7 @@ static int GpioExecCmd(uint16_t gpio, struct GpioBitInfo *info, int cmd) HDF_LOGE("%s: set dir fail:%d", __func__, ret); return -1; } - PLAT_LOGV("%s: gpio:%u set dir:%u done!", __func__, gpio, info->direction); + PLAT_LOGV("%s: gpio:%hu set dir:%u done!", __func__, gpio, info->direction); break; case GPIO_GET_DIR: ret = GpioGetDir(gpio, &tmp); @@ -71,7 +71,7 @@ static int GpioExecCmd(uint16_t gpio, struct GpioBitInfo *info, int cmd) return -1; } info->direction = (unsigned char)tmp; - PLAT_LOGV("%s: gpio:%u get dir:%u done!", __func__, gpio, info->direction); + PLAT_LOGV("%s: gpio:%hu get dir:%u done!", __func__, gpio, info->direction); break; case GPIO_READ_BIT: ret = GpioRead(gpio, &tmp); @@ -80,7 +80,7 @@ static int GpioExecCmd(uint16_t gpio, struct GpioBitInfo *info, int cmd) return -1; } info->value = (unsigned char)tmp; - PLAT_LOGV("%s: gpio:%u read:%u done!", __func__, gpio, info->value); + PLAT_LOGV("%s: gpio:%hu read:%u done!", __func__, gpio, info->value); break; case GPIO_WRITE_BIT: ret = GpioWrite(gpio, info->value); @@ -88,7 +88,7 @@ static int GpioExecCmd(uint16_t gpio, struct GpioBitInfo *info, int cmd) HDF_LOGE("%s: write gpio fail:%d", __func__, ret); return -1; } - PLAT_LOGV("%s: gpio:%u write:%u done!", __func__, gpio, info->value); + PLAT_LOGV("%s: gpio:%hu write:%u done!", __func__, gpio, info->value); break; default: ret = -1; @@ -118,7 +118,7 @@ static int GpioIoctl(struct file *filep, int cmd, unsigned long arg) return -1; } gpio = info.groupnumber * bitNum + info.bitnumber; - PLAT_LOGV("%s: gn:%u, bn:%u, gpio:%u", __func__, info.groupnumber, info.bitnumber, gpio); + PLAT_LOGV("%s: gn:%u, bn:%u, gpio:%hu", __func__, info.groupnumber, info.bitnumber, gpio); ret = GpioExecCmd(gpio, &info, cmd); if (ret != 0) { diff --git a/khdf/liteos/platform/src/spi_dev.c b/khdf/liteos/platform/src/spi_dev.c index 7adb112..226a7b8 100644 --- a/khdf/liteos/platform/src/spi_dev.c +++ b/khdf/liteos/platform/src/spi_dev.c @@ -163,7 +163,7 @@ static int32_t SpiDevGetCfg(struct SpiDev *dev, struct SpiCfg *mask, unsigned lo HDF_LOGI("%s: get mode 0x%x", __func__, tmp); } else if (mask->bitsPerWord == 1) { tmp = cfg.bitsPerWord; - HDF_LOGI("%s: get word %d", __func__, tmp); + HDF_LOGI("%s: get word %u", __func__, tmp); } else if (mask->maxSpeedHz == 1) { tmp = cfg.maxSpeedHz; HDF_LOGI("%s: get maxspeed %d", __func__, tmp); @@ -201,7 +201,7 @@ static int32_t SpiDevSetCfg(struct SpiDev *dev, struct SpiCfg *mask, unsigned lo HDF_LOGI("%s: set mode 0x%x", __func__, tmp); cfg.mode = tmp; } else if (mask->bitsPerWord == 1) { - HDF_LOGI("%s: set word %d", __func__, tmp); + HDF_LOGI("%s: set word %u", __func__, tmp); cfg.bitsPerWord = tmp; } else if (mask->maxSpeedHz == 1) { HDF_LOGI("%s: set maxspeed %d", __func__, tmp); @@ -420,7 +420,7 @@ static void SpiAddRemoveDev(struct SpiDev *dev, bool add) return; } if (add) { - HDF_LOGI("creat /dev/spidev%u.%u", dev->cntlr->busNum, dev->csNum); + HDF_LOGI("create /dev/spidev%u.%u", dev->cntlr->busNum, dev->csNum); if (register_driver(devName, &g_spiDevFops, HDF_SPI_FS_MODE, dev)) { HDF_LOGE("%s: gen /dev/spidev%u.%u", __func__, dev->cntlr->busNum, dev->csNum); } diff --git a/khdf/liteos/platform/src/uart_dev.c b/khdf/liteos/platform/src/uart_dev.c index 30c7b0c..dd4d560 100644 --- a/khdf/liteos/platform/src/uart_dev.c +++ b/khdf/liteos/platform/src/uart_dev.c @@ -226,7 +226,7 @@ static void UartAddRemoveDev(struct UartHost *host, bool add) return; } if (add) { - HDF_LOGI("creat /dev/uartdev-%d", host->num); + HDF_LOGI("create /dev/uartdev-%d", host->num); if (register_driver(devName, &g_uartDevFops, HDF_UART_FS_MODE, host)) { HDF_LOGE("%s: gen /dev/uartdev-%d fail!", __func__, host->num); OsalMemFree(devName); -- Gitee From 04708bfb7376d2ddcb4e89d37cea00988cfa2ee6 Mon Sep 17 00:00:00 2001 From: zhang Date: Fri, 1 Apr 2022 15:17:43 +0800 Subject: [PATCH 053/102] =?UTF-8?q?fix=EF=BC=9Amodify=20the=20API=20to=20j?= =?UTF-8?q?udge=20whether=20a=20node=20exists?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhang --- platform/i2c/i2c_bes.c | 3 +-- platform/pwm/pwm_bes.c | 3 +-- platform/spi/spi_bes.c | 3 +-- platform/uart/uart_bes.c | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/platform/i2c/i2c_bes.c b/platform/i2c/i2c_bes.c index e2bfb43..3e5aef3 100644 --- a/platform/i2c/i2c_bes.c +++ b/platform/i2c/i2c_bes.c @@ -150,7 +150,6 @@ int32_t InitI2cDevice(struct I2cDevice *device) break; \ } \ } while (0) -#define PLATFORM_CONFIG HCS_NODE(HCS_ROOT, platform) #define PLATFORM_I2C_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), i2c_config) static uint32_t GetI2cDeviceResource(struct I2cDevice *device, const char *deviceMatchAttr) @@ -163,7 +162,7 @@ static uint32_t GetI2cDeviceResource(struct I2cDevice *device, return HDF_ERR_INVALID_PARAM; } resource = &device->resource; -#if HCS_NODE_HAS_PROP(PLATFORM_CONFIG, i2c_config) +#if HCS_NODE_EXISTS(PLATFORM_I2C_CONFIG) HCS_FOREACH_CHILD_VARGS(PLATFORM_I2C_CONFIG, I2C_FIND_CONFIG, deviceMatchAttr, resource); #endif if (result != HDF_SUCCESS) { diff --git a/platform/pwm/pwm_bes.c b/platform/pwm/pwm_bes.c index efb202e..f8f2c2f 100644 --- a/platform/pwm/pwm_bes.c +++ b/platform/pwm/pwm_bes.c @@ -99,7 +99,6 @@ static int InitPwmDevice(struct PwmDev *host) break; \ } \ } while (0) -#define PLATFORM_CONFIG HCS_NODE(HCS_ROOT, platform) #define PLATFORM_PWM_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), pwm_config) static uint32_t GetPwmDeviceResource(struct PwmDevice *device, const char *deviceMatchAttr) { @@ -111,7 +110,7 @@ static uint32_t GetPwmDeviceResource(struct PwmDevice *device, const char *devic return HDF_ERR_INVALID_PARAM; } resource = &device->resource; -#if HCS_NODE_HAS_PROP(PLATFORM_CONFIG, pwm_config) +#if HCS_NODE_EXISTS(PLATFORM_PWM_CONFIG) HCS_FOREACH_CHILD_VARGS(PLATFORM_PWM_CONFIG, PWM_FIND_CONFIG, deviceMatchAttr, resource); #endif if (result != HDF_SUCCESS) { diff --git a/platform/spi/spi_bes.c b/platform/spi/spi_bes.c index 9d317c5..bb93f0d 100644 --- a/platform/spi/spi_bes.c +++ b/platform/spi/spi_bes.c @@ -438,7 +438,6 @@ static int32_t InitSpiDevice(struct SpiDevice *spiDevice) } \ } while (0) -#define PLATFORM_CONFIG HCS_NODE(HCS_ROOT, platform) #define PLATFORM_SPI_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), spi_config) static int32_t GetSpiDeviceResource(struct SpiDevice *spiDevice, const char *deviceMatchAttr) { @@ -450,7 +449,7 @@ static int32_t GetSpiDeviceResource(struct SpiDevice *spiDevice, const char *dev return HDF_ERR_INVALID_PARAM; } resource = &spiDevice->resource; -#if HCS_NODE_HAS_PROP(PLATFORM_CONFIG, spi_config) +#if HCS_NODE_EXISTS(PLATFORM_SPI_CONFIG) HCS_FOREACH_CHILD_VARGS(PLATFORM_SPI_CONFIG, SPI_FIND_CONFIG, deviceMatchAttr, resource); #endif if (result != HDF_SUCCESS) { diff --git a/platform/uart/uart_bes.c b/platform/uart/uart_bes.c index 32c2161..c5be0c4 100644 --- a/platform/uart/uart_bes.c +++ b/platform/uart/uart_bes.c @@ -474,7 +474,6 @@ static int InitUartDevice(struct UartHost *host) } \ } while (0) -#define PLATFORM_CONFIG HCS_NODE(HCS_ROOT, platform) #define PLATFORM_UART_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), uart_config) static uint32_t GetUartDeviceResource(struct UartDevice *device, const char *deviceMatchAttr) { @@ -485,7 +484,7 @@ static uint32_t GetUartDeviceResource(struct UartDevice *device, const char *dev return HDF_ERR_INVALID_PARAM; } resource = &device->resource; -#if HCS_NODE_HAS_PROP(PLATFORM_CONFIG, uart_config) +#if HCS_NODE_EXISTS(PLATFORM_UART_CONFIG) HCS_FOREACH_CHILD_VARGS(PLATFORM_UART_CONFIG, UART_FIND_CONFIG, deviceMatchAttr, resource); #endif if (result != HDF_SUCCESS) { -- Gitee From 78c64a7c5c93dabea1b84d92a49ae774369e1140 Mon Sep 17 00:00:00 2001 From: zhangyalei Date: Fri, 1 Apr 2022 03:48:06 -0700 Subject: [PATCH 054/102] feat: adc adapts to linux iio framework Signed-off-by: zhangyalei --- uhdf/test/unittest/platform/BUILD.gn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uhdf/test/unittest/platform/BUILD.gn b/uhdf/test/unittest/platform/BUILD.gn index 12781ec..236f3a2 100644 --- a/uhdf/test/unittest/platform/BUILD.gn +++ b/uhdf/test/unittest/platform/BUILD.gn @@ -36,6 +36,7 @@ if (board_name == "hi3516dv300" || board_name == "hispark_taurus") { defines += [ "HDF_LITEOS_TEST" ] } sources = [ + "//drivers/framework/support/platform/test/unittest/common/hdf_adc_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_gpio_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_platform_device_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_platform_event_test.cpp", @@ -45,6 +46,7 @@ if (board_name == "hi3516dv300" || board_name == "hispark_taurus") { "//drivers/framework/support/platform/test/unittest/common/hdf_regulator_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_rtc_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_spi_test.cpp", + "//drivers/framework/test/unittest/platform/common/adc_test.c", "//drivers/framework/test/unittest/platform/common/gpio_test.c", "//drivers/framework/test/unittest/platform/common/pwm_test.c", "//drivers/framework/test/unittest/platform/common/rtc_test.c", @@ -52,7 +54,6 @@ if (board_name == "hi3516dv300" || board_name == "hispark_taurus") { ] if (ohos_kernel_type == "liteos_a") { sources += [ - "//drivers/framework/support/platform/test/unittest/common/hdf_adc_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_dac_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_i2s_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_i3c_test.cpp", @@ -62,7 +63,6 @@ if (board_name == "hi3516dv300" || board_name == "hispark_taurus") { "//drivers/framework/support/platform/test/unittest/common/hdf_timer_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_uart_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_watchdog_test.cpp", - "//drivers/framework/test/unittest/platform/common/adc_test.c", "//drivers/framework/test/unittest/platform/common/dac_test.c", "//drivers/framework/test/unittest/platform/common/timer_test.c", "//drivers/framework/test/unittest/platform/common/uart_test.c", -- Gitee From 3e1a6e88358b49a99030ec9a99a389003a412380 Mon Sep 17 00:00:00 2001 From: guodongqi Date: Wed, 6 Apr 2022 10:35:22 +0800 Subject: [PATCH 055/102] fix:modify code review comments Signed-off-by: guodongqi --- uhdf2/host/src/devsvc_manager_proxy.c | 4 ++-- uhdf2/manager/src/devmgr_service_stub.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/uhdf2/host/src/devsvc_manager_proxy.c b/uhdf2/host/src/devsvc_manager_proxy.c index bc472f9..ccb9d3c 100644 --- a/uhdf2/host/src/devsvc_manager_proxy.c +++ b/uhdf2/host/src/devsvc_manager_proxy.c @@ -203,7 +203,7 @@ void DevSvcManagerProxyRemoveService(struct IDevSvcManager *inst, const char *sv break; } int status = dispatcher->Dispatch(remoteService, DEVSVC_MANAGER_REMOVE_SERVICE, data, reply); - HDF_LOGD("Device service manager proxy remove service status is %{public}d", status); + HDF_LOGW("Device service manager proxy remove service status is %{public}d", status); } while (0); if (reply != NULL) { @@ -225,7 +225,7 @@ static void DevSvcManagerProxyOnRemoteDied(struct HdfDeathRecipient *recipient, struct DevHostServiceFull *fullService = (struct DevHostServiceFull *)instance; struct HdfMessageLooper *looper = &fullService->looper; - HDF_LOGD("%{public}s: DevSvcManager dead, host %{public}d stop", __func__, fullService->super.hostId); + HDF_LOGW("%{public}s: DevSvcManager dead, host %{public}d stop", __func__, fullService->super.hostId); if ((looper != NULL) && (looper->Stop != NULL)) { looper->Stop(looper); } diff --git a/uhdf2/manager/src/devmgr_service_stub.c b/uhdf2/manager/src/devmgr_service_stub.c index 9c33da0..6da88c2 100644 --- a/uhdf2/manager/src/devmgr_service_stub.c +++ b/uhdf2/manager/src/devmgr_service_stub.c @@ -225,7 +225,6 @@ static struct HdfRemoteDispatcher g_devmgrDispatcher = { int DevmgrServiceStubStartService(struct IDevmgrService *inst) { struct DevmgrServiceStub *fullService = (struct DevmgrServiceStub *)inst; - int status; if (fullService == NULL) { return HDF_ERR_INVALID_PARAM; } @@ -252,7 +251,8 @@ int DevmgrServiceStubStartService(struct IDevmgrService *inst) return HDF_ERR_MALLOC_FAIL; } deviceObject->service = (struct IDeviceIoService *)remoteService; - status = DevSvcManagerAddService(serviceManager, DEVICE_MANAGER_SERVICE, DEVICE_CLASS_DEFAULT, deviceObject, NULL); + int status = + DevSvcManagerAddService(serviceManager, DEVICE_MANAGER_SERVICE, DEVICE_CLASS_DEFAULT, deviceObject, NULL); if (status != HDF_SUCCESS) { HdfRemoteServiceRecycle(remoteService); OsalMemFree(deviceObject); -- Gitee From 7c2bacd9a3ed6d1f1f75269b87cac35101d1af15 Mon Sep 17 00:00:00 2001 From: long_xingkai Date: Thu, 7 Apr 2022 14:19:15 +0800 Subject: [PATCH 056/102] add niobe407 hdf drivers Signed-off-by: long_xingkai Change-Id: Ie59422b1275ae4273b2dc3b7b7c5ecfeb4cd9d6f --- khdf/liteos_m/core/BUILD.gn | 4 + khdf/liteos_m/hdf_hcs.gni | 1 + platform/gpio/BUILD.gn | 7 + platform/gpio/gpio_stm32f4xx.c | 604 +++++++++++++ platform/i2c/BUILD.gn | 7 + platform/i2c/i2c_stm32f4xx.c | 395 +++++++++ platform/pwm/BUILD.gn | 7 + platform/pwm/pwm_stm32f4xx.c | 591 +++++++++++++ platform/spi/BUILD.gn | 7 + platform/spi/spi_stm32f4xx.c | 765 +++++++++++++++++ platform/uart/BUILD.gn | 7 + platform/uart/uart_stm32f4xx.c | 1093 ++++++++++++++++++++++++ platform/watchdog/BUILD.gn | 4 + platform/watchdog/watchdog_stm32f4xx.c | 49 +- 14 files changed, 3538 insertions(+), 3 deletions(-) mode change 100755 => 100644 khdf/liteos_m/hdf_hcs.gni create mode 100644 platform/gpio/gpio_stm32f4xx.c create mode 100644 platform/i2c/i2c_stm32f4xx.c create mode 100644 platform/pwm/pwm_stm32f4xx.c create mode 100644 platform/spi/spi_stm32f4xx.c create mode 100644 platform/uart/uart_stm32f4xx.c mode change 100755 => 100644 platform/watchdog/watchdog_stm32f4xx.c diff --git a/khdf/liteos_m/core/BUILD.gn b/khdf/liteos_m/core/BUILD.gn index 8b2c9b8..49a4e5f 100644 --- a/khdf/liteos_m/core/BUILD.gn +++ b/khdf/liteos_m/core/BUILD.gn @@ -83,4 +83,8 @@ hdf_driver("hdf_core") { defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { deps = [ "//device/board/fnlink/shields" ] } + if (defined(LOSCFG_NIOBE407_USE_HDF) && + defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { + deps = [ "//device/board/talkweb/niobe407/liteos_m/hdf_config" ] + } } diff --git a/khdf/liteos_m/hdf_hcs.gni b/khdf/liteos_m/hdf_hcs.gni old mode 100755 new mode 100644 index 95ac84e..e62b039 --- a/khdf/liteos_m/hdf_hcs.gni +++ b/khdf/liteos_m/hdf_hcs.gni @@ -98,5 +98,6 @@ set_defaults("hdf_driver") { configs = [ "$HDFTOPDIR:hdf_config" ] visibility = [ "$HDFTOPDIR:*" ] visibility += [ "//device/soc/bestechnic/bes2600/liteos_m/*" ] + visibility += [ "//device/board/talkweb/niobe407/liteos_m/*" ] visibility += [ "//drivers/adapter/*" ] } diff --git a/platform/gpio/BUILD.gn b/platform/gpio/BUILD.gn index bf7e7ab..ec5a261 100644 --- a/platform/gpio/BUILD.gn +++ b/platform/gpio/BUILD.gn @@ -25,10 +25,17 @@ hdf_driver(module_name) { if (defined(LOSCFG_SOC_COMPANY_WINNERMICRO)) { sources += [ "gpio_wm.c" ] } + if (defined(LOSCFG_SOC_SERIES_STM32F4xx)) { + sources += [ "gpio_stm32f4xx.c" ] + } include_dirs = [ "." ] if (defined(LOSCFG_SHIELD_V200ZR_EVB_T1) && defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { deps = [ "//device/board/fnlink/shields" ] } + if (defined(LOSCFG_NIOBE407_USE_HDF) && + defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { + deps = [ "//device/board/talkweb/niobe407/liteos_m/hdf_config" ] + } } diff --git a/platform/gpio/gpio_stm32f4xx.c b/platform/gpio/gpio_stm32f4xx.c new file mode 100644 index 0000000..60b4664 --- /dev/null +++ b/platform/gpio/gpio_stm32f4xx.c @@ -0,0 +1,604 @@ +/* + * Copyright (c) 2022 Talkweb Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include +#include "hal_gpio.h" +#include "hal_exti.h" +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO +#include "hcs_macro.h" +#include "hdf_config_macro.h" +#else +#include "device_resource_if.h" +#endif +#include "gpio_core.h" +#include "hdf_log.h" +#include "osal_irq.h" + +#define HDF_LOG_TAG gpio_stm_c + +static const uint16_t g_stmRealPinMaps[STM32_GPIO_PIN_MAX] = { + LL_GPIO_PIN_0, + LL_GPIO_PIN_1, + LL_GPIO_PIN_2, + LL_GPIO_PIN_3, + LL_GPIO_PIN_4, + LL_GPIO_PIN_5, + LL_GPIO_PIN_6, + LL_GPIO_PIN_7, + LL_GPIO_PIN_8, + LL_GPIO_PIN_9, + LL_GPIO_PIN_10, + LL_GPIO_PIN_11, + LL_GPIO_PIN_12, + LL_GPIO_PIN_13, + LL_GPIO_PIN_14, + LL_GPIO_PIN_15, +}; + +typedef struct { + uint32_t group; + uint32_t realPin; + uint32_t pin; +} GpioInflectInfo; + +GpioInflectInfo g_gpioPinsMap[STM32_GPIO_PIN_MAX * STM32_GPIO_GROUP_MAX] = {0}; + +static const GPIO_TypeDef* g_gpioxMaps[STM32_GPIO_GROUP_MAX] = { + GPIOA, + GPIOB, + GPIOC, + GPIOD, + GPIOE, + GPIOF, + GPIOG, + GPIOH, + GPIOI, +}; + +static const uint32_t g_gpioExitLineMap[STM32_GPIO_PIN_MAX] = { + LL_EXTI_LINE_0, + LL_EXTI_LINE_1, + LL_EXTI_LINE_2, + LL_EXTI_LINE_3, + LL_EXTI_LINE_4, + LL_EXTI_LINE_5, + LL_EXTI_LINE_6, + LL_EXTI_LINE_7, + LL_EXTI_LINE_8, + LL_EXTI_LINE_9, + LL_EXTI_LINE_10, + LL_EXTI_LINE_11, + LL_EXTI_LINE_12, + LL_EXTI_LINE_13, + LL_EXTI_LINE_14, + LL_EXTI_LINE_15, +}; + +typedef struct { + uint32_t pin; + uint32_t realPin; + uint32_t mode; + uint32_t group; + uint32_t pull; + uint32_t speed; + uint32_t outputType; + uint32_t alternate; +} GpioResource; + +enum GpioDeviceState { + GPIO_DEVICE_UNINITIALIZED = 0x0u, + GPIO_DEVICE_INITIALIZED = 0x1u, +}; + +typedef struct { + uint32_t pinNums; + GpioResource resource; + STM32_GPIO_GROUP group; /* gpio config */ +} GpioDevice; + +static struct GpioCntlr g_stmGpioCntlr; + +static HAL_GPIO_EXIT_CFG_T g_gpioExitCfg[STM32_GPIO_PIN_MAX * STM32_GPIO_GROUP_MAX] = {0}; + +static void OemGpioIrqHdl(uint32_t pin) +{ + GpioCntlrIrqCallback(&g_stmGpioCntlr, pin); + return; +} + +/* HdfDriverEntry method definitions */ +static int32_t GpioDriverInit(struct HdfDeviceObject *device); +static void GpioDriverRelease(struct HdfDeviceObject *device); + +/* HdfDriverEntry definitions */ +struct HdfDriverEntry g_GpioDriverEntry = { + .moduleVersion = 1, + .moduleName = "ST_GPIO_MODULE_HDF", + .Init = GpioDriverInit, + .Release = GpioDriverRelease, +}; +HDF_INIT(g_GpioDriverEntry); + +/* GpioMethod method definitions */ +static int32_t GpioDevWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val); +static int32_t GpioDevRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val); +static int32_t GpioDevSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t dir); +static int32_t GpioDevGetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *dir); +static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mode); +static int32_t GpioDevUnSetIrq(struct GpioCntlr *cntlr, uint16_t gpio); +static int32_t GpioDevEnableIrq(struct GpioCntlr *cntlr, uint16_t gpio); +static int32_t GpioDevDisableIrq(struct GpioCntlr *cntlr, uint16_t gpio); + +/* GpioMethod definitions */ +struct GpioMethod g_GpioCntlrMethod = { + .request = NULL, + .release = NULL, + .write = GpioDevWrite, + .read = GpioDevRead, + .setDir = GpioDevSetDir, + .getDir = GpioDevGetDir, + .toIrq = NULL, + .setIrq = GpioDevSetIrq, + .unsetIrq = GpioDevUnSetIrq, + .enableIrq = GpioDevEnableIrq, + .disableIrq = GpioDevDisableIrq, +}; + +static void InitGpioClock(STM32_GPIO_GROUP group) +{ + switch (group) { + case STM32_GPIO_GROUP_A: + LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA); + break; + case STM32_GPIO_GROUP_B: + LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); + break; + case STM32_GPIO_GROUP_C: + LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOC); + break; + case STM32_GPIO_GROUP_D: + LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOD); + break; + case STM32_GPIO_GROUP_E: + LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOE); + break; + case STM32_GPIO_GROUP_F: + LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOF); + break; + case STM32_GPIO_GROUP_G: + LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOG); + break; + case STM32_GPIO_GROUP_H: + LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOH); + break; + case STM32_GPIO_GROUP_I: + LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOI); + break; + default: + break; + } +} + +static int32_t InitGpioDevice(GpioDevice* device) +{ + LL_GPIO_InitTypeDef gpioInitStruct = {0}; + if (device == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + uint32_t halGpio = g_stmRealPinMaps[device->resource.realPin]; + if (halGpio > LL_GPIO_PIN_15 || halGpio < LL_GPIO_PIN_0) { + HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, halGpio); + return HDF_ERR_NOT_SUPPORT; + } + + /* init clock */ + InitGpioClock(device->resource.group); + + GPIO_TypeDef* goiox = g_gpioxMaps[device->resource.group]; + if (device->resource.mode & LL_GPIO_MODE_OUTPUT) { + LL_GPIO_ResetOutputPin(goiox, halGpio); + } + + gpioInitStruct.Pin = halGpio; + gpioInitStruct.Mode = device->resource.mode; + gpioInitStruct.Pull = device->resource.pull; + gpioInitStruct.Speed = device->resource.speed; + gpioInitStruct.OutputType = device->resource.outputType; + gpioInitStruct.Alternate = device->resource.alternate; + LL_GPIO_Init(goiox, &gpioInitStruct); + + return HDF_SUCCESS; +} + +#ifndef LOSCFG_DRIVERS_HDF_CONFIG_MACRO +static int32_t GpioParseHcs(const struct DeviceResourceIface *dri, + GpioDevice *device, const struct DeviceResourceNode *resourceNode) +{ + GpioResource *resource = NULL; + resource = &device->resource; + if (resource == NULL) { + HDF_LOGE("%s: resource is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + if (dri->GetUint32(resourceNode, "pinNum", &device->pinNums, 0) != HDF_SUCCESS) { + HDF_LOGE("gpio config read pinNum fail"); + return HDF_FAILURE; + } + + for (size_t i = 0; i < device->pinNums; i++) { + if (dri->GetUint32ArrayElem(resourceNode, "pin", i, &resource->pin, 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + if (dri->GetUint32ArrayElem(resourceNode, "realPin", i, &resource->realPin, 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + if (dri->GetUint32ArrayElem(resourceNode, "mode", i, &resource->mode, 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + if (dri->GetUint32ArrayElem(resourceNode, "speed", i, &resource->speed, 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + if (dri->GetUint32ArrayElem(resourceNode, "pull", i, &resource->pull, 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + if (dri->GetUint32ArrayElem(resourceNode, "output", i, &resource->outputType, 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + if (dri->GetUint32ArrayElem(resourceNode, "group", i, &resource->group, 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + if (dri->GetUint32ArrayElem(resourceNode, "alternate", i, &resource->alternate, 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + g_gpioPinsMap[resource->pin].group = resource->group; + g_gpioPinsMap[resource->pin].realPin = resource->realPin; + g_gpioPinsMap[resource->pin].pin = resource->pin; + + if (InitGpioDevice(device) != HDF_SUCCESS) { + HDF_LOGE("InitGpioDevice FAIL\r\n"); + return HDF_FAILURE; + } + } + + return HDF_SUCCESS; +} +#endif + +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO +#define PLATFORM_GPIO_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), gpio_config) +static uint32_t GetGpioDeviceResource(GpioDevice *device) +{ + uint32_t relPin; + int32_t ret; + GpioResource *resource = NULL; + if (device == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + resource = &device->resource; + if (resource == NULL) { + HDF_LOGE("%s: resource is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + device->pinNums = HCS_PROP(PLATFORM_GPIO_CONFIG, pinNum); + uint32_t pins[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, pin)); + uint32_t realPins[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, realPin)); + uint32_t groups[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, group)); + uint32_t modes[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, mode)); + uint32_t speeds[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, speed)); + uint32_t pulls[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, pull)); + uint32_t outputs[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, output)); + uint32_t alternates[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, alternate)); + for (size_t i = 0; i < device->pinNums; i++) { + resource->pin = pins[i]; + resource->realPin = realPins[i]; + resource->group = groups[i]; + resource->mode = modes[i]; + resource->speed = speeds[i]; + resource->pull = pulls[i]; + resource->outputType = outputs[i]; + resource->alternate = alternates[i]; + g_gpioPinsMap[resource->pin].group = resource->group; + g_gpioPinsMap[resource->pin].realPin = resource->realPin; + g_gpioPinsMap[resource->pin].pin = resource->pin; + + if (InitGpioDevice(device) != HDF_SUCCESS) { + HDF_LOGE("InitGpioDevice FAIL\r\n"); + return HDF_FAILURE; + } + } + + return HDF_SUCCESS; +} +#else +static int32_t GetGpioDeviceResource(GpioDevice *device, const struct DeviceResourceNode *resourceNode) +{ + int32_t ret; + struct DeviceResourceIface *dri = NULL; + if (device == NULL || resourceNode == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + + dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (dri == NULL || dri->GetUint32 == NULL) { + HDF_LOGE("DeviceResourceIface is invalid"); + return HDF_ERR_INVALID_OBJECT; + } + + if (GpioParseHcs(dri, device, resourceNode) != HDF_SUCCESS) { + HDF_LOGE("gpio config parse hcs fail"); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} +#endif + +static int32_t AttachGpioDevice(struct GpioCntlr *gpioCntlr, struct HdfDeviceObject *device) +{ + int32_t ret; + + GpioDevice *gpioDevice = NULL; +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO + if (device == NULL) { +#else + if (device == NULL || device->property == NULL) { +#endif + HDF_LOGE("%s: property is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + + gpioDevice = (GpioDevice *)OsalMemAlloc(sizeof(GpioDevice)); + if (gpioDevice == NULL) { + HDF_LOGE("%s: OsalMemAlloc gpioDevice error", __func__); + return HDF_ERR_MALLOC_FAIL; + } + +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO + ret = GetGpioDeviceResource(gpioDevice); +#else + ret = GetGpioDeviceResource(gpioDevice, device->property); +#endif + if (ret != HDF_SUCCESS) { + (void)OsalMemFree(gpioDevice); + return HDF_FAILURE; + } + gpioCntlr->priv = gpioDevice; + gpioCntlr->count = gpioDevice->pinNums; + + return HDF_SUCCESS; +} + +static int32_t GpioDriverInit(struct HdfDeviceObject *device) +{ + int32_t ret; + struct GpioCntlr *gpioCntlr = NULL; + + if (device == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + + ret = PlatformDeviceBind(&g_stmGpioCntlr.device, device); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: bind hdf device failed:%d", __func__, ret); + return ret; + } + + gpioCntlr = GpioCntlrFromHdfDev(device); + if (gpioCntlr == NULL) { + HDF_LOGE("GpioCntlrFromHdfDev fail\r\n"); + return HDF_DEV_ERR_NO_DEVICE_SERVICE; + } + + ret = AttachGpioDevice(gpioCntlr, device); /* GpioCntlr add GpioDevice to priv */ + if (ret != HDF_SUCCESS) { + HDF_LOGE("AttachGpioDevice fail\r\n"); + return HDF_DEV_ERR_ATTACHDEV_FAIL; + } + + gpioCntlr->ops = &g_GpioCntlrMethod; /* register callback */ + ret = GpioCntlrAdd(gpioCntlr); + if (ret != HDF_SUCCESS) { + HDF_LOGE("GpioCntlrAdd fail %d\r\n", gpioCntlr->start); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +static int32_t GpioDriverBind(struct HdfDeviceObject *device) +{ + if (device == NULL) { + HDF_LOGE("device object is NULL\n"); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +static void GpioDriverRelease(struct HdfDeviceObject *device) +{ + struct GpioCntlr *gpioCntlr = NULL; + + if (device == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return; + } + + gpioCntlr = GpioCntlrFromHdfDev(device); + if (gpioCntlr == NULL) { + HDF_LOGE("%s: host is NULL", __func__); + return; + } + + gpioCntlr->count = 0; +} + +/* dev api */ +static int32_t GpioDevWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val) +{ + uint16_t realPin = g_gpioPinsMap[gpio].realPin; + uint32_t pinReg = g_stmRealPinMaps[realPin]; + if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) { + HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin); + return HDF_ERR_NOT_SUPPORT; + } + HDF_LOGE("%s %d ,write pin num %d", __func__, __LINE__, realPin); + GPIO_TypeDef* gpiox = g_gpioxMaps[g_gpioPinsMap[gpio].group]; + if (val) { + LL_GPIO_SetOutputPin(gpiox, pinReg); + } else { + LL_GPIO_ResetOutputPin(gpiox, pinReg); + } + + return HDF_SUCCESS; +} + +static int32_t GpioDevRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val) +{ + uint16_t realPin = g_gpioPinsMap[gpio].realPin; + uint32_t pinReg = g_stmRealPinMaps[realPin]; + uint16_t value = 0; + if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) { + HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin); + return HDF_ERR_NOT_SUPPORT; + } + + GPIO_TypeDef* gpiox = g_gpioxMaps[g_gpioPinsMap[gpio].group]; + value = LL_GPIO_ReadInputPin(gpiox, pinReg); + *val = value; + + return HDF_SUCCESS; +} + +static int32_t GpioDevSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t dir) +{ + (void)cntlr; + uint16_t realPin = g_gpioPinsMap[gpio].realPin; + uint32_t pinReg = g_stmRealPinMaps[realPin]; + uint16_t value = 0; + if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) { + HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin); + return HDF_ERR_NOT_SUPPORT; + } + GPIO_TypeDef* gpiox = g_gpioxMaps[g_gpioPinsMap[gpio].group]; + LL_GPIO_SetPinMode(gpiox, pinReg, dir); + + return HDF_SUCCESS; +} + +static int32_t GpioDevGetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *dir) +{ + (void)cntlr; + uint16_t realPin = g_gpioPinsMap[gpio].realPin; + uint32_t pinReg = g_stmRealPinMaps[realPin]; + uint16_t value = 0; + if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) { + HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin); + return HDF_ERR_NOT_SUPPORT; + } + GPIO_TypeDef* gpiox = g_gpioxMaps[g_gpioPinsMap[gpio].group]; + value = LL_GPIO_GetPinMode(gpiox, pinReg); + *dir = value; + + return HDF_SUCCESS; +} + +static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mode) +{ + (void)cntlr; + uint16_t realPin = g_gpioPinsMap[gpio].realPin; + uint32_t pinReg = g_stmRealPinMaps[realPin]; + if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) { + HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin); + return HDF_ERR_NOT_SUPPORT; + } + + if (mode == OSAL_IRQF_TRIGGER_RISING) { + g_gpioExitCfg[gpio].trigger = LL_EXTI_TRIGGER_RISING; + } else if (mode == OSAL_IRQF_TRIGGER_FALLING) { + g_gpioExitCfg[gpio].trigger = LL_EXTI_TRIGGER_FALLING; + } else { + HDF_LOGE("%s %d, error mode:%d", __func__, __LINE__, mode); + return HDF_ERR_NOT_SUPPORT; + } + + return HDF_SUCCESS; +} + +static int32_t GpioDevUnSetIrq(struct GpioCntlr *cntlr, uint16_t gpio) +{ + (void)cntlr; + uint16_t realPin = g_gpioPinsMap[gpio].realPin; + uint32_t pinReg = g_stmRealPinMaps[realPin]; + if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) { + HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin); + return HDF_ERR_NOT_SUPPORT; + } + + return HDF_SUCCESS; +} + +static int32_t GpioDevEnableIrq(struct GpioCntlr *cntlr, uint16_t gpio) +{ + (void)cntlr; + LL_EXTI_InitConfig exitInitConfig = {0}; + uint16_t realPin = g_gpioPinsMap[gpio].realPin; + uint32_t pinReg = g_stmRealPinMaps[realPin]; + if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) { + HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin); + return HDF_ERR_NOT_SUPPORT; + } + + exitInitConfig.Exithandler = OemGpioIrqHdl; + exitInitConfig.Gpiox = g_gpioxMaps[g_gpioPinsMap[gpio].group]; + exitInitConfig.initType.Line_0_31 = g_gpioExitLineMap[g_gpioPinsMap[gpio].realPin]; + exitInitConfig.initType.LineCommand = ENABLE; + exitInitConfig.initType.Mode = LL_EXTI_MODE_IT; + exitInitConfig.PinReg = pinReg; + exitInitConfig.initType.Trigger = g_gpioExitCfg[gpio].trigger; + + LL_SETUP_EXTI(&exitInitConfig, g_gpioPinsMap[gpio].realPin, gpio, g_gpioPinsMap[gpio].group); + + return HDF_SUCCESS; +} + +static int32_t GpioDevDisableIrq(struct GpioCntlr *cntlr, uint16_t gpio) +{ + (void)cntlr; + LL_EXTI_InitConfig exitInitConfig = {0}; + uint16_t realPin = g_gpioPinsMap[gpio].realPin; + uint32_t pinReg = g_stmRealPinMaps[realPin]; + if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) { + HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin); + return HDF_ERR_NOT_SUPPORT; + } + + exitInitConfig.Exithandler = NULL; + exitInitConfig.Gpiox = g_gpioxMaps[g_gpioPinsMap[gpio].group]; + exitInitConfig.initType.Line_0_31 = g_gpioExitLineMap[g_gpioPinsMap[gpio].realPin]; + exitInitConfig.initType.LineCommand = DISABLE; + exitInitConfig.initType.Mode = LL_EXTI_MODE_IT; + exitInitConfig.PinReg = pinReg; + exitInitConfig.initType.Trigger = g_gpioExitCfg[gpio].trigger; + LL_SETUP_EXTI(&exitInitConfig, g_gpioPinsMap[gpio].realPin, gpio, g_gpioPinsMap[gpio].group); + + return HDF_SUCCESS; +} \ No newline at end of file diff --git a/platform/i2c/BUILD.gn b/platform/i2c/BUILD.gn index 491883c..0677ba8 100644 --- a/platform/i2c/BUILD.gn +++ b/platform/i2c/BUILD.gn @@ -19,10 +19,17 @@ hdf_driver(module_name) { if (defined(LOSCFG_SOC_COMPANY_WINNERMICRO)) { sources += [ "i2c_wm.c" ] } + if (defined(LOSCFG_SOC_SERIES_STM32F4xx)) { + sources += [ "i2c_stm32f4xx.c" ] + } include_dirs = [ "." ] if (defined(LOSCFG_SHIELD_V200ZR_EVB_T1) && defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { deps = [ "//device/board/fnlink/shields" ] } + if (defined(LOSCFG_NIOBE407_USE_HDF) && + defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { + deps = [ "//device/board/talkweb/niobe407/liteos_m/hdf_config" ] + } } diff --git a/platform/i2c/i2c_stm32f4xx.c b/platform/i2c/i2c_stm32f4xx.c new file mode 100644 index 0000000..f00f9d7 --- /dev/null +++ b/platform/i2c/i2c_stm32f4xx.c @@ -0,0 +1,395 @@ +/* + * Copyright (c) 2022 Talkweb 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 +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO +#include "hcs_macro.h" +#include "hdf_config_macro.h" +#else +#include "device_resource_if.h" +#endif +#include "hdf_device_desc.h" +#include "hdf_log.h" +#include "i2c_core.h" +#include "i2c_if.h" +#include "osal_mutex.h" +#include "hdf_base_hal.h" +#include "stm32f4xx_ll_i2c.h" + +#define HDF_LOG_TAG "hdf_i2c" + +typedef enum { + I2C_HANDLE_NULL = 0, + I2C_HANDLE_1 = 1, + I2C_HANDLE_2 = 2, + I2C_HANDLE_3 = 3, + I2C_HANDLE_MAX = I2C_HANDLE_3 +} I2C_HANDLE; + +struct RealI2cResource { + uint8_t port; + uint8_t devMode; + uint32_t devAddr; + uint32_t speed; + struct OsalMutex mutex; +}; + +static bool g_I2cEnableFlg[I2C_HANDLE_MAX] = {0}; + +static void HdfI2cInit(I2C_HANDLE i2cx, unsigned int i2cRate, unsigned int addr); +static void HdfI2cWrite(I2C_HANDLE i2cx, unsigned char devAddr, unsigned char *buf, unsigned int len); +static void HdfI2cRead(I2C_HANDLE i2cx, unsigned char devAddr, unsigned char *buf, unsigned int len); + +static int32_t I2cDriverBind(struct HdfDeviceObject *device); +static int32_t I2cDriverInit(struct HdfDeviceObject *device); +static void I2cDriverRelease(struct HdfDeviceObject *device); +static int32_t I2cDataTransfer(struct I2cCntlr *cntlr, struct I2cMsg *msgs, int16_t count); + +struct HdfDriverEntry gI2cHdfDriverEntry = { + .moduleVersion = 1, + .moduleName = "HDF_I2C", + .Bind = I2cDriverBind, + .Init = I2cDriverInit, + .Release = I2cDriverRelease, +}; +HDF_INIT(gI2cHdfDriverEntry); + +struct I2cMethod gI2cHostMethod = { + .transfer = I2cDataTransfer, +}; + +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO +#define I2C_FIND_CONFIG(node, name, resource) \ + do { \ + if (strcmp(HCS_PROP(node, match_attr), name) == 0) { \ + resource->port = HCS_PROP(node, port); \ + resource->devMode = HCS_PROP(node, devMode); \ + resource->devAddr = HCS_PROP(node, devAddr); \ + resource->speed = HCS_PROP(node, speed); \ + result = HDF_SUCCESS; \ + } \ + } while (0) +#define PLATFORM_CONFIG HCS_NODE(HCS_ROOT, platform) +#define PLATFORM_I2C_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), i2c_config) +static uint32_t GetI2cDeviceResource(struct RealI2cResource *i2cResource, const char *deviceMatchAttr) +{ + int32_t result = HDF_FAILURE; + struct RealI2cResource *resource = NULL; + if (i2cResource == NULL || deviceMatchAttr == NULL) { + HDF_LOGE("device or deviceMatchAttr is NULL\r\n"); + return HDF_ERR_INVALID_PARAM; + } + resource = i2cResource; +#if HCS_NODE_HAS_PROP(PLATFORM_CONFIG, i2c_config) + HCS_FOREACH_CHILD_VARGS(PLATFORM_I2C_CONFIG, I2C_FIND_CONFIG, deviceMatchAttr, resource); +#endif + if (result != HDF_SUCCESS) { + HDF_LOGE("resourceNode %s is NULL\r\n", deviceMatchAttr); + } else { + HdfI2cInit(i2cResource->port, i2cResource->speed, i2cResource->devAddr); + } + return result; +} +#else +static int32_t GetI2cDeviceResource(struct RealI2cResource *i2cResource, const struct DeviceResourceNode *resourceNode) +{ + if (i2cResource == NULL || resourceNode == NULL) { + HDF_LOGE("[%s]: param is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + struct DeviceResourceIface *dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (dri == NULL || dri->GetUint8 == NULL || dri->GetUint32 == NULL || dri->GetUint32Array == NULL) { + HDF_LOGE("DeviceResourceIface is invalid\r\n"); + return HDF_ERR_INVALID_OBJECT; + } + + if (dri->GetUint8(resourceNode, "port", &i2cResource->port, 0) != HDF_SUCCESS) { + HDF_LOGE("i2c config port fail\r\n"); + return HDF_FAILURE; + } + + if (dri->GetUint8(resourceNode, "devMode", &i2cResource->devMode, 0) != HDF_SUCCESS) { + HDF_LOGE("i2c config devMode fail\r\n"); + return HDF_FAILURE; + } + + if (dri->GetUint32(resourceNode, "devAddr", &i2cResource->devAddr, 0) != HDF_SUCCESS) { + HDF_LOGE("i2c config devAddr fail\r\n"); + return HDF_FAILURE; + } + + if (dri->GetUint32(resourceNode, "speed", &i2cResource->speed, 0) != HDF_SUCCESS) { + HDF_LOGE("i2c config speed fail\r\n"); + return HDF_FAILURE; + } + + HdfI2cInit(i2cResource->port, i2cResource->speed, i2cResource->devAddr); + + return HDF_SUCCESS; +} +#endif + +static int32_t AttachI2cDevice(struct I2cCntlr *host, struct HdfDeviceObject *device) +{ + int32_t ret = HDF_FAILURE; + + if (host == NULL || device == NULL) { + HDF_LOGE("[%s]: param is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + struct RealI2cResource *i2cResource = (struct RealI2cResource *)OsalMemAlloc(sizeof(struct RealI2cResource)); + if (i2cResource == NULL) { + HDF_LOGE("[%s]: OsalMemAlloc RealI2cResource fail\r\n", __func__); + return HDF_ERR_MALLOC_FAIL; + } + memset_s(i2cResource, sizeof(struct RealI2cResource), 0, sizeof(struct RealI2cResource)); +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO + ret = GetI2cDeviceResource(i2cResource, device->deviceMatchAttr); +#else + ret = GetI2cDeviceResource(i2cResource, device->property); +#endif + if (ret != HDF_SUCCESS) { + OsalMemFree(i2cResource); + return HDF_FAILURE; + } + + host->busId = i2cResource->port; + host->priv = i2cResource; + + return HDF_SUCCESS; +} + +static int32_t I2cDataTransfer(struct I2cCntlr *cntlr, struct I2cMsg *msgs, int16_t count) +{ + if (cntlr == NULL || msgs == NULL || cntlr->priv == NULL) { + HDF_LOGE("[%s]: I2cDataTransfer param is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (count <= 0) { + HDF_LOGE("[%s]: I2cDataTransfer count err\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + struct RealI2cResource *device = (struct I2cDevice *)cntlr->priv; + if (device == NULL) { + HDF_LOGE("%s: I2cDevice is NULL\r\n", __func__); + return HDF_DEV_ERR_NO_DEVICE; + } + + struct I2cMsg *msg = NULL; + if (HDF_SUCCESS != OsalMutexLock(&device->mutex)) { + HDF_LOGE("[%s]: OsalMutexLock fail\r\n", __func__); + return HDF_ERR_TIMEOUT; + } + + for (int32_t i = 0; i < count; i++) { + msg = &msgs[i]; + if (msg->flags == I2C_FLAG_READ) { + HdfI2cRead(device->port, msg->addr, msg->buf, msg->len); + } else { + HdfI2cWrite(device->port, msg->addr, msg->buf, msg->len); + } + } + OsalMutexUnlock(&device->mutex); + + return count; +} + +static int32_t I2cDriverBind(struct HdfDeviceObject *device) +{ + if (device == NULL) { + HDF_LOGE("[%s]: I2c device is NULL\r\n", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +static int32_t I2cDriverInit(struct HdfDeviceObject *device) +{ + int32_t ret = HDF_FAILURE; + struct I2cCntlr *host = NULL; + if (device == NULL) { + HDF_LOGE("[%s]: I2c device is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + host = (struct I2cCntlr *)OsalMemAlloc(sizeof(struct I2cCntlr)); + if (host == NULL) { + HDF_LOGE("[%s]: malloc host is NULL\r\n", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + memset_s(host, sizeof(struct I2cCntlr), 0, sizeof(struct I2cCntlr)); + host->ops = &gI2cHostMethod; + device->priv = (void *)host; + + ret = AttachI2cDevice(host, device); + if (ret != HDF_SUCCESS) { + HDF_LOGE("[%s]: AttachI2cDevice error, ret = %d\r\n", __func__, ret); + I2cDriverRelease(device); + return HDF_DEV_ERR_ATTACHDEV_FAIL; + } + + ret = I2cCntlrAdd(host); + if (ret != HDF_SUCCESS) { + I2cDriverRelease(device); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +static void I2cDriverRelease(struct HdfDeviceObject *device) +{ + if (device == NULL) { + HDF_LOGE("%s: device is NULL\r\n", __func__); + return; + } + + struct I2cCntlr *i2cCntrl = device->priv; + if (i2cCntrl == NULL || i2cCntrl->priv == NULL) { + HDF_LOGE("%s: i2cCntrl is NULL\r\n", __func__); + return; + } + i2cCntrl->ops = NULL; + struct RealI2cResource *i2cDevice = (struct I2cDevice *)i2cCntrl->priv; + OsalMemFree(i2cCntrl); + + if (i2cDevice != NULL) { + OsalMutexDestroy(&i2cDevice->mutex); + OsalMemFree(i2cDevice); + } +} + +static I2C_TypeDef *GetLLI2cHandlerMatch(I2C_HANDLE i2cx) +{ + if (i2cx > I2C_HANDLE_MAX) { + printf("ERR: GetLLI2cClkMatch fail, param match fail\r\n"); + return NULL; + } + + switch (i2cx) { + case I2C_HANDLE_1: + return (I2C_TypeDef *)I2C1; + case I2C_HANDLE_2: + return (I2C_TypeDef *)I2C2; + case I2C_HANDLE_3: + return (I2C_TypeDef *)I2C3; + default: + printf("ERR: GetLLI2cClkMatch fail, handler match fail\r\n"); + return NULL; + } +} + +static bool EnableLLI2cClock(I2C_TypeDef *i2cx) +{ + if (i2cx == I2C1) { + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1); + return true; + } else if (i2cx == I2C2) { + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C2); + return true; + } else if (i2cx == I2C3) { + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C3); + return true; + } else { + printf("EnableI2cClock fail, i2cx match fail\r\n"); + return false; + } +} + +static void HdfI2cInit(I2C_HANDLE i2cx, unsigned int i2cRate, unsigned int addr) +{ + LL_I2C_InitTypeDef I2C_InitStruct = {0}; + I2C_TypeDef *myI2c = GetLLI2cHandlerMatch(i2cx); + if (myI2c == NULL) { + return; + } + + EnableLLI2cClock(myI2c); + LL_I2C_DisableOwnAddress2(myI2c); + LL_I2C_DisableGeneralCall(myI2c); + LL_I2C_EnableClockStretching(myI2c); + I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C; + I2C_InitStruct.ClockSpeed = i2cRate; + I2C_InitStruct.DutyCycle = LL_I2C_DUTYCYCLE_2; + I2C_InitStruct.OwnAddress1 = addr; + I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK; + I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT; + LL_I2C_Init(myI2c, &I2C_InitStruct); + LL_I2C_SetOwnAddress2(myI2c, 0); + + g_I2cEnableFlg[i2cx] = true; +} + +static void HdfI2cWrite(I2C_HANDLE i2cx, unsigned char devAddr, unsigned char *buf, unsigned int len) +{ + if (g_I2cEnableFlg[i2cx] != true) { + printf("I2C_WriteByte err, Please initialize first!"); + return; + } + + I2C_TypeDef *myI2c = GetLLI2cHandlerMatch(i2cx); + if (myI2c == NULL) { + return; + } + + while (LL_I2C_IsActiveFlag_BUSY(myI2c)); + + LL_I2C_GenerateStartCondition(myI2c); + while (LL_I2C_IsActiveFlag_SB(myI2c) == RESET); + + LL_I2C_TransmitData8(myI2c, (devAddr << 1)); + while (LL_I2C_IsActiveFlag_TXE(myI2c) == RESET); + + LL_I2C_ClearFlag_ADDR(myI2c); + while (LL_I2C_IsActiveFlag_TXE(myI2c) == RESET); + + for (unsigned int i = 0; i < len; i++) { + LL_I2C_TransmitData8(myI2c, buf[i]); + while (LL_I2C_IsActiveFlag_TXE(myI2c) == RESET); + } + + LL_I2C_GenerateStopCondition(myI2c); +} + +static void HdfI2cRead(I2C_HANDLE i2cx, unsigned char devAddr, unsigned char *buf, unsigned int len) +{ + if (g_I2cEnableFlg[i2cx] != true) { + printf("I2C_ReadByte err, Please initialize first!"); + return; + } + + I2C_TypeDef *myI2c = GetLLI2cHandlerMatch(i2cx); + if (myI2c == NULL) { + return; + } + + while (LL_I2C_IsActiveFlag_BUSY(myI2c)); + + LL_I2C_GenerateStartCondition(myI2c); + while (LL_I2C_IsActiveFlag_SB(myI2c) == RESET); + + LL_I2C_TransmitData8(myI2c, ((devAddr << 1) | 1)); + while ((LL_I2C_IsActiveFlag_ADDR(myI2c) == RESET) || (LL_I2C_IsActiveFlag_MSL(myI2c) == RESET) || + (LL_I2C_IsActiveFlag_BUSY(myI2c) == RESET)); + + for (unsigned int i = 0; i < len; i++) { + if (i < len - 1) { + LL_I2C_AcknowledgeNextData(myI2c, LL_I2C_ACK); + } else { + LL_I2C_AcknowledgeNextData(myI2c, LL_I2C_NACK); + } + while (LL_I2C_IsActiveFlag_RXNE(myI2c) == RESET); + buf[i] = LL_I2C_ReceiveData8(myI2c); + } + LL_I2C_GenerateStopCondition(myI2c); +} \ No newline at end of file diff --git a/platform/pwm/BUILD.gn b/platform/pwm/BUILD.gn index d7bbac6..77499ba 100644 --- a/platform/pwm/BUILD.gn +++ b/platform/pwm/BUILD.gn @@ -19,10 +19,17 @@ hdf_driver(module_name) { if (defined(LOSCFG_SOC_COMPANY_WINNERMICRO)) { sources += [ "pwm_wm.c" ] } + if (defined(LOSCFG_SOC_SERIES_STM32F4xx)) { + sources += [ "pwm_stm32f4xx.c" ] + } include_dirs = [ "." ] if (defined(LOSCFG_SHIELD_V200ZR_EVB_T1) && defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { deps = [ "//device/board/fnlink/shields" ] } + if (defined(LOSCFG_NIOBE407_USE_HDF) && + defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { + deps = [ "//device/board/talkweb/niobe407/liteos_m/hdf_config" ] + } } diff --git a/platform/pwm/pwm_stm32f4xx.c b/platform/pwm/pwm_stm32f4xx.c new file mode 100644 index 0000000..3ee1a83 --- /dev/null +++ b/platform/pwm/pwm_stm32f4xx.c @@ -0,0 +1,591 @@ +/* + * Copyright (c) 2022 Talkweb Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include +#include +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO +#include "hcs_macro.h" +#include "hdf_config_macro.h" +#else +#include "device_resource_if.h" +#endif +#include "hdf_device_desc.h" +#include "pwm_core.h" +#include "hdf_log.h" +#include "hdf_base_hal.h" +#include "stm32f4xx_ll_tim.h" + +#define GPIO_STR_MAX_LENGTH 32 + +typedef enum { + PWM_CH1 = 0, + PWM_CH2, + PWM_CH3, + PWM_CH4, + PWM_CH_MAX +} PWM_CH; + +typedef enum { + PWM_TIM1 = 0, + PWM_TIM2, + PWM_TIM3, + PWM_TIM4, + PWM_TIM5, + PWM_TIM6, + PWM_TIM7, + PWM_TIM8, + PWM_TIM9, + PWM_TIM10, + PWM_TIM11, + PWM_TIM12, + PWM_TIM13, + PWM_TIM14, + PWM_TIM_MAX +} PWM_TIM; + +typedef struct { + PWM_CH pwmCh; + PWM_TIM pwmTim; + uint32_t prescaler; + uint32_t timPeroid; + uint32_t realHz; +} PwmResource; + +typedef struct { + LL_TIM_InitTypeDef timInitStruct; + LL_TIM_OC_InitTypeDef timOcInitStruct; +} PwmConfig; + +typedef struct { + struct IDeviceIoService ioService; + PwmConfig stPwmCfg; + struct PwmConfig *cfg; + PwmResource resource; +} PwmDevice; + +typedef struct { + uint32_t period; + uint32_t duty; + PWM_TIM pwmCh; + PWM_TIM pwmTim; +} PwmFreqArg; + +static TIM_TypeDef* g_stTimMap[PWM_TIM_MAX] = { + TIM1, + TIM2, + TIM3, + TIM4, + TIM5, + TIM6, + TIM7, + TIM8, + TIM9, + TIM10, + TIM11, + TIM12, + TIM13, + TIM14, +}; + +static uint32_t g_stChannelMap[PWM_CH_MAX] = { + LL_TIM_CHANNEL_CH1, + LL_TIM_CHANNEL_CH2, + LL_TIM_CHANNEL_CH3, + LL_TIM_CHANNEL_CH4, +}; + +static uint32_t g_stTimIrqMap[PWM_TIM_MAX] = { + TIM1_CC_IRQn, + TIM2_IRQn, + TIM3_IRQn, + TIM4_IRQn, + TIM5_IRQn, + TIM6_DAC_IRQn, + TIM7_IRQn, + TIM8_CC_IRQn, + TIM1_BRK_TIM9_IRQn, + TIM1_UP_TIM10_IRQn, + TIM1_TRG_COM_TIM11_IRQn, + TIM8_BRK_TIM12_IRQn, + TIM8_UP_TIM13_IRQn, + TIM8_TRG_COM_TIM14_IRQn, +}; + +static uint32_t g_stTimFreq[PWM_TIM_MAX] = { // tim2-tim7, tim12-tim14 is 84M,TIM1、TIM8~TIM11 is 168M + 168000000, + 84000000, + 84000000, + 84000000, + 84000000, + 84000000, + 84000000, + 168000000, + 168000000, + 168000000, + 168000000, + 84000000, + 84000000, +}; + +#define PER_SEC_NSEC 1000000000 + +static int32_t PwmDevSetConfig(struct PwmDev *pwm, struct PwmConfig *config); +static int32_t PwmDevOpen(struct PwmDev *pwm); +static int32_t PwmDevClose(struct PwmDev *pwm); + +struct PwmMethod g_pwmmethod = { + .setConfig = PwmDevSetConfig, + .open = PwmDevOpen, + .close = PwmDevClose, +}; + +static void InitPwmClock(PWM_TIM tim) +{ + switch (tim) { + case PWM_TIM1: + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM1); + break; + case PWM_TIM2: + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2); + break; + case PWM_TIM3: + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3); + break; + case PWM_TIM4: + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4); + break; + case PWM_TIM5: + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM5); + break; + case PWM_TIM6: + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM6); + break; + case PWM_TIM7: + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM7); + break; + case PWM_TIM8: + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM8); + break; + case PWM_TIM9: + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM9); + break; + case PWM_TIM10: + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM10); + break; + case PWM_TIM11: + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM11); + break; + case PWM_TIM12: + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM12); + break; + case PWM_TIM13: + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM13); + break; + case PWM_TIM14: + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM14); + break; + default: + break; + } +} + +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO +#define PWM_FIND_CONFIG(node, name, resource) \ + do { \ + if (strcmp(HCS_PROP(node, match_attr), name) == 0) { \ + uint8_t tim = HCS_PROP(node, pwmTim); \ + uint8_t ch = HCS_PROP(node, pwmCh); \ + uint8_t prescaler = HCS_PROP(node, prescaler); \ + resource->pwmCh = ch; \ + resource->pwmTim = tim; \ + resource->prescaler = prescaler; \ + result = HDF_SUCCESS; \ + } \ + } while (0) +#define PLATFORM_CONFIG HCS_NODE(HCS_ROOT, platform) +#define PLATFORM_PWM_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), pwm_config) +static uint32_t GetPwmDeviceResource(PwmDevice *device, const char *deviceMatchAttr) +{ + int32_t result = HDF_FAILURE; + PwmResource *resource = NULL; + if (device == NULL || deviceMatchAttr == NULL) { + HDF_LOGE("%s: device or deviceMatchAttr is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + resource = &device->resource; +#if HCS_NODE_HAS_PROP(PLATFORM_CONFIG, pwm_config) + HCS_FOREACH_CHILD_VARGS(PLATFORM_PWM_CONFIG, PWM_FIND_CONFIG, deviceMatchAttr, resource); +#endif + if (result != HDF_SUCCESS) { + HDF_LOGE("resourceNode %s is NULL\r\n", deviceMatchAttr); + } + + return result; +} +#else +static int32_t GetPwmDeviceResource(PwmDevice *device, const struct DeviceResourceNode *resourceNode) +{ + struct DeviceResourceIface *dri = NULL; + PwmResource *resource = NULL; + + if (device == NULL || resourceNode == NULL) { + HDF_LOGE("resource or device is NULL\r\n"); + return HDF_ERR_INVALID_PARAM; + } + + resource = &device->resource; + if (resource == NULL) { + HDF_LOGE("resource is NULL\r\n"); + return HDF_ERR_INVALID_OBJECT; + } + + dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (dri == NULL || dri->GetUint8 == NULL || dri->GetUint32 == NULL) { + HDF_LOGE("DeviceResourceIface is invalid\r\n"); + return HDF_ERR_INVALID_PARAM; + } + + if (dri->GetUint8(resourceNode, "pwmTim", &resource->pwmTim, 0) != HDF_SUCCESS) { + HDF_LOGE("read pwmPin fail\r\n"); + return HDF_ERR_INVALID_PARAM; + } + + if (resource->pwmTim == PWM_TIM6 || resource->pwmTim == PWM_TIM7) { + HDF_LOGE("unsupport tim\r\n"); + return HDF_ERR_INVALID_PARAM; + } + + if (dri->GetUint8(resourceNode, "pwmCh", &resource->pwmCh, 0) != HDF_SUCCESS) { + HDF_LOGE("read pwmCh fail\r\n"); + return HDF_FAILURE; + } + + if (dri->GetUint32(resourceNode, "prescaler", &resource->prescaler, 0) != HDF_SUCCESS) { + HDF_LOGE("read prescaler fail\r\n"); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} +#endif + +static int32_t AttachPwmDevice(struct PwmDev *host, struct HdfDeviceObject *device) +{ + int32_t ret; + PwmDevice *pwmDevice = NULL; +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO + if (device == NULL || host == NULL) { +#else + if (device == NULL || device->property == NULL || host == NULL) { +#endif + HDF_LOGE("%s: param is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + pwmDevice = (PwmDevice *)OsalMemAlloc(sizeof(PwmDevice)); + if (pwmDevice == NULL) { + HDF_LOGE("%s: OsalMemAlloc pwmDevice error\r\n", __func__); + return HDF_ERR_MALLOC_FAIL; + } +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO + ret = GetPwmDeviceResource(pwmDevice, device->deviceMatchAttr); +#else + ret = GetPwmDeviceResource(pwmDevice, device->property); +#endif + if (ret != HDF_SUCCESS) { + (void)OsalMemFree(pwmDevice); + return HDF_FAILURE; + } + host->priv = pwmDevice; + host->num = pwmDevice->resource.pwmTim; + + return HDF_SUCCESS; +} + +static int32_t PwmDriverBind(struct HdfDeviceObject *device); +static int32_t PwmDriverInit(struct HdfDeviceObject *device); +static void PwmDriverRelease(struct HdfDeviceObject *device); + +struct HdfDriverEntry g_pwmDriverEntry = { + .moduleVersion = 1, + .moduleName = "ST_HDF_PLATFORM_PWM", + .Bind = PwmDriverBind, + .Init = PwmDriverInit, + .Release = PwmDriverRelease, +}; +HDF_INIT(g_pwmDriverEntry); + +static int32_t PwmDriverBind(struct HdfDeviceObject *device) +{ + struct PwmDev *devService = NULL; + if (device == NULL) { + HDF_LOGE("hdfDevice object is null!\r\n"); + return HDF_FAILURE; + } + + devService = (struct PwmDev *)OsalMemCalloc(sizeof(struct PwmDev)); + if (devService == NULL) { + HDF_LOGE("malloc pwmDev failed\n"); + } + device->service = &devService->service; + devService->device = device; + + return HDF_SUCCESS; +} + +static int32_t PwmDriverInit(struct HdfDeviceObject *device) +{ + int32_t ret; + struct PwmDev *host = NULL; + + if (device == NULL) { + HDF_LOGE("%s: device is NULL\r\n", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + host = (struct PwmDev *)device->service; + if (host == NULL) { + HDF_LOGE("%s: host is NULL\r\n", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + ret = AttachPwmDevice(host, device); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s:attach error\r\n", __func__); + return HDF_DEV_ERR_ATTACHDEV_FAIL; + } + + host->method = &g_pwmmethod; + ret = PwmDeviceAdd(device, host); + if (ret != HDF_SUCCESS) { + PwmDeviceRemove(device, host); + OsalMemFree(host->device); + OsalMemFree(host); + return HDF_DEV_ERR_NO_DEVICE; + } + + return HDF_SUCCESS; +} + +static void PwmDriverRelease(struct HdfDeviceObject *device) +{ + struct PwmDev *host = NULL; + + if (device == NULL || device->service == NULL) { + HDF_LOGE("device is null\r\n"); + return; + } + + host = (struct PwmDev *)device->service; + if (host != NULL && host->device != NULL) { + host->method = NULL; + OsalMemFree(host->device); + OsalMemFree(host); + host->device = NULL; + host = NULL; + } + + device->service = NULL; + host = NULL; + + return; +} + +static int32_t InitPwmFreqAndPeriod(const struct PwmConfig *config, PwmFreqArg* arg, const PwmResource *resource) +{ + if (arg == NULL) { + HDF_LOGE("null ptr\r\n"); + return HDF_FAILURE; + } + + uint32_t freq = 0; + uint32_t period = 0; + uint32_t duty = 0; + uint32_t realHz = 0; + + if (config->period != 0) { + freq = (uint32_t)(PER_SEC_NSEC / config->period); + } else { + HDF_LOGE("invalid div\r\n"); + return HDF_FAILURE; + } + + realHz = (uint32_t)(((double)g_stTimFreq[arg->pwmTim]) / ((double)(resource->prescaler + 1))); + + if (freq != 0) { + period = (uint32_t)(realHz / freq); + } else { + HDF_LOGE("invalid div\r\n"); + return HDF_FAILURE; + } + + if (config->period != 0) { + duty = (uint32_t)(((double)config->duty / (double)config->period) * period); + } else { + HDF_LOGE("invalid div\r\n"); + return HDF_FAILURE; + } + + arg->period = period; + arg->duty = duty; + + return HDF_SUCCESS; +} + +static void InitTimPwm(const PwmFreqArg* arg, const struct PwmConfig *config, + PwmConfig *pwmCfg, const PwmResource *resource) +{ + if (arg == NULL) { + HDF_LOGE("null ptr\r\n"); + return; + } + + pwmCfg->timInitStruct.Autoreload = arg->period - 1; // if period is 1000 20KHz/1000=20Hz,period is 50ms + pwmCfg->timInitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; + pwmCfg->timInitStruct.CounterMode = LL_TIM_COUNTERMODE_UP; + pwmCfg->timInitStruct.Prescaler = resource->prescaler; + LL_TIM_Init(g_stTimMap[arg->pwmTim], &pwmCfg->timInitStruct); + LL_TIM_EnableARRPreload(g_stTimMap[arg->pwmTim]); + LL_TIM_SetClockSource(g_stTimMap[arg->pwmTim], LL_TIM_CLOCKSOURCE_INTERNAL); + LL_TIM_SetTriggerOutput(g_stTimMap[arg->pwmTim], LL_TIM_TRGO_RESET); + LL_TIM_DisableMasterSlaveMode(g_stTimMap[arg->pwmTim]); + + pwmCfg->timOcInitStruct.OCMode = LL_TIM_OCMODE_PWM1; // PWM1 mode + pwmCfg->timOcInitStruct.OCState = LL_TIM_OCSTATE_DISABLE; + pwmCfg->timOcInitStruct.CompareValue = arg->duty; + if (config->polarity == PWM_NORMAL_POLARITY) { + pwmCfg->timOcInitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH; + } else { + pwmCfg->timOcInitStruct.OCPolarity = LL_TIM_OCPOLARITY_LOW; + } + pwmCfg->timOcInitStruct.OCIdleState = LL_TIM_OCPOLARITY_LOW; + + LL_TIM_OC_Init(g_stTimMap[arg->pwmTim], g_stChannelMap[arg->pwmCh], &pwmCfg->timOcInitStruct); + LL_TIM_OC_DisableFast(g_stTimMap[arg->pwmTim], g_stChannelMap[arg->pwmCh]); + + if (arg->pwmTim == PWM_TIM1 || arg->pwmTim == PWM_TIM8) { + LL_TIM_BDTR_InitTypeDef bdtrInitStruct = {0}; + bdtrInitStruct.OSSRState = LL_TIM_OSSR_DISABLE; + bdtrInitStruct.OSSIState = LL_TIM_OSSI_DISABLE; + bdtrInitStruct.LockLevel = LL_TIM_LOCKLEVEL_OFF; + bdtrInitStruct.DeadTime = 0; // dead area time 200ns 0x28 + bdtrInitStruct.BreakState = LL_TIM_BREAK_ENABLE; + bdtrInitStruct.BreakPolarity = LL_TIM_BREAK_POLARITY_HIGH; + bdtrInitStruct.AutomaticOutput = LL_TIM_AUTOMATICOUTPUT_ENABLE; + LL_TIM_BDTR_Init(g_stTimMap[arg->pwmTim], &bdtrInitStruct); + } + + NVIC_SetPriority(g_stTimIrqMap[arg->pwmTim], NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 1, 1)); + NVIC_EnableIRQ(g_stTimIrqMap[arg->pwmTim]); + + if (arg->pwmTim == PWM_TIM1 || arg->pwmTim == PWM_TIM8) { + LL_TIM_EnableAutomaticOutput(g_stTimMap[arg->pwmTim]); + LL_TIM_GenerateEvent_UPDATE(g_stTimMap[arg->pwmTim]); + } + LL_TIM_EnableCounter(g_stTimMap[arg->pwmTim]); + LL_TIM_CC_EnableChannel(g_stTimMap[arg->pwmTim], g_stChannelMap[arg->pwmCh]); + LL_TIM_OC_EnablePreload(g_stTimMap[arg->pwmTim], g_stChannelMap[arg->pwmCh]); + + return; +} + +static void DeInitTimPwm(PWM_TIM pwmId, PWM_CH pwmCh) +{ + LL_TIM_DeInit(g_stTimMap[pwmId]); + LL_TIM_OC_DisableClear(g_stTimMap[pwmId], g_stChannelMap[pwmCh]); + NVIC_DisableIRQ(g_stTimIrqMap[pwmId]); + + LL_TIM_DisableCounter(g_stTimMap[pwmId]); + LL_TIM_CC_DisableChannel(g_stTimMap[pwmId], g_stChannelMap[pwmCh]); + LL_TIM_OC_DisablePreload(g_stTimMap[pwmId], g_stChannelMap[pwmCh]); + + if (pwmId== PWM_TIM1 || pwmId == PWM_TIM8) { + LL_TIM_DisableAutomaticOutput(g_stTimMap[pwmId]); + } + + return; +} + +static int32_t PwmDevSetConfig(struct PwmDev *pwm, struct PwmConfig *config) +{ + PwmDevice *prvPwm = NULL; + PwmConfig *pwmCfg = NULL; + PWM_TIM pwmId; + PWM_CH pwmCh; + PwmResource *resource = NULL; + + if (pwm == NULL || config == NULL || (config->period > PER_SEC_NSEC)) { + HDF_LOGE("%s\r\n", __FUNCTION__); + return HDF_FAILURE; + } + + prvPwm = (struct PwmDevice *)PwmGetPriv(pwm); + if (prvPwm == NULL) { + return HDF_FAILURE; + } + resource = &prvPwm->resource; + if (resource == NULL) { + return HDF_FAILURE; + } + pwmCfg = &prvPwm->stPwmCfg; + if (pwmCfg == NULL) { + return HDF_FAILURE; + } + pwmId = prvPwm->resource.pwmTim; + pwmCh = prvPwm->resource.pwmCh; + + if (config->status == PWM_ENABLE_STATUS) { + PwmFreqArg arg = {0}; + arg.pwmCh = pwmCh; + arg.pwmTim = pwmId; + if (InitPwmFreqAndPeriod(config, &arg, resource) != HDF_SUCCESS) { + HDF_LOGE("calculate freq and period failed!\r\n"); + return HDF_FAILURE; + } + + InitPwmClock(pwmId); + InitTimPwm(&arg, config, pwmCfg, resource); + } else { + DeInitTimPwm(pwmId, pwmCh); + } + + return HDF_SUCCESS; +} + +static int32_t PwmDevOpen(struct PwmDev *pwm) +{ + if (pwm == NULL) { + HDF_LOGE("%s\r\n", __FUNCTION__); + return HDF_ERR_INVALID_PARAM; + } + + return HDF_SUCCESS; +} + +static int32_t PwmDevClose(struct PwmDev *pwm) +{ + PwmDevice *prvPwm = NULL; + PWM_TIM pwmId; + PWM_CH pwmCh; + if (pwm == NULL) { + HDF_LOGE("%s\r\n", __FUNCTION__); + return HDF_ERR_INVALID_PARAM; + } + prvPwm = (PwmDevice *)PwmGetPriv(pwm); + if (prvPwm == NULL) { + HDF_LOGE("%s\r\n", __FUNCTION__); + return HDF_DEV_ERR_NO_DEVICE; + } + + pwmId = prvPwm->resource.pwmTim; + pwmCh = prvPwm->resource.pwmCh; + LL_TIM_DeInit(g_stTimMap[pwmId]); + LL_TIM_OC_DisableClear(g_stTimMap[pwmId], g_stChannelMap[pwmCh]); + NVIC_DisableIRQ(g_stTimIrqMap[pwmId]); + + return HDF_SUCCESS; +} \ No newline at end of file diff --git a/platform/spi/BUILD.gn b/platform/spi/BUILD.gn index f2bb81d..27ea450 100644 --- a/platform/spi/BUILD.gn +++ b/platform/spi/BUILD.gn @@ -19,10 +19,17 @@ hdf_driver(module_name) { if (defined(LOSCFG_SOC_COMPANY_WINNERMICRO)) { sources += [ "spi_wm.c" ] } + if (defined(LOSCFG_SOC_SERIES_STM32F4xx)) { + sources += [ "spi_stm32f4xx.c" ] + } include_dirs = [ "." ] if (defined(LOSCFG_SHIELD_V200ZR_EVB_T1) && defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { deps = [ "//device/board/fnlink/shields" ] } + if (defined(LOSCFG_NIOBE407_USE_HDF) && + defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { + deps = [ "//device/board/talkweb/niobe407/liteos_m/hdf_config" ] + } } diff --git a/platform/spi/spi_stm32f4xx.c b/platform/spi/spi_stm32f4xx.c new file mode 100644 index 0000000..82611ba --- /dev/null +++ b/platform/spi/spi_stm32f4xx.c @@ -0,0 +1,765 @@ +/* + * Copyright (c) 2022 Talkweb Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include +#include +#include "hal_gpio.h" +#include "hal_spi.h" +#include "osal_mutex.h" +#include "osal_sem.h" +#include "spi_core.h" +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO +#include "hcs_macro.h" +#include "hdf_config_macro.h" +#else +#include "device_resource_if.h" +#include "hdf_log.h" +#endif +#include "hdf_base_hal.h" + +#define BITWORD_EIGHT 8 +#define BITWORD_SIXTEEN 16 +#define GPIO_STR_MAX 32 +#define PER_MS_IN_SEC 1000 +typedef enum { + SPI_WORK_MODE_0, // CPOL = 0; CPHA = 0 + SPI_WORK_MODE_2, // CPOL = 1; CPHA = 0 + SPI_WORK_MODE_1, // CPOL = 0; CPHA = 1 + SPI_WORK_MODE_3, // CPOL = 1; CPHA = 1 + SPI_WORD_MODE_MAX, +} SPI_CLK_MODE; + +typedef enum { + SPI_TRANSFER_DMA, + SPI_TRANSFER_NORMAL, + SPI_TRANSFER_MAX, +} SPI_TRANS_MODE; + +typedef enum { + FULL_DUPLEX = 0, + SIMPLE_RX, + HALF_RX, + HALF_TX, + SPI_TRANS_DIR_MAX, +} SPI_TRANS_DIR; + +typedef enum { + SPI_SLAVE_MODE = 0, + SPI_MASTER_MODE, + SPI_MASTER_SLAVE_MAX, +} SPI_SLAVE_MASTER; + +typedef enum { + SPI_DATA_WIDTH_8 = 0, + SPI_DATA_WIDTH_16, + SPI_DATA_WIDTH_MAX, +} SPI_DATA_WIDTH; + +typedef enum { + SPI_NSS_SOFT_MODE = 0, + SPI_NSS_HARD_INPUT_MODE, + SPI_NSS_HARD_OUTPUT_MODE, + SPI_NSS_MODE_MAX, +} SPI_NSS; + +typedef enum { + BAUD_RATE_DIV2 = 0, + BAUD_RATE_DIV4, + BAUD_RATE_DIV8, + BAUD_RATE_DIV16, + BAUD_RATE_DIV32, + BAUD_RATE_DIV64, + BAUD_RATE_DIV128, + BAUD_RATE_DIV256, + BAUD_RATE_DIV_MAX, +} SPI_BAUD_RATE; + +typedef enum { + SPI_MSB_FIRST = 0, + SPI_LSB_FIRST, + SPI_MLSB_MAX, +} SPI_BYTE_ORDER; + +typedef enum { + CRC_DISABLE = 0, + CRC_ENABLE, + CRC_STATE_MAX, +} CRC_CALULATION; + +typedef enum { + SPI_PORT1 = 1, + SPI_PORT2, + SPI_PORT3, +} SPI_GROUPS; + +typedef enum { + SPI_PROTO_MOTOROLA = 0, + SPI_PROTO_TI, + SPI_PROTO_MAX, +} SPI_PROTO_STANDARD; + +typedef struct { + uint8_t busNum; + uint8_t csNum; + SPI_TRANS_DIR transDir; + SPI_TRANS_MODE transMode; + + SPI_SLAVE_MASTER smMode; + SPI_CLK_MODE clkMode; + SPI_DATA_WIDTH dataWidth; + SPI_NSS nss; + + SPI_BAUD_RATE baudRate; + SPI_BYTE_ORDER bitOrder; + CRC_CALULATION crcEnable; + SPI_GROUPS spix; + + STM32_GPIO_PIN csPin; + STM32_GPIO_GROUP csGroup; + SPI_PROTO_STANDARD standard; + uint8_t dummyByte; + + uint16_t crcPoly; +} SpiResource; + +#define HCS_UINT8_PARSE_NUM 16 +static const char *g_parseHcsMap[HCS_UINT8_PARSE_NUM] = { + "busNum", + "csNum", + "transDir", + "transMode", + "smMode", + "clkMode", + "dataWidth", + "nss", + "baudRate", + "bitOrder", + "crcEnable", + "spix", + "csPin", + "csGpiox", + "standard", + "dummyByte", +}; + +typedef struct { + struct OsalSem* sem; + struct OsalMutex* mutex; + SPI_TypeDef* spix; +} SPI_CONTEXT_T; + +typedef struct { + uint32_t spiId; + SpiResource resource; +} SpiDevice; + +static uint32_t g_transDirMaps[SPI_TRANS_DIR_MAX] = { + LL_SPI_FULL_DUPLEX, + LL_SPI_SIMPLEX_RX, + LL_SPI_HALF_DUPLEX_RX, + LL_SPI_HALF_DUPLEX_TX, +}; + +static uint32_t g_nssMaps[SPI_NSS_MODE_MAX] = { + LL_SPI_NSS_SOFT, + LL_SPI_NSS_HARD_INPUT, + LL_SPI_NSS_HARD_OUTPUT, +}; + +static uint32_t g_baudMaps[BAUD_RATE_DIV_MAX] = { + LL_SPI_BAUDRATEPRESCALER_DIV2, + LL_SPI_BAUDRATEPRESCALER_DIV4, + LL_SPI_BAUDRATEPRESCALER_DIV8, + LL_SPI_BAUDRATEPRESCALER_DIV16, + LL_SPI_BAUDRATEPRESCALER_DIV32, + LL_SPI_BAUDRATEPRESCALER_DIV64, + LL_SPI_BAUDRATEPRESCALER_DIV128, + LL_SPI_BAUDRATEPRESCALER_DIV256, +}; + +static SPI_TypeDef* g_spiGroupMaps[SPI_PORT3] = { + SPI1, + SPI2, + SPI3, +}; + +static void EnableSpiClock(uint32_t spiNum) +{ + switch (spiNum) { + case SPI_PORT1: + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1); + break; + case SPI_PORT2: + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI2); + break; + case SPI_PORT3: + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI3); + break; + default: + break; + } +} + +static SPI_CONTEXT_T spiContext[SPI_PORT3] = { + { + .sem = {NULL}, + .mutex = {NULL}, + .spix = {NULL}, + }, + { + .sem = {NULL}, + .mutex = {NULL}, + .spix = {NULL}, + }, + { + .sem = {NULL}, + .mutex = {NULL}, + .spix = {NULL}, + }, +}; + +int32_t HalSpiSend(SpiDevice *spiDevice, const uint8_t *data, uint16_t size) +{ + uint32_t spiId; + SpiResource *resource = NULL; + + if (spiDevice == NULL || data == NULL || size == 0) { + HDF_LOGE("spi input para err\r\n"); + return HDF_ERR_INVALID_PARAM; + } + + spiId = spiDevice->spiId; + resource = &spiDevice->resource; + if (resource == NULL) { + HDF_LOGE("resource is null\r\n"); + return HDF_ERR_INVALID_OBJECT; + } + + if (resource->transMode == SPI_TRANSFER_DMA) { + return HDF_ERR_INVALID_PARAM; // unsupport now + } else { + uint8_t readData; + while (size--) { + readData = LL_SPI_Transmit(spiContext[spiId].spix, *data); + data++; + } + } + + return HDF_SUCCESS; +} + +int32_t HalSpiRecv(SpiDevice *spiDevice, uint8_t *data, uint16_t size) +{ + uint32_t len = size; + uint32_t remainder = 0; + uint8_t *cmd = NULL; + uint32_t spiId; + SpiResource *resource = NULL; + if (spiDevice == NULL || data == NULL || size == 0) { + HDF_LOGE("spi input para err\r\n"); + return HDF_ERR_INVALID_PARAM; + } + + spiId = spiDevice->spiId; + resource = &spiDevice->resource; + if (resource == NULL) { + HDF_LOGE("resource is null\r\n"); + return HDF_ERR_INVALID_OBJECT; + } + cmd = (uint8_t *)OsalMemAlloc(len); + if (cmd == NULL) { + HDF_LOGE("%s OsalMemAlloc size %ld error\r\n", __FUNCTION__, len); + return HDF_ERR_MALLOC_FAIL; + } + + memset_s(cmd, len, resource->dummyByte, len); + + if (resource->transMode == SPI_TRANSFER_DMA) { + return HDF_ERR_INVALID_PARAM; // unsupport now + } else { + while (len--) { + *data = LL_SPI_Transmit(spiContext[spiId].spix, *cmd); + data++; + cmd++; + } + } + + OsalMemFree(cmd); + return HDF_SUCCESS; +} + +int32_t HalSpiSendRecv(SpiDevice *spiDevice, uint8_t *txData, + uint16_t txSize, uint8_t *rxData, uint16_t rxSize) +{ + uint32_t spiId; + uint8_t* data = rxData; + int16_t dropSize = 0; + SpiResource *resource = NULL; + if (spiDevice == NULL || txData == NULL || txSize == 0 || rxData == NULL || rxSize == 0) { + HDF_LOGE("spi input para err\r\n"); + return HDF_ERR_INVALID_PARAM; + } + spiId = spiDevice->spiId; + resource = &spiDevice->resource; + + if (resource->transMode == SPI_TRANSFER_DMA) { + return HDF_ERR_INVALID_PARAM; // unsupport now + } else { + while (rxSize--) { + *rxData = LL_SPI_Transmit(spiContext[spiId].spix, *txData); + rxData++; + txData++; + } + } + + return HDF_SUCCESS; +} + +static void InitSpiInitStruct(LL_SPI_InitTypeDef *spiInitStruct, const SpiResource *resource) +{ + spiInitStruct->TransferDirection = g_transDirMaps[resource->transDir]; + if (resource->smMode == SPI_SLAVE_MODE) { + spiInitStruct->Mode = LL_SPI_MODE_SLAVE; + } else { + spiInitStruct->Mode = LL_SPI_MODE_MASTER; + } + + if (resource->dataWidth == SPI_DATA_WIDTH_8) { + spiInitStruct->DataWidth = LL_SPI_DATAWIDTH_8BIT; + } else { + spiInitStruct->DataWidth = LL_SPI_DATAWIDTH_16BIT; + } + + switch (resource->clkMode) { + case SPI_WORK_MODE_0: + spiInitStruct->ClockPolarity = LL_SPI_POLARITY_LOW; + spiInitStruct->ClockPhase = LL_SPI_PHASE_1EDGE; + break; + case SPI_WORK_MODE_1: + spiInitStruct->ClockPolarity = LL_SPI_POLARITY_HIGH; + spiInitStruct->ClockPhase = LL_SPI_PHASE_1EDGE; + break; + case SPI_WORK_MODE_2: + spiInitStruct->ClockPolarity = LL_SPI_POLARITY_LOW; + spiInitStruct->ClockPhase = LL_SPI_PHASE_2EDGE; + break; + case SPI_WORK_MODE_3: + spiInitStruct->ClockPolarity = LL_SPI_POLARITY_HIGH; + spiInitStruct->ClockPhase = LL_SPI_PHASE_2EDGE; + break; + default: + spiInitStruct->ClockPolarity = LL_SPI_POLARITY_LOW; + spiInitStruct->ClockPhase = LL_SPI_PHASE_1EDGE; + } + + spiInitStruct->NSS = g_nssMaps[resource->nss]; + spiInitStruct->BaudRate = g_baudMaps[resource->baudRate]; + + if (resource->bitOrder == SPI_MSB_FIRST) { + spiInitStruct->BitOrder = LL_SPI_MSB_FIRST; + } else { + spiInitStruct->BitOrder = LL_SPI_LSB_FIRST; + } + + if (resource->crcEnable == CRC_DISABLE) { + spiInitStruct->CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; + } else { + spiInitStruct->CRCCalculation = LL_SPI_CRCCALCULATION_ENABLE; + } + spiInitStruct->CRCPoly = resource->crcPoly; + + return; +} + +static int32_t InitSpiDevice(SpiDevice *spiDevice) +{ + uint32_t spiPort; + SpiResource *resource = NULL; + if (spiDevice == NULL) { + HDF_LOGE("%s: invalid parameter\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + LL_SPI_InitTypeDef spiInitStruct = {0}; + resource = &spiDevice->resource; + spiPort = spiDevice->spiId; + EnableSpiClock(spiPort + 1); + InitSpiInitStruct(&spiInitStruct, resource); + SPI_TypeDef* spix = g_spiGroupMaps[resource->spix]; + + spiContext[spiPort].spix = spix; + LL_SPI_Disable(spix); + uint8_t ret = LL_SPI_Init(spix, &spiInitStruct); + if (ret != 0) { + HDF_LOGE("HAL INIT SPI FAILED\r\n"); + return HDF_FAILURE; + } + if (resource->standard == SPI_PROTO_MOTOROLA) { + LL_SPI_SetStandard(spix, LL_SPI_PROTOCOL_MOTOROLA); + } else { + LL_SPI_SetStandard(spix, LL_SPI_PROTOCOL_TI); + } + + return HDF_SUCCESS; +} + +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO +#define SPI_FIND_CONFIG(node, name, resource, spiDevice) \ + do { \ + if (strcmp(HCS_PROP(node, match_attr), name) == 0) { \ + resource->busNum = HCS_PROP(node, busNum); \ + spiDevice->spiId = resource->busNum; \ + resource->csNum = HCS_PROP(node, csNum); \ + resource->transDir = HCS_PROP(node, transDir); \ + resource->transMode = HCS_PROP(node, transMode); \ + resource->smMode = HCS_PROP(node, smMode); \ + resource->dataWidth = HCS_PROP(node, dataWidth); \ + resource->clkMode = HCS_PROP(node, clkMode); \ + resource->csNum = HCS_PROP(node, csNum); \ + resource->nss = HCS_PROP(node, nss); \ + resource->baudRate = HCS_PROP(node, baudRate); \ + resource->bitOrder = HCS_PROP(node, bitOrder); \ + resource->crcEnable = HCS_PROP(node, crcEnable); \ + resource->crcPoly = HCS_PROP(node, crcPoly); \ + resource->spix = HCS_PROP(node, spix); \ + resource->csPin = HCS_PROP(node, csPin); \ + resource->csGroup = HCS_PROP(node, csGpiox); \ + resource->standard = HCS_PROP(node, standard); \ + resource->dummyByte = HCS_PROP(node, dummyByte); \ + result = HDF_SUCCESS; \ + } \ + } while (0) + +#define PLATFORM_CONFIG HCS_NODE(HCS_ROOT, platform) +#define PLATFORM_SPI_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), spi_config) +static int32_t GetSpiDeviceResource(SpiDevice *spiDevice, const char *deviceMatchAttr) +{ + int32_t result = HDF_FAILURE; + SpiResource *resource = NULL; + if (spiDevice == NULL || deviceMatchAttr == NULL) { + HDF_LOGE("device or deviceMatchAttr is NULL\r\n"); + return HDF_ERR_INVALID_PARAM; + } + resource = &spiDevice->resource; +#if HCS_NODE_HAS_PROP(PLATFORM_CONFIG, spi_config) + HCS_FOREACH_CHILD_VARGS(PLATFORM_SPI_CONFIG, SPI_FIND_CONFIG, deviceMatchAttr, resource, spiDevice); +#endif + if (result != HDF_SUCCESS) { + HDF_LOGE("resourceNode %s is NULL\r\n", deviceMatchAttr); + } + return result; +} +#else +static int32_t GetSpiDeviceResource(SpiDevice *spiDevice, const struct DeviceResourceNode *resourceNode) +{ + struct DeviceResourceIface *dri = NULL; + if (spiDevice == NULL || resourceNode == NULL) { + HDF_LOGE("%s: PARAM is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + SpiResource *resource = NULL; + resource = &spiDevice->resource; + if (resource == NULL) { + HDF_LOGE("%s: resource is NULL\r\n", __func__); + return HDF_ERR_INVALID_OBJECT; + } + dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); // open HDF + if (dri == NULL || dri->GetUint16 == NULL || dri->GetUint8 == NULL || dri->GetUint32 == NULL) { + HDF_LOGE("DeviceResourceIface is invalid\r\n"); + return HDF_ERR_INVALID_PARAM; + } + uint8_t temp[HCS_UINT8_PARSE_NUM] = {0}; + for (int i = 0; i < HCS_UINT8_PARSE_NUM; i++) { + if (dri->GetUint8(resourceNode, g_parseHcsMap[i], &temp[i], 0) != HDF_SUCCESS) { + HDF_LOGE("get config %s failed\r\n", g_parseHcsMap[i]); + return HDF_FAILURE; + } + } + int ret = memcpy_s(resource, HCS_UINT8_PARSE_NUM, temp, HCS_UINT8_PARSE_NUM); + if (ret != 0) { + HDF_LOGE("memcpy failed\r\n"); + return HDF_FAILURE; + } + if (dri->GetUint16(resourceNode, "crcPoly", &resource->crcPoly, 0) != HDF_SUCCESS) { + HDF_LOGE("get config %s failed\r\n", "crcPoly"); + return HDF_FAILURE; + } + spiDevice->spiId = resource->busNum; + + return HDF_SUCCESS; +} +#endif + +int32_t AttachSpiDevice(struct SpiCntlr *spiCntlr, struct HdfDeviceObject *device) +{ + int32_t ret; + SpiDevice *spiDevice = NULL; + +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO + if (spiCntlr == NULL || device == NULL) { +#else + if (spiCntlr == NULL || device == NULL || device->property == NULL) { +#endif + HDF_LOGE("%s: property is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + spiDevice = (SpiDevice *)OsalMemAlloc(sizeof(SpiDevice)); + if (spiDevice == NULL) { + HDF_LOGE("%s: OsalMemAlloc spiDevice error\r\n", __func__); + return HDF_ERR_MALLOC_FAIL; + } + +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO + ret = GetSpiDeviceResource(spiDevice, device->deviceMatchAttr); +#else + ret = GetSpiDeviceResource(spiDevice, device->property); +#endif + if (ret != HDF_SUCCESS) { + (void)OsalMemFree(spiDevice); + return HDF_FAILURE; + } + + spiCntlr->priv = spiDevice; + spiCntlr->busNum = spiDevice->spiId; + InitSpiDevice(spiDevice); + + return HDF_SUCCESS; +} +/* SPI Method */ +static int32_t SpiDevGetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg); +static int32_t SpiDevSetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg); +static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg, uint32_t count); +static int32_t SpiDevOpen(struct SpiCntlr *spiCntlr); +static int32_t SpiDevClose(struct SpiCntlr *spiCntlr); + +struct SpiCntlrMethod g_twSpiCntlrMethod = { + .GetCfg = SpiDevGetCfg, + .SetCfg = SpiDevSetCfg, + .Transfer = SpiDevTransfer, + .Open = SpiDevOpen, + .Close = SpiDevClose, +}; + +/* HdfDriverEntry method definitions */ +static int32_t SpiDriverBind(struct HdfDeviceObject *device); +static int32_t SpiDriverInit(struct HdfDeviceObject *device); +static void SpiDriverRelease(struct HdfDeviceObject *device); + +/* HdfDriverEntry definitions */ +struct HdfDriverEntry g_SpiDriverEntry = { + .moduleVersion = 1, + .moduleName = "ST_SPI_MODULE_HDF", + .Bind = SpiDriverBind, + .Init = SpiDriverInit, + .Release = SpiDriverRelease, +}; + +HDF_INIT(g_SpiDriverEntry); + +static int32_t SpiDriverBind(struct HdfDeviceObject *device) +{ + struct SpiCntlr *spiCntlr = NULL; + if (device == NULL) { + HDF_LOGE("Sample device object is null!\r\n"); + return HDF_ERR_INVALID_PARAM; + } + HDF_LOGI("Enter %s:\r\n", __func__); + spiCntlr = SpiCntlrCreate(device); + if (spiCntlr == NULL) { + HDF_LOGE("SpiCntlrCreate object is null!\r\n"); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +static int32_t SpiDriverInit(struct HdfDeviceObject *device) +{ + int32_t ret; + struct SpiCntlr *spiCntlr = NULL; + + if (device == NULL) { + HDF_LOGE("%s: device is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + HDF_LOGI("Enter %s:", __func__); + spiCntlr = SpiCntlrFromDevice(device); + if (spiCntlr == NULL) { + HDF_LOGE("%s: spiCntlr is NULL", __func__); + return HDF_DEV_ERR_NO_DEVICE; + } + + ret = AttachSpiDevice(spiCntlr, device); // SpiCntlr add TWSpiDevice to priv + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: attach error\r\n", __func__); + return HDF_DEV_ERR_ATTACHDEV_FAIL; + } + + spiCntlr->method = &g_twSpiCntlrMethod; // register callback + + return ret; +} + +static void SpiDriverRelease(struct HdfDeviceObject *device) +{ + struct SpiCntlr *spiCntlr = NULL; + SpiDevice *spiDevice = NULL; + + HDF_LOGI("Enter %s\r\n", __func__); + + if (device == NULL) { + HDF_LOGE("%s: device is NULL\r\n", __func__); + return; + } + + spiCntlr = SpiCntlrFromDevice(device); + if (spiCntlr == NULL || spiCntlr->priv == NULL) { + HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__); + return; + } + + spiDevice = (SpiDevice *)spiCntlr->priv; + OsalMemFree(spiDevice); + + return; +} + +static int32_t SpiDevOpen(struct SpiCntlr *spiCntlr) +{ + HDF_LOGI("Enter %s\r\n", __func__); + uint32_t spiPort; + SpiDevice *spiDevice = NULL; + + spiDevice = (SpiDevice*)spiCntlr->priv; + spiPort = spiDevice->spiId; + SPI_TypeDef* spix = g_spiGroupMaps[spiDevice->resource.spix]; + LL_SPI_Enable(spix); + + return HDF_SUCCESS; +} + +static int32_t SpiDevClose(struct SpiCntlr *spiCntlr) +{ + uint32_t spiPort; + SpiDevice *spiDevice = NULL; + + spiDevice = (SpiDevice*)spiCntlr->priv; + spiPort = spiDevice->spiId; + SPI_TypeDef* spix = g_spiGroupMaps[spiDevice->resource.spix]; + LL_SPI_Disable(spix); + + return HDF_SUCCESS; +} + +static int32_t SpiDevGetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg) +{ + SpiDevice *spiDevice = NULL; + if (spiCntlr == NULL || spiCfg == NULL || spiCntlr->priv == NULL) { + HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + spiDevice = (SpiDevice *)spiCntlr->priv; + if (spiDevice == NULL) { + return HDF_DEV_ERR_NO_DEVICE; + } + spiCfg->maxSpeedHz = spiDevice->resource.baudRate; + spiCfg->mode = spiDevice->resource.clkMode; + spiCfg->transferMode = spiDevice->resource.transMode; + spiCfg->bitsPerWord = spiDevice->resource.dataWidth; + + if (spiDevice->resource.dataWidth) { + spiCfg->bitsPerWord = BITWORD_SIXTEEN; + } else { + spiCfg->bitsPerWord = BITWORD_EIGHT; + } + + return HDF_SUCCESS; +} +static int32_t SpiDevSetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg) +{ + SpiDevice *spiDevice = NULL; + if (spiCntlr == NULL || spiCfg == NULL || spiCntlr->priv == NULL) { + HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + spiDevice = (SpiDevice *)spiCntlr->priv; + if (spiDevice == NULL) { + HDF_LOGE("%s: spiDevice is NULL\r\n", __func__); + return HDF_DEV_ERR_NO_DEVICE; + } + + spiDevice->resource.baudRate = spiCfg->maxSpeedHz; + spiDevice->resource.clkMode = spiCfg->mode; + spiDevice->resource.transMode = spiCfg->transferMode; + if (spiCfg->bitsPerWord == BITWORD_EIGHT) { + spiDevice->resource.dataWidth = SPI_DATA_WIDTH_8; + } else { + spiDevice->resource.dataWidth = SPI_DATA_WIDTH_16; + } + + return InitSpiDevice(spiDevice); +} + +static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg, uint32_t count) +{ + uint32_t spiId; + SpiDevice *spiDevice = NULL; + uint32_t ticks = 0; + uint8_t singleCsChange = 0; + struct SpiMsg *msg = NULL; + if (spiCntlr == NULL || spiCntlr->priv == NULL) { + HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__); + return HDF_ERR_INVALID_PARAM; + } + + spiDevice = (SpiDevice *)spiCntlr->priv; + spiId = spiDevice->spiId; + for (size_t i = 0; i < count; i++) { + msg = &spiMsg[i]; + LL_GPIO_ResetOutputPin(LL_GET_GPIOX(spiDevice->resource.csGroup), LL_GET_HAL_PIN(spiDevice->resource.csPin)); + + if ((msg->rbuf == NULL) && (msg->wbuf != NULL)) { + singleCsChange = msg->wbuf[0]; + + if (msg->len == 1) { + goto CS_DOWN; + } + HalSpiSend(spiDevice, msg->wbuf + 1, msg->len - 1); + } + + if ((msg->rbuf != NULL) && (msg->wbuf == NULL)) { + singleCsChange = msg->rbuf[0]; + + if (msg->len == 1) { + goto CS_DOWN; + } + HalSpiRecv(spiDevice, msg->rbuf + 1, msg->len - 1); + } + + if ((msg->wbuf != NULL) && (msg->rbuf != NULL)) { + HalSpiSendRecv(spiDevice, msg->wbuf, msg->len, msg->rbuf, msg->len); + } + + if (msg->csChange || singleCsChange) { + LL_GPIO_SetOutputPin(LL_GET_GPIOX(spiDevice->resource.csGroup), LL_GET_HAL_PIN(spiDevice->resource.csPin)); + } + if (msg->delayUs > 0) { + ticks = (msg->delayUs / PER_MS_IN_SEC); + osDelay(ticks); + } + } + return HDF_SUCCESS; +CS_DOWN: + if (msg->csChange || singleCsChange) { + LL_GPIO_SetOutputPin(LL_GET_GPIOX(spiDevice->resource.csGroup), LL_GET_HAL_PIN(spiDevice->resource.csPin)); + } + return HDF_SUCCESS; +} + diff --git a/platform/uart/BUILD.gn b/platform/uart/BUILD.gn index f1c1a1e..b1f26ec 100644 --- a/platform/uart/BUILD.gn +++ b/platform/uart/BUILD.gn @@ -25,10 +25,17 @@ hdf_driver(module_name) { if (defined(LOSCFG_SOC_COMPANY_WINNERMICRO)) { sources += [ "uart_wm.c" ] } + if (defined(LOSCFG_SOC_SERIES_STM32F4xx)) { + sources += [ "uart_stm32f4xx.c" ] + } include_dirs = [ "." ] if (defined(LOSCFG_SHIELD_V200ZR_EVB_T1) && defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { deps = [ "//device/board/fnlink/shields" ] } + if (defined(LOSCFG_NIOBE407_USE_HDF) && + defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { + deps = [ "//device/board/talkweb/niobe407/liteos_m/hdf_config" ] + } } diff --git a/platform/uart/uart_stm32f4xx.c b/platform/uart/uart_stm32f4xx.c new file mode 100644 index 0000000..e25dbe5 --- /dev/null +++ b/platform/uart/uart_stm32f4xx.c @@ -0,0 +1,1093 @@ +/* + * Copyright (c) 2022 Talkweb Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include +#include +#include "hal_gpio.h" +#include "uart_if.h" +#include "stm32f4xx_ll_bus.h" +#include "uart_core.h" +#include "hal_usart.h" +#include "osal_sem.h" +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO +#include "hcs_macro.h" +#include "hdf_config_macro.h" +#else +#include "device_resource_if.h" +#endif +#include "hdf_log.h" + +#define HDF_UART_TMO 1000 +#define HDF_LOG_TAG uartDev +#define GPIO_MAX_LENGTH 32 +#define UART_FIFO_MAX_BUFFER 2048 +#define UART_DMA_RING_BUFFER_SIZE 256 // mast be 2^n + +#define UART_IRQ_PRO 5 +#define UART_DEV_SERVICE_NAME_PREFIX "HDF_PLATFORM_UART%d" +#define MAX_DEV_NAME_SIZE 32 +typedef enum { + USART_NUM_1 = 1, + USART_NUM_2, + USART_NUM_3, + USART_NUM_4, + USART_NUM_5, + USART_NUM_6, +} USART_NUM; + +typedef enum { + USART_DATAWIDTH_8 = 0, + USART_DATAWIDTH_9, + USART_DATAWIDTH_MAX, +} USART_DATAWIDTH; + +typedef enum { + USART_STOP_BIT_0_5 = 0, + USART_STOP_BIT_1, + USART_STOP_BIT_1_5, + USART_STOP_BIT_2, + USART_STOP_BIT_MAX, +} USART_STOP_BIT; + +typedef enum { + USART_PARITY_CHECK_NONE = 0, + USART_PARITY_CHECK_EVENT, + USART_PARITY_CHECK_ODD, + USART_PARITY_CHECK_MAX, +} USART_PARITY_CHECK; + +typedef enum { + USART_TRANS_DIR_NONE = 0, + USART_TRANS_DIR_RX, + USART_TRANS_DIR_TX, + USART_TRANS_DIR_RX_TX, + USART_TRANS_DIR_MAX, +} USART_TRANS_DIR; + +typedef enum { + USART_FLOW_CTRL_NONE = 0, + USART_FLOW_CTRL_RTS, + USART_FLOW_CTRL_CTS, + USART_FLOW_CTRL_RTS_CTS, + USART_FLOW_CTRL_MAX, +} USART_FLOW_CTRL; + +typedef enum { + USART_OVER_SIMPLING_16 = 0, + USART_OVER_SIMPLING_8, + USART_OVER_SIMPLING_MAX, +} USART_OVER_SIMPLING; + +typedef enum { + USART_TRANS_BLOCK = 0, // block + USART_TRANS_NOBLOCK, + USART_TRANS_TX_DMA, // TX DMA RX NORMAL + USART_TRANS_RX_DMA, // TX NORMAL RX DMA + USART_TRANS_TX_RX_DMA, // TX DMA RX DMA + USART_TRANS_MODE_MAX, +} USART_TRANS_MODE; + +typedef enum { + USART_IDLE_IRQ_DISABLE = 0, + USART_IDLE_IRQ_ENABLE, + USART_IDLE_IRQ_MAX, +} USART_IDLE_IRQ; + +typedef enum { + USART_232 = 0, + USART_485, + USART_TYPE_MAX, +} USART_TYPE; + +typedef struct { + USART_NUM num; + uint32_t baudRate; + USART_DATAWIDTH dataWidth; + USART_STOP_BIT stopBit; + USART_PARITY_CHECK parity; + USART_TRANS_DIR transDir; + USART_FLOW_CTRL flowCtrl; + USART_OVER_SIMPLING overSimpling; + USART_TRANS_MODE transMode; + USART_TYPE uartType; + STM32_GPIO_PIN dePin; + STM32_GPIO_GROUP deGroup; +} UartResource; + +typedef enum { + UART_DEVICE_UNINITIALIZED = 0x0u, + UART_DEVICE_INITIALIZED = 0x1u, +} UartDeviceState; + +typedef enum { + UART_ATTR_HDF_TO_NIOBE = 0, + UART_ATTR_NIOBE_TO_HDF, +} UART_ATTR_TRAN_TYPE; + +typedef void (*HWI_UART_IDLE_IRQ)(void); + +typedef struct { + bool txDMA; + bool rxDMA; + bool isBlock; + uint8_t dePin; + uint8_t deGroup; + uint8_t uartType; +} UsartContextObj; + +typedef struct { + struct IDeviceIoService ioService; + UartResource resource; + LL_USART_InitTypeDef initTypedef; + uint32_t uartId; + bool initFlag; + USART_TRANS_MODE transMode; +} UartDevice; + +static const uint32_t g_dataWidthMap[USART_DATAWIDTH_MAX] = { + LL_USART_DATAWIDTH_8B, + LL_USART_DATAWIDTH_9B, +}; + +static const uint32_t g_stopBitMap[USART_STOP_BIT_MAX] = { + LL_USART_STOPBITS_0_5, + LL_USART_STOPBITS_1, + LL_USART_STOPBITS_1_5, + LL_USART_STOPBITS_2, +}; + +static const uint32_t g_flowControlMap[USART_FLOW_CTRL_MAX] = { + LL_USART_HWCONTROL_NONE, + LL_USART_HWCONTROL_RTS, + LL_USART_HWCONTROL_CTS, + LL_USART_HWCONTROL_RTS_CTS, +}; + +static const uint32_t g_overSimplingMap[USART_OVER_SIMPLING_MAX] = { + LL_USART_OVERSAMPLING_16, + LL_USART_OVERSAMPLING_8, +}; + +static const uint32_t g_transDirMap[USART_TRANS_DIR_MAX] = { + LL_USART_DIRECTION_NONE, + LL_USART_DIRECTION_RX, + LL_USART_DIRECTION_TX, + LL_USART_DIRECTION_TX_RX, +}; + +static const uint32_t g_parityMap[USART_PARITY_CHECK_MAX] = { + LL_USART_PARITY_NONE, + LL_USART_PARITY_EVEN, + LL_USART_PARITY_ODD, +}; + +static const USART_TypeDef* g_usartRegMap[USART_NUM_6] = { + USART1, + USART2, + USART3, + UART4, + UART5, + USART6, +}; +static UsartContextObj g_uartCtx[USART_NUM_6] = {0}; + +static void USARTTxMode(STM32_GPIO_PIN gpioPin, STM32_GPIO_GROUP group) +{ + uint32_t pinReg = LL_GET_HAL_PIN(gpioPin); + GPIO_TypeDef* gpiox = NULL; + gpiox = LL_GET_GPIOX(group); + if (gpiox == NULL) { + return; + } + LL_GPIO_SetOutputPin(gpiox, pinReg); +} + +static void USARTRxMode(STM32_GPIO_PIN gpioPin, STM32_GPIO_GROUP group) +{ + uint32_t pinReg = LL_GET_HAL_PIN(gpioPin); + GPIO_TypeDef* gpiox = NULL; + gpiox = LL_GET_GPIOX(group); + if (gpiox == NULL) { + return; + } + LL_GPIO_ResetOutputPin(gpiox, pinReg); +} + +static const uint32_t g_exitIrqnMap[USART_NUM_6] = { + USART1_IRQn, + USART2_IRQn, + USART3_IRQn, + UART4_IRQn, + UART5_IRQn, + USART6_IRQn, +}; + +static void InitUsartClock(USART_NUM num) +{ + switch (num) { + case USART_NUM_1: + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1); + break; + case USART_NUM_2: + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART2); + break; + case USART_NUM_3: + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART3); + break; + case USART_NUM_4: + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_UART4); + break; + case USART_NUM_5: + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_UART5); + break; + case USART_NUM_6: + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART6); + break; + default: + break; + } +} + +static void InitContextTransMode(UsartContextObj* ctx, USART_TRANS_MODE mode) +{ + switch (mode) { + case USART_TRANS_BLOCK: + ctx->isBlock = true; + ctx->rxDMA = false; + ctx->txDMA = false; + break; + case USART_TRANS_NOBLOCK: + ctx->isBlock = false; + ctx->rxDMA = false; + ctx->txDMA = false; + break; + case USART_TRANS_TX_DMA: // TX DMA RX NORMAL + ctx->isBlock = false; + ctx->rxDMA = false; + ctx->txDMA = true; + break; + case USART_TRANS_RX_DMA: // TX NORMAL RX DMA + ctx->isBlock = false; + ctx->rxDMA = true; + ctx->txDMA = false; + break; + case USART_TRANS_TX_RX_DMA: // TX DMA RX DMA + ctx->isBlock = false; + ctx->rxDMA = true; + ctx->txDMA = true; + break; + default: + break; + } +} + +static int32_t UartDriverBind(struct HdfDeviceObject *device); +static int32_t UartDriverInit(struct HdfDeviceObject *device); +static void UartDriverRelease(struct HdfDeviceObject *device); + +struct HdfDriverEntry g_UartDriverEntry = { + .moduleVersion = 1, + .moduleName = "ST_UART_MODULE_HDF", + .Bind = UartDriverBind, + .Init = UartDriverInit, + .Release = UartDriverRelease, +}; +HDF_INIT(g_UartDriverEntry); + +static int32_t UartHostDevInit(struct UartHost *host); +static int32_t UartHostDevDeinit(struct UartHost *host); +static int32_t UartHostDevWrite(struct UartHost *host, uint8_t *data, uint32_t size); +static int32_t UartHostDevSetBaud(struct UartHost *host, uint32_t baudRate); +static int32_t UartHostDevGetBaud(struct UartHost *host, uint32_t *baudRate); +static int32_t UartHostDevRead(struct UartHost *host, uint8_t *data, uint32_t size); +static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribute *attribute); +static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribute *attribute); +static int32_t UartHostDevSetTransMode(struct UartHost *host, enum UartTransMode mode); + +struct UartHostMethod g_uartHostMethod = { + .Init = UartHostDevInit, + .Deinit = UartHostDevDeinit, + .Read = UartHostDevRead, + .Write = UartHostDevWrite, + .SetBaud = UartHostDevSetBaud, + .GetBaud = UartHostDevGetBaud, + .SetAttribute = UartHostDevSetAttribute, + .GetAttribute = UartHostDevGetAttribute, + .SetTransMode = UartHostDevSetTransMode, +}; + +static int InitUartDevice(struct UartHost *host) +{ + uint8_t initRet = 0; + UartDevice *uartDevice = NULL; + LL_USART_InitTypeDef *initTypedef = NULL; + UartResource *resource = NULL; + if (host == NULL || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + uartDevice = (UartDevice *)host->priv; + if (uartDevice == NULL) { + HDF_LOGE("%s: INVALID OBJECT", __func__); + return HDF_ERR_INVALID_OBJECT; + } + resource = &uartDevice->resource; + if (resource == NULL) { + HDF_LOGE("%s: INVALID OBJECT", __func__); + return HDF_ERR_INVALID_OBJECT; + } + initTypedef = &uartDevice->initTypedef; + if (initTypedef == NULL) { + HDF_LOGE("%s: INVALID OBJECT", __func__); + return HDF_ERR_INVALID_OBJECT; + } + InitContextTransMode(&g_uartCtx[uartDevice->uartId - 1], resource->transMode); + LL_USART_Disable(g_usartRegMap[uartDevice->uartId - 1]); + LL_USART_DeInit(g_usartRegMap[uartDevice->uartId - 1]); + InitUsartClock(uartDevice->uartId); + + if (!uartDevice->initFlag) { + initRet = LL_USART_Init(g_usartRegMap[uartDevice->uartId - 1], initTypedef); + if (initRet) { + HDF_LOGE("uart %ld device init failed\r\n", uartDevice->uartId); + return HDF_FAILURE; + } + LL_USART_ConfigAsyncMode(g_usartRegMap[uartDevice->uartId - 1]); + LL_USART_Enable(g_usartRegMap[uartDevice->uartId - 1]); + UART_IRQ_INIT(g_usartRegMap[uartDevice->uartId - 1], uartDevice->uartId, + g_exitIrqnMap[uartDevice->uartId - 1], g_uartCtx[uartDevice->uartId - 1].isBlock); + + uartDevice->initFlag = true; + } + + return HDF_SUCCESS; +} + +#ifndef LOSCFG_DRIVERS_HDF_CONFIG_MACRO +static int32_t GetUartHcs(struct DeviceResourceIface *dri, + const struct DeviceResourceNode *resourceNode, UartResource *resource) +{ + if (dri->GetUint8(resourceNode, "num", &resource->num, 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + if (dri->GetUint32(resourceNode, "baudRate", &resource->baudRate, 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + if (dri->GetUint8(resourceNode, "dataWidth", &resource->dataWidth, 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + if (dri->GetUint8(resourceNode, "stopBit", &resource->stopBit, 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + if (dri->GetUint8(resourceNode, "parity", &resource->parity, 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + if (dri->GetUint8(resourceNode, "transDir", &resource->transDir, 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + if (dri->GetUint8(resourceNode, "flowCtrl", &resource->flowCtrl, 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + if (dri->GetUint8(resourceNode, "overSimpling", &resource->overSimpling, 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + if (dri->GetUint8(resourceNode, "transMode", &resource->transMode, 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + if (dri->GetUint8(resourceNode, "uartType", &resource->uartType, 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + if (dri->GetUint8(resourceNode, "uartDePin", &resource->dePin, 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + if (dri->GetUint8(resourceNode, "uartDeGroup", &resource->deGroup, 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} +#endif + +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO +#define UART_FIND_CONFIG(node, name, resource) \ + do { \ + if (strcmp(HCS_PROP(node, match_attr), name) == 0) { \ + resource->num = HCS_PROP(node, num); \ + resource->baudRate = HCS_PROP(node, baudRate); \ + resource->dataWidth = HCS_PROP(node, dataWidth); \ + resource->stopBit = HCS_PROP(node, stopBit); \ + resource->parity = HCS_PROP(node, parity); \ + resource->transDir = HCS_PROP(node, transDir); \ + resource->flowCtrl = HCS_PROP(node, flowCtrl); \ + resource->overSimpling = HCS_PROP(node, overSimpling); \ + resource->transMode = HCS_PROP(node, transMode); \ + resource->uartType = HCS_PROP(node, uartType); \ + resource->dePin = HCS_PROP(node, uartDePin); \ + resource->deGroup = HCS_PROP(node, uartDeGroup); \ + result = HDF_SUCCESS; \ + } \ + } while (0) +#define PLATFORM_CONFIG HCS_NODE(HCS_ROOT, platform) +#define PLATFORM_UART_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), uart_config) +static uint32_t GetUartDeviceResource(UartDevice *device, const char *deviceMatchAttr) +{ + UartResource *resource = NULL; + int32_t result = HDF_FAILURE; + if (device == NULL || deviceMatchAttr == NULL) { + HDF_LOGE("device or deviceMatchAttr is NULL\r\n"); + return HDF_ERR_INVALID_PARAM; + } + resource = &device->resource; +#if HCS_NODE_HAS_PROP(PLATFORM_CONFIG, uart_config) + HCS_FOREACH_CHILD_VARGS(PLATFORM_UART_CONFIG, UART_FIND_CONFIG, deviceMatchAttr, resource); +#endif + if (result != HDF_SUCCESS) { + HDF_LOGE("resourceNode %s is NULL\r\n", deviceMatchAttr); + return result; + } + device->uartId = resource->num; + g_uartCtx[device->uartId - 1].dePin = resource->dePin; + g_uartCtx[device->uartId - 1].deGroup = resource->deGroup; + g_uartCtx[device->uartId - 1].uartType = resource->uartType; + device->initFlag = false; + device->initTypedef.BaudRate = resource->baudRate; + device->initTypedef.DataWidth = g_dataWidthMap[resource->dataWidth]; + device->initTypedef.HardwareFlowControl = g_flowControlMap[resource->flowCtrl]; + device->initTypedef.StopBits = g_stopBitMap[resource->stopBit]; + device->initTypedef.OverSampling = g_overSimplingMap[resource->overSimpling]; + device->initTypedef.TransferDirection = g_transDirMap[resource->transDir]; + device->initTypedef.Parity = g_parityMap[resource->parity]; + return HDF_SUCCESS; +} +#else +static int32_t GetUartDeviceResource(UartDevice *device, const struct DeviceResourceNode *resourceNode) +{ + struct DeviceResourceIface *dri = NULL; + UartResource *resource = NULL; + if (device == NULL || resourceNode == NULL) { + HDF_LOGE("%s: INVALID PARAM", __func__); + return HDF_ERR_INVALID_PARAM; + } + resource = &device->resource; + if (resource == NULL) { + HDF_LOGE("%s: INVALID OBJECT", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (dri == NULL || dri->GetUint32 == NULL || dri->GetUint8 == NULL) { + HDF_LOGE("DeviceResourceIface is invalid"); + return HDF_ERR_INVALID_PARAM; + } + + if (GetUartHcs(dri, resourceNode, resource) != HDF_SUCCESS) { + HDF_LOGE("Get uart hcs failed\n"); + return HDF_ERR_INVALID_PARAM; + } + + device->uartId = resource->num; + g_uartCtx[device->uartId - 1].dePin = resource->dePin; + g_uartCtx[device->uartId - 1].deGroup = resource->deGroup; + g_uartCtx[device->uartId - 1].uartType = resource->uartType; + device->initFlag = false; + device->initTypedef.BaudRate = resource->baudRate; + device->initTypedef.DataWidth = g_dataWidthMap[resource->dataWidth]; + device->initTypedef.HardwareFlowControl = g_flowControlMap[resource->flowCtrl]; + device->initTypedef.StopBits = g_stopBitMap[resource->stopBit]; + device->initTypedef.OverSampling = g_overSimplingMap[resource->overSimpling]; + device->initTypedef.TransferDirection = g_transDirMap[resource->transDir]; + device->initTypedef.Parity = g_parityMap[resource->parity]; + + return HDF_SUCCESS; +} +#endif + +static int32_t AttachUartDevice(struct UartHost *uartHost, struct HdfDeviceObject *device) +{ + int32_t ret; + UartDevice *uartDevice = NULL; + +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO + if (device == NULL || uartHost == NULL) { +#else + if (uartHost == NULL || device == NULL || device->property == NULL) { +#endif + HDF_LOGE("%s: property is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + + uartDevice = (UartDevice *)OsalMemAlloc(sizeof(UartDevice)); + if (uartDevice == NULL) { + HDF_LOGE("%s: OsalMemCalloc uartDevice error", __func__); + return HDF_ERR_MALLOC_FAIL; + } +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO + ret = GetUartDeviceResource(uartDevice, device->deviceMatchAttr); +#else + ret = GetUartDeviceResource(uartDevice, device->property); +#endif + if (ret != HDF_SUCCESS) { + (void)OsalMemFree(uartDevice); + return HDF_FAILURE; + } + + uartHost->priv = uartDevice; + + return HDF_SUCCESS; +} + +static int32_t UartDriverBind(struct HdfDeviceObject *device) +{ + struct UartHost *devService; + if (device == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return (UartHostCreate(device) == NULL) ? HDF_FAILURE : HDF_SUCCESS; +} + +static void UartDriverRelease(struct HdfDeviceObject *device) +{ + HDF_LOGI("Enter %s:", __func__); + uint32_t uartId; + struct UartHost *host = NULL; + UartDevice *uartDevice = NULL; + if (device == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return; + } + + host = UartHostFromDevice(device); + if (host == NULL || host->priv == NULL) { + HDF_LOGE("%s: host is NULL", __func__); + return; + } + + uartDevice = (UartDevice *)host->priv; + if (uartDevice == NULL) { + HDF_LOGE("%s: INVALID OBJECT", __func__); + return; + } + uartId = uartDevice->uartId; + host->method = NULL; + + OsalMemFree(uartDevice); +} + +static int32_t UartDriverInit(struct HdfDeviceObject *device) +{ + HDF_LOGI("Enter %s:", __func__); + int32_t ret; + struct UartHost *host = NULL; + + if (device == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + host = UartHostFromDevice(device); + if (host == NULL) { + HDF_LOGE("%s: host is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + ret = AttachUartDevice(host, device); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: attach error", __func__); + return HDF_FAILURE; + } + + host->method = &g_uartHostMethod; + + return ret; +} + +/* UartHostMethod implementations */ +static int32_t UartHostDevInit(struct UartHost *host) +{ + HDF_LOGI("%s: Enter\r\n", __func__); + if (host == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return InitUartDevice(host); +} + +static int32_t UartHostDevDeinit(struct UartHost *host) +{ + HDF_LOGI("%s: Enter", __func__); + uint32_t uartId; + UartDevice *uartDevice = NULL; + if (host == NULL || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + uartDevice = (UartDevice *)host->priv; + if (uartDevice == NULL) { + HDF_LOGE("%s: INVALID OBJECT", __func__); + return HDF_ERR_INVALID_OBJECT; + } + uartId = uartDevice->uartId; + uartDevice->initFlag = false; + UART_IRQ_DEINIT(g_usartRegMap[uartDevice->uartId - 1], g_exitIrqnMap[uartId -1]); + LL_USART_Disable(g_usartRegMap[uartDevice->uartId - 1]); + + return LL_USART_DeInit(g_usartRegMap[uartId - 1]); +} + +static int32_t UartHostDevWrite(struct UartHost *host, uint8_t *data, uint32_t size) +{ + UartDevice *device = NULL; + uint32_t portId; + + if (host == NULL || data == NULL || size == 0 || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + device = (UartDevice*)host->priv; + if (device == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + portId = device->uartId; + USART_TypeDef* usartx = g_usartRegMap[portId - 1]; + if (g_uartCtx[portId - 1].uartType == USART_485) { + USARTTxMode(g_uartCtx[portId - 1].dePin, g_uartCtx[portId - 1].deGroup); + } + if (g_uartCtx[portId - 1].txDMA) { + HDF_LOGE("unsupport dma now\n"); + return HDF_ERR_INVALID_PARAM; + } else { + USART_TxData(usartx, data, size); + } + if (g_uartCtx[portId - 1].uartType == USART_485) { + USARTRxMode(g_uartCtx[portId - 1].dePin, g_uartCtx[portId - 1].deGroup); + } + + return HDF_SUCCESS; +} + +static int32_t UartHostDevRead(struct UartHost *host, uint8_t *data, uint32_t size) +{ + uint32_t recvSize = 0; + int32_t ret; + uint32_t uartId; + UartDevice *uartDevice = NULL; + if (host == NULL || data == NULL || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + uartDevice = (UartDevice *)host->priv; + if (uartDevice == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + uartId = uartDevice->uartId; + USART_TypeDef* usartx = g_usartRegMap[uartId - 1]; + if (g_uartCtx[uartId - 1].uartType == USART_485) { + USARTRxMode(g_uartCtx[uartId - 1].dePin, g_uartCtx[uartId - 1].deGroup); + } + + if (g_uartCtx[uartId - 1].rxDMA) { + HDF_LOGE("unsupport dma now\n"); + return HDF_ERR_INVALID_PARAM; + } else { + ret = USART_RxData(uartId, data, size, g_uartCtx[uartId - 1].isBlock); + } + + return ret; +} + +static int32_t UartHostDevSetBaud(struct UartHost *host, uint32_t baudRate) +{ + HDF_LOGI("%s: Enter", __func__); + UartDevice *uartDevice = NULL; + LL_USART_InitTypeDef *uartInit = NULL; + + uint32_t uartId; + if (host == NULL || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + uartDevice = (UartDevice *)host->priv; + if (uartDevice == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + uartId = uartDevice->uartId; + + uartInit = &uartDevice->initTypedef; + if (uartInit == NULL) { + HDF_LOGE("%s: device config is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + uartInit->BaudRate = baudRate; + UartHostDevDeinit(host); + UartHostDevInit(host); + + return HDF_SUCCESS; +} + +static int32_t UartHostDevGetBaud(struct UartHost *host, uint32_t *baudRate) +{ + HDF_LOGI("%s: Enter", __func__); + UartDevice *uartDevice = NULL; + LL_USART_InitTypeDef *uartInit = NULL; + uint32_t uartId; + if (host == NULL || baudRate == NULL || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + uartDevice = (UartDevice *)host->priv; + if (uartDevice == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + uartId = uartDevice->uartId; + uartInit = &uartDevice->initTypedef; + if (uartInit == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + *baudRate = uartInit->BaudRate; + + return HDF_SUCCESS; +} +static void TransDataWidth(LL_USART_InitTypeDef *uartInit, struct UartAttribute *attribute, UART_ATTR_TRAN_TYPE type) +{ + if (uartInit == NULL || attribute == NULL) { + HDF_LOGE("null ptr\r\n"); + return; + } + + if (type == UART_ATTR_NIOBE_TO_HDF) { + switch (uartInit->DataWidth) { // only support 9bit and 8 bit in niobe407 + case LL_USART_DATAWIDTH_8B: + attribute->dataBits = UART_ATTR_DATABIT_8; + break; + default: + attribute->dataBits = UART_ATTR_DATABIT_8; + break; + } + } else { + switch (attribute->dataBits) { + case UART_ATTR_DATABIT_8: + uartInit->DataWidth = LL_USART_DATAWIDTH_8B; + break; + default: + uartInit->DataWidth = LL_USART_DATAWIDTH_8B; + break; + } + } + + return; +} + +static void TransParity(LL_USART_InitTypeDef *uartInit, struct UartAttribute *attribute, UART_ATTR_TRAN_TYPE type) +{ + if (uartInit == NULL || attribute == NULL) { + HDF_LOGE("null ptr\r\n"); + return; + } + + if (type == UART_ATTR_NIOBE_TO_HDF) { + switch (uartInit->Parity) { + case LL_USART_PARITY_NONE: + attribute->parity = UART_ATTR_PARITY_NONE; + break; + case LL_USART_PARITY_EVEN: + attribute->parity = UART_ATTR_PARITY_EVEN; + break; + case LL_USART_PARITY_ODD: + attribute->parity = UART_ATTR_PARITY_ODD; + break; + default: + attribute->parity = UART_ATTR_PARITY_NONE; + break; + } + } else { + switch (attribute->parity) { + case UART_ATTR_PARITY_NONE: + uartInit->Parity = LL_USART_PARITY_NONE; + break; + case UART_ATTR_PARITY_EVEN: + uartInit->Parity = LL_USART_PARITY_EVEN; + break; + case UART_ATTR_PARITY_ODD: + uartInit->Parity = LL_USART_PARITY_ODD; + break; + default: + uartInit->Parity = LL_USART_PARITY_NONE; + break; + } + } + + return; +} + +static void TransStopbit(LL_USART_InitTypeDef *uartInit, struct UartAttribute *attribute, UART_ATTR_TRAN_TYPE type) +{ + if (uartInit == NULL || attribute == NULL) { + HDF_LOGE("null ptr\r\n"); + return; + } + + if (type == UART_ATTR_NIOBE_TO_HDF) { + switch (uartInit->StopBits) { + case LL_USART_STOPBITS_1: + attribute->stopBits = UART_ATTR_STOPBIT_1; + break; + case LL_USART_STOPBITS_1_5: + attribute->stopBits = UART_ATTR_STOPBIT_1P5; + break; + case LL_USART_STOPBITS_2: + attribute->stopBits = UART_ATTR_STOPBIT_2; + break; + default: + attribute->stopBits = UART_ATTR_PARITY_NONE; + break; + } + } else { + switch (attribute->stopBits) { + case UART_ATTR_STOPBIT_1: + uartInit->StopBits = LL_USART_STOPBITS_1; + break; + case UART_ATTR_STOPBIT_1P5: + uartInit->StopBits = LL_USART_STOPBITS_1_5; + break; + case UART_ATTR_STOPBIT_2: + uartInit->StopBits = LL_USART_STOPBITS_2; + break; + default: + uartInit->StopBits = LL_USART_STOPBITS_1; + break; + } + } + + return; +} + +static void TransFlowCtrl(LL_USART_InitTypeDef *uartInit, struct UartAttribute *attribute, UART_ATTR_TRAN_TYPE type) +{ + if (uartInit == NULL || attribute == NULL) { + HDF_LOGE("null ptr\r\n"); + return; + } + + if (type == UART_ATTR_NIOBE_TO_HDF) { + switch (uartInit->HardwareFlowControl) { + case LL_USART_HWCONTROL_NONE: + attribute->rts = 0; + attribute->cts = 0; + break; + case LL_USART_HWCONTROL_CTS: + attribute->rts = 0; + attribute->cts = 1; + break; + case LL_USART_HWCONTROL_RTS: + attribute->rts = 1; + attribute->cts = 0; + break; + case LL_USART_HWCONTROL_RTS_CTS: + attribute->rts = 1; + attribute->cts = 1; + break; + default: + attribute->rts = 0; + attribute->cts = 0; + break; + } + } else { + if (attribute->rts && attribute->cts) { + uartInit->HardwareFlowControl = LL_USART_HWCONTROL_RTS_CTS; + } else if (attribute->rts && !attribute->cts) { + uartInit->HardwareFlowControl = LL_USART_HWCONTROL_RTS; + } else if (!attribute->rts && attribute->cts) { + uartInit->HardwareFlowControl = LL_USART_HWCONTROL_CTS; + } else { + uartInit->HardwareFlowControl = LL_USART_HWCONTROL_NONE; + } + } + + return; +} + +static void TransDir(LL_USART_InitTypeDef *uartInit, struct UartAttribute *attribute, UART_ATTR_TRAN_TYPE type) +{ + if (uartInit == NULL || attribute == NULL) { + HDF_LOGE("null ptr\r\n"); + return; + } + if (type == UART_ATTR_NIOBE_TO_HDF) { + switch (uartInit->TransferDirection) { + case LL_USART_DIRECTION_NONE: + attribute->fifoRxEn = 0; + attribute->fifoTxEn = 0; + break; + case LL_USART_DIRECTION_RX: + attribute->fifoRxEn = 1; + attribute->fifoTxEn = 0; + break; + case LL_USART_DIRECTION_TX: + attribute->fifoRxEn = 0; + attribute->fifoTxEn = 1; + break; + case LL_USART_DIRECTION_TX_RX: + attribute->fifoRxEn = 1; + attribute->fifoTxEn = 1; + break; + default: + attribute->fifoRxEn = 1; + attribute->fifoTxEn = 1; + break; + } + } else { + if (attribute->fifoRxEn && attribute->fifoTxEn) { + uartInit->TransferDirection = LL_USART_DIRECTION_TX_RX; + } else if (attribute->fifoRxEn && !attribute->fifoTxEn) { + uartInit->TransferDirection = LL_USART_DIRECTION_RX; + } else if (!attribute->fifoRxEn && attribute->fifoTxEn) { + uartInit->TransferDirection = LL_USART_DIRECTION_TX; + } else { + uartInit->TransferDirection = LL_USART_DIRECTION_NONE; + } + } + + return; +} + +static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribute *attribute) +{ + HDF_LOGI("%s: Enter", __func__); + UartDevice *uartDevice = NULL; + LL_USART_InitTypeDef *uartInit = NULL; + uint32_t uartId; + if (host == NULL || attribute == NULL || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + uartDevice = (UartDevice *)host->priv; + if (uartDevice == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + uartId = uartDevice->uartId; + uartInit = &uartDevice->initTypedef; + if (uartInit == NULL) { + HDF_LOGE("%s: config is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + TransDataWidth(uartInit, attribute, UART_ATTR_HDF_TO_NIOBE); + TransParity(uartInit, attribute, UART_ATTR_HDF_TO_NIOBE); + TransStopbit(uartInit, attribute, UART_ATTR_HDF_TO_NIOBE); + TransFlowCtrl(uartInit, attribute, UART_ATTR_HDF_TO_NIOBE); + TransDir(uartInit, attribute, UART_ATTR_HDF_TO_NIOBE); + + UartHostDevDeinit(host); + UartHostDevInit(host); + + return HDF_SUCCESS; +} + +static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribute *attribute) +{ + HDF_LOGI("%s: Enter", __func__); + UartDevice *uartDevice = NULL; + LL_USART_InitTypeDef *uartInit = NULL; + if (host == NULL || attribute == NULL || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + uartDevice = (UartDevice *)host->priv; + if (uartDevice == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + uartInit = &uartDevice->initTypedef; + if (uartInit == NULL) { + HDF_LOGE("%s: uartInit is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + TransDataWidth(uartInit, attribute, UART_ATTR_NIOBE_TO_HDF); + TransParity(uartInit, attribute, UART_ATTR_NIOBE_TO_HDF); + TransStopbit(uartInit, attribute, UART_ATTR_NIOBE_TO_HDF); + TransFlowCtrl(uartInit, attribute, UART_ATTR_NIOBE_TO_HDF); + TransDir(uartInit, attribute, UART_ATTR_NIOBE_TO_HDF); + + return HDF_SUCCESS; +} + +static int32_t UartHostDevSetTransMode(struct UartHost *host, enum UartTransMode mode) +{ + HDF_LOGI("%s: Enter", __func__); + UartDevice *uartDevice = NULL; + uint32_t uartId; + if (host == NULL || host->priv == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + uartDevice = (UartDevice *)host->priv; + if (uartDevice == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + uartId = uartDevice->uartId; + + switch (mode) { + case UART_MODE_RD_BLOCK: + g_uartCtx[uartId - 1].isBlock = true; + break; + case UART_MODE_RD_NONBLOCK: + g_uartCtx[uartId - 1].isBlock = false; + break; + case UART_MODE_DMA_RX_EN: + g_uartCtx[uartId - 1].rxDMA = true; + break; + case UART_MODE_DMA_RX_DIS: + g_uartCtx[uartId - 1].rxDMA = false; + break; + case UART_MODE_DMA_TX_EN: + g_uartCtx[uartId - 1].txDMA = true; + break; + case UART_MODE_DMA_TX_DIS: + g_uartCtx[uartId - 1].txDMA = false; + break; + default: + HDF_LOGE("%s: UartTransMode(%d) invalid", __func__, mode); + break; + } + + return HDF_SUCCESS; +} \ No newline at end of file diff --git a/platform/watchdog/BUILD.gn b/platform/watchdog/BUILD.gn index 9f2fc02..2d99168 100644 --- a/platform/watchdog/BUILD.gn +++ b/platform/watchdog/BUILD.gn @@ -26,4 +26,8 @@ hdf_driver(module_name) { } include_dirs = [ "." ] + if (defined(LOSCFG_NIOBE407_USE_HDF) && + defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { + deps = [ "//device/board/talkweb/niobe407/liteos_m/hdf_config" ] + } } diff --git a/platform/watchdog/watchdog_stm32f4xx.c b/platform/watchdog/watchdog_stm32f4xx.c old mode 100755 new mode 100644 index 9fb1d73..934d43c --- a/platform/watchdog/watchdog_stm32f4xx.c +++ b/platform/watchdog/watchdog_stm32f4xx.c @@ -8,7 +8,12 @@ #include #include +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO +#include "hcs_macro.h" +#include "hdf_config_macro.h" +#else #include "device_resource_if.h" +#endif #include "hdf_device_desc.h" #include "hdf_log.h" #include "watchdog_core.h" @@ -54,6 +59,35 @@ static int InitWatchdogDeviceInfo(WatchdogDeviceInfo *watchdogdeviceinfo) return HDF_SUCCESS; } +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO +#define WATCHDOG_FIND_CONFIG(node, name, device) \ + do { \ + if (strcmp(HCS_PROP(node, match_attr), name) == 0) { \ + device->watchdogId = HCS_PROP(node, id); \ + device->timeout = HCS_PROP(node, timeout); \ + result = HDF_SUCCESS; \ + } \ + } while (0) +#define PLATFORM_CONFIG HCS_NODE(HCS_ROOT, platform) +#define PLATFORM_WATCHDOG_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), watchdog_config) +static uint32_t GetWatchdogDeviceInfoResource(WatchdogDeviceInfo *device, const char *deviceMatchAttr) +{ + int32_t result = HDF_FAILURE; + if (device == NULL || deviceMatchAttr == NULL) { + HDF_LOGE("device or deviceMatchAttr is NULL\r\n"); + return HDF_ERR_INVALID_PARAM; + } +#if HCS_NODE_HAS_PROP(PLATFORM_CONFIG, watchdog_config) + HCS_FOREACH_CHILD_VARGS(PLATFORM_WATCHDOG_CONFIG, WATCHDOG_FIND_CONFIG, deviceMatchAttr, device); +#endif + if (result != HDF_SUCCESS) { + HDF_LOGE("resourceNode %s is NULL\r\n", deviceMatchAttr); + return result; + } + + return HDF_SUCCESS; +} +#else static uint32_t GetWatchdogDeviceInfoResource(WatchdogDeviceInfo *device, const struct DeviceResourceNode *resourceNode) { struct DeviceResourceIface *dri = NULL; @@ -76,19 +110,24 @@ static uint32_t GetWatchdogDeviceInfoResource(WatchdogDeviceInfo *device, const HDF_LOGE("read watchdogId fail\r\n"); return HDF_FAILURE; } - + HDF_LOGI("watchdogId = %d\n", device->watchdogId); HDF_LOGI("timeout = %dms\n", device->timeout); - + return HDF_SUCCESS; } +#endif static int32_t AttachWatchdogDeviceInfo(struct WatchdogCntlr *watchdogCntlr, struct HdfDeviceObject *device) { int32_t ret; WatchdogDeviceInfo *watchdogdeviceinfo = NULL; +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO + if (device == NULL || device->deviceMatchAttr == NULL) { +#else if (device == NULL || device->property == NULL) { +#endif HDF_LOGE("%s: param is NULL\r\n", __func__); return HDF_FAILURE; } @@ -99,7 +138,11 @@ static int32_t AttachWatchdogDeviceInfo(struct WatchdogCntlr *watchdogCntlr, str return HDF_ERR_MALLOC_FAIL; } +#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO + ret = GetWatchdogDeviceInfoResource(watchdogdeviceinfo, device->deviceMatchAttr); +#else ret = GetWatchdogDeviceInfoResource(watchdogdeviceinfo, device->property); +#endif if (ret != HDF_SUCCESS) { (void)OsalMemFree(watchdogdeviceinfo); return HDF_FAILURE; @@ -177,7 +220,7 @@ static int32_t WatchdogDriverInit(struct HdfDeviceObject *device) } watchdogCntlr->ops = &g_WatchdogCntlrMethod; - + HDF_LOGI("WatchdogDriverInit success!\r\n"); return ret; } -- Gitee From 32102e4c1443ab0aac7fb6595747a73176f8fea8 Mon Sep 17 00:00:00 2001 From: "weidongwang@bestechnic.com" Date: Sun, 3 Apr 2022 13:16:40 +0800 Subject: [PATCH 057/102] fix bug Change-Id: Ibd3bc7bc3095c29b0d488e234f305062e74fe6e3 Signed-off-by: weidongwang@bestechnic.com --- platform/gpio/gpio_bes.c | 8 ++++---- platform/i2c/i2c_bes.c | 4 ++-- platform/pwm/pwm_bes.c | 8 ++++---- platform/spi/spi_bes.c | 24 ++++++++++++++---------- platform/uart/uart_bes.c | 22 +++++++++++----------- platform/watchdog/watchdog_bes.c | 4 ++-- 6 files changed, 37 insertions(+), 33 deletions(-) mode change 100644 => 100755 platform/gpio/gpio_bes.c mode change 100644 => 100755 platform/i2c/i2c_bes.c mode change 100644 => 100755 platform/pwm/pwm_bes.c mode change 100644 => 100755 platform/spi/spi_bes.c mode change 100644 => 100755 platform/uart/uart_bes.c mode change 100644 => 100755 platform/watchdog/watchdog_bes.c diff --git a/platform/gpio/gpio_bes.c b/platform/gpio/gpio_bes.c old mode 100644 new mode 100755 index e1188a4..d06f02f --- a/platform/gpio/gpio_bes.c +++ b/platform/gpio/gpio_bes.c @@ -371,7 +371,7 @@ static int32_t GpioDevRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val uint16_t value; uint16_t halGpio = g_gpioPinReflectionMap[gpio]; if ((enum HAL_GPIO_PIN_T)halGpio >= HAL_GPIO_PIN_LED_NUM) { - HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, halGpio); + HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, halGpio); return HDF_ERR_NOT_SUPPORT; } @@ -386,7 +386,7 @@ static int32_t GpioDevSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t di (void)cntlr; uint16_t halGpio = g_gpioPinReflectionMap[gpio]; if ((enum HAL_GPIO_PIN_T)halGpio >= HAL_GPIO_PIN_LED_NUM) { - HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, halGpio); + HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, halGpio); return HDF_ERR_NOT_SUPPORT; } @@ -401,7 +401,7 @@ static int32_t GpioDevGetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *d uint16_t value; uint16_t halGpio = g_gpioPinReflectionMap[gpio]; if ((enum HAL_GPIO_PIN_T)halGpio >= HAL_GPIO_PIN_LED_NUM) { - HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, gpio); + HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, gpio); return HDF_ERR_NOT_SUPPORT; } @@ -425,7 +425,7 @@ static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mo } else if ((mode == OSAL_IRQF_TRIGGER_HIGH) || (mode == OSAL_IRQF_TRIGGER_LOW)) { g_gpioIrqCfg[pin].irq_type = HAL_GPIO_IRQ_TYPE_LEVEL_SENSITIVE; } else { - HDF_LOGE("%s %d, error mode:%d", __func__, __LINE__, mode); + HDF_LOGE("%s %d, error mode:%hu", __func__, __LINE__, mode); return HDF_ERR_NOT_SUPPORT; } diff --git a/platform/i2c/i2c_bes.c b/platform/i2c/i2c_bes.c old mode 100644 new mode 100755 index e2bfb43..2e172ce --- a/platform/i2c/i2c_bes.c +++ b/platform/i2c/i2c_bes.c @@ -60,7 +60,7 @@ static void I2cDeviceIomuxInit(uint32_t i2cId, struct I2cResource *resource) {0, 0, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}, }; -#ifdef CHIP_BEST2003 +#ifdef LOSCFG_SOC_SERIES_BES2600 if (i2cId == 0) { pinMuxI2c[0].function = HAL_IOMUX_FUNC_I2C_M0_SCL; pinMuxI2c[1].function = HAL_IOMUX_FUNC_I2C_M0_SDA; @@ -68,7 +68,7 @@ static void I2cDeviceIomuxInit(uint32_t i2cId, struct I2cResource *resource) pinMuxI2c[0].function = HAL_IOMUX_FUNC_I2C_M1_SCL; pinMuxI2c[1].function = HAL_IOMUX_FUNC_I2C_M1_SDA; } -#elif defined (CHIP_BEST1600) +#elif defined (LOSCFG_SOC_SERIES_BES2700) if (i2cId == 0) { pinMuxI2c[0].function = HAL_IOMUX_FUNC_SYS_I2C_M0_SCL; pinMuxI2c[1].function = HAL_IOMUX_FUNC_SYS_I2C_M0_SDA; diff --git a/platform/pwm/pwm_bes.c b/platform/pwm/pwm_bes.c old mode 100644 new mode 100755 index efb202e..af89491 --- a/platform/pwm/pwm_bes.c +++ b/platform/pwm/pwm_bes.c @@ -21,9 +21,9 @@ #include "device_resource_if.h" #endif -#if defined (CHIP_BEST1600) +#if defined (LOSCFG_SOC_SERIES_BES2700) #define PWM_MAX_FUNCTION 4 -#elif defined (CHIP_BEST2003) +#elif defined (LOSCFG_SOC_SERIES_BES2600) #include "hal_iomux.h" #define PWM_MAX_FUNCTION 8 #endif @@ -38,7 +38,7 @@ static uint32_t g_pwmFunction[PWM_MAX_FUNCTION] = { HAL_IOMUX_FUNC_PWM1, HAL_IOMUX_FUNC_PWM2, HAL_IOMUX_FUNC_PWM3, -#if defined (CHIP_BEST2003) +#if defined (LOSCFG_SOC_SERIES_BES2600) HAL_IOMUX_FUNC_PWM4, HAL_IOMUX_FUNC_PWM5, HAL_IOMUX_FUNC_PWM6, @@ -61,7 +61,7 @@ static int InitPwmDevice(struct PwmDev *host) struct PwmDevice *pwmDevice = NULL; struct PwmResource *resource = NULL; if (host == NULL || host->priv == NULL) { - HDF_LOGE("%s: invaild parameter\r\n", __func__); + HDF_LOGE("%s: invalid parameter\r\n", __func__); return HDF_ERR_INVALID_PARAM; } pwmDevice = (struct PwmDevice *)host->priv; diff --git a/platform/spi/spi_bes.c b/platform/spi/spi_bes.c old mode 100644 new mode 100755 index 9d317c5..1fba460 --- a/platform/spi/spi_bes.c +++ b/platform/spi/spi_bes.c @@ -37,12 +37,12 @@ static void Spi1DmaIrq(int error); static struct SPI_CTX_OBJ_T spiCtx[MAX_SPI_NUMBER] = { { .spiPinCS0 = 0, -#if defined (CHIP_BEST1600) +#if defined (LOSCFG_SOC_SERIES_BES2700) .spiFunDI0 = HAL_IOMUX_FUNC_SYS_SPI_DI0, .spiFunCLK = HAL_IOMUX_FUNC_SYS_SPI_CLK, .spiFunCS0 = HAL_IOMUX_FUNC_SYS_SPI_CS0, .spiFunDIO = HAL_IOMUX_FUNC_SYS_SPI_DIO, -#elif defined (CHIP_BEST2003) +#elif defined (LOSCFG_SOC_SERIES_BES2600) .spiFunDI0 = HAL_IOMUX_FUNC_SPI_DI0, .spiFunCLK = HAL_IOMUX_FUNC_SPI_CLK, .spiFunCS0 = HAL_IOMUX_FUNC_SPI_CS0, @@ -60,12 +60,12 @@ static struct SPI_CTX_OBJ_T spiCtx[MAX_SPI_NUMBER] = { }, { .spiPinCS0 = 0, -#if defined (CHIP_BEST1600) +#if defined (LOSCFG_SOC_SERIES_BES2700) .spiFunDI0 = HAL_IOMUX_FUNC_SYS_SPILCD_DI0, .spiFunCLK = HAL_IOMUX_FUNC_SYS_SPILCD_CLK, .spiFunCS0 = HAL_IOMUX_FUNC_SYS_SPILCD_CS0, .spiFunDIO = HAL_IOMUX_FUNC_SYS_SPILCD_DIO, -#elif defined (CHIP_BEST2003) +#elif defined (LOSCFG_SOC_SERIES_BES2600) .spiFunDI0 = HAL_IOMUX_FUNC_SPILCD_DI0, .spiFunCLK = HAL_IOMUX_FUNC_SPILCD_CLK, .spiFunCS0 = HAL_IOMUX_FUNC_SPILCD_CS0, @@ -237,7 +237,7 @@ int32_t HalSpiSend(struct SpiDevice *spiDevice, const uint8_t *data, uint16_t si HDF_LOGE("%s spi_mutex wait error = 0x%X!\r\n", __func__, status); return HDF_ERR_TIMEOUT; } -#ifdef CHIP_BEST1600 +#ifdef LOSCFG_SOC_SERIES_BES2700 hal_cache_sync_all(HAL_CACHE_ID_D_CACHE); #endif if (resource->transmode == SPI_TRANSFER_DMA) { @@ -301,7 +301,7 @@ static int32_t HalSpiRecv(struct SpiDevice *spiDevice, uint8_t *data, uint16_t s HDF_LOGE("%s spi_mutex wait error = 0x%X!\r\n", __func__, status); return HDF_ERR_TIMEOUT; } -#ifdef CHIP_BEST1600 +#ifdef LOSCFG_SOC_SERIES_BES2700 hal_cache_sync_all(HAL_CACHE_ID_D_CACHE); #endif do { @@ -350,7 +350,7 @@ static int32_t HalSpiSendRecv(struct SpiDevice *spiDevice, uint8_t *txData, uint HDF_LOGE("%s OsalMutexLock error = 0x%X!\r\n", __func__, status); return HDF_ERR_TIMEOUT; } -#ifdef CHIP_BEST1600 +#ifdef LOSCFG_SOC_SERIES_BES2700 hal_cache_sync_all(HAL_CACHE_ID_D_CACHE); #endif if (resource->transmode == SPI_TRANSFER_DMA) { @@ -785,6 +785,7 @@ static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg, struct SpiDevice *spiDevice = NULL; struct HAL_SPI_CFG_T *spiDevCfg = NULL; struct SpiMsg *msg = NULL; + int32_t ret; if (spiCntlr == NULL || spiCntlr->priv == NULL) { HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__); return HDF_ERR_INVALID_PARAM; @@ -799,19 +800,22 @@ static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg, } if ((msg->wbuf != NULL) && (msg->rbuf == NULL)) { - HalSpiSend(spiDevice, msg->wbuf, msg->len, TIMEOUT); + ret = HalSpiSend(spiDevice, msg->wbuf, msg->len, TIMEOUT); } if ((msg->rbuf != NULL) && (msg->wbuf == NULL)) { - HalSpiRecv(spiDevice, msg->rbuf, msg->len, TIMEOUT); + ret = HalSpiRecv(spiDevice, msg->rbuf, msg->len, TIMEOUT); } if ((msg->wbuf != NULL) && (msg->rbuf != NULL)) { - HalSpiSendRecv(spiDevice, msg->wbuf, msg->len, msg->rbuf, msg->len); + ret = HalSpiSendRecv(spiDevice, msg->wbuf, msg->len, msg->rbuf, msg->len); } /* pull pull up cs at the end */ if (msg->csChange) { hal_gpio_pin_set_dir(spiCtx[spiId].spiPinCS0, HAL_GPIO_DIR_OUT, 1); } + if (ret < 0) { + HDF_LOGE("%s send error!\r\n", __func__); + } DelayUs(msg->delayUs); } return HDF_SUCCESS; diff --git a/platform/uart/uart_bes.c b/platform/uart/uart_bes.c old mode 100644 new mode 100755 index 32c2161..439fabc --- a/platform/uart/uart_bes.c +++ b/platform/uart/uart_bes.c @@ -27,14 +27,14 @@ #define UART_FIFO_MAX_BUFFER 2048 #define UART_DMA_RING_BUFFER_SIZE 256 // mast be 2^n -#ifdef CHIP_BEST1600 +#ifdef LOSCFG_SOC_SERIES_BES2700 #include "hal_location.h" #define MAX_UART_NUMBER 2 #define MAX_UART_ID HAL_UART_ID_1 static SRAM_BSS_LOC unsigned char g_halUartBuf[UART_DMA_RING_BUFFER_SIZE]; static SRAM_BSS_LOC unsigned char g_halUart1Buf[UART_DMA_RING_BUFFER_SIZE]; static unsigned char *g_uartKfifoBuffer[MAX_UART_NUMBER] = { NULL, NULL }; -#elif defined (CHIP_BEST2003) +#elif defined (LOSCFG_SOC_SERIES_BES2600) #define MAX_UART_NUMBER 3 #define MAX_UART_ID HAL_UART_ID_2 static __SRAMBSS unsigned char g_halUartBuf[UART_DMA_RING_BUFFER_SIZE]; @@ -70,7 +70,7 @@ static void HalSetUartIomux(enum HAL_UART_ID_T uartId) if (uartId == HAL_UART_ID_1) { hal_iomux_set_uart1(); } -#ifdef CHIP_BEST2003 +#ifdef LOSCFG_SOC_SERIES_BES2600 if (uartId == HAL_UART_ID_2) { hal_iomux_set_uart2(); } @@ -104,14 +104,14 @@ static void UartRxHandler(enum HAL_UART_ID_T uartId, union HAL_UART_IRQ_T status return; } if (status.TX) { - if (OsalSemPost(&g_uartCtx[uartId].txSem != HDF_SUCCESS)) { + if (OsalSemPost(&g_uartCtx[uartId].txSem) != HDF_SUCCESS) { HDF_LOGE("%s OsalSemPost txSem failed!\r\n", __func__); return; } } if (status.RX || status.RT) { - if (OsalSemPost(&g_uartCtx[uartId].rxSem != HDF_SUCCESS)) { + if (OsalSemPost(&g_uartCtx[uartId].rxSem) != HDF_SUCCESS) { HDF_LOGE("%s OsalSemPost rxSem failed!\r\n", __func__); return; } @@ -127,7 +127,7 @@ static void UartDmaRxHandler(uint32_t xferSize, int dmaError, union HAL_UART_IRQ return; } - memset_s(g_uartCtx[HAL_UART_ID_0].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE); + (void)memset_s(g_uartCtx[HAL_UART_ID_0].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE); OsalSemPost(&g_uartCtx[HAL_UART_ID_0].rxSem); HalUartStartDmaRx(HAL_UART_ID_0); } @@ -155,7 +155,7 @@ static void Uart1DmaTxHandler(uint32_t xferSize, int dmaError) OsalSemPost(&g_uartCtx[HAL_UART_ID_1].txSem); } -#ifdef CHIP_BEST2003 +#ifdef LOSCFG_SOC_SERIES_BES2600 /* uart2 */ static void Uart2DmaRxHandler(uint32_t xferSize, int dmaError, union HAL_UART_IRQ_T status) { @@ -207,7 +207,7 @@ static int32_t HalUartSend(uint32_t uartId, const void *data, uint32_t size, uin return HDF_ERR_NOT_SUPPORT; } descCnt = 1; -#ifdef CHIP_BEST1600 +#ifdef LOSCFG_SOC_SERIES_BES2700 hal_cache_sync_all(HAL_CACHE_ID_D_CACHE); #endif hal_uart_dma_send(uartId, data, size, &dmaSescTx, &descCnt); @@ -294,7 +294,7 @@ static int32_t InitUartCtxCfg(struct UartDevice *device) g_uartCtx[uartId].UartDmaTxHandler = Uart1DmaTxHandler; g_uartCtx[uartId].buffer = g_halUart1Buf; } -#ifdef CHIP_BEST2003 +#ifdef LOSCFG_SOC_SERIES_BES2600 if (uartId == HAL_UART_ID_2) { g_uartCtx[uartId].UartDmaRxHandler = Uart2DmaRxHandler; g_uartCtx[uartId].UartDmaTxHandler = Uart2DmaTxHandler; @@ -679,8 +679,8 @@ static int32_t UartHostDevInit(struct UartHost *host) HDF_LOGE("%s: invalid parameter", __func__); return HDF_ERR_INVALID_PARAM; } - InitUartDevice(host); - return HDF_SUCCESS; + + return InitUartDevice(host); } static int32_t UartHostDevDeinit(struct UartHost *host) diff --git a/platform/watchdog/watchdog_bes.c b/platform/watchdog/watchdog_bes.c old mode 100644 new mode 100755 index e70f336..7071f41 --- a/platform/watchdog/watchdog_bes.c +++ b/platform/watchdog/watchdog_bes.c @@ -47,7 +47,7 @@ static int InitWatchdogDevice(struct WatchdogDevice *watchdogDevice) struct WatchdogResource *resource = NULL; int32_t watchdogId; if (watchdogDevice == NULL) { - HDF_LOGE("%s: invaild parameter\r\n", __func__); + HDF_LOGE("%s: invalid parameter\r\n", __func__); return HDF_ERR_INVALID_PARAM; } @@ -182,7 +182,7 @@ static int32_t WatchdogDriverInit(struct HdfDeviceObject *device) } watchdogCntlr->ops = &g_WatchdogCntlrMethod; - + HDF_LOGE("WatchdogDriverInit success!\r\n"); return ret; } -- Gitee From b6447733a6e4b34283c00f568c21b2f0cd36b1c8 Mon Sep 17 00:00:00 2001 From: yuanbo Date: Thu, 14 Apr 2022 18:00:36 +0800 Subject: [PATCH 058/102] fix: sysevent compatibility issue Signed-off-by: yuanbo --- uhdf2/manager/hdf_devmgrmusl.cfg | 2 +- uhdf2/osal/src/osal_sysevent.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/uhdf2/manager/hdf_devmgrmusl.cfg b/uhdf2/manager/hdf_devmgrmusl.cfg index c54809e..695a2e1 100644 --- a/uhdf2/manager/hdf_devmgrmusl.cfg +++ b/uhdf2/manager/hdf_devmgrmusl.cfg @@ -5,7 +5,7 @@ "uid" : "hdf_devmgr", "gid" : ["hdf_devmgr"], "start-mode" : "boot", - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_SYS_MODULE"] } ] } diff --git a/uhdf2/osal/src/osal_sysevent.c b/uhdf2/osal/src/osal_sysevent.c index 9b9d0d8..318ea20 100644 --- a/uhdf2/osal/src/osal_sysevent.c +++ b/uhdf2/osal/src/osal_sysevent.c @@ -102,15 +102,15 @@ static int OnKEventReceived( return HDF_FAILURE; } - receivedEvent->content = HdfSbufReadString(data); - + const char *eventContent = HdfSbufReadString(data); + eventContent = eventContent == NULL ? "" : eventContent; OsalMutexLock(¬ifier->mutex); struct HdfSysEventNotifyNode *notifyNode = NULL; DLIST_FOR_EACH_ENTRY(notifyNode, ¬ifier->notifyNodeList, struct HdfSysEventNotifyNode, listNode) { if (receivedEvent->eventClass & notifyNode->classFilter) { (void)notifyNode->callback( - notifyNode, receivedEvent->eventClass, receivedEvent->eventid, receivedEvent->content); + notifyNode, receivedEvent->eventClass, receivedEvent->eventid, eventContent); } } -- Gitee From 316542e84b01ced6643e69575f9ed1111d274c7a Mon Sep 17 00:00:00 2001 From: baoguotao Date: Fri, 15 Apr 2022 17:21:26 +0800 Subject: [PATCH 059/102] fix:optimizing compiler dependency mechanism of macro parsing Signed-off-by: baoguotao --- khdf/liteos_m/core/BUILD.gn | 12 +++-- khdf/liteos_m/hdf.gni | 33 +++++++++++- khdf/liteos_m/hdf_hcs.gni | 103 ------------------------------------ platform/gpio/BUILD.gn | 12 +++-- platform/i2c/BUILD.gn | 12 +++-- platform/i2c/i2c_bes.c | 8 +-- platform/pwm/BUILD.gn | 12 +++-- platform/spi/BUILD.gn | 12 +++-- platform/uart/BUILD.gn | 12 +++-- platform/watchdog/BUILD.gn | 12 +++-- 10 files changed, 98 insertions(+), 130 deletions(-) delete mode 100644 khdf/liteos_m/hdf_hcs.gni diff --git a/khdf/liteos_m/core/BUILD.gn b/khdf/liteos_m/core/BUILD.gn index 49a4e5f..9428fea 100644 --- a/khdf/liteos_m/core/BUILD.gn +++ b/khdf/liteos_m/core/BUILD.gn @@ -83,8 +83,14 @@ hdf_driver("hdf_core") { defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { deps = [ "//device/board/fnlink/shields" ] } - if (defined(LOSCFG_NIOBE407_USE_HDF) && - defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { - deps = [ "//device/board/talkweb/niobe407/liteos_m/hdf_config" ] + if (defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { + HDF_HCS_BUILD_PATH = rebase_path( + "//device/board/$device_company/$device_name/liteos_m/hdf_config") + cmd = "if [ -f ${HDF_HCS_BUILD_PATH}/BUILD.gn ]; then echo true; else echo false; fi" + HAVE_HCS_BUILD_PATH = + exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value") + if (HAVE_HCS_BUILD_PATH) { + deps = [ "${HDF_HCS_BUILD_PATH}" ] + } } } diff --git a/khdf/liteos_m/hdf.gni b/khdf/liteos_m/hdf.gni index b1b631b..18a6ee4 100644 --- a/khdf/liteos_m/hdf.gni +++ b/khdf/liteos_m/hdf.gni @@ -41,12 +41,30 @@ template("hdf_driver") { module_switch = true } - if (module_switch && defined(invoker.hcs_sources)) { + if (defined(invoker.macro_switch)) { + macro_switch = invoker.macro_switch + } else { + macro_switch = false + } + + if (!macro_switch && module_switch && defined(invoker.hcs_sources)) { hc_gen_hex("${target_name}_hc_gen_hex") { sources = invoker.hcs_sources } } + + if (macro_switch && module_switch && defined(invoker.hcs_sources)) { + hc_gen_macro("${target_name}_hc_gen_macro") { + sources = invoker.hcs_sources + outputs = [ "$target_gen_dir/hdf_config_macro.h" ] + } + } + kernel_module(target_name) { + if (defined(invoker.special_visibility)) { + visibility += invoker.special_visibility + } + forward_variables_from(invoker, "*", [ @@ -59,7 +77,8 @@ template("hdf_driver") { if (defined(invoker.visibility)) { visibility += invoker.visibility } - if (module_switch && defined(invoker.hcs_sources)) { + + if (module_switch && !macro_switch && defined(invoker.hcs_sources)) { hc_gen = ":${target_name}_hc_gen_hex" generated_sources = get_target_outputs(hc_gen) set_sources_assignment_filter([ "*.hcb" ]) @@ -74,10 +93,20 @@ template("hdf_driver") { deps = [ hc_gen ] } } + + if (module_switch && macro_switch && defined(invoker.hcs_sources)) { + hc_gen_macro = ":${target_name}_hc_gen_macro" + if (defined(invoker.deps)) { + deps += [ hc_gen_macro ] + } else { + deps = [ hc_gen_macro ] + } + } } } set_defaults("hdf_driver") { configs = [ "$HDFTOPDIR:hdf_config" ] visibility = [ "$HDFTOPDIR:*" ] + visibility += [ "//drivers/adapter/*" ] } diff --git a/khdf/liteos_m/hdf_hcs.gni b/khdf/liteos_m/hdf_hcs.gni deleted file mode 100644 index e62b039..0000000 --- a/khdf/liteos_m/hdf_hcs.gni +++ /dev/null @@ -1,103 +0,0 @@ -# -# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: -# -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -import("//drivers/framework/tools/hc-gen/hc_gen.gni") -import("//kernel/liteos_m/liteos.gni") - -HDF_FRAMEWORKS_PATH = "//drivers/framework" -HDF_PERIPHERAL_PATH = "//drivers/peripheral" -HDF_ADAPTER_PLATFORM_PATH = "//drivers/adapter/platform" - -template("hdf_driver") { - if (defined(invoker.module_switch)) { - forward_variables_from(invoker, [ "module_switch" ]) - } else { - module_switch = true - } - - if (defined(invoker.macro_switch)) { - forward_variables_from(invoker, [ "macro_switch" ]) - } - if (module_switch && !macro_switch && defined(invoker.hcs_sources)) { - hc_gen_hex("${target_name}_hc_gen_hex") { - sources = invoker.hcs_sources - } - } - if (module_switch && macro_switch && defined(invoker.hcs_sources)) { - hc_gen_macro("${target_name}_hc_gen_macro") { - sources = invoker.hcs_sources - outputs = [ "$target_gen_dir/hdf_config_macro.h" ] - } - } - kernel_module(target_name) { - forward_variables_from(invoker, - "*", - [ - "configs", - "visibility", - ]) - if (defined(invoker.configs)) { - configs += invoker.configs - } - if (defined(invoker.visibility)) { - visibility += invoker.visibility - } - if (module_switch && !macro_switch && defined(invoker.hcs_sources)) { - hc_gen = ":${target_name}_hc_gen_hex" - generated_sources = get_target_outputs(hc_gen) - set_sources_assignment_filter([ "*.hcb" ]) - if (defined(invoker.sources)) { - sources += generated_sources - } else { - sources = generated_sources - } - if (defined(invoker.deps)) { - deps += [ hc_gen ] - } else { - deps = [ hc_gen ] - } - } - if (module_switch && macro_switch && defined(invoker.hcs_sources)) { - hc_gen_macro = ":${target_name}_hc_gen_macro" - if (defined(invoker.deps)) { - deps += [ hc_gen_macro ] - } else { - deps = [ hc_gen_macro ] - } - } - } -} - -set_defaults("hdf_driver") { - configs = [ "$HDFTOPDIR:hdf_config" ] - visibility = [ "$HDFTOPDIR:*" ] - visibility += [ "//device/soc/bestechnic/bes2600/liteos_m/*" ] - visibility += [ "//device/board/talkweb/niobe407/liteos_m/*" ] - visibility += [ "//drivers/adapter/*" ] -} diff --git a/platform/gpio/BUILD.gn b/platform/gpio/BUILD.gn index ec5a261..090587d 100644 --- a/platform/gpio/BUILD.gn +++ b/platform/gpio/BUILD.gn @@ -34,8 +34,14 @@ hdf_driver(module_name) { defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { deps = [ "//device/board/fnlink/shields" ] } - if (defined(LOSCFG_NIOBE407_USE_HDF) && - defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { - deps = [ "//device/board/talkweb/niobe407/liteos_m/hdf_config" ] + if (defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { + HDF_HCS_BUILD_PATH = rebase_path( + "//device/board/$device_company/$device_name/liteos_m/hdf_config") + cmd = "if [ -f ${HDF_HCS_BUILD_PATH}/BUILD.gn ]; then echo true; else echo false; fi" + HAVE_HCS_BUILD_PATH = + exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value") + if (HAVE_HCS_BUILD_PATH) { + deps = [ "${HDF_HCS_BUILD_PATH}" ] + } } } diff --git a/platform/i2c/BUILD.gn b/platform/i2c/BUILD.gn index 0677ba8..7007f7d 100644 --- a/platform/i2c/BUILD.gn +++ b/platform/i2c/BUILD.gn @@ -28,8 +28,14 @@ hdf_driver(module_name) { defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { deps = [ "//device/board/fnlink/shields" ] } - if (defined(LOSCFG_NIOBE407_USE_HDF) && - defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { - deps = [ "//device/board/talkweb/niobe407/liteos_m/hdf_config" ] + if (defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { + HDF_HCS_BUILD_PATH = rebase_path( + "//device/board/$device_company/$device_name/liteos_m/hdf_config") + cmd = "if [ -f ${HDF_HCS_BUILD_PATH}/BUILD.gn ]; then echo true; else echo false; fi" + HAVE_HCS_BUILD_PATH = + exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value") + if (HAVE_HCS_BUILD_PATH) { + deps = [ "${HDF_HCS_BUILD_PATH}" ] + } } } diff --git a/platform/i2c/i2c_bes.c b/platform/i2c/i2c_bes.c index fe6753c..39597f6 100755 --- a/platform/i2c/i2c_bes.c +++ b/platform/i2c/i2c_bes.c @@ -133,7 +133,7 @@ int32_t InitI2cDevice(struct I2cDevice *device) } #ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO -#define I2C_FIND_CONFIG(node, name, resource) \ +#define I2C_FIND_CONFIG(node, name, resource, result, tempPin) \ do { \ if (strcmp(HCS_PROP(node, match_attr), name) == 0) { \ resource->port = HCS_PROP(node, port); \ @@ -158,15 +158,15 @@ static uint32_t GetI2cDeviceResource(struct I2cDevice *device, int32_t result = HDF_FAILURE; struct I2cResource *resource = NULL; if (device == NULL || deviceMatchAttr == NULL) { - HDF_LOGE("device or deviceMatchAttr is NULL\r\n"); + HDF_LOGE("device or deviceMatchAttr is NULL"); return HDF_ERR_INVALID_PARAM; } resource = &device->resource; #if HCS_NODE_EXISTS(PLATFORM_I2C_CONFIG) - HCS_FOREACH_CHILD_VARGS(PLATFORM_I2C_CONFIG, I2C_FIND_CONFIG, deviceMatchAttr, resource); + HCS_FOREACH_CHILD_VARGS(PLATFORM_I2C_CONFIG, I2C_FIND_CONFIG, deviceMatchAttr, resource, result, tempPin); #endif if (result != HDF_SUCCESS) { - HDF_LOGE("resourceNode %s is NULL\r\n", deviceMatchAttr); + HDF_LOGE("resourceNode %s is NULL", deviceMatchAttr); } return result; } diff --git a/platform/pwm/BUILD.gn b/platform/pwm/BUILD.gn index 77499ba..5daedb6 100644 --- a/platform/pwm/BUILD.gn +++ b/platform/pwm/BUILD.gn @@ -28,8 +28,14 @@ hdf_driver(module_name) { defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { deps = [ "//device/board/fnlink/shields" ] } - if (defined(LOSCFG_NIOBE407_USE_HDF) && - defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { - deps = [ "//device/board/talkweb/niobe407/liteos_m/hdf_config" ] + if (defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { + HDF_HCS_BUILD_PATH = rebase_path( + "//device/board/$device_company/$device_name/liteos_m/hdf_config") + cmd = "if [ -f ${HDF_HCS_BUILD_PATH}/BUILD.gn ]; then echo true; else echo false; fi" + HAVE_HCS_BUILD_PATH = + exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value") + if (HAVE_HCS_BUILD_PATH) { + deps = [ "${HDF_HCS_BUILD_PATH}" ] + } } } diff --git a/platform/spi/BUILD.gn b/platform/spi/BUILD.gn index 27ea450..b4558ab 100644 --- a/platform/spi/BUILD.gn +++ b/platform/spi/BUILD.gn @@ -28,8 +28,14 @@ hdf_driver(module_name) { defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { deps = [ "//device/board/fnlink/shields" ] } - if (defined(LOSCFG_NIOBE407_USE_HDF) && - defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { - deps = [ "//device/board/talkweb/niobe407/liteos_m/hdf_config" ] + if (defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { + HDF_HCS_BUILD_PATH = rebase_path( + "//device/board/$device_company/$device_name/liteos_m/hdf_config") + cmd = "if [ -f ${HDF_HCS_BUILD_PATH}/BUILD.gn ]; then echo true; else echo false; fi" + HAVE_HCS_BUILD_PATH = + exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value") + if (HAVE_HCS_BUILD_PATH) { + deps = [ "${HDF_HCS_BUILD_PATH}" ] + } } } diff --git a/platform/uart/BUILD.gn b/platform/uart/BUILD.gn index b1f26ec..4d4b371 100644 --- a/platform/uart/BUILD.gn +++ b/platform/uart/BUILD.gn @@ -34,8 +34,14 @@ hdf_driver(module_name) { defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { deps = [ "//device/board/fnlink/shields" ] } - if (defined(LOSCFG_NIOBE407_USE_HDF) && - defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { - deps = [ "//device/board/talkweb/niobe407/liteos_m/hdf_config" ] + if (defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { + HDF_HCS_BUILD_PATH = rebase_path( + "//device/board/$device_company/$device_name/liteos_m/hdf_config") + cmd = "if [ -f ${HDF_HCS_BUILD_PATH}/BUILD.gn ]; then echo true; else echo false; fi" + HAVE_HCS_BUILD_PATH = + exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value") + if (HAVE_HCS_BUILD_PATH) { + deps = [ "${HDF_HCS_BUILD_PATH}" ] + } } } diff --git a/platform/watchdog/BUILD.gn b/platform/watchdog/BUILD.gn index 2d99168..1088512 100644 --- a/platform/watchdog/BUILD.gn +++ b/platform/watchdog/BUILD.gn @@ -26,8 +26,14 @@ hdf_driver(module_name) { } include_dirs = [ "." ] - if (defined(LOSCFG_NIOBE407_USE_HDF) && - defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { - deps = [ "//device/board/talkweb/niobe407/liteos_m/hdf_config" ] + if (defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) { + HDF_HCS_BUILD_PATH = rebase_path( + "//device/board/$device_company/$device_name/liteos_m/hdf_config") + cmd = "if [ -f ${HDF_HCS_BUILD_PATH}/BUILD.gn ]; then echo true; else echo false; fi" + HAVE_HCS_BUILD_PATH = + exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value") + if (HAVE_HCS_BUILD_PATH) { + deps = [ "${HDF_HCS_BUILD_PATH}" ] + } } } -- Gitee From 8c2594a69c701ed0ed925a1d003dd8edcb74e703 Mon Sep 17 00:00:00 2001 From: yuanbo Date: Sat, 16 Apr 2022 11:13:25 +0800 Subject: [PATCH 060/102] feat: optimize hdi class to decoupling ipc class Signed-off-by: yuanbo --- uhdf2/hdi/BUILD.gn | 3 +- uhdf2/hdi/src/hdi_support.cpp | 102 ++++++++++++++++ uhdf2/hdi/src/idevmgr_client.cpp | 20 +-- uhdf2/hdi/src/iservmgr_client.cpp | 43 +++---- uhdf2/hdi/src/object_collector.cpp | 96 +++++++++++++++ uhdf2/hdi/src/servmgr_client.c | 4 +- uhdf2/hdi/test/BUILD.gn | 2 + .../sample_client_cpp_test.cpp | 80 ++++++++++++ .../sample_client_cpp/unittest/BUILD.gn | 62 ++++++++++ .../sample_client_cpp/unittest/foo_proxy.cpp | 54 +++++++++ .../sample_client_cpp/unittest/foo_proxy.h | 43 +++++++ .../unittest/sample_proxy.cpp | 90 ++++++++++++++ .../sample_client_cpp/unittest/sample_proxy.h | 41 +++++++ .../hdi_sample/sample_service_cpp/BUILD.gn | 82 +++++++++++++ .../sample_service_cpp/foo_service.cpp | 36 ++++++ .../sample_service_cpp/foo_service.h | 38 ++++++ .../sample_service_cpp/foo_stub.cpp | 94 +++++++++++++++ .../hdi_sample/sample_service_cpp/foo_stub.h | 55 +++++++++ .../test/hdi_sample/sample_service_cpp/ifoo.h | 44 +++++++ .../hdi_sample/sample_service_cpp/isample.h | 54 +++++++++ .../sample_service_cpp/sample_driver.cpp | 114 ++++++++++++++++++ .../sample_service_cpp/sample_service.cpp | 40 ++++++ .../sample_service_cpp/sample_service.h | 37 ++++++ .../sample_service_stub.cpp | 104 ++++++++++++++++ .../sample_service_cpp/sample_service_stub.h | 49 ++++++++ uhdf2/host/include/devsvc_manager_proxy.h | 4 +- uhdf2/include/hdi/hdi_base.h | 39 ++++++ .../hdi/{hdf_load_hdi.h => hdi_support.h} | 25 +--- uhdf2/include/hdi/idevmgr_hdi.h | 9 +- uhdf2/include/hdi/iservmgr_hdi.h | 10 +- uhdf2/ipc/include/iproxy_broker.h | 65 ++++++++++ uhdf2/ipc/include/object_collector.h | 78 ++++++++++++ uhdf2/manager/src/devmgr_service_stub.c | 2 +- uhdf2/manager/src/devsvc_manager_stub.c | 4 +- 34 files changed, 1558 insertions(+), 65 deletions(-) create mode 100644 uhdf2/hdi/src/hdi_support.cpp create mode 100644 uhdf2/hdi/src/object_collector.cpp create mode 100644 uhdf2/hdi/test/hdi_sample/sample_client_cpp/sample_client_cpp_test.cpp create mode 100644 uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/BUILD.gn create mode 100644 uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/foo_proxy.cpp create mode 100644 uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/foo_proxy.h create mode 100644 uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.cpp create mode 100644 uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.h create mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_cpp/BUILD.gn create mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_service.cpp create mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_service.h create mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_stub.cpp create mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_stub.h create mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_cpp/ifoo.h create mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_cpp/isample.h create mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_driver.cpp create mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service.cpp create mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service.h create mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.cpp create mode 100644 uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.h create mode 100644 uhdf2/include/hdi/hdi_base.h rename uhdf2/include/hdi/{hdf_load_hdi.h => hdi_support.h} (57%) create mode 100644 uhdf2/ipc/include/iproxy_broker.h create mode 100644 uhdf2/ipc/include/object_collector.h diff --git a/uhdf2/hdi/BUILD.gn b/uhdf2/hdi/BUILD.gn index c089d80..667fdb2 100644 --- a/uhdf2/hdi/BUILD.gn +++ b/uhdf2/hdi/BUILD.gn @@ -57,10 +57,11 @@ if (defined(ohos_lite)) { sources = [ "$hdf_framework_path/core/shared/src/service_status.c", "src/devmgr_client.c", - "src/hdf_load_hdi.c", "src/hdi_smq_syncer.cpp", + "src/hdi_support.cpp", "src/idevmgr_client.cpp", "src/iservmgr_client.cpp", + "src/object_collector.cpp", "src/servmgr_client.c", "src/servstat_listener.c", "src/servstat_listener_stub.cpp", diff --git a/uhdf2/hdi/src/hdi_support.cpp b/uhdf2/hdi/src/hdi_support.cpp new file mode 100644 index 0000000..59f4ad7 --- /dev/null +++ b/uhdf2/hdi/src/hdi_support.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +#include "hdf_base.h" +#include "hdf_log.h" +#include "hdi_support.h" + +#define HDF_LOG_TAG load_hdi + +#ifdef __ARM64__ +#define HDI_SO_PATH HDF_LIBRARY_DIR "64" +#else +#define HDI_SO_PATH HDF_LIBRARY_DIR +#endif + +constexpr int VERSION_SIZE = 2; +constexpr size_t INTERFACE_SIZE = 5; +constexpr size_t INTERFACE_VERSION_INDEX = 3; +constexpr size_t INTERFACE_NAME_INDEX = 2; + +int ParseInterface(std::string fullName, std::string &interface, uint32_t &versionMajor, uint32_t &versionMinor) +{ + std::vector spInfo; + OHOS::SplitStr(fullName, ".", spInfo, false, true); + if (spInfo.size() != INTERFACE_SIZE) { + HDF_LOGE("invlid interface format"); + return HDF_FAILURE; + } + + interface = spInfo[INTERFACE_NAME_INDEX]; + int ret = sscanf_s(spInfo[INTERFACE_VERSION_INDEX].data(), "V%u_%u", &versionMajor, &versionMinor); + if (ret != VERSION_SIZE) { + HDF_LOGE("failed to get interface version\n"); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +void *LoadHdiImpl(const char *fullIfName) +{ + char path[PATH_MAX + 1] = {0}; + char resolvedPath[PATH_MAX + 1] = {0}; + // interface name like "OHOS.HDI.Sample.V1_0.IFoo", the last two are version and interface name + if (fullIfName == nullptr) { + HDF_LOGE("fullIfName is nullptr"); + return nullptr; + } + + HDF_LOGD("load interface impl: %{public}s", fullIfName); + std::string fullName = fullIfName; + std::string interfaceName; + uint32_t versionMajor = 0; + uint32_t versionMinor = 0; + if (ParseInterface(fullIfName, interfaceName, versionMajor, versionMinor) != HDF_SUCCESS) { + HDF_LOGE("failed to parse hdi interface info"); + return nullptr; + } + // hdi implement name like libsample_service_1.0.z.so + if (snprintf_s(path, sizeof(path), sizeof(path) - 1, "%s/lib%s_service_%u.%u.z.so", HDI_SO_PATH, + OHOS::LowerStr(interfaceName).data(), versionMajor, versionMinor) < 0) { + HDF_LOGE("%{public}s snprintf_s failed", __func__); + return nullptr; + } + if (realpath(path, resolvedPath) == nullptr || strncmp(resolvedPath, HDI_SO_PATH, strlen(HDI_SO_PATH)) != 0) { + HDF_LOGE("%{public}s invalid hdi impl so name %{public}s", __func__, path); + return nullptr; + } + void *handler = dlopen(resolvedPath, RTLD_LAZY); + if (handler == nullptr) { + HDF_LOGE("%{public}s dlopen failed %{public}s", __func__, dlerror()); + return nullptr; + } + std::string symName = interfaceName.append("ImplGetInstance"); + using HdiImplInstanceFunc = void *(*)(void); + HdiImplInstanceFunc hdiImplInstanceFunc = (HdiImplInstanceFunc)dlsym(handler, symName.data()); + if (hdiImplInstanceFunc == nullptr) { + HDF_LOGE("%{public}s dlsym failed %{public}s", __func__, dlerror()); + dlclose(handler); + return nullptr; + } + return hdiImplInstanceFunc(); +} diff --git a/uhdf2/hdi/src/idevmgr_client.cpp b/uhdf2/hdi/src/idevmgr_client.cpp index 902755e..8536a33 100644 --- a/uhdf2/hdi/src/idevmgr_client.cpp +++ b/uhdf2/hdi/src/idevmgr_client.cpp @@ -13,9 +13,12 @@ * limitations under the License. */ -#include #include #include +#include +#include +#include + #include "idevmgr_hdi.h" #include "iservmgr_hdi.h" @@ -25,7 +28,7 @@ namespace OHOS { namespace HDI { namespace DeviceManager { namespace V1_0 { -enum DevngrCmdId : uint32_t { +enum DevmgrCmdId : uint32_t { DEVMGR_SERVICE_ATTACH_DEVICE_HOST = 1, DEVMGR_SERVICE_ATTACH_DEVICE, DEVMGR_SERVICE_DETACH_DEVICE, @@ -34,12 +37,13 @@ enum DevngrCmdId : uint32_t { DEVMGR_SERVICE_QUERY_DEVICE, }; -class DeviceManagerProxy : public IRemoteProxy { +class DeviceManagerProxy : public IProxyBroker { public: - explicit DeviceManagerProxy(const sptr& impl) : IRemoteProxy(impl) {} + explicit DeviceManagerProxy(const sptr &impl) : IProxyBroker(impl) {} ~DeviceManagerProxy() {} - virtual int32_t LoadDevice(const std::string &serviceName); - virtual int32_t UnloadDevice(const std::string &serviceName); + int32_t LoadDevice(const std::string &serviceName) override; + int32_t UnloadDevice(const std::string &serviceName) override; + private: static inline BrokerDelegator delegator_; }; @@ -50,7 +54,7 @@ int32_t DeviceManagerProxy::LoadDevice(const std::string &serviceName) MessageParcel reply; MessageOption option; HDF_LOGI("load device: %{public}s", serviceName.data()); - if (!data.WriteInterfaceToken(DeviceManagerProxy::GetDescriptor())) { + if (!data.WriteInterfaceToken(GetDescriptor())) { return HDF_FAILURE; } if (!data.WriteCString(serviceName.data())) { @@ -93,7 +97,7 @@ sptr IDeviceManager::Get() } sptr remote = servmgr->GetService("hdf_device_manager"); if (remote != nullptr) { - return iface_cast(remote); + return hdi_facecast(remote); } HDF_LOGE("hdf device manager not exist"); diff --git a/uhdf2/hdi/src/iservmgr_client.cpp b/uhdf2/hdi/src/iservmgr_client.cpp index 6977b65..27c8b29 100644 --- a/uhdf2/hdi/src/iservmgr_client.cpp +++ b/uhdf2/hdi/src/iservmgr_client.cpp @@ -13,10 +13,13 @@ * limitations under the License. */ -#include -#include #include #include +#include +#include +#include +#include + #include "iservmgr_hdi.h" namespace OHOS { @@ -25,18 +28,18 @@ namespace ServiceManager { namespace V1_0 { constexpr int DEVICE_SERVICE_MANAGER_SA_ID = 5100; constexpr int DEVSVC_MANAGER_GET_SERVICE = 3; -constexpr int DEVSVC_MANAGER_REGISER_SVCLISTENER = 4; -constexpr int DEVSVC_MANAGER_UNREGISER_SVCLISTENER = 5; +constexpr int DEVSVC_MANAGER_REGISTER_SVCLISTENER = 4; +constexpr int DEVSVC_MANAGER_UNREGISTER_SVCLISTENER = 5; -class ServiceManagerProxy : public IRemoteProxy { +class ServiceManagerProxy : public IProxyBroker { public: - explicit ServiceManagerProxy(const sptr& impl) : IRemoteProxy(impl) {} + explicit ServiceManagerProxy(const sptr &impl) : IProxyBroker(impl) {} ~ServiceManagerProxy() {} - sptr GetService(const char* serviceName) override; - int32_t RegisterServiceStatusListener(::OHOS::sptr listener, - uint16_t deviceClass) override; - int32_t UnregisterServiceStatusListener(::OHOS::sptr listener) override; + sptr GetService(const char *serviceName) override; + int32_t RegisterServiceStatusListener(sptr listener, uint16_t deviceClass) override; + int32_t UnregisterServiceStatusListener(sptr listener) override; + private: static inline BrokerDelegator delegator_; }; @@ -50,27 +53,26 @@ sptr IServiceManager::Get() } sptr remote = saManager->GetSystemAbility(DEVICE_SERVICE_MANAGER_SA_ID); if (remote != nullptr) { - return iface_cast(remote); + return new ServiceManagerProxy(remote); } HDF_LOGE("failed to get sa hdf service manager"); return nullptr; } -int32_t ServiceManagerProxy::RegisterServiceStatusListener(::OHOS::sptr listener, - uint16_t deviceClass) +int32_t ServiceManagerProxy::RegisterServiceStatusListener( + ::OHOS::sptr listener, uint16_t deviceClass) { MessageParcel data; MessageParcel reply; MessageOption option; - if (!data.WriteInterfaceToken(ServiceManagerProxy::GetDescriptor()) || - !data.WriteUint16(deviceClass) || + if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteUint16(deviceClass) || !data.WriteRemoteObject(listener->AsObject())) { return HDF_FAILURE; } - int status = Remote()->SendRequest(DEVSVC_MANAGER_REGISER_SVCLISTENER, data, reply, option); + int status = Remote()->SendRequest(DEVSVC_MANAGER_REGISTER_SVCLISTENER, data, reply, option); if (status) { HDF_LOGE("failed to register servstat listener, %{public}d", status); } @@ -83,23 +85,22 @@ int32_t ServiceManagerProxy::UnregisterServiceStatusListener(::OHOS::sptrAsObject())) { + if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteRemoteObject(listener->AsObject())) { return HDF_FAILURE; } - int status = Remote()->SendRequest(DEVSVC_MANAGER_UNREGISER_SVCLISTENER, data, reply, option); + int status = Remote()->SendRequest(DEVSVC_MANAGER_UNREGISTER_SVCLISTENER, data, reply, option); if (status) { HDF_LOGE("failed to unregister servstat listener, %{public}d", status); } return status; } -sptr ServiceManagerProxy::GetService(const char* serviceName) +sptr ServiceManagerProxy::GetService(const char *serviceName) { MessageParcel data; MessageParcel reply; - if (!data.WriteInterfaceToken(ServiceManagerProxy::GetDescriptor()) || !data.WriteCString(serviceName)) { + if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteCString(serviceName)) { return nullptr; } diff --git a/uhdf2/hdi/src/object_collector.cpp b/uhdf2/hdi/src/object_collector.cpp new file mode 100644 index 0000000..f73fac1 --- /dev/null +++ b/uhdf2/hdi/src/object_collector.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "hdf_base.h" +#include "hdf_log.h" + +#include "object_collector.h" + +using namespace OHOS::HDI; + +std::map ObjectCollector::constructorMapper_; +std::map ObjectCollector::interfaceObjectCollector_; +std::mutex ObjectCollector::mutex_; + +const ObjectCollector &ObjectCollector::GetInstance() +{ + static ObjectCollector mapper; + return mapper; +} + +bool ObjectCollector::ConstructorRegister(const std::u16string &interfaceName, const Constructor &constructor) const +{ + if (interfaceName.empty()) { + return false; + } + std::lock_guard lock(mutex_); + constructorMapper_.insert({interfaceName, std::move(constructor)}); + return true; +} + +void ObjectCollector::ConstructorUnRegister(const std::u16string &interfaceName) const +{ + std::lock_guard lock(mutex_); + constructorMapper_.erase(interfaceName); +} + +OHOS::sptr ObjectCollector::NewObjectLocked( + const OHOS::sptr &interface, const std::u16string &interfaceName) const +{ + if (interface == nullptr) { + return nullptr; + } + auto constructor = constructorMapper_.find(interfaceName); + if (constructor != constructorMapper_.end()) { + return constructor->second(interface); + } + + return nullptr; +} + +OHOS::sptr ObjectCollector::NewObject( + const OHOS::sptr &interface, const std::u16string &interfaceName) const +{ + std::lock_guard lock(mutex_); + return NewObjectLocked(interface, interfaceName); +} + +OHOS::sptr ObjectCollector::GetOrNewObject( + const OHOS::sptr &interface, const std::u16string &interfaceName) const +{ + std::lock_guard lock(mutex_); + + auto it = interfaceObjectCollector_.find(interface.GetRefPtr()); + if (it != interfaceObjectCollector_.end()) { + return it->second; + } + sptr object = NewObjectLocked(interface, interfaceName); + interfaceObjectCollector_[interface.GetRefPtr()] = object.GetRefPtr(); + + return object; +} + +bool ObjectCollector::RemoveObject(const OHOS::sptr &interface) const +{ + std::lock_guard lock(mutex_); + auto it = interfaceObjectCollector_.find(interface.GetRefPtr()); + if (it == interfaceObjectCollector_.end()) { + return false; + } + interfaceObjectCollector_.erase(it); + return true; +} \ No newline at end of file diff --git a/uhdf2/hdi/src/servmgr_client.c b/uhdf2/hdi/src/servmgr_client.c index 04afe98..2a5c4e2 100644 --- a/uhdf2/hdi/src/servmgr_client.c +++ b/uhdf2/hdi/src/servmgr_client.c @@ -96,7 +96,7 @@ int32_t HDIServMgrRegisterServiceStatusListener(struct HDIServiceManager *self, return HDF_FAILURE; } - int32_t ret = ServiceManagerHdiCall(servMgrClient, DEVSVC_MANAGER_REGISER_SVCLISTENER, data, NULL); + int32_t ret = ServiceManagerHdiCall(servMgrClient, DEVSVC_MANAGER_REGISTER_SVCLISTENER, data, NULL); if (ret != HDF_SUCCESS) { HDF_LOGE("failed to register hdi service listener"); } @@ -121,7 +121,7 @@ int32_t HDIServMgrUnregisterServiceStatusListener(struct HDIServiceManager *self return HDF_FAILURE; } - int32_t ret = ServiceManagerHdiCall(servMgrClient, DEVSVC_MANAGER_UNREGISER_SVCLISTENER, data, NULL); + int32_t ret = ServiceManagerHdiCall(servMgrClient, DEVSVC_MANAGER_UNREGISTER_SVCLISTENER, data, NULL); if (ret != HDF_SUCCESS) { HDF_LOGE("failed to unregister hdi service listener"); } diff --git a/uhdf2/hdi/test/BUILD.gn b/uhdf2/hdi/test/BUILD.gn index 3a2f9db..65aac55 100644 --- a/uhdf2/hdi/test/BUILD.gn +++ b/uhdf2/hdi/test/BUILD.gn @@ -65,5 +65,7 @@ group("unittest") { deps = [ ":HdiServiceManagerTest", ":HdiServiceManagerTestCC", + "hdi_sample/sample_client_cpp/unittest:sample_client_cpp", + "hdi_sample/sample_service_cpp:sample_service_cpp", ] } diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/sample_client_cpp_test.cpp b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/sample_client_cpp_test.cpp new file mode 100644 index 0000000..c351504 --- /dev/null +++ b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/sample_client_cpp_test.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include +#include + +#include "sample_proxy.h" + +using namespace testing::ext; +using namespace OHOS::HDI::Sample::V1_0; + +#define HDF_LOG_TAG sample_client_cpp_test + +constexpr const char *TEST_SERVICE_NAME = "sample_driver_service"; + +class SampleObjCPPTest : public testing::Test { +public: + static void SetUpTestCase() + { + auto devmgr = IDeviceManager::Get(); + if (devmgr != nullptr) { + devmgr->LoadDevice(TEST_SERVICE_NAME); + } + } + static void TearDownTestCase() + { + auto devmgr = IDeviceManager::Get(); + if (devmgr != nullptr) { + devmgr->UnloadDevice(TEST_SERVICE_NAME); + } + } + void SetUp() {} + void TearDown() {} +}; + +// IPC mode get interface object +HWTEST_F(SampleObjCPPTest, ServMgrTest100, TestSize.Level1) +{ + OHOS::sptr sampleService = ISample::Get(TEST_SERVICE_NAME, false); + ASSERT_TRUE(sampleService != nullptr); + OHOS::sptr fooInterface = nullptr; + int ret = sampleService->GetInterface(fooInterface); + ASSERT_EQ(ret, 0); + + bool value = false; + ret = fooInterface->PingTest(true, value); + ASSERT_EQ(ret, 0); + ASSERT_EQ(value, true); +} + +// passthrough mode get interface object +HWTEST_F(SampleObjCPPTest, ServMgrTest101, TestSize.Level1) +{ + OHOS::sptr sampleService = ISample::Get(TEST_SERVICE_NAME, true); + ASSERT_TRUE(sampleService != nullptr); + OHOS::sptr fooInterface = nullptr; + int ret = sampleService->GetInterface(fooInterface); + ASSERT_EQ(ret, 0); + + bool value = false; + ret = fooInterface->PingTest(true, value); + ASSERT_EQ(ret, 0); + ASSERT_EQ(value, true); +} diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/BUILD.gn b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/BUILD.gn new file mode 100644 index 0000000..e19499c --- /dev/null +++ b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/BUILD.gn @@ -0,0 +1,62 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//drivers/adapter/uhdf2/uhdf.gni") +group("sample_client_cpp") { + deps = [ ":libsample_client_cpp" ] +} +config("libsample_client_cpp_config") { + visibility = [ ":*" ] + + include_dirs = [ + "./", + "$hdf_uhdf_path/hdi/test/hdi_sample/sample_service_cpp", + ] +} +ohos_shared_library("libsample_client_cpp") { + include_dirs = [ + "$hdf_uhdf_path/manager/include", + "$hdf_uhdf_path/include/hdi", + "$hdf_uhdf_path/hdi/test/hdi_sample", + ] + public_configs = [ ":libsample_client_cpp_config" ] + sources = [ + "foo_proxy.cpp", + "sample_proxy.cpp", + ] + + deps = [ + "$hdf_uhdf_path/hdi:libhdi", + "//drivers/adapter/uhdf2/host:libhdf_host", + "//drivers/adapter/uhdf2/ipc:libhdf_ipc_adapter", + "//drivers/adapter/uhdf2/utils:libhdf_utils", + ] + + if (is_standard_system) { + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_single", + "utils_base:utils", + ] + } else { + external_deps = [ + "hilog:libhilog", + "ipc:ipc_single", + ] + } + + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "device_driver_framework" +} diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/foo_proxy.cpp b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/foo_proxy.cpp new file mode 100644 index 0000000..7370db1 --- /dev/null +++ b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/foo_proxy.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "ifoo.h" + +#include "foo_proxy.h" + +namespace OHOS { +namespace HDI { +namespace Sample { +namespace V1_0 { +int32_t FooProxy::PingTest(const bool input, bool &output) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(IFoo::GetDescriptor())) { + return HDF_FAILURE; + } + if (!data.WriteBool(input)) { + HDF_LOGE("%{public}s: write bool input failed!", __func__); + return HDF_FAILURE; + } + + int32_t ret = Remote()->SendRequest(CMD_FOO_PING, data, reply, option); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret); + return ret; + } + output = reply.ReadBool(); + + return HDF_SUCCESS; +} +} // namespace V1_0 +} // namespace Sample +} // namespace HDI +} // namespace OHOS \ No newline at end of file diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/foo_proxy.h b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/foo_proxy.h new file mode 100644 index 0000000..c8b740e --- /dev/null +++ b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/foo_proxy.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HDI_SAMPLE_CPP_CLIENT_H +#define HDI_SAMPLE_CPP_CLIENT_H + +#include +#include + +#include "ifoo.h" + +namespace OHOS { +namespace HDI { +namespace Sample { +namespace V1_0 { +class FooProxy : public IProxyBroker { +public: + explicit FooProxy(const sptr &impl) : IProxyBroker(impl) {} + virtual ~FooProxy() = default; + + int32_t PingTest(const bool input, bool &output) override; + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace V1_0 +} // namespace Sample +} // namespace HDI +} // namespace OHOS + +#endif // HDI_SAMPLE_CPP_CLIENT_H \ No newline at end of file diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.cpp b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.cpp new file mode 100644 index 0000000..be2073a --- /dev/null +++ b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "sample_proxy.h" + +namespace OHOS { +namespace HDI { +namespace Sample { +namespace V1_0 { +sptr ISample::Get(const std::string &serviceName, bool isStub) +{ + if (!isStub) { + using namespace OHOS::HDI::ServiceManager::V1_0; + auto servMgr = IServiceManager::Get(); + if (servMgr == nullptr) { + return nullptr; + } + + sptr remote = servMgr->GetService(serviceName.c_str()); + if (remote != nullptr) { + return hdi_facecast(remote); + } + + HDF_LOGE("%{public}s: get %{public}s failed!", __func__, serviceName.c_str()); + return nullptr; + } + + std::string desc = Str16ToStr8(ISample::GetDescriptor()); + void *impl = LoadHdiImpl(desc.data()); + if (impl == nullptr) { + HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); + return nullptr; + } + + return reinterpret_cast(impl); +} + +sptr ISample::Get(bool isStub) +{ + return ISample::Get("sample_service", isStub); +} + +int32_t SampleProxy::GetInterface(sptr &output) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInterfaceToken(ISample::GetDescriptor()); + int32_t ret = Remote()->SendRequest(CMD_INTERFACE_TRANS_TEST, data, reply, option); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret); + return ret; + } + auto remote = reply.ReadRemoteObject(); + if (remote == nullptr) { + HDF_LOGE("%{public}s: failed to read remote object", __func__); + return HDF_FAILURE; + } + + output = hdi_facecast(remote); + if (output == nullptr) { + HDF_LOGE("%{public}s: failed to cast foo proxy", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} +} // namespace V1_0 +} // namespace Sample +} // namespace HDI +} // namespace OHOS \ No newline at end of file diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.h b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.h new file mode 100644 index 0000000..b6b1168 --- /dev/null +++ b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef HDI_SAMPLE_CLIENT_PROXY_CPP_INF_H +#define HDI_SAMPLE_CLIENT_PROXY_CPP_INF_H + +#include + +#include "isample.h" + +namespace OHOS { +namespace HDI { +namespace Sample { +namespace V1_0 { +class SampleProxy : public IProxyBroker { +public: + explicit SampleProxy(const sptr &impl) : IProxyBroker(impl) {} + virtual ~SampleProxy() = default; + + int32_t GetInterface(sptr &output) override; + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace V1_0 +} // namespace Sample +} // namespace HDI +} // namespace OHOS + +#endif // HDI_SAMPLE_CLIENT_PROXY_CPP_INF_H \ No newline at end of file diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/BUILD.gn b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/BUILD.gn new file mode 100644 index 0000000..ef06ba8 --- /dev/null +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/BUILD.gn @@ -0,0 +1,82 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//drivers/adapter/uhdf2/uhdf.gni") + +ohos_shared_library("libhdisample_driver_cpp") { + sources = [ "sample_driver.cpp" ] + + deps = [ ":libsample_stub_1.0" ] + + external_deps = [ + "device_driver_framework:libhdf_host", + "device_driver_framework:libhdf_ipc_adapter", + "device_driver_framework:libhdf_utils", + "device_driver_framework:libhdi", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_single", + "utils_base:utils", + ] + + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "device_driver_framework" +} + +ohos_shared_library("libsample_stub_1.0") { + sources = [ + "foo_stub.cpp", + "sample_service_stub.cpp", + ] + + external_deps = [ + "device_driver_framework:libhdf_utils", + "device_driver_framework:libhdi", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_single", + "utils_base:utils", + ] + + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "device_driver_framework" +} + +ohos_shared_library("libsample_service_1.0") { + sources = [ + "foo_service.cpp", + "sample_service.cpp", + "sample_service_stub.cpp", + ] + + external_deps = [ + "device_driver_framework:libhdf_utils", + "device_driver_framework:libhdi", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_single", + "utils_base:utils", + ] + + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "device_driver_framework" +} + +group("sample_service_cpp") { + deps = [ + ":libhdisample_driver_cpp", + ":libsample_service_1.0", + ":libsample_stub_1.0", + ] +} diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_service.cpp b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_service.cpp new file mode 100644 index 0000000..d2a2c5b --- /dev/null +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_service.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "ifoo.h" + +#include "foo_service.h" + +namespace OHOS { +namespace HDI { +namespace Sample { +namespace V1_0 { +int32_t FooService::PingTest(const bool input, bool &output) +{ + HDF_LOGI("FooService::PingTest, in=%{public}d", input); + output = input; + return 0; +} +} // namespace V1_0 +} // namespace Sample +} // namespace HDI +} // namespace OHOS \ No newline at end of file diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_service.h b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_service.h new file mode 100644 index 0000000..9735c6d --- /dev/null +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_service.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HDI_FOO_SERVICE_CPP_INF_H +#define HDI_FOO_SERVICE_CPP_INF_H + +#include +#include +#include + +#include "ifoo.h" + +namespace OHOS { +namespace HDI { +namespace Sample { +namespace V1_0 { +class FooService : public IFoo { +public: + int32_t PingTest(const bool input, bool &output) override; +}; +} // namespace V1_0 +} // namespace Sample +} // namespace HDI +} // namespace OHOS + +#endif // HDI_FOO_SERVICE_CPP_INF_H diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_stub.cpp b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_stub.cpp new file mode 100644 index 0000000..37c752b --- /dev/null +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_stub.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "ifoo.h" + +#include "foo_stub.h" + + +namespace OHOS { +namespace HDI { +namespace Sample { +namespace V1_0 { +sptr IFoo::Get(bool isStub) +{ + if (!isStub) { + return nullptr; + } + std::string desc = Str16ToStr8(IFoo::GetDescriptor()); + void *impl = LoadHdiImpl(desc.data()); + if (impl == nullptr) { + HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); + return nullptr; + } + + return reinterpret_cast(impl); +} + +FooStub::FooStub(const sptr serviceImpl) : IPCObjectStub(IFoo::GetDescriptor()), impl_(serviceImpl) {} + +FooStub::~FooStub() +{ + ObjectCollector::GetInstance().RemoveObject(impl_); +} + +int32_t FooStub::StubPingTest(OHOS::MessageParcel &data, OHOS::MessageParcel &reply, OHOS::MessageOption &option) +{ + if (data.ReadInterfaceToken() != IFoo::GetDescriptor()) { + HDF_LOGE("failed to check interface token"); + return HDF_ERR_INVALID_PARAM; + } + bool input = data.ReadBool(); + bool output; + + if (impl_ == nullptr) { + HDF_LOGE("invalid service impl"); + return HDF_ERR_INVALID_OBJECT; + } + + int ret = impl_->PingTest(input, output); + if (ret != HDF_SUCCESS) { + return ret; + } + + reply.WriteBool(output); + return ret; +} + +int32_t FooStub::OnRemoteRequest( + uint32_t code, OHOS::MessageParcel &data, OHOS::MessageParcel &reply, OHOS::MessageOption &option) +{ + switch (code) { + case CMD_FOO_PING: + return StubPingTest(data, reply, option); + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } +} + +sptr FooStub::ToInterface() +{ + return impl_; +} +} // namespace V1_0 +} // namespace Sample +} // namespace HDI +} // namespace OHOS \ No newline at end of file diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_stub.h b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_stub.h new file mode 100644 index 0000000..19d14d7 --- /dev/null +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_stub.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HDI_FOO_STUB_CPP_INF_H +#define HDI_FOO_STUB_CPP_INF_H + +#include +#include +#include + +#include "ifoo.h" + +namespace OHOS { +namespace HDI { +namespace Sample { +namespace V1_0 { +class FooStub : public OHOS::IPCObjectStub { +public: + explicit FooStub(const sptr serviceImpl); + virtual ~FooStub(); + + // function handle start + int32_t StubPingTest(OHOS::MessageParcel &data, OHOS::MessageParcel &reply, OHOS::MessageOption &option); + // function handle end + + // base functions + int32_t OnRemoteRequest( + uint32_t code, OHOS::MessageParcel &data, OHOS::MessageParcel &reply, OHOS::MessageOption &option); + + sptr ToInterface(); + +private: + // Add constructor function to constructor map, only stub object need this + static inline ObjectDelegator objDelegator_; + + sptr impl_; +}; +} // namespace V1_0 +} // namespace Sample +} // namespace HDI +} // namespace OHOS + +#endif // HDI_FOO_STUB_CPP_INF_H diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/ifoo.h b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/ifoo.h new file mode 100644 index 0000000..b547490 --- /dev/null +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/ifoo.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HDI_FOO_CPP_INF_H +#define HDI_FOO_CPP_INF_H + +#include + +namespace OHOS { +namespace HDI { +namespace Sample { +namespace V1_0 { +enum FooCommand { + CMD_FOO_PING = 1, +}; + +class IFoo : public HdiBase { +public: + DECLARE_HDI_DESCRIPTOR(u"OHOS.HDI.Sample.V1_0.IFoo"); + IFoo() = default; + virtual ~IFoo() = default; + + virtual int32_t PingTest(const bool input, bool &output) = 0; + + static sptr Get(bool isStub); +}; +} // namespace V1_0 +} // namespace Sample +} // namespace HDI +} // namespace OHOS + +#endif // HDI_FOO_CPP_INF_H \ No newline at end of file diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/isample.h b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/isample.h new file mode 100644 index 0000000..15f2e57 --- /dev/null +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/isample.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HDI_SAMPLE_CPP_INF_H +#define HDI_SAMPLE_CPP_INF_H + +#include +#include +#include +#include +#include +#include "ifoo.h" + +namespace OHOS { +namespace HDI { +namespace Sample { +namespace V1_0 { +struct StructSample { + int8_t first; + int16_t second; +}; + +enum SampleCmdId { + CMD_INTERFACE_TRANS_TEST, +}; + +class ISample : public HdiBase { +public: + DECLARE_HDI_DESCRIPTOR(u"OHOS.HDI.Sample.V1_0.ISample"); + ISample() = default; + virtual ~ISample() = default; + virtual int32_t GetInterface(sptr &output) = 0; + + static sptr Get(bool isStub = false); + static sptr Get(const std::string &serviceName, bool isStub = false); +}; +} // namespace V1_0 +} // namespace Sample +} // namespace HDI +} // namespace OHOS + +#endif // HDI_SAMPLE_CPP_INF_H \ No newline at end of file diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_driver.cpp b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_driver.cpp new file mode 100644 index 0000000..8218496 --- /dev/null +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_driver.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "sample_service_stub.h" + +#define HDF_LOG_TAG sample_service_cpp + +using namespace OHOS::HDI::Sample::V1_0; + +struct HdfSampleService { + struct IDeviceIoService ioservice; + OHOS::sptr sampleStub; +}; + +static int32_t SampleServiceDispatch( + struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct HdfSampleService *hdfSampleService = + CONTAINER_OF(client->device->service, struct HdfSampleService, ioservice); + + OHOS::MessageParcel *dataParcel = nullptr; + OHOS::MessageParcel *replyParcel = nullptr; + OHOS::MessageOption option; + if (SbufToParcel(data, &dataParcel) != HDF_SUCCESS || SbufToParcel(reply, &replyParcel) != HDF_SUCCESS) { + HDF_LOGE("%{public}s: failed trans sbuf to parcel", __func__); + return HDF_FAILURE; + } + return hdfSampleService->sampleStub->SendRequest(cmdId, *dataParcel, *replyParcel, option); +} + +static int HdfSampleDriverInit(struct HdfDeviceObject *deviceObject) +{ + (void)deviceObject; + HDF_LOGI("HdfSampleDriverInit enter, new hdi impl"); + return HDF_SUCCESS; +} + +static int HdfSampleDriverBind(struct HdfDeviceObject *deviceObject) +{ + HDF_LOGI("HdfSampleDriverBind enter!"); + struct HdfSampleService *hdfSampleService = new HdfSampleService(); + if (hdfSampleService == nullptr) { + HDF_LOGE("HdfSampleDriverBind: OsalMemAlloc HdfSampleService failed!"); + return HDF_FAILURE; + } + hdfSampleService->sampleStub = nullptr; + auto sampleImpl = ISample::Get(true); + if (sampleImpl == nullptr) { + HDF_LOGE("HdfSampleDriverBind: failed to get ISample implement"); + return HDF_FAILURE; + } + + hdfSampleService->sampleStub = + OHOS::HDI::ObjectCollector::GetInstance().GetOrNewObject(sampleImpl, ISample::GetDescriptor()); + if (hdfSampleService->sampleStub == nullptr) { + HDF_LOGE("HdfSampleDriverBind: failed to get ISample stub object"); + return HDF_FAILURE; + } + + hdfSampleService->ioservice.Dispatch = SampleServiceDispatch; + hdfSampleService->ioservice.Open = NULL; + hdfSampleService->ioservice.Release = NULL; + + deviceObject->service = &hdfSampleService->ioservice; + return HDF_SUCCESS; +} + +static void HdfSampleDriverRelease(struct HdfDeviceObject *deviceObject) +{ + HDF_LOGI("HdfSampleDriverRelease called"); + if (deviceObject->service == nullptr) { + HDF_LOGE("HdfSampleDriverRelease not initted"); + return; + } + struct HdfSampleService *hdfSampleService = CONTAINER_OF(deviceObject->service, struct HdfSampleService, ioservice); + hdfSampleService->sampleStub = nullptr; + delete hdfSampleService; +} + +static struct HdfDriverEntry g_sampleDriverEntry = { + .moduleVersion = 1, + .moduleName = "sample_service_cpp", + .Bind = HdfSampleDriverBind, + .Init = HdfSampleDriverInit, + .Release = HdfSampleDriverRelease, +}; + +#ifndef __cplusplus +extern "C" { +#endif + +HDF_INIT(g_sampleDriverEntry); + +#ifndef __cplusplus +} +#endif \ No newline at end of file diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service.cpp b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service.cpp new file mode 100644 index 0000000..0fd3ac5 --- /dev/null +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "foo_service.h" + +#include "sample_service.h" + +namespace OHOS { +namespace HDI { +namespace Sample { +namespace V1_0 { +int32_t SampleService::GetInterface(sptr &output) +{ + output = new FooService(); + return 0; +} + +extern "C" +ISample *SampleImplGetInstance(void) +{ + return new SampleService(); +} +} // namespace V1_0 +} // namespace Sample +} // namespace HDI +} // namespace OHOS \ No newline at end of file diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service.h b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service.h new file mode 100644 index 0000000..9845a7a --- /dev/null +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HDI_SAMPLE_SERVICE_CPP_INF_H +#define HDI_SAMPLE_SERVICE_CPP_INF_H + +#include "isample.h" + +namespace OHOS { +namespace HDI { +namespace Sample { +namespace V1_0 { +class SampleService : public ISample { +public: + SampleService() {} + ~SampleService() override {} + + int32_t GetInterface(sptr &output) override; +}; +} // namespace V1_0 +} // namespace Sample +} // namespace HDI +} // namespace OHOS + +#endif // HDI_SAMPLE_SERVICE_CPP_INF_H diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.cpp b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.cpp new file mode 100644 index 0000000..340f4c2 --- /dev/null +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +#include "foo_service.h" + +#include "sample_service_stub.h" + +#define HDF_LOG_TAG sample_stub + +namespace OHOS { +namespace HDI { +namespace Sample { +namespace V1_0 { +sptr ISample::Get(const std::string &serviceName, bool isStub) +{ + if (!isStub) { + return nullptr; + } + + std::string desc = Str16ToStr8(ISample::GetDescriptor()); + void *impl = LoadHdiImpl(desc.data()); + if (impl == nullptr) { + HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); + return nullptr; + } + + return reinterpret_cast(impl); +} + +sptr ISample::Get(bool isStub) +{ + return ISample::Get("sample_service", isStub); +} + +SampleServiceStub::SampleServiceStub(const sptr serviceImpl) : + IPCObjectStub(ISample::GetDescriptor()), impl_(serviceImpl) +{ +} + +SampleServiceStub::~SampleServiceStub() +{ + ObjectCollector::GetInstance().RemoveObject(impl_); +} + +int32_t SampleServiceStub::SampleStubGetInterface( + MessageParcel &data, MessageParcel &reply, MessageOption &option) const +{ + if (data.ReadInterfaceToken() != ISample::GetDescriptor()) { + HDF_LOGE("failed to check interface"); + return HDF_ERR_INVALID_PARAM; + } + sptr interfaceObj; + auto ret = impl_->GetInterface(interfaceObj); + if (ret != HDF_SUCCESS || interfaceObj == nullptr) { + HDF_LOGE("%{public}s: call failed", __func__); + return HDF_FAILURE; + } + + sptr stubObject = ObjectCollector::GetInstance().GetOrNewObject(interfaceObj, IFoo::GetDescriptor()); + if (stubObject == nullptr) { + HDF_LOGE("%{public}s: failed to cast interface to stub object", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + reply.WriteRemoteObject(stubObject); + return HDF_SUCCESS; +} + +int32_t SampleServiceStub::OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + switch (code) { + case CMD_INTERFACE_TRANS_TEST: + return SampleStubGetInterface(data, reply, option); + default: { + HDF_LOGE("%{public}s: not support cmd %{public}d", __func__, code); + return HDF_ERR_INVALID_PARAM; + } + } + return HDF_SUCCESS; +} +} // namespace V1_0 +} // namespace Sample +} // namespace HDI +} // namespace OHOS diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.h b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.h new file mode 100644 index 0000000..9644ea7 --- /dev/null +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HDI_SAMPLE_SERVICE_STUB_CPP_INF_H +#define HDI_SAMPLE_SERVICE_STUB_CPP_INF_H + +#include +#include +#include +#include +#include + +#include "sample_service.h" + +namespace OHOS { +namespace HDI { +namespace Sample { +namespace V1_0 { +class SampleServiceStub : public OHOS::IPCObjectStub { +public: + explicit SampleServiceStub(const sptr serviceImpl); + virtual ~SampleServiceStub(); + + int32_t SampleStubGetInterface(MessageParcel &data, MessageParcel &reply, MessageOption &option) const; + + int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + static inline ObjectDelegator objDelegator_; + sptr impl_; +}; +} // namespace V1_0 +} // namespace Sample +} // namespace HDI +} // namespace OHOS + +#endif // HDI_SAMPLE_SERVICE_STUB_CPP_INF_H \ No newline at end of file diff --git a/uhdf2/host/include/devsvc_manager_proxy.h b/uhdf2/host/include/devsvc_manager_proxy.h index 01d3ffc..8479845 100644 --- a/uhdf2/host/include/devsvc_manager_proxy.h +++ b/uhdf2/host/include/devsvc_manager_proxy.h @@ -30,8 +30,8 @@ enum { DEVSVC_MANAGER_ADD_SERVICE = 1, DEVSVC_MANAGER_UPDATE_SERVICE, DEVSVC_MANAGER_GET_SERVICE, - DEVSVC_MANAGER_REGISER_SVCLISTENER, - DEVSVC_MANAGER_UNREGISER_SVCLISTENER, + DEVSVC_MANAGER_REGISTER_SVCLISTENER, + DEVSVC_MANAGER_UNREGISTER_SVCLISTENER, DEVSVC_MANAGER_LIST_SERVICE, DEVSVC_MANAGER_REMOVE_SERVICE, }; diff --git a/uhdf2/include/hdi/hdi_base.h b/uhdf2/include/hdi/hdi_base.h new file mode 100644 index 0000000..270729a --- /dev/null +++ b/uhdf2/include/hdi/hdi_base.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HDI_BASE_INTERFACE_H +#define HDI_BASE_INTERFACE_H + +#include +#include + +namespace OHOS { +namespace HDI { +class HdiBase : virtual public OHOS::RefBase { +public: + HdiBase() = default; + virtual ~HdiBase() = default; +}; + +#define DECLARE_HDI_DESCRIPTOR(DESCRIPTOR) \ + const static inline std::u16string metaDescriptor_ = {DESCRIPTOR}; \ + const static inline std::u16string &GetDescriptor() \ + { \ + return metaDescriptor_; \ + } +} // namespace HDI +} // namespace OHOS + +#endif // HDI_BASE_INTERFACE_H diff --git a/uhdf2/include/hdi/hdf_load_hdi.h b/uhdf2/include/hdi/hdi_support.h similarity index 57% rename from uhdf2/include/hdi/hdf_load_hdi.h rename to uhdf2/include/hdi/hdi_support.h index 184e159..1787540 100644 --- a/uhdf2/include/hdi/hdf_load_hdi.h +++ b/uhdf2/include/hdi/hdi_support.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef HDF_LOAD_HDI_H -#define HDF_LOAD_HDI_H +#ifndef HDF_HDI_SUPPORT_H +#define HDF_HDI_SUPPORT_H #include "hdf_base.h" @@ -22,26 +22,11 @@ extern "C" { #endif /* __cplusplus */ -struct HdiBase { - uint32_t moduleVersion; - const char *moduleName; - int (*OpenHdi)(); - int (*CloseHdi)(); -}; - -struct HdiObject { - uintptr_t dlHandler; - struct HdiBase *hdiBase; -}; - -struct HdiObject *LoadHdi(const char *name, uint32_t version); -void CloseHdi(struct HdiObject *hdi); - -#define HDF_HDI_INIT(module) struct HdiBase *hdfHdiDesc = (struct HdiBase *)&(module) +void *LoadHdiImpl(const char *fullIfName); #ifdef __cplusplus } #endif /* __cplusplus */ -#endif /* HDF_LOAD_HDI_H */ +#endif /* HDF_HDI_SUPPORT_H */ diff --git a/uhdf2/include/hdi/idevmgr_hdi.h b/uhdf2/include/hdi/idevmgr_hdi.h index 6432506..0daf343 100644 --- a/uhdf2/include/hdi/idevmgr_hdi.h +++ b/uhdf2/include/hdi/idevmgr_hdi.h @@ -15,16 +15,17 @@ #ifndef HDI_DEVICE_MANAGER_HDI_INF_H #define HDI_DEVICE_MANAGER_HDI_INF_H -#include -#include +#include namespace OHOS { namespace HDI { namespace DeviceManager { namespace V1_0 { -class IDeviceManager : public IRemoteBroker { +class IDeviceManager : public HdiBase { public: - DECLARE_INTERFACE_DESCRIPTOR(u"HDI.IDeviceManager.V1_0"); + DECLARE_HDI_DESCRIPTOR(u"HDI.IDeviceManager.V1_0"); + IDeviceManager() = default; + virtual ~IDeviceManager() = default; static ::OHOS::sptr Get(); virtual int32_t LoadDevice(const std::string &serviceName) = 0; virtual int32_t UnloadDevice(const std::string &serviceName) = 0; diff --git a/uhdf2/include/hdi/iservmgr_hdi.h b/uhdf2/include/hdi/iservmgr_hdi.h index 5ce2c9e..c0cee12 100644 --- a/uhdf2/include/hdi/iservmgr_hdi.h +++ b/uhdf2/include/hdi/iservmgr_hdi.h @@ -15,19 +15,21 @@ #ifndef HDI_ISERVICE_MANAGER_INF_H #define HDI_ISERVICE_MANAGER_INF_H -#include +#include #include +#include + #include "iservstat_listener_hdi.h" namespace OHOS { namespace HDI { namespace ServiceManager { namespace V1_0 { -class IServiceManager : public IRemoteBroker { +class IServiceManager : public HdiBase { public: - DECLARE_INTERFACE_DESCRIPTOR(u"HDI.IServiceManager.V1_0"); + DECLARE_HDI_DESCRIPTOR(u"HDI.IServiceManager.V1_0"); static ::OHOS::sptr Get(); - virtual ::OHOS::sptr GetService(const char* serviceName) = 0; + virtual ::OHOS::sptr GetService(const char *serviceName) = 0; virtual int32_t RegisterServiceStatusListener(::OHOS::sptr listener, uint16_t deviceClass) = 0; virtual int32_t UnregisterServiceStatusListener(::OHOS::sptr listener) = 0; }; diff --git a/uhdf2/ipc/include/iproxy_broker.h b/uhdf2/ipc/include/iproxy_broker.h new file mode 100644 index 0000000..7b6e0c3 --- /dev/null +++ b/uhdf2/ipc/include/iproxy_broker.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HDI_PROXY_BROKER_H +#define HDI_PROXY_BROKER_H + +#include +#include +#include + +namespace OHOS { +namespace HDI { +template +class IProxyBroker : public OHOS::PeerHolder, public OHOS::IRemoteBroker, public INTERFACE { +public: + explicit IProxyBroker(const sptr &object); + virtual ~IProxyBroker() = default; + virtual sptr AsInterface(); + +protected: + sptr AsObject() override; +}; + +template +IProxyBroker::IProxyBroker(const sptr &object) : PeerHolder(object) +{ +} + +template +sptr IProxyBroker::AsInterface() +{ + return this; +} + +template +sptr IProxyBroker::AsObject() +{ + return Remote(); +} + +template +inline sptr hdi_facecast(const sptr &object) +{ + const std::u16string descriptor = INTERFACE::GetDescriptor(); + BrokerRegistration ®istration = BrokerRegistration::Get(); + sptr broker = registration.NewInstance(descriptor, object); + INTERFACE *proxyBroker = static_cast *>(broker.GetRefPtr()); + return static_cast(proxyBroker); +} +} // namespace HDI +} // namespace OHOS + +#endif // HDI_PROXY_BROKER_H diff --git a/uhdf2/ipc/include/object_collector.h b/uhdf2/ipc/include/object_collector.h new file mode 100644 index 0000000..1d0b794 --- /dev/null +++ b/uhdf2/ipc/include/object_collector.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HDI_OBJECT_MAPPER_H +#define HDI_OBJECT_MAPPER_H + +#include +#include +#include +#include +#include +#include + +namespace OHOS { +namespace HDI { +class ObjectCollector { +public: + using Constructor = std::function(const sptr &interface)>; + ObjectCollector() = default; + + static const ObjectCollector &GetInstance(); + + bool ConstructorRegister(const std::u16string &interfaceName, const Constructor &constructor) const; + void ConstructorUnRegister(const std::u16string &interfaceName) const; + sptr NewObject(const sptr &interface, const std::u16string &interfaceName) const; + sptr GetOrNewObject(const sptr &interface, const std::u16string &interfaceName) const; + bool RemoveObject(const sptr &interface) const; + +private: + sptr NewObjectLocked(const sptr &interface, const std::u16string &interfaceName) const; + static std::map constructorMapper_; + static std::map interfaceObjectCollector_; + static std::mutex mutex_; +}; + +template +class ObjectDelegator { +public: + ObjectDelegator(); + ~ObjectDelegator(); + +private: + ObjectDelegator(const ObjectDelegator &) = delete; + ObjectDelegator(ObjectDelegator &&) = delete; + ObjectDelegator &operator=(const ObjectDelegator &) = delete; + ObjectDelegator &operator=(ObjectDelegator &&) = delete; +}; + +template +ObjectDelegator::ObjectDelegator() +{ + ObjectCollector::GetInstance().ConstructorRegister( + INTERFACE::GetDescriptor(), [](const sptr &interface) -> sptr { + return new OBJECT(static_cast(interface.GetRefPtr())); + }); +} + +template +ObjectDelegator::~ObjectDelegator() +{ + ObjectCollector::GetInstance().ConstructorUnRegister(INTERFACE::GetDescriptor()); +} +} // namespace HDI +} // namespace OHOS + +#endif // HDI_OBJECT_MAPPER_H diff --git a/uhdf2/manager/src/devmgr_service_stub.c b/uhdf2/manager/src/devmgr_service_stub.c index 6da88c2..fee2aa4 100644 --- a/uhdf2/manager/src/devmgr_service_stub.c +++ b/uhdf2/manager/src/devmgr_service_stub.c @@ -151,7 +151,7 @@ static int32_t InstallModule(const char *module) } int32_t ret = syscall(SYS_finit_module, fd, "", 0); if (ret != 0) { - HDF_LOGE("failed to install module %{public}s", module); + HDF_LOGE("failed to install module %{public}s, %{public}d", module, ret); } close(fd); diff --git a/uhdf2/manager/src/devsvc_manager_stub.c b/uhdf2/manager/src/devsvc_manager_stub.c index 7ad16d8..f1a45e5 100644 --- a/uhdf2/manager/src/devsvc_manager_stub.c +++ b/uhdf2/manager/src/devsvc_manager_stub.c @@ -290,10 +290,10 @@ int DevSvcManagerStubDispatch(struct HdfRemoteService *service, int code, struct case DEVSVC_MANAGER_REMOVE_SERVICE: ret = DevSvcManagerStubRemoveService(super, data); break; - case DEVSVC_MANAGER_REGISER_SVCLISTENER: + case DEVSVC_MANAGER_REGISTER_SVCLISTENER: ret = DevSvcManagerStubRegisterServListener(super, data); break; - case DEVSVC_MANAGER_UNREGISER_SVCLISTENER: + case DEVSVC_MANAGER_UNREGISTER_SVCLISTENER: ret = DevSvcManagerStubUnregisterServListener(super, data); break; default: -- Gitee From 79c7d9a04572905b3c30a6279577e4120b1c03d2 Mon Sep 17 00:00:00 2001 From: haizhouyang Date: Wed, 20 Apr 2022 15:36:08 +0800 Subject: [PATCH 061/102] optimize cs keeping logic for spi transfer Signed-off-by: haizhouyang --- khdf/liteos/platform/src/spi_dev.c | 2 +- platform/spi/spi_bes.c | 2 +- platform/spi/spi_stm32f4xx.c | 4 ++-- platform/spi/spi_wm.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/khdf/liteos/platform/src/spi_dev.c b/khdf/liteos/platform/src/spi_dev.c index 226a7b8..9564ab1 100644 --- a/khdf/liteos/platform/src/spi_dev.c +++ b/khdf/liteos/platform/src/spi_dev.c @@ -285,7 +285,7 @@ static int32_t SpiDevRealTransfer(struct SpiDev *dev, struct SpiMsg *msg, struct kmsg[i].wbuf = wbuf + pos; kmsg[i].rbuf = rbuf + pos; kmsg[i].len = msg[i].len; - kmsg[i].csChange = msg[i].csChange; + kmsg[i].keepCs = msg[i].keepCs; kmsg[i].delayUs = msg[i].delayUs; kmsg[i].speed = msg[i].speed; pos += msg[i].len; diff --git a/platform/spi/spi_bes.c b/platform/spi/spi_bes.c index 5fd6678..5a83d94 100755 --- a/platform/spi/spi_bes.c +++ b/platform/spi/spi_bes.c @@ -809,7 +809,7 @@ static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg, } /* pull pull up cs at the end */ - if (msg->csChange) { + if (msg->keepCs == 0) { hal_gpio_pin_set_dir(spiCtx[spiId].spiPinCS0, HAL_GPIO_DIR_OUT, 1); } if (ret < 0) { diff --git a/platform/spi/spi_stm32f4xx.c b/platform/spi/spi_stm32f4xx.c index 82611ba..e90c0b2 100644 --- a/platform/spi/spi_stm32f4xx.c +++ b/platform/spi/spi_stm32f4xx.c @@ -747,7 +747,7 @@ static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg, HalSpiSendRecv(spiDevice, msg->wbuf, msg->len, msg->rbuf, msg->len); } - if (msg->csChange || singleCsChange) { + if (msg->keepCs == 0|| singleCsChange) { LL_GPIO_SetOutputPin(LL_GET_GPIOX(spiDevice->resource.csGroup), LL_GET_HAL_PIN(spiDevice->resource.csPin)); } if (msg->delayUs > 0) { @@ -757,7 +757,7 @@ static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg, } return HDF_SUCCESS; CS_DOWN: - if (msg->csChange || singleCsChange) { + if (msg->keepCs == 0 || singleCsChange) { LL_GPIO_SetOutputPin(LL_GET_GPIOX(spiDevice->resource.csGroup), LL_GET_HAL_PIN(spiDevice->resource.csPin)); } return HDF_SUCCESS; diff --git a/platform/spi/spi_wm.c b/platform/spi/spi_wm.c index e317bff..61cd9d9 100755 --- a/platform/spi/spi_wm.c +++ b/platform/spi/spi_wm.c @@ -500,7 +500,7 @@ static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg, } /* pull pull up cs at the end */ - if (msg->csChange && spiDevice->resource.spiCsSoft) { + if (msg->keepCs == 0 && spiDevice->resource.spiCsSoft) { tls_gpio_write(WM_IO_PB_00 + spiDevice->resource.spiCsPin, 1); } } -- Gitee From 960fcc1108850ca5fc571d94bf8e0c9ee52cea44 Mon Sep 17 00:00:00 2001 From: yuanbo Date: Thu, 21 Apr 2022 21:11:29 +0800 Subject: [PATCH 062/102] feat: support hdf service selinux check Signed-off-by: yuanbo --- uhdf2/ipc/include/hdf_remote_adapter_if.h | 4 +++ uhdf2/ipc/src/hdf_remote_adapter.cpp | 10 ++++++ uhdf2/manager/BUILD.gn | 15 ++++---- uhdf2/manager/hdf_devmgrmusl.cfg | 4 +-- uhdf2/manager/src/devsvc_manager_stub.c | 44 +++++++++++++++++++++++ uhdf2/shared/include/hdf_remote_service.h | 1 - 6 files changed, 66 insertions(+), 12 deletions(-) diff --git a/uhdf2/ipc/include/hdf_remote_adapter_if.h b/uhdf2/ipc/include/hdf_remote_adapter_if.h index 979faf0..27f0449 100644 --- a/uhdf2/ipc/include/hdf_remote_adapter_if.h +++ b/uhdf2/ipc/include/hdf_remote_adapter_if.h @@ -16,6 +16,7 @@ #ifndef HDF_REMOTE_ADAPATER_IF_H #define HDF_REMOTE_ADAPATER_IF_H +#include #include "hdf_remote_service.h" #ifdef __cplusplus @@ -44,6 +45,9 @@ bool HdfRemoteAdapterWriteInterfaceToken(struct HdfRemoteService *service, struc bool HdfRemoteAdapterCheckInterfaceToken(struct HdfRemoteService *service, struct HdfSBuf *data); +pid_t HdfRemoteGetCallingPid(void); + +pid_t HdfRemoteGetCallingUid(void); #ifdef __cplusplus } diff --git a/uhdf2/ipc/src/hdf_remote_adapter.cpp b/uhdf2/ipc/src/hdf_remote_adapter.cpp index a728680..8544dff 100644 --- a/uhdf2/ipc/src/hdf_remote_adapter.cpp +++ b/uhdf2/ipc/src/hdf_remote_adapter.cpp @@ -367,3 +367,13 @@ bool HdfRemoteAdapterCheckInterfaceToken(struct HdfRemoteService *service, struc return true; } + +pid_t HdfRemoteGetCallingPid(void) +{ + return OHOS::IPCSkeleton::GetCallingPid(); +} + +pid_t HdfRemoteGetCallingUid(void) +{ + return OHOS::IPCSkeleton::GetCallingUid(); +} \ No newline at end of file diff --git a/uhdf2/manager/BUILD.gn b/uhdf2/manager/BUILD.gn index f77e366..01448cf 100644 --- a/uhdf2/manager/BUILD.gn +++ b/uhdf2/manager/BUILD.gn @@ -64,15 +64,12 @@ ohos_executable("hdf_devmgr") { "$hdf_uhdf_path/utils:libhdf_utils", ] - if (is_standard_system) { - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "init:libbegetutil", - "utils_base:utils", - ] - } else { - external_deps = [ "hilog:libhilog" ] - } + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "init:libbegetutil", + "selinux:libservice_checker", + "utils_base:utils", + ] cflags = [ "-Wall", diff --git a/uhdf2/manager/hdf_devmgrmusl.cfg b/uhdf2/manager/hdf_devmgrmusl.cfg index 695a2e1..10512d9 100644 --- a/uhdf2/manager/hdf_devmgrmusl.cfg +++ b/uhdf2/manager/hdf_devmgrmusl.cfg @@ -3,9 +3,9 @@ "name" : "hdf_devmgr", "path" : ["/vendor/bin/hdf_devmgr"], "uid" : "hdf_devmgr", - "gid" : ["hdf_devmgr"], + "gid" : ["hdf_devmgr", "readproc"], "start-mode" : "boot", - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH", "CAP_SYS_MODULE"] + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH","CAP_SYS_MODULE", "CAP_SYS_RAWIO"] } ] } diff --git a/uhdf2/manager/src/devsvc_manager_stub.c b/uhdf2/manager/src/devsvc_manager_stub.c index f1a45e5..3acfd02 100644 --- a/uhdf2/manager/src/devsvc_manager_stub.c +++ b/uhdf2/manager/src/devsvc_manager_stub.c @@ -14,18 +14,44 @@ */ #include "devsvc_manager_stub.h" + +#include + #include "device_token_proxy.h" #include "devmgr_service_stub.h" #include "devsvc_listener_holder.h" #include "devsvc_manager_proxy.h" #include "hdf_cstring.h" #include "hdf_log.h" +#include "hdf_remote_adapter_if.h" #include "hdf_sbuf.h" #include "hdf_slist.h" #include "osal_mem.h" #define HDF_LOG_TAG devsvc_manager_stub +static int32_t AddServicePermCheck(const char *servName) +{ + pid_t callingPid = HdfRemoteGetCallingPid(); + if (HdfAddServiceCheck(callingPid, servName) != 0) { + HDF_LOGE("[selinux] %{public}d haven't \"add service\" permission to %{public}s", callingPid, servName); + return HDF_ERR_NOPERM; + } + + return HDF_SUCCESS; +} + +static int32_t GetServicePermCheck(const char *servName) +{ + pid_t callingPid = HdfRemoteGetCallingPid(); + if (HdfGetServiceCheck(callingPid, servName) != 0) { + HDF_LOGE("[selinux] %{public}d haven't \"get service\" permission to %{public}s", callingPid, servName); + return HDF_ERR_NOPERM; + } + + return HDF_SUCCESS; +} + static struct HdfDeviceObject *ObtainServiceObject( struct DevSvcManagerStub *stub, const char *name, struct HdfRemoteService *service) { @@ -76,6 +102,11 @@ static int32_t DevSvcManagerStubAddService(struct IDevSvcManager *super, struct HDF_LOGE("%{public}s failed, name is null", __func__); return ret; } + ret = AddServicePermCheck(name); + if (ret != HDF_SUCCESS) { + return ret; + } + uint16_t devClass = DEVICE_CLASS_DEFAULT; if (!HdfSbufReadUint16(data, &devClass)) { HDF_LOGE("%{public}s failed, devClass invalid", __func__); @@ -117,6 +148,11 @@ static int32_t DevSvcManagerStubUpdateService(struct IDevSvcManager *super, stru HDF_LOGE("%{public}s failed, name is null", __func__); return ret; } + ret = AddServicePermCheck(name); + if (ret != HDF_SUCCESS) { + return ret; + } + uint16_t devClass = DEVICE_CLASS_DEFAULT; if (!HdfSbufReadUint16(data, &devClass)) { HDF_LOGE("%{public}s failed, devClass invalid", __func__); @@ -164,6 +200,10 @@ static int32_t DevSvcManagerStubGetService(struct IDevSvcManager *super, struct HDF_LOGE("%{public}s failed, name is null", __func__); return ret; } + ret = GetServicePermCheck(name); + if (ret != HDF_SUCCESS) { + return ret; + } struct HdfRemoteService *remoteService = (struct HdfRemoteService *)super->GetService(super, name); if (remoteService != NULL) { ret = HDF_SUCCESS; @@ -188,6 +228,10 @@ static int32_t DevSvcManagerStubRemoveService(struct IDevSvcManager *super, stru HDF_LOGE("%{public}s failed, name is null", __func__); return HDF_FAILURE; } + int32_t ret = AddServicePermCheck(name); + if (ret != HDF_SUCCESS) { + return ret; + } struct HdfDeviceObject *serviceObject = super->GetObject(super, name); if (serviceObject == NULL) { HDF_LOGE("remove service %{public}s not exist", name); diff --git a/uhdf2/shared/include/hdf_remote_service.h b/uhdf2/shared/include/hdf_remote_service.h index db7f079..ae71b25 100644 --- a/uhdf2/shared/include/hdf_remote_service.h +++ b/uhdf2/shared/include/hdf_remote_service.h @@ -58,7 +58,6 @@ bool HdfRemoteServiceWriteInterfaceToken(struct HdfRemoteService *service, struc bool HdfRemoteServiceCheckInterfaceToken(struct HdfRemoteService *service, struct HdfSBuf *data); - #ifdef __cplusplus } #endif /* __cplusplus */ -- Gitee From 4e16f10040ebdaef9ac6ba23ce0279c30c4ffff0 Mon Sep 17 00:00:00 2001 From: yuanbo Date: Sun, 24 Apr 2022 14:19:59 +0800 Subject: [PATCH 063/102] feat: support selinux feature switch Signed-off-by: yuanbo --- uhdf2/manager/BUILD.gn | 6 +++++- uhdf2/manager/src/devsvc_manager_stub.c | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/uhdf2/manager/BUILD.gn b/uhdf2/manager/BUILD.gn index 01448cf..1b9d139 100644 --- a/uhdf2/manager/BUILD.gn +++ b/uhdf2/manager/BUILD.gn @@ -67,7 +67,6 @@ ohos_executable("hdf_devmgr") { external_deps = [ "hiviewdfx_hilog_native:libhilog", "init:libbegetutil", - "selinux:libservice_checker", "utils_base:utils", ] @@ -77,6 +76,11 @@ ohos_executable("hdf_devmgr") { "-Werror", ] + if (build_selinux) { + external_deps += [ "selinux:libservice_checker" ] + cflags += [ "-DWITH_SELINUX" ] + } + install_enable = true install_images = [ chipset_base_dir ] subsystem_name = "hdf" diff --git a/uhdf2/manager/src/devsvc_manager_stub.c b/uhdf2/manager/src/devsvc_manager_stub.c index 3acfd02..daf0d9b 100644 --- a/uhdf2/manager/src/devsvc_manager_stub.c +++ b/uhdf2/manager/src/devsvc_manager_stub.c @@ -15,7 +15,9 @@ #include "devsvc_manager_stub.h" +#ifdef WITH_SELINUX #include +#endif #include "device_token_proxy.h" #include "devmgr_service_stub.h" @@ -32,22 +34,25 @@ static int32_t AddServicePermCheck(const char *servName) { +#ifdef WITH_SELINUX pid_t callingPid = HdfRemoteGetCallingPid(); if (HdfAddServiceCheck(callingPid, servName) != 0) { HDF_LOGE("[selinux] %{public}d haven't \"add service\" permission to %{public}s", callingPid, servName); return HDF_ERR_NOPERM; } - +#endif return HDF_SUCCESS; } static int32_t GetServicePermCheck(const char *servName) { +#ifdef WITH_SELINUX pid_t callingPid = HdfRemoteGetCallingPid(); if (HdfGetServiceCheck(callingPid, servName) != 0) { HDF_LOGE("[selinux] %{public}d haven't \"get service\" permission to %{public}s", callingPid, servName); return HDF_ERR_NOPERM; } +#endif return HDF_SUCCESS; } -- Gitee From b719304a162b98c2c3c041ae8ab444e6b7b9c576 Mon Sep 17 00:00:00 2001 From: taiyipei Date: Sun, 24 Apr 2022 01:49:39 -0700 Subject: [PATCH 064/102] delete redundancy third party deps Signed-off-by: taiyipei --- khdf/liteos/model/misc/dsoftbus/BUILD.gn | 1 - 1 file changed, 1 deletion(-) diff --git a/khdf/liteos/model/misc/dsoftbus/BUILD.gn b/khdf/liteos/model/misc/dsoftbus/BUILD.gn index 314ac7a..6c5cb87 100644 --- a/khdf/liteos/model/misc/dsoftbus/BUILD.gn +++ b/khdf/liteos/model/misc/dsoftbus/BUILD.gn @@ -48,7 +48,6 @@ hdf_driver(module_name) { include_dirs += [ "include", "//kernel/liteos_a/net/lwip-2.1/porting/include", - "//third_party/lwip/src/include/lwip", ] cflags += [ "-DENABLE_LWIP_MONITOR" ] } -- Gitee From 3d329e4ec5f11bef4b25bb09f6cf84803205e6e0 Mon Sep 17 00:00:00 2001 From: guodongqi Date: Fri, 22 Apr 2022 16:17:50 +0800 Subject: [PATCH 065/102] fix: finish code review comments Signed-off-by: guodongqi --- uhdf2/hdi/src/hdi_support.cpp | 7 +++-- uhdf2/hdi/src/object_collector.cpp | 21 ++++++-------- .../sample_client_cpp_test.cpp | 2 +- .../sample_client_cpp/unittest/BUILD.gn | 2 +- .../sample_client_cpp/unittest/foo_proxy.cpp | 2 +- .../sample_client_cpp/unittest/foo_proxy.h | 2 +- .../unittest/sample_proxy.cpp | 2 +- .../sample_client_cpp/unittest/sample_proxy.h | 2 +- .../hdi_sample/sample_service_cpp/BUILD.gn | 2 +- .../sample_service_cpp/foo_service.cpp | 4 +-- .../sample_service_cpp/foo_service.h | 2 +- .../sample_service_cpp/foo_stub.cpp | 2 +- .../test/hdi_sample/sample_service_cpp/ifoo.h | 2 +- .../sample_service_stub.cpp | 2 +- .../sample_service_cpp/sample_service_stub.h | 5 ++-- uhdf2/include/hdi/hdi_base.h | 2 +- uhdf2/ipc/include/object_collector.h | 28 +++++++++---------- 17 files changed, 44 insertions(+), 45 deletions(-) diff --git a/uhdf2/hdi/src/hdi_support.cpp b/uhdf2/hdi/src/hdi_support.cpp index 59f4ad7..fae506a 100644 --- a/uhdf2/hdi/src/hdi_support.cpp +++ b/uhdf2/hdi/src/hdi_support.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "hdi_support.h" #include #include #include @@ -22,7 +23,6 @@ #include "hdf_base.h" #include "hdf_log.h" -#include "hdi_support.h" #define HDF_LOG_TAG load_hdi @@ -32,12 +32,15 @@ #define HDI_SO_PATH HDF_LIBRARY_DIR #endif +namespace { constexpr int VERSION_SIZE = 2; constexpr size_t INTERFACE_SIZE = 5; constexpr size_t INTERFACE_VERSION_INDEX = 3; constexpr size_t INTERFACE_NAME_INDEX = 2; +} // namespace -int ParseInterface(std::string fullName, std::string &interface, uint32_t &versionMajor, uint32_t &versionMinor) +static int ParseInterface( + const std::string &fullName, std::string &interface, uint32_t &versionMajor, uint32_t &versionMinor) { std::vector spInfo; OHOS::SplitStr(fullName, ".", spInfo, false, true); diff --git a/uhdf2/hdi/src/object_collector.cpp b/uhdf2/hdi/src/object_collector.cpp index f73fac1..8b99b84 100644 --- a/uhdf2/hdi/src/object_collector.cpp +++ b/uhdf2/hdi/src/object_collector.cpp @@ -13,26 +13,21 @@ * limitations under the License. */ +#include "object_collector.h" #include #include "hdf_base.h" #include "hdf_log.h" -#include "object_collector.h" - using namespace OHOS::HDI; -std::map ObjectCollector::constructorMapper_; -std::map ObjectCollector::interfaceObjectCollector_; -std::mutex ObjectCollector::mutex_; - -const ObjectCollector &ObjectCollector::GetInstance() +ObjectCollector &ObjectCollector::GetInstance() { static ObjectCollector mapper; return mapper; } -bool ObjectCollector::ConstructorRegister(const std::u16string &interfaceName, const Constructor &constructor) const +bool ObjectCollector::ConstructorRegister(const std::u16string &interfaceName, const Constructor &constructor) { if (interfaceName.empty()) { return false; @@ -42,14 +37,14 @@ bool ObjectCollector::ConstructorRegister(const std::u16string &interfaceName, c return true; } -void ObjectCollector::ConstructorUnRegister(const std::u16string &interfaceName) const +void ObjectCollector::ConstructorUnRegister(const std::u16string &interfaceName) { std::lock_guard lock(mutex_); constructorMapper_.erase(interfaceName); } OHOS::sptr ObjectCollector::NewObjectLocked( - const OHOS::sptr &interface, const std::u16string &interfaceName) const + const OHOS::sptr &interface, const std::u16string &interfaceName) { if (interface == nullptr) { return nullptr; @@ -63,14 +58,14 @@ OHOS::sptr ObjectCollector::NewObjectLocked( } OHOS::sptr ObjectCollector::NewObject( - const OHOS::sptr &interface, const std::u16string &interfaceName) const + const OHOS::sptr &interface, const std::u16string &interfaceName) { std::lock_guard lock(mutex_); return NewObjectLocked(interface, interfaceName); } OHOS::sptr ObjectCollector::GetOrNewObject( - const OHOS::sptr &interface, const std::u16string &interfaceName) const + const OHOS::sptr &interface, const std::u16string &interfaceName) { std::lock_guard lock(mutex_); @@ -84,7 +79,7 @@ OHOS::sptr ObjectCollector::GetOrNewObject( return object; } -bool ObjectCollector::RemoveObject(const OHOS::sptr &interface) const +bool ObjectCollector::RemoveObject(const OHOS::sptr &interface) { std::lock_guard lock(mutex_); auto it = interfaceObjectCollector_.find(interface.GetRefPtr()); diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/sample_client_cpp_test.cpp b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/sample_client_cpp_test.cpp index c351504..076c1b9 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/sample_client_cpp_test.cpp +++ b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/sample_client_cpp_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/BUILD.gn b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/BUILD.gn index e19499c..17ff575 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/BUILD.gn +++ b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/foo_proxy.cpp b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/foo_proxy.cpp index 7370db1..dfad28f 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/foo_proxy.cpp +++ b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/foo_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/foo_proxy.h b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/foo_proxy.h index c8b740e..8b892c9 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/foo_proxy.h +++ b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/foo_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.cpp b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.cpp index be2073a..73744e2 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.cpp +++ b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.h b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.h index b6b1168..bd35983 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.h +++ b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/BUILD.gn b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/BUILD.gn index ef06ba8..781276d 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/BUILD.gn +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_service.cpp b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_service.cpp index d2a2c5b..e21a5c6 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_service.cpp +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_service.cpp @@ -24,11 +24,11 @@ namespace OHOS { namespace HDI { namespace Sample { namespace V1_0 { -int32_t FooService::PingTest(const bool input, bool &output) +int32_t FooService::PingTest(bool input, bool &output) { HDF_LOGI("FooService::PingTest, in=%{public}d", input); output = input; - return 0; + return HDF_SUCCESS; } } // namespace V1_0 } // namespace Sample diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_service.h b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_service.h index 9735c6d..8992128 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_service.h +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_service.h @@ -28,7 +28,7 @@ namespace Sample { namespace V1_0 { class FooService : public IFoo { public: - int32_t PingTest(const bool input, bool &output) override; + int32_t PingTest(bool input, bool &output) override; }; } // namespace V1_0 } // namespace Sample diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_stub.cpp b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_stub.cpp index 37c752b..3be47a7 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_stub.cpp +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_stub.cpp @@ -57,7 +57,7 @@ int32_t FooStub::StubPingTest(OHOS::MessageParcel &data, OHOS::MessageParcel &re return HDF_ERR_INVALID_PARAM; } bool input = data.ReadBool(); - bool output; + bool output = false; if (impl_ == nullptr) { HDF_LOGE("invalid service impl"); diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/ifoo.h b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/ifoo.h index b547490..7d9ed9f 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/ifoo.h +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/ifoo.h @@ -32,7 +32,7 @@ public: IFoo() = default; virtual ~IFoo() = default; - virtual int32_t PingTest(const bool input, bool &output) = 0; + virtual int32_t PingTest(bool input, bool &output) = 0; static sptr Get(bool isStub); }; diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.cpp b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.cpp index 340f4c2..5947f3b 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.cpp +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.cpp @@ -51,7 +51,7 @@ sptr ISample::Get(bool isStub) return ISample::Get("sample_service", isStub); } -SampleServiceStub::SampleServiceStub(const sptr serviceImpl) : +SampleServiceStub::SampleServiceStub(const sptr &serviceImpl) : IPCObjectStub(ISample::GetDescriptor()), impl_(serviceImpl) { } diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.h b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.h index 9644ea7..cff89dd 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.h +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.h @@ -30,12 +30,13 @@ namespace Sample { namespace V1_0 { class SampleServiceStub : public OHOS::IPCObjectStub { public: - explicit SampleServiceStub(const sptr serviceImpl); + explicit SampleServiceStub(const sptr &serviceImpl); virtual ~SampleServiceStub(); int32_t SampleStubGetInterface(MessageParcel &data, MessageParcel &reply, MessageOption &option) const; - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + int32_t OnRemoteRequest( +uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; private: static inline ObjectDelegator objDelegator_; diff --git a/uhdf2/include/hdi/hdi_base.h b/uhdf2/include/hdi/hdi_base.h index 270729a..c896db2 100644 --- a/uhdf2/include/hdi/hdi_base.h +++ b/uhdf2/include/hdi/hdi_base.h @@ -16,8 +16,8 @@ #ifndef HDI_BASE_INTERFACE_H #define HDI_BASE_INTERFACE_H -#include #include +#include namespace OHOS { namespace HDI { diff --git a/uhdf2/ipc/include/object_collector.h b/uhdf2/ipc/include/object_collector.h index 1d0b794..b95746b 100644 --- a/uhdf2/ipc/include/object_collector.h +++ b/uhdf2/ipc/include/object_collector.h @@ -13,36 +13,36 @@ * limitations under the License. */ -#ifndef HDI_OBJECT_MAPPER_H -#define HDI_OBJECT_MAPPER_H +#ifndef HDI_OBJECT_COLLECTOR_H +#define HDI_OBJECT_COLLECTOR_H +#include #include #include #include #include #include -#include namespace OHOS { namespace HDI { class ObjectCollector { public: using Constructor = std::function(const sptr &interface)>; - ObjectCollector() = default; - static const ObjectCollector &GetInstance(); + static ObjectCollector &GetInstance(); - bool ConstructorRegister(const std::u16string &interfaceName, const Constructor &constructor) const; - void ConstructorUnRegister(const std::u16string &interfaceName) const; - sptr NewObject(const sptr &interface, const std::u16string &interfaceName) const; - sptr GetOrNewObject(const sptr &interface, const std::u16string &interfaceName) const; - bool RemoveObject(const sptr &interface) const; + bool ConstructorRegister(const std::u16string &interfaceName, const Constructor &constructor); + void ConstructorUnRegister(const std::u16string &interfaceName); + sptr NewObject(const sptr &interface, const std::u16string &interfaceName); + sptr GetOrNewObject(const sptr &interface, const std::u16string &interfaceName); + bool RemoveObject(const sptr &interface); private: - sptr NewObjectLocked(const sptr &interface, const std::u16string &interfaceName) const; - static std::map constructorMapper_; - static std::map interfaceObjectCollector_; - static std::mutex mutex_; + ObjectCollector() = default; + sptr NewObjectLocked(const sptr &interface, const std::u16string &interfaceName); + std::map constructorMapper_; + std::map interfaceObjectCollector_; + std::mutex mutex_; }; template -- Gitee From 58362ae04faaba2dc4a2afed6d2f1cd4af0212b7 Mon Sep 17 00:00:00 2001 From: yuanbo Date: Mon, 25 Apr 2022 15:29:53 +0800 Subject: [PATCH 066/102] feat: support interface object cast to remote object Signed-off-by: yuanbo --- uhdf2/hdi/test/BUILD.gn | 1 + .../hdi_sample/sample_client_cpp/BUILD.gn | 37 +++++++++++++++++++ .../sample_client_cpp_test.cpp | 33 +++++++++++++++-- .../sample_client_cpp/unittest/BUILD.gn | 17 +++------ uhdf2/ipc/include/iproxy_broker.h | 9 ++++- 5 files changed, 80 insertions(+), 17 deletions(-) create mode 100644 uhdf2/hdi/test/hdi_sample/sample_client_cpp/BUILD.gn diff --git a/uhdf2/hdi/test/BUILD.gn b/uhdf2/hdi/test/BUILD.gn index 65aac55..2ff57be 100644 --- a/uhdf2/hdi/test/BUILD.gn +++ b/uhdf2/hdi/test/BUILD.gn @@ -65,6 +65,7 @@ group("unittest") { deps = [ ":HdiServiceManagerTest", ":HdiServiceManagerTestCC", + "hdi_sample/sample_client_cpp:HdiSampleTestCC", "hdi_sample/sample_client_cpp/unittest:sample_client_cpp", "hdi_sample/sample_service_cpp:sample_service_cpp", ] diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/BUILD.gn b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/BUILD.gn new file mode 100644 index 0000000..ba35a97 --- /dev/null +++ b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//drivers/adapter/uhdf2/uhdf.gni") + +module_output_path = "hdf/hdi" + +ohos_unittest("HdiSampleTestCC") { + module_out_path = module_output_path + sources = [ "sample_client_cpp_test.cpp" ] + + deps = [ + "$hdf_uhdf_path/hdi:libhdi", + "$hdf_uhdf_path/utils:libhdf_utils", + "unittest:libsample_client_cpp", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_single", + "samgr_standard:samgr_proxy", + "utils_base:utils", + ] +} diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/sample_client_cpp_test.cpp b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/sample_client_cpp_test.cpp index 076c1b9..06d01fa 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/sample_client_cpp_test.cpp +++ b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/sample_client_cpp_test.cpp @@ -14,6 +14,9 @@ */ #include #include +#include +#include +#include #include #include #include @@ -24,12 +27,16 @@ using namespace testing::ext; using namespace OHOS::HDI::Sample::V1_0; +using OHOS::IRemoteObject; +using OHOS::sptr; +using OHOS::wptr; +using OHOS::HDI::DeviceManager::V1_0::IDeviceManager; #define HDF_LOG_TAG sample_client_cpp_test constexpr const char *TEST_SERVICE_NAME = "sample_driver_service"; -class SampleObjCPPTest : public testing::Test { +class SampleHdiCppTest : public testing::Test { public: static void SetUpTestCase() { @@ -50,7 +57,7 @@ public: }; // IPC mode get interface object -HWTEST_F(SampleObjCPPTest, ServMgrTest100, TestSize.Level1) +HWTEST_F(SampleHdiCppTest, HdiCppTest001, TestSize.Level1) { OHOS::sptr sampleService = ISample::Get(TEST_SERVICE_NAME, false); ASSERT_TRUE(sampleService != nullptr); @@ -65,7 +72,7 @@ HWTEST_F(SampleObjCPPTest, ServMgrTest100, TestSize.Level1) } // passthrough mode get interface object -HWTEST_F(SampleObjCPPTest, ServMgrTest101, TestSize.Level1) +HWTEST_F(SampleHdiCppTest, HdiCppTest002, TestSize.Level1) { OHOS::sptr sampleService = ISample::Get(TEST_SERVICE_NAME, true); ASSERT_TRUE(sampleService != nullptr); @@ -78,3 +85,23 @@ HWTEST_F(SampleObjCPPTest, ServMgrTest101, TestSize.Level1) ASSERT_EQ(ret, 0); ASSERT_EQ(value, true); } + +class SampleDeathRecipient : public IRemoteObject::DeathRecipient { +public: + void OnRemoteDied(const wptr &object) override + { + HDF_LOGI("sample service dead"); + } +}; + +// IPC mode add DeathRecipient +HWTEST_F(SampleHdiCppTest, HdiCppTest003, TestSize.Level1) +{ + sptr sampleService = ISample::Get(TEST_SERVICE_NAME, false); + ASSERT_TRUE(sampleService != nullptr); + + const sptr recipient = new SampleDeathRecipient(); + sptr remote = OHOS::HDI::hdi_objcast(sampleService); + bool ret = remote->AddDeathRecipient(recipient); + ASSERT_EQ(ret, true); +} diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/BUILD.gn b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/BUILD.gn index 17ff575..9d5b49b 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/BUILD.gn +++ b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/BUILD.gn @@ -43,18 +43,11 @@ ohos_shared_library("libsample_client_cpp") { "//drivers/adapter/uhdf2/utils:libhdf_utils", ] - if (is_standard_system) { - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_single", - "utils_base:utils", - ] - } else { - external_deps = [ - "hilog:libhilog", - "ipc:ipc_single", - ] - } + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_single", + "utils_base:utils", + ] install_images = [ chipset_base_dir ] subsystem_name = "hdf" diff --git a/uhdf2/ipc/include/iproxy_broker.h b/uhdf2/ipc/include/iproxy_broker.h index 7b6e0c3..182d32d 100644 --- a/uhdf2/ipc/include/iproxy_broker.h +++ b/uhdf2/ipc/include/iproxy_broker.h @@ -28,8 +28,6 @@ public: explicit IProxyBroker(const sptr &object); virtual ~IProxyBroker() = default; virtual sptr AsInterface(); - -protected: sptr AsObject() override; }; @@ -59,6 +57,13 @@ inline sptr hdi_facecast(const sptr &object) INTERFACE *proxyBroker = static_cast *>(broker.GetRefPtr()); return static_cast(proxyBroker); } + +template +inline sptr hdi_objcast(const sptr &iface) +{ + IProxyBroker *brokerObject = static_cast *>(iface.GetRefPtr()); + return brokerObject->AsObject(); +} } // namespace HDI } // namespace OHOS -- Gitee From 12f2e4b31c0a7368b5ddf71d54398b55a03c4801 Mon Sep 17 00:00:00 2001 From: guodongqi Date: Thu, 28 Apr 2022 14:13:58 +0800 Subject: [PATCH 067/102] fix: fix unpackaged shared library Signed-off-by: guodongqi --- uhdf2/hdi/test/BUILD.gn | 1 - 1 file changed, 1 deletion(-) diff --git a/uhdf2/hdi/test/BUILD.gn b/uhdf2/hdi/test/BUILD.gn index 2ff57be..65aac55 100644 --- a/uhdf2/hdi/test/BUILD.gn +++ b/uhdf2/hdi/test/BUILD.gn @@ -65,7 +65,6 @@ group("unittest") { deps = [ ":HdiServiceManagerTest", ":HdiServiceManagerTestCC", - "hdi_sample/sample_client_cpp:HdiSampleTestCC", "hdi_sample/sample_client_cpp/unittest:sample_client_cpp", "hdi_sample/sample_service_cpp:sample_service_cpp", ] -- Gitee From 27b8222a3d528619fb12137c9de5f7827c7c3725 Mon Sep 17 00:00:00 2001 From: s00442234 Date: Thu, 28 Apr 2022 20:44:37 +0800 Subject: [PATCH 068/102] add dfx dumper Signed-off-by: s00442234 --- khdf/liteos/platform/BUILD.gn | 3 ++- khdf/liteos/platform/Makefile | 3 ++- khdf/liteos/test/BUILD.gn | 3 ++- khdf/liteos/test/Makefile | 3 ++- uhdf/test/unittest/platform/BUILD.gn | 4 +++- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/khdf/liteos/platform/BUILD.gn b/khdf/liteos/platform/BUILD.gn index d4b0319..8fa3e82 100644 --- a/khdf/liteos/platform/BUILD.gn +++ b/khdf/liteos/platform/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -35,6 +35,7 @@ hdf_driver(module_name) { sources = [ "$HDF_FRAMEWORKS_PATH/support/platform/src/fwk/platform_common.c", "$HDF_FRAMEWORKS_PATH/support/platform/src/fwk/platform_device.c", + "$HDF_FRAMEWORKS_PATH/support/platform/src/fwk/platform_dumper.c", "$HDF_FRAMEWORKS_PATH/support/platform/src/fwk/platform_event.c", "$HDF_FRAMEWORKS_PATH/support/platform/src/fwk/platform_manager.c", "$HDF_FRAMEWORKS_PATH/support/platform/src/fwk/platform_queue.c", diff --git a/khdf/liteos/platform/Makefile b/khdf/liteos/platform/Makefile index d9bb550..781fd77 100644 --- a/khdf/liteos/platform/Makefile +++ b/khdf/liteos/platform/Makefile @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -41,6 +41,7 @@ ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM), y) $(HDF_FRAMEWORKS)/support/platform/src/fwk/platform_event.c \ $(HDF_FRAMEWORKS)/support/platform/src/fwk/platform_manager.c \ $(HDF_FRAMEWORKS)/support/platform/src/fwk/platform_queue.c \ + $(HDF_FRAMEWORKS)/support/platform/src/fwk/platform_dumper.c \ $(HDF_FRAMEWORKS)/support/platform/src/fwk/platform_common.c endif diff --git a/khdf/liteos/test/BUILD.gn b/khdf/liteos/test/BUILD.gn index b6f2934..c56474b 100755 --- a/khdf/liteos/test/BUILD.gn +++ b/khdf/liteos/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -82,6 +82,7 @@ hdf_driver(module_name) { sources += [ "$HDF_TEST_FRAMWORK_ROOT/platform/common/platform_device_test.c", "$HDF_TEST_FRAMWORK_ROOT/platform/common/platform_driver_test.c", + "$HDF_TEST_FRAMWORK_ROOT/platform/common/platform_dumper_test.c", "$HDF_TEST_FRAMWORK_ROOT/platform/common/platform_event_test.c", "$HDF_TEST_FRAMWORK_ROOT/platform/common/platform_manager_test.c", "$HDF_TEST_FRAMWORK_ROOT/platform/common/platform_queue_test.c", diff --git a/khdf/liteos/test/Makefile b/khdf/liteos/test/Makefile index 54c1412..d5441e0 100755 --- a/khdf/liteos/test/Makefile +++ b/khdf/liteos/test/Makefile @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -65,6 +65,7 @@ ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM), y) LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_driver_test.c LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_event_test.c LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_queue_test.c +LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_dumper_test.c LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_device_test.c LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_manager_test.c LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/entry/hdf_platform_core_entry_test.c diff --git a/uhdf/test/unittest/platform/BUILD.gn b/uhdf/test/unittest/platform/BUILD.gn index 236f3a2..11c9b3a 100644 --- a/uhdf/test/unittest/platform/BUILD.gn +++ b/uhdf/test/unittest/platform/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -39,6 +39,7 @@ if (board_name == "hi3516dv300" || board_name == "hispark_taurus") { "//drivers/framework/support/platform/test/unittest/common/hdf_adc_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_gpio_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_platform_device_test.cpp", + "//drivers/framework/support/platform/test/unittest/common/hdf_platform_dumper_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_platform_event_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_platform_manager_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_platform_queue_test.cpp", @@ -114,6 +115,7 @@ if (board_name == "hi3516dv300" || board_name == "hispark_taurus") { defines = [ "__USER__" ] sources = [ "//drivers/framework/support/platform/test/unittest/common/hdf_platform_device_test.cpp", + "//drivers/framework/support/platform/test/unittest/common/hdf_platform_dumper_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_platform_event_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_platform_manager_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_platform_queue_test.cpp", -- Gitee From 0db5ef430ab1dad2766eebbadca2488af571cdee Mon Sep 17 00:00:00 2001 From: haizhouyang Date: Fri, 29 Apr 2022 14:27:23 +0800 Subject: [PATCH 069/102] Add CANBUS framework support on liteos Signed-off-by: haizhouyang --- khdf/liteos/Kconfig | 7 +++++++ khdf/liteos/hdf.gni | 1 + khdf/liteos/platform/BUILD.gn | 12 ++++++++++++ khdf/liteos/platform/Makefile | 10 ++++++++++ 4 files changed, 30 insertions(+) diff --git a/khdf/liteos/Kconfig b/khdf/liteos/Kconfig index 8b9bd8f..6725970 100644 --- a/khdf/liteos/Kconfig +++ b/khdf/liteos/Kconfig @@ -193,6 +193,13 @@ config DRIVERS_HDF_PLATFORM_TIMER help Answer Y to enable HDF platform timer driver. +config DRIVERS_HDF_PLATFORM_CAN + bool "Enable HDF platform can bus driver" + default n + depends on DRIVERS_HDF_PLATFORM + help + Answer Y to enable HDF platform can bus driver. + config DRIVERS_HIEDMAC bool "Enable HIEDMAC" default n diff --git a/khdf/liteos/hdf.gni b/khdf/liteos/hdf.gni index 9acc618..c76eb70 100644 --- a/khdf/liteos/hdf.gni +++ b/khdf/liteos/hdf.gni @@ -31,6 +31,7 @@ import("//kernel/liteos_a/liteos.gni") HDF_FRAMEWORKS_PATH = "//drivers/framework" HDF_PERIPHERAL_PATH = "//drivers/peripheral" +HDF_ADAPTERS_PATH = "//drivers/adapter" template("hdf_driver") { if (defined(invoker.module_switch)) { diff --git a/khdf/liteos/platform/BUILD.gn b/khdf/liteos/platform/BUILD.gn index d4b0319..a02b396 100644 --- a/khdf/liteos/platform/BUILD.gn +++ b/khdf/liteos/platform/BUILD.gn @@ -195,6 +195,18 @@ hdf_driver(module_name) { ] } + if (defined(LOSCFG_DRIVERS_HDF_PLATFORM_CAN)) { + sources += [ + "$HDF_FRAMEWORKS_PATH/support/platform/src/can/can_client.c", + "$HDF_FRAMEWORKS_PATH/support/platform/src/can/can_core.c", + "$HDF_FRAMEWORKS_PATH/support/platform/src/can/can_if.c", + "$HDF_FRAMEWORKS_PATH/support/platform/src/can/can_mail.c", + "$HDF_FRAMEWORKS_PATH/support/platform/src/can/can_manager.c", + "$HDF_FRAMEWORKS_PATH/support/platform/src/can/can_msg.c", + "$HDF_FRAMEWORKS_PATH/support/platform/src/can/can_service.c", + ] + } + public_configs = [ ":public" ] } diff --git a/khdf/liteos/platform/Makefile b/khdf/liteos/platform/Makefile index d9bb550..30e6c9c 100644 --- a/khdf/liteos/platform/Makefile +++ b/khdf/liteos/platform/Makefile @@ -163,4 +163,14 @@ ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_TIMER), y) $(HDF_FRAMEWORKS)/support/platform/src/timer/timer_core.c endif +ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_CAN), y) + LOCAL_SRCS += $(HDF_FRAMEWORKS)/support/platform/src/can/can_client.c \ + $(HDF_FRAMEWORKS)/support/platform/src/can/can_core.c \ + $(HDF_FRAMEWORKS)/support/platform/src/can/can_if.c \ + $(HDF_FRAMEWORKS)/support/platform/src/can/can_mail.c \ + $(HDF_FRAMEWORKS)/support/platform/src/can/can_manager.c \ + $(HDF_FRAMEWORKS)/support/platform/src/can/can_msg.c \ + $(HDF_FRAMEWORKS)/support/platform/src/can/can_service.c +endif + include $(HDF_DRIVER) -- Gitee From 2ced7de43ae6a40831f8088f4508b8af88ec3179 Mon Sep 17 00:00:00 2001 From: yue Date: Fri, 29 Apr 2022 15:40:18 +0800 Subject: [PATCH 070/102] feat:support hdi passthrought mode Signed-off-by: yue --- uhdf2/hdi.gni | 12 ++--- uhdf2/hdi/src/hdi_support.cpp | 75 +++++++++++++++++++++++------- uhdf2/hdi/src/object_collector.cpp | 15 ++++-- 3 files changed, 76 insertions(+), 26 deletions(-) diff --git a/uhdf2/hdi.gni b/uhdf2/hdi.gni index 5868103..d620918 100755 --- a/uhdf2/hdi.gni +++ b/uhdf2/hdi.gni @@ -50,9 +50,7 @@ template("hdi") { config("hdi_public_config") { include_dirs = [ - "$hdf_uhdf_path/include/hdi", "$hdf_uhdf_path/include/host", - "$hdf_uhdf_path/ipc/include", "${files_info.root_package_dir}", "${files_info.version_dir}", ] @@ -121,9 +119,10 @@ template("hdi") { public_configs = [ ":hdi_public_config" ] - deps = [ + deps = [ "$hdi_gen" ] + + public_deps = [ "$hdf_uhdf_path/hdi:libhdi", - "$hdi_gen", "//drivers/adapter/uhdf2/ipc:libhdf_ipc_adapter", "//drivers/adapter/uhdf2/utils:libhdf_utils", ] @@ -164,9 +163,10 @@ template("hdi") { public_configs = [ ":hdi_public_config" ] - deps = [ + deps = [ "$hdi_gen" ] + + public_deps = [ "$hdf_uhdf_path/hdi:libhdi", - "$hdi_gen", "//drivers/adapter/uhdf2/ipc:libhdf_ipc_adapter", "//drivers/adapter/uhdf2/utils:libhdf_utils", ] diff --git a/uhdf2/hdi/src/hdi_support.cpp b/uhdf2/hdi/src/hdi_support.cpp index fae506a..91d8fca 100644 --- a/uhdf2/hdi/src/hdi_support.cpp +++ b/uhdf2/hdi/src/hdi_support.cpp @@ -15,6 +15,7 @@ #include "hdi_support.h" #include +#include #include #include #include @@ -33,37 +34,76 @@ #endif namespace { -constexpr int VERSION_SIZE = 2; -constexpr size_t INTERFACE_SIZE = 5; -constexpr size_t INTERFACE_VERSION_INDEX = 3; -constexpr size_t INTERFACE_NAME_INDEX = 2; +constexpr size_t INTERFACE_MATCH_RESIZE = 4; +constexpr size_t INTERFACE_VERSION_MAJOR_INDEX = 1; +constexpr size_t INTERFACE_VERSION_MINOR_INDEX = 2; +constexpr size_t INTERFACE_NAME_INDEX = 3; +static const std::regex reInfDesc("[a-zA-Z_][a-zA-Z0-9_]*(?:\\.[a-zA-Z_][a-zA-Z0-9_]*)*\\." + "[V|v]([0-9]+)_([0-9]+)\\." + "([a-zA-Z_][a-zA-Z0-9_]*)"); } // namespace -static int ParseInterface( - const std::string &fullName, std::string &interface, uint32_t &versionMajor, uint32_t &versionMinor) +static int32_t ParseInterface(const std::string &fullName, std::string &interface, uint32_t &versionMajor, + uint32_t &versionMinor) { - std::vector spInfo; - OHOS::SplitStr(fullName, ".", spInfo, false, true); - if (spInfo.size() != INTERFACE_SIZE) { - HDF_LOGE("invlid interface format"); + std::smatch result; + if (!std::regex_match(fullName, result, reInfDesc)) { + HDF_LOGE("invalid format of interface descriptor '%{public}s'", fullName.c_str()); return HDF_FAILURE; } - interface = spInfo[INTERFACE_NAME_INDEX]; - int ret = sscanf_s(spInfo[INTERFACE_VERSION_INDEX].data(), "V%u_%u", &versionMajor, &versionMinor); - if (ret != VERSION_SIZE) { - HDF_LOGE("failed to get interface version\n"); + if (result.size() < INTERFACE_MATCH_RESIZE) { + HDF_LOGE("failed to parse interface descriptor '%{public}s'", fullName.c_str()); + return HDF_FAILURE; + } + + versionMajor = std::stoul(result[INTERFACE_VERSION_MAJOR_INDEX]); + versionMinor = std::stoul(result[INTERFACE_VERSION_MINOR_INDEX]); + std::string interfaceName = result[INTERFACE_NAME_INDEX]; + + interface = interfaceName[0] == 'I' ? interfaceName.substr(1) : interfaceName; + if (interface.empty()) { + HDF_LOGE("failed to get invalid interface name"); return HDF_FAILURE; } return HDF_SUCCESS; } +static std::string TransFileName(const std::string& interfaceName) +{ + if (interfaceName.empty()) { + return interfaceName; + } + + std::string result; + for (size_t i = 0; i < interfaceName.size(); i++) { + char c = interfaceName[i]; + if (std::isupper(c) != 0) { + if (i > 1) { + result += '_'; + } + result += std::tolower(c); + } else { + result += c; + } + } + return result; +} + +/* + * interface descriptor name: ohos.hdi.sample.v1_0.IFoo + * interface: Foo + * versionMajor: 1 + * versionMinor: 0 + * library name: libfoo_service_1.0.z.so + * method name: FooImplGetInstance + */ void *LoadHdiImpl(const char *fullIfName) { char path[PATH_MAX + 1] = {0}; char resolvedPath[PATH_MAX + 1] = {0}; - // interface name like "OHOS.HDI.Sample.V1_0.IFoo", the last two are version and interface name + // interface descriptor name like "ohos.hdi.sample.v1_0.IFoo", the last two are version and interface base name if (fullIfName == nullptr) { HDF_LOGE("fullIfName is nullptr"); return nullptr; @@ -78,9 +118,10 @@ void *LoadHdiImpl(const char *fullIfName) HDF_LOGE("failed to parse hdi interface info"); return nullptr; } - // hdi implement name like libsample_service_1.0.z.so + + // hdi implement name like libfoo_service_1.0.z.so if (snprintf_s(path, sizeof(path), sizeof(path) - 1, "%s/lib%s_service_%u.%u.z.so", HDI_SO_PATH, - OHOS::LowerStr(interfaceName).data(), versionMajor, versionMinor) < 0) { + TransFileName(interfaceName).data(), versionMajor, versionMinor) < 0) { HDF_LOGE("%{public}s snprintf_s failed", __func__); return nullptr; } diff --git a/uhdf2/hdi/src/object_collector.cpp b/uhdf2/hdi/src/object_collector.cpp index 8b99b84..7e1c69a 100644 --- a/uhdf2/hdi/src/object_collector.cpp +++ b/uhdf2/hdi/src/object_collector.cpp @@ -18,6 +18,7 @@ #include "hdf_base.h" #include "hdf_log.h" +#include "osal_time.h" using namespace OHOS::HDI; @@ -67,15 +68,23 @@ OHOS::sptr ObjectCollector::NewObject( OHOS::sptr ObjectCollector::GetOrNewObject( const OHOS::sptr &interface, const std::u16string &interfaceName) { - std::lock_guard lock(mutex_); - + mutex_.lock(); +RETRY: auto it = interfaceObjectCollector_.find(interface.GetRefPtr()); if (it != interfaceObjectCollector_.end()) { + if (it->second->GetSptrRefCount() == 0) { + // may object is releasing, yield to sync + mutex_.unlock(); + OsalMSleep(1); + mutex_.lock(); + goto RETRY; + } + mutex_.unlock(); return it->second; } sptr object = NewObjectLocked(interface, interfaceName); interfaceObjectCollector_[interface.GetRefPtr()] = object.GetRefPtr(); - + mutex_.unlock(); return object; } -- Gitee From 21f511ebed2024e1c6810274da7c5da0116ac5e7 Mon Sep 17 00:00:00 2001 From: s00442234 Date: Sat, 7 May 2022 14:10:31 +0800 Subject: [PATCH 071/102] add dfx trace Signed-off-by: s00442234 --- khdf/liteos/Kconfig | 9 +- khdf/liteos/platform/BUILD.gn | 9 +- khdf/liteos/platform/Makefile | 7 +- khdf/liteos/platform/src/platform_trace.c | 141 ++++++++++++++++++++++ khdf/liteos/test/BUILD.gn | 7 +- khdf/liteos/test/Makefile | 5 +- uhdf/test/unittest/platform/BUILD.gn | 3 +- 7 files changed, 175 insertions(+), 6 deletions(-) create mode 100644 khdf/liteos/platform/src/platform_trace.c diff --git a/khdf/liteos/Kconfig b/khdf/liteos/Kconfig index 8b9bd8f..ad266cc 100644 --- a/khdf/liteos/Kconfig +++ b/khdf/liteos/Kconfig @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -185,6 +185,13 @@ config DRIVERS_HDF_PLATFORM_WATCHDOG depends on DRIVERS_HDF_PLATFORM help Answer Y to enable HDF platform watchdog driver. + +config DRIVERS_HDF_PLATFORM_TRACE + bool "Enable HDF platform trace driver" + default n + depends on DRIVERS_HDF_PLATFORM + help + Answer Y to enable HDF platform trace driver. config DRIVERS_HDF_PLATFORM_TIMER bool "Enable HDF platform timer driver" diff --git a/khdf/liteos/platform/BUILD.gn b/khdf/liteos/platform/BUILD.gn index d4b0319..14c3cb0 100644 --- a/khdf/liteos/platform/BUILD.gn +++ b/khdf/liteos/platform/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -41,6 +41,13 @@ hdf_driver(module_name) { "src/plat_common.c", ] + if (defined(LOSCFG_DRIVERS_HDF_PLATFORM_TRACE)) { + sources += [ + "$HDF_FRAMEWORKS_PATH/support/platform/src/fwk/platform_trace_transfer.c", + "src/platform_trace.c", + ] + } + if (defined(LOSCFG_DRIVERS_HDF_PLATFORM_I2C)) { sources += [ "$HDF_FRAMEWORKS_PATH/support/platform/src/i2c/i2c_core.c", diff --git a/khdf/liteos/platform/Makefile b/khdf/liteos/platform/Makefile index d9bb550..07fe935 100644 --- a/khdf/liteos/platform/Makefile +++ b/khdf/liteos/platform/Makefile @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -44,6 +44,11 @@ ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM), y) $(HDF_FRAMEWORKS)/support/platform/src/fwk/platform_common.c endif +ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_TRACE), y) + LOCAL_SRCS += ./src/platform_trace.c \ + $(HDF_FRAMEWORKS)/support/platform/src/fwk/platform_trace_transfer.c +endif + ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_I2C), y) LOCAL_SRCS += $(HDF_FRAMEWORKS)/support/platform/src/i2c/i2c_if.c \ $(HDF_FRAMEWORKS)/support/platform/src/i2c/i2c_core.c diff --git a/khdf/liteos/platform/src/platform_trace.c b/khdf/liteos/platform/src/platform_trace.c new file mode 100644 index 0000000..76cb2b6 --- /dev/null +++ b/khdf/liteos/platform/src/platform_trace.c @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "platform_trace.h" +#include "hdf_base.h" +#include "hdf_log.h" +#include "los_trace.h" + +int32_t PlatformTraceStart(void) +{ +#ifdef LOSCFG_KERNEL_TRACE + uint32_t ret; + ret = LOS_TraceStart(); + if (ret != LOS_OK) { + HDF_LOGE("PlatformTraceStart error:%d", ret); + return HDF_FAILURE; + } +#endif + return HDF_SUCCESS; +} + +int32_t PlatformTraceStop(void) +{ +#ifdef LOSCFG_KERNEL_TRACE + LOS_TraceStop(); +#endif + return HDF_SUCCESS; +} + +void PlatformTraceReset(void) +{ +#ifdef LOSCFG_KERNEL_TRACE + LOS_TraceReset(); +#endif +} + +#ifdef LOSCFG_KERNEL_TRACE +static void TraceMeanPrint(void) +{ + uint32_t i = 0; + dprintf("********trace moudle and function explain:********\t"); + const struct PlatformTraceModuleExplain *explains = PlatformTraceModuleExplainGetAll(); + int32_t size = PlatformTraceModuleExplainCount(); + for (i = 0; i < size; i++) { + if (explains[i].moduleInfo < PLATFORM_TRACE_MODULE_MAX) { + dprintf("meaning of module num 0x%x is %s\t", explains[i].moduleInfo, explains[i].moduleMean); + } else if (explains[i].moduleInfo > PLATFORM_TRACE_MODULE_MAX) { + dprintf("meaning of function num 0x%x is %s\t", explains[i].moduleInfo, explains[i].moduleMean); + } + } +} +#endif + +void PlatformTraceInfoDump(void) +{ +#ifdef LOSCFG_KERNEL_TRACE + TraceMeanPrint(); + LOS_TraceRecordDump(FALSE); +#endif +} + +#define PLATFORM_TRACE_IDENTIFY 0x33 +void PlatformTraceAddUintMsg(int module, int moduleFun, uint infos[], uint8_t size) +{ +#ifdef LOSCFG_KERNEL_TRACE + if ((size <= 0) || (size > PLATFORM_TRACE_UINT_PARAM_SIZE_MAX)) { + HDF_LOGE("PlatformTraceAddUintMsg %hhu size illegal", size); + return; + } + if ((module < PLATFORM_TRACE_MODULE_I2S) || (module >= PLATFORM_TRACE_MODULE_MAX)) { + HDF_LOGE("PlatformTraceAddUintMsg %d module illegal", module); + return; + } + if ((moduleFun < PLATFORM_TRACE_MODULE_I2S_FUN) || (moduleFun >= PLATFORM_TRACE_MODULE_MAX_FUN)) { + HDF_LOGE("PlatformTraceAddUintMsg %d moduleFun illegal", moduleFun); + return; + } + + switch (size) { + case PLATFORM_TRACE_UINT_PARAM_SIZE_1: + LOS_TRACE_EASY(TRACE_SYS_FLAG, PLATFORM_TRACE_IDENTIFY, module, moduleFun, + infos[PLATFORM_TRACE_UINT_PARAM_SIZE_1 - 1]); + break; + case PLATFORM_TRACE_UINT_PARAM_SIZE_2: + LOS_TRACE_EASY(TRACE_SYS_FLAG, PLATFORM_TRACE_IDENTIFY, module, moduleFun, + infos[PLATFORM_TRACE_UINT_PARAM_SIZE_1 - 1], infos[PLATFORM_TRACE_UINT_PARAM_SIZE_2 - 1]); + break; + case PLATFORM_TRACE_UINT_PARAM_SIZE_3: + LOS_TRACE_EASY(TRACE_SYS_FLAG, PLATFORM_TRACE_IDENTIFY, module, moduleFun, + infos[PLATFORM_TRACE_UINT_PARAM_SIZE_1 - 1], infos[PLATFORM_TRACE_UINT_PARAM_SIZE_2 - 1], + infos[PLATFORM_TRACE_UINT_PARAM_SIZE_3 - 1]); + break; + case PLATFORM_TRACE_UINT_PARAM_SIZE_4: + LOS_TRACE_EASY(TRACE_SYS_FLAG, PLATFORM_TRACE_IDENTIFY, module, moduleFun, + infos[PLATFORM_TRACE_UINT_PARAM_SIZE_1 - 1], infos[PLATFORM_TRACE_UINT_PARAM_SIZE_2 - 1], + infos[PLATFORM_TRACE_UINT_PARAM_SIZE_3 - 1], infos[PLATFORM_TRACE_UINT_PARAM_SIZE_4 - 1]); + break; + case PLATFORM_TRACE_UINT_PARAM_SIZE_MAX: + LOS_TRACE_EASY(TRACE_SYS_FLAG, PLATFORM_TRACE_IDENTIFY, module, moduleFun, + infos[PLATFORM_TRACE_UINT_PARAM_SIZE_1 - 1], infos[PLATFORM_TRACE_UINT_PARAM_SIZE_2 - 1], + infos[PLATFORM_TRACE_UINT_PARAM_SIZE_3 - 1], infos[PLATFORM_TRACE_UINT_PARAM_SIZE_4 - 1], + infos[PLATFORM_TRACE_UINT_PARAM_SIZE_MAX - 1]); + break; + default: + HDF_LOGE("PlatformTraceAddUintMsg %hhu size illegal", size); + break; + } +#endif +} + +void PlatformTraceAddMsg(const char *module, const char *moduleFun, const char *fmt, ...) +{ + // not support, return + return; +} diff --git a/khdf/liteos/test/BUILD.gn b/khdf/liteos/test/BUILD.gn index b6f2934..be9d667 100755 --- a/khdf/liteos/test/BUILD.gn +++ b/khdf/liteos/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -88,6 +88,11 @@ hdf_driver(module_name) { "$HDF_TEST_FRAMWORK_ROOT/platform/entry/hdf_platform_core_entry_test.c", ] + if (defined(LOSCFG_DRIVERS_HDF_PLATFORM_TRACE)) { + sources += + [ "$HDF_TEST_FRAMWORK_ROOT/platform/common/platform_trace_test.c" ] + } + if (defined(LOSCFG_DRIVERS_HDF_PLATFORM_GPIO)) { sources += [ "$HDF_TEST_FRAMWORK_ROOT/platform/common/gpio_driver_test.c", diff --git a/khdf/liteos/test/Makefile b/khdf/liteos/test/Makefile index 54c1412..3a8e8ed 100755 --- a/khdf/liteos/test/Makefile +++ b/khdf/liteos/test/Makefile @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -68,6 +68,9 @@ LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_queue_test.c LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_device_test.c LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_manager_test.c LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/entry/hdf_platform_core_entry_test.c +ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_TRACE), y) +LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_trace_test.c +endif ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_GPIO), y) LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/gpio_test.c LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/gpio_driver_test.c diff --git a/uhdf/test/unittest/platform/BUILD.gn b/uhdf/test/unittest/platform/BUILD.gn index 236f3a2..2124153 100644 --- a/uhdf/test/unittest/platform/BUILD.gn +++ b/uhdf/test/unittest/platform/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -42,6 +42,7 @@ if (board_name == "hi3516dv300" || board_name == "hispark_taurus") { "//drivers/framework/support/platform/test/unittest/common/hdf_platform_event_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_platform_manager_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_platform_queue_test.cpp", + "//drivers/framework/support/platform/test/unittest/common/hdf_platform_trace_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_pwm_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_regulator_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_rtc_test.cpp", -- Gitee From 5e3ea3f1f4abcda0cd4ff11696ecb247848e54af Mon Sep 17 00:00:00 2001 From: yuanbo Date: Sat, 7 May 2022 14:52:53 +0800 Subject: [PATCH 072/102] fix: add hdf_devmgr secontext Signed-off-by: yuanbo --- uhdf2/manager/hdf_devmgr.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/uhdf2/manager/hdf_devmgr.cfg b/uhdf2/manager/hdf_devmgr.cfg index f109028..0596505 100644 --- a/uhdf2/manager/hdf_devmgr.cfg +++ b/uhdf2/manager/hdf_devmgr.cfg @@ -4,6 +4,7 @@ "path" : ["/vendor/bin/hdf_devmgr"], "uid" : "root", "gid" : ["system"], + "secon" : "u:r:hdf_devmgr:s0", "start-mode" : "boot" } ] -- Gitee From e7a7a866450dc54e4a3dcfa58537cde58d03df26 Mon Sep 17 00:00:00 2001 From: zhang Date: Wed, 27 Apr 2022 17:26:33 +0800 Subject: [PATCH 073/102] fix:add command line to query device information and debug hdi Signed-off-by: zhang --- BUILD.gn | 1 + uhdf2/hdi/src/idevmgr_client.cpp | 45 +++++++++++- uhdf2/hdi/src/iservmgr_client.cpp | 39 ++++++++++- uhdf2/host/include/devsvc_manager_proxy.h | 3 +- uhdf2/host/src/devhost_service_stub.c | 77 ++++++++++++--------- uhdf2/include/hdi/idevmgr_hdi.h | 10 ++- uhdf2/include/hdi/iservmgr_hdi.h | 9 ++- uhdf2/manager/include/devmgr_service_stub.h | 3 +- uhdf2/manager/src/devmgr_service_stub.c | 15 +++- uhdf2/manager/src/devsvc_manager_stub.c | 35 +++++++++- 10 files changed, 197 insertions(+), 40 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 3154017..896f53e 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -40,6 +40,7 @@ if (defined(ohos_lite)) { "//drivers/adapter/uhdf2/manager:hdf_devmgr.cfg", "//drivers/adapter/uhdf2/platform:libhdf_platform", "//drivers/adapter/uhdf2/utils:libhdf_utils", + "//drivers/framework/tools/hdf_dbg:hdf_dbg", "//drivers/peripheral/base:hdf_peripheral.cfg", ] } diff --git a/uhdf2/hdi/src/idevmgr_client.cpp b/uhdf2/hdi/src/idevmgr_client.cpp index 8536a33..643d81f 100644 --- a/uhdf2/hdi/src/idevmgr_client.cpp +++ b/uhdf2/hdi/src/idevmgr_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -35,6 +35,7 @@ enum DevmgrCmdId : uint32_t { DEVMGR_SERVICE_LOAD_DEVICE, DEVMGR_SERVICE_UNLOAD_DEVICE, DEVMGR_SERVICE_QUERY_DEVICE, + DEVMGR_SERVICE_LIST_ALL_DEVICE, }; class DeviceManagerProxy : public IProxyBroker { @@ -43,6 +44,7 @@ public: ~DeviceManagerProxy() {} int32_t LoadDevice(const std::string &serviceName) override; int32_t UnloadDevice(const std::string &serviceName) override; + int32_t ListAllDevice(std::vector &deviceInfos) override; private: static inline BrokerDelegator delegator_; @@ -88,6 +90,47 @@ int32_t DeviceManagerProxy::UnloadDevice(const std::string &serviceName) return status; } +static void HdfDevMgrDbgFillDeviceInfo(std::vector &deviceInfos, MessageParcel &reply) +{ + while (true) { + uint32_t devId; + uint32_t devCnt; + struct HdiDevHostInfo info; + const char *hostName = reply.ReadCString(); + if (hostName == nullptr) { + break; + } + info.hostName = hostName; + info.hostId = reply.ReadUint32(); + devCnt = reply.ReadUint32(); + for (uint32_t i = 0; i < devCnt; i++) { + devId = reply.ReadUint32(); + info.devId.push_back(devId); + } + deviceInfos.push_back(info); + } + return; +} + +int32_t DeviceManagerProxy::ListAllDevice(std::vector &deviceInfos) +{ + MessageParcel data; + MessageParcel reply; + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return HDF_FAILURE; + } + + MessageOption option; + int status = Remote()->SendRequest(DEVMGR_SERVICE_LIST_ALL_DEVICE, data, reply, option); + if (status != HDF_SUCCESS) { + HDF_LOGE("list all device info failed, %{public}d", status); + } else { + HdfDevMgrDbgFillDeviceInfo(deviceInfos, reply); + } + return status; +} + sptr IDeviceManager::Get() { auto servmgr = ServiceManager::V1_0::IServiceManager::Get(); diff --git a/uhdf2/hdi/src/iservmgr_client.cpp b/uhdf2/hdi/src/iservmgr_client.cpp index 27c8b29..8068390 100644 --- a/uhdf2/hdi/src/iservmgr_client.cpp +++ b/uhdf2/hdi/src/iservmgr_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -30,6 +30,7 @@ constexpr int DEVICE_SERVICE_MANAGER_SA_ID = 5100; constexpr int DEVSVC_MANAGER_GET_SERVICE = 3; constexpr int DEVSVC_MANAGER_REGISTER_SVCLISTENER = 4; constexpr int DEVSVC_MANAGER_UNREGISTER_SVCLISTENER = 5; +constexpr int DEVSVC_MANAGER_LIST_ALL_SERVICE = 6; class ServiceManagerProxy : public IProxyBroker { public: @@ -37,6 +38,7 @@ public: ~ServiceManagerProxy() {} sptr GetService(const char *serviceName) override; + int32_t ListAllService(std::vector &serviceInfos) override; int32_t RegisterServiceStatusListener(sptr listener, uint16_t deviceClass) override; int32_t UnregisterServiceStatusListener(sptr listener) override; @@ -113,6 +115,41 @@ sptr ServiceManagerProxy::GetService(const char *serviceName) HDF_LOGD("get hdi service %{public}s success ", serviceName); return reply.ReadRemoteObject(); } + +static void HdfDevMgrDbgFillServiceInfo(std::vector &serviceInfos, MessageParcel &reply) +{ + while (true) { + HdiServiceInfo info; + const char *servName = reply.ReadCString(); + if (servName == nullptr) { + break; + } + info.serviceName = servName; + info.devClass = reply.ReadUint16(); + serviceInfos.push_back(info); + } + return; +} + +int32_t ServiceManagerProxy::ListAllService(std::vector &serviceInfos) +{ + MessageParcel data; + MessageParcel reply; + if (!data.WriteInterfaceToken(GetDescriptor())) { + return HDF_FAILURE; + } + + MessageOption option; + int status = Remote()->SendRequest(DEVSVC_MANAGER_LIST_ALL_SERVICE, data, reply, option); + if (status != HDF_SUCCESS) { + HDF_LOGE("list all service info failed, %{public}d", status); + return status; + } else { + HdfDevMgrDbgFillServiceInfo(serviceInfos, reply); + } + HDF_LOGD("get all service info success"); + return status; +} } // namespace V1_0 } // namespace ServiceManager } // namespace HDI diff --git a/uhdf2/host/include/devsvc_manager_proxy.h b/uhdf2/host/include/devsvc_manager_proxy.h index 8479845..c803510 100644 --- a/uhdf2/host/include/devsvc_manager_proxy.h +++ b/uhdf2/host/include/devsvc_manager_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -32,6 +32,7 @@ enum { DEVSVC_MANAGER_GET_SERVICE, DEVSVC_MANAGER_REGISTER_SVCLISTENER, DEVSVC_MANAGER_UNREGISTER_SVCLISTENER, + DEVSVC_MANAGER_LIST_ALL_SERVICE, DEVSVC_MANAGER_LIST_SERVICE, DEVSVC_MANAGER_REMOVE_SERVICE, }; diff --git a/uhdf2/host/src/devhost_service_stub.c b/uhdf2/host/src/devhost_service_stub.c index a5f6797..a30edae 100644 --- a/uhdf2/host/src/devhost_service_stub.c +++ b/uhdf2/host/src/devhost_service_stub.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -30,12 +30,52 @@ static void DevHostSetCurrentSecurec(const char *hostName) (void) hostName; } +static int DispatchAddDevice(struct IDevHostService *serviceIf, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + (void)reply; + if ((serviceIf == NULL) || (serviceIf->AddDevice == NULL)) { + HDF_LOGE("serviceIf or serviceIf->AddDevice is NULL"); + return HDF_FAILURE; + } + struct HdfDeviceInfo *attribute = DeviceAttributeDeserialize(data); + if (attribute == NULL) { + HDF_LOGE("Dispatch failed, attribute is null"); + return HDF_FAILURE; + } + HDF_LOGI("add device 0x%{public}x", attribute->deviceId); + int ret = serviceIf->AddDevice(serviceIf, attribute); + if (ret != HDF_SUCCESS) { + HDF_LOGE("Dispatch failed, add service failed and ret is %{public}d", ret); + } + DeviceSerializedAttributeRelease(attribute); + return ret; +} + +static int DispatchDelDevice(struct IDevHostService *serviceIf, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + uint32_t deviceId = 0; + (void)reply; + if ((serviceIf == NULL) || (serviceIf->DelDevice == NULL)) { + HDF_LOGE("serviceIf or serviceIf->DelDevice is NULL"); + return HDF_FAILURE; + } + if (!HdfSbufReadUint32(data, &deviceId)) { + HDF_LOGE("failed to del device, invalid device id"); + return HDF_FAILURE; + } + + HDF_LOGI("del device 0x%{public}x", deviceId); + int ret = serviceIf->DelDevice(serviceIf, deviceId); + if (ret != HDF_SUCCESS) { + HDF_LOGE("del service failed, ret is %{public}d", ret); + } + return ret; +} + static int DevHostServiceStubDispatch( struct HdfRemoteService *stub, int code, struct HdfSBuf *data, struct HdfSBuf *reply) { - (void)reply; int ret = HDF_FAILURE; - uint32_t deviceId = 0; if (stub == NULL || data == NULL) { return ret; } @@ -45,38 +85,11 @@ static int DevHostServiceStubDispatch( OsalMutexLock(&serviceStub->hostSvcMutex); switch (code) { case DEVHOST_SERVICE_ADD_DEVICE: { - if ((serviceIf == NULL) || (serviceIf->AddDevice == NULL)) { - HDF_LOGE("serviceIf or serviceIf->AddDevice is NULL"); - break; - } - struct HdfDeviceInfo *attribute = DeviceAttributeDeserialize(data); - if (attribute == NULL) { - HDF_LOGE("Dispatch failed, attribute is null"); - break; - } - HDF_LOGI("add device 0x%{public}x", attribute->deviceId); - ret = serviceIf->AddDevice(serviceIf, attribute); - if (ret != HDF_SUCCESS) { - HDF_LOGE("Dispatch failed, add service failed and ret is %{public}d", ret); - } - DeviceSerializedAttributeRelease(attribute); + ret = DispatchAddDevice(serviceIf, data, reply); break; } case DEVHOST_SERVICE_DEL_DEVICE: { - if ((serviceIf == NULL) || (serviceIf->DelDevice == NULL)) { - HDF_LOGE("serviceIf or serviceIf->DelDevice is NULL"); - break; - } - if (!HdfSbufReadUint32(data, &deviceId)) { - HDF_LOGE("failed to del device, invalid device id"); - break; - } - - HDF_LOGI("del device 0x%{public}x", deviceId); - ret = serviceIf->DelDevice(serviceIf, deviceId); - if (ret != HDF_SUCCESS) { - HDF_LOGE("del service failed, ret is %{public}d", ret); - } + ret = DispatchDelDevice(serviceIf, data, reply); break; } default: { diff --git a/uhdf2/include/hdi/idevmgr_hdi.h b/uhdf2/include/hdi/idevmgr_hdi.h index 0daf343..8e2abe0 100644 --- a/uhdf2/include/hdi/idevmgr_hdi.h +++ b/uhdf2/include/hdi/idevmgr_hdi.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -15,12 +15,19 @@ #ifndef HDI_DEVICE_MANAGER_HDI_INF_H #define HDI_DEVICE_MANAGER_HDI_INF_H +#include #include namespace OHOS { namespace HDI { namespace DeviceManager { namespace V1_0 { +struct HdiDevHostInfo { + std::string hostName; + uint32_t hostId; + std::vector devId; +}; + class IDeviceManager : public HdiBase { public: DECLARE_HDI_DESCRIPTOR(u"HDI.IDeviceManager.V1_0"); @@ -29,6 +36,7 @@ public: static ::OHOS::sptr Get(); virtual int32_t LoadDevice(const std::string &serviceName) = 0; virtual int32_t UnloadDevice(const std::string &serviceName) = 0; + virtual int32_t ListAllDevice(std::vector &deviceInfos) = 0; }; } // namespace V1_0 } // namespace DeviceManager diff --git a/uhdf2/include/hdi/iservmgr_hdi.h b/uhdf2/include/hdi/iservmgr_hdi.h index c0cee12..1cb7414 100644 --- a/uhdf2/include/hdi/iservmgr_hdi.h +++ b/uhdf2/include/hdi/iservmgr_hdi.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -15,6 +15,7 @@ #ifndef HDI_ISERVICE_MANAGER_INF_H #define HDI_ISERVICE_MANAGER_INF_H +#include #include #include #include @@ -25,11 +26,17 @@ namespace OHOS { namespace HDI { namespace ServiceManager { namespace V1_0 { +struct HdiServiceInfo { + std::string serviceName; + uint16_t devClass; +}; + class IServiceManager : public HdiBase { public: DECLARE_HDI_DESCRIPTOR(u"HDI.IServiceManager.V1_0"); static ::OHOS::sptr Get(); virtual ::OHOS::sptr GetService(const char *serviceName) = 0; + virtual int32_t ListAllService(std::vector &serviceInfos) = 0; virtual int32_t RegisterServiceStatusListener(::OHOS::sptr listener, uint16_t deviceClass) = 0; virtual int32_t UnregisterServiceStatusListener(::OHOS::sptr listener) = 0; }; diff --git a/uhdf2/manager/include/devmgr_service_stub.h b/uhdf2/manager/include/devmgr_service_stub.h index c0ac543..45b02f2 100644 --- a/uhdf2/manager/include/devmgr_service_stub.h +++ b/uhdf2/manager/include/devmgr_service_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -35,6 +35,7 @@ enum { DEVMGR_SERVICE_LOAD_DEVICE, DEVMGR_SERVICE_UNLOAD_DEVICE, DEVMGR_SERVICE_QUERY_DEVICE, + DEVMGR_SERVICE_LIST_ALL_DEVICE, }; struct HdfObject *DevmgrServiceStubCreate(void); diff --git a/uhdf2/manager/src/devmgr_service_stub.c b/uhdf2/manager/src/devmgr_service_stub.c index fee2aa4..6fa9952 100644 --- a/uhdf2/manager/src/devmgr_service_stub.c +++ b/uhdf2/manager/src/devmgr_service_stub.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -82,6 +82,16 @@ static int32_t DevmgrServiceStubDispatchUnloadDevice(struct IDevmgrService *devm return devmgrSvc->UnloadDevice(devmgrSvc, serviceName); } +static int32_t DevmgrServiceStubDispatchListAllDevice(struct IDevmgrService *devmgrSvc, struct HdfSBuf *reply) +{ + if (devmgrSvc == NULL || reply == NULL) { + HDF_LOGE("%{public}s:service name is null", __func__); + return HDF_ERR_INVALID_PARAM; + } + HDF_LOGD("%{public}s:get all device info", __func__); + return devmgrSvc->ListAllDevice(devmgrSvc, reply); +} + int32_t DevmgrServiceStubDispatch(struct HdfRemoteService *stub, int code, struct HdfSBuf *data, struct HdfSBuf *reply) { int32_t ret = HDF_FAILURE; @@ -120,6 +130,9 @@ int32_t DevmgrServiceStubDispatch(struct HdfRemoteService *stub, int code, struc case DEVMGR_SERVICE_QUERY_DEVICE: ret = DevFillQueryDeviceInfo(super, data, reply); break; + case DEVMGR_SERVICE_LIST_ALL_DEVICE: + ret = DevmgrServiceStubDispatchListAllDevice(super, reply); + break; default: break; } diff --git a/uhdf2/manager/src/devsvc_manager_stub.c b/uhdf2/manager/src/devsvc_manager_stub.c index daf0d9b..43c7654 100644 --- a/uhdf2/manager/src/devsvc_manager_stub.c +++ b/uhdf2/manager/src/devsvc_manager_stub.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -57,6 +57,19 @@ static int32_t GetServicePermCheck(const char *servName) return HDF_SUCCESS; } +static int32_t ListServicePermCheck() +{ +#ifdef WITH_SELINUX + pid_t callingPid = HdfRemoteGetCallingPid(); + if (HdfListServiceCheck(callingPid) != 0) { + HDF_LOGE("[selinux] %{public}d haven't \"list service\" permission", callingPid); + return HDF_ERR_NOPERM; + } +#endif + + return HDF_SUCCESS; +} + static struct HdfDeviceObject *ObtainServiceObject( struct DevSvcManagerStub *stub, const char *name, struct HdfRemoteService *service) { @@ -221,6 +234,23 @@ static int32_t DevSvcManagerStubGetService(struct IDevSvcManager *super, struct return ret; } +static int32_t DevSvcManagerStubListAllService( + struct IDevSvcManager *super, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct DevSvcManagerStub *stub = (struct DevSvcManagerStub *)super; + if (!HdfRemoteServiceCheckInterfaceToken(stub->remote, data)) { + HDF_LOGE("%{public}s: invalid interface token", __func__); + return HDF_ERR_INVALID_PARAM; + } + int ret = ListServicePermCheck(); + if (ret != HDF_SUCCESS) { + return ret; + } + super->ListAllService(super, reply); + + return HDF_SUCCESS; +} + static int32_t DevSvcManagerStubRemoveService(struct IDevSvcManager *super, struct HdfSBuf *data) { struct DevSvcManagerStub *stub = (struct DevSvcManagerStub *)super; @@ -345,6 +375,9 @@ int DevSvcManagerStubDispatch(struct HdfRemoteService *service, int code, struct case DEVSVC_MANAGER_UNREGISTER_SVCLISTENER: ret = DevSvcManagerStubUnregisterServListener(super, data); break; + case DEVSVC_MANAGER_LIST_ALL_SERVICE: + ret = DevSvcManagerStubListAllService(super, data, reply); + break; default: HDF_LOGE("Unknown code : %{public}d", code); ret = HDF_FAILURE; -- Gitee From 20ec81db9210b513bdc91618722c359bdb9c41ac Mon Sep 17 00:00:00 2001 From: yanghaizhou Date: Mon, 9 May 2022 20:50:17 +0800 Subject: [PATCH 074/102] Add can bus driver support on liteos Signed-off-by: yanghaizhou --- khdf/liteos/test/BUILD.gn | 10 +- khdf/liteos/test/Makefile | 7 +- platform/can/can_virtual.c | 366 +++++++++++++++++++++++++++ uhdf/test/unittest/platform/BUILD.gn | 1 + 4 files changed, 382 insertions(+), 2 deletions(-) create mode 100644 platform/can/can_virtual.c diff --git a/khdf/liteos/test/BUILD.gn b/khdf/liteos/test/BUILD.gn index e7492da..553b67a 100755 --- a/khdf/liteos/test/BUILD.gn +++ b/khdf/liteos/test/BUILD.gn @@ -86,7 +86,7 @@ hdf_driver(module_name) { "$HDF_TEST_FRAMWORK_ROOT/platform/common/platform_event_test.c", "$HDF_TEST_FRAMWORK_ROOT/platform/common/platform_manager_test.c", "$HDF_TEST_FRAMWORK_ROOT/platform/common/platform_queue_test.c", - "$HDF_TEST_FRAMWORK_ROOT/platform/entry/hdf_platform_core_entry_test.c", + "$HDF_TEST_FRAMWORK_ROOT/platform/entry/hdf_platform_entry_test.c", ] if (defined(LOSCFG_DRIVERS_HDF_PLATFORM_TRACE)) { @@ -248,6 +248,14 @@ hdf_driver(module_name) { "$HDF_TEST_FRAMWORK_ROOT/platform/entry/hdf_timer_entry_test.c", ] } + + if (defined(LOSCFG_DRIVERS_HDF_PLATFORM_CAN)) { + sources += [ + "$HDF_ADAPTERS_PATH/platform/can/can_virtual.c", + "$HDF_TEST_FRAMWORK_ROOT/platform/common/can_test.c", + "$HDF_TEST_FRAMWORK_ROOT/platform/config/can_test_config.c", + ] + } } if (defined(LOSCFG_DRIVERS_HDF_SENSOR)) { diff --git a/khdf/liteos/test/Makefile b/khdf/liteos/test/Makefile index df4b4b1..f979c60 100755 --- a/khdf/liteos/test/Makefile +++ b/khdf/liteos/test/Makefile @@ -31,6 +31,7 @@ include ./test_lite.mk MODULE_NAME := hdf_test HDF_TEST_FRAMWORK_ROOT = $(LITEOSTOPDIR)/../../drivers/framework/test/unittest +HDF_ADAPTERS_ROOT = $(LITEOSTOPDIR)/../../drivers/adapter LOCAL_SRCS := $(HDF_TEST_FRAMWORK_ROOT)/common/hdf_main_test.c \ $(HDF_TEST_FRAMWORK_ROOT)/manager/sample_driver_test.c \ @@ -68,7 +69,7 @@ LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_queue_test.c LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_dumper_test.c LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_device_test.c LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_manager_test.c -LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/entry/hdf_platform_core_entry_test.c +LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/entry/hdf_platform_entry_test.c ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_TRACE), y) LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_trace_test.c endif @@ -163,6 +164,10 @@ LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/timer_driver_test.c LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/timer_test.c LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/entry/hdf_timer_entry_test.c endif +ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_CAN), y) +LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/can_test.c +LOCAL_SRCS += $(HDF_ADAPTERS_ROOT)/platform/can/can_virtual.c +endif endif ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_REGULATOR), y) diff --git a/platform/can/can_virtual.c b/platform/can/can_virtual.c new file mode 100644 index 0000000..1c8dc77 --- /dev/null +++ b/platform/can/can_virtual.c @@ -0,0 +1,366 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * This file is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include + +#include "can/can_core.h" +#include "device_resource_if.h" +#include "hdf_log.h" +#include "osal_mem.h" + +#define HDF_LOG_TAG can_virtual_c +#define CAN_VIRTUAL_BUS_NUM_DFT 31 + +struct VirtualCanCntlr { + struct CanCntlr cntlr; + uint8_t workMode; + uint32_t bitRate; + uint32_t syncJumpWidth; + uint32_t timeSeg1; + uint32_t timeSeg2; + uint32_t prescaler; + int32_t busState; +}; + +enum VIRTUAL_CAN_SPEED { + CAN_SPEED_1M = 1000UL * 1000, /* 1 MBit/sec */ + CAN_SPEED_800K = 1000UL * 800, /* 800 kBit/sec */ + CAN_SPEED_500K = 1000UL * 500, /* 500 kBit/sec */ + CAN_SPEED_250K = 1000UL * 250, /* 250 kBit/sec */ + CAN_SPEED_125K = 1000UL * 125, /* 125 kBit/sec */ + CAN_SPEED_100K = 1000UL * 100, /* 100 kBit/sec */ + CAN_SPEED_50K = 1000UL * 50, /* 50 kBit/sec */ + CAN_SPEED_20K = 1000UL * 20, /* 20 kBit/sec */ + CAN_SPEED_10K = 1000UL * 10 /* 10 kBit/sec */ +}; + +static int32_t VirtualReadConfigFromHcs(struct VirtualCanCntlr *virtualCan) +{ + uint32_t value; + const struct DeviceResourceNode *node = NULL; + struct DeviceResourceIface *iface = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + + if (virtualCan == NULL) { + HDF_LOGE("%s: virtual cntlr is null", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + node = PlatformDeviceGetDrs(&virtualCan->cntlr.device); + if (node == NULL) { + HDF_LOGE("%s: properity node null", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (iface == NULL || iface->GetUint32 == NULL) { + HDF_LOGE("%s: face is invalid", __func__); + return HDF_ERR_NOT_SUPPORT; + } + + if (iface->GetUint32(node, "bus_num", &value, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: read bus number failed", __func__); + return HDF_FAILURE; + } + virtualCan->cntlr.number = (int32_t)value; + + if (iface->GetUint8(node, "work_mode", &virtualCan->workMode, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: read work mode failed", __func__); + return HDF_FAILURE; + } + + if (iface->GetUint32(node, "bit_rate", &virtualCan->bitRate, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: read bit reate failed", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +static int32_t VirtualCanMsgLoopBack(struct VirtualCanCntlr *virtualCan, const struct CanMsg *msg) +{ + struct CanMsg *new = NULL; + + new = CanMsgObtain(); + if (new == NULL) { + return HDF_ERR_MALLOC_FAIL; + } + + *new = *msg; // Yeah! this is loop back ... + + virtualCan->busState = CAN_BUS_READY; + return CanCntlrOnNewMsg(&virtualCan->cntlr, new); +} + +static int32_t VirtualCanSendMsg(struct CanCntlr *cntlr, const struct CanMsg *msg) +{ + struct VirtualCanCntlr *virtualCan = NULL; + + if (cntlr == NULL) { + return HDF_ERR_INVALID_OBJECT; + } + + if (msg == NULL) { + return HDF_ERR_INVALID_PARAM; + } + + virtualCan = (struct VirtualCanCntlr *)cntlr->device.priv; + if (virtualCan == NULL) { + HDF_LOGE("%s: private data is null", __func__); + return HDF_ERR_INVALID_OBJECT; + } + virtualCan->busState = CAN_BUS_BUSY; + + return VirtualCanMsgLoopBack(virtualCan, msg); +} + +struct VirtualSpeedConfigMap { + uint32_t speed; + uint32_t sjw; + uint32_t tsg1; + uint32_t tsg2; + uint32_t prescaler; +}; + +#define CAN_CLK 80M + +#define CAN_SJW_2TQ 2 +#define CAN_BS1_5TQ 5 +#define CAN_BS1_7TQ 7 +#define CAN_BS1_13TQ 13 +#define CAN_BS1_14TQ 14 +#define CAN_BS2_2TQ 2 +#define CAN_BS2_5TQ 5 + +/* + * S(bit rate) = 1 / ((1 + BS1 + BS2) * TQ) + * TQ = Prescaler / Fclk + * S(bit rate) = Fclk / (Prescaler * (1 + BS1 + BS2)) + */ + +static const struct VirtualSpeedConfigMap g_speedMaps[] = { + {CAN_SPEED_1M, CAN_SJW_2TQ, CAN_BS1_5TQ, CAN_BS2_2TQ, 10 }, + {CAN_SPEED_800K, CAN_SJW_2TQ, CAN_BS1_14TQ, CAN_BS2_5TQ, 5 }, + {CAN_SPEED_500K, CAN_SJW_2TQ, CAN_BS1_7TQ, CAN_BS2_2TQ, 16 }, + {CAN_SPEED_250K, CAN_SJW_2TQ, CAN_BS1_13TQ, CAN_BS2_2TQ, 20 }, + {CAN_SPEED_125K, CAN_SJW_2TQ, CAN_BS1_13TQ, CAN_BS2_2TQ, 40 }, + {CAN_SPEED_100K, CAN_SJW_2TQ, CAN_BS1_13TQ, CAN_BS2_2TQ, 50 }, + {CAN_SPEED_50K, CAN_SJW_2TQ, CAN_BS1_13TQ, CAN_BS2_2TQ, 100}, + {CAN_SPEED_20K, CAN_SJW_2TQ, CAN_BS1_13TQ, CAN_BS2_2TQ, 250}, + {CAN_SPEED_10K, CAN_SJW_2TQ, CAN_BS1_13TQ, CAN_BS2_2TQ, 500} +}; + +static int32_t VirtualCanSetBitRate(struct VirtualCanCntlr *virtualCan, uint32_t speed) +{ + int32_t i; + const struct VirtualSpeedConfigMap *cfgMap; + + for (i = 0; i < sizeof(g_speedMaps) / sizeof(g_speedMaps[0]); i++) { + if (g_speedMaps[i].speed == speed) { + break; + } + } + + if (i >= (sizeof(g_speedMaps) / sizeof(g_speedMaps[0]))) { + HDF_LOGE("%s: speed: %u not support", __func__, speed); + return HDF_ERR_NOT_SUPPORT; + } + + cfgMap = &g_speedMaps[i]; + virtualCan->syncJumpWidth = cfgMap->sjw; + virtualCan->timeSeg1 = cfgMap->tsg1; + virtualCan->timeSeg2 = cfgMap->tsg2; + virtualCan->prescaler = cfgMap->prescaler; + virtualCan->bitRate = speed; + return HDF_SUCCESS; +} + +static int32_t VirtualCanSetMode(struct VirtualCanCntlr *virtualCan, int32_t mode) +{ + switch (mode) { + case CAN_BUS_LOOPBACK: + virtualCan->workMode = CAN_BUS_LOOPBACK; + break; + default: + return HDF_ERR_NOT_SUPPORT; + } + return HDF_SUCCESS; +} + +static int32_t VirtualCanSetCfg(struct CanCntlr *cntlr, const struct CanConfig *cfg) +{ + int32_t ret; + struct VirtualCanCntlr *virtualCan = NULL; + + virtualCan = (struct VirtualCanCntlr *)cntlr->device.priv; + if (virtualCan == NULL) { + HDF_LOGE("%s: private data is null", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + virtualCan->busState = CAN_BUS_RESET; + if ((ret = VirtualCanSetBitRate(virtualCan, cfg->speed) != HDF_SUCCESS)) { + HDF_LOGE("%s: set speed failed", __func__); + return ret; + } + + if ((ret = VirtualCanSetMode(virtualCan, cfg->mode) != HDF_SUCCESS)) { + HDF_LOGE("%s: set mode failed", __func__); + return ret; + } + + virtualCan->busState = CAN_BUS_READY; + return HDF_SUCCESS; +} + +static int32_t VirtualCanGetCfg(struct CanCntlr *cntlr, struct CanConfig *cfg) +{ + struct VirtualCanCntlr *virtualCan = NULL; + + virtualCan = (struct VirtualCanCntlr *)cntlr->device.priv; + if (virtualCan == NULL) { + HDF_LOGE("%s: private data is null", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + cfg->speed = virtualCan->bitRate; + cfg->mode = virtualCan->workMode; + return HDF_SUCCESS; +} + +struct CanCntlrMethod g_virtualCanMethod = { + .sendMsg = VirtualCanSendMsg, + .setCfg = VirtualCanSetCfg, + .getCfg = VirtualCanGetCfg, +}; + +/* + * ! this function will not be invoked when polciy is 0 + * ! no need to make any changes here + */ +static int32_t HdfVirtualCanBind(struct HdfDeviceObject *device) +{ + return CanServiceBind(device); +} + +static void VirtualCanSetDefault(struct VirtualCanCntlr *virtualCan) +{ + virtualCan->cntlr.number = CAN_VIRTUAL_BUS_NUM_DFT; + virtualCan->workMode = CAN_BUS_LOOPBACK; + virtualCan->bitRate = CAN_SPEED_10K; +} + +static int32_t VirtualCanInit(struct VirtualCanCntlr *virtualCan) +{ + int32_t ret; + + HDF_LOGI("%s: enter", __func__); + if (virtualCan == NULL) { + return HDF_ERR_INVALID_OBJECT; + } + + VirtualCanSetDefault(virtualCan); + + ret = VirtualReadConfigFromHcs(virtualCan); + if (ret != HDF_SUCCESS) { + HDF_LOGW("VirtualUartInit: read hcs config failed"); + } + + if ((ret = VirtualCanSetBitRate(virtualCan, virtualCan->bitRate) != HDF_SUCCESS)) { + HDF_LOGE("%s: set bit rate failed", __func__); + return ret; + } + + if ((ret = VirtualCanSetMode(virtualCan, virtualCan->workMode) != HDF_SUCCESS)) { + HDF_LOGE("%s: set mode failed", __func__); + return ret; + } + + return HDF_SUCCESS; +} + +static int32_t HdfVirtualCanInit(struct HdfDeviceObject *device) +{ + int32_t ret; + struct VirtualCanCntlr *virtualCan = NULL; + + HDF_LOGI("%s: entry", __func__); + if (device == NULL) { + HDF_LOGE("%s: device is null", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + virtualCan = (struct VirtualCanCntlr *)OsalMemCalloc(sizeof(*virtualCan)); + if (virtualCan == NULL) { + return HDF_ERR_MALLOC_FAIL; + } + + virtualCan->busState = CAN_BUS_RESET; + ret = VirtualCanInit(virtualCan); + if (ret != HDF_SUCCESS) { + OsalMemFree(virtualCan); + HDF_LOGE("%s: can init error: %d", __func__, ret); + return ret; + } + virtualCan->busState = CAN_BUS_READY; + + virtualCan->cntlr.ops = &g_virtualCanMethod; + virtualCan->cntlr.device.priv = virtualCan; + ret = CanCntlrAdd(&virtualCan->cntlr); + if (ret != HDF_SUCCESS) { + OsalMemFree(virtualCan); + HDF_LOGE("%s: add cntlr failed: %d", __func__, ret); + return ret; + } + + ret = CanCntlrSetHdfDev(&virtualCan->cntlr, device); + if (ret != HDF_SUCCESS) { + HDF_LOGW("%s: can controller attach failed:%d", __func__, ret); + } + + return HDF_SUCCESS; +} + +static int32_t VirtualCanDeinit(struct VirtualCanCntlr *virtualCan) +{ + (void)virtualCan; + return HDF_SUCCESS; +} + +static void HdfVirtualCanRelease(struct HdfDeviceObject *device) +{ + struct VirtualCanCntlr *virtualCan = NULL; + + HDF_LOGI("%s: entry", __func__); + if (device == NULL) { + HDF_LOGE("%s: device is null", __func__); + return; + } + + virtualCan = (struct VirtualCanCntlr *)CanCntlrFromHdfDev(device); + if (virtualCan == NULL) { + HDF_LOGE("%s: platform device not bind", __func__); + return; + } + + (void)CanCntlrDel(&virtualCan->cntlr); + VirtualCanDeinit(virtualCan); + OsalMemFree(virtualCan); +} + +static struct HdfDriverEntry g_hdfCanDriver = { + .moduleVersion = 1, + .moduleName = "can_driver_virtual", + .Bind = HdfVirtualCanBind, + .Init = HdfVirtualCanInit, + .Release = HdfVirtualCanRelease, +}; + +struct HdfDriverEntry *CanVirtualGetEntry(void) +{ + return &g_hdfCanDriver; +} + +HDF_INIT(g_hdfCanDriver); diff --git a/uhdf/test/unittest/platform/BUILD.gn b/uhdf/test/unittest/platform/BUILD.gn index 07a22b9..fb96d9b 100644 --- a/uhdf/test/unittest/platform/BUILD.gn +++ b/uhdf/test/unittest/platform/BUILD.gn @@ -37,6 +37,7 @@ if (board_name == "hi3516dv300" || board_name == "hispark_taurus") { } sources = [ "//drivers/framework/support/platform/test/unittest/common/hdf_adc_test.cpp", + "//drivers/framework/support/platform/test/unittest/common/hdf_can_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_gpio_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_platform_device_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_platform_dumper_test.cpp", -- Gitee From 2db8d9adf4f0fbdc7741ce5d86f7ac38be4848a7 Mon Sep 17 00:00:00 2001 From: mahai Date: Fri, 6 May 2022 12:25:25 +0800 Subject: [PATCH 075/102] feat:add platform driver fuzz test script Signed-off-by: mahai --- uhdf2/test/BUILD.gn | 1 + uhdf2/test/fuzztest/BUILD.gn | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 uhdf2/test/fuzztest/BUILD.gn diff --git a/uhdf2/test/BUILD.gn b/uhdf2/test/BUILD.gn index aef0d79..6cfa3eb 100644 --- a/uhdf2/test/BUILD.gn +++ b/uhdf2/test/BUILD.gn @@ -14,6 +14,7 @@ group("hdf_test_uhdf") { testonly = true deps = [ + "fuzztest:hdf_platform_test", "unittest/config:hdf_adapter_uhdf_test_config", "unittest/manager:hdf_adapter_uhdf_test_ioservice", "unittest/manager:hdf_adapter_uhdf_test_manager", diff --git a/uhdf2/test/fuzztest/BUILD.gn b/uhdf2/test/fuzztest/BUILD.gn new file mode 100644 index 0000000..15b895a --- /dev/null +++ b/uhdf2/test/fuzztest/BUILD.gn @@ -0,0 +1,13 @@ +# Copyright (c) 2022 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. + +group("hdf_platform_test") { + testonly = true + deps = [] + deps += [ + "//drivers/framework/support/platform/test/fuzztest:hdf_platform_fuzztest", + ] +} -- Gitee From 3892c46df2a5fc5cfffb1e496f14ea347d72747b Mon Sep 17 00:00:00 2001 From: yuanbo Date: Tue, 10 May 2022 10:55:03 +0800 Subject: [PATCH 076/102] fix: add secon for devmgr process Signed-off-by: yuanbo --- uhdf2/manager/hdf_devmgrmusl.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/uhdf2/manager/hdf_devmgrmusl.cfg b/uhdf2/manager/hdf_devmgrmusl.cfg index 10512d9..89c7900 100644 --- a/uhdf2/manager/hdf_devmgrmusl.cfg +++ b/uhdf2/manager/hdf_devmgrmusl.cfg @@ -5,6 +5,7 @@ "uid" : "hdf_devmgr", "gid" : ["hdf_devmgr", "readproc"], "start-mode" : "boot", + "secon" : "u:r:hdf_devmgr:s0", "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH","CAP_SYS_MODULE", "CAP_SYS_RAWIO"] } ] -- Gitee From 53e693a9c0193ea7aae61082ad202945f5b3426f Mon Sep 17 00:00:00 2001 From: yuanbo Date: Wed, 11 May 2022 14:14:32 +0800 Subject: [PATCH 077/102] fix: hdi interface proxy should use separate parts Signed-off-by: yuanbo --- uhdf2/hdi.gni | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 uhdf2/hdi.gni diff --git a/uhdf2/hdi.gni b/uhdf2/hdi.gni old mode 100755 new mode 100644 index d620918..eaca57e --- a/uhdf2/hdi.gni +++ b/uhdf2/hdi.gni @@ -142,7 +142,7 @@ template("hdi") { install_images = [ system_base_dir ] subsystem_name = invoker.subsystem_name - part_name = invoker.part_name + part_name = invoker.part_name + "_interface" } } -- Gitee From 5d44ac8ba8dc0ee61e23c2f80749f88ab542530e Mon Sep 17 00:00:00 2001 From: zhang Date: Wed, 11 May 2022 17:43:28 +0800 Subject: [PATCH 078/102] fix:optimization process startup configuration is not generated according to musl Signed-off-by: zhang --- uhdf2/hcs/BUILD.gn | 6 +----- uhdf2/manager/BUILD.gn | 6 +----- uhdf2/manager/hdf_devmgr.cfg | 7 ++++--- uhdf2/manager/hdf_devmgrmusl.cfg | 12 ------------ 4 files changed, 6 insertions(+), 25 deletions(-) delete mode 100644 uhdf2/manager/hdf_devmgrmusl.cfg diff --git a/uhdf2/hcs/BUILD.gn b/uhdf2/hcs/BUILD.gn index 003d78b..ff65e83 100644 --- a/uhdf2/hcs/BUILD.gn +++ b/uhdf2/hcs/BUILD.gn @@ -46,11 +46,7 @@ hc_gen_start_cfg("gen_start_cfg") { hcs_config_path = "//vendor/$product_company/$product_name/hdf_config/uhdf/" } sources = [ rebase_path(hcs_config_path + hcs_source) ] - if (use_musl) { - outputs = [ "$target_gen_dir/hdf_devhostmusl.cfg" ] - } else { - outputs = [ "$target_gen_dir/hdf_devhost.cfg" ] - } + outputs = [ "$target_gen_dir/hdf_devhost.cfg" ] } ohos_prebuilt_etc("hdf_devhost.cfg") { diff --git a/uhdf2/manager/BUILD.gn b/uhdf2/manager/BUILD.gn index 1b9d139..d6ef7c0 100644 --- a/uhdf2/manager/BUILD.gn +++ b/uhdf2/manager/BUILD.gn @@ -88,11 +88,7 @@ ohos_executable("hdf_devmgr") { } ohos_prebuilt_etc("hdf_devmgr.cfg") { - if (use_musl) { - source = "hdf_devmgrmusl.cfg" - } else { - source = "hdf_devmgr.cfg" - } + source = "hdf_devmgr.cfg" relative_install_dir = "init" install_images = [ chipset_base_dir ] subsystem_name = "hdf" diff --git a/uhdf2/manager/hdf_devmgr.cfg b/uhdf2/manager/hdf_devmgr.cfg index 0596505..89c7900 100644 --- a/uhdf2/manager/hdf_devmgr.cfg +++ b/uhdf2/manager/hdf_devmgr.cfg @@ -2,10 +2,11 @@ "services" : [{ "name" : "hdf_devmgr", "path" : ["/vendor/bin/hdf_devmgr"], - "uid" : "root", - "gid" : ["system"], + "uid" : "hdf_devmgr", + "gid" : ["hdf_devmgr", "readproc"], + "start-mode" : "boot", "secon" : "u:r:hdf_devmgr:s0", - "start-mode" : "boot" + "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH","CAP_SYS_MODULE", "CAP_SYS_RAWIO"] } ] } diff --git a/uhdf2/manager/hdf_devmgrmusl.cfg b/uhdf2/manager/hdf_devmgrmusl.cfg deleted file mode 100644 index 89c7900..0000000 --- a/uhdf2/manager/hdf_devmgrmusl.cfg +++ /dev/null @@ -1,12 +0,0 @@ -{ - "services" : [{ - "name" : "hdf_devmgr", - "path" : ["/vendor/bin/hdf_devmgr"], - "uid" : "hdf_devmgr", - "gid" : ["hdf_devmgr", "readproc"], - "start-mode" : "boot", - "secon" : "u:r:hdf_devmgr:s0", - "caps" : ["DAC_OVERRIDE", "DAC_READ_SEARCH","CAP_SYS_MODULE", "CAP_SYS_RAWIO"] - } - ] -} -- Gitee From 7727dac73559a5ea53096127edb0d1738b303318 Mon Sep 17 00:00:00 2001 From: mahai Date: Thu, 12 May 2022 09:49:35 +0800 Subject: [PATCH 079/102] fix:add platform pwm driver fuzz test script Signed-off-by: mahai --- uhdf2/platform/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/uhdf2/platform/BUILD.gn b/uhdf2/platform/BUILD.gn index b7fad46..9d69bd3 100755 --- a/uhdf2/platform/BUILD.gn +++ b/uhdf2/platform/BUILD.gn @@ -36,6 +36,7 @@ ohos_shared_library("libhdf_platform") { "$HDF_FRAMEWORKS/support/platform/src/adc/adc_if_u.c", "$HDF_FRAMEWORKS/support/platform/src/gpio/gpio_if_u.c", "$HDF_FRAMEWORKS/support/platform/src/i2c/i2c_if_u.c", + "$HDF_FRAMEWORKS/support/platform/src/pwm/pwm_if_u.c", "$HDF_FRAMEWORKS/support/platform/src/rtc/rtc_base.c", "$HDF_FRAMEWORKS/support/platform/src/rtc/rtc_if_u.c", "$HDF_FRAMEWORKS/support/platform/src/spi/spi_if_u.c", -- Gitee From d04323c42a56959ff882bd2574f906b6fffb55c3 Mon Sep 17 00:00:00 2001 From: yue Date: Thu, 12 May 2022 18:32:34 +0800 Subject: [PATCH 080/102] fix:modify load library mode of hdi Signed-off-by: yue --- uhdf2/hdi/src/hdi_support.cpp | 37 +++++++++---------- .../unittest/sample_proxy.cpp | 2 +- .../sample_service_cpp/foo_stub.cpp | 15 -------- .../test/hdi_sample/sample_service_cpp/ifoo.h | 2 - .../sample_service_stub.cpp | 2 +- uhdf2/include/hdi/hdi_support.h | 2 +- 6 files changed, 21 insertions(+), 39 deletions(-) diff --git a/uhdf2/hdi/src/hdi_support.cpp b/uhdf2/hdi/src/hdi_support.cpp index 91d8fca..d3b0c69 100644 --- a/uhdf2/hdi/src/hdi_support.cpp +++ b/uhdf2/hdi/src/hdi_support.cpp @@ -18,9 +18,7 @@ #include #include #include -#include #include -#include #include "hdf_base.h" #include "hdf_log.h" @@ -43,17 +41,15 @@ static const std::regex reInfDesc("[a-zA-Z_][a-zA-Z0-9_]*(?:\\.[a-zA-Z_][a-zA-Z0 "([a-zA-Z_][a-zA-Z0-9_]*)"); } // namespace -static int32_t ParseInterface(const std::string &fullName, std::string &interface, uint32_t &versionMajor, +static int32_t ParseInterface(const std::string &desc, std::string &interface, uint32_t &versionMajor, uint32_t &versionMinor) { std::smatch result; - if (!std::regex_match(fullName, result, reInfDesc)) { - HDF_LOGE("invalid format of interface descriptor '%{public}s'", fullName.c_str()); + if (!std::regex_match(desc, result, reInfDesc)) { return HDF_FAILURE; } if (result.size() < INTERFACE_MATCH_RESIZE) { - HDF_LOGE("failed to parse interface descriptor '%{public}s'", fullName.c_str()); return HDF_FAILURE; } @@ -63,7 +59,6 @@ static int32_t ParseInterface(const std::string &fullName, std::string &interfac interface = interfaceName[0] == 'I' ? interfaceName.substr(1) : interfaceName; if (interface.empty()) { - HDF_LOGE("failed to get invalid interface name"); return HDF_FAILURE; } @@ -91,37 +86,39 @@ static std::string TransFileName(const std::string& interfaceName) return result; } -/* +/* service name: xxx_service * interface descriptor name: ohos.hdi.sample.v1_0.IFoo * interface: Foo * versionMajor: 1 * versionMinor: 0 - * library name: libfoo_service_1.0.z.so + * library name: libfoo_xxx_service_1.0.z.so * method name: FooImplGetInstance */ -void *LoadHdiImpl(const char *fullIfName) +void *LoadHdiImpl(const char *desc, const char *serviceName) { char path[PATH_MAX + 1] = {0}; char resolvedPath[PATH_MAX + 1] = {0}; // interface descriptor name like "ohos.hdi.sample.v1_0.IFoo", the last two are version and interface base name - if (fullIfName == nullptr) { - HDF_LOGE("fullIfName is nullptr"); + if (desc == nullptr || serviceName == nullptr) { + HDF_LOGE("%{public}s interface descriptor or service name is nullptr", __func__); + return nullptr; + } + + if (strlen(desc) == 0 || strlen(serviceName) == 0) { + HDF_LOGE("%{public}s invalid interface descriptor or service name", __func__); return nullptr; } - HDF_LOGD("load interface impl: %{public}s", fullIfName); - std::string fullName = fullIfName; std::string interfaceName; uint32_t versionMajor = 0; uint32_t versionMinor = 0; - if (ParseInterface(fullIfName, interfaceName, versionMajor, versionMinor) != HDF_SUCCESS) { - HDF_LOGE("failed to parse hdi interface info"); + if (ParseInterface(desc, interfaceName, versionMajor, versionMinor) != HDF_SUCCESS) { + HDF_LOGE("failed to parse hdi interface info from '%{public}s'", desc); return nullptr; } - // hdi implement name like libfoo_service_1.0.z.so - if (snprintf_s(path, sizeof(path), sizeof(path) - 1, "%s/lib%s_service_%u.%u.z.so", HDI_SO_PATH, - TransFileName(interfaceName).data(), versionMajor, versionMinor) < 0) { + if (snprintf_s(path, sizeof(path), sizeof(path) - 1, "%s/lib%s_%s_%u.%u.z.so", HDI_SO_PATH, + TransFileName(interfaceName).c_str(), serviceName, versionMajor, versionMinor) < 0) { HDF_LOGE("%{public}s snprintf_s failed", __func__); return nullptr; } @@ -129,6 +126,8 @@ void *LoadHdiImpl(const char *fullIfName) HDF_LOGE("%{public}s invalid hdi impl so name %{public}s", __func__, path); return nullptr; } + + HDF_LOGD("load interface impl lib: %{public}s", resolvedPath); void *handler = dlopen(resolvedPath, RTLD_LAZY); if (handler == nullptr) { HDF_LOGE("%{public}s dlopen failed %{public}s", __func__, dlerror()); diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.cpp b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.cpp index 73744e2..3e2640b 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.cpp +++ b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/unittest/sample_proxy.cpp @@ -46,7 +46,7 @@ sptr ISample::Get(const std::string &serviceName, bool isStub) } std::string desc = Str16ToStr8(ISample::GetDescriptor()); - void *impl = LoadHdiImpl(desc.data()); + void *impl = LoadHdiImpl(desc.data(), serviceName.c_str()); if (impl == nullptr) { HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); return nullptr; diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_stub.cpp b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_stub.cpp index 3be47a7..0fd075e 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_stub.cpp +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/foo_stub.cpp @@ -28,21 +28,6 @@ namespace OHOS { namespace HDI { namespace Sample { namespace V1_0 { -sptr IFoo::Get(bool isStub) -{ - if (!isStub) { - return nullptr; - } - std::string desc = Str16ToStr8(IFoo::GetDescriptor()); - void *impl = LoadHdiImpl(desc.data()); - if (impl == nullptr) { - HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); - return nullptr; - } - - return reinterpret_cast(impl); -} - FooStub::FooStub(const sptr serviceImpl) : IPCObjectStub(IFoo::GetDescriptor()), impl_(serviceImpl) {} FooStub::~FooStub() diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/ifoo.h b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/ifoo.h index 7d9ed9f..06be1b5 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/ifoo.h +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/ifoo.h @@ -33,8 +33,6 @@ public: virtual ~IFoo() = default; virtual int32_t PingTest(bool input, bool &output) = 0; - - static sptr Get(bool isStub); }; } // namespace V1_0 } // namespace Sample diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.cpp b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.cpp index 5947f3b..25caedd 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.cpp +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.cpp @@ -37,7 +37,7 @@ sptr ISample::Get(const std::string &serviceName, bool isStub) } std::string desc = Str16ToStr8(ISample::GetDescriptor()); - void *impl = LoadHdiImpl(desc.data()); + void *impl = LoadHdiImpl(desc.data(), serviceName.c_str()); if (impl == nullptr) { HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); return nullptr; diff --git a/uhdf2/include/hdi/hdi_support.h b/uhdf2/include/hdi/hdi_support.h index 1787540..d4c301e 100644 --- a/uhdf2/include/hdi/hdi_support.h +++ b/uhdf2/include/hdi/hdi_support.h @@ -22,7 +22,7 @@ extern "C" { #endif /* __cplusplus */ -void *LoadHdiImpl(const char *fullIfName); +void *LoadHdiImpl(const char *desc, const char *serviceName); #ifdef __cplusplus } -- Gitee From 51ac21e86ea504ff71ba92167c2cf5cc0b6e6f0d Mon Sep 17 00:00:00 2001 From: yafeng_wang Date: Mon, 16 May 2022 09:50:26 +0800 Subject: [PATCH 081/102] fix: Add watchdog to build script and add fuzz test case for it. Signed-off-by: yafeng_wang --- uhdf2/platform/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/uhdf2/platform/BUILD.gn b/uhdf2/platform/BUILD.gn index 9d69bd3..b699198 100755 --- a/uhdf2/platform/BUILD.gn +++ b/uhdf2/platform/BUILD.gn @@ -42,6 +42,7 @@ ohos_shared_library("libhdf_platform") { "$HDF_FRAMEWORKS/support/platform/src/spi/spi_if_u.c", "$HDF_FRAMEWORKS/support/platform/src/timer/timer_if_u.c", "$HDF_FRAMEWORKS/support/platform/src/uart/uart_if_u.c", + "$HDF_FRAMEWORKS/support/platform/src/watchdog/watchdog_if_u.c", ] include_dirs = [ -- Gitee From 1b80eb5b7d6abf724b9b64b0178ac347fef89335 Mon Sep 17 00:00:00 2001 From: guodongqi Date: Tue, 17 May 2022 16:39:21 +0800 Subject: [PATCH 082/102] test: code optimization Signed-off-by: guodongqi --- uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp | 4 ++-- uhdf2/include/hdi/base/hdi_smq.h | 2 +- uhdf2/test/BUILD.gn | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp b/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp index 03acd0d..be31636 100644 --- a/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp +++ b/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp @@ -561,7 +561,7 @@ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest012, TestSize.Level1) t[0].data64 = i + 1; t[1].data32 = i + 1; t[1].data64 = i + 1; - HDF_LOGI("%{public}s:write smq message %{public}zu", __func__, i); + HDF_LOGI("%{public}s:write smq message %{public}d", __func__, i); auto status = smq->Write(&t[0], ELEMENT_SIZE, OHOS::MillisecToNanosec(SMQ_TEST_WAIT_TIME)); ASSERT_EQ(status, 0); } @@ -603,7 +603,7 @@ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest013, TestSize.Level1) t[0].data64 = i + 1; t[1].data32 = i + 1; t[1].data64 = i + 1; - HDF_LOGI("%{public}s:write smq message %{public}zu", __func__, i); + HDF_LOGI("%{public}s:write smq message %{public}d", __func__, i); status = smq->WriteNonBlocking(&t[0], ELEMENT_SIZE); ASSERT_EQ(status, 0); } diff --git a/uhdf2/include/hdi/base/hdi_smq.h b/uhdf2/include/hdi/base/hdi_smq.h index 5c1f417..345f9fc 100644 --- a/uhdf2/include/hdi/base/hdi_smq.h +++ b/uhdf2/include/hdi/base/hdi_smq.h @@ -99,7 +99,7 @@ SharedMemQueue::SharedMemQueue(uint32_t elementCount, SmqType type) : aligned } meta_ = std::make_shared>(elementCount, type); - HDF_LOGI("create SharedMemQueue, count=%{public}u, size=%{public}u", elementCount, meta_->GetSize()); + HDF_LOGI("create SharedMemQueue, count=%{public}u, size=%{public}zu", elementCount, meta_->GetSize()); int ashmemFd = AshmemCreate("hdi_smq", Align(meta_->GetSize(), PAGE_SIZE)); if (ashmemFd < 0) { HDF_LOGE("failed to create ashmem"); diff --git a/uhdf2/test/BUILD.gn b/uhdf2/test/BUILD.gn index 6cfa3eb..ded2b82 100644 --- a/uhdf2/test/BUILD.gn +++ b/uhdf2/test/BUILD.gn @@ -22,5 +22,6 @@ group("hdf_test_uhdf") { "unittest/manager:hdf_adapter_uhdf_test_sbuf", "unittest/osal:hdf_adapter_uhdf_test_osal", "unittest/osal:hdf_adapter_uhdf_test_osal_posix", + "//drivers/framework/test/fuzztest:hdf_framework_fuzztest", ] } -- Gitee From 435c82427f8381cb49a986537ce9bc6f41d7f754 Mon Sep 17 00:00:00 2001 From: guodongqi Date: Thu, 19 May 2022 10:09:10 +0800 Subject: [PATCH 083/102] fix: optimize hdi-gen and drivers code Signed-off-by: guodongqi --- uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_driver.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_driver.cpp b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_driver.cpp index 8218496..eb5206e 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_driver.cpp +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_driver.cpp @@ -65,6 +65,7 @@ static int HdfSampleDriverBind(struct HdfDeviceObject *deviceObject) auto sampleImpl = ISample::Get(true); if (sampleImpl == nullptr) { HDF_LOGE("HdfSampleDriverBind: failed to get ISample implement"); + delete hdfSampleService; return HDF_FAILURE; } @@ -72,6 +73,7 @@ static int HdfSampleDriverBind(struct HdfDeviceObject *deviceObject) OHOS::HDI::ObjectCollector::GetInstance().GetOrNewObject(sampleImpl, ISample::GetDescriptor()); if (hdfSampleService->sampleStub == nullptr) { HDF_LOGE("HdfSampleDriverBind: failed to get ISample stub object"); + delete hdfSampleService; return HDF_FAILURE; } -- Gitee From 7db72e8984e001f4c892750ccc35ba0e74a3529b Mon Sep 17 00:00:00 2001 From: zenglifeng Date: Thu, 19 May 2022 16:04:47 +0800 Subject: [PATCH 084/102] feat: delete accessorycodec and unified codec structure Signed-off-by: zenglifeng --- khdf/liteos/model/audio/BUILD.gn | 38 +++++++++++++++----------------- khdf/liteos/model/audio/Makefile | 19 ++++++++-------- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/khdf/liteos/model/audio/BUILD.gn b/khdf/liteos/model/audio/BUILD.gn index 0fa972b..b8e341b 100644 --- a/khdf/liteos/model/audio/BUILD.gn +++ b/khdf/liteos/model/audio/BUILD.gn @@ -31,12 +31,11 @@ import("//drivers/adapter/khdf/liteos/hdf.gni") module_switch = defined(LOSCFG_DRIVERS_HDF_AUDIO) module_name = "hdf_audio_driver" hdf_driver(module_name) { - PERIPHERAL_ADUIO_ROOT = [] FRAMEWORKS_ADUIO_ROOT = "$HDF_FRAMEWORKS_PATH/model/audio" - PERIPHERAL_ADUIO_ROOT = "$HDF_PERIPHERAL_PATH/audio" + PERIPHERAL_ADUIO_ROOT = + "//device/board/hisilicon/hispark_taurus/audio_drivers" sources = [ - "$FRAMEWORKS_ADUIO_ROOT/common/src/audio_accessory_base.c", "$FRAMEWORKS_ADUIO_ROOT/common/src/audio_codec_base.c", "$FRAMEWORKS_ADUIO_ROOT/common/src/audio_dai_base.c", "$FRAMEWORKS_ADUIO_ROOT/common/src/audio_dma_base.c", @@ -69,32 +68,31 @@ hdf_driver(module_name) { if (defined(LOSCFG_DRIVERS_HDF_AUDIO_CODEC_HI3516)) { sources += [ - "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/codec/src/hi3516_codec_adapter.c", - "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/codec/src/hi3516_codec_impl.c", - "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/codec/src/hi3516_codec_ops.c", - "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/dsp/src/dsp_adapter.c", - "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/dsp/src/dsp_ops.c", - "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/soc/src/hi3516_aiao_impl.c", - "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/soc/src/hi3516_dai_adapter.c", - "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/soc/src/hi3516_dai_ops.c", - "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/soc/src/hi3516_dma_adapter.c", - "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/soc/src/hi3516_dma_ops.c", + "$PERIPHERAL_ADUIO_ROOT/codec/hi3516/src/hi3516_codec_adapter.c", + "$PERIPHERAL_ADUIO_ROOT/codec/hi3516/src/hi3516_codec_impl.c", + "$PERIPHERAL_ADUIO_ROOT/codec/hi3516/src/hi3516_codec_ops.c", + "$PERIPHERAL_ADUIO_ROOT/dsp/src/dsp_adapter.c", + "$PERIPHERAL_ADUIO_ROOT/dsp/src/dsp_ops.c", + "$PERIPHERAL_ADUIO_ROOT/soc/src/hi3516_aiao_impl.c", + "$PERIPHERAL_ADUIO_ROOT/soc/src/hi3516_dai_adapter.c", + "$PERIPHERAL_ADUIO_ROOT/soc/src/hi3516_dai_ops.c", + "$PERIPHERAL_ADUIO_ROOT/soc/src/hi3516_dma_adapter.c", + "$PERIPHERAL_ADUIO_ROOT/soc/src/hi3516_dma_ops.c", ] include_dirs += [ - "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/codec/include", - "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/soc/include", - "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/dsp/include", + "$PERIPHERAL_ADUIO_ROOT/codec/hi3516/include", + "$PERIPHERAL_ADUIO_ROOT/soc/include", + "$PERIPHERAL_ADUIO_ROOT/dsp/include", ] } if (defined(LOSCFG_DRIVERS_HDF_AUDIO_CODEC_TF9879)) { sources += [ - "$PERIPHERAL_ADUIO_ROOT/chipsets/tfa9879/accessory/src/tfa9879_accessory_adapter.c", - "$PERIPHERAL_ADUIO_ROOT/chipsets/tfa9879/accessory/src/tfa9879_accessory_impl.c", + "$PERIPHERAL_ADUIO_ROOT/codec/tfa9879/src/tfa9879_codec_adapter.c", + "$PERIPHERAL_ADUIO_ROOT/codec/tfa9879/src/tfa9879_codec_ops.c", ] - include_dirs += - [ "$PERIPHERAL_ADUIO_ROOT/chipsets/tfa9879/accessory/include" ] + include_dirs += [ "$PERIPHERAL_ADUIO_ROOT/codec/tfa9879/include" ] } cflags = [ diff --git a/khdf/liteos/model/audio/Makefile b/khdf/liteos/model/audio/Makefile index 482e942..edea03c 100644 --- a/khdf/liteos/model/audio/Makefile +++ b/khdf/liteos/model/audio/Makefile @@ -33,7 +33,7 @@ MODULE_NAME := hdf_audio_driver KHDF_AUDIO_BASE_ROOT_DIR = $(LITEOSTOPDIR)/../../ KHDF_AUDIO_ROOT_DIR = $(KHDF_AUDIO_BASE_ROOT_DIR)/drivers/framework/model/audio KHDF_FRAMEWORK_ROOT_DIR = $(KHDF_AUDIO_BASE_ROOT_DIR)/drivers/framework -KHDF_AUDIO_HI3516DV300_DIR = $(KHDF_AUDIO_BASE_ROOT_DIR)/drivers/peripheral/audio/chipsets/hi3516dv300 +KHDF_AUDIO_HI3516DV300_DIR = $(KHDF_AUDIO_BASE_ROOT_DIR)/device/board/hisilicon/hispark_taurus/audio_drivers LOCAL_INCLUDE := $(KHDF_AUDIO_BASE_ROOT_DIR)/third_party/bounds_checking_function/include \ $(KHDF_AUDIO_KHDF_ROOT_DIR)/osal/include \ @@ -47,8 +47,8 @@ LOCAL_INCLUDE := $(KHDF_AUDIO_BASE_ROOT_DIR)/third_party/bounds_checking_functio $(KHDF_FRAMEWORK_ROOT_DIR)/model/audio/sapm/include \ $(KHDF_FRAMEWORK_ROOT_DIR)/model/audio/dispatch/include \ $(KHDF_FRAMEWORK_ROOT_DIR)/model/audio/common/include \ - $(KHDF_AUDIO_HI3516DV300_DIR)/../tfa9879/accessory/include \ - $(KHDF_AUDIO_HI3516DV300_DIR)/codec/include \ + $(KHDF_AUDIO_HI3516DV300_DIR)/codec/tfa9879/include \ + $(KHDF_AUDIO_HI3516DV300_DIR)/codec/hi3516/include \ $(KHDF_AUDIO_HI3516DV300_DIR)/soc/include \ $(KHDF_AUDIO_HI3516DV300_DIR)/dsp/include \ $(LITEOSTOPDIR)/kernel/base/include @@ -56,7 +56,6 @@ LOCAL_INCLUDE := $(KHDF_AUDIO_BASE_ROOT_DIR)/third_party/bounds_checking_functio LOCAL_SRCS += $(KHDF_AUDIO_ROOT_DIR)/core/src/audio_core.c \ $(KHDF_AUDIO_ROOT_DIR)/core/src/audio_host.c \ $(KHDF_AUDIO_ROOT_DIR)/core/src/audio_parse.c \ - $(KHDF_AUDIO_ROOT_DIR)/common/src/audio_accessory_base.c \ $(KHDF_AUDIO_ROOT_DIR)/common/src/audio_codec_base.c \ $(KHDF_AUDIO_ROOT_DIR)/common/src/audio_platform_base.c \ $(KHDF_AUDIO_ROOT_DIR)/common/src/audio_dsp_base.c \ @@ -65,11 +64,11 @@ LOCAL_SRCS += $(KHDF_AUDIO_ROOT_DIR)/core/src/audio_core.c \ $(KHDF_AUDIO_ROOT_DIR)/sapm/src/audio_sapm.c \ $(KHDF_AUDIO_ROOT_DIR)/dispatch/src/audio_stream_dispatch.c \ $(KHDF_AUDIO_ROOT_DIR)/dispatch/src/audio_control_dispatch.c \ - $(KHDF_AUDIO_HI3516DV300_DIR)/../tfa9879/accessory/src/tfa9879_accessory_adapter.c \ - $(KHDF_AUDIO_HI3516DV300_DIR)/../tfa9879/accessory/src/tfa9879_accessory_impl.c \ - $(KHDF_AUDIO_HI3516DV300_DIR)/codec/src/hi3516_codec_adapter.c \ - $(KHDF_AUDIO_HI3516DV300_DIR)/codec/src/hi3516_codec_impl.c \ - $(KHDF_AUDIO_HI3516DV300_DIR)/codec/src/hi3516_codec_ops.c \ + $(KHDF_AUDIO_HI3516DV300_DIR)/codec/tfa9879/src/tfa9879_codec_adapter.c \ + $(KHDF_AUDIO_HI3516DV300_DIR)/codec/tfa9879/src/tfa9879_codec_ops.c \ + $(KHDF_AUDIO_HI3516DV300_DIR)/codec/hi3516/src/hi3516_codec_adapter.c \ + $(KHDF_AUDIO_HI3516DV300_DIR)/codec/hi3516/src/hi3516_codec_impl.c \ + $(KHDF_AUDIO_HI3516DV300_DIR)/codec/hi3516/src/hi3516_codec_ops.c \ $(KHDF_AUDIO_HI3516DV300_DIR)/dsp/src/dsp_adapter.c \ $(KHDF_AUDIO_HI3516DV300_DIR)/dsp/src/dsp_ops.c \ $(KHDF_AUDIO_HI3516DV300_DIR)/soc/src/hi3516_dai_adapter.c \ @@ -79,4 +78,4 @@ LOCAL_SRCS += $(KHDF_AUDIO_ROOT_DIR)/core/src/audio_core.c \ $(KHDF_AUDIO_HI3516DV300_DIR)/soc/src/hi3516_dma_adapter.c LOCAL_CFLAGS += -Wno-error -include $(HDF_DRIVER) \ No newline at end of file +include $(HDF_DRIVER) -- Gitee From f4b164ea9cec412d8708dd64fa44870a38f1598f Mon Sep 17 00:00:00 2001 From: yanghaizhou Date: Mon, 23 May 2022 11:04:20 +0800 Subject: [PATCH 085/102] Call CanServiceRlease in virtual can driver Rlease Signed-off-by: yanghaizhou --- platform/can/can_virtual.c | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/can/can_virtual.c b/platform/can/can_virtual.c index 1c8dc77..1dbcf99 100644 --- a/platform/can/can_virtual.c +++ b/platform/can/can_virtual.c @@ -345,6 +345,7 @@ static void HdfVirtualCanRelease(struct HdfDeviceObject *device) return; } + CanServiceRelease(device); (void)CanCntlrDel(&virtualCan->cntlr); VirtualCanDeinit(virtualCan); OsalMemFree(virtualCan); -- Gitee From e7ec818d053a4de2b1fc0affb2a66d545fd79169 Mon Sep 17 00:00:00 2001 From: wu Date: Sun, 22 May 2022 23:29:55 -0700 Subject: [PATCH 086/102] fix: modify word spelling of register Signed-off-by: wu --- khdf/liteos/model/usb/host/src/usb_pnp_notify.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/khdf/liteos/model/usb/host/src/usb_pnp_notify.c b/khdf/liteos/model/usb/host/src/usb_pnp_notify.c index 33ccfba..01dc4be 100644 --- a/khdf/liteos/model/usb/host/src/usb_pnp_notify.c +++ b/khdf/liteos/model/usb/host/src/usb_pnp_notify.c @@ -848,7 +848,7 @@ static int32_t UsbPnpNotifyDriverRegisterDevice(struct HdfDeviceObject *device, ret = HdfDeviceObjectRegister(devObj); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: failed to regitst device %s", __func__, moduleName); + HDF_LOGE("%s: failed to register device %s", __func__, moduleName); HdfDeviceObjectRelease(devObj); return ret; } @@ -856,7 +856,7 @@ static int32_t UsbPnpNotifyDriverRegisterDevice(struct HdfDeviceObject *device, ret = HdfDeviceObjectPublishService(devObj, serviceName, SERVICE_POLICY_CAPACITY, OSAL_S_IREAD | OSAL_S_IWRITE | OSAL_S_IRGRP | OSAL_S_IWGRP | OSAL_S_IROTH); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: failed to regitst device %s", __func__, serviceName); + HDF_LOGE("%s: failed to register device %s", __func__, serviceName); HdfDeviceObjectRelease(devObj); } -- Gitee From 19635c8de49eb8c579e5734eefe359396c4de229 Mon Sep 17 00:00:00 2001 From: heyangbo Date: Tue, 24 May 2022 11:05:45 +0800 Subject: [PATCH 087/102] feat: hal and client unittest cases decouple from common cases Signed-off-by: heyangbo --- uhdf2/test/resource/wlan/ohos_test.xml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/uhdf2/test/resource/wlan/ohos_test.xml b/uhdf2/test/resource/wlan/ohos_test.xml index c711d04..a7f87b4 100644 --- a/uhdf2/test/resource/wlan/ohos_test.xml +++ b/uhdf2/test/resource/wlan/ohos_test.xml @@ -14,7 +14,17 @@ limitations under the License. --> - + + + + + + + + + -- Gitee From 7448bb3d122de8b5dfe45049a6b38d1563a1cc41 Mon Sep 17 00:00:00 2001 From: sunxuejiao Date: Tue, 24 May 2022 15:09:58 +0800 Subject: [PATCH 088/102] feat:sensor/vibrator chipset optimization Signed-off-by: sunxuejiao --- khdf/liteos/model/misc/vibrator/BUILD.gn | 7 +++--- khdf/liteos/model/misc/vibrator/Makefile | 7 +++--- khdf/liteos/model/sensor/BUILD.gn | 31 ++++++++++++------------ khdf/liteos/model/sensor/Makefile | 27 +++++++++++---------- 4 files changed, 38 insertions(+), 34 deletions(-) diff --git a/khdf/liteos/model/misc/vibrator/BUILD.gn b/khdf/liteos/model/misc/vibrator/BUILD.gn index 3a5b13b..6b0a52c 100644 --- a/khdf/liteos/model/misc/vibrator/BUILD.gn +++ b/khdf/liteos/model/misc/vibrator/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -32,6 +32,7 @@ module_switch = defined(LOSCFG_DRIVERS_HDF_VIBRATOR) module_name = "hdf_vibrator_driver" hdf_driver(module_name) { FRAMEWORKS_VIBRATOR_ROOT = "$HDF_FRAMEWORKS_PATH/model/misc/vibrator/driver" + PERIPHERAL_VIBRATOR_ROOT = "$HDF_PERIPHERAL_PATH/misc/vibrator" sources = [ "$FRAMEWORKS_VIBRATOR_ROOT/src/vibrator_driver.c", @@ -39,11 +40,11 @@ hdf_driver(module_name) { ] if (defined(LOSCFG_DRIVERS_HDF_VIBRATOR_LINEAR)) { - sources += [ "$FRAMEWORKS_VIBRATOR_ROOT/chipset/vibrator_linear_driver.c" ] + sources += [ "$PERIPHERAL_VIBRATOR_ROOT/chipset/vibrator_linear_driver.c" ] } include_dirs = [ "$FRAMEWORKS_VIBRATOR_ROOT/include", - "$FRAMEWORKS_VIBRATOR_ROOT/chipset", + "$PERIPHERAL_VIBRATOR_ROOT/chipset", ] } diff --git a/khdf/liteos/model/misc/vibrator/Makefile b/khdf/liteos/model/misc/vibrator/Makefile index ebc67f6..66cb379 100644 --- a/khdf/liteos/model/misc/vibrator/Makefile +++ b/khdf/liteos/model/misc/vibrator/Makefile @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2022 Huawei Device Co., Ltd. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -31,15 +31,16 @@ include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk MODULE_NAME := hdf_vibrator_driver FRAMEWORKS_VIBRATOR_ROOT = $(LITEOSTOPDIR)/../../drivers/framework/model/misc/vibrator/driver +PERIPHERAL_VIBRATOR_ROOT = $(LITEOSTOPDIR)/../../drivers/peripheral/misc/vibrator LOCAL_INCLUDE := $(FRAMEWORKS_VIBRATOR_ROOT)/include \ - $(FRAMEWORKS_VIBRATOR_ROOT)/chipset + $(PERIPHERAL_VIBRATOR_ROOT)/chipset LOCAL_SRCS += $(FRAMEWORKS_VIBRATOR_ROOT)/src/vibrator_driver.c \ $(FRAMEWORKS_VIBRATOR_ROOT)/src/vibrator_haptic.c ifeq ($(LOSCFG_DRIVERS_HDF_VIBRATOR_LINEAR), y) -LOCAL_SRCS += $(FRAMEWORKS_VIBRATOR_ROOT)/chipset/vibrator_linear_driver.c +LOCAL_SRCS += $(PERIPHERAL_VIBRATOR_ROOT)/chipset/vibrator_linear_driver.c endif include $(HDF_DRIVER) diff --git a/khdf/liteos/model/sensor/BUILD.gn b/khdf/liteos/model/sensor/BUILD.gn index f7e8a7b..233039f 100644 --- a/khdf/liteos/model/sensor/BUILD.gn +++ b/khdf/liteos/model/sensor/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -32,6 +32,7 @@ module_switch = defined(LOSCFG_DRIVERS_HDF_SENSOR) module_name = "hdf_sensor_driver" hdf_driver(module_name) { FRAMEWORKS_SENSOR_ROOT = "$HDF_FRAMEWORKS_PATH/model/sensor/driver" + PERIPHERAL_SENSOR_ROOT = "$HDF_PERIPHERAL_PATH/sensor" sources = [ "$FRAMEWORKS_SENSOR_ROOT/common/src/sensor_config_controller.c", "$FRAMEWORKS_SENSOR_ROOT/common/src/sensor_config_parser.c", @@ -43,14 +44,14 @@ hdf_driver(module_name) { sources += [ "$FRAMEWORKS_SENSOR_ROOT/accel/sensor_accel_driver.c" ] } if (defined(LOSCFG_DRIVERS_HDF_SENSOR_ACCEL_BMI160)) { - sources += [ "$FRAMEWORKS_SENSOR_ROOT/chipset/accel/accel_bmi160.c" ] + sources += [ "$PERIPHERAL_SENSOR_ROOT/chipset/accel/accel_bmi160.c" ] } if (defined(LOSCFG_DRIVERS_HDF_SENSOR_ALS)) { sources += [ "$FRAMEWORKS_SENSOR_ROOT/als/sensor_als_driver.c" ] } if (defined(LOSCFG_DRIVERS_HDF_SENSOR_ALS_BH1745)) { - sources += [ "$FRAMEWORKS_SENSOR_ROOT/chipset/als/als_bh1745.c" ] + sources += [ "$PERIPHERAL_SENSOR_ROOT/chipset/als/als_bh1745.c" ] } if (defined(LOSCFG_DRIVERS_HDF_SENSOR_BAROMETER)) { @@ -58,20 +59,20 @@ hdf_driver(module_name) { } if (defined(LOSCFG_DRIVERS_HDF_SENSOR_BAROMETER_BMP180)) { sources += - [ "$FRAMEWORKS_SENSOR_ROOT/chipset/barometer/barometer_bmp180.c" ] + [ "$PERIPHERAL_SENSOR_ROOT/chipset/barometer/barometer_bmp180.c" ] } if (defined(LOSCFG_DRIVERS_HDF_SENSOR_PROXIMITY)) { sources += [ "$FRAMEWORKS_SENSOR_ROOT/proximity/sensor_proximity_driver.c" ] } if (defined(LOSCFG_DRIVERS_HDF_SENSOR_PROXIMITY_APDS9960)) { sources += - [ "$FRAMEWORKS_SENSOR_ROOT/chipset/proximity/proximity_apds9960.c" ] + [ "$PERIPHERAL_SENSOR_ROOT/chipset/proximity/proximity_apds9960.c" ] } if (defined(LOSCFG_DRIVERS_HDF_SENSOR_GYRO)) { sources += [ - "$FRAMEWORKS_SENSOR_ROOT/chipset/gyro/gyro_bmi160.c", "$FRAMEWORKS_SENSOR_ROOT/gyro/sensor_gyro_driver.c", + "$PERIPHERAL_SENSOR_ROOT/chipset/gyro/gyro_bmi160.c", ] } @@ -79,14 +80,14 @@ hdf_driver(module_name) { sources += [ "$FRAMEWORKS_SENSOR_ROOT/hall/sensor_hall_driver.c" ] } if (defined(LOSCFG_DRIVERS_HDF_SENSOR_HALL_AK8789)) { - sources += [ "$FRAMEWORKS_SENSOR_ROOT/chipset/hall/hall_ak8789.c" ] + sources += [ "$PERIPHERAL_SENSOR_ROOT/chipset/hall/hall_ak8789.c" ] } if (defined(LOSCFG_DRIVERS_HDF_SENSOR_MAGNETIC)) { sources += [ "$FRAMEWORKS_SENSOR_ROOT/magnetic/sensor_magnetic_driver.c" ] } if (defined(LOSCFG_DRIVERS_HDF_SENSOR_MAGNETIC_LSM303)) { - sources += [ "$FRAMEWORKS_SENSOR_ROOT/chipset/magnetic/magnetic_lsm303.c" ] + sources += [ "$PERIPHERAL_SENSOR_ROOT/chipset/magnetic/magnetic_lsm303.c" ] } if (defined(LOSCFG_DRIVERS_HDF_SENSOR_GRAVITY)) { @@ -97,18 +98,18 @@ hdf_driver(module_name) { "$FRAMEWORKS_SENSOR_ROOT/include", "$FRAMEWORKS_SENSOR_ROOT/common/include", "$FRAMEWORKS_SENSOR_ROOT/accel", - "$FRAMEWORKS_SENSOR_ROOT/chipset/accel", + "$PERIPHERAL_SENSOR_ROOT/chipset/accel", "$FRAMEWORKS_SENSOR_ROOT/als", - "$FRAMEWORKS_SENSOR_ROOT/chipset/als", + "$PERIPHERAL_SENSOR_ROOT/chipset/als", "$FRAMEWORKS_SENSOR_ROOT/barometer", - "$FRAMEWORKS_SENSOR_ROOT/chipset/barometer", + "$PERIPHERAL_SENSOR_ROOT/chipset/barometer", "$FRAMEWORKS_SENSOR_ROOT/gyro", - "$FRAMEWORKS_SENSOR_ROOT/chipset/gyro", + "$PERIPHERAL_SENSOR_ROOT/chipset/gyro", "$FRAMEWORKS_SENSOR_ROOT/hall", - "$FRAMEWORKS_SENSOR_ROOT/chipset/hall", + "$PERIPHERAL_SENSOR_ROOT/chipset/hall", "$FRAMEWORKS_SENSOR_ROOT/magnetic", - "$FRAMEWORKS_SENSOR_ROOT/chipset/magnetic", + "$PERIPHERAL_SENSOR_ROOT/chipset/magnetic", "$FRAMEWORKS_SENSOR_ROOT/proximity", - "$FRAMEWORKS_SENSOR_ROOT/chipset/proximity", + "$PERIPHERAL_SENSOR_ROOT/chipset/proximity", ] } diff --git a/khdf/liteos/model/sensor/Makefile b/khdf/liteos/model/sensor/Makefile index 220b485..f604529 100644 --- a/khdf/liteos/model/sensor/Makefile +++ b/khdf/liteos/model/sensor/Makefile @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -31,21 +31,22 @@ include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk MODULE_NAME := hdf_sensor_driver FRAMEWORKS_SENSOR_ROOT = $(LITEOSTOPDIR)/../../drivers/framework/model/sensor/driver +PERIPHERAL_SENSOR_ROOT = $(LITEOSTOPDIR)/../../drivers/peripheral/sensor LOCAL_INCLUDE := $(FRAMEWORKS_SENSOR_ROOT)/include \ $(FRAMEWORKS_SENSOR_ROOT)/common/include \ $(FRAMEWORKS_SENSOR_ROOT)/accel \ - $(FRAMEWORKS_SENSOR_ROOT)/chipset/accel \ + $(PERIPHERAL_SENSOR_ROOT)/chipset/accel \ $(FRAMEWORKS_SENSOR_ROOT)/als \ - $(FRAMEWORKS_SENSOR_ROOT)/chipset/als \ + $(PERIPHERAL_SENSOR_ROOT)/chipset/als \ $(FRAMEWORKS_SENSOR_ROOT)/barometer \ - $(FRAMEWORKS_SENSOR_ROOT)/chipset/barometer \ + $(PERIPHERAL_SENSOR_ROOT)/chipset/barometer \ $(FRAMEWORKS_SENSOR_ROOT)/hall \ - $(FRAMEWORKS_SENSOR_ROOT)/chipset/hall \ + $(PERIPHERAL_SENSOR_ROOT)/chipset/hall \ $(FRAMEWORKS_SENSOR_ROOT)/magnetic \ - $(FRAMEWORKS_SENSOR_ROOT)/chipset/magnetic \ + $(PERIPHERAL_SENSOR_ROOT)/chipset/magnetic \ $(FRAMEWORKS_SENSOR_ROOT)/proximity \ - $(FRAMEWORKS_SENSOR_ROOT)/chipset/proximity + $(PERIPHERAL_SENSOR_ROOT)/chipset/proximity LOCAL_SRCS += $(FRAMEWORKS_SENSOR_ROOT)/common/src/sensor_config_controller.c \ $(FRAMEWORKS_SENSOR_ROOT)/common/src/sensor_config_parser.c \ @@ -54,32 +55,32 @@ LOCAL_SRCS += $(FRAMEWORKS_SENSOR_ROOT)/common/src/sensor_config_controller.c \ ifeq ($(LOSCFG_DRIVERS_HDF_SENSOR_ACCEL), y) LOCAL_SRCS += $(FRAMEWORKS_SENSOR_ROOT)/accel/sensor_accel_driver.c \ - $(FRAMEWORKS_SENSOR_ROOT)/chipset/accel/accel_bmi160.c + $(PERIPHERAL_SENSOR_ROOT)/chipset/accel/accel_bmi160.c endif ifeq ($(LOSCFG_DRIVERS_HDF_SENSOR_ALS), y) LOCAL_SRCS += $(FRAMEWORKS_SENSOR_ROOT)/als/sensor_als_driver.c \ - $(FRAMEWORKS_SENSOR_ROOT)/chipset/als/als_bh1745.c + $(PERIPHERAL_SENSOR_ROOT)/chipset/als/als_bh1745.c endif ifeq ($(LOSCFG_DRIVERS_HDF_SENSOR_BAROMETER), y) LOCAL_SRCS += $(FRAMEWORKS_SENSOR_ROOT)/barometer/sensor_barometer_driver.c \ - $(FRAMEWORKS_SENSOR_ROOT)/chipset/barometer/barometer_bmp180.c + $(PERIPHERAL_SENSOR_ROOT)/chipset/barometer/barometer_bmp180.c endif ifeq ($(LOSCFG_DRIVERS_HDF_SENSOR_HALL), y) LOCAL_SRCS += $(FRAMEWORKS_SENSOR_ROOT)/hall/sensor_hall_driver.c \ - $(FRAMEWORKS_SENSOR_ROOT)/chipset/hall/hall_ak8789.c + $(PERIPHERAL_SENSOR_ROOT)/chipset/hall/hall_ak8789.c endif ifeq ($(LOSCFG_DRIVERS_HDF_SENSOR_MAGNETIC), y) LOCAL_SRCS += $(FRAMEWORKS_SENSOR_ROOT)/magnetic/sensor_magnetic_driver.c \ - $(FRAMEWORKS_SENSOR_ROOT)/chipset/magnetic/magnetic_lsm303.c + $(PERIPHERAL_SENSOR_ROOT)/chipset/magnetic/magnetic_lsm303.c endif ifeq ($(LOSCFG_DRIVERS_HDF_SENSOR_PROXIMITY), y) LOCAL_SRCS += $(FRAMEWORKS_SENSOR_ROOT)/proximity/sensor_proximity_driver.c \ - $(FRAMEWORKS_SENSOR_ROOT)/chipset/proximity/proximity_apds9960.c + $(PERIPHERAL_SENSOR_ROOT)/chipset/proximity/proximity_apds9960.c endif ifeq ($(LOSCFG_DRIVERS_HDF_SENSOR_GRAVITY), y) -- Gitee From f3a2db2de389530ebe75a1d0538475d38fc9ec73 Mon Sep 17 00:00:00 2001 From: zhang Date: Wed, 25 May 2022 16:53:44 +0800 Subject: [PATCH 089/102] fix: add lock protection when writing description members of remote objects Signed-off-by: zhang --- uhdf2/ipc/src/hdf_remote_adapter.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/uhdf2/ipc/src/hdf_remote_adapter.cpp b/uhdf2/ipc/src/hdf_remote_adapter.cpp index 8544dff..0d0600e 100644 --- a/uhdf2/ipc/src/hdf_remote_adapter.cpp +++ b/uhdf2/ipc/src/hdf_remote_adapter.cpp @@ -141,6 +141,8 @@ bool HdfRemoteServiceHolder::SetInterfaceDescriptor(const char *desc) HDF_LOGE("failed to set interface des, error on cover str8 to str16, %{public}s", desc); return false; } + static std::mutex descMutex; + std::lock_guard lock(descMutex); (const_cast(&remote_->descriptor_))->assign(newDesc); return true; -- Gitee From 9f2ecd18f6c401cd5949e5b63474e212087ed3be Mon Sep 17 00:00:00 2001 From: yue Date: Wed, 25 May 2022 19:45:09 +0800 Subject: [PATCH 090/102] fix:add sequenceable and expression function Signed-off-by: yue --- uhdf2/hdi.gni | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/uhdf2/hdi.gni b/uhdf2/hdi.gni index eaca57e..95b2a70 100644 --- a/uhdf2/hdi.gni +++ b/uhdf2/hdi.gni @@ -22,7 +22,9 @@ template("hdi") { assert(defined(invoker.subsystem_name), "subsystem_name are must") assert(defined(invoker.part_name), "part_name are must") - root_package_mapping = "ohos.hdi:drivers/interface" + root_path = rebase_path("//drivers/interface") + root_package_mapping = "ohos.hdi:${root_path}" + get_info_args = [ "-i", invoker.language, @@ -127,6 +129,10 @@ template("hdi") { "//drivers/adapter/uhdf2/utils:libhdf_utils", ] + if (defined(invoker.sequenceable)) { + public_deps += invoker.sequenceable + } + if (is_standard_system) { external_deps = [ "hiviewdfx_hilog_native:libhilog", @@ -171,6 +177,10 @@ template("hdi") { "//drivers/adapter/uhdf2/utils:libhdf_utils", ] + if (defined(invoker.sequenceable)) { + public_deps += invoker.sequenceable + } + if (is_standard_system) { external_deps = [ "hiviewdfx_hilog_native:libhilog", -- Gitee From 8d7736ecd5ecf49de142ae140f3920b78818cd7e Mon Sep 17 00:00:00 2001 From: kerninfo Date: Mon, 16 May 2022 14:35:06 +0800 Subject: [PATCH 091/102] modify HDF wlan bus compilation configuration selection Signed-off-by: kerninfo modify HDF wlan bus compilation configuration selection Signed-off-by: kerninfo modify HDF wlan bus compilation configuration selection Signed-off-by: kerninfo modify HDF wlan bus compilation configuration selection Signed-off-by: kerninfo modify HDF wlan bus compilation configuration selection Signed-off-by: kerninfo --- khdf/liteos/model/network/wifi/BUILD.gn | 1 + khdf/liteos/model/network/wifi/Makefile | 1 + 2 files changed, 2 insertions(+) diff --git a/khdf/liteos/model/network/wifi/BUILD.gn b/khdf/liteos/model/network/wifi/BUILD.gn index e2ba840..d1043f8 100644 --- a/khdf/liteos/model/network/wifi/BUILD.gn +++ b/khdf/liteos/model/network/wifi/BUILD.gn @@ -69,6 +69,7 @@ hdf_driver(module_name) { "$FRAMEWORKS_WIFI_ROOT/core/components/eapol", "$FRAMEWORKS_WIFI_ROOT/core/components/p2p", "$FRAMEWORKS_WIFI_ROOT/../common/netdevice", + "$FRAMEWORKS_WIFI_ROOT/core", "$FRAMEWORKS_WIFI_ROOT/core/module", "$HDF_FRAMEWORKS_PATH/include/wifi", "$FRAMEWORKS_WIFI_ROOT/bus", diff --git a/khdf/liteos/model/network/wifi/Makefile b/khdf/liteos/model/network/wifi/Makefile index 56903df..02f8cda 100644 --- a/khdf/liteos/model/network/wifi/Makefile +++ b/khdf/liteos/model/network/wifi/Makefile @@ -58,6 +58,7 @@ WIFI_CFLAGS += -I $(INC_PATH) \ -I $(NETDEV_PATH) \ -I $(MODULE_PATH) \ -I $(INC_WIFI_PATH) \ + -I $(HDM_WIFI_ROOT)/core \ -I $(IBUS_PATH) -- Gitee From ad288df8af73c8f55302e5a18a7bd0fd173e5d5b Mon Sep 17 00:00:00 2001 From: yuanbo Date: Fri, 27 May 2022 10:32:25 +0800 Subject: [PATCH 092/102] feat: support hdi passthrough with C Signed-off-by: yuanbo --- uhdf2/hdi/BUILD.gn | 1 + uhdf2/hdi/src/hdi_support.cpp | 160 ++++++++----- uhdf2/hdi/src/stub_collector.cpp | 112 +++++++++ uhdf2/hdi/test/BUILD.gn | 2 - .../test/hdi_sample/sample_client_c/BUILD.gn | 38 +++ .../sample_client_c/sample_client_c_test.cpp | 217 ++++++++++++++++++ uhdf2/include/hdi/hdi_support.h | 2 +- uhdf2/ipc/include/stub_collector.h | 38 +++ uhdf2/ipc/src/hdf_sbuf_impl_hipc.cpp | 4 +- 9 files changed, 514 insertions(+), 60 deletions(-) create mode 100644 uhdf2/hdi/src/stub_collector.cpp create mode 100644 uhdf2/hdi/test/hdi_sample/sample_client_c/BUILD.gn create mode 100644 uhdf2/hdi/test/hdi_sample/sample_client_c/sample_client_c_test.cpp create mode 100644 uhdf2/ipc/include/stub_collector.h diff --git a/uhdf2/hdi/BUILD.gn b/uhdf2/hdi/BUILD.gn index 667fdb2..1fba602 100644 --- a/uhdf2/hdi/BUILD.gn +++ b/uhdf2/hdi/BUILD.gn @@ -65,6 +65,7 @@ if (defined(ohos_lite)) { "src/servmgr_client.c", "src/servstat_listener.c", "src/servstat_listener_stub.cpp", + "src/stub_collector.cpp", ] deps = [ diff --git a/uhdf2/hdi/src/hdi_support.cpp b/uhdf2/hdi/src/hdi_support.cpp index d3b0c69..df99214 100644 --- a/uhdf2/hdi/src/hdi_support.cpp +++ b/uhdf2/hdi/src/hdi_support.cpp @@ -15,6 +15,8 @@ #include "hdi_support.h" #include +#include +#include #include #include #include @@ -39,10 +41,51 @@ constexpr size_t INTERFACE_NAME_INDEX = 3; static const std::regex reInfDesc("[a-zA-Z_][a-zA-Z0-9_]*(?:\\.[a-zA-Z_][a-zA-Z0-9_]*)*\\." "[V|v]([0-9]+)_([0-9]+)\\." "([a-zA-Z_][a-zA-Z0-9_]*)"); +using HdiImplInstanceFunc = void *(*)(void); +using HdiImplReleaseFunc = void (*)(void *); } // namespace -static int32_t ParseInterface(const std::string &desc, std::string &interface, uint32_t &versionMajor, - uint32_t &versionMinor) +static std::string TransFileName(const std::string &interfaceName) +{ + if (interfaceName.empty()) { + return interfaceName; + } + + std::string result; + for (size_t i = 0; i < interfaceName.size(); i++) { + char c = interfaceName[i]; + if (std::isupper(c) != 0) { + if (i > 1) { + result += '_'; + } + result += std::tolower(c); + } else { + result += c; + } + } + return result; +} + +struct HdiImpl { + HdiImpl() : handler(nullptr), constructor(nullptr), destructor(nullptr), useCount(0) {} + ~HdiImpl() = default; + void Unload() + { + if (handler != nullptr) { + dlclose(handler); + } + } + void *handler; + void *(*constructor)(void); + void (*destructor)(void *); + uint32_t useCount; +}; + +static std::map g_hdiConstructorMap; +static std::mutex g_loaderMutex; + +static int32_t ParseInterface( + const std::string &desc, std::string &interface, std::string &libpath, const char *serviceName) { std::smatch result; if (!std::regex_match(desc, result, reInfDesc)) { @@ -53,41 +96,33 @@ static int32_t ParseInterface(const std::string &desc, std::string &interface, u return HDF_FAILURE; } - versionMajor = std::stoul(result[INTERFACE_VERSION_MAJOR_INDEX]); - versionMinor = std::stoul(result[INTERFACE_VERSION_MINOR_INDEX]); + uint32_t versionMajor = std::stoul(result[INTERFACE_VERSION_MAJOR_INDEX]); + uint32_t versionMinor = std::stoul(result[INTERFACE_VERSION_MINOR_INDEX]); std::string interfaceName = result[INTERFACE_NAME_INDEX]; interface = interfaceName[0] == 'I' ? interfaceName.substr(1) : interfaceName; if (interface.empty()) { return HDF_FAILURE; } - - return HDF_SUCCESS; -} - -static std::string TransFileName(const std::string& interfaceName) -{ - if (interfaceName.empty()) { - return interfaceName; + char path[PATH_MAX + 1] = {0}; + char resolvedPath[PATH_MAX + 1] = {0}; + if (snprintf_s(path, sizeof(path), sizeof(path) - 1, "%s/lib%s_%s_%u.%u.z.so", HDI_SO_PATH, + TransFileName(interface).c_str(), serviceName, versionMajor, versionMinor) < 0) { + HDF_LOGE("%{public}s snprintf_s failed", __func__); + return HDF_FAILURE; } - std::string result; - for (size_t i = 0; i < interfaceName.size(); i++) { - char c = interfaceName[i]; - if (std::isupper(c) != 0) { - if (i > 1) { - result += '_'; - } - result += std::tolower(c); - } else { - result += c; - } + if (realpath(path, resolvedPath) == nullptr || strncmp(resolvedPath, HDI_SO_PATH, strlen(HDI_SO_PATH)) != 0) { + HDF_LOGE("%{public}s invalid hdi impl so name %{public}s", __func__, path); + return HDF_FAILURE; } - return result; + libpath = path; + return HDF_SUCCESS; } -/* service name: xxx_service - * interface descriptor name: ohos.hdi.sample.v1_0.IFoo +/* + * service name: xxx_service + * interface descriptor name: ohos.hdi.sample.v1_0.IFoo, the last two are version and interface base name * interface: Foo * versionMajor: 1 * versionMinor: 0 @@ -96,50 +131,65 @@ static std::string TransFileName(const std::string& interfaceName) */ void *LoadHdiImpl(const char *desc, const char *serviceName) { - char path[PATH_MAX + 1] = {0}; - char resolvedPath[PATH_MAX + 1] = {0}; - // interface descriptor name like "ohos.hdi.sample.v1_0.IFoo", the last two are version and interface base name - if (desc == nullptr || serviceName == nullptr) { - HDF_LOGE("%{public}s interface descriptor or service name is nullptr", __func__); - return nullptr; - } - - if (strlen(desc) == 0 || strlen(serviceName) == 0) { + if (desc == nullptr || serviceName == nullptr || strlen(desc) == 0 || strlen(serviceName) == 0) { HDF_LOGE("%{public}s invalid interface descriptor or service name", __func__); return nullptr; } std::string interfaceName; - uint32_t versionMajor = 0; - uint32_t versionMinor = 0; - if (ParseInterface(desc, interfaceName, versionMajor, versionMinor) != HDF_SUCCESS) { + std::string libpath; + if (ParseInterface(desc, interfaceName, libpath, serviceName) != HDF_SUCCESS) { HDF_LOGE("failed to parse hdi interface info from '%{public}s'", desc); return nullptr; } - if (snprintf_s(path, sizeof(path), sizeof(path) - 1, "%s/lib%s_%s_%u.%u.z.so", HDI_SO_PATH, - TransFileName(interfaceName).c_str(), serviceName, versionMajor, versionMinor) < 0) { - HDF_LOGE("%{public}s snprintf_s failed", __func__); - return nullptr; - } - if (realpath(path, resolvedPath) == nullptr || strncmp(resolvedPath, HDI_SO_PATH, strlen(HDI_SO_PATH)) != 0) { - HDF_LOGE("%{public}s invalid hdi impl so name %{public}s", __func__, path); - return nullptr; + std::lock_guard lock(g_loaderMutex); + auto constructor = g_hdiConstructorMap.find(libpath); + if (constructor != g_hdiConstructorMap.end()) { + return constructor->second.constructor(); } - HDF_LOGD("load interface impl lib: %{public}s", resolvedPath); - void *handler = dlopen(resolvedPath, RTLD_LAZY); - if (handler == nullptr) { + HdiImpl hdiImpl; + hdiImpl.handler = dlopen(libpath.c_str(), RTLD_LAZY); + if (hdiImpl.handler == nullptr) { HDF_LOGE("%{public}s dlopen failed %{public}s", __func__, dlerror()); return nullptr; } - std::string symName = interfaceName.append("ImplGetInstance"); - using HdiImplInstanceFunc = void *(*)(void); - HdiImplInstanceFunc hdiImplInstanceFunc = (HdiImplInstanceFunc)dlsym(handler, symName.data()); - if (hdiImplInstanceFunc == nullptr) { + std::string symName = interfaceName + "ImplGetInstance"; + hdiImpl.constructor = (HdiImplInstanceFunc)dlsym(hdiImpl.handler, symName.data()); + if (hdiImpl.constructor == nullptr) { HDF_LOGE("%{public}s dlsym failed %{public}s", __func__, dlerror()); - dlclose(handler); + hdiImpl.Unload(); return nullptr; } - return hdiImplInstanceFunc(); + std::string desSymName = interfaceName + "ImplRelease"; + hdiImpl.destructor = (HdiImplReleaseFunc)dlsym(hdiImpl.handler, desSymName.data()); + + void *implInstance = hdiImpl.constructor(); + if (implInstance == nullptr) { + HDF_LOGE("%{public}s no full hdi implementation in %{public}s", __func__, libpath.c_str()); + hdiImpl.Unload(); + } else { + g_hdiConstructorMap.emplace(std::make_pair(libpath, std::move(hdiImpl))); + } + return implInstance; +} + +void UnloadHdiImpl(const char *desc, const char *serviceName, void *impl) +{ + if (desc == nullptr || impl == nullptr) { + return; + } + + std::string interfaceName; + std::string libpath; + if (ParseInterface(desc, interfaceName, libpath, serviceName) != HDF_SUCCESS) { + HDF_LOGE("%{public}s: failed to parse hdi interface info from '%{public}s'", __func__, desc); + return; + } + std::lock_guard lock(g_loaderMutex); + auto constructor = g_hdiConstructorMap.find(libpath); + if (constructor != g_hdiConstructorMap.end() && constructor->second.destructor != nullptr) { + constructor->second.destructor(impl); + } } diff --git a/uhdf2/hdi/src/stub_collector.cpp b/uhdf2/hdi/src/stub_collector.cpp new file mode 100644 index 0000000..e5219a8 --- /dev/null +++ b/uhdf2/hdi/src/stub_collector.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stub_collector.h" +#include +#include +#include + +static std::map g_constructorMap; +static std::map g_stubMap; +static std::mutex g_consMapLock; +static std::mutex g_stubMapLock; + +void StubConstructorRegister(const char *ifDesc, struct StubConstructor *constructor) +{ + if (ifDesc == nullptr || constructor == nullptr) { + return; + } + + const std::lock_guard lock(g_consMapLock); + if (g_constructorMap.find(ifDesc) != g_constructorMap.end()) { + HDF_LOGE("repeat registration stub constructor for if %{public}s", ifDesc); + return; + } + g_constructorMap.emplace(std::make_pair(ifDesc, constructor)); + return; +} + +void StubConstructorUnregister(const char *ifDesc, struct StubConstructor *constructor) +{ + if (ifDesc == nullptr || constructor == nullptr) { + return; + } + + const std::lock_guard lock(g_consMapLock); + g_constructorMap.erase(ifDesc); + return; +} + +struct HdfRemoteService **StubCollectorGetOrNewObject(const char *ifDesc, void *servPtr) +{ + if (ifDesc == nullptr || servPtr == nullptr) { + return nullptr; + } + const std::lock_guard stublock(g_stubMapLock); + auto stub = g_stubMap.find(servPtr); + if (stub != g_stubMap.end()) { + return stub->second; + } + + HDF_LOGI("g_constructorMap size %{public}zu", g_constructorMap.size()); + for (auto &consruct : g_constructorMap) { + HDF_LOGI("g_constructorMap it: %{public}s", consruct.first.c_str()); + } + + const std::lock_guard lock(g_consMapLock); + auto constructor = g_constructorMap.find(ifDesc); + if (constructor == g_constructorMap.end()) { + HDF_LOGE("no stub constructor for %{public}s", ifDesc); + return nullptr; + } + + if (constructor->second->constructor == nullptr) { + HDF_LOGE("no stub constructor method for %{public}s", ifDesc); + return nullptr; + } + + HdfRemoteService **stubObject = constructor->second->constructor(servPtr); + if (stubObject == nullptr) { + HDF_LOGE("failed to construct stub obj %{public}s", ifDesc); + return nullptr; + } + g_stubMap.insert(std::make_pair(servPtr, stubObject)); + return stubObject; +} + +void StubCollectorRemoveObject(const char *ifDesc, void *servPtr) +{ + if (ifDesc == nullptr || servPtr == nullptr) { + return; + } + + const std::lock_guard stublock(g_stubMapLock); + auto stub = g_stubMap.find(servPtr); + if (stub == g_stubMap.end()) { + return; + } + const std::lock_guard lock(g_consMapLock); + auto constructor = g_constructorMap.find(ifDesc); + if (constructor == g_constructorMap.end()) { + HDF_LOGE("no stub constructor for %{public}s", ifDesc); + return; + } + + if (constructor->second->destructor != nullptr) { + constructor->second->destructor(stub->second); + } + + g_stubMap.erase(servPtr); +} diff --git a/uhdf2/hdi/test/BUILD.gn b/uhdf2/hdi/test/BUILD.gn index 65aac55..3a2f9db 100644 --- a/uhdf2/hdi/test/BUILD.gn +++ b/uhdf2/hdi/test/BUILD.gn @@ -65,7 +65,5 @@ group("unittest") { deps = [ ":HdiServiceManagerTest", ":HdiServiceManagerTestCC", - "hdi_sample/sample_client_cpp/unittest:sample_client_cpp", - "hdi_sample/sample_service_cpp:sample_service_cpp", ] } diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_c/BUILD.gn b/uhdf2/hdi/test/hdi_sample/sample_client_c/BUILD.gn new file mode 100644 index 0000000..6b76340 --- /dev/null +++ b/uhdf2/hdi/test/hdi_sample/sample_client_c/BUILD.gn @@ -0,0 +1,38 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//drivers/adapter/uhdf2/uhdf.gni") + +module_output_path = "hdf/hdi" + +ohos_unittest("HdiSampleTestC") { + module_out_path = module_output_path + sources = [ "sample_client_c_test.cpp" ] + + deps = [ + "$hdf_uhdf_path/hdi:libhdi", + "$hdf_uhdf_path/utils:libhdf_utils", + "unittest:libsample_client_c", + "//drivers/adapter/uhdf2/ipc:libhdf_ipc_adapter", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_single", + "samgr_standard:samgr_proxy", + "utils_base:utils", + ] +} diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_c/sample_client_c_test.cpp b/uhdf2/hdi/test/hdi_sample/sample_client_c/sample_client_c_test.cpp new file mode 100644 index 0000000..95b3e04 --- /dev/null +++ b/uhdf2/hdi/test/hdi_sample/sample_client_c/sample_client_c_test.cpp @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ifoo.h" +#include "isample.h" +#include "isample_callback.h" + +using namespace OHOS; +using namespace testing::ext; + +#define HDF_LOG_TAG sample_client_c_test + +constexpr const char *TEST_SERVICE_NAME = "sample_driver_service"; + +class SampleHdiCTest : public testing::Test { +public: + static void SetUpTestCase() + { + auto devmgr = HDIDeviceManagerGet(); + if (devmgr != nullptr) { + devmgr->LoadDevice(devmgr, TEST_SERVICE_NAME); + HDIDeviceManagerRelease(devmgr); + } + } + static void TearDownTestCase() + { + auto devmgr = HDIDeviceManagerGet(); + if (devmgr != nullptr) { + devmgr->UnloadDevice(devmgr, TEST_SERVICE_NAME); + HDIDeviceManagerRelease(devmgr); + } + } + void SetUp() {} + void TearDown() {} +}; + +// IPC mode get interface object +HWTEST_F(SampleHdiCTest, HdiCTest001, TestSize.Level1) +{ + struct ISample *sampleService = ISampleGetInstance(TEST_SERVICE_NAME, false); + ASSERT_TRUE(sampleService != nullptr); + + struct IFoo *fooInterface = nullptr; + int ret = sampleService->GetInterface(sampleService, &fooInterface); + ASSERT_EQ(ret, 0); + ASSERT_NE(fooInterface, nullptr); + + ret = fooInterface->FooEvent(fooInterface, 1); + ASSERT_EQ(ret, 0); + + bool value = false; + ret = sampleService->PingTest(sampleService, true, &value); + ASSERT_EQ(ret, 0); + ASSERT_EQ(value, true); + + IFooRelease(true, fooInterface); + ISampleRelease(false, sampleService); +} + +// passthrough mode get interface object +HWTEST_F(SampleHdiCTest, HdiCTest002, TestSize.Level1) +{ + struct ISample *sampleService = ISampleGet(true); + ASSERT_TRUE(sampleService != nullptr); + + struct IFoo *fooInterface = nullptr; + int ret = sampleService->GetInterface(sampleService, &fooInterface); + ASSERT_EQ(ret, 0); + ASSERT_NE(fooInterface, nullptr); + + ret = fooInterface->FooEvent(fooInterface, 1); + ASSERT_EQ(ret, 0); + + bool value = false; + ret = sampleService->PingTest(sampleService, true, &value); + ASSERT_EQ(ret, 0); + ASSERT_EQ(value, true); + + IFooRelease(true, fooInterface); + ISampleRelease(true, sampleService); +} + +struct SampleCallbackImpl { + struct ISampleCallback interface; + bool called; +}; + +static int32_t SampleCallbackPingTest(struct ISampleCallback *self, int event) +{ + if (self == nullptr) { + return HDF_ERR_INVALID_PARAM; + } + struct SampleCallbackImpl *callback = CONTAINER_OF(self, struct SampleCallbackImpl, interface); + callback->called = true; + HDF_LOGI("%{public}s called, event = %{public}d", __func__, event); + return HDF_SUCCESS; +} + +// ipc mode set callback +HWTEST_F(SampleHdiCTest, HdiCTest003, TestSize.Level1) +{ + struct ISample *sampleService = ISampleGetInstance(TEST_SERVICE_NAME, false); + ASSERT_TRUE(sampleService != nullptr); + + bool value = false; + int ret = sampleService->PingTest(sampleService, true, &value); + ASSERT_EQ(ret, 0); + ASSERT_EQ(value, true); + + struct SampleCallbackImpl callback; + callback.interface.PingTest = SampleCallbackPingTest; + ret = sampleService->SetCallback(sampleService, &callback.interface); + + uint32_t retry = 0; + constexpr int WAIT_COUNT = 200; + while (!callback.called && retry < WAIT_COUNT) { + retry++; + OsalMSleep(1); + } + + ASSERT_TRUE(callback.called); + ISampleRelease(false, sampleService); +} + +// passthrougt mode set callback +HWTEST_F(SampleHdiCTest, HdiCTest004, TestSize.Level1) +{ + struct ISample *sampleService = ISampleGet(true); + ASSERT_TRUE(sampleService != nullptr); + + bool value = false; + int ret = sampleService->PingTest(sampleService, true, &value); + ASSERT_EQ(ret, 0); + ASSERT_EQ(value, true); + struct SampleCallbackImpl callback; + callback.interface.PingTest = SampleCallbackPingTest; + ret = sampleService->SetCallback(sampleService, &callback.interface); + uint32_t retry = 0; + + constexpr int WAIT_COUNT = 20; + while (!callback.called && retry < WAIT_COUNT) { + retry++; + OsalMSleep(1); + } + + ASSERT_TRUE(callback.called); + ISampleRelease(true, sampleService); +} + +struct SampleDeathRecipient { + struct HdfDeathRecipient recipient; + bool called; +}; + +static void SampleOnRemoteDied(struct HdfDeathRecipient *deathRecipient, struct HdfRemoteService *remote) +{ + HDF_LOGI("sample service dead"); + if (deathRecipient == nullptr || remote == nullptr) { + return; + } + struct SampleDeathRecipient *sampleRecipient = CONTAINER_OF(deathRecipient, struct SampleDeathRecipient, recipient); + sampleRecipient->called = true; +} + +// IPC mode add DeathRecipient +HWTEST_F(SampleHdiCTest, HdiCTest005, TestSize.Level1) +{ + struct ISample *sampleService = ISampleGetInstance(TEST_SERVICE_NAME, false); + ASSERT_TRUE(sampleService != nullptr); + + struct SampleDeathRecipient deathRecipient = { + .recipient = { + .OnRemoteDied = SampleOnRemoteDied, + }, + .called = false, + }; + + ASSERT_NE(sampleService->AsObject, nullptr); + struct HdfRemoteService *remote = sampleService->AsObject(sampleService); + ASSERT_NE(remote, nullptr); + + HdfRemoteAdapterAddDeathRecipient(remote, &deathRecipient.recipient); + TearDownTestCase(); + + int retry = 0; + constexpr int WAIT_COUNT = 200; + while (!deathRecipient.called && retry < WAIT_COUNT) { + retry++; + OsalMSleep(1); + } + ASSERT_TRUE(deathRecipient.called); + + HdfRemoteAdapterRemoveDeathRecipient(remote, &deathRecipient.recipient); + ISampleRelease(true, sampleService); +} \ No newline at end of file diff --git a/uhdf2/include/hdi/hdi_support.h b/uhdf2/include/hdi/hdi_support.h index d4c301e..b2a0dda 100644 --- a/uhdf2/include/hdi/hdi_support.h +++ b/uhdf2/include/hdi/hdi_support.h @@ -23,7 +23,7 @@ extern "C" { #endif /* __cplusplus */ void *LoadHdiImpl(const char *desc, const char *serviceName); - +void UnloadHdiImpl(const char *desc, const char *serviceName, void *impl); #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/uhdf2/ipc/include/stub_collector.h b/uhdf2/ipc/include/stub_collector.h new file mode 100644 index 0000000..46046de --- /dev/null +++ b/uhdf2/ipc/include/stub_collector.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HDI_STUB_COLLECTOR_H +#define HDI_STUB_COLLECTOR_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +struct StubConstructor { + struct HdfRemoteService **(*constructor)(void *); + void (*destructor)(struct HdfRemoteService **); +}; +void StubConstructorRegister(const char *ifDesc, struct StubConstructor *constructor); +void StubConstructorUnregister(const char *ifDesc, struct StubConstructor *constructor); +struct HdfRemoteService **StubCollectorGetOrNewObject(const char *ifDesc, void *servPtr); +void StubCollectorRemoveObject(const char *ifDesc, void *servPtr); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // HDI_STUB_COLLECTOR_H diff --git a/uhdf2/ipc/src/hdf_sbuf_impl_hipc.cpp b/uhdf2/ipc/src/hdf_sbuf_impl_hipc.cpp index f6d0c06..534e70d 100644 --- a/uhdf2/ipc/src/hdf_sbuf_impl_hipc.cpp +++ b/uhdf2/ipc/src/hdf_sbuf_impl_hipc.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -330,7 +330,7 @@ static const char16_t *SbufMParcelImplReadString16(struct HdfSBufImpl *sbuf) static int32_t SbufMParcelImplWriteRemoteService(struct HdfSBufImpl *sbuf, const struct HdfRemoteService *service) { if (sbuf == nullptr || service == nullptr) { - return false; + return HDF_ERR_INVALID_PARAM; } MessageParcel *parcel = MParcelCast(sbuf); const struct HdfRemoteServiceHolder *holder = reinterpret_cast(service); -- Gitee From 832d8fbd59d563c2f42b00ad09e23cbf70bc1430 Mon Sep 17 00:00:00 2001 From: yuanbo Date: Sat, 28 May 2022 08:16:38 +0800 Subject: [PATCH 093/102] fix: remove member access of IRmoteObject Signed-off-by: yuanbo --- uhdf2/ipc/include/hdf_remote_adapter.h | 1 + uhdf2/ipc/src/hdf_remote_adapter.cpp | 15 ++++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/uhdf2/ipc/include/hdf_remote_adapter.h b/uhdf2/ipc/include/hdf_remote_adapter.h index e5153dc..44dfce4 100644 --- a/uhdf2/ipc/include/hdf_remote_adapter.h +++ b/uhdf2/ipc/include/hdf_remote_adapter.h @@ -56,6 +56,7 @@ struct HdfRemoteServiceHolder { struct HdfRemoteService service_; OHOS::sptr remote_; OHOS::sptr deathRecipient_; + std::u16string descriptor_; }; struct HdfRemoteService *HdfRemoteAdapterBind(OHOS::sptr binder); diff --git a/uhdf2/ipc/src/hdf_remote_adapter.cpp b/uhdf2/ipc/src/hdf_remote_adapter.cpp index 0d0600e..75448ec 100644 --- a/uhdf2/ipc/src/hdf_remote_adapter.cpp +++ b/uhdf2/ipc/src/hdf_remote_adapter.cpp @@ -133,7 +133,7 @@ HdfRemoteServiceHolder::HdfRemoteServiceHolder() : remote_(nullptr), deathRecipi bool HdfRemoteServiceHolder::SetInterfaceDescriptor(const char *desc) { - if (remote_ == nullptr || desc == nullptr) { + if (desc == nullptr) { return false; } std::u16string newDesc = OHOS::Str8ToStr16(std::string(desc)); @@ -141,10 +141,8 @@ bool HdfRemoteServiceHolder::SetInterfaceDescriptor(const char *desc) HDF_LOGE("failed to set interface des, error on cover str8 to str16, %{public}s", desc); return false; } - static std::mutex descMutex; - std::lock_guard lock(descMutex); - (const_cast(&remote_->descriptor_))->assign(newDesc); + descriptor_.assign(newDesc); return true; } @@ -335,11 +333,11 @@ bool HdfRemoteAdapterWriteInterfaceToken(struct HdfRemoteService *service, struc HDF_LOGE("failed to write interface token, holder->remote is nullptr"); return false; } - if (holder->remote_->GetObjectDescriptor().empty()) { + if (holder->descriptor_.empty()) { HDF_LOGE("failed to write interface token, empty token"); return false; } - return parcel->WriteInterfaceToken(holder->remote_->GetObjectDescriptor()); + return parcel->WriteInterfaceToken(holder->descriptor_); } bool HdfRemoteAdapterCheckInterfaceToken(struct HdfRemoteService *service, struct HdfSBuf *data) @@ -361,9 +359,8 @@ bool HdfRemoteAdapterCheckInterfaceToken(struct HdfRemoteService *service, struc HDF_LOGE("failed to check interface, empty token"); return false; } - if (holder->remote_->GetObjectDescriptor() != desc) { - std::string descStr8 = OHOS::Str16ToStr8(desc); - HDF_LOGE("calling unknown interface: %{public}s", descStr8.c_str()); + if (holder->descriptor_ != desc) { + HDF_LOGE("calling unknown interface: %{public}s", OHOS::Str16ToStr8(desc).c_str()); return false; } -- Gitee From 065c7a6bd67cbc7a474b46d4563cc6fcd86253f9 Mon Sep 17 00:00:00 2001 From: kevin Date: Sat, 28 May 2022 17:58:29 +0800 Subject: [PATCH 094/102] fix:modify unittest out path Signed-off-by: kevin --- uhdf2/hdi/test/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uhdf2/hdi/test/BUILD.gn b/uhdf2/hdi/test/BUILD.gn index 3a2f9db..f03ebac 100644 --- a/uhdf2/hdi/test/BUILD.gn +++ b/uhdf2/hdi/test/BUILD.gn @@ -14,7 +14,7 @@ import("//build/test.gni") import("//drivers/adapter/uhdf2/uhdf.gni") -module_output_path = "hdf/hdi" +module_output_path = "hdf/srvmgr" ###########################palTest########################### -- Gitee From 06c2398fe4b6ecf676f79f53154b4d6b3a7f97d9 Mon Sep 17 00:00:00 2001 From: s00442234 Date: Tue, 31 May 2022 09:33:30 +0800 Subject: [PATCH 095/102] Feat:add user notify Signed-off-by: s00442234 --- uhdf/platform/BUILD.gn | 1 + uhdf/test/unittest/platform/BUILD.gn | 3 +++ uhdf2/platform/BUILD.gn | 1 + 3 files changed, 5 insertions(+) diff --git a/uhdf/platform/BUILD.gn b/uhdf/platform/BUILD.gn index bf75582..23ccc94 100644 --- a/uhdf/platform/BUILD.gn +++ b/uhdf/platform/BUILD.gn @@ -52,6 +52,7 @@ ohos_shared_library("hdf_platform") { "$HDF_FRAMEWORKS/model/storage/src/mmc/mmc_if.c", "$HDF_FRAMEWORKS/support/platform/src/adc/adc_if_u.c", "$HDF_FRAMEWORKS/support/platform/src/dac/dac_if_u.c", + "$HDF_FRAMEWORKS/support/platform/src/fwk/platform_listener_u.c", "$HDF_FRAMEWORKS/support/platform/src/gpio/gpio_if_u.c", "$HDF_FRAMEWORKS/support/platform/src/hdmi/hdmi_if.c", "$HDF_FRAMEWORKS/support/platform/src/i2c/i2c_if_u.c", diff --git a/uhdf/test/unittest/platform/BUILD.gn b/uhdf/test/unittest/platform/BUILD.gn index fb96d9b..c71e011 100644 --- a/uhdf/test/unittest/platform/BUILD.gn +++ b/uhdf/test/unittest/platform/BUILD.gn @@ -35,6 +35,9 @@ if (board_name == "hi3516dv300" || board_name == "hispark_taurus") { if (ohos_kernel_type == "liteos_a") { defines += [ "HDF_LITEOS_TEST" ] } + if (ohos_kernel_type == "linux") { + defines += [ "_LINUX_USER_" ] + } sources = [ "//drivers/framework/support/platform/test/unittest/common/hdf_adc_test.cpp", "//drivers/framework/support/platform/test/unittest/common/hdf_can_test.cpp", diff --git a/uhdf2/platform/BUILD.gn b/uhdf2/platform/BUILD.gn index b699198..6f0747e 100755 --- a/uhdf2/platform/BUILD.gn +++ b/uhdf2/platform/BUILD.gn @@ -34,6 +34,7 @@ ohos_shared_library("libhdf_platform") { public_configs = [ ":libhdf_platform_pub_config" ] sources = [ "$HDF_FRAMEWORKS/support/platform/src/adc/adc_if_u.c", + "$HDF_FRAMEWORKS/support/platform/src/fwk/platform_listener_u.c", "$HDF_FRAMEWORKS/support/platform/src/gpio/gpio_if_u.c", "$HDF_FRAMEWORKS/support/platform/src/i2c/i2c_if_u.c", "$HDF_FRAMEWORKS/support/platform/src/pwm/pwm_if_u.c", -- Gitee From 903abc97857ca090ab5088826cf065b597a19077 Mon Sep 17 00:00:00 2001 From: guodongqi Date: Wed, 1 Jun 2022 10:33:15 +0800 Subject: [PATCH 096/102] fix: support HDI of extended directory Signed-off-by: guodongqi --- uhdf2/hdi.gni | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/uhdf2/hdi.gni b/uhdf2/hdi.gni index 95b2a70..13132ba 100644 --- a/uhdf2/hdi.gni +++ b/uhdf2/hdi.gni @@ -22,14 +22,20 @@ template("hdi") { assert(defined(invoker.subsystem_name), "subsystem_name are must") assert(defined(invoker.part_name), "part_name are must") + root_package = "ohos.hdi" root_path = rebase_path("//drivers/interface") - root_package_mapping = "ohos.hdi:${root_path}" + if (defined(invoker.root)) { + package_path_map = string_split(invoker.root, ":") + root_package = package_path_map[0] + root_path = rebase_path(package_path_map[1]) + } + root_package_path = "${root_package}:${root_path}" get_info_args = [ "-i", invoker.language, rebase_path(target_gen_dir), - root_package_mapping, + root_package_path, ] get_info_args += rebase_path(invoker.sources) files_info = exec_script("$hdf_fwk_path/tools/hdi-gen/build_hdi_files.py", @@ -100,7 +106,7 @@ template("hdi") { } args += [ "-r", - root_package_mapping, + root_package_path, ] } -- Gitee From 941c4b3181000182e7348b93f115a0b4158cc8c1 Mon Sep 17 00:00:00 2001 From: yue Date: Wed, 1 Jun 2022 10:34:47 +0800 Subject: [PATCH 097/102] fix:add condition to check null pointer Signed-off-by: yue --- .../hdi_sample/sample_client_cpp/sample_client_cpp_test.cpp | 2 +- .../test/hdi_sample/sample_service_cpp/sample_service_stub.cpp | 3 ++- uhdf2/host/src/hdf_device_thread.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/sample_client_cpp_test.cpp b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/sample_client_cpp_test.cpp index 06d01fa..7918135 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_client_cpp/sample_client_cpp_test.cpp +++ b/uhdf2/hdi/test/hdi_sample/sample_client_cpp/sample_client_cpp_test.cpp @@ -74,7 +74,7 @@ HWTEST_F(SampleHdiCppTest, HdiCppTest001, TestSize.Level1) // passthrough mode get interface object HWTEST_F(SampleHdiCppTest, HdiCppTest002, TestSize.Level1) { - OHOS::sptr sampleService = ISample::Get(TEST_SERVICE_NAME, true); + OHOS::sptr sampleService = ISample::Get(true); ASSERT_TRUE(sampleService != nullptr); OHOS::sptr fooInterface = nullptr; int ret = sampleService->GetInterface(fooInterface); diff --git a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.cpp b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.cpp index 25caedd..3905fc9 100644 --- a/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.cpp +++ b/uhdf2/hdi/test/hdi_sample/sample_service_cpp/sample_service_stub.cpp @@ -48,7 +48,8 @@ sptr ISample::Get(const std::string &serviceName, bool isStub) sptr ISample::Get(bool isStub) { - return ISample::Get("sample_service", isStub); + std::string defaultName = "sample_service"; + return ISample::Get(defaultName, isStub); } SampleServiceStub::SampleServiceStub(const sptr &serviceImpl) : diff --git a/uhdf2/host/src/hdf_device_thread.c b/uhdf2/host/src/hdf_device_thread.c index 9bb01a6..44514ae 100644 --- a/uhdf2/host/src/hdf_device_thread.c +++ b/uhdf2/host/src/hdf_device_thread.c @@ -49,7 +49,7 @@ int32_t DeviceThreadMessageHandler(struct HdfMessageTask *task, struct HdfMessag int DeviceThreadAttach(struct DeviceThread *inst, struct IHdfDevice *device, struct HdfDeviceNode *service) { - if (inst != NULL || device == NULL || service == NULL) { + if (inst == NULL || device == NULL || service == NULL) { return HDF_ERR_INVALID_PARAM; } -- Gitee From f6ed9cb19d8291fe43c43cd8f6f7f3c850cac7c2 Mon Sep 17 00:00:00 2001 From: zhang Date: Mon, 6 Jun 2022 14:18:40 +0800 Subject: [PATCH 098/102] solve the problem that the host process will crash when the devmgr process exits Signed-off-by: zhang --- uhdf2/host/src/driver_loader_full.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/uhdf2/host/src/driver_loader_full.c b/uhdf2/host/src/driver_loader_full.c index 8818730..29f9c04 100644 --- a/uhdf2/host/src/driver_loader_full.c +++ b/uhdf2/host/src/driver_loader_full.c @@ -90,11 +90,6 @@ void HdfDriverLoaderFullReclaimDriver(struct HdfDriver *driver) return; } - if (driver->priv != NULL) { - dlclose(driver->priv); - driver->priv = NULL; - } - OsalMemFree(driver); } -- Gitee From 0101128f2d23c3acafa4095f9ba3b4819cdb2d52 Mon Sep 17 00:00:00 2001 From: baoguotao Date: Mon, 6 Jun 2022 16:42:15 +0800 Subject: [PATCH 099/102] fix: repair hdf_dbg code problem Signed-off-by: baoguotao --- uhdf2/manager/src/devmgr_service_stub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uhdf2/manager/src/devmgr_service_stub.c b/uhdf2/manager/src/devmgr_service_stub.c index 6fa9952..32deb18 100644 --- a/uhdf2/manager/src/devmgr_service_stub.c +++ b/uhdf2/manager/src/devmgr_service_stub.c @@ -84,7 +84,7 @@ static int32_t DevmgrServiceStubDispatchUnloadDevice(struct IDevmgrService *devm static int32_t DevmgrServiceStubDispatchListAllDevice(struct IDevmgrService *devmgrSvc, struct HdfSBuf *reply) { - if (devmgrSvc == NULL || reply == NULL) { + if (reply == NULL) { HDF_LOGE("%{public}s:service name is null", __func__); return HDF_ERR_INVALID_PARAM; } -- Gitee From e9bbff7f3a06885a9e53445cea02a1a3143fd192 Mon Sep 17 00:00:00 2001 From: wby <838434211@qq.com> Date: Tue, 7 Jun 2022 17:45:59 +0800 Subject: [PATCH 100/102] =?UTF-8?q?fix:=20=E6=B8=85=E9=99=A4drivers/adapte?= =?UTF-8?q?r/platform/spi=E4=B8=8B=E7=9A=84spi=5Fstm32f4xx.c=E4=B8=AD?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA=E6=9C=AA=E4=BD=BF=E7=94=A8=E7=9A=84=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wby <838434211@qq.com> Change-Id: I41e6ba24181d289f3a94c9c8ab497c7c957452cd --- platform/spi/spi_stm32f4xx.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/platform/spi/spi_stm32f4xx.c b/platform/spi/spi_stm32f4xx.c index e90c0b2..f630a1f 100644 --- a/platform/spi/spi_stm32f4xx.c +++ b/platform/spi/spi_stm32f4xx.c @@ -256,7 +256,6 @@ int32_t HalSpiSend(SpiDevice *spiDevice, const uint8_t *data, uint16_t size) int32_t HalSpiRecv(SpiDevice *spiDevice, uint8_t *data, uint16_t size) { uint32_t len = size; - uint32_t remainder = 0; uint8_t *cmd = NULL; uint32_t spiId; SpiResource *resource = NULL; @@ -297,8 +296,6 @@ int32_t HalSpiSendRecv(SpiDevice *spiDevice, uint8_t *txData, uint16_t txSize, uint8_t *rxData, uint16_t rxSize) { uint32_t spiId; - uint8_t* data = rxData; - int16_t dropSize = 0; SpiResource *resource = NULL; if (spiDevice == NULL || txData == NULL || txSize == 0 || rxData == NULL || rxSize == 0) { HDF_LOGE("spi input para err\r\n"); @@ -634,11 +631,9 @@ static void SpiDriverRelease(struct HdfDeviceObject *device) static int32_t SpiDevOpen(struct SpiCntlr *spiCntlr) { HDF_LOGI("Enter %s\r\n", __func__); - uint32_t spiPort; SpiDevice *spiDevice = NULL; spiDevice = (SpiDevice*)spiCntlr->priv; - spiPort = spiDevice->spiId; SPI_TypeDef* spix = g_spiGroupMaps[spiDevice->resource.spix]; LL_SPI_Enable(spix); @@ -647,11 +642,9 @@ static int32_t SpiDevOpen(struct SpiCntlr *spiCntlr) static int32_t SpiDevClose(struct SpiCntlr *spiCntlr) { - uint32_t spiPort; SpiDevice *spiDevice = NULL; spiDevice = (SpiDevice*)spiCntlr->priv; - spiPort = spiDevice->spiId; SPI_TypeDef* spix = g_spiGroupMaps[spiDevice->resource.spix]; LL_SPI_Disable(spix); @@ -709,7 +702,6 @@ static int32_t SpiDevSetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg) static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg, uint32_t count) { - uint32_t spiId; SpiDevice *spiDevice = NULL; uint32_t ticks = 0; uint8_t singleCsChange = 0; @@ -720,7 +712,6 @@ static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg, } spiDevice = (SpiDevice *)spiCntlr->priv; - spiId = spiDevice->spiId; for (size_t i = 0; i < count; i++) { msg = &spiMsg[i]; LL_GPIO_ResetOutputPin(LL_GET_GPIOX(spiDevice->resource.csGroup), LL_GET_HAL_PIN(spiDevice->resource.csPin)); -- Gitee From 9a4b420d9ffd2fc587b7b1522e027b37978c69db Mon Sep 17 00:00:00 2001 From: hobbycao Date: Mon, 6 Jun 2022 20:02:45 +0800 Subject: [PATCH 101/102] feat: add buffer handle sequenceable for idl Signed-off-by: hobbycao --- .../sequenceable/buffer_handle/BUILD.gn | 38 ++++++++++ .../buffer_handle_sequenceable.cpp | 71 +++++++++++++++++++ .../buffer_handle_sequenceable.h | 50 +++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 uhdf2/model/display/sequenceable/buffer_handle/BUILD.gn create mode 100644 uhdf2/model/display/sequenceable/buffer_handle/buffer_handle_sequenceable.cpp create mode 100644 uhdf2/model/display/sequenceable/buffer_handle/buffer_handle_sequenceable.h diff --git a/uhdf2/model/display/sequenceable/buffer_handle/BUILD.gn b/uhdf2/model/display/sequenceable/buffer_handle/BUILD.gn new file mode 100644 index 0000000..aaf1db0 --- /dev/null +++ b/uhdf2/model/display/sequenceable/buffer_handle/BUILD.gn @@ -0,0 +1,38 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//drivers/adapter/uhdf2/uhdf.gni") + +config("buffer_handle_sequenceable_config") { + include_dirs = [ + "./", + "//drivers/peripheral/base", + ] +} + +ohos_shared_library("libbuffer_handle_sequenceable_1.0") { + sources = [ "buffer_handle_sequenceable.cpp" ] + + public_configs = [ ":buffer_handle_sequenceable_config" ] + + external_deps = [ + "graphic_chipsetsdk:buffer_handle", + "ipc:ipc_single", + "utils_base:utils", + ] + + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "distributed_camera_device_driver" +} diff --git a/uhdf2/model/display/sequenceable/buffer_handle/buffer_handle_sequenceable.cpp b/uhdf2/model/display/sequenceable/buffer_handle/buffer_handle_sequenceable.cpp new file mode 100644 index 0000000..9fc898f --- /dev/null +++ b/uhdf2/model/display/sequenceable/buffer_handle/buffer_handle_sequenceable.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "buffer_handle_sequenceable.h" + +#include +#include "buffer_handle_parcel.h" + +namespace OHOS { +namespace HDI { +namespace Sequenceable { +namespace V1_0 { +BufferHandleSequenceable::BufferHandleSequenceable() : bufferHandle_(nullptr) +{ +} + +BufferHandleSequenceable::BufferHandleSequenceable(BufferHandle *bufferHandle) + : bufferHandle_(bufferHandle) +{ +} + +BufferHandleSequenceable::~BufferHandleSequenceable() +{ +} + +bool BufferHandleSequenceable::Marshalling(Parcel &parcel) const +{ + if (bufferHandle_ == nullptr) { + return false; + } + + MessageParcel &reply = static_cast(parcel); + return WriteBufferHandle(reply, *bufferHandle_); +} + +sptr BufferHandleSequenceable::Unmarshalling(Parcel &parcel) +{ + MessageParcel &data = static_cast(parcel); + BufferHandle *bufferHandle = ReadBufferHandle(data); + if (bufferHandle == nullptr) { + return nullptr; + } + sptr bufferHandleSeq = new BufferHandleSequenceable(bufferHandle); + return bufferHandleSeq; +} + +BufferHandle *BufferHandleSequenceable::GetBufferHandle() +{ + return bufferHandle_; +} + +void BufferHandleSequenceable::SetBufferHandle(BufferHandle *bufferHandle) +{ + bufferHandle_ = bufferHandle; +} +} // namespace V1_0 +} // namespace Sequenceable +} // namespace HDI +} // namespace OHOS \ No newline at end of file diff --git a/uhdf2/model/display/sequenceable/buffer_handle/buffer_handle_sequenceable.h b/uhdf2/model/display/sequenceable/buffer_handle/buffer_handle_sequenceable.h new file mode 100644 index 0000000..7277dd2 --- /dev/null +++ b/uhdf2/model/display/sequenceable/buffer_handle/buffer_handle_sequenceable.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_BUFFER_HANDLE_SEQUENCE_H +#define OHOS_HDI_BUFFER_HANDLE_SEQUENCE_H + +#include + +#include "buffer_handle.h" + +namespace OHOS { +namespace HDI { +namespace Sequenceable { +namespace V1_0 { +using OHOS::Parcelable; +using OHOS::Parcel; +using OHOS::sptr; + +class BufferHandleSequenceable : public Parcelable { +public: + BufferHandleSequenceable(); + explicit BufferHandleSequenceable(BufferHandle *bufferHandle); + virtual ~BufferHandleSequenceable(); + + bool Marshalling(Parcel &parcel) const override; + static sptr Unmarshalling(Parcel &parcel); + + BufferHandle *GetBufferHandle(); + void SetBufferHandle(BufferHandle *bufferHandle); + +private: + BufferHandle *bufferHandle_; +}; +} // namespace V1_0 +} // namespace Sequenceable +} // namespace HDI +} // namespace OHOS +#endif \ No newline at end of file -- Gitee From 0ab4eebf27c354e6c6ce088a9195f10e3aa14292 Mon Sep 17 00:00:00 2001 From: haiyangzhang Date: Sun, 9 Oct 2022 16:31:22 +0800 Subject: [PATCH 102/102] fix gpio trigger error Signed-off-by: haiyangzhang --- platform/gpio/gpio_bes.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/platform/gpio/gpio_bes.c b/platform/gpio/gpio_bes.c index d06f02f..5f93f7c 100755 --- a/platform/gpio/gpio_bes.c +++ b/platform/gpio/gpio_bes.c @@ -429,6 +429,12 @@ static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mo return HDF_ERR_NOT_SUPPORT; } + if (mode == OSAL_IRQF_TRIGGER_HIGH || mode == OSAL_IRQF_TRIGGER_RISING) { + mode = HAL_GPIO_IRQ_POLARITY_HIGH_RISING; + } else { + mode = HAL_GPIO_IRQ_POLARITY_LOW_FALLING; + } + g_gpioIrqCfg[pin].irq_polarity = mode; return HDF_SUCCESS; -- Gitee