mirror of
https://github.com/openharmony/drivers_framework.git
synced 2026-06-30 21:57:58 -04:00
sync code to l0l1
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
*.o
|
||||
*.a
|
||||
*.d
|
||||
*.cmd
|
||||
@@ -0,0 +1,99 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Notes:
|
||||
This is project config file for OpenHarmony OSS Audit Tool, if you have any questions or concerns, please email chenyaxun@huawei.com.
|
||||
-->
|
||||
<!-- OAT(OSS Audit Tool) configuration guide:
|
||||
basedir: Root dir, the basedir + project path is the real source file location.
|
||||
licensefile:
|
||||
1.If the project don't have "LICENSE" in root dir, please define all the license files in this project in , OAT will check license files according to this rule.
|
||||
|
||||
tasklist(only for batch mode):
|
||||
1. task: Define oat check thread, each task will start a new thread.
|
||||
2. task name: Only an name, no practical effect.
|
||||
3. task policy: Default policy for projects under this task, this field is required and the specified policy must defined in policylist.
|
||||
4. task filter: Default filefilter for projects under this task, this field is required and the specified filefilter must defined in filefilterlist.
|
||||
5. task project: Projects to be checked, the path field define the source root dir of the project.
|
||||
|
||||
|
||||
policyList:
|
||||
1. policy: All policyitems will be merged to default OAT.xml rules, the name of policy doesn't affect OAT check process.
|
||||
2. policyitem: The fields type, name, path, desc is required, and the fields rule, group, filefilter is optional,the default value is:
|
||||
<policyitem type="" name="" path="" desc="" rule="may" group="defaultGroup" filefilter="defaultPolicyFilter"/>
|
||||
3. policyitem type:
|
||||
"compatibility" is used to check license compatibility in the specified path;
|
||||
"license" is used to check source license header in the specified path;
|
||||
"copyright" is used to check source copyright header in the specified path;
|
||||
"import" is used to check source dependency in the specified path, such as import ... ,include ...
|
||||
"filetype" is used to check file type in the specified path, supported file types: archive, binary
|
||||
"filename" is used to check whether the specified file exists in the specified path(support projectroot in default OAT.xml), supported file names: LICENSE, README, README.OpenSource
|
||||
|
||||
4. policyitem name: This field is used for define the license, copyright, "*" means match all, the "!" prefix means could not match this value. For example, "!GPL" means can not use GPL license.
|
||||
5. policyitem path: This field is used for define the source file scope to apply this policyitem, the "!" prefix means exclude the files. For example, "!.*/lib/.*" means files in lib dir will be exclude while process this policyitem.
|
||||
6. policyitem rule and group: These two fields are used together to merge policy results. "may" policyitems in the same group means any one in this group passed, the result will be passed.
|
||||
7. policyitem filefilter: Used to bind filefilter which define filter rules.
|
||||
8. filefilter: Filter rules, the type filename is used to filter file name, the type filepath is used to filter file path.
|
||||
|
||||
Note:If the text contains special characters, please escape them according to the following rules:
|
||||
" == >
|
||||
& == >
|
||||
' == >
|
||||
< == >
|
||||
> == >
|
||||
-->
|
||||
<configuration>
|
||||
<oatconfig>
|
||||
<licensefile></licensefile>
|
||||
<policylist>
|
||||
<policy name="projectPolicy" desc="">
|
||||
<policyitem type="license" name="GPL" path=".*" desc="linux kernel adapter codes"/>
|
||||
<policyitem type="license" name="BSD" path=".*" desc="huawei codes"/>
|
||||
<!--policyitem type="compatibility" name="GPL" path=".*" desc="linux kernel adapter codes"/-->
|
||||
<!--policyitem type="compatibility" name="GPL-2.0+" path=".*" desc="linux kernel adapter codes"/-->
|
||||
</policy>
|
||||
</policylist>
|
||||
<filefilterlist>
|
||||
<filefilter name="defaultFilter" desc="Files not to check">
|
||||
<filteritem type="filename" name="*.lds|*.pod"/>
|
||||
<filteritem type="filename" name="*.a|*.d|*.o|*.cmd|*.hcb|*.swp|hc-gen"/>
|
||||
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
|
||||
</filefilter>
|
||||
<filefilter name="defaultPolicyFilter" desc="Filters for compatibility,license header policies">
|
||||
<filteritem type="filename" name="README.OpenSource"/>
|
||||
<filteritem type="filename" name="README"/>
|
||||
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
|
||||
</filefilter>
|
||||
<filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies" >
|
||||
<filteritem type="filename" name="README.OpenSource"/>
|
||||
<filteritem type="filename" name="README"/>
|
||||
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
|
||||
</filefilter>
|
||||
<filefilter name="licenseFileNamePolicyFilter" desc="Filters for LICENSE file policies" >
|
||||
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
|
||||
<filteritem type="filepath" name="core/adapter/.*" desc="it's not a repo"/>
|
||||
</filefilter>
|
||||
<filefilter name="readmeFileNamePolicyFilter" desc="Filters for README file policies" >
|
||||
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
|
||||
</filefilter>
|
||||
<filefilter name="readmeOpenSourcefileNamePolicyFilter" desc="Filters for README.OpenSource file policies" >
|
||||
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
|
||||
</filefilter>
|
||||
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies" >
|
||||
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
|
||||
</filefilter>
|
||||
</filefilterlist>
|
||||
</oatconfig>
|
||||
</configuration>
|
||||
@@ -156,9 +156,9 @@ For details, see [WLAN Overview](https://gitee.com/openharmony/docs/blob/master
|
||||
|
||||
drivers\_framework
|
||||
|
||||
[drivers\_adapter\_uhdf](https://gitee.com/openharmony/drivers_adapter_uhdf/blob/master/README.md)
|
||||
[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README.md)
|
||||
|
||||
[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_uhdf/blob/master/README.md)
|
||||
[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README.md)
|
||||
|
||||
[drivers\_adapter\_khdf\_liteos](https://gitee.com/openharmony/drivers_adapter_uhdf/blob/master/README.md)
|
||||
[drivers\_peripheral](https://gitee.com/openharmony/drivers_peripheral/blob/master/README.md)
|
||||
|
||||
|
||||
+2
-6
@@ -156,13 +156,9 @@ HDF驱动框架详细开发请参考[驱动开发指南](https://gitee.com/openh
|
||||
|
||||
drivers\_framework
|
||||
|
||||
[drivers\_adapter\_uhdf](https://gitee.com/openharmony/drivers_adapter_uhdf/blob/master/README_zh.md)
|
||||
[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README_zh.md)
|
||||
|
||||
[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README_zh.md)
|
||||
|
||||
[drivers\_adapter\_khdf\_liteos](https://gitee.com/openharmony/drivers_adapter_khdf_liteos/blob/master/README_zh.md)
|
||||
|
||||
<a name="table19581927144220"></a>
|
||||
<table><tbody></tbody>
|
||||
</table>
|
||||
[drivers\_peripheral](https://gitee.com/openharmony/drivers_peripheral/blob/master/README_zh.md)
|
||||
|
||||
|
||||
@@ -12,9 +12,6 @@
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_slist.h"
|
||||
|
||||
#define USB_PNP_INFO_MAX_INTERFACES 32
|
||||
#define USB_PNP_DEBUG_STRING ""
|
||||
|
||||
enum {
|
||||
HDF_SERVICE_UNUSABLE,
|
||||
HDF_SERVICE_USABLE,
|
||||
@@ -39,75 +36,6 @@ struct HdfDeviceInfo {
|
||||
const char *moduleName;
|
||||
const char *svcName;
|
||||
const char *deviceMatchAttr;
|
||||
const void *private;
|
||||
};
|
||||
|
||||
enum UsbPnpNotifyServiceCmd {
|
||||
USB_PNP_NOTIFY_ADD_INTERFACE,
|
||||
USB_PNP_NOTIFY_REMOVE_INTERFACE,
|
||||
USB_PNP_NOTIFY_REPORT_INTERFACE,
|
||||
};
|
||||
|
||||
enum UsbPnpNotifyRemoveType {
|
||||
USB_PNP_NOTIFY_REMOVE_BUS_DEV_NUM,
|
||||
USB_PNP_NOTIFY_REMOVE_INTERFACE_NUM,
|
||||
};
|
||||
|
||||
enum {
|
||||
USB_PNP_NOTIFY_MATCH_VENDOR = 0x0001,
|
||||
USB_PNP_NOTIFY_MATCH_PRODUCT = 0x0002,
|
||||
USB_PNP_NOTIFY_MATCH_DEV_LOW = 0x0004,
|
||||
USB_PNP_NOTIFY_MATCH_DEV_HIGH = 0x0008,
|
||||
USB_PNP_NOTIFY_MATCH_DEV_CLASS = 0x0010,
|
||||
USB_PNP_NOTIFY_MATCH_DEV_SUBCLASS = 0x0020,
|
||||
USB_PNP_NOTIFY_MATCH_DEV_PROTOCOL = 0x0040,
|
||||
USB_PNP_NOTIFY_MATCH_INT_CLASS = 0x0080,
|
||||
USB_PNP_NOTIFY_MATCH_INT_SUBCLASS = 0x0100,
|
||||
USB_PNP_NOTIFY_MATCH_INT_PROTOCOL = 0x0200,
|
||||
USB_PNP_NOTIFY_MATCH_INT_NUMBER = 0x0400,
|
||||
};
|
||||
|
||||
struct UsbPnpNotifyServiceInfo {
|
||||
int32_t length;
|
||||
|
||||
int32_t devNum;
|
||||
int32_t busNum;
|
||||
|
||||
int32_t interfaceLength;
|
||||
uint8_t interfaceNumber[USB_PNP_INFO_MAX_INTERFACES];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct UsbPnpNotifyInterfaceInfo {
|
||||
uint8_t interfaceClass;
|
||||
uint8_t interfaceSubClass;
|
||||
uint8_t interfaceProtocol;
|
||||
|
||||
uint8_t interfaceNumber;
|
||||
};
|
||||
|
||||
struct UsbPnpNotifyDeviceInfo {
|
||||
uint16_t vendorId;
|
||||
uint16_t productId;
|
||||
|
||||
uint16_t bcdDeviceLow;
|
||||
uint16_t bcdDeviceHigh;
|
||||
|
||||
uint8_t deviceClass;
|
||||
uint8_t deviceSubClass;
|
||||
uint8_t deviceProtocol;
|
||||
};
|
||||
|
||||
struct UsbPnpNotifyMatchInfoTable {
|
||||
uint32_t usbDevAddr;
|
||||
int32_t devNum;
|
||||
int32_t busNum;
|
||||
|
||||
struct UsbPnpNotifyDeviceInfo deviceInfo;
|
||||
|
||||
uint8_t removeType;
|
||||
uint8_t numInfos;
|
||||
|
||||
struct UsbPnpNotifyInterfaceInfo interfaceInfo[USB_PNP_INFO_MAX_INTERFACES];
|
||||
};
|
||||
|
||||
struct HdfDeviceInfo *HdfDeviceInfoNewInstance(void);
|
||||
|
||||
@@ -29,7 +29,6 @@ void HdfDeviceInfoConstruct(struct HdfDeviceInfo *deviceInfo)
|
||||
deviceInfo->svcName = NULL;
|
||||
deviceInfo->moduleName = NULL;
|
||||
deviceInfo->deviceMatchAttr = NULL;
|
||||
deviceInfo->private = NULL;
|
||||
}
|
||||
|
||||
struct HdfDeviceInfo *HdfDeviceInfoNewInstance()
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 80 KiB After Width: | Height: | Size: 74 KiB |
@@ -17,12 +17,12 @@
|
||||
|
||||
static struct NetDeviceImpl *g_netDeviceImplTable[MAX_NETDEVICE_COUNT] = {NULL};
|
||||
|
||||
static bool FindAvailableTable(int32_t *index)
|
||||
static bool FindAvailableTable(uint32_t *index)
|
||||
{
|
||||
int32_t i;
|
||||
uint32_t i;
|
||||
|
||||
if (index == NULL) {
|
||||
HDF_LOGE("Find Available table index error!");
|
||||
HDF_LOGE("%s Find Available table index error!", __func__);
|
||||
return false;
|
||||
}
|
||||
for (i = 0; i < MAX_NETDEVICE_COUNT; i++) {
|
||||
@@ -34,7 +34,7 @@ static bool FindAvailableTable(int32_t *index)
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool AddNetDeviceImplToTable(int32_t index, struct NetDeviceImpl *netDeviceImpl)
|
||||
static bool AddNetDeviceImplToTable(uint32_t index, struct NetDeviceImpl *netDeviceImpl)
|
||||
{
|
||||
if (index >= MAX_NETDEVICE_COUNT) {
|
||||
HDF_LOGE("%s error because of not enough space!", __func__);
|
||||
@@ -68,7 +68,6 @@ static struct NetDeviceImpl *InitNetDeviceImpl(NetDevice *nd, NetIfCategory ifCa
|
||||
HDF_LOGE("%s fail: OsalMemCalloc fail!", __func__);
|
||||
return NULL;
|
||||
}
|
||||
(void)memset_s(ndImpl, sizeof(struct NetDeviceImpl), 0, sizeof(struct NetDeviceImpl));
|
||||
|
||||
ndImpl->netDevice = nd;
|
||||
if (RegisterNetDeviceImpl(ndImpl) != HDF_SUCCESS) {
|
||||
@@ -100,6 +99,7 @@ static void DeInitNetDeviceImpl(struct NetDeviceImpl *netDeviceImpl)
|
||||
|
||||
/* last release netDeviceImpl */
|
||||
OsalMemFree(netDeviceImpl);
|
||||
netDeviceImpl = NULL;
|
||||
HDF_LOGI("%s success!", __func__);
|
||||
return;
|
||||
}
|
||||
@@ -117,7 +117,7 @@ static struct NetDeviceImpl *GetImplByNetDevice(const struct NetDevice *netDevic
|
||||
}
|
||||
}
|
||||
}
|
||||
HDF_LOGE("Don't Get Impl by netdevice");
|
||||
HDF_LOGE("%s Get Impl by netdevice failed", __func__);
|
||||
return ndImpl;
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ struct NetDevice *NetDeviceInit(const char *ifName, uint32_t len, NetIfCategory
|
||||
{
|
||||
NetDevice *netDevice = NULL;
|
||||
struct NetDeviceImpl *ndImpl = NULL;
|
||||
int32_t index = 0;
|
||||
uint32_t index = 0;
|
||||
int32_t ret;
|
||||
|
||||
if ((ifName == NULL) || (strlen(ifName) != len) || (strlen(ifName) > IFNAMSIZ - 1)) {
|
||||
@@ -137,9 +137,8 @@ struct NetDevice *NetDeviceInit(const char *ifName, uint32_t len, NetIfCategory
|
||||
HDF_LOGE("%s fail: OsalMemCalloc fail!", __func__);
|
||||
return NULL;
|
||||
}
|
||||
(void)memset_s(netDevice, sizeof(NetDevice), 0, sizeof(NetDevice));
|
||||
if (memcpy_s(netDevice->name, IFNAMSIZ, ifName, len + 1) != EOK) {
|
||||
HDF_LOGE("%s fail: memcpy_s fail!", __func__);
|
||||
if (strcpy_s(netDevice->name, IFNAMSIZ, ifName) != EOK) {
|
||||
HDF_LOGE("%s fail: strcpy_s fail!", __func__);
|
||||
OsalMemFree(netDevice);
|
||||
return NULL;
|
||||
}
|
||||
@@ -318,7 +317,7 @@ static int32_t NetIfRxImpl(const struct NetDevice *netDevice, NetBuf *buff, Rece
|
||||
ProcessingResult ret = PROCESSING_CONTINUE;
|
||||
|
||||
if (ndImpl == NULL || ndImpl->interFace == NULL || ndImpl->interFace->receive == NULL) {
|
||||
HDF_LOGE("NetIfRxImpl fail : netdevice not exist!");
|
||||
HDF_LOGE("%s: NetIfRxImpl fail : netdevice not exist!", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
@@ -333,7 +332,7 @@ static int32_t NetIfRxImpl(const struct NetDevice *netDevice, NetBuf *buff, Rece
|
||||
HDF_LOGI("NetIfRxImpl specialEtherType Process not need TCP/IP stack!");
|
||||
return HDF_SUCCESS;
|
||||
} else {
|
||||
HDF_LOGE("NetIfRxImpl specialEtherType Process error");
|
||||
HDF_LOGE("%s: NetIfRxImpl specialEtherType Process error", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,13 +39,13 @@ int32_t HdfWifiGetBusIdx(void)
|
||||
* @brief as for now, we just support one wlan module in one board cause driver binds to wlan featere
|
||||
* due to that reason, once we detected one chip, we stop rescan.
|
||||
*/
|
||||
int HdfWlanSdioScan(struct HdfWlanDevice *data, struct HdfConfigWlanBus *busConfig)
|
||||
int32_t HdfWlanSdioScan(struct HdfWlanDevice *data, struct HdfConfigWlanBus *busConfig)
|
||||
{
|
||||
/* get config vendId, deviceId and chip-name which used in detect match process */
|
||||
HdfWlanGetSdioTableByConfig();
|
||||
|
||||
HdfWlanSdioScanTriggerByBusIndex(busConfig->busIdx);
|
||||
int ret = HdfWlanGetDetectedChip(data, busConfig);
|
||||
int32_t ret = HdfWlanGetDetectedChip(data, busConfig);
|
||||
HdfWlanSdioDriverUnReg();
|
||||
if (ret != HDF_SUCCESS) {
|
||||
return ret;
|
||||
@@ -54,7 +54,7 @@ int HdfWlanSdioScan(struct HdfWlanDevice *data, struct HdfConfigWlanBus *busConf
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int HdfWifiDriverBind(struct HdfDeviceObject *dev)
|
||||
static int32_t HdfWifiDriverBind(struct HdfDeviceObject *dev)
|
||||
{
|
||||
ErrorCode errCode;
|
||||
static struct IDeviceIoService wifiService = {
|
||||
@@ -179,7 +179,7 @@ static struct HdfChipDriverFactory *HdfWlanGetDriverFactory(const char *driverNa
|
||||
static int32_t HdfWlanDeinitInterface(struct HdfWlanDevice *device, const char *ifName,
|
||||
struct HdfChipDriverFactory *factory)
|
||||
{
|
||||
int ret;
|
||||
int32_t ret;
|
||||
struct NetDevice *netdev = NULL;
|
||||
struct HdfChipDriver *chipDriver = NULL;
|
||||
|
||||
@@ -369,7 +369,7 @@ static struct HdfWlanDevice *ProbeDevice(struct HdfConfigWlanDevInst *deviceConf
|
||||
return device;
|
||||
}
|
||||
|
||||
int32_t DeinitDevice(struct HdfWlanDevice *device)
|
||||
int32_t HdfWifiDeinitDevice(struct HdfWlanDevice *device)
|
||||
{
|
||||
struct HdfChipDriverFactory *chipDriverFact = NULL;
|
||||
int32_t ret;
|
||||
@@ -394,7 +394,7 @@ int32_t DeinitDevice(struct HdfWlanDevice *device)
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t InitDevice(struct HdfWlanDevice *device)
|
||||
int32_t HdfWifiInitDevice(struct HdfWlanDevice *device)
|
||||
{
|
||||
int32_t ret;
|
||||
struct HdfChipDriverFactory *chipDriverFact = NULL;
|
||||
@@ -424,7 +424,7 @@ int32_t InitDevice(struct HdfWlanDevice *device)
|
||||
/* thread callback function */
|
||||
static int32_t HdfWlanInitThread(void *para)
|
||||
{
|
||||
const uint32_t initDelaySec = 5;
|
||||
const uint32_t initDelaySec = 15;
|
||||
struct HdfDeviceObject *device = (struct HdfDeviceObject *)para;
|
||||
struct SubscriberCallback callback = { NULL };
|
||||
struct HdfConfigWlanDeviceList *devList = NULL;
|
||||
@@ -465,7 +465,7 @@ static int32_t HdfWlanInitThread(void *para)
|
||||
|
||||
// Load chip driver
|
||||
(void)DevSvcManagerClntSubscribeService(wlanDevice->driverName, callback);
|
||||
(void)InitDevice(wlanDevice);
|
||||
(void)HdfWifiInitDevice(wlanDevice);
|
||||
}
|
||||
|
||||
HDF_LOGV("%s:finished.", __func__);
|
||||
|
||||
@@ -17,9 +17,9 @@ extern "C" {
|
||||
#endif
|
||||
int32_t HdfWifiGetBusIdx(void);
|
||||
|
||||
int32_t DeinitDevice(struct HdfWlanDevice *device);
|
||||
int32_t HdfWifiDeinitDevice(struct HdfWlanDevice *device);
|
||||
|
||||
int32_t InitDevice(struct HdfWlanDevice *device);
|
||||
int32_t HdfWifiInitDevice(struct HdfWlanDevice *device);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef emmc_CORE_H
|
||||
#define emmc_CORE_H
|
||||
#ifndef EMMC_CORE_H
|
||||
#define EMMC_CORE_H
|
||||
|
||||
#include "emmc_if.h"
|
||||
#include "hdf_base.h"
|
||||
@@ -39,7 +39,7 @@ struct EmmcCntlr {
|
||||
|
||||
/**
|
||||
* @brief emmc host device operations.
|
||||
* These methods need to be filled up by specific paltform.
|
||||
* These methods need to be filled up by specific platform.
|
||||
*/
|
||||
struct EmmcMethod {
|
||||
int32_t (*getCid)(struct EmmcCntlr *, uint8_t *, uint32_t);
|
||||
|
||||
@@ -13,4 +13,4 @@
|
||||
|
||||
bool PlatInIrqContext(void);
|
||||
|
||||
#endif
|
||||
#endif /* PLATFORM_COMMON_H */
|
||||
|
||||
@@ -17,4 +17,4 @@
|
||||
#define PLAT_LOGV(fmt, arg...) HDF_LOGV(fmt, ##arg)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif /* PLATFORM_LOG_H */
|
||||
|
||||
@@ -38,7 +38,7 @@ struct SdioCntlr {
|
||||
|
||||
/**
|
||||
* @brief sdio host device operations.
|
||||
* These methods need to be filled up by specific paltform.
|
||||
* These methods need to be filled up by specific platform.
|
||||
*/
|
||||
struct SdioMethod {
|
||||
int32_t (*incrAddrReadBytes)(struct SdioCntlr *, uint8_t *, uint32_t, uint32_t, uint32_t);
|
||||
|
||||
@@ -45,7 +45,7 @@ struct WatchdogMethod {
|
||||
/**
|
||||
* @brief Add a new WatchdogCntlr to HDF.
|
||||
*
|
||||
* @param cntlr The watchdog conroller to be added.
|
||||
* @param cntlr The watchdog controller to be added.
|
||||
*
|
||||
* @return Returns 0 on success; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
|
||||
@@ -212,7 +212,7 @@ static int32_t GpioIrqBridgeFunc(uint16_t local, void *data)
|
||||
|
||||
(void)local;
|
||||
(void)OsalSpinLockIrqSave(&bridge->spin, &flags);
|
||||
if (bridge->stop == false) {
|
||||
if (!bridge->stop) {
|
||||
(void)OsalSemPost(&bridge->sem);
|
||||
}
|
||||
(void)OsalSpinUnlockIrqRestore(&bridge->spin, &flags);
|
||||
@@ -230,7 +230,7 @@ static int GpioIrqThreadWorker(void *data)
|
||||
if (ret != HDF_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
if (bridge->stop == true) {
|
||||
if (bridge->stop) {
|
||||
break;
|
||||
}
|
||||
PLAT_LOGV("GpioIrqThreadWorker: enter! gpio:%u-%u", bridge->cntlr->start, bridge->local);
|
||||
@@ -320,7 +320,7 @@ static void GpioIrqBridgeDestroy(struct GpioIrqBridge *bridge)
|
||||
#ifndef __KERNEL__
|
||||
uint32_t flags;
|
||||
(void)OsalSpinLockIrqSave(&bridge->spin, &flags);
|
||||
if (bridge->stop == false) {
|
||||
if (!bridge->stop) {
|
||||
bridge->stop = true;
|
||||
(void)OsalSemPost(&bridge->sem);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ static struct Watchdog *WatchdogGetById(int16_t wdtId)
|
||||
return service;
|
||||
}
|
||||
|
||||
|
||||
DevHandle WatchdogOpen(int16_t wdtId)
|
||||
{
|
||||
struct Watchdog *service = NULL;
|
||||
|
||||
@@ -106,7 +106,7 @@ int32_t OsalMutexTimedLock(struct OsalMutex *mutex, uint32_t ms)
|
||||
if (ret == ETIMEDOUT) {
|
||||
return HDF_ERR_TIMEOUT;
|
||||
} else {
|
||||
HDF_LOGE("%s time_out time:%d ret:%d", __func__, ms, ret);
|
||||
HDF_LOGE("%s time_out time:%u ret:%d", __func__, ms, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "osal_spinlock.h"
|
||||
#include <pthread.h>
|
||||
#include "hdf_log.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
#define HDF_LOG_TAG osal_spinlock
|
||||
|
||||
int32_t OsalSpinInit(OsalSpinlock *spinlock)
|
||||
{
|
||||
pthread_spinlock_t *spinTmp = NULL;
|
||||
int ret;
|
||||
|
||||
if (spinlock == NULL) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
spinlock->realSpinlock = NULL;
|
||||
|
||||
spinTmp = (pthread_spinlock_t *)OsalMemCalloc(sizeof(pthread_spinlock_t));
|
||||
if (spinTmp == NULL) {
|
||||
HDF_LOGE("malloc fail");
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
|
||||
ret = pthread_spin_init(spinTmp, PTHREAD_PROCESS_PRIVATE);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("pthread_spin_init fail %d %d", ret, __LINE__);
|
||||
OsalMemFree(spinTmp);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
spinlock->realSpinlock = (void *)spinTmp;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalSpinDestroy(OsalSpinlock *spinlock)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (spinlock == NULL || spinlock->realSpinlock == NULL) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
ret = pthread_spin_destroy((pthread_spinlock_t *)spinlock->realSpinlock);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("pthread_spin_destroy fail %d %d", ret, __LINE__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
OsalMemFree(spinlock->realSpinlock);
|
||||
spinlock->realSpinlock = NULL;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalSpinLock(OsalSpinlock *spinlock)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (spinlock == NULL || spinlock->realSpinlock == NULL) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
ret = pthread_spin_lock((pthread_spinlock_t *)spinlock->realSpinlock);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("pthread_spin_lock fail %d %d", ret, __LINE__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalSpinUnlock(OsalSpinlock *spinlock)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (spinlock == NULL || spinlock->realSpinlock == NULL) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
ret = pthread_spin_unlock((pthread_spinlock_t *)spinlock->realSpinlock);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("pthread_spin_unlock fail %d %d", ret, __LINE__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
#include "hdf_log.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
#define OSAL_PTHREAD_STACK_MIN 4096
|
||||
|
||||
#define HDF_LOG_TAG osal_thread
|
||||
|
||||
typedef void *(*PosixEntry)(void *data);
|
||||
@@ -75,7 +73,7 @@ int32_t OsalThreadCreate(struct OsalThread *thread, OsalThreadEntry threadEntry,
|
||||
|
||||
int32_t OsalThreadDestroy(struct OsalThread *thread)
|
||||
{
|
||||
if (thread->realThread != NULL) {
|
||||
if (thread != NULL && thread->realThread != NULL) {
|
||||
OsalMemFree(thread->realThread);
|
||||
thread->realThread = NULL;
|
||||
}
|
||||
@@ -129,7 +127,7 @@ int32_t OsalThreadStart(struct OsalThread *thread, const struct OsalThreadParam
|
||||
|
||||
size_t stackSize = param->stackSize;
|
||||
if (stackSize > 0) {
|
||||
stackSize = (stackSize < OSAL_PTHREAD_STACK_MIN) ? OSAL_PTHREAD_STACK_MIN : stackSize;
|
||||
stackSize = (stackSize < PTHREAD_STACK_MIN) ? PTHREAD_STACK_MIN : stackSize;
|
||||
resultCode = pthread_attr_setstacksize(&attribute, stackSize);
|
||||
if (resultCode != 0) {
|
||||
HDF_LOGE("pthread_attr_setstacksize errorno: %d", resultCode);
|
||||
|
||||
@@ -258,7 +258,7 @@ int HcsTestGetUint8ArrayElemSuccess(void)
|
||||
{
|
||||
uint8_t data[DATA_TEST_ARRAY_LENGTH] = { 0 };
|
||||
// the test data is 0, 1, 2, 3, 4, 5, 6, 7.
|
||||
uint8_t testData[DATA_TEST_ARRAY_LENGTH] = {0, 1, 2, 3, 4, 5, 6, 7};
|
||||
uint8_t testData[DATA_TEST_ARRAY_LENGTH] = { 0, 1, 2, 3, 4, 5, 6, 7 };
|
||||
uint32_t i;
|
||||
if (!TestGetRootNode()) {
|
||||
return HDF_FAILURE;
|
||||
@@ -272,7 +272,7 @@ int HcsTestGetUint8ArrayElemSuccess(void)
|
||||
int32_t ret = g_devResInstance->GetUint8ArrayElem(dataType, TEST_U8_ELEM_DATA, i, &data[i],
|
||||
DEFAULT_UINT8_MAX);
|
||||
if ((ret != HDF_SUCCESS) || (data[i] != testData[i])) {
|
||||
HDF_LOGE("%s failed, line: %d, ret = %d, i = %d, data = %u", __FUNCTION__, __LINE__, ret, i, data[i]);
|
||||
HDF_LOGE("%s failed, line: %d, ret = %d, i = %u, data = %u", __FUNCTION__, __LINE__, ret, i, data[i]);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
}
|
||||
@@ -303,7 +303,7 @@ int HcsTestGetUint8ArrayElemFail(void)
|
||||
for (i = 0; i < count; i++) {
|
||||
ret = g_devResInstance->GetUint8ArrayElem(dataType, READ_FOUR_DATA_TYPE, i, &data1[i], DEFAULT_UINT8_MAX);
|
||||
}
|
||||
// the 0~3 represents the loction in array.
|
||||
// the 0~3 represents the location in array.
|
||||
if ((ret == HDF_SUCCESS) || (data1[0] != U8_DATA) || (data1[1] != DEFAULT_UINT8_MAX) ||
|
||||
(data1[2] != DEFAULT_UINT8_MAX) || (data1[3] != DEFAULT_UINT8_MAX)) {
|
||||
HDF_LOGE("%s failed, line: %d, ret = %d, data = %x", __FUNCTION__, __LINE__, ret, data);
|
||||
@@ -321,7 +321,7 @@ int HcsTestGetUint8ArraySuccess(void)
|
||||
const struct DeviceResourceNode *dataType = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_DATA_TYPE_TEST);
|
||||
int32_t ret = g_devResInstance->GetUint8Array(dataType, TEST_U8_ELEM_DATA, data, DATA_TEST_ARRAY_LENGTH,
|
||||
DEFAULT_UINT8_MAX);
|
||||
// the 0~7 represents the loction in array or the value in hcs file.
|
||||
// the 0~7 represents the location in array or the value in hcs file.
|
||||
if ((ret != HDF_SUCCESS) || (data[0] != 0) || (data[1] != 1) || (data[2] != 2) || (data[3] != 3) || (data[4] != 4)
|
||||
|| (data[5] != 5) || (data[6] != 6) || (data[7] != 7)) {
|
||||
return HDF_FAILURE;
|
||||
@@ -337,13 +337,13 @@ int HcsTestGetUint8ArrayFail(void)
|
||||
}
|
||||
const struct DeviceResourceNode *dataType = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_DATA_TYPE_TEST);
|
||||
int32_t ret = g_devResInstance->GetUint8Array(dataType, READ_FOUR_DATA_TYPE, data, 0, DEFAULT_UINT8_MAX);
|
||||
// the 0, 1, 2 represents the loction in array, the 0 of second param is defalut value.
|
||||
// the 0, 1, 2 represents the location in array, the 0 of second param is default value.
|
||||
if ((ret == HDF_SUCCESS) || (data[0] != 0) || (data[1] != 0) || (data[2] != 0)) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
ret = g_devResInstance->GetUint8Array(dataType, READ_FOUR_DATA_TYPE, data, DATA_TYPE_NUM_U64 + 1,
|
||||
DEFAULT_UINT8_MAX);
|
||||
// the 0, 1, 2, 3, 4 represents the loction in array
|
||||
// the 0, 1, 2, 3, 4 represents the location in array
|
||||
if ((ret == HDF_SUCCESS) || (data[0] != U8_DATA) || (data[1] != DEFAULT_UINT8_MAX) || (data[2] != DEFAULT_UINT8_MAX)
|
||||
|| (data[3] != DEFAULT_UINT8_MAX) || (data[4] != DEFAULT_UINT8_MAX)) {
|
||||
return HDF_FAILURE;
|
||||
@@ -402,7 +402,7 @@ int HcsTestGetUint16ArrayElemSuccess(void)
|
||||
// the length of data is 8.
|
||||
uint16_t data[DATA_TEST_ARRAY_LENGTH] = { 0 };
|
||||
// the test data is 0, 1, 2, 3, 4, 5, 256, 257.
|
||||
uint16_t testData[DATA_TEST_ARRAY_LENGTH] = {0, 1, 2, 3, 4, 5, 256, 257};
|
||||
uint16_t testData[DATA_TEST_ARRAY_LENGTH] = { 0, 1, 2, 3, 4, 5, 256, 257 };
|
||||
uint32_t i;
|
||||
if (!TestGetRootNode()) {
|
||||
return HDF_FAILURE;
|
||||
@@ -444,7 +444,7 @@ int HcsTestGetUint16ArrayElemFail(void)
|
||||
for (i = 0; i < count; i++) {
|
||||
ret = g_devResInstance->GetUint16ArrayElem(dataType, READ_FOUR_DATA_TYPE, i, &data1[i], DEFAULT_UINT16_MAX);
|
||||
}
|
||||
// the 0~3 represents the loction in array.
|
||||
// the 0~3 represents the location in array.
|
||||
if ((ret == HDF_SUCCESS) || (data1[0] != U8_DATA) || (data1[1] != U16_DATA) || (data1[2] != DEFAULT_UINT16_MAX) ||
|
||||
(data1[3] != DEFAULT_UINT16_MAX)) {
|
||||
return HDF_FAILURE;
|
||||
@@ -461,7 +461,7 @@ int HcsTestGetUint16ArraySuccess(void)
|
||||
const struct DeviceResourceNode *dataType = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_DATA_TYPE_TEST);
|
||||
int32_t ret = g_devResInstance->GetUint16Array(dataType, TEST_U16_ELEM_DATA, data, DATA_TEST_ARRAY_LENGTH,
|
||||
DEFAULT_UINT16_MAX);
|
||||
// the data[0~7] represents the loction in array, the test data is 0, 1, 2, 3, 4, 5, 256, 257.
|
||||
// the data[0~7] represents the location in array, the test data is 0, 1, 2, 3, 4, 5, 256, 257.
|
||||
if ((ret != HDF_SUCCESS) || (data[0] != 0) || (data[1] != 1) || (data[2] != 2) || (data[3] != 3) || (data[4] != 4)
|
||||
|| (data[5] != 5) || (data[6] != 256) || (data[7] != 257)) {
|
||||
return HDF_FAILURE;
|
||||
@@ -477,13 +477,13 @@ int HcsTestGetUint16ArrayFail(void)
|
||||
}
|
||||
const struct DeviceResourceNode *dataType = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_DATA_TYPE_TEST);
|
||||
int32_t ret = g_devResInstance->GetUint16Array(dataType, READ_FOUR_DATA_TYPE, data, 0, DEFAULT_UINT16_MAX);
|
||||
// the 0, 1, 2 represents the loction in array, the 0 of second param is defalut value.
|
||||
// the 0, 1, 2 represents the location in array, the 0 of second param is default value.
|
||||
if ((ret == HDF_SUCCESS) || (data[0] != 0) || (data[1] != 0) || (data[2] != 0)) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
ret = g_devResInstance->GetUint16Array(dataType, READ_FOUR_DATA_TYPE, data, DATA_TYPE_NUM_U64 + 1,
|
||||
DEFAULT_UINT16_MAX);
|
||||
// the 0, 1, 2, 3, 4 represents the loction in array
|
||||
// the 0, 1, 2, 3, 4 represents the location in array
|
||||
if ((ret == HDF_SUCCESS) || (data[0] != U8_DATA) || (data[1] != U16_DATA) || (data[2] != DEFAULT_UINT16_MAX)
|
||||
|| (data[3] != DEFAULT_UINT16_MAX) || (data[4] != DEFAULT_UINT16_MAX)) {
|
||||
return HDF_FAILURE;
|
||||
@@ -537,7 +537,7 @@ int HcsTestGetUint32AttrValueFail(void)
|
||||
int HcsTestGetUint32ArrayElemSuccess(void)
|
||||
{
|
||||
uint32_t data[DATA_TYPE_NUM_U32] = { 0 };
|
||||
uint32_t testData[DATA_TYPE_NUM_U32] = {U8_DATA, U16_DATA, U32_DATA};
|
||||
uint32_t testData[DATA_TYPE_NUM_U32] = { U8_DATA, U16_DATA, U32_DATA };
|
||||
int32_t i;
|
||||
if (!TestGetRootNode()) {
|
||||
return HDF_FAILURE;
|
||||
@@ -578,7 +578,7 @@ int HcsTestGetUint32ArraySuccess(void)
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
int32_t ret = g_devResInstance->GetUint32Array(g_testRoot, BOARD_ID, data, BOARDID_LENGTH, DEFAULT_UINT32_MAX);
|
||||
// the 0, 1 represents the loction in array.
|
||||
// the 0, 1 represents the location in array.
|
||||
if ((ret != HDF_SUCCESS) || (data[0] != U32_DATA) || (data[1] != U16_DATA)) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
@@ -592,12 +592,12 @@ int HcsTestGetUint32ArrayFail(void)
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
int32_t ret = g_devResInstance->GetUint32Array(g_testRoot, BOARD_ID, data, 0, DEFAULT_UINT32_MAX);
|
||||
// the 0, 1, 2 represents the loction in array, the 0 of second param is defalut value.
|
||||
// the 0, 1, 2 represents the location in array, the 0 of second param is default value.
|
||||
if ((ret == HDF_SUCCESS) || (data[0] != 0) || (data[1] != 0) || (data[2] != 0)) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
ret = g_devResInstance->GetUint32Array(g_testRoot, BOARD_ID, data, DATA_TYPE_NUM_U32, DEFAULT_UINT32_MAX);
|
||||
// the 0, 1, 2 represents the loction in array
|
||||
// the 0, 1, 2 represents the location in array
|
||||
if ((ret == HDF_SUCCESS) || (data[0] != U32_DATA) || (data[1] != U16_DATA) || (data[2] != DEFAULT_UINT32_MAX)) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
@@ -655,7 +655,7 @@ int HcsTestGetUint64AttrValueFail(void)
|
||||
int HcsTestGetUint64ArrayElemSuccess(void)
|
||||
{
|
||||
uint64_t data[DATA_TYPE_NUM_U64] = { 0 };
|
||||
uint64_t testData[DATA_TYPE_NUM_U64] = {U8_DATA, U16_DATA, U32_DATA, U64_DATA};
|
||||
uint64_t testData[DATA_TYPE_NUM_U64] = { U8_DATA, U16_DATA, U32_DATA, U64_DATA };
|
||||
uint32_t i;
|
||||
if (!TestGetRootNode()) {
|
||||
return HDF_FAILURE;
|
||||
@@ -699,7 +699,7 @@ int HcsTestGetUint64ArraySuccess(void)
|
||||
const struct DeviceResourceNode *dataType = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_DATA_TYPE_TEST);
|
||||
int32_t ret = g_devResInstance->GetUint64Array(dataType, READ_FOUR_DATA_TYPE, data, DATA_TYPE_NUM_U64,
|
||||
DEFAULT_UINT64_MAX);
|
||||
// the 0, 1, 2 represents the loction in array.
|
||||
// the 0, 1, 2 represents the location in array.
|
||||
if ((ret != HDF_SUCCESS) || (data[0] != U8_DATA) || (data[1] != U16_DATA) || (data[2] != U32_DATA) ||
|
||||
(data[3] != U64_DATA)) {
|
||||
return HDF_FAILURE;
|
||||
@@ -715,13 +715,13 @@ int HcsTestGetUint64ArrayFail(void)
|
||||
}
|
||||
const struct DeviceResourceNode *dataType = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_DATA_TYPE_TEST);
|
||||
int32_t ret = g_devResInstance->GetUint64Array(dataType, READ_FOUR_DATA_TYPE, data, 0, DEFAULT_UINT64_MAX);
|
||||
// the 0, 1, 2 represents the loction in array, the 0 of second param is defalut value.
|
||||
// the 0, 1, 2 represents the location in array, the 0 of second param is default value.
|
||||
if ((ret == HDF_SUCCESS) || (data[0] != 0) || (data[1] != 0) || (data[2] != 0)) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
ret = g_devResInstance->GetUint64Array(dataType, READ_FOUR_DATA_TYPE, data, DATA_TYPE_NUM_U64 + 1,
|
||||
DEFAULT_UINT64_MAX);
|
||||
// the 0, 1, 2, 3, 4 represents the loction in array
|
||||
// the 0, 1, 2, 3, 4 represents the location in array
|
||||
if ((ret == HDF_SUCCESS) || (data[0] != U8_DATA) || (data[1] != U16_DATA) || (data[2] != U32_DATA)
|
||||
|| (data[3] != U64_DATA) || (data[4] != DEFAULT_UINT64_MAX)) {
|
||||
return HDF_FAILURE;
|
||||
@@ -865,7 +865,7 @@ int HcsTestTraverseAttrInNodeFail(void)
|
||||
|
||||
const struct DeviceResourceNode *childNode = NULL;
|
||||
DEV_RES_NODE_FOR_EACH_CHILD_NODE(fingerprintNode, childNode) {
|
||||
if (childNode == NULL) {
|
||||
if ((childNode == NULL) || (childNode->name == NULL)) {
|
||||
break;
|
||||
}
|
||||
if ((strcmp(childNode->name, "fingerprint_one") == 0) || (strcmp(childNode->name, "fingerprint_two") == 0)) {
|
||||
@@ -886,9 +886,9 @@ int HcsTestGetStringSuccess(void)
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
const struct DeviceResourceNode *audioNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_AUDIO_INFO);
|
||||
const char *ptype = NULL;
|
||||
int32_t readString = g_devResInstance->GetString(audioNode, "cust_name", &ptype, NULL);
|
||||
if ((readString != HDF_SUCCESS) || (ptype == NULL) || (strcmp(ptype, "audio_custom_v2") != HDF_SUCCESS)) {
|
||||
const char *type = NULL;
|
||||
int32_t readString = g_devResInstance->GetString(audioNode, "cust_name", &type, NULL);
|
||||
if ((readString != HDF_SUCCESS) || (type == NULL) || (strcmp(type, "audio_custom_v2") != HDF_SUCCESS)) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
@@ -900,17 +900,17 @@ int HcsTestGetStringFail(void)
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
const struct DeviceResourceNode *audioNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_AUDIO_INFO);
|
||||
const char *ptype = NULL;
|
||||
int32_t testReadString = g_devResInstance->GetString(audioNode, INVALID_STRING, &ptype, STRING_ATTR_VALUE);
|
||||
if ((testReadString == HDF_SUCCESS) || (ptype == NULL) || (strcmp(ptype, STRING_ATTR_VALUE) != HDF_SUCCESS)) {
|
||||
const char *type = NULL;
|
||||
int32_t testReadString = g_devResInstance->GetString(audioNode, INVALID_STRING, &type, STRING_ATTR_VALUE);
|
||||
if ((testReadString == HDF_SUCCESS) || (type == NULL) || (strcmp(type, STRING_ATTR_VALUE) != HDF_SUCCESS)) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
testReadString = g_devResInstance->GetString(audioNode, INVALID_STRING, NULL, STRING_ATTR_VALUE);
|
||||
if ((testReadString == HDF_SUCCESS) || (ptype == NULL) || (strcmp(ptype, STRING_ATTR_VALUE) != HDF_SUCCESS)) {
|
||||
if ((testReadString == HDF_SUCCESS) || (type == NULL) || (strcmp(type, STRING_ATTR_VALUE) != HDF_SUCCESS)) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
testReadString = g_devResInstance->GetString(audioNode, INVALID_STRING, &ptype, NULL);
|
||||
if (testReadString == HDF_SUCCESS || ptype != NULL) {
|
||||
testReadString = g_devResInstance->GetString(audioNode, INVALID_STRING, &type, NULL);
|
||||
if ((testReadString == HDF_SUCCESS) || (type != NULL)) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
@@ -923,17 +923,17 @@ int HcsTestGetStringArrayElemSuccess(void)
|
||||
}
|
||||
const char *rawDataDts = NULL;
|
||||
const struct DeviceResourceNode *fingerprintNode = g_devResInstance->GetChildNode(g_testRoot, FINGERPRINT_INFO);
|
||||
// the third param is the loction in string_list_names array.
|
||||
// the third param(0) is the location in string_list_names array.
|
||||
int32_t ret = g_devResInstance->GetStringArrayElem(fingerprintNode, STRING_LIST_NAMES, 0, &rawDataDts, NULL);
|
||||
if ((ret != HDF_SUCCESS) || (strcmp(rawDataDts, "first") != HDF_SUCCESS)) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
// the third param is the loction in string_list_names array.
|
||||
// the third param(1) is the location in string_list_names array.
|
||||
ret = g_devResInstance->GetStringArrayElem(fingerprintNode, STRING_LIST_NAMES, 1, &rawDataDts, NULL);
|
||||
if ((ret != HDF_SUCCESS) || (strcmp(rawDataDts, "second") != HDF_SUCCESS)) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
// the second param is 2, indicates the index, the third param is the loction in string_list_names array.
|
||||
// the third param(2) is the location in string_list_names array.
|
||||
ret = g_devResInstance->GetStringArrayElem(fingerprintNode, STRING_LIST_NAMES, 2, &rawDataDts, NULL);
|
||||
if ((ret != HDF_SUCCESS) || (strcmp(rawDataDts, "third") != HDF_SUCCESS)) {
|
||||
return HDF_FAILURE;
|
||||
@@ -948,14 +948,14 @@ int HcsTestGetStringArrayElemFail(void)
|
||||
}
|
||||
const char *rawDataDts = NULL;
|
||||
const struct DeviceResourceNode *fingerprintNode = g_devResInstance->GetChildNode(g_testRoot, FINGERPRINT_INFO);
|
||||
// the third param(3) is the loction in string_list_names array.
|
||||
// the third param(3) is the location in string_list_names array.
|
||||
int32_t ret = g_devResInstance->GetStringArrayElem(fingerprintNode, STRING_LIST_NAMES, 3, &rawDataDts,
|
||||
STRING_ATTR_VALUE);
|
||||
if ((ret == HDF_SUCCESS) || (strcmp(rawDataDts, STRING_ATTR_VALUE) != HDF_SUCCESS)) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
// the third param(1) is the loction in string_list_names array.
|
||||
// the third param(1) is the location in string_list_names array.
|
||||
ret = g_devResInstance->GetStringArrayElem(fingerprintNode, READ_U32_INDEX, 1, &rawDataDts, STRING_ATTR_VALUE);
|
||||
if ((ret == HDF_SUCCESS) || (strcmp(rawDataDts, STRING_ATTR_VALUE) != HDF_SUCCESS)) {
|
||||
return HDF_FAILURE;
|
||||
|
||||
@@ -69,7 +69,7 @@ int HdfTestSendMsgToService(struct HdfTestMsg *msg)
|
||||
}
|
||||
|
||||
if (!HdfSbufReadBuffer(g_reply, (const void **)&testReply, &len)) {
|
||||
printf("HdfTestSendMsgToService g_reply read failed\n\r");
|
||||
printf("HdfTestSendMsgToService g_reply read failed\n\r");
|
||||
}
|
||||
|
||||
if (testReply == NULL) {
|
||||
|
||||
@@ -127,7 +127,7 @@ static int32_t HdfTestCaseProcess(struct HdfDeviceIoClient *client,
|
||||
replyMsg.cmd = msg->cmd;
|
||||
replyMsg.subCmd = msg->subCmd;
|
||||
|
||||
HDF_LOGE("%s::Hdf test receive cmd: command[%d], subCommand[%d]", __func__, msg->cmd, msg->subCmd);
|
||||
HDF_LOGE("%s::Hdf test receive cmd: command[%u], subCommand[%u]", __func__, msg->cmd, msg->subCmd);
|
||||
|
||||
replyMsg.result = HDF_FAILURE;
|
||||
for (i = 0; i < sizeof(g_hdfTestFuncList) / sizeof(g_hdfTestFuncList[0]); ++i) {
|
||||
|
||||
@@ -12,12 +12,10 @@
|
||||
|
||||
#define HDF_LOG_TAG sample_driver_test
|
||||
|
||||
#define SAMPLE_WRITE_READ 123
|
||||
#ifndef INT32_MAX
|
||||
#define INT32_MAX 0x7fffffff
|
||||
#endif
|
||||
|
||||
|
||||
void HdfSampleDriverRelease(struct HdfDeviceObject *deviceObject)
|
||||
{
|
||||
(void)deviceObject;
|
||||
|
||||
@@ -860,7 +860,7 @@ pTestCaseFunc g_hdfNetBufQueueTestCaseLists[] = {
|
||||
HdfNetBufQueueTest009,
|
||||
};
|
||||
|
||||
// HDFNetBuf test canse Entry
|
||||
// HDFNetBuf test case Entry
|
||||
int32_t HdfNetBufTest(void)
|
||||
{
|
||||
int32_t ret, i;
|
||||
@@ -879,7 +879,7 @@ int32_t HdfNetBufTest(void)
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
// HdfNetBufQueue test canse Entry
|
||||
// HdfNetBufQueue test case Entry
|
||||
int32_t HdfNetBufQueueTest(void)
|
||||
{
|
||||
int32_t ret, i;
|
||||
|
||||
@@ -21,7 +21,10 @@ static bool WiFiNetDeviceTestEnv(void)
|
||||
{
|
||||
if (g_netDevice == NULL) {
|
||||
char devName[IFNAMSIZ] = {0};
|
||||
strncpy_s(devName, IFNAMSIZ, "wlan_test_0", strlen("wlan_test_0") + 1);
|
||||
if (strncpy_s(devName, IFNAMSIZ, "wlan_test_0", strlen("wlan_test_0") + 1) != EOK) {
|
||||
HDF_LOGE("%s: strcpy_s fail", __func__);
|
||||
return false;
|
||||
}
|
||||
g_netDevice = NetDeviceInit(devName, strlen(devName), LITE_OS);
|
||||
if (g_netDevice == NULL) {
|
||||
HDF_LOGE("%s fail ", __func__);
|
||||
@@ -117,6 +120,7 @@ int32_t WiFiNetDviceTestSetAddr(void)
|
||||
int32_t WiFiNetDviceTestRx(void)
|
||||
{
|
||||
NetBuf *buff = NULL;
|
||||
|
||||
int count = sizeof(g_filterData);
|
||||
buff = NetBufAlloc(count);
|
||||
if (buff == NULL) {
|
||||
|
||||
@@ -154,7 +154,7 @@ int32_t WiFiFlowControlTestSendData(void)
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (g_flowControlInstance->interface == NULL) {
|
||||
HDF_LOGE("%s interface =null!", __func__);
|
||||
HDF_LOGE("%s interface = null!", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
id = g_flowControlInstance->interface->getQueueIdByEtherBuff(buff);
|
||||
|
||||
@@ -158,7 +158,7 @@ int ThreadTest2(void *arg)
|
||||
OsalGetTime(&hdfTs2);
|
||||
OsalDiffTime(&hdfTs1, &hdfTs2, &hdfTsDiff);
|
||||
if (cnt % HDF_THREAD_TEST_MUX_CNT == 0) {
|
||||
HDF_LOGE("%s %ds %dus", __func__,
|
||||
HDF_LOGE("%s %us %uus", __func__,
|
||||
(uint32_t)hdfTsDiff.sec, (uint32_t)hdfTsDiff.usec);
|
||||
}
|
||||
if (g_testEndFlag) {
|
||||
@@ -345,7 +345,7 @@ static void OsaFWTest(int flag)
|
||||
(void)memset_s(&fw, sizeof(fw), 0, sizeof(fw));
|
||||
ret = OsalRequestFirmware(&fw, name, NULL);
|
||||
UT_TEST_CHECK_RET(ret != HDF_SUCCESS, OSAL_FW_REQUEST);
|
||||
HDF_LOGE("%s %d", name, fw.fwSize);
|
||||
HDF_LOGE("%s %u", name, fw.fwSize);
|
||||
|
||||
(void)memset_s(&block, sizeof(block), 0, sizeof(block));
|
||||
ret = OsalReadFirmware(&fw, &block);
|
||||
@@ -355,10 +355,10 @@ static void OsaFWTest(int flag)
|
||||
#if defined(__LITEOS__)
|
||||
ret = OsalSeekFirmware(&fw, HDF_FILE_SEEK_TEST);
|
||||
UT_TEST_CHECK_RET(ret != HDF_SUCCESS, OSAL_FW_SEEK);
|
||||
HDF_LOGE("%s %d %d", name, block.dataSize, block.curOffset);
|
||||
HDF_LOGE("%s %u %d", name, block.dataSize, block.curOffset);
|
||||
ret = OsalReadFirmware(&fw, &block);
|
||||
UT_TEST_CHECK_RET(ret != HDF_SUCCESS, OSAL_FW_READ);
|
||||
HDF_LOGE("%s %d %d", name, block.dataSize, block.curOffset);
|
||||
HDF_LOGE("%s %u %d", name, block.dataSize, block.curOffset);
|
||||
fwBuf += HDF_FILE_SEEK_TEST;
|
||||
UT_TEST_CHECK_RET(memcmp(block.data, fwBuf, block.dataSize) != 0, OSAL_FW_DATA_CHECK);
|
||||
#endif
|
||||
@@ -367,8 +367,6 @@ static void OsaFWTest(int flag)
|
||||
ret = OsalReadFirmware(&fw, &block);
|
||||
UT_TEST_CHECK_RET(ret == HDF_SUCCESS, OSAL_FW_READ_AFTER_RELEASE);
|
||||
HDF_LOGE("[OSAL_UT_TEST]%s end", __func__);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#define THREAD_TEST_TIMER_RUN 20
|
||||
@@ -542,8 +540,6 @@ void OsaThreadTest1(void)
|
||||
UT_TEST_CHECK_RET(ret != HDF_SUCCESS, OSAL_THREAD_CREATE);
|
||||
ret = OsalThreadStart(&thread, &threadCfg);
|
||||
UT_TEST_CHECK_RET(ret != HDF_SUCCESS, OSAL_THREAD_CREATE);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void OsaThreadTest(void)
|
||||
@@ -601,27 +597,27 @@ static void OsaTimeTest(void)
|
||||
ret = OsalGetTime(&hdfTs2);
|
||||
UT_TEST_CHECK_RET(ret != HDF_SUCCESS, OSAL_TIME_GETTIME);
|
||||
ret = OsalDiffTime(&hdfTs, &hdfTs2, &hdfTsDiff);
|
||||
HDF_LOGE("%s %ds %dus", __func__, (uint32_t)hdfTsDiff.sec, (uint32_t)hdfTsDiff.usec);
|
||||
HDF_LOGE("%s %us %uus", __func__, (uint32_t)hdfTsDiff.sec, (uint32_t)hdfTsDiff.usec);
|
||||
UT_TEST_CHECK_RET(!OsalCheckTime(&hdfTsDiff, TIME_TEST_SLEEP_S * HDF_KILO_UNIT), OSAL_TIME_DIFFTIME);
|
||||
|
||||
OsalGetTime(&hdfTs);
|
||||
OsalUDelay(TIME_TEST_SLEEP_MS);
|
||||
(void)OsalGetTime(&hdfTs2);
|
||||
(void)OsalDiffTime(&hdfTs, &hdfTs2, &hdfTsDiff);
|
||||
HDF_LOGE("%s %ds %dus", __func__, (uint32_t)hdfTsDiff.sec, (uint32_t)hdfTsDiff.usec);
|
||||
HDF_LOGE("%s %us %uus", __func__, (uint32_t)hdfTsDiff.sec, (uint32_t)hdfTsDiff.usec);
|
||||
|
||||
OsalGetTime(&hdfTs);
|
||||
OsalMDelay(TIME_TEST_SLEEP_MS);
|
||||
(void)OsalGetTime(&hdfTs2);
|
||||
(void)OsalDiffTime(&hdfTs, &hdfTs2, &hdfTsDiff);
|
||||
HDF_LOGE("%s %ds %dus", __func__, (uint32_t)hdfTsDiff.sec, (uint32_t)hdfTsDiff.usec);
|
||||
HDF_LOGE("%s %us %uus", __func__, (uint32_t)hdfTsDiff.sec, (uint32_t)hdfTsDiff.usec);
|
||||
|
||||
OsalGetTime(&hdfTs);
|
||||
OsalMSleep(TIME_TEST_SLEEP_MS);
|
||||
ret = OsalGetTime(&hdfTs2);
|
||||
UT_TEST_CHECK_RET(ret != HDF_SUCCESS, OSAL_TIME_GETTIME);
|
||||
ret = OsalDiffTime(&hdfTs, &hdfTs2, &hdfTsDiff);
|
||||
HDF_LOGE("%s %ds %dus", __func__, (uint32_t)hdfTsDiff.sec, (uint32_t)hdfTsDiff.usec);
|
||||
HDF_LOGE("%s %us %uus", __func__, (uint32_t)hdfTsDiff.sec, (uint32_t)hdfTsDiff.usec);
|
||||
UT_TEST_CHECK_RET(ret != HDF_SUCCESS, OSAL_TIME_DIFFTIME);
|
||||
UT_TEST_CHECK_RET(!OsalCheckTime(&hdfTsDiff, TIME_TEST_SLEEP_MS), OSAL_TIME_DIFFTIME);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
int OsalGetTestResult(uint32_t cmd)
|
||||
{
|
||||
HDF_LOGD("[OSAL_UT_TEST]%s %d start", __func__, cmd);
|
||||
HDF_LOGD("[OSAL_UT_TEST]%s %u start", __func__, cmd);
|
||||
return OSAL_TEST_CASE_CHECK(cmd);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ int32_t HdfOsalEntry(HdfTestMsg *msg)
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
HDF_LOGD("HdfTest:osal test result[%s-%d %d]", ((result != 0) ? "failed" : "pass"), result, msg->subCmd);
|
||||
HDF_LOGD("HdfTest:osal test result[%s-%d %u]", ((result != 0) ? "failed" : "pass"), result, msg->subCmd);
|
||||
msg->result = (result != 0) ? HDF_FAILURE : HDF_SUCCESS;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
|
||||
@@ -46,7 +46,7 @@ static int32_t TestEmmcGetCid(struct EmmcTester *tester)
|
||||
|
||||
ret = EmmcGetCid(tester->handle, cid, EMMC_CID_LEN);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: EmmcGetCid fail! ret=%d.", __func__, ret);
|
||||
HDF_LOGE("%s: EmmcGetCid failed ret=%d.", __func__, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
for (i = 0; i < EMMC_CID_LEN; i++) {
|
||||
@@ -62,7 +62,7 @@ struct EmmcTestFunc g_emmcTestFunc[] = {
|
||||
static int32_t EmmcTestEntry(struct EmmcTester *tester, int32_t cmd)
|
||||
{
|
||||
int32_t i;
|
||||
int32_t ret;
|
||||
int32_t ret = HDF_SUCCESS;
|
||||
bool isFind = false;
|
||||
|
||||
if (tester == NULL) {
|
||||
@@ -71,7 +71,7 @@ static int32_t EmmcTestEntry(struct EmmcTester *tester, int32_t cmd)
|
||||
}
|
||||
tester->handle = EmmcTestGetHandle(tester);
|
||||
if (tester->handle == NULL) {
|
||||
HDF_LOGE("%s: emmc test get handle fail", __func__);
|
||||
HDF_LOGE("%s: emmc test get handle failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
for (i = 0; i < sizeof(g_emmcTestFunc) / sizeof(g_emmcTestFunc[0]); i++) {
|
||||
@@ -81,9 +81,9 @@ static int32_t EmmcTestEntry(struct EmmcTester *tester, int32_t cmd)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isFind == false) {
|
||||
if (!isFind) {
|
||||
ret = HDF_ERR_NOT_SUPPORT;
|
||||
HDF_LOGE("%s: cmd %d not support", __func__, cmd);
|
||||
HDF_LOGE("%s: cmd %d not supported", __func__, cmd);
|
||||
}
|
||||
EmmcTestReleaseHandle(tester->handle);
|
||||
return ret;
|
||||
@@ -96,19 +96,19 @@ static int32_t EmmcTestFillConfig(struct EmmcTester *tester, const struct Device
|
||||
|
||||
drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
|
||||
if (drsOps == NULL || drsOps->GetUint32 == NULL) {
|
||||
HDF_LOGE("%s: invalid drs ops fail!", __func__);
|
||||
HDF_LOGE("%s: invalid drs ops", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
ret = drsOps->GetUint32(node, "busNum", &(tester->busNum), 0);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: fill bus num fail!", __func__);
|
||||
HDF_LOGE("%s: fill bus num failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = drsOps->GetUint32(node, "hostId", &(tester->hostId), 0);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: fill hostId fail!", __func__);
|
||||
HDF_LOGE("%s: fill hostId failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ static int32_t EmmcTestInit(struct HdfDeviceObject *device)
|
||||
}
|
||||
ret = EmmcTestFillConfig(tester, device->property);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: read config fail!", __func__);
|
||||
HDF_LOGE("%s: read config failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
tester->TestEntry = EmmcTestEntry;
|
||||
|
||||
@@ -195,7 +195,7 @@ static int32_t TestCaseGpioIrq(struct GpioTester *tester, uint16_t mode, bool in
|
||||
}
|
||||
#endif
|
||||
if (tester->irqCnt <= 0) {
|
||||
HDF_LOGE("%s: mode:%x on %u fail!", __func__, mode, tester->gpioIrq);
|
||||
HDF_LOGE("%s: set mode:%x on %u failed", __func__, mode, tester->gpioIrq);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
|
||||
@@ -24,7 +24,7 @@ static int32_t I2cTestDispatch(struct HdfDeviceIoClient *client, int cmd, struct
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
if (!HdfSbufWriteBuffer(reply, &g_config, sizeof(g_config))) {
|
||||
HDF_LOGE("%s: writ reply fail!", __func__);
|
||||
HDF_LOGE("%s: write reply failed", __func__);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
} else {
|
||||
@@ -41,37 +41,37 @@ static int32_t I2cTestReadConfig(struct I2cTestConfig *config, const struct Devi
|
||||
|
||||
drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
|
||||
if (drsOps == NULL || drsOps->GetUint32 == NULL) {
|
||||
HDF_LOGE("%s: invalid drs ops fail!", __func__);
|
||||
HDF_LOGE("%s: invalid drs ops", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
ret = drsOps->GetUint16(node, "bus_num", &config->busNum, 0);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: read bus num fail!", __func__);
|
||||
HDF_LOGE("%s: read bus num failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = drsOps->GetUint16(node, "dev_addr", &config->devAddr, 0);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: read dev addr fail!", __func__);
|
||||
HDF_LOGE("%s: read dev addr failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = drsOps->GetUint16(node, "reg_len", &config->regLen, 1);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: read reg len fail!", __func__);
|
||||
HDF_LOGE("%s: read reg len failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = drsOps->GetUint16(node, "reg_addr", &config->regAddr, 0);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: read reg addr fail!", __func__);
|
||||
HDF_LOGE("%s: read reg addr failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = drsOps->GetUint16(node, "buf_size", &config->bufSize, 0);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: read buf size fail!", __func__);
|
||||
HDF_LOGE("%s: read buf size failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ static int32_t I2cTestBind(struct HdfDeviceObject *device)
|
||||
|
||||
ret = I2cTestReadConfig(&g_config, device->property);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: read config fail!", __func__);
|
||||
HDF_LOGE("%s: read config failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#define I2C_TEST_BUF_SIZE_MAX 128
|
||||
#define I2C_TEST_REG_LEN 2
|
||||
#define I2C_TEST_MLTTHD_TIMES 1000
|
||||
#define I2C_TEST_STACK_SIZE (1024*100)
|
||||
#define I2C_TEST_STACK_SIZE (1024 * 100)
|
||||
#define I2C_TEST_WAIT_TIMES 200
|
||||
|
||||
static struct I2cMsg g_msgs[I2C_TEST_MSG_NUM];
|
||||
@@ -84,7 +84,7 @@ struct I2cTester *I2cTesterGet(void)
|
||||
static struct I2cTester tester;
|
||||
static bool hasInit = false;
|
||||
|
||||
if (hasInit == true) {
|
||||
if (hasInit) {
|
||||
return &tester;
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ struct I2cTester *I2cTesterGet(void)
|
||||
|
||||
tester.handle = I2cOpen(tester.config.busNum);
|
||||
if (tester.handle == NULL) {
|
||||
HDF_LOGE("I2cTesterGet: open i2cBus:%u fail! handle:%p", tester.config.busNum, tester.handle);
|
||||
HDF_LOGE("I2cTesterGet: open i2cBus:%u fail!", tester.config.busNum);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -217,14 +217,14 @@ int32_t I2cTestWriteRead(void)
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int I2cTestThreadFunc(void *parm)
|
||||
static int I2cTestThreadFunc(void *param)
|
||||
{
|
||||
int32_t i, ret;
|
||||
struct I2cTester *tester = NULL;
|
||||
|
||||
tester = I2cTesterGet();
|
||||
if (tester == NULL || tester->handle == NULL) {
|
||||
*((int32_t *)parm) = 1;
|
||||
*((int32_t *)param) = 1;
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ static int I2cTestThreadFunc(void *parm)
|
||||
}
|
||||
}
|
||||
|
||||
*((int32_t *)parm) = 1;
|
||||
*((int32_t *)param) = 1;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ static void DoAllPlatformTest(void)
|
||||
|
||||
static int32_t PlatformTestBind(struct HdfDeviceObject *device)
|
||||
{
|
||||
struct IDeviceIoService service;
|
||||
static struct IDeviceIoService service;
|
||||
|
||||
if (device == NULL) {
|
||||
HDF_LOGE("%s: device is null!", __func__);
|
||||
|
||||
@@ -60,13 +60,13 @@ static int32_t TestSdioIncrAddrReadAndWriteOtherBytes(struct SdioTester *tester)
|
||||
HDF_LOGE("%s: SdioReadBytes fail! ret=%d.", __func__, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HDF_LOGE("%s: read, data[0]:%d\n", __func__, data[0]);
|
||||
HDF_LOGE("%s: read, data[0]:%u\n", __func__, data[0]);
|
||||
ret = SdioWriteBytes(tester->handle, &data[0], addr, 1, 0);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: SdioWriteBytes fail! ret=%d.", __func__, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HDF_LOGE("%s: write, data[0]:%d\n", __func__, data[0]);
|
||||
HDF_LOGE("%s: write, data[0]:%u\n", __func__, data[0]);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ static int32_t TestSdioIncrAddrReadAndWriteOneByte(struct SdioTester *tester)
|
||||
HDF_LOGE("%s: SdioReadBytes fail! ret=%d.", __func__, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HDF_LOGE("%s: read, val:%d.", __func__, val);
|
||||
HDF_LOGE("%s: read, val:%u.", __func__, val);
|
||||
/* read 1 bits */
|
||||
addr++;
|
||||
ret = SdioReadBytes(tester->handle, &val, addr, 1, 0);
|
||||
@@ -106,7 +106,7 @@ static int32_t TestSdioIncrAddrReadAndWriteOneByte(struct SdioTester *tester)
|
||||
HDF_LOGE("%s: SdioReadBytes fail! ret=%d.", __func__, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HDF_LOGE("%s: read, val:%d.", __func__, val);
|
||||
HDF_LOGE("%s: read, val:%u.", __func__, val);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -144,14 +144,14 @@ static int32_t TestSdioFixedAddrReadAndWriteOtherBytes(struct SdioTester *tester
|
||||
HDF_LOGE("%s: SdioReadBytesFromFixedAddr fail! ret=%d.", __func__, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HDF_LOGE("%s: read, data[0]:%d, data[1]:%d\n", __func__, data[0], data[1]);
|
||||
HDF_LOGE("%s: read, data[0]:%u, data[1]:%u\n", __func__, data[0], data[1]);
|
||||
/* write bits */
|
||||
ret = SdioWriteBytes(tester->handle, &data[0], addr, 1, 0);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: SdioWriteBytesToFixedAddr fail! ret=%d.", __func__, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HDF_LOGE("%s: write, data[0]:%d, data[1]:%d.", __func__, data[0], data[1]);
|
||||
HDF_LOGE("%s: write, data[0]:%u, data[1]:%u.", __func__, data[0], data[1]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ static int32_t TestSdioFunc0ReadAndWriteBytes(struct SdioTester *tester)
|
||||
}
|
||||
SdioReleaseHost(tester->handle);
|
||||
|
||||
HDF_LOGE("%s: Func0 Read, val :%d.", __func__, val);
|
||||
HDF_LOGE("%s: Func0 Read, val:%u.", __func__, val);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ static int32_t TestSdioSetAndGetFuncInfo(struct SdioTester *tester)
|
||||
HDF_LOGE("%s: SdioGetCommonInfo fail! ret=%d.", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
HDF_LOGE("%s: succ! Timeout=%d.", __func__, info.funcInfo.enTimeout);
|
||||
HDF_LOGE("%s: succ! Timeout=%u.", __func__, info.funcInfo.enTimeout);
|
||||
|
||||
info.funcInfo.enTimeout = TEST_TIME_OUT;
|
||||
ret = SdioSetCommonInfo(tester->handle, &info, SDIO_FUNC_INFO);
|
||||
@@ -278,7 +278,7 @@ static int32_t TestSdioSetAndGetFuncInfo(struct SdioTester *tester)
|
||||
HDF_LOGE("%s: SdioGetCommonInfo fail! ret=%d.", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
HDF_LOGE("%s: again succ! Timeout=%d.", __func__, info.funcInfo.enTimeout);
|
||||
HDF_LOGE("%s: again succ! Timeout=%u.", __func__, info.funcInfo.enTimeout);
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
@@ -355,7 +355,7 @@ struct SdioTestFunc g_sdioTestFunc[] = {
|
||||
static int32_t SdioTestEntry(struct SdioTester *tester, int32_t cmd)
|
||||
{
|
||||
int32_t i;
|
||||
int32_t ret;
|
||||
int32_t ret = HDF_SUCCESS;
|
||||
bool isFind = false;
|
||||
|
||||
if (tester == NULL) {
|
||||
@@ -374,7 +374,7 @@ static int32_t SdioTestEntry(struct SdioTester *tester, int32_t cmd)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isFind == false) {
|
||||
if (!isFind) {
|
||||
ret = HDF_ERR_NOT_SUPPORT;
|
||||
HDF_LOGE("%s: cmd %d not support", __func__, cmd);
|
||||
}
|
||||
@@ -415,8 +415,8 @@ static int32_t SdioTestFillConfig(struct SdioTester *tester, const struct Device
|
||||
return ret;
|
||||
}
|
||||
|
||||
HDF_LOGE("%s: busNum:%d, funcNum:%d, vendorId:0x%x, deviceId:0x%x.", __func__,
|
||||
tester->busNum, tester->funcNum, tester->vendorId, tester->deviceId);
|
||||
HDF_LOGE("%s: busNum:%u, funcNum:%u, vendorId:0x%x.", __func__,
|
||||
tester->busNum, tester->funcNum, tester->vendorId);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ static int32_t UartGetBaudTest(struct UartTest *test)
|
||||
HDF_LOGE("%s: error", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HDF_LOGE("%s: baud %d", __func__, baud);
|
||||
HDF_LOGE("%s: baud %u", __func__, baud);
|
||||
HDF_LOGE("%s: success", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
@@ -94,13 +94,13 @@ static int32_t UartGetAttributeTest(struct UartTest *test)
|
||||
HDF_LOGE("%s: error", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HDF_LOGE("dataBits %d", attribute.dataBits);
|
||||
HDF_LOGE("parity %d", attribute.parity);
|
||||
HDF_LOGE("stopBits %d", attribute.stopBits);
|
||||
HDF_LOGE("rts %d", attribute.rts);
|
||||
HDF_LOGE("cts %d", attribute.cts);
|
||||
HDF_LOGE("fifoRxEn %d", attribute.fifoRxEn);
|
||||
HDF_LOGE("fifoTxEn %d", attribute.fifoTxEn);
|
||||
HDF_LOGE("dataBits %u", attribute.dataBits);
|
||||
HDF_LOGE("parity %u", attribute.parity);
|
||||
HDF_LOGE("stopBits %u", attribute.stopBits);
|
||||
HDF_LOGE("rts %u", attribute.rts);
|
||||
HDF_LOGE("cts %u", attribute.cts);
|
||||
HDF_LOGE("fifoRxEn %u", attribute.fifoRxEn);
|
||||
HDF_LOGE("fifoTxEn %u", attribute.fifoTxEn);
|
||||
HDF_LOGE("%s: success", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ static int32_t TestCaseWatchdogReliability(struct WatchdogTester *tester)
|
||||
(void)WatchdogSetTimeout(NULL, WATCHDOG_TEST_TIMEOUT);
|
||||
/* invalid device handle */
|
||||
(void)WatchdogGetTimeout(NULL, &timeout);
|
||||
/* invalid timout pointer */
|
||||
/* invalid timeout pointer */
|
||||
(void)WatchdogGetTimeout(tester->handle, NULL);
|
||||
|
||||
HDF_LOGE("%s: test dfr for WatchdogFeed ...", __func__);
|
||||
|
||||
@@ -23,7 +23,7 @@ int32_t HdfMipiDsiEntry(HdfTestMsg *msg)
|
||||
|
||||
test = MipiDsiTestServiceGet();
|
||||
if (test == NULL) {
|
||||
HDF_LOGE("%s: get servie fail!\n", __func__);
|
||||
HDF_LOGE("%s: get service fail!", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ static int8_t g_rtcIrqCallback = HDF_FAILURE;
|
||||
int32_t RtcAlarmACallback(enum RtcAlarmIndex alarmIndex)
|
||||
{
|
||||
if (alarmIndex == RTC_ALARM_INDEX_A) {
|
||||
HDF_LOGE("RtcAlarmACallback alarm a success");
|
||||
HDF_LOGE("RtcAlarmACallback: alarm a callback success");
|
||||
g_rtcIrqCallback = HDF_SUCCESS;
|
||||
} else {
|
||||
g_rtcIrqCallback = HDF_FAILURE;
|
||||
@@ -87,14 +87,14 @@ static int32_t RtcReadWriteTimeTest(struct RtcTime *writeTime)
|
||||
}
|
||||
ret = RtcWriteTime(g_rtcHandle, writeTime);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("RtcReadWriteTimeTest write fail");
|
||||
HDF_LOGE("RtcReadWriteTimeTest write failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
OsalMSleep(RTC_TEST_WR_WAIT_MS);
|
||||
ret = RtcReadTime(g_rtcHandle, &readTime);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("RtcReadWriteTimeTest read fail");
|
||||
HDF_LOGE("RtcReadWriteTimeTest read failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -116,14 +116,14 @@ static int32_t RtcReadWriteAlarmTimeTest(struct RtcTime *writeTime)
|
||||
|
||||
ret = RtcWriteAlarm(g_rtcHandle, RTC_ALARM_INDEX_A, writeTime);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("RtcReadWriteAlarmTimeTest write fail");
|
||||
HDF_LOGE("RtcReadWriteAlarmTimeTest write failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
OsalMSleep(RTC_TEST_WR_WAIT_MS);
|
||||
ret = RtcReadAlarm(g_rtcHandle, RTC_ALARM_INDEX_A, &readTime);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("RtcReadWriteAlarmTimeTest read fail");
|
||||
HDF_LOGE("RtcReadWriteAlarmTimeTest read failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ static int32_t RtcReadWriteTime(void)
|
||||
|
||||
ret = RtcReadWriteTimeTest(&tm);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("RtcReadWriteTime fail");
|
||||
HDF_LOGE("RtcReadWriteTime failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ static int32_t RtcReadWriteMaxTime(void)
|
||||
tm.weekday = weekday;
|
||||
ret = RtcReadWriteTimeTest(&tm);
|
||||
if (ret == 0) {
|
||||
HDF_LOGE("RtcReadWriteMaxTime fail");
|
||||
HDF_LOGE("RtcReadWriteMaxTime failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ static int32_t RtcReadWriteMinTime(void)
|
||||
tm.weekday = weekday;
|
||||
ret = RtcReadWriteTimeTest(&tm);
|
||||
if (ret == 0) {
|
||||
HDF_LOGE("RtcReadWriteMinTime fail");
|
||||
HDF_LOGE("RtcReadWriteMinTime failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ static int32_t RtcReadWriteAlarmTime(void)
|
||||
tm.weekday = weekday;
|
||||
ret = RtcReadWriteAlarmTimeTest(&tm);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("RtcReadWriteAlarmTime read fail");
|
||||
HDF_LOGE("RtcReadWriteAlarmTime read failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ static int32_t RtcReadWriteMaxAlarmTime(void)
|
||||
tm.weekday = weekday;
|
||||
ret = RtcReadWriteAlarmTimeTest(&tm);
|
||||
if (ret == 0) {
|
||||
HDF_LOGE("RtcReadWriteMaxAlarmTime read fail");
|
||||
HDF_LOGE("RtcReadWriteMaxAlarmTime read failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -273,7 +273,7 @@ static int32_t RtcReadWriteMinAlarmTime(void)
|
||||
time.weekday = weekday;
|
||||
ret = RtcReadWriteAlarmTimeTest(&time);
|
||||
if (ret == 0) {
|
||||
HDF_LOGE("RtcReadWriteMinAlarmTime read fail");
|
||||
HDF_LOGE("RtcReadWriteMinAlarmTime read failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -299,12 +299,12 @@ static int32_t RtcAlarmEnable(void)
|
||||
tm.weekday = weekday;
|
||||
ret = RtcReadWriteAlarmTimeTest(&tm);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("RtcReadWriteAlarmTime read fail");
|
||||
HDF_LOGE("RtcReadWriteAlarmTime read failed");
|
||||
return -1;
|
||||
}
|
||||
ret = RtcAlarmInterruptEnable(g_rtcHandle, RTC_ALARM_INDEX_A, 1);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("RtcAlarmInterruptEnable fail");
|
||||
HDF_LOGE("RtcAlarmInterruptEnable failed");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
@@ -323,17 +323,17 @@ static int32_t RtcAlarmIrqAttachConfig(void)
|
||||
|
||||
ret = RtcRegisterAlarmCallback(g_rtcHandle, RTC_ALARM_INDEX_A, RtcAlarmACallback);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("RtcRegisterAlarmCallback fail");
|
||||
HDF_LOGE("RtcRegisterAlarmCallback failed");
|
||||
return -1;
|
||||
}
|
||||
ret = RtcSetFreq(g_rtcHandle, freq);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("RtcSetFreq fail");
|
||||
HDF_LOGE("RtcSetFreq failed");
|
||||
return -1;
|
||||
}
|
||||
ret = RtcAlarmInterruptEnable(g_rtcHandle, RTC_ALARM_INDEX_A, 1);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("RtcAlarmInterruptEnable fail");
|
||||
HDF_LOGE("RtcAlarmInterruptEnable failed");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
@@ -361,24 +361,24 @@ static int32_t RtcAlarmIrq(void)
|
||||
time.weekday = weekday;
|
||||
ret = RtcAlarmIrqAttachConfig();
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("RtcWriteTime fail");
|
||||
HDF_LOGE("RtcWriteTime failed");
|
||||
return -1;
|
||||
}
|
||||
ret = RtcWriteTime(g_rtcHandle, &time);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("RtcWriteTime fail");
|
||||
HDF_LOGE("RtcWriteTime failed");
|
||||
return -1;
|
||||
}
|
||||
/* set alarm time 2020-08-08 Saturday 08:08:09 .000 */
|
||||
time.second = RTC_TEST_TIME_SECOND + 1;
|
||||
ret = RtcWriteAlarm(g_rtcHandle, RTC_ALARM_INDEX_A, &time);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("RtcWriteAlarm fail");
|
||||
HDF_LOGE("RtcWriteAlarm failed");
|
||||
return -1;
|
||||
}
|
||||
OsalSleep(RTC_TEST_WAIT_TIME_S);
|
||||
if (g_rtcIrqCallback == HDF_FAILURE) {
|
||||
HDF_LOGE("RtcWriteAlarm fail");
|
||||
HDF_LOGE("RtcWriteAlarm failed");
|
||||
return -1;
|
||||
}
|
||||
g_rtcIrqCallback = HDF_FAILURE;
|
||||
@@ -394,7 +394,7 @@ static int32_t RtcRegisterCallback(void)
|
||||
}
|
||||
ret = RtcRegisterAlarmCallback(g_rtcHandle, RTC_ALARM_INDEX_A, RtcAlarmACallback);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("RtcRegisterCallback fail");
|
||||
HDF_LOGE("RtcRegisterCallback failed");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
@@ -410,7 +410,7 @@ static int32_t RtcRegisterNullCallback(void)
|
||||
|
||||
ret = RtcRegisterAlarmCallback(g_rtcHandle, RTC_ALARM_INDEX_A, NULL);
|
||||
if (ret == 0) {
|
||||
HDF_LOGE("RtcRegisterCallback fail");
|
||||
HDF_LOGE("RtcRegisterCallback failed");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
@@ -426,7 +426,7 @@ static int32_t RtcSetNormalFreq(void)
|
||||
|
||||
ret = RtcSetFreq(g_rtcHandle, RTC_TEST_FREQ);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("RtcSetNormalFreq fail");
|
||||
HDF_LOGE("RtcSetNormalFreq failed");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
@@ -442,7 +442,7 @@ static int32_t RtcSetMaxFreq(void)
|
||||
|
||||
ret = RtcSetFreq(g_rtcHandle, RTC_TEST_FREQ * RTC_TIME_UNIT);
|
||||
if (ret == 0) {
|
||||
HDF_LOGE("RtcSetMaxFreq fail");
|
||||
HDF_LOGE("RtcSetMaxFreq failed");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
@@ -458,7 +458,7 @@ static int32_t RtcSetMinFreq(void)
|
||||
|
||||
ret = RtcSetFreq(g_rtcHandle, 0);
|
||||
if (ret == 0) {
|
||||
HDF_LOGE("RtcSetMinFreq fail");
|
||||
HDF_LOGE("RtcSetMinFreq failed");
|
||||
return -1;
|
||||
}
|
||||
ret = RtcSetFreq(g_rtcHandle, RTC_TEST_FREQ);
|
||||
@@ -476,12 +476,12 @@ static int32_t RtcReadWriteUserReg(void)
|
||||
|
||||
ret = RtcWriteReg(g_rtcHandle, 0, value);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("RtcReadWriteUserReg write fail");
|
||||
HDF_LOGE("RtcReadWriteUserReg write failed");
|
||||
return -1;
|
||||
}
|
||||
ret = RtcReadReg(g_rtcHandle, 0, &value);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("RtcSetMinFreq read fail");
|
||||
HDF_LOGE("RtcSetMinFreq read failed");
|
||||
return -1;
|
||||
}
|
||||
if (value != RTC_TEST_USER_VALUE) {
|
||||
@@ -501,12 +501,12 @@ static int32_t RtcReadWriteMaxUserIndex(void)
|
||||
|
||||
ret = RtcWriteReg(g_rtcHandle, RTC_TEST_USER_MAX_INDEX, value);
|
||||
if (ret == 0) {
|
||||
HDF_LOGE("RtcReadWriteUserReg write fail");
|
||||
HDF_LOGE("RtcReadWriteUserReg write failed");
|
||||
return -1;
|
||||
}
|
||||
ret = RtcReadReg(g_rtcHandle, RTC_TEST_USER_MAX_INDEX, &value);
|
||||
if (ret == 0) {
|
||||
HDF_LOGE("RtcSetMinFreq read fail");
|
||||
HDF_LOGE("RtcSetMinFreq read failed");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -34,4 +34,4 @@ typedef enum {
|
||||
} HdfRtcTestCaseCmd;
|
||||
|
||||
int32_t HdfRtcEntry(HdfTestMsg *msg);
|
||||
#endif // HDF_RTC_ENTRY_TEST_H
|
||||
#endif /* HDF_RTC_ENTRY_TEST_H */
|
||||
|
||||
@@ -177,7 +177,7 @@ int32_t InitSensorDriverTest(struct HdfDeviceObject *device)
|
||||
struct SensorDeviceInfo deviceInfo = {
|
||||
.sensorInfo = {
|
||||
.sensorName = "sensor_test",
|
||||
.vendorName = "huawei",
|
||||
.vendorName = "default",
|
||||
.firmwareVersion = "1.0",
|
||||
.hardwareVersion = "1.0",
|
||||
.sensorTypeId = SENSOR_TAG_NONE,
|
||||
|
||||
@@ -54,10 +54,15 @@ int32_t HdfWifiEntry(HdfTestMsg *msg)
|
||||
{
|
||||
int32_t result, i;
|
||||
|
||||
if (msg == NULL) {
|
||||
HDF_LOGE("%s is fail: HdfTestMsg is NULL!", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(g_hdfWiFiTestCaseList) / sizeof(g_hdfWiFiTestCaseList[0]); ++i) {
|
||||
if ((msg->subCmd == g_hdfWiFiTestCaseList[i].subCmd) && (g_hdfWiFiTestCaseList[i].testFunc != NULL)) {
|
||||
result = g_hdfWiFiTestCaseList[i].testFunc();
|
||||
HDF_LOGE("HdfTest:Wifi test result[%s-%d]", ((result == 0) ? "pass" : "fail"), msg->subCmd);
|
||||
HDF_LOGE("HdfTest:Wifi test result[%s-%u]", ((result == 0) ? "pass" : "fail"), msg->subCmd);
|
||||
msg->result = (result == 0) ? HDF_SUCCESS : HDF_FAILURE;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,6 @@ typedef enum {
|
||||
WIFI_MODULE_ADD_FEATURE,
|
||||
WIFI_MODULE_DELETE_FEATURE,
|
||||
WIFI_MODULE_END = 200,
|
||||
|
||||
/* message */
|
||||
WIFI_MESSAGE_QUEUE_001 = WIFI_MODULE_END,
|
||||
WIFI_MESSAGE_QUEUE_002,
|
||||
|
||||
@@ -16,7 +16,7 @@ BOUNDS_CHECK_LIB := $(abspath ../../../../third_party/bounds_checking_function/)
|
||||
INCLUDE_DIR := ./include $(BOUNDS_CHECK_LIB)/include
|
||||
OUT_DIR := build
|
||||
|
||||
TEST_CASE := $(abspath ../../../adapter/khdf/liteos/test/tools/hc-gen/test/unittest)
|
||||
TEST_CASE := $(abspath ../../../adapter/lite/khdf/test/tools/hc-gen/test/unittest)
|
||||
|
||||
ORIGIN_SOURCES := $(wildcard src/*)
|
||||
ORIGIN_SOURCES += $(wildcard $(BOUNDS_CHECK_LIB)/src/*)
|
||||
|
||||
@@ -1 +1 @@
|
||||
hc-gen compilation requires flex and bison, make sure that they are installed before compiling.
|
||||
hc-gen compilation requires flex and bison, so make sure they are installed before you get start.
|
||||
Binary file not shown.
@@ -18,7 +18,7 @@
|
||||
|
||||
#define HBC_MAGIC_NUM 0xA00AA00A
|
||||
#define HCS_COMPILER_VERSION_MAJOR 00
|
||||
#define HCS_COMPILER_VERSION_MINOR 65
|
||||
#define HCS_COMPILER_VERSION_MINOR 66
|
||||
|
||||
typedef struct HbcHeader {
|
||||
uint32_t magicNumber;
|
||||
@@ -31,8 +31,8 @@ typedef struct HbcHeader {
|
||||
/* Parse compiler options */
|
||||
int32_t DoOption(int32_t argc, char *argv[]);
|
||||
|
||||
int32_t HcsDoCompile();
|
||||
int32_t HcsDoCompile(void);
|
||||
|
||||
int32_t HcsDoOptimize();
|
||||
int32_t HcsDoOptimize(void);
|
||||
|
||||
#endif // HCS_COMPILER_H
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
|
||||
#include "hcs_compiler.h"
|
||||
|
||||
int32_t HcsDoDecompile();
|
||||
int32_t HcsDoDecompile(void);
|
||||
|
||||
int32_t HcsDecompileOutput();
|
||||
int32_t HcsDecompileOutput(void);
|
||||
|
||||
#endif // HCS_DECOMPILE_H
|
||||
|
||||
@@ -34,7 +34,7 @@ struct HcsSourceName {
|
||||
struct HcsSourceName *next;
|
||||
};
|
||||
|
||||
const char *HcsGetInputFileName();
|
||||
const char *HcsGetInputFileName(void);
|
||||
|
||||
void HcsSetInputFileName(const char *name);
|
||||
|
||||
@@ -46,9 +46,11 @@ int32_t HcsSetOutPutName(const char *name);
|
||||
|
||||
int32_t HcsSetOutPutNameWithCurrentWorkPath(const char *name);
|
||||
|
||||
const char *HcsGetOutPutFileName();
|
||||
const char *HcsGetOutPutFilePath(void);
|
||||
|
||||
const char *HcsGetStripedOutputFileName();
|
||||
char *HcsGetOutputFileNameWithoutSuffix(void);
|
||||
|
||||
const char *HcsGetOutputFileName(void);
|
||||
|
||||
struct HcsFile *HcsOpenOutputFile(const char *suffix);
|
||||
|
||||
@@ -56,6 +58,8 @@ void HcsCloseOutput(struct HcsFile *output);
|
||||
|
||||
int32_t HcsOutputWrite(const void *buffer, uint32_t length);
|
||||
|
||||
int32_t HcsFormatOutputWrite(const char *format, ...);
|
||||
|
||||
int32_t HcsOutputWriteAlign(const void *buffer, uint32_t length);
|
||||
|
||||
void HcsMockOutPut(bool dummyOutput);
|
||||
@@ -66,13 +70,13 @@ void HcsResetOutputCurrentCount(void);
|
||||
|
||||
void HcsSourceQueuePush(struct HcsFile *sourceFile);
|
||||
|
||||
void HcsSourceQueuePop();
|
||||
void HcsSourceQueuePop(void);
|
||||
|
||||
struct HcsFile *HcsSourceQueueTop();
|
||||
struct HcsFile *HcsSourceQueueTop(void);
|
||||
|
||||
uint32_t HcsSourceQueueSize();
|
||||
uint32_t HcsSourceQueueSize(void);
|
||||
|
||||
const char *HcsGetCurrentSourceName();
|
||||
const char *HcsGetCurrentSourceName(void);
|
||||
|
||||
int32_t HcsSourceNameSetPush(const char *name);
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
int32_t HcsBytecodeOutput();
|
||||
int32_t HcsTextCodeOutput();
|
||||
int32_t HcsBytecodeOutput(void);
|
||||
int32_t HcsTextCodeOutput(void);
|
||||
int32_t HcsBinaryToHexdump(const char *inputFileName);
|
||||
|
||||
#endif // HCS_COMPILER_GENER_H
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
#define HCS_OBJECT_PR(prefix, object, fmt, args...) \
|
||||
do { \
|
||||
HCS_LOG_PRINT (prefix": %s:%u\n\t" fmt"\n", \
|
||||
HCS_LOG_PRINT(prefix": %s:%u\n\t" fmt"\n", \
|
||||
object ? ((ParserObjectBase*)object)->src : "unknown", \
|
||||
object ? ((ParserObjectBase*)object)->lineno : 0, \
|
||||
##args); \
|
||||
@@ -52,12 +52,20 @@
|
||||
#define PRINTF_CHECK_AND_RETURN(printRes) \
|
||||
do { \
|
||||
if ((printRes) < 0) { \
|
||||
HCS_ERROR("Error:%s(%d), sprintf_s fail", \
|
||||
HCS_ERROR("Error:%s(%d), sprintf_s failed", \
|
||||
__FUNCTION__, __LINE__); \
|
||||
return EOUTPUT; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define OUTPUT_CHECK_AND_RETURN(printRes) \
|
||||
do { \
|
||||
if ((printRes) < 0) { \
|
||||
HCS_ERROR("Error:%s(%d), output write failed", \
|
||||
__FUNCTION__, __LINE__); \
|
||||
return EOUTPUT; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define SPRINTF_ERROR_INFO "sprintf fail"
|
||||
|
||||
#endif // HCS_COMPILER_LOG_H
|
||||
|
||||
@@ -27,7 +27,7 @@ typedef struct {
|
||||
const char *opStr;
|
||||
} OpCodeMapEntry;
|
||||
|
||||
const OpCodeMapEntry *HcsGetOpCodeMap();
|
||||
const OpCodeMapEntry *HcsGetOpCodeMap(void);
|
||||
|
||||
const OpCodeMapEntry *HcsParserObjectTypeToByteCode(uint32_t objectType);
|
||||
|
||||
|
||||
@@ -10,20 +10,20 @@
|
||||
#define HCS_COMPILER_OPTION_H
|
||||
#include <stdbool.h>
|
||||
|
||||
bool HcsOptShouldAlign();
|
||||
bool HcsOptShouldAlign(void);
|
||||
|
||||
void HcsOptSetAlign(bool align);
|
||||
|
||||
bool HcsOptShouldGenTextConfig();
|
||||
bool HcsOptShouldGenTextConfig(void);
|
||||
|
||||
bool HcsOptShouldGenByteCodeConfig();
|
||||
bool HcsOptShouldGenByteCodeConfig(void);
|
||||
|
||||
bool HcsOptDecompile();
|
||||
bool HcsOptDecompile(void);
|
||||
|
||||
bool HcsOptShouldGenHexdump();
|
||||
bool HcsOptShouldGenHexdump(void);
|
||||
|
||||
const char *HcsOptGetSymbolNamePrefix();
|
||||
const char *HcsOptGetSymbolNamePrefix(void);
|
||||
|
||||
bool HcsVerbosePrint();
|
||||
bool HcsVerbosePrint(void);
|
||||
|
||||
#endif // HCS_COMPILER_OPTION_H
|
||||
|
||||
+12
-13
@@ -6,13 +6,13 @@
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "hcs_ast.h"
|
||||
#include <string.h>
|
||||
#include <securec.h>
|
||||
#include "hcs_file.h"
|
||||
#include "hcs_mem.h"
|
||||
#include "hcs_log.h"
|
||||
#include "hcs_option.h"
|
||||
#include "hcs_ast.h"
|
||||
|
||||
#define ANONYMOUS_OBJECT_NAME "|_"
|
||||
static ParserObject *g_parserRoot = NULL;
|
||||
@@ -24,14 +24,14 @@ bool HcsIsAnonymousObject(const ParserObject *obj)
|
||||
|
||||
ParserObject *HcsAllocParserObject(void)
|
||||
{
|
||||
ParserObject *new = (ParserObject *)HcsMemZalloc(sizeof(ParserObject));
|
||||
if (new == NULL) {
|
||||
HCS_ERROR("%s %d %s OOM", __FILE__, __LINE__, __func__);
|
||||
ParserObject *newObject = (ParserObject *)HcsMemZalloc(sizeof(ParserObject));
|
||||
if (newObject == NULL) {
|
||||
HCS_ERROR("%s:%d OOM", __func__, __LINE__);
|
||||
return NULL;
|
||||
}
|
||||
new->objectBase.src = HcsGetCurrentSourceName();
|
||||
new->objectBase.lineno = HcsGetCurrentSourceLine();
|
||||
return new;
|
||||
newObject->objectBase.src = HcsGetCurrentSourceName();
|
||||
newObject->objectBase.lineno = HcsGetCurrentSourceLine();
|
||||
return newObject;
|
||||
}
|
||||
|
||||
void HcsAstFreeObject(ParserObject *object)
|
||||
@@ -77,7 +77,7 @@ void HcsDeleteParserObjectTree(ParserObject *object)
|
||||
if (object == NULL) {
|
||||
return;
|
||||
}
|
||||
/* delete current and subtree */
|
||||
/* delete current tree and subtree */
|
||||
HcsAstFreeObjectAndSubtree(object);
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ ParserObject *HcsGetParserRoot(void)
|
||||
HCS_DEBUG("instance root node");
|
||||
char *rootNodeName = strdup("root");
|
||||
if (rootNodeName == NULL) {
|
||||
HCS_ERROR("%s %d %s OOM", __FILE__, __LINE__, __func__);
|
||||
HCS_ERROR("%s:%d OOM", __func__, __LINE__);
|
||||
return NULL;
|
||||
}
|
||||
g_parserRoot = HcsNewConfigNode(rootNodeName, CONFIG_NODE_NOREF, NULL);
|
||||
@@ -311,7 +311,7 @@ static ParserObject *HcsParserObjectClone(const ParserObject *object)
|
||||
}
|
||||
ParserObject *clone = HcsAllocParserObject();
|
||||
if (clone == NULL) {
|
||||
HCS_ERROR("%s %d %s OOM", __FILE__, __LINE__, __func__);
|
||||
HCS_ERROR("%s:%d OOM", __func__, __LINE__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -384,7 +384,7 @@ int32_t HcsAstCopyArray(const ParserObject *src, ParserObject *dst)
|
||||
while (arrayElement != NULL) {
|
||||
ParserObject *copy = HcsParserObjectClone(arrayElement);
|
||||
if (copy == NULL) {
|
||||
HCS_ERROR("%s %d %s OOM", __FILE__, __LINE__, __func__);
|
||||
HCS_ERROR("%s:%d OOM", __func__, __LINE__);
|
||||
return EOOM;
|
||||
}
|
||||
HcsAstAddChild(dst, copy);
|
||||
@@ -407,7 +407,7 @@ static int32_t HcsCopyObject(const ParserObject *src, ParserObject *dst)
|
||||
HcsMemFree(dst->objectBase.stringValue);
|
||||
dst->objectBase.stringValue = strdup(src->objectBase.stringValue);
|
||||
if (dst->objectBase.stringValue == NULL) {
|
||||
HCS_ERROR("%s %d %s OOM", __FILE__, __LINE__, __func__);
|
||||
HCS_ERROR("%s:%d OOM", __func__, __LINE__);
|
||||
return EOOM;
|
||||
}
|
||||
} else if (src->objectBase.type == PARSEROP_ARRAY) {
|
||||
@@ -442,7 +442,6 @@ static int32_t HcsAstCopyTree(ParserObject *src, ParserObject *dstTree, uint32_t
|
||||
}
|
||||
} else if (HcsOptShouldGenTextConfig() && HcsIsNumberObject(src) &&
|
||||
dstExistObject->objectBase.type > src->objectBase.type) {
|
||||
/* At template case, should do type upward transformation to template */
|
||||
src->objectBase.type = dstExistObject->objectBase.type;
|
||||
}
|
||||
|
||||
|
||||
@@ -83,9 +83,9 @@ static int32_t ByteCodeWriteWalk(ParserObject *current, int32_t walkDepth)
|
||||
}
|
||||
int32_t ret = NOERR;
|
||||
switch (current->objectBase.opCode) {
|
||||
case HCS_BYTE_OP:
|
||||
case HCS_WORD_OP:
|
||||
case HCS_DWORD_OP:
|
||||
case HCS_BYTE_OP: /* fall-through */
|
||||
case HCS_WORD_OP: /* fall-through */
|
||||
case HCS_DWORD_OP: /* fall-through */
|
||||
case HCS_QWORD_OP: {
|
||||
const OpCodeMapEntry *byteCodeMap = HcsGetOpCodeMap();
|
||||
ret = HcsOutputWriteAlign(¤t->objectBase.integerValue, byteCodeMap[current->objectBase.type].size);
|
||||
@@ -103,7 +103,6 @@ static int32_t ByteCodeWriteWalk(ParserObject *current, int32_t walkDepth)
|
||||
}
|
||||
ret = HcsOutputWriteAlign(¤t->objectBase.subSize, sizeof(current->objectBase.subSize));
|
||||
break;
|
||||
/* fall-through */
|
||||
case HCS_ARRAY_OP: {
|
||||
uint16_t size = HcsCountArraySize(current);
|
||||
ret = HcsOutputWriteAlign(&size, sizeof(size));
|
||||
@@ -122,20 +121,20 @@ static int32_t ByteCodeWriteWalk(ParserObject *current, int32_t walkDepth)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t HcsBytecodeOutput()
|
||||
int32_t HcsBytecodeOutput(void)
|
||||
{
|
||||
ParserObject *astRoot = HcsGetParserRoot();
|
||||
if (astRoot == NULL) {
|
||||
return EFAIL;
|
||||
}
|
||||
|
||||
/* generate OpCode for every object on AST and calculate size for each */
|
||||
/* generate OpCode for every object on AST and calculate size for each object */
|
||||
int32_t ret = HcsWalkAst(astRoot, AST_WALK_BACKEND, NULL, ByteCodeConvert);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* ast data is ready, do binder output */
|
||||
/* ast data is ready, do bindary output */
|
||||
struct HcsFile *outputFIle = HcsOpenOutputFile(HCS_OUTPUT_FILE_SUFFIX);
|
||||
|
||||
HbcHeader header = {
|
||||
@@ -181,7 +180,7 @@ int32_t HcsBytecodeOutput()
|
||||
HcsCloseOutput(outputFIle);
|
||||
HCS_DEBUG("Total size: %u ", astRoot->objectBase.size);
|
||||
if (ret == NOERR && HcsOptShouldGenHexdump()) {
|
||||
ret = HcsBinaryToHexdump(HcsGetOutPutFileName());
|
||||
ret = HcsBinaryToHexdump(HcsGetOutPutFilePath());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ static char *HcsAssembleNodeRefName(char *buff, uint32_t buffSize, const char *n
|
||||
}
|
||||
char *str = strdup(buff);
|
||||
if (str == NULL) {
|
||||
HCS_ERROR("%s %d %s OOM", __FILE__, __LINE__, __func__);
|
||||
HCS_ERROR("%s:%d OOM", __func__, __LINE__);
|
||||
return NULL;
|
||||
}
|
||||
return str;
|
||||
@@ -83,65 +83,59 @@ static char *HcsGetNodeRefPath(uint64_t hash)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int32_t HcsDecompilePrintBaseType(char *buffer, uint32_t bufferSize, const ParserObject *object);
|
||||
static int32_t HcsDecompilePrintBaseType(const ParserObject *object);
|
||||
|
||||
static int32_t HcsDecompilePrintArrayType(char *buffer, uint32_t bufferSize, const ParserObject *object)
|
||||
static int32_t HcsDecompilePrintArrayType(const ParserObject *object)
|
||||
{
|
||||
int32_t res = sprintf_s(buffer, bufferSize, "[");
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
int32_t res;
|
||||
PRINTF_CHECK_AND_RETURN(HcsFormatOutputWrite("["));
|
||||
ParserObject *arrayElement = (ParserObject *)object->objectBase.child;
|
||||
while (arrayElement->objectBase.next) {
|
||||
res = HcsDecompilePrintBaseType(buffer + strlen(buffer), bufferSize - strlen(buffer), arrayElement);
|
||||
res = HcsDecompilePrintBaseType(arrayElement);
|
||||
if (res) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
res = sprintf_s(buffer + strlen(buffer), bufferSize - strlen(buffer), ", ");
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
PRINTF_CHECK_AND_RETURN(HcsFormatOutputWrite(", "));
|
||||
arrayElement = (ParserObject *)arrayElement->objectBase.next;
|
||||
}
|
||||
res = HcsDecompilePrintBaseType(buffer + strlen(buffer), bufferSize - strlen(buffer), arrayElement);
|
||||
res = HcsDecompilePrintBaseType(arrayElement);
|
||||
if (res) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
res = sprintf_s(buffer + strlen(buffer), bufferSize - strlen(buffer), "]");
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
|
||||
return NOERR;
|
||||
return HcsFormatOutputWrite("]");
|
||||
}
|
||||
|
||||
static int32_t HcsDecompilePrintBaseType(char *buffer, uint32_t bufferSize, const ParserObject *object)
|
||||
static int32_t HcsDecompilePrintBaseType(const ParserObject *object)
|
||||
{
|
||||
int32_t res;
|
||||
int32_t res = NOERR;
|
||||
switch (object->objectBase.type) {
|
||||
case PARSEROP_UINT8:
|
||||
case PARSEROP_UINT16:
|
||||
case PARSEROP_UINT32:
|
||||
case PARSEROP_UINT64:
|
||||
res = sprintf_s(buffer, bufferSize, "0x%"PRIx64, object->objectBase.integerValue);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
res = HcsFormatOutputWrite("0x%"PRIx64, object->objectBase.integerValue);
|
||||
break;
|
||||
case PARSEROP_STRING:
|
||||
res = sprintf_s(buffer, bufferSize, "\"%s\"", object->objectBase.stringValue);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
res = HcsFormatOutputWrite("\"%s\"", object->objectBase.stringValue);
|
||||
break;
|
||||
case PARSEROP_NODEREF: {
|
||||
char *refPath = HcsGetNodeRefPath(object->objectBase.value);
|
||||
if (refPath == NULL) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
res = sprintf_s(buffer, bufferSize, "&%s", refPath);
|
||||
res = HcsFormatOutputWrite("&%s", refPath);
|
||||
HcsMemFree(refPath);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
}
|
||||
break;
|
||||
case PARSEROP_ARRAY:
|
||||
return HcsDecompilePrintArrayType(buffer, bufferSize, object);
|
||||
return HcsDecompilePrintArrayType(object);
|
||||
default:
|
||||
HCS_ERROR("unknown OpCode %u", object->objectBase.type);
|
||||
return EFAIL;
|
||||
}
|
||||
|
||||
return NOERR;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t HcsDecompileOutputWalk(ParserObject *current, int32_t walkDepth)
|
||||
@@ -151,41 +145,31 @@ static int32_t HcsDecompileOutputWalk(ParserObject *current, int32_t walkDepth)
|
||||
}
|
||||
|
||||
int32_t res;
|
||||
char writeBuffer[WRITE_BUFFER_LEN] = {'\0'};
|
||||
int32_t tabSize = walkDepth * HCS_TAB_SIZE;
|
||||
if (walkDepth) {
|
||||
res = sprintf_s(writeBuffer, WRITE_BUFFER_LEN, "%*c", tabSize, ' ');
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
PRINTF_CHECK_AND_RETURN(HcsFormatOutputWrite("%*c", tabSize, ' '));
|
||||
}
|
||||
|
||||
switch (current->objectBase.type) {
|
||||
case PARSEROP_CONFNODE:
|
||||
res = sprintf_s(writeBuffer + strlen(writeBuffer), WRITE_BUFFER_LEN - strlen(writeBuffer),
|
||||
"%s {\n", current->configNode.name);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
OUTPUT_CHECK_AND_RETURN(HcsFormatOutputWrite("%s {\n", current->configNode.name));
|
||||
if (current->objectBase.child == NULL) {
|
||||
res = sprintf_s(writeBuffer + strlen(writeBuffer) - 1,
|
||||
WRITE_BUFFER_LEN - strlen(writeBuffer) + 1, "}\n");
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
return HcsFormatOutputWrite("%*c}\n", tabSize, ' ');
|
||||
}
|
||||
break;
|
||||
case PARSEROP_CONFTERM:
|
||||
res = sprintf_s(writeBuffer + strlen(writeBuffer), WRITE_BUFFER_LEN - strlen(writeBuffer),
|
||||
"%s = ", current->configNode.name);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
res = HcsDecompilePrintBaseType(writeBuffer + strlen(writeBuffer), WRITE_BUFFER_LEN - strlen(writeBuffer),
|
||||
(ParserObject *)current->configNode.child);
|
||||
OUTPUT_CHECK_AND_RETURN(HcsFormatOutputWrite("%s = ", current->configNode.name));
|
||||
res = HcsDecompilePrintBaseType(
|
||||
(ParserObject *) current->configNode.child);
|
||||
if (res) {
|
||||
return res;
|
||||
}
|
||||
res = sprintf_s(writeBuffer + strlen(writeBuffer), WRITE_BUFFER_LEN - strlen(writeBuffer), ";\n");
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
break;
|
||||
return HcsFormatOutputWrite(";\n");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return HcsOutputWrite(writeBuffer, strlen(writeBuffer));
|
||||
return NOERR;
|
||||
}
|
||||
|
||||
static int32_t HcsDecompileCloseBraceGen(ParserObject *current, int32_t walkDepth)
|
||||
@@ -193,22 +177,13 @@ static int32_t HcsDecompileCloseBraceGen(ParserObject *current, int32_t walkDept
|
||||
if (current->objectBase.type != PARSEROP_CONFNODE) {
|
||||
return NOERR;
|
||||
}
|
||||
int32_t res;
|
||||
int32_t tabSize = walkDepth * HCS_TAB_SIZE;
|
||||
char writeBuffer[WRITE_BUFFER_LEN] = {'\0'};
|
||||
|
||||
if (current != HcsGetParserRoot()) {
|
||||
res = sprintf_s(writeBuffer, WRITE_BUFFER_LEN, "%*c}\n", tabSize, ' ');
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
} else {
|
||||
res = sprintf_s(writeBuffer, WRITE_BUFFER_LEN, "}\n");
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
}
|
||||
|
||||
return HcsOutputWrite(writeBuffer, strlen(writeBuffer));
|
||||
return current != HcsGetParserRoot() ? HcsFormatOutputWrite("%*c}\n", tabSize, ' ') :
|
||||
HcsFormatOutputWrite("}\n");
|
||||
}
|
||||
|
||||
int32_t HcsDecompileOutput()
|
||||
int32_t HcsDecompileOutput(void)
|
||||
{
|
||||
ParserObject *astRoot = HcsGetParserRoot();
|
||||
if (astRoot == NULL) {
|
||||
@@ -221,8 +196,7 @@ int32_t HcsDecompileOutput()
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
const char *fileHeader = HCS_DECOMPILE_FILE_HEADER;
|
||||
if (HcsOutputWrite(fileHeader, strlen(fileHeader))) {
|
||||
if (HcsFormatOutputWrite(HCS_DECOMPILE_FILE_HEADER) != EOK) {
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "hcs_decompiler.h"
|
||||
#include <string.h>
|
||||
#include "hcs_option.h"
|
||||
#include "hcs_file.h"
|
||||
#include "hcs_opcode.h"
|
||||
#include "hcs_parser.h"
|
||||
#include "hcs_log.h"
|
||||
#include "hcs_compiler.h"
|
||||
#include "hcs_decompiler.h"
|
||||
|
||||
static ParserObject *RebuildObject(uint8_t opCode);
|
||||
|
||||
@@ -42,7 +42,7 @@ static bool HcsVerifyHbcFile()
|
||||
}
|
||||
|
||||
HCS_INFO("Build by hcs compile %u.%u", header.versionMajor, header.versionMinor);
|
||||
HCS_INFO("hcb file total size: %u\n", header.totalSize);
|
||||
HCS_INFO("hcb file total size: %d\n", header.totalSize);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ static char *ReadCString()
|
||||
}
|
||||
char *str = strdup(buff);
|
||||
if (str == NULL) {
|
||||
HCS_ERROR("%s %d %s OOM", __FILE__, __LINE__, __func__);
|
||||
HCS_ERROR("%s:%d OOM", __func__, __LINE__);
|
||||
return NULL;
|
||||
}
|
||||
return str;
|
||||
@@ -348,7 +348,7 @@ static bool RebuildAst()
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t HcsDoDecompile()
|
||||
int32_t HcsDoDecompile(void)
|
||||
{
|
||||
struct HcsFile *source = NULL;
|
||||
uint32_t ret = HcsOpenSourceFile(HcsGetInputFileName(), &source, "rb");
|
||||
|
||||
+96
-59
@@ -6,6 +6,7 @@
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "hcs_file.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -15,11 +16,10 @@
|
||||
#include "hcs_parser.h"
|
||||
#include "hcs_mem.h"
|
||||
#include "hcs_log.h"
|
||||
#include "hcs_file.h"
|
||||
|
||||
static char *g_outputFilename = NULL;
|
||||
static FILE *g_outputFIle = NULL;
|
||||
const char *g_inputFileName = NULL;
|
||||
static char *g_outputFileName = NULL;
|
||||
static FILE *g_outputFile = NULL;
|
||||
static const char *g_inputFileName = NULL;
|
||||
static bool g_dummyOutput = false;
|
||||
static uint32_t g_outputWriteCount = 0;
|
||||
static struct HcsFileQueue g_inputSourceFileQueue = { 0 };
|
||||
@@ -30,20 +30,17 @@ void HcsSetInputFileName(const char *name)
|
||||
g_inputFileName = name;
|
||||
}
|
||||
|
||||
const char *HcsGetInputFileName()
|
||||
const char *HcsGetInputFileName(void)
|
||||
{
|
||||
return g_inputFileName;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return: true - not exist, false - already exist and not overwrite
|
||||
*/
|
||||
int32_t HcsSourceNameSetPush(const char *name)
|
||||
{
|
||||
if (g_sourceNameSetHead == NULL) {
|
||||
struct HcsSourceName *head = HcsMemZalloc(sizeof(*head));
|
||||
if (head == NULL) {
|
||||
HCS_ERROR("%s %d %s OOM", __FILE__, __LINE__, __func__);
|
||||
HCS_ERROR("%s:%d OOM", __func__, __LINE__);
|
||||
return EOOM;
|
||||
}
|
||||
head->name = name;
|
||||
@@ -61,13 +58,13 @@ int32_t HcsSourceNameSetPush(const char *name)
|
||||
last = last->next;
|
||||
}
|
||||
|
||||
struct HcsSourceName *new = HcsMemZalloc(sizeof(struct HcsSourceName));
|
||||
if (new == NULL) {
|
||||
HCS_ERROR("%s %d %s OOM", __FILE__, __LINE__, __func__);
|
||||
struct HcsSourceName *newName = HcsMemZalloc(sizeof(struct HcsSourceName));
|
||||
if (newName == NULL) {
|
||||
HCS_ERROR("%s:%d OOM", __func__, __LINE__);
|
||||
return EOOM;
|
||||
}
|
||||
new->name = name;
|
||||
pre->next = new;
|
||||
newName->name = name;
|
||||
pre->next = newName;
|
||||
return NOERR;
|
||||
}
|
||||
|
||||
@@ -101,6 +98,9 @@ void HcsSourceNameSetClean(void)
|
||||
|
||||
static const char *GetFileName(const char *path)
|
||||
{
|
||||
if (path == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
int32_t length = (int32_t)strlen(path);
|
||||
int32_t i = length - 1;
|
||||
for (; i >= 0; --i) {
|
||||
@@ -147,7 +147,7 @@ static int32_t CopyAndSaveFileName(const char *filePath, char **savedFileName, c
|
||||
}
|
||||
|
||||
/* if no specified output file name, use input name */
|
||||
if (HcsGetOutPutFileName() == NULL && HcsSetOutPutNameWithCurrentWorkPath(fileName)) {
|
||||
if (HcsGetOutPutFilePath() == NULL && HcsSetOutPutNameWithCurrentWorkPath(fileName)) {
|
||||
HcsMemFree((void *)fileName);
|
||||
return EOOM;
|
||||
}
|
||||
@@ -172,26 +172,25 @@ int32_t HcsOpenSourceFile(const char *path, struct HcsFile **file, const char *f
|
||||
char *realPath = realpath(path, pathBuf);
|
||||
#endif
|
||||
if (realPath == NULL) {
|
||||
HCS_ERROR("fail to open source file: %s", path);
|
||||
HCS_ERROR("failed to open source file: %s", path);
|
||||
return EINVALF;
|
||||
}
|
||||
|
||||
/* push to name set and check reopen */
|
||||
int32_t ret = HcsSourceNameSetFind(realPath);
|
||||
if (ret == true) {
|
||||
if (HcsSourceNameSetFind(realPath)) {
|
||||
return EREOPENF;
|
||||
}
|
||||
|
||||
HCS_DEBUG("source file path: %s", realPath);
|
||||
FILE *f = fopen(realPath, flag ? flag : "r");
|
||||
if (f == NULL) {
|
||||
HCS_ERROR("fail to open source file: %s", realPath);
|
||||
HCS_ERROR("failed to open source file: %s", realPath);
|
||||
return EINVALF;
|
||||
}
|
||||
|
||||
char *fileName = NULL;
|
||||
char *filePath = NULL;
|
||||
ret = CopyAndSaveFileName(realPath, &fileName, &filePath);
|
||||
int32_t ret = CopyAndSaveFileName(realPath, &fileName, &filePath);
|
||||
if (ret) {
|
||||
fclose(f);
|
||||
return EFAIL;
|
||||
@@ -200,6 +199,7 @@ int32_t HcsOpenSourceFile(const char *path, struct HcsFile **file, const char *f
|
||||
struct HcsFile *sourceFile = HcsMemZalloc(sizeof(struct HcsFile));
|
||||
if (sourceFile == NULL) {
|
||||
HcsMemFree(fileName);
|
||||
HcsMemFree(filePath);
|
||||
fclose(f);
|
||||
HCS_ERROR("oom");
|
||||
return EOOM;
|
||||
@@ -272,17 +272,17 @@ int32_t HcsSetOutPutNameWithCurrentWorkPath(const char *name)
|
||||
|
||||
int32_t HcsSetOutPutName(const char *name)
|
||||
{
|
||||
if (g_outputFilename != NULL) {
|
||||
HcsMemFree(g_outputFilename);
|
||||
if (g_outputFileName != NULL) {
|
||||
HcsMemFree(g_outputFileName);
|
||||
}
|
||||
|
||||
g_outputFilename = strdup(name);
|
||||
if (g_outputFilename == NULL) {
|
||||
g_outputFileName = strdup(name);
|
||||
if (g_outputFileName == NULL) {
|
||||
HCS_ERROR("oom");
|
||||
return EOOM;
|
||||
}
|
||||
#ifdef OS_WIN
|
||||
char *temp = g_outputFilename;
|
||||
char *temp = g_outputFileName;
|
||||
while (*temp != '\0') {
|
||||
if (*temp == UNIX_SEPARATOR) {
|
||||
*temp = WIN_SEPARATOR;
|
||||
@@ -296,13 +296,13 @@ int32_t HcsSetOutPutName(const char *name)
|
||||
|
||||
bool HcsSetOutputFileSuffix(const char *suffix)
|
||||
{
|
||||
const char *fileNameBefore = g_outputFilename;
|
||||
const char *fileNameBefore = g_outputFileName;
|
||||
const char *fileNameWithoutSuffix = GetFileNameWithoutSuffix(fileNameBefore);
|
||||
if (fileNameWithoutSuffix == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t newNameSize = strlen(g_outputFilename) + strlen(suffix) + 1;
|
||||
uint32_t newNameSize = strlen(g_outputFileName) + strlen(suffix) + 1;
|
||||
char *newOutputFilename = HcsMemZalloc(newNameSize);
|
||||
if (newOutputFilename == NULL) {
|
||||
HcsMemFree((void *)fileNameWithoutSuffix);
|
||||
@@ -312,37 +312,58 @@ bool HcsSetOutputFileSuffix(const char *suffix)
|
||||
int32_t ret = strcpy_s(newOutputFilename, newNameSize, fileNameWithoutSuffix);
|
||||
HcsMemFree((void *)fileNameWithoutSuffix);
|
||||
if (ret) {
|
||||
HCS_ERROR("string copy fail");
|
||||
HCS_ERROR("failed to copy string");
|
||||
HcsMemFree(newOutputFilename);
|
||||
return false;
|
||||
}
|
||||
ret = strcat_s(newOutputFilename, newNameSize, suffix);
|
||||
if (ret) {
|
||||
HCS_ERROR("string copy fail");
|
||||
HCS_ERROR("failed to copy string");
|
||||
HcsMemFree(newOutputFilename);
|
||||
return false;
|
||||
}
|
||||
|
||||
HcsMemFree((void *)fileNameBefore);
|
||||
g_outputFilename = newOutputFilename;
|
||||
g_outputFileName = newOutputFilename;
|
||||
return true;
|
||||
}
|
||||
|
||||
// return output file name only
|
||||
const char *HcsGetStripedOutputFileName()
|
||||
const char *HcsGetOutputFileName(void)
|
||||
{
|
||||
return GetFileName(g_outputFilename);
|
||||
return GetFileName(g_outputFileName);
|
||||
}
|
||||
|
||||
// return full path of output file
|
||||
const char *HcsGetOutPutFileName()
|
||||
char *HcsGetOutputFileNameWithoutSuffix(void)
|
||||
{
|
||||
return g_outputFilename;
|
||||
const char *fileName = HcsGetOutputFileName();
|
||||
if (fileName == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *retName = strdup(fileName);
|
||||
if (retName == NULL) {
|
||||
HCS_ERROR("oom");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *dot = strchr(retName, '.');
|
||||
if (dot != NULL) {
|
||||
*dot = '\0';
|
||||
}
|
||||
return retName;
|
||||
}
|
||||
|
||||
|
||||
// return full path of output file
|
||||
const char *HcsGetOutPutFilePath(void)
|
||||
{
|
||||
return g_outputFileName;
|
||||
}
|
||||
|
||||
bool HcsOutputNameVerify()
|
||||
{
|
||||
const char *fileName = g_outputFilename;
|
||||
const char *fileName = g_outputFileName;
|
||||
char lastChar = fileName[strlen(fileName) - 1];
|
||||
if (lastChar == OS_SEPARATOR) {
|
||||
HCS_ERROR("output name is DIR");
|
||||
@@ -360,10 +381,10 @@ struct HcsFile *HcsOpenOutputFile(const char *suffix)
|
||||
if (!HcsSetOutputFileSuffix(suffix)) {
|
||||
return NULL;
|
||||
}
|
||||
const char *outputFileName = HcsGetOutPutFileName();
|
||||
g_outputFIle = fopen(outputFileName, "wb");
|
||||
if (g_outputFIle == NULL) {
|
||||
HCS_ERROR("fail to open output file: %s", outputFileName);
|
||||
const char *outputFileName = HcsGetOutPutFilePath();
|
||||
g_outputFile = fopen(outputFileName, "wb");
|
||||
if (g_outputFile == NULL) {
|
||||
HCS_ERROR("failed to open output file: %s", outputFileName);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -371,12 +392,12 @@ struct HcsFile *HcsOpenOutputFile(const char *suffix)
|
||||
struct HcsFile *outputFile = HcsMemZalloc(sizeof(struct HcsFile));
|
||||
if (outputFile == NULL) {
|
||||
HCS_ERROR("oom");
|
||||
fclose(g_outputFIle);
|
||||
g_outputFIle = NULL;
|
||||
fclose(g_outputFile);
|
||||
g_outputFile = NULL;
|
||||
return NULL;
|
||||
}
|
||||
outputFile->name = outputFileName;
|
||||
outputFile->file = g_outputFIle;
|
||||
outputFile->file = g_outputFile;
|
||||
outputFile->pos = 0;
|
||||
outputFile->fullPath = outputFileName;
|
||||
g_outputWriteCount = 0;
|
||||
@@ -404,15 +425,38 @@ int32_t HcsOutputWrite(const void *buffer, uint32_t length)
|
||||
return NOERR;
|
||||
}
|
||||
|
||||
uint32_t writeLen = fwrite(buffer, 1, length, g_outputFIle);
|
||||
uint32_t writeLen = fwrite(buffer, 1, length, g_outputFile);
|
||||
if (writeLen != length) {
|
||||
HCS_ERROR("output file write fail");
|
||||
HCS_ERROR("failed to write output file");
|
||||
return EOUTPUT;
|
||||
}
|
||||
|
||||
return NOERR;
|
||||
}
|
||||
|
||||
#define WRITE_MAX_PER_TIME 2048
|
||||
|
||||
int32_t HcsFormatOutputWrite(const char *format, ...)
|
||||
{
|
||||
if (format == NULL) {
|
||||
return EINVALARG;
|
||||
}
|
||||
static char writeBuffer[WRITE_MAX_PER_TIME] = {'\0'};
|
||||
|
||||
va_list argList;
|
||||
|
||||
va_start(argList, format);
|
||||
int length = vsprintf_s(writeBuffer, WRITE_MAX_PER_TIME, format, argList);
|
||||
va_end(argList);
|
||||
(void)argList;
|
||||
|
||||
if (length < 0) {
|
||||
HCS_ERROR("Output too long in one time");
|
||||
return EOUTPUT;
|
||||
}
|
||||
return HcsOutputWrite(writeBuffer, length);
|
||||
}
|
||||
|
||||
int32_t HcsOutputWriteAlign(const void *buffer, uint32_t length)
|
||||
{
|
||||
static const uint8_t alignData[ALIGN_SIZE] = {0};
|
||||
@@ -460,7 +504,7 @@ void HcsSourceQueuePush(struct HcsFile *sourceFile)
|
||||
sourceQueue->count++;
|
||||
}
|
||||
|
||||
void HcsSourceQueuePop()
|
||||
void HcsSourceQueuePop(void)
|
||||
{
|
||||
struct HcsFileQueue *sourceQueue = &g_inputSourceFileQueue;
|
||||
if (sourceQueue->head == NULL) {
|
||||
@@ -470,17 +514,17 @@ void HcsSourceQueuePop()
|
||||
sourceQueue->count--;
|
||||
}
|
||||
|
||||
struct HcsFile *HcsSourceQueueTop()
|
||||
struct HcsFile *HcsSourceQueueTop(void)
|
||||
{
|
||||
return g_inputSourceFileQueue.head;
|
||||
}
|
||||
|
||||
uint32_t HcsSourceQueueSize()
|
||||
uint32_t HcsSourceQueueSize(void)
|
||||
{
|
||||
return g_inputSourceFileQueue.count;
|
||||
}
|
||||
|
||||
const char *HcsGetCurrentSourceName()
|
||||
const char *HcsGetCurrentSourceName(void)
|
||||
{
|
||||
struct HcsFile *source = HcsSourceQueueTop();
|
||||
return source ? source->fullPath : "";
|
||||
@@ -488,19 +532,12 @@ const char *HcsGetCurrentSourceName()
|
||||
|
||||
bool HcsFileCopyDir(char *dst, uint32_t dstBufferSize, const char *fullPath)
|
||||
{
|
||||
const char *c = strlen(fullPath) + fullPath;
|
||||
while (c >= fullPath) {
|
||||
if (*c == OS_SEPARATOR) {
|
||||
break;
|
||||
}
|
||||
c--;
|
||||
}
|
||||
int32_t len = (int32_t)(c - fullPath) + 1;
|
||||
if (len <= 0) {
|
||||
const char *c = strrchr(fullPath, OS_SEPARATOR);
|
||||
if (c == NULL) {
|
||||
HCS_ERROR("%s: path '%s' not include dir", __func__, fullPath);
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t len = (int32_t)(c - fullPath) + 1;
|
||||
int32_t ret = strncpy_s(dst, dstBufferSize, fullPath, len);
|
||||
if (ret) {
|
||||
HCS_ERROR("%s:string copy fail", __func__);
|
||||
|
||||
@@ -61,13 +61,14 @@ int32_t HcsBinaryToHexdump(const char *inputFileName)
|
||||
|
||||
struct HcsFile *out = HcsOpenOutputFile(HCS_HEXDUMP_FILE_SUFFIX);
|
||||
if (out == NULL) {
|
||||
HCS_ERROR("can not open %s", HcsGetOutPutFileName());
|
||||
HCS_ERROR("can not open %s", HcsGetOutPutFilePath());
|
||||
HcsCloseFile(source);
|
||||
return EINVALF;
|
||||
}
|
||||
|
||||
int32_t ret = HcsHexdumpOutput(source->file, out->file);
|
||||
if (ret) {
|
||||
HCS_ERROR("fail to gen bytecode hexdump in C style");
|
||||
HCS_ERROR("failed to gen bytecode hexdump in C style");
|
||||
}
|
||||
HcsCloseFile(source);
|
||||
HcsCloseFile(out);
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "hcs_mem.h"
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <securec.h>
|
||||
#include "hcs_mem.h"
|
||||
#define MEM_MAX (1024*1024)
|
||||
#define MEM_MAX (1024 * 1024)
|
||||
|
||||
void *HcsMemAlloc(uint32_t size)
|
||||
{
|
||||
@@ -18,8 +18,7 @@ void *HcsMemAlloc(uint32_t size)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *newMem = malloc(size);
|
||||
return newMem;
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void *HcsMemZalloc(uint32_t size)
|
||||
|
||||
@@ -38,17 +38,14 @@ static ParserObject *HcsLookupAstObject(const ParserObject *current, const char
|
||||
ParserObject *object = HcsGetParserRoot();
|
||||
while (nodeName != NULL) {
|
||||
object = HcsAstLookupObjectInChildren(object, nodeName);
|
||||
if (object == NULL)
|
||||
if (object == NULL) {
|
||||
break;
|
||||
}
|
||||
nodeName = strtok(NULL, ".");
|
||||
}
|
||||
HcsMemFree(splitPath);
|
||||
|
||||
if (object != NULL) {
|
||||
return object;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return object;
|
||||
}
|
||||
|
||||
static int32_t HcsExpandNodeRef(ParserObject *object)
|
||||
@@ -105,7 +102,7 @@ static int32_t HcsExpandNodeCopy(ParserObject *object)
|
||||
ParserObjectBase *copyChild = copyNode->objectBase.child;
|
||||
while (copyChild != NULL) {
|
||||
if (copyChild->type == PARSEROP_CONFNODE) {
|
||||
HCS_OBJECT_ERROR(object, "Not allow copy node has child node when output text config, at %s:%d",
|
||||
HCS_OBJECT_ERROR(object, "Not allow copy node has child node when output text config, at %s:%u",
|
||||
copyChild->src, copyChild->lineno);
|
||||
return EINVALARG;
|
||||
}
|
||||
@@ -340,12 +337,12 @@ static bool HcsApplyDelete(ParserObject *dst, ParserObject *src)
|
||||
static int32_t HcsMergeTree(ParserObject *dst, ParserObject *src)
|
||||
{
|
||||
if (strcmp(src->objectBase.name, dst->objectBase.name) != 0) {
|
||||
HCS_OBJECT_ERROR(src, "merge different node to %s:%d", dst->objectBase.src, dst->objectBase.lineno);
|
||||
HCS_OBJECT_ERROR(src, "merge different node to %s:%u", dst->objectBase.src, dst->objectBase.lineno);
|
||||
return EINVALARG;
|
||||
}
|
||||
|
||||
if (src->objectBase.type != dst->objectBase.type) {
|
||||
HCS_OBJECT_ERROR(src, "conflict type with %s:%d", dst->objectBase.src, dst->objectBase.lineno);
|
||||
HCS_OBJECT_ERROR(src, "conflict type with %s:%u", dst->objectBase.src, dst->objectBase.lineno);
|
||||
return EINVALARG;
|
||||
}
|
||||
|
||||
@@ -373,7 +370,7 @@ static int32_t HcsMergeTree(ParserObject *dst, ParserObject *src)
|
||||
ParserObject *childSrcNext = (ParserObject *)childSrc->objectBase.next;
|
||||
ParserObject *childDst = HcsAstLookupObjectInChildren(dst, childSrc->objectBase.name);
|
||||
if (childDst != NULL && childSrc->objectBase.type != childDst->objectBase.type) {
|
||||
HCS_OBJECT_ERROR(childSrc, "overwrite with different type at %s:%d", childDst->objectBase.src,
|
||||
HCS_OBJECT_ERROR(childSrc, "overwrite with different type at %s:%u", childDst->objectBase.src,
|
||||
childDst->objectBase.lineno);
|
||||
return EINVALARG;
|
||||
}
|
||||
@@ -435,7 +432,7 @@ static int32_t HcsMiddleMerge(ParserObject **mergedRoot)
|
||||
return NOERR;
|
||||
}
|
||||
|
||||
int32_t HcsDoOptimize()
|
||||
int32_t HcsDoOptimize(void)
|
||||
{
|
||||
ParserObject *root = HcsGetParserRoot();
|
||||
if (root == NULL) {
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "hcs_opcode.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
OpCodeMapEntry g_byteCodeMap[PARSEROP_COUNT] = {
|
||||
@@ -22,7 +22,7 @@ OpCodeMapEntry g_byteCodeMap[PARSEROP_COUNT] = {
|
||||
[PARSEROP_NODEREF] = {HCS_NODEREF_OP, DWORD_SIZE, "NodeRef"}, /* RefHashCode - DWORD */
|
||||
};
|
||||
|
||||
const OpCodeMapEntry *HcsGetOpCodeMap()
|
||||
const OpCodeMapEntry *HcsGetOpCodeMap(void)
|
||||
{
|
||||
return g_byteCodeMap;
|
||||
}
|
||||
|
||||
@@ -14,15 +14,15 @@
|
||||
#define ARG_COUNT_MIN 2
|
||||
#define USAGE(option, info) HCS_PRINT(" %-12s%s\n", option, info)
|
||||
|
||||
bool g_genTextConfigOutput = false;
|
||||
bool g_genByteCodeConfigOutput = true;
|
||||
bool g_genByteCodeHexdump = false;
|
||||
bool g_verbosePrint = false;
|
||||
bool g_decompile = false;
|
||||
bool g_shouldAlign = false;
|
||||
const char *g_symbolPrefix = NULL;
|
||||
static bool g_genTextConfigOutput = false;
|
||||
static bool g_genByteCodeConfigOutput = true;
|
||||
static bool g_genByteCodeHexdump = false;
|
||||
static bool g_verbosePrint = false;
|
||||
static bool g_decompile = false;
|
||||
static bool g_shouldAlign = false;
|
||||
static const char *g_symbolPrefix = NULL;
|
||||
|
||||
bool HcsOptShouldAlign()
|
||||
bool HcsOptShouldAlign(void)
|
||||
{
|
||||
return g_shouldAlign;
|
||||
}
|
||||
@@ -32,26 +32,27 @@ void HcsOptSetAlign(bool align)
|
||||
g_shouldAlign = align;
|
||||
}
|
||||
|
||||
|
||||
bool HcsOptShouldGenTextConfig()
|
||||
bool HcsOptShouldGenTextConfig(void)
|
||||
{
|
||||
return g_genTextConfigOutput;
|
||||
}
|
||||
bool HcsOptShouldGenByteCodeConfig()
|
||||
|
||||
bool HcsOptShouldGenByteCodeConfig(void)
|
||||
{
|
||||
return g_genByteCodeConfigOutput;
|
||||
}
|
||||
bool HcsOptDecompile()
|
||||
|
||||
bool HcsOptDecompile(void)
|
||||
{
|
||||
return g_decompile;
|
||||
}
|
||||
|
||||
const char *HcsOptGetSymbolNamePrefix()
|
||||
const char *HcsOptGetSymbolNamePrefix(void)
|
||||
{
|
||||
return g_symbolPrefix;
|
||||
}
|
||||
|
||||
bool HcsOptShouldGenHexdump()
|
||||
bool HcsOptShouldGenHexdump(void)
|
||||
{
|
||||
return g_genByteCodeHexdump;
|
||||
}
|
||||
@@ -151,7 +152,7 @@ int32_t DoOption(int32_t argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool HcsVerbosePrint()
|
||||
bool HcsVerbosePrint(void)
|
||||
{
|
||||
return g_verbosePrint;
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ int32_t HcsProcessInclude(char *includePath, uint32_t lineNumber)
|
||||
return NOERR;
|
||||
}
|
||||
|
||||
int32_t HcsDoCompile()
|
||||
int32_t HcsDoCompile(void)
|
||||
{
|
||||
struct HcsFile *source = NULL;
|
||||
char *forestName = strdup("ForestRoot");
|
||||
|
||||
+125
-272
@@ -18,20 +18,16 @@
|
||||
|
||||
#define TAB_SIZE 4
|
||||
#define WRITE_BUFFER_LEN 256
|
||||
#define INCLUDE_PATH_MAX_LEN 128
|
||||
#define VARIABLE_NAME_LEN 128
|
||||
#define GEN_CODE_MARGIN_SIZE 100
|
||||
#define GEN_ARRAY_SEP_SIZE 2
|
||||
#define ELEMENT_PER_LINE 16
|
||||
#define HCS_CONFIG_FILE_HEADER "/*\n" \
|
||||
" * It's HDF config auto-gen file, do not modify it manually\n" \
|
||||
" * This is an automatically generated HDF config file. Do not modify it manually.\n" \
|
||||
" */\n\n"
|
||||
|
||||
#define HCS_CONFIG_INCLUDE_HEADER "#include <stdint.h>\n\n"
|
||||
|
||||
#define DEFAULT_PREFIX "HdfConfig"
|
||||
|
||||
#define HCS_CONFIG_INCLUDE_FUNC_DECLARATION "const struct %s%sRoot* HdfGet%sModuleConfigRoot(void);\n\n"
|
||||
|
||||
#define HCS_CONFIG_FUNC_IMPLEMENT "\nconst struct %s%sRoot* HdfGet%sModuleConfigRoot(void)\n" \
|
||||
"{\n" \
|
||||
" return &%s;\n" \
|
||||
@@ -96,7 +92,7 @@ static int32_t InitConfigVariableNames()
|
||||
return EOOM;
|
||||
}
|
||||
if (strcpy_s(g_bigHumpModuleName, strlen(moduleName) + 1, moduleName) != EOK) {
|
||||
HCS_ERROR("string copy fail");
|
||||
HCS_ERROR("failed to copy string");
|
||||
return EFAIL;
|
||||
}
|
||||
ToUpperCamelString(g_bigHumpModuleName, strlen(g_bigHumpModuleName));
|
||||
@@ -309,14 +305,16 @@ const char *g_typeMap[PARSEROP_COUNT] = {
|
||||
static int32_t GenConfigStructName(const ParserObject *node, char *name, uint32_t nameBuffLen)
|
||||
{
|
||||
char nameBuffer[OBJECT_NAME_MAX_LEN] = {'\0'};
|
||||
int32_t res = strcpy_s(nameBuffer, OBJECT_NAME_MAX_LEN, HcsGetModuleName());
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
if (strcpy_s(nameBuffer, OBJECT_NAME_MAX_LEN, HcsGetModuleName()) != EOK) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
ToUpperCamelString(nameBuffer, strlen(nameBuffer));
|
||||
res = sprintf_s(name, nameBuffLen, "%s%s", g_namePrefix, nameBuffer);
|
||||
int32_t res = sprintf_s(name, nameBuffLen, "%s%s", g_namePrefix, nameBuffer);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
|
||||
res = strcpy_s(nameBuffer, OBJECT_NAME_MAX_LEN, node->configNode.name);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
if (strcpy_s(nameBuffer, OBJECT_NAME_MAX_LEN, node->configNode.name) != EOK) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
ToUpperCamelString(nameBuffer, strlen(nameBuffer));
|
||||
res = sprintf_s(name + strlen(name), nameBuffLen - strlen(name), "%s", nameBuffer);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
@@ -329,7 +327,7 @@ static int32_t GenConfigArrayName(ParserObject *array, char *name, uint32_t name
|
||||
char buffer[OBJECT_NAME_MAX_LEN] = {'\0'};
|
||||
|
||||
if (strcpy_s(buffer, sizeof(buffer), array->objectBase.name) != EOK) {
|
||||
HCS_ERROR("%s: string copy fail", __func__);
|
||||
HCS_ERROR("%s: failed to copy string", __func__);
|
||||
return EOUTPUT;
|
||||
}
|
||||
ToUpperCamelString(buffer, strlen(buffer));
|
||||
@@ -376,32 +374,27 @@ static int32_t GetArraySize(const ParserObject *array)
|
||||
return size;
|
||||
}
|
||||
|
||||
static int32_t HcsPrintTermDefinition(char *buffer, uint32_t bufferSize, const ParserObject *object)
|
||||
static int32_t HcsPrintTermDefinition(const ParserObject *object)
|
||||
{
|
||||
ParserObject *termContext = (ParserObject *)object->objectBase.child;
|
||||
int32_t res;
|
||||
int32_t res = NOERR;
|
||||
switch (termContext->objectBase.type) {
|
||||
case PARSEROP_ARRAY:
|
||||
if (HcsIsInTemplateNode(object)) {
|
||||
res = sprintf_s(buffer, bufferSize, "const %s *%s;\n", GetArrayType(termContext),
|
||||
object->configTerm.name);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
res = sprintf_s(buffer + strlen(buffer), bufferSize - strlen(buffer), "%*cuint32_t %sSize;\n", TAB_SIZE,
|
||||
' ', object->configTerm.name);
|
||||
res = HcsFormatOutputWrite("const %s *%s;\n", GetArrayType(termContext), object->configTerm.name);
|
||||
OUTPUT_CHECK_AND_RETURN(res);
|
||||
res = HcsFormatOutputWrite("%*cuint32_t %sSize;\n", TAB_SIZE, ' ', object->configTerm.name);
|
||||
} else {
|
||||
res = sprintf_s(buffer, bufferSize, "%s %s[%d];\n", GetArrayType(termContext), object->configTerm.name,
|
||||
res = HcsFormatOutputWrite("%s %s[%d];\n", GetArrayType(termContext), object->configTerm.name,
|
||||
GetArraySize(termContext));
|
||||
}
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
break;
|
||||
case PARSEROP_UINT8:
|
||||
case PARSEROP_UINT16:
|
||||
case PARSEROP_UINT32:
|
||||
case PARSEROP_UINT64:
|
||||
case PARSEROP_STRING:
|
||||
res = sprintf_s(buffer, bufferSize - strlen(buffer), "%s %s;\n", g_typeMap[termContext->objectBase.type],
|
||||
object->configTerm.name);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
res = HcsFormatOutputWrite("%s %s;\n", g_typeMap[termContext->objectBase.type], object->configTerm.name);
|
||||
break;
|
||||
case PARSEROP_NODEREF: {
|
||||
char refType[OBJECT_NAME_MAX_LEN] = {'\0'};
|
||||
@@ -409,15 +402,13 @@ static int32_t HcsPrintTermDefinition(char *buffer, uint32_t bufferSize, const P
|
||||
if (res) {
|
||||
return res;
|
||||
}
|
||||
res = sprintf_s(buffer, bufferSize - strlen(buffer), "const struct %s* %s;\n", refType,
|
||||
object->configTerm.name);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
res = HcsFormatOutputWrite("const struct %s* %s;\n", refType, object->configTerm.name);
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return NOERR;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t HcsObjectDefinitionGen(const ParserObject *current)
|
||||
@@ -426,9 +417,8 @@ static int32_t HcsObjectDefinitionGen(const ParserObject *current)
|
||||
return NOERR;
|
||||
}
|
||||
|
||||
char writeBuffer[WRITE_BUFFER_LEN] = {'\0'};
|
||||
int32_t res = sprintf_s(writeBuffer, WRITE_BUFFER_LEN, "%*c", TAB_SIZE, ' ');
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
int res = NOERR;
|
||||
OUTPUT_CHECK_AND_RETURN(HcsFormatOutputWrite("%*c", TAB_SIZE, ' '));
|
||||
switch (current->objectBase.type) {
|
||||
case PARSEROP_CONFNODE: {
|
||||
char structName[OBJECT_NAME_MAX_LEN] = {'\0'};
|
||||
@@ -438,32 +428,27 @@ static int32_t HcsObjectDefinitionGen(const ParserObject *current)
|
||||
}
|
||||
if (current->configNode.nodeType == CONFIG_NODE_TEMPLATE) {
|
||||
char nodeName[OBJECT_NAME_MAX_LEN] = {0};
|
||||
if (strcpy_s(nodeName, sizeof(nodeName), current->configNode.name)) {
|
||||
if (strcpy_s(nodeName, sizeof(nodeName), current->configNode.name) != EOK) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
ToLowerCamelString(nodeName, strlen(nodeName));
|
||||
res = sprintf_s(writeBuffer + TAB_SIZE, WRITE_BUFFER_LEN - strlen(writeBuffer),
|
||||
"const struct %s* %s;\n", structName, nodeName);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
res = sprintf_s(writeBuffer + strlen(writeBuffer), WRITE_BUFFER_LEN - strlen(writeBuffer),
|
||||
"%*cuint16_t %sSize;\n", TAB_SIZE, ' ', nodeName);
|
||||
OUTPUT_CHECK_AND_RETURN(HcsFormatOutputWrite("const struct %s* %s;\n", structName, nodeName));
|
||||
res = HcsFormatOutputWrite("%*cuint16_t %sSize;\n", TAB_SIZE, ' ', nodeName);
|
||||
} else if (current->configNode.nodeType == CONFIG_NODE_INHERIT) {
|
||||
return NOERR;
|
||||
} else {
|
||||
res = sprintf_s(writeBuffer + TAB_SIZE, WRITE_BUFFER_LEN - strlen(writeBuffer), "struct %s %s;\n",
|
||||
structName, current->configNode.name);
|
||||
res = HcsFormatOutputWrite("struct %s %s;\n", structName, current->configNode.name);
|
||||
}
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
break;
|
||||
}
|
||||
case PARSEROP_CONFTERM:
|
||||
HcsPrintTermDefinition(writeBuffer + TAB_SIZE, WRITE_BUFFER_LEN - strlen(writeBuffer), current);
|
||||
res = HcsPrintTermDefinition(current);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return HcsOutputWrite(writeBuffer, strlen(writeBuffer));
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t HcsDuplicateCheckWalkCallBack(ParserObject *current, int32_t walkDepth)
|
||||
@@ -479,7 +464,6 @@ static int32_t HcsDuplicateCheckWalkCallBack(ParserObject *current, int32_t walk
|
||||
static int32_t HcsGenNormalNodeDefinition(ParserObject *object, int32_t walkDepth)
|
||||
{
|
||||
(void)walkDepth;
|
||||
char writeBuffer[WRITE_BUFFER_LEN] = {'\0'};
|
||||
char structName[OBJECT_NAME_MAX_LEN] = {'\0'};
|
||||
int32_t res = GenConfigStructName(object, structName, OBJECT_NAME_MAX_LEN - 1);
|
||||
if (res) {
|
||||
@@ -491,11 +475,7 @@ static int32_t HcsGenNormalNodeDefinition(ParserObject *object, int32_t walkDept
|
||||
HcsSymbolTableAdd(structName, object);
|
||||
}
|
||||
|
||||
res = sprintf_s(writeBuffer, (WRITE_BUFFER_LEN - 1), "struct %s {\n", structName);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
if (HcsOutputWrite(writeBuffer, strlen(writeBuffer))) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
OUTPUT_CHECK_AND_RETURN(HcsFormatOutputWrite("struct %s {\n", structName));
|
||||
|
||||
ParserObject *terms = (ParserObject *)object->objectBase.child;
|
||||
while (terms != NULL) {
|
||||
@@ -506,10 +486,7 @@ static int32_t HcsGenNormalNodeDefinition(ParserObject *object, int32_t walkDept
|
||||
terms = (ParserObject *)terms->objectBase.next;
|
||||
}
|
||||
|
||||
res = sprintf_s(writeBuffer, (WRITE_BUFFER_LEN - 1), "};\n\n");
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
|
||||
return HcsOutputWrite(writeBuffer, strlen(writeBuffer));
|
||||
return HcsFormatOutputWrite("};\n\n");
|
||||
}
|
||||
|
||||
static int32_t HcsGenNodeTemplateDefinition(ParserObject *object, int32_t walkDepth)
|
||||
@@ -532,20 +509,18 @@ static int32_t HcsDefinitionGenWalkCallBack(ParserObject *current, int32_t walkD
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t HcsPrintTermValue(char *buffer, uint32_t buffSize, const ParserObject *object)
|
||||
static uint32_t HcsPrintTermValue(const ParserObject *object)
|
||||
{
|
||||
int32_t res = 0;
|
||||
int32_t res = NOERR;
|
||||
switch (object->objectBase.type) {
|
||||
case PARSEROP_UINT8: /* fallthrough */
|
||||
case PARSEROP_UINT16: /* fallthrough */
|
||||
case PARSEROP_UINT32: /* fallthrough */
|
||||
case PARSEROP_UINT64:
|
||||
res = sprintf_s(buffer, buffSize, "0x%" PRIx64, object->objectBase.integerValue);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
res = HcsFormatOutputWrite("0x%" PRIx64, object->objectBase.integerValue);
|
||||
break;
|
||||
case PARSEROP_STRING:
|
||||
res = sprintf_s(buffer, buffSize, "\"%s\"", object->objectBase.stringValue);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
res = HcsFormatOutputWrite("\"%s\"", object->objectBase.stringValue);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -603,19 +578,15 @@ static char *HcsBuildObjectPath(const ParserObject *refObject)
|
||||
return path;
|
||||
}
|
||||
|
||||
static int32_t HcsPrintArrayImplInSubClass(char *buffer, uint32_t bufferSize, ParserObject *object, uint8_t tabSize)
|
||||
static int32_t HcsPrintArrayImplInSubClass(ParserObject *object, uint8_t tabSize)
|
||||
{
|
||||
int32_t size = sprintf_s(buffer, bufferSize, "%*c.%s = ", tabSize, ' ', object->objectBase.name);
|
||||
PRINTF_CHECK_AND_RETURN(size);
|
||||
if (GenConfigArrayName(object, buffer + size, bufferSize - size)) {
|
||||
char arrayName[VARIABLE_NAME_LEN] = {0};
|
||||
if (GenConfigArrayName(object, arrayName, VARIABLE_NAME_LEN)) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
size = sprintf_s(buffer + strlen(buffer), bufferSize - strlen(buffer), ",\n");
|
||||
PRINTF_CHECK_AND_RETURN(size);
|
||||
size = sprintf_s(buffer + strlen(buffer), bufferSize - strlen(buffer), "%*c.%sSize = %d,\n", tabSize, ' ',
|
||||
object->configTerm.name, GetArraySize((ParserObject *)object->objectBase.child));
|
||||
PRINTF_CHECK_AND_RETURN(size);
|
||||
return HcsOutputWrite(buffer, strlen(buffer));
|
||||
OUTPUT_CHECK_AND_RETURN(HcsFormatOutputWrite(".%s = %s,\n", object->objectBase.name, arrayName));
|
||||
return HcsFormatOutputWrite("%*c.%sSize = %d,\n", tabSize, ' ',
|
||||
object->configTerm.name, GetArraySize((ParserObject *)object->objectBase.child));
|
||||
}
|
||||
|
||||
static int32_t HcsPrintArrayContent(const ParserObject *object, int32_t tabSize)
|
||||
@@ -624,59 +595,44 @@ static int32_t HcsPrintArrayContent(const ParserObject *object, int32_t tabSize)
|
||||
return NOERR;
|
||||
}
|
||||
|
||||
char writeBuffer[WRITE_BUFFER_LEN] = {'\0'};
|
||||
ParserObject *element = (ParserObject *)object->objectBase.child;
|
||||
uint32_t writeSize = 0;
|
||||
uint32_t elementCount = 0;
|
||||
while (element != NULL) {
|
||||
int32_t size = HcsPrintTermValue(writeBuffer + writeSize, sizeof(writeBuffer) - writeSize, element);
|
||||
writeBuffer[writeSize + size++] = ',';
|
||||
writeBuffer[writeSize + size++] = ' ';
|
||||
writeSize += size;
|
||||
if (writeSize >= GEN_CODE_MARGIN_SIZE) {
|
||||
writeSize -= 1; /* strip space at line end */
|
||||
size = sprintf_s(writeBuffer + writeSize, sizeof(writeBuffer) - writeSize, "\n%*c", tabSize, ' ');
|
||||
PRINTF_CHECK_AND_RETURN(size);
|
||||
writeSize += size;
|
||||
if (HcsOutputWrite(writeBuffer, writeSize)) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
writeSize = 0;
|
||||
if (HcsPrintTermValue(element) != NOERR) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
if (elementCount++ >= ELEMENT_PER_LINE) {
|
||||
OUTPUT_CHECK_AND_RETURN(HcsFormatOutputWrite("\n%*c", tabSize, ' '));
|
||||
}
|
||||
element = (ParserObject *)element->configTerm.next;
|
||||
if (element != NULL) {
|
||||
OUTPUT_CHECK_AND_RETURN(HcsFormatOutputWrite(", "));
|
||||
}
|
||||
}
|
||||
|
||||
return writeSize ? HcsOutputWrite(writeBuffer, writeSize - GEN_ARRAY_SEP_SIZE) : NOERR;
|
||||
return NOERR;
|
||||
}
|
||||
|
||||
static int32_t HcsPrintArrayImplement(char *buffer, uint32_t bufferSize, ParserObject *object, uint8_t tabSize)
|
||||
static int32_t HcsPrintArrayImplement(ParserObject *object, uint8_t tabSize)
|
||||
{
|
||||
if (HcsIsInSubClassNode(object)) {
|
||||
return HcsPrintArrayImplInSubClass(buffer, bufferSize, object, tabSize);
|
||||
return HcsPrintArrayImplInSubClass(object, tabSize);
|
||||
}
|
||||
|
||||
ParserObject *termContext = (ParserObject *)object->objectBase.child;
|
||||
int32_t res = sprintf_s(buffer + strlen(buffer), bufferSize - strlen(buffer), "%*c.%s = { ", tabSize, ' ',
|
||||
object->configTerm.name);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
if (HcsOutputWrite(buffer, strlen(buffer))) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
OUTPUT_CHECK_AND_RETURN(HcsFormatOutputWrite(".%s = { ", object->configTerm.name));
|
||||
|
||||
if (HcsPrintArrayContent(termContext, tabSize + TAB_SIZE)) {
|
||||
HCS_ERROR("fail to write array content");
|
||||
return EOUTPUT;
|
||||
}
|
||||
res = sprintf_s(buffer, bufferSize, " },\n");
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
if (HcsOutputWrite(buffer, strlen(buffer))) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
return NOERR;
|
||||
return HcsFormatOutputWrite(" },\n");
|
||||
}
|
||||
|
||||
static int32_t HcsPrintTermImplement(char *buffer, uint32_t bufferSize, ParserObject *object, int32_t tabSize)
|
||||
static int32_t HcsPrintTermImplement(ParserObject *object, int32_t tabSize)
|
||||
{
|
||||
int32_t res;
|
||||
sprintf_s(buffer, bufferSize, "%*c", tabSize, ' ');
|
||||
int32_t res = NOERR;
|
||||
OUTPUT_CHECK_AND_RETURN(HcsFormatOutputWrite("%*c", tabSize, ' '));
|
||||
ParserObject *termContext = (ParserObject *)object->objectBase.child;
|
||||
switch (termContext->objectBase.type) {
|
||||
case PARSEROP_UINT8:
|
||||
@@ -686,52 +642,43 @@ static int32_t HcsPrintTermImplement(char *buffer, uint32_t bufferSize, ParserOb
|
||||
case PARSEROP_UINT32:
|
||||
/* fall-through */
|
||||
case PARSEROP_UINT64:
|
||||
res = sprintf_s(buffer + strlen(buffer), bufferSize - strlen(buffer), ".%s = ", object->configTerm.name);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
if (!HcsPrintTermValue(buffer + strlen(buffer), bufferSize - strlen(buffer), termContext)) {
|
||||
OUTPUT_CHECK_AND_RETURN(HcsFormatOutputWrite(".%s = ", object->configTerm.name));
|
||||
if (HcsPrintTermValue(termContext) != NOERR) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
res = sprintf_s(buffer + strlen(buffer), bufferSize - strlen(buffer), ",\n");
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
res = HcsFormatOutputWrite(",\n");
|
||||
break;
|
||||
case PARSEROP_STRING:
|
||||
res = sprintf_s(buffer + strlen(buffer), bufferSize - strlen(buffer), ".%s = ", object->configTerm.name);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
if (!HcsPrintTermValue(buffer + strlen(buffer), bufferSize - strlen(buffer), termContext)) {
|
||||
OUTPUT_CHECK_AND_RETURN(HcsFormatOutputWrite(".%s = ", object->configTerm.name));
|
||||
if (HcsPrintTermValue(termContext) != NOERR) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
res = sprintf_s(buffer + strlen(buffer), bufferSize - strlen(buffer), ",\n");
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
res = HcsFormatOutputWrite(",\n");
|
||||
break;
|
||||
case PARSEROP_ARRAY:
|
||||
if (HcsPrintArrayImplement(buffer + strlen(buffer), bufferSize - strlen(buffer), object, tabSize)) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
buffer[0] = '\0';
|
||||
res = HcsPrintArrayImplement(object, tabSize);
|
||||
break;
|
||||
case PARSEROP_NODEREF: {
|
||||
char *refPath = HcsBuildObjectPath((ParserObject *)object->objectBase.child->value);
|
||||
if (refPath == NULL) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
res = sprintf_s(buffer + strlen(buffer), bufferSize - strlen(buffer), ".%s = &%s,\n",
|
||||
object->configTerm.name, refPath);
|
||||
res = HcsFormatOutputWrite(".%s = &%s,\n", object->configTerm.name, refPath);
|
||||
HcsMemFree(refPath);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return NOERR;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t HcsGenTemplateVariableName(ParserObject *object, char *nameBuff, uint32_t nameBufferSize)
|
||||
{
|
||||
char tempName[OBJECT_NAME_MAX_LEN] = {'\0'};
|
||||
if (strcpy_s(tempName, sizeof(tempName), object->objectBase.name)) {
|
||||
HCS_ERROR("s: string copy fail");
|
||||
if (strcpy_s(tempName, sizeof(tempName), object->objectBase.name) != EOK) {
|
||||
HCS_ERROR("failed to copy string");
|
||||
return EOUTPUT;
|
||||
}
|
||||
ToUpperCamelString(tempName, sizeof(tempName));
|
||||
@@ -756,24 +703,22 @@ static int32_t HcsGenTemplateVariableName(ParserObject *object, char *nameBuff,
|
||||
|
||||
static int32_t HcsTemplateNodeImplGen(ParserObject *current, int32_t tabSize)
|
||||
{
|
||||
char writeBuffer[WRITE_BUFFER_LEN] = {'\0'};
|
||||
char templateVariableName[VARIABLE_NAME_LEN] = {'\0'};
|
||||
if (HcsGenTemplateVariableName(current, templateVariableName, sizeof(templateVariableName))) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
char nodeName[OBJECT_NAME_MAX_LEN] = {0};
|
||||
if (strcpy_s(nodeName, sizeof(nodeName), current->configNode.name)) {
|
||||
HCS_ERROR("%s: string copy fail", __func__);
|
||||
if (strcpy_s(nodeName, sizeof(nodeName), current->configNode.name) != EOK) {
|
||||
HCS_ERROR("%s: failed to copy string", __func__);
|
||||
return EOUTPUT;
|
||||
}
|
||||
|
||||
ToLowerCamelString(nodeName, strlen(nodeName));
|
||||
int32_t res = sprintf_s(writeBuffer, WRITE_BUFFER_LEN, "%*c.%s = %s,\n", tabSize, ' ', nodeName,
|
||||
current->configNode.inheritCount ? templateVariableName : "0");
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
res = sprintf_s(writeBuffer + strlen(writeBuffer), WRITE_BUFFER_LEN - strlen(writeBuffer), "%*c.%sSize = %d,\n",
|
||||
OUTPUT_CHECK_AND_RETURN(HcsFormatOutputWrite("%*c.%s = %s,\n", tabSize, ' ', nodeName,
|
||||
current->configNode.inheritCount ? templateVariableName : "0"));
|
||||
|
||||
return HcsFormatOutputWrite("%*c.%sSize = %d,\n",
|
||||
tabSize, ' ', nodeName, current->configNode.inheritCount);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
return HcsOutputWrite(writeBuffer, strlen(writeBuffer));
|
||||
}
|
||||
|
||||
static int32_t HcsInheritObjectImplGen(ParserObject *current, int32_t tabSize)
|
||||
@@ -787,33 +732,26 @@ static int32_t HcsInheritObjectImplGen(ParserObject *current, int32_t tabSize)
|
||||
|
||||
static int32_t HcsObjectImplementGen(ParserObject *current, int32_t tabSize)
|
||||
{
|
||||
char writeBuffer[WRITE_BUFFER_LEN] = {'\0'};
|
||||
int32_t res;
|
||||
int32_t res = NOERR;
|
||||
switch (current->objectBase.type) {
|
||||
case PARSEROP_CONFNODE: {
|
||||
case PARSEROP_CONFNODE:
|
||||
if (current->configNode.nodeType != CONFIG_NODE_NOREF) {
|
||||
res = HcsInheritObjectImplGen(current, tabSize);
|
||||
return res ? res : EASTWALKBREAK;
|
||||
}
|
||||
res = sprintf_s(writeBuffer, WRITE_BUFFER_LEN, "%*c.%s = {\n", tabSize, ' ', current->configNode.name);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
OUTPUT_CHECK_AND_RETURN(HcsFormatOutputWrite("%*c.%s = {\n", tabSize, ' ', current->configNode.name));
|
||||
if (current->objectBase.child == NULL) {
|
||||
res = sprintf_s(writeBuffer + strlen(writeBuffer) - 1, WRITE_BUFFER_LEN - strlen(writeBuffer) + 1,
|
||||
"},\n");
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
res = HcsFormatOutputWrite("%*c},\n", tabSize, ' ');
|
||||
}
|
||||
} break;
|
||||
break;
|
||||
case PARSEROP_CONFTERM:
|
||||
res = HcsPrintTermImplement(writeBuffer, WRITE_BUFFER_LEN, current, tabSize);
|
||||
if (res) {
|
||||
return res;
|
||||
}
|
||||
res = HcsPrintTermImplement(current, tabSize);
|
||||
break;
|
||||
default:
|
||||
return NOERR;
|
||||
}
|
||||
|
||||
return HcsOutputWrite(writeBuffer, strlen(writeBuffer));
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t HcsImplementGenWalkCallBack(ParserObject *current, int32_t walkDepth)
|
||||
@@ -827,20 +765,17 @@ static int32_t HcsImplementGenWalkCallBack(ParserObject *current, int32_t walkDe
|
||||
}
|
||||
|
||||
if (current == HcsGetParserRoot()) {
|
||||
char writeBuffer[WRITE_BUFFER_LEN] = {'\0'};
|
||||
char structName[OBJECT_NAME_MAX_LEN] = {'\0'};
|
||||
int32_t res = GenConfigStructName(current, structName, OBJECT_NAME_MAX_LEN - 1);
|
||||
if (res) {
|
||||
return res;
|
||||
}
|
||||
res = sprintf_s(writeBuffer, WRITE_BUFFER_LEN, "static const struct %s %s = {\n", structName,
|
||||
GetConfigRootVariableName());
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
OUTPUT_CHECK_AND_RETURN(HcsFormatOutputWrite("static const struct %s %s = {\n",
|
||||
structName, GetConfigRootVariableName()));
|
||||
if (current->objectBase.child == NULL) {
|
||||
res = sprintf_s(writeBuffer + strlen(writeBuffer), WRITE_BUFFER_LEN - strlen(writeBuffer), "};\n");
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
res = HcsFormatOutputWrite("};\n");
|
||||
}
|
||||
return HcsOutputWrite(writeBuffer, strlen(writeBuffer));
|
||||
return res;
|
||||
}
|
||||
return HcsObjectImplementGen(current, walkDepth * TAB_SIZE);
|
||||
}
|
||||
@@ -856,18 +791,12 @@ static int32_t HcsImplementCloseBraceGen(ParserObject *current, int32_t walkDept
|
||||
}
|
||||
|
||||
int32_t tabSize = walkDepth * TAB_SIZE;
|
||||
char writeBuffer[WRITE_BUFFER_LEN] = {'\0'};
|
||||
|
||||
int32_t res;
|
||||
if (current != HcsGetParserRoot()) {
|
||||
res = sprintf_s(writeBuffer, WRITE_BUFFER_LEN, "%*c},\n", tabSize, ' ');
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
return HcsFormatOutputWrite("%*c},\n", tabSize, ' ');
|
||||
} else {
|
||||
res = sprintf_s(writeBuffer, WRITE_BUFFER_LEN, "};\n");
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
return HcsFormatOutputWrite("};\n");
|
||||
}
|
||||
|
||||
return HcsOutputWrite(writeBuffer, strlen(writeBuffer));
|
||||
}
|
||||
|
||||
static void ToUpperString(char *str, uint32_t strLen)
|
||||
@@ -877,118 +806,71 @@ static void ToUpperString(char *str, uint32_t strLen)
|
||||
}
|
||||
}
|
||||
|
||||
static void StripFileNameSuffix(char *fileName, uint32_t fileNameLen)
|
||||
{
|
||||
for (uint32_t i = 0; i < fileNameLen; ++i) {
|
||||
if (fileName[i] == '.') {
|
||||
fileName[i] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define HCS_HEADER_MACRO_MAX_LEN 150
|
||||
static char *GenHeaderProtectionMacro()
|
||||
{
|
||||
const char *outPutFileName = HcsGetStripedOutputFileName();
|
||||
char *headerMacro = strdup(outPutFileName);
|
||||
if (headerMacro == NULL) {
|
||||
HCS_ERROR("oom");
|
||||
char *fileName = HcsGetOutputFileNameWithoutSuffix();
|
||||
if (fileName == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
StripFileNameSuffix(headerMacro, strlen(headerMacro));
|
||||
ToUpperString(headerMacro, strlen(headerMacro));
|
||||
ToUpperString(fileName, strlen(fileName));
|
||||
|
||||
char *macro = HcsMemZalloc(sizeof(char) * HCS_HEADER_MACRO_MAX_LEN);
|
||||
if (macro == NULL) {
|
||||
HCS_ERROR("oom");
|
||||
HcsMemFree(headerMacro);
|
||||
HcsMemFree(fileName);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t res = sprintf_s(macro, HCS_HEADER_MACRO_MAX_LEN, "HCS_CONFIG_%s_HEADER_H", headerMacro);
|
||||
int32_t res = sprintf_s(macro, HCS_HEADER_MACRO_MAX_LEN, "HCS_CONFIG_%s_HEADER_H", fileName);
|
||||
HcsMemFree(fileName);
|
||||
if (res <= 0) {
|
||||
HcsMemFree(headerMacro);
|
||||
HcsMemFree(macro);
|
||||
return NULL;
|
||||
}
|
||||
HcsMemFree(headerMacro);
|
||||
return macro;
|
||||
}
|
||||
|
||||
static int32_t HcsWriteHeaderFileHead()
|
||||
{
|
||||
/* Write copyright info */
|
||||
const char *header = HCS_CONFIG_FILE_HEADER;
|
||||
if (HcsOutputWrite(header, strlen(header))) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
OUTPUT_CHECK_AND_RETURN(HcsFormatOutputWrite(HCS_CONFIG_FILE_HEADER));
|
||||
|
||||
/* Write header protection macro */
|
||||
char *headerProtectMacro = GenHeaderProtectionMacro();
|
||||
if (headerProtectMacro == NULL) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
char writeBuffer[WRITE_BUFFER_LEN] = {'\0'};
|
||||
int32_t ret = sprintf_s(writeBuffer, WRITE_BUFFER_LEN, "#ifndef %s\n#define %s\n\n",
|
||||
headerProtectMacro, headerProtectMacro);
|
||||
HcsMemFree(headerProtectMacro);
|
||||
if (ret <= 0) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
|
||||
if (HcsOutputWrite(writeBuffer, strlen(writeBuffer))) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
OUTPUT_CHECK_AND_RETURN(HcsFormatOutputWrite("#ifndef %s\n#define %s\n\n",
|
||||
headerProtectMacro, headerProtectMacro));
|
||||
|
||||
/* Write include header file */
|
||||
header = HCS_CONFIG_INCLUDE_HEADER;
|
||||
if (HcsOutputWrite(header, strlen(header))) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
|
||||
return NOERR;
|
||||
return HcsFormatOutputWrite(HCS_CONFIG_INCLUDE_HEADER);
|
||||
}
|
||||
|
||||
static int32_t HcsWriteHeaderFileEnd()
|
||||
{
|
||||
char writeBuffer[WRITE_BUFFER_LEN] = {'\0'};
|
||||
/* Write header protection macro */
|
||||
char *headerMacro = GenHeaderProtectionMacro();
|
||||
if (headerMacro == NULL) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
int32_t ret = sprintf_s(writeBuffer, (WRITE_BUFFER_LEN - 1), "#endif // %s", headerMacro);
|
||||
int32_t ret = HcsFormatOutputWrite("\n\n#endif // %s", headerMacro);
|
||||
HcsMemFree(headerMacro);
|
||||
if (ret <= 0) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
|
||||
return HcsOutputWrite(writeBuffer, strlen(writeBuffer));
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t HcsWriteFunctionDeclaration()
|
||||
{
|
||||
char writeBuffer[WRITE_BUFFER_LEN] = {'\0'};
|
||||
int32_t ret = sprintf_s(writeBuffer, (WRITE_BUFFER_LEN - 1), HCS_CONFIG_INCLUDE_FUNC_DECLARATION, g_namePrefix,
|
||||
return HcsFormatOutputWrite("const struct %s%sRoot* HdfGet%sModuleConfigRoot(void);", g_namePrefix,
|
||||
g_bigHumpModuleName, g_bigHumpModuleName);
|
||||
if (ret <= 0) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
|
||||
return HcsOutputWrite(writeBuffer, strlen(writeBuffer));
|
||||
}
|
||||
|
||||
static int32_t HcsWriteFunctionImplement()
|
||||
{
|
||||
char writeBuffer[WRITE_BUFFER_LEN] = {'\0'};
|
||||
int32_t ret = sprintf_s(writeBuffer, (WRITE_BUFFER_LEN - 1), HCS_CONFIG_FUNC_IMPLEMENT, g_namePrefix,
|
||||
return HcsFormatOutputWrite(HCS_CONFIG_FUNC_IMPLEMENT, g_namePrefix,
|
||||
g_bigHumpModuleName, g_bigHumpModuleName, GetConfigRootVariableName());
|
||||
if (ret <= 0) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
|
||||
return HcsOutputWrite(writeBuffer, strlen(writeBuffer));
|
||||
}
|
||||
|
||||
static int32_t HcsOutputHeaderFile()
|
||||
@@ -1064,47 +946,33 @@ static int32_t HcsTemplateImplGenWalkCallBack(ParserObject *current, int32_t wal
|
||||
return NOERR;
|
||||
}
|
||||
|
||||
char writeBuffer[WRITE_BUFFER_LEN] = {'\0'};
|
||||
char nameBuff[OBJECT_NAME_MAX_LEN] = {'\0'};
|
||||
int32_t res = GenConfigStructName(current, nameBuff, OBJECT_NAME_MAX_LEN - 1);
|
||||
if (res) {
|
||||
return res;
|
||||
}
|
||||
|
||||
res = sprintf_s(writeBuffer, sizeof(writeBuffer), "static const struct %s ", nameBuff);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
OUTPUT_CHECK_AND_RETURN(HcsFormatOutputWrite("static const struct %s ", nameBuff));
|
||||
if (HcsGenTemplateVariableName(current, nameBuff, sizeof(nameBuff))) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
res = sprintf_s(writeBuffer + strlen(writeBuffer), sizeof(writeBuffer) - strlen(writeBuffer),
|
||||
"%s[] = {\n", nameBuff);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
HcsOutputWrite(writeBuffer, strlen(writeBuffer));
|
||||
/* Generate C global variables definition file */
|
||||
OUTPUT_CHECK_AND_RETURN(HcsFormatOutputWrite("%s[] = {\n", nameBuff));
|
||||
|
||||
/* Generate C global variables definition file */
|
||||
TemplateNodeInstance *subClasses = current->configNode.subClasses;
|
||||
g_baseTabsize = TAB_SIZE + TAB_SIZE;
|
||||
while (subClasses != NULL) {
|
||||
res = sprintf_s(writeBuffer, sizeof(writeBuffer), "%*c[%d] = {\n", TAB_SIZE, ' ',
|
||||
subClasses->nodeObject->inheritIndex);
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
if (HcsOutputWrite(writeBuffer, res)) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
OUTPUT_CHECK_AND_RETURN(HcsFormatOutputWrite("%*c[%d] = {\n", TAB_SIZE, ' ',
|
||||
subClasses->nodeObject->inheritIndex));
|
||||
|
||||
if (HcsTemplateVariableGen((ParserObject *)subClasses->nodeObject)) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
res = sprintf_s(writeBuffer, sizeof(writeBuffer), "%*c},\n", TAB_SIZE, ' ');
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
if (HcsOutputWrite(writeBuffer, strlen(writeBuffer))) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
OUTPUT_CHECK_AND_RETURN(HcsFormatOutputWrite("%*c},\n", TAB_SIZE, ' '));
|
||||
subClasses = subClasses->next;
|
||||
}
|
||||
|
||||
res = sprintf_s(writeBuffer, sizeof(writeBuffer), "};\n\n");
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
return HcsOutputWrite(writeBuffer, strlen(writeBuffer));
|
||||
return HcsFormatOutputWrite("};\n\n");
|
||||
}
|
||||
|
||||
static int32_t HcsArrayVariablesDeclareGen(ParserObject *term)
|
||||
@@ -1113,26 +981,21 @@ static int32_t HcsArrayVariablesDeclareGen(ParserObject *term)
|
||||
return NOERR;
|
||||
}
|
||||
|
||||
char writeBuffer[WRITE_BUFFER_LEN] = {'\0'};
|
||||
char nameBuff[OBJECT_NAME_MAX_LEN] = {'\0'};
|
||||
int32_t res = GenConfigArrayName(term, nameBuff, OBJECT_NAME_MAX_LEN - 1);
|
||||
if (res) {
|
||||
return res;
|
||||
}
|
||||
ParserObject *array = (ParserObject *)term->configTerm.child;
|
||||
res = sprintf_s(writeBuffer, sizeof(writeBuffer), "\nstatic const %s %s[%d] = {\n%*c", GetArrayType(array),
|
||||
res = HcsFormatOutputWrite("\nstatic const %s %s[%d] = {\n%*c", GetArrayType(array),
|
||||
nameBuff, GetArraySize(array), TAB_SIZE, ' ');
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
if (HcsOutputWrite(writeBuffer, strlen(writeBuffer))) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
OUTPUT_CHECK_AND_RETURN(res);
|
||||
|
||||
if (HcsPrintArrayContent(array, TAB_SIZE)) {
|
||||
HCS_ERROR("fail to write array content");
|
||||
return EOUTPUT;
|
||||
}
|
||||
res = sprintf_s(writeBuffer, sizeof(writeBuffer), "\n};\n");
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
return HcsOutputWrite(writeBuffer, strlen(writeBuffer));
|
||||
return HcsFormatOutputWrite("\n};\n");
|
||||
}
|
||||
|
||||
static int32_t HcsTemplateVariablesDeclareGenWalk(ParserObject *current, int32_t walkDepth)
|
||||
@@ -1174,10 +1037,8 @@ static int32_t HcsTemplateVariablesDeclareGen(ParserObject *astRoot)
|
||||
/* if no template variable generated, should not output end line */
|
||||
return NOERR;
|
||||
}
|
||||
char writeBuffer[WRITE_BUFFER_LEN] = {'\0'};
|
||||
int32_t res = sprintf_s(writeBuffer, sizeof(writeBuffer), "\n");
|
||||
PRINTF_CHECK_AND_RETURN(res);
|
||||
return HcsOutputWrite(writeBuffer, strlen(writeBuffer));
|
||||
const char *lineEnd = "\n";
|
||||
return HcsOutputWrite(lineEnd, strlen(lineEnd));
|
||||
}
|
||||
|
||||
static int32_t HcsOutputTemplateImplement(ParserObject *astRoot)
|
||||
@@ -1206,32 +1067,24 @@ static int32_t HcsOutputCFile()
|
||||
return EINVALF;
|
||||
}
|
||||
|
||||
const char *header = HCS_CONFIG_FILE_HEADER;
|
||||
if (HcsOutputWrite(header, strlen(header))) {
|
||||
if (HcsFormatOutputWrite(HCS_CONFIG_FILE_HEADER)) {
|
||||
HcsCloseOutput(outputFIle);
|
||||
return EOUTPUT;
|
||||
}
|
||||
|
||||
char include[INCLUDE_PATH_MAX_LEN] = {'\0'};
|
||||
int32_t res = sprintf_s(include, INCLUDE_PATH_MAX_LEN, "#include \"%s", HcsGetStripedOutputFileName());
|
||||
if (res <= 0) {
|
||||
HcsCloseOutput(outputFIle);
|
||||
char *fileName = HcsGetOutputFileNameWithoutSuffix();
|
||||
if (fileName == NULL) {
|
||||
return EOUTPUT;
|
||||
}
|
||||
|
||||
res = sprintf_s(include + strlen(include) - 1, WRITE_BUFFER_LEN - strlen(include), "h\"\n\n");
|
||||
if (res <= 0) {
|
||||
HcsCloseOutput(outputFIle);
|
||||
return EOUTPUT;
|
||||
}
|
||||
|
||||
if (HcsOutputWrite(include, strlen(include))) {
|
||||
int32_t res = HcsFormatOutputWrite("#include \"%s.h\"\n\n", fileName);
|
||||
HcsMemFree(fileName);
|
||||
if (res != NOERR) {
|
||||
HcsCloseOutput(outputFIle);
|
||||
return EOUTPUT;
|
||||
}
|
||||
|
||||
res = HcsOutputTemplateImplement(astRoot);
|
||||
if (res) {
|
||||
if (res != NOERR) {
|
||||
HcsCloseOutput(outputFIle);
|
||||
return EOUTPUT;
|
||||
}
|
||||
@@ -1248,7 +1101,7 @@ static int32_t HcsOutputCFile()
|
||||
return res;
|
||||
}
|
||||
|
||||
int32_t HcsTextCodeOutput()
|
||||
int32_t HcsTextCodeOutput(void)
|
||||
{
|
||||
int32_t ret = HcsSymbolTableInit();
|
||||
if (ret) {
|
||||
|
||||
Reference in New Issue
Block a user