mirror of
https://github.com/openharmony/drivers_framework.git
synced 2026-07-19 16:24:45 -04:00
add OpenHarmony 1.0 baseline
This commit is contained in:
Executable
+13
@@ -0,0 +1,13 @@
|
||||
### 该问题是怎么引起的?
|
||||
|
||||
|
||||
|
||||
### 重现步骤
|
||||
|
||||
|
||||
|
||||
### 报错信息
|
||||
|
||||
|
||||
|
||||
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
### 相关的Issue
|
||||
|
||||
|
||||
### 原因(目的、解决的问题等)
|
||||
|
||||
|
||||
### 描述(做了什么,变更了什么)
|
||||
|
||||
|
||||
### 测试用例(新增、改动、可能影响的功能)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Executable
+84
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "device_resource_if.h"
|
||||
#include "hcs_tree_if.h"
|
||||
#include "hdf_log.h"
|
||||
|
||||
static void HcsIfaceConstruct(struct DeviceResourceIface *instance)
|
||||
{
|
||||
instance->GetRootNode = HcsGetRootNode;
|
||||
instance->GetBool = HcsGetBool;
|
||||
instance->GetUint8 = HcsGetUint8;
|
||||
instance->GetUint8ArrayElem = HcsGetUint8ArrayElem;
|
||||
instance->GetUint8Array = HcsGetUint8Array;
|
||||
instance->GetUint16 = HcsGetUint16;
|
||||
instance->GetUint16ArrayElem = HcsGetUint16ArrayElem;
|
||||
instance->GetUint16Array = HcsGetUint16Array;
|
||||
instance->GetUint32 = HcsGetUint32;
|
||||
instance->GetUint32ArrayElem = HcsGetUint32ArrayElem;
|
||||
instance->GetUint32Array = HcsGetUint32Array;
|
||||
instance->GetUint64 = HcsGetUint64;
|
||||
instance->GetUint64ArrayElem = HcsGetUint64ArrayElem;
|
||||
instance->GetUint64Array = HcsGetUint64Array;
|
||||
instance->GetString = HcsGetString;
|
||||
instance->GetStringArrayElem = HcsGetStringArrayElem;
|
||||
instance->GetElemNum = HcsGetElemNum;
|
||||
instance->GetNodeByMatchAttr = HcsGetNodeByMatchAttr;
|
||||
instance->GetChildNode = HcsGetChildNode;
|
||||
instance->GetNodeByRefAttr = HcsGetNodeByRefAttr;
|
||||
}
|
||||
|
||||
static bool DeviceResourceIfaceConstruct(struct DeviceResourceIface *instance, DeviceResourceType type)
|
||||
{
|
||||
switch (type) {
|
||||
case HDF_CONFIG_SOURCE:
|
||||
HcsIfaceConstruct(instance);
|
||||
break;
|
||||
default:
|
||||
HDF_LOGE("%s: Currently, this configuration type is not supported. the type is %d", __func__, type);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
struct DeviceResourceIface *DeviceResourceGetIfaceInstance(DeviceResourceType type)
|
||||
{
|
||||
static struct DeviceResourceIface *instance = NULL;
|
||||
if (instance == NULL) {
|
||||
static struct DeviceResourceIface singletonInstance;
|
||||
if (!DeviceResourceIfaceConstruct(&singletonInstance, type)) {
|
||||
return NULL;
|
||||
}
|
||||
instance = &singletonInstance;
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef HCS_BLOB_IF_H
|
||||
#define HCS_BLOB_IF_H
|
||||
|
||||
#include <string.h>
|
||||
#include "hdf_base.h"
|
||||
|
||||
#define CONFIG_NODE 0x1
|
||||
#define CONFIG_ATTR 0x2
|
||||
#define CONFIG_REFERENCE 0x3
|
||||
#define CONFIG_ARRAY 0x4
|
||||
#define CONFIG_BYTE 0x10
|
||||
#define CONFIG_WORD 0x11
|
||||
#define CONFIG_DWORD 0x12
|
||||
#define CONFIG_QWORD 0x13
|
||||
#define CONFIG_STRING 0x14
|
||||
|
||||
struct HbcHeader {
|
||||
uint32_t magicNumber;
|
||||
uint32_t versionMajor;
|
||||
uint32_t versionMinor;
|
||||
uint32_t checkSum;
|
||||
int32_t totalSize;
|
||||
};
|
||||
|
||||
#define HBC_MAGIC_NUMBER 0xA00AA00A
|
||||
#define HBC_HEADER_LENGTH sizeof(struct HbcHeader)
|
||||
#define HBC_BLOB_MAX_LENGTH (1024 * 1024 * 10) // The maximum length is 10 MB.
|
||||
#define HBC_ROOT_NAME "root"
|
||||
|
||||
bool HcsIsByteAlign(void);
|
||||
#define HCS_ALIGN_SIZE 4
|
||||
static inline size_t HcsAlignSize(size_t size)
|
||||
{
|
||||
return (size + HCS_ALIGN_SIZE - 1) & (~(HCS_ALIGN_SIZE - 1));
|
||||
}
|
||||
|
||||
static inline uint8_t HcsByteCodeToUint8(const char *start)
|
||||
{
|
||||
return *(uint8_t *)(start);
|
||||
}
|
||||
|
||||
static inline uint16_t HcsByteCodeToUint16(const char *start)
|
||||
{
|
||||
return *(uint16_t *)(start);
|
||||
}
|
||||
|
||||
static inline uint32_t HcsByteCodeToUint32(const char *start)
|
||||
{
|
||||
return *(uint32_t *)(start);
|
||||
}
|
||||
|
||||
static inline uint64_t HcsByteCodeToUint64(const char *start)
|
||||
{
|
||||
return *(uint64_t *)(start);
|
||||
}
|
||||
|
||||
static inline uint32_t HcsGetPrefix(const char *start)
|
||||
{
|
||||
return HcsIsByteAlign() ? HcsByteCodeToUint32(start) : HcsByteCodeToUint8(start);
|
||||
}
|
||||
|
||||
#define HCS_DWORD_LENGTH 4
|
||||
#define HCS_QWORD_LENGTH 8
|
||||
#define HCS_PREFIX_LENGTH (HcsIsByteAlign() ? HCS_DWORD_LENGTH : 1)
|
||||
#define HCS_BYTE_LENGTH (HcsIsByteAlign() ? HCS_DWORD_LENGTH : 1)
|
||||
#define HCS_WORD_LENGTH (HcsIsByteAlign() ? HCS_DWORD_LENGTH : 2)
|
||||
#define HCS_STRING_LENGTH(str) (HcsIsByteAlign() ? HcsAlignSize(strlen(str) + 1) : (strlen(str) + 1)) // add the '\0'.
|
||||
int32_t HcsGetDataTypeOffset(const char *start);
|
||||
int32_t HcsGetAttrLength(const char *start);
|
||||
int32_t HcsGetNodeOrAttrLength(const char *start);
|
||||
int32_t HcsGetNodeLength(const char *blob);
|
||||
bool HcsCheckBlobFormat(const char *start, uint32_t length);
|
||||
bool HcsSwapToUint8(uint8_t *value, const char *realValue, uint32_t type);
|
||||
bool HcsSwapToUint16(uint16_t *value, const char *realValue, uint32_t type);
|
||||
bool HcsSwapToUint32(uint32_t *value, const char *realValue, uint32_t type);
|
||||
bool HcsSwapToUint64(uint64_t *value, const char *realValue, uint32_t type);
|
||||
|
||||
#endif // HCS_BLOB_IF_H
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef HCS_GENERATE_TREE_H
|
||||
#define HCS_GENERATE_TREE_H
|
||||
|
||||
#include "device_resource_if.h"
|
||||
|
||||
#define TREE_STACK_MAX 64
|
||||
struct TreeStack {
|
||||
uint32_t offset; // the offset of node in blob
|
||||
struct DeviceResourceNode *node; // the node is the head node of every layer tree
|
||||
};
|
||||
int32_t GenerateCfgTree(const char *treeStart, int32_t length, char *treeMem, struct DeviceResourceNode **root);
|
||||
|
||||
#endif // HCS_GENERATE_TREE_H
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef HCS_PARSER_H
|
||||
#define HCS_PARSER_H
|
||||
|
||||
#include "device_resource_if.h"
|
||||
|
||||
bool HcsDecompile(const char *hcsBlob, uint32_t offset, struct DeviceResourceNode **root);
|
||||
|
||||
#endif // HCS_PARSER_H
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef HCS_TREE_IF_H
|
||||
#define HCS_TREE_IF_H
|
||||
|
||||
#include "device_resource_if.h"
|
||||
#include "hdf_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define HCS_MATCH_ATTR "match_attr"
|
||||
|
||||
const struct DeviceResourceNode *HcsGetRootNode(void);
|
||||
bool HcsGetBool(const struct DeviceResourceNode *node, const char *attrName);
|
||||
int32_t HcsGetUint8(const struct DeviceResourceNode *node, const char *attrName, uint8_t *value, uint8_t def);
|
||||
int32_t HcsGetUint8ArrayElem(const struct DeviceResourceNode *node, const char *attrName, uint32_t index,
|
||||
uint8_t *value, uint8_t def);
|
||||
int32_t HcsGetUint8Array(const struct DeviceResourceNode *node, const char *attrName, uint8_t *value, uint32_t len,
|
||||
uint8_t def);
|
||||
int32_t HcsGetUint16(const struct DeviceResourceNode *node, const char *attrName, uint16_t *value, uint16_t def);
|
||||
int32_t HcsGetUint16ArrayElem(const struct DeviceResourceNode *node, const char *attrName, uint32_t index,
|
||||
uint16_t *value, uint16_t def);
|
||||
int32_t HcsGetUint16Array(const struct DeviceResourceNode *node, const char *attrName, uint16_t *value, uint32_t len,
|
||||
uint16_t def);
|
||||
int32_t HcsGetUint32(const struct DeviceResourceNode *node, const char *attrName, uint32_t *value, uint32_t def);
|
||||
int32_t HcsGetUint32ArrayElem(const struct DeviceResourceNode *node, const char *attrName, uint32_t index,
|
||||
uint32_t *value, uint32_t def);
|
||||
int32_t HcsGetUint32Array(const struct DeviceResourceNode *node, const char *attrName, uint32_t *value,
|
||||
uint32_t len, uint32_t def);
|
||||
int32_t HcsGetUint64(const struct DeviceResourceNode *node, const char *attrName, uint64_t *value, uint64_t def);
|
||||
int32_t HcsGetUint64ArrayElem(const struct DeviceResourceNode *node, const char *attrName, uint32_t index,
|
||||
uint64_t *value, uint64_t def);
|
||||
int32_t HcsGetUint64Array(const struct DeviceResourceNode *node, const char *attrName, uint64_t *value,
|
||||
uint32_t len, uint64_t def);
|
||||
int32_t HcsGetStringArrayElem(const struct DeviceResourceNode *node, const char *attrName, uint32_t index,
|
||||
const char **value, const char *def);
|
||||
int32_t HcsGetString(const struct DeviceResourceNode *node, const char *attrName, const char **value, const char *def);
|
||||
int32_t HcsGetElemNum(const struct DeviceResourceNode *node, const char *attrName);
|
||||
const struct DeviceResourceNode *HcsGetNodeByMatchAttr(const struct DeviceResourceNode *node, const char *attrValue);
|
||||
const struct DeviceResourceNode *HcsGetChildNode(const struct DeviceResourceNode *node, const char *nodeName);
|
||||
const struct DeviceResourceNode *HcsGetNodeByRefAttr(const struct DeviceResourceNode *node, const char *attrName);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif // HCS_TREE_IF_H
|
||||
Executable
+232
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "hcs_blob_if.h"
|
||||
#include "hdf_log.h"
|
||||
|
||||
#define HDF_LOG_TAG hcs_blob_if
|
||||
|
||||
static bool g_byteAlign = false;
|
||||
|
||||
bool HcsIsByteAlign()
|
||||
{
|
||||
return g_byteAlign;
|
||||
}
|
||||
|
||||
int32_t HcsGetDataTypeOffset(const char *start)
|
||||
{
|
||||
int32_t len;
|
||||
switch (HcsGetPrefix(start)) {
|
||||
case CONFIG_BYTE:
|
||||
len = HCS_BYTE_LENGTH + HCS_PREFIX_LENGTH;
|
||||
break;
|
||||
case CONFIG_WORD:
|
||||
len = HCS_WORD_LENGTH + HCS_PREFIX_LENGTH;
|
||||
break;
|
||||
case CONFIG_DWORD:
|
||||
case CONFIG_REFERENCE:
|
||||
len = HCS_DWORD_LENGTH + HCS_PREFIX_LENGTH;
|
||||
break;
|
||||
case CONFIG_QWORD:
|
||||
len = HCS_QWORD_LENGTH + HCS_PREFIX_LENGTH;
|
||||
break;
|
||||
case CONFIG_STRING:
|
||||
len = HCS_STRING_LENGTH(start + HCS_PREFIX_LENGTH) + HCS_PREFIX_LENGTH;
|
||||
break;
|
||||
default:
|
||||
len = HDF_FAILURE;
|
||||
break;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
static int32_t HcsGetArrayLength(const char *start)
|
||||
{
|
||||
int32_t arrayLen = HCS_PREFIX_LENGTH + HCS_WORD_LENGTH;
|
||||
uint16_t count;
|
||||
(void)HcsSwapToUint16(&count, start + HCS_PREFIX_LENGTH, CONFIG_WORD);
|
||||
for (uint16_t i = 0; i < count; i++) {
|
||||
int32_t lenData = HcsGetDataTypeOffset(start + arrayLen);
|
||||
if (lenData < 0) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
arrayLen += lenData;
|
||||
}
|
||||
return arrayLen;
|
||||
}
|
||||
|
||||
int32_t HcsGetAttrLength(const char *start)
|
||||
{
|
||||
int32_t length = HCS_PREFIX_LENGTH + HCS_STRING_LENGTH(start + HCS_PREFIX_LENGTH);
|
||||
int32_t dataLen;
|
||||
switch (HcsGetPrefix(start + length)) {
|
||||
case CONFIG_BYTE:
|
||||
case CONFIG_WORD:
|
||||
case CONFIG_DWORD:
|
||||
case CONFIG_QWORD:
|
||||
case CONFIG_STRING:
|
||||
case CONFIG_REFERENCE:
|
||||
dataLen = HcsGetDataTypeOffset(start + length);
|
||||
break;
|
||||
case CONFIG_ARRAY:
|
||||
dataLen = HcsGetArrayLength(start + length);
|
||||
break;
|
||||
default:
|
||||
dataLen = HDF_FAILURE;
|
||||
break;
|
||||
}
|
||||
return (dataLen < 0) ? HDF_FAILURE : (dataLen + length);
|
||||
}
|
||||
|
||||
int32_t HcsGetNodeOrAttrLength(const char *start)
|
||||
{
|
||||
int32_t length;
|
||||
switch (HcsGetPrefix(start)) {
|
||||
case CONFIG_NODE:
|
||||
length = HCS_STRING_LENGTH(start + HCS_PREFIX_LENGTH) + HCS_PREFIX_LENGTH + HCS_DWORD_LENGTH;
|
||||
break;
|
||||
case CONFIG_ATTR:
|
||||
length = HcsGetAttrLength(start);
|
||||
break;
|
||||
default:
|
||||
length = HDF_FAILURE;
|
||||
break;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
int32_t HcsGetNodeLength(const char *blob)
|
||||
{
|
||||
int32_t rootLen = HcsGetNodeOrAttrLength(blob);
|
||||
if (rootLen < 0) {
|
||||
HDF_LOGE("%s failed, the rootLen is %d", __func__, rootLen);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
rootLen += HcsByteCodeToUint32(blob + HCS_PREFIX_LENGTH + HCS_STRING_LENGTH(blob + HCS_PREFIX_LENGTH));
|
||||
return rootLen;
|
||||
}
|
||||
|
||||
bool HcsSwapToUint8(uint8_t *value, const char *realValue, uint32_t type)
|
||||
{
|
||||
if (type == CONFIG_BYTE) {
|
||||
*value = g_byteAlign ? (uint8_t)HcsByteCodeToUint32(realValue) : HcsByteCodeToUint8(realValue);
|
||||
return true;
|
||||
}
|
||||
HDF_LOGE("%s failed, type: %u", __func__, type);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HcsSwapToUint16(uint16_t *value, const char *realValue, uint32_t type)
|
||||
{
|
||||
uint8_t data;
|
||||
if (type == CONFIG_WORD) {
|
||||
*value = g_byteAlign ? (uint16_t)HcsByteCodeToUint32(realValue) : HcsByteCodeToUint16(realValue);
|
||||
return true;
|
||||
}
|
||||
if (HcsSwapToUint8(&data, realValue, type)) {
|
||||
*value = data;
|
||||
return true;
|
||||
}
|
||||
HDF_LOGE("%s failed, type: %u", __func__, type);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HcsSwapToUint32(uint32_t *value, const char *realValue, uint32_t type)
|
||||
{
|
||||
uint16_t data;
|
||||
if (type == CONFIG_DWORD) {
|
||||
*value = HcsByteCodeToUint32(realValue);
|
||||
return true;
|
||||
}
|
||||
if (HcsSwapToUint16(&data, realValue, type)) {
|
||||
*value = data;
|
||||
return true;
|
||||
}
|
||||
HDF_LOGE("%s failed, type: %u", __func__, type);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HcsSwapToUint64(uint64_t *value, const char *realValue, uint32_t type)
|
||||
{
|
||||
uint32_t data;
|
||||
if (type == CONFIG_QWORD) {
|
||||
*value = HcsByteCodeToUint64(realValue);
|
||||
return true;
|
||||
}
|
||||
if (HcsSwapToUint32(&data, realValue, type)) {
|
||||
*value = data;
|
||||
return true;
|
||||
}
|
||||
HDF_LOGE("%s failed, type: %u", __func__, type);
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool CheckHcsBlobLength(const char *start, uint32_t length, struct HbcHeader *header)
|
||||
{
|
||||
uint32_t rootNodeLen = HCS_STRING_LENGTH(HBC_ROOT_NAME) + HCS_PREFIX_LENGTH + HCS_DWORD_LENGTH;
|
||||
uint32_t minLength = rootNodeLen + HBC_HEADER_LENGTH;
|
||||
uint32_t blobLength;
|
||||
if (header->totalSize >= 0) {
|
||||
blobLength = HBC_HEADER_LENGTH + header->totalSize;
|
||||
g_byteAlign = false;
|
||||
HDF_LOGE("%s: the blobLength: %u, byteAlign: %d, totalSize: %d", __func__, blobLength,
|
||||
g_byteAlign, header->totalSize);
|
||||
} else {
|
||||
blobLength = HBC_HEADER_LENGTH - header->totalSize;
|
||||
g_byteAlign = true;
|
||||
HDF_LOGE("%s: the blobLength: %u, byteAlign: %d, totalSize: %d", __func__, blobLength,
|
||||
g_byteAlign, header->totalSize);
|
||||
}
|
||||
if ((length != blobLength) || (blobLength < minLength)) {
|
||||
HDF_LOGE("%s failed, Hcsblob file length is %u, But the length of calculation is %u",
|
||||
__func__, length, blobLength);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HcsCheckBlobFormat(const char *start, uint32_t length)
|
||||
{
|
||||
struct HbcHeader *header = NULL;
|
||||
if ((start == NULL) || (length < HBC_HEADER_LENGTH) || (length > HBC_BLOB_MAX_LENGTH)) {
|
||||
HDF_LOGE("%s failed, Hcsblob file length is %u", __func__, length);
|
||||
return false;
|
||||
}
|
||||
header = (struct HbcHeader *)start;
|
||||
if (header->magicNumber != HBC_MAGIC_NUMBER) {
|
||||
HDF_LOGE("%s failed, the magic of HBC is %x", __func__, header->magicNumber);
|
||||
return false;
|
||||
}
|
||||
if (!CheckHcsBlobLength(start, length, header)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
+174
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "hcs_generate_tree.h"
|
||||
#include "hcs_blob_if.h"
|
||||
#include "hdf_log.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
#define HDF_LOG_TAG hcs_generate_tree
|
||||
|
||||
static struct DeviceResourceNode *GetParentNode(int32_t offset, const struct TreeStack *treeStack,
|
||||
int32_t *treeLayer, int32_t configOffset)
|
||||
{
|
||||
int32_t parentLayer = *treeLayer;
|
||||
while ((parentLayer > 0) && (configOffset + offset > 0)) {
|
||||
if (treeStack[parentLayer].offset >= (uint32_t)(configOffset + offset)) {
|
||||
*treeLayer = parentLayer;
|
||||
return treeStack[parentLayer].node;
|
||||
}
|
||||
parentLayer--;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct DeviceResourceNode *CreateTreeNode(const char *start, int32_t offset,
|
||||
struct DeviceResourceNode *parentNode, char **treeMem)
|
||||
{
|
||||
struct DeviceResourceNode *newNode = (struct DeviceResourceNode *)(*treeMem);
|
||||
*treeMem += sizeof(struct DeviceResourceNode);
|
||||
newNode->name = start + offset + HCS_PREFIX_LENGTH;
|
||||
newNode->hashValue = offset + sizeof(struct HbcHeader);
|
||||
if (parentNode != NULL) {
|
||||
newNode->parent = parentNode;
|
||||
struct DeviceResourceNode *curNode = parentNode->child;
|
||||
while ((curNode != NULL) && (curNode->sibling != NULL)) {
|
||||
curNode = curNode->sibling;
|
||||
}
|
||||
if (curNode == NULL) {
|
||||
parentNode->child = newNode;
|
||||
} else {
|
||||
curNode->sibling = newNode;
|
||||
}
|
||||
}
|
||||
return newNode;
|
||||
}
|
||||
|
||||
static bool UpdateTreeStack(struct TreeStack **treeStack, int32_t *treeLayer, struct DeviceResourceNode *newNode,
|
||||
uint32_t offset)
|
||||
{
|
||||
if (*treeLayer >= (TREE_STACK_MAX - 1)) {
|
||||
HDF_LOGE("%s failed, the treeLayer error. treeLayer: %d", __func__, *treeLayer);
|
||||
return false;
|
||||
}
|
||||
(*treeLayer)++;
|
||||
(*treeStack)[*treeLayer].node = newNode;
|
||||
(*treeStack)[*treeLayer].offset = offset;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool AddAttrInNode(const char *start, struct DeviceResourceNode *parentNode, char **treeMem)
|
||||
{
|
||||
if (parentNode == NULL) {
|
||||
HDF_LOGE("%s failed, the parentNode is NULL", __func__);
|
||||
return false;
|
||||
}
|
||||
struct DeviceResourceAttr *newAttr = (struct DeviceResourceAttr *)(*treeMem);
|
||||
*treeMem += sizeof(struct DeviceResourceAttr);
|
||||
newAttr->name = start + HCS_PREFIX_LENGTH;
|
||||
newAttr->value = start + HCS_PREFIX_LENGTH + HCS_STRING_LENGTH(newAttr->name);
|
||||
struct DeviceResourceAttr *curAttr = parentNode->attrData;
|
||||
parentNode->attrData = newAttr;
|
||||
newAttr->next = curAttr;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int32_t ParseByteCode(const char *treeStart, int32_t offset, char **treeMem,
|
||||
struct TreeStack **treeStack, int32_t *treeLayerOrMemLen)
|
||||
{
|
||||
int32_t termOffset = HcsGetNodeOrAttrLength(treeStart + offset);
|
||||
if (termOffset <= 0) {
|
||||
HDF_LOGE("%s failed, HcsGetNodeOrAttrLength failed, errno: %d", __func__, termOffset);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
struct DeviceResourceNode *parentOrCurNode = NULL;
|
||||
switch (HcsGetPrefix(treeStart + offset)) {
|
||||
case CONFIG_NODE:
|
||||
if (*treeMem == NULL) {
|
||||
*treeLayerOrMemLen += sizeof(struct DeviceResourceNode);
|
||||
break;
|
||||
}
|
||||
parentOrCurNode = GetParentNode(offset, *treeStack, treeLayerOrMemLen, termOffset);
|
||||
struct DeviceResourceNode *newNode = CreateTreeNode(treeStart, offset, parentOrCurNode, treeMem);
|
||||
uint32_t newNodeOffset;
|
||||
(void)HcsSwapToUint32(&newNodeOffset, treeStart + offset + HCS_STRING_LENGTH(newNode->name) +
|
||||
HCS_PREFIX_LENGTH, CONFIG_DWORD);
|
||||
newNodeOffset += offset + termOffset;
|
||||
if (!UpdateTreeStack(treeStack, treeLayerOrMemLen, newNode, newNodeOffset)) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
break;
|
||||
case CONFIG_ATTR:
|
||||
if (*treeMem == NULL) {
|
||||
*treeLayerOrMemLen += sizeof(struct DeviceResourceAttr);
|
||||
break;
|
||||
}
|
||||
parentOrCurNode = GetParentNode(offset, *treeStack, treeLayerOrMemLen, termOffset);
|
||||
if (!AddAttrInNode(treeStart + offset, parentOrCurNode, treeMem)) {
|
||||
HDF_LOGE("%s failed, the AddAttrInNode error", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
termOffset = HDF_FAILURE;
|
||||
break;
|
||||
}
|
||||
return termOffset;
|
||||
}
|
||||
|
||||
int32_t GenerateCfgTree(const char *treeStart, int32_t length, char *treeMem, struct DeviceResourceNode **root)
|
||||
{
|
||||
int32_t offset = 0;
|
||||
int32_t treeLayerOrMemLen = 0;
|
||||
|
||||
struct TreeStack *treeStack = (struct TreeStack *)OsalMemCalloc(sizeof(struct TreeStack) * TREE_STACK_MAX);
|
||||
if (treeStack == NULL) {
|
||||
HDF_LOGE("%s failed, treeStack malloc error", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
while ((offset < length) && (offset >= 0)) {
|
||||
int32_t eachOffset = ParseByteCode(treeStart, offset, &treeMem, &treeStack, &treeLayerOrMemLen);
|
||||
if (eachOffset <= 0) {
|
||||
HDF_LOGE("%s failed, the ParseByteCode error", __func__);
|
||||
treeLayerOrMemLen = eachOffset;
|
||||
break;
|
||||
}
|
||||
offset += eachOffset;
|
||||
}
|
||||
if ((treeMem != NULL) && (root != NULL) && (treeLayerOrMemLen > 0)) {
|
||||
// the treeStack[1] is root
|
||||
*root = treeStack[1].node;
|
||||
}
|
||||
OsalMemFree(treeStack);
|
||||
return treeLayerOrMemLen;
|
||||
}
|
||||
Executable
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "hcs_parser.h"
|
||||
#include "hcs_blob_if.h"
|
||||
#include "hcs_generate_tree.h"
|
||||
#include "hdf_log.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
#define HDF_LOG_TAG hcs_parser
|
||||
|
||||
static int32_t GetHcsTreeSize(const char *blob, int32_t nodeLength)
|
||||
{
|
||||
return GenerateCfgTree(blob, nodeLength, NULL, NULL);
|
||||
}
|
||||
|
||||
bool HcsDecompile(const char *hcsBlob, uint32_t offset, struct DeviceResourceNode **root)
|
||||
{
|
||||
int32_t nodeLength = HcsGetNodeLength(hcsBlob + offset);
|
||||
if (nodeLength < 0) {
|
||||
HDF_LOGE("%s failed, HcsGetNodeLength failed", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t treeMemLength = GetHcsTreeSize(hcsBlob + offset, nodeLength);
|
||||
if (treeMemLength <= 0) {
|
||||
HDF_LOGE("%s failed, GetHcsTreeSize failed", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
char *treeMem = (char *)OsalMemCalloc(treeMemLength);
|
||||
if (treeMem == NULL) {
|
||||
HDF_LOGE("%s failed, OsalMemCalloc Device tree memory failed", __func__);
|
||||
return false;
|
||||
}
|
||||
int32_t treeLayer = GenerateCfgTree(hcsBlob + offset, nodeLength, treeMem, root);
|
||||
if (treeLayer <= 0) {
|
||||
HDF_LOGE("%s failed, the treeLayer is %d", __func__, treeLayer);
|
||||
OsalMemFree(treeMem);
|
||||
*root = NULL;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Executable
+437
@@ -0,0 +1,437 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "hcs_tree_if.h"
|
||||
#include "hcs_blob_if.h"
|
||||
#include "hdf_log.h"
|
||||
|
||||
#define HDF_LOG_TAG hcs_tree_if
|
||||
|
||||
static struct DeviceResourceAttr *GetAttrInNode(const struct DeviceResourceNode *node, const char *attrName)
|
||||
{
|
||||
struct DeviceResourceAttr *attr = NULL;
|
||||
if ((node == NULL) || (attrName == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
for (attr = node->attrData; attr != NULL; attr = attr->next) {
|
||||
if ((attr->name != NULL) && (strcmp(attr->name, attrName) == 0)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return attr;
|
||||
}
|
||||
|
||||
bool HcsGetBool(const struct DeviceResourceNode *node, const char *attrName)
|
||||
{
|
||||
struct DeviceResourceAttr *attr = GetAttrInNode(node, attrName);
|
||||
if ((attr == NULL) || (attr->value == NULL)) {
|
||||
HDF_LOGE("%s failed, the node or attrName is NULL", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t value;
|
||||
if (!HcsSwapToUint8(&value, attr->value + HCS_PREFIX_LENGTH, HcsGetPrefix(attr->value))) {
|
||||
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
|
||||
return false;
|
||||
}
|
||||
return value ? true : false;
|
||||
}
|
||||
|
||||
#define RETURN_DEFAULT_VALUE(attr, attrName, value, def) do { \
|
||||
if (((attr) == NULL) || ((attr)->value == NULL) || ((value) == NULL)) { \
|
||||
HDF_LOGE("%s failed, the attr of %s is NULL, or the value is NULL, return the default value", \
|
||||
__func__, ((attrName) == NULL) ? "error attrName" : (attrName)); \
|
||||
if ((value) != NULL) { \
|
||||
*(value) = (def); \
|
||||
} \
|
||||
return HDF_FAILURE; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
int32_t HcsGetUint8(const struct DeviceResourceNode *node, const char *attrName, uint8_t *value, uint8_t def)
|
||||
{
|
||||
struct DeviceResourceAttr *attr = GetAttrInNode(node, attrName);
|
||||
RETURN_DEFAULT_VALUE(attr, attrName, value, def);
|
||||
|
||||
if (!HcsSwapToUint8(value, attr->value + HCS_PREFIX_LENGTH, HcsGetPrefix(attr->value))) {
|
||||
*value = def;
|
||||
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t HcsGetUint16(const struct DeviceResourceNode *node, const char *attrName, uint16_t *value, uint16_t def)
|
||||
{
|
||||
struct DeviceResourceAttr *attr = GetAttrInNode(node, attrName);
|
||||
RETURN_DEFAULT_VALUE(attr, attrName, value, def);
|
||||
|
||||
if (!HcsSwapToUint16(value, attr->value + HCS_PREFIX_LENGTH, HcsGetPrefix(attr->value))) {
|
||||
*value = def;
|
||||
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t HcsGetUint32(const struct DeviceResourceNode *node, const char *attrName, uint32_t *value, uint32_t def)
|
||||
{
|
||||
struct DeviceResourceAttr *attr = GetAttrInNode(node, attrName);
|
||||
RETURN_DEFAULT_VALUE(attr, attrName, value, def);
|
||||
|
||||
if (!HcsSwapToUint32(value, attr->value + HCS_PREFIX_LENGTH, HcsGetPrefix(attr->value))) {
|
||||
*value = def;
|
||||
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t HcsGetUint64(const struct DeviceResourceNode *node, const char *attrName, uint64_t *value, uint64_t def)
|
||||
{
|
||||
struct DeviceResourceAttr *attr = GetAttrInNode(node, attrName);
|
||||
RETURN_DEFAULT_VALUE(attr, attrName, value, def);
|
||||
|
||||
if (!HcsSwapToUint64(value, attr->value + HCS_PREFIX_LENGTH, HcsGetPrefix(attr->value))) {
|
||||
*value = def;
|
||||
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static const char *GetArrayElem(const struct DeviceResourceAttr *attr, uint32_t index)
|
||||
{
|
||||
int32_t offset = HCS_WORD_LENGTH + HCS_PREFIX_LENGTH;
|
||||
uint16_t count;
|
||||
if ((HcsGetPrefix(attr->value) != CONFIG_ARRAY) ||
|
||||
!HcsSwapToUint16(&count, attr->value + HCS_PREFIX_LENGTH, CONFIG_WORD)) {
|
||||
HDF_LOGE("%s failed, the attr of %s is not array", __func__, attr->name);
|
||||
return NULL;
|
||||
}
|
||||
if (index >= count) {
|
||||
HDF_LOGE("%s failed, the index: %u >= count: %u", __func__, index, count);
|
||||
return NULL;
|
||||
}
|
||||
for (uint32_t i = 0; i < index; i++) {
|
||||
int32_t result = HcsGetDataTypeOffset(attr->value + offset);
|
||||
if (result < 0) {
|
||||
return NULL;
|
||||
}
|
||||
offset += result;
|
||||
}
|
||||
return attr->value + offset;
|
||||
}
|
||||
|
||||
int32_t HcsGetUint8ArrayElem(const struct DeviceResourceNode *node, const char *attrName, uint32_t index,
|
||||
uint8_t *value, uint8_t def)
|
||||
{
|
||||
const char *realValue = NULL;
|
||||
struct DeviceResourceAttr *attr = GetAttrInNode(node, attrName);
|
||||
RETURN_DEFAULT_VALUE(attr, attrName, value, def);
|
||||
|
||||
realValue = GetArrayElem(attr, index);
|
||||
if (realValue == NULL) {
|
||||
*value = def;
|
||||
HDF_LOGE("%s failed, the realValue is NULL", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (!HcsSwapToUint8(value, realValue + HCS_PREFIX_LENGTH, HcsGetPrefix(realValue))) {
|
||||
*value = def;
|
||||
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t HcsGetUint16ArrayElem(const struct DeviceResourceNode *node, const char *attrName, uint32_t index,
|
||||
uint16_t *value, uint16_t def)
|
||||
{
|
||||
const char *realValue = NULL;
|
||||
struct DeviceResourceAttr *attr = GetAttrInNode(node, attrName);
|
||||
RETURN_DEFAULT_VALUE(attr, attrName, value, def);
|
||||
|
||||
realValue = GetArrayElem(attr, index);
|
||||
if (realValue == NULL) {
|
||||
*value = def;
|
||||
HDF_LOGE("%s failed, the realValue is NULL", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (!HcsSwapToUint16(value, realValue + HCS_PREFIX_LENGTH, HcsGetPrefix(realValue))) {
|
||||
*value = def;
|
||||
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t HcsGetUint32ArrayElem(const struct DeviceResourceNode *node, const char *attrName, uint32_t index,
|
||||
uint32_t *value, uint32_t def)
|
||||
{
|
||||
const char *realValue = NULL;
|
||||
struct DeviceResourceAttr *attr = GetAttrInNode(node, attrName);
|
||||
RETURN_DEFAULT_VALUE(attr, attrName, value, def);
|
||||
|
||||
realValue = GetArrayElem(attr, index);
|
||||
if (realValue == NULL) {
|
||||
*value = def;
|
||||
HDF_LOGE("%s failed, the realValue is NULL", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (!HcsSwapToUint32(value, realValue + HCS_PREFIX_LENGTH, HcsGetPrefix(realValue))) {
|
||||
*value = def;
|
||||
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t HcsGetUint64ArrayElem(const struct DeviceResourceNode *node, const char *attrName, uint32_t index,
|
||||
uint64_t *value, uint64_t def)
|
||||
{
|
||||
const char *realValue = NULL;
|
||||
struct DeviceResourceAttr *attr = GetAttrInNode(node, attrName);
|
||||
RETURN_DEFAULT_VALUE(attr, attrName, value, def);
|
||||
|
||||
realValue = GetArrayElem(attr, index);
|
||||
if ((realValue == NULL) || !HcsSwapToUint64(value, realValue + HCS_PREFIX_LENGTH, HcsGetPrefix(realValue))) {
|
||||
*value = def;
|
||||
HDF_LOGE("%s failed, the realValue is NULL or incorrect prefix code", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
#define CONTINUE_RETURN_DIFFERENT_ERRNO(ret, result) do { \
|
||||
if ((result) == HDF_ERR_INVALID_OBJECT) { \
|
||||
(ret) = HDF_ERR_INVALID_OBJECT; \
|
||||
HDF_LOGE("%s failed, the ret is %d", __func__, (result)); \
|
||||
continue; \
|
||||
} \
|
||||
if ((result) != HDF_SUCCESS) { \
|
||||
HDF_LOGE("%s failed, the ret is %d", __func__, (result)); \
|
||||
return result; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
int32_t HcsGetUint8Array(const struct DeviceResourceNode *node, const char *attrName, uint8_t *value, uint32_t len,
|
||||
uint8_t def)
|
||||
{
|
||||
if ((value == NULL) || (len == 0)) {
|
||||
HDF_LOGE("%s failed, parameter error, len: %u", __func__, len);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
int32_t ret = HDF_SUCCESS;
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
int32_t result = HcsGetUint8ArrayElem(node, attrName, i, value + i, def);
|
||||
// If the error type is HDF_ERR_INVALID_OBJECT, the error is recorded and returned after the loop exits.
|
||||
CONTINUE_RETURN_DIFFERENT_ERRNO(ret, result);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t HcsGetUint16Array(const struct DeviceResourceNode *node, const char *attrName, uint16_t *value, uint32_t len,
|
||||
uint16_t def)
|
||||
{
|
||||
if ((value == NULL) || (len == 0)) {
|
||||
HDF_LOGE("%s failed, parameter error, len: %u", __func__, len);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
int32_t ret = HDF_SUCCESS;
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
int32_t result = HcsGetUint16ArrayElem(node, attrName, i, value + i, def);
|
||||
// If the error type is HDF_ERR_INVALID_OBJECT, the error is recorded and returned after the loop exits.
|
||||
CONTINUE_RETURN_DIFFERENT_ERRNO(ret, result);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t HcsGetUint32Array(const struct DeviceResourceNode *node, const char *attrName, uint32_t *value, uint32_t len,
|
||||
uint32_t def)
|
||||
{
|
||||
if ((value == NULL) || (len == 0)) {
|
||||
HDF_LOGE("%s failed, parameter error, len: %u", __func__, len);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
int32_t ret = HDF_SUCCESS;
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
int32_t result = HcsGetUint32ArrayElem(node, attrName, i, value + i, def);
|
||||
// If the error type is HDF_ERR_INVALID_OBJECT, the error is recorded and returned after the loop exits.
|
||||
CONTINUE_RETURN_DIFFERENT_ERRNO(ret, result);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t HcsGetUint64Array(const struct DeviceResourceNode *node, const char *attrName, uint64_t *value, uint32_t len,
|
||||
uint64_t def)
|
||||
{
|
||||
if ((value == NULL) || (len == 0)) {
|
||||
HDF_LOGE("%s failed, parameter error, len: %u", __func__, len);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
int32_t result = HcsGetUint64ArrayElem(node, attrName, i, value + i, def);
|
||||
if (result != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s failed, the ret is %d", __func__, result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t HcsGetStringArrayElem(const struct DeviceResourceNode *node, const char *attrName, uint32_t index,
|
||||
const char **value, const char *def)
|
||||
{
|
||||
struct DeviceResourceAttr *attr = GetAttrInNode(node, attrName);
|
||||
RETURN_DEFAULT_VALUE(attr, attrName, value, def);
|
||||
|
||||
const char *realValue = GetArrayElem(attr, index);
|
||||
if ((realValue == NULL) || (HcsGetPrefix(realValue) != CONFIG_STRING)) {
|
||||
*value = def;
|
||||
HDF_LOGE("%s failed, %s attr is default value", __func__, attrName);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
*value = realValue + HCS_PREFIX_LENGTH;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t HcsGetString(const struct DeviceResourceNode *node, const char *attrName, const char **value, const char *def)
|
||||
{
|
||||
struct DeviceResourceAttr *attr = GetAttrInNode(node, attrName);
|
||||
RETURN_DEFAULT_VALUE(attr, attrName, value, def);
|
||||
if (HcsGetPrefix(attr->value) != CONFIG_STRING) {
|
||||
*value = def;
|
||||
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
*value = attr->value + HCS_PREFIX_LENGTH;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t HcsGetElemNum(const struct DeviceResourceNode *node, const char *attrName)
|
||||
{
|
||||
struct DeviceResourceAttr *attr = GetAttrInNode(node, attrName);
|
||||
if ((attr == NULL) || (attr->value == NULL) || (HcsGetPrefix(attr->value) != CONFIG_ARRAY)) {
|
||||
HDF_LOGE("%s failed, %s attr error", __func__, (attrName == NULL) ? "error attrName" : attrName);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
uint16_t num;
|
||||
(void)HcsSwapToUint16(&num, attr->value + HCS_PREFIX_LENGTH, CONFIG_WORD);
|
||||
return num;
|
||||
}
|
||||
|
||||
static struct DeviceResourceAttr *GetAttrValueInNode(const struct DeviceResourceNode *node, const char *attrValue)
|
||||
{
|
||||
struct DeviceResourceAttr *attr = NULL;
|
||||
if ((node == NULL) || (attrValue == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
for (attr = node->attrData; attr != NULL; attr = attr->next) {
|
||||
if ((attr->value != NULL) && (strcmp(attr->value + HCS_PREFIX_LENGTH, attrValue) == 0) &&
|
||||
(attr->name != NULL) && (strcmp(attr->name, HCS_MATCH_ATTR) == 0)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return attr;
|
||||
}
|
||||
|
||||
static const struct DeviceResourceNode *TraverseTreeNode(const struct DeviceResourceNode *curNode)
|
||||
{
|
||||
const struct DeviceResourceNode *nextNode = curNode;
|
||||
while (nextNode->parent && !nextNode->sibling) {
|
||||
nextNode = nextNode->parent;
|
||||
}
|
||||
nextNode = nextNode->sibling;
|
||||
return nextNode;
|
||||
}
|
||||
|
||||
const struct DeviceResourceNode *HcsGetNodeByMatchAttr(const struct DeviceResourceNode *node, const char *attrValue)
|
||||
{
|
||||
struct DeviceResourceIface *instance = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
|
||||
if ((attrValue == NULL) || (instance == NULL) || (instance->GetRootNode == NULL)) {
|
||||
HDF_LOGE("%s failed, attrValue is NULL or DeviceResourceGetIfaceInstance error", __func__);
|
||||
return NULL;
|
||||
}
|
||||
const struct DeviceResourceNode *curNode = (node != NULL) ? node : instance->GetRootNode();
|
||||
while (curNode != NULL) {
|
||||
if (GetAttrValueInNode(curNode, attrValue) != NULL) {
|
||||
break;
|
||||
}
|
||||
curNode = (curNode->child != NULL) ? curNode->child : TraverseTreeNode(curNode);
|
||||
}
|
||||
return curNode;
|
||||
}
|
||||
|
||||
const struct DeviceResourceNode *HcsGetChildNode(const struct DeviceResourceNode *node, const char *nodeName)
|
||||
{
|
||||
if ((node == NULL) || (nodeName == NULL)) {
|
||||
HDF_LOGE("%s failed, the node or nodeName is NULL", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct DeviceResourceNode *child = NULL;
|
||||
for (child = node->child; child != NULL; child = child->sibling) {
|
||||
if ((child->name != NULL) && (strcmp(nodeName, child->name) == 0)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return child;
|
||||
}
|
||||
|
||||
const struct DeviceResourceNode *HcsGetNodeByRefAttr(const struct DeviceResourceNode *node, const char *attrName)
|
||||
{
|
||||
struct DeviceResourceAttr *attr = GetAttrInNode(node, attrName);
|
||||
if ((attr == NULL) || (attr->value == NULL) || (HcsGetPrefix(attr->value) != CONFIG_REFERENCE)) {
|
||||
HDF_LOGE("%s failed, %s attr error", __func__, (attrName == NULL) ? "error attrName" : attrName);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint32_t attrValue;
|
||||
(void)HcsSwapToUint32(&attrValue, attr->value + HCS_PREFIX_LENGTH, CONFIG_DWORD);
|
||||
struct DeviceResourceIface *instance = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
|
||||
if ((instance == NULL) || (instance->GetRootNode == NULL)) {
|
||||
HDF_LOGE("%s failed, DeviceResourceGetIfaceInstance error", __func__);
|
||||
return NULL;
|
||||
}
|
||||
const struct DeviceResourceNode *curNode = instance->GetRootNode();
|
||||
while (curNode != NULL) {
|
||||
if (curNode->hashValue == attrValue) {
|
||||
break;
|
||||
}
|
||||
curNode = (curNode->child != NULL) ? curNode->child : TraverseTreeNode(curNode);
|
||||
}
|
||||
return curNode;
|
||||
}
|
||||
Executable
+416
@@ -0,0 +1,416 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
/**
|
||||
* @addtogroup Core
|
||||
* @{
|
||||
*
|
||||
* @brief Provides OpenHarmony Driver Foundation (HDF) APIs.
|
||||
*
|
||||
* The HDF implements driver framework capabilities such as driver loading, service management,
|
||||
* and driver message model. You can develop drivers based on the HDF.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file hdf_sbuf.h
|
||||
*
|
||||
* @brief Defines functions related to a <b>HdfSBuf</b>. The HDF provides data serialization and deserialization
|
||||
* capabilities for data transmission between user-mode applications and kernel-mode drivers.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
#ifndef HDF_SBUF_H
|
||||
#define HDF_SBUF_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "hdf_cstring.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Defines a <b>HdfSBuf</b>.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct HdfSBuf {
|
||||
size_t writePos; /**< Current write position */
|
||||
size_t readPos; /**< Current read position */
|
||||
size_t capacity; /**< Storage capacity, at most 512 KB. */
|
||||
uint8_t *data; /**< Pointer to data storage */
|
||||
bool isBind; /**< Whether to bind the externally transferred pointer for data storage */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Writes a data segment to a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param data Indicates the pointer to the data segment to write.
|
||||
* @param writeSize Indicates the size of the data segment to write. The maximum value is 512 KB.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufWriteBuffer(struct HdfSBuf *sbuf, const void *data, uint32_t writeSize);
|
||||
|
||||
/**
|
||||
* @brief Writes a 64-bit unsigned integer to a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param value Indicates the 64-bit unsigned integer to write.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufWriteUint64(struct HdfSBuf *sbuf, uint64_t value);
|
||||
|
||||
/**
|
||||
* @brief Writes a 32-bit unsigned integer to a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param value Indicates the 32-bit unsigned integer to write.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufWriteUint32(struct HdfSBuf *sbuf, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Writes a 16-bit unsigned integer to a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param value Indicates the 16-bit unsigned integer to write.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufWriteUint16(struct HdfSBuf *sbuf, uint16_t value);
|
||||
|
||||
/**
|
||||
* @brief Writes an 8-bit unsigned integer to a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param value Indicates the 8-bit unsigned integer to write.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufWriteUint8(struct HdfSBuf *sbuf, uint8_t value);
|
||||
|
||||
/**
|
||||
* @brief Writes a 64-bit signed integer to a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param value Indicates the 64-bit signed integer to write.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufWriteInt64(struct HdfSBuf *sbuf, int64_t value);
|
||||
|
||||
/**
|
||||
* @brief Writes a 32-bit signed integer to a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param value Indicates the 32-bit signed integer to write.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufWriteInt32(struct HdfSBuf *sbuf, int32_t value);
|
||||
|
||||
/**
|
||||
* @brief Writes a 16-bit signed integer to a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param value Indicates the 16-bit signed integer to write.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufWriteInt16(struct HdfSBuf *sbuf, int16_t value);
|
||||
|
||||
/**
|
||||
* @brief Writes an 8-bit signed integer to a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param value Indicates the 8-bit signed integer to write.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufWriteInt8(struct HdfSBuf *sbuf, int8_t value);
|
||||
|
||||
/**
|
||||
* @brief Writes a string to a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param value Indicates the pointer to the string to write.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufWriteString(struct HdfSBuf *sbuf, const char *value);
|
||||
|
||||
/**
|
||||
* @brief Reads a data segment from a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param data Indicates the double pointer to the data read. The data read is stored in <b>*data</b>,
|
||||
* which is requested by the caller. The memory pointed to by <b>*data</b> is managed by the <b>SBuf</b>
|
||||
* and they share the same lifecycle.
|
||||
* @param readSize Indicates the pointer to the size of the data read.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufReadBuffer(struct HdfSBuf *sbuf, const void **data, uint32_t *readSize);
|
||||
|
||||
/**
|
||||
* @brief Reads a 64-bit unsigned integer from a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param value Indicates the pointer to the 64-bit unsigned integer read, which is requested by the caller.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufReadUint64(struct HdfSBuf *sbuf, uint64_t *value);
|
||||
|
||||
/**
|
||||
* @brief Reads a 32-bit unsigned integer from a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param value Indicates the pointer to the 32-bit unsigned integer read, which is requested by the caller.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufReadUint32(struct HdfSBuf *sbuf, uint32_t *value);
|
||||
|
||||
/**
|
||||
* @brief Reads a 16-bit unsigned integer from a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param value Indicates the pointer to the 16-bit unsigned integer read, which is requested by the caller.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufReadUint16(struct HdfSBuf *sbuf, uint16_t *value);
|
||||
|
||||
/**
|
||||
* @brief Reads an 8-bit unsigned integer from a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param value Indicates the pointer to the 8-bit unsigned integer read, which is requested by the caller.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufReadUint8(struct HdfSBuf *sbuf, uint8_t *value);
|
||||
|
||||
/**
|
||||
* @brief Reads a 64-bit signed integer from a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param value Indicates the pointer to the 64-bit signed integer read, which is requested by the caller.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufReadInt64(struct HdfSBuf *sbuf, int64_t *value);
|
||||
|
||||
/**
|
||||
* @brief Reads a 32-bit signed integer from a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param value Indicates the pointer to the 32-bit signed integer read, which is requested by the caller.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufReadInt32(struct HdfSBuf *sbuf, int32_t *value);
|
||||
|
||||
/**
|
||||
* @brief Reads a 16-bit signed integer from a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param value Indicates the pointer to the 16-bit signed integer read, which is requested by the caller.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufReadInt16(struct HdfSBuf *sbuf, int16_t *value);
|
||||
|
||||
/**
|
||||
* @brief Reads an 8-bit signed integer from a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param value Indicates the pointer to the 8-bit signed integer read, which is requested by the caller.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufReadInt8(struct HdfSBuf *sbuf, int8_t *value);
|
||||
|
||||
/**
|
||||
* @brief Reads a string from a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @return Returns the pointer to the string read if the operation is successful; returns <b>NULL</b> otherwise.
|
||||
* The memory pointed to by this pointer is managed by the <b>SBuf</b> and they share the same lifecycle.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
const char *HdfSbufReadString(struct HdfSBuf *sbuf);
|
||||
|
||||
/**
|
||||
* @brief Obtains the pointer to the data stored in a<b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @return Returns the pointer to the data stored in the target <b>SBuf</b>.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
uint8_t *HdfSbufGetData(const struct HdfSBuf *sbuf);
|
||||
|
||||
/**
|
||||
* @brief Clears the data stored in a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void HdfSbufFlush(struct HdfSBuf *sbuf);
|
||||
|
||||
/**
|
||||
* @brief Obtains the capacity of a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @return Returns the <b>SBuf</b> capacity.
|
||||
* @since 1.0
|
||||
*/
|
||||
size_t HdfSbufGetCapacity(const struct HdfSBuf *sbuf);
|
||||
|
||||
/**
|
||||
* @brief Obtains the size of the data stored in a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @return Returns the data size.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
size_t HdfSbufGetDataSize(const struct HdfSBuf *sbuf);
|
||||
|
||||
/**
|
||||
* @brief Obtains a <b>SBuf</b> instance.
|
||||
*
|
||||
* @param capacity Indicates the initial capacity of the<b>SBuf</b>.
|
||||
* @return Returns the <b>SBuf</b> instance.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct HdfSBuf *HdfSBufObtain(size_t capacity);
|
||||
|
||||
/**
|
||||
* @brief Obtains a <b>SBuf</b> instance of the default capacity (256 bytes).
|
||||
*
|
||||
* @return Returns the <b>SBuf</b> instance.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct HdfSBuf *HdfSBufObtainDefaultSize(void);
|
||||
|
||||
/**
|
||||
* @brief Creates a <b>SBuf</b> instance with the specified data and size.
|
||||
* The pointer to the data stored in the <b>SBuf</b> is released by the caller,
|
||||
* and the written data size should not exceed the specified value of <b>size</b>.
|
||||
*
|
||||
* @param base Indicates the base of the data to use.
|
||||
* @param size Indicates the size of the data to use.
|
||||
* @return Returns the <b>SBuf</b> instance.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct HdfSBuf *HdfSBufBind(uintptr_t base, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Releases a <b>SBuf </b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the <b>SBuf</b> to release.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void HdfSBufRecycle(struct HdfSBuf *sbuf);
|
||||
|
||||
/**
|
||||
* @brief Creates a <b>SBuf</b> instance with an original <b>SBuf</b>.
|
||||
* This function moves the data stored in the original <b>SBuf</b> to the new one without memory copy.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the original <b>SBuf</b>.
|
||||
* @return Returns the new <b>SBuf</b> instance.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct HdfSBuf *HdfSBufMove(struct HdfSBuf *sbuf);
|
||||
|
||||
/**
|
||||
* @brief Creates a <b>SBuf</b> instance with an original <b>SBuf</b>.
|
||||
* This function copies the data stored in the original <b>SBuf</b> to the new one.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the original <b>SBuf</b>.
|
||||
* @return Returns the new <b>SBuf</b> instance.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct HdfSBuf *HdfSBufCopy(const struct HdfSBuf *sbuf);
|
||||
|
||||
/**
|
||||
* @brief Transfers the data ownership to a <b>SBuf</b>. Once the <b>SBuf</b> is released,
|
||||
* the bound data memory is also released. This function is used together with {@link HdfSBufBind}.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void HdfSbufTransDataOwnership(struct HdfSBuf *sbuf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* HDF_SBUF_H */
|
||||
/** @} */
|
||||
Executable
+474
@@ -0,0 +1,474 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 <securec.h>
|
||||
#include "osal_mem.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_sbuf.h"
|
||||
|
||||
#define HDF_SBUF_GROW_SIZE_DEFAULT 256
|
||||
#define HDF_SBUF_MAX_SIZE (512 * 1024) // 512kB
|
||||
#define HDF_SBUF_ALIGN 4
|
||||
|
||||
static inline size_t HdfSbufGetAlignSize(size_t size)
|
||||
{
|
||||
return (size + HDF_SBUF_ALIGN - 1) & (~(HDF_SBUF_ALIGN - 1));
|
||||
}
|
||||
|
||||
static size_t HdfSbufGetLeftWriteSize(struct HdfSBuf *sbuf)
|
||||
{
|
||||
return (sbuf->capacity < sbuf->writePos) ? 0 : (sbuf->capacity - sbuf->writePos);
|
||||
}
|
||||
|
||||
static size_t HdfSbufGetLeftReadSize(struct HdfSBuf *sbuf)
|
||||
{
|
||||
return (sbuf->writePos < sbuf->readPos) ? 0 : (sbuf->writePos - sbuf->readPos);
|
||||
}
|
||||
|
||||
static bool HdfSbufWriteRollback(struct HdfSBuf *sbuf, uint32_t size)
|
||||
{
|
||||
size_t alignSize = HdfSbufGetAlignSize(size);
|
||||
if (sbuf->writePos < alignSize) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sbuf->writePos -= alignSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HdfSbufReadRollback(struct HdfSBuf *sbuf, uint32_t size)
|
||||
{
|
||||
size_t alignSize = HdfSbufGetAlignSize(size);
|
||||
if (sbuf->readPos < alignSize) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sbuf->readPos -= alignSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *HdfSbufGetData(const struct HdfSBuf *sbuf)
|
||||
{
|
||||
if (sbuf == NULL) {
|
||||
HDF_LOGE("Get data is null, input sbuf is null");
|
||||
return NULL;
|
||||
}
|
||||
return (uint8_t *)sbuf->data;
|
||||
}
|
||||
|
||||
void HdfSbufFlush(struct HdfSBuf *sbuf)
|
||||
{
|
||||
if (sbuf != NULL) {
|
||||
sbuf->readPos = 0;
|
||||
sbuf->writePos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
size_t HdfSbufGetCapacity(const struct HdfSBuf *sbuf)
|
||||
{
|
||||
return (sbuf != NULL) ? sbuf->capacity : 0;
|
||||
}
|
||||
|
||||
size_t HdfSbufGetDataSize(const struct HdfSBuf *sbuf)
|
||||
{
|
||||
return (sbuf != NULL) ? sbuf->writePos : 0;
|
||||
}
|
||||
|
||||
static bool HdfSbufGrow(struct HdfSBuf *sbuf, uint32_t growSize)
|
||||
{
|
||||
if (sbuf->isBind) {
|
||||
HDF_LOGE("%s: binded sbuf oom", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t newSize = HdfSbufGetAlignSize(sbuf->capacity + growSize);
|
||||
if (newSize < sbuf->capacity) {
|
||||
HDF_LOGE("%s: grow size overflow", __func__);
|
||||
return false;
|
||||
}
|
||||
if (newSize > HDF_SBUF_MAX_SIZE) {
|
||||
HDF_LOGE("%s: buf size over limit", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t *newData = OsalMemCalloc(newSize);
|
||||
if (newData == NULL) {
|
||||
HDF_LOGE("%s: oom", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (memcpy_s(newData, newSize, sbuf->data, sbuf->writePos) != EOK) {
|
||||
OsalMemFree(newData);
|
||||
return false;
|
||||
}
|
||||
|
||||
OsalMemFree(sbuf->data);
|
||||
sbuf->data = newData;
|
||||
sbuf->capacity = newSize;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HdfSbufWrite(struct HdfSBuf *sbuf, const uint8_t *data, uint32_t size)
|
||||
{
|
||||
if (sbuf == NULL || data == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (size == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t alignSize = HdfSbufGetAlignSize(size);
|
||||
// in case of desireCapacity overflow
|
||||
if (alignSize < size) {
|
||||
HDF_LOGE("desireCapacity is overflow");
|
||||
return false;
|
||||
}
|
||||
size_t writeableSize = HdfSbufGetLeftWriteSize(sbuf);
|
||||
if (alignSize > writeableSize) {
|
||||
size_t growSize = (alignSize > HDF_SBUF_GROW_SIZE_DEFAULT) ? (alignSize + HDF_SBUF_GROW_SIZE_DEFAULT) :
|
||||
HDF_SBUF_GROW_SIZE_DEFAULT;
|
||||
if (!HdfSbufGrow(sbuf, growSize)) {
|
||||
return false;
|
||||
}
|
||||
writeableSize = HdfSbufGetLeftWriteSize(sbuf);
|
||||
}
|
||||
|
||||
uint8_t *dest = sbuf->data + sbuf->writePos;
|
||||
if (memcpy_s(dest, writeableSize, data, size) != EOK) {
|
||||
return false; /* never hits */
|
||||
}
|
||||
|
||||
sbuf->writePos += alignSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HdfSbufRead(struct HdfSBuf *sbuf, uint8_t *data, uint32_t readSize)
|
||||
{
|
||||
if (sbuf == NULL || data == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (readSize == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t alignSize = HdfSbufGetAlignSize(readSize);
|
||||
if (alignSize > HdfSbufGetLeftReadSize(sbuf)) {
|
||||
HDF_LOGE("Read out of buffer range");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (memcpy_s(data, readSize, sbuf->data + sbuf->readPos, readSize) != EOK) {
|
||||
return false; // never hits
|
||||
}
|
||||
sbuf->readPos += alignSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HdfSbufWriteBuffer(struct HdfSBuf *sbuf, const void *data, uint32_t writeSize)
|
||||
{
|
||||
if (sbuf == NULL) {
|
||||
HDF_LOGE("Write buffer failed, input param is invalid");
|
||||
return false;
|
||||
}
|
||||
if (data == NULL) {
|
||||
return HdfSbufWriteInt32(sbuf, 0);
|
||||
}
|
||||
|
||||
if (!HdfSbufWriteInt32(sbuf, writeSize)) {
|
||||
return false;
|
||||
}
|
||||
if (!HdfSbufWrite(sbuf, data, writeSize)) {
|
||||
(void)HdfSbufWriteRollback(sbuf, sizeof(int32_t));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* return actual read size */
|
||||
bool HdfSbufReadBuffer(struct HdfSBuf *sbuf, const void **data, uint32_t *readSize)
|
||||
{
|
||||
if (sbuf == NULL || data == NULL || readSize == NULL) {
|
||||
HDF_LOGE("%s:input invalid", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
int buffSize = 0;
|
||||
if (!HdfSbufReadInt32(sbuf, &buffSize)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (buffSize == 0) {
|
||||
*data = NULL;
|
||||
*readSize = 0;
|
||||
return true;
|
||||
}
|
||||
size_t alignSize = HdfSbufGetAlignSize(buffSize);
|
||||
if (alignSize > HdfSbufGetLeftReadSize(sbuf)) {
|
||||
HDF_LOGE("%s:readBuff out of range", __func__);
|
||||
(void)HdfSbufReadRollback(sbuf, sizeof(int32_t));
|
||||
return false;
|
||||
}
|
||||
|
||||
*data = sbuf->data + sbuf->readPos;
|
||||
*readSize = buffSize;
|
||||
sbuf->readPos += alignSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HdfSbufWriteUint64(struct HdfSBuf *sbuf, uint64_t value)
|
||||
{
|
||||
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
|
||||
}
|
||||
|
||||
bool HdfSbufWriteUint32(struct HdfSBuf *sbuf, uint32_t value)
|
||||
{
|
||||
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
|
||||
}
|
||||
|
||||
bool HdfSbufWriteUint16(struct HdfSBuf *sbuf, uint16_t value)
|
||||
{
|
||||
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
|
||||
}
|
||||
|
||||
bool HdfSbufWriteUint8(struct HdfSBuf *sbuf, uint8_t value)
|
||||
{
|
||||
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
|
||||
}
|
||||
|
||||
bool HdfSbufWriteInt64(struct HdfSBuf *sbuf, int64_t value)
|
||||
{
|
||||
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
|
||||
}
|
||||
|
||||
bool HdfSbufWriteInt32(struct HdfSBuf *sbuf, int32_t value)
|
||||
{
|
||||
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
|
||||
}
|
||||
|
||||
bool HdfSbufWriteInt16(struct HdfSBuf *sbuf, int16_t value)
|
||||
{
|
||||
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
|
||||
}
|
||||
|
||||
bool HdfSbufWriteInt8(struct HdfSBuf *sbuf, int8_t value)
|
||||
{
|
||||
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
|
||||
}
|
||||
|
||||
bool HdfSbufWriteString(struct HdfSBuf *sbuf, const char *value)
|
||||
{
|
||||
if (sbuf == NULL) {
|
||||
HDF_LOGE("%s:input null", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
return HdfSbufWriteBuffer(sbuf, value, value ? (strlen(value) + 1) : 0);
|
||||
}
|
||||
|
||||
bool HdfSbufReadUint64(struct HdfSBuf *sbuf, uint64_t *value)
|
||||
{
|
||||
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
|
||||
}
|
||||
|
||||
bool HdfSbufReadUint32(struct HdfSBuf *sbuf, uint32_t *value)
|
||||
{
|
||||
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
|
||||
}
|
||||
|
||||
bool HdfSbufReadUint16(struct HdfSBuf *sbuf, uint16_t *value)
|
||||
{
|
||||
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
|
||||
}
|
||||
|
||||
bool HdfSbufReadUint8(struct HdfSBuf *sbuf, uint8_t *value)
|
||||
{
|
||||
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
|
||||
}
|
||||
|
||||
bool HdfSbufReadInt64(struct HdfSBuf *sbuf, int64_t *value)
|
||||
{
|
||||
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
|
||||
}
|
||||
|
||||
bool HdfSbufReadInt32(struct HdfSBuf *sbuf, int32_t *value)
|
||||
{
|
||||
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
|
||||
}
|
||||
|
||||
bool HdfSbufReadInt16(struct HdfSBuf *sbuf, int16_t *value)
|
||||
{
|
||||
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
|
||||
}
|
||||
|
||||
bool HdfSbufReadInt8(struct HdfSBuf *sbuf, int8_t *value)
|
||||
{
|
||||
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
|
||||
}
|
||||
|
||||
const char *HdfSbufReadString(struct HdfSBuf *sbuf)
|
||||
{
|
||||
if (sbuf == NULL) {
|
||||
HDF_LOGE("%s:input null", __func__);
|
||||
return NULL;
|
||||
}
|
||||
/* this length contains '\0' at the end. */
|
||||
int32_t strLen = 0;
|
||||
if (!HdfSbufReadInt32(sbuf, &strLen) || strLen <= 0) {
|
||||
return NULL;
|
||||
}
|
||||
size_t alignSize = HdfSbufGetAlignSize(strLen);
|
||||
if (strLen > INT16_MAX || alignSize > HdfSbufGetLeftReadSize(sbuf)) {
|
||||
(void)HdfSbufReadRollback(sbuf, sizeof(int32_t));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *str = (char *)(sbuf->data + sbuf->readPos);
|
||||
sbuf->readPos += alignSize;
|
||||
/* force set '\0' at end of the string */
|
||||
str[strLen - 1] = '\0';
|
||||
return str;
|
||||
}
|
||||
|
||||
struct HdfSBuf *HdfSBufObtainDefaultSize()
|
||||
{
|
||||
return HdfSBufObtain(HDF_SBUF_GROW_SIZE_DEFAULT);
|
||||
}
|
||||
|
||||
struct HdfSBuf *HdfSBufObtain(size_t capacity)
|
||||
{
|
||||
if (capacity > HDF_SBUF_MAX_SIZE) {
|
||||
HDF_LOGE("%s: buf size over limit", __func__);
|
||||
return NULL;
|
||||
}
|
||||
struct HdfSBuf *sbuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf));
|
||||
if (sbuf == NULL) {
|
||||
HDF_LOGE("instance usbuf failure");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sbuf->data = (uint8_t *)OsalMemCalloc(capacity);
|
||||
if (sbuf->data == NULL) {
|
||||
OsalMemFree(sbuf);
|
||||
HDF_LOGE("sbuf obtain oom, size=%u", (uint32_t)capacity);
|
||||
return NULL;
|
||||
}
|
||||
sbuf->capacity = capacity;
|
||||
sbuf->writePos = 0;
|
||||
sbuf->readPos = 0;
|
||||
sbuf->isBind = false;
|
||||
return sbuf;
|
||||
}
|
||||
|
||||
struct HdfSBuf *HdfSBufBind(uintptr_t base, size_t size)
|
||||
{
|
||||
/* require 4 byte alignment for base */
|
||||
if ((base & 0x3) != 0) {
|
||||
HDF_LOGE("Base is not align for 4-byte");
|
||||
return NULL;
|
||||
}
|
||||
struct HdfSBuf *sbuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf));
|
||||
if (sbuf == NULL) {
|
||||
HDF_LOGE("%s: oom", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sbuf->data = (uint8_t *)base;
|
||||
sbuf->capacity = size;
|
||||
sbuf->writePos = size;
|
||||
sbuf->readPos = 0;
|
||||
sbuf->isBind = true;
|
||||
return sbuf;
|
||||
}
|
||||
|
||||
struct HdfSBuf *HdfSBufCopy(const struct HdfSBuf *sbuf)
|
||||
{
|
||||
if (sbuf == NULL || sbuf->data == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct HdfSBuf *new = HdfSBufObtain(sbuf->capacity);
|
||||
if (new == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
new->capacity = sbuf->capacity;
|
||||
new->readPos = 0;
|
||||
new->writePos = sbuf->writePos;
|
||||
if (memcpy_s(new->data, new->capacity, sbuf->data, sbuf->capacity) != EOK) {
|
||||
HdfSBufRecycle(new);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
struct HdfSBuf *HdfSBufMove(struct HdfSBuf *sbuf)
|
||||
{
|
||||
if (sbuf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct HdfSBuf *new = OsalMemCalloc(sizeof(struct HdfSBuf));
|
||||
if (new == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
new->capacity = sbuf->capacity;
|
||||
new->readPos = 0;
|
||||
new->writePos = sbuf->writePos;
|
||||
new->data = sbuf->data;
|
||||
|
||||
sbuf->data = NULL;
|
||||
sbuf->capacity = 0;
|
||||
HdfSbufFlush(sbuf);
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
void HdfSbufTransDataOwnership(struct HdfSBuf *sbuf)
|
||||
{
|
||||
if (sbuf == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
sbuf->isBind = false;
|
||||
}
|
||||
void HdfSBufRecycle(struct HdfSBuf *sbuf)
|
||||
{
|
||||
if (sbuf != NULL) {
|
||||
if (sbuf->data != NULL && !sbuf->isBind) {
|
||||
OsalMemFree(sbuf->data);
|
||||
}
|
||||
OsalMemFree(sbuf);
|
||||
}
|
||||
}
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef DEVICE_HOST_SERVICE_H
|
||||
#define DEVICE_HOST_SERVICE_H
|
||||
|
||||
#include "devhost_service_if.h"
|
||||
#include "hdf_service_observer.h"
|
||||
#include "hdf_slist.h"
|
||||
#include "osal_mutex.h"
|
||||
|
||||
struct DevHostService {
|
||||
struct IDevHostService super;
|
||||
uint16_t hostId;
|
||||
const char *hostName;
|
||||
struct HdfSList devices;
|
||||
struct HdfServiceObserver observer;
|
||||
};
|
||||
|
||||
struct IDevHostService *DevHostServiceNewInstance(uint16_t hostId, const char *hostName);
|
||||
void DevHostServiceFreeInstance(struct IDevHostService *service);
|
||||
struct HdfObject *DevHostServiceCreate(void);
|
||||
void DevHostServiceRelease(struct HdfObject *object);
|
||||
|
||||
#endif /* DEVICE_HOST_SERVICE_H */
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef DEVMGR_SERVICE_CLIENT_H
|
||||
#define DEVMGR_SERVICE_CLIENT_H
|
||||
|
||||
#include "devhost_service_if.h"
|
||||
#include "devmgr_service_if.h"
|
||||
#include "hdf_device_token.h"
|
||||
|
||||
struct DevmgrServiceClnt {
|
||||
struct IDevmgrService *devMgrSvcIf;
|
||||
};
|
||||
|
||||
struct DevmgrServiceClnt *DevmgrServiceClntGetInstance(void);
|
||||
void DevmgrServiceClntFreeInstance(struct DevmgrServiceClnt *inst);
|
||||
int DevmgrServiceClntAttachDevice(const struct HdfDeviceInfo *deviceInfo, struct IHdfDeviceToken *deviceToken);
|
||||
int DevmgrServiceClntAttachDeviceHost(uint16_t hostId, struct IDevHostService *hostService);
|
||||
|
||||
#endif /* DEVMGR_SERVICE_CLIENT_H */
|
||||
Executable
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef DEVSVC_MANAGER_CLNT_H
|
||||
#define DEVSVC_MANAGER_CLNT_H
|
||||
|
||||
#include "devsvc_manager_if.h"
|
||||
#include "devsvc_manager_stub.h"
|
||||
|
||||
struct DevSvcManagerClnt {
|
||||
struct IDevSvcManager *devSvcMgrIf;
|
||||
};
|
||||
|
||||
struct DevSvcManagerClnt *DevSvcManagerClntGetInstance(void);
|
||||
struct HdfDeviceObject *DevSvcManagerClntGetDeviceObject(const char *svcName);
|
||||
int DevSvcManagerClntAddService(const char *svcName, struct HdfDeviceObject *service);
|
||||
void DevSvcManagerClntRemoveService(const char *svcName);
|
||||
|
||||
#endif /* DEVSVC_MANAGER_CLNT_H */
|
||||
Executable
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef HDF_DEVICE_H
|
||||
#define HDF_DEVICE_H
|
||||
|
||||
#include "devhost_service.h"
|
||||
#include "device_token_if.h"
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_object.h"
|
||||
#include "hdf_service_observer.h"
|
||||
#include "hdf_slist.h"
|
||||
#include "osal_mutex.h"
|
||||
|
||||
struct HdfDeviceNode;
|
||||
|
||||
struct IHdfDevice {
|
||||
struct HdfObject object;
|
||||
int (*Attach)(struct IHdfDevice *, struct HdfDeviceNode *);
|
||||
};
|
||||
|
||||
struct HdfDevice {
|
||||
struct IHdfDevice super;
|
||||
struct HdfSListNode node;
|
||||
struct HdfSList services;
|
||||
uint16_t deviceId;
|
||||
uint16_t hostId;
|
||||
};
|
||||
|
||||
struct HdfObject *HdfDeviceCreate(void);
|
||||
void HdfDeviceRelease(struct HdfObject *object);
|
||||
struct HdfDevice *HdfDeviceNewInstance(void);
|
||||
void HdfDeviceFreeInstance(struct HdfDevice *device);
|
||||
void HdfDeviceDelete(struct HdfSListNode *deviceEntry);
|
||||
|
||||
#endif /* HDF_DEVICE_H */
|
||||
Executable
+69
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef HDF_DEVICE_NODE_H
|
||||
#define HDF_DEVICE_NODE_H
|
||||
|
||||
#include "hdf_device.h"
|
||||
#include "hdf_device_info.h"
|
||||
#include "hdf_device_desc.h"
|
||||
|
||||
struct HdfDeviceNode;
|
||||
struct DevHostService;
|
||||
|
||||
struct IDeviceNode {
|
||||
struct HdfObject object;
|
||||
int (*PublishService)(struct HdfDeviceNode *, const char *);
|
||||
int (*LaunchNode)(struct HdfDeviceNode *, struct IHdfDevice *);
|
||||
};
|
||||
|
||||
struct HdfDeviceNode {
|
||||
struct IDeviceNode super;
|
||||
struct HdfSListNode entry;
|
||||
struct PowerStateToken *powerToken;
|
||||
struct DevHostService *hostService;
|
||||
struct HdfDeviceObject deviceObject;
|
||||
struct IHdfDeviceToken *token;
|
||||
struct HdfDriverEntry *driverEntry;
|
||||
const struct HdfDeviceInfo *deviceInfo;
|
||||
};
|
||||
|
||||
int HdfDeviceNodeAddPowerStateListener(
|
||||
struct HdfDeviceNode *devNode, struct IPowerEventListener *listener);
|
||||
void HdfDeviceNodeConstruct(struct HdfDeviceNode *service);
|
||||
void HdfDeviceNodeDestruct(struct HdfDeviceNode *service);
|
||||
struct HdfDeviceNode *HdfDeviceNodeNewInstance(void);
|
||||
void HdfDeviceNodeFreeInstance(struct HdfDeviceNode *service);
|
||||
void HdfDeviceNodeDelete(struct HdfSListNode *deviceEntry);
|
||||
int HdfDeviceNodePublishPublicService(struct HdfDeviceNode *service, const char *svcName);
|
||||
void HdfDeviceNodeReclaimService(const char *svcName);
|
||||
|
||||
#endif /* HDF_DEVICE_NODE_H */
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef HDF_DEVICE_OBJECT_H
|
||||
#define HDF_DEVICE_OBJECT_H
|
||||
|
||||
#include "hdf_device_desc.h"
|
||||
|
||||
void HdfDeviceObjectConstruct(struct HdfDeviceObject *deviceObject);
|
||||
|
||||
#endif /* HDF_DEVICE_OBJECT_H */
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef HDF_DEVICE_TOKEN_H
|
||||
#define HDF_DEVICE_TOKEN_H
|
||||
|
||||
#include "device_token_if.h"
|
||||
#include "hdf_slist.h"
|
||||
|
||||
struct HdfDeviceToken {
|
||||
struct HdfSListNode node;
|
||||
struct IHdfDeviceToken super;
|
||||
};
|
||||
|
||||
struct HdfObject *HdfDeviceTokenCreate(void);
|
||||
void HdfDeviceTokenRelease(struct HdfObject *object);
|
||||
struct IHdfDeviceToken *HdfDeviceTokenNewInstance(void);
|
||||
void HdfDeviceTokenFreeInstance(struct IHdfDeviceToken *token);
|
||||
|
||||
#endif /* HDF_DEVICE_TOKEN_H */
|
||||
Executable
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef HDF_DRIVER_LOADER_H
|
||||
#define HDF_DRIVER_LOADER_H
|
||||
|
||||
#include "hdf_device_info.h"
|
||||
#include "hdf_device_node.h"
|
||||
#include "hdf_object.h"
|
||||
|
||||
struct IDriverLoader {
|
||||
struct HdfObject object;
|
||||
struct HdfDriverEntry *(*GetDriverEntry)(const struct HdfDeviceInfo *deviceInfo);
|
||||
struct HdfDeviceNode *(*LoadNode)(struct IDriverLoader *, const struct HdfDeviceInfo *deviceInfo);
|
||||
void (*UnLoadNode)(struct IDriverLoader *, const struct HdfDeviceInfo *deviceInfo);
|
||||
};
|
||||
|
||||
struct HdfDriverLoader {
|
||||
struct IDriverLoader super;
|
||||
};
|
||||
|
||||
struct HdfObject *HdfDriverLoaderCreate(void);
|
||||
void HdfDriverLoaderRelease(struct HdfObject *object);
|
||||
struct IDriverLoader *HdfDriverLoaderGetInstance(void);
|
||||
struct HdfDriverEntry *HdfDriverLoaderGetDriverEntry(const struct HdfDeviceInfo *deviceInfo);
|
||||
|
||||
#endif /* HDF_DRIVER_LOADER_H */
|
||||
Executable
+57
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef HDF_OBSERVER_RECORD_H
|
||||
#define HDF_OBSERVER_RECORD_H
|
||||
|
||||
#include "hdf_object.h"
|
||||
#include "hdf_slist.h"
|
||||
#include "osal_mutex.h"
|
||||
|
||||
struct HdfServiceObserverRecord {
|
||||
struct HdfSListNode entry;
|
||||
uint32_t serviceKey;
|
||||
uint16_t policy;
|
||||
uint32_t matchId;
|
||||
struct OsalMutex obsRecMutex;
|
||||
struct HdfSList subscribers;
|
||||
struct HdfObject *publisher;
|
||||
};
|
||||
|
||||
uint32_t HdfMakeHardwareId(uint16_t hostId, uint16_t deviceId);
|
||||
struct HdfServiceObserverRecord *HdfServiceObserverRecordObtain(uint32_t serviceKey);
|
||||
void HdfServiceObserverRecordRecycle(struct HdfServiceObserverRecord *record);
|
||||
bool HdfServiceObserverRecordCompare(struct HdfSListNode *listEntry, uint32_t serviceKey);
|
||||
void HdfServiceObserverRecordNotifySubscribers(
|
||||
struct HdfServiceObserverRecord *record, uint32_t matchId, uint16_t policy);
|
||||
void HdfServiceObserverRecordDelete(struct HdfSListNode *listEntry);
|
||||
|
||||
#endif /* HDF_OBSERVER_RECORD_H */
|
||||
Executable
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef HDF_SERVICE_OBSERVER_H
|
||||
#define HDF_SERVICE_OBSERVER_H
|
||||
|
||||
#include "hdf_service_subscriber.h"
|
||||
#include "osal_mutex.h"
|
||||
|
||||
struct HdfServiceObserver {
|
||||
struct HdfSList services;
|
||||
struct OsalMutex observerMutex;
|
||||
};
|
||||
|
||||
bool HdfServiceObserverConstruct(struct HdfServiceObserver *observer);
|
||||
void HdfServiceObserverDestruct(struct HdfServiceObserver *observer);
|
||||
int HdfServiceObserverPublishService(struct HdfServiceObserver *observer,
|
||||
const char *svcName, uint32_t pubHardwareId, uint16_t policy, struct HdfObject *service);
|
||||
int HdfServiceObserverSubscribeService(struct HdfServiceObserver *observer,
|
||||
const char *svcName, uint32_t subHardwareId, struct SubscriberCallback callback);
|
||||
void HdfServiceObserverRemoveRecord(struct HdfServiceObserver *observer, const char *svcName);
|
||||
|
||||
#endif /* HDF_SERVICE_OBSERVER_H */
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef HDF_SERVICE_SUBSCRIBER_H
|
||||
#define HDF_SERVICE_SUBSCRIBER_H
|
||||
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_slist.h"
|
||||
|
||||
struct HdfServiceSubscriber {
|
||||
struct HdfSListNode entry;
|
||||
uint32_t state;
|
||||
uint32_t matchId;
|
||||
struct SubscriberCallback callback;
|
||||
};
|
||||
|
||||
enum {
|
||||
HDF_SUBSCRIBER_STATE_PENDING,
|
||||
HDF_SUBSCRIBER_STATE_READY
|
||||
};
|
||||
|
||||
struct HdfServiceSubscriber *HdfServiceSubscriberObtain(struct SubscriberCallback callback, uint32_t matchId);
|
||||
void HdfServiceSubscriberRecycle(struct HdfServiceSubscriber *subscriber);
|
||||
void HdfServiceSubscriberDelete(struct HdfSListNode *listEntry);
|
||||
|
||||
#endif /* HDF_SERVICE_SUBSCRIBER_H */
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef POWER_STATE_TOKEN_H
|
||||
#define POWER_STATE_TOKEN_H
|
||||
|
||||
#include "hdf_sref.h"
|
||||
#include "power_state_token_if.h"
|
||||
|
||||
struct PowerStateToken {
|
||||
struct IPowerStateToken super;
|
||||
struct IPowerEventListener *listener;
|
||||
struct HdfDeviceObject *deviceObject;
|
||||
struct HdfSRef wakeRef;
|
||||
HdfPowerState state;
|
||||
};
|
||||
|
||||
struct PowerStateToken *PowerStateTokenNewInstance(
|
||||
struct HdfDeviceObject *deviceObject, struct IPowerEventListener *listener);
|
||||
void PowerStateTokenFreeInstance(struct PowerStateToken *stateToken);
|
||||
|
||||
#endif /* POWER_STATE_TOKEN_H */
|
||||
Executable
+213
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "devhost_service.h"
|
||||
#include "devmgr_service_clnt.h"
|
||||
#include "devsvc_manager_clnt.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_driver_loader.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_object_manager.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
#define HDF_LOG_TAG devhost_service
|
||||
|
||||
static struct HdfDevice *DevHostServiceFindDevice(struct DevHostService *inst, uint16_t deviceId)
|
||||
{
|
||||
struct HdfSListIterator it;
|
||||
struct HdfDevice *deviceNode = NULL;
|
||||
if (inst == NULL) {
|
||||
HDF_LOGE("Find driver failed, inst is null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
HdfSListIteratorInit(&it, &inst->devices);
|
||||
while (HdfSListIteratorHasNext(&it)) {
|
||||
deviceNode = (struct HdfDevice *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfSListNode, HdfSListIteratorNext(&it), struct HdfDevice, node);
|
||||
if (deviceNode->deviceId == deviceId) {
|
||||
return deviceNode;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void DevHostServiceFreeDevice(struct DevHostService *inst, uint16_t deviceId)
|
||||
{
|
||||
struct HdfDevice *deviceNode = DevHostServiceFindDevice(inst, deviceId);
|
||||
if (deviceNode != NULL) {
|
||||
HdfSListRemove(&inst->devices, &deviceNode->node);
|
||||
HdfDeviceFreeInstance(deviceNode);
|
||||
}
|
||||
}
|
||||
|
||||
static struct HdfDevice *DevHostServiceGetDevice(struct DevHostService *inst, uint16_t deviceId)
|
||||
{
|
||||
struct HdfDevice *device = DevHostServiceFindDevice(inst, deviceId);
|
||||
if (device == NULL) {
|
||||
device = HdfDeviceNewInstance();
|
||||
if (device == NULL) {
|
||||
HDF_LOGE("Dev host service create driver instance failed");
|
||||
return NULL;
|
||||
}
|
||||
device->hostId = inst->hostId;
|
||||
HdfSListAdd(&inst->devices, &device->node);
|
||||
}
|
||||
return device;
|
||||
}
|
||||
|
||||
static int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDeviceInfo *deviceInfo)
|
||||
{
|
||||
int ret = HDF_FAILURE;
|
||||
struct HdfDevice *device = NULL;
|
||||
struct HdfDeviceNode *devNode = NULL;
|
||||
struct DevHostService *hostService = (struct DevHostService *)inst;
|
||||
struct IDriverLoader *driverLoader = HdfDriverLoaderGetInstance();
|
||||
|
||||
if ((deviceInfo == NULL) || (driverLoader == NULL) || (driverLoader->LoadNode == NULL)) {
|
||||
HDF_LOGE("Add device failed, input param is null");
|
||||
return ret;
|
||||
}
|
||||
|
||||
device = DevHostServiceGetDevice(hostService, deviceInfo->deviceId);
|
||||
if (device == NULL || device->super.Attach == NULL) {
|
||||
ret = HDF_DEV_ERR_NO_MEMORY;
|
||||
goto error;
|
||||
}
|
||||
|
||||
devNode = driverLoader->LoadNode(driverLoader, deviceInfo);
|
||||
if (devNode == NULL) {
|
||||
ret = HDF_DEV_ERR_NO_DEVICE_SERVICE;
|
||||
goto error;
|
||||
}
|
||||
devNode->hostService = hostService;
|
||||
ret = device->super.Attach(&device->super, devNode);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
goto error;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
|
||||
error:
|
||||
if (HdfSListIsEmpty(&hostService->devices)) {
|
||||
DevHostServiceFreeDevice(hostService, hostService->hostId);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int DevHostServiceDelDevice(struct IDevHostService *inst, const struct HdfDeviceInfo *deviceInfo)
|
||||
{
|
||||
struct HdfDevice *device = NULL;
|
||||
struct DevHostService *hostService = (struct DevHostService *)inst;
|
||||
struct IDriverLoader *driverLoader = HdfDriverLoaderGetInstance();
|
||||
|
||||
if ((deviceInfo == NULL) || (driverLoader == NULL) || (driverLoader->UnLoadNode == NULL)) {
|
||||
HDF_LOGE("Add device failed, input param is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
device = DevHostServiceGetDevice(hostService, deviceInfo->deviceId);
|
||||
if (device == NULL) {
|
||||
HDF_LOGW("Del device failed, device is not exist");
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
driverLoader->UnLoadNode(driverLoader, deviceInfo);
|
||||
if (HdfSListIsEmpty(&hostService->devices)) {
|
||||
DevHostServiceFreeDevice(hostService, device->deviceId);
|
||||
}
|
||||
DevSvcManagerClntRemoveService(deviceInfo->svcName);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int DevHostServiceStartService(struct IDevHostService *service)
|
||||
{
|
||||
struct DevHostService *hostService = (struct DevHostService*)service;
|
||||
if (hostService == NULL) {
|
||||
HDF_LOGE("Start device service failed, hostService is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return DevmgrServiceClntAttachDeviceHost(hostService->hostId, service);
|
||||
}
|
||||
|
||||
static void DevHostServiceConstruct(struct DevHostService *service)
|
||||
{
|
||||
struct IDevHostService *hostServiceIf = &service->super;
|
||||
if (hostServiceIf != NULL) {
|
||||
hostServiceIf->AddDevice = DevHostServiceAddDevice;
|
||||
hostServiceIf->DelDevice = DevHostServiceDelDevice;
|
||||
hostServiceIf->StartService = DevHostServiceStartService;
|
||||
HdfSListInit(&service->devices);
|
||||
HdfServiceObserverConstruct(&service->observer);
|
||||
}
|
||||
}
|
||||
|
||||
static void DevHostServiceDestruct(struct DevHostService *service)
|
||||
{
|
||||
HdfSListFlush(&service->devices, HdfDeviceDelete);
|
||||
HdfServiceObserverDestruct(&service->observer);
|
||||
}
|
||||
|
||||
struct HdfObject *DevHostServiceCreate()
|
||||
{
|
||||
struct DevHostService *devHostService = (struct DevHostService *)OsalMemCalloc(sizeof(struct DevHostService));
|
||||
if (devHostService != NULL) {
|
||||
DevHostServiceConstruct(devHostService);
|
||||
}
|
||||
return (struct HdfObject *)devHostService;
|
||||
}
|
||||
|
||||
void DevHostServiceRelease(struct HdfObject *object)
|
||||
{
|
||||
struct DevHostService *devHostService = (struct DevHostService *)object;
|
||||
if (devHostService != NULL) {
|
||||
DevHostServiceDestruct(devHostService);
|
||||
OsalMemFree(devHostService);
|
||||
}
|
||||
}
|
||||
|
||||
struct IDevHostService *DevHostServiceNewInstance(uint16_t hostId, const char *hostName)
|
||||
{
|
||||
struct DevHostService *hostService =
|
||||
(struct DevHostService *)HdfObjectManagerGetObject(HDF_OBJECT_ID_DEVHOST_SERVICE);
|
||||
if (hostService != NULL) {
|
||||
hostService->hostId = hostId;
|
||||
hostService->hostName = hostName;
|
||||
}
|
||||
return (struct IDevHostService *)hostService;
|
||||
}
|
||||
|
||||
void DevHostServiceFreeInstance(struct IDevHostService *service)
|
||||
{
|
||||
if (service != NULL) {
|
||||
HdfObjectManagerFreeObject(&service->object);
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+90
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "devmgr_service_clnt.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_device.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_object_manager.h"
|
||||
|
||||
#define HDF_LOG_TAG devmgr_service_clnt
|
||||
|
||||
int DevmgrServiceClntAttachDeviceHost(uint16_t hostId, struct IDevHostService *hostService)
|
||||
{
|
||||
struct IDevmgrService *devMgrSvcIf = NULL;
|
||||
struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance();
|
||||
if ((inst == NULL) || (inst->devMgrSvcIf == NULL)) {
|
||||
HDF_LOGE("Attach device host failed, get device manager service client is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
devMgrSvcIf = inst->devMgrSvcIf;
|
||||
if (devMgrSvcIf->AttachDeviceHost == NULL) {
|
||||
HDF_LOGE("Attach device host failed, attach device host function is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return devMgrSvcIf->AttachDeviceHost(devMgrSvcIf, hostId, hostService);
|
||||
}
|
||||
|
||||
int DevmgrServiceClntAttachDevice(const struct HdfDeviceInfo *deviceInfo, struct IHdfDeviceToken *deviceToken)
|
||||
{
|
||||
struct IDevmgrService *devMgrSvcIf = NULL;
|
||||
struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance();
|
||||
if ((inst == NULL) || (inst->devMgrSvcIf == NULL)) {
|
||||
HDF_LOGE("Device manager service client attach device failed, inst is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
devMgrSvcIf = inst->devMgrSvcIf;
|
||||
if (devMgrSvcIf->AttachDevice == NULL) {
|
||||
HDF_LOGE("Device manager service client attach device failed, dmsOps->AttachDevice is nul");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return devMgrSvcIf->AttachDevice(devMgrSvcIf, deviceInfo, deviceToken);
|
||||
}
|
||||
|
||||
struct DevmgrServiceClnt *DevmgrServiceClntGetInstance()
|
||||
{
|
||||
static struct DevmgrServiceClnt instance = {0};
|
||||
if (instance.devMgrSvcIf == NULL) {
|
||||
instance.devMgrSvcIf = (struct IDevmgrService *)HdfObjectManagerGetObject(HDF_OBJECT_ID_DEVMGR_SERVICE);
|
||||
}
|
||||
return &instance;
|
||||
}
|
||||
|
||||
void DevmgrServiceClntFreeInstance(struct DevmgrServiceClnt *inst)
|
||||
{
|
||||
if ((inst != NULL) && (inst->devMgrSvcIf != NULL)) {
|
||||
HdfObjectManagerFreeObject((struct HdfObject *)inst->devMgrSvcIf);
|
||||
inst->devMgrSvcIf = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+160
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "devsvc_manager_clnt.h"
|
||||
#include "devsvc_manager.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_object_manager.h"
|
||||
|
||||
#define HDF_LOG_TAG devsvc_manager_clnt
|
||||
|
||||
int DevSvcManagerClntAddService(const char *svcName, struct HdfDeviceObject *service)
|
||||
{
|
||||
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
|
||||
if (devSvcMgrClnt == NULL) {
|
||||
HDF_LOGE("Get device manager client is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
if (serviceManager->AddService == NULL) {
|
||||
HDF_LOGE("AddService function is not assigned");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return serviceManager->AddService(serviceManager, svcName, service);
|
||||
}
|
||||
|
||||
const struct HdfObject *DevSvcManagerClntGetService(const char *svcName)
|
||||
{
|
||||
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
|
||||
if (devSvcMgrClnt == NULL) {
|
||||
HDF_LOGE("Get device manager client is null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
if (serviceManager->GetService == NULL) {
|
||||
HDF_LOGE("GetService function is not assigned");
|
||||
return NULL;
|
||||
}
|
||||
return serviceManager->GetService(serviceManager, svcName);
|
||||
}
|
||||
|
||||
struct HdfDeviceObject *DevSvcManagerClntGetDeviceObject(const char *svcName)
|
||||
{
|
||||
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
|
||||
if (devSvcMgrClnt == NULL) {
|
||||
HDF_LOGE("Get device manager client is null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
if (serviceManager->GetObject == NULL) {
|
||||
HDF_LOGE("GetObject function is not assigned");
|
||||
return NULL;
|
||||
}
|
||||
return serviceManager->GetObject(serviceManager, svcName);
|
||||
}
|
||||
|
||||
int DevSvcManagerClntSubscribeService(const char *svcName, struct SubscriberCallback callback)
|
||||
{
|
||||
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
|
||||
if (devSvcMgrClnt == NULL) {
|
||||
HDF_LOGE("Get device manager client is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
if (serviceManager->SubscribeService == NULL) {
|
||||
HDF_LOGE("SubscribeService function is not assigned");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return serviceManager->SubscribeService(serviceManager, svcName, callback);
|
||||
}
|
||||
|
||||
int DevSvcManagerClntUnsubscribeService(const char *svcName)
|
||||
{
|
||||
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
|
||||
if (devSvcMgrClnt == NULL) {
|
||||
HDF_LOGE("Get device manager client is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
if (serviceManager->UnsubscribeService == NULL) {
|
||||
HDF_LOGE("UnsubService function is not assigned");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return serviceManager->UnsubscribeService(serviceManager, svcName);
|
||||
}
|
||||
|
||||
void DevSvcManagerClntRemoveService(const char *svcName)
|
||||
{
|
||||
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
|
||||
if (devSvcMgrClnt == NULL) {
|
||||
HDF_LOGE("Get device manager client is null");
|
||||
return;
|
||||
}
|
||||
|
||||
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
if (serviceManager->RemoveService == NULL) {
|
||||
HDF_LOGE("Remove service function is not assigned");
|
||||
return;
|
||||
}
|
||||
serviceManager->RemoveService(serviceManager, svcName);
|
||||
}
|
||||
|
||||
static void DevSvcManagerClntConstruct(struct DevSvcManagerClnt *inst)
|
||||
{
|
||||
inst->devSvcMgrIf = (struct IDevSvcManager *)HdfObjectManagerGetObject(HDF_OBJECT_ID_DEVSVC_MANAGER);
|
||||
}
|
||||
|
||||
struct DevSvcManagerClnt *DevSvcManagerClntGetInstance()
|
||||
{
|
||||
static struct DevSvcManagerClnt *instance = NULL;
|
||||
if (instance == NULL) {
|
||||
static struct DevSvcManagerClnt singletonInstance;
|
||||
DevSvcManagerClntConstruct(&singletonInstance);
|
||||
instance = &singletonInstance;
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
void DevSvcManagerClntFreeInstance(struct DevSvcManagerClnt *instance)
|
||||
{
|
||||
if (instance != NULL) {
|
||||
if (instance->devSvcMgrIf != NULL) {
|
||||
HdfObjectManagerFreeObject((struct HdfObject *)instance->devSvcMgrIf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+106
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "hdf_device.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_cstring.h"
|
||||
#include "hdf_device_node.h"
|
||||
#include "hdf_device_token.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_object_manager.h"
|
||||
#include "hdf_service_observer.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
#define HDF_LOG_TAG hdf_device
|
||||
|
||||
static int HdfDeviceAttach(struct IHdfDevice *devInst, struct HdfDeviceNode *devNode)
|
||||
{
|
||||
struct HdfDevice *device = (struct HdfDevice *)devInst;
|
||||
struct IDeviceNode *nodeIf = (struct IDeviceNode *)devNode;
|
||||
if (device == NULL || nodeIf == NULL || nodeIf->LaunchNode == NULL) {
|
||||
HDF_LOGE("Device attach failed, input params is wrong");
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
HdfSListAdd(&device->services, &devNode->entry);
|
||||
return nodeIf->LaunchNode(devNode, devInst);
|
||||
}
|
||||
|
||||
static void HdfDeviceConstruct(struct HdfDevice *device)
|
||||
{
|
||||
device->super.Attach = HdfDeviceAttach;
|
||||
HdfSListInit(&device->services);
|
||||
}
|
||||
|
||||
static void HdfDeviceDestruct(struct HdfDevice *device)
|
||||
{
|
||||
HdfSListFlush(&device->services, HdfDeviceNodeDelete);
|
||||
}
|
||||
|
||||
struct HdfObject *HdfDeviceCreate()
|
||||
{
|
||||
struct HdfDevice *device =
|
||||
(struct HdfDevice *)OsalMemCalloc(sizeof(struct HdfDevice));
|
||||
if (device != NULL) {
|
||||
HdfDeviceConstruct(device);
|
||||
}
|
||||
return (struct HdfObject *)device;
|
||||
}
|
||||
|
||||
void HdfDeviceRelease(struct HdfObject *object)
|
||||
{
|
||||
struct HdfDevice *device = (struct HdfDevice *)object;
|
||||
if (device != NULL) {
|
||||
HdfDeviceDestruct(device);
|
||||
OsalMemFree(device);
|
||||
}
|
||||
}
|
||||
|
||||
struct HdfDevice *HdfDeviceNewInstance()
|
||||
{
|
||||
return (struct HdfDevice *)HdfObjectManagerGetObject(HDF_OBJECT_ID_DEVICE);
|
||||
}
|
||||
|
||||
void HdfDeviceFreeInstance(struct HdfDevice *device)
|
||||
{
|
||||
if (device != NULL) {
|
||||
HdfObjectManagerFreeObject((struct HdfObject *)device);
|
||||
}
|
||||
}
|
||||
|
||||
void HdfDeviceDelete(struct HdfSListNode *listEntry)
|
||||
{
|
||||
if (listEntry != NULL) {
|
||||
struct HdfDevice *device = (struct HdfDevice *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfSListNode, listEntry, struct HdfDevice, node);
|
||||
HdfDeviceFreeInstance(device);
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+200
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "hdf_device_node.h"
|
||||
#include "devhost_service.h"
|
||||
#include "devmgr_service_clnt.h"
|
||||
#include "devsvc_manager_clnt.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_device_object.h"
|
||||
#include "hdf_device_token.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_object_manager.h"
|
||||
#include "hdf_observer_record.h"
|
||||
#include "osal_mem.h"
|
||||
#include "power_state_token.h"
|
||||
|
||||
#define HDF_LOG_TAG device_node
|
||||
|
||||
static int HdfDeviceNodePublishLocalService(
|
||||
struct HdfDeviceNode *devNode, const struct HdfDeviceInfo *deviceInfo)
|
||||
{
|
||||
uint32_t matchId;
|
||||
if ((devNode == NULL) || (deviceInfo == NULL)) {
|
||||
HDF_LOGE("Publish local service failed, device is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
struct DevHostService *hostService = devNode->hostService;
|
||||
if (hostService == NULL) {
|
||||
HDF_LOGE("Publish local service failed, host service is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
matchId = HdfMakeHardwareId(deviceInfo->hostId, deviceInfo->deviceId);
|
||||
return HdfServiceObserverPublishService(&hostService->observer, deviceInfo->svcName,
|
||||
matchId, deviceInfo->policy, (struct HdfObject *)devNode->deviceObject.service);
|
||||
}
|
||||
|
||||
static int HdfDeviceNodePublishService(
|
||||
struct HdfDeviceNode *devNode, const struct HdfDeviceInfo *deviceInfo, struct IHdfDevice *device)
|
||||
{
|
||||
int status = HDF_SUCCESS;
|
||||
if (deviceInfo->policy == SERVICE_POLICY_NONE) {
|
||||
HDF_LOGI("policy is %d", SERVICE_POLICY_NONE);
|
||||
return status;
|
||||
}
|
||||
|
||||
struct IDeviceNode *nodeIf = &devNode->super;
|
||||
if ((deviceInfo->policy == SERVICE_POLICY_PUBLIC) ||
|
||||
(deviceInfo->policy == SERVICE_POLICY_CAPACITY)) {
|
||||
if (nodeIf->PublishService != NULL) {
|
||||
status = nodeIf->PublishService(devNode, deviceInfo->svcName);
|
||||
}
|
||||
}
|
||||
if (status == HDF_SUCCESS) {
|
||||
status = HdfDeviceNodePublishLocalService(devNode, deviceInfo);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int HdfDeviceLaunchNode(struct HdfDeviceNode *devNode, struct IHdfDevice *devInst)
|
||||
{
|
||||
struct HdfDevice *device = (struct HdfDevice *)devInst;
|
||||
if (device == NULL || devNode == NULL) {
|
||||
HDF_LOGE("Launch service failed, device or service is null");
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
struct HdfDriverEntry *driverEntry = devNode->driverEntry;
|
||||
const struct HdfDeviceInfo *deviceInfo = devNode->deviceInfo;
|
||||
struct IHdfDeviceToken *deviceToken = NULL;
|
||||
|
||||
if (deviceInfo == NULL) {
|
||||
HDF_LOGE("Launch service failed, deviceInfo is null");
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if ((driverEntry == NULL) || (driverEntry->Init == NULL)) {
|
||||
HDF_LOGE("deviceEntry or deviceEntry->Init is null");
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
int ret = driverEntry->Init(&devNode->deviceObject);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
if (driverEntry->Release != NULL) {
|
||||
driverEntry->Release(&devNode->deviceObject);
|
||||
}
|
||||
return HDF_DEV_ERR_DEV_INIT_FAIL;
|
||||
}
|
||||
ret = HdfDeviceNodePublishService(devNode, deviceInfo, devInst);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
if (driverEntry->Release != NULL) {
|
||||
driverEntry->Release(&devNode->deviceObject);
|
||||
}
|
||||
return HDF_DEV_ERR_PUBLISH_FAIL;
|
||||
}
|
||||
deviceToken = devNode->token;
|
||||
ret = DevmgrServiceClntAttachDevice(deviceInfo, deviceToken);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
if (driverEntry->Release != NULL) {
|
||||
driverEntry->Release(&devNode->deviceObject);
|
||||
}
|
||||
return HDF_DEV_ERR_ATTACHDEV_FAIL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int HdfDeviceNodeAddPowerStateListener(
|
||||
struct HdfDeviceNode *devNode, struct IPowerEventListener *listener)
|
||||
{
|
||||
if (devNode->powerToken != NULL) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (devNode->powerToken == NULL) {
|
||||
devNode->powerToken = PowerStateTokenNewInstance(&devNode->deviceObject, listener);
|
||||
}
|
||||
return (devNode->powerToken == NULL) ? HDF_SUCCESS : HDF_FAILURE;
|
||||
}
|
||||
|
||||
int HdfDeviceNodePublishPublicService(struct HdfDeviceNode *devNode, const char *svcName)
|
||||
{
|
||||
if ((devNode == NULL) || (devNode->deviceObject.service == NULL)) {
|
||||
HDF_LOGE("device method is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return DevSvcManagerClntAddService(svcName, &devNode->deviceObject);
|
||||
}
|
||||
|
||||
void HdfDeviceNodeReclaimService(const char *svcName)
|
||||
{
|
||||
DevSvcManagerClntRemoveService(svcName);
|
||||
}
|
||||
|
||||
void HdfDeviceNodeConstruct(struct HdfDeviceNode *devNode)
|
||||
{
|
||||
if (devNode != NULL) {
|
||||
struct IDeviceNode *nodeIf = &devNode->super;
|
||||
HdfDeviceObjectConstruct(&devNode->deviceObject);
|
||||
devNode->token = HdfDeviceTokenNewInstance();
|
||||
nodeIf->LaunchNode = HdfDeviceLaunchNode;
|
||||
nodeIf->PublishService = HdfDeviceNodePublishPublicService;
|
||||
}
|
||||
}
|
||||
|
||||
void HdfDeviceNodeDestruct(struct HdfDeviceNode *devNode)
|
||||
{
|
||||
if (devNode == NULL) {
|
||||
return;
|
||||
}
|
||||
HdfDeviceTokenFreeInstance(devNode->token);
|
||||
devNode->token = NULL;
|
||||
PowerStateTokenFreeInstance(devNode->powerToken);
|
||||
devNode->powerToken = NULL;
|
||||
}
|
||||
|
||||
struct HdfDeviceNode *HdfDeviceNodeNewInstance()
|
||||
{
|
||||
return (struct HdfDeviceNode *)HdfObjectManagerGetObject(HDF_OBJECT_ID_DEVICE_SERVICE);
|
||||
}
|
||||
|
||||
void HdfDeviceNodeFreeInstance(struct HdfDeviceNode *devNode)
|
||||
{
|
||||
HdfObjectManagerFreeObject((struct HdfObject *) devNode);
|
||||
}
|
||||
|
||||
void HdfDeviceNodeDelete(struct HdfSListNode *deviceEntry)
|
||||
{
|
||||
if (deviceEntry == NULL) {
|
||||
return;
|
||||
}
|
||||
struct HdfDeviceNode *devNode =
|
||||
HDF_SLIST_CONTAINER_OF(struct HdfSListNode, deviceEntry, struct HdfDeviceNode, entry);
|
||||
HdfDeviceNodeFreeInstance(devNode);
|
||||
}
|
||||
|
||||
Executable
+129
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "hdf_device_object.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_device_node.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_observer_record.h"
|
||||
#include "hdf_service_observer.h"
|
||||
#include "power_state_token.h"
|
||||
|
||||
#define HDF_LOG_TAG device_object
|
||||
|
||||
int32_t HdfDeviceSubscribeService(
|
||||
struct HdfDeviceObject *deviceObject, const char *serviceName, struct SubscriberCallback callback)
|
||||
{
|
||||
uint32_t matchId;
|
||||
struct DevHostService *hostService = NULL;
|
||||
const struct HdfDeviceInfo *deviceInfo = NULL;
|
||||
if (deviceObject == NULL || serviceName == NULL) {
|
||||
HDF_LOGE("%s input param is invalid", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
|
||||
hostService = devNode->hostService;
|
||||
if (hostService == NULL) {
|
||||
HDF_LOGE("Get host service is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
deviceInfo = devNode->deviceInfo;
|
||||
if (deviceInfo == NULL) {
|
||||
HDF_LOGE("Get device deviceInfo is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
matchId = HdfMakeHardwareId(deviceInfo->hostId, deviceInfo->deviceId);
|
||||
return HdfServiceObserverSubscribeService(&hostService->observer, serviceName, matchId, callback);
|
||||
}
|
||||
|
||||
const char *HdfDeviceGetServiceName(const struct HdfDeviceObject *deviceObject)
|
||||
{
|
||||
if (deviceObject == NULL) {
|
||||
HDF_LOGE("%s input param is invalid", __func__);
|
||||
return NULL;
|
||||
}
|
||||
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
|
||||
const struct HdfDeviceInfo *deviceInfo = devNode->deviceInfo;
|
||||
if (deviceInfo == NULL) {
|
||||
HDF_LOGE("Get device deviceInfo is null");
|
||||
return NULL;
|
||||
}
|
||||
return deviceInfo->svcName;
|
||||
}
|
||||
|
||||
void HdfDeviceRegisterPowerListener(struct HdfDeviceObject *deviceObject, struct IPowerEventListener *listener)
|
||||
{
|
||||
if (deviceObject == NULL) {
|
||||
HDF_LOGE("%s input param is invalid", __func__);
|
||||
return;
|
||||
}
|
||||
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
|
||||
HdfDeviceNodeAddPowerStateListener(devNode, listener);
|
||||
}
|
||||
|
||||
void HdfDeviceAcquireWakeLock(struct HdfDeviceObject *deviceObject)
|
||||
{
|
||||
if (deviceObject == NULL) {
|
||||
HDF_LOGE("%s input param is invalid", __func__);
|
||||
return;
|
||||
}
|
||||
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
|
||||
struct IPowerStateToken *tokenIf = (struct IPowerStateToken *)devNode->powerToken;
|
||||
if ((tokenIf != NULL) && (tokenIf->AcquireWakeLock != NULL)) {
|
||||
tokenIf->AcquireWakeLock(tokenIf);
|
||||
}
|
||||
}
|
||||
|
||||
void HdfDeviceReleaseWakeLock(struct HdfDeviceObject *deviceObject)
|
||||
{
|
||||
if (deviceObject == NULL) {
|
||||
HDF_LOGE("%s input param is invalid", __func__);
|
||||
return;
|
||||
}
|
||||
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
|
||||
struct IPowerStateToken *tokenIf = (struct IPowerStateToken *)devNode->powerToken;
|
||||
if ((tokenIf != NULL) && (tokenIf->ReleaseWakeLock != NULL)) {
|
||||
tokenIf->ReleaseWakeLock(tokenIf);
|
||||
}
|
||||
}
|
||||
|
||||
void HdfDeviceObjectConstruct(struct HdfDeviceObject *deviceObject)
|
||||
{
|
||||
if (deviceObject != NULL) {
|
||||
deviceObject->property = NULL;
|
||||
deviceObject->service = NULL;
|
||||
}
|
||||
}
|
||||
Executable
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "hdf_device_token.h"
|
||||
#include "hdf_object_manager.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
static void HdfDeviceTokenConstruct(struct HdfDeviceToken *inst)
|
||||
{
|
||||
inst->super.object.objectId = HDF_OBJECT_ID_DEVICE_TOKEN;
|
||||
}
|
||||
|
||||
struct HdfObject *HdfDeviceTokenCreate()
|
||||
{
|
||||
struct HdfDeviceToken *token =
|
||||
(struct HdfDeviceToken *)OsalMemCalloc(sizeof(struct HdfDeviceToken));
|
||||
if (token != NULL) {
|
||||
HdfDeviceTokenConstruct(token);
|
||||
}
|
||||
return (struct HdfObject *)token;
|
||||
}
|
||||
|
||||
void HdfDeviceTokenRelease(struct HdfObject *object)
|
||||
{
|
||||
struct HdfDeviceToken *deviceToken = (struct HdfDeviceToken *)object;
|
||||
if (deviceToken != NULL) {
|
||||
OsalMemFree(deviceToken);
|
||||
}
|
||||
}
|
||||
|
||||
struct IHdfDeviceToken *HdfDeviceTokenNewInstance()
|
||||
{
|
||||
return (struct IHdfDeviceToken *)HdfObjectManagerGetObject(HDF_OBJECT_ID_DEVICE_TOKEN);
|
||||
}
|
||||
|
||||
void HdfDeviceTokenFreeInstance(struct IHdfDeviceToken *token)
|
||||
{
|
||||
if (token != NULL) {
|
||||
HdfObjectManagerFreeObject(&token->object);
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+135
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "hdf_driver_loader.h"
|
||||
#include "devsvc_manager_clnt.h"
|
||||
#include "hcs_tree_if.h"
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_device_node.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_object_manager.h"
|
||||
|
||||
#define HDF_LOG_TAG driver_loader
|
||||
|
||||
static struct HdfDeviceNode *HdfDriverLoaderLoadNode(
|
||||
struct IDriverLoader *loader, const struct HdfDeviceInfo *deviceInfo)
|
||||
{
|
||||
struct HdfDriverEntry *driverEntry = NULL;
|
||||
struct HdfDeviceNode *devNode = NULL;
|
||||
if ((loader == NULL) || (loader->GetDriverEntry == NULL)) {
|
||||
HDF_LOGE("loader or loader->GetDriverEntry is null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
driverEntry = loader->GetDriverEntry(deviceInfo);
|
||||
if (driverEntry == NULL) {
|
||||
HDF_LOGE("Load service failed, deviceEntry is null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
devNode = HdfDeviceNodeNewInstance();
|
||||
if (devNode == NULL) {
|
||||
HDF_LOGE("Load service failed, device node is null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
devNode->driverEntry = driverEntry;
|
||||
devNode->deviceInfo = deviceInfo;
|
||||
devNode->deviceObject.property = HcsGetNodeByMatchAttr(HcsGetRootNode(), deviceInfo->deviceMatchAttr);
|
||||
if (devNode->deviceObject.property == NULL) {
|
||||
HDF_LOGW("Get property is null, match attr is: %s", deviceInfo->deviceMatchAttr);
|
||||
}
|
||||
|
||||
if ((deviceInfo->policy == SERVICE_POLICY_PUBLIC) || (deviceInfo->policy == SERVICE_POLICY_CAPACITY)) {
|
||||
if (driverEntry->Bind == NULL) {
|
||||
HDF_LOGE("driver bind method is null");
|
||||
HdfDeviceNodeFreeInstance(devNode);
|
||||
return NULL;
|
||||
}
|
||||
if (driverEntry->Bind(&devNode->deviceObject) != 0) {
|
||||
HDF_LOGE("bind driver failed");
|
||||
HdfDeviceNodeFreeInstance(devNode);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return devNode;
|
||||
}
|
||||
|
||||
static void HdfDriverLoaderUnLoadNode(struct IDriverLoader *loader, const struct HdfDeviceInfo *deviceInfo)
|
||||
{
|
||||
struct HdfDriverEntry *driverEntry = NULL;
|
||||
struct HdfDeviceObject *deviceObject = NULL;
|
||||
if ((loader == NULL) || (loader->GetDriverEntry == NULL)) {
|
||||
HDF_LOGE("loader or loader->GetDriverEntry is null");
|
||||
return;
|
||||
}
|
||||
|
||||
driverEntry = loader->GetDriverEntry(deviceInfo);
|
||||
if (driverEntry == NULL) {
|
||||
HDF_LOGE("Load service failed, driverEntry is null");
|
||||
return;
|
||||
}
|
||||
if (driverEntry->Release == NULL) {
|
||||
HDF_LOGI("Device Release func is null");
|
||||
return;
|
||||
}
|
||||
deviceObject = DevSvcManagerClntGetDeviceObject(deviceInfo->svcName);
|
||||
driverEntry->Release(deviceObject);
|
||||
}
|
||||
|
||||
static void HdfDriverLoaderConstruct(struct HdfDriverLoader *inst)
|
||||
{
|
||||
struct IDriverLoader *driverLoaderIf = (struct IDriverLoader *)inst;
|
||||
driverLoaderIf->LoadNode = HdfDriverLoaderLoadNode;
|
||||
driverLoaderIf->UnLoadNode = HdfDriverLoaderUnLoadNode;
|
||||
driverLoaderIf->GetDriverEntry = HdfDriverLoaderGetDriverEntry;
|
||||
}
|
||||
|
||||
struct HdfObject *HdfDriverLoaderCreate()
|
||||
{
|
||||
static bool isDriverLoaderInit = false;
|
||||
static struct HdfDriverLoader driverLoader;
|
||||
if (!isDriverLoaderInit) {
|
||||
HdfDriverLoaderConstruct(&driverLoader);
|
||||
isDriverLoaderInit = true;
|
||||
}
|
||||
return (struct HdfObject *)&driverLoader;
|
||||
}
|
||||
|
||||
struct IDriverLoader *HdfDriverLoaderGetInstance()
|
||||
{
|
||||
static struct IDriverLoader *instance = NULL;
|
||||
if (instance == NULL) {
|
||||
instance = (struct IDriverLoader *)HdfObjectManagerGetObject(HDF_OBJECT_ID_DRIVER_LOADER);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
Executable
+116
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "hdf_observer_record.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_service_subscriber.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
#define HDF_LOG_TAG observer_record
|
||||
#define HALF_INT_LEN 16
|
||||
|
||||
uint32_t HdfMakeHardwareId(uint16_t hostId, uint16_t deviceId)
|
||||
{
|
||||
uint32_t hardwareId = hostId;
|
||||
hardwareId = (hardwareId << HALF_INT_LEN) | deviceId;
|
||||
return hardwareId;
|
||||
}
|
||||
|
||||
struct HdfServiceObserverRecord *HdfServiceObserverRecordObtain(uint32_t serviceKey)
|
||||
{
|
||||
struct HdfServiceObserverRecord *observerRecord =
|
||||
(struct HdfServiceObserverRecord *)OsalMemCalloc(sizeof(struct HdfServiceObserverRecord));
|
||||
if (observerRecord != NULL) {
|
||||
observerRecord->serviceKey = serviceKey;
|
||||
observerRecord->publisher = NULL;
|
||||
if (OsalMutexInit(&observerRecord->obsRecMutex) != HDF_SUCCESS) {
|
||||
OsalMemFree(observerRecord);
|
||||
return NULL;
|
||||
}
|
||||
HdfSListInit(&observerRecord->subscribers);
|
||||
}
|
||||
return observerRecord;
|
||||
}
|
||||
|
||||
void HdfServiceObserverRecordRecycle(struct HdfServiceObserverRecord *observerRecord)
|
||||
{
|
||||
if (observerRecord != NULL) {
|
||||
HdfSListFlush(&observerRecord->subscribers, HdfServiceSubscriberDelete);
|
||||
OsalMutexDestroy(&observerRecord->obsRecMutex);
|
||||
observerRecord->obsRecMutex.realMutex = NULL;
|
||||
OsalMemFree(observerRecord);
|
||||
}
|
||||
}
|
||||
|
||||
bool HdfServiceObserverRecordCompare(struct HdfSListNode *listEntry, uint32_t serviceKey)
|
||||
{
|
||||
if (listEntry == NULL) {
|
||||
return false;
|
||||
}
|
||||
struct HdfServiceObserverRecord *record = (struct HdfServiceObserverRecord *)listEntry;
|
||||
if (record->serviceKey == serviceKey) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void HdfServiceObserverRecordNotifySubscribers(
|
||||
struct HdfServiceObserverRecord *record, uint32_t matchId, uint16_t policy)
|
||||
{
|
||||
struct HdfSListIterator it;
|
||||
if (record == NULL) {
|
||||
HDF_LOGE("%s: record is null", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
OsalMutexLock(&record->obsRecMutex);
|
||||
HdfSListIteratorInit(&it, &record->subscribers);
|
||||
while (HdfSListIteratorHasNext(&it)) {
|
||||
struct HdfServiceSubscriber *subscriber =
|
||||
(struct HdfServiceSubscriber *)HdfSListIteratorNext(&it);
|
||||
if ((matchId == subscriber->matchId) || (policy != SERVICE_POLICY_PRIVATE)) {
|
||||
subscriber->state = HDF_SUBSCRIBER_STATE_READY;
|
||||
if (subscriber->callback.OnServiceConnected != NULL) {
|
||||
subscriber->callback.OnServiceConnected(subscriber->callback.deviceObject, record->publisher);
|
||||
}
|
||||
}
|
||||
}
|
||||
OsalMutexUnlock(&record->obsRecMutex);
|
||||
}
|
||||
|
||||
void HdfServiceObserverRecordDelete(struct HdfSListNode *listEntry)
|
||||
{
|
||||
struct HdfServiceObserverRecord *observerRecord = (struct HdfServiceObserverRecord *)listEntry;
|
||||
if (observerRecord != NULL) {
|
||||
HdfServiceObserverRecordRecycle(observerRecord);
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+152
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "hdf_service_observer.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_cstring.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_observer_record.h"
|
||||
|
||||
#define HDF_LOG_TAG service_observer
|
||||
|
||||
bool HdfServiceObserverConstruct(struct HdfServiceObserver *observer)
|
||||
{
|
||||
if (observer == NULL) {
|
||||
HDF_LOGE("observer is null");
|
||||
return false;
|
||||
}
|
||||
if (OsalMutexInit(&observer->observerMutex) != HDF_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
HdfSListInit(&observer->services);
|
||||
return true;
|
||||
}
|
||||
|
||||
void HdfServiceObserverDestruct(struct HdfServiceObserver *observer)
|
||||
{
|
||||
if (observer != NULL) {
|
||||
HdfSListFlush(&observer->services, HdfServiceObserverRecordDelete);
|
||||
OsalMutexDestroy(&observer->observerMutex);
|
||||
observer->observerMutex.realMutex = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int HdfServiceObserverSubscribeService(struct HdfServiceObserver *observer,
|
||||
const char *svcName, uint32_t matchId, struct SubscriberCallback callback)
|
||||
{
|
||||
struct HdfServiceObserverRecord *serviceRecord = NULL;
|
||||
struct HdfServiceSubscriber *subscriber = NULL;
|
||||
uint32_t serviceKey = HdfStringMakeHashKey(svcName, 0);
|
||||
if ((observer == NULL) || (svcName == NULL)) {
|
||||
HDF_LOGE("observer or svcName or callback.OnServiceConnected is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
serviceRecord = (struct HdfServiceObserverRecord *)HdfSListSearch(
|
||||
&observer->services, serviceKey, HdfServiceObserverRecordCompare);
|
||||
if (serviceRecord == NULL) {
|
||||
serviceRecord = HdfServiceObserverRecordObtain(serviceKey);
|
||||
if (serviceRecord == NULL) {
|
||||
HDF_LOGE("SubscribeService failed, serviceRecord is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
subscriber = HdfServiceSubscriberObtain(callback, matchId);
|
||||
if (subscriber == NULL) {
|
||||
HDF_LOGE("SubscribeService failed, subscriber is null");
|
||||
HdfServiceObserverRecordRecycle(serviceRecord);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HdfSListAdd(&observer->services, &serviceRecord->entry);
|
||||
} else {
|
||||
subscriber = HdfServiceSubscriberObtain(callback, matchId);
|
||||
if (subscriber == NULL) {
|
||||
HDF_LOGE("SubscribeService failed, hdf search list is null, subscriber is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
}
|
||||
if ((serviceRecord->publisher != NULL) &&
|
||||
(subscriber->callback.OnServiceConnected != NULL) &&
|
||||
((serviceRecord->policy != SERVICE_POLICY_PRIVATE) ||
|
||||
(serviceRecord->matchId == matchId))) {
|
||||
subscriber->state = HDF_SUBSCRIBER_STATE_READY;
|
||||
subscriber->callback.OnServiceConnected(subscriber->callback.deviceObject, serviceRecord->publisher);
|
||||
}
|
||||
OsalMutexLock(&serviceRecord->obsRecMutex);
|
||||
HdfSListAdd(&serviceRecord->subscribers, &subscriber->entry);
|
||||
OsalMutexUnlock(&serviceRecord->obsRecMutex);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int HdfServiceObserverPublishService(struct HdfServiceObserver *observer,
|
||||
const char *svcName, uint32_t matchId, uint16_t policy, struct HdfObject *service)
|
||||
{
|
||||
struct HdfServiceObserverRecord *serviceRecord = NULL;
|
||||
uint32_t serviceKey = HdfStringMakeHashKey(svcName, 0);
|
||||
if ((observer == NULL) || (svcName == NULL)) {
|
||||
HDF_LOGE("observer or svcName is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
serviceRecord = (struct HdfServiceObserverRecord *)HdfSListSearch(
|
||||
&observer->services, serviceKey, HdfServiceObserverRecordCompare);
|
||||
if (serviceRecord == NULL) {
|
||||
serviceRecord = HdfServiceObserverRecordObtain(serviceKey);
|
||||
if (serviceRecord == NULL) {
|
||||
HDF_LOGE("PublishService failed, serviceRecord is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
serviceRecord->publisher = service;
|
||||
serviceRecord->matchId = matchId;
|
||||
serviceRecord->policy = policy;
|
||||
HdfSListAdd(&observer->services, &serviceRecord->entry);
|
||||
} else {
|
||||
serviceRecord->publisher = service;
|
||||
HdfServiceObserverRecordNotifySubscribers(serviceRecord, matchId, policy);
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
void HdfServiceObserverRemoveRecord(struct HdfServiceObserver *observer, const char *svcName)
|
||||
{
|
||||
struct HdfServiceObserverRecord *serviceRecord = NULL;
|
||||
uint32_t serviceKey = HdfStringMakeHashKey(svcName, 0);
|
||||
if ((observer == NULL) || (svcName == NULL)) {
|
||||
HDF_LOGW("observer or svcName is null");
|
||||
return;
|
||||
}
|
||||
serviceRecord = (struct HdfServiceObserverRecord *)HdfSListSearch(
|
||||
&observer->services, serviceKey, HdfServiceObserverRecordCompare);
|
||||
if (serviceRecord != NULL) {
|
||||
OsalMutexLock(&observer->observerMutex);
|
||||
HdfSListRemove(&observer->services, &serviceRecord->entry);
|
||||
OsalMutexUnlock(&observer->observerMutex);
|
||||
HdfServiceObserverRecordRecycle(serviceRecord);
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "osal_mem.h"
|
||||
#include "hdf_service_subscriber.h"
|
||||
|
||||
struct HdfServiceSubscriber *HdfServiceSubscriberObtain(struct SubscriberCallback callback, uint32_t matchId)
|
||||
{
|
||||
struct HdfServiceSubscriber *serviceSubscriber =
|
||||
(struct HdfServiceSubscriber *)OsalMemCalloc(sizeof(struct HdfServiceSubscriber));
|
||||
if (serviceSubscriber != NULL) {
|
||||
serviceSubscriber->state = HDF_SUBSCRIBER_STATE_PENDING;
|
||||
serviceSubscriber->matchId = matchId;
|
||||
serviceSubscriber->callback = callback;
|
||||
}
|
||||
return serviceSubscriber;
|
||||
}
|
||||
|
||||
void HdfServiceSubscriberRecycle(struct HdfServiceSubscriber *subscriber)
|
||||
{
|
||||
if (subscriber != NULL) {
|
||||
OsalMemFree(subscriber);
|
||||
}
|
||||
}
|
||||
|
||||
void HdfServiceSubscriberDelete(struct HdfSListNode *listEntry)
|
||||
{
|
||||
struct HdfServiceSubscriber *serviceSubscriber = (struct HdfServiceSubscriber *)listEntry;
|
||||
if (serviceSubscriber != NULL) {
|
||||
HdfServiceSubscriberRecycle(serviceSubscriber);
|
||||
}
|
||||
}
|
||||
Executable
+159
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "power_state_token.h"
|
||||
#include "devmgr_service_clnt.h"
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_slist.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
static void PowerStateTokenAcqureWakeLock(struct IPowerStateToken *token)
|
||||
{
|
||||
struct HdfSRef *sref = NULL;
|
||||
struct PowerStateToken *stateToken = (struct PowerStateToken *)token;
|
||||
if (stateToken == NULL) {
|
||||
return;
|
||||
}
|
||||
sref = (struct HdfSRef *)&stateToken->wakeRef;
|
||||
if ((sref != NULL) && (sref->Acquire != NULL)) {
|
||||
sref->Acquire(sref);
|
||||
}
|
||||
}
|
||||
|
||||
static void PowerStateTokenReleaseWakeLock(struct IPowerStateToken *token)
|
||||
{
|
||||
struct HdfSRef *sref = NULL;
|
||||
struct PowerStateToken *stateToken = (struct PowerStateToken *)token;
|
||||
if (stateToken == NULL) {
|
||||
return;
|
||||
}
|
||||
sref = (struct HdfSRef *)&stateToken->wakeRef;
|
||||
if ((sref != NULL) && (sref->Release != NULL)) {
|
||||
sref->Release(sref);
|
||||
}
|
||||
}
|
||||
|
||||
static void PowerStateTokenOnFirstAcquire(struct HdfSRef *sref)
|
||||
{
|
||||
if (sref == NULL) {
|
||||
return;
|
||||
}
|
||||
struct PowerStateToken *stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfSRef, sref, struct PowerStateToken, wakeRef);
|
||||
if (stateToken->state != POWER_STATE_ACTIVE) {
|
||||
struct IDevmgrService *devMgrSvcIf = NULL;
|
||||
struct IPowerEventListener* listener = stateToken->listener;
|
||||
struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance();
|
||||
if (inst == NULL) {
|
||||
return;
|
||||
}
|
||||
devMgrSvcIf = (struct IDevmgrService *)inst->devMgrSvcIf;
|
||||
if (devMgrSvcIf->AcquireWakeLock == NULL) {
|
||||
return;
|
||||
}
|
||||
devMgrSvcIf->AcquireWakeLock(devMgrSvcIf, &stateToken->super);
|
||||
if (stateToken->state == POWER_STATE_INACTIVE) {
|
||||
if ((listener != NULL) && (listener->Resume != NULL)) {
|
||||
listener->Resume(stateToken->deviceObject);
|
||||
}
|
||||
}
|
||||
stateToken->state = POWER_STATE_ACTIVE;
|
||||
}
|
||||
}
|
||||
|
||||
static void PowerStateTokenOnLastRelease(struct HdfSRef *sref)
|
||||
{
|
||||
if (sref == NULL) {
|
||||
return;
|
||||
}
|
||||
struct PowerStateToken *stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfSRef, sref, struct PowerStateToken, wakeRef);
|
||||
if (stateToken->state == POWER_STATE_ACTIVE) {
|
||||
struct IDevmgrService *devMgrSvcIf = NULL;
|
||||
struct IPowerEventListener *listener = stateToken->listener;
|
||||
struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance();
|
||||
if (inst == NULL) {
|
||||
return;
|
||||
}
|
||||
devMgrSvcIf = (struct IDevmgrService *)inst->devMgrSvcIf;
|
||||
if ((devMgrSvcIf == NULL) || (devMgrSvcIf->AcquireWakeLock == NULL)) {
|
||||
return;
|
||||
}
|
||||
devMgrSvcIf->ReleaseWakeLock(devMgrSvcIf, &stateToken->super);
|
||||
if ((listener != NULL) && (listener->Suspend != NULL)) {
|
||||
listener->Suspend(stateToken->deviceObject);
|
||||
}
|
||||
stateToken->state = POWER_STATE_INACTIVE;
|
||||
}
|
||||
}
|
||||
|
||||
static void PowerStateTokenConstruct(
|
||||
struct PowerStateToken *powerStateToken, struct HdfDeviceObject *deviceObject, struct IPowerEventListener *listener)
|
||||
{
|
||||
struct IPowerStateToken *tokenIf = (struct IPowerStateToken *)powerStateToken;
|
||||
struct IHdfSRefListener *srefListener = (struct IHdfSRefListener *)OsalMemCalloc(sizeof(struct IHdfSRefListener));
|
||||
if (srefListener == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
tokenIf->AcquireWakeLock = PowerStateTokenAcqureWakeLock;
|
||||
tokenIf->ReleaseWakeLock = PowerStateTokenReleaseWakeLock;
|
||||
|
||||
srefListener->OnFirstAcquire = PowerStateTokenOnFirstAcquire;
|
||||
srefListener->OnLastRelease = PowerStateTokenOnLastRelease;
|
||||
|
||||
powerStateToken->state = POWER_STATE_IDLE;
|
||||
powerStateToken->listener = listener;
|
||||
powerStateToken->deviceObject = deviceObject;
|
||||
HdfSRefConstruct(&powerStateToken->wakeRef, srefListener);
|
||||
}
|
||||
|
||||
struct PowerStateToken *PowerStateTokenNewInstance(
|
||||
struct HdfDeviceObject *deviceObject, struct IPowerEventListener *listener)
|
||||
{
|
||||
struct PowerStateToken *stateToken =
|
||||
(struct PowerStateToken *)OsalMemCalloc(sizeof(struct PowerStateToken));
|
||||
if (stateToken != NULL) {
|
||||
PowerStateTokenConstruct(stateToken, deviceObject, listener);
|
||||
}
|
||||
return stateToken;
|
||||
}
|
||||
|
||||
void PowerStateTokenFreeInstance(struct PowerStateToken *stateToken)
|
||||
{
|
||||
if (stateToken != NULL) {
|
||||
if (stateToken->wakeRef.listener != NULL) {
|
||||
OsalMemFree(stateToken->wakeRef.listener);
|
||||
stateToken->wakeRef.listener = NULL;
|
||||
}
|
||||
OsalMemFree(stateToken);
|
||||
}
|
||||
}
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef DEVHOST_SERVICE_CLNT_H
|
||||
#define DEVHOST_SERVICE_CLNT_H
|
||||
|
||||
#include "devhost_service_if.h"
|
||||
#include "hdf_slist.h"
|
||||
|
||||
struct DevHostServiceClnt {
|
||||
struct HdfSListNode node;
|
||||
struct HdfSList devices;
|
||||
struct HdfSList *deviceInfos;
|
||||
struct IDevHostService *hostService;
|
||||
uint16_t hostId;
|
||||
int hostPid;
|
||||
const char *hostName;
|
||||
};
|
||||
|
||||
int DevHostServiceClntInstallDriver(struct DevHostServiceClnt *hostClnt);
|
||||
struct DevHostServiceClnt *DevHostServiceClntNewInstance(uint16_t hostId, const char *hostName);
|
||||
void DevHostServiceClntFreeInstance(struct DevHostServiceClnt* hostClnt);
|
||||
void DevHostServiceClntDelete(struct HdfSListNode *listEntry);
|
||||
|
||||
#endif /* DEVHOST_SERVICE_CLNT_H */
|
||||
Executable
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef DEVICE_TOKEN_CLNT_H
|
||||
#define DEVICE_TOKEN_CLNT_H
|
||||
|
||||
#include "device_token_if.h"
|
||||
#include "hdf_device_info.h"
|
||||
#include "hdf_slist.h"
|
||||
|
||||
struct DeviceTokenClnt {
|
||||
struct HdfSListNode node;
|
||||
struct IHdfDeviceToken *tokenIf;
|
||||
const struct HdfDeviceInfo *deviceInfo;
|
||||
};
|
||||
|
||||
struct DeviceTokenClnt *DeviceTokenClntNewInstance(struct IHdfDeviceToken *token);
|
||||
void DeviceTokenClntFreeInstance(struct DeviceTokenClnt *token);
|
||||
void DeviceTokenClntDelete(struct HdfSListNode *listEntry);
|
||||
|
||||
#endif /* DEVICE_TOKEN_CLNT_H */
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef DEVICE_MANAGER_SERVICE_H
|
||||
#define DEVICE_MANAGER_SERVICE_H
|
||||
|
||||
#include "devmgr_service_if.h"
|
||||
#include "hdf_slist.h"
|
||||
#include "osal_mutex.h"
|
||||
|
||||
struct DevmgrService {
|
||||
struct IDevmgrService super;
|
||||
struct HdfSList hosts;
|
||||
struct OsalMutex devMgrMutex;
|
||||
};
|
||||
|
||||
int DevmgrServiceStartService(struct IDevmgrService *inst);
|
||||
struct HdfObject *DevmgrServiceCreate(void);
|
||||
void DevmgrServiceRelease(struct HdfObject *object);
|
||||
struct IDevmgrService *DevmgrServiceGetInstance(void);
|
||||
int DevmgrServiceLoadDevice(const char *svcName);
|
||||
int DevmgrServiceUnLoadDevice(const char *svcName);
|
||||
void DevmgrServiceAcquireWakeLock(struct IDevmgrService *inst, struct IPowerStateToken *tokenIf);
|
||||
void DevmgrServiceReleaseWakeLock(struct IDevmgrService *inst, struct IPowerStateToken *tokenIf);
|
||||
|
||||
#endif /* DEVICE_MANAGER_SERVICE_H */
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef DEVICE_SERVICE_MANAGER_H
|
||||
#define DEVICE_SERVICE_MANAGER_H
|
||||
|
||||
#include "devsvc_manager_if.h"
|
||||
#include "hdf_service_observer.h"
|
||||
#include "hdf_slist.h"
|
||||
#include "osal_mutex.h"
|
||||
|
||||
struct DevSvcManager {
|
||||
struct IDevSvcManager super;
|
||||
struct HdfSList services;
|
||||
struct HdfServiceObserver observer;
|
||||
struct OsalMutex mutex;
|
||||
};
|
||||
|
||||
struct HdfObject *DevSvcManagerCreate(void);
|
||||
void DevSvcManagerRelease(struct HdfObject *object);
|
||||
struct IDevSvcManager *DevSvcManagerGetInstance(void);
|
||||
int DevSvcManagerAddService(struct IDevSvcManager *manager, const char *svcName, struct HdfDeviceObject *service);
|
||||
struct HdfObject *DevSvcManagerGetService(struct IDevSvcManager *manager, const char *svcName);
|
||||
void DevSvcManagerRemoveService(struct IDevSvcManager *manager, const char *svcName);
|
||||
|
||||
#endif /* DEVICE_SERVICE_MANAGER_H */
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef DEVSVC_MANAGER_STUB_H
|
||||
#define DEVSVC_MANAGER_STUB_H
|
||||
|
||||
#include "hdf_device_desc.h"
|
||||
|
||||
int DevSvcManagerClntSubscribeService(const char *svcName, struct SubscriberCallback callback);
|
||||
int DevSvcManagerClntUnsubscribeService(const char *svcName);
|
||||
|
||||
#endif /* DEVSVC_MANAGER_STUB_H */
|
||||
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef HDF_DRIVER_INSTALLER_H
|
||||
#define HDF_DRIVER_INSTALLER_H
|
||||
|
||||
#include "hdf_object.h"
|
||||
#include "hdf_slist.h"
|
||||
|
||||
struct IDriverInstaller {
|
||||
struct HdfObject object;
|
||||
int (*StartDeviceHost)(uint32_t, const char *);
|
||||
};
|
||||
|
||||
struct DriverInstaller {
|
||||
struct IDriverInstaller super;
|
||||
};
|
||||
|
||||
struct HdfObject *DriverInstallerCreate(void);
|
||||
struct IDriverInstaller *DriverInstallerGetInstance(void);
|
||||
|
||||
#endif /* HDF_DRIVER_INSTALLER_H */
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef HDF_HOST_INFO_H
|
||||
#define HDF_HOST_INFO_H
|
||||
|
||||
#include "hdf_slist.h"
|
||||
|
||||
struct HdfHostInfo {
|
||||
struct HdfSListNode node;
|
||||
uint16_t hostId;
|
||||
uint16_t priority;
|
||||
const char *hostName;
|
||||
};
|
||||
|
||||
struct HdfHostInfo *HdfHostInfoNewInstance(void);
|
||||
void HdfHostInfoFreeInstance(struct HdfHostInfo *hostInfo);
|
||||
void HdfHostInfoDelete(struct HdfSListNode *listEntry);
|
||||
|
||||
#endif /* HDF_HOST_INFO_H */
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef POWER_STATE_MANAGER_H
|
||||
#define POWER_STATE_MANAGER_H
|
||||
|
||||
#include "hdf_sref.h"
|
||||
#include "hdf_slist.h"
|
||||
#include "power_state_token_if.h"
|
||||
|
||||
struct PowerStateManager {
|
||||
struct HdfSRef wakeRef;
|
||||
struct HdfSList tokens;
|
||||
void (*AcquireWakeLock)(struct PowerStateManager *, struct IPowerStateToken *);
|
||||
void (*ReleaseWakeLock)(struct PowerStateManager *, struct IPowerStateToken *);
|
||||
};
|
||||
|
||||
struct PowerStateManager *PowerStateManagerGetInstance(void);
|
||||
|
||||
#endif /* POWER_STATE_MANAGER_H */
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef POWER_STATE_TOKEN_CLNT_H
|
||||
#define POWER_STATE_TOKEN_CLNT_H
|
||||
|
||||
#include "hdf_slist.h"
|
||||
#include "power_state_token_if.h"
|
||||
|
||||
struct PowerStateTokenClnt {
|
||||
struct HdfSListNode entry;
|
||||
HdfPowerState powerState;
|
||||
struct IPowerStateToken* tokenIf;
|
||||
};
|
||||
|
||||
struct PowerStateTokenClnt *PowerStateTokenClntNewInstance(struct IPowerStateToken *tokenIf);
|
||||
void PowerStateTokenClntFreeInstance(struct PowerStateTokenClnt *tokenClnt);
|
||||
|
||||
#endif /* POWER_STATE_TOKEN_CLNT_H */
|
||||
Executable
+105
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "device_token_clnt.h"
|
||||
#include "devhost_service_clnt.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_driver_installer.h"
|
||||
#include "hdf_log.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
#define HDF_LOG_TAG devhost_service_clnt
|
||||
|
||||
int DevHostServiceClntInstallDriver(struct DevHostServiceClnt *hostClnt)
|
||||
{
|
||||
int ret;
|
||||
struct HdfSListIterator it;
|
||||
struct HdfDeviceInfo *deviceInfo = NULL;
|
||||
struct IDevHostService *devHostSvcIf = NULL;
|
||||
if (hostClnt == NULL) {
|
||||
HDF_LOGE("Install driver failed, hostClnt is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
devHostSvcIf = (struct IDevHostService *)hostClnt->hostService;
|
||||
if (devHostSvcIf == NULL || devHostSvcIf->AddDevice == NULL) {
|
||||
HDF_LOGE("devHostSvcIf or devHostSvcIf->AddDevice is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HdfSListIteratorInit(&it, hostClnt->deviceInfos);
|
||||
while (HdfSListIteratorHasNext(&it)) {
|
||||
deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&it);
|
||||
if ((deviceInfo == NULL) || (deviceInfo->preload != DEVICE_PRELOAD_ENABLE)) {
|
||||
continue;
|
||||
}
|
||||
ret = devHostSvcIf->AddDevice(devHostSvcIf, deviceInfo);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
deviceInfo->preload = DEVICE_PRELOAD_DISABLE;
|
||||
HDF_LOGE("Install %s driver failed, ret = %d", deviceInfo->svcName, ret);
|
||||
}
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static void DevHostServiceClntConstruct(struct DevHostServiceClnt *hostClnt)
|
||||
{
|
||||
HdfSListInit(&hostClnt->devices);
|
||||
}
|
||||
|
||||
struct DevHostServiceClnt *DevHostServiceClntNewInstance(uint16_t hostId, const char *hostName)
|
||||
{
|
||||
struct DevHostServiceClnt *hostClnt =
|
||||
(struct DevHostServiceClnt *)OsalMemCalloc(sizeof(struct DevHostServiceClnt));
|
||||
if (hostClnt != NULL) {
|
||||
hostClnt->hostId = hostId;
|
||||
hostClnt->hostName = hostName;
|
||||
DevHostServiceClntConstruct(hostClnt);
|
||||
}
|
||||
return hostClnt;
|
||||
}
|
||||
|
||||
void DevHostServiceClntFreeInstance(struct DevHostServiceClnt *hostClnt)
|
||||
{
|
||||
if (hostClnt != NULL) {
|
||||
HdfSListFlush(&hostClnt->devices, DeviceTokenClntDelete);
|
||||
HdfSListFlush(hostClnt->deviceInfos, HdfDeviceInfoDelete);
|
||||
OsalMemFree(hostClnt);
|
||||
}
|
||||
}
|
||||
|
||||
void DevHostServiceClntDelete(struct HdfSListNode *listEntry)
|
||||
{
|
||||
struct DevHostServiceClnt *hostClnt = (struct DevHostServiceClnt *)listEntry;
|
||||
if (hostClnt != NULL) {
|
||||
DevHostServiceClntFreeInstance(hostClnt);
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "device_token_clnt.h"
|
||||
#include "hdf_device_token.h"
|
||||
#include "hdf_log.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
#define HDF_LOG_TAG device_token_clnt
|
||||
|
||||
static void DeviceTokenClntConstruct(struct DeviceTokenClnt *tokenClnt, struct IHdfDeviceToken *tokenIf)
|
||||
{
|
||||
tokenClnt->tokenIf = tokenIf;
|
||||
tokenClnt->deviceInfo = NULL;
|
||||
}
|
||||
|
||||
struct DeviceTokenClnt *DeviceTokenClntNewInstance(struct IHdfDeviceToken *tokenIf)
|
||||
{
|
||||
struct DeviceTokenClnt *tokenClnt = NULL;
|
||||
if (tokenIf == NULL) {
|
||||
HDF_LOGE("New token client failed, tokenIf is null");
|
||||
return NULL;
|
||||
}
|
||||
tokenClnt = (struct DeviceTokenClnt *)OsalMemCalloc(sizeof(struct DeviceTokenClnt));
|
||||
if (tokenClnt != NULL) {
|
||||
DeviceTokenClntConstruct(tokenClnt, tokenIf);
|
||||
}
|
||||
return tokenClnt;
|
||||
}
|
||||
|
||||
void DeviceTokenClntFreeInstance(struct DeviceTokenClnt *tokenClnt)
|
||||
{
|
||||
if (tokenClnt != NULL) {
|
||||
OsalMemFree(tokenClnt);
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceTokenClntDelete(struct HdfSListNode *listEntry)
|
||||
{
|
||||
struct DeviceTokenClnt *tokenClnt = (struct DeviceTokenClnt *)listEntry;
|
||||
if (tokenClnt != NULL) {
|
||||
DeviceTokenClntFreeInstance(tokenClnt);
|
||||
}
|
||||
}
|
||||
Executable
+280
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "devmgr_service.h"
|
||||
#include <string.h>
|
||||
#include "devhost_service_clnt.h"
|
||||
#include "device_token_clnt.h"
|
||||
#include "hdf_attribute_manager.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_driver_installer.h"
|
||||
#include "hdf_host_info.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_object_manager.h"
|
||||
#include "power_state_manager.h"
|
||||
|
||||
|
||||
#define HDF_LOG_TAG devmgr_service
|
||||
|
||||
static int DevmgrServiceActiveDevice(struct DevHostServiceClnt *hostClnt, struct HdfDeviceInfo *deviceInfo, bool isLoad)
|
||||
{
|
||||
struct IDevHostService *devHostSvcIf = (struct IDevHostService *)hostClnt->hostService;
|
||||
if (isLoad) {
|
||||
int ret = devHostSvcIf->AddDevice(devHostSvcIf, deviceInfo);
|
||||
if (ret == HDF_SUCCESS) {
|
||||
deviceInfo->preload = DEVICE_PRELOAD_ENABLE;
|
||||
}
|
||||
return ret;
|
||||
} else {
|
||||
devHostSvcIf->DelDevice(devHostSvcIf, deviceInfo);
|
||||
deviceInfo->preload = DEVICE_PRELOAD_DISABLE;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
static int DevmgrServiceFindAndActiveDevice(const char *svcName, bool isLoad)
|
||||
{
|
||||
struct HdfSListIterator itHost;
|
||||
struct HdfSListIterator itDeviceInfo;
|
||||
struct HdfDeviceInfo *deviceInfo = NULL;
|
||||
struct DevHostServiceClnt *hostClnt = NULL;
|
||||
struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
|
||||
if (devMgrSvc == NULL || svcName == NULL) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
HdfSListIteratorInit(&itHost, &devMgrSvc->hosts);
|
||||
while (HdfSListIteratorHasNext(&itHost)) {
|
||||
hostClnt = (struct DevHostServiceClnt *)HdfSListIteratorNext(&itHost);
|
||||
HdfSListIteratorInit(&itDeviceInfo, hostClnt->deviceInfos);
|
||||
while (HdfSListIteratorHasNext(&itDeviceInfo)) {
|
||||
deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo);
|
||||
if (strcmp(deviceInfo->svcName, svcName) == 0) {
|
||||
return DevmgrServiceActiveDevice(hostClnt, deviceInfo, isLoad);
|
||||
}
|
||||
}
|
||||
}
|
||||
HDF_LOGE("Find %s deviceInfo failed, active is: %u", svcName, isLoad);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
int DevmgrServiceLoadDevice(const char *svcName)
|
||||
{
|
||||
return DevmgrServiceFindAndActiveDevice(svcName, true);
|
||||
}
|
||||
|
||||
int DevmgrServiceUnLoadDevice(const char *svcName)
|
||||
{
|
||||
return DevmgrServiceFindAndActiveDevice(svcName, false);
|
||||
}
|
||||
|
||||
static struct DevHostServiceClnt *DevmgrServiceFindDeviceHost(struct IDevmgrService *inst, uint16_t hostId)
|
||||
{
|
||||
struct HdfSListIterator it;
|
||||
struct DevHostServiceClnt *hostClnt = NULL;
|
||||
struct DevmgrService *dmService = (struct DevmgrService *)inst;
|
||||
if (dmService == NULL) {
|
||||
HDF_LOGE("Find device host failed, dmService is null");
|
||||
return NULL;
|
||||
}
|
||||
HdfSListIteratorInit(&it, &dmService->hosts);
|
||||
while (HdfSListIteratorHasNext(&it)) {
|
||||
hostClnt = (struct DevHostServiceClnt *)HdfSListIteratorNext(&it);
|
||||
if (hostClnt->hostId == hostId) {
|
||||
return hostClnt;
|
||||
}
|
||||
}
|
||||
HDF_LOGE("Find host failed, host id is %u", hostId);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int DevmgrServiceAttachDevice(
|
||||
struct IDevmgrService *inst, const struct HdfDeviceInfo *deviceInfo, struct IHdfDeviceToken *token)
|
||||
{
|
||||
if (deviceInfo == NULL) {
|
||||
HDF_LOGE("deviceInfo is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
struct DevHostServiceClnt *hostClnt = DevmgrServiceFindDeviceHost(inst, deviceInfo->hostId);
|
||||
if (hostClnt == NULL) {
|
||||
HDF_LOGE("hostClnt is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
struct IDevHostService *hostService = hostClnt->hostService;
|
||||
if ((hostService == NULL) || (hostClnt->deviceInfos == NULL)) {
|
||||
HDF_LOGE("hostService or hostClnt->deviceInfos is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
struct DeviceTokenClnt *tokenClnt = DeviceTokenClntNewInstance(token);
|
||||
if (tokenClnt == NULL) {
|
||||
HDF_LOGE("tokenClnt is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
tokenClnt->deviceInfo = deviceInfo;
|
||||
HdfSListAdd(&hostClnt->devices, &tokenClnt->node);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int DevmgrServiceAttachDeviceHost(
|
||||
struct IDevmgrService *inst, uint16_t hostId, struct IDevHostService *hostService)
|
||||
{
|
||||
struct DevHostServiceClnt *hostClnt = DevmgrServiceFindDeviceHost(inst, hostId);
|
||||
if (hostClnt == NULL) {
|
||||
HDF_LOGE("Attach device host failed, hostClnt is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (hostService == NULL) {
|
||||
HDF_LOGE("Attach device host failed, hostService is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
hostClnt->deviceInfos = HdfAttributeManagerGetDeviceList(hostClnt->hostId, hostClnt->hostName);
|
||||
if (hostClnt->deviceInfos == NULL) {
|
||||
HDF_LOGE("Get device list failed");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
hostClnt->hostService = hostService;
|
||||
return DevHostServiceClntInstallDriver(hostClnt);
|
||||
}
|
||||
|
||||
static int DevmgrServiceStartDeviceHosts(struct DevmgrService *inst)
|
||||
{
|
||||
struct HdfSList hostList;
|
||||
struct HdfSListIterator it;
|
||||
struct HdfHostInfo *hostAttr = NULL;
|
||||
struct DevHostServiceClnt *hostClnt = NULL;
|
||||
struct IDriverInstaller *installer = NULL;
|
||||
installer = DriverInstallerGetInstance();
|
||||
if ((installer == NULL) || (installer->StartDeviceHost == NULL)) {
|
||||
HDF_LOGE("installer or installer->StartDeviceHost is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HdfSListInit(&hostList);
|
||||
if (!HdfAttributeManagerGetHostList(&hostList)) {
|
||||
HDF_LOGW("Get device host list failed");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HdfSListIteratorInit(&it, &hostList);
|
||||
while (HdfSListIteratorHasNext(&it)) {
|
||||
hostAttr = (struct HdfHostInfo *)HdfSListIteratorNext(&it);
|
||||
hostClnt = DevHostServiceClntNewInstance(hostAttr->hostId, hostAttr->hostName);
|
||||
if (hostClnt == NULL) {
|
||||
HDF_LOGW("Create new device host client failed");
|
||||
continue;
|
||||
}
|
||||
HdfSListAdd(&inst->hosts, &hostClnt->node);
|
||||
hostClnt->hostPid = installer->StartDeviceHost(hostAttr->hostId, hostAttr->hostName);
|
||||
if (hostClnt->hostPid == HDF_FAILURE) {
|
||||
HDF_LOGW("Start device host failed, host id is %u", hostAttr->hostId);
|
||||
HdfSListRemove(&inst->hosts, &hostClnt->node);
|
||||
DevHostServiceClntFreeInstance(hostClnt);
|
||||
}
|
||||
}
|
||||
HdfSListFlush(&hostList, HdfHostInfoDelete);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int DevmgrServiceStartService(struct IDevmgrService *inst)
|
||||
{
|
||||
struct DevmgrService *dmService = (struct DevmgrService *)inst;
|
||||
if (dmService == NULL) {
|
||||
HDF_LOGE("Start device manager service failed, dmService is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return DevmgrServiceStartDeviceHosts(dmService);
|
||||
}
|
||||
|
||||
static bool DevmgrServiceConstruct(struct DevmgrService *inst)
|
||||
{
|
||||
if (OsalMutexInit(&inst->devMgrMutex) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s mutex init failed", __func__);
|
||||
return false;
|
||||
}
|
||||
struct IDevmgrService *devMgrSvcIf = (struct IDevmgrService *)inst;
|
||||
if (devMgrSvcIf != NULL) {
|
||||
devMgrSvcIf->AttachDevice = DevmgrServiceAttachDevice;
|
||||
devMgrSvcIf->AttachDeviceHost = DevmgrServiceAttachDeviceHost;
|
||||
devMgrSvcIf->StartService = DevmgrServiceStartService;
|
||||
devMgrSvcIf->AcquireWakeLock = DevmgrServiceAcquireWakeLock;
|
||||
devMgrSvcIf->ReleaseWakeLock = DevmgrServiceReleaseWakeLock;
|
||||
HdfSListInit(&inst->hosts);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
struct HdfObject *DevmgrServiceCreate()
|
||||
{
|
||||
static bool isDevMgrServiceInit = false;
|
||||
static struct DevmgrService devmgrServiceInstance;
|
||||
if (!isDevMgrServiceInit) {
|
||||
if (!DevmgrServiceConstruct(&devmgrServiceInstance)) {
|
||||
return NULL;
|
||||
}
|
||||
isDevMgrServiceInit = true;
|
||||
}
|
||||
return (struct HdfObject *)&devmgrServiceInstance;
|
||||
}
|
||||
|
||||
struct IDevmgrService *DevmgrServiceGetInstance()
|
||||
{
|
||||
static struct IDevmgrService *instance = NULL;
|
||||
if (instance == NULL) {
|
||||
instance = (struct IDevmgrService *)HdfObjectManagerGetObject(HDF_OBJECT_ID_DEVMGR_SERVICE);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
void DevmgrServiceRelease(struct HdfObject *object)
|
||||
{
|
||||
struct DevmgrService *devmgrService = (struct DevmgrService *)object;
|
||||
if (devmgrService == NULL) {
|
||||
return;
|
||||
}
|
||||
HdfSListFlush(&devmgrService->hosts, DevHostServiceClntDelete);
|
||||
OsalMutexDestroy(&devmgrService->devMgrMutex);
|
||||
}
|
||||
|
||||
void DevmgrServiceAcquireWakeLock(struct IDevmgrService *inst, struct IPowerStateToken *tokenIf)
|
||||
{
|
||||
struct PowerStateManager *stateManager = PowerStateManagerGetInstance();
|
||||
if ((stateManager != NULL) && (stateManager->AcquireWakeLock != NULL)) {
|
||||
stateManager->AcquireWakeLock(stateManager, tokenIf);
|
||||
}
|
||||
}
|
||||
|
||||
void DevmgrServiceReleaseWakeLock(struct IDevmgrService *inst, struct IPowerStateToken *tokenIf)
|
||||
{
|
||||
struct PowerStateManager *stateManager = PowerStateManagerGetInstance();
|
||||
if ((stateManager != NULL) && (stateManager->ReleaseWakeLock != NULL)) {
|
||||
stateManager->ReleaseWakeLock(stateManager, tokenIf);
|
||||
}
|
||||
}
|
||||
Executable
+212
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "devsvc_manager.h"
|
||||
#include "devmgr_service.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_cstring.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_object_manager.h"
|
||||
#include "hdf_service_record.h"
|
||||
|
||||
#define HDF_LOG_TAG devsvc_manager
|
||||
|
||||
struct DevSvcRecord *DevSvcManagerSearchService(struct IDevSvcManager *inst, uint32_t serviceKey)
|
||||
{
|
||||
struct HdfSListIterator it;
|
||||
struct DevSvcRecord *record = NULL;
|
||||
struct DevSvcRecord *searchResult = NULL;
|
||||
struct DevSvcManager *devSvcManager = (struct DevSvcManager *)inst;
|
||||
if (devSvcManager == NULL) {
|
||||
HDF_LOGE("Search service failed, devSvcManager is null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OsalMutexLock(&devSvcManager->mutex);
|
||||
HdfSListIteratorInit(&it, &devSvcManager->services);
|
||||
while (HdfSListIteratorHasNext(&it)) {
|
||||
record = (struct DevSvcRecord *)HdfSListIteratorNext(&it);
|
||||
if ((record != NULL) && (record->key == serviceKey)) {
|
||||
searchResult = record;
|
||||
break;
|
||||
}
|
||||
}
|
||||
OsalMutexUnlock(&devSvcManager->mutex);
|
||||
return searchResult;
|
||||
}
|
||||
|
||||
int DevSvcManagerAddService(struct IDevSvcManager *inst, const char *svcName, struct HdfDeviceObject *service)
|
||||
{
|
||||
struct DevSvcManager *devSvcManager = (struct DevSvcManager *)inst;
|
||||
if ((devSvcManager == NULL) || (service == NULL) || (svcName == NULL)) {
|
||||
HDF_LOGE("Add service failed, input param is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
struct DevSvcRecord *record = DevSvcRecordNewInstance();
|
||||
if (record == NULL) {
|
||||
HDF_LOGE("Add service failed, record is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
record->key = HdfStringMakeHashKey(svcName, 0);
|
||||
record->value = service;
|
||||
OsalMutexLock(&devSvcManager->mutex);
|
||||
HdfSListAdd(&devSvcManager->services, &record->entry);
|
||||
OsalMutexUnlock(&devSvcManager->mutex);
|
||||
return HdfServiceObserverPublishService(
|
||||
&devSvcManager->observer, svcName, 0, SERVICE_POLICY_PUBLIC, (struct HdfObject *)service->service);
|
||||
}
|
||||
|
||||
int DevSvcManagerSubscribeService(struct IDevSvcManager *inst, const char *svcName, struct SubscriberCallback callBack)
|
||||
{
|
||||
int ret = HDF_FAILURE;
|
||||
struct DevSvcManager *devSvcMgr = (struct DevSvcManager *)inst;
|
||||
if (svcName == NULL || devSvcMgr == NULL) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = HdfServiceObserverSubscribeService(&devSvcMgr->observer, svcName, 0, callBack);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct HdfObject *deviceService = DevSvcManagerGetService(inst, svcName);
|
||||
if (deviceService != NULL) {
|
||||
if (callBack.OnServiceConnected != NULL) {
|
||||
callBack.OnServiceConnected(callBack.deviceObject, deviceService);
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
return DevmgrServiceLoadDevice(svcName);
|
||||
}
|
||||
|
||||
int DevSvcManagerUnsubscribeService(struct IDevSvcManager *inst, const char *svcName)
|
||||
{
|
||||
struct DevSvcManager *devSvcMgr = (struct DevSvcManager *)inst;
|
||||
if (devSvcMgr == NULL) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HdfServiceObserverRemoveRecord(&devSvcMgr->observer, svcName);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
void DevSvcManagerRemoveService(struct IDevSvcManager *inst, const char *svcName)
|
||||
{
|
||||
struct DevSvcManager *devSvcManager = (struct DevSvcManager *)inst;
|
||||
uint32_t serviceKey = HdfStringMakeHashKey(svcName, 0);
|
||||
if (svcName == NULL || devSvcManager == NULL) {
|
||||
return;
|
||||
}
|
||||
struct DevSvcRecord *serviceRecord = DevSvcManagerSearchService(inst, serviceKey);
|
||||
if (serviceRecord != NULL) {
|
||||
OsalMutexLock(&devSvcManager->mutex);
|
||||
HdfSListRemove(&devSvcManager->services, &serviceRecord->entry);
|
||||
OsalMutexUnlock(&devSvcManager->mutex);
|
||||
}
|
||||
}
|
||||
|
||||
struct HdfDeviceObject *DevSvcManagerGetObject(struct IDevSvcManager *inst, const char *svcName)
|
||||
{
|
||||
uint32_t serviceKey = HdfStringMakeHashKey(svcName, 0);
|
||||
if (svcName == NULL) {
|
||||
HDF_LOGE("Get service failed, svcName is null");
|
||||
return NULL;
|
||||
}
|
||||
struct DevSvcRecord *serviceRecord = DevSvcManagerSearchService(inst, serviceKey);
|
||||
if (serviceRecord != NULL) {
|
||||
return serviceRecord->value;
|
||||
}
|
||||
HDF_LOGE("Get object failed, serviceRecord is null, svcName is %s", svcName);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct HdfObject *DevSvcManagerGetService(struct IDevSvcManager *inst, const char *svcName)
|
||||
{
|
||||
struct HdfDeviceObject *deviceObject = DevSvcManagerGetObject(inst, svcName);
|
||||
if (deviceObject == NULL) {
|
||||
HDF_LOGE("Get service failed");
|
||||
return NULL;
|
||||
}
|
||||
return (struct HdfObject *)deviceObject->service;
|
||||
}
|
||||
|
||||
static bool DevSvcManagerConstruct(struct DevSvcManager *inst)
|
||||
{
|
||||
struct IDevSvcManager *devSvcMgrIf = &inst->super;
|
||||
devSvcMgrIf->AddService = DevSvcManagerAddService;
|
||||
devSvcMgrIf->SubscribeService = DevSvcManagerSubscribeService;
|
||||
devSvcMgrIf->UnsubscribeService = DevSvcManagerUnsubscribeService;
|
||||
devSvcMgrIf->RemoveService = DevSvcManagerRemoveService;
|
||||
devSvcMgrIf->GetService = DevSvcManagerGetService;
|
||||
devSvcMgrIf->GetObject = DevSvcManagerGetObject;
|
||||
HdfSListInit(&inst->services);
|
||||
if (OsalMutexInit(&inst->mutex) != HDF_SUCCESS) {
|
||||
HDF_LOGE("Device service manager create mutex failed!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
struct HdfObject *DevSvcManagerCreate()
|
||||
{
|
||||
static bool isDevSvcManagerInit = false;
|
||||
static struct DevSvcManager devSvcManagerInstance;
|
||||
if (!isDevSvcManagerInit) {
|
||||
if (!DevSvcManagerConstruct(&devSvcManagerInstance)) {
|
||||
return NULL;
|
||||
}
|
||||
isDevSvcManagerInit = true;
|
||||
}
|
||||
return (struct HdfObject *)&devSvcManagerInstance;
|
||||
}
|
||||
|
||||
void DevSvcManagerRelease(struct HdfObject *object)
|
||||
{
|
||||
struct DevSvcManager *devSvcManager = (struct DevSvcManager *)object;
|
||||
if (object == NULL) {
|
||||
return;
|
||||
}
|
||||
HdfSListFlush(&devSvcManager->services, DevSvcRecordDelete);
|
||||
OsalMutexDestroy(&devSvcManager->mutex);
|
||||
}
|
||||
|
||||
struct IDevSvcManager *DevSvcManagerGetInstance()
|
||||
{
|
||||
static struct IDevSvcManager *instance = NULL;
|
||||
if (instance == NULL) {
|
||||
instance = (struct IDevSvcManager *)HdfObjectManagerGetObject(HDF_OBJECT_ID_DEVSVC_MANAGER);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
Executable
+80
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "hdf_driver_installer.h"
|
||||
#include "devhost_service.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_object_manager.h"
|
||||
|
||||
#define HDF_LOG_TAG driver_installer
|
||||
|
||||
static int DriverInstallerStartDeviceHost(uint32_t devHostId, const char *devHostName)
|
||||
{
|
||||
struct IDevHostService *hostServiceIf = DevHostServiceNewInstance(devHostId, devHostName);
|
||||
if ((hostServiceIf == NULL) || (hostServiceIf->StartService == NULL)) {
|
||||
HDF_LOGE("hostServiceIf or hostServiceIf->StartService is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
int ret = hostServiceIf->StartService(hostServiceIf);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("Start host service failed, ret is: %d", ret);
|
||||
DevHostServiceFreeInstance(hostServiceIf);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void DriverInstallerConstruct(struct DriverInstaller *inst)
|
||||
{
|
||||
struct IDriverInstaller *driverInstallIf = (struct IDriverInstaller *)inst;
|
||||
driverInstallIf->StartDeviceHost = DriverInstallerStartDeviceHost;
|
||||
}
|
||||
|
||||
struct HdfObject *DriverInstallerCreate(void)
|
||||
{
|
||||
static bool isDriverInstInit = false;
|
||||
static struct DriverInstaller driverInstaller;
|
||||
if (!isDriverInstInit) {
|
||||
DriverInstallerConstruct(&driverInstaller);
|
||||
isDriverInstInit = true;
|
||||
}
|
||||
return (struct HdfObject *)&driverInstaller;
|
||||
}
|
||||
|
||||
struct IDriverInstaller *DriverInstallerGetInstance()
|
||||
{
|
||||
static struct IDriverInstaller *installer = NULL;
|
||||
if (installer == NULL) {
|
||||
installer = (struct IDriverInstaller *)HdfObjectManagerGetObject(HDF_OBJECT_ID_DRIVER_INSTALLER);
|
||||
}
|
||||
return installer;
|
||||
}
|
||||
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "hdf_host_info.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
struct HdfHostInfo *HdfHostInfoNewInstance()
|
||||
{
|
||||
return (struct HdfHostInfo *)OsalMemCalloc(sizeof(struct HdfHostInfo));
|
||||
}
|
||||
|
||||
void HdfHostInfoFreeInstance(struct HdfHostInfo *hostInfo)
|
||||
{
|
||||
if (hostInfo != NULL) {
|
||||
OsalMemFree(hostInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void HdfHostInfoDelete(struct HdfSListNode *listEntry)
|
||||
{
|
||||
struct HdfHostInfo *hostInfo = (struct HdfHostInfo *)listEntry;
|
||||
if (hostInfo != NULL) {
|
||||
HdfHostInfoFreeInstance(hostInfo);
|
||||
}
|
||||
}
|
||||
Executable
+107
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "power_state_manager.h"
|
||||
#include "hdf_object_manager.h"
|
||||
#include "power_state_token_clnt.h"
|
||||
|
||||
static struct PowerStateTokenClnt *PowerStateManagerGetStateTokenClnt(
|
||||
struct PowerStateManager *inst, struct IPowerStateToken *tokenIf)
|
||||
{
|
||||
struct HdfSListIterator it;
|
||||
if (inst == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
HdfSListIteratorInit(&it, &inst->tokens);
|
||||
while (HdfSListIteratorHasNext(&it)) {
|
||||
struct PowerStateTokenClnt *tokenClnt =
|
||||
(struct PowerStateTokenClnt *)HdfSListIteratorNext(&it);
|
||||
if (tokenClnt->tokenIf == tokenIf) {
|
||||
return tokenClnt;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void PowerStateManagerAcquireWakeLock(
|
||||
struct PowerStateManager *inst, struct IPowerStateToken *tokenIf)
|
||||
{
|
||||
if (inst == NULL) {
|
||||
return;
|
||||
}
|
||||
struct HdfSRef *sref = &inst->wakeRef;
|
||||
struct PowerStateTokenClnt *stateTokeClnt = PowerStateManagerGetStateTokenClnt(inst, tokenIf);
|
||||
if (stateTokeClnt == NULL) {
|
||||
return;
|
||||
}
|
||||
stateTokeClnt->powerState = POWER_STATE_ACTIVE;
|
||||
if (sref->Acquire != NULL) {
|
||||
sref->Acquire(sref);
|
||||
}
|
||||
}
|
||||
|
||||
static void PowerStateManagerReleaseWakeLock(
|
||||
struct PowerStateManager *inst, struct IPowerStateToken *tokenIf)
|
||||
{
|
||||
struct HdfSRef *sref = NULL;
|
||||
struct PowerStateTokenClnt *stateTokeClnt = PowerStateManagerGetStateTokenClnt(inst, tokenIf);
|
||||
if (inst == NULL || stateTokeClnt == NULL) {
|
||||
return;
|
||||
}
|
||||
stateTokeClnt->powerState = POWER_STATE_INACTIVE;
|
||||
sref = &inst->wakeRef;
|
||||
if (sref->Release != NULL) {
|
||||
sref->Release(sref);
|
||||
}
|
||||
}
|
||||
|
||||
static void PowerStateManagerConstruct(struct PowerStateManager *inst)
|
||||
{
|
||||
// not support system acquire and release
|
||||
static struct IHdfSRefListener wakeLockRefListener = {
|
||||
.OnFirstAcquire = NULL,
|
||||
.OnLastRelease = NULL,
|
||||
};
|
||||
|
||||
inst->AcquireWakeLock = PowerStateManagerAcquireWakeLock;
|
||||
inst->ReleaseWakeLock = PowerStateManagerReleaseWakeLock;
|
||||
HdfSListInit(&inst->tokens);
|
||||
HdfSRefConstruct(&inst->wakeRef, &wakeLockRefListener);
|
||||
}
|
||||
|
||||
struct PowerStateManager *PowerStateManagerGetInstance()
|
||||
{
|
||||
static struct PowerStateManager powerStateManager = { 0 };
|
||||
if (powerStateManager.AcquireWakeLock == NULL) {
|
||||
PowerStateManagerConstruct(&powerStateManager);
|
||||
}
|
||||
return &powerStateManager;
|
||||
}
|
||||
Executable
+57
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "power_state_token_clnt.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
static void PowerStateTokenClntConstruct(struct PowerStateTokenClnt *clnt, struct IPowerStateToken *tokenIf)
|
||||
{
|
||||
clnt->tokenIf = tokenIf;
|
||||
clnt->powerState = POWER_STATE_INACTIVE;
|
||||
}
|
||||
|
||||
struct PowerStateTokenClnt *PowerStateTokenClntNewInstance(struct IPowerStateToken *tokenIf)
|
||||
{
|
||||
struct PowerStateTokenClnt *tokenClnt =
|
||||
(struct PowerStateTokenClnt *)OsalMemCalloc(sizeof(struct PowerStateTokenClnt));
|
||||
if (tokenClnt != NULL) {
|
||||
PowerStateTokenClntConstruct(tokenClnt, tokenIf);
|
||||
return tokenClnt;
|
||||
}
|
||||
return tokenClnt;
|
||||
}
|
||||
|
||||
void PowerStateTokenClntFreeInstance(struct PowerStateTokenClnt *tokenClnt)
|
||||
{
|
||||
if (tokenClnt != NULL) {
|
||||
OsalMemFree(tokenClnt);
|
||||
}
|
||||
}
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef DEVHOST_SERVICE_IF_H
|
||||
#define DEVHOST_SERVICE_IF_H
|
||||
|
||||
#include "hdf_device_info.h"
|
||||
#include "hdf_object.h"
|
||||
|
||||
struct IDevHostService {
|
||||
struct HdfObject object;
|
||||
int (*AddDevice)(struct IDevHostService *, const struct HdfDeviceInfo *);
|
||||
int (*DelDevice)(struct IDevHostService *, const struct HdfDeviceInfo *);
|
||||
int (*StartService)(struct IDevHostService *);
|
||||
};
|
||||
|
||||
#endif /* DEVHOST_SERVICE_IF_H */
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef DEVICE_TOKEN_IF_H
|
||||
#define DEVICE_TOKEN_IF_H
|
||||
|
||||
#include "hdf_object.h"
|
||||
|
||||
struct IHdfDeviceToken {
|
||||
struct HdfObject object;
|
||||
};
|
||||
|
||||
#endif /* DEVICE_TOKEN_IF_H */
|
||||
Executable
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef DEVMGR_SERVICE_IF_H
|
||||
#define DEVMGR_SERVICE_IF_H
|
||||
|
||||
#include "devhost_service_if.h"
|
||||
#include "device_token_if.h"
|
||||
#include "hdf_object.h"
|
||||
#include "power_state_token_if.h"
|
||||
|
||||
struct IDevmgrService {
|
||||
struct HdfDeviceObject object;
|
||||
int (*AttachDeviceHost)(struct IDevmgrService *, uint16_t, struct IDevHostService *);
|
||||
int (*AttachDevice)(struct IDevmgrService *, const struct HdfDeviceInfo *, struct IHdfDeviceToken *);
|
||||
int (*StartService)(struct IDevmgrService *);
|
||||
void (*AcquireWakeLock)(struct IDevmgrService *, struct IPowerStateToken *);
|
||||
void (*ReleaseWakeLock)(struct IDevmgrService *, struct IPowerStateToken *);
|
||||
};
|
||||
|
||||
#endif /* DEVMGR_SERVICE_IF_H */
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef DEVSVC_MANAGER_IF_H
|
||||
#define DEVSVC_MANAGER_IF_H
|
||||
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_object.h"
|
||||
|
||||
struct IDevSvcManager {
|
||||
struct HdfObject object;
|
||||
int (*AddService)(struct IDevSvcManager *, const char *, struct HdfDeviceObject *);
|
||||
int (*SubscribeService)(struct IDevSvcManager *, const char *, struct SubscriberCallback);
|
||||
int (*UnsubscribeService)(struct IDevSvcManager *, const char *);
|
||||
struct HdfObject *(*GetService)(struct IDevSvcManager *, const char *);
|
||||
struct HdfDeviceObject *(*GetObject)(struct IDevSvcManager *, const char *);
|
||||
void (*RemoveService)(struct IDevSvcManager *, const char *);
|
||||
};
|
||||
|
||||
#endif /* DEVSVC_MANAGER_IF_H */
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef HDF_ATTRIBUTE_MANAGER_H
|
||||
#define HDF_ATTRIBUTE_MANAGER_H
|
||||
|
||||
#include "hdf_slist.h"
|
||||
|
||||
bool HdfAttributeManagerGetHostList(struct HdfSList *hostList);
|
||||
struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *hostName);
|
||||
void ReleaseHcsTree(void);
|
||||
|
||||
#endif /* HDF_ATTRIBUTE_MANAGER_H */
|
||||
Executable
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef HDF_DEVICE_INFO_H
|
||||
#define HDF_DEVICE_INFO_H
|
||||
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_slist.h"
|
||||
|
||||
struct HdfDeviceInfo {
|
||||
struct HdfSListNode node;
|
||||
uint16_t hostId;
|
||||
uint16_t deviceId;
|
||||
uint16_t policy;
|
||||
uint16_t priority;
|
||||
uint16_t preload;
|
||||
uint16_t permission;
|
||||
const char *moduleName;
|
||||
const char *svcName;
|
||||
const char *deviceMatchAttr;
|
||||
};
|
||||
|
||||
struct HdfDeviceInfo *HdfDeviceInfoNewInstance(void);
|
||||
void HdfDeviceInfoFreeInstance(struct HdfDeviceInfo *deviceInfo);
|
||||
void HdfDeviceInfoDelete(struct HdfSListNode *listEntry);
|
||||
|
||||
#endif /* HDF_DEVICE_INFO_H */
|
||||
Executable
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef HDF_IO_SERVICE_H
|
||||
#define HDF_IO_SERVICE_H
|
||||
|
||||
#include "hdf_io_service_if.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define DEV_NODE_PATH "/dev/"
|
||||
#define DEV_MGR_NODE "dev_mgr"
|
||||
#define MAX_MODE_SIZE 0777
|
||||
|
||||
struct HdfIoService *HdfIoServiceObtain(
|
||||
struct HdfObject *object, struct HdfIoDispatcher *dispatcher);
|
||||
struct HdfIoService *HdfIoServiceAdapterObtain(const char* serviceName, mode_t mode);
|
||||
void HdfIoServiceAdapterRecycle(struct HdfIoService *service);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* HDF_IO_SERVICE_H */
|
||||
|
||||
Executable
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef HDF_OBJECT_MANAGER_H
|
||||
#define HDF_OBJECT_MANAGER_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include "hdf_object.h"
|
||||
|
||||
enum {
|
||||
HDF_OBJECT_ID_DEVMGR_SERVICE = 0,
|
||||
HDF_OBJECT_ID_DEVSVC_MANAGER,
|
||||
HDF_OBJECT_ID_DEVHOST_SERVICE,
|
||||
HDF_OBJECT_ID_DRIVER_INSTALLER,
|
||||
HDF_OBJECT_ID_DRIVER_LOADER,
|
||||
HDF_OBJECT_ID_DEVICE,
|
||||
HDF_OBJECT_ID_DEVICE_TOKEN,
|
||||
HDF_OBJECT_ID_DEVICE_SERVICE,
|
||||
HDF_OBJECT_ID_REMOTE_SERVICE,
|
||||
HDF_OBJECT_ID_MAX
|
||||
};
|
||||
|
||||
struct HdfObjectCreator {
|
||||
struct HdfObject *(*Create)(void);
|
||||
void (*Release)(struct HdfObject *);
|
||||
};
|
||||
|
||||
const struct HdfObjectCreator *HdfObjectManagerGetCreators(int objectId);
|
||||
struct HdfObject *HdfObjectManagerGetObject(int ObjectId);
|
||||
void HdfObjectManagerFreeObject(struct HdfObject *object);
|
||||
|
||||
#endif /* HDF_OBJECT_MANAGER_H */
|
||||
Executable
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef DEVSVC_RECORD_H
|
||||
#define DEVSVC_RECORD_H
|
||||
|
||||
#include "hdf_object.h"
|
||||
#include "hdf_slist.h"
|
||||
|
||||
struct DevSvcRecord {
|
||||
struct HdfSListNode entry;
|
||||
uint32_t key;
|
||||
struct HdfDeviceObject *value;
|
||||
};
|
||||
|
||||
struct DevSvcRecord *DevSvcRecordNewInstance(void);
|
||||
void DevSvcRecordFreeInstance(struct DevSvcRecord *inst);
|
||||
void DevSvcRecordDelete(struct HdfSListNode *listEntry);
|
||||
|
||||
#endif /* DEVSVC_RECORD_H */
|
||||
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef POWER_STATE_TOKEN_IF_H
|
||||
#define POWER_STATE_TOKEN_IF_H
|
||||
|
||||
typedef enum {
|
||||
POWER_STATE_IDLE, /* Idle state */
|
||||
POWER_STATE_ACTIVE, /* Activated state */
|
||||
POWER_STATE_INACTIVE, /* Error state */
|
||||
} HdfPowerState;
|
||||
|
||||
struct IPowerStateToken {
|
||||
void (*AcquireWakeLock)(struct IPowerStateToken *);
|
||||
void (*ReleaseWakeLock)(struct IPowerStateToken *);
|
||||
};
|
||||
|
||||
#endif /* POWER_STATE_TOKEN_IF_H */
|
||||
Executable
+75
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "hdf_device_info.h"
|
||||
#include "hdf_log.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
#define HDF_LOG_TAG device_info
|
||||
|
||||
static void HdfDeviceInfoConstruct(struct HdfDeviceInfo *deviceInfo)
|
||||
{
|
||||
deviceInfo->hostId = 0;
|
||||
deviceInfo->deviceId = 0;
|
||||
deviceInfo->policy = SERVICE_POLICY_INVALID;
|
||||
deviceInfo->priority = 0;
|
||||
deviceInfo->preload = DEVICE_PRELOAD_ENABLE;
|
||||
deviceInfo->permission = 0;
|
||||
deviceInfo->svcName = NULL;
|
||||
deviceInfo->moduleName = NULL;
|
||||
deviceInfo->deviceMatchAttr = NULL;
|
||||
}
|
||||
|
||||
struct HdfDeviceInfo *HdfDeviceInfoNewInstance()
|
||||
{
|
||||
struct HdfDeviceInfo *deviceInfo =
|
||||
(struct HdfDeviceInfo*)OsalMemCalloc(sizeof(struct HdfDeviceInfo));
|
||||
if (deviceInfo != NULL) {
|
||||
HdfDeviceInfoConstruct(deviceInfo);
|
||||
return deviceInfo;
|
||||
}
|
||||
HDF_LOGE("Create device deviceInfo failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void HdfDeviceInfoFreeInstance(struct HdfDeviceInfo *deviceInfo)
|
||||
{
|
||||
if (deviceInfo != NULL) {
|
||||
OsalMemFree(deviceInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void HdfDeviceInfoDelete(struct HdfSListNode *listEntry)
|
||||
{
|
||||
struct HdfDeviceInfo *deviceInfo = (struct HdfDeviceInfo *)listEntry;
|
||||
HdfDeviceInfoFreeInstance(deviceInfo);
|
||||
}
|
||||
|
||||
Executable
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "hdf_io_service.h"
|
||||
#include "hdf_vnode_adapter.h"
|
||||
|
||||
struct HdfIoService *HdfIoServiceObtain(
|
||||
struct HdfObject *object, struct HdfIoDispatcher *dispatcher)
|
||||
{
|
||||
struct HdfIoService *service = HdfIoServiceAdapterObtain(NULL, 0);
|
||||
if ((service != NULL) && (service->dispatcher == NULL)) {
|
||||
service->dispatcher = dispatcher;
|
||||
service->target = object;
|
||||
}
|
||||
return service;
|
||||
}
|
||||
|
||||
struct HdfIoService *HdfIoServiceBind(const char *serviceName, mode_t permission)
|
||||
{
|
||||
return HdfIoServiceAdapterObtain(serviceName, permission);
|
||||
}
|
||||
|
||||
void HdfIoServiceRecycle(struct HdfIoService *service)
|
||||
{
|
||||
HdfIoServiceAdapterRecycle(service);
|
||||
}
|
||||
|
||||
Executable
+58
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "hdf_object_manager.h"
|
||||
|
||||
struct HdfObject *HdfObjectManagerGetObject(int objectId)
|
||||
{
|
||||
struct HdfObject *object = NULL;
|
||||
const struct HdfObjectCreator *targetCreator = HdfObjectManagerGetCreators(objectId);
|
||||
if ((targetCreator != NULL) && (targetCreator->Create != NULL)) {
|
||||
object = targetCreator->Create();
|
||||
if (object != NULL) {
|
||||
object->objectId = objectId;
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
void HdfObjectManagerFreeObject(struct HdfObject *object)
|
||||
{
|
||||
const struct HdfObjectCreator *targetCreator = NULL;
|
||||
if (object == NULL) {
|
||||
return;
|
||||
}
|
||||
targetCreator = HdfObjectManagerGetCreators(object->objectId);
|
||||
if ((targetCreator == NULL) || (targetCreator->Release == NULL)) {
|
||||
return;
|
||||
}
|
||||
targetCreator->Release(object);
|
||||
}
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "hdf_service_record.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
struct DevSvcRecord *DevSvcRecordNewInstance(void)
|
||||
{
|
||||
return (struct DevSvcRecord *)OsalMemCalloc(sizeof(struct DevSvcRecord));
|
||||
}
|
||||
|
||||
void DevSvcRecordFreeInstance(struct DevSvcRecord *inst)
|
||||
{
|
||||
if (inst != NULL) {
|
||||
OsalMemFree(inst);
|
||||
}
|
||||
}
|
||||
|
||||
void DevSvcRecordDelete(struct HdfSListNode *listEntry)
|
||||
{
|
||||
if (listEntry != NULL) {
|
||||
OsalMemFree(listEntry);
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+470
@@ -0,0 +1,470 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup DriverConfig
|
||||
* @{
|
||||
*
|
||||
* @brief Defines an API for HDF driver developers to read driver configuration information.
|
||||
*
|
||||
* During version compilation of the device resource source file defined by developers, the compilation tool
|
||||
* (for example, the compilation tool of the HCS file is hc-gen) generates bytecodes. When the HDF starts,
|
||||
* it transfers the bytecode memory to the <b>DriverConfig</b> module. The <b>DriverConfig</b> module converts
|
||||
* the bytecodes into a configuration tree and provides an API for developers to query the tree.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file device_resource_if.h
|
||||
*
|
||||
* @brief Declares the API for querying the configuration tree.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef DEVICE_RESOURCE_IF_H
|
||||
#define DEVICE_RESOURCE_IF_H
|
||||
|
||||
#include "hdf_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Enumerates configuration file types.
|
||||
*/
|
||||
typedef enum {
|
||||
HDF_CONFIG_SOURCE = 0, /**< HDF configuration file */
|
||||
INVALID, /**< Invalid configuration file type */
|
||||
} DeviceResourceType;
|
||||
|
||||
/**
|
||||
* @brief Defines the attributes of a tree node in the configuration tree.
|
||||
*
|
||||
* The tree node attributes are saved in a linked list. The information about each node in the linked list contains
|
||||
* the attribute name, attribute value, and pointer that points to the next attribute.
|
||||
*/
|
||||
struct DeviceResourceAttr {
|
||||
const char *name; /**< Pointer to the attribute name */
|
||||
const char *value; /**< Pointer to the attribute value */
|
||||
struct DeviceResourceAttr *next; /**< Pointer to the next attribute of the node in the configuration tree. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines a tree node in the configuration tree.
|
||||
*
|
||||
* The tree node information includes the node name, unique node ID, node attributes, parent node, child nodes,
|
||||
* and sibling nodes.
|
||||
*/
|
||||
struct DeviceResourceNode {
|
||||
const char *name; /**< Pointer to the node name */
|
||||
uint32_t hashValue; /**< Unique ID of a node */
|
||||
struct DeviceResourceAttr *attrData; /**< Pointer to the node attributes */
|
||||
struct DeviceResourceNode *parent; /**< Pointer to the parent node */
|
||||
struct DeviceResourceNode *child; /**< Pointer to a child node */
|
||||
struct DeviceResourceNode *sibling; /**< Pointer to a sibling node */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Provides functions for obtaining information about the device resource configuration tree.
|
||||
*
|
||||
* This structure provides functions for obtaining information about the device resource configuration tree,
|
||||
* including the root node, the <b>unit</b> attribute data, and the <b>String</b> attribute data.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
struct DeviceResourceIface {
|
||||
/**
|
||||
* @brief Obtains the root node of the configuration tree.
|
||||
*
|
||||
* When the driver framework is started, a configuration tree is created. You can use this function to obtain
|
||||
* the root node of the configuration tree.
|
||||
*
|
||||
* @return Returns the root node of the configuration tree if the operation is successful;
|
||||
* returns <b>NULL</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
const struct DeviceResourceNode *(*GetRootNode)(void);
|
||||
/**
|
||||
* @brief Obtains the value of a <b>BOOL</b> attribute of a configuration tree node.
|
||||
*
|
||||
* @param node Indicates the pointer to the configuration tree node.
|
||||
* @param attrName Indicates the pointer to the name of the attribute.
|
||||
*
|
||||
* @return Returns the value of the <b>BOOL</b> attribute if the operation is successful;
|
||||
* returns <b>false</b> if <b>node</b> and <b>attrName</b> are null pointers.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
bool (*GetBool)(const struct DeviceResourceNode *node, const char *attrName);
|
||||
/**
|
||||
* @brief Obtains the value of a <b>Uint8</b> attribute of a configuration tree node.
|
||||
*
|
||||
* @param node Indicates the pointer to the configuration tree node.
|
||||
* @param attrName Indicates the pointer to the name of the attribute.
|
||||
* @param value Indicates the pointer to the memory that stores the obtained data. The memory is applied
|
||||
* by the user.
|
||||
* @param def Indicates the value to fill into the memory pointed by <b>value</b> if the operation fails.
|
||||
*
|
||||
* @return Returns <b>0</b> if the attribute value is obtained successfully; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t (*GetUint8)(const struct DeviceResourceNode *node, const char *attrName, uint8_t *value, uint8_t def);
|
||||
/**
|
||||
* @brief Obtains the value of a <b>Unit8</b> array attribute numbered <b>index</b> of a configuration tree node.
|
||||
*
|
||||
* @param node Indicates the pointer to the configuration tree node.
|
||||
* @param attrName Indicates the pointer to the name of the array attribute.
|
||||
* @param index Indicates the number of the index (counting from 0) where the value is to obtain.
|
||||
* @param value Indicates the pointer to the memory that stores the obtained data. The memory is applied
|
||||
* by the user.
|
||||
* @param def Indicates the value to fill into the memory pointed by <b>value</b> if the operation fails.
|
||||
*
|
||||
* @return Returns <b>0</b> if the array attribute value is obtained successfully; returns a negative value
|
||||
* otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t (*GetUint8ArrayElem)(const struct DeviceResourceNode *node, const char *attrName, uint32_t index,
|
||||
uint8_t *value, uint8_t def);
|
||||
/**
|
||||
* @brief Obtains the values of a <b>Uint8</b> array attribute of a configuration tree node.
|
||||
*
|
||||
* @param node Indicates the pointer to the configuration tree node.
|
||||
* @param attrName Indicates the pointer to the name of the array attribute.
|
||||
* @param value Indicates the pointer to the array that stores the obtained data. The memory of the array is applied
|
||||
* by the user.
|
||||
* @param len Indicates the length of the array.
|
||||
* @param def Indicates the value to fill into <b>value</b> if the operation fails. If the obtained attribute value
|
||||
* contains 16-bit, 32-bit, or 64-bit data, the element corresponding to the 16-bit, 32-bit, or 64-bit data in the
|
||||
* array is filled using the value of <b>def</b>, and the other elements are filled with the actual value obtained.
|
||||
* If the failure is caused by other exceptions, the first element in the array is filled using the value of
|
||||
* <b>def</b>.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t (*GetUint8Array)(const struct DeviceResourceNode *node, const char *attrName, uint8_t *value, uint32_t len,
|
||||
uint8_t def);
|
||||
/**
|
||||
* @brief Obtains the value of a <b>Uint16</b> attribute of a configuration tree node.
|
||||
*
|
||||
* @param node Indicates the pointer to the configuration tree node.
|
||||
* @param attrName Indicates the pointer to the name of the attribute.
|
||||
* @param value Indicates the pointer to the memory that stores the obtained data. The memory is applied
|
||||
* by the user.
|
||||
* @param def Indicates the value to fill into the memory pointed by <b>value</b> if the operation fails.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t (*GetUint16)(const struct DeviceResourceNode *node, const char *attrName, uint16_t *value, uint16_t def);
|
||||
/**
|
||||
* @brief Obtains the value of a <b>Uint16</b> array attribute numbered <b>index</b> of a configuration tree node.
|
||||
*
|
||||
* @param node Indicates the pointer to the configuration tree node.
|
||||
* @param attrName Indicates the pointer to the name of the array attribute.
|
||||
* @param index Indicates the number of the index (counting from 0) where the value is to obtain.
|
||||
* @param value Indicates the pointer to the memory that stores the obtained data. The memory is applied
|
||||
* by the user.
|
||||
* @param def Indicates the value to fill into the memory pointed by <b>value</b> if the operation fails.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t (*GetUint16ArrayElem)(const struct DeviceResourceNode *node, const char *attrName, uint32_t index,
|
||||
uint16_t *value, uint16_t def);
|
||||
/**
|
||||
* @brief Obtains the values of a <b>Uint16</b> array attribute of a configuration tree node.
|
||||
*
|
||||
* @param node Indicates the pointer to the configuration tree node.
|
||||
* @param attrName Indicates the pointer to the name of the array attribute.
|
||||
* @param value Indicates the pointer to the array that stores the obtained data. The memory of the array is applied
|
||||
* by the user.
|
||||
* @param len Indicates the length of the array.
|
||||
* @param def Indicates the value to fill into <b>value</b> if the operation fails. If the obtained attribute value
|
||||
* contains 32-bit or 64-bit data, the element corresponding to the 32-bit or 64-bit data in the array is filled
|
||||
* using the value of <b>def</b>, and the other elements are filled with the actual value obtained. If the failure
|
||||
* is caused by other exceptions, the first element in the array is filled using the value of <b>def</b>.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t (*GetUint16Array)(const struct DeviceResourceNode *node, const char *attrName, uint16_t *value,
|
||||
uint32_t len, uint16_t def);
|
||||
/**
|
||||
* @brief Obtains the value of a <b>Uint32</b> attribute of a configuration tree node.
|
||||
*
|
||||
* @param node Indicates the pointer to the configuration tree node.
|
||||
* @param attrName Indicates the pointer to the name of the attribute.
|
||||
* @param value Indicates the pointer to the memory that stores the obtained data. The memory is applied
|
||||
* by the user.
|
||||
* @param def Indicates the value to fill into the memory pointed by <b>value</b> if the operation fails.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t (*GetUint32)(const struct DeviceResourceNode *node, const char *attrName, uint32_t *value, uint32_t def);
|
||||
/**
|
||||
* @brief Obtains the value of a <b>Uint32</b> array attribute numbered <b>index</b> of a configuration tree node.
|
||||
*
|
||||
* @param node Indicates the pointer to the configuration tree node.
|
||||
* @param attrName Indicates the pointer to the name of the array attribute.
|
||||
* @param index Indicates the number of the index (counting from 0) where the value is to obtain.
|
||||
* @param value Indicates the pointer to the memory that stores the obtained data. The memory is applied
|
||||
* by the user.
|
||||
* @param def Indicates the value to fill into the memory pointed by <b>value</b> if the operation fails.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t (*GetUint32ArrayElem)(const struct DeviceResourceNode *node, const char *attrName, uint32_t index,
|
||||
uint32_t *value, uint32_t def);
|
||||
/**
|
||||
* @brief Obtains the values of a <b>Uint32</b> array attribute of a configuration tree node.
|
||||
*
|
||||
* @param node Indicates the pointer to the configuration tree node.
|
||||
* @param attrName Indicates the pointer to the name of the array attribute.
|
||||
* @param value Indicates the pointer to an array that stores the obtained data.
|
||||
* @param len Indicates the pointer to the array that stores the obtained data. The memory of the array is applied
|
||||
* by the user.
|
||||
* @param def Indicates the value to fill into <b>value</b> if the operation fails. If the obtained attribute value
|
||||
* contains 64-bit data, the element corresponding to the 64-bit data in the array is filled using the value of
|
||||
* <b>def</b>, and the other elements are filled with the actual value obtained. If the failure is caused by other
|
||||
* exceptions, the first element in the array is filled using the value of <b>def</b>.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t (*GetUint32Array)(const struct DeviceResourceNode *node, const char *attrName, uint32_t *value,
|
||||
uint32_t len, uint32_t def);
|
||||
/**
|
||||
* @brief Obtains the value of a <b>Uint64</b> attribute of a configuration tree node.
|
||||
*
|
||||
* @param node Indicates the pointer to the configuration tree node.
|
||||
* @param attrName Indicates the pointer to the name of the attribute.
|
||||
* @param value Indicates the pointer to the memory that stores the obtained data. The memory is applied
|
||||
* by the user.
|
||||
* @param def Indicates the value to fill into the memory pointed by <b>value</b> if the operation fails.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t (*GetUint64)(const struct DeviceResourceNode *node, const char *attrName, uint64_t *value, uint64_t def);
|
||||
/**
|
||||
* @brief Obtains the value of a <b>Uint64</b> array attribute numbered <b>index</b> of a configuration tree node.
|
||||
*
|
||||
* @param node Indicates the pointer to the configuration tree node.
|
||||
* @param attrName Indicates the pointer to the name of the array attribute.
|
||||
* @param index Indicates the number of the index (counting from 0) where the value is to obtain.
|
||||
* @param value Indicates the pointer to the memory that stores the obtained data. The memory is applied
|
||||
* by the user.
|
||||
* @param def Indicates the value to fill into the memory pointed by <b>value</b> if the operation fails.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t (*GetUint64ArrayElem)(const struct DeviceResourceNode *node, const char *attrName, uint32_t index,
|
||||
uint64_t *value, uint64_t def);
|
||||
/**
|
||||
* @brief Obtains the values of a <b>Uint64</b> array attribute of a configuration tree node.
|
||||
*
|
||||
* @param node Indicates the pointer to the configuration tree node.
|
||||
* @param attrName Indicates the pointer to the name of the array attribute.
|
||||
* @param value Indicates the pointer to the array that stores the obtained data. The memory of the array is applied
|
||||
* by the user.
|
||||
* @param len Indicates the length of the array.
|
||||
* @param def Indicates the value to fill into the first element in the <b>value</b> array if the operation fails.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t (*GetUint64Array)(const struct DeviceResourceNode *node, const char *attrName, uint64_t *value,
|
||||
uint32_t len, uint64_t def);
|
||||
/**
|
||||
* @brief Obtains the value of a <b>String</b> attribute of a configuration tree node.
|
||||
*
|
||||
* @param node Indicates the pointer to the configuration tree node.
|
||||
* @param attrName Indicates the pointer to the name of the attribute.
|
||||
* @param value Indicates the double pointer to the memory where the obtained data is stored. The string memory is
|
||||
* provided by the function implementer. Users only need to transfer the double pointer. The memory cannot be
|
||||
* released after being used.
|
||||
* @param def Indicates the value to be passed to <b>value</b> if the operation fails.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t (*GetString)(const struct DeviceResourceNode *node, const char *attrName, const char **value,
|
||||
const char *def);
|
||||
/**
|
||||
* @brief Obtains the value of a <b>String</b> array attribute numbered <b>index</b> of a configuration tree node.
|
||||
*
|
||||
* @param node Indicates the pointer to the configuration tree node.
|
||||
* @param attrName Indicates the pointer to the name of the array attribute.
|
||||
* @param index Indicates the number of the index (counting from 0) where the value is to obtain.
|
||||
* @param value Indicates the double pointer to the memory where the obtained data is stored. The string memory is
|
||||
* provided by the function implementer. Users only need to transfer the double pointer. The memory cannot be
|
||||
* released after being used.
|
||||
* @param def def Indicates the value to be passed to <b>value</b> if the operation fails.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t (*GetStringArrayElem)(const struct DeviceResourceNode *node, const char *attrName, uint32_t index,
|
||||
const char **value, const char *def);
|
||||
/**
|
||||
* @brief Obtains the number of values for an array attribute of a configuration tree node.
|
||||
*
|
||||
* @param node Indicates the pointer to the configuration tree node.
|
||||
* @param attrName Indicates the pointer to the name of the array attribute.
|
||||
*
|
||||
* @return Returns the number of values for an array attribute if the operation is successful;
|
||||
* return a negative value otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t (*GetElemNum)(const struct DeviceResourceNode *node, const char *attrName);
|
||||
/**
|
||||
* @brief Obtains a specified child node of the current tree node based on the value of a specific reserved
|
||||
* attribute (for example, the reserved attribute of the HCS is <b>match_attr</b>).
|
||||
*
|
||||
* There is a specific reserved attribute in the syntax of the device resource configuration source file.
|
||||
* If this attribute is set for a tree node, you can obtain the node based on the attribute value.
|
||||
* Users can set the attribute value based on the usage of their own nodes, but they must ensure that the attribute
|
||||
* values are unique.
|
||||
*
|
||||
* @param node Indicates the pointer to the node for whom a child node is to be obtained. The node can be the child
|
||||
* node's parent node or grandparent node.
|
||||
* @param attrValue Indicates the pointer to the value of the reserved attribute configured for the child node.
|
||||
*
|
||||
* @return Returns the target node if the operation is successful; returns <b>NULL</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
const struct DeviceResourceNode *(*GetNodeByMatchAttr)(const struct DeviceResourceNode *node,
|
||||
const char *attrValue);
|
||||
/**
|
||||
* @brief Obtains the child node with a specified node name from a parent node.
|
||||
*
|
||||
* @param node Indicates the pointer to the parent node.
|
||||
* @param nodeName Indicates the pointer to the name of the child node to obtain.
|
||||
*
|
||||
* @return Returns the child nodes if the operation is successful; returns <b>NULL</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
const struct DeviceResourceNode *(*GetChildNode)(const struct DeviceResourceNode *node, const char *nodeName);
|
||||
/**
|
||||
* @brief Obtains the node that is specified by a node-type attribute of a configuration tree node.
|
||||
*
|
||||
* If the attribute value is a configuration tree node, the path of the node is converted to a globally unique
|
||||
* <b>hashValue</b> when the device resource source file is compiled (for example, the compilation tool of the HCS
|
||||
* source file is hc-gen). For details about the <b>hashValue</b>, see {@link struct DeviceResourceNode}.
|
||||
* When you obtain a tree node using the node-type attribute, you obtain the <b>hashValue</b> through the node-type
|
||||
* attribute first, and then traverse the tree to obtain the tree node corresponding to the <b>hashValue</b>.
|
||||
*
|
||||
* @param node Indicates the pointer to the tree node whose attribute is to obtain.
|
||||
* @param attrName Indicates the pointer to the name of attribute whose value is a node path.
|
||||
* @return Returns the target node if the operation is successful; returns <b>NULL</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
const struct DeviceResourceNode *(*GetNodeByRefAttr)(const struct DeviceResourceNode *node, const char *attrName);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Obtains the device resource interface handle of the corresponding configuration tree type.
|
||||
*
|
||||
* You can use the obtained handle to use the device resource interface.
|
||||
*
|
||||
* @param type Indicates the type of the device resource interface handle to obtain.
|
||||
*
|
||||
* @return Returns the device resource interface handle if the operation is successful; returns <b>NULL</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
struct DeviceResourceIface *DeviceResourceGetIfaceInstance(DeviceResourceType type);
|
||||
|
||||
/**
|
||||
* @brief Traverses the attributes of the current configuration tree node.
|
||||
*
|
||||
* This operation is a <b>for</b> loop in essence.
|
||||
*
|
||||
* @param node Indicates the configuration tree node to traverse.
|
||||
* @param attr Indicates the traversed attributes.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define DEV_RES_NODE_FOR_EACH_ATTR(node, attr) \
|
||||
for ((attr) = (node)->attrData; (attr) != NULL; (attr) = (attr)->next)
|
||||
|
||||
/**
|
||||
* @brief Traverses the child nodes of the current configuration tree node.
|
||||
*
|
||||
* This operation is a <b>for</b> loop in essence.
|
||||
*
|
||||
* @param node Indicates the configuration tree node to traverse.
|
||||
* @param childNode Indicates the traversed child nodes.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define DEV_RES_NODE_FOR_EACH_CHILD_NODE(node, childNode) \
|
||||
for ((childNode) = (node)->child; (childNode) != NULL; (childNode) = (childNode)->sibling)
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif // DEVICE_RESOURCE_IF_H
|
||||
/** @} */
|
||||
Executable
+343
@@ -0,0 +1,343 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup Core
|
||||
* @{
|
||||
*
|
||||
* @brief Provides OpenHarmony Driver Foundation (HDF) APIs.
|
||||
*
|
||||
* The HDF implements driver framework capabilities such as driver loading, service management,
|
||||
* and driver message model. You can develop drivers based on the HDF.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file hdf_device_desc.h
|
||||
*
|
||||
* @brief Declares functions related to driver loading, service obtaining, and power management.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
#ifndef HDF_DEVICE_DESC_H
|
||||
#define HDF_DEVICE_DESC_H
|
||||
|
||||
#include "hdf_device_section.h"
|
||||
#include "hdf_object.h"
|
||||
#include "hdf_sbuf.h"
|
||||
|
||||
/**
|
||||
* @brief The maximum priority for loading the host and device.
|
||||
*/
|
||||
#define MAX_PRIORITY_NUM 200
|
||||
|
||||
/**
|
||||
* @brief Enumerates policies for releasing driver services developed based on the HDF.
|
||||
*
|
||||
* If a driver is developed based on the HDF and uses the service management feature of the HDF, you need to
|
||||
* configure the policy for releasing services to external systems.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
typedef enum {
|
||||
/** The driver does not provide services externally. */
|
||||
SERVICE_POLICY_NONE = 0,
|
||||
/** The driver provides services for kernel-level applications. */
|
||||
SERVICE_POLICY_PUBLIC,
|
||||
/** The driver provides services for both kernel- and user-level applications. */
|
||||
SERVICE_POLICY_CAPACITY,
|
||||
/** Driver services are not released externally but can be subscribed to. */
|
||||
SERVICE_POLICY_FRIENDLY,
|
||||
/** Driver services are only internally available.
|
||||
They are not released externally and cannot be subscribed to by external users. */
|
||||
SERVICE_POLICY_PRIVATE,
|
||||
/** The service policy is incorrect. */
|
||||
SERVICE_POLICY_INVALID
|
||||
} ServicePolicy;
|
||||
|
||||
/**
|
||||
* @brief Enumerates driver loading policies.
|
||||
*
|
||||
* If a driver developed based on the HDF needs to use the on-demand loading mechanism in the HDF, the <b>PRELOAD</b>
|
||||
* field must be correctly set in the driver configuration information to control the driver loading mode.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
typedef enum {
|
||||
DEVICE_PRELOAD_ENABLE = 0, /**< The driver is loaded during system startup by default. */
|
||||
DEVICE_PRELOAD_DISABLE, /**< The driver is not loaded during system startup by default. */
|
||||
DEVICE_PRELOAD_INVALID /**< The loading policy is incorrect. */
|
||||
} DevicePreload;
|
||||
|
||||
/**
|
||||
* @brief Defines the device object.
|
||||
*
|
||||
* This structure is a device object defined by the HDF and is used to store private data and interface information
|
||||
* of a device.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct HdfDeviceObject {
|
||||
/** Pointer to the service interface object, which is registered with the HDF by the driver */
|
||||
struct IDeviceIoService *service;
|
||||
/** Pointer to the private data of the device, which is read by the HDF from the configuration file and
|
||||
transmitted to the driver. */
|
||||
const struct DeviceResourceNode *property;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines the client object structure of the I/O service.
|
||||
*
|
||||
* This structure describes the invoker information of the I/O servcie.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct HdfDeviceIoClient {
|
||||
/** Device object corresponding to the client object */
|
||||
struct HdfDeviceObject *device;
|
||||
/** Private data of the client object. The driver can use <b>priv</b> to bind the internal data with the client. */
|
||||
void *priv;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines the driver service.
|
||||
*
|
||||
* When a driver releases services to user-level applications, the service interface must inherit this structure
|
||||
* and implements the <b>Dispatch</b> function in the structure.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct IDeviceIoService {
|
||||
/** Driver service object ID */
|
||||
struct HdfObject object;
|
||||
/**
|
||||
* @brief Called when the driver service is enabled by a user-level application.
|
||||
*
|
||||
* @param client Indicates the pointer to the client object of the service.
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t (*Open)(struct HdfDeviceIoClient *client);
|
||||
/**
|
||||
* @brief Called when the driver service is invoked by a user-level application.
|
||||
*
|
||||
* @param client Indicates the pointer to the client object of the service.
|
||||
* @param cmdId Indicates the command word of the service interface.
|
||||
* @param data Indicates the pointer to the data passed by the invoker.
|
||||
* @param reply Indicates the pointer to the data that needs to be returned to the invoker.
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t (*Dispatch)(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply);
|
||||
/**
|
||||
* @brief Called when the driver service is released by a user-level application.
|
||||
*
|
||||
* @param client Indicates the pointer to the client object of the service.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void (*Release)(struct HdfDeviceIoClient *client);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Called when the driver subscribes to other driver services.
|
||||
*
|
||||
* The callback is used in the service subscription mechanism. After the driver is registered with the HDF, the HDF
|
||||
* proactively invokes the callback after the subscribed-to driver is loaded.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct SubscriberCallback {
|
||||
/** Driver object of the subscriber */
|
||||
struct HdfDeviceObject *deviceObject;
|
||||
/**
|
||||
* @brief Called by the HDF when the subscribed-to driver service is loaded.
|
||||
*
|
||||
* @param deviceObject Indicates the pointer to the variable of the {@link HdfDeviceObject} type. This variable
|
||||
* is generated by the HDF and passed to the driver.
|
||||
* @param service Indicates the pointer to the service object.
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t (*OnServiceConnected)(struct HdfDeviceObject *deviceObject, const struct HdfObject *service);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines the power management functions provided by the HDF for the driver.
|
||||
*
|
||||
* To use the power management mechanism provided by the HDF, implement operations of <b>IPowerEventListener</b> and
|
||||
* invoke {@linkHdfDeviceRegisterPowerListener} to register the operations with the HDF.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct IPowerEventListener {
|
||||
/** Wakes up the driver device. The driver developer implements the operation. */
|
||||
void (*Resume)(struct HdfDeviceObject *deviceObject);
|
||||
/** Hibernates the driver device. The driver developer implements the operation. */
|
||||
void (*Suspend)(struct HdfDeviceObject *deviceObject);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines the entry structure of the driver in the HDF.
|
||||
*
|
||||
* This structure must be used as the entry for the driver to use the HDF mechanism.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct HdfDriverEntry {
|
||||
/** Driver version */
|
||||
int32_t moduleVersion;
|
||||
/** Driver module name, which is used to match the driver information in the configuration file. */
|
||||
const char *moduleName;
|
||||
/**
|
||||
* @brief Binds the external service interface of a driver to the HDF. This function is implemented by the driver
|
||||
* developer and called by the HDF.
|
||||
*
|
||||
* @param deviceObject Indicates the pointer to the variable of the {@link HdfDeviceObject} type. This variable
|
||||
* is generated by the HDF and passed to the driver. Then, the service object of the driver is bound to the
|
||||
* <b>service</b> parameter of <b>deviceObject</b>.
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t (*Bind)(struct HdfDeviceObject *deviceObject);
|
||||
/**
|
||||
* @brief Initializes the driver. This function is implemented by the driver developer and called by the HDF.
|
||||
*
|
||||
* @param deviceObject Indicates the pointer to the variable of the {@link HdfDeviceObject} type. It is the same
|
||||
* as the parameter of {@link Bind}.
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t (*Init)(struct HdfDeviceObject *deviceObject);
|
||||
/**
|
||||
* @brief Releases driver resources. This function is implemented by the driver developer. When an exception
|
||||
* occurs during driver loading or the driver is uninstalled, the HDF calls this function to release the
|
||||
* driver resources.
|
||||
*
|
||||
* @param deviceObject Indicates the pointer to the variable of the {@link HdfDeviceObject} type. It is the same
|
||||
* as the parameter of {@link Bind}.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void (*Release)(struct HdfDeviceObject *deviceObject);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Registers the driver with the HDF.
|
||||
*
|
||||
* For a driver developed based on the HDF, {@link HDF_INIT} must be used to register an entry with the HDF, and the
|
||||
* registered object must be of the {@link HdfDriverEntry} type.
|
||||
*
|
||||
* @param module Indicates the global variable of the {@link HdfDriverEntry} type
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define HDF_INIT(module) HDF_DRIVER_INIT(module)
|
||||
|
||||
/**
|
||||
* @brief Obtains the driver service object based on a driver service name.
|
||||
*
|
||||
* @param serviceName Indicates the pointer to the released driver service name.
|
||||
*
|
||||
* @return Returns the driver service object if the operation is successful; returns <b>NULL</b> otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
const struct HdfObject *DevSvcManagerClntGetService(const char *svcName);
|
||||
|
||||
/**
|
||||
* @brief Obtains the service name of a driver.
|
||||
*
|
||||
* If a driver does not save its service name, it can use this function to obtain the service name. \n
|
||||
*
|
||||
* @param deviceObject Indicates the pointer to the driver device object.
|
||||
*
|
||||
* @return Returns the service name if the operation is successful; returns <b>NULL</b> otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
const char *HdfDeviceGetServiceName(const struct HdfDeviceObject *deviceObject);
|
||||
|
||||
/**
|
||||
* @brief Subscribes to a driver service.
|
||||
*
|
||||
* If the driver loading time is not perceived, this function can be used to subscribe to the driver service. (The
|
||||
* driver service and the subscriber must be on the same host.) After the subscribed-to driver service is loaded by the
|
||||
* HDF, the framework proactively releases the service interface to the subscriber. \n
|
||||
*
|
||||
* @param deviceObject Indicates the pointer to the driver device object of the subscriber.
|
||||
* @param serviceName Indicates the pointer to the driver service name.
|
||||
* @param callback Indicates the callback invoked by the HDF after the subscribed-to driver service is loaded.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t HdfDeviceSubscribeService(
|
||||
struct HdfDeviceObject *deviceObject, const char *serviceName, struct SubscriberCallback callback);
|
||||
|
||||
/**
|
||||
* @brief Sends event messages.
|
||||
*
|
||||
* When the driver service invokes this function to send a message, all user-level applications that have registered
|
||||
* listeners through {@link HdfDeviceRegisterEventListener} will receive the message.
|
||||
*
|
||||
* @param deviceObject Indicates the pointer to the driver device object.
|
||||
* @param id Indicates the ID of the message sending event.
|
||||
* @param data Indicates the pointer to the message content sent by the driver.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t HdfDeviceSendEvent(const struct HdfDeviceObject *deviceObject, uint32_t id, const struct HdfSBuf *data);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sends an event message to a specified client object.
|
||||
*
|
||||
* When the driver service invokes this function to send a message, the user-level applications that have registered
|
||||
* listeners through {@link HdfDeviceRegisterEventListener} and correspond to this client object will receive
|
||||
* the message.
|
||||
*
|
||||
* @param client Indicates the pointer to the client object of the driver service.
|
||||
* @param id Indicates the ID of the message sending event.
|
||||
* @param data Indicates the pointer to the message content sent by the driver.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
|
||||
* @since 1.0 */
|
||||
int32_t HdfDeviceSendEventToClient(const struct HdfDeviceIoClient *client, uint32_t id, const struct HdfSBuf *data);
|
||||
|
||||
#endif /* HDF_DEVICE_DESC_H */
|
||||
/** @} */
|
||||
Executable
+169
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
/**
|
||||
* @addtogroup Core
|
||||
* @{
|
||||
*
|
||||
* @brief Provides OpenHarmony Driver Foundation (HDF) APIs.
|
||||
*
|
||||
* The HDF implements driver framework capabilities such as driver loading, service management,
|
||||
* and driver message model. You can develop drivers based on the HDF.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file hdf_io_service_if.h
|
||||
*
|
||||
* @brief Declares the structures defining driver service objects and event listeners, as well as the functions for
|
||||
* obtaining a driver service object, dispatching a driver service call, and registering or unregistering an
|
||||
* event listener.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#ifndef HDF_IO_SERVICE_IF_H
|
||||
#define HDF_IO_SERVICE_IF_H
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include "hdf_dlist.h"
|
||||
#include "hdf_object.h"
|
||||
#include "hdf_sbuf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Called when a driver event occurs.
|
||||
*
|
||||
* You can implement this function and bind it to the custom {@link HdfDevEventlistener} object. \n
|
||||
*
|
||||
* @param priv Indicates the pointer to the private data bound to this listener.
|
||||
* @param id Indicates the serial number of the driver event occurred.
|
||||
* @param data Indicates the pointer to the content data of the driver event.
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
typedef int (*OnEventReceived)(void *priv, uint32_t id, struct HdfSBuf *data);
|
||||
|
||||
/**
|
||||
* @brief Defines a driver event listener object.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct HdfDevEventlistener {
|
||||
/** Callback invoked when the monitored device reports an event */
|
||||
OnEventReceived callBack;
|
||||
/** Intrusive list node used by the HDF to manage listeners. You can ignore this node. */
|
||||
struct DListHead listNode;
|
||||
/** Private data of the listener, which is passed as the first input parameter in <b>callback</b> */
|
||||
void *priv;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines a driver service call dispatcher.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct HdfIoDispatcher {
|
||||
/** Dispatches a driver service call. <b>service</b> indicates the pointer to the driver service object, <b>id</b>
|
||||
indicates the command word of the function, <b>data</b> indicates the pointer to the data you want to pass to
|
||||
the driver, and <b>reply</b> indicates the pointer to the data returned by the driver. */
|
||||
int (*Dispatch)(struct HdfObject *service, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines a driver service object.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct HdfIoService {
|
||||
/** Base class object */
|
||||
struct HdfObject object;
|
||||
/** Pointer to the bound service entity, which is used for framework management. You can ignore it. */
|
||||
struct HdfObject *target;
|
||||
/** Service call dispatcher */
|
||||
struct HdfIoDispatcher *dispatcher;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Obtains a driver service object.
|
||||
*
|
||||
* @param serviceName Indicates the pointer to the name of the service to obtain.
|
||||
* @param permission Indicates the permission to create device nodes. The default value <b>0</b> can be used
|
||||
* when this function is called from user space.
|
||||
* @return Returns the pointer to the driver service object if the operation is successful;
|
||||
* returns <b>NULL</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct HdfIoService *HdfIoServiceBind(const char *serviceName, mode_t permission);
|
||||
|
||||
/**
|
||||
* @brief Destroys a specified driver service object to release resources if it is no longer required.
|
||||
*
|
||||
* @param service Indicates the pointer to the driver service object to destroy.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void HdfIoServiceRecycle(struct HdfIoService *service);
|
||||
|
||||
/**
|
||||
* @brief Registers a custom {@link HdfDevEventlistener} for listening for events reported
|
||||
* by a specified driver service object.
|
||||
*
|
||||
* @param target Indicates the pointer to the driver service object to listen, which is obtained through
|
||||
* the {@link HdfIoServiceBind} function.
|
||||
* @param listener Indicates the pointer to the listener to register.
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int HdfDeviceRegisterEventListener(struct HdfIoService *target, struct HdfDevEventlistener *listener);
|
||||
|
||||
/**
|
||||
* @brief Unregisters a previously registered {@link HdfDevEventlistener} to release resources
|
||||
* if it is no longer required.
|
||||
*
|
||||
* @param target Indicates the pointer to the driver service object that has been listened.
|
||||
* @param listener Indicates the listener object registered by {@link HdfDeviceRegisterEventListener}.
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int HdfDeviceUnregisterEventListener(struct HdfIoService *target, struct HdfDevEventlistener *listener);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* HDF_IO_SERVICE_IF_H */
|
||||
/** @} */
|
||||
Executable
+67
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup Core
|
||||
* @{
|
||||
*
|
||||
* @brief Provides OpenHarmony Driver Foundation (HDF) APIs.
|
||||
*
|
||||
* The HDF implements driver framework capabilities such as driver loading, service management,
|
||||
* and driver message model. You can develop drivers based on the HDF.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file hdf_object.h
|
||||
*
|
||||
* @brief Declares the base object provided by the HDF for the driver.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
#ifndef HDF_OBJECT_H
|
||||
#define HDF_OBJECT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief Describes base class objects defined by the HDF.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct HdfObject {
|
||||
int32_t objectId; /**< Base object ID */
|
||||
};
|
||||
|
||||
#endif /* HDF_OBJECT_H */
|
||||
/** @} */
|
||||
Executable
+466
@@ -0,0 +1,466 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup WLAN
|
||||
* @{
|
||||
*
|
||||
* @brief Defines a WLAN module that supports cross-OS migration, component adaptation, and modular assembly and
|
||||
* compilation. Driver developers of WLAN vendors can adapt their driver code based on the unified APIs provided
|
||||
* by the WLAN module.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file hdf_netbuf.h
|
||||
*
|
||||
* @brief Declares network data buffers and provides APIs for operating buffer queues.
|
||||
*
|
||||
* This file describes the following network data operations for network device driver development: \n
|
||||
*
|
||||
* Applying for, releasing, and moving a network data buffer
|
||||
* Initializing a network data buffer queue, placing a network data buffer to a queue, and removing a network data
|
||||
* buffer from a queue
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef HDF_NETBUF_H
|
||||
#define HDF_NETBUF_H
|
||||
|
||||
#include "los_spinlock.h"
|
||||
#include "hdf_dlist.h"
|
||||
#include "lwip/pbuf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Enumerates the segments of a network data buffer.
|
||||
*
|
||||
* The entire network data buffer is divided into three segments: a header, data, and a tail.
|
||||
* The header and tail are used to extend both ends of the data segment.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
enum {
|
||||
E_HEAD_BUF, /**< Header buffer segment */
|
||||
E_DATA_BUF, /**< Data segment */
|
||||
E_TAIL_BUF, /**< Tail buffer segment */
|
||||
MAX_BUF_NUM /**< Maximum number of buffer segments */
|
||||
};
|
||||
|
||||
struct BufField {
|
||||
uint32_t offset;
|
||||
uint32_t len;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines the reserved field of a network data buffer used to store private information.
|
||||
*
|
||||
* The length of the reserved field is <b>68</b> bytes.
|
||||
*/
|
||||
#define MAX_NETBUF_RESEVER_SIZE 68
|
||||
|
||||
/**
|
||||
* @brief Records and saves a network data buffer.
|
||||
*
|
||||
* This structure is used to transmit network data between the protocol stack and network driver.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct NetBuf {
|
||||
struct DListHead dlist; /**< Doubly linked list. Generally, multiple network data buffers are
|
||||
linked by using a doubly linked list. */
|
||||
struct BufField bufs[MAX_BUF_NUM]; /**< Defines buffer segments used to record the offset address
|
||||
(based on the memory buffer address) and length of each buffer segment,
|
||||
including the header buffer segment, data segment, and tail buffer segment.
|
||||
For details, see {@link MAX_BUF_NUM}. */
|
||||
uint8_t *mem; /**< Memory buffer address */
|
||||
uint32_t len; /**< Length of the memory buffer */
|
||||
uint32_t dataLen; /**< Actual data length of the network data buffer */
|
||||
void *dev; /**< Network device that receives the network data */
|
||||
uint32_t qmap; /**< Queue mappings of the network data buffer */
|
||||
uint8_t rsv[MAX_NETBUF_RESEVER_SIZE]; /**< Reserved field. For details, see {@link MAX_NETBUF_RESEVER_SIZE}. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Indicates the queues for storing network data.
|
||||
*
|
||||
* Queues can be used to process multiple pieces of network data in a centralized manner, improving efficiency.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct NetBufQueue {
|
||||
struct DListHead dlist; /**< Doubly linked list. Generally, multiple network data buffers are linked
|
||||
by using a doubly linked list. */
|
||||
uint32_t size; /**< Number of network data buffers in the queue */
|
||||
struct Spinlock lock; /**< Queue operation lock */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Initializes a network data buffer queue.
|
||||
*
|
||||
* @param q Indicates the pointer to the network data buffer queue.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
static inline void NetBufQueueInit(struct NetBufQueue *q)
|
||||
{
|
||||
DListHeadInit(&q->dlist);
|
||||
LOS_SpinInit(&q->lock);
|
||||
q->size = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the size of a network data buffer queue.
|
||||
*
|
||||
* @param q Indicates the pointer to the network data buffer queue.
|
||||
*
|
||||
* @return Returns the size of the network data buffer queue.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
static inline uint32_t NetBufQueueSize(const struct NetBufQueue *q)
|
||||
{
|
||||
return q->size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks whether the network data buffer queue is empty.
|
||||
*
|
||||
* @param q Indicates the pointer to the network data buffer queue.
|
||||
*
|
||||
* @return Returns <b>true</b> if the queue is empty; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
static inline bool NetBufQueueIsEmpty(const struct NetBufQueue *q)
|
||||
{
|
||||
return DListIsEmpty(&q->dlist);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Adds a network data buffer to the tail of a queue.
|
||||
*
|
||||
* @param q Indicates the pointer to the network data buffer queue.
|
||||
* @param nb Indicates the pointer to the network data buffer.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void NetBufQueueEnqueue(struct NetBufQueue *q, struct NetBuf *nb);
|
||||
|
||||
/**
|
||||
* @brief Adds a network data buffer to the header of a queue.
|
||||
*
|
||||
* @param q Indicates the pointer to the network data buffer queue.
|
||||
* @param nb Indicates the pointer to the network data buffer.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void NetBufQueueEnqueueHead(struct NetBufQueue *q, struct NetBuf *nb);
|
||||
|
||||
/**
|
||||
* @brief Obtains a network data buffer from the header of a queue and deletes it from the queue.
|
||||
*
|
||||
* @param q Indicates the pointer to the network data buffer queue.
|
||||
*
|
||||
* @return Returns the pointer to the first network data buffer if the queue is not empty;
|
||||
* returns <b>NULL</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct NetBuf *NetBufQueueDequeue(struct NetBufQueue *q);
|
||||
|
||||
/**
|
||||
* @brief Obtains a network data buffer from the tail of a queue and deletes it from the queue.
|
||||
*
|
||||
* @param q Indicates the pointer to the network data buffer queue.
|
||||
*
|
||||
* @return Returns the pointer to the last network data buffer if the queue is not empty;
|
||||
* returns <b>NULL</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct NetBuf *NetBufQueueDequeueTail(struct NetBufQueue *q);
|
||||
|
||||
/**
|
||||
* @brief Obtains the network data buffer from the header of a queue, without deleting it from the queue.
|
||||
*
|
||||
* @param q Indicates the pointer to the network data buffer queue.
|
||||
*
|
||||
* @return Returns the pointer to the first network data buffer if the queue is not empty;
|
||||
* returns <b>NULL</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
static inline struct NetBuf *NetBufQueueAtHead(const struct NetBufQueue *q)
|
||||
{
|
||||
return (DListIsEmpty(&q->dlist)) ? NULL : DLIST_FIRST_ENTRY(&q->dlist, struct NetBuf, dlist);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the network data buffer from the tail of a queue, without deleting it from the queue.
|
||||
*
|
||||
* @param q Indicates the pointer to the network data buffer queue.
|
||||
*
|
||||
* @return Returns the pointer to the last network data buffer if the queue is not empty;
|
||||
* returns <b>NULL</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
static inline struct NetBuf *NetBufQueueAtTail(const struct NetBufQueue *q)
|
||||
{
|
||||
return (DListIsEmpty(&q->dlist)) ? NULL : DLIST_LAST_ENTRY(&q->dlist, struct NetBuf, dlist);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clears a network data buffer queue and releases the network data buffer in the queue.
|
||||
*
|
||||
* @param q Indicates the pointer to the network data buffer queue.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void NetBufQueueClear(struct NetBufQueue *q);
|
||||
|
||||
/**
|
||||
* @brief Moves all network data buffers from one queue to another and clears the source queue.
|
||||
*
|
||||
* @param q Indicates the pointer to the target network data buffer queue.
|
||||
* @param add Indicates the pointer to the source network data buffer queue.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void NetBufQueueConcat(struct NetBufQueue *q, struct NetBufQueue *add);
|
||||
|
||||
struct NetDevice;
|
||||
|
||||
/**
|
||||
* @brief Applies for a network data buffer.
|
||||
*
|
||||
* @param size Indicates the size of the network data buffer.
|
||||
*
|
||||
* @return Returns the pointer to the network data buffer if the operation is successful;
|
||||
* returns <b>NULL</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct NetBuf *NetBufAlloc(uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief Releases a network data buffer.
|
||||
*
|
||||
* @param nb Indicates the pointer to the network data buffer.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void NetBufFree(struct NetBuf *nb);
|
||||
|
||||
/**
|
||||
* @brief Applies for a network data buffer based on the reserved space and requested size set by a network device.
|
||||
*
|
||||
* @param dev Indicates the pointer to the network device.
|
||||
* @param size Indicates the size of the network data buffer applied.
|
||||
*
|
||||
* @return Returns the pointer to the network data buffer if the operation is successful;
|
||||
* returns <b>NULL</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct NetBuf *NetBufDevAlloc(const struct NetDevice *dev, uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief Performs operations based on the segment ID of a network data buffer.
|
||||
* The function is opposite to that of {@link NetBufPop}.
|
||||
*
|
||||
* Description:
|
||||
* ID Type | Result
|
||||
* -------|---------
|
||||
* E_HEAD_BUF | The length of the header buffer segment is increased and the length of the data segment is reduced.
|
||||
* E_DATA_BUF | The length of the data segment is increased and the length of the tail buffer segment is reduced.
|
||||
* E_TAIL_BUF | The length of the tail buffer segment is increased and the length of the data segment is reduced.
|
||||
*
|
||||
* @param nb Indicates the pointer to the network data buffer.
|
||||
* @param id Indicates the buffer segment ID.
|
||||
* @param len Indicates the operation length.
|
||||
*
|
||||
* @return Returns the start address of the data segment if the operation is successful;
|
||||
* returns <b>NULL</b> if the operation length exceeds the space of a specified buffer segment.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void *NetBufPush(struct NetBuf *nb, uint32_t id, uint32_t len);
|
||||
|
||||
/**
|
||||
* @brief Performs operations based on the segment ID of a network data buffer.
|
||||
* The function is opposite to that of {@link NetBufPush}.
|
||||
*
|
||||
* Description:
|
||||
* ID Type | Result
|
||||
* -------|---------
|
||||
* E_HEAD_BUF | The length of the header buffer segment is reduced and the length of the data segment is increased.
|
||||
* E_DATA_BUF| The length of the data segment is reduced and the length of the tail buffer segment is increased.
|
||||
* E_TAIL_BUF | The length of the tail buffer segment is reduced and the length of the data segment is increased.
|
||||
*
|
||||
* @param nb Indicates the pointer to the network data buffer.
|
||||
* @param id Indicates the buffer segment ID.
|
||||
* @param len Indicates the operation length.
|
||||
*
|
||||
* @return Returns the start address of the data segment if the operation is successful;
|
||||
* returns <b>NULL</b> if the operation length exceeds the space of a specified buffer segment.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void *NetBufPop(struct NetBuf *nb, uint32_t id, uint32_t len);
|
||||
|
||||
/**
|
||||
* @brief Obtains the address of a specified buffer segment in a network data buffer.
|
||||
*
|
||||
* @param nb Indicates the pointer to the network data buffer.
|
||||
* @param id Indicates the buffer segment ID.
|
||||
*
|
||||
* @return Returns the address of the specified buffer segment if the operation is successful;
|
||||
* returns <b>NULL</b> if the buffer segment ID is invalid.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
static inline uint8_t *NetBufGetAddress(const struct NetBuf *nb, uint32_t id)
|
||||
{
|
||||
if (id < MAX_BUF_NUM) {
|
||||
return (nb->mem + nb->bufs[id].offset);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the size of a specified buffer segment space in a network data buffer.
|
||||
*
|
||||
* @param nb Indicates the pointer to the network data buffer.
|
||||
* @param id Indicates the buffer segment ID.
|
||||
*
|
||||
* @return Returns the size of the specified buffer segment space if the operation is successful;
|
||||
* returns <b>NULL</b> if the buffer segment ID is invalid.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
static inline uint32_t NetBufGetRoom(const struct NetBuf *nb, uint32_t id)
|
||||
{
|
||||
if (id < MAX_BUF_NUM) {
|
||||
return nb->bufs[id].len;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the actual data length of the data segment of a network data buffer.
|
||||
*
|
||||
* @param nb Indicates the pointer to the network data buffer.
|
||||
*
|
||||
* @return Returns the actual data length of the data segment.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
static inline uint32_t NetBufGetDataLen(const struct NetBuf *nb)
|
||||
{
|
||||
return nb->dataLen;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Adjusts the size of a network data buffer space.
|
||||
*
|
||||
* This function is used to apply for a new network data buffer based on the configured reserved space and
|
||||
* the size of the source network data buffer, and copy the actual data to the new network data buffer.
|
||||
*
|
||||
* @param nb Indicates the pointer to the network data buffer.
|
||||
* @param head Indicates the size of the header buffer segment reserved.
|
||||
* @param tail Indicates the size of the tail buffer segment reserved.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t NetBufResizeRoom(struct NetBuf *nb, uint32_t head, uint32_t tail);
|
||||
|
||||
/**
|
||||
* @brief Copies data in a network data buffer to another network data buffer.
|
||||
*
|
||||
* @param nb Indicates the pointer to the network data buffer.
|
||||
* @param cnb Indicates the pointer to the target network data buffer.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
uint32_t NetBufConcat(struct NetBuf *nb, struct NetBuf *cnb);
|
||||
|
||||
/**
|
||||
* @brief Converts the <b>pbuf</b> structure of Lightweight TCP/IP Stack (lwIP) to a network data buffer.
|
||||
*
|
||||
* When a network device is specified, the reserved space of the network device will be added to
|
||||
* the size of the converted network data buffer.
|
||||
*
|
||||
* @param netdev Indicates the pointer to the network device.
|
||||
* @param lwip_buf Indicates the pointer to the data buffer of lwIP.
|
||||
*
|
||||
* @return Returns the pointer to the network data buffer if the operation is successful;
|
||||
* returns <b>NULL</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct NetBuf *Pbuf2NetBuf(const struct NetDevice *netdev, struct pbuf *lwipBuf);
|
||||
|
||||
/**
|
||||
* @brief Converts a network data buffer to the <b>pbuf</b> structure of Lightweight TCP/IP Stack (lwIP).
|
||||
*
|
||||
* @param nb Indicates the pointer to the network data buffer.
|
||||
*
|
||||
* @return Returns the pointer to the <b>pbuf</b> structure if the operation is successful;
|
||||
* returns <b>NULL</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct pbuf *NetBuf2Pbuf(const struct NetBuf *nb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* HDF_NETBUF_H */
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef OSAL_H
|
||||
#define OSAL_H
|
||||
|
||||
#include "osal/osal_firmware.h"
|
||||
#include "osal/osal_irq.h"
|
||||
#include "osal/osal_mem.h"
|
||||
#include "osal/osal_mutex.h"
|
||||
#include "osal/osal_sem.h"
|
||||
#include "osal/osal_spinlock.h"
|
||||
#include "osal/osal_thread.h"
|
||||
#include "osal/osal_time.h"
|
||||
#include "osal/osal_timer.h"
|
||||
#include "utils/hdf_base.h"
|
||||
#include "utils/hdf_log.h"
|
||||
#include "utils/hdf_dlist.h"
|
||||
|
||||
#endif /* OSAL_H */
|
||||
Executable
+172
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup OSAL
|
||||
* @{
|
||||
*
|
||||
* @brief Defines the structures and interfaces for the Operating System Abstraction Layer (OSAL) module.
|
||||
*
|
||||
* The OSAL module harmonizes OS interface differences and provides unified OS interfaces externally,
|
||||
* including the memory management, thread, mutex, spinlock, semaphore, timer, file, interrupt, time,
|
||||
* atomic, firmware, and I/O operation modules.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file osal_atomic.h
|
||||
*
|
||||
* @brief Declares atomic and bit operation interfaces.
|
||||
*
|
||||
* This file provides interfaces such as reading and setting an atomic,
|
||||
* incrementing and decrementing an atomic counter by 1.
|
||||
* This file also provides interfaces such as checking the bit status of a variable,
|
||||
* and setting and clearing the bit value of a variable.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef OSAL_ATOMIC_H
|
||||
#define OSAL_ATOMIC_H
|
||||
|
||||
#include "hdf_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Describes an atomic.
|
||||
*/
|
||||
typedef struct {
|
||||
volatile int32_t counter;/**< Counter (an atomic variable).
|
||||
* An operation on the atomic is to operate this variable.
|
||||
*/
|
||||
} OsalAtomic;
|
||||
|
||||
/**
|
||||
* @brief Reads the counter of an atomic.
|
||||
*
|
||||
* @param v Indicates the pointer to the atomic {@link OsalAtomic}.
|
||||
*
|
||||
* @return Returns the counter.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalAtomicRead(const OsalAtomic *v);
|
||||
|
||||
/**
|
||||
* @brief Sets the counter for an atomic.
|
||||
*
|
||||
* @param v Indicates the pointer to the atomic {@link OsalAtomic}.
|
||||
* @param counter Indicates the counter to set.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void OsalAtomicSet(OsalAtomic *v, int32_t counter);
|
||||
|
||||
/**
|
||||
* @brief Increments the counter of an atomic by 1.
|
||||
*
|
||||
* @param v Indicates the pointer to the atomic {@link OsalAtomic}.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void OsalAtomicInc(OsalAtomic *v);
|
||||
|
||||
/**
|
||||
* @brief Decrements the counter of an atomic by 1.
|
||||
*
|
||||
* @param v Indicates the pointer to the atomic {@link OsalAtomic}.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void OsalAtomicDec(OsalAtomic *v);
|
||||
|
||||
/**
|
||||
* @brief Tests the value of a specified bit of a variable.
|
||||
*
|
||||
* @param nr Indicates the bit of the variable. The value ranges from <b>0</b> to <b>31</b>.
|
||||
* @param addr Indicates the pointer to the variable.
|
||||
*
|
||||
* @return Returns the bit value.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalTestBit(unsigned long nr, const volatile unsigned long *addr);
|
||||
|
||||
/**
|
||||
* @brief Sets the value of a specified bit of the variable and returns the bit value before the setting.
|
||||
*
|
||||
* @param nr Indicates the bit of the variable. The value ranges from <b>0</b> to <b>31</b>.
|
||||
* @param addr Indicates the pointer to the variable.
|
||||
*
|
||||
* @return Returns the bit value before the setting.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalTestSetBit(unsigned long nr, volatile unsigned long *addr);
|
||||
|
||||
/**
|
||||
* @brief Clears the value of a specified bit of the variable and returns the bit value before clearing.
|
||||
*
|
||||
* @param nr Indicates the bit of the variable. The value ranges from <b>0</b> to <b>31</b>.
|
||||
* @param addr Indicates the pointer to the variable.
|
||||
*
|
||||
* @return Returns the bit value before the bit is cleared.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalTestClearBit(unsigned long nr, volatile unsigned long *addr);
|
||||
|
||||
/**
|
||||
* @brief Clears the value of a specified bit of the variable.
|
||||
*
|
||||
* @param nr Indicates the bit of the variable. The value ranges from <b>0</b> to <b>31</b>.
|
||||
* @param addr Indicates the pointer to the variable.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void OsalClearBit(unsigned long nr, volatile unsigned long *addr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OSAL_ATOMIC_H */
|
||||
/** @} */
|
||||
Executable
+230
@@ -0,0 +1,230 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup OSAL
|
||||
* @{
|
||||
*
|
||||
* @brief Defines the structures and interfaces for the Operating System Abstraction Layer (OSAL) module.
|
||||
*
|
||||
* The OSAL module harmonizes OS interface differences and provides unified OS interfaces externally,
|
||||
* including the memory management, thread, mutex, spinlock, semaphore, timer, file, interrupt, time,
|
||||
* atomic, firmware, and I/O operation modules.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file osal_file.h
|
||||
*
|
||||
* @brief Declares the file structures and interfaces.
|
||||
*
|
||||
* This file provides interfaces for opening, closing, reading, and writing a file, and setting the read/write offset.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef OSAL_FILE_H
|
||||
#define OSAL_FILE_H
|
||||
|
||||
#include "hdf_base.h"
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Opens a file in read-only mode.
|
||||
*/
|
||||
#define OSAL_O_RD_ONLY 0
|
||||
/**
|
||||
* @brief Opens a file in write-only mode.
|
||||
*/
|
||||
#define OSAL_O_WR_ONLY 1
|
||||
/**
|
||||
* @brief Opens a file in read and write mode.
|
||||
*/
|
||||
#define OSAL_O_RDWR 2
|
||||
|
||||
/**
|
||||
* @brief Defines the read permission for the owner.
|
||||
*/
|
||||
#define OSAL_S_IREAD 00400
|
||||
/**
|
||||
* @brief Defines the write permission for the owner.
|
||||
*/
|
||||
#define OSAL_S_IWRITE 00200
|
||||
/**
|
||||
* @brief Defines the execution permission for the owner.
|
||||
*/
|
||||
#define OSAL_S_IEXEC 00100
|
||||
|
||||
/**
|
||||
* @brief Defines the read permission for the group.
|
||||
*/
|
||||
#define OSAL_S_IRGRP 00040
|
||||
/**
|
||||
* @brief Defines the write permission for the group.
|
||||
*/
|
||||
#define OSAL_S_IWGRP 00020
|
||||
/**
|
||||
* @brief Defines the execution permission for the group.
|
||||
*/
|
||||
#define OSAL_S_IXGRP 00010
|
||||
|
||||
/**
|
||||
* @brief Defines the read permission for others.
|
||||
*/
|
||||
#define OSAL_S_IROTH 00004
|
||||
/**
|
||||
* @brief Defines the write permission for others.
|
||||
*/
|
||||
#define OSAL_S_IWOTH 00002
|
||||
/**
|
||||
* @brief Defines the execution permission for others.
|
||||
*/
|
||||
#define OSAL_S_IXOTH 00001
|
||||
|
||||
/**
|
||||
* @brief Defines the offset from the file header.
|
||||
*/
|
||||
#define OSAL_SEEK_SET 0
|
||||
/**
|
||||
* @brief Defines the offset from the current position.
|
||||
*/
|
||||
#define OSAL_SEEK_CUR 1
|
||||
/**
|
||||
* @brief Defines the offset from the end of the file.
|
||||
*/
|
||||
#define OSAL_SEEK_END 2
|
||||
|
||||
/**
|
||||
* @brief Declares a file type.
|
||||
*/
|
||||
typedef struct {
|
||||
void *realFile; /**< Pointer to a file object to access */
|
||||
} OsalFile;
|
||||
|
||||
/**
|
||||
* @brief Opens a file.
|
||||
*
|
||||
* @param file Indicates the pointer to the file type {@link OsalFile}.
|
||||
* @param path Indicates the pointer to the name of the file to open.
|
||||
* @param flags Indicates the mode of opening the file. For details, see {@link OSAL_O_RD_ONLY}.
|
||||
* @param rights Indicates the permissions required for opening the file. For details, see {@link OSAL_S_IREAD}.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to open the file.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalFileOpen(OsalFile *file, const char *path, int flags, uint32_t rights);
|
||||
|
||||
/**
|
||||
* @brief Writes a file.
|
||||
*
|
||||
* @param file Indicates the pointer to the file type {@link OsalFile}.
|
||||
* @param string Indicates the pointer to the content to write.
|
||||
* @param length Indicates the length of the content to write.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* ssize_t | Description
|
||||
* -----------------------------------------| -----------------------
|
||||
* Greater than <b>0</b> | The length of the file content is successfully written.
|
||||
* HDF_FAILURE {@link HDF_STATUS} | Failed to invoke the system function to write the file.
|
||||
* HDF_ERR_INVALID_PARAM {@link HDF_STATUS} | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
ssize_t OsalFileWrite(OsalFile *file, const void *string, uint32_t length);
|
||||
|
||||
/**
|
||||
* @brief Closes a file.
|
||||
*
|
||||
* @param file Indicates the pointer to the file type {@link OsalFile}.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void OsalFileClose(OsalFile *file);
|
||||
|
||||
/**
|
||||
* @brief Reads a file.
|
||||
*
|
||||
* @param file Indicates the pointer to the file type {@link OsalFile}.
|
||||
* @param buf Indicates the pointer to the buffer for storing the content to read.
|
||||
* @param length Indicates the length of the content to read.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* ssize_t | Description
|
||||
* -----------------------------------------| -----------------------
|
||||
* Greater than <b>0</b> | The length of the file content is successfully read.
|
||||
* HDF_FAILURE {@link HDF_STATUS} | Failed to invoke the system function to read the file.
|
||||
* HDF_ERR_INVALID_PARAM {@link HDF_STATUS} | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
ssize_t OsalFileRead(OsalFile *file, void *buf, uint32_t length);
|
||||
|
||||
/**
|
||||
* @brief Sets the file read/write offset.
|
||||
*
|
||||
* @param file Indicates the pointer to the file type {@link OsalFile}.
|
||||
* @param offset Indicates the offset to set.
|
||||
* @param whence Indicates the position from which the offset is to set. For details, see {@link OSAL_SEEK_SET}.
|
||||
*
|
||||
* off_t | Description
|
||||
* -----------------------------------------| -----------------------
|
||||
* Greater than <b>0</b> | The offset is set.
|
||||
* HDF_FAILURE {@link HDF_STATUS} | Failed to invoke the system function to set the file offset.
|
||||
* HDF_ERR_INVALID_PARAM {@link HDF_STATUS} | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
off_t OsalFileLseek(OsalFile *file, off_t offset, int32_t whence);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OSAL_FILE_H */
|
||||
/** @} */
|
||||
Executable
+164
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup OSAL
|
||||
* @{
|
||||
*
|
||||
* @brief Defines the structures and interfaces for the Operating System Abstraction Layer (OSAL) module.
|
||||
*
|
||||
* The OSAL module harmonizes OS interface differences and provides unified OS interfaces externally,
|
||||
* including the memory management, thread, mutex, spinlock, semaphore, timer, file, interrupt, time,
|
||||
* atomic, firmware, and I/O operation modules.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file osal_firmware.h
|
||||
*
|
||||
* @brief Declares firmware structures and interfaces.
|
||||
*
|
||||
* This file provides operations such as requesting and reading a firmware file, setting the offset for reading
|
||||
* a firmware file, and releasing a firmware file. The firmware file can be read in split mode.
|
||||
* The size of the firmware block to read each time is defined by the macro {@link HDF_FW_BLOCK_SIZE}.
|
||||
* The firmware file is requested by calling {@link OsalRequestFirmware}, the firmware block is read from
|
||||
* the firmware file by calling {@link OsalReadFirmware}, and the firmware block can also be randomly read
|
||||
* at a specified position by calling {@link OsalSeekFirmware}.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef OSAL_FIRMWARE_H
|
||||
#define OSAL_FIRMWARE_H
|
||||
|
||||
#include "hdf_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Defines the data structure for operating a firmware file.
|
||||
*/
|
||||
struct OsalFirmware {
|
||||
uint32_t fwSize; /**< Firmware file size, which is returned by calling {@link OsalRequestFirmware}. */
|
||||
void *para; /**< Pointer to a firmware file, which is returned by calling {@link OsalRequestFirmware}.
|
||||
* You do not need to allocate space.
|
||||
*/
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines the data structure for reading a firmware file.
|
||||
*
|
||||
* This structure declares the firmware block to read each time. The firmware file can be read in split mode.
|
||||
*/
|
||||
struct OsalFwBlock {
|
||||
uint8_t *data; /**< Firmware content read this time. You do not need to allocate space. */
|
||||
bool endFlag; /**< Whether the firmware file is read completely */
|
||||
uint32_t dataSize; /**< Firmware block size read this time */
|
||||
int32_t curOffset; /**< Offset in the firmware file */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Requests a firmware file based on its name and device information.
|
||||
*
|
||||
* @param fw Indicates the pointer to the firmware file {@link OsalFirmware}, which cannot be empty.
|
||||
* @param fwName Indicates the pointer to the firmware file name, which cannot be empty.
|
||||
* @param device Indicates the pointer to the information about the device that requests the firmware file.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
* HDF_ERR_MALLOC_FAIL | Memory allocation fails.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalRequestFirmware(struct OsalFirmware *fw, const char *fwName, void *device);
|
||||
|
||||
/**
|
||||
* @brief Reads a firmware file.
|
||||
*
|
||||
* @param fw Indicates the pointer to the firmware file {@link OsalFirmware}.
|
||||
* @param block Indicates the pointer to the firmware block to read. For details, see {@link OsalFwBlock}.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalSeekFirmware(struct OsalFirmware *fw, uint32_t offset);
|
||||
|
||||
/**
|
||||
* @brief Releases a firmware file.
|
||||
*
|
||||
* After the firmware file is read, this function is called to release the firmware file.
|
||||
*
|
||||
* @param fw Indicates the pointer to the firmware file {@link OsalFirmware}.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalReadFirmware(struct OsalFirmware *fw, struct OsalFwBlock *block);
|
||||
|
||||
/**
|
||||
* Release firmware resource
|
||||
*
|
||||
* @param : fw Firmware parameter, see detail in OsalFirmware
|
||||
* block Firmware data block, see detail in hdf_FWBlock
|
||||
* @return : true or false
|
||||
*/
|
||||
int32_t OsalReleaseFirmware(struct OsalFirmware *fw);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OSAL_FIRMWARE_H */
|
||||
/** @} */
|
||||
Executable
+166
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup OSAL
|
||||
* @{
|
||||
*
|
||||
* @brief Defines the structures and interfaces for the Operating System Abstraction Layer (OSAL) module.
|
||||
*
|
||||
* The OSAL module harmonizes OS interface differences and provides unified OS interfaces externally,
|
||||
* including the memory management, thread, mutex, spinlock, semaphore, timer, file, interrupt, time,
|
||||
* atomic, firmware, and I/O operation modules.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file osal_io.h
|
||||
*
|
||||
* @brief Declares I/O interfaces.
|
||||
*
|
||||
* This file provides operations, such as reading data from and writing data into an I/O address space,
|
||||
* remapping an I/O address space to its virtual address space, and unmapping an I/O virtual address
|
||||
* associated with the physical address.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef OSAL_IO_H
|
||||
#define OSAL_IO_H
|
||||
|
||||
#include <linux/io.h>
|
||||
#include <linux/kernel.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Writes one byte of data into an I/O address space.
|
||||
*
|
||||
* @param value Indicates the data to write.
|
||||
* @param address Indicates the address to write.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define OSAL_WRITEB(value, address) writeb(value, address)
|
||||
/**
|
||||
* @brief Writes a short integer into an I/O address space.
|
||||
*
|
||||
* @param value Indicates the data to write.
|
||||
* @param address Indicates the address to write.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define OSAL_WRITEW(value, address) writew(value, address)
|
||||
/**
|
||||
* @brief Writes an integer into an I/O address space.
|
||||
*
|
||||
* @param value Indicates the data to write.
|
||||
* @param address Indicates the address to write.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define OSAL_WRITEL(value, address) writel(value, address)
|
||||
|
||||
/**
|
||||
* @brief Reads one byte of data from an I/O address space.
|
||||
*
|
||||
* @param address Indicates the address to read.
|
||||
* @return Returns the byte.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define OSAL_READB(address) readb(address)
|
||||
/**
|
||||
* @brief Reads a short integer from an I/O address space.
|
||||
*
|
||||
* @param address Indicates the address to read.
|
||||
* @return Returns the short integer.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define OSAL_READW(address) readw(address)
|
||||
/**
|
||||
* @brief Reads an integer from an I/O address space.
|
||||
*
|
||||
* @param address Indicates the address to read.
|
||||
* @return Returns the integer.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define OSAL_READL(address) readl(address)
|
||||
|
||||
/**
|
||||
* @brief Remaps an I/O physical address to its virtual address.
|
||||
*
|
||||
* @param phys_addr Indicates the I/O physical address.
|
||||
* @param size Indicates the size of the physical address to remap.
|
||||
* @return Returns the virtual address.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static inline void *OsalIoRemap(unsigned long phys_addr, unsigned long size)
|
||||
{
|
||||
return ioremap(phys_addr, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unmaps an I/O virtual address associated with the physical address.
|
||||
*
|
||||
* The virtual address is the one returned by calling {@link OsalIoRemap}.
|
||||
*
|
||||
* @param addr Indicates the pointer to the virtual address to unmap.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static inline void OsalIoUnmap(void *addr)
|
||||
{
|
||||
iounmap(addr);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OSAL_IO_H */
|
||||
/** @} */
|
||||
Executable
+157
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup OSAL
|
||||
* @{
|
||||
*
|
||||
* @brief Defines the structures and interfaces for the Operating System Abstraction Layer (OSAL) module.
|
||||
*
|
||||
* The OSAL module harmonizes OS interface differences and provides unified OS interfaces externally,
|
||||
* including the memory management, thread, mutex, spinlock, semaphore, timer, file, interrupt, time,
|
||||
* atomic, firmware, and I/O operation modules.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file osal_irq.h
|
||||
*
|
||||
* @brief Declares interrupt request (IRQ) interfaces and common IRQ trigger modes.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef OSAL_IRQ_H
|
||||
#define OSAL_IRQ_H
|
||||
|
||||
#include "hdf_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Enumerates interrupt trigger modes.
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
typedef enum {
|
||||
OSAL_IRQF_TRIGGER_NONE = 0, /**< Edge-triggered is not set */
|
||||
OSAL_IRQF_TRIGGER_RISING = 1, /**< Rising edge triggered */
|
||||
OSAL_IRQF_TRIGGER_FALLING = 2, /**< Failing edge triggered */
|
||||
OSAL_IRQF_TRIGGER_HIGH = 4, /**< High-level triggered */
|
||||
OSAL_IRQF_TRIGGER_LOW = 8, /**< Low-level triggered */
|
||||
} OSAL_IRQ_TRIGGER_MODE;
|
||||
|
||||
/**
|
||||
* @brief Defines an IRQ type.
|
||||
*/
|
||||
typedef uint32_t (*OsalIRQHandle)(uint32_t irqId, void *dev);
|
||||
|
||||
/**
|
||||
* @brief Registers an IRQ.
|
||||
*
|
||||
* @param irqId Indicates the IRQ ID.
|
||||
* @param config Indicates the interrupt trigger mode. For details, see {@link OSAL_IRQ_TRIGGER_MODE}.
|
||||
* @param handle Indicates the interrupt processing function.
|
||||
* @param name Indicates the pointer to the device name for registering an IRQ.
|
||||
* @param dev Indicates the pointer to the parameter passed to the interrupt processing function.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to register the IRQ.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalRegisterIrq(uint32_t irqId, uint32_t config, OsalIRQHandle handle, const char *name, void *dev);
|
||||
|
||||
/**
|
||||
* @brief Unregisters an IRQ.
|
||||
*
|
||||
* @param irqId Indicates the IRQ ID.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to unregister the IRQ.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalUnregisterIrq(uint32_t irqId);
|
||||
|
||||
/**
|
||||
* @brief Enables an IRQ.
|
||||
*
|
||||
* @param irqId Indicates the IRQ ID.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalEnableIrq(uint32_t irqId);
|
||||
|
||||
/**
|
||||
* @brief Disables an IRQ.
|
||||
*
|
||||
* @param irqId Indicates the IRQ ID.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalDisableIrq(uint32_t irqId);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OSAL_IRQ_H */
|
||||
/** @} */
|
||||
Executable
+111
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup OSAL
|
||||
* @{
|
||||
*
|
||||
* @brief Defines the structures and interfaces for the Operating System Abstraction Layer (OSAL) module.
|
||||
*
|
||||
* The OSAL module harmonizes OS interface differences and provides unified OS interfaces externally,
|
||||
* including the memory management, thread, mutex, spinlock, semaphore, timer, file, interrupt, time,
|
||||
* atomic, firmware, and I/O operation modules.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file osal_mem.h
|
||||
*
|
||||
* @brief Declares the driver memory request and release interfaces.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef OSAL_MEM_H
|
||||
#define OSAL_MEM_H
|
||||
|
||||
#include "hdf_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Allocates memory of a specified size.
|
||||
*
|
||||
* @param size Indicates the size of memory to allocate.
|
||||
*
|
||||
* @return Returns the pointer to the allocated memory if the operation is successful; returns <b>NULL</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void *OsalMemAlloc(size_t size);
|
||||
|
||||
/**
|
||||
* @brief Allocates memory of a specified size, and clears the allocated memory.
|
||||
*
|
||||
* @param size Indicates the size of memory to allocate.
|
||||
*
|
||||
* @return Returns the pointer to the allocated memory if the operation is successful; returns <b>NULL</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void *OsalMemCalloc(size_t size);
|
||||
|
||||
/**
|
||||
* @brief Allocates memory of a specified size, and aligns the memory address on a given boundary.
|
||||
*
|
||||
* @param alignment Indicates the memory boundary alignment. The value must be a power of 2.
|
||||
* @param size Indicates the size of memory to allocate.
|
||||
*
|
||||
* @return Returns the pointer to the allocated memory if the operation is successful; returns <b>NULL</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void *OsalMemAllocAlign(size_t alignment, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Releases memory.
|
||||
*
|
||||
* @param mem Indicates the pointer to the memory to release.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void OsalMemFree(void *mem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OSAL_MEM_H */
|
||||
/** @} */
|
||||
Executable
+170
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup OSAL
|
||||
* @{
|
||||
*
|
||||
* @brief Defines the structures and interfaces for the Operating System Abstraction Layer (OSAL) module.
|
||||
*
|
||||
* The OSAL module harmonizes OS interface differences and provides unified OS interfaces externally,
|
||||
* including the memory management, thread, mutex, spinlock, semaphore, timer, file, interrupt, time,
|
||||
* atomic, firmware, and I/O operation modules.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file osal_mutex.h
|
||||
*
|
||||
* @brief Declares mutex types and interfaces.
|
||||
*
|
||||
* This file provides interfaces for initializing and destroying a mutex, locking a mutex,
|
||||
* locking a mutex upon timeout, and unlocking a mutex. The mutex must be destroyed after being used.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef OSAL_MUTEX_H
|
||||
#define OSAL_MUTEX_H
|
||||
|
||||
#include "hdf_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Describes a mutex.
|
||||
*/
|
||||
struct OsalMutex {
|
||||
void *realMutex; /**< Pointer to a mutex object to operate */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines a mutex.
|
||||
*/
|
||||
#define OSAL_DECLARE_MUTEX(mutex) struct OsalMutex mutex
|
||||
|
||||
/**
|
||||
* @brief Initializes a mutex.
|
||||
*
|
||||
* @param mutex Indicates the pointer to the mutex {@link OsalMutex}.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to initialize the mutex.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalMutexInit(struct OsalMutex *mutex);
|
||||
|
||||
/**
|
||||
* @brief Destroys a mutex.
|
||||
*
|
||||
* @param mutex Indicates the pointer to the mutex {@link OsalMutex}.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to destroy the mutex.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalMutexDestroy(struct OsalMutex *mutex);
|
||||
|
||||
/**
|
||||
* @brief Locks a mutex.
|
||||
*
|
||||
* @param mutex Indicates the pointer to the mutex {@link OsalMutex}.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to lock the mutex.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalMutexLock(struct OsalMutex *mutex);
|
||||
|
||||
/**
|
||||
* @brief Locks a mutex with a specified timeout duration.
|
||||
*
|
||||
* @param mutex Indicates the pointer to the mutex {@link OsalMutex}.
|
||||
* @param ms Indicates the timeout duration, in milliseconds.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to lock the mutex.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
* HDF_ERR_TIMEOUT | Timeout occurs.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalMutexTimedLock(struct OsalMutex *mutex, uint32_t ms);
|
||||
|
||||
/**
|
||||
* @brief Unlocks a mutex.
|
||||
*
|
||||
* @param mutex Indicates the pointer to the mutex {@link OsalMutex}.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to unlock the mutex.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalMutexUnlock(struct OsalMutex *mutex);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OSAL_MUTEX_H */
|
||||
/** @} */
|
||||
Executable
+151
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup OSAL
|
||||
* @{
|
||||
*
|
||||
* @brief Defines the structures and interfaces for the Operating System Abstraction Layer (OSAL) module.
|
||||
*
|
||||
* The OSAL module harmonizes OS interface differences and provides unified OS interfaces externally,
|
||||
* including the memory management, thread, mutex, spinlock, semaphore, timer, file, interrupt, time,
|
||||
* atomic, firmware, and I/O operation modules.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file osal_sem.h
|
||||
*
|
||||
* @brief Declares semaphore structures and interfaces.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef OSAL_SEM_H
|
||||
#define OSAL_SEM_H
|
||||
|
||||
#include "hdf_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Describes a semaphore.
|
||||
*/
|
||||
struct OsalSem {
|
||||
void *realSemaphore; /**< Pointer to a semaphore to operate */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines a semaphore.
|
||||
*/
|
||||
#define OSAL_DECLARE_SEMAPHORE(sem) struct OsalSem sem
|
||||
|
||||
/**
|
||||
* @brief Initializes a semaphore.
|
||||
*
|
||||
* @param sem Indicates the pointer to the semaphore {@link OsalSem}.
|
||||
* @param value Indicates the initial value of the semaphore.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to initialize the semaphore.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalSemInit(struct OsalSem *sem, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Waits for a semaphore.
|
||||
*
|
||||
* @param sem Indicates the pointer to the semaphore {@link OsalSem}.
|
||||
* @param ms Indicates the timeout interval.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to wait for the semaphore.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
* HDF_ERR_TIMEOUT | Timeout occurs.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalSemWait(struct OsalSem *sem, uint32_t ms);
|
||||
|
||||
/**
|
||||
* @brief Releases a semaphore.
|
||||
*
|
||||
* @param sem Indicates the pointer to the semaphore {@link OsalSem}.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to release the semaphore.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalSemPost(struct OsalSem *sem);
|
||||
|
||||
/**
|
||||
* @brief Destroys a semaphore.
|
||||
*
|
||||
* @param sem Indicates the pointer to the semaphore {@link OsalSem}.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to destroy the semaphore.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalSemDestroy(struct OsalSem *sem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OSAL_SEM_H */
|
||||
/** @} */
|
||||
Executable
+224
@@ -0,0 +1,224 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup OSAL
|
||||
* @{
|
||||
*
|
||||
* @brief Defines the structures and interfaces for the Operating System Abstraction Layer (OSAL) module.
|
||||
*
|
||||
* The OSAL module harmonizes OS interface differences and provides unified OS interfaces externally,
|
||||
* including the memory management, thread, mutex, spinlock, semaphore, timer, file, interrupt, time,
|
||||
* atomic, firmware, and I/O operation modules.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file osal_spinlock.h
|
||||
*
|
||||
* @brief Declares spinlock types and interfaces.
|
||||
*
|
||||
* This file provides the interfaces for initializing, destroying, obtaining, and releasing a spinlock,
|
||||
* the interfaces for obtaining a spinlock and disabling the interrupt request (IRQ), releasing a spinlock
|
||||
* and enabling the IRQ, obtaining a spinlock, disabling the IRQ, and saving its status, and releasing a spinlock,
|
||||
* enabling the IRQ, and restoring the saved IRQ status. The spinlock needs to be destroyed when it is no longer used.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef OSAL_SPINLOCK_H
|
||||
#define OSAL_SPINLOCK_H
|
||||
|
||||
#include "hdf_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Describes a spinlock.
|
||||
*/
|
||||
typedef struct {
|
||||
void *realSpinlock; /**< Pointer to a spinlock */
|
||||
} OsalSpinlock;
|
||||
|
||||
/**
|
||||
* @brief Defines a spinlock.
|
||||
*/
|
||||
#define OSAL_DECLARE_SPINLOCK(spinlock) OsalSpinlock spinlock
|
||||
|
||||
/**
|
||||
* @brief Initializes a spinlock.
|
||||
*
|
||||
* @param spinlock Indicates the pointer to the spinlock {@link OsalSpinlock}.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to initialize the spinlock.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
* HDF_ERR_MALLOC_FAIL | Memory allocation fails.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalSpinInit(OsalSpinlock *spinlock);
|
||||
|
||||
/**
|
||||
* @brief Destroys a spinlock.
|
||||
*
|
||||
* @param spinlock Indicates the pointer to the spinlock {@link OsalSpinlock}.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to destroy the spinlock.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalSpinDestroy(OsalSpinlock *spinlock);
|
||||
|
||||
/**
|
||||
* @brief Obtains a spinlock.
|
||||
*
|
||||
* @param spinlock Indicates the pointer to the spinlock {@link OsalSpinlock}.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to obtain the spinlock.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalSpinLock(OsalSpinlock *spinlock);
|
||||
|
||||
/**
|
||||
* @brief Releases a spinlock.
|
||||
*
|
||||
* @param spinlock Indicates the pointer to the spinlock {@link OsalSpinlock}.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to release the spinlock.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalSpinUnlock(OsalSpinlock *spinlock);
|
||||
|
||||
/**
|
||||
* @brief Obtains a spinlock and disables the IRQ.
|
||||
*
|
||||
* @param spinlock Indicates the pointer to the spinlock {@link OsalSpinlock}.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to obtain the spinlock.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalSpinLockIrq(OsalSpinlock *spinlock);
|
||||
|
||||
/**
|
||||
* @brief Releases a spinlock and enables the IRQ.
|
||||
*
|
||||
* @param spinlock Indicates the pointer to the spinlock {@link OsalSpinlock}.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to release the spinlock.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalSpinUnlockIrq(OsalSpinlock *spinlock);
|
||||
|
||||
/**
|
||||
* @brief Obtains a spinlock, disables the IRQ, and saves its status.
|
||||
*
|
||||
* @param spinlock Indicates the pointer to the spinlock {@link OsalSpinlock}.
|
||||
* @param flags Indicates the pointer to the status of the IRQ register.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to obtain the spinlock.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalSpinLockIrqSave(OsalSpinlock *spinlock, uint32_t *flags);
|
||||
|
||||
/**
|
||||
* @brief Releases a spinlock, enables the IRQ, and restores the saved IRQ status.
|
||||
*
|
||||
* @param spinlock Indicates the pointer to the spinlock {@link OsalSpinlock}.
|
||||
* @param flags Indicates the pointer to the value used to restore the IRQ register.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to release the spinlock.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalSpinUnlockIrqRestore(OsalSpinlock *spinlock, uint32_t *flags);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OSAL_SPINLOCK_H */
|
||||
/** @} */
|
||||
Executable
+189
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup OSAL
|
||||
* @{
|
||||
*
|
||||
* @brief Defines the structures and interfaces for the Operating System Abstraction Layer (OSAL) module.
|
||||
*
|
||||
* The OSAL module harmonizes OS interface differences and provides unified OS interfaces externally,
|
||||
* including the memory management, thread, mutex, spinlock, semaphore, timer, file, interrupt, time,
|
||||
* atomic, firmware, and I/O operation modules.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file osal_thread.h
|
||||
*
|
||||
* @brief Declares thread types and interfaces.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef OSAL_THREAD_H
|
||||
#define OSAL_THREAD_H
|
||||
|
||||
#include "hdf_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Enumerates thread priorities.
|
||||
*/
|
||||
typedef enum {
|
||||
OSAL_THREAD_PRI_LOW, /**< Low priority */
|
||||
OSAL_THREAD_PRI_DEFAULT, /**< Default priority */
|
||||
OSAL_THREAD_PRI_HIGH, /**< High priority */
|
||||
OSAL_THREAD_PRI_HIGHEST /**< Highest priority */
|
||||
} OSAL_THREAD_PRIORITY;
|
||||
|
||||
/**
|
||||
* @brief Describes thread parameters.
|
||||
*/
|
||||
struct OsalThreadParam {
|
||||
char *name; /**< Thread name */
|
||||
size_t stackSize; /**< Stack size of a thread */
|
||||
OSAL_THREAD_PRIORITY priority; /**< Thread priority */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines a thread callback function type.
|
||||
*/
|
||||
typedef int (*OsalThreadEntry)(void *);
|
||||
|
||||
/**
|
||||
* @brief Describes a thread.
|
||||
*/
|
||||
struct OsalThread {
|
||||
int32_t status; /**< Thread running status */
|
||||
void *realThread; /**< Pointer to a created thread object */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines a thread macro.
|
||||
*/
|
||||
#define OSAL_DECLARE_THREAD(thread) struct OsalThread thread
|
||||
|
||||
/**
|
||||
* @brief Creates a thread.
|
||||
*
|
||||
* @param thread Indicates the pointer to the thread {@link OsalThread}.
|
||||
* @param threadEntry Indicates the thread callback function {@link OsalThreadEntry}.
|
||||
* @param entryPara Indicates the pointer to the parameter passed to the thread callback function.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
* HDF_ERR_MALLOC_FAIL | Memory allocation fails.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalThreadCreate(struct OsalThread *thread, OsalThreadEntry threadEntry, void *entryPara);
|
||||
/**
|
||||
* @brief Starts a thread.
|
||||
*
|
||||
* @param thread Indicates the pointer to the thread {@link OsalThread}.
|
||||
* @param param Indicates the pointer to the parameter used to start a thread. For details, see {@link OsalThreadParam}.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to start the thread.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalThreadStart(struct OsalThread *thread, const struct OsalThreadParam *param);
|
||||
|
||||
/**
|
||||
* @brief Destroys a thread.
|
||||
*
|
||||
* @param thread Indicates the pointer to the thread {@link OsalThread}.
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to destroy the thread.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalThreadDestroy(struct OsalThread *thread);
|
||||
|
||||
/**
|
||||
* @brief Suspends a thread.
|
||||
*
|
||||
* @param thread Indicates the pointer to the thread {@link OsalThread}.
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to suspend the thread.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalThreadSuspend(struct OsalThread *thread);
|
||||
|
||||
/**
|
||||
* @brief Resumes a thread.
|
||||
*
|
||||
* @param thread Indicates the pointer to the thread {@link OsalThread}.
|
||||
* @since 1.0
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to resume the thread.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalThreadResume(struct OsalThread *thread);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OSAL_THREAD_H */
|
||||
/** @} */
|
||||
Executable
+164
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup OSAL
|
||||
* @{
|
||||
*
|
||||
* @brief Defines the structures and interfaces for the Operating System Abstraction Layer (OSAL) module.
|
||||
*
|
||||
* The OSAL module harmonizes OS interface differences and provides unified OS interfaces externally,
|
||||
* including the memory management, thread, mutex, spinlock, semaphore, timer, file, interrupt, time,
|
||||
* atomic, firmware, and I/O operation modules.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file osal_time.h
|
||||
*
|
||||
* @brief Declares the time, sleep, and delay interfaces.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef OSAL_TIME_H
|
||||
#define OSAL_TIME_H
|
||||
|
||||
#include "hdf_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Defines time.
|
||||
*/
|
||||
typedef struct {
|
||||
uint64_t sec; /**< Second */
|
||||
uint64_t usec; /**< Microsecond */
|
||||
} OsalTimespec;
|
||||
|
||||
/**
|
||||
* @brief Describes thread sleep, in seconds.
|
||||
*
|
||||
* When a thread invokes this function, the CPU is released and the thread enters the sleep state.
|
||||
*
|
||||
* @param sec Indicates the sleep time, in seconds.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void OsalSleep(uint32_t sec);
|
||||
|
||||
/**
|
||||
* @brief Describes thread sleep, in milliseconds.
|
||||
*
|
||||
* When a thread invokes this function, the CPU is released and the thread enters the sleep state.
|
||||
*
|
||||
* @param ms Indicates the sleep time, in milliseconds.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void OsalMSleep(uint32_t ms);
|
||||
|
||||
/**
|
||||
* @brief Obtains the second and microsecond time.
|
||||
*
|
||||
* @param time Indicates the pointer to the time structure {@link OsalTimespec}.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to obtain time.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalGetTime(OsalTimespec *time);
|
||||
|
||||
/**
|
||||
* @brief Obtains time difference.
|
||||
*
|
||||
* @param start Indicates the pointer to the start time {@link OsalTimespec}.
|
||||
* @param end Indicates the pointer to the end time {@link OsalTimespec}.
|
||||
* @param diff Indicates the pointer to the time difference {@link OsalTimespec}.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalDiffTime(const OsalTimespec *start, const OsalTimespec *end, OsalTimespec *diff);
|
||||
|
||||
/**
|
||||
* @brief Obtains the system time.
|
||||
*
|
||||
* @return Returns the system time, in milliseconds.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
uint64_t OsalGetSysTimeMs(void);
|
||||
|
||||
/**
|
||||
* @brief Describes thread delay, in milliseconds.
|
||||
*
|
||||
* When a thread invokes this function, the CPU is not released. This function returns after waiting for milliseconds.
|
||||
*
|
||||
* @param ms Indicates the delay time, in milliseconds.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void OsalMDelay(uint32_t ms);
|
||||
|
||||
/**
|
||||
* @brief Describes thread delay, in microseconds.
|
||||
*
|
||||
* When a thread invokes this function, the CPU is not released. This function returns after waiting for microseconds.
|
||||
*
|
||||
* @param us Indicates the delay time, in microseconds.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void OsalUDelay(uint32_t us);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OSAL_TIME_H */
|
||||
/** @} */
|
||||
Executable
+176
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup OSAL
|
||||
* @{
|
||||
*
|
||||
* @brief Defines the structures and interfaces for the Operating System Abstraction Layer (OSAL) module.
|
||||
*
|
||||
* The OSAL module harmonizes OS interface differences and provides unified OS interfaces externally,
|
||||
* including the memory management, thread, mutex, spinlock, semaphore, timer, file, interrupt, time,
|
||||
* atomic, firmware, and I/O operation modules.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file osal_timer.h
|
||||
*
|
||||
* @brief Declares timer types and interfaces.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef OSAL_TIMER_H
|
||||
#define OSAL_TIMER_H
|
||||
|
||||
#include "hdf_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Describes a timer.
|
||||
*/
|
||||
typedef struct {
|
||||
void *realTimer; /**< Pointer to a timer object */
|
||||
} OsalTimer;
|
||||
|
||||
/**
|
||||
* @brief Describes a timer execution function type.
|
||||
*/
|
||||
typedef void (*OsalTimerFunc)(uintptr_t arg);
|
||||
|
||||
/**
|
||||
* @brief Defines a timer macro.
|
||||
*/
|
||||
#define OSAL_DECLARE_TIMER(timer) OsalTimer timer
|
||||
|
||||
/**
|
||||
* @brief Creates a timer.
|
||||
*
|
||||
* @param timer Indicates the pointer to the timer {@link OsalTimer}.
|
||||
* @param interval Indicates the timer interval.
|
||||
* @param func Indicates the timer execution function {@link OsalTimerFunc}.
|
||||
* @param arg Indicates the argument passed to the timer execution function.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
* HDF_ERR_MALLOC_FAIL | Memory allocation fails.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalTimerCreate(OsalTimer *timer, uint32_t interval, OsalTimerFunc func, uintptr_t arg);
|
||||
|
||||
/**
|
||||
* @brief Deletes a timer.
|
||||
*
|
||||
* @param timer Indicates the pointer to the timer {@link OsalTimer}.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to delete the timer.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalTimerDelete(OsalTimer *timer);
|
||||
|
||||
/**
|
||||
* @brief Starts a timer.
|
||||
*
|
||||
* @param timer Indicates the pointer to the timer {@link OsalTimer}.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to start the timer.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalTimerStartOnce(OsalTimer *timer);
|
||||
|
||||
/**
|
||||
* @brief Starts a periodic timer.
|
||||
*
|
||||
* @param timer Indicates the pointer to the timer {@link OsalTimer}.
|
||||
* @param interval Indicates the timer interval, in milliseconds.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function to start the timer.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalTimerStartLoop(OsalTimer *timer);
|
||||
|
||||
/**
|
||||
* @brief Sets the interval of a timer.
|
||||
*
|
||||
* @param timer Indicates the pointer to the timer {@link OsalTimer}.
|
||||
* @param interval Indicates the timer interval, in milliseconds.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_FAILURE | Failed to invoke the system function.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalTimerSetTimeout(OsalTimer *timer, uint32_t interval);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OSAL_TIMER_H */
|
||||
/** @} */
|
||||
Executable
+215
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup GPIO
|
||||
* @{
|
||||
*
|
||||
* @brief Provides standard general-purpose input/output (GPIO) interfaces for driver development.
|
||||
*
|
||||
* You can use this module to perform operations on a GPIO pin, including setting the input/output direction,
|
||||
* reading/writing the level value, and setting the interrupt service routine (ISR) function.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file gpio_if.h
|
||||
*
|
||||
* @brief Declares the standard GPIO interface functions.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
#ifndef GPIO_IF_H
|
||||
#define GPIO_IF_H
|
||||
|
||||
#include "hdf_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Enumerates GPIO level values.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
enum GpioValue {
|
||||
GPIO_VAL_LOW = 0, /**< Low GPIO level */
|
||||
GPIO_VAL_HIGH = 1, /**< High GPIO level */
|
||||
GPIO_VAL_ERR, /**< Invalid GPIO level */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Enumerates GPIO directions.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
enum GpioDirType {
|
||||
GPIO_DIR_IN = 0, /**< Input direction */
|
||||
GPIO_DIR_OUT = 1, /**< Output direction */
|
||||
GPIO_DIR_ERR, /**< Invalid direction */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines the function type of a GPIO interrupt service routine (ISR).
|
||||
*
|
||||
* This function is used when you call {@link GpioSetIrq} to register the ISR for a GPIO pin.
|
||||
*
|
||||
* @param gpio Indicates the GPIO number of the ISR.
|
||||
* @param data Indicates the pointer to the private data passed to this ISR (The data is specified when the ISR
|
||||
* is registered).
|
||||
*
|
||||
* @return Returns <b>0</b> if the ISR function type is successfully defined; returns a negative value otherwise.
|
||||
* @see GpioSetIrq
|
||||
* @since 1.0
|
||||
*/
|
||||
typedef int32_t (*GpioIrqFunc)(uint16_t gpio, void *data);
|
||||
|
||||
/**
|
||||
* @brief Reads the level value of a GPIO pin.
|
||||
*
|
||||
* Before using this function, you need to call {@link GpioSetDir} to set the GPIO pin direction to input.
|
||||
*
|
||||
* @param gpio Indicates the GPIO pin number.
|
||||
* @param val Indicates the pointer to the read level value. For details, see {@link GpioValue}.
|
||||
*
|
||||
* @return Returns <b>0</b> if the GPIO pin level value is successfully read; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t GpioRead(uint16_t gpio, uint16_t *val);
|
||||
|
||||
/**
|
||||
* @brief Writes the level value for a GPIO pin.
|
||||
*
|
||||
* Before using this function, you need to call {@link GpioSetDir} to set the GPIO pin direction to output.
|
||||
*
|
||||
* @param gpio Indicates the GPIO pin number.
|
||||
* @param val Indicates the level value to be written. For details, see {@link GpioValue}.
|
||||
*
|
||||
* @return Returns <b>0</b> if the GPIO pin level value is successfully written; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t GpioWrite(uint16_t gpio, uint16_t val);
|
||||
|
||||
/**
|
||||
* @brief Sets the input/output direction for a GPIO pin.
|
||||
*
|
||||
* Generally, you can set the direction to input when external level signals need to be read, and set the
|
||||
* direction to output when the level signals need to be sent externally.
|
||||
*
|
||||
* @param gpio Indicates the GPIO pin number.
|
||||
* @param dir Indicates the direction to set. For details, see {@link GpioDirType}.
|
||||
*
|
||||
* @return Returns <b>0</b> if the GPIO pin direction is successfully set; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t GpioSetDir(uint16_t gpio, uint16_t dir);
|
||||
|
||||
/**
|
||||
* @brief Obtains the input/output direction of a GPIO pin.
|
||||
*
|
||||
* @param gpio Indicates the GPIO pin number.
|
||||
* @param dir Indicates the pointer to the obtained input/output direction. For details, see {@link GpioDirType}.
|
||||
*
|
||||
* @return Returns <b>0</b> if the GPIO pin direction is successfully obtained; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t GpioGetDir(uint16_t gpio, uint16_t *dir);
|
||||
|
||||
/**
|
||||
* @brief Sets the ISR function for a GPIO pin.
|
||||
*
|
||||
* Before using a GPIO pin as an interrupt, you must call this function to set an ISR function for this GPIO pin,
|
||||
* including the ISR parameters and the interrupt trigger mode.
|
||||
* After the setting is successful, you also need to call {@link GpioEnableIrq} to enable the interrupt, so that
|
||||
* the ISR function can respond correctly.
|
||||
*
|
||||
* @param gpio Indicates the GPIO pin number.
|
||||
* @param mode Indicates the interrupt trigger mode. For details, see {@link OSAL_IRQF_TRIGGER_RISING}.
|
||||
* @param func Indicates the ISR function to set, which is specified by {@link GpioIrqFunc}.
|
||||
* @param arg Indicates the pointer to the parameters passed to the ISR function.
|
||||
*
|
||||
* @return Returns <b>0</b> if the ISR function of the GPIO pin is successfully set; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t GpioSetIrq(uint16_t gpio, uint16_t mode, GpioIrqFunc func, void *arg);
|
||||
|
||||
/**
|
||||
* @brief Cancels the setting of the ISR function for a GPIO pin.
|
||||
*
|
||||
* If you do not need the GPIO pin as an interrupt, call this function to cancel the ISR function set via
|
||||
* {@link GpioSetIrq}. Since this ISR function is no longer valid, you are advised to use {@link GpioDisableIrq} to
|
||||
* disable the GPIO pin interrupt.
|
||||
*
|
||||
* @param gpio Indicates the GPIO pin number.
|
||||
*
|
||||
* @return Returns <b>0</b> if the ISR function of the GPIO pin is successfully cancelled; returns a negative value
|
||||
* otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t GpioUnSetIrq(uint16_t gpio);
|
||||
|
||||
/**
|
||||
* @brief Enables a GPIO pin interrupt.
|
||||
*
|
||||
* Before enabling the interrupt, you must call {@link GpioSetIrq} to set the ISR function for the GPIO pin.
|
||||
*
|
||||
* @param gpio Indicates the GPIO pin number.
|
||||
*
|
||||
* @return Returns <b>0</b> if the GPIO pin interrupt is successfully enabled; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t GpioEnableIrq(uint16_t gpio);
|
||||
|
||||
/**
|
||||
* @brief Disables a GPIO pin interrupt.
|
||||
*
|
||||
* You can call this function when you need to temporarily mask a GPIO pin interrupt or cancel an ISR function.
|
||||
*
|
||||
* @param gpio Indicates the GPIO pin number.
|
||||
*
|
||||
* @return Returns <b>0</b> if the GPIO pin interrupt is successfully disabled; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t GpioDisableIrq(uint16_t gpio);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* GPIO_IF_H */
|
||||
/** @} */
|
||||
Executable
+82
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup COMMON
|
||||
* @{
|
||||
*
|
||||
* @brief Provides common APIs of the platform driver.
|
||||
*
|
||||
* This module also provides <b>DevHandle</b>, which represents the common data structure of the platform driver.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file hdf_platform.h
|
||||
*
|
||||
* @brief Declares common APIs of the platform driver.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
#ifndef HDF_PLATFORM_H
|
||||
#define HDF_PLATFORM_H
|
||||
|
||||
#include "hdf_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Defines the common device handle of the platform driver.
|
||||
*
|
||||
* The handle is associated with a specific platform device and is used as the
|
||||
* first input parameter for all APIs of the platform driver.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct DevHandle {
|
||||
/** Pointer to a specific platform device */
|
||||
void *object;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* HDF_PLATFORM_H */
|
||||
/** @} */
|
||||
Executable
+169
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup I2C
|
||||
* @{
|
||||
*
|
||||
* @brief Provides standard Inter-Integrated Circuit (I2C) interfaces.
|
||||
*
|
||||
* This module allows a driver to perform operations on an I2C controller for accessing devices on the I2C bus,
|
||||
* including creating and destroying I2C controller handles as well as reading and writing data.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file i2c_if.h
|
||||
*
|
||||
* @brief Declares the standard I2C interface functions.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
#ifndef I2C_IF_H
|
||||
#define I2C_IF_H
|
||||
|
||||
#include "hdf_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Defines the I2C transfer message used during custom transfers.
|
||||
*
|
||||
* @attention This structure does not limit the data transfer length specified by <b>len</b>.
|
||||
* The specific I2C controller determines the maximum length allowed. \n
|
||||
* The device address <b>addr</b> indicates the original device address and does not need to
|
||||
* contain the read/write flag bit.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct I2cMsg {
|
||||
/** Address of the I2C device */
|
||||
uint16_t addr;
|
||||
/** Address of the buffer for storing transferred data */
|
||||
uint8_t *buf;
|
||||
/** Length of the transferred data */
|
||||
uint16_t len;
|
||||
/**
|
||||
* Transfer Mode Flag | Description
|
||||
* ------------| -----------------------
|
||||
* I2C_FLAG_READ | Read flag
|
||||
* I2C_FLAG_ADDR_10BIT | 10-bit addressing flag
|
||||
* I2C_FLAG_READ_NO_ACK | No-ACK read flag
|
||||
* I2C_FLAG_IGNORE_NO_ACK | Ignoring no-ACK flag
|
||||
* I2C_FLAG_NO_START | No START condition flag
|
||||
* I2C_FLAG_STOP | STOP condition flag
|
||||
*/
|
||||
uint16_t flags;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Enumerates flags used for transferring I2C messages.
|
||||
*
|
||||
* Multiple flags can be used to jointly control a single I2C message transfer.
|
||||
* If a bit is set to <b>1</b>, the corresponding feature is enabled. If a bit is set to <b>0</b>,
|
||||
* the corresponding feature is disabled.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
enum I2cFlag {
|
||||
/** Read flag. The value <b>1</b> indicates the read operation, and <b>0</b> indicates the write operation. */
|
||||
I2C_FLAG_READ = (0x1 << 0),
|
||||
/** 10-bit addressing flag. The value <b>1</b> indicates that a 10-bit address is used. */
|
||||
I2C_FLAG_ADDR_10BIT = (0x1 << 4),
|
||||
/** Non-ACK read flag. The value <b>1</b> indicates that no ACK signal is sent during the read process. */
|
||||
I2C_FLAG_READ_NO_ACK = (0x1 << 11),
|
||||
/** Ignoring no-ACK flag. The value <b>1</b> indicates that the non-ACK signal is ignored. */
|
||||
I2C_FLAG_IGNORE_NO_ACK = (0x1 << 12),
|
||||
/**
|
||||
* No START condition flag. The value <b>1</b> indicates that there is no START condition for the message
|
||||
* transfer.
|
||||
*/
|
||||
I2C_FLAG_NO_START = (0x1 << 14),
|
||||
/** STOP condition flag. The value <b>1</b> indicates that the current transfer ends with a STOP condition. */
|
||||
I2C_FLAG_STOP = (0x1 << 15),
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Obtains the handle of an I2C controller.
|
||||
*
|
||||
* You must call this function before accessing the I2C bus.
|
||||
*
|
||||
* @param number Indicates the I2C controller ID.
|
||||
*
|
||||
* @return Returns the pointer to the {@link DevHandle} of the I2C controller if the operation is successful;
|
||||
* returns <b>NULL</b> otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
struct DevHandle *I2cOpen(int16_t number);
|
||||
|
||||
/**
|
||||
* @brief Releases the handle of an I2C controller.
|
||||
*
|
||||
* If you no longer need to access the I2C controller, you should call this function to close its handle so as
|
||||
* to release unused memory resources.
|
||||
*
|
||||
* @param handle Indicates the pointer to the device handle of the I2C controller.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void I2cClose(struct DevHandle *handle);
|
||||
|
||||
/**
|
||||
* @brief Launches a custom transfer to an I2C device.
|
||||
*
|
||||
* @param handle Indicates the pointer to the device handle of the I2C controller obtained via {@link I2cOpen}.
|
||||
* @param msgs Indicates the pointer to the I2C transfer message structure array.
|
||||
* @param count Indicates the length of the message structure array.
|
||||
*
|
||||
* @return Returns the number of transferred message structures if the operation is successful;
|
||||
* returns a negative value otherwise.
|
||||
* @see I2cMsg
|
||||
* @attention This function does not limit the number of message structures specified by <b>count</b> or the data
|
||||
* length of each message structure. The specific I2C controller determines the maximum number and data length allowed.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t I2cTransfer(struct DevHandle *handle, struct I2cMsg *msgs, int16_t count);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* I2C_IF_H */
|
||||
/** @} */
|
||||
Executable
+289
@@ -0,0 +1,289 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup RTC
|
||||
* @{
|
||||
*
|
||||
* @brief Provides standard real-time clock (RTC) APIs.
|
||||
*
|
||||
* These APIs allow you to perform operations such as reading or writing system time, reading or writing alarm time,
|
||||
* setting alarm interrupts, registering alarm callbacks, setting the external frequency, resetting the RTC driver,
|
||||
* and customizing RTC configurations. \n
|
||||
* The RTC driver provides precise real time for the operating system (OS). If the OS is powered off, the RTC driver
|
||||
* continues to keep track of the system time using an external battery.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file rtc_if.h
|
||||
*
|
||||
* @brief Declares the standard RTC APIs.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
#ifndef RTC_IF_H
|
||||
#define RTC_IF_H
|
||||
|
||||
#include "hdf_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Enumerates alarm indexes.
|
||||
*
|
||||
* The alarm indexes will be used when you perform operations related to alarms.
|
||||
*
|
||||
* @since V1.0
|
||||
*/
|
||||
enum RtcAlarmIndex {
|
||||
RTC_ALARM_INDEX_A = 0, /**< Index of alarm A */
|
||||
RTC_ALARM_INDEX_B = 1, /**< Index of alarm B */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines a callback that will be invoked when an alarm is generated at the specified time.
|
||||
*
|
||||
*/
|
||||
typedef int32_t (*RtcAlarmCallback)(enum RtcAlarmIndex);
|
||||
|
||||
/**
|
||||
* @brief Defines the RTC information.
|
||||
*
|
||||
* The RTC information includes the year, month, day, day of the week, hour, minute, second, and millisecond.
|
||||
* The start time is 1970/01/01 Thursday 00:00:00 (UTC).
|
||||
*/
|
||||
struct RtcTime {
|
||||
uint8_t second; /**< Second. The value ranges from 0 to 59. */
|
||||
uint8_t minute; /**< Minute. The value ranges from 0 to 59. */
|
||||
uint8_t hour; /**< Hour. The value ranges from 0 to 23. */
|
||||
uint8_t day; /**< Day. The value ranges from 1 to 31. */
|
||||
uint8_t weekday; /**< Day of the week. The value ranges from 1 to 7, representing Monday to Sunday. */
|
||||
uint8_t month; /**< Month. The value ranges from 1 to 12. */
|
||||
uint16_t year; /**< Year. The value is greater than or equal to 1970. */
|
||||
uint16_t millisecond; /**< Millisecond. The value ranges from 0 to 990, with a precision of 10 milliseconds. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Opens the RTC device to obtain its handle.
|
||||
*
|
||||
* The OS supports only one RTC device.
|
||||
*
|
||||
* @return Returns {@link DevHandle} if the operation is successful; returns <b>NULL</b> if the operation fails.
|
||||
* @since 1.0
|
||||
*/
|
||||
struct DevHandle *RtcOpen(void);
|
||||
|
||||
/**
|
||||
* @brief Releases a specified handle of the RTC device.
|
||||
*
|
||||
* @param handle Indicates the pointer to the RTC device handle to release, which is created via {@link RtcGetHandle}.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void RtcClose(struct DevHandle *handle);
|
||||
|
||||
/**
|
||||
* @brief Reads time from the RTC driver.
|
||||
*
|
||||
* The time information includes the year, month, day, day of the week, hour, minute, second, and millisecond.
|
||||
*
|
||||
* @param handle Indicates the pointer to the RTC device handle, which is obtained via {@link RtcGetHandle}.
|
||||
* @param time Indicates the pointer to the time information read from the RTC driver.
|
||||
* For details, see {@link RtcTime}.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* For details, see {@link HDF_STATUS}.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t RtcReadTime(struct DevHandle *handle, struct RtcTime *time);
|
||||
|
||||
/**
|
||||
* @brief Writes format-compliant time to the RTC driver.
|
||||
*
|
||||
* Note that the RTC start time is 1970/01/01 Thursday 00:00:00 (UTC). Set the maximum value of <b>year</b> based on
|
||||
* the requirements specified in the product manual of the in-use component.
|
||||
*
|
||||
* @param handle Indicates the pointer to the RTC device handle, which is obtained via {@link RtcGetHandle}.
|
||||
* @param time Indicates the pointer to the time information to write. For details, see {@link RtcTime}.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* For details, see {@link HDF_STATUS}.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t RtcWriteTime(struct DevHandle *handle, const struct RtcTime *time);
|
||||
|
||||
/**
|
||||
* @brief Reads the RTC alarm time that was set last time.
|
||||
*
|
||||
* @param handle Indicates the pointer to the RTC device handle, which is obtained via {@link RtcGetHandle}.
|
||||
* @param alarmIndex Indicates the RTC alarm index. For details, see {@link RtcAlarmIndex}.
|
||||
* @param time Indicates the pointer to the RTC alarm time information. For details, see {@link RtcTime}.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* For details, see {@link HDF_STATUS}.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t RtcReadAlarm(struct DevHandle *handle, enum RtcAlarmIndex alarmIndex, struct RtcTime *time);
|
||||
|
||||
/**
|
||||
* @brief Writes the RTC alarm time based on the alarm index.
|
||||
*
|
||||
* Note that the RTC start time is 1970/01/01 Thursday 00:00:00 (UTC). Set the maximum value of <b>year</b> based on
|
||||
* the requirements specified in the product manual of the in-use component.
|
||||
*
|
||||
* @param handle Indicates the pointer to the RTC device handle, which is obtained via {@link RtcGetHandle}.
|
||||
* @param alarmIndex Indicates the RTC alarm index. For details, see {@link RtcAlarmIndex}.
|
||||
* @param tm Indicates the pointer to the RTC alarm time information. For details, see {@link RtcTime}.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* For details, see {@link HDF_STATUS}.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t RtcWriteAlarm(struct DevHandle *handle, enum RtcAlarmIndex alarmIndex, const struct RtcTime *time);
|
||||
|
||||
/**
|
||||
* @brief Registers {@link RtcAlarmCallback} that will be invoked when an alarm is generated at the specified time.
|
||||
*
|
||||
* @param handle Indicates the pointer to the RTC device handle, which is obtained via {@link RtcGetHandle}.
|
||||
* @param alarmIndex Indicates the RTC alarm index. For details, see {@link RtcAlarmIndex}.
|
||||
* @param cb Indicates the callback to register. For details, see {@link RtcAlarmCallback}.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* For details, see {@link HDF_STATUS}.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t RtcRegisterAlarmCallback(struct DevHandle *handle, enum RtcAlarmIndex alarmIndex, RtcAlarmCallback cb);
|
||||
|
||||
/**
|
||||
* @brief Enables or disables alarm interrupts.
|
||||
*
|
||||
* Before performing alarm operations, you need to call this function to enable alarm interrupts,
|
||||
* so that the {@link RtcRegisterAlarmCallback} will be called when the alarm is not generated upon a timeout.
|
||||
*
|
||||
* @param handle Indicates the pointer to the RTC device handle, which is obtained via {@link RtcGetHandle}.
|
||||
* @param alarmIndex Indicates the RTC alarm index. For details, see {@link RtcAlarmIndex}.
|
||||
* @param enable Specifies whether to enable RTC alarm interrupts. The value <b>1</b> means to
|
||||
* enable alarm interrupts and value <b>0</b> means to disable alarm interrupts.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* For details, see {@link HDF_STATUS}.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t RtcAlarmInterruptEnable(struct DevHandle *handle, enum RtcAlarmIndex alarmIndex, uint8_t enable);
|
||||
|
||||
/**
|
||||
* @brief Reads the RTC external frequency.
|
||||
*
|
||||
* This function reads the frequency of the external crystal oscillator connected to the RTC driver.
|
||||
*
|
||||
* @param handle Indicates the pointer to the RTC device handle, which is obtained via {@link RtcGetHandle}.
|
||||
* @param freq Indicates the pointer to the frequency of the external crystal oscillator, in Hz.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* For details, see {@link HDF_STATUS}.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t RtcGetFreq(struct DevHandle *handle, uint32_t *freq);
|
||||
|
||||
/**
|
||||
* @brief Sets the frequency of the external crystal oscillator connected to the RTC driver.
|
||||
*
|
||||
* Note that the frequency must be configured in accordance with the requirements specified in the product manual of
|
||||
* the in-use component.
|
||||
*
|
||||
* @param handle Indicates the pointer to the RTC device handle, which is obtained via {@link RtcGetHandle}.
|
||||
* @param freq Indicates the frequency to set for the external crystal oscillator, in Hz.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* For details, see {@link HDF_STATUS}.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t RtcSetFreq(struct DevHandle *handle, uint32_t freq);
|
||||
|
||||
/**
|
||||
* @brief Resets the RTC driver.
|
||||
*
|
||||
* After the reset, the configuration registers are restored to the default values.
|
||||
*
|
||||
* @param handle Indicates the pointer to the RTC device handle, which is obtained via {@link RtcGetHandle}.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* For details, see {@link HDF_STATUS}.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t RtcReset(struct DevHandle *handle);
|
||||
|
||||
/**
|
||||
* @brief Reads the configuration of a custom RTC register based on the register index.
|
||||
*
|
||||
* One index corresponds to one byte of the configuration value.
|
||||
*
|
||||
* @param handle Indicates the pointer to the RTC device handle, which is obtained via {@link RtcGetHandle}.
|
||||
* @param usrDefIndex Indicates the index of the custom register.
|
||||
* @param value Indicates the pointer to the configuration value of the specified register index.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* For details, see {@link HDF_STATUS}.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t RtcReadReg(struct DevHandle *handle, uint8_t usrDefIndex, uint8_t *value);
|
||||
|
||||
/**
|
||||
* @brief Writes the configuration of a custom RTC register based on the register index.
|
||||
*
|
||||
* One index corresponds to one byte of the configuration value.
|
||||
*
|
||||
* @param handle Indicates the pointer to the RTC device handle, which is obtained via {@link RtcGetHandle}.
|
||||
* @param usrDefIndex Indicates the index of the custom register.
|
||||
* @param value Indicates the configuration value to write at the index of the register.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* For details, see {@link HDF_STATUS}.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t RtcWriteReg(struct DevHandle *handle, uint8_t usrDefIndex, uint8_t value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* RTC_IF_H */
|
||||
/** @} */
|
||||
|
||||
Executable
+398
@@ -0,0 +1,398 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup SDIO
|
||||
* @{
|
||||
*
|
||||
* @brief Declares standard APIs of basic secure digital input and output (SDIO) capabilities.
|
||||
*
|
||||
* You can use this module to access the SDIO and enable the driver to operate an SDIO-compliant device.
|
||||
* These capabilities include reading and writing data based on SDIO, setting the block size,
|
||||
* applying for and releasing interrupts, enabling and disabling devices, and occupying and releasing the bus.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file sdio_if.h
|
||||
*
|
||||
* @brief Declares the standard SDIO APIs.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
#ifndef SDIO_IF_H
|
||||
#define SDIO_IF_H
|
||||
|
||||
#include "hdf_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Enumerates SDIO common information types.
|
||||
*
|
||||
* When obtaining SDIO common information by calling {@link SdioGetCommonInfo} or setting the information
|
||||
* by calling {@link SdioSetCommonInfo}, you need to pass the information type.
|
||||
*/
|
||||
typedef enum {
|
||||
SDIO_FUNC_INFO = 0, /**< Functionality information */
|
||||
SDIO_OTHER_INFO, /**< Other information */
|
||||
} SdioCommonInfoType;
|
||||
|
||||
/**
|
||||
* @brief Defines the SDIO capabilities.
|
||||
*
|
||||
* You can obtain and set the SDIO capabilities by calling {@link SdioGetCommonInfo} and {@link SdioSetCommonInfo}
|
||||
* with {@link SdioCommonInfo} and {@link SdioCommonInfoType} passed.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t maxBlockNum; /**< Maximum number of blocks in a request */
|
||||
uint32_t maxBlockSize; /**< Maximum number of bytes in a block.
|
||||
* The value ranges from <b>1</b> to <b>2048</b>.
|
||||
*/
|
||||
uint32_t maxRequestSize; /**< Maximum number of bytes in a request.
|
||||
* The value ranges from <b>1</b> to <b>2048</b>.
|
||||
*/
|
||||
uint32_t enTimeout; /**< Maximum timeout duration, in milliseconds.
|
||||
* The value cannot exceed <b>1</b> second.
|
||||
*/
|
||||
uint32_t funcNum; /**< Functionality number, ranging from <b>1</b> to <b>7</b>. */
|
||||
uint32_t irqCap; /**< IRQ capabilities */
|
||||
void *data; /**< Private data */
|
||||
} SdioFuncInfo;
|
||||
|
||||
/**
|
||||
* @brief Defines SDIO common information.
|
||||
*
|
||||
* You can obtain and set common SDIO information by calling {@link SdioGetCommonInfo} and {@link SdioSetCommonInfo}
|
||||
* with {@link SdioCommonInfo} and {@link SdioCommonInfoType} passed.
|
||||
*/
|
||||
typedef union {
|
||||
SdioFuncInfo funcInfo; /**< Functionality information */
|
||||
} SdioCommonInfo;
|
||||
|
||||
/**
|
||||
* @brief Defines the function type of an SDIO IRQ.
|
||||
*
|
||||
* This function is registered when you call {@link SdioClaimIrq} to request the SDIO IRQ.
|
||||
*
|
||||
* @param data Indicates the private data passed to this IRQ (The data is specified when the IRQ is registered).
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
typedef void SdioIrqHandler(void *);
|
||||
|
||||
/**
|
||||
* @brief Opens an SDIO controller with a specified bus number.
|
||||
*
|
||||
* Before using the SDIO interface, you can obtain the device handle of the SDIO controller
|
||||
* by calling {@link SdioOpen}. This function is used in pair with {@link SdioClose}.
|
||||
*
|
||||
* @param busNum Indicates the bus number.
|
||||
*
|
||||
* @return Returns the device handle {@link DevHandle} of the SDIO controller if the operation is successful;
|
||||
* returns <b>NULL</b> otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
struct DevHandle *SdioOpen(int16_t busNum);
|
||||
|
||||
/**
|
||||
* @brief Closes an SDIO controller.
|
||||
*
|
||||
* After the SDIO interface is used, you can close the SDIO controller by calling {@link SdioClose}.
|
||||
* This function is used in pair with {@link SdioOpen}.
|
||||
*
|
||||
* @param handle Indicates the pointer to the device handle of the SDIO controller.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void SdioClose(struct DevHandle *handle);
|
||||
|
||||
/**
|
||||
* @brief Incrementally reads a given length of data from the specified SDIO address.
|
||||
*
|
||||
* If the length of the data to read is greater than the size of a block, the data is read by block,
|
||||
* and the remaining data that is smaller than one block is read by byte. Otherwise, data is read by byte.
|
||||
*
|
||||
* @param handle Indicates the pointer to the device handle of the SDIO controller obtained by {@link SdioOpen}.
|
||||
* @param data Indicates the pointer to the data to read.
|
||||
* @param addr Indicates the start address of the data to read.
|
||||
* @param size Indicates the length of the data to read.
|
||||
* @param timeOut Indicates the timeout duration for reading data, in milliseconds.
|
||||
* If the value is <b>0</b>,the default value is used. The default value varies according to the application.
|
||||
* Generally, the default value is <b>1</b> second.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t SdioReadBytes(struct DevHandle *handle, uint8_t *data, uint32_t addr,
|
||||
uint32_t size, uint32_t timeOut);
|
||||
|
||||
/**
|
||||
* @brief Incrementally writes a given length of data into the specified SDIO address.
|
||||
*
|
||||
* If the length of the data to write is greater than the size of a block, the data is written by block first,
|
||||
* and the remaining data that is smaller than one block is written by byte. Otherwise, data is written by byte.
|
||||
*
|
||||
* @param handle Indicates the pointer to the device handle of the SDIO controller obtained by {@link SdioOpen}.
|
||||
* @param data Indicates the pointer to the data to write.
|
||||
* @param addr Indicates the start address of the data to write.
|
||||
* @param size Indicates the length of the data to write.
|
||||
* @param timeOut Indicates the timeout duration for writing data, in milliseconds.
|
||||
* If the value is <b>0</b>, the default value is used. The default value varies according to the application.
|
||||
* Generally, the default value is <b>1</b> second.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t SdioWriteBytes(struct DevHandle *handle, uint8_t *data, uint32_t addr,
|
||||
uint32_t size, uint32_t timeOut);
|
||||
|
||||
/**
|
||||
* @brief Reads a given length of data from the fixed SDIO address.
|
||||
*
|
||||
* If the length of the data to read is greater than the size of a block, the data is read by block,
|
||||
* and the remaining data that is smaller than one block is read by byte. Otherwise, data is read by byte.
|
||||
*
|
||||
* @param handle Indicates the pointer to the device handle of the SDIO controller obtained by {@link SdioOpen}.
|
||||
* @param data Indicates the pointer to the data to read.
|
||||
* @param addr Indicates the fixed address of the data to read.
|
||||
* @param size Indicates the length of the data to read.
|
||||
* @param timeOut Indicates the timeout duration for reading data, in milliseconds.
|
||||
* If the value is <b>0</b>, the default value is used. The default value varies according to the application.
|
||||
* Generally, the default value is <b>1</b> second.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t SdioReadBytesFromFixedAddr(struct DevHandle *handle, uint8_t *data,
|
||||
uint32_t addr, uint32_t size, uint32_t timeOut);
|
||||
|
||||
/**
|
||||
* @brief Writes a given length of data into the fixed SDIO address.
|
||||
*
|
||||
* If the length of the data to write is greater than the size of a block, the data is written by block first,
|
||||
* and the remaining data that is smaller than one block is written by byte. Otherwise, data is written by byte.
|
||||
*
|
||||
* @param handle Indicates the pointer to the device handle of the SDIO controller obtained by {@link SdioOpen}.
|
||||
* @param data Indicates the pointer to the data to write.
|
||||
* @param addr Indicates the fixed address of the data to write.
|
||||
* @param size Indicates the length of the data to write.
|
||||
* @param timeOut Indicates the timeout duration for writing data, in milliseconds.
|
||||
* If the value is <b>0</b>, the default value is used. The default value varies according to the application.
|
||||
* Generally, the default value is <b>1</b> second.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t SdioWriteBytesToFixedAddr(struct DevHandle *handle, uint8_t *data,
|
||||
uint32_t addr, uint32_t size, uint32_t timeOut);
|
||||
|
||||
/**
|
||||
* @brief Reads a given length of data from the address space of SDIO function 0.
|
||||
*
|
||||
* Currently, only one byte of data can be read.
|
||||
*
|
||||
* @param handle Indicates the pointer to the device handle of the SDIO controller obtained by {@link SdioOpen}.
|
||||
* @param data Indicates the pointer to the data to read.
|
||||
* @param addr Indicates the start address of the data to read.
|
||||
* @param size Indicates the length of the data to read.
|
||||
* @param timeOut Indicates the timeout duration for reading data, in milliseconds.
|
||||
* If the value is <b>0</b>, the default value is used. The default value varies according to the application.
|
||||
* Generally, the default value is <b>1</b> second.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t SdioReadBytesFromFunc0(struct DevHandle *handle, uint8_t *data,
|
||||
uint32_t addr, uint32_t size, uint32_t timeOut);
|
||||
|
||||
/**
|
||||
* @brief Writes a given length of data into the address space of SDIO function 0.
|
||||
*
|
||||
* Currently, only one byte of data can be written.
|
||||
*
|
||||
* @param handle Indicates the pointer to the device handle of the SDIO controller obtained by {@link SdioOpen}.
|
||||
* @param data Indicates the pointer to the data to write.
|
||||
* @param addr Indicates the start address of the data to write.
|
||||
* @param size Indicates the length of the data to write.
|
||||
* @param timeOut Indicates the timeout duration for writing data, in milliseconds.
|
||||
* If the value is <b>0</b>, the default value is used. The default value varies according to the application.
|
||||
* Generally, the default value is <b>1</b> second.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t SdioWriteBytesToFunc0(struct DevHandle *handle, uint8_t *data,
|
||||
uint32_t addr, uint32_t size, uint32_t timeOut);
|
||||
|
||||
/**
|
||||
* @brief Sets the block size.
|
||||
*
|
||||
* If data to read or write is performed, use this function to set the block size.
|
||||
*
|
||||
* @param handle Indicates the pointer to the device handle of the SDIO controller obtained by {@link SdioOpen}.
|
||||
* @param blockSize Indicates the block size to be set. If the value is <b>0</b>, the default value is used.
|
||||
* The value ranges from <b>1</b> to <b>2048</b> bytes.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t SdioSetBlockSize(struct DevHandle *handle, uint32_t blockSize);
|
||||
|
||||
/**
|
||||
* @brief Obtains common information.
|
||||
*
|
||||
* You can call this function to obtain the capabilities and private data of the I/O function.
|
||||
*
|
||||
* @param handle Indicates the pointer to the device handle of the SDIO controller obtained by {@link SdioOpen}.
|
||||
* @param info Indicates the pointer to the common information to be obtained.
|
||||
* For details, see {@link SdioCommonInfo}.
|
||||
* @param infoType Indicates the type of the common information to be obtained.
|
||||
* For details, see {@link SdioCommonInfoType}.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t SdioGetCommonInfo(struct DevHandle *handle, SdioCommonInfo *info, SdioCommonInfoType infoType);
|
||||
|
||||
/**
|
||||
* @brief Sets common information.
|
||||
*
|
||||
* You can call this function to set the maximum timeout duration and private data.
|
||||
*
|
||||
* @param handle Indicates the pointer to the device handle of the SDIO controller obtained by {@link SdioOpen}.
|
||||
* @param info Indicates the pointer to the common information to be set.
|
||||
* For details, see {@link SdioCommonInfo}.
|
||||
* @param infoType Indicates the type of the common information to be set.
|
||||
* For details, see {@link SdioCommonInfoType}.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t SdioSetCommonInfo(struct DevHandle *handle, SdioCommonInfo *info, SdioCommonInfoType infoType);
|
||||
|
||||
/**
|
||||
* @brief Flushes data.
|
||||
*
|
||||
* You can call this function when an SDIO needs to be reinitialized or an unexpected error occurs.
|
||||
*
|
||||
* @param handle Indicates the pointer to the device handle of the SDIO controller obtained by {@link SdioOpen}.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t SdioFlushData(struct DevHandle *handle);
|
||||
|
||||
/**
|
||||
* @brief Claims a host exclusively.
|
||||
*
|
||||
* You can call this function to enable the SDIO module to exclusively claim a host
|
||||
* and then perform operations on the devices connected to the host. After performing required operations,
|
||||
* release the host by calling {@link SdioReleaseHost}.
|
||||
*
|
||||
* @param handle Indicates the pointer to the device handle of the SDIO controller obtained by {@link SdioOpen}.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void SdioClaimHost(struct DevHandle *handle);
|
||||
|
||||
/**
|
||||
* @brief Releases the exclusively claimed host.
|
||||
*
|
||||
* This function is used in pair with {@link SdioClaimHost}.
|
||||
*
|
||||
* @param handle Indicates the pointer to the device handle of the SDIO controller obtained by {@link SdioOpen}.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void SdioReleaseHost(struct DevHandle *handle);
|
||||
|
||||
/**
|
||||
* @brief Enables the SDIO device so that its register can be accessed.
|
||||
*
|
||||
* @param handle Indicates the pointer to the device handle of the SDIO controller obtained by {@link SdioOpen}.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t SdioEnableFunc(struct DevHandle *handle);
|
||||
|
||||
/**
|
||||
* @brief Disables the SDIO device.
|
||||
*
|
||||
* This function is used in pair with {@link SdioEnableFunc}.
|
||||
*
|
||||
* @param handle Indicates the pointer to the device handle of the SDIO controller obtained by {@link SdioOpen}.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t SdioDisableFunc(struct DevHandle *handle);
|
||||
|
||||
/**
|
||||
* @brief Claims an SDIO IRQ.
|
||||
*
|
||||
* When there is data, commands, or events, the IRQ function is executed.
|
||||
*
|
||||
* @param handle Indicates the pointer to the device handle of the SDIO controller obtained by {@link SdioOpen}.
|
||||
* @param irqHandler Indicates the pointer to the SDIO IRQ function. For details, see {@link SdioIrqHandler}.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t SdioClaimIrq(struct DevHandle *handle, SdioIrqHandler *irqHandler);
|
||||
|
||||
/**
|
||||
* @brief Releases an SDIO IRQ.
|
||||
*
|
||||
* This function is used in pair with {@link SdioClaimIrq}.
|
||||
*
|
||||
* @param handle Indicates the pointer to the device handle of the SDIO controller obtained by {@link SdioOpen}.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value if the operation fails.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t SdioReleaseIrq(struct DevHandle *handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* SDIO_IF_H */
|
||||
/** @} */
|
||||
Executable
+283
@@ -0,0 +1,283 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup SPI
|
||||
* @{
|
||||
*
|
||||
* @brief Defines standard APIs of the Serial Peripheral Interface (SPI) capabilities.
|
||||
*
|
||||
* The SPI module abstracts the SPI capabilities of different system platforms to provide stable APIs
|
||||
* for driver development.
|
||||
* This module can create and destroy SPI device handles, read and write SPI data,
|
||||
* and obtain and set configuration parameters.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file spi_if.h
|
||||
*
|
||||
* @brief Defines standard SPI-specific interfaces for driver development.
|
||||
*
|
||||
* A driver needs to use the SPI-specific interfaces for data writing and reading
|
||||
* before performing any operations on an SPI-compliant device.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
#ifndef SPI_IF_H
|
||||
#define SPI_IF_H
|
||||
|
||||
#include "hdf_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Indicates the SPI clock phase. The value <b>0</b> indicates that data will be sampled on the first clock edge,
|
||||
* and <b>1</b> indicates that data will be sampled on the second clock edge.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define SPI_CLK_PHASE (1 << 0)
|
||||
/**
|
||||
* @brief Indicates the SPI clock polarity. The value <b>0</b> indicates a low-level clock signal in the idle state,
|
||||
* and <b>1</b> indicates a high-level clock signal in the idle state.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define SPI_CLK_POLARITY (1 << 1)
|
||||
/**
|
||||
* @brief Indicates that a single data line is used for both input and output.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define SPI_MODE_3WIRE (1 << 2)
|
||||
/**
|
||||
* @brief Indicates the SPI loopback mode.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define SPI_MODE_LOOP (1 << 3)
|
||||
/**
|
||||
* @brief Indicates the SPI data transfer order. The value <b>0</b> indicates that data is transferred from the most
|
||||
* significant bit (MSB) to the least significant bit (LSB), and <b>1</b> indicates the opposite.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define SPI_MODE_LSBFE (1 << 4)
|
||||
/**
|
||||
* @brief Indicates that there is only one SPI device, and no chip select (CS) is required.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define SPI_MODE_NOCS (1 << 5)
|
||||
/**
|
||||
* @brief Indicates that the CS level is high when an SPI device is selected.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define SPI_MODE_CS_HIGH (1 << 6)
|
||||
/**
|
||||
* @brief Indicates that the SPI device is set to low for pausing data transfer.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define SPI_MODE_READY (1 << 7)
|
||||
|
||||
/**
|
||||
* @brief Enumerates transfer modes of SPI data.
|
||||
*
|
||||
* @attention The specific SPI controller determines which variables in this structure are supported.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
enum SpiTransferMode {
|
||||
SPI_INTERRUPT_TRANSFER = 0, /**< Interrupt transfer mode */
|
||||
SPI_POLLING_TRANSFER, /**< Polling transfer mode */
|
||||
SPI_DMA_TRANSFER, /**< Direct Memory Access (DMA) transfer mode */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines the general SPI device descriptor, which can be used as the unique identifier of an SPI device.
|
||||
* When operating an SPI device, you need to specify a descriptor of the {@link SpiDevInfo} type, and obtain the
|
||||
* handle of the SPI device by calling {@link SpiOpen}.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct SpiDevInfo {
|
||||
uint32_t busNum; /**< SPI bus number */
|
||||
uint32_t csNum; /**< SPI device chip select (CS) */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines the custom SPI transfer message.
|
||||
*
|
||||
* @attention The specific SPI controller determines whether <b>speed</b>, <b>delayUs</b>,
|
||||
* and <b>csChange</b> are supported.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct SpiMsg {
|
||||
uint8_t *wbuf; /**< Address of the write buffer */
|
||||
uint8_t *rbuf; /**< Address of the read buffer */
|
||||
uint32_t len; /**< Length of the read and write buffers. The read buffer and the write
|
||||
* buffer have the same length.
|
||||
*/
|
||||
uint32_t speed; /**< Current message transfer speed */
|
||||
uint16_t delayUs; /**< Delay (in microseconds) before starting the next transfer.
|
||||
* The value <b>0</b> indicates there is no delay between transfers.
|
||||
*/
|
||||
uint8_t csChange; /**< Whether to switch off the CS before the next transfer when the current transfer has been
|
||||
* completed. <b>1</b> indicates to switch off the CS; <b>0</b> indicates to switch on the CS.
|
||||
*/
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines the configuration of an SPI device.
|
||||
*
|
||||
* @attention The specific SPI controller determines which variables in this structure are supported.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct SpiCfg {
|
||||
uint32_t maxSpeedHz; /**< Maximum clock frequency */
|
||||
uint16_t mode; /**< Input and output mode of SPI data | Description
|
||||
* -----------------| -----------------------
|
||||
* SPI_CLK_PHASE | SPI clock phase.
|
||||
* SPI_CLK_POLARITY | SPI clock polarity.
|
||||
* SPI_MODE_3WIRE | A single data line is used for both input and output.
|
||||
* SPI_MODE_LOOP | SPI loopback mode.
|
||||
* SPI_MODE_LSBFE | SPI data transfer order
|
||||
* SPI_MODE_NOCS | There is only one SPI device, and no CS is required.
|
||||
* SPI_MODE_CS_HIGH | The CS level is high when an SPI device is selected.
|
||||
* SPI_MODE_READY | The SPI device is set to low for pausing data transfer.
|
||||
*/
|
||||
uint8_t transferMode; /**< Data transfer mode, as defined in {@link SpiTransferMode}. */
|
||||
uint8_t bitsPerWord; /**< Data transfer bit width */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Obtains the handle of an SPI device.
|
||||
*
|
||||
* @param info Indicates the pointer to the SPI device information.
|
||||
*
|
||||
* @return Returns the pointer to the handle of the SPI device if the operation is successful;
|
||||
* returns <b>NULL</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct DevHandle *SpiOpen(const struct SpiDevInfo *info);
|
||||
|
||||
/**
|
||||
* @brief Releases the handle of an SPI device.
|
||||
*
|
||||
* @param handle Indicates the pointer to the SPI device handle obtained via {@link SpiOpen}.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void SpiClose(struct DevHandle *handle);
|
||||
|
||||
/**
|
||||
* @brief Launches a custom transfer to an SPI device.
|
||||
*
|
||||
* @param handle Indicates the pointer to the SPI device handle obtained via {@link SpiOpen}.
|
||||
* @param msgs Indicates the pointer to the data to transfer.
|
||||
* @param count Indicates the length of the message structure array.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
* @see SpiMsg
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t SpiTransfer(struct DevHandle *handle, struct SpiMsg *msgs, uint32_t count);
|
||||
|
||||
/**
|
||||
* @brief Reads data of a specified length from an SPI device.
|
||||
*
|
||||
* @param handle Indicates the pointer to the SPI device handle obtained via {@link SpiOpen}.
|
||||
* @param buf Indicates the pointer to the buffer for receiving the data.
|
||||
* @param len Indicates the length of the data to read.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t SpiRead(struct DevHandle *handle, uint8_t *buf, uint32_t len);
|
||||
|
||||
/**
|
||||
* @brief Writes data of a specified length to an SPI device.
|
||||
*
|
||||
* @param handle Indicates the pointer to the SPI device handle obtained via {@link SpiOpen}.
|
||||
* @param buf Indicates the pointer to the data to write.
|
||||
* @param len Indicates the length of the data to write.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t SpiWrite(struct DevHandle *handle, uint8_t *buf, uint32_t len);
|
||||
|
||||
/**
|
||||
* @brief Sets configuration parameters for an SPI device.
|
||||
*
|
||||
* @param handle Indicates the pointer to the SPI device handle obtained via {@link SpiOpen}.
|
||||
* @param cfg Indicates the pointer to the configuration parameters.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t SpiSetCfg(struct DevHandle *handle, struct SpiCfg *cfg);
|
||||
|
||||
/**
|
||||
* @brief Obtains the configuration parameters of an SPI device.
|
||||
*
|
||||
* @param handle Indicates the pointer to the SPI device handle obtained via {@link SpiOpen}.
|
||||
* @param cfg Indicates the pointer to the configuration parameters.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t SpiGetCfg(struct DevHandle *handle, struct SpiCfg *cfg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* SPI_IF_H */
|
||||
/** @} */
|
||||
Executable
+382
@@ -0,0 +1,382 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup UART
|
||||
* @{
|
||||
*
|
||||
* @brief Defines standard APIs of universal asynchronous receiver/transmitter (UART) capabilities.
|
||||
*
|
||||
* You can use this module to access the UART and enable the driver to operate a UART-compliant device.
|
||||
* The functions in this module help you to obtain and release the UART device handle, read and write data,
|
||||
* obtain and set the baud rate and device attributes.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file uart_if.h
|
||||
*
|
||||
* @brief Declares standard UART APIs.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
#ifndef UART_IF_H
|
||||
#define UART_IF_H
|
||||
|
||||
#include "hdf_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Defines basic attributes of the UART port.
|
||||
*
|
||||
* You can configure the attributes via {@link UartSetAttribute}. If the parameters are not set,
|
||||
* default attributes are used.
|
||||
*
|
||||
* @attention The UART controller determines which UART attribute parameters are supported.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct UartAttribute {
|
||||
/**
|
||||
* Data Bit | Description
|
||||
* ------------| -----------------------
|
||||
* UART_ATTR_DATABIT_8 | 8 data bits
|
||||
* UART_ATTR_DATABIT_7 | 7 data bits
|
||||
* UART_ATTR_DATABIT_6 | 6 data bits
|
||||
* UART_ATTR_DATABIT_5 | 5 data bits
|
||||
*/
|
||||
unsigned int dataBits : 4;
|
||||
/**
|
||||
* @brief Indicates the UART word length, which is 8 data bits per frame.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define UART_ATTR_DATABIT_8 0
|
||||
/**
|
||||
* @brief Indicates the UART word length, which is 7 data bits per frame.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define UART_ATTR_DATABIT_7 1
|
||||
/**
|
||||
* @brief Indicates the UART word length, which is 6 data bits per frame.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define UART_ATTR_DATABIT_6 2
|
||||
/**
|
||||
* @brief Indicates the UART word length, which is 5 data bits per frame.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define UART_ATTR_DATABIT_5 3
|
||||
/**
|
||||
* Parity Bit | Description
|
||||
* ------------| -----------------------
|
||||
* UART_ATTR_PARITY_NONE | No parity bit
|
||||
* UART_ATTR_PARITY_ODD | Odd parity bit
|
||||
* UART_ATTR_PARITY_EVEN | Even parity bit
|
||||
* UART_ATTR_PARITY_MARK | <b>1</b>
|
||||
* UART_ATTR_PARITY_SPACE | <b>0</b>
|
||||
*/
|
||||
unsigned int parity : 4;
|
||||
/**
|
||||
* @brief Indicates that the UART device has no parity bit.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define UART_ATTR_PARITY_NONE 0
|
||||
/**
|
||||
* @brief Indicates that the UART device has an odd parity bit.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define UART_ATTR_PARITY_ODD 1
|
||||
/**
|
||||
* @brief Indicates that the UART device has an even parity bit.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define UART_ATTR_PARITY_EVEN 2
|
||||
/**
|
||||
* @brief Indicates that the parity bit is 1.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define UART_ATTR_PARITY_MARK 3
|
||||
/**
|
||||
* @brief Indicates that the parity bit is 0.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define UART_ATTR_PARITY_SPACE 4
|
||||
/**
|
||||
* Stop Bit | Description
|
||||
* ------------| -----------------------
|
||||
* UART_ATTR_STOPBIT_1 | 1 stop bit
|
||||
* UART_ATTR_STOPBIT_1P5 | 1.5 stop bits
|
||||
* UART_ATTR_STOPBIT_2 | 2 stop bits
|
||||
*/
|
||||
unsigned int stopBits : 4;
|
||||
/**
|
||||
* @brief Indicates that the UART device has 1 stop bit.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define UART_ATTR_STOPBIT_1 0
|
||||
/**
|
||||
* @brief Indicates that the UART device has 1.5 stop bits.
|
||||
*
|
||||
* @since 1.0 */
|
||||
#define UART_ATTR_STOPBIT_1P5 1
|
||||
/**
|
||||
* @brief Indicates that the UART device has 2 stop bits.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define UART_ATTR_STOPBIT_2 2
|
||||
/**
|
||||
* RTS | Description
|
||||
* ------------| -----------------------
|
||||
* UART_ATTR_RTS_DIS | RTS disabled
|
||||
* UART_ATTR_RTS_EN | RTS enabled
|
||||
*/
|
||||
unsigned int rts : 1;
|
||||
/**
|
||||
* @brief Indicates that Request To Send (RTS) is disabled for the UART device.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define UART_ATTR_RTS_DIS 0
|
||||
/**
|
||||
* @brief Indicates that RTS is enabled for the UART device.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define UART_ATTR_RTS_EN 1
|
||||
/**
|
||||
* CTS | Description
|
||||
* ------------| -----------------------
|
||||
* UART_ATTR_CTS_DIS | CTS disabled
|
||||
* UART_ATTR_CTS_EN | CTS enabled
|
||||
*/
|
||||
unsigned int cts : 1;
|
||||
/**
|
||||
* @brief Indicates that Clear To Send (CTS) is disabled for the UART device.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define UART_ATTR_CTS_DIS 0
|
||||
/**
|
||||
* @brief Indicates that CTS is enabled for the UART device.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define UART_ATTR_CTS_EN 1
|
||||
/**
|
||||
* Receiver FIFO | Description
|
||||
* ------------| -----------------------
|
||||
* UART_ATTR_RX_FIFO_DIS | FIFO disabled
|
||||
* UART_ATTR_RX_FIFO_EN | FIFO enabled
|
||||
*/
|
||||
unsigned int fifoRxEn : 1;
|
||||
/**
|
||||
* @brief Indicates that First In First Out (FIFO) is disabled for the receiving UART.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define UART_ATTR_RX_FIFO_DIS 0
|
||||
/**
|
||||
* @brief Indicates that FIFO is enabled for the receiving UART.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define UART_ATTR_RX_FIFO_EN 1
|
||||
/**
|
||||
* Transmitter FIFO | Description
|
||||
* ------------| -----------------------
|
||||
* UART_ATTR_TX_FIFO_DIS | FIFO disabled
|
||||
* UART_ATTR_TX_FIFO_EN | FIFO enabled
|
||||
*/
|
||||
unsigned int fifoTxEn : 1;
|
||||
/**
|
||||
* @brief Indicates that FIFO is disabled for the transmitting UART.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define UART_ATTR_TX_FIFO_DIS 0
|
||||
/**
|
||||
* @brief Indicates that FIFO is enabled for the transmitting UART.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
#define UART_ATTR_TX_FIFO_EN 1
|
||||
/** Reserved bits */
|
||||
unsigned int reserved : 16;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Enumerates UART transmission modes.
|
||||
*
|
||||
* @attention The UART controller determines whether an enumerated transmission mode is supported.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
enum UartTransMode {
|
||||
UART_MODE_RD_BLOCK = 0, /**< Blocking mode */
|
||||
UART_MODE_RD_NONBLOCK, /**< Non-blocking mode */
|
||||
UART_MODE_DMA_RX_EN, /**< DMA enabled for data receiving */
|
||||
UART_MODE_DMA_RX_DIS, /**< DMA disabled for data receiving */
|
||||
UART_MODE_DMA_TX_EN, /**< DMA enabled for data transmitting */
|
||||
UART_MODE_DMA_TX_DIS, /**< DMA disabled for data transmitting */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Obtains the UART device handle.
|
||||
*
|
||||
* Before accessing the UART device, you must call this function to obtain the UART device handle.
|
||||
*
|
||||
* @param port Indicates the UART port.
|
||||
*
|
||||
* @return Returns the pointer to the UART device handle if the handle is obtained; returns <b>NULL</b> otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
struct DevHandle *UartOpen(uint32_t port);
|
||||
|
||||
/**
|
||||
* @brief Releases the UART device handle.
|
||||
*
|
||||
* If you no longer need to access the UART device, you should call this function to close its handle so as to
|
||||
* release unused memory resources.
|
||||
*
|
||||
* @param handle Indicates the pointer to the UART device handle, which is obtained via {@link UartOpen}.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void UartClose(struct DevHandle *handle);
|
||||
|
||||
/**
|
||||
* @brief Reads data of a specified size from a UART device.
|
||||
*
|
||||
* @param handle Indicates the pointer to the UART device handle, which is obtained via {@link UartOpen}.
|
||||
* @param data Indicates the pointer to the buffer for receiving the data.
|
||||
* @param size Indicates the size of the data to read.
|
||||
*
|
||||
* @return Returns the size of the data that is successfully read; returns a negative number if the reading fails.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t UartRead(struct DevHandle *handle, uint8_t *data, uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief Writes data of a specified size into a UART device.
|
||||
*
|
||||
* @param handle Indicates the pointer to the UART device handle, which is obtained via {@link UartOpen}.
|
||||
* @param data Indicates the pointer to the data to write.
|
||||
* @param size Indicates the size of the data to write.
|
||||
*
|
||||
* @return Returns <b>0</b> if the data is successfully written; returns a negative number otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t UartWrite(struct DevHandle *handle, uint8_t *data, uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief Obtains the baud rate of the UART device.
|
||||
*
|
||||
* @param handle Indicates the pointer to the UART device handle, which is obtained via {@link UartOpen}.
|
||||
* @param baudRate Indicates the pointer to the obtained baud rate.
|
||||
*
|
||||
* @return Returns <b>0</b> if the baud rate is obtained; returns a negative number otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t UartGetBaud(struct DevHandle *handle, uint32_t *baudRate);
|
||||
|
||||
/**
|
||||
* @brief Sets the baud rate for the UART device.
|
||||
*
|
||||
* @param handle Indicates the pointer to the UART device handle, which is obtained via {@link UartOpen}.
|
||||
* @param baudRate Indicates the baud rate to set.
|
||||
*
|
||||
* @return Returns <b>0</b> if the setting is successful; returns a negative number otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t UartSetBaud(struct DevHandle *handle, uint32_t baudRate);
|
||||
|
||||
/**
|
||||
* @brief Obtains the UART attribute.
|
||||
*
|
||||
* UART attributes include data bits, stop bits, parity bit, CTS, RTS, and receiving and transmitting FIFO.
|
||||
*
|
||||
* @param handle Indicates the pointer to the UART device handle, which is obtained via {@link UartOpen}.
|
||||
* @param attribute Indicates the pointer to the obtained UART attribute.
|
||||
*
|
||||
* @return Returns <b>0</b> if the UART attribute is obtained; returns a negative number otherwise.
|
||||
* @since 1.0 */
|
||||
int32_t UartGetAttribute(struct DevHandle *handle, struct UartAttribute *attribute);
|
||||
|
||||
/**
|
||||
* @brief Sets the UART attribute.
|
||||
*
|
||||
* UART attributes include data bits, stop bits, parity bit, CTS, RTS, and receiving and transmitting FIFO.
|
||||
*
|
||||
* @param handle Indicates the pointer to the UART device handle, which is obtained via {@link UartOpen}.
|
||||
* @param attribute Indicates the pointer to the UART attribute to set.
|
||||
*
|
||||
* @return Returns <b>0</b> if the setting is successful; returns a negative number otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t UartSetAttribute(struct DevHandle *handle, struct UartAttribute *attribute);
|
||||
|
||||
/**
|
||||
* @brief Sets the UART transmission mode.
|
||||
*
|
||||
* @param handle Indicates the pointer to the UART device handle, which is obtained via {@link UartOpen}.
|
||||
* @param mode Indicates a transmission mode enumerated in {@linkUartTransMode}.
|
||||
*
|
||||
* @return Returns <b>0</b> if the setting is successful; returns a negative number otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t UartSetTransMode(struct DevHandle *handle, enum UartTransMode mode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* PAL_UART_IF_H */
|
||||
/** @} */
|
||||
Executable
+187
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup WATCHDOG
|
||||
* @{
|
||||
*
|
||||
* @brief Provides watchdog APIs, such as setting the watchdog timeout duration and feeding a watchdog (resetting
|
||||
* a watchdog timer).
|
||||
*
|
||||
* If an error occurs in the main program of the system, for example, if the program crashes or the watchdog timer
|
||||
* is not reset in time, the watchdog timer generates a reset signal, and the system restores from the suspending
|
||||
* state to the normal state.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file watchdog_if.h
|
||||
*
|
||||
* @brief Declares standard watchdog APIs.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
#ifndef WATCHDOG_IF_H
|
||||
#define WATCHDOG_IF_H
|
||||
|
||||
#include "hdf_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Enumerates watchdog statuses.
|
||||
*
|
||||
* To obtain the watchdog status, call the {@link WatchdogGetStatus} function.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
enum WatchdogStatus {
|
||||
WATCHDOG_STOP, /**< Stopped */
|
||||
WATCHDOG_START, /**< Started */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Opens a watchdog.
|
||||
*
|
||||
* Before operating a watchdog, you must call this function to open it and obtain its device handle.
|
||||
*
|
||||
* @param wdtId Indicates the watchdog ID.
|
||||
*
|
||||
* @return Returns the pointer to the device handle of the watch dog if the operation is successful;
|
||||
* returns <b>NULL</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct DevHandle *WatchdogOpen(int16_t wdtId);
|
||||
|
||||
/**
|
||||
* @brief Closes a watchdog.
|
||||
*
|
||||
* If you no longer need a watchdog, call this function to close it and release its device handle to prevent
|
||||
* unnecessary use of memory resources.
|
||||
*
|
||||
* @param handle Indicates the pointer to the watchdog device handle.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void WatchdogClose(struct DevHandle *handle);
|
||||
|
||||
/**
|
||||
* @brief Obtains the watchdog status.
|
||||
*
|
||||
* For the available watchdog statuses, see {@link WatchdogStatus}.
|
||||
*
|
||||
* @param handle Indicates the pointer to the watchdog handle, which is obtained via {@link WatchdogOpen}.
|
||||
* @param status Indicates the pointer to the watchdog status.
|
||||
*
|
||||
* @return Returns <b>0</b> if the watchdog status is obtained; returns a negative value otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t WatchdogGetStatus(struct DevHandle *handle, int32_t *status);
|
||||
|
||||
/**
|
||||
* @brief Starts a watchdog.
|
||||
*
|
||||
* This function starts the watchdog timer. You must feed the watchdog periodically; otherwise, the watchdog hardware
|
||||
* will reset the system upon a timeout.
|
||||
*
|
||||
* @param handle Indicates the pointer to the watchdog handle, which is obtained via {@link WatchdogOpen}.
|
||||
*
|
||||
* @return Returns <b>0</b> if the watchdog is successfully started; returns a negative value otherwise.
|
||||
* @attention If the watchdog timer has started before this function is called, calling this function will succeed;
|
||||
* however, the watchdog hardware determines whether to reset the timer.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t WatchdogStart(struct DevHandle *handle);
|
||||
|
||||
/**
|
||||
* @brief Stops a watchdog.
|
||||
*
|
||||
* If the watchdog has stopped before this function is called, calling this function will succeed.
|
||||
*
|
||||
* @param handle Indicates the pointer to the watchdog handle, which is obtained via {@link WatchdogOpen}.
|
||||
*
|
||||
* @return Returns <b>0</b> if the watchdog is successfully stopped; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t WatchdogStop(struct DevHandle *handle);
|
||||
|
||||
/**
|
||||
* @brief Sets the watchdog timeout duration.
|
||||
*
|
||||
* @param handle Indicates the pointer to the watchdog handle, which is obtained via {@link WatchdogOpen}.
|
||||
* @param seconds Indicates the timeout duration, in seconds.
|
||||
*
|
||||
* @return Returns <b>0</b> if the setting is successful; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t WatchdogSetTimeout(struct DevHandle *handle, uint32_t seconds);
|
||||
|
||||
/**
|
||||
* @brief Obtains the watchdog timeout duration.
|
||||
*
|
||||
* @param handle Indicates the pointer to the watchdog handle, which is obtained via {@link WatchdogOpen}.
|
||||
* @param seconds Indicates the pointer to the timeout duration, in seconds.
|
||||
*
|
||||
* @return Returns <b>0</b> if the watchdog timeout duration is obtained; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t WatchdogGetTimeout(struct DevHandle *handle, uint32_t *seconds);
|
||||
|
||||
/**
|
||||
* @brief Feeds a watchdog, that is, resets a watchdog timer.
|
||||
*
|
||||
* After a watchdog is started, you must feed it to reset the watchdog timer periodically.
|
||||
* If you do not do so, the watchdog hardware will reset the system upon a timeout.
|
||||
*
|
||||
* @param handle Indicates the pointer to the watchdog handle, which is obtained via {@link WatchdogOpen}.
|
||||
*
|
||||
* @return Returns <b>0</b> if the watchdog is fed; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t WatchdogFeed(struct DevHandle *handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* WATCHDOG_IF_H */
|
||||
/** @} */
|
||||
Executable
+125
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup DriverUtils
|
||||
* @{
|
||||
*
|
||||
* @brief Defines common macros and interfaces of the driver module.
|
||||
*
|
||||
* This module provides interfaces such as log printing, doubly linked list operations, and work queues.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file hdf_base.h
|
||||
*
|
||||
* @brief Declares driver common types, including the enumerated values returned by the function
|
||||
* and the macro for obtaining the array size.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef HDF_BASE_TYPE_H
|
||||
#define HDF_BASE_TYPE_H
|
||||
|
||||
#if defined(__KERNEL__)
|
||||
#include <linux/types.h>
|
||||
#else
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Enumerates HDF return value types.
|
||||
*/
|
||||
typedef enum {
|
||||
HDF_SUCCESS = 0, /**< The operation is successful. */
|
||||
HDF_FAILURE = -1, /**< Failed to invoke the OS underlying function. */
|
||||
HDF_ERR_NOT_SUPPORT = -2, /**< Not supported. */
|
||||
HDF_ERR_INVALID_PARAM = -3, /**< Invalid parameter. */
|
||||
HDF_ERR_INVALID_OBJECT = -4, /**< Invalid object. */
|
||||
HDF_ERR_MALLOC_FAIL = -6, /**< Memory allocation fails. */
|
||||
HDF_ERR_TIMEOUT = -7, /**< Timeout occurs. */
|
||||
HDF_ERR_THREAD_CREATE_FAIL = -10, /**< Failed to create a thread. */
|
||||
HDF_ERR_QUEUE_FULL = -15, /**< The queue is full. */
|
||||
HDF_ERR_DEVICE_BUSY = -16, /**< The device is busy. */
|
||||
HDF_ERR_IO = -17, /**< I/O error. */
|
||||
HDF_ERR_BAD_FD = -18, /**< Incorrect file descriptor. */
|
||||
|
||||
#define HDF_BSP_ERR_START (-100) /**< Defines the start of the Board Support Package (BSP) module error codes. */
|
||||
#define HDF_BSP_ERR_NUM(v) (HDF_BSP_ERR_START + (v)) /**< Defines the BSP module error codes. */
|
||||
HDF_BSP_ERR_OP = HDF_BSP_ERR_NUM(-1), /**< Failed to operate a BSP module. */
|
||||
HDF_ERR_BSP_PLT_API_ERR = HDF_BSP_ERR_NUM(-2), /**< The platform API of the BSP module is incorrect. */
|
||||
HDF_PAL_ERR_DEV_CREATE = HDF_BSP_ERR_NUM(-3), /**< Failed to create a BSP module device. */
|
||||
HDF_PAL_ERR_INNER = HDF_BSP_ERR_NUM(-4), /**< Internal error codes of the BSP module. */
|
||||
|
||||
#define HDF_DEV_ERR_START (-200) /**< Defines the start of the device module error codes. */
|
||||
#define HDF_DEV_ERR_NUM(v) (HDF_DEV_ERR_START + (v)) /**< Defines the device module error codes. */
|
||||
HDF_DEV_ERR_NO_MEMORY = HDF_DEV_ERR_NUM(-1), /**< Failed to allocate memory to the device module. */
|
||||
HDF_DEV_ERR_NO_DEVICE = HDF_DEV_ERR_NUM(-2), /**< The device module has no device. */
|
||||
HDF_DEV_ERR_NO_DEVICE_SERVICE = HDF_DEV_ERR_NUM(-3), /**< The device module has no device service. */
|
||||
HDF_DEV_ERR_DEV_INIT_FAIL = HDF_DEV_ERR_NUM(-4), /**< Failed to initialize a device module. */
|
||||
HDF_DEV_ERR_PUBLISH_FAIL = HDF_DEV_ERR_NUM(-5), /**< The device module failed to release a service. */
|
||||
HDF_DEV_ERR_ATTACHDEV_FAIL = HDF_DEV_ERR_NUM(-6), /**< Failed to attach a device to a device module. */
|
||||
HDF_DEV_ERR_NODATA = HDF_DEV_ERR_NUM(-7), /**< Failed to read data from a device module. */
|
||||
HDF_DEV_ERR_NORANGE = HDF_DEV_ERR_NUM(-8), /**< The device module data is out of range. */
|
||||
HDF_DEV_ERR_OP = HDF_DEV_ERR_NUM(-10), /**< Failed to operate a device module. */
|
||||
} HDF_STATUS;
|
||||
|
||||
/**
|
||||
* @brief Indicates that the function keeps waiting to obtain a semaphore or mutex.
|
||||
*/
|
||||
#define HDF_WAIT_FOREVER 0xFFFFFFFF
|
||||
|
||||
/**
|
||||
* @brief Defines the array size.
|
||||
*/
|
||||
#define HDF_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
||||
|
||||
/**
|
||||
* @brief Defines a time conversion unit, for example, the unit for converting from second to millisecond.
|
||||
*/
|
||||
#define HDF_KILO_UNIT 1000
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* HDF_BASE_TYPE_H */
|
||||
/** @} */
|
||||
Executable
+243
@@ -0,0 +1,243 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
/**
|
||||
* @addtogroup DriverUtils
|
||||
* @{
|
||||
*
|
||||
* @brief Defines common macros and interfaces of the driver module.
|
||||
*
|
||||
* This module provides interfaces such as log printing, doubly linked list operations, and work queues.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file hdf_dlist.h
|
||||
*
|
||||
* @brief Declares doubly linked list structures and interfaces.
|
||||
*
|
||||
* This file provides interfaces such as inserting a node from the head or tail of a doubly linked list,
|
||||
* checking whether a doubly linked list is empty, traversing a doubly linked list, and merging doubly linked lists.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef HDF_LIST_H
|
||||
#define HDF_LIST_H
|
||||
|
||||
#include "hdf_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Describes a doubly linked list.
|
||||
*/
|
||||
struct DListHead {
|
||||
struct DListHead *next; /**< Pointer to the next node */
|
||||
struct DListHead *prev; /**< Pointer to the previous node */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Initializes a doubly linked list.
|
||||
*
|
||||
* @param head Indicates the pointer to the linked list {@link DListHead}. The parameter cannot be empty.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static inline void DListHeadInit(struct DListHead *head)
|
||||
{
|
||||
head->next = head;
|
||||
head->prev = head;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks whether a doubly linked list is empty.
|
||||
*
|
||||
* @param head Indicates the pointer to the linked list {@link DListHead}. The parameter cannot be empty.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static inline bool DListIsEmpty(const struct DListHead *head)
|
||||
{
|
||||
return (head->next == head) ? true : false;
|
||||
}
|
||||
/**
|
||||
* @brief Removes a node from a doubly linked list.
|
||||
*
|
||||
* @param entry Indicates the pointer to the node to remove. For details, see {@link DListHead}.
|
||||
* The parameter cannot be empty.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static inline void DListRemove(struct DListHead *entry)
|
||||
{
|
||||
entry->prev->next = entry->next;
|
||||
entry->next->prev = entry->prev;
|
||||
|
||||
entry->prev = NULL;
|
||||
entry->next = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inserts a node from the head of a doubly linked list.
|
||||
*
|
||||
* @param entry Indicates the pointer to the node to insert. For details, see {@link DListHead}.
|
||||
* The parameter cannot be empty.
|
||||
* @param head Indicates the pointer to the linked list {@link DListHead}. The parameter cannot be empty.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static inline void DListInsertHead(struct DListHead *entry, struct DListHead *head)
|
||||
{
|
||||
entry->next = head->next;
|
||||
entry->prev = head;
|
||||
|
||||
head->next->prev = entry;
|
||||
head->next = entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inserts a node from the tail of a doubly linked list.
|
||||
*
|
||||
* @param entry Indicates the pointer to the node to insert. For details, see {@link DListHead}.
|
||||
* The parameter cannot be empty.
|
||||
* @param head Indicates the pointer to the linked list {@link DListHead}. The parameter cannot be empty.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static inline void DListInsertTail(struct DListHead *entry, struct DListHead *head)
|
||||
{
|
||||
entry->next = head;
|
||||
entry->prev = head->prev;
|
||||
|
||||
head->prev->next = entry;
|
||||
head->prev = entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Merges two linked lists by adding the list specified by <b>list</b> to
|
||||
* the head of the list specified by <b>head</b> and initializes the merged list.
|
||||
*
|
||||
* @param list Indicates the pointer to the linked list {@link DListHead}. The parameter cannot be empty.
|
||||
* @param head Indicates the pointer to the linked list {@link DListHead}. The parameter cannot be empty.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static inline void DListMerge(struct DListHead *list, struct DListHead *head)
|
||||
{
|
||||
list->next->prev = head;
|
||||
list->prev->next = head->next;
|
||||
|
||||
head->next->prev = list->prev;
|
||||
head->next = list->next;
|
||||
|
||||
DListHeadInit(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the address of a structure variable from its member address.
|
||||
*
|
||||
* @param ptr Indicates the structure member address.
|
||||
* @param type Indicates the structure type.
|
||||
* @param member Indicates the structure member.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define CONTAINER_OF(ptr, type, member) \
|
||||
(type *)((char *)(ptr) - (char *)&((type *)0)->member)
|
||||
|
||||
/**
|
||||
* @brief Obtains the first node of a doubly linked list.
|
||||
*
|
||||
* @param ptr Indicates the structure member address.
|
||||
* @param type Indicates the structure type.
|
||||
* @param member Indicates the structure member.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define DLIST_FIRST_ENTRY(ptr, type, member) \
|
||||
CONTAINER_OF((ptr)->next, type, member)
|
||||
|
||||
/**
|
||||
* @brief Obtains the last node of a doubly linked list.
|
||||
*
|
||||
* @param ptr Indicates the structure member address.
|
||||
* @param type Indicates the structure type.
|
||||
* @param member Indicates the structure member.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define DLIST_LAST_ENTRY(ptr, type, member) \
|
||||
CONTAINER_OF((ptr)->prev, type, member)
|
||||
|
||||
/**
|
||||
* @brief Traverses all nodes in a doubly linked list.
|
||||
*
|
||||
* @param pos Indicates the pointer to the structure variable.
|
||||
* @param head Indicates the pointer to the linked list head.
|
||||
* @param type Indicates the structure type.
|
||||
* @param member Indicates the member type of the structure.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define DLIST_FOR_EACH_ENTRY(pos, head, type, member) \
|
||||
for ((pos) = CONTAINER_OF((head)->next, type, member); \
|
||||
&(pos)->member != (head); \
|
||||
(pos) = CONTAINER_OF((pos)->member.next, type, member))
|
||||
|
||||
/**
|
||||
* @brief Traverses all nodes in a doubly linked list.
|
||||
* This function is used to delete the nodes pointed to by <b>pos</b> during traversal.
|
||||
*
|
||||
* @param pos Indicates the pointer to the structure variable.
|
||||
* @param tmp Indicates the pointer to the structure variable, pointing to the next node of <b>pos</b>.
|
||||
* @param head Indicates the pointer to the linked list head.
|
||||
* @param type Indicates the structure type.
|
||||
* @param member Indicates the member type of the structure.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, head, type, member) \
|
||||
for ((pos) = CONTAINER_OF((head)->next, type, member), \
|
||||
(tmp) = CONTAINER_OF((pos)->member.next, type, member); \
|
||||
&(pos)->member != (head); \
|
||||
(pos) = (tmp), (tmp) = CONTAINER_OF((pos)->member.next, type, member))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* HDF_LIST_H */
|
||||
/** @} */
|
||||
Executable
+332
@@ -0,0 +1,332 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup DriverUtils
|
||||
* @{
|
||||
*
|
||||
* @brief Defines common macros and interfaces of the driver module.
|
||||
*
|
||||
* This module provides interfaces such as log printing, doubly linked list operations, and work queues.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file hdf_log.h
|
||||
*
|
||||
* @brief Declares log printing functions of the driver module.
|
||||
* This module provides functions for printing logs at the verbose, debug, information, warning, and error levels.
|
||||
*
|
||||
* To use these functions, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef HDF_LOG_H
|
||||
#define HDF_LOG_H
|
||||
|
||||
#ifdef HDF_LOG_TAG
|
||||
#undef HDF_LOG_TAG
|
||||
#endif /* HDF_LOG_TAG */
|
||||
|
||||
/** Add quotation mark */
|
||||
#define LOG_TAG_MARK_EXTEND(HDF_TAG) #HDF_TAG
|
||||
#define LOG_TAG_MARK(HDF_TAG) LOG_TAG_MARK_EXTEND(HDF_TAG)
|
||||
|
||||
#ifndef LOG_TAG
|
||||
#define LOG_TAG LOG_TAG_MARK(HDF_LOG_TAG)
|
||||
#endif /* LOG_TAG */
|
||||
|
||||
#if defined(_LINUX_USER_)
|
||||
#include "cutils/log.h"
|
||||
#elif defined(__KERNEL__)
|
||||
#include <linux/printk.h>
|
||||
#elif defined(__LITEOS__) && defined(__USER__)
|
||||
#include <stdio.h>
|
||||
#elif defined(__LITEOS__)
|
||||
#include "los_printf.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if defined(_LINUX_USER_)
|
||||
/**
|
||||
* @brief Prints logs at the verbose level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGV(...) ALOGV(__VA_ARGS__)
|
||||
/**
|
||||
* @brief Prints logs at the debug level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGD(...) ALOGD(__VA_ARGS__)
|
||||
/**
|
||||
* @brief Prints logs at the information level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGI(...) ALOGI(__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Prints logs at the warning level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGW(...) ALOGW(__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Prints logs at the error level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGE(...) ALOGE(__VA_ARGS__)
|
||||
|
||||
#elif defined(__KERNEL__)
|
||||
#define _HDF_FMT_TAG(TAG, LEVEL) "[" #LEVEL "/" #TAG "] "
|
||||
#define HDF_FMT_TAG(TAG, LEVEL) _HDF_FMT_TAG(TAG, LEVEL)
|
||||
|
||||
/**
|
||||
* @brief Prints logs at the verbose level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGV(fmt, args...) printk(KERN_DEBUG HDF_FMT_TAG(HDF_LOG_TAG, V) fmt, ## args)
|
||||
/**
|
||||
* @brief Prints logs at the debug level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGD(fmt, args...) printk(KERN_DEBUG HDF_FMT_TAG(HDF_LOG_TAG, D) fmt, ## args)
|
||||
/**
|
||||
* @brief Prints logs at the information level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGI(fmt, args...) printk(KERN_INFO HDF_FMT_TAG(HDF_LOG_TAG, I) fmt, ## args)
|
||||
/**
|
||||
* @brief Prints logs at the warning level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGW(fmt, args...) printk(KERN_WARNING HDF_FMT_TAG(HDF_LOG_TAG, W) fmt, ## args)
|
||||
/**
|
||||
* @brief Prints logs at the error level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGE(fmt, args...) printk(KERN_ERR HDF_FMT_TAG(HDF_LOG_TAG, E) fmt, ## args)
|
||||
|
||||
#elif defined(__LITEOS__) && defined(__USER__)
|
||||
/**
|
||||
* @brief Prints logs at the verbose level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGV(fmt, arg...) printf("[HDF:V/" LOG_TAG "]" fmt "\r\n", ##arg)
|
||||
/**
|
||||
* @brief Prints logs at the debug level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGD(fmt, arg...) printf("[HDF:D/" LOG_TAG "]" fmt "\r\n", ##arg)
|
||||
/**
|
||||
* @brief Prints logs at the information level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGI(fmt, arg...) printf("[HDF:I/" LOG_TAG "]" fmt "\r\n", ##arg)
|
||||
/**
|
||||
* @brief Prints logs at the warning level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGW(fmt, arg...) printf("[HDF:W/" LOG_TAG "]" fmt "\r\n", ##arg)
|
||||
/**
|
||||
* @brief Prints logs at the error level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGE(fmt, arg...) printf("[HDF:E/" LOG_TAG "]" fmt "\r\n", ##arg)
|
||||
#elif defined(__LITEOS__)
|
||||
/**
|
||||
* @brief Prints logs at the verbose level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGV(fmt, arg...) PRINT_DEBUG("[HDF:V/" LOG_TAG "]" fmt "\r\n", ##arg)
|
||||
/**
|
||||
* @brief Prints logs at the debug level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGD(fmt, arg...) PRINT_DEBUG("[HDF:D/" LOG_TAG "]" fmt "\r\n", ##arg)
|
||||
/**
|
||||
* @brief Prints logs at the information level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGI(fmt, arg...) PRINT_INFO("[HDF:I/" LOG_TAG "]" fmt "\r\n", ##arg)
|
||||
/**
|
||||
* @brief Prints logs at the warning level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGW(fmt, arg...) PRINT_WARN("[HDF:W/" LOG_TAG "]" fmt "\r\n", ##arg)
|
||||
/**
|
||||
* @brief Prints logs at the error level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGE(fmt, arg...) PRINT_ERR("[HDF:E/" LOG_TAG "]" fmt "\r\n", ##arg)
|
||||
#else
|
||||
/**
|
||||
* @brief Prints logs at the verbose level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGV(fmt, arg...) printf("[HDF:V/" LOG_TAG "]" fmt "\r\n", ##arg)
|
||||
/**
|
||||
* @brief Prints logs at the debug level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGD(fmt, arg...) printf("[HDF:D/" LOG_TAG "]" fmt "\r\n", ##arg)
|
||||
/**
|
||||
* @brief Prints logs at the information level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGI(fmt, arg...) printf("[HDF:I/" LOG_TAG "]" fmt "\r\n", ##arg)
|
||||
/**
|
||||
* @brief Prints logs at the warning level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGW(fmt, arg...) printf("[HDF:W/" LOG_TAG "]" fmt "\r\n", ##arg)
|
||||
/**
|
||||
* @brief Prints logs at the error level.
|
||||
*
|
||||
* To use this function, you must define <b>HDF_LOG_TAG</b>, for example, #define HDF_LOG_TAG evt.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define HDF_LOGE(fmt, arg...) printf("[HDF:E/" LOG_TAG "]" fmt "\r\n", ##arg)
|
||||
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* HDF_LOG_H */
|
||||
/** @} */
|
||||
Executable
+256
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup DriverUtils
|
||||
* @{
|
||||
*
|
||||
* @brief Defines common macros and interfaces of the driver module.
|
||||
*
|
||||
* This module provides interfaces such as log printing, doubly linked list operations, and work queues.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file hdf_workqueue.h
|
||||
*
|
||||
* @brief Declares work queue structures and interfaces.
|
||||
*
|
||||
* This file provides interfaces such as initializing a work queue, a work item, and a delayed work item,
|
||||
* adding a work or delayed work item to a work queue, and destroying a work queue, a work item,
|
||||
* and a delayed work item. You need to define a work queue, a work item, and a delayed work item,
|
||||
* and then call the initialization function to initialize them. The work item, delayed work item,
|
||||
* and work queue must be destroyed when they are no longer used.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef HDF_WORKQUEUE_H
|
||||
#define HDF_WORKQUEUE_H
|
||||
|
||||
#include "hdf_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Describes a work execution function type.
|
||||
*
|
||||
* The thread of the work queue executes this function after the work item is added to the work queue.
|
||||
*/
|
||||
typedef void (*HdfWorkFunc)(void *);
|
||||
|
||||
/**
|
||||
* @brief Enumerates statuses of a work item or a delayed work item.
|
||||
*/
|
||||
enum {
|
||||
HDF_WORK_BUSY_PENDING = 1 << 0, /**< The work item or delayed work item is pending. */
|
||||
HDF_WORK_BUSY_RUNNING = 1 << 1, /**< The work item or delayed work item is running. */
|
||||
};
|
||||
/**
|
||||
* @brief Describes a work item and a delayed work item.
|
||||
* This structure defines the work and delayed work items, and then calls the initialization
|
||||
* function {@link HdfWorkInit} or {@link HdfDelayedWorkInit} to perform initialization.
|
||||
* The <b>HdfAddWork()</b> function is to add a work item to a work queue immediately,
|
||||
* and the <b>HdfAddDelayedWork()</b> function is to add a work item to a work queue after the configured delayed time.
|
||||
*/
|
||||
typedef struct {
|
||||
void *realWork; /**< Pointer to a work item and a delayed work item */
|
||||
} HdfWork;
|
||||
|
||||
/**
|
||||
* @brief Describes a work queue.
|
||||
*/
|
||||
typedef struct {
|
||||
void *realWorkQueue; /**< Pointer to a work queue */
|
||||
} HdfWorkQueue;
|
||||
|
||||
/**
|
||||
* @brief Initializes a work queue.
|
||||
*
|
||||
* When a work queue is initialized, a thread is created. The thread cyclically executes the work items
|
||||
* in the work queue, that is, executes their functions.
|
||||
*
|
||||
* @param queue Indicates the pointer to the work queue {@link OsalWorkQueue}.
|
||||
* @param name Indicates the pointer to the work queue name.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
* HDF_ERR_MALLOC_FAIL | Memory allocation fails.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t HdfWorkQueueInit(HdfWorkQueue *queue, char *name);
|
||||
|
||||
/**
|
||||
* @brief Initializes a work item.
|
||||
*
|
||||
* This function uses <b>func</b> and <b>arg</b> to initialize a work item.
|
||||
* After the work item is added to a work queue, the thread of the work queue executes this function,
|
||||
* and <b>arg</b> is passed to <b>func</b>.
|
||||
*
|
||||
* @param work Indicates the pointer to the work item {@link HdfWork}.
|
||||
* @param func Indicates the work execution function.
|
||||
* @param arg Indicates the pointer to the argument of the work execution function.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
* HDF_ERR_MALLOC_FAIL | Memory allocation fails.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t HdfWorkInit(HdfWork *work, HdfWorkFunc func, void *arg);
|
||||
|
||||
/**
|
||||
* @brief Initializes a delayed work item.
|
||||
*
|
||||
* This function uses <b>func</b> and <b>arg</b> to initialize a work item.
|
||||
* The work item is added to a work queue after the configured delayed time.
|
||||
* The thread of the work queue executes this function, and <b>arg</b> is passed to <b>func</b>.
|
||||
*
|
||||
* @param work Indicates the pointer to the delayed work item {@link HdfWork}.
|
||||
* @param func Indicates the work execution function.
|
||||
* @param arg Indicates the pointer to the argument of the work execution function.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
* HDF_ERR_MALLOC_FAIL | Memory allocation fails.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t HdfDelayedWorkInit(HdfWork *work, HdfWorkFunc func, void *arg);
|
||||
|
||||
/**
|
||||
* @brief Destroys a work item.
|
||||
*
|
||||
* @param work Indicates the pointer to the work item {@link HdfWork}.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void HdfWorkDestroy(HdfWork *work);
|
||||
|
||||
/**
|
||||
* @brief Destroys a work queue.
|
||||
*
|
||||
* @param queue Indicates the pointer to the work queue {@link HdfWorkQueue}.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void HdfWorkQueueDestroy(HdfWorkQueue *queue);
|
||||
|
||||
/**
|
||||
* @brief Destroys a delayed work item.
|
||||
*
|
||||
* @param work Indicates the pointer to the delayed work item {@link HdfWork}.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void HdfDelayedWorkDestroy(HdfWork *work);
|
||||
|
||||
/**
|
||||
* @brief Adds a work item to a work queue.
|
||||
*
|
||||
* After a work item is added to a work queue, the thread of the work queue executes the function of the work item.
|
||||
*
|
||||
* @param queue Indicates the pointer to the work queue {@link HdfWorkQueue}.
|
||||
* @param work Indicates the pointer to the work item {@link HdfWork}.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
bool HdfAddWork(HdfWorkQueue *queue, HdfWork *work);
|
||||
|
||||
/**
|
||||
* @brief Adds a delayed work item to a work queue.
|
||||
*
|
||||
* A delayed work item is added to a work queue after the configured delayed time (ms),
|
||||
* and the thread of the work queue executes the work function.
|
||||
*
|
||||
* @param queue Indicates the pointer to the work queue {@link HdfWorkQueue}.
|
||||
* @param work Indicates the pointer to the delayed work item {@link HdfWork}.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
bool HdfAddDelayedWork(HdfWorkQueue *queue, HdfWork *work, unsigned long ms);
|
||||
|
||||
/**
|
||||
* @brief Obtains the status of a work item or delayed work item.
|
||||
*
|
||||
* @param work Indicates the pointer to the work item or delayed work item {@link HdfWork}.
|
||||
* @return Returns <b>HDF_WORK_BUSY_PENDING</b> if the work item is pending;
|
||||
* returns <b>HDF_WORK_BUSY_RUNNING</b> if the work item is running.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
unsigned int HdfWorkBusy(HdfWork *work);
|
||||
|
||||
/**
|
||||
* @brief Cancels a work item. This function waits until the work item is complete.
|
||||
*
|
||||
* @param work Indicates the pointer to the work item {@link HdfWork}.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
bool HdfCancelWorkSync(HdfWork *work);
|
||||
|
||||
/**
|
||||
* @brief Cancels a delayed work item.
|
||||
*
|
||||
* @param work Indicates the pointer to the delayed work item {@link HdfWork}.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
bool HdfCancelDelayedWorkSync(HdfWork *work);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* HDF_WORKQUEUE_H */
|
||||
/** @} */
|
||||
Executable
+467
@@ -0,0 +1,467 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup WLAN
|
||||
* @{
|
||||
*
|
||||
* @brief Defines a WLAN module that supports cross-OS migration, component adaptation, and modular assembly and
|
||||
* compilation. Driver developers of WLAN vendors can adapt their driver code based on the unified APIs provided
|
||||
* by the WLAN module.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file hdf_wifi_event.h
|
||||
*
|
||||
* @brief Declares WLAN driver events.
|
||||
*
|
||||
* The functions in this file are used to report events such as scanning results, scanning completion, and station
|
||||
* disconnection to the WPA interface.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef __HDF_WIFI_EVENT_H__
|
||||
#define __HDF_WIFI_EVENT_H__
|
||||
|
||||
#include "hdf_wifi_cmd.h"
|
||||
#include "wifi_mac80211_ops.h"
|
||||
#include "net_device.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Defines the rate information received or sent over WLAN.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct RateInfo {
|
||||
uint8_t flags; /**< Flag field, used to indicate a specific rate transmission type of 802.11n */
|
||||
uint8_t mcs; /**< Modulation and Coding Scheme (MCS) index of the HT/VHT/HE rate */
|
||||
uint16_t legacy; /**< 100 kbit/s bit rate defined in 802.11a/b/g */
|
||||
uint8_t nss; /**< Number of streams (for VHT and HE only) */
|
||||
uint8_t resv; /**< Reserved */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines parameters related to the WLAN module that works in station mode.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct StaBssParameters {
|
||||
uint8_t flags; /**< Flag, used to indicate a specific rate transmission type of 802.11n */
|
||||
uint8_t dtimPeriod; /**< Delivery Traffic Indication Message (DTIM) period of BSS */
|
||||
uint16_t beaconInterval; /**< Beacon interval */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines the update of the <b>Sta</b> flag.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct StaFlagUpdate {
|
||||
uint32_t mask; /**< Flag mask */
|
||||
uint32_t set; /**< Flag value */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines station information.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct StationInfo {
|
||||
uint32_t filled; /**< Flag values of relevant structures */
|
||||
uint32_t connectedTime; /**< Duration (in seconds) since the last station connection */
|
||||
uint32_t inactiveTime; /**< Duration (in milliseconds) since the last station
|
||||
* activity
|
||||
*/
|
||||
uint16_t llid; /**< Local mesh ID */
|
||||
uint16_t plid; /**< Peer mesh ID */
|
||||
|
||||
uint64_t rxBytes; /**< Received bytes */
|
||||
uint64_t txBytes; /**< Transmitted bytes */
|
||||
struct RateInfo txRate; /**< Transmission rate */
|
||||
struct RateInfo rxRate; /**< Receive rate */
|
||||
|
||||
uint32_t rxPackets; /**< Received data packets */
|
||||
uint32_t txPackets; /**< Transmitted data packets */
|
||||
uint32_t txPetries; /**< Number of retransmissions */
|
||||
uint32_t txFailed; /**< Number of failed transmissions */
|
||||
|
||||
uint32_t rxDroppedMisc; /**< Number of receive failures */
|
||||
int32_t generation; /**< Generation number */
|
||||
struct StaBssParameters bssParam; /**< Current BSS parameters */
|
||||
struct StaFlagUpdate staFlags; /**< Station flag masks and values */
|
||||
|
||||
int64_t offset; /**< Time offset of station */
|
||||
const uint8_t *assocReqIes; /**< Information Elements (IEs) in Association Request */
|
||||
uint32_t assocReqIesLen; /**< IE length in Association Request */
|
||||
uint32_t beaconLossCount; /**< Number of beacon loss events triggered */
|
||||
|
||||
uint8_t plinkState; /**< Mesh peer state */
|
||||
int8_t signal; /**< Signal strength */
|
||||
int8_t signalAvg; /**< Average signal strength */
|
||||
uint8_t resv1; /**< Reserved */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines authentication information.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct Auth {
|
||||
uint16_t authAlg; /**< Authentication algorithm */
|
||||
uint16_t authTransaction; /**< Authentication transaction */
|
||||
uint16_t statusCode; /**< Authentication status code */
|
||||
uint8_t variable[0]; /**< Algorithm challenge information stored in a flexible array */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines deauthentication information.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct Deauth {
|
||||
uint16_t reasonCode; /**< Deauthentication cause code */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines station association request.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct AssocReq {
|
||||
uint16_t capabInfo; /**< WLAN capability information */
|
||||
uint16_t listenInterval; /**< Scan interval */
|
||||
uint8_t variable[0]; /**< SSID and rate information stored in a flexible array */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines station association response.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct AssocResp {
|
||||
uint16_t capabInfo; /**< WLAN capability information */
|
||||
uint16_t statusCode; /**< Status code */
|
||||
uint16_t aid; /**< Authentication ID */
|
||||
uint8_t variable[0]; /**< Rate information stored in a flexible array */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines station reassociation request.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct ReassocReq {
|
||||
uint16_t capabInfo; /**< WLAN capability information */
|
||||
uint16_t listenInterval; /**< Scan interval */
|
||||
uint8_t currentAp[6]; /**< Current AP */
|
||||
uint8_t variable[0]; /**< SSID and rate information stored in a flexible array */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines station reassociation response.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct ReassocResp {
|
||||
uint16_t capabInfo; /**< WLAN capability information */
|
||||
uint16_t statusCode; /**< Status code */
|
||||
uint16_t aid; /**< Authentication ID */
|
||||
uint8_t variable[0]; /**< Rate information stored in a flexible array */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines station disconnection.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct Disassoc {
|
||||
uint16_t reasonCode; /**< Cause code */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines the update of the <b>Sta</b> flag.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct Beacon {
|
||||
uint64_t timestamp; /**< Timestamp */
|
||||
uint16_t beaconInt; /**< Beacon interval */
|
||||
uint16_t capabInfo; /**< WLAN capability information */
|
||||
uint8_t variable[0]; /**< SSID and rate information */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines scanning response.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct ProbeResp {
|
||||
uint64_t timestamp; /**< Timestamp */
|
||||
uint16_t beaconInt; /**< Beacon interval */
|
||||
uint16_t capabInfo; /**< WLAN capability information */
|
||||
uint8_t variable[0]; /**< SSID and rate information */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines management frame information.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct Ieee80211Mgmt {
|
||||
uint16_t frameControl; /**< Frame control field */
|
||||
uint16_t duration; /**< Duration */
|
||||
uint8_t dstAddr[6]; /**< Destination MAC address */
|
||||
uint8_t srcAddr[6]; /**< Source MAC address */
|
||||
uint8_t bssid[6]; /**< BSS ID */
|
||||
uint16_t seqCtrl; /**< Sequence control */
|
||||
union {
|
||||
struct Auth auth; /**< Authentication Information */
|
||||
struct Deauth deauth; /**< Deauthentication Information */
|
||||
struct AssocReq assocReq; /**< Association request */
|
||||
struct AssocResp assocResp; /**< Association response */
|
||||
struct ReassocReq reassocReq; /**< Re-authentication */
|
||||
struct ReassocResp reassocResp; /**< Re-authentication response */
|
||||
struct Disassoc disassoc; /**< Disconnected */
|
||||
struct Beacon beacon; /**< Beacon frame */
|
||||
struct ProbeResp probeResp; /**< Probe response frame */
|
||||
} u;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents the scanned BSS information.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct ScannedBssInfo {
|
||||
int32_t signal; /**< Signal strength */
|
||||
int16_t freq; /**< Center frequency of the channel where the BSS is located */
|
||||
uint8_t arry[2]; /**< Reserved */
|
||||
uint32_t mgmtLen; /**< Management frame length */
|
||||
struct Ieee80211Mgmt *mgmt; /**< Start address of the management frame */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines association results.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct ConnetResult {
|
||||
uint8_t bssid[ETH_ADDR_LEN]; /**< MAC address of the AP associated with the station */
|
||||
uint16_t statusCode; /**< 16-bit status code defined in the IEEE protocol */
|
||||
uint8_t *rspIe; /**< Association response IE */
|
||||
uint8_t *reqIe; /**< Association request IE */
|
||||
uint32_t reqIeLen; /**< Length of the association request IE */
|
||||
uint32_t rspIeLen; /**< Length of the association response IE */
|
||||
uint16_t connectStatus; /**< Connection status */
|
||||
uint16_t freq; /**< Frequency of the AP */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Enumerates MLME management statuses, indicating whether a device is successfully associated or
|
||||
* fails to be associated.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
enum WifiHmacMgmtStatus {
|
||||
WIFI_HMAC_MGMT_SUCCESS = 0, /**< Association succeeds */
|
||||
WIFI_HMAC_MGMT_INVALID = 1, /**< Association fails */
|
||||
WIFI_HMAC_MGMT_TIMEOUT = 2, /**< Association timeout */
|
||||
WIFI_HMAC_MGMT_REFUSED = 3, /**< Association refused */
|
||||
WIFI_HMAC_MGMT_TOMANY_REQ = 4, /**< Repeated association request */
|
||||
WIFI_HMAC_MGMT_ALREADY_BSS = 5 /**< Associated with the BSS */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Reports a new STA event.
|
||||
*
|
||||
* @param netdev Indicates the pointer to the network device. This parameter cannot be null.
|
||||
* @param macAddr Indicates the pointer to the MAC address of the station. This parameter cannot be null.
|
||||
* @param addrLen Indicates the length of the MAC address of the station. The length is fixed to six bytes.
|
||||
* @param info Indicates the pointer to the station information.
|
||||
*
|
||||
* @return Returns <b>0</b> if the event is reported successfully; returns <b>-1</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t HdfWifiEventNewSta(const struct NetDevice *netdev, const uint8_t *macAddr, uint8_t addrLen,
|
||||
const struct StationInfo *info);
|
||||
|
||||
/**
|
||||
* @brief Reports a station deletion event.
|
||||
*
|
||||
* @param netdev Indicates the pointer to the network device. This parameter cannot be null.
|
||||
* @param macAddr Indicates the pointer to the MAC address of the station. This parameter cannot be null.
|
||||
* @param addrLen Indicates the length of the MAC address of the station. The length is fixed to six bytes.
|
||||
*
|
||||
* @return Returns <b>0</b> if the event is reported successfully; returns <b>-1</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t HdfWifiEventDelSta(struct NetDevice *netdev, const uint8_t *macAddr, uint8_t addrLen);
|
||||
|
||||
/**
|
||||
* @brief Reports a scanned BSS event.
|
||||
*
|
||||
* @param netdev Indicates the pointer to the network device. This parameter cannot be null.
|
||||
* @param wiphy Indicates the pointer to the physical layer of the wireless network. This parameter cannot be null.
|
||||
* @param channel Indicates the pointer to the channel information. This parameter cannot be null.
|
||||
* @param bssInfo Indicates the pointer to the BSS information. This parameter cannot be null.
|
||||
*
|
||||
* @return Returns <b>0</b> if the event is reported successfully; returns <b>-1</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t HdfWifiEventInformBssFrame(const struct NetDevice *netdev, struct Wiphy *wiphy,
|
||||
const struct Ieee80211Channel *channel, const struct ScannedBssInfo *bssInfo);
|
||||
|
||||
/**
|
||||
* @brief Reports a scanning completion event.
|
||||
*
|
||||
* @param netdev Indicates the pointer to the network device. This parameter cannot be null.
|
||||
* @param status Indicates the scanning completion status. Value <b>0</b> indicates that the scanning is successful,
|
||||
* and other values indicate that the scanning fails.
|
||||
*
|
||||
* @return Returns <b>0</b> if the event is reported successfully; returns <b>-1</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t HdfWifiEventScanDone(const struct NetDevice *netdev, WifiScanStatus status);
|
||||
|
||||
/**
|
||||
* @brief Reports a connection result event.
|
||||
*
|
||||
* @param netdev Indicates the pointer to the network device. This parameter cannot be null.
|
||||
* @param result Indicates the pointer to the connection result. This parameter cannot be null.
|
||||
*
|
||||
* @return Returns <b>0</b> if the event is reported successfully; returns <b>-1</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t HdfWifiEventConnectResult(const struct NetDevice *netdev, const struct ConnetResult *result);
|
||||
|
||||
/**
|
||||
* @brief Reports a disconnection event.
|
||||
*
|
||||
* @param netdev Indicates the pointer to the network device. This parameter cannot be null.
|
||||
* @param reason Indicates the reason for disconnection.
|
||||
* @param ie Indicates the pointer to the deauth/disassoc frame IE.
|
||||
* @param ieLen Indicates the length of the deauth/disassoc IE.
|
||||
*
|
||||
* @return Returns <b>0</b> if the event is reported successfully; returns <b>-1</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t HdfWifiEventDisconnected(const struct NetDevice *netdev, uint16_t reason, const uint8_t *ie, uint32_t len);
|
||||
|
||||
/**
|
||||
* @brief Reports a transmission management status event.
|
||||
*
|
||||
* @param netdev Indicates the pointer to the network device. This parameter cannot be null.
|
||||
* @param buf Indicates the pointer to the transmission management frame. This parameter cannot be null.
|
||||
* @param len Indicates the length of the transmission management frame.
|
||||
* @param ack Indicates whether the transmission management frame is acknowledged.
|
||||
*
|
||||
* @return Returns <b>0</b> if the event is reported successfully; returns <b>-1</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t HdfWifiEventMgmtTxStatus(const struct NetDevice *netdev, const uint8_t *buf, size_t len, uint8_t ack);
|
||||
|
||||
/**
|
||||
* @brief Reports a receive management status event.
|
||||
*
|
||||
* @param netdev Indicates the pointer to the network device. This parameter cannot be null.
|
||||
* @param freq Indicates the frequency of receiving management frame.
|
||||
* @param sigMbm Indicates the signal strength (in dBm).
|
||||
* @param buf Indicates the pointer to the receive management frame. This parameter cannot be null.
|
||||
* @param len Indicates the length of the receive management frame.
|
||||
*
|
||||
* @return Returns <b>0</b> if the event is reported successfully; returns <b>-1</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t HdfWifiEventRxMgmt(const struct NetDevice *netdev, int32_t freq, int32_t sigMbm,
|
||||
const uint8_t *buf, size_t len);
|
||||
|
||||
/**
|
||||
* @brief Reports a CSA channel switching event.
|
||||
*
|
||||
* @param netdev Indicates the pointer to the network device. This parameter cannot be null.
|
||||
* @param freq Indicates the frequency of the channel.
|
||||
*
|
||||
* @return Returns <b>0</b> if the event is reported successfully; returns <b>-1</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t HdfWifiEventCsaChannelSwitch(const struct NetDevice *netdev, int32_t freq);
|
||||
|
||||
/**
|
||||
* @brief Reports a timeout disconnection event.
|
||||
*
|
||||
* @param netdev Indicates the pointer to the network device. This parameter cannot be null.
|
||||
*
|
||||
* @return Returns <b>0</b> if the event is reported successfully; returns <b>-1</b> otherwise.
|
||||
*
|
||||
* @since 1.0 */
|
||||
int32_t HdfWifiEventTimeoutDisconnected(const struct NetDevice *netdev);
|
||||
|
||||
/**
|
||||
* @brief Reports the event of receiving the EAPOL frame and notifies WPA to read the EAPOL frame.
|
||||
*
|
||||
* @param name Indicates the pointer to the network port name, for example, <b>wlan0</b>.
|
||||
* @param context Indicates the pointer to the context. This parameter is reserved.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t HdfWifiEventEapolRecv(const char *name, void *context);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* __HDF_WIFI_EVENT_H__ */
|
||||
|
||||
Executable
+88
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup WLAN
|
||||
* @{
|
||||
*
|
||||
* @brief Defines a WLAN module that supports cross-OS migration, component adaptation, and modular assembly and
|
||||
* compilation. Driver developers of WLAN vendors can adapt their driver code based on the unified APIs provided
|
||||
* by the WLAN module.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file hdf_wifi_product.h
|
||||
*
|
||||
* @brief Declares the data structure of the WLAN module.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef HDFLITE_HDF_WIFI_PRODUCT_H
|
||||
#define HDFLITE_HDF_WIFI_PRODUCT_H
|
||||
|
||||
#include "wifi_module.h"
|
||||
#include "hdf_device_desc.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Defines the WLAN module.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct HdfWifiProductData {
|
||||
char product_name[MAX_WIFI_COMPONENT_NAME_LEN]; /**< WLAN module name, which contains a maximum of 10 bytes */
|
||||
char state; /**< WLAN module state */
|
||||
struct WifiModule *module; /**< Structure of the WLAN module */
|
||||
struct HdfDeviceObject *device; /**< Structure of the Device Object */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Obtains the data structure of the WLAN module.
|
||||
*
|
||||
* @return Returns the pointer to the data structure of the WLAN module. For details, see {@link HdfWifiProductData}.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
struct HdfWifiProductData *HdfWifiGetProduct(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // HDFLITE_HDF_WIFI_PRODUCT_H
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user