From aaf8a8159d60fea0d6bb8858809a2907ae1c1d0c Mon Sep 17 00:00:00 2001 From: lixinsheng2 Date: Fri, 8 Mar 2024 12:57:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=89=A9=E5=B1=95=E5=A4=96=E8=AE=BE?= =?UTF-8?q?=E6=A1=86=E6=9E=B6=E6=96=B0=E5=A2=9E=E5=9F=BA=E7=A1=80api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixinsheng2 --- drivers/external_device_manager/base/BUILD.gn | 33 ++++++ .../external_device_manager/base/ddk_api.h | 88 ++++++++++++++ .../external_device_manager/base/ddk_types.h | 107 ++++++++++++++++++ .../base/libhid.ndk.json | 14 +++ 4 files changed, 242 insertions(+) create mode 100644 drivers/external_device_manager/base/BUILD.gn create mode 100644 drivers/external_device_manager/base/ddk_api.h create mode 100644 drivers/external_device_manager/base/ddk_types.h create mode 100644 drivers/external_device_manager/base/libhid.ndk.json diff --git a/drivers/external_device_manager/base/BUILD.gn b/drivers/external_device_manager/base/BUILD.gn new file mode 100644 index 000000000..f6ffc5bea --- /dev/null +++ b/drivers/external_device_manager/base/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2023 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") + +ohos_ndk_headers("ddk_header") { + dest_dir = "$ndk_headers_out_dir/hid/" + sources = [ + "ddk_api.h", + "ddk_types.h", + ] +} + +ohos_ndk_library("libddk") { + ndk_description_file = "./libddk.ndk.json" + min_compact_version = "12" + output_name = "ddk" + system_capability = "SystemCapability.Driver.DDK.Extension" + system_capability_headers = [ + "base/ddk_api.h", + "base/ddk_types.h", + ] +} diff --git a/drivers/external_device_manager/base/ddk_api.h b/drivers/external_device_manager/base/ddk_api.h new file mode 100644 index 000000000..362fa0614 --- /dev/null +++ b/drivers/external_device_manager/base/ddk_api.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2024 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 DDK_API_H +#define DDK_API_H + +/** + * @addtogroup Ddk + * @{ + * + * @brief Provides Base DDK APIs, including creating the shared memory, mapping the shared memory,\n + * unmapping the shared memory, and destroying the shared memory. + * + * @since 12 + */ + +/** + * @file ddk_api.h + * + * @brief Declares the Base DDK APIs. + * + * @syscap SystemCapability.Driver.DDK.Extension + * @since 12 + */ + +#include +#include "ddk_types.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @brief Creates shared memory. To prevent resource leakage, destroy the shared memory that is not required by\n + * calling OH_DDK_DestroyAShMem. + * + * @param name Pointer to the shared memory to create. + * @param size Size of the buffer corresponding to the shared memory. + * @param aSharedMem Pointer to the shared memory created. + * @return Returns DDK_SUCCESS if the operation is successful; returns a negative value otherwise. + * @since 12 + */ +DDK_RetCode OH_DDK_CreateAShMem(const uint8_t *name, size_t size, DDK_ASharedMem **aSharedMem); + +/** + * @brief Maps the created shared memory to the user space. Unmap the shared memory that is not required by using\n + * OH_DDK_UnMapAShMem. + * + * @param aShMemFd File descriptor of the shared memory to map. + * @param aShMemMapType Protection permission value of the shared memory. + * @return Returns DDK_SUCCESS if the operation is successful; returns a negative value otherwise. + * @since 12 + */ +DDK_RetCode OH_DDK_MapAShMem(const int32_t aShMemFd, const uint8_t aShMemMapType); + +/** + * @brief Unmaps shared memory. + * + * @param aShMemFd File descriptor of the shared memory to unmap. + * @return Returns DDK_SUCCESS if the operation is successful; returns a negative value otherwise. + * @since 12 + */ +DDK_RetCode OH_DDK_UnMapAShMem(const int32_t aShMemFd); + +/** + * @brief Destroys shared memory. + * + * @param aShMemFd File descriptor of the shared memory to destroy. + * @return Returns DDK_SUCCESS if the operation is successful; returns a negative value otherwise. + * @since 12 + */ +DDK_RetCode OH_DDK_DestroyAShMem(const int32_t aShMemFd); +/** @} */ +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif // DDK_API_H diff --git a/drivers/external_device_manager/base/ddk_types.h b/drivers/external_device_manager/base/ddk_types.h new file mode 100644 index 000000000..6b982cf37 --- /dev/null +++ b/drivers/external_device_manager/base/ddk_types.h @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2024 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 DDK_TYPES_H +#define DDK_TYPES_H + +/** + * @addtogroup Ddk + * @{ + * + * @brief Provides Base DDK types and declares the macros, enums, and\n + * data structs used by the Base DDK APIs. + * + * @since 12 + */ + +/** + * @file usb_ddk_types.h + * + * @brief Provides the enums, structs, and macros used in USB Base APIs. + * + * @syscap SystemCapability.Driver.DDK.Extension + * @since 12 + */ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @brief Defines the shared memory created by using OH_DDK_CreateAShMem.\n + * A buffer for the shared memory provides better performance. + * + * @since 12 + */ +typedef struct DDK_ASharedMem { + /** File descriptor of the shared memory. */ + int32_t aShMemFd; + /** Buffer address. */ + uint8_t * const address; + /** Buffer size. */ + const size_t size; + /** Offset of the used buffer. The default value is 0, which indicates that there is no offset\n + * and the buffer starts from the specified address. + */ + uint32_t offset; + /** Length of the used buffer. By default, the value is equal to the size, which indicates that\n + * the entire buffer is used. + */ + uint32_t bufferLength; + /** Length of the transferred data. */ + uint32_t transferredLength; +} DDK_ASharedMem; + +/** + * @brief Enumerates the permissions on the mapped memory. + * + * @since 12 + */ +typedef enum { + /** The mapped memory is inaccessible. */ + PROT_NONE = 0, + /** The mapped memory is readable. */ + PROT_READ = 1, + /** The mapped memory is writable. */ + PROT_WRITE = 2, + /** The mapped memory is executable. */ + PROT_EXEC = 4 + +} DDK_ASharedMemMapType; + +/** + * @brief Enumerates the error codes used in the Base DDK. + * + * @since 12 + */ +typedef enum { + /** Operation success */ + DDK_SUCCESS = 0, + /** Operation failed */ + DDK_FAILURE = -1, + /** Invalid parameter */ + DDK_INVALID_PARAMETER = -2, + /** Invalid operation */ + DDK_INVALID_OPERATION = -3, + /** Null pointer exception */ + DDK_NULL_PTR = -4 +} DDK_RetCode; +#ifdef __cplusplus +} +/** @} */ +#endif /* __cplusplus */ +#endif // DDK_TYPES_H diff --git a/drivers/external_device_manager/base/libhid.ndk.json b/drivers/external_device_manager/base/libhid.ndk.json new file mode 100644 index 000000000..ca085204b --- /dev/null +++ b/drivers/external_device_manager/base/libhid.ndk.json @@ -0,0 +1,14 @@ +[ + { + "name": "OH_DDK_CreateAShMem" + }, + { + "name": "OH_DDK_MapAShMem" + }, + { + "name": "OH_DDK_UnMapAShMem" + }, + { + "name": "OH_DDK_DestroyAShMem" + } +] \ No newline at end of file -- Gitee From 759b463bed8f33b4d7007c99f5dc55f0f8fc3bbf Mon Sep 17 00:00:00 2001 From: lixinsheng2 Date: Fri, 8 Mar 2024 13:00:55 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=89=A9=E5=B1=95=E5=A4=96=E8=AE=BE?= =?UTF-8?q?=E6=A1=86=E6=9E=B6=E6=96=B0=E5=A2=9E=E5=9F=BA=E7=A1=80api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixinsheng2 --- .../external_device_manager/base/ddk_api.h | 22 +++++++++---------- .../external_device_manager/base/ddk_types.h | 11 +++++----- .../base/libddk.ndk.json | 14 ++++++++++++ .../base/libhid.ndk.json | 14 ------------ 4 files changed, 30 insertions(+), 31 deletions(-) create mode 100644 drivers/external_device_manager/base/libddk.ndk.json delete mode 100644 drivers/external_device_manager/base/libhid.ndk.json diff --git a/drivers/external_device_manager/base/ddk_api.h b/drivers/external_device_manager/base/ddk_api.h index 362fa0614..3d2275a8c 100644 --- a/drivers/external_device_manager/base/ddk_api.h +++ b/drivers/external_device_manager/base/ddk_api.h @@ -43,44 +43,44 @@ extern "C" { /** * @brief Creates shared memory. To prevent resource leakage, destroy the shared memory that is not required by\n - * calling OH_DDK_DestroyAShMem. + * calling OH_DDK_DestroyAshmem. * * @param name Pointer to the shared memory to create. * @param size Size of the buffer corresponding to the shared memory. - * @param aSharedMem Pointer to the shared memory created. + * @param ashmem Pointer to the shared memory created. * @return Returns DDK_SUCCESS if the operation is successful; returns a negative value otherwise. * @since 12 */ -DDK_RetCode OH_DDK_CreateAShMem(const uint8_t *name, size_t size, DDK_ASharedMem **aSharedMem); +DDK_RetCode OH_DDK_CreateAshmem(const uint8_t *name, size_t size, DDK_Ashmem **ashmem); /** * @brief Maps the created shared memory to the user space. Unmap the shared memory that is not required by using\n - * OH_DDK_UnMapAShMem. + * OH_DDK_UnmapAshmemm. * - * @param aShMemFd File descriptor of the shared memory to map. - * @param aShMemMapType Protection permission value of the shared memory. + * @param ashmemFd File descriptor of the shared memory to map. + * @param ashmemMapType Protection permission value of the shared memory. * @return Returns DDK_SUCCESS if the operation is successful; returns a negative value otherwise. * @since 12 */ -DDK_RetCode OH_DDK_MapAShMem(const int32_t aShMemFd, const uint8_t aShMemMapType); +DDK_RetCode OH_DDK_MapAshmem(const int32_t ashmemFd, const uint8_t ashmemMapType); /** * @brief Unmaps shared memory. * - * @param aShMemFd File descriptor of the shared memory to unmap. + * @param ashmemFd File descriptor of the shared memory to unmap. * @return Returns DDK_SUCCESS if the operation is successful; returns a negative value otherwise. * @since 12 */ -DDK_RetCode OH_DDK_UnMapAShMem(const int32_t aShMemFd); +DDK_RetCode OH_DDK_UnmapAshmemm(const int32_t ashmemFd); /** * @brief Destroys shared memory. * - * @param aShMemFd File descriptor of the shared memory to destroy. + * @param ashmemFd File descriptor of the shared memory to destroy. * @return Returns DDK_SUCCESS if the operation is successful; returns a negative value otherwise. * @since 12 */ -DDK_RetCode OH_DDK_DestroyAShMem(const int32_t aShMemFd); +DDK_RetCode OH_DDK_DestroyAshmem(const int32_t ashmemFd); /** @} */ #ifdef __cplusplus } diff --git a/drivers/external_device_manager/base/ddk_types.h b/drivers/external_device_manager/base/ddk_types.h index 6b982cf37..c40d3dde2 100644 --- a/drivers/external_device_manager/base/ddk_types.h +++ b/drivers/external_device_manager/base/ddk_types.h @@ -42,14 +42,14 @@ extern "C" { #endif /* __cplusplus */ /** - * @brief Defines the shared memory created by using OH_DDK_CreateAShMem.\n + * @brief Defines the shared memory created by using OH_DDK_CreateAshmem.\n * A buffer for the shared memory provides better performance. * * @since 12 */ -typedef struct DDK_ASharedMem { +typedef struct DDK_Ashmem { /** File descriptor of the shared memory. */ - int32_t aShMemFd; + int32_t ashmemFd; /** Buffer address. */ uint8_t * const address; /** Buffer size. */ @@ -64,7 +64,7 @@ typedef struct DDK_ASharedMem { uint32_t bufferLength; /** Length of the transferred data. */ uint32_t transferredLength; -} DDK_ASharedMem; +} DDK_Ashmem; /** * @brief Enumerates the permissions on the mapped memory. @@ -80,8 +80,7 @@ typedef enum { PROT_WRITE = 2, /** The mapped memory is executable. */ PROT_EXEC = 4 - -} DDK_ASharedMemMapType; +} DDK_AshmemMapType; /** * @brief Enumerates the error codes used in the Base DDK. diff --git a/drivers/external_device_manager/base/libddk.ndk.json b/drivers/external_device_manager/base/libddk.ndk.json new file mode 100644 index 000000000..6d7083b1a --- /dev/null +++ b/drivers/external_device_manager/base/libddk.ndk.json @@ -0,0 +1,14 @@ +[ + { + "name": "OH_DDK_CreateAshmem" + }, + { + "name": "OH_DDK_MapAshmem" + }, + { + "name": "OH_DDK_UnmapAshmemm" + }, + { + "name": "OH_DDK_DestroyAshmem" + } +] \ No newline at end of file diff --git a/drivers/external_device_manager/base/libhid.ndk.json b/drivers/external_device_manager/base/libhid.ndk.json deleted file mode 100644 index ca085204b..000000000 --- a/drivers/external_device_manager/base/libhid.ndk.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "name": "OH_DDK_CreateAShMem" - }, - { - "name": "OH_DDK_MapAShMem" - }, - { - "name": "OH_DDK_UnMapAShMem" - }, - { - "name": "OH_DDK_DestroyAShMem" - } -] \ No newline at end of file -- Gitee