diff --git a/BUILD.gn b/BUILD.gn
old mode 100755
new mode 100644
index d937682279dc3f5b7d341ec0c9617376b14721ea..896f53ee1a4601b3ddd7b9acd4caf23340f4954f
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -30,17 +30,18 @@ if (defined(ohos_lite)) {
group("uhdf_entry") {
deps = [
"//drivers/adapter/uhdf2/hcs:hdf_default.hcb",
+ "//drivers/adapter/uhdf2/hcs:hdf_devhost.cfg",
"//drivers/adapter/uhdf2/hdi:libhdi",
"//drivers/adapter/uhdf2/host:hdf_devhost",
- "//drivers/adapter/uhdf2/host:hdf_devhost.rc",
"//drivers/adapter/uhdf2/host:libhdf_host",
"//drivers/adapter/uhdf2/host/test/unittest/sample_driver:libsample_driver",
"//drivers/adapter/uhdf2/ipc:libhdf_ipc_adapter",
"//drivers/adapter/uhdf2/manager:hdf_devmgr",
- "//drivers/adapter/uhdf2/manager:hdf_devmgr.rc",
+ "//drivers/adapter/uhdf2/manager:hdf_devmgr.cfg",
"//drivers/adapter/uhdf2/platform:libhdf_platform",
"//drivers/adapter/uhdf2/utils:libhdf_utils",
- "//drivers/peripheral/base:hdf_peripheral.rc",
+ "//drivers/framework/tools/hdf_dbg:hdf_dbg",
+ "//drivers/peripheral/base:hdf_peripheral.cfg",
]
}
group("uhdf_test_entry") {
diff --git a/OAT.xml b/OAT.xml
index 5cb0caf2b1abbc474945fb464e71e40ff2a20ace..4a9810f6848ddac8d935a0d7f818397cf7b4ee02 100644
--- a/OAT.xml
+++ b/OAT.xml
@@ -59,6 +59,9 @@ Note:If the text contains special characters, please escape them according to th
+
+
+
diff --git a/README.md b/README.md
index c4b773b7960fd68700e72ed007ea12bc8c0e2f8d..b3cce1881f2c8060832194c7f46dae6f1b12bca2 100644
--- a/README.md
+++ b/README.md
@@ -24,7 +24,7 @@ This repository stores the code and compilation scripts for the kerner or user-m
[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README.md)
-drivers\_adapter
+[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README.md)
[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README.md)
diff --git a/README_zh.md b/README_zh.md
index d70dade5d797d44b8acaa956bc2d77b427201d50..ebb4d89c413aeaada2038bf5dfadf1154e412cb7 100644
--- a/README_zh.md
+++ b/README_zh.md
@@ -24,7 +24,7 @@
[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README_zh.md)
-drivers\_adapter
+[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README_zh.md)
[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README_zh.md)
diff --git a/bundle.json b/bundle.json
old mode 100755
new mode 100644
diff --git a/khdf/liteos/Kconfig b/khdf/liteos/Kconfig
old mode 100755
new mode 100644
index 8b9bd8fe75dce2e124b227943af17d3783d9696f..4d179b07788312a6d8949f4f71887d8de24c9a83
--- a/khdf/liteos/Kconfig
+++ b/khdf/liteos/Kconfig
@@ -1,4 +1,4 @@
-# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
@@ -185,6 +185,13 @@ config DRIVERS_HDF_PLATFORM_WATCHDOG
depends on DRIVERS_HDF_PLATFORM
help
Answer Y to enable HDF platform watchdog driver.
+
+config DRIVERS_HDF_PLATFORM_TRACE
+ bool "Enable HDF platform trace driver"
+ default n
+ depends on DRIVERS_HDF_PLATFORM
+ help
+ Answer Y to enable HDF platform trace driver.
config DRIVERS_HDF_PLATFORM_TIMER
bool "Enable HDF platform timer driver"
@@ -193,6 +200,13 @@ config DRIVERS_HDF_PLATFORM_TIMER
help
Answer Y to enable HDF platform timer driver.
+config DRIVERS_HDF_PLATFORM_CAN
+ bool "Enable HDF platform can bus driver"
+ default n
+ depends on DRIVERS_HDF_PLATFORM
+ help
+ Answer Y to enable HDF platform can bus driver.
+
config DRIVERS_HIEDMAC
bool "Enable HIEDMAC"
default n
diff --git a/khdf/liteos/README.md b/khdf/liteos/README.md
index 5ec1664ef9a6673323a59bc3db76051fe083e5f0..c7b2f65f850d58dec884939432dd5b20d98301fa 100644
--- a/khdf/liteos/README.md
+++ b/khdf/liteos/README.md
@@ -31,8 +31,8 @@ This repository stores the code and compilation scripts for the OpenHarmony driv
[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README.md)
-[drivers\_adapter\_uhdf](https://gitee.com/openharmony/drivers_adapter_uhdf/blob/master/README.md)
+[drivers\_adapter\_uhdf](https://gitee.com/openharmony/drivers_adapter/blob/master/uhdf/README.md)
[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_uhdf/blob/master/README.md)
-drivers\_adapter\_khdf\_liteos
+[drivers\_adapter\_khdf\_liteos](https://gitee.com/openharmony/drivers_adapter/blob/master/khdf/liteos/README.md)
diff --git a/khdf/liteos/README_zh.md b/khdf/liteos/README_zh.md
index 3a6f45373f11801b0e1a42ca2f95451730cf6d00..357d7cf3c706b560113945f192c8fe0f5e644327 100644
--- a/khdf/liteos/README_zh.md
+++ b/khdf/liteos/README_zh.md
@@ -31,8 +31,8 @@
[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README_zh.md)
-[drivers\_adapter\_uhdf](https://gitee.com/openharmony/drivers_adapter_uhdf/blob/master/README_zh.md)
+[drivers\_adapter\_uhdf](https://gitee.com/openharmony/drivers_adapter/blob/master/uhdf/README_zh.md)
[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README_zh.md)
-drivers\_adapter\_khdf\_liteos
+[drivers\_adapter\_khdf\_liteos](https://gitee.com/openharmony/drivers_adapter/blob/master/khdf/liteos/README_zh.md)
diff --git a/khdf/liteos/hdf.gni b/khdf/liteos/hdf.gni
index 9acc618df15f116e827054098b55f7e74f133c62..c76eb7039763cd68f896ab8271dccc04520ae8a7 100644
--- a/khdf/liteos/hdf.gni
+++ b/khdf/liteos/hdf.gni
@@ -31,6 +31,7 @@ import("//kernel/liteos_a/liteos.gni")
HDF_FRAMEWORKS_PATH = "//drivers/framework"
HDF_PERIPHERAL_PATH = "//drivers/peripheral"
+HDF_ADAPTERS_PATH = "//drivers/adapter"
template("hdf_driver") {
if (defined(invoker.module_switch)) {
diff --git a/khdf/liteos/hdf_lite.mk b/khdf/liteos/hdf_lite.mk
old mode 100755
new mode 100644
index 7b203de96e3d325d8ae697fb9213974f045d075a..58f1bc10c4784e88ab3d67d73196ae8d0f5d995f
--- a/khdf/liteos/hdf_lite.mk
+++ b/khdf/liteos/hdf_lite.mk
@@ -172,6 +172,8 @@ endif
COMPANY_OF_SOC := $(patsubst "%",%,$(LOSCFG_DEVICE_COMPANY))
ifeq ($(COMPANY_OF_SOC), hisilicon)
-include $(LITEOSTOPDIR)/../../device/soc/$(COMPANY_OF_SOC)/common/platform/lite.mk
+else ifeq ($(COMPANY_OF_SOC), st)
+-include $(LITEOSTOPDIR)/../../device/soc/$(COMPANY_OF_SOC)/common/platform/lite.mk
else
-include $(LITEOSTOPDIR)/../../device/$(COMPANY_OF_SOC)/drivers/lite.mk
endif
diff --git a/khdf/liteos/manager/src/devmgr_pm_reg.c b/khdf/liteos/manager/src/devmgr_pm_reg.c
index 5ffd3a834b8a3ffa2c584b331d8cadd5142a53ca..c7d66a068163b8c82079da8a83c4a4781af718e4 100755
--- a/khdf/liteos/manager/src/devmgr_pm_reg.c
+++ b/khdf/liteos/manager/src/devmgr_pm_reg.c
@@ -38,7 +38,7 @@
UINT32 DevmgrPmSuspend(UINT32 mode)
{
if (mode != LOS_SYS_LIGHT_SLEEP) {
- HDF_LOGI("%s: hdf Suspend %d", __func__, mode);
+ HDF_LOGI("%s: hdf Suspend %u", __func__, mode);
}
HDF_LOGI("%s hdf suspend start", __func__);
diff --git a/khdf/liteos/model/audio/BUILD.gn b/khdf/liteos/model/audio/BUILD.gn
index 1aa7f9b0a904bcaa49902fe132e0e392d60015a5..b8e341b9801920cde04f110c65be8bfa03ff0da0 100644
--- a/khdf/liteos/model/audio/BUILD.gn
+++ b/khdf/liteos/model/audio/BUILD.gn
@@ -1,4 +1,4 @@
-# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+# Copyright (c) 2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
@@ -31,12 +31,11 @@ import("//drivers/adapter/khdf/liteos/hdf.gni")
module_switch = defined(LOSCFG_DRIVERS_HDF_AUDIO)
module_name = "hdf_audio_driver"
hdf_driver(module_name) {
- PERIPHERAL_ADUIO_ROOT = []
FRAMEWORKS_ADUIO_ROOT = "$HDF_FRAMEWORKS_PATH/model/audio"
- PERIPHERAL_ADUIO_ROOT = "$HDF_PERIPHERAL_PATH/audio"
+ PERIPHERAL_ADUIO_ROOT =
+ "//device/board/hisilicon/hispark_taurus/audio_drivers"
sources = [
- "$FRAMEWORKS_ADUIO_ROOT/common/src/audio_accessory_base.c",
"$FRAMEWORKS_ADUIO_ROOT/common/src/audio_codec_base.c",
"$FRAMEWORKS_ADUIO_ROOT/common/src/audio_dai_base.c",
"$FRAMEWORKS_ADUIO_ROOT/common/src/audio_dma_base.c",
@@ -69,32 +68,31 @@ hdf_driver(module_name) {
if (defined(LOSCFG_DRIVERS_HDF_AUDIO_CODEC_HI3516)) {
sources += [
- "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/codec/src/hi3516_codec_adapter.c",
- "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/codec/src/hi3516_codec_impl.c",
- "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/codec/src/hi3516_codec_ops.c",
- "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/dsp/src/dsp_adapter.c",
- "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/dsp/src/dsp_ops.c",
- "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/soc/src/hi3516_aiao_impl.c",
- "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/soc/src/hi3516_dai_adapter.c",
- "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/soc/src/hi3516_dai_ops.c",
- "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/soc/src/hi3516_dma_adapter.c",
- "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/soc/src/hi3516_dma_ops.c",
+ "$PERIPHERAL_ADUIO_ROOT/codec/hi3516/src/hi3516_codec_adapter.c",
+ "$PERIPHERAL_ADUIO_ROOT/codec/hi3516/src/hi3516_codec_impl.c",
+ "$PERIPHERAL_ADUIO_ROOT/codec/hi3516/src/hi3516_codec_ops.c",
+ "$PERIPHERAL_ADUIO_ROOT/dsp/src/dsp_adapter.c",
+ "$PERIPHERAL_ADUIO_ROOT/dsp/src/dsp_ops.c",
+ "$PERIPHERAL_ADUIO_ROOT/soc/src/hi3516_aiao_impl.c",
+ "$PERIPHERAL_ADUIO_ROOT/soc/src/hi3516_dai_adapter.c",
+ "$PERIPHERAL_ADUIO_ROOT/soc/src/hi3516_dai_ops.c",
+ "$PERIPHERAL_ADUIO_ROOT/soc/src/hi3516_dma_adapter.c",
+ "$PERIPHERAL_ADUIO_ROOT/soc/src/hi3516_dma_ops.c",
]
include_dirs += [
- "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/codec/include",
- "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/soc/include",
- "$PERIPHERAL_ADUIO_ROOT/chipsets/hi3516dv300/dsp/include",
+ "$PERIPHERAL_ADUIO_ROOT/codec/hi3516/include",
+ "$PERIPHERAL_ADUIO_ROOT/soc/include",
+ "$PERIPHERAL_ADUIO_ROOT/dsp/include",
]
}
if (defined(LOSCFG_DRIVERS_HDF_AUDIO_CODEC_TF9879)) {
sources += [
- "$PERIPHERAL_ADUIO_ROOT/chipsets/tfa9879/accessory/src/tfa9879_accessory_adapter.c",
- "$PERIPHERAL_ADUIO_ROOT/chipsets/tfa9879/accessory/src/tfa9879_accessory_impl.c",
+ "$PERIPHERAL_ADUIO_ROOT/codec/tfa9879/src/tfa9879_codec_adapter.c",
+ "$PERIPHERAL_ADUIO_ROOT/codec/tfa9879/src/tfa9879_codec_ops.c",
]
- include_dirs +=
- [ "$PERIPHERAL_ADUIO_ROOT/chipsets/tfa9879/accessory/include" ]
+ include_dirs += [ "$PERIPHERAL_ADUIO_ROOT/codec/tfa9879/include" ]
}
cflags = [
diff --git a/khdf/liteos/model/audio/Makefile b/khdf/liteos/model/audio/Makefile
index 482e942ddc9e7d6164719955320909ec2703f46c..edea03cb83332c8d04d26a0e92fe13e688e43f41 100644
--- a/khdf/liteos/model/audio/Makefile
+++ b/khdf/liteos/model/audio/Makefile
@@ -33,7 +33,7 @@ MODULE_NAME := hdf_audio_driver
KHDF_AUDIO_BASE_ROOT_DIR = $(LITEOSTOPDIR)/../../
KHDF_AUDIO_ROOT_DIR = $(KHDF_AUDIO_BASE_ROOT_DIR)/drivers/framework/model/audio
KHDF_FRAMEWORK_ROOT_DIR = $(KHDF_AUDIO_BASE_ROOT_DIR)/drivers/framework
-KHDF_AUDIO_HI3516DV300_DIR = $(KHDF_AUDIO_BASE_ROOT_DIR)/drivers/peripheral/audio/chipsets/hi3516dv300
+KHDF_AUDIO_HI3516DV300_DIR = $(KHDF_AUDIO_BASE_ROOT_DIR)/device/board/hisilicon/hispark_taurus/audio_drivers
LOCAL_INCLUDE := $(KHDF_AUDIO_BASE_ROOT_DIR)/third_party/bounds_checking_function/include \
$(KHDF_AUDIO_KHDF_ROOT_DIR)/osal/include \
@@ -47,8 +47,8 @@ LOCAL_INCLUDE := $(KHDF_AUDIO_BASE_ROOT_DIR)/third_party/bounds_checking_functio
$(KHDF_FRAMEWORK_ROOT_DIR)/model/audio/sapm/include \
$(KHDF_FRAMEWORK_ROOT_DIR)/model/audio/dispatch/include \
$(KHDF_FRAMEWORK_ROOT_DIR)/model/audio/common/include \
- $(KHDF_AUDIO_HI3516DV300_DIR)/../tfa9879/accessory/include \
- $(KHDF_AUDIO_HI3516DV300_DIR)/codec/include \
+ $(KHDF_AUDIO_HI3516DV300_DIR)/codec/tfa9879/include \
+ $(KHDF_AUDIO_HI3516DV300_DIR)/codec/hi3516/include \
$(KHDF_AUDIO_HI3516DV300_DIR)/soc/include \
$(KHDF_AUDIO_HI3516DV300_DIR)/dsp/include \
$(LITEOSTOPDIR)/kernel/base/include
@@ -56,7 +56,6 @@ LOCAL_INCLUDE := $(KHDF_AUDIO_BASE_ROOT_DIR)/third_party/bounds_checking_functio
LOCAL_SRCS += $(KHDF_AUDIO_ROOT_DIR)/core/src/audio_core.c \
$(KHDF_AUDIO_ROOT_DIR)/core/src/audio_host.c \
$(KHDF_AUDIO_ROOT_DIR)/core/src/audio_parse.c \
- $(KHDF_AUDIO_ROOT_DIR)/common/src/audio_accessory_base.c \
$(KHDF_AUDIO_ROOT_DIR)/common/src/audio_codec_base.c \
$(KHDF_AUDIO_ROOT_DIR)/common/src/audio_platform_base.c \
$(KHDF_AUDIO_ROOT_DIR)/common/src/audio_dsp_base.c \
@@ -65,11 +64,11 @@ LOCAL_SRCS += $(KHDF_AUDIO_ROOT_DIR)/core/src/audio_core.c \
$(KHDF_AUDIO_ROOT_DIR)/sapm/src/audio_sapm.c \
$(KHDF_AUDIO_ROOT_DIR)/dispatch/src/audio_stream_dispatch.c \
$(KHDF_AUDIO_ROOT_DIR)/dispatch/src/audio_control_dispatch.c \
- $(KHDF_AUDIO_HI3516DV300_DIR)/../tfa9879/accessory/src/tfa9879_accessory_adapter.c \
- $(KHDF_AUDIO_HI3516DV300_DIR)/../tfa9879/accessory/src/tfa9879_accessory_impl.c \
- $(KHDF_AUDIO_HI3516DV300_DIR)/codec/src/hi3516_codec_adapter.c \
- $(KHDF_AUDIO_HI3516DV300_DIR)/codec/src/hi3516_codec_impl.c \
- $(KHDF_AUDIO_HI3516DV300_DIR)/codec/src/hi3516_codec_ops.c \
+ $(KHDF_AUDIO_HI3516DV300_DIR)/codec/tfa9879/src/tfa9879_codec_adapter.c \
+ $(KHDF_AUDIO_HI3516DV300_DIR)/codec/tfa9879/src/tfa9879_codec_ops.c \
+ $(KHDF_AUDIO_HI3516DV300_DIR)/codec/hi3516/src/hi3516_codec_adapter.c \
+ $(KHDF_AUDIO_HI3516DV300_DIR)/codec/hi3516/src/hi3516_codec_impl.c \
+ $(KHDF_AUDIO_HI3516DV300_DIR)/codec/hi3516/src/hi3516_codec_ops.c \
$(KHDF_AUDIO_HI3516DV300_DIR)/dsp/src/dsp_adapter.c \
$(KHDF_AUDIO_HI3516DV300_DIR)/dsp/src/dsp_ops.c \
$(KHDF_AUDIO_HI3516DV300_DIR)/soc/src/hi3516_dai_adapter.c \
@@ -79,4 +78,4 @@ LOCAL_SRCS += $(KHDF_AUDIO_ROOT_DIR)/core/src/audio_core.c \
$(KHDF_AUDIO_HI3516DV300_DIR)/soc/src/hi3516_dma_adapter.c
LOCAL_CFLAGS += -Wno-error
-include $(HDF_DRIVER)
\ No newline at end of file
+include $(HDF_DRIVER)
diff --git a/khdf/liteos/model/bus/usb/Kconfig b/khdf/liteos/model/bus/usb/Kconfig
old mode 100755
new mode 100644
diff --git a/khdf/liteos/model/bus/usb/Makefile b/khdf/liteos/model/bus/usb/Makefile
old mode 100755
new mode 100644
diff --git a/khdf/liteos/model/bus/usb/include/hdf_usb.h b/khdf/liteos/model/bus/usb/include/hdf_usb.h
index 04973655a33b912f352fe04ffca22e3d902008cb..b8e60441b369107798d5dd5d6382bf118cb65a68 100644
--- a/khdf/liteos/model/bus/usb/include/hdf_usb.h
+++ b/khdf/liteos/model/bus/usb/include/hdf_usb.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2021-2022 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
diff --git a/khdf/liteos/model/display/Kconfig b/khdf/liteos/model/display/Kconfig
old mode 100755
new mode 100644
diff --git a/khdf/liteos/model/display/Makefile b/khdf/liteos/model/display/Makefile
old mode 100755
new mode 100644
diff --git a/khdf/liteos/model/input/Kconfig b/khdf/liteos/model/input/Kconfig
old mode 100755
new mode 100644
diff --git a/khdf/liteos/model/input/Makefile b/khdf/liteos/model/input/Makefile
old mode 100755
new mode 100644
diff --git a/khdf/liteos/model/misc/dsoftbus/BUILD.gn b/khdf/liteos/model/misc/dsoftbus/BUILD.gn
index 314ac7ac4cd727da09673cb99adf24aacd8710be..6c5cb8712d179b4a8387062032c7ebaa8daf2626 100644
--- a/khdf/liteos/model/misc/dsoftbus/BUILD.gn
+++ b/khdf/liteos/model/misc/dsoftbus/BUILD.gn
@@ -48,7 +48,6 @@ hdf_driver(module_name) {
include_dirs += [
"include",
"//kernel/liteos_a/net/lwip-2.1/porting/include",
- "//third_party/lwip/src/include/lwip",
]
cflags += [ "-DENABLE_LWIP_MONITOR" ]
}
diff --git a/khdf/liteos/model/misc/dsoftbus/src/softbus_lwip_monitor.c b/khdf/liteos/model/misc/dsoftbus/src/softbus_lwip_monitor.c
index 807d9d4f8f7db266f61810dbaf7ccb91927ecdd8..9330256d25eb1e87cb69a10abab63f7614aa0055 100644
--- a/khdf/liteos/model/misc/dsoftbus/src/softbus_lwip_monitor.c
+++ b/khdf/liteos/model/misc/dsoftbus/src/softbus_lwip_monitor.c
@@ -56,7 +56,7 @@ typedef struct {
static void ReportEvent(const LwipMonitorReportInfo *reportInfo)
{
- struct HdfSBuf *data = data = HdfSbufObtainDefaultSize();
+ struct HdfSBuf *data = HdfSbufObtainDefaultSize();
if (data == NULL) {
dprintf("get sbuf fail\n");
@@ -77,9 +77,8 @@ static void NetifStatusCallback(struct netif *netif, netif_nsc_reason_t reason,
LwipMonitorReportInfo reportInfo;
bool needReport = true;
- (void)args;
- if (netif == NULL) {
- dprintf("NetifStatusCallback: input netif is NULL\n");
+ if (netif == NULL || args == NULL) {
+ dprintf("NetifStatusCallback: input args is NULL\n");
return;
}
dprintf("NetifStatusCallback(%s): nsc event: 0x%x\n", netif->full_name, (uint32_t)reason);
diff --git a/khdf/liteos/model/misc/vibrator/BUILD.gn b/khdf/liteos/model/misc/vibrator/BUILD.gn
index 3a5b13ba1bf9f90738efb6bd7980476ee94a2b61..6b0a52c8f3405c7abbeee6c4f482092d38810ed9 100644
--- a/khdf/liteos/model/misc/vibrator/BUILD.gn
+++ b/khdf/liteos/model/misc/vibrator/BUILD.gn
@@ -1,4 +1,4 @@
-# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
@@ -32,6 +32,7 @@ module_switch = defined(LOSCFG_DRIVERS_HDF_VIBRATOR)
module_name = "hdf_vibrator_driver"
hdf_driver(module_name) {
FRAMEWORKS_VIBRATOR_ROOT = "$HDF_FRAMEWORKS_PATH/model/misc/vibrator/driver"
+ PERIPHERAL_VIBRATOR_ROOT = "$HDF_PERIPHERAL_PATH/misc/vibrator"
sources = [
"$FRAMEWORKS_VIBRATOR_ROOT/src/vibrator_driver.c",
@@ -39,11 +40,11 @@ hdf_driver(module_name) {
]
if (defined(LOSCFG_DRIVERS_HDF_VIBRATOR_LINEAR)) {
- sources += [ "$FRAMEWORKS_VIBRATOR_ROOT/chipset/vibrator_linear_driver.c" ]
+ sources += [ "$PERIPHERAL_VIBRATOR_ROOT/chipset/vibrator_linear_driver.c" ]
}
include_dirs = [
"$FRAMEWORKS_VIBRATOR_ROOT/include",
- "$FRAMEWORKS_VIBRATOR_ROOT/chipset",
+ "$PERIPHERAL_VIBRATOR_ROOT/chipset",
]
}
diff --git a/khdf/liteos/model/misc/vibrator/Makefile b/khdf/liteos/model/misc/vibrator/Makefile
index ebc67f6f81f96ee3c954df58398aaefde353dce0..66cb379cc066ab78806539bbd2c7b09f57508fbf 100644
--- a/khdf/liteos/model/misc/vibrator/Makefile
+++ b/khdf/liteos/model/misc/vibrator/Makefile
@@ -1,4 +1,4 @@
-# Copyright (c) 2021 Huawei Device Co., Ltd. All rights reserved.
+# Copyright (c) 2022 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
@@ -31,15 +31,16 @@ include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk
MODULE_NAME := hdf_vibrator_driver
FRAMEWORKS_VIBRATOR_ROOT = $(LITEOSTOPDIR)/../../drivers/framework/model/misc/vibrator/driver
+PERIPHERAL_VIBRATOR_ROOT = $(LITEOSTOPDIR)/../../drivers/peripheral/misc/vibrator
LOCAL_INCLUDE := $(FRAMEWORKS_VIBRATOR_ROOT)/include \
- $(FRAMEWORKS_VIBRATOR_ROOT)/chipset
+ $(PERIPHERAL_VIBRATOR_ROOT)/chipset
LOCAL_SRCS += $(FRAMEWORKS_VIBRATOR_ROOT)/src/vibrator_driver.c \
$(FRAMEWORKS_VIBRATOR_ROOT)/src/vibrator_haptic.c
ifeq ($(LOSCFG_DRIVERS_HDF_VIBRATOR_LINEAR), y)
-LOCAL_SRCS += $(FRAMEWORKS_VIBRATOR_ROOT)/chipset/vibrator_linear_driver.c
+LOCAL_SRCS += $(PERIPHERAL_VIBRATOR_ROOT)/chipset/vibrator_linear_driver.c
endif
include $(HDF_DRIVER)
diff --git a/khdf/liteos/model/network/ethernet/BUILD.gn b/khdf/liteos/model/network/ethernet/BUILD.gn
old mode 100755
new mode 100644
diff --git a/khdf/liteos/model/network/ethernet/Kconfig b/khdf/liteos/model/network/ethernet/Kconfig
old mode 100755
new mode 100644
diff --git a/khdf/liteos/model/network/ethernet/Makefile b/khdf/liteos/model/network/ethernet/Makefile
old mode 100755
new mode 100644
diff --git a/khdf/liteos/model/network/wifi/BUILD.gn b/khdf/liteos/model/network/wifi/BUILD.gn
index e2ba840da0fda410091cd8d91a808e322855e50e..d1043f88161b1375561278d4b5adabb2da507493 100644
--- a/khdf/liteos/model/network/wifi/BUILD.gn
+++ b/khdf/liteos/model/network/wifi/BUILD.gn
@@ -69,6 +69,7 @@ hdf_driver(module_name) {
"$FRAMEWORKS_WIFI_ROOT/core/components/eapol",
"$FRAMEWORKS_WIFI_ROOT/core/components/p2p",
"$FRAMEWORKS_WIFI_ROOT/../common/netdevice",
+ "$FRAMEWORKS_WIFI_ROOT/core",
"$FRAMEWORKS_WIFI_ROOT/core/module",
"$HDF_FRAMEWORKS_PATH/include/wifi",
"$FRAMEWORKS_WIFI_ROOT/bus",
diff --git a/khdf/liteos/model/network/wifi/Makefile b/khdf/liteos/model/network/wifi/Makefile
old mode 100755
new mode 100644
index 56903df2d9ac661e8e426f3aa445bb1f510b12ee..02f8cdab54f74f0910e8769e809d28288e912314
--- a/khdf/liteos/model/network/wifi/Makefile
+++ b/khdf/liteos/model/network/wifi/Makefile
@@ -58,6 +58,7 @@ WIFI_CFLAGS += -I $(INC_PATH) \
-I $(NETDEV_PATH) \
-I $(MODULE_PATH) \
-I $(INC_WIFI_PATH) \
+ -I $(HDM_WIFI_ROOT)/core \
-I $(IBUS_PATH)
diff --git a/khdf/liteos/model/network/wifi/platform/src/hdf_wlan_queue.c b/khdf/liteos/model/network/wifi/platform/src/hdf_wlan_queue.c
index 153f9465158e2a1f9822baa0a2a9877e2d00a111..f3834015c3069037330c6dd7f98b0327f35e84b2 100644
--- a/khdf/liteos/model/network/wifi/platform/src/hdf_wlan_queue.c
+++ b/khdf/liteos/model/network/wifi/platform/src/hdf_wlan_queue.c
@@ -61,7 +61,7 @@ void DestroyQueue(HdfWlanQueue *queue)
HdfWlanQueueImpl *queueImpl = (HdfWlanQueueImpl *)queue;
uint32_t status = LOS_QueueDelete(queueImpl->queueID);
if (status != LOS_OK) {
- HDF_LOGE("Destroy message queue failed!err=%d", status);
+ HDF_LOGE("Destroy message queue failed!err=%u", status);
}
OsalMemFree(queue);
}
@@ -93,7 +93,7 @@ int32_t PushQueue(HdfWlanQueue *queue, void *context)
uint32_t ret = LOS_QueueWriteCopy(queueImpl->queueID, &context, sizeof(void *), LOS_WAIT_FOREVER);
if (ret != LOS_OK) {
- HDF_LOGE("%s:Write queue failed!ret=%d", __func__, ret);
+ HDF_LOGE("%s:Write queue failed!ret=%u", __func__, ret);
return HDF_FAILURE;
}
return HDF_SUCCESS;
diff --git a/khdf/liteos/model/sensor/BUILD.gn b/khdf/liteos/model/sensor/BUILD.gn
index f7e8a7babdd50d58e27855b7da58538aae015cd1..233039f5b7860174080a3293a23dff995cb97aee 100644
--- a/khdf/liteos/model/sensor/BUILD.gn
+++ b/khdf/liteos/model/sensor/BUILD.gn
@@ -1,4 +1,4 @@
-# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
@@ -32,6 +32,7 @@ module_switch = defined(LOSCFG_DRIVERS_HDF_SENSOR)
module_name = "hdf_sensor_driver"
hdf_driver(module_name) {
FRAMEWORKS_SENSOR_ROOT = "$HDF_FRAMEWORKS_PATH/model/sensor/driver"
+ PERIPHERAL_SENSOR_ROOT = "$HDF_PERIPHERAL_PATH/sensor"
sources = [
"$FRAMEWORKS_SENSOR_ROOT/common/src/sensor_config_controller.c",
"$FRAMEWORKS_SENSOR_ROOT/common/src/sensor_config_parser.c",
@@ -43,14 +44,14 @@ hdf_driver(module_name) {
sources += [ "$FRAMEWORKS_SENSOR_ROOT/accel/sensor_accel_driver.c" ]
}
if (defined(LOSCFG_DRIVERS_HDF_SENSOR_ACCEL_BMI160)) {
- sources += [ "$FRAMEWORKS_SENSOR_ROOT/chipset/accel/accel_bmi160.c" ]
+ sources += [ "$PERIPHERAL_SENSOR_ROOT/chipset/accel/accel_bmi160.c" ]
}
if (defined(LOSCFG_DRIVERS_HDF_SENSOR_ALS)) {
sources += [ "$FRAMEWORKS_SENSOR_ROOT/als/sensor_als_driver.c" ]
}
if (defined(LOSCFG_DRIVERS_HDF_SENSOR_ALS_BH1745)) {
- sources += [ "$FRAMEWORKS_SENSOR_ROOT/chipset/als/als_bh1745.c" ]
+ sources += [ "$PERIPHERAL_SENSOR_ROOT/chipset/als/als_bh1745.c" ]
}
if (defined(LOSCFG_DRIVERS_HDF_SENSOR_BAROMETER)) {
@@ -58,20 +59,20 @@ hdf_driver(module_name) {
}
if (defined(LOSCFG_DRIVERS_HDF_SENSOR_BAROMETER_BMP180)) {
sources +=
- [ "$FRAMEWORKS_SENSOR_ROOT/chipset/barometer/barometer_bmp180.c" ]
+ [ "$PERIPHERAL_SENSOR_ROOT/chipset/barometer/barometer_bmp180.c" ]
}
if (defined(LOSCFG_DRIVERS_HDF_SENSOR_PROXIMITY)) {
sources += [ "$FRAMEWORKS_SENSOR_ROOT/proximity/sensor_proximity_driver.c" ]
}
if (defined(LOSCFG_DRIVERS_HDF_SENSOR_PROXIMITY_APDS9960)) {
sources +=
- [ "$FRAMEWORKS_SENSOR_ROOT/chipset/proximity/proximity_apds9960.c" ]
+ [ "$PERIPHERAL_SENSOR_ROOT/chipset/proximity/proximity_apds9960.c" ]
}
if (defined(LOSCFG_DRIVERS_HDF_SENSOR_GYRO)) {
sources += [
- "$FRAMEWORKS_SENSOR_ROOT/chipset/gyro/gyro_bmi160.c",
"$FRAMEWORKS_SENSOR_ROOT/gyro/sensor_gyro_driver.c",
+ "$PERIPHERAL_SENSOR_ROOT/chipset/gyro/gyro_bmi160.c",
]
}
@@ -79,14 +80,14 @@ hdf_driver(module_name) {
sources += [ "$FRAMEWORKS_SENSOR_ROOT/hall/sensor_hall_driver.c" ]
}
if (defined(LOSCFG_DRIVERS_HDF_SENSOR_HALL_AK8789)) {
- sources += [ "$FRAMEWORKS_SENSOR_ROOT/chipset/hall/hall_ak8789.c" ]
+ sources += [ "$PERIPHERAL_SENSOR_ROOT/chipset/hall/hall_ak8789.c" ]
}
if (defined(LOSCFG_DRIVERS_HDF_SENSOR_MAGNETIC)) {
sources += [ "$FRAMEWORKS_SENSOR_ROOT/magnetic/sensor_magnetic_driver.c" ]
}
if (defined(LOSCFG_DRIVERS_HDF_SENSOR_MAGNETIC_LSM303)) {
- sources += [ "$FRAMEWORKS_SENSOR_ROOT/chipset/magnetic/magnetic_lsm303.c" ]
+ sources += [ "$PERIPHERAL_SENSOR_ROOT/chipset/magnetic/magnetic_lsm303.c" ]
}
if (defined(LOSCFG_DRIVERS_HDF_SENSOR_GRAVITY)) {
@@ -97,18 +98,18 @@ hdf_driver(module_name) {
"$FRAMEWORKS_SENSOR_ROOT/include",
"$FRAMEWORKS_SENSOR_ROOT/common/include",
"$FRAMEWORKS_SENSOR_ROOT/accel",
- "$FRAMEWORKS_SENSOR_ROOT/chipset/accel",
+ "$PERIPHERAL_SENSOR_ROOT/chipset/accel",
"$FRAMEWORKS_SENSOR_ROOT/als",
- "$FRAMEWORKS_SENSOR_ROOT/chipset/als",
+ "$PERIPHERAL_SENSOR_ROOT/chipset/als",
"$FRAMEWORKS_SENSOR_ROOT/barometer",
- "$FRAMEWORKS_SENSOR_ROOT/chipset/barometer",
+ "$PERIPHERAL_SENSOR_ROOT/chipset/barometer",
"$FRAMEWORKS_SENSOR_ROOT/gyro",
- "$FRAMEWORKS_SENSOR_ROOT/chipset/gyro",
+ "$PERIPHERAL_SENSOR_ROOT/chipset/gyro",
"$FRAMEWORKS_SENSOR_ROOT/hall",
- "$FRAMEWORKS_SENSOR_ROOT/chipset/hall",
+ "$PERIPHERAL_SENSOR_ROOT/chipset/hall",
"$FRAMEWORKS_SENSOR_ROOT/magnetic",
- "$FRAMEWORKS_SENSOR_ROOT/chipset/magnetic",
+ "$PERIPHERAL_SENSOR_ROOT/chipset/magnetic",
"$FRAMEWORKS_SENSOR_ROOT/proximity",
- "$FRAMEWORKS_SENSOR_ROOT/chipset/proximity",
+ "$PERIPHERAL_SENSOR_ROOT/chipset/proximity",
]
}
diff --git a/khdf/liteos/model/sensor/Kconfig b/khdf/liteos/model/sensor/Kconfig
old mode 100755
new mode 100644
diff --git a/khdf/liteos/model/sensor/Makefile b/khdf/liteos/model/sensor/Makefile
index 220b48514b2b9c44b53ca15f2cbdff485d9a1189..f604529a9d38249c2f55d18239006ee143781cd9 100644
--- a/khdf/liteos/model/sensor/Makefile
+++ b/khdf/liteos/model/sensor/Makefile
@@ -1,4 +1,4 @@
-# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
@@ -31,21 +31,22 @@ include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk
MODULE_NAME := hdf_sensor_driver
FRAMEWORKS_SENSOR_ROOT = $(LITEOSTOPDIR)/../../drivers/framework/model/sensor/driver
+PERIPHERAL_SENSOR_ROOT = $(LITEOSTOPDIR)/../../drivers/peripheral/sensor
LOCAL_INCLUDE := $(FRAMEWORKS_SENSOR_ROOT)/include \
$(FRAMEWORKS_SENSOR_ROOT)/common/include \
$(FRAMEWORKS_SENSOR_ROOT)/accel \
- $(FRAMEWORKS_SENSOR_ROOT)/chipset/accel \
+ $(PERIPHERAL_SENSOR_ROOT)/chipset/accel \
$(FRAMEWORKS_SENSOR_ROOT)/als \
- $(FRAMEWORKS_SENSOR_ROOT)/chipset/als \
+ $(PERIPHERAL_SENSOR_ROOT)/chipset/als \
$(FRAMEWORKS_SENSOR_ROOT)/barometer \
- $(FRAMEWORKS_SENSOR_ROOT)/chipset/barometer \
+ $(PERIPHERAL_SENSOR_ROOT)/chipset/barometer \
$(FRAMEWORKS_SENSOR_ROOT)/hall \
- $(FRAMEWORKS_SENSOR_ROOT)/chipset/hall \
+ $(PERIPHERAL_SENSOR_ROOT)/chipset/hall \
$(FRAMEWORKS_SENSOR_ROOT)/magnetic \
- $(FRAMEWORKS_SENSOR_ROOT)/chipset/magnetic \
+ $(PERIPHERAL_SENSOR_ROOT)/chipset/magnetic \
$(FRAMEWORKS_SENSOR_ROOT)/proximity \
- $(FRAMEWORKS_SENSOR_ROOT)/chipset/proximity
+ $(PERIPHERAL_SENSOR_ROOT)/chipset/proximity
LOCAL_SRCS += $(FRAMEWORKS_SENSOR_ROOT)/common/src/sensor_config_controller.c \
$(FRAMEWORKS_SENSOR_ROOT)/common/src/sensor_config_parser.c \
@@ -54,32 +55,32 @@ LOCAL_SRCS += $(FRAMEWORKS_SENSOR_ROOT)/common/src/sensor_config_controller.c \
ifeq ($(LOSCFG_DRIVERS_HDF_SENSOR_ACCEL), y)
LOCAL_SRCS += $(FRAMEWORKS_SENSOR_ROOT)/accel/sensor_accel_driver.c \
- $(FRAMEWORKS_SENSOR_ROOT)/chipset/accel/accel_bmi160.c
+ $(PERIPHERAL_SENSOR_ROOT)/chipset/accel/accel_bmi160.c
endif
ifeq ($(LOSCFG_DRIVERS_HDF_SENSOR_ALS), y)
LOCAL_SRCS += $(FRAMEWORKS_SENSOR_ROOT)/als/sensor_als_driver.c \
- $(FRAMEWORKS_SENSOR_ROOT)/chipset/als/als_bh1745.c
+ $(PERIPHERAL_SENSOR_ROOT)/chipset/als/als_bh1745.c
endif
ifeq ($(LOSCFG_DRIVERS_HDF_SENSOR_BAROMETER), y)
LOCAL_SRCS += $(FRAMEWORKS_SENSOR_ROOT)/barometer/sensor_barometer_driver.c \
- $(FRAMEWORKS_SENSOR_ROOT)/chipset/barometer/barometer_bmp180.c
+ $(PERIPHERAL_SENSOR_ROOT)/chipset/barometer/barometer_bmp180.c
endif
ifeq ($(LOSCFG_DRIVERS_HDF_SENSOR_HALL), y)
LOCAL_SRCS += $(FRAMEWORKS_SENSOR_ROOT)/hall/sensor_hall_driver.c \
- $(FRAMEWORKS_SENSOR_ROOT)/chipset/hall/hall_ak8789.c
+ $(PERIPHERAL_SENSOR_ROOT)/chipset/hall/hall_ak8789.c
endif
ifeq ($(LOSCFG_DRIVERS_HDF_SENSOR_MAGNETIC), y)
LOCAL_SRCS += $(FRAMEWORKS_SENSOR_ROOT)/magnetic/sensor_magnetic_driver.c \
- $(FRAMEWORKS_SENSOR_ROOT)/chipset/magnetic/magnetic_lsm303.c
+ $(PERIPHERAL_SENSOR_ROOT)/chipset/magnetic/magnetic_lsm303.c
endif
ifeq ($(LOSCFG_DRIVERS_HDF_SENSOR_PROXIMITY), y)
LOCAL_SRCS += $(FRAMEWORKS_SENSOR_ROOT)/proximity/sensor_proximity_driver.c \
- $(FRAMEWORKS_SENSOR_ROOT)/chipset/proximity/proximity_apds9960.c
+ $(PERIPHERAL_SENSOR_ROOT)/chipset/proximity/proximity_apds9960.c
endif
ifeq ($(LOSCFG_DRIVERS_HDF_SENSOR_GRAVITY), y)
diff --git a/khdf/liteos/model/storage/src/mmc/mmc_block_lite.c b/khdf/liteos/model/storage/src/mmc/mmc_block_lite.c
index f986201bd35b696ac715448df3c70cbd99862055..95ce058aab95edbafd5451136ed6a5e5955222c1 100644
--- a/khdf/liteos/model/storage/src/mmc/mmc_block_lite.c
+++ b/khdf/liteos/model/storage/src/mmc/mmc_block_lite.c
@@ -91,8 +91,15 @@ static int LiteosBlockClose(FAR struct Vnode *vnode)
static ssize_t LiteosBlockRead(FAR struct Vnode *vnode, FAR unsigned char *buf,
unsigned long long secStart, unsigned int nSecs)
{
- size_t max = (size_t)(-1);
- struct MmcBlock *mb = (struct MmcBlock *)((struct drv_data*)vnode->data)->priv;
+ size_t max;
+ struct MmcBlock *mb = NULL;
+
+ if (vnode == NULL || vnode->data == NULL) {
+ HDF_LOGE("%s: vnode is NULL or data of vnode is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ max = (size_t)(-1);
+ mb = (struct MmcBlock *)((struct drv_data*)vnode->data)->priv;
if (secStart >= max || nSecs >= max) {
return HDF_ERR_INVALID_PARAM;
@@ -108,8 +115,15 @@ static ssize_t LiteosBlockRead(FAR struct Vnode *vnode, FAR unsigned char *buf,
static ssize_t LiteosBlockWrite(FAR struct Vnode *vnode, FAR const unsigned char *buf,
unsigned long long secStart, unsigned int nSecs)
{
- size_t max = (size_t)(-1);
- struct MmcBlock *mb = (struct MmcBlock *)((struct drv_data*)vnode->data)->priv;
+ size_t max;
+ struct MmcBlock *mb = NULL;
+
+ if (vnode == NULL || vnode->data == NULL) {
+ HDF_LOGE("%s: vnode is NULL or data of vnode is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ max = (size_t)(-1);
+ mb = (struct MmcBlock *)((struct drv_data*)vnode->data)->priv;
if (secStart >= max || nSecs >= max) {
return HDF_ERR_INVALID_PARAM;
@@ -124,8 +138,13 @@ static ssize_t LiteosBlockWrite(FAR struct Vnode *vnode, FAR const unsigned char
static int LiteosBlockGeometry(FAR struct Vnode *vnode, FAR struct geometry *geometry)
{
- struct MmcBlock *mb = (struct MmcBlock *)((struct drv_data*)vnode->data)->priv;
+ struct MmcBlock *mb = NULL;
+ if (vnode == NULL || vnode->data == NULL) {
+ HDF_LOGE("%s: vnode is NULL or data of vnode is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ mb = (struct MmcBlock *)((struct drv_data*)vnode->data)->priv;
if (mb == NULL) {
return HDF_ERR_INVALID_OBJECT;
}
@@ -146,6 +165,11 @@ static int32_t LiteosBlockSaveGeometry(FAR struct Vnode *vnode, unsigned long ar
struct geometry gm;
struct RtDeviceBlkGeometry rtGeo = {0};
+ if (vnode == NULL || vnode->data == NULL) {
+ HDF_LOGE("%s: vnode is NULL or data of vnode is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
ret = LiteosBlockGeometry(vnode, &gm);
if (ret != HDF_SUCCESS) {
return ret;
@@ -190,6 +214,11 @@ static int32_t LiteosBlockIoctl(FAR struct Vnode *vnode, int cmd, unsigned long
uint32_t auSize;
struct MmcBlock *mb = NULL;
+ if (vnode == NULL || vnode->data == NULL) {
+ HDF_LOGE("%s: vnode is NULL or data of vnode is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
mb = (struct MmcBlock *)((struct drv_data*)vnode->data)->priv;
switch (cmd) {
@@ -263,7 +292,7 @@ int32_t MmcBlockOsInit(struct MmcDevice *mmcDevice)
}
diskId = los_alloc_diskid_byname(mb->name);
- if (!mb->removeable) {
+ if (!mb->removable) {
info = &g_emmcInfo;
info->sector_count = mb->capacity;
}
diff --git a/khdf/liteos/model/storage/src/mtd/mtd_char_lite.c b/khdf/liteos/model/storage/src/mtd/mtd_char_lite.c
index e8fadcc937a1c64fc520e31b9093b1dac7c8cc3f..df9ed3e4d9618432af4f742ffb06cb1fd580de1c 100644
--- a/khdf/liteos/model/storage/src/mtd/mtd_char_lite.c
+++ b/khdf/liteos/model/storage/src/mtd/mtd_char_lite.c
@@ -54,8 +54,18 @@ struct MtdFileInfo {
*/
static int MtdCharOpen(FAR struct file *filep)
{
- struct drv_data *drv = (struct drv_data *)filep->f_vnode->data;
+ struct drv_data *drv = NULL;
+
+ if (filep == NULL || filep->f_vnode == NULL || filep->f_vnode->data == NULL) {
+ HDF_LOGE("%s: filep is NULL or f_vnode of filep is NULL or data of f_vnode is NULL", __func__);
+ return -EINVAL;
+ }
+ drv = (struct drv_data *)filep->f_vnode->data;
mtd_partition *partition = (mtd_partition *)drv->priv;
+ if (partition == NULL) {
+ HDF_LOGE("%s: partition is NULL", __func__);
+ return -EINVAL;
+ }
struct MtdFileInfo *mfi = NULL;
if (partition->user_num != 0) { // be opened
@@ -117,6 +127,11 @@ static ssize_t MtdCharRead(FAR struct file *filep, FAR char *buffer, size_t bufl
size_t partSize = (partition->end_block + 1 - partition->start_block) * blockSize;
size_t partOobSize = (partSize >> mtdDevice->writeSizeShift) * mtdDevice->oobSize;
+ if (buffer == NULL) {
+ HDF_LOGE("%s: buffer is NULL", __func__);
+ return -EINVAL;
+ }
+
(void)LOS_MuxLock(&partition->lock, LOS_WAIT_FOREVER);
if (ppos < 0 || ppos > partSize) {
PRINTK("%s: current file offset:0x%x invalid\n", __func__, ppos);
@@ -172,6 +187,10 @@ static ssize_t MtdCharWrite(FAR struct file *filep, FAR const char *buffer, size
size_t partSize = (partition->end_block + 1 - partition->start_block) * blockSize;
size_t partOobSize = (partSize >> mtdDevice->writeSizeShift) * mtdDevice->oobSize;
+ if (buffer == NULL) {
+ HDF_LOGE("%s: buffer is NULL", __func__);
+ return -EINVAL;
+ }
(void)LOS_MuxLock(&partition->lock, LOS_WAIT_FOREVER);
if (ppos < 0 || ppos > partSize) {
@@ -282,8 +301,7 @@ static int MtdCharIoctlGetInfo(const mtd_partition *part, const struct MtdDevice
size_t endAddr;
(void)cmd;
-
- MtdCharGetMtdInfo(mtdDevice, &mtdInfo);
+ MtdCharGetMtdInfo(mtdDevice, &mtdInfo);
startAddr = part->start_block * mtdDevice->eraseSize;
endAddr = (part->end_block + 1) * mtdDevice->eraseSize;
ret = LOS_CopyFromKernel((void *)(uintptr_t)arg, sizeof(mtdInfo), (void *)&mtdInfo, sizeof(mtdInfo));
@@ -356,21 +374,30 @@ static int MtdCharIoctl(FAR struct file *filep, int cmd, unsigned long arg)
struct MtdDev *mtdDev = (struct MtdDev *)(partition->mtd_info);
struct MtdDevice *mtdDevice = (struct MtdDevice *)mtdDev->priv;
+ if (mtdDevice == NULL || arg == 0) {
+ HDF_LOGE("%s: mtdDevice is NULL or arg is 0", __func__);
+ return -EINVAL;
+ }
+
(void)LOS_MuxLock(&partition->lock, LOS_WAIT_FOREVER);
switch (cmd) {
case MTD_IOC_GETINFO: {
ret = MtdCharIoctlGetInfo(partition, mtdDevice, cmd, arg);
+ break;
}
case MTD_IOC_ERASE:
case MTD_IOC_ERASE64: {
ret = MtdCharIoctlErase(partition, mtdDevice, cmd, arg);
+ break;
}
case MTD_IOC_GETBADBLOCK: {
ret = MtdCharIoctlGetBadBlock(partition, mtdDevice, cmd, arg);
+ break;
}
case MTD_IOC_SETBADBLOCK: {
ret = MtdCharIoctlSetBadBlock(partition, mtdDevice, cmd, arg);
+ break;
}
case MTD_IOC_SETFILEMODE:
mfi->mode = 0;
@@ -392,6 +419,9 @@ static int MtdCharIoctl(FAR struct file *filep, int cmd, unsigned long arg)
static ssize_t MtdCharMap(FAR struct file* filep, FAR LosVmMapRegion *region)
{
+ (void)filep;
+ (void)region;
+
PRINTK("%s %d, mmap is not support\n", __FUNCTION__, __LINE__);
return 0;
}
@@ -438,6 +468,10 @@ int HdfMtdDevErase(struct MtdDev *mtdDev, UINT64 start, UINT64 len, UINT64 *fail
if (mtdDev == NULL) {
return HDF_ERR_INVALID_OBJECT;
}
+ if (failAddr == NULL) {
+ HDF_LOGE("%s: failAddr is NULL", __func__);
+ return -EINVAL;
+ }
ret = MtdDeviceErase((struct MtdDevice *)mtdDev->priv, start, len, &failPos);
if (ret != HDF_SUCCESS) {
*failAddr = failPos;
diff --git a/khdf/liteos/model/storage/src/mtd/mtd_legacy_lite.c b/khdf/liteos/model/storage/src/mtd/mtd_legacy_lite.c
index 2bd0b760105d1f38f0a991a90678ccc549889aec..616b7e35f0239528b044f4a8543d4476dae5c541 100644
--- a/khdf/liteos/model/storage/src/mtd/mtd_legacy_lite.c
+++ b/khdf/liteos/model/storage/src/mtd/mtd_legacy_lite.c
@@ -264,7 +264,8 @@ static int MtdDeviceLegacyNandRead(MtdInfoLegacy *mtd, off_t addr, size_t len, s
{
int ret;
- if (mtd == NULL) {
+ if (mtd == NULL || mtd->priv == NULL || retlen == NULL || buf == NULL) {
+ HDF_LOGE("%s: function parameter is null", __func__);
return -EINVAL;
}
@@ -277,7 +278,8 @@ static int MtdDeviceLegacyNandWrite(MtdInfoLegacy *mtd, off_t addr, size_t len,
{
int ret;
- if (mtd == NULL) {
+ if (mtd == NULL || retlen == NULL) {
+ HDF_LOGE("%s: function parameter is null", __func__);
return -EINVAL;
}
@@ -290,7 +292,8 @@ static int MtdDeviceLegacyNandReadOob(MtdInfoLegacy *mtd, off_t addr, size_t len
{
int ret;
- if (mtd == NULL) {
+ if (mtd == NULL || retlen == NULL) {
+ HDF_LOGE("%s: function parameter is null", __func__);
return -EINVAL;
}
@@ -303,7 +306,8 @@ static int MtdDeviceLegacyNandWriteOob(MtdInfoLegacy *mtd, off_t addr, size_t le
{
int ret;
- if (mtd == NULL) {
+ if (mtd == NULL || retlen == NULL) {
+ HDF_LOGE("%s: function parameter is null", __func__);
return -EINVAL;
}
diff --git a/khdf/liteos/model/usb/device/BUILD.gn b/khdf/liteos/model/usb/device/BUILD.gn
old mode 100755
new mode 100644
diff --git a/khdf/liteos/model/usb/device/Kconfig b/khdf/liteos/model/usb/device/Kconfig
old mode 100755
new mode 100644
diff --git a/khdf/liteos/model/usb/device/Makefile b/khdf/liteos/model/usb/device/Makefile
old mode 100755
new mode 100644
diff --git a/khdf/liteos/model/usb/host/include/usb_pnp_notify.h b/khdf/liteos/model/usb/host/include/usb_pnp_notify.h
index 82661d788e4726074323cc9f79c078450b3df5e2..242123f41aa0a71bbcf115c2ba0af687572b5501 100755
--- a/khdf/liteos/model/usb/host/include/usb_pnp_notify.h
+++ b/khdf/liteos/model/usb/host/include/usb_pnp_notify.h
@@ -83,7 +83,7 @@ struct UsbInfoQueryPara {
UsbInfoQueryParaType type;
union {
int32_t id;
- uintptr_t usbDevAddr;
+ uint64_t usbDevAddr;
struct {
int32_t devNum;
int32_t busNum;
diff --git a/khdf/liteos/model/usb/host/src/usb_pnp_manager.c b/khdf/liteos/model/usb/host/src/usb_pnp_manager.c
old mode 100755
new mode 100644
diff --git a/khdf/liteos/model/usb/host/src/usb_pnp_notify.c b/khdf/liteos/model/usb/host/src/usb_pnp_notify.c
old mode 100755
new mode 100644
index f7982e9caec4ada5e4db00229db2046437689e8d..01dc4be5b7d5b26f7f0924bf07a0b17608414c44
--- a/khdf/liteos/model/usb/host/src/usb_pnp_notify.c
+++ b/khdf/liteos/model/usb/host/src/usb_pnp_notify.c
@@ -80,7 +80,7 @@ static bool UsbPnpNotifyFindDeviceList(struct usb_device *deviceObj, bool freeFl
struct UsbPnpNotifyDeviceList, deviceList) {
if (pnpNotifyDevicePos->device == deviceObj) {
findFlag = true;
- if (freeFlag == true) {
+ if (freeFlag) {
DListRemove(&pnpNotifyDevicePos->deviceList);
OsalMemFree(&pnpNotifyDevicePos);
}
@@ -96,29 +96,25 @@ static bool UsbPnpNotifyFindDeviceList(struct usb_device *deviceObj, bool freeFl
static struct UsbPnpDeviceInfo *UsbPnpNotifyCreateInfo(void)
{
struct UsbPnpDeviceInfo *infoTemp = NULL;
- unsigned char *ptr = NULL;
- static int32_t idNum = 0;
+ static int32_t idNum = 1;
- ptr = OsalMemCalloc(sizeof(struct UsbPnpDeviceInfo));
- if (ptr == NULL) {
- HDF_LOGE("%s:%d OsalMemAlloc faile ", __func__, __LINE__);
+ infoTemp = (struct UsbPnpDeviceInfo *)OsalMemCalloc(sizeof(struct UsbPnpDeviceInfo));
+ if (infoTemp == NULL) {
+ HDF_LOGE("%s:%d OsalMemAlloc failed ", __func__, __LINE__);
return NULL;
- } else {
- infoTemp = (struct UsbPnpDeviceInfo *)ptr;
-
- if (idNum++ >= INT32_MAX) {
- idNum = 0;
- }
- infoTemp->id = idNum;
- OsalMutexInit(&infoTemp->lock);
- infoTemp->status = USB_PNP_DEVICE_INIT_STATUS;
- DListHeadInit(&infoTemp->list);
- memset_s(infoTemp->interfaceRemoveStatus, USB_PNP_INFO_MAX_INTERFACES,
- 0, sizeof(infoTemp->interfaceRemoveStatus));
- DListInsertTail(&infoTemp->list, &g_usbPnpInfoListHead);
+ }
- return infoTemp;
+ if (idNum == INT32_MAX) {
+ idNum = 1;
}
+ infoTemp->id = idNum;
+ OsalMutexInit(&infoTemp->lock);
+ infoTemp->status = USB_PNP_DEVICE_INIT_STATUS;
+ DListHeadInit(&infoTemp->list);
+ DListInsertTail(&infoTemp->list, &g_usbPnpInfoListHead);
+ idNum++;
+
+ return infoTemp;
}
static struct UsbPnpDeviceInfo *UsbPnpNotifyFindInfo(struct UsbInfoQueryPara queryPara)
@@ -128,7 +124,7 @@ static struct UsbPnpDeviceInfo *UsbPnpNotifyFindInfo(struct UsbInfoQueryPara que
bool findFlag = false;
if (DListIsEmpty(&g_usbPnpInfoListHead)) {
- HDF_LOGE("%s:%d usb pnp list head is empty. ", __func__, __LINE__);
+ HDF_LOGE("%s:%d usb pnp list head is empty.", __func__, __LINE__);
return NULL;
}
@@ -153,13 +149,13 @@ static struct UsbPnpDeviceInfo *UsbPnpNotifyFindInfo(struct UsbInfoQueryPara que
break;
}
- if (findFlag == true) {
+ if (findFlag) {
break;
}
}
- if (findFlag == false) {
- HDF_LOGE("%s:%d the usb pnp info to be find does not exist. ", __func__, __LINE__);
+ if (!findFlag) {
+ HDF_LOGE("%s:%d the usb pnp info to be find does not exist.", __func__, __LINE__);
return NULL;
} else {
return infoPos;
@@ -175,7 +171,7 @@ static HDF_STATUS UsbPnpNotifyDestroyInfo(struct UsbPnpDeviceInfo *deviceInfo)
if (deviceInfo == NULL) {
ret = HDF_FAILURE;
- HDF_LOGE("%s:%d the deviceInfo is NULL, ret=%d ", __func__, __LINE__, ret);
+ HDF_LOGE("%s:%d the deviceInfo is NULL, ret = %d ", __func__, __LINE__, ret);
return ret;
}
@@ -194,9 +190,9 @@ static HDF_STATUS UsbPnpNotifyDestroyInfo(struct UsbPnpDeviceInfo *deviceInfo)
}
}
- if (findFlag == false) {
+ if (!findFlag) {
ret = HDF_FAILURE;
- HDF_LOGE("%s:%d the deviceInfoto be destroyed does not exist, ret=%d ", __func__, __LINE__, ret);
+ HDF_LOGE("%s:%d the deviceInfoto be destroyed does not exist, ret = %d ", __func__, __LINE__, ret);
}
return ret;
@@ -206,7 +202,7 @@ static int32_t UsbPnpNotifyAddInitInfo(struct UsbPnpDeviceInfo *deviceInfo, unio
{
int32_t ret = HDF_SUCCESS;
- deviceInfo->info.usbDevAddr = (uintptr_t)infoData.usbDev;
+ deviceInfo->info.usbDevAddr = (uint64_t)infoData.usbDev;
deviceInfo->info.devNum = infoData.usbDev->address;
deviceInfo->info.busNum = (int32_t)infoData.usbDev->port_no;
@@ -226,8 +222,7 @@ static int32_t UsbPnpNotifyAddInitInfo(struct UsbPnpDeviceInfo *deviceInfo, unio
deviceInfo->info.numInfos = infoData.usbDev->cdesc->bNumInterface;
for (uint8_t i = 0; i < deviceInfo->info.numInfos; i++) {
if (infoData.usbDev->ifaces[i].idesc == NULL) {
- HDF_LOGE("%s:%d interface[%d].idesc is NULL",
- __func__, __LINE__, i);
+ HDF_LOGE("%s:%d interface[%hhu].idesc is NULL", __func__, __LINE__, i);
ret = HDF_ERR_INVALID_PARAM;
goto OUT;
}
@@ -240,7 +235,7 @@ static int32_t UsbPnpNotifyAddInitInfo(struct UsbPnpDeviceInfo *deviceInfo, unio
deviceInfo->info.interfaceInfo[i].interfaceNumber =
infoData.usbDev->ifaces[i].idesc->bInterfaceNumber;
- HDF_LOGI("%s:%d i=%d, interfaceInfo=0x%x-0x%x-0x%x-0x%x",
+ HDF_LOGI("%s:%d i = %hhu, interfaceInfo=0x%x-0x%x-0x%x-0x%x",
__func__, __LINE__, i, deviceInfo->info.interfaceInfo[i].interfaceClass,
deviceInfo->info.interfaceInfo[i].interfaceSubClass,
deviceInfo->info.interfaceInfo[i].interfaceProtocol,
@@ -279,7 +274,7 @@ static void UsbPnpNotifyAddInterfaceInitInfo(struct UsbPnpDeviceInfo *deviceInfo
} else {
for (i = 0, j = 0; i < deviceInfo->info.numInfos; i++) {
if (deviceInfo->interfaceRemoveStatus[i] == true) {
- HDF_LOGI("%s:%d j=%d deviceInfo->interfaceRemoveStatus[%d] is true!", __func__, __LINE__, j, i);
+ HDF_LOGI("%s:%d j = %hhu deviceInfo->interfaceRemoveStatus[%hhu] is true!", __func__, __LINE__, j, i);
continue;
}
infoTable->interfaceInfo[j].interfaceClass = deviceInfo->info.interfaceInfo[i].interfaceClass;
@@ -288,7 +283,7 @@ static void UsbPnpNotifyAddInterfaceInitInfo(struct UsbPnpDeviceInfo *deviceInfo
infoTable->interfaceInfo[j].interfaceNumber = deviceInfo->info.interfaceInfo[i].interfaceNumber;
j++;
- HDF_LOGI("%s:%d i=%d, j=%d, interfaceInfo=0x%x-0x%x-0x%x-0x%x",
+ HDF_LOGI("%s:%d i = %d, j = %d, interfaceInfo=0x%x-0x%x-0x%x-0x%x",
__func__, __LINE__, i, j - 1, infoTable->interfaceInfo[j - 1].interfaceClass,
infoTable->interfaceInfo[j - 1].interfaceSubClass,
infoTable->interfaceInfo[j - 1].interfaceProtocol,
@@ -304,8 +299,8 @@ static int32_t UsbPnpNotifyInitInfo(
int32_t ret = HDF_SUCCESS;
const void *data = NULL;
- if ((g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_ADD_INTERFACE)
- || (g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_REMOVE_INTERFACE)) {
+ if ((g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_ADD_INTERFACE) ||
+ (g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_REMOVE_INTERFACE)) {
static struct UsbPnpNotifyMatchInfoTable infoTable;
infoTable.usbDevAddr = deviceInfo->info.usbDevAddr;
@@ -387,7 +382,7 @@ static int32_t UsbPnpNotifyGetDeviceInfo(void *eventData, union UsbPnpDeviceInfo
} else if ((g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_ADD_DEVICE)
|| (g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_REMOVE_DEVICE)) {
infoQueryPara.type = USB_INFO_DEVICE_ADDRESS_TYPE;
- infoQueryPara.usbDevAddr = (uintptr_t)pnpInfoData->usbDev;
+ infoQueryPara.usbDevAddr = (uint64_t)pnpInfoData->usbDev;
*deviceInfo = UsbPnpNotifyFindInfo(infoQueryPara);
} else {
*deviceInfo = UsbPnpNotifyCreateInfo();
@@ -470,7 +465,7 @@ static void TestReadPnpInfo(struct HdfSBuf *data)
bool flag;
flag = HdfSbufReadBuffer(data, (const void **)(&g_testUsbPnpInfo), &infoSize);
- if ((flag == false) || (g_testUsbPnpInfo == NULL)) {
+ if ((!flag) || (g_testUsbPnpInfo == NULL)) {
HDF_LOGE("%s: fail to read g_testUsbPnpInfo, flag=%d, g_testUsbPnpInfo=%px", \
__func__, flag, g_testUsbPnpInfo);
return;
@@ -536,8 +531,8 @@ static int32_t TestPnpNotifyHdfSendEvent(const struct HdfDeviceObject *deviceObj
goto OUT;
}
- HDF_LOGI("%s: report one device information, %d usbDev=0x%x, devNum=%d, busNum=%d, infoTable=%d-0x%x-0x%x!", \
- __func__, g_usbPnpNotifyCmdType, (uint32_t)infoTable.usbDevAddr, infoTable.devNum, infoTable.busNum, \
+ HDF_LOGI("%s: report one device information, %d usbDev=%llu, devNum=%d, busNum=%d, infoTable=%d-0x%x-0x%x!", \
+ __func__, g_usbPnpNotifyCmdType, infoTable.usbDevAddr, infoTable.devNum, infoTable.busNum, \
infoTable.numInfos, infoTable.deviceInfo.vendorId, infoTable.deviceInfo.productId);
ret = UsbPnpNotifySendEventLoader(data);
@@ -559,6 +554,7 @@ static int32_t UsbPnpNotifyFirstReportDevice(struct HdfDeviceIoClient *client)
{
struct UsbPnpNotifyDeviceList *pnpNotifyDevicePos = NULL;
struct UsbPnpNotifyDeviceList *pnpNotifyDeviceTemp = NULL;
+ int32_t ret;
dprintf("%s:%d Enter!\n", __func__, __LINE__);
@@ -570,7 +566,10 @@ static int32_t UsbPnpNotifyFirstReportDevice(struct HdfDeviceIoClient *client)
OsalMutexLock(&g_usbPnpNotifyDevicelistLock);
DLIST_FOR_EACH_ENTRY_SAFE(pnpNotifyDevicePos, pnpNotifyDeviceTemp, &g_usbPnpDeviceListHead,
struct UsbPnpNotifyDeviceList, deviceList) {
- UsbPnpNotifyHdfSendEvent(client->device, pnpNotifyDevicePos->device);
+ ret = UsbPnpNotifyHdfSendEvent(client->device, pnpNotifyDevicePos->device);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%{public}s:%{public}d UsbPnpNotifyHdfSendEvent failed, ret=%{public}d", __func__, __LINE__, ret);
+ }
}
OsalMutexUnlock(&g_usbPnpNotifyDevicelistLock);
@@ -677,12 +676,12 @@ static void UsbPnpNotifyAttachDevice(struct usb_device *udev)
int32_t error;
static int32_t listLockInit = 0;
- if ((udev->ddesc.bDeviceClass == UICLASS_HUB) || UsbPnpNotifyFindDeviceList(udev, false) == true) {
+ if ((udev->ddesc.bDeviceClass == UICLASS_HUB) || UsbPnpNotifyFindDeviceList(udev, false)) {
PRINTK("%s:%d findDeviceList is true!\n", __func__, __LINE__);
return;
}
- if (0 == listLockInit) {
+ if (listLockInit == 0) {
error = OsalMutexInit(&g_usbPnpNotifyDevicelistLock);
if (error != HDF_SUCCESS) {
HDF_LOGE("%s:%d error=%d!", __func__, __LINE__, error);
@@ -708,9 +707,9 @@ static void UsbPnpNotifyDetachDevice(struct usb_device *udev)
struct UsbInfoQueryPara infoQueryPara;
struct UsbPnpDeviceInfo *deviceInfo = NULL;
- if (UsbPnpNotifyFindDeviceList(udev, true) == true) {
+ if (UsbPnpNotifyFindDeviceList(udev, true)) {
infoQueryPara.type = USB_INFO_DEVICE_ADDRESS_TYPE;
- infoQueryPara.usbDevAddr = (uintptr_t)udev;
+ infoQueryPara.usbDevAddr = (uint64_t)udev;
deviceInfo = UsbPnpNotifyFindInfo(infoQueryPara);
if (deviceInfo == NULL) {
PRINTK("%s:%d USB_DEVICE_REMOVE find info failed", __func__, __LINE__);
@@ -770,7 +769,7 @@ struct usb_device *UsbPnpNotifyGetUsbDevice(struct UsbGetDevicePara paraData)
break;
}
- if (findFlag == true) {
+ if (findFlag) {
usbPnpDevice = pnpNotifyDevicePos->device;
break;
}
@@ -789,7 +788,7 @@ static void UsbPnpNotifyReadPnpInfo(struct HdfSBuf *data)
bool flag;
flag = HdfSbufReadBuffer(data, (const void **)(&usbPnpInfo), &infoSize);
- if ((flag == false) || (usbPnpInfo == NULL)) {
+ if ((!flag) || (usbPnpInfo == NULL)) {
HDF_LOGE("%s:%d fail to read g_usbPnpInfo, flag=%d", __func__, __LINE__, flag);
return;
}
@@ -849,7 +848,7 @@ static int32_t UsbPnpNotifyDriverRegisterDevice(struct HdfDeviceObject *device,
ret = HdfDeviceObjectRegister(devObj);
if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: failed to regitst device %s", __func__, moduleName);
+ HDF_LOGE("%s: failed to register device %s", __func__, moduleName);
HdfDeviceObjectRelease(devObj);
return ret;
}
@@ -857,7 +856,7 @@ static int32_t UsbPnpNotifyDriverRegisterDevice(struct HdfDeviceObject *device,
ret = HdfDeviceObjectPublishService(devObj, serviceName, SERVICE_POLICY_CAPACITY,
OSAL_S_IREAD | OSAL_S_IWRITE | OSAL_S_IRGRP | OSAL_S_IWGRP | OSAL_S_IROTH);
if (ret != HDF_SUCCESS) {
- HDF_LOGE("%s: failed to regitst device %s", __func__, serviceName);
+ HDF_LOGE("%s: failed to register device %s", __func__, serviceName);
HdfDeviceObjectRelease(devObj);
}
@@ -967,7 +966,7 @@ static int32_t UsbPnpNotifyBind(struct HdfDeviceObject *device)
static int32_t UsbPnpNotifyInit(struct HdfDeviceObject *device)
{
static bool firstInitFlag = true;
- HDF_STATUS ret;
+ int32_t ret;
struct OsalThreadParam threadCfg;
dprintf("%s:%d enter!\n", __func__, __LINE__);
@@ -977,7 +976,7 @@ static int32_t UsbPnpNotifyInit(struct HdfDeviceObject *device)
return HDF_ERR_INVALID_OBJECT;
}
- if (firstInitFlag == true) {
+ if (firstInitFlag) {
firstInitFlag = false;
DListHeadInit(&g_usbPnpInfoListHead);
@@ -988,10 +987,14 @@ static int32_t UsbPnpNotifyInit(struct HdfDeviceObject *device)
OsalMutexInit(&g_usbSendEventLock);
- g_usbPnpThreadRunningFlag = true;
-
/* Creat thread to handle send usb interface information. */
- (void)memset_s(&threadCfg, sizeof(threadCfg), 0, sizeof(threadCfg));
+ ret = memset_s(&threadCfg, sizeof(threadCfg), 0, sizeof(threadCfg));
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%{public}s:%{public}d memset_s failed", __func__, __LINE__);
+ return ret;
+ }
+
+ g_usbPnpThreadRunningFlag = true;
threadCfg.name = "LiteOS usb pnp notify handle kthread";
threadCfg.priority = OSAL_THREAD_PRI_HIGH;
threadCfg.stackSize = USB_PNP_NOTIFY_REPORT_STACK_SIZE;
diff --git a/khdf/liteos/model/usb/host/src/usb_test_pnp_notify.c b/khdf/liteos/model/usb/host/src/usb_test_pnp_notify.c
old mode 100755
new mode 100644
diff --git a/khdf/liteos/ndk/BUILD.gn b/khdf/liteos/ndk/BUILD.gn
old mode 100755
new mode 100644
diff --git a/khdf/liteos/network/src/netbuf_adapter.c b/khdf/liteos/network/src/netbuf_adapter.c
index 6d9d2fe855a7570ef6e307217357182017443c95..176251b8004d49fcfc667e99a23bae10006583af 100644
--- a/khdf/liteos/network/src/netbuf_adapter.c
+++ b/khdf/liteos/network/src/netbuf_adapter.c
@@ -307,7 +307,7 @@ NetBuf *NetBufAlloc(uint32_t size)
}
(void)memset_s(nb, sizeof(NetBuf), 0, sizeof(NetBuf));
- (void)memset_s(data, sizeof(uint8_t), 0, sizeof(uint8_t));
+ (void)memset_s(data, size, 0, size);
nb->mem = data;
nb->len = size;
diff --git a/khdf/liteos/osal/include/osal_uaccess.h b/khdf/liteos/osal/include/osal_uaccess.h
index f8a69a608d79fa8d28f1996f5862f9915776597a..dee351035c2506624d7dde627708adad1630b187 100644
--- a/khdf/liteos/osal/include/osal_uaccess.h
+++ b/khdf/liteos/osal/include/osal_uaccess.h
@@ -38,12 +38,12 @@
extern "C" {
#endif /* __cplusplus */
-static inline size_t CopyToUser (void* to, const void* from, size_t len)
+static inline size_t CopyToUser(void* to, const void* from, size_t len)
{
return LOS_ArchCopyToUser(to, from, len);
}
-static inline size_t CopyFromUser (void* to, const void* from, size_t len)
+static inline size_t CopyFromUser(void* to, const void* from, size_t len)
{
return LOS_ArchCopyFromUser(to, from, len);
}
diff --git a/khdf/liteos/osal/src/osal_file.c b/khdf/liteos/osal/src/osal_file.c
index 86bf1189c580569fff7cc741616d2077063e98cf..d5da1a14e461b45de1c61dd01d7ec7d28655a753 100644
--- a/khdf/liteos/osal/src/osal_file.c
+++ b/khdf/liteos/osal/src/osal_file.c
@@ -56,7 +56,7 @@ int32_t OsalFileOpen(OsalFile *file, const char *path, int flags, uint32_t right
fd = open(pathName, flags, rights);
if (fd < 0) {
- HDF_LOGE("%s open file fail %d %d %d", __func__, flags, rights, errno);
+ HDF_LOGE("%s open file fail %d %u %d", __func__, flags, rights, errno);
return HDF_FAILURE;
}
@@ -104,7 +104,7 @@ ssize_t OsalFileRead(OsalFile *file, void *buf, uint32_t length)
ret = read((int32_t)(uintptr_t)file->realFile, buf, length);
if (ret < 0) {
- HDF_LOGE("%s read file fail %d %d", __func__, length, errno);
+ HDF_LOGE("%s read file fail %u %d", __func__, length, errno);
return HDF_FAILURE;
}
diff --git a/khdf/liteos/osal/src/osal_firmware.c b/khdf/liteos/osal/src/osal_firmware.c
index 9b578faa82f7f39499959726927151619a2e0ec5..3b90f7fb4c0ed6d46795092f136c97be20d3a35c 100644
--- a/khdf/liteos/osal/src/osal_firmware.c
+++ b/khdf/liteos/osal/src/osal_firmware.c
@@ -127,7 +127,7 @@ int32_t OsalReadFirmware(struct OsalFirmware *fwPara, struct OsalFwBlock *block)
}
fw = (struct OsalFwDesc *)fwPara->para;
- if (fw->openFlag == false) {
+ if (!fw->openFlag) {
HDF_LOGE("%s file do not open", __func__);
return HDF_ERR_INVALID_PARAM;
}
@@ -153,7 +153,7 @@ int32_t OsalReadFirmware(struct OsalFirmware *fwPara, struct OsalFwBlock *block)
readOffset = (uint32_t)lseek(fw->fd, fw->offset, SEEK_SET);
if (readOffset != fw->offset) {
- HDF_LOGE("%s seek offset fail %d %d", __func__, readOffset, fw->offset);
+ HDF_LOGE("%s seek offset fail %u %d", __func__, readOffset, fw->offset);
return HDF_FAILURE;
}
readSize = (uint32_t)read(fw->fd, block->data, block->dataSize);
diff --git a/khdf/liteos/osal/src/osal_irq.c b/khdf/liteos/osal/src/osal_irq.c
index e2a19c641ba971a6c616651d1fae2314b7537a62..33f53ed184cbbdba30297daac0b95fe6ea35cbf7 100644
--- a/khdf/liteos/osal/src/osal_irq.c
+++ b/khdf/liteos/osal/src/osal_irq.c
@@ -49,7 +49,7 @@ int32_t OsalRegisterIrq(uint32_t irqId, uint32_t config, OsalIRQHandle handle, c
irqParam.pName = name;
ret = LOS_HwiCreate(irqId, 0, (HWI_MODE_T)config, (HWI_PROC_FUNC)handle, &irqParam);
if (ret != LOS_OK) {
- HDF_LOGE("%s %d register fail 0x%x", __func__, irqId, ret);
+ HDF_LOGE("%s %u register fail 0x%x", __func__, irqId, ret);
return HDF_FAILURE;
}
HalIrqUnmask(irqId);
@@ -63,7 +63,7 @@ int32_t OsalUnregisterIrq(uint32_t irqId, void *dev)
HwiIrqParam irqParam;
if (irqId >= OS_HWI_MAX_NUM) {
- HDF_LOGE("invalid irq number %d\n", irqId);
+ HDF_LOGE("invalid irq number %u\n", irqId);
return HDF_ERR_INVALID_PARAM;
}
@@ -71,7 +71,7 @@ int32_t OsalUnregisterIrq(uint32_t irqId, void *dev)
irqParam.pDevId = dev;
ret = LOS_HwiDelete(irqId, &irqParam);
if (ret != LOS_OK) {
- HDF_LOGE("irq %d unregister fail %d\n", irqId, ret);
+ HDF_LOGE("irq %u unregister fail %u\n", irqId, ret);
return HDF_FAILURE;
}
@@ -81,7 +81,7 @@ int32_t OsalUnregisterIrq(uint32_t irqId, void *dev)
int32_t OsalEnableIrq(uint32_t irqId)
{
if (irqId >= OS_HWI_MAX_NUM) {
- HDF_LOGE("invalid irq number %d\n", irqId);
+ HDF_LOGE("invalid irq number %u\n", irqId);
return HDF_ERR_INVALID_PARAM;
}
@@ -93,7 +93,7 @@ int32_t OsalEnableIrq(uint32_t irqId)
int32_t OsalDisableIrq(uint32_t irqId)
{
if (irqId >= OS_HWI_MAX_NUM) {
- HDF_LOGE("invalid irq number %d\n", irqId);
+ HDF_LOGE("invalid irq number %u\n", irqId);
return HDF_ERR_INVALID_PARAM;
}
diff --git a/khdf/liteos/osal/src/osal_thread.c b/khdf/liteos/osal/src/osal_thread.c
index 7897c58ad3303b9ac346c96be3541c55b0cfe7a6..b3e37f4d1b3a39657e43a196c675a45a3d15a157 100644
--- a/khdf/liteos/osal/src/osal_thread.c
+++ b/khdf/liteos/osal/src/osal_thread.c
@@ -174,7 +174,7 @@ int32_t OsalThreadSuspend(struct OsalThread *thread)
bool flag = false;
flag = OsalCheckPara(thread);
- if (flag == false) {
+ if (!flag) {
HDF_LOGE("%s invalid parameter %d\n", __func__, __LINE__);
return HDF_ERR_INVALID_PARAM;
}
@@ -193,7 +193,7 @@ int32_t OsalThreadDestroy(struct OsalThread *thread)
bool flag = false;
flag = OsalCheckPara(thread);
- if (flag == false) {
+ if (!flag) {
HDF_LOGE("%s invalid parameter %d\n", __func__, __LINE__);
return HDF_ERR_INVALID_PARAM;
}
@@ -210,7 +210,7 @@ int32_t OsalThreadResume(struct OsalThread *thread)
bool flag = false;
flag = OsalCheckPara(thread);
- if (flag == false) {
+ if (!flag) {
HDF_LOGE("%s invalid parameter %d\n", __func__, __LINE__);
return HDF_ERR_INVALID_PARAM;
}
diff --git a/khdf/liteos/osal/src/osal_workqueue.c b/khdf/liteos/osal/src/osal_workqueue.c
index e39c23ca933b2cf01139416280a52d57cd14e1d2..22348b006265ca72dc3cc363715a3fa1e7e7a800 100644
--- a/khdf/liteos/osal/src/osal_workqueue.c
+++ b/khdf/liteos/osal/src/osal_workqueue.c
@@ -170,7 +170,7 @@ bool HdfAddWork(HdfWorkQueue *queue, HdfWork *work)
return queue_work(queue->realWorkQueue, &((struct WorkWrapper *)work->realWork)->work.work);
}
-bool HdfAddDelayedWork(HdfWorkQueue *queue, HdfWork *work, unsigned long ms)
+bool HdfAddDelayedWork(HdfWorkQueue *queue, HdfWork *work, uint32_t ms)
{
if (queue == NULL || queue->realWorkQueue == NULL || work == NULL || work->realWork == NULL) {
HDF_LOGE("%s invalid para", __func__);
diff --git a/khdf/liteos/platform/BUILD.gn b/khdf/liteos/platform/BUILD.gn
index d4b031930b4081fff7de31a37cbead2e8bf46fec..fdd264508e912ba3627f85f116e4b7f18e351d7b 100644
--- a/khdf/liteos/platform/BUILD.gn
+++ b/khdf/liteos/platform/BUILD.gn
@@ -1,4 +1,4 @@
-# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
@@ -35,12 +35,20 @@ hdf_driver(module_name) {
sources = [
"$HDF_FRAMEWORKS_PATH/support/platform/src/fwk/platform_common.c",
"$HDF_FRAMEWORKS_PATH/support/platform/src/fwk/platform_device.c",
+ "$HDF_FRAMEWORKS_PATH/support/platform/src/fwk/platform_dumper.c",
"$HDF_FRAMEWORKS_PATH/support/platform/src/fwk/platform_event.c",
"$HDF_FRAMEWORKS_PATH/support/platform/src/fwk/platform_manager.c",
"$HDF_FRAMEWORKS_PATH/support/platform/src/fwk/platform_queue.c",
"src/plat_common.c",
]
+ if (defined(LOSCFG_DRIVERS_HDF_PLATFORM_TRACE)) {
+ sources += [
+ "$HDF_FRAMEWORKS_PATH/support/platform/src/fwk/platform_trace_transfer.c",
+ "src/platform_trace.c",
+ ]
+ }
+
if (defined(LOSCFG_DRIVERS_HDF_PLATFORM_I2C)) {
sources += [
"$HDF_FRAMEWORKS_PATH/support/platform/src/i2c/i2c_core.c",
@@ -195,6 +203,18 @@ hdf_driver(module_name) {
]
}
+ if (defined(LOSCFG_DRIVERS_HDF_PLATFORM_CAN)) {
+ sources += [
+ "$HDF_FRAMEWORKS_PATH/support/platform/src/can/can_client.c",
+ "$HDF_FRAMEWORKS_PATH/support/platform/src/can/can_core.c",
+ "$HDF_FRAMEWORKS_PATH/support/platform/src/can/can_if.c",
+ "$HDF_FRAMEWORKS_PATH/support/platform/src/can/can_mail.c",
+ "$HDF_FRAMEWORKS_PATH/support/platform/src/can/can_manager.c",
+ "$HDF_FRAMEWORKS_PATH/support/platform/src/can/can_msg.c",
+ "$HDF_FRAMEWORKS_PATH/support/platform/src/can/can_service.c",
+ ]
+ }
+
public_configs = [ ":public" ]
}
diff --git a/khdf/liteos/platform/Makefile b/khdf/liteos/platform/Makefile
index d9bb5507925b39323ed22012766e05a5376a2775..fb539e4c2cfe888caa918f54a29e9e4b45444fcf 100644
--- a/khdf/liteos/platform/Makefile
+++ b/khdf/liteos/platform/Makefile
@@ -1,4 +1,4 @@
-# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
@@ -41,9 +41,15 @@ ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM), y)
$(HDF_FRAMEWORKS)/support/platform/src/fwk/platform_event.c \
$(HDF_FRAMEWORKS)/support/platform/src/fwk/platform_manager.c \
$(HDF_FRAMEWORKS)/support/platform/src/fwk/platform_queue.c \
+ $(HDF_FRAMEWORKS)/support/platform/src/fwk/platform_dumper.c \
$(HDF_FRAMEWORKS)/support/platform/src/fwk/platform_common.c
endif
+ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_TRACE), y)
+ LOCAL_SRCS += ./src/platform_trace.c \
+ $(HDF_FRAMEWORKS)/support/platform/src/fwk/platform_trace_transfer.c
+endif
+
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_I2C), y)
LOCAL_SRCS += $(HDF_FRAMEWORKS)/support/platform/src/i2c/i2c_if.c \
$(HDF_FRAMEWORKS)/support/platform/src/i2c/i2c_core.c
@@ -163,4 +169,14 @@ ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_TIMER), y)
$(HDF_FRAMEWORKS)/support/platform/src/timer/timer_core.c
endif
+ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_CAN), y)
+ LOCAL_SRCS += $(HDF_FRAMEWORKS)/support/platform/src/can/can_client.c \
+ $(HDF_FRAMEWORKS)/support/platform/src/can/can_core.c \
+ $(HDF_FRAMEWORKS)/support/platform/src/can/can_if.c \
+ $(HDF_FRAMEWORKS)/support/platform/src/can/can_mail.c \
+ $(HDF_FRAMEWORKS)/support/platform/src/can/can_manager.c \
+ $(HDF_FRAMEWORKS)/support/platform/src/can/can_msg.c \
+ $(HDF_FRAMEWORKS)/support/platform/src/can/can_service.c
+endif
+
include $(HDF_DRIVER)
diff --git a/khdf/liteos/platform/src/gpio_dev.c b/khdf/liteos/platform/src/gpio_dev.c
index dd9f605eab049b1bd2cbaee08fef5cd52fad78e2..196efc00559078a1c87c90f51e08abbb2f2ce82f 100644
--- a/khdf/liteos/platform/src/gpio_dev.c
+++ b/khdf/liteos/platform/src/gpio_dev.c
@@ -62,7 +62,7 @@ static int GpioExecCmd(uint16_t gpio, struct GpioBitInfo *info, int cmd)
HDF_LOGE("%s: set dir fail:%d", __func__, ret);
return -1;
}
- PLAT_LOGV("%s: gpio:%u set dir:%u done!", __func__, gpio, info->direction);
+ PLAT_LOGV("%s: gpio:%hu set dir:%u done!", __func__, gpio, info->direction);
break;
case GPIO_GET_DIR:
ret = GpioGetDir(gpio, &tmp);
@@ -71,7 +71,7 @@ static int GpioExecCmd(uint16_t gpio, struct GpioBitInfo *info, int cmd)
return -1;
}
info->direction = (unsigned char)tmp;
- PLAT_LOGV("%s: gpio:%u get dir:%u done!", __func__, gpio, info->direction);
+ PLAT_LOGV("%s: gpio:%hu get dir:%u done!", __func__, gpio, info->direction);
break;
case GPIO_READ_BIT:
ret = GpioRead(gpio, &tmp);
@@ -80,7 +80,7 @@ static int GpioExecCmd(uint16_t gpio, struct GpioBitInfo *info, int cmd)
return -1;
}
info->value = (unsigned char)tmp;
- PLAT_LOGV("%s: gpio:%u read:%u done!", __func__, gpio, info->value);
+ PLAT_LOGV("%s: gpio:%hu read:%u done!", __func__, gpio, info->value);
break;
case GPIO_WRITE_BIT:
ret = GpioWrite(gpio, info->value);
@@ -88,7 +88,7 @@ static int GpioExecCmd(uint16_t gpio, struct GpioBitInfo *info, int cmd)
HDF_LOGE("%s: write gpio fail:%d", __func__, ret);
return -1;
}
- PLAT_LOGV("%s: gpio:%u write:%u done!", __func__, gpio, info->value);
+ PLAT_LOGV("%s: gpio:%hu write:%u done!", __func__, gpio, info->value);
break;
default:
ret = -1;
@@ -102,7 +102,14 @@ static int GpioIoctl(struct file *filep, int cmd, unsigned long arg)
uint16_t bitNum;
uint16_t gpio;
struct GpioBitInfo info = {0};
- struct drv_data* drvData = (struct drv_data* )filep->f_vnode->data;
+ struct drv_data *drvData = NULL;
+
+ if (filep == NULL || filep->f_vnode == NULL || filep->f_vnode->data == NULL) {
+ HDF_LOGE("%s: function parameter is null", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ drvData = (struct drv_data *)filep->f_vnode->data;
bitNum = (uint16_t)(uintptr_t)drvData->priv;
ret = LOS_CopyToKernel(&info, sizeof(struct GpioBitInfo),
@@ -111,7 +118,7 @@ static int GpioIoctl(struct file *filep, int cmd, unsigned long arg)
return -1;
}
gpio = info.groupnumber * bitNum + info.bitnumber;
- PLAT_LOGV("%s: gn:%u, bn:%u, gpio:%u", __func__, info.groupnumber, info.bitnumber, gpio);
+ PLAT_LOGV("%s: gn:%u, bn:%u, gpio:%hu", __func__, info.groupnumber, info.bitnumber, gpio);
ret = GpioExecCmd(gpio, &info, cmd);
if (ret != 0) {
diff --git a/khdf/liteos/platform/src/i2c_dev.c b/khdf/liteos/platform/src/i2c_dev.c
index cf01a948e2aed8eb1b8bd1bc60fa883d8b94bb4c..dd1506d48e542f23635e3adef7a0340e26b704bb 100644
--- a/khdf/liteos/platform/src/i2c_dev.c
+++ b/khdf/liteos/platform/src/i2c_dev.c
@@ -348,8 +348,15 @@ static int I2cFsOpen(struct file *filep)
{
DevHandle handle = NULL;
struct I2cClient *client = NULL;
- struct drv_data* drvData = (struct drv_data* )filep->f_vnode->data;
- int16_t id = (int16_t)(uintptr_t)drvData->priv;
+ struct drv_data *drvData = NULL;
+ int16_t id;
+
+ if (filep == NULL || filep->f_vnode == NULL || filep->f_vnode->data == NULL) {
+ HDF_LOGE("%s: function parameter is null", __func__);
+ return -EINVAL;
+ }
+ drvData = (struct drv_data *)filep->f_vnode->data;
+ id = (int16_t)(uintptr_t)drvData->priv;
handle = I2cOpen(id);
if (handle == NULL) {
diff --git a/khdf/liteos/platform/src/platform_trace.c b/khdf/liteos/platform/src/platform_trace.c
new file mode 100644
index 0000000000000000000000000000000000000000..76cb2b6d0020537910d94b87320b994cf358d595
--- /dev/null
+++ b/khdf/liteos/platform/src/platform_trace.c
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2022 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "platform_trace.h"
+#include "hdf_base.h"
+#include "hdf_log.h"
+#include "los_trace.h"
+
+int32_t PlatformTraceStart(void)
+{
+#ifdef LOSCFG_KERNEL_TRACE
+ uint32_t ret;
+ ret = LOS_TraceStart();
+ if (ret != LOS_OK) {
+ HDF_LOGE("PlatformTraceStart error:%d", ret);
+ return HDF_FAILURE;
+ }
+#endif
+ return HDF_SUCCESS;
+}
+
+int32_t PlatformTraceStop(void)
+{
+#ifdef LOSCFG_KERNEL_TRACE
+ LOS_TraceStop();
+#endif
+ return HDF_SUCCESS;
+}
+
+void PlatformTraceReset(void)
+{
+#ifdef LOSCFG_KERNEL_TRACE
+ LOS_TraceReset();
+#endif
+}
+
+#ifdef LOSCFG_KERNEL_TRACE
+static void TraceMeanPrint(void)
+{
+ uint32_t i = 0;
+ dprintf("********trace moudle and function explain:********\t");
+ const struct PlatformTraceModuleExplain *explains = PlatformTraceModuleExplainGetAll();
+ int32_t size = PlatformTraceModuleExplainCount();
+ for (i = 0; i < size; i++) {
+ if (explains[i].moduleInfo < PLATFORM_TRACE_MODULE_MAX) {
+ dprintf("meaning of module num 0x%x is %s\t", explains[i].moduleInfo, explains[i].moduleMean);
+ } else if (explains[i].moduleInfo > PLATFORM_TRACE_MODULE_MAX) {
+ dprintf("meaning of function num 0x%x is %s\t", explains[i].moduleInfo, explains[i].moduleMean);
+ }
+ }
+}
+#endif
+
+void PlatformTraceInfoDump(void)
+{
+#ifdef LOSCFG_KERNEL_TRACE
+ TraceMeanPrint();
+ LOS_TraceRecordDump(FALSE);
+#endif
+}
+
+#define PLATFORM_TRACE_IDENTIFY 0x33
+void PlatformTraceAddUintMsg(int module, int moduleFun, uint infos[], uint8_t size)
+{
+#ifdef LOSCFG_KERNEL_TRACE
+ if ((size <= 0) || (size > PLATFORM_TRACE_UINT_PARAM_SIZE_MAX)) {
+ HDF_LOGE("PlatformTraceAddUintMsg %hhu size illegal", size);
+ return;
+ }
+ if ((module < PLATFORM_TRACE_MODULE_I2S) || (module >= PLATFORM_TRACE_MODULE_MAX)) {
+ HDF_LOGE("PlatformTraceAddUintMsg %d module illegal", module);
+ return;
+ }
+ if ((moduleFun < PLATFORM_TRACE_MODULE_I2S_FUN) || (moduleFun >= PLATFORM_TRACE_MODULE_MAX_FUN)) {
+ HDF_LOGE("PlatformTraceAddUintMsg %d moduleFun illegal", moduleFun);
+ return;
+ }
+
+ switch (size) {
+ case PLATFORM_TRACE_UINT_PARAM_SIZE_1:
+ LOS_TRACE_EASY(TRACE_SYS_FLAG, PLATFORM_TRACE_IDENTIFY, module, moduleFun,
+ infos[PLATFORM_TRACE_UINT_PARAM_SIZE_1 - 1]);
+ break;
+ case PLATFORM_TRACE_UINT_PARAM_SIZE_2:
+ LOS_TRACE_EASY(TRACE_SYS_FLAG, PLATFORM_TRACE_IDENTIFY, module, moduleFun,
+ infos[PLATFORM_TRACE_UINT_PARAM_SIZE_1 - 1], infos[PLATFORM_TRACE_UINT_PARAM_SIZE_2 - 1]);
+ break;
+ case PLATFORM_TRACE_UINT_PARAM_SIZE_3:
+ LOS_TRACE_EASY(TRACE_SYS_FLAG, PLATFORM_TRACE_IDENTIFY, module, moduleFun,
+ infos[PLATFORM_TRACE_UINT_PARAM_SIZE_1 - 1], infos[PLATFORM_TRACE_UINT_PARAM_SIZE_2 - 1],
+ infos[PLATFORM_TRACE_UINT_PARAM_SIZE_3 - 1]);
+ break;
+ case PLATFORM_TRACE_UINT_PARAM_SIZE_4:
+ LOS_TRACE_EASY(TRACE_SYS_FLAG, PLATFORM_TRACE_IDENTIFY, module, moduleFun,
+ infos[PLATFORM_TRACE_UINT_PARAM_SIZE_1 - 1], infos[PLATFORM_TRACE_UINT_PARAM_SIZE_2 - 1],
+ infos[PLATFORM_TRACE_UINT_PARAM_SIZE_3 - 1], infos[PLATFORM_TRACE_UINT_PARAM_SIZE_4 - 1]);
+ break;
+ case PLATFORM_TRACE_UINT_PARAM_SIZE_MAX:
+ LOS_TRACE_EASY(TRACE_SYS_FLAG, PLATFORM_TRACE_IDENTIFY, module, moduleFun,
+ infos[PLATFORM_TRACE_UINT_PARAM_SIZE_1 - 1], infos[PLATFORM_TRACE_UINT_PARAM_SIZE_2 - 1],
+ infos[PLATFORM_TRACE_UINT_PARAM_SIZE_3 - 1], infos[PLATFORM_TRACE_UINT_PARAM_SIZE_4 - 1],
+ infos[PLATFORM_TRACE_UINT_PARAM_SIZE_MAX - 1]);
+ break;
+ default:
+ HDF_LOGE("PlatformTraceAddUintMsg %hhu size illegal", size);
+ break;
+ }
+#endif
+}
+
+void PlatformTraceAddMsg(const char *module, const char *moduleFun, const char *fmt, ...)
+{
+ // not support, return
+ return;
+}
diff --git a/khdf/liteos/platform/src/spi_dev.c b/khdf/liteos/platform/src/spi_dev.c
index 7adb112a2a3b8f3fa9d9fc3724abbf8f296d3d27..9564ab1e6cf9a7673380e59688526ebf0b3419ea 100644
--- a/khdf/liteos/platform/src/spi_dev.c
+++ b/khdf/liteos/platform/src/spi_dev.c
@@ -163,7 +163,7 @@ static int32_t SpiDevGetCfg(struct SpiDev *dev, struct SpiCfg *mask, unsigned lo
HDF_LOGI("%s: get mode 0x%x", __func__, tmp);
} else if (mask->bitsPerWord == 1) {
tmp = cfg.bitsPerWord;
- HDF_LOGI("%s: get word %d", __func__, tmp);
+ HDF_LOGI("%s: get word %u", __func__, tmp);
} else if (mask->maxSpeedHz == 1) {
tmp = cfg.maxSpeedHz;
HDF_LOGI("%s: get maxspeed %d", __func__, tmp);
@@ -201,7 +201,7 @@ static int32_t SpiDevSetCfg(struct SpiDev *dev, struct SpiCfg *mask, unsigned lo
HDF_LOGI("%s: set mode 0x%x", __func__, tmp);
cfg.mode = tmp;
} else if (mask->bitsPerWord == 1) {
- HDF_LOGI("%s: set word %d", __func__, tmp);
+ HDF_LOGI("%s: set word %u", __func__, tmp);
cfg.bitsPerWord = tmp;
} else if (mask->maxSpeedHz == 1) {
HDF_LOGI("%s: set maxspeed %d", __func__, tmp);
@@ -285,7 +285,7 @@ static int32_t SpiDevRealTransfer(struct SpiDev *dev, struct SpiMsg *msg, struct
kmsg[i].wbuf = wbuf + pos;
kmsg[i].rbuf = rbuf + pos;
kmsg[i].len = msg[i].len;
- kmsg[i].csChange = msg[i].csChange;
+ kmsg[i].keepCs = msg[i].keepCs;
kmsg[i].delayUs = msg[i].delayUs;
kmsg[i].speed = msg[i].speed;
pos += msg[i].len;
@@ -420,7 +420,7 @@ static void SpiAddRemoveDev(struct SpiDev *dev, bool add)
return;
}
if (add) {
- HDF_LOGI("creat /dev/spidev%u.%u", dev->cntlr->busNum, dev->csNum);
+ HDF_LOGI("create /dev/spidev%u.%u", dev->cntlr->busNum, dev->csNum);
if (register_driver(devName, &g_spiDevFops, HDF_SPI_FS_MODE, dev)) {
HDF_LOGE("%s: gen /dev/spidev%u.%u", __func__, dev->cntlr->busNum, dev->csNum);
}
diff --git a/khdf/liteos/platform/src/uart_dev.c b/khdf/liteos/platform/src/uart_dev.c
old mode 100755
new mode 100644
index d727fb6fdbe3e17214db7935d42489c91957715a..dd4d560ab45663a2b58c2613f9f52a3eec926f3c
--- a/khdf/liteos/platform/src/uart_dev.c
+++ b/khdf/liteos/platform/src/uart_dev.c
@@ -47,7 +47,7 @@ static int32_t UartDevOpen(struct file *filep)
}
struct drv_data *drv = (struct drv_data *)filep->f_vnode->data;
host = (struct UartHost *)drv->priv;
- return UartHostInit(host);
+ return UartHostRequest(host);
}
static int32_t UartDevRelease(struct file *filep)
{
@@ -59,7 +59,7 @@ static int32_t UartDevRelease(struct file *filep)
struct drv_data *drv = (struct drv_data *)filep->f_vnode->data;
host = (struct UartHost *)drv->priv;
- return UartHostDeinit(host);
+ return UartHostRelease(host);
}
static ssize_t UartDevRead(struct file *filep, char *buf, size_t count)
@@ -226,7 +226,7 @@ static void UartAddRemoveDev(struct UartHost *host, bool add)
return;
}
if (add) {
- HDF_LOGI("creat /dev/uartdev-%d", host->num);
+ HDF_LOGI("create /dev/uartdev-%d", host->num);
if (register_driver(devName, &g_uartDevFops, HDF_UART_FS_MODE, host)) {
HDF_LOGE("%s: gen /dev/uartdev-%d fail!", __func__, host->num);
OsalMemFree(devName);
diff --git a/khdf/liteos/test/BUILD.gn b/khdf/liteos/test/BUILD.gn
index b6f2934feba3e824ad7a261b4fdae92502c86485..553b67a8c8f2f08f597a7878ecf0444f62d83ca5 100755
--- a/khdf/liteos/test/BUILD.gn
+++ b/khdf/liteos/test/BUILD.gn
@@ -1,4 +1,4 @@
-# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
@@ -82,12 +82,18 @@ hdf_driver(module_name) {
sources += [
"$HDF_TEST_FRAMWORK_ROOT/platform/common/platform_device_test.c",
"$HDF_TEST_FRAMWORK_ROOT/platform/common/platform_driver_test.c",
+ "$HDF_TEST_FRAMWORK_ROOT/platform/common/platform_dumper_test.c",
"$HDF_TEST_FRAMWORK_ROOT/platform/common/platform_event_test.c",
"$HDF_TEST_FRAMWORK_ROOT/platform/common/platform_manager_test.c",
"$HDF_TEST_FRAMWORK_ROOT/platform/common/platform_queue_test.c",
- "$HDF_TEST_FRAMWORK_ROOT/platform/entry/hdf_platform_core_entry_test.c",
+ "$HDF_TEST_FRAMWORK_ROOT/platform/entry/hdf_platform_entry_test.c",
]
+ if (defined(LOSCFG_DRIVERS_HDF_PLATFORM_TRACE)) {
+ sources +=
+ [ "$HDF_TEST_FRAMWORK_ROOT/platform/common/platform_trace_test.c" ]
+ }
+
if (defined(LOSCFG_DRIVERS_HDF_PLATFORM_GPIO)) {
sources += [
"$HDF_TEST_FRAMWORK_ROOT/platform/common/gpio_driver_test.c",
@@ -242,6 +248,14 @@ hdf_driver(module_name) {
"$HDF_TEST_FRAMWORK_ROOT/platform/entry/hdf_timer_entry_test.c",
]
}
+
+ if (defined(LOSCFG_DRIVERS_HDF_PLATFORM_CAN)) {
+ sources += [
+ "$HDF_ADAPTERS_PATH/platform/can/can_virtual.c",
+ "$HDF_TEST_FRAMWORK_ROOT/platform/common/can_test.c",
+ "$HDF_TEST_FRAMWORK_ROOT/platform/config/can_test_config.c",
+ ]
+ }
}
if (defined(LOSCFG_DRIVERS_HDF_SENSOR)) {
diff --git a/khdf/liteos/test/Makefile b/khdf/liteos/test/Makefile
index 54c14125ab00878d2d6472112df4cb47ddad674a..f979c606430b5d7bb2fee9967d976c948956dde6 100755
--- a/khdf/liteos/test/Makefile
+++ b/khdf/liteos/test/Makefile
@@ -1,4 +1,4 @@
-# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
@@ -31,6 +31,7 @@ include ./test_lite.mk
MODULE_NAME := hdf_test
HDF_TEST_FRAMWORK_ROOT = $(LITEOSTOPDIR)/../../drivers/framework/test/unittest
+HDF_ADAPTERS_ROOT = $(LITEOSTOPDIR)/../../drivers/adapter
LOCAL_SRCS := $(HDF_TEST_FRAMWORK_ROOT)/common/hdf_main_test.c \
$(HDF_TEST_FRAMWORK_ROOT)/manager/sample_driver_test.c \
@@ -65,9 +66,13 @@ ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM), y)
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_driver_test.c
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_event_test.c
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_queue_test.c
+LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_dumper_test.c
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_device_test.c
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_manager_test.c
-LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/entry/hdf_platform_core_entry_test.c
+LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/entry/hdf_platform_entry_test.c
+ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_TRACE), y)
+LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_trace_test.c
+endif
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_GPIO), y)
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/gpio_test.c
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/gpio_driver_test.c
@@ -159,6 +164,10 @@ LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/timer_driver_test.c
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/timer_test.c
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/entry/hdf_timer_entry_test.c
endif
+ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_CAN), y)
+LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/can_test.c
+LOCAL_SRCS += $(HDF_ADAPTERS_ROOT)/platform/can/can_virtual.c
+endif
endif
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_REGULATOR), y)
diff --git a/khdf/liteos_m/Kconfig b/khdf/liteos_m/Kconfig
index b6adead9b5d0453426709174df580716a8cb8a9c..80ba9281fb6e8e56163103cb93f7e348a4fc5142 100644
--- a/khdf/liteos_m/Kconfig
+++ b/khdf/liteos_m/Kconfig
@@ -35,7 +35,7 @@ config DRIVERS_HDF
Answer Y to enable LiteOS support HDF.
if DRIVERS_HDF
config DRIVERS_HDF_CONFIG_MACRO
- bool "Enable HDF platform driver"
+ bool "Enable HDF config macro parser"
default n
depends on DRIVERS_HDF
help
diff --git a/khdf/liteos_m/core/BUILD.gn b/khdf/liteos_m/core/BUILD.gn
index 8b2c9b8f5f16bfe69d1a95df6a2ab7387830d9ff..9428feaf7acd50b898cbc9b5fc1695bfb6fad2cc 100644
--- a/khdf/liteos_m/core/BUILD.gn
+++ b/khdf/liteos_m/core/BUILD.gn
@@ -83,4 +83,14 @@ hdf_driver("hdf_core") {
defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) {
deps = [ "//device/board/fnlink/shields" ]
}
+ if (defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) {
+ HDF_HCS_BUILD_PATH = rebase_path(
+ "//device/board/$device_company/$device_name/liteos_m/hdf_config")
+ cmd = "if [ -f ${HDF_HCS_BUILD_PATH}/BUILD.gn ]; then echo true; else echo false; fi"
+ HAVE_HCS_BUILD_PATH =
+ exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
+ if (HAVE_HCS_BUILD_PATH) {
+ deps = [ "${HDF_HCS_BUILD_PATH}" ]
+ }
+ }
}
diff --git a/khdf/liteos_m/hdf.gni b/khdf/liteos_m/hdf.gni
index b1b631bff14c4655c0eaa26c8bb78bc334d5c8cd..18a6ee47be06799fa9aef543c50479cf306e6e31 100644
--- a/khdf/liteos_m/hdf.gni
+++ b/khdf/liteos_m/hdf.gni
@@ -41,12 +41,30 @@ template("hdf_driver") {
module_switch = true
}
- if (module_switch && defined(invoker.hcs_sources)) {
+ if (defined(invoker.macro_switch)) {
+ macro_switch = invoker.macro_switch
+ } else {
+ macro_switch = false
+ }
+
+ if (!macro_switch && module_switch && defined(invoker.hcs_sources)) {
hc_gen_hex("${target_name}_hc_gen_hex") {
sources = invoker.hcs_sources
}
}
+
+ if (macro_switch && module_switch && defined(invoker.hcs_sources)) {
+ hc_gen_macro("${target_name}_hc_gen_macro") {
+ sources = invoker.hcs_sources
+ outputs = [ "$target_gen_dir/hdf_config_macro.h" ]
+ }
+ }
+
kernel_module(target_name) {
+ if (defined(invoker.special_visibility)) {
+ visibility += invoker.special_visibility
+ }
+
forward_variables_from(invoker,
"*",
[
@@ -59,7 +77,8 @@ template("hdf_driver") {
if (defined(invoker.visibility)) {
visibility += invoker.visibility
}
- if (module_switch && defined(invoker.hcs_sources)) {
+
+ if (module_switch && !macro_switch && defined(invoker.hcs_sources)) {
hc_gen = ":${target_name}_hc_gen_hex"
generated_sources = get_target_outputs(hc_gen)
set_sources_assignment_filter([ "*.hcb" ])
@@ -74,10 +93,20 @@ template("hdf_driver") {
deps = [ hc_gen ]
}
}
+
+ if (module_switch && macro_switch && defined(invoker.hcs_sources)) {
+ hc_gen_macro = ":${target_name}_hc_gen_macro"
+ if (defined(invoker.deps)) {
+ deps += [ hc_gen_macro ]
+ } else {
+ deps = [ hc_gen_macro ]
+ }
+ }
}
}
set_defaults("hdf_driver") {
configs = [ "$HDFTOPDIR:hdf_config" ]
visibility = [ "$HDFTOPDIR:*" ]
+ visibility += [ "//drivers/adapter/*" ]
}
diff --git a/khdf/liteos_m/hdf_macro.gni b/khdf/liteos_m/hdf_macro.gni
deleted file mode 100755
index 6d6ee4b2523f9852b800343bddec9efe0ccc894d..0000000000000000000000000000000000000000
--- a/khdf/liteos_m/hdf_macro.gni
+++ /dev/null
@@ -1,85 +0,0 @@
-#
-# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
-#
-# 1. Redistributions of source code must retain the above copyright notice, this list of
-# conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice, this list
-# of conditions and the following disclaimer in the documentation and/or other materials
-# provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its contributors may be used
-# to endorse or promote products derived from this software without specific prior written
-# permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-import("//drivers/framework/tools/hc-gen/hc_gen.gni")
-import("//kernel/liteos_m/liteos.gni")
-
-HDF_FRAMEWORKS_PATH = "//drivers/framework"
-HDF_PERIPHERAL_PATH = "//drivers/peripheral"
-HDF_ADAPTER_PLATFORM_PATH = "//drivers/adapter/platform"
-
-template("hdf_driver") {
- if (defined(invoker.module_switch)) {
- forward_variables_from(invoker, [ "module_switch" ])
- } else {
- module_switch = true
- }
-
- if (module_switch && defined(invoker.hcs_sources)) {
- hc_gen_macro("${target_name}_hc_gen_macro") {
- sources = invoker.hcs_sources
- outputs = invoker.outputs
- }
- }
- kernel_module(target_name) {
- forward_variables_from(invoker,
- "*",
- [
- "configs",
- "visibility",
- ])
- if (defined(invoker.configs)) {
- configs += invoker.configs
- }
- if (defined(invoker.visibility)) {
- visibility += invoker.visibility
- }
- if (module_switch && defined(invoker.hcs_sources)) {
- hc_gen_macro = ":${target_name}_hc_gen_macro"
- generated_include = get_path_info(get_target_outputs(hc_gen_macro), "dir")
- if (defined(invoker.include_dirs)) {
- include_dirs += generated_include
- } else {
- include_dirs = generated_include
- }
- if (defined(invoker.deps)) {
- deps += [ hc_gen_macro ]
- } else {
- deps = [ hc_gen_macro ]
- }
- }
- }
-}
-
-set_defaults("hdf_driver") {
- configs = [ "$HDFTOPDIR:hdf_config" ]
- visibility = [ "$HDFTOPDIR:*" ]
- visibility += [ "//device/soc/bestechnic/bes2600/liteos_m/*" ]
- visibility += [ "//drivers/adapter/*" ]
-}
diff --git a/khdf/liteos_m/network/src/net_device_adapter.c b/khdf/liteos_m/network/src/net_device_adapter.c
index 7888835d05cc50a8c7fa3b22f1de839a13df4228..55ab63e71303416ac155239e2a993591768f18b8 100644
--- a/khdf/liteos_m/network/src/net_device_adapter.c
+++ b/khdf/liteos_m/network/src/net_device_adapter.c
@@ -71,6 +71,7 @@ static int32_t LiteNetDevInit(struct NetDeviceImpl *netDeviceImpl)
HDF_LOGI("%s Success!", __func__);
return HDF_SUCCESS;
}
+
static int32_t LiteNetDevDeInit(struct NetDeviceImpl *netDeviceImpl)
{
if (netDeviceImpl == NULL) {
diff --git a/khdf/liteos_m/network/src/netbuf_adapter.c b/khdf/liteos_m/network/src/netbuf_adapter.c
index 75bcc4b4440dda69088c27892c5eedbff76a9c55..c83308336a99320e5da4764cea216f000f89c082 100644
--- a/khdf/liteos_m/network/src/netbuf_adapter.c
+++ b/khdf/liteos_m/network/src/netbuf_adapter.c
@@ -28,6 +28,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "netbuf_adapter.h"
#include "hdf_netbuf.h"
#include "los_memory.h"
#include "lwip/prot/ethernet.h"
diff --git a/khdf/liteos_m/osal/src/osal_thread.c b/khdf/liteos_m/osal/src/osal_thread.c
index af025da61feb074c537a60e7c1f74ac83e378514..d84b29fd525031841af65abc4df77c356e2bd135 100644
--- a/khdf/liteos_m/osal/src/osal_thread.c
+++ b/khdf/liteos_m/osal/src/osal_thread.c
@@ -167,7 +167,7 @@ int32_t OsalThreadSuspend(struct OsalThread *thread)
bool flag = false;
flag = OsalCheckPara(thread);
- if (flag == false) {
+ if (!flag) {
HDF_LOGE("%s invalid parameter %d", __func__, __LINE__);
return HDF_ERR_INVALID_PARAM;
}
@@ -186,7 +186,7 @@ int32_t OsalThreadDestroy(struct OsalThread *thread)
bool flag = false;
flag = OsalCheckPara(thread);
- if (flag == false) {
+ if (!flag) {
HDF_LOGE("%s invalid parameter %d", __func__, __LINE__);
return HDF_ERR_INVALID_PARAM;
}
@@ -203,7 +203,7 @@ int32_t OsalThreadResume(struct OsalThread *thread)
bool flag = false;
flag = OsalCheckPara(thread);
- if (flag == false) {
+ if (!flag) {
HDF_LOGE("%s invalid parameter %d", __func__, __LINE__);
return HDF_ERR_INVALID_PARAM;
}
diff --git a/khdf/liteos_m/platform/BUILD.gn b/khdf/liteos_m/platform/BUILD.gn
index 6228cc04900ac6206f6a2615904b42dcc4e144a7..7a33e4cb563bc137bbb60fd1027ccb54cf808931 100755
--- a/khdf/liteos_m/platform/BUILD.gn
+++ b/khdf/liteos_m/platform/BUILD.gn
@@ -64,7 +64,10 @@ hdf_driver("hdf_platform_lite") {
}
if (defined(LOSCFG_DRIVERS_HDF_PLATFORM_PWM)) {
- sources += [ "$HDF_FRAMEWORKS_PATH/support/platform/src/pwm/pwm_core.c" ]
+ sources += [
+ "$HDF_FRAMEWORKS_PATH/support/platform/src/pwm/pwm_core.c",
+ "$HDF_FRAMEWORKS_PATH/support/platform/src/pwm/pwm_if.c",
+ ]
}
if (defined(LOSCFG_DRIVERS_HDF_PLATFORM_RTC)) {
diff --git a/platform/BUILD.gn b/platform/BUILD.gn
index 4b2029491a54f6e06f2a0487d16bb5bb92fd14c1..3aff7986ef77671ff54d6136a3a25bcd39e91a2e 100644
--- a/platform/BUILD.gn
+++ b/platform/BUILD.gn
@@ -1,31 +1,10 @@
#
-# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved.
+# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
#
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
+# This file is dual licensed: you can use it either under the terms of
+# the GPL, or the BSD license, at your option.
+# See the LICENSE file in the root of this repository for complete details.
#
-# 1. Redistributions of source code must retain the above copyright notice, this list of
-# conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice, this list
-# of conditions and the following disclaimer in the documentation and/or other materials
-# provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its contributors may be used
-# to endorse or promote products derived from this software without specific prior written
-# permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
diff --git a/platform/can/can_virtual.c b/platform/can/can_virtual.c
new file mode 100644
index 0000000000000000000000000000000000000000..1dbcf9994ab81a34c35f2bc20b2896bb8f702433
--- /dev/null
+++ b/platform/can/can_virtual.c
@@ -0,0 +1,367 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ *
+ * This file is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include
+
+#include "can/can_core.h"
+#include "device_resource_if.h"
+#include "hdf_log.h"
+#include "osal_mem.h"
+
+#define HDF_LOG_TAG can_virtual_c
+#define CAN_VIRTUAL_BUS_NUM_DFT 31
+
+struct VirtualCanCntlr {
+ struct CanCntlr cntlr;
+ uint8_t workMode;
+ uint32_t bitRate;
+ uint32_t syncJumpWidth;
+ uint32_t timeSeg1;
+ uint32_t timeSeg2;
+ uint32_t prescaler;
+ int32_t busState;
+};
+
+enum VIRTUAL_CAN_SPEED {
+ CAN_SPEED_1M = 1000UL * 1000, /* 1 MBit/sec */
+ CAN_SPEED_800K = 1000UL * 800, /* 800 kBit/sec */
+ CAN_SPEED_500K = 1000UL * 500, /* 500 kBit/sec */
+ CAN_SPEED_250K = 1000UL * 250, /* 250 kBit/sec */
+ CAN_SPEED_125K = 1000UL * 125, /* 125 kBit/sec */
+ CAN_SPEED_100K = 1000UL * 100, /* 100 kBit/sec */
+ CAN_SPEED_50K = 1000UL * 50, /* 50 kBit/sec */
+ CAN_SPEED_20K = 1000UL * 20, /* 20 kBit/sec */
+ CAN_SPEED_10K = 1000UL * 10 /* 10 kBit/sec */
+};
+
+static int32_t VirtualReadConfigFromHcs(struct VirtualCanCntlr *virtualCan)
+{
+ uint32_t value;
+ const struct DeviceResourceNode *node = NULL;
+ struct DeviceResourceIface *iface = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+
+ if (virtualCan == NULL) {
+ HDF_LOGE("%s: virtual cntlr is null", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ node = PlatformDeviceGetDrs(&virtualCan->cntlr.device);
+ if (node == NULL) {
+ HDF_LOGE("%s: properity node null", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ if (iface == NULL || iface->GetUint32 == NULL) {
+ HDF_LOGE("%s: face is invalid", __func__);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ if (iface->GetUint32(node, "bus_num", &value, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s: read bus number failed", __func__);
+ return HDF_FAILURE;
+ }
+ virtualCan->cntlr.number = (int32_t)value;
+
+ if (iface->GetUint8(node, "work_mode", &virtualCan->workMode, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s: read work mode failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ if (iface->GetUint32(node, "bit_rate", &virtualCan->bitRate, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s: read bit reate failed", __func__);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t VirtualCanMsgLoopBack(struct VirtualCanCntlr *virtualCan, const struct CanMsg *msg)
+{
+ struct CanMsg *new = NULL;
+
+ new = CanMsgObtain();
+ if (new == NULL) {
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ *new = *msg; // Yeah! this is loop back ...
+
+ virtualCan->busState = CAN_BUS_READY;
+ return CanCntlrOnNewMsg(&virtualCan->cntlr, new);
+}
+
+static int32_t VirtualCanSendMsg(struct CanCntlr *cntlr, const struct CanMsg *msg)
+{
+ struct VirtualCanCntlr *virtualCan = NULL;
+
+ if (cntlr == NULL) {
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ if (msg == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ virtualCan = (struct VirtualCanCntlr *)cntlr->device.priv;
+ if (virtualCan == NULL) {
+ HDF_LOGE("%s: private data is null", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ virtualCan->busState = CAN_BUS_BUSY;
+
+ return VirtualCanMsgLoopBack(virtualCan, msg);
+}
+
+struct VirtualSpeedConfigMap {
+ uint32_t speed;
+ uint32_t sjw;
+ uint32_t tsg1;
+ uint32_t tsg2;
+ uint32_t prescaler;
+};
+
+#define CAN_CLK 80M
+
+#define CAN_SJW_2TQ 2
+#define CAN_BS1_5TQ 5
+#define CAN_BS1_7TQ 7
+#define CAN_BS1_13TQ 13
+#define CAN_BS1_14TQ 14
+#define CAN_BS2_2TQ 2
+#define CAN_BS2_5TQ 5
+
+/*
+ * S(bit rate) = 1 / ((1 + BS1 + BS2) * TQ)
+ * TQ = Prescaler / Fclk
+ * S(bit rate) = Fclk / (Prescaler * (1 + BS1 + BS2))
+ */
+
+static const struct VirtualSpeedConfigMap g_speedMaps[] = {
+ {CAN_SPEED_1M, CAN_SJW_2TQ, CAN_BS1_5TQ, CAN_BS2_2TQ, 10 },
+ {CAN_SPEED_800K, CAN_SJW_2TQ, CAN_BS1_14TQ, CAN_BS2_5TQ, 5 },
+ {CAN_SPEED_500K, CAN_SJW_2TQ, CAN_BS1_7TQ, CAN_BS2_2TQ, 16 },
+ {CAN_SPEED_250K, CAN_SJW_2TQ, CAN_BS1_13TQ, CAN_BS2_2TQ, 20 },
+ {CAN_SPEED_125K, CAN_SJW_2TQ, CAN_BS1_13TQ, CAN_BS2_2TQ, 40 },
+ {CAN_SPEED_100K, CAN_SJW_2TQ, CAN_BS1_13TQ, CAN_BS2_2TQ, 50 },
+ {CAN_SPEED_50K, CAN_SJW_2TQ, CAN_BS1_13TQ, CAN_BS2_2TQ, 100},
+ {CAN_SPEED_20K, CAN_SJW_2TQ, CAN_BS1_13TQ, CAN_BS2_2TQ, 250},
+ {CAN_SPEED_10K, CAN_SJW_2TQ, CAN_BS1_13TQ, CAN_BS2_2TQ, 500}
+};
+
+static int32_t VirtualCanSetBitRate(struct VirtualCanCntlr *virtualCan, uint32_t speed)
+{
+ int32_t i;
+ const struct VirtualSpeedConfigMap *cfgMap;
+
+ for (i = 0; i < sizeof(g_speedMaps) / sizeof(g_speedMaps[0]); i++) {
+ if (g_speedMaps[i].speed == speed) {
+ break;
+ }
+ }
+
+ if (i >= (sizeof(g_speedMaps) / sizeof(g_speedMaps[0]))) {
+ HDF_LOGE("%s: speed: %u not support", __func__, speed);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ cfgMap = &g_speedMaps[i];
+ virtualCan->syncJumpWidth = cfgMap->sjw;
+ virtualCan->timeSeg1 = cfgMap->tsg1;
+ virtualCan->timeSeg2 = cfgMap->tsg2;
+ virtualCan->prescaler = cfgMap->prescaler;
+ virtualCan->bitRate = speed;
+ return HDF_SUCCESS;
+}
+
+static int32_t VirtualCanSetMode(struct VirtualCanCntlr *virtualCan, int32_t mode)
+{
+ switch (mode) {
+ case CAN_BUS_LOOPBACK:
+ virtualCan->workMode = CAN_BUS_LOOPBACK;
+ break;
+ default:
+ return HDF_ERR_NOT_SUPPORT;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t VirtualCanSetCfg(struct CanCntlr *cntlr, const struct CanConfig *cfg)
+{
+ int32_t ret;
+ struct VirtualCanCntlr *virtualCan = NULL;
+
+ virtualCan = (struct VirtualCanCntlr *)cntlr->device.priv;
+ if (virtualCan == NULL) {
+ HDF_LOGE("%s: private data is null", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ virtualCan->busState = CAN_BUS_RESET;
+ if ((ret = VirtualCanSetBitRate(virtualCan, cfg->speed) != HDF_SUCCESS)) {
+ HDF_LOGE("%s: set speed failed", __func__);
+ return ret;
+ }
+
+ if ((ret = VirtualCanSetMode(virtualCan, cfg->mode) != HDF_SUCCESS)) {
+ HDF_LOGE("%s: set mode failed", __func__);
+ return ret;
+ }
+
+ virtualCan->busState = CAN_BUS_READY;
+ return HDF_SUCCESS;
+}
+
+static int32_t VirtualCanGetCfg(struct CanCntlr *cntlr, struct CanConfig *cfg)
+{
+ struct VirtualCanCntlr *virtualCan = NULL;
+
+ virtualCan = (struct VirtualCanCntlr *)cntlr->device.priv;
+ if (virtualCan == NULL) {
+ HDF_LOGE("%s: private data is null", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ cfg->speed = virtualCan->bitRate;
+ cfg->mode = virtualCan->workMode;
+ return HDF_SUCCESS;
+}
+
+struct CanCntlrMethod g_virtualCanMethod = {
+ .sendMsg = VirtualCanSendMsg,
+ .setCfg = VirtualCanSetCfg,
+ .getCfg = VirtualCanGetCfg,
+};
+
+/*
+ * ! this function will not be invoked when polciy is 0
+ * ! no need to make any changes here
+ */
+static int32_t HdfVirtualCanBind(struct HdfDeviceObject *device)
+{
+ return CanServiceBind(device);
+}
+
+static void VirtualCanSetDefault(struct VirtualCanCntlr *virtualCan)
+{
+ virtualCan->cntlr.number = CAN_VIRTUAL_BUS_NUM_DFT;
+ virtualCan->workMode = CAN_BUS_LOOPBACK;
+ virtualCan->bitRate = CAN_SPEED_10K;
+}
+
+static int32_t VirtualCanInit(struct VirtualCanCntlr *virtualCan)
+{
+ int32_t ret;
+
+ HDF_LOGI("%s: enter", __func__);
+ if (virtualCan == NULL) {
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ VirtualCanSetDefault(virtualCan);
+
+ ret = VirtualReadConfigFromHcs(virtualCan);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGW("VirtualUartInit: read hcs config failed");
+ }
+
+ if ((ret = VirtualCanSetBitRate(virtualCan, virtualCan->bitRate) != HDF_SUCCESS)) {
+ HDF_LOGE("%s: set bit rate failed", __func__);
+ return ret;
+ }
+
+ if ((ret = VirtualCanSetMode(virtualCan, virtualCan->workMode) != HDF_SUCCESS)) {
+ HDF_LOGE("%s: set mode failed", __func__);
+ return ret;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t HdfVirtualCanInit(struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct VirtualCanCntlr *virtualCan = NULL;
+
+ HDF_LOGI("%s: entry", __func__);
+ if (device == NULL) {
+ HDF_LOGE("%s: device is null", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ virtualCan = (struct VirtualCanCntlr *)OsalMemCalloc(sizeof(*virtualCan));
+ if (virtualCan == NULL) {
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ virtualCan->busState = CAN_BUS_RESET;
+ ret = VirtualCanInit(virtualCan);
+ if (ret != HDF_SUCCESS) {
+ OsalMemFree(virtualCan);
+ HDF_LOGE("%s: can init error: %d", __func__, ret);
+ return ret;
+ }
+ virtualCan->busState = CAN_BUS_READY;
+
+ virtualCan->cntlr.ops = &g_virtualCanMethod;
+ virtualCan->cntlr.device.priv = virtualCan;
+ ret = CanCntlrAdd(&virtualCan->cntlr);
+ if (ret != HDF_SUCCESS) {
+ OsalMemFree(virtualCan);
+ HDF_LOGE("%s: add cntlr failed: %d", __func__, ret);
+ return ret;
+ }
+
+ ret = CanCntlrSetHdfDev(&virtualCan->cntlr, device);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGW("%s: can controller attach failed:%d", __func__, ret);
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t VirtualCanDeinit(struct VirtualCanCntlr *virtualCan)
+{
+ (void)virtualCan;
+ return HDF_SUCCESS;
+}
+
+static void HdfVirtualCanRelease(struct HdfDeviceObject *device)
+{
+ struct VirtualCanCntlr *virtualCan = NULL;
+
+ HDF_LOGI("%s: entry", __func__);
+ if (device == NULL) {
+ HDF_LOGE("%s: device is null", __func__);
+ return;
+ }
+
+ virtualCan = (struct VirtualCanCntlr *)CanCntlrFromHdfDev(device);
+ if (virtualCan == NULL) {
+ HDF_LOGE("%s: platform device not bind", __func__);
+ return;
+ }
+
+ CanServiceRelease(device);
+ (void)CanCntlrDel(&virtualCan->cntlr);
+ VirtualCanDeinit(virtualCan);
+ OsalMemFree(virtualCan);
+}
+
+static struct HdfDriverEntry g_hdfCanDriver = {
+ .moduleVersion = 1,
+ .moduleName = "can_driver_virtual",
+ .Bind = HdfVirtualCanBind,
+ .Init = HdfVirtualCanInit,
+ .Release = HdfVirtualCanRelease,
+};
+
+struct HdfDriverEntry *CanVirtualGetEntry(void)
+{
+ return &g_hdfCanDriver;
+}
+
+HDF_INIT(g_hdfCanDriver);
diff --git a/platform/gpio/BUILD.gn b/platform/gpio/BUILD.gn
index 31b7bbfd9bf0bffe6198e986d55caaa3f352a5e7..090587dc1f1abb1476126a9eeb9c5d3a5de0bbcc 100644
--- a/platform/gpio/BUILD.gn
+++ b/platform/gpio/BUILD.gn
@@ -1,31 +1,10 @@
#
-# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved.
+# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
#
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
+# This file is dual licensed: you can use it either under the terms of
+# the GPL, or the BSD license, at your option.
+# See the LICENSE file in the root of this repository for complete details.
#
-# 1. Redistributions of source code must retain the above copyright notice, this list of
-# conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice, this list
-# of conditions and the following disclaimer in the documentation and/or other materials
-# provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its contributors may be used
-# to endorse or promote products derived from this software without specific prior written
-# permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
@@ -40,9 +19,29 @@ hdf_driver(module_name) {
if (defined(LOSCFG_SOC_COMPANY_GOODIX)) {
sources += [ "gpio_gr5xx.c" ]
}
+ if (defined(LOSCFG_SOC_COMPANY_ASRMICRO)) {
+ sources += [ "gpio_asr.c" ]
+ }
+ if (defined(LOSCFG_SOC_COMPANY_WINNERMICRO)) {
+ sources += [ "gpio_wm.c" ]
+ }
+ if (defined(LOSCFG_SOC_SERIES_STM32F4xx)) {
+ sources += [ "gpio_stm32f4xx.c" ]
+ }
include_dirs = [ "." ]
- if (defined(LOSCFG_SHIELD_V200ZR_EVB_T1)) {
+ if (defined(LOSCFG_SHIELD_V200ZR_EVB_T1) &&
+ defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) {
deps = [ "//device/board/fnlink/shields" ]
}
+ if (defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) {
+ HDF_HCS_BUILD_PATH = rebase_path(
+ "//device/board/$device_company/$device_name/liteos_m/hdf_config")
+ cmd = "if [ -f ${HDF_HCS_BUILD_PATH}/BUILD.gn ]; then echo true; else echo false; fi"
+ HAVE_HCS_BUILD_PATH =
+ exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
+ if (HAVE_HCS_BUILD_PATH) {
+ deps = [ "${HDF_HCS_BUILD_PATH}" ]
+ }
+ }
}
diff --git a/platform/gpio/gpio_asr.c b/platform/gpio/gpio_asr.c
new file mode 100644
index 0000000000000000000000000000000000000000..24fe2b222aff5e893656dd8f8fb6fee88ae38243
--- /dev/null
+++ b/platform/gpio/gpio_asr.c
@@ -0,0 +1,477 @@
+/*
+ * Copyright (c) 2022 ASR Microelectronics (Shanghai) Co., Ltd. All rights reserved.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include
+#include "gpio_core.h"
+#include "hdf_log.h"
+#include "osal_irq.h"
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+#include "hcs_macro.h"
+#include "hdf_config_macro.h"
+#else
+#include "device_resource_if.h"
+#endif
+#include "duet_gpio.h"
+
+#define ASR_GPIO_TOTAL_NUM DUET_GPIO_TOTAL_NUM
+#define asr_gpio_config_t duet_gpio_config_t
+#define ASR_ANALOG_MODE DUET_ANALOG_MODE
+#define ASR_IRQ_MODE DUET_IRQ_MODE
+#define ASR_INPUT_PULL_UP DUET_INPUT_PULL_UP
+#define ASR_INPUT_PULL_DOWN DUET_INPUT_PULL_DOWN
+#define ASR_INPUT_HIGH_IMPEDANCE DUET_INPUT_HIGH_IMPEDANCE
+#define ASR_OUTPUT_PUSH_PULL DUET_OUTPUT_PUSH_PULL
+#define ASR_OUTPUT_OPEN_DRAIN_NO_PULL DUET_OUTPUT_OPEN_DRAIN_NO_PULL
+#define ASR_OUTPUT_OPEN_DRAIN_PULL_UP DUET_OUTPUT_OPEN_DRAIN_PULL_UP
+
+#define asr_gpio_dev_t duet_gpio_dev_t
+#define asr_gpio_irq_trigger_t duet_gpio_irq_trigger_t
+#define asr_gpio_irq_handler_t duet_gpio_irq_handler_t
+#define asr_gpio_cb_t duet_gpio_cb_t
+#define asr_gpio_init duet_gpio_init
+#define asr_gpio_output_high duet_gpio_output_high
+#define asr_gpio_output_low duet_gpio_output_low
+#define asr_gpio_output_toggle duet_gpio_output_toggle
+#define asr_gpio_input_get duet_gpio_input_get
+#define asr_gpio_enable_irq duet_gpio_enable_irq
+#define asr_gpio_disable_irq duet_gpio_disable_irq
+#define asr_gpio_clear_irq duet_gpio_clear_irq
+#define asr_gpio_finalize duet_gpio_finalize
+
+#define HDF_LOG_TAG GPIO_ASR
+
+struct GpioResource {
+ uint32_t pin;
+ uint32_t realPin;
+ uint32_t config;
+ uint32_t pinNum;
+ uint32_t type; /**< Type of the input event EV_KEY */
+ uint32_t code; /**< Specific code item of the input event KEY_POWER*/
+ unsigned long physBase;
+};
+
+enum GpioDeviceState {
+ GPIO_DEVICE_UNINITIALIZED = 0x0u,
+ GPIO_DEVICE_INITIALIZED = 0x1u,
+};
+
+struct GpioDevice {
+ asr_gpio_dev_t dev;
+ struct GpioResource resource;
+};
+
+static struct GpioCntlr g_gpioCntlr;
+struct OemGpioIrqHandler {
+ uint8_t port;
+ GpioIrqFunc func;
+ void *arg;
+};
+
+static asr_gpio_dev_t g_gpioPinMap[ASR_GPIO_TOTAL_NUM] = {0};
+static asr_gpio_irq_trigger_t g_gpioIrqCfg[ASR_GPIO_TOTAL_NUM] = {0};
+
+static void OemGpioIrqHdl(uint16_t *arg)
+{
+ asr_gpio_dev_t *dev = NULL;
+ uint16_t gpio = (uint16_t)arg;
+
+ dev = &g_gpioPinMap[gpio];
+ if ((uint16_t)dev->port >= ASR_GPIO_TOTAL_NUM) {
+ HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, (uint16_t)dev->port);
+ return;
+ }
+ GpioCntlrIrqCallback(&g_gpioCntlr, gpio);
+}
+
+/* dispatch */
+int32_t GpioDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ if (client == NULL || client->device == NULL || data == NULL || reply == NULL) {
+ HDF_LOGE("%s: client or client->device is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ return HDF_SUCCESS;
+}
+
+/* dev api */
+static int32_t GpioDevWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val)
+{
+ (void)cntlr;
+ uint32_t ret = 0;
+ asr_gpio_dev_t *dev = &g_gpioPinMap[gpio];
+
+ if (val) {
+ ret = asr_gpio_output_high(dev);
+ } else {
+ ret = asr_gpio_output_low(dev);
+ }
+ if (EIO == ret) {
+ HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, dev->port);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDevRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val)
+{
+ (void)cntlr;
+ uint32_t ret = 0;
+ asr_gpio_dev_t *dev = &g_gpioPinMap[gpio];
+
+ if ((cntlr == NULL) || (val == NULL)) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ ret = asr_gpio_input_get(dev, val);
+ if (EIO == ret) {
+ HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, dev->port);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDevSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t dir)
+{
+ (void)cntlr;
+ uint32_t ret = 0;
+ asr_gpio_dev_t *dev = &g_gpioPinMap[gpio];
+
+ if (cntlr == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ dev->config = (asr_gpio_config_t)dir;
+ ret = asr_gpio_init(dev);
+ if (EIO == ret) {
+ HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, dev->port);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDevGetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *dir)
+{
+ (void)cntlr;
+ uint32_t ret = 0;
+ asr_gpio_dev_t *dev = &g_gpioPinMap[gpio];
+
+ if ((cntlr == NULL) || (dir == NULL)) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ if (dev->port >= ASR_GPIO_TOTAL_NUM) {
+ HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, dev->port);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+ *dir = (uint16_t)dev->config;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mode)
+{
+ (void)cntlr;
+ asr_gpio_dev_t *dev = &g_gpioPinMap[gpio];
+
+ HDF_LOGE("%s %d, pin:%d", __func__, __LINE__, (uint16_t)dev->port);
+ if (dev->port >= ASR_GPIO_TOTAL_NUM) {
+ HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, dev->port);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ if ((mode == OSAL_IRQF_TRIGGER_RISING) || (mode == OSAL_IRQF_TRIGGER_FALLING)
+ || (mode == (OSAL_IRQF_TRIGGER_RISING | OSAL_IRQF_TRIGGER_FALLING))) {
+ g_gpioIrqCfg[gpio] = (asr_gpio_config_t)mode;
+ } else {
+ HDF_LOGE("%s %d, error mode:%d", __func__, __LINE__, mode);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDevUnSetIrq(struct GpioCntlr *cntlr, uint16_t gpio)
+{
+ (void)cntlr;
+ asr_gpio_dev_t *dev = &g_gpioPinMap[gpio];
+
+ if (dev->port >= ASR_GPIO_TOTAL_NUM) {
+ HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, dev->port);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDevEnableIrq(struct GpioCntlr *cntlr, uint16_t gpio)
+{
+ (void)cntlr;
+ asr_gpio_dev_t *dev = &g_gpioPinMap[gpio];
+
+ if ((uint16_t)dev->port >= ASR_GPIO_TOTAL_NUM) {
+ HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, (uint16_t)dev->port);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ dev->config = ASR_IRQ_MODE;
+ asr_gpio_init(dev);
+ asr_gpio_enable_irq(dev, g_gpioIrqCfg[gpio], OemGpioIrqHdl, (void *)gpio);
+ HDF_LOGE("%s %d, pin:%d", __func__, __LINE__, (uint16_t)dev->port);
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDevDisableIrq(struct GpioCntlr *cntlr, uint16_t gpio)
+{
+ (void)cntlr;
+ asr_gpio_dev_t *dev = &g_gpioPinMap[gpio];
+
+ if ((uint16_t)dev->port >= ASR_GPIO_TOTAL_NUM) {
+ HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, (uint16_t)dev->port);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+ asr_gpio_disable_irq(dev);
+
+ return HDF_SUCCESS;
+}
+
+struct GpioMethod g_GpioCntlrMethod = {
+ .request = NULL,
+ .release = NULL,
+ .write = GpioDevWrite,
+ .read = GpioDevRead,
+ .setDir = GpioDevSetDir,
+ .getDir = GpioDevGetDir,
+ .toIrq = NULL,
+ .setIrq = GpioDevSetIrq,
+ .unsetIrq = GpioDevUnSetIrq,
+ .enableIrq = GpioDevEnableIrq,
+ .disableIrq = GpioDevDisableIrq,
+};
+
+static int InitGpioDevice(struct GpioDevice *device)
+{
+ uint32_t ret = 0;
+
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ HDF_LOGE("%s %d, pin:%d, mode:%d", __func__, __LINE__, device->dev.port, device->dev.config);
+ ret = asr_gpio_init(&device->dev);
+ if (EIO == ret) {
+ HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, device->dev.port);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ return HDF_SUCCESS;
+}
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+#define PLATFORM_GPIO_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), gpio_config)
+static uint32_t GetGpioDeviceResource(struct GpioDevice *device)
+{
+ uint32_t relPin;
+ int32_t ret;
+ struct GpioResource *resource = NULL;
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ resource = &device->resource;
+ if (resource == NULL) {
+ HDF_LOGE("%s: resource is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ resource->pinNum = HCS_PROP(PLATFORM_GPIO_CONFIG, pinNum);
+ uint32_t pins[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, pin));
+ uint32_t realPins[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, realPin));
+ uint32_t configs[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, config));
+ for (size_t i = 0; i < resource->pinNum; i++) {
+ resource->pin = pins[i];
+ resource->realPin = realPins[i];
+ resource->config = configs[i];
+
+ relPin = resource->realPin;// / DECIMALNUM * OCTALNUM + resource->realPin % DECIMALNUM;
+ g_gpioPinMap[resource->pin].port = (uint8_t)relPin;
+ g_gpioPinMap[resource->pin].config = (asr_gpio_config_t)resource->config;
+ device->dev.config = (asr_gpio_config_t)resource->config;
+ resource->pin = relPin;
+ device->dev.port = relPin;
+
+ ret = InitGpioDevice(device);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("InitGpioDevice FAIL\r\n");
+ return HDF_FAILURE;
+ }
+ }
+
+ return HDF_SUCCESS;
+}
+#else
+static uint32_t GetGpioDeviceResource(
+ struct GpioDevice *device, const struct DeviceResourceNode *resourceNode)
+{
+ uint32_t relPin;
+ int32_t ret;
+ struct GpioResource *resource = NULL;
+ struct DeviceResourceIface *dri = NULL;
+ if (device == NULL || resourceNode == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ resource = &device->resource;
+ if (resource == NULL) {
+ HDF_LOGE("%s: resource is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ if (dri == NULL || dri->GetUint32 == NULL) {
+ HDF_LOGE("DeviceResourceIface is invalid");
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ if (dri->GetUint32(resourceNode, "pinNum", &resource->pinNum, 0) != HDF_SUCCESS) {
+ HDF_LOGE("gpio config read pinNum fail");
+ return HDF_FAILURE;
+ }
+
+ for (size_t i = 0; i < resource->pinNum; i++) {
+ if (dri->GetUint32ArrayElem(resourceNode, "pin", i, &resource->pin, 0) != HDF_SUCCESS) {
+ HDF_LOGE("gpio config read pin fail");
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint32ArrayElem(resourceNode, "realPin", i, &resource->realPin, 0) != HDF_SUCCESS) {
+ HDF_LOGE("gpio config read realPin fail");
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint32ArrayElem(resourceNode, "config", i, &resource->config, 0) != HDF_SUCCESS) {
+ HDF_LOGE("gpio config read config fail");
+ return HDF_FAILURE;
+ }
+
+ relPin = resource->realPin;// / DECIMALNUM * OCTALNUM + resource->realPin % DECIMALNUM;
+ g_gpioPinMap[resource->pin].port = (uint8_t)relPin;
+ g_gpioPinMap[resource->pin].config = (asr_gpio_config_t)resource->config;
+ device->dev.config = (asr_gpio_config_t)resource->config;
+ device->dev.port = relPin;
+ resource->pin = relPin;
+
+ ret = InitGpioDevice(device);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("InitGpioDevice FAIL\r\n");
+ return HDF_FAILURE;
+ }
+ }
+
+ return HDF_SUCCESS;
+}
+#endif
+
+
+static int32_t AttachGpioDevice(struct GpioCntlr *gpioCntlr, struct HdfDeviceObject *device)
+{
+ int32_t ret;
+
+ struct GpioDevice *gpioDevice = NULL;
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+ if (device == NULL) {
+#else
+ if (device == NULL || device->property == NULL) {
+#endif
+ HDF_LOGE("%s: param is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ gpioDevice = (struct GpioDevice *)OsalMemAlloc(sizeof(struct GpioDevice));
+ if (gpioDevice == NULL) {
+ HDF_LOGE("%s: OsalMemAlloc gpioDevice error", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+ ret = GetGpioDeviceResource(gpioDevice);
+#else
+ ret = GetGpioDeviceResource(gpioDevice, device->property);
+#endif
+ if (ret != HDF_SUCCESS) {
+ (void)OsalMemFree(gpioDevice);
+ return HDF_FAILURE;
+ }
+
+ (void)OsalMemFree(gpioDevice);
+ gpioCntlr->count = gpioDevice->resource.pinNum;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDriverInit(struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct GpioCntlr *gpioCntlr = NULL;
+
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ ret = PlatformDeviceBind(&g_gpioCntlr.device, device);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: bind hdf device failed:%d", __func__, ret);
+ return ret;
+ }
+
+ gpioCntlr = GpioCntlrFromHdfDev(device);
+ if (gpioCntlr == NULL) {
+ HDF_LOGE("GpioCntlrFromHdfDev fail\r\n");
+ return HDF_DEV_ERR_NO_DEVICE_SERVICE;
+ }
+
+ ret = AttachGpioDevice(gpioCntlr, device); // GpioCntlr add GpioDevice to priv
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("AttachGpioDevice fail\r\n");
+ return HDF_DEV_ERR_ATTACHDEV_FAIL;
+ }
+
+ gpioCntlr->ops = &g_GpioCntlrMethod; // register callback
+ ret = GpioCntlrAdd(gpioCntlr);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("GpioCntlrAdd fail %d\r\n", gpioCntlr->start);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+static void GpioDriverRelease(struct HdfDeviceObject *device)
+{
+ struct GpioCntlr *gpioCntlr = NULL;
+
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return;
+ }
+
+ gpioCntlr = GpioCntlrFromHdfDev(device);
+ if (gpioCntlr == NULL) {
+ HDF_LOGE("GpioCntlrFromHdfDev fail\r\n");
+ return HDF_DEV_ERR_NO_DEVICE_SERVICE;
+ }
+
+ (void)OsalMemFree(gpioCntlr->priv);
+ gpioCntlr->count = 0;
+}
+
+/* HdfDriverEntry definitions */
+struct HdfDriverEntry g_GpioDriverEntry = {
+ .moduleVersion = 1,
+ .moduleName = "ASR_GPIO_MODULE_HDF",
+ .Init = GpioDriverInit,
+ .Release = GpioDriverRelease,
+};
+HDF_INIT(g_GpioDriverEntry);
diff --git a/platform/gpio/gpio_bes.c b/platform/gpio/gpio_bes.c
old mode 100644
new mode 100755
index 4d1cc8fd730b3376cfffdf7cb7f80dbc41182c0a..5f93f7caa79b27b6e14b057c005b19e816375c3d
--- a/platform/gpio/gpio_bes.c
+++ b/platform/gpio/gpio_bes.c
@@ -1,17 +1,11 @@
/*
- * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * This file is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
+
#include
#include "gpio_core.h"
#include "hal_gpio.h"
@@ -75,26 +69,10 @@ typedef int32_t (*oem_gpio_irq_handler_t)(uint16_t gpio, void *data);
#define OCTALNUM 8
static struct GpioCntlr g_gpioCntlr;
-struct OemGpioIrqHandler {
- uint8_t port;
- GpioIrqFunc func;
- void *arg;
-};
enum HAL_GPIO_PIN_T g_gpioPinReflectionMap[HAL_GPIO_PIN_LED_NUM] = {0};
-static struct HAL_GPIO_IRQ_CFG_T g_gpioIrqCfg[HAL_GPIO_PIN_LED_NUM] = {0};
-static struct HAL_GPIO_IRQ_CFG_T HalGpioGetIrqConfig(enum HAL_GPIO_PIN_T pin)
-{
- struct HAL_GPIO_IRQ_CFG_T irqCfg;
-
- irqCfg.irq_enable = g_gpioIrqCfg[pin].irq_enable;
- irqCfg.irq_debounce = g_gpioIrqCfg[pin].irq_debounce;
- irqCfg.irq_type = g_gpioIrqCfg[pin].irq_type;
- irqCfg.irq_polarity = g_gpioIrqCfg[pin].irq_polarity;
-
- return irqCfg;
-}
+static struct HAL_GPIO_IRQ_CFG_T g_gpioIrqCfg[HAL_GPIO_PIN_LED_NUM] = {0};
static void OemGpioIrqHdl(enum HAL_GPIO_PIN_T pin)
{
@@ -277,12 +255,10 @@ static uint32_t GetGpioDeviceResource(
return HDF_FAILURE;
}
}
-
return HDF_SUCCESS;
}
#endif
-
static int32_t AttachGpioDevice(struct GpioCntlr *gpioCntlr, struct HdfDeviceObject *device)
{
int32_t ret;
@@ -308,12 +284,12 @@ static int32_t AttachGpioDevice(struct GpioCntlr *gpioCntlr, struct HdfDeviceObj
ret = GetGpioDeviceResource(gpioDevice, device->property);
#endif
if (ret != HDF_SUCCESS) {
- (void)OsalMemFree(gpioDevice);
+ OsalMemFree(gpioDevice);
return HDF_FAILURE;
}
gpioCntlr->count = gpioDevice->resource.pinNum;
-
+ gpioCntlr->priv = (void *)gpioDevice;
return HDF_SUCCESS;
}
@@ -369,7 +345,8 @@ static void GpioDriverRelease(struct HdfDeviceObject *device)
return HDF_DEV_ERR_NO_DEVICE_SERVICE;
}
- (void)OsalMemFree(gpioCntlr->priv);
+ gpioCntlr->ops = NULL;
+ OsalMemFree(gpioCntlr->priv);
gpioCntlr->count = 0;
}
@@ -394,7 +371,7 @@ static int32_t GpioDevRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val
uint16_t value;
uint16_t halGpio = g_gpioPinReflectionMap[gpio];
if ((enum HAL_GPIO_PIN_T)halGpio >= HAL_GPIO_PIN_LED_NUM) {
- HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, halGpio);
+ HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, halGpio);
return HDF_ERR_NOT_SUPPORT;
}
@@ -409,7 +386,7 @@ static int32_t GpioDevSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t di
(void)cntlr;
uint16_t halGpio = g_gpioPinReflectionMap[gpio];
if ((enum HAL_GPIO_PIN_T)halGpio >= HAL_GPIO_PIN_LED_NUM) {
- HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, halGpio);
+ HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, halGpio);
return HDF_ERR_NOT_SUPPORT;
}
@@ -424,7 +401,7 @@ static int32_t GpioDevGetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *d
uint16_t value;
uint16_t halGpio = g_gpioPinReflectionMap[gpio];
if ((enum HAL_GPIO_PIN_T)halGpio >= HAL_GPIO_PIN_LED_NUM) {
- HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, gpio);
+ HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, gpio);
return HDF_ERR_NOT_SUPPORT;
}
@@ -448,10 +425,16 @@ static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mo
} else if ((mode == OSAL_IRQF_TRIGGER_HIGH) || (mode == OSAL_IRQF_TRIGGER_LOW)) {
g_gpioIrqCfg[pin].irq_type = HAL_GPIO_IRQ_TYPE_LEVEL_SENSITIVE;
} else {
- HDF_LOGE("%s %d, error mode:%d", __func__, __LINE__, mode);
+ HDF_LOGE("%s %d, error mode:%hu", __func__, __LINE__, mode);
return HDF_ERR_NOT_SUPPORT;
}
+ if (mode == OSAL_IRQF_TRIGGER_HIGH || mode == OSAL_IRQF_TRIGGER_RISING) {
+ mode = HAL_GPIO_IRQ_POLARITY_HIGH_RISING;
+ } else {
+ mode = HAL_GPIO_IRQ_POLARITY_LOW_FALLING;
+ }
+
g_gpioIrqCfg[pin].irq_polarity = mode;
return HDF_SUCCESS;
diff --git a/platform/gpio/gpio_gr5xx.c b/platform/gpio/gpio_gr5xx.c
index 1ce446e7f78a0c3a3f5f3388362e7791999fc633..57463a43195c19d597fab640db8886f4a42b1ca1 100644
--- a/platform/gpio/gpio_gr5xx.c
+++ b/platform/gpio/gpio_gr5xx.c
@@ -1,17 +1,11 @@
/*
- * Copyright (c) 2021 GOODIX.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Copyright (c) 2021-2022 GOODIX.
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * This file is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
+
#include "app_io.h"
#include "app_gpiote.h"
#include "gpio/gpio_core.h"
diff --git a/platform/gpio/gpio_stm32f4xx.c b/platform/gpio/gpio_stm32f4xx.c
new file mode 100644
index 0000000000000000000000000000000000000000..60b4664073f35617161dfa3daf8f504f6eabfc51
--- /dev/null
+++ b/platform/gpio/gpio_stm32f4xx.c
@@ -0,0 +1,604 @@
+/*
+ * Copyright (c) 2022 Talkweb Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include
+#include "hal_gpio.h"
+#include "hal_exti.h"
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+#include "hcs_macro.h"
+#include "hdf_config_macro.h"
+#else
+#include "device_resource_if.h"
+#endif
+#include "gpio_core.h"
+#include "hdf_log.h"
+#include "osal_irq.h"
+
+#define HDF_LOG_TAG gpio_stm_c
+
+static const uint16_t g_stmRealPinMaps[STM32_GPIO_PIN_MAX] = {
+ LL_GPIO_PIN_0,
+ LL_GPIO_PIN_1,
+ LL_GPIO_PIN_2,
+ LL_GPIO_PIN_3,
+ LL_GPIO_PIN_4,
+ LL_GPIO_PIN_5,
+ LL_GPIO_PIN_6,
+ LL_GPIO_PIN_7,
+ LL_GPIO_PIN_8,
+ LL_GPIO_PIN_9,
+ LL_GPIO_PIN_10,
+ LL_GPIO_PIN_11,
+ LL_GPIO_PIN_12,
+ LL_GPIO_PIN_13,
+ LL_GPIO_PIN_14,
+ LL_GPIO_PIN_15,
+};
+
+typedef struct {
+ uint32_t group;
+ uint32_t realPin;
+ uint32_t pin;
+} GpioInflectInfo;
+
+GpioInflectInfo g_gpioPinsMap[STM32_GPIO_PIN_MAX * STM32_GPIO_GROUP_MAX] = {0};
+
+static const GPIO_TypeDef* g_gpioxMaps[STM32_GPIO_GROUP_MAX] = {
+ GPIOA,
+ GPIOB,
+ GPIOC,
+ GPIOD,
+ GPIOE,
+ GPIOF,
+ GPIOG,
+ GPIOH,
+ GPIOI,
+};
+
+static const uint32_t g_gpioExitLineMap[STM32_GPIO_PIN_MAX] = {
+ LL_EXTI_LINE_0,
+ LL_EXTI_LINE_1,
+ LL_EXTI_LINE_2,
+ LL_EXTI_LINE_3,
+ LL_EXTI_LINE_4,
+ LL_EXTI_LINE_5,
+ LL_EXTI_LINE_6,
+ LL_EXTI_LINE_7,
+ LL_EXTI_LINE_8,
+ LL_EXTI_LINE_9,
+ LL_EXTI_LINE_10,
+ LL_EXTI_LINE_11,
+ LL_EXTI_LINE_12,
+ LL_EXTI_LINE_13,
+ LL_EXTI_LINE_14,
+ LL_EXTI_LINE_15,
+};
+
+typedef struct {
+ uint32_t pin;
+ uint32_t realPin;
+ uint32_t mode;
+ uint32_t group;
+ uint32_t pull;
+ uint32_t speed;
+ uint32_t outputType;
+ uint32_t alternate;
+} GpioResource;
+
+enum GpioDeviceState {
+ GPIO_DEVICE_UNINITIALIZED = 0x0u,
+ GPIO_DEVICE_INITIALIZED = 0x1u,
+};
+
+typedef struct {
+ uint32_t pinNums;
+ GpioResource resource;
+ STM32_GPIO_GROUP group; /* gpio config */
+} GpioDevice;
+
+static struct GpioCntlr g_stmGpioCntlr;
+
+static HAL_GPIO_EXIT_CFG_T g_gpioExitCfg[STM32_GPIO_PIN_MAX * STM32_GPIO_GROUP_MAX] = {0};
+
+static void OemGpioIrqHdl(uint32_t pin)
+{
+ GpioCntlrIrqCallback(&g_stmGpioCntlr, pin);
+ return;
+}
+
+/* HdfDriverEntry method definitions */
+static int32_t GpioDriverInit(struct HdfDeviceObject *device);
+static void GpioDriverRelease(struct HdfDeviceObject *device);
+
+/* HdfDriverEntry definitions */
+struct HdfDriverEntry g_GpioDriverEntry = {
+ .moduleVersion = 1,
+ .moduleName = "ST_GPIO_MODULE_HDF",
+ .Init = GpioDriverInit,
+ .Release = GpioDriverRelease,
+};
+HDF_INIT(g_GpioDriverEntry);
+
+/* GpioMethod method definitions */
+static int32_t GpioDevWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val);
+static int32_t GpioDevRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val);
+static int32_t GpioDevSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t dir);
+static int32_t GpioDevGetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *dir);
+static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mode);
+static int32_t GpioDevUnSetIrq(struct GpioCntlr *cntlr, uint16_t gpio);
+static int32_t GpioDevEnableIrq(struct GpioCntlr *cntlr, uint16_t gpio);
+static int32_t GpioDevDisableIrq(struct GpioCntlr *cntlr, uint16_t gpio);
+
+/* GpioMethod definitions */
+struct GpioMethod g_GpioCntlrMethod = {
+ .request = NULL,
+ .release = NULL,
+ .write = GpioDevWrite,
+ .read = GpioDevRead,
+ .setDir = GpioDevSetDir,
+ .getDir = GpioDevGetDir,
+ .toIrq = NULL,
+ .setIrq = GpioDevSetIrq,
+ .unsetIrq = GpioDevUnSetIrq,
+ .enableIrq = GpioDevEnableIrq,
+ .disableIrq = GpioDevDisableIrq,
+};
+
+static void InitGpioClock(STM32_GPIO_GROUP group)
+{
+ switch (group) {
+ case STM32_GPIO_GROUP_A:
+ LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA);
+ break;
+ case STM32_GPIO_GROUP_B:
+ LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB);
+ break;
+ case STM32_GPIO_GROUP_C:
+ LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOC);
+ break;
+ case STM32_GPIO_GROUP_D:
+ LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOD);
+ break;
+ case STM32_GPIO_GROUP_E:
+ LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOE);
+ break;
+ case STM32_GPIO_GROUP_F:
+ LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOF);
+ break;
+ case STM32_GPIO_GROUP_G:
+ LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOG);
+ break;
+ case STM32_GPIO_GROUP_H:
+ LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOH);
+ break;
+ case STM32_GPIO_GROUP_I:
+ LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOI);
+ break;
+ default:
+ break;
+ }
+}
+
+static int32_t InitGpioDevice(GpioDevice* device)
+{
+ LL_GPIO_InitTypeDef gpioInitStruct = {0};
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ uint32_t halGpio = g_stmRealPinMaps[device->resource.realPin];
+ if (halGpio > LL_GPIO_PIN_15 || halGpio < LL_GPIO_PIN_0) {
+ HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, halGpio);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ /* init clock */
+ InitGpioClock(device->resource.group);
+
+ GPIO_TypeDef* goiox = g_gpioxMaps[device->resource.group];
+ if (device->resource.mode & LL_GPIO_MODE_OUTPUT) {
+ LL_GPIO_ResetOutputPin(goiox, halGpio);
+ }
+
+ gpioInitStruct.Pin = halGpio;
+ gpioInitStruct.Mode = device->resource.mode;
+ gpioInitStruct.Pull = device->resource.pull;
+ gpioInitStruct.Speed = device->resource.speed;
+ gpioInitStruct.OutputType = device->resource.outputType;
+ gpioInitStruct.Alternate = device->resource.alternate;
+ LL_GPIO_Init(goiox, &gpioInitStruct);
+
+ return HDF_SUCCESS;
+}
+
+#ifndef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+static int32_t GpioParseHcs(const struct DeviceResourceIface *dri,
+ GpioDevice *device, const struct DeviceResourceNode *resourceNode)
+{
+ GpioResource *resource = NULL;
+ resource = &device->resource;
+ if (resource == NULL) {
+ HDF_LOGE("%s: resource is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ if (dri->GetUint32(resourceNode, "pinNum", &device->pinNums, 0) != HDF_SUCCESS) {
+ HDF_LOGE("gpio config read pinNum fail");
+ return HDF_FAILURE;
+ }
+
+ for (size_t i = 0; i < device->pinNums; i++) {
+ if (dri->GetUint32ArrayElem(resourceNode, "pin", i, &resource->pin, 0) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint32ArrayElem(resourceNode, "realPin", i, &resource->realPin, 0) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint32ArrayElem(resourceNode, "mode", i, &resource->mode, 0) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint32ArrayElem(resourceNode, "speed", i, &resource->speed, 0) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint32ArrayElem(resourceNode, "pull", i, &resource->pull, 0) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint32ArrayElem(resourceNode, "output", i, &resource->outputType, 0) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint32ArrayElem(resourceNode, "group", i, &resource->group, 0) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint32ArrayElem(resourceNode, "alternate", i, &resource->alternate, 0) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ g_gpioPinsMap[resource->pin].group = resource->group;
+ g_gpioPinsMap[resource->pin].realPin = resource->realPin;
+ g_gpioPinsMap[resource->pin].pin = resource->pin;
+
+ if (InitGpioDevice(device) != HDF_SUCCESS) {
+ HDF_LOGE("InitGpioDevice FAIL\r\n");
+ return HDF_FAILURE;
+ }
+ }
+
+ return HDF_SUCCESS;
+}
+#endif
+
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+#define PLATFORM_GPIO_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), gpio_config)
+static uint32_t GetGpioDeviceResource(GpioDevice *device)
+{
+ uint32_t relPin;
+ int32_t ret;
+ GpioResource *resource = NULL;
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ resource = &device->resource;
+ if (resource == NULL) {
+ HDF_LOGE("%s: resource is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ device->pinNums = HCS_PROP(PLATFORM_GPIO_CONFIG, pinNum);
+ uint32_t pins[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, pin));
+ uint32_t realPins[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, realPin));
+ uint32_t groups[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, group));
+ uint32_t modes[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, mode));
+ uint32_t speeds[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, speed));
+ uint32_t pulls[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, pull));
+ uint32_t outputs[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, output));
+ uint32_t alternates[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, alternate));
+ for (size_t i = 0; i < device->pinNums; i++) {
+ resource->pin = pins[i];
+ resource->realPin = realPins[i];
+ resource->group = groups[i];
+ resource->mode = modes[i];
+ resource->speed = speeds[i];
+ resource->pull = pulls[i];
+ resource->outputType = outputs[i];
+ resource->alternate = alternates[i];
+ g_gpioPinsMap[resource->pin].group = resource->group;
+ g_gpioPinsMap[resource->pin].realPin = resource->realPin;
+ g_gpioPinsMap[resource->pin].pin = resource->pin;
+
+ if (InitGpioDevice(device) != HDF_SUCCESS) {
+ HDF_LOGE("InitGpioDevice FAIL\r\n");
+ return HDF_FAILURE;
+ }
+ }
+
+ return HDF_SUCCESS;
+}
+#else
+static int32_t GetGpioDeviceResource(GpioDevice *device, const struct DeviceResourceNode *resourceNode)
+{
+ int32_t ret;
+ struct DeviceResourceIface *dri = NULL;
+ if (device == NULL || resourceNode == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ if (dri == NULL || dri->GetUint32 == NULL) {
+ HDF_LOGE("DeviceResourceIface is invalid");
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ if (GpioParseHcs(dri, device, resourceNode) != HDF_SUCCESS) {
+ HDF_LOGE("gpio config parse hcs fail");
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+#endif
+
+static int32_t AttachGpioDevice(struct GpioCntlr *gpioCntlr, struct HdfDeviceObject *device)
+{
+ int32_t ret;
+
+ GpioDevice *gpioDevice = NULL;
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+ if (device == NULL) {
+#else
+ if (device == NULL || device->property == NULL) {
+#endif
+ HDF_LOGE("%s: property is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ gpioDevice = (GpioDevice *)OsalMemAlloc(sizeof(GpioDevice));
+ if (gpioDevice == NULL) {
+ HDF_LOGE("%s: OsalMemAlloc gpioDevice error", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+ ret = GetGpioDeviceResource(gpioDevice);
+#else
+ ret = GetGpioDeviceResource(gpioDevice, device->property);
+#endif
+ if (ret != HDF_SUCCESS) {
+ (void)OsalMemFree(gpioDevice);
+ return HDF_FAILURE;
+ }
+ gpioCntlr->priv = gpioDevice;
+ gpioCntlr->count = gpioDevice->pinNums;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDriverInit(struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct GpioCntlr *gpioCntlr = NULL;
+
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ ret = PlatformDeviceBind(&g_stmGpioCntlr.device, device);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: bind hdf device failed:%d", __func__, ret);
+ return ret;
+ }
+
+ gpioCntlr = GpioCntlrFromHdfDev(device);
+ if (gpioCntlr == NULL) {
+ HDF_LOGE("GpioCntlrFromHdfDev fail\r\n");
+ return HDF_DEV_ERR_NO_DEVICE_SERVICE;
+ }
+
+ ret = AttachGpioDevice(gpioCntlr, device); /* GpioCntlr add GpioDevice to priv */
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("AttachGpioDevice fail\r\n");
+ return HDF_DEV_ERR_ATTACHDEV_FAIL;
+ }
+
+ gpioCntlr->ops = &g_GpioCntlrMethod; /* register callback */
+ ret = GpioCntlrAdd(gpioCntlr);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("GpioCntlrAdd fail %d\r\n", gpioCntlr->start);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDriverBind(struct HdfDeviceObject *device)
+{
+ if (device == NULL) {
+ HDF_LOGE("device object is NULL\n");
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static void GpioDriverRelease(struct HdfDeviceObject *device)
+{
+ struct GpioCntlr *gpioCntlr = NULL;
+
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return;
+ }
+
+ gpioCntlr = GpioCntlrFromHdfDev(device);
+ if (gpioCntlr == NULL) {
+ HDF_LOGE("%s: host is NULL", __func__);
+ return;
+ }
+
+ gpioCntlr->count = 0;
+}
+
+/* dev api */
+static int32_t GpioDevWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val)
+{
+ uint16_t realPin = g_gpioPinsMap[gpio].realPin;
+ uint32_t pinReg = g_stmRealPinMaps[realPin];
+ if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) {
+ HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+ HDF_LOGE("%s %d ,write pin num %d", __func__, __LINE__, realPin);
+ GPIO_TypeDef* gpiox = g_gpioxMaps[g_gpioPinsMap[gpio].group];
+ if (val) {
+ LL_GPIO_SetOutputPin(gpiox, pinReg);
+ } else {
+ LL_GPIO_ResetOutputPin(gpiox, pinReg);
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDevRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val)
+{
+ uint16_t realPin = g_gpioPinsMap[gpio].realPin;
+ uint32_t pinReg = g_stmRealPinMaps[realPin];
+ uint16_t value = 0;
+ if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) {
+ HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ GPIO_TypeDef* gpiox = g_gpioxMaps[g_gpioPinsMap[gpio].group];
+ value = LL_GPIO_ReadInputPin(gpiox, pinReg);
+ *val = value;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDevSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t dir)
+{
+ (void)cntlr;
+ uint16_t realPin = g_gpioPinsMap[gpio].realPin;
+ uint32_t pinReg = g_stmRealPinMaps[realPin];
+ uint16_t value = 0;
+ if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) {
+ HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+ GPIO_TypeDef* gpiox = g_gpioxMaps[g_gpioPinsMap[gpio].group];
+ LL_GPIO_SetPinMode(gpiox, pinReg, dir);
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDevGetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *dir)
+{
+ (void)cntlr;
+ uint16_t realPin = g_gpioPinsMap[gpio].realPin;
+ uint32_t pinReg = g_stmRealPinMaps[realPin];
+ uint16_t value = 0;
+ if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) {
+ HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+ GPIO_TypeDef* gpiox = g_gpioxMaps[g_gpioPinsMap[gpio].group];
+ value = LL_GPIO_GetPinMode(gpiox, pinReg);
+ *dir = value;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mode)
+{
+ (void)cntlr;
+ uint16_t realPin = g_gpioPinsMap[gpio].realPin;
+ uint32_t pinReg = g_stmRealPinMaps[realPin];
+ if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) {
+ HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ if (mode == OSAL_IRQF_TRIGGER_RISING) {
+ g_gpioExitCfg[gpio].trigger = LL_EXTI_TRIGGER_RISING;
+ } else if (mode == OSAL_IRQF_TRIGGER_FALLING) {
+ g_gpioExitCfg[gpio].trigger = LL_EXTI_TRIGGER_FALLING;
+ } else {
+ HDF_LOGE("%s %d, error mode:%d", __func__, __LINE__, mode);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDevUnSetIrq(struct GpioCntlr *cntlr, uint16_t gpio)
+{
+ (void)cntlr;
+ uint16_t realPin = g_gpioPinsMap[gpio].realPin;
+ uint32_t pinReg = g_stmRealPinMaps[realPin];
+ if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) {
+ HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDevEnableIrq(struct GpioCntlr *cntlr, uint16_t gpio)
+{
+ (void)cntlr;
+ LL_EXTI_InitConfig exitInitConfig = {0};
+ uint16_t realPin = g_gpioPinsMap[gpio].realPin;
+ uint32_t pinReg = g_stmRealPinMaps[realPin];
+ if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) {
+ HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ exitInitConfig.Exithandler = OemGpioIrqHdl;
+ exitInitConfig.Gpiox = g_gpioxMaps[g_gpioPinsMap[gpio].group];
+ exitInitConfig.initType.Line_0_31 = g_gpioExitLineMap[g_gpioPinsMap[gpio].realPin];
+ exitInitConfig.initType.LineCommand = ENABLE;
+ exitInitConfig.initType.Mode = LL_EXTI_MODE_IT;
+ exitInitConfig.PinReg = pinReg;
+ exitInitConfig.initType.Trigger = g_gpioExitCfg[gpio].trigger;
+
+ LL_SETUP_EXTI(&exitInitConfig, g_gpioPinsMap[gpio].realPin, gpio, g_gpioPinsMap[gpio].group);
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDevDisableIrq(struct GpioCntlr *cntlr, uint16_t gpio)
+{
+ (void)cntlr;
+ LL_EXTI_InitConfig exitInitConfig = {0};
+ uint16_t realPin = g_gpioPinsMap[gpio].realPin;
+ uint32_t pinReg = g_stmRealPinMaps[realPin];
+ if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) {
+ HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ exitInitConfig.Exithandler = NULL;
+ exitInitConfig.Gpiox = g_gpioxMaps[g_gpioPinsMap[gpio].group];
+ exitInitConfig.initType.Line_0_31 = g_gpioExitLineMap[g_gpioPinsMap[gpio].realPin];
+ exitInitConfig.initType.LineCommand = DISABLE;
+ exitInitConfig.initType.Mode = LL_EXTI_MODE_IT;
+ exitInitConfig.PinReg = pinReg;
+ exitInitConfig.initType.Trigger = g_gpioExitCfg[gpio].trigger;
+ LL_SETUP_EXTI(&exitInitConfig, g_gpioPinsMap[gpio].realPin, gpio, g_gpioPinsMap[gpio].group);
+
+ return HDF_SUCCESS;
+}
\ No newline at end of file
diff --git a/platform/gpio/gpio_wm.c b/platform/gpio/gpio_wm.c
new file mode 100755
index 0000000000000000000000000000000000000000..4161e7403631c0321bf17c1dc6166f39738bd444
--- /dev/null
+++ b/platform/gpio/gpio_wm.c
@@ -0,0 +1,376 @@
+/*
+ * Copyright (c) 2022 Jiangsu Hoperun Software Co., Ltd.
+ *
+ * This file is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include
+#include "gpio_core.h"
+#include "gpio_if.h"
+#include "device_resource_if.h"
+#include "osal_irq.h"
+#include "hdf_log.h"
+#include "wm_io.h"
+#include "wm_gpio.h"
+
+#define DECIMALNUM 10
+#define OCTALNUM 8
+
+#define HDF_LOG_TAG gpioDriver
+#define WM_IO_MAX_GPIO_PIN_NUM 48
+
+/*
+ * Pin configuration
+ */
+enum GPIO_CONFIG {
+ ANALOG_MODE, /* Used as a function pin, input and output analog */
+ IRQ_MODE, /* Used to trigger interrupt */
+ INPUT_PULL_UP, /* Input with an internal pull-up resistor - use with devices
+ that actively drive the signal low - e.g. button connected to ground */
+ INPUT_PULL_DOWN, /* Input with an internal pull-down resistor - use with devices
+ that actively drive the signal high - e.g. button connected to a power rail */
+ INPUT_HIGH_IMPEDANCE, /* Input - must always be driven, either actively or by an external pullup resistor */
+ OUTPUT_PUSH_PULL, /* Output actively driven high and actively driven low -
+ must not be connected to other active outputs - e.g. LED output */
+ OUTPUT_OPEN_DRAIN_NO_PULL, /* Output actively driven low but is high-impedance when set high -
+ can be connected to other open-drain/open-collector outputs.
+ Needs an external pull-up resistor */
+ OUTPUT_OPEN_DRAIN_PULL_UP, /* Output actively driven low and is pulled high
+ with an internal resistor when set high -
+ can be connected to other open-drain/open-collector outputs. */
+};
+
+struct GpioResource {
+ uint32_t groupNum;
+ uint32_t realPin;
+ uint32_t config;
+ uint32_t pinNum;
+};
+
+struct GpioDevice {
+ uint8_t port; /* gpio port */
+ struct GpioResource resource;
+ enum GPIO_CONFIG config; /* gpio config */
+};
+
+typedef void (* tls_gpio_pin_orq_handler)(enum tls_io_name pin);
+
+static struct GpioCntlr gpioCntlr;
+struct wmGpioIrqHandler {
+ uint8_t port;
+};
+
+enum tls_io_name g_gpioPinReflectionMap[WM_IO_MAX_GPIO_PIN_NUM] = {0};
+static struct wmGpioIrqHandler g_wmGpioIrqHandler[WM_IO_MAX_GPIO_PIN_NUM] = {0};
+enum tls_gpio_irq_trig g_gpioIrqCfg[WM_IO_MAX_GPIO_PIN_NUM] = {0};
+
+
+GpioIrqFunc GpioIrqHdl()
+{
+ uint16_t ret;
+
+ for (size_t i = 0; i < WM_IO_MAX_GPIO_PIN_NUM; i++) {
+ ret = tls_get_gpio_irq_status(g_wmGpioIrqHandler[i].port);
+ if ((enum tls_io_name)g_gpioPinReflectionMap[i] && (ret != 0)) {
+ GpioCntlrIrqCallback(&gpioCntlr, i);
+ return HDF_SUCCESS;
+ }
+ }
+}
+
+/* dispatch */
+int32_t GpioDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ if (client == NULL || client->device == NULL || data == NULL || reply == NULL) {
+ HDF_LOGE("%s: client or client->device is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ return HDF_SUCCESS;
+}
+
+/* GpioMethod method definitions */
+static int32_t GpioDevWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val);
+static int32_t GpioDevRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val);
+static int32_t GpioDevSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t dir);
+static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mode);
+static int32_t GpioDevUnSetIrq(struct GpioCntlr *cntlr, uint16_t gpio);
+static int32_t GpioDevEnableIrq(struct GpioCntlr *cntlr, uint16_t gpio);
+static int32_t GpioDevDisableIrq(struct GpioCntlr *cntlr, uint16_t gpio);
+/* GpioMethod definitions */
+struct GpioMethod g_GpioCntlrMethod = {
+ .request = NULL,
+ .release = NULL,
+ .write = GpioDevWrite,
+ .read = GpioDevRead,
+ .setDir = GpioDevSetDir,
+ .getDir = NULL,
+ .toIrq = NULL,
+ .setIrq = GpioDevSetIrq,
+ .unsetIrq = GpioDevUnSetIrq,
+ .enableIrq = GpioDevEnableIrq,
+ .disableIrq = GpioDevDisableIrq,
+};
+
+/* dev api */
+static int32_t GpioDevWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val)
+{
+ (void)cntlr;
+ uint16_t wmGpio = g_gpioPinReflectionMap[gpio];
+ if ((enum tls_io_name)wmGpio > WM_IO_MAX_GPIO_PIN_NUM) {
+ HDF_LOGE("%s %d, error wmGpio:%d", __func__, __LINE__, wmGpio);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ tls_gpio_write((enum tls_io_name)wmGpio, val);
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDevRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val)
+{
+ (void)cntlr;
+ uint16_t value;
+ uint16_t wmGpio = g_gpioPinReflectionMap[gpio];
+ if ((enum tls_io_name)wmGpio > WM_IO_MAX_GPIO_PIN_NUM) {
+ HDF_LOGE("%s %d, error wmGpio:%d", __func__, __LINE__, wmGpio);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ value = tls_gpio_read((enum tls_io_name)wmGpio);
+ *val = value;
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDevSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t dir)
+{
+ (void)cntlr;
+ uint16_t wmGpio = g_gpioPinReflectionMap[gpio];
+ if ((enum tls_io_name)wmGpio > WM_IO_MAX_GPIO_PIN_NUM) {
+ HDF_LOGE("%s %d, error wmGpio:%d", __func__, __LINE__, wmGpio);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ switch (dir) {
+ case GPIO_DIR_OUT:
+ dir = WM_GPIO_DIR_OUTPUT;
+ break;
+ case GPIO_DIR_IN:
+ dir = WM_GPIO_DIR_INPUT;
+ break;
+ }
+
+ tls_gpio_cfg((enum tls_io_name)wmGpio, (enum tls_gpio_dir)dir, WM_GPIO_ATTR_FLOATING);
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mode)
+{
+ (void)cntlr;
+ uint16_t wmGpio = g_gpioPinReflectionMap[gpio];
+ if ((enum tls_io_name)wmGpio > WM_IO_MAX_GPIO_PIN_NUM) {
+ HDF_LOGE("%s %d, error wmGpio:%d", __func__, __LINE__, wmGpio);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ g_wmGpioIrqHandler[wmGpio].port = gpio;
+ tls_gpio_isr_register((enum tls_io_name)wmGpio, (tls_gpio_irq_callback)GpioIrqHdl, NULL);
+
+ switch (mode) {
+ case OSAL_IRQF_TRIGGER_RISING:
+ g_gpioIrqCfg[wmGpio] = WM_GPIO_IRQ_TRIG_RISING_EDGE;
+ break;
+ case OSAL_IRQF_TRIGGER_FALLING:
+ g_gpioIrqCfg[wmGpio] = WM_GPIO_IRQ_TRIG_FALLING_EDGE;
+ break;
+ case OSAL_IRQF_TRIGGER_HIGH:
+ g_gpioIrqCfg[wmGpio] = WM_GPIO_IRQ_TRIG_HIGH_LEVEL;
+ break;
+ case OSAL_IRQF_TRIGGER_LOW:
+ g_gpioIrqCfg[wmGpio] = WM_GPIO_IRQ_TRIG_LOW_LEVEL;
+ break;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDevUnSetIrq(struct GpioCntlr *cntlr, uint16_t gpio)
+{
+ (void)cntlr;
+ uint16_t wmGpio = g_gpioPinReflectionMap[gpio];
+ if ((enum tls_io_name)wmGpio > WM_IO_MAX_GPIO_PIN_NUM) {
+ HDF_LOGE("%s %d, error wmGpio:%d", __func__, __LINE__, wmGpio);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDevEnableIrq(struct GpioCntlr *cntlr, uint16_t gpio)
+{
+ (void)cntlr;
+ uint16_t wmGpio = g_gpioPinReflectionMap[gpio];
+ if ((enum tls_io_name)wmGpio > WM_IO_MAX_GPIO_PIN_NUM) {
+ HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, wmGpio);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ // config gpio interrupt
+ tls_gpio_irq_enable((enum tls_io_name)wmGpio, g_gpioIrqCfg[wmGpio]);
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDevDisableIrq(struct GpioCntlr *cntlr, uint16_t gpio)
+{
+ (void)cntlr;
+ uint16_t wmGpio = g_gpioPinReflectionMap[gpio];
+ if ((enum tls_io_name)wmGpio > WM_IO_MAX_GPIO_PIN_NUM) {
+ HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, wmGpio);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ tls_gpio_irq_disable((enum tls_io_name)wmGpio);
+ return HDF_SUCCESS;
+}
+
+static uint32_t GetGpioDeviceResource(struct GpioDevice *device,
+ const struct DeviceResourceNode *resourceNode)
+{
+ uint32_t relPin;
+ int32_t ret;
+ struct GpioResource *resource = NULL;
+ struct DeviceResourceIface *dri = NULL;
+ if (device == NULL || resourceNode == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ resource = &device->resource;
+ if (resource == NULL) {
+ HDF_LOGE("%s: resource is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ if (dri == NULL || dri->GetUint32 == NULL) {
+ HDF_LOGE("DeviceResourceIface is invalid");
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ if (dri->GetUint32(resourceNode, "groupNum", &resource->groupNum, 0) != HDF_SUCCESS) {
+ HDF_LOGE("gpio config read groupNum fail");
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint32(resourceNode, "pinNum", &resource->pinNum, 0) != HDF_SUCCESS) {
+ HDF_LOGE("gpio config read pinNum fail");
+ return HDF_FAILURE;
+ }
+
+ for (size_t i = 0; i < resource->groupNum; i++) {
+ if (dri->GetUint32ArrayElem(resourceNode, "config", i, &resource->config, 0) != HDF_SUCCESS) {
+ HDF_LOGE("gpio config read config fail");
+ return HDF_FAILURE;
+ }
+ }
+ device->config = resource->config;
+ return HDF_SUCCESS;
+}
+
+static int32_t AttachGpioDevice(struct GpioCntlr *gpioCntlr, struct HdfDeviceObject *device)
+{
+ int32_t ret;
+
+ struct GpioDevice *gpioDevice = NULL;
+ if (device == NULL || device->property == NULL) {
+ HDF_LOGE("%s: property is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ gpioDevice = (struct GpioDevice *)OsalMemAlloc(sizeof(struct GpioDevice));
+ if (gpioDevice == NULL) {
+ HDF_LOGE("%s: OsalMemAlloc gpioDevice error", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ ret = GetGpioDeviceResource(gpioDevice, device->property);
+ if (ret != HDF_SUCCESS) {
+ (void)OsalMemFree(gpioDevice);
+ return HDF_FAILURE;
+ }
+
+ gpioCntlr->count = gpioDevice->resource.pinNum;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDriverInit(struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct GpioCntlr *gpioCntlr = NULL;
+
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ gpioCntlr = GpioCntlrFromHdfDev(device);
+ if (gpioCntlr == NULL) {
+ HDF_LOGE("GpioCntlrFromHdfDev fail\r\n");
+ return HDF_DEV_ERR_NO_DEVICE_SERVICE;
+ }
+
+ ret = AttachGpioDevice(gpioCntlr, device); // GpioCntlr add GpioDevice to priv
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("AttachGpioDevice fail\r\n");
+ return HDF_DEV_ERR_ATTACHDEV_FAIL;
+ }
+
+ gpioCntlr->ops = &g_GpioCntlrMethod; // register callback
+ ret = GpioCntlrAdd(gpioCntlr);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("GpioCntlrAdd fail %d\r\n", gpioCntlr->start);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t GpioDriverBind(struct HdfDeviceObject *device)
+{
+ if (device == NULL) {
+ HDF_LOGE("Sample device object is null!");
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ gpioCntlr.device.hdfDev = device;
+ device->service = gpioCntlr.device.hdfDev;
+
+ return HDF_SUCCESS;
+}
+
+static void GpioDriverRelease(struct HdfDeviceObject *device)
+{
+ struct GpioCntlr *gpioCntlr = NULL;
+
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return;
+ }
+
+ gpioCntlr = GpioCntlrFromHdfDev(device);
+ if (gpioCntlr == NULL) {
+ HDF_LOGE("%s: host is NULL", __func__);
+ return;
+ }
+
+ gpioCntlr->ops = NULL;
+ OsalMemFree(gpioCntlr);
+}
+
+/* HdfDriverEntry definitions */
+struct HdfDriverEntry g_GpioDriverEntry = {
+ .moduleVersion = 1,
+ .moduleName = "WM_GPIO_MODULE_HDF",
+ .Bind = GpioDriverBind,
+ .Init = GpioDriverInit,
+ .Release = GpioDriverRelease,
+};
+HDF_INIT(g_GpioDriverEntry);
diff --git a/platform/i2c/BUILD.gn b/platform/i2c/BUILD.gn
index 9db0f785b96b387b5888cfe5d01350bbfa52781e..7007f7d27c4c5932d86ddbff65a25f71bc21549f 100644
--- a/platform/i2c/BUILD.gn
+++ b/platform/i2c/BUILD.gn
@@ -1,31 +1,10 @@
#
-# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved.
+# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
#
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
+# This file is dual licensed: you can use it either under the terms of
+# the GPL, or the BSD license, at your option.
+# See the LICENSE file in the root of this repository for complete details.
#
-# 1. Redistributions of source code must retain the above copyright notice, this list of
-# conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice, this list
-# of conditions and the following disclaimer in the documentation and/or other materials
-# provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its contributors may be used
-# to endorse or promote products derived from this software without specific prior written
-# permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
@@ -37,10 +16,26 @@ hdf_driver(module_name) {
if (defined(LOSCFG_SOC_COMPANY_BESTECHNIC)) {
sources += [ "i2c_bes.c" ]
}
+ if (defined(LOSCFG_SOC_COMPANY_WINNERMICRO)) {
+ sources += [ "i2c_wm.c" ]
+ }
+ if (defined(LOSCFG_SOC_SERIES_STM32F4xx)) {
+ sources += [ "i2c_stm32f4xx.c" ]
+ }
include_dirs = [ "." ]
if (defined(LOSCFG_SHIELD_V200ZR_EVB_T1) &&
defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) {
deps = [ "//device/board/fnlink/shields" ]
}
+ if (defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) {
+ HDF_HCS_BUILD_PATH = rebase_path(
+ "//device/board/$device_company/$device_name/liteos_m/hdf_config")
+ cmd = "if [ -f ${HDF_HCS_BUILD_PATH}/BUILD.gn ]; then echo true; else echo false; fi"
+ HAVE_HCS_BUILD_PATH =
+ exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
+ if (HAVE_HCS_BUILD_PATH) {
+ deps = [ "${HDF_HCS_BUILD_PATH}" ]
+ }
+ }
}
diff --git a/platform/i2c/i2c_bes.c b/platform/i2c/i2c_bes.c
index 9ffa5b1fbabde2324796340e650e77361fbce625..39597f6601333a40bbffe095b5006c4ee704a9d2 100755
--- a/platform/i2c/i2c_bes.c
+++ b/platform/i2c/i2c_bes.c
@@ -1,17 +1,11 @@
/*
- * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * This file is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
+
#include "i2c_bes.h"
#include
#include
@@ -54,25 +48,9 @@ struct I2cMethod g_i2cHostMethod = {
.transfer = i2cHostTransfer,
};
-int32_t InitI2cDevice(struct I2cDevice *device)
+static void I2cDeviceIomuxInit(uint32_t i2cId, struct I2cResource *resource)
{
- int32_t ret = -1;
- uint32_t i2cPort;
- struct I2cResource *resource = NULL;
- struct HAL_I2C_CONFIG_T *i2cConfig = NULL;
- if (device == NULL) {
- HDF_LOGE("device is NULL\r\n");
- return HDF_ERR_INVALID_PARAM;
- }
-
- resource = &device->resource;
- if (resource == NULL) {
- HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__);
- return HDF_ERR_INVALID_PARAM;
- }
-
- i2cConfig = &device->i2cCfg;
- if (i2cConfig == NULL) {
+ if (i2cId > HAL_I2C_ID_NUM || resource == NULL) {
HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__);
return HDF_ERR_INVALID_PARAM;
}
@@ -82,63 +60,51 @@ int32_t InitI2cDevice(struct I2cDevice *device)
{0, 0, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE},
};
- device->port = resource->port;
- i2cPort = device->port;
- if (i2cPort > HAL_I2C_ID_NUM) {
- HDF_LOGE("i2c port %u not support\r\n", i2cPort);
- return HDF_ERR_NOT_SUPPORT;
- }
-
- if (i2cPort == 0) {
+#ifdef LOSCFG_SOC_SERIES_BES2600
+ if (i2cId == 0) {
pinMuxI2c[0].function = HAL_IOMUX_FUNC_I2C_M0_SCL;
pinMuxI2c[1].function = HAL_IOMUX_FUNC_I2C_M0_SDA;
} else {
pinMuxI2c[0].function = HAL_IOMUX_FUNC_I2C_M1_SCL;
pinMuxI2c[1].function = HAL_IOMUX_FUNC_I2C_M1_SDA;
}
-
- if (OsalMutexInit(&device->mutex) != HDF_SUCCESS) {
- HDF_LOGE("%s %d OsalMutexInit fail\r\n", __func__, __LINE__);
- return HDF_FAILURE;
- }
-
- if (HDF_SUCCESS != OsalMutexLock(&device->mutex)) {
- HDF_LOGE("%s %d osMutexWait fail\r\n", __func__, __LINE__);
- return HDF_ERR_TIMEOUT;
+#elif defined (LOSCFG_SOC_SERIES_BES2700)
+ if (i2cId == 0) {
+ pinMuxI2c[0].function = HAL_IOMUX_FUNC_SYS_I2C_M0_SCL;
+ pinMuxI2c[1].function = HAL_IOMUX_FUNC_SYS_I2C_M0_SDA;
+ } else {
+ pinMuxI2c[0].function = HAL_IOMUX_FUNC_SYS_I2C_M1_SCL;
+ pinMuxI2c[1].function = HAL_IOMUX_FUNC_SYS_I2C_M1_SDA;
}
-
+#endif
pinMuxI2c[0].pin = resource->sclPin;
pinMuxI2c[1].pin = resource->sdaPin;
hal_iomux_init(pinMuxI2c, ARRAY_SIZE(pinMuxI2c));
-
- ret = hal_i2c_open(i2cPort, i2cConfig);
- if (ret == HDF_SUCCESS) {
- HDF_LOGD("open %u i2c succ.\r\n", i2cPort);
- }
- OsalMutexUnlock(&device->mutex);
- return ret;
}
-static int32_t HostRestI2cDevice(struct I2cDevice *device)
+int32_t InitI2cDevice(struct I2cDevice *device)
{
- int32_t ret = -1;
+ int32_t ret;
+ uint32_t i2cPort;
struct I2cResource *resource = NULL;
struct HAL_I2C_CONFIG_T *i2cConfig = NULL;
- uint32_t i2cPort;
if (device == NULL) {
- HDF_LOGE("%s %d device is null\r\n", __func__, __LINE__);
+ HDF_LOGE("device is NULL\r\n");
return HDF_ERR_INVALID_PARAM;
}
+
resource = &device->resource;
if (resource == NULL) {
HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__);
- return HDF_ERR_INVALID_OBJECT;
+ return HDF_ERR_INVALID_PARAM;
}
+
i2cConfig = &device->i2cCfg;
if (i2cConfig == NULL) {
HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__);
- return HDF_ERR_INVALID_OBJECT;
+ return HDF_ERR_INVALID_PARAM;
}
+
device->port = resource->port;
i2cPort = device->port;
if (i2cPort > HAL_I2C_ID_NUM) {
@@ -146,15 +112,28 @@ static int32_t HostRestI2cDevice(struct I2cDevice *device)
return HDF_ERR_NOT_SUPPORT;
}
- hal_i2c_close(i2cPort);
+ if (OsalMutexInit(&device->mutex) != HDF_SUCCESS) {
+ HDF_LOGE("%s %d OsalMutexInit fail\r\n", __func__, __LINE__);
+ return HDF_FAILURE;
+ }
+
+ if (HDF_SUCCESS != OsalMutexLock(&device->mutex)) {
+ HDF_LOGE("%s %d osMutexWait fail\r\n", __func__, __LINE__);
+ return HDF_ERR_TIMEOUT;
+ }
+
+ I2cDeviceIomuxInit(i2cPort, resource);
+
ret = hal_i2c_open(i2cPort, i2cConfig);
if (ret == HDF_SUCCESS) {
HDF_LOGD("open %u i2c succ.\r\n", i2cPort);
}
+ OsalMutexUnlock(&device->mutex);
return ret;
}
+
#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
-#define I2C_FIND_CONFIG(node, name, resource) \
+#define I2C_FIND_CONFIG(node, name, resource, result, tempPin) \
do { \
if (strcmp(HCS_PROP(node, match_attr), name) == 0) { \
resource->port = HCS_PROP(node, port); \
@@ -167,34 +146,35 @@ static int32_t HostRestI2cDevice(struct I2cDevice *device)
resource->useDma = HCS_PROP(node, useDma); \
resource->useSync = HCS_PROP(node, useSync); \
resource->asMaster = HCS_PROP(node, asMaster); \
+ result = HDF_SUCCESS; \
break; \
} \
} while (0)
-
#define PLATFORM_I2C_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), i2c_config)
static uint32_t GetI2cDeviceResource(struct I2cDevice *device,
const char *deviceMatchAttr)
{
- uint32_t tempPin = 0;
+ uint32_t tempPin;
+ int32_t result = HDF_FAILURE;
struct I2cResource *resource = NULL;
- if (device == NULL) {
- HDF_LOGE("device or resourceNode is NULL\r\n");
+ if (device == NULL || deviceMatchAttr == NULL) {
+ HDF_LOGE("device or deviceMatchAttr is NULL");
return HDF_ERR_INVALID_PARAM;
}
resource = &device->resource;
- if (resource == NULL) {
- HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__);
- return HDF_ERR_INVALID_OBJECT;
+#if HCS_NODE_EXISTS(PLATFORM_I2C_CONFIG)
+ HCS_FOREACH_CHILD_VARGS(PLATFORM_I2C_CONFIG, I2C_FIND_CONFIG, deviceMatchAttr, resource, result, tempPin);
+#endif
+ if (result != HDF_SUCCESS) {
+ HDF_LOGE("resourceNode %s is NULL", deviceMatchAttr);
}
-
- HCS_FOREACH_CHILD_VARGS(PLATFORM_I2C_CONFIG, I2C_FIND_CONFIG, deviceMatchAttr, resource);
- return HDF_SUCCESS;
+ return result;
}
#else
static uint32_t GetI2cDeviceResource(struct I2cDevice *device,
const struct DeviceResourceNode *resourceNode)
{
- uint32_t tempPin = 0;
+ uint32_t tempPin;
struct I2cResource *resource = NULL;
struct DeviceResourceIface *dri = NULL;
if (device == NULL || resourceNode == NULL) {
diff --git a/platform/i2c/i2c_bes.h b/platform/i2c/i2c_bes.h
old mode 100755
new mode 100644
index b4c59455a21b022010d604a665a381ec7c73507a..404e8ff60c0cae6b752044989078ca4c890549d3
--- a/platform/i2c/i2c_bes.h
+++ b/platform/i2c/i2c_bes.h
@@ -1,16 +1,9 @@
/*
- * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * This file is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#ifndef _I2C_BES_H__
@@ -18,7 +11,9 @@
#include "hal_i2c.h"
#include "hal_iomux.h"
+#ifdef CHIP_BEST2003
#include "hal_iomux_best2003.h"
+#endif
#include "device_resource_if.h"
#include "osal_mutex.h"
#ifdef __cplusplus
@@ -51,4 +46,4 @@ struct I2cDevice {
}
#endif
-#endif
\ No newline at end of file
+#endif
diff --git a/platform/i2c/i2c_stm32f4xx.c b/platform/i2c/i2c_stm32f4xx.c
new file mode 100644
index 0000000000000000000000000000000000000000..f00f9d7ab9bc46592a84fd5254d027d685b6b509
--- /dev/null
+++ b/platform/i2c/i2c_stm32f4xx.c
@@ -0,0 +1,395 @@
+/*
+ * Copyright (c) 2022 Talkweb Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+#include "hcs_macro.h"
+#include "hdf_config_macro.h"
+#else
+#include "device_resource_if.h"
+#endif
+#include "hdf_device_desc.h"
+#include "hdf_log.h"
+#include "i2c_core.h"
+#include "i2c_if.h"
+#include "osal_mutex.h"
+#include "hdf_base_hal.h"
+#include "stm32f4xx_ll_i2c.h"
+
+#define HDF_LOG_TAG "hdf_i2c"
+
+typedef enum {
+ I2C_HANDLE_NULL = 0,
+ I2C_HANDLE_1 = 1,
+ I2C_HANDLE_2 = 2,
+ I2C_HANDLE_3 = 3,
+ I2C_HANDLE_MAX = I2C_HANDLE_3
+} I2C_HANDLE;
+
+struct RealI2cResource {
+ uint8_t port;
+ uint8_t devMode;
+ uint32_t devAddr;
+ uint32_t speed;
+ struct OsalMutex mutex;
+};
+
+static bool g_I2cEnableFlg[I2C_HANDLE_MAX] = {0};
+
+static void HdfI2cInit(I2C_HANDLE i2cx, unsigned int i2cRate, unsigned int addr);
+static void HdfI2cWrite(I2C_HANDLE i2cx, unsigned char devAddr, unsigned char *buf, unsigned int len);
+static void HdfI2cRead(I2C_HANDLE i2cx, unsigned char devAddr, unsigned char *buf, unsigned int len);
+
+static int32_t I2cDriverBind(struct HdfDeviceObject *device);
+static int32_t I2cDriverInit(struct HdfDeviceObject *device);
+static void I2cDriverRelease(struct HdfDeviceObject *device);
+static int32_t I2cDataTransfer(struct I2cCntlr *cntlr, struct I2cMsg *msgs, int16_t count);
+
+struct HdfDriverEntry gI2cHdfDriverEntry = {
+ .moduleVersion = 1,
+ .moduleName = "HDF_I2C",
+ .Bind = I2cDriverBind,
+ .Init = I2cDriverInit,
+ .Release = I2cDriverRelease,
+};
+HDF_INIT(gI2cHdfDriverEntry);
+
+struct I2cMethod gI2cHostMethod = {
+ .transfer = I2cDataTransfer,
+};
+
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+#define I2C_FIND_CONFIG(node, name, resource) \
+ do { \
+ if (strcmp(HCS_PROP(node, match_attr), name) == 0) { \
+ resource->port = HCS_PROP(node, port); \
+ resource->devMode = HCS_PROP(node, devMode); \
+ resource->devAddr = HCS_PROP(node, devAddr); \
+ resource->speed = HCS_PROP(node, speed); \
+ result = HDF_SUCCESS; \
+ } \
+ } while (0)
+#define PLATFORM_CONFIG HCS_NODE(HCS_ROOT, platform)
+#define PLATFORM_I2C_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), i2c_config)
+static uint32_t GetI2cDeviceResource(struct RealI2cResource *i2cResource, const char *deviceMatchAttr)
+{
+ int32_t result = HDF_FAILURE;
+ struct RealI2cResource *resource = NULL;
+ if (i2cResource == NULL || deviceMatchAttr == NULL) {
+ HDF_LOGE("device or deviceMatchAttr is NULL\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+ resource = i2cResource;
+#if HCS_NODE_HAS_PROP(PLATFORM_CONFIG, i2c_config)
+ HCS_FOREACH_CHILD_VARGS(PLATFORM_I2C_CONFIG, I2C_FIND_CONFIG, deviceMatchAttr, resource);
+#endif
+ if (result != HDF_SUCCESS) {
+ HDF_LOGE("resourceNode %s is NULL\r\n", deviceMatchAttr);
+ } else {
+ HdfI2cInit(i2cResource->port, i2cResource->speed, i2cResource->devAddr);
+ }
+ return result;
+}
+#else
+static int32_t GetI2cDeviceResource(struct RealI2cResource *i2cResource, const struct DeviceResourceNode *resourceNode)
+{
+ if (i2cResource == NULL || resourceNode == NULL) {
+ HDF_LOGE("[%s]: param is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ struct DeviceResourceIface *dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ if (dri == NULL || dri->GetUint8 == NULL || dri->GetUint32 == NULL || dri->GetUint32Array == NULL) {
+ HDF_LOGE("DeviceResourceIface is invalid\r\n");
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ if (dri->GetUint8(resourceNode, "port", &i2cResource->port, 0) != HDF_SUCCESS) {
+ HDF_LOGE("i2c config port fail\r\n");
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint8(resourceNode, "devMode", &i2cResource->devMode, 0) != HDF_SUCCESS) {
+ HDF_LOGE("i2c config devMode fail\r\n");
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint32(resourceNode, "devAddr", &i2cResource->devAddr, 0) != HDF_SUCCESS) {
+ HDF_LOGE("i2c config devAddr fail\r\n");
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint32(resourceNode, "speed", &i2cResource->speed, 0) != HDF_SUCCESS) {
+ HDF_LOGE("i2c config speed fail\r\n");
+ return HDF_FAILURE;
+ }
+
+ HdfI2cInit(i2cResource->port, i2cResource->speed, i2cResource->devAddr);
+
+ return HDF_SUCCESS;
+}
+#endif
+
+static int32_t AttachI2cDevice(struct I2cCntlr *host, struct HdfDeviceObject *device)
+{
+ int32_t ret = HDF_FAILURE;
+
+ if (host == NULL || device == NULL) {
+ HDF_LOGE("[%s]: param is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ struct RealI2cResource *i2cResource = (struct RealI2cResource *)OsalMemAlloc(sizeof(struct RealI2cResource));
+ if (i2cResource == NULL) {
+ HDF_LOGE("[%s]: OsalMemAlloc RealI2cResource fail\r\n", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+ memset_s(i2cResource, sizeof(struct RealI2cResource), 0, sizeof(struct RealI2cResource));
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+ ret = GetI2cDeviceResource(i2cResource, device->deviceMatchAttr);
+#else
+ ret = GetI2cDeviceResource(i2cResource, device->property);
+#endif
+ if (ret != HDF_SUCCESS) {
+ OsalMemFree(i2cResource);
+ return HDF_FAILURE;
+ }
+
+ host->busId = i2cResource->port;
+ host->priv = i2cResource;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t I2cDataTransfer(struct I2cCntlr *cntlr, struct I2cMsg *msgs, int16_t count)
+{
+ if (cntlr == NULL || msgs == NULL || cntlr->priv == NULL) {
+ HDF_LOGE("[%s]: I2cDataTransfer param is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ if (count <= 0) {
+ HDF_LOGE("[%s]: I2cDataTransfer count err\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ struct RealI2cResource *device = (struct I2cDevice *)cntlr->priv;
+ if (device == NULL) {
+ HDF_LOGE("%s: I2cDevice is NULL\r\n", __func__);
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+
+ struct I2cMsg *msg = NULL;
+ if (HDF_SUCCESS != OsalMutexLock(&device->mutex)) {
+ HDF_LOGE("[%s]: OsalMutexLock fail\r\n", __func__);
+ return HDF_ERR_TIMEOUT;
+ }
+
+ for (int32_t i = 0; i < count; i++) {
+ msg = &msgs[i];
+ if (msg->flags == I2C_FLAG_READ) {
+ HdfI2cRead(device->port, msg->addr, msg->buf, msg->len);
+ } else {
+ HdfI2cWrite(device->port, msg->addr, msg->buf, msg->len);
+ }
+ }
+ OsalMutexUnlock(&device->mutex);
+
+ return count;
+}
+
+static int32_t I2cDriverBind(struct HdfDeviceObject *device)
+{
+ if (device == NULL) {
+ HDF_LOGE("[%s]: I2c device is NULL\r\n", __func__);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t I2cDriverInit(struct HdfDeviceObject *device)
+{
+ int32_t ret = HDF_FAILURE;
+ struct I2cCntlr *host = NULL;
+ if (device == NULL) {
+ HDF_LOGE("[%s]: I2c device is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ host = (struct I2cCntlr *)OsalMemAlloc(sizeof(struct I2cCntlr));
+ if (host == NULL) {
+ HDF_LOGE("[%s]: malloc host is NULL\r\n", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ memset_s(host, sizeof(struct I2cCntlr), 0, sizeof(struct I2cCntlr));
+ host->ops = &gI2cHostMethod;
+ device->priv = (void *)host;
+
+ ret = AttachI2cDevice(host, device);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("[%s]: AttachI2cDevice error, ret = %d\r\n", __func__, ret);
+ I2cDriverRelease(device);
+ return HDF_DEV_ERR_ATTACHDEV_FAIL;
+ }
+
+ ret = I2cCntlrAdd(host);
+ if (ret != HDF_SUCCESS) {
+ I2cDriverRelease(device);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static void I2cDriverRelease(struct HdfDeviceObject *device)
+{
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL\r\n", __func__);
+ return;
+ }
+
+ struct I2cCntlr *i2cCntrl = device->priv;
+ if (i2cCntrl == NULL || i2cCntrl->priv == NULL) {
+ HDF_LOGE("%s: i2cCntrl is NULL\r\n", __func__);
+ return;
+ }
+ i2cCntrl->ops = NULL;
+ struct RealI2cResource *i2cDevice = (struct I2cDevice *)i2cCntrl->priv;
+ OsalMemFree(i2cCntrl);
+
+ if (i2cDevice != NULL) {
+ OsalMutexDestroy(&i2cDevice->mutex);
+ OsalMemFree(i2cDevice);
+ }
+}
+
+static I2C_TypeDef *GetLLI2cHandlerMatch(I2C_HANDLE i2cx)
+{
+ if (i2cx > I2C_HANDLE_MAX) {
+ printf("ERR: GetLLI2cClkMatch fail, param match fail\r\n");
+ return NULL;
+ }
+
+ switch (i2cx) {
+ case I2C_HANDLE_1:
+ return (I2C_TypeDef *)I2C1;
+ case I2C_HANDLE_2:
+ return (I2C_TypeDef *)I2C2;
+ case I2C_HANDLE_3:
+ return (I2C_TypeDef *)I2C3;
+ default:
+ printf("ERR: GetLLI2cClkMatch fail, handler match fail\r\n");
+ return NULL;
+ }
+}
+
+static bool EnableLLI2cClock(I2C_TypeDef *i2cx)
+{
+ if (i2cx == I2C1) {
+ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1);
+ return true;
+ } else if (i2cx == I2C2) {
+ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C2);
+ return true;
+ } else if (i2cx == I2C3) {
+ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C3);
+ return true;
+ } else {
+ printf("EnableI2cClock fail, i2cx match fail\r\n");
+ return false;
+ }
+}
+
+static void HdfI2cInit(I2C_HANDLE i2cx, unsigned int i2cRate, unsigned int addr)
+{
+ LL_I2C_InitTypeDef I2C_InitStruct = {0};
+ I2C_TypeDef *myI2c = GetLLI2cHandlerMatch(i2cx);
+ if (myI2c == NULL) {
+ return;
+ }
+
+ EnableLLI2cClock(myI2c);
+ LL_I2C_DisableOwnAddress2(myI2c);
+ LL_I2C_DisableGeneralCall(myI2c);
+ LL_I2C_EnableClockStretching(myI2c);
+ I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C;
+ I2C_InitStruct.ClockSpeed = i2cRate;
+ I2C_InitStruct.DutyCycle = LL_I2C_DUTYCYCLE_2;
+ I2C_InitStruct.OwnAddress1 = addr;
+ I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK;
+ I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT;
+ LL_I2C_Init(myI2c, &I2C_InitStruct);
+ LL_I2C_SetOwnAddress2(myI2c, 0);
+
+ g_I2cEnableFlg[i2cx] = true;
+}
+
+static void HdfI2cWrite(I2C_HANDLE i2cx, unsigned char devAddr, unsigned char *buf, unsigned int len)
+{
+ if (g_I2cEnableFlg[i2cx] != true) {
+ printf("I2C_WriteByte err, Please initialize first!");
+ return;
+ }
+
+ I2C_TypeDef *myI2c = GetLLI2cHandlerMatch(i2cx);
+ if (myI2c == NULL) {
+ return;
+ }
+
+ while (LL_I2C_IsActiveFlag_BUSY(myI2c));
+
+ LL_I2C_GenerateStartCondition(myI2c);
+ while (LL_I2C_IsActiveFlag_SB(myI2c) == RESET);
+
+ LL_I2C_TransmitData8(myI2c, (devAddr << 1));
+ while (LL_I2C_IsActiveFlag_TXE(myI2c) == RESET);
+
+ LL_I2C_ClearFlag_ADDR(myI2c);
+ while (LL_I2C_IsActiveFlag_TXE(myI2c) == RESET);
+
+ for (unsigned int i = 0; i < len; i++) {
+ LL_I2C_TransmitData8(myI2c, buf[i]);
+ while (LL_I2C_IsActiveFlag_TXE(myI2c) == RESET);
+ }
+
+ LL_I2C_GenerateStopCondition(myI2c);
+}
+
+static void HdfI2cRead(I2C_HANDLE i2cx, unsigned char devAddr, unsigned char *buf, unsigned int len)
+{
+ if (g_I2cEnableFlg[i2cx] != true) {
+ printf("I2C_ReadByte err, Please initialize first!");
+ return;
+ }
+
+ I2C_TypeDef *myI2c = GetLLI2cHandlerMatch(i2cx);
+ if (myI2c == NULL) {
+ return;
+ }
+
+ while (LL_I2C_IsActiveFlag_BUSY(myI2c));
+
+ LL_I2C_GenerateStartCondition(myI2c);
+ while (LL_I2C_IsActiveFlag_SB(myI2c) == RESET);
+
+ LL_I2C_TransmitData8(myI2c, ((devAddr << 1) | 1));
+ while ((LL_I2C_IsActiveFlag_ADDR(myI2c) == RESET) || (LL_I2C_IsActiveFlag_MSL(myI2c) == RESET) ||
+ (LL_I2C_IsActiveFlag_BUSY(myI2c) == RESET));
+
+ for (unsigned int i = 0; i < len; i++) {
+ if (i < len - 1) {
+ LL_I2C_AcknowledgeNextData(myI2c, LL_I2C_ACK);
+ } else {
+ LL_I2C_AcknowledgeNextData(myI2c, LL_I2C_NACK);
+ }
+ while (LL_I2C_IsActiveFlag_RXNE(myI2c) == RESET);
+ buf[i] = LL_I2C_ReceiveData8(myI2c);
+ }
+ LL_I2C_GenerateStopCondition(myI2c);
+}
\ No newline at end of file
diff --git a/platform/i2c/i2c_wm.c b/platform/i2c/i2c_wm.c
new file mode 100755
index 0000000000000000000000000000000000000000..e87dd774db099dd70090fc43a4396bcf2a886f3e
--- /dev/null
+++ b/platform/i2c/i2c_wm.c
@@ -0,0 +1,344 @@
+/*
+ * Copyright (c) 2022 Jiangsu Hoperun Software Co., Ltd.
+ *
+ * This file is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include
+#include
+#include "i2c_core.h"
+#include "i2c_if.h"
+#include "wm_i2c.h"
+#include "wm_gpio_afsel.h"
+#include "device_resource_if.h"
+#include "osal_mutex.h"
+
+#define DEC_NUM 10
+#define GROUP_PIN_NUM 8
+#define I2C_INVALID_ADDR 0xFFFF
+#define HAL_I2C_ID_NUM 1
+
+struct I2cResource {
+ uint32_t port;
+ uint32_t sclPin;
+ uint32_t sdaPin;
+ uint32_t speed;
+};
+
+struct I2cDevice {
+ uint16_t devAddr; /**< slave device addr */
+ uint32_t addressWidth; /**< Addressing mode: 7 bit or 10 bit */
+ struct OsalMutex mutex;
+ uint32_t port;
+ struct I2cResource resource;
+};
+
+/* HdfDriverEntry method definitions */
+static int32_t i2cDriverBind(struct HdfDeviceObject *device);
+static int32_t i2cDriverInit(struct HdfDeviceObject *device);
+static void i2cDriverRelease(struct HdfDeviceObject *device);
+
+/* HdfDriverEntry definitions */
+struct HdfDriverEntry g_i2cDriverEntry = {
+ .moduleVersion = 1,
+ .moduleName = "W800_I2C_MODULE_HDF",
+ .Bind = i2cDriverBind,
+ .Init = i2cDriverInit,
+ .Release = i2cDriverRelease,
+};
+
+// Initialize HdfDriverEntry
+HDF_INIT(g_i2cDriverEntry);
+
+/* I2cHostMethod method definitions */
+static int32_t i2cHostTransfer(struct I2cCntlr *cntlr, struct I2cMsg *msgs, int16_t count);
+
+struct I2cMethod g_i2cHostMethod = {
+ .transfer = i2cHostTransfer,
+};
+
+int32_t InitI2cDevice(struct I2cDevice *device)
+{
+ int32_t ret = -1;
+ uint32_t i2cPort;
+ struct I2cResource *resource = NULL;
+
+ if (device == NULL) {
+ HDF_LOGE("device is NULL\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ resource = &device->resource;
+ device->port = resource->port;
+ i2cPort = device->port;
+ if (i2cPort >= HAL_I2C_ID_NUM) {
+ HDF_LOGE("i2c port %u not support\r\n", i2cPort);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ if (OsalMutexInit(&device->mutex) != HDF_SUCCESS) {
+ HDF_LOGE("%s %d OsalMutexInit fail\r\n", __func__, __LINE__);
+ return HDF_FAILURE;
+ }
+
+ if (HDF_SUCCESS != OsalMutexLock(&device->mutex)) {
+ HDF_LOGE("%s %d osMutexWait fail\r\n", __func__, __LINE__);
+ return HDF_ERR_TIMEOUT;
+ }
+
+ if ((resource->sclPin == WM_IO_PA_01) && (resource->sdaPin == WM_IO_PA_04)) {
+ wm_i2c_scl_config(WM_IO_PA_01);
+ wm_i2c_sda_config(WM_IO_PA_04);
+ } else {
+ HDF_LOGE("%s %d scl sda pin fail\r\n", __func__, __LINE__);
+ OsalMutexUnlock(&device->mutex);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ tls_i2c_init(resource->speed);
+ OsalMutexUnlock(&device->mutex);
+ return HDF_SUCCESS;
+}
+
+static int32_t HostRestI2cDevice(struct I2cDevice *device)
+{
+ int32_t ret = -1;
+ struct I2cResource *resource = NULL;
+ uint32_t i2cPort;
+
+ if (device == NULL) {
+ HDF_LOGE("%s %d device is null\r\n", __func__, __LINE__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ resource = &device->resource;
+ if (resource == NULL) {
+ HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ device->port = resource->port;
+ i2cPort = device->port;
+ if (i2cPort > HAL_I2C_ID_NUM) {
+ HDF_LOGE("i2c port %u not support\r\n", i2cPort);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static uint32_t GetI2cDeviceResource(struct I2cDevice *device,
+ const struct DeviceResourceNode *resourceNode)
+{
+ uint32_t tempPin = 0;
+ struct I2cResource *resource = NULL;
+ struct DeviceResourceIface *dri = NULL;
+ if (device == NULL || resourceNode == NULL) {
+ HDF_LOGE("device or resourceNode is NULL\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+ resource = &device->resource;
+ if (resource == NULL) {
+ HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ if (dri == NULL || dri->GetUint32 == NULL) {
+ HDF_LOGE("DeviceResourceIface is invalid\r\n");
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ if (dri->GetUint32(resourceNode, "port", &resource->port, 0) != HDF_SUCCESS) {
+ HDF_LOGE("i2c config port fail\r\n");
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint32(resourceNode, "sclPin", &tempPin, 0) != HDF_SUCCESS) {
+ HDF_LOGE("i2c config sclPin fail\r\n");
+ return HDF_FAILURE;
+ }
+ resource->sclPin = ((tempPin / DEC_NUM) * GROUP_PIN_NUM) + (tempPin % DEC_NUM);
+
+ if (dri->GetUint32(resourceNode, "sdaPin", &tempPin, 0) != HDF_SUCCESS) {
+ HDF_LOGE("i2c config sdaPin fail\r\n");
+ return HDF_FAILURE;
+ }
+ resource->sdaPin = ((tempPin / DEC_NUM) * GROUP_PIN_NUM) + (tempPin % DEC_NUM);
+
+ if (dri->GetUint32(resourceNode, "speed", &resource->speed, 0) != HDF_SUCCESS) {
+ HDF_LOGE("i2c config speed fail\r\n");
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t AttachI2cDevice(struct I2cCntlr *host, struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct I2cDevice *i2cDevice = NULL;
+ struct I2cResource *resource = NULL;
+
+ if (device == NULL || host == NULL) {
+ HDF_LOGE("%s: device or host is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ i2cDevice = (struct I2cDevice *)OsalMemAlloc(sizeof(struct I2cDevice));
+ if (i2cDevice == NULL) {
+ HDF_LOGE("%s: OsalMemAlloc i2cDevice error\r\n", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+ (void)memset_s(i2cDevice, sizeof(struct I2cDevice), 0, sizeof(struct I2cDevice));
+ ret = GetI2cDeviceResource(i2cDevice, device->property);
+ if (ret != HDF_SUCCESS) {
+ OsalMemFree(i2cDevice);
+ return HDF_FAILURE;
+ }
+ resource = &i2cDevice->resource;
+ if (resource == NULL) {
+ HDF_LOGE("%s %d: invalid parameter\r\n", __func__, __LINE__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ host->priv = i2cDevice;
+ host->busId = i2cDevice->port;
+
+ return InitI2cDevice(i2cDevice);
+}
+
+static int32_t i2cDriverInit(struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct I2cCntlr *host = NULL;
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ host = (struct I2cCntlr *)OsalMemAlloc(sizeof(struct I2cCntlr));
+ if (host == NULL) {
+ HDF_LOGE("%s: host is NULL\r\n", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+ (void)memset_s(host, sizeof(struct I2cCntlr), 0, sizeof(struct I2cCntlr));
+ host->ops = &g_i2cHostMethod;
+ device->priv = (void *)host;
+ ret = AttachI2cDevice(host, device);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: attach error\r\n", __func__);
+ i2cDriverRelease(device);
+ return HDF_DEV_ERR_ATTACHDEV_FAIL;
+ }
+ ret = I2cCntlrAdd(host);
+ if (ret != HDF_SUCCESS) {
+ i2cDriverRelease(device);
+ return HDF_FAILURE;
+ }
+ return ret;
+}
+
+static int32_t i2cDriverBind(struct HdfDeviceObject *device)
+{
+ if (device == NULL) {
+ HDF_LOGE("%s: I2c device object is NULL\r\n", __func__);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+static void i2cDriverRelease(struct HdfDeviceObject *device)
+{
+ struct I2cCntlr *i2cCntrl = NULL;
+ struct I2cDevice *i2cDevice = NULL;
+
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL\r\n", __func__);
+ return;
+ }
+ i2cCntrl = device->priv;
+ if (i2cCntrl == NULL || i2cCntrl->priv == NULL) {
+ HDF_LOGE("%s: i2cCntrl is NULL\r\n", __func__);
+ return;
+ }
+ i2cCntrl->ops = NULL;
+ i2cDevice = (struct I2cDevice *)i2cCntrl->priv;
+ OsalMemFree(i2cCntrl);
+
+ if (i2cDevice != NULL) {
+ OsalMutexDestroy(&i2cDevice->mutex);
+ OsalMemFree(i2cDevice);
+ }
+}
+
+static int32_t i2c_send(struct I2cMsg *msg)
+{
+ uint16_t len;
+ uint8_t ifack, ifstop, ifstart;
+
+ len = msg->len;
+ ifstop = 0;
+ if (msg->flags & I2C_FLAG_READ) {
+ ifack = msg->flags & I2C_FLAG_READ_NO_ACK ? 0 : 1;
+ for (int32_t j = 0; j < len; j++) {
+ if (((msg->flags & I2C_FLAG_STOP) && j) == (len - 1)) {
+ ifstop = 1;
+ }
+ msg->buf[j] = tls_i2c_read_byte(ifack, ifstop);
+ }
+ } else {
+ ifack = msg->flags & I2C_FLAG_IGNORE_NO_ACK ? 0 : 1;
+ for (int32_t j = 0; j < len; j++) {
+ if (((msg->flags & I2C_FLAG_NO_START) == 0) && (j == 0)) {
+ ifstart = 1;
+ }
+ tls_i2c_write_byte(msg->buf[j], ifstart);
+ if (ifack) {
+ tls_i2c_wait_ack();
+ }
+ }
+ }
+}
+
+static int32_t i2c_transfer(struct I2cDevice *device, struct I2cMsg *msgs, int16_t count)
+{
+ int ret;
+ struct I2cMsg *msg = NULL;
+
+ uint32_t i2cPort;
+ if (device == NULL || msgs == NULL) {
+ HDF_LOGE("%s: device or msgs is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ i2cPort = (uint32_t)device->port;
+ if (i2cPort > HAL_I2C_ID_NUM) {
+ HDF_LOGE("i2c port %u not support\r\n", i2cPort);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+ if (HDF_SUCCESS != OsalMutexLock(&device->mutex)) {
+ HDF_LOGE("%s %d OsalMutexTimedLock fail\r\n", __func__, __LINE__);
+ return HDF_ERR_TIMEOUT;
+ }
+ for (int32_t i = 0; i < count; i++) {
+ msg = &msgs[i];
+ i2c_send(msg);
+ }
+ OsalMutexUnlock(&device->mutex);
+ return count;
+}
+
+static int32_t i2cHostTransfer(struct I2cCntlr *cntlr, struct I2cMsg *msgs, int16_t count)
+{
+ struct I2cDevice *device = NULL;
+ if (cntlr == NULL || msgs == NULL || cntlr->priv == NULL) {
+ HDF_LOGE("%s: I2cCntlr or msgs is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ device = (struct I2cDevice *)cntlr->priv;
+ if (device == NULL) {
+ HDF_LOGE("%s: I2cDevice is NULL\r\n", __func__);
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+
+ return i2c_transfer(device, msgs, count);
+}
diff --git a/platform/pwm/BUILD.gn b/platform/pwm/BUILD.gn
index a9ce95429560afc88dbf66c09bfd919c93675e6c..5daedb61b92061c3f3c8de593d2f9ea08a5e4859 100644
--- a/platform/pwm/BUILD.gn
+++ b/platform/pwm/BUILD.gn
@@ -1,31 +1,10 @@
#
-# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved.
+# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
#
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
+# This file is dual licensed: you can use it either under the terms of
+# the GPL, or the BSD license, at your option.
+# See the LICENSE file in the root of this repository for complete details.
#
-# 1. Redistributions of source code must retain the above copyright notice, this list of
-# conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice, this list
-# of conditions and the following disclaimer in the documentation and/or other materials
-# provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its contributors may be used
-# to endorse or promote products derived from this software without specific prior written
-# permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
@@ -37,10 +16,26 @@ hdf_driver(module_name) {
if (defined(LOSCFG_SOC_COMPANY_BESTECHNIC)) {
sources += [ "pwm_bes.c" ]
}
+ if (defined(LOSCFG_SOC_COMPANY_WINNERMICRO)) {
+ sources += [ "pwm_wm.c" ]
+ }
+ if (defined(LOSCFG_SOC_SERIES_STM32F4xx)) {
+ sources += [ "pwm_stm32f4xx.c" ]
+ }
include_dirs = [ "." ]
if (defined(LOSCFG_SHIELD_V200ZR_EVB_T1) &&
defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) {
deps = [ "//device/board/fnlink/shields" ]
}
+ if (defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) {
+ HDF_HCS_BUILD_PATH = rebase_path(
+ "//device/board/$device_company/$device_name/liteos_m/hdf_config")
+ cmd = "if [ -f ${HDF_HCS_BUILD_PATH}/BUILD.gn ]; then echo true; else echo false; fi"
+ HAVE_HCS_BUILD_PATH =
+ exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
+ if (HAVE_HCS_BUILD_PATH) {
+ deps = [ "${HDF_HCS_BUILD_PATH}" ]
+ }
+ }
}
diff --git a/platform/pwm/pwm_bes.c b/platform/pwm/pwm_bes.c
index 435298120ad7f20b940f3d5859eb2ede86f642d4..386e7809664d24555486cdc11c5d1bb10eb1055d 100755
--- a/platform/pwm/pwm_bes.c
+++ b/platform/pwm/pwm_bes.c
@@ -1,24 +1,17 @@
/*
- * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * This file is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
+
#include "pwm_bes.h"
#include
#include
#include "hdf_device_desc.h"
#include "hal_trace.h"
#include "hal_timer.h"
-#include "hal_iomux.h"
#include "pwm_core.h"
#include "hdf_log.h"
#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
@@ -28,7 +21,13 @@
#include "device_resource_if.h"
#endif
+#if defined (LOSCFG_SOC_SERIES_BES2700)
+#define PWM_MAX_FUNCTION 4
+#elif defined (LOSCFG_SOC_SERIES_BES2600)
+#include "hal_iomux.h"
#define PWM_MAX_FUNCTION 8
+#endif
+
#define UNTIL_NAN0SECONDS 1000000000
#define PERCENT 100
#define DEC_TEN 10
@@ -39,10 +38,12 @@ static uint32_t g_pwmFunction[PWM_MAX_FUNCTION] = {
HAL_IOMUX_FUNC_PWM1,
HAL_IOMUX_FUNC_PWM2,
HAL_IOMUX_FUNC_PWM3,
+#if defined (LOSCFG_SOC_SERIES_BES2600)
HAL_IOMUX_FUNC_PWM4,
HAL_IOMUX_FUNC_PWM5,
HAL_IOMUX_FUNC_PWM6,
HAL_IOMUX_FUNC_PWM7,
+#endif
};
static int32_t PwmDevSetConfig(struct PwmDev *pwm, struct PwmConfig *config);
@@ -60,7 +61,7 @@ static int InitPwmDevice(struct PwmDev *host)
struct PwmDevice *pwmDevice = NULL;
struct PwmResource *resource = NULL;
if (host == NULL || host->priv == NULL) {
- HDF_LOGE("%s: invaild parameter\r\n", __func__);
+ HDF_LOGE("%s: invalid parameter\r\n", __func__);
return HDF_ERR_INVALID_PARAM;
}
pwmDevice = (struct PwmDevice *)host->priv;
@@ -88,8 +89,34 @@ static int InitPwmDevice(struct PwmDev *host)
}
#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
-static uint32_t GetPwmDeviceResource(struct PwmDevice *device)
+#define PWM_FIND_CONFIG(node, name, resource) \
+ do { \
+ if (strcmp(HCS_PROP(node, match_attr), name) == 0) { \
+ tempPin = HCS_PROP(node, pwmPin); \
+ resource->pwmPin = ((tempPin / DEC_TEN) * PIN_GROUP_NUM) + (tempPin % DEC_TEN); \
+ resource->pwmId = HCS_PROP(node, pwmId); \
+ result = HDF_SUCCESS; \
+ break; \
+ } \
+ } while (0)
+#define PLATFORM_PWM_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), pwm_config)
+static uint32_t GetPwmDeviceResource(struct PwmDevice *device, const char *deviceMatchAttr)
{
+ uint32_t tempPin;
+ int32_t result = HDF_FAILURE;
+ struct PwmResource *resource = NULL;
+ if (device == NULL || deviceMatchAttr == NULL) {
+ HDF_LOGE("%s: device or deviceMatchAttr is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ resource = &device->resource;
+#if HCS_NODE_EXISTS(PLATFORM_PWM_CONFIG)
+ HCS_FOREACH_CHILD_VARGS(PLATFORM_PWM_CONFIG, PWM_FIND_CONFIG, deviceMatchAttr, resource);
+#endif
+ if (result != HDF_SUCCESS) {
+ HDF_LOGE("resourceNode %s is NULL\r\n", deviceMatchAttr);
+ }
+ return result;
}
#else
static uint32_t GetPwmDeviceResource(
@@ -148,7 +175,7 @@ static int32_t AttachPwmDevice(struct PwmDev *host, struct HdfDeviceObject *devi
return HDF_ERR_MALLOC_FAIL;
}
#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
- ret = GetPwmDeviceResource(pwmDevice);
+ ret = GetPwmDeviceResource(pwmDevice, device->deviceMatchAttr);
#else
ret = GetPwmDeviceResource(pwmDevice, device->property);
#endif
diff --git a/platform/pwm/pwm_bes.h b/platform/pwm/pwm_bes.h
old mode 100755
new mode 100644
index 0bc76f928f65b3594ba71b0c1fdd8822aaf30ab7..98af98e78b414e3edfb740aaf21cbe462eb6469f
--- a/platform/pwm/pwm_bes.h
+++ b/platform/pwm/pwm_bes.h
@@ -1,23 +1,19 @@
/*
- * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * This file is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
+
#ifndef __PWM_BES_H__
#define __PWM_BES_H__
#include "hal_pwm.h"
#include "hal_gpio.h"
+#ifdef CHIP_BEST2003
#include "hal_iomux.h"
+#endif
#include "pwm_core.h"
#ifdef __cplusplus
@@ -39,4 +35,4 @@ struct PwmDevice {
#ifdef __cplusplus
}
#endif
-#endif
\ No newline at end of file
+#endif
diff --git a/platform/pwm/pwm_stm32f4xx.c b/platform/pwm/pwm_stm32f4xx.c
new file mode 100644
index 0000000000000000000000000000000000000000..3ee1a83112c2f31e62558ed48934ad692d476a34
--- /dev/null
+++ b/platform/pwm/pwm_stm32f4xx.c
@@ -0,0 +1,591 @@
+/*
+ * Copyright (c) 2022 Talkweb Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include
+#include
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+#include "hcs_macro.h"
+#include "hdf_config_macro.h"
+#else
+#include "device_resource_if.h"
+#endif
+#include "hdf_device_desc.h"
+#include "pwm_core.h"
+#include "hdf_log.h"
+#include "hdf_base_hal.h"
+#include "stm32f4xx_ll_tim.h"
+
+#define GPIO_STR_MAX_LENGTH 32
+
+typedef enum {
+ PWM_CH1 = 0,
+ PWM_CH2,
+ PWM_CH3,
+ PWM_CH4,
+ PWM_CH_MAX
+} PWM_CH;
+
+typedef enum {
+ PWM_TIM1 = 0,
+ PWM_TIM2,
+ PWM_TIM3,
+ PWM_TIM4,
+ PWM_TIM5,
+ PWM_TIM6,
+ PWM_TIM7,
+ PWM_TIM8,
+ PWM_TIM9,
+ PWM_TIM10,
+ PWM_TIM11,
+ PWM_TIM12,
+ PWM_TIM13,
+ PWM_TIM14,
+ PWM_TIM_MAX
+} PWM_TIM;
+
+typedef struct {
+ PWM_CH pwmCh;
+ PWM_TIM pwmTim;
+ uint32_t prescaler;
+ uint32_t timPeroid;
+ uint32_t realHz;
+} PwmResource;
+
+typedef struct {
+ LL_TIM_InitTypeDef timInitStruct;
+ LL_TIM_OC_InitTypeDef timOcInitStruct;
+} PwmConfig;
+
+typedef struct {
+ struct IDeviceIoService ioService;
+ PwmConfig stPwmCfg;
+ struct PwmConfig *cfg;
+ PwmResource resource;
+} PwmDevice;
+
+typedef struct {
+ uint32_t period;
+ uint32_t duty;
+ PWM_TIM pwmCh;
+ PWM_TIM pwmTim;
+} PwmFreqArg;
+
+static TIM_TypeDef* g_stTimMap[PWM_TIM_MAX] = {
+ TIM1,
+ TIM2,
+ TIM3,
+ TIM4,
+ TIM5,
+ TIM6,
+ TIM7,
+ TIM8,
+ TIM9,
+ TIM10,
+ TIM11,
+ TIM12,
+ TIM13,
+ TIM14,
+};
+
+static uint32_t g_stChannelMap[PWM_CH_MAX] = {
+ LL_TIM_CHANNEL_CH1,
+ LL_TIM_CHANNEL_CH2,
+ LL_TIM_CHANNEL_CH3,
+ LL_TIM_CHANNEL_CH4,
+};
+
+static uint32_t g_stTimIrqMap[PWM_TIM_MAX] = {
+ TIM1_CC_IRQn,
+ TIM2_IRQn,
+ TIM3_IRQn,
+ TIM4_IRQn,
+ TIM5_IRQn,
+ TIM6_DAC_IRQn,
+ TIM7_IRQn,
+ TIM8_CC_IRQn,
+ TIM1_BRK_TIM9_IRQn,
+ TIM1_UP_TIM10_IRQn,
+ TIM1_TRG_COM_TIM11_IRQn,
+ TIM8_BRK_TIM12_IRQn,
+ TIM8_UP_TIM13_IRQn,
+ TIM8_TRG_COM_TIM14_IRQn,
+};
+
+static uint32_t g_stTimFreq[PWM_TIM_MAX] = { // tim2-tim7, tim12-tim14 is 84M,TIM1、TIM8~TIM11 is 168M
+ 168000000,
+ 84000000,
+ 84000000,
+ 84000000,
+ 84000000,
+ 84000000,
+ 84000000,
+ 168000000,
+ 168000000,
+ 168000000,
+ 168000000,
+ 84000000,
+ 84000000,
+};
+
+#define PER_SEC_NSEC 1000000000
+
+static int32_t PwmDevSetConfig(struct PwmDev *pwm, struct PwmConfig *config);
+static int32_t PwmDevOpen(struct PwmDev *pwm);
+static int32_t PwmDevClose(struct PwmDev *pwm);
+
+struct PwmMethod g_pwmmethod = {
+ .setConfig = PwmDevSetConfig,
+ .open = PwmDevOpen,
+ .close = PwmDevClose,
+};
+
+static void InitPwmClock(PWM_TIM tim)
+{
+ switch (tim) {
+ case PWM_TIM1:
+ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM1);
+ break;
+ case PWM_TIM2:
+ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
+ break;
+ case PWM_TIM3:
+ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
+ break;
+ case PWM_TIM4:
+ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4);
+ break;
+ case PWM_TIM5:
+ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM5);
+ break;
+ case PWM_TIM6:
+ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM6);
+ break;
+ case PWM_TIM7:
+ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM7);
+ break;
+ case PWM_TIM8:
+ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM8);
+ break;
+ case PWM_TIM9:
+ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM9);
+ break;
+ case PWM_TIM10:
+ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM10);
+ break;
+ case PWM_TIM11:
+ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM11);
+ break;
+ case PWM_TIM12:
+ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM12);
+ break;
+ case PWM_TIM13:
+ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM13);
+ break;
+ case PWM_TIM14:
+ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM14);
+ break;
+ default:
+ break;
+ }
+}
+
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+#define PWM_FIND_CONFIG(node, name, resource) \
+ do { \
+ if (strcmp(HCS_PROP(node, match_attr), name) == 0) { \
+ uint8_t tim = HCS_PROP(node, pwmTim); \
+ uint8_t ch = HCS_PROP(node, pwmCh); \
+ uint8_t prescaler = HCS_PROP(node, prescaler); \
+ resource->pwmCh = ch; \
+ resource->pwmTim = tim; \
+ resource->prescaler = prescaler; \
+ result = HDF_SUCCESS; \
+ } \
+ } while (0)
+#define PLATFORM_CONFIG HCS_NODE(HCS_ROOT, platform)
+#define PLATFORM_PWM_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), pwm_config)
+static uint32_t GetPwmDeviceResource(PwmDevice *device, const char *deviceMatchAttr)
+{
+ int32_t result = HDF_FAILURE;
+ PwmResource *resource = NULL;
+ if (device == NULL || deviceMatchAttr == NULL) {
+ HDF_LOGE("%s: device or deviceMatchAttr is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ resource = &device->resource;
+#if HCS_NODE_HAS_PROP(PLATFORM_CONFIG, pwm_config)
+ HCS_FOREACH_CHILD_VARGS(PLATFORM_PWM_CONFIG, PWM_FIND_CONFIG, deviceMatchAttr, resource);
+#endif
+ if (result != HDF_SUCCESS) {
+ HDF_LOGE("resourceNode %s is NULL\r\n", deviceMatchAttr);
+ }
+
+ return result;
+}
+#else
+static int32_t GetPwmDeviceResource(PwmDevice *device, const struct DeviceResourceNode *resourceNode)
+{
+ struct DeviceResourceIface *dri = NULL;
+ PwmResource *resource = NULL;
+
+ if (device == NULL || resourceNode == NULL) {
+ HDF_LOGE("resource or device is NULL\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ resource = &device->resource;
+ if (resource == NULL) {
+ HDF_LOGE("resource is NULL\r\n");
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ if (dri == NULL || dri->GetUint8 == NULL || dri->GetUint32 == NULL) {
+ HDF_LOGE("DeviceResourceIface is invalid\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ if (dri->GetUint8(resourceNode, "pwmTim", &resource->pwmTim, 0) != HDF_SUCCESS) {
+ HDF_LOGE("read pwmPin fail\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ if (resource->pwmTim == PWM_TIM6 || resource->pwmTim == PWM_TIM7) {
+ HDF_LOGE("unsupport tim\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ if (dri->GetUint8(resourceNode, "pwmCh", &resource->pwmCh, 0) != HDF_SUCCESS) {
+ HDF_LOGE("read pwmCh fail\r\n");
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint32(resourceNode, "prescaler", &resource->prescaler, 0) != HDF_SUCCESS) {
+ HDF_LOGE("read prescaler fail\r\n");
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+#endif
+
+static int32_t AttachPwmDevice(struct PwmDev *host, struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ PwmDevice *pwmDevice = NULL;
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+ if (device == NULL || host == NULL) {
+#else
+ if (device == NULL || device->property == NULL || host == NULL) {
+#endif
+ HDF_LOGE("%s: param is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ pwmDevice = (PwmDevice *)OsalMemAlloc(sizeof(PwmDevice));
+ if (pwmDevice == NULL) {
+ HDF_LOGE("%s: OsalMemAlloc pwmDevice error\r\n", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+ ret = GetPwmDeviceResource(pwmDevice, device->deviceMatchAttr);
+#else
+ ret = GetPwmDeviceResource(pwmDevice, device->property);
+#endif
+ if (ret != HDF_SUCCESS) {
+ (void)OsalMemFree(pwmDevice);
+ return HDF_FAILURE;
+ }
+ host->priv = pwmDevice;
+ host->num = pwmDevice->resource.pwmTim;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t PwmDriverBind(struct HdfDeviceObject *device);
+static int32_t PwmDriverInit(struct HdfDeviceObject *device);
+static void PwmDriverRelease(struct HdfDeviceObject *device);
+
+struct HdfDriverEntry g_pwmDriverEntry = {
+ .moduleVersion = 1,
+ .moduleName = "ST_HDF_PLATFORM_PWM",
+ .Bind = PwmDriverBind,
+ .Init = PwmDriverInit,
+ .Release = PwmDriverRelease,
+};
+HDF_INIT(g_pwmDriverEntry);
+
+static int32_t PwmDriverBind(struct HdfDeviceObject *device)
+{
+ struct PwmDev *devService = NULL;
+ if (device == NULL) {
+ HDF_LOGE("hdfDevice object is null!\r\n");
+ return HDF_FAILURE;
+ }
+
+ devService = (struct PwmDev *)OsalMemCalloc(sizeof(struct PwmDev));
+ if (devService == NULL) {
+ HDF_LOGE("malloc pwmDev failed\n");
+ }
+ device->service = &devService->service;
+ devService->device = device;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t PwmDriverInit(struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct PwmDev *host = NULL;
+
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ host = (struct PwmDev *)device->service;
+ if (host == NULL) {
+ HDF_LOGE("%s: host is NULL\r\n", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ ret = AttachPwmDevice(host, device);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s:attach error\r\n", __func__);
+ return HDF_DEV_ERR_ATTACHDEV_FAIL;
+ }
+
+ host->method = &g_pwmmethod;
+ ret = PwmDeviceAdd(device, host);
+ if (ret != HDF_SUCCESS) {
+ PwmDeviceRemove(device, host);
+ OsalMemFree(host->device);
+ OsalMemFree(host);
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static void PwmDriverRelease(struct HdfDeviceObject *device)
+{
+ struct PwmDev *host = NULL;
+
+ if (device == NULL || device->service == NULL) {
+ HDF_LOGE("device is null\r\n");
+ return;
+ }
+
+ host = (struct PwmDev *)device->service;
+ if (host != NULL && host->device != NULL) {
+ host->method = NULL;
+ OsalMemFree(host->device);
+ OsalMemFree(host);
+ host->device = NULL;
+ host = NULL;
+ }
+
+ device->service = NULL;
+ host = NULL;
+
+ return;
+}
+
+static int32_t InitPwmFreqAndPeriod(const struct PwmConfig *config, PwmFreqArg* arg, const PwmResource *resource)
+{
+ if (arg == NULL) {
+ HDF_LOGE("null ptr\r\n");
+ return HDF_FAILURE;
+ }
+
+ uint32_t freq = 0;
+ uint32_t period = 0;
+ uint32_t duty = 0;
+ uint32_t realHz = 0;
+
+ if (config->period != 0) {
+ freq = (uint32_t)(PER_SEC_NSEC / config->period);
+ } else {
+ HDF_LOGE("invalid div\r\n");
+ return HDF_FAILURE;
+ }
+
+ realHz = (uint32_t)(((double)g_stTimFreq[arg->pwmTim]) / ((double)(resource->prescaler + 1)));
+
+ if (freq != 0) {
+ period = (uint32_t)(realHz / freq);
+ } else {
+ HDF_LOGE("invalid div\r\n");
+ return HDF_FAILURE;
+ }
+
+ if (config->period != 0) {
+ duty = (uint32_t)(((double)config->duty / (double)config->period) * period);
+ } else {
+ HDF_LOGE("invalid div\r\n");
+ return HDF_FAILURE;
+ }
+
+ arg->period = period;
+ arg->duty = duty;
+
+ return HDF_SUCCESS;
+}
+
+static void InitTimPwm(const PwmFreqArg* arg, const struct PwmConfig *config,
+ PwmConfig *pwmCfg, const PwmResource *resource)
+{
+ if (arg == NULL) {
+ HDF_LOGE("null ptr\r\n");
+ return;
+ }
+
+ pwmCfg->timInitStruct.Autoreload = arg->period - 1; // if period is 1000 20KHz/1000=20Hz,period is 50ms
+ pwmCfg->timInitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
+ pwmCfg->timInitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
+ pwmCfg->timInitStruct.Prescaler = resource->prescaler;
+ LL_TIM_Init(g_stTimMap[arg->pwmTim], &pwmCfg->timInitStruct);
+ LL_TIM_EnableARRPreload(g_stTimMap[arg->pwmTim]);
+ LL_TIM_SetClockSource(g_stTimMap[arg->pwmTim], LL_TIM_CLOCKSOURCE_INTERNAL);
+ LL_TIM_SetTriggerOutput(g_stTimMap[arg->pwmTim], LL_TIM_TRGO_RESET);
+ LL_TIM_DisableMasterSlaveMode(g_stTimMap[arg->pwmTim]);
+
+ pwmCfg->timOcInitStruct.OCMode = LL_TIM_OCMODE_PWM1; // PWM1 mode
+ pwmCfg->timOcInitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
+ pwmCfg->timOcInitStruct.CompareValue = arg->duty;
+ if (config->polarity == PWM_NORMAL_POLARITY) {
+ pwmCfg->timOcInitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
+ } else {
+ pwmCfg->timOcInitStruct.OCPolarity = LL_TIM_OCPOLARITY_LOW;
+ }
+ pwmCfg->timOcInitStruct.OCIdleState = LL_TIM_OCPOLARITY_LOW;
+
+ LL_TIM_OC_Init(g_stTimMap[arg->pwmTim], g_stChannelMap[arg->pwmCh], &pwmCfg->timOcInitStruct);
+ LL_TIM_OC_DisableFast(g_stTimMap[arg->pwmTim], g_stChannelMap[arg->pwmCh]);
+
+ if (arg->pwmTim == PWM_TIM1 || arg->pwmTim == PWM_TIM8) {
+ LL_TIM_BDTR_InitTypeDef bdtrInitStruct = {0};
+ bdtrInitStruct.OSSRState = LL_TIM_OSSR_DISABLE;
+ bdtrInitStruct.OSSIState = LL_TIM_OSSI_DISABLE;
+ bdtrInitStruct.LockLevel = LL_TIM_LOCKLEVEL_OFF;
+ bdtrInitStruct.DeadTime = 0; // dead area time 200ns 0x28
+ bdtrInitStruct.BreakState = LL_TIM_BREAK_ENABLE;
+ bdtrInitStruct.BreakPolarity = LL_TIM_BREAK_POLARITY_HIGH;
+ bdtrInitStruct.AutomaticOutput = LL_TIM_AUTOMATICOUTPUT_ENABLE;
+ LL_TIM_BDTR_Init(g_stTimMap[arg->pwmTim], &bdtrInitStruct);
+ }
+
+ NVIC_SetPriority(g_stTimIrqMap[arg->pwmTim], NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 1, 1));
+ NVIC_EnableIRQ(g_stTimIrqMap[arg->pwmTim]);
+
+ if (arg->pwmTim == PWM_TIM1 || arg->pwmTim == PWM_TIM8) {
+ LL_TIM_EnableAutomaticOutput(g_stTimMap[arg->pwmTim]);
+ LL_TIM_GenerateEvent_UPDATE(g_stTimMap[arg->pwmTim]);
+ }
+ LL_TIM_EnableCounter(g_stTimMap[arg->pwmTim]);
+ LL_TIM_CC_EnableChannel(g_stTimMap[arg->pwmTim], g_stChannelMap[arg->pwmCh]);
+ LL_TIM_OC_EnablePreload(g_stTimMap[arg->pwmTim], g_stChannelMap[arg->pwmCh]);
+
+ return;
+}
+
+static void DeInitTimPwm(PWM_TIM pwmId, PWM_CH pwmCh)
+{
+ LL_TIM_DeInit(g_stTimMap[pwmId]);
+ LL_TIM_OC_DisableClear(g_stTimMap[pwmId], g_stChannelMap[pwmCh]);
+ NVIC_DisableIRQ(g_stTimIrqMap[pwmId]);
+
+ LL_TIM_DisableCounter(g_stTimMap[pwmId]);
+ LL_TIM_CC_DisableChannel(g_stTimMap[pwmId], g_stChannelMap[pwmCh]);
+ LL_TIM_OC_DisablePreload(g_stTimMap[pwmId], g_stChannelMap[pwmCh]);
+
+ if (pwmId== PWM_TIM1 || pwmId == PWM_TIM8) {
+ LL_TIM_DisableAutomaticOutput(g_stTimMap[pwmId]);
+ }
+
+ return;
+}
+
+static int32_t PwmDevSetConfig(struct PwmDev *pwm, struct PwmConfig *config)
+{
+ PwmDevice *prvPwm = NULL;
+ PwmConfig *pwmCfg = NULL;
+ PWM_TIM pwmId;
+ PWM_CH pwmCh;
+ PwmResource *resource = NULL;
+
+ if (pwm == NULL || config == NULL || (config->period > PER_SEC_NSEC)) {
+ HDF_LOGE("%s\r\n", __FUNCTION__);
+ return HDF_FAILURE;
+ }
+
+ prvPwm = (struct PwmDevice *)PwmGetPriv(pwm);
+ if (prvPwm == NULL) {
+ return HDF_FAILURE;
+ }
+ resource = &prvPwm->resource;
+ if (resource == NULL) {
+ return HDF_FAILURE;
+ }
+ pwmCfg = &prvPwm->stPwmCfg;
+ if (pwmCfg == NULL) {
+ return HDF_FAILURE;
+ }
+ pwmId = prvPwm->resource.pwmTim;
+ pwmCh = prvPwm->resource.pwmCh;
+
+ if (config->status == PWM_ENABLE_STATUS) {
+ PwmFreqArg arg = {0};
+ arg.pwmCh = pwmCh;
+ arg.pwmTim = pwmId;
+ if (InitPwmFreqAndPeriod(config, &arg, resource) != HDF_SUCCESS) {
+ HDF_LOGE("calculate freq and period failed!\r\n");
+ return HDF_FAILURE;
+ }
+
+ InitPwmClock(pwmId);
+ InitTimPwm(&arg, config, pwmCfg, resource);
+ } else {
+ DeInitTimPwm(pwmId, pwmCh);
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t PwmDevOpen(struct PwmDev *pwm)
+{
+ if (pwm == NULL) {
+ HDF_LOGE("%s\r\n", __FUNCTION__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t PwmDevClose(struct PwmDev *pwm)
+{
+ PwmDevice *prvPwm = NULL;
+ PWM_TIM pwmId;
+ PWM_CH pwmCh;
+ if (pwm == NULL) {
+ HDF_LOGE("%s\r\n", __FUNCTION__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ prvPwm = (PwmDevice *)PwmGetPriv(pwm);
+ if (prvPwm == NULL) {
+ HDF_LOGE("%s\r\n", __FUNCTION__);
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+
+ pwmId = prvPwm->resource.pwmTim;
+ pwmCh = prvPwm->resource.pwmCh;
+ LL_TIM_DeInit(g_stTimMap[pwmId]);
+ LL_TIM_OC_DisableClear(g_stTimMap[pwmId], g_stChannelMap[pwmCh]);
+ NVIC_DisableIRQ(g_stTimIrqMap[pwmId]);
+
+ return HDF_SUCCESS;
+}
\ No newline at end of file
diff --git a/platform/pwm/pwm_wm.c b/platform/pwm/pwm_wm.c
new file mode 100755
index 0000000000000000000000000000000000000000..1c45381c353adbd11cff87d01b1155f1d49f4c3f
--- /dev/null
+++ b/platform/pwm/pwm_wm.c
@@ -0,0 +1,213 @@
+/*
+ * Copyright (c) 2022 Jiangsu Hoperun Software Co., Ltd.
+ *
+ * This file is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include
+#include
+#include "device_resource_if.h"
+#include "hdf_device_desc.h"
+#include "pwm_core.h"
+#include "hdf_log.h"
+#include "wm_pwm.h"
+
+struct PwmResource {
+ uint32_t channel;
+ uint32_t freq;
+};
+
+struct PwmDevice {
+ struct IDeviceIoService ioService;
+ pwm_init_param pwmCfg;
+ struct PwmConfig *cfg;
+ struct PwmResource resource;
+};
+
+static int32_t PwmDevSetConfig(struct PwmDev *pwm, struct PwmConfig *config);
+
+struct PwmMethod g_pwmmethod = {
+ .setConfig = PwmDevSetConfig,
+};
+
+static int32_t PwmDevSetConfig(struct PwmDev *pwm, struct PwmConfig *config)
+{
+ struct PwmDevice *prvPwm = NULL;
+ pwm_init_param *pwmCfg = NULL;
+ uint32_t freq;
+
+ if (pwm == NULL || config == NULL) {
+ HDF_LOGE("%s\r\n", __FUNCTION__);
+ return HDF_FAILURE;
+ }
+
+ prvPwm = (struct PwmDevice *)PwmGetPriv(pwm);
+ if (prvPwm == NULL) {
+ return HDF_FAILURE;
+ }
+ pwmCfg = &prvPwm->pwmCfg;
+ pwmCfg->period = config->period;
+ pwmCfg->duty = config->duty;
+ pwmCfg->pnum = config->number;
+ pwmCfg->channel = prvPwm->resource.channel;
+ freq = prvPwm->resource.freq;
+
+ if (config->status == PWM_ENABLE_STATUS) {
+ tls_pwm_init(pwmCfg->channel, freq, pwmCfg->duty, pwmCfg->pnum);
+ }
+
+ return HDF_SUCCESS;
+}
+
+static uint32_t GetPwmDeviceResource(
+ struct PwmDevice *device, const struct DeviceResourceNode *resourceNode)
+{
+ uint32_t tempPin = 0;
+ struct DeviceResourceIface *dri = NULL;
+ struct PwmResource *resource = NULL;
+ if (device == NULL || resourceNode == NULL) {
+ HDF_LOGE("resource or device is NULL\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ resource = &device->resource;
+ if (resource == NULL) {
+ HDF_LOGE("resource is NULL\r\n");
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ if (dri == NULL || dri->GetUint32 == NULL) {
+ HDF_LOGE("DeviceResourceIface is invalid\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ if (dri->GetUint32(resourceNode, "channel", &resource->channel, 0) != HDF_SUCCESS) {
+ HDF_LOGE("read channel fail\r\n");
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint32(resourceNode, "freq", &resource->freq, 0) != HDF_SUCCESS) {
+ HDF_LOGE("read freq fail\r\n");
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t AttachPwmDevice(struct PwmDev *host, struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct PwmDevice *pwmDevice = NULL;
+ if (device == NULL || device->property == NULL || host == NULL) {
+ HDF_LOGE("%s: param is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ pwmDevice = (struct PwmDevice *)OsalMemAlloc(sizeof(struct PwmDevice));
+ if (pwmDevice == NULL) {
+ HDF_LOGE("%s: OsalMemAlloc pwmDevice error\r\n", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ ret = GetPwmDeviceResource(pwmDevice, device->property);
+ if (ret != HDF_SUCCESS) {
+ (void)OsalMemFree(pwmDevice);
+ return HDF_FAILURE;
+ }
+
+ host->priv = pwmDevice;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t PwmDriverBind(struct HdfDeviceObject *device)
+{
+ static struct PwmDev devService;
+
+ if (device == NULL) {
+ HDF_LOGE("hdfDevice object is null!\r\n");
+ return HDF_FAILURE;
+ }
+
+ device->service = &devService.service;
+ devService.device = device;
+ HDF_LOGI("Enter %s\r\n", __func__);
+
+ return HDF_SUCCESS;
+}
+
+static int32_t PwmDriverInit(struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct PwmDev *host = NULL;
+
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ HDF_LOGI("Enter %s:\r\n", __func__);
+
+ host = (struct PwmDev *)OsalMemAlloc(sizeof(struct PwmDev));
+ if (host == NULL) {
+ HDF_LOGE("%s: host is NULL\r\n", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ ret = AttachPwmDevice(host, device);
+ if (ret != HDF_SUCCESS) {
+ OsalMemFree(host);
+ HDF_LOGE("%s:attach error\r\n", __func__);
+ return HDF_DEV_ERR_ATTACHDEV_FAIL;
+ }
+
+ host->method = &g_pwmmethod;
+ ret = PwmDeviceAdd(device, host);
+ if (ret != HDF_SUCCESS) {
+ PwmDeviceRemove(device, host);
+ OsalMemFree(host->device);
+ OsalMemFree(host);
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+
+ HDF_LOGI("PwmDriverInit success!\r\n");
+ return HDF_SUCCESS;
+}
+
+static void PwmDriverRelease(struct HdfDeviceObject *device)
+{
+ struct PwmDev *host = NULL;
+
+ if (device == NULL || device->service == NULL) {
+ HDF_LOGE("device is null\r\n");
+ return;
+ }
+
+ host = (struct PwmDev *)device->service;
+ if (host != NULL && host->device != NULL) {
+ host->method = NULL;
+ OsalMemFree(host->device);
+ OsalMemFree(host);
+ host->device = NULL;
+ host = NULL;
+ }
+
+ device->service = NULL;
+ HDF_LOGI("PwmDriverRelease finish!!\r\n");
+ return;
+}
+
+/* HdfDriverEntry definitions */
+struct HdfDriverEntry g_pwmDriverEntry = {
+ .moduleVersion = 1,
+ .moduleName = "WM_PWM_MODULE_HDF",
+ .Bind = PwmDriverBind,
+ .Init = PwmDriverInit,
+ .Release = PwmDriverRelease,
+};
+
+// Initialize HdfDriverEntry
+HDF_INIT(g_pwmDriverEntry);
diff --git a/platform/spi/BUILD.gn b/platform/spi/BUILD.gn
index 49ec290b99f076ba8007d13bf5bcc0a05b3f59d2..b4558abfb0e2c5c8c0606a5db8f7994fbf63667f 100644
--- a/platform/spi/BUILD.gn
+++ b/platform/spi/BUILD.gn
@@ -1,31 +1,10 @@
#
-# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved.
+# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
#
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
+# This file is dual licensed: you can use it either under the terms of
+# the GPL, or the BSD license, at your option.
+# See the LICENSE file in the root of this repository for complete details.
#
-# 1. Redistributions of source code must retain the above copyright notice, this list of
-# conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice, this list
-# of conditions and the following disclaimer in the documentation and/or other materials
-# provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its contributors may be used
-# to endorse or promote products derived from this software without specific prior written
-# permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
@@ -37,10 +16,26 @@ hdf_driver(module_name) {
if (defined(LOSCFG_SOC_COMPANY_BESTECHNIC)) {
sources += [ "spi_bes.c" ]
}
+ if (defined(LOSCFG_SOC_COMPANY_WINNERMICRO)) {
+ sources += [ "spi_wm.c" ]
+ }
+ if (defined(LOSCFG_SOC_SERIES_STM32F4xx)) {
+ sources += [ "spi_stm32f4xx.c" ]
+ }
include_dirs = [ "." ]
if (defined(LOSCFG_SHIELD_V200ZR_EVB_T1) &&
defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) {
deps = [ "//device/board/fnlink/shields" ]
}
+ if (defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) {
+ HDF_HCS_BUILD_PATH = rebase_path(
+ "//device/board/$device_company/$device_name/liteos_m/hdf_config")
+ cmd = "if [ -f ${HDF_HCS_BUILD_PATH}/BUILD.gn ]; then echo true; else echo false; fi"
+ HAVE_HCS_BUILD_PATH =
+ exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
+ if (HAVE_HCS_BUILD_PATH) {
+ deps = [ "${HDF_HCS_BUILD_PATH}" ]
+ }
+ }
}
diff --git a/platform/spi/spi_bes.c b/platform/spi/spi_bes.c
index b1e92777096bd34dc49ee8522257cb3e6d7cc6b1..5a83d949b669c1464941a2aa8b66eedb9f68fd30 100755
--- a/platform/spi/spi_bes.c
+++ b/platform/spi/spi_bes.c
@@ -1,17 +1,11 @@
/*
- * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * This file is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
+
#include "spi_bes.h"
#include
#include
@@ -43,10 +37,17 @@ static void Spi1DmaIrq(int error);
static struct SPI_CTX_OBJ_T spiCtx[MAX_SPI_NUMBER] = {
{
.spiPinCS0 = 0,
+#if defined (LOSCFG_SOC_SERIES_BES2700)
+ .spiFunDI0 = HAL_IOMUX_FUNC_SYS_SPI_DI0,
+ .spiFunCLK = HAL_IOMUX_FUNC_SYS_SPI_CLK,
+ .spiFunCS0 = HAL_IOMUX_FUNC_SYS_SPI_CS0,
+ .spiFunDIO = HAL_IOMUX_FUNC_SYS_SPI_DIO,
+#elif defined (LOSCFG_SOC_SERIES_BES2600)
.spiFunDI0 = HAL_IOMUX_FUNC_SPI_DI0,
.spiFunCLK = HAL_IOMUX_FUNC_SPI_CLK,
.spiFunCS0 = HAL_IOMUX_FUNC_SPI_CS0,
.spiFunDIO = HAL_IOMUX_FUNC_SPI_DIO,
+#endif
.sem = { NULL },
.mutex = { NULL },
.SpiOpen = hal_spi_open,
@@ -59,10 +60,17 @@ static struct SPI_CTX_OBJ_T spiCtx[MAX_SPI_NUMBER] = {
},
{
.spiPinCS0 = 0,
+#if defined (LOSCFG_SOC_SERIES_BES2700)
+ .spiFunDI0 = HAL_IOMUX_FUNC_SYS_SPILCD_DI0,
+ .spiFunCLK = HAL_IOMUX_FUNC_SYS_SPILCD_CLK,
+ .spiFunCS0 = HAL_IOMUX_FUNC_SYS_SPILCD_CS0,
+ .spiFunDIO = HAL_IOMUX_FUNC_SYS_SPILCD_DIO,
+#elif defined (LOSCFG_SOC_SERIES_BES2600)
.spiFunDI0 = HAL_IOMUX_FUNC_SPILCD_DI0,
.spiFunCLK = HAL_IOMUX_FUNC_SPILCD_CLK,
.spiFunCS0 = HAL_IOMUX_FUNC_SPILCD_CS0,
.spiFunDIO = HAL_IOMUX_FUNC_SPILCD_DIO,
+#endif
.sem = { NULL },
.mutex = { NULL },
.SpiOpen = hal_spilcd_open,
@@ -113,12 +121,12 @@ static void SpiIomuxInit(struct SpiDevice *spiDevice)
resource = &spiDevice->resource;
if (resource == NULL) {
HDF_LOGE("resource is null\r\n");
- return HDF_ERR_INVALID_OBJECT;
+ return;
}
spiDevCfg = &spiDevice->spiDevCfg;
if (spiDevCfg == NULL) {
HDF_LOGE("resource is null\r\n");
- return HDF_ERR_INVALID_OBJECT;
+ return;
}
spiDevCfg->rate = resource->speed;
@@ -141,14 +149,55 @@ static void SpiIomuxInit(struct SpiDevice *spiDevice)
pinMuxSpi[SPI_PIN_2].function = spiCtx[spiPort].spiFunCS0;
pinMuxSpi[SPI_PIN_3].function = spiCtx[spiPort].spiFunDIO;
- if (spiDevCfg->rate > MAX_SPI_SPEED) {
- hal_iomux_set_io_drv(pinMuxSpi[SPI_PIN_1].pin, DRIVER_LEVEL);
- hal_iomux_set_io_drv(pinMuxSpi[SPI_PIN_3].pin, DRIVER_LEVEL);
- }
+ hal_iomux_set_io_drv(pinMuxSpi[SPI_PIN_0].pin, DRIVER_LEVEL);
+ hal_iomux_set_io_drv(pinMuxSpi[SPI_PIN_1].pin, DRIVER_LEVEL);
+ hal_iomux_set_io_drv(pinMuxSpi[SPI_PIN_2].pin, DRIVER_LEVEL);
+ hal_iomux_set_io_drv(pinMuxSpi[SPI_PIN_3].pin, DRIVER_LEVEL);
hal_iomux_init(pinMuxSpi, ARRAY_SIZE(pinMuxSpi));
}
+static int32_t SpiDevCfgInit(struct HAL_SPI_CFG_T *spiDevCfg, struct SpiResource *resource)
+{
+ if (spiDevCfg == NULL || resource == NULL) {
+ HDF_LOGE("spi input para err\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+ switch (resource->mode) {
+ case SPI_WORK_MODE_0:
+ spiDevCfg->clk_delay_half = false;
+ spiDevCfg->clk_polarity = false;
+ break;
+ case SPI_WORK_MODE_1:
+ spiDevCfg->clk_delay_half = true;
+ spiDevCfg->clk_polarity = false;
+ break;
+ case SPI_WORK_MODE_2:
+ spiDevCfg->clk_delay_half = false;
+ spiDevCfg->clk_polarity = true;
+ break;
+ case SPI_WORK_MODE_3:
+ spiDevCfg->clk_delay_half = true;
+ spiDevCfg->clk_polarity = true;
+ break;
+ default:
+ spiDevCfg->clk_delay_half = true;
+ spiDevCfg->clk_polarity = true;
+ }
+ spiDevCfg->slave = 0;
+ if (resource->transmode == SPI_TRANSFER_DMA) {
+ spiDevCfg->dma_rx = true;
+ spiDevCfg->dma_tx = true;
+ } else {
+ spiDevCfg->dma_rx = false;
+ spiDevCfg->dma_tx = false;
+ }
+ spiDevCfg->cs = 0;
+ spiDevCfg->rx_bits = resource->dataSize;
+ spiDevCfg->tx_bits = resource->dataSize;
+ spiDevCfg->rx_frame_bits = 0;
+ return HDF_SUCCESS;
+}
/**
* Spi send
*
@@ -166,7 +215,7 @@ static void SpiIomuxInit(struct SpiDevice *spiDevice)
#endif
int32_t HalSpiSend(struct SpiDevice *spiDevice, const uint8_t *data, uint16_t size, uint32_t timeOut)
{
- int32_t ret = 0;
+ int32_t ret;
uint32_t spiId;
uint32_t len = size;
struct SpiResource *resource = NULL;
@@ -188,7 +237,9 @@ int32_t HalSpiSend(struct SpiDevice *spiDevice, const uint8_t *data, uint16_t si
HDF_LOGE("%s spi_mutex wait error = 0x%X!\r\n", __func__, status);
return HDF_ERR_TIMEOUT;
}
-
+#ifdef LOSCFG_SOC_SERIES_BES2700
+ hal_cache_sync_all(HAL_CACHE_ID_D_CACHE);
+#endif
if (resource->transmode == SPI_TRANSFER_DMA) {
ret = spiCtx[spiId].SpiDmaSend(data, len, spiCtx[spiId].SpiDmaIrq);
if (OsalSemWait(&spiCtx[spiId].sem, timeOut) != HDF_SUCCESS) {
@@ -223,11 +274,11 @@ OUT:
*
* @return 0 : on success, EIO : if the SPI device could not be initialised
*/
-int32_t HalSpiRecv(struct SpiDevice *spiDevice, uint8_t *data, uint16_t size, uint32_t timeOut)
+static int32_t HalSpiRecv(struct SpiDevice *spiDevice, uint8_t *data, uint16_t size, uint32_t timeOut)
{
- int32_t ret = 0;
- uint32_t len = size;
- uint32_t remainder = 0;
+ int32_t ret;
+ int32_t len = (int32_t)size;
+ uint32_t remainder;
int32_t status = HDF_FAILURE;
uint8_t *cmd = NULL;
uint32_t spiId;
@@ -243,50 +294,46 @@ int32_t HalSpiRecv(struct SpiDevice *spiDevice, uint8_t *data, uint16_t size, ui
HDF_LOGE("resource is null\r\n");
return HDF_ERR_INVALID_OBJECT;
}
- cmd = (uint8_t *)OsalMemAlloc(len);
- if (cmd == NULL) {
- HDF_LOGE("%s OsalMemAlloc size %ld error\r\n", __FUNCTION__, len);
- return HDF_ERR_MALLOC_FAIL;
- }
-
- memset_s(cmd, len, 0, len);
+ cmd = (uint8_t *)0x20020000; // 0x20020000 : non secure sram base. tx buf is useless, use sram instead of malloc.
status = OsalMutexLock(&spiCtx[spiId].mutex);
if (HDF_SUCCESS != status) {
HDF_LOGE("%s spi_mutex wait error = 0x%X!\r\n", __func__, status);
- OsalMemFree(cmd);
return HDF_ERR_TIMEOUT;
}
- remainder = len <= SPI_DMA_MAX ? len : SPI_DMA_MAX;
-
- if (resource->transmode == SPI_TRANSFER_DMA) {
- ret = spiCtx[spiId].SpiDmaRecv(cmd, data, remainder, spiCtx[spiId].SpiDmaIrq);
- if (OsalSemWait(&spiCtx[spiId].sem, timeOut) <= 0) {
- HDF_LOGE("SPI Read timeOut!\r\n");
- goto OUT;
+#ifdef LOSCFG_SOC_SERIES_BES2700
+ hal_cache_sync_all(HAL_CACHE_ID_D_CACHE);
+#endif
+ do {
+ remainder = len <= SPI_DMA_MAX ? len : SPI_DMA_MAX;
+ if (resource->transmode == SPI_TRANSFER_DMA) {
+ ret = spiCtx[spiId].SpiDmaRecv(cmd, data, remainder, spiCtx[spiId].SpiDmaIrq);
+ if (OsalSemWait(&spiCtx[spiId].sem, timeOut) <= 0) {
+ HDF_LOGE("SPI Read timeOut!\r\n");
+ goto OUT;
+ }
+ } else {
+ ret = spiCtx[spiId].SpiRecv(cmd, data, remainder);
}
- } else {
- ret = spiCtx[spiId].SpiRecv(cmd, data, remainder);
- }
- len -= remainder;
- data += remainder;
+ len -= remainder;
+ data += remainder;
- if (ret) {
- HDF_LOGE("spi tail fail %ld, size %ld\r\n", ret, len);
- goto OUT;
- }
+ if (ret != 0) {
+ HDF_LOGE("spi tail fail %ld, size %ld\r\n", ret, len);
+ goto OUT;
+ }
+ } while (len);
OUT:
OsalMutexUnlock(&spiCtx[spiId].mutex);
- OsalMemFree(cmd);
return ret;
}
#ifdef HalSpiSendRecv
#undef HalSpiSendRecv
#endif
-int32_t HalSpiSendRecv(struct SpiDevice *spiDevice, uint8_t *txData, uint16_t txSize, uint8_t *rxData,
- uint16_t rxSize, uint32_t timeOut)
+static int32_t HalSpiSendRecv(struct SpiDevice *spiDevice, uint8_t *txData, uint16_t txSize, uint8_t *rxData,
+ uint16_t rxSize)
{
int32_t ret;
int32_t status;
@@ -300,13 +347,15 @@ int32_t HalSpiSendRecv(struct SpiDevice *spiDevice, uint8_t *txData, uint16_t tx
resource = &spiDevice->resource;
status = OsalMutexLock(&spiCtx[spiId].mutex);
if (HDF_SUCCESS != status) {
- HDF_LOGE("%s spi_mutex wait error = 0x%X!\r\n", __func__, status);
+ HDF_LOGE("%s OsalMutexLock error = 0x%X!\r\n", __func__, status);
return HDF_ERR_TIMEOUT;
}
-
+#ifdef LOSCFG_SOC_SERIES_BES2700
+ hal_cache_sync_all(HAL_CACHE_ID_D_CACHE);
+#endif
if (resource->transmode == SPI_TRANSFER_DMA) {
ret = spiCtx[spiId].SpiDmaRecv(txData, rxData, rxSize, spiCtx[spiId].SpiDmaIrq);
- if (OsalSemWait(&spiCtx[spiId].sem, timeOut) <= 0) {
+ if (OsalSemWait(&spiCtx[spiId].sem, TIMEOUT) <= 0) {
HDF_LOGE("%s:SPI Read timeOut!\r\n", __func__);
goto OUT;
}
@@ -315,7 +364,6 @@ int32_t HalSpiSendRecv(struct SpiDevice *spiDevice, uint8_t *txData, uint16_t tx
}
if (ret) {
HDF_LOGE("spi dma tail fail %d\r\n", ret);
- goto OUT;
}
OUT:
OsalMutexUnlock(&spiCtx[spiId].mutex);
@@ -325,6 +373,7 @@ OUT:
static int32_t InitSpiDevice(struct SpiDevice *spiDevice)
{
uint32_t spiPort;
+ int32_t ret;
struct HAL_SPI_CFG_T *spiDevCfg = NULL;
struct SpiResource *resource = NULL;
if (spiDevice == NULL) {
@@ -337,40 +386,11 @@ static int32_t InitSpiDevice(struct SpiDevice *spiDevice)
spiPort = spiDevice->spiId;
SpiIomuxInit(spiDevice);
-
- switch (resource->mode) {
- case SPI_WORK_MODE_0:
- spiDevCfg->clk_delay_half = false;
- spiDevCfg->clk_polarity = false;
- break;
- case SPI_WORK_MODE_1:
- spiDevCfg->clk_delay_half = true;
- spiDevCfg->clk_polarity = false;
- break;
- case SPI_WORK_MODE_2:
- spiDevCfg->clk_delay_half = false;
- spiDevCfg->clk_polarity = true;
- break;
- case SPI_WORK_MODE_3:
- spiDevCfg->clk_delay_half = true;
- spiDevCfg->clk_polarity = true;
- break;
- default:
- spiDevCfg->clk_delay_half = true;
- spiDevCfg->clk_polarity = true;
- }
- spiDevCfg->slave = 0;
- if (resource->transmode == SPI_TRANSFER_DMA) {
- spiDevCfg->dma_rx = true;
- spiDevCfg->dma_tx = true;
- } else {
- spiDevCfg->dma_rx = false;
- spiDevCfg->dma_tx = false;
+ ret = SpiDevCfgInit(spiDevCfg, resource);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: SPI config init failed\r\n", __func__);
+ return HDF_FAILURE;
}
- spiDevCfg->cs = 0;
- spiDevCfg->rx_bits = resource->dataSize;
- spiDevCfg->tx_bits = resource->dataSize;
- spiDevCfg->rx_frame_bits = 0;
/* spi open move to hdf open api */
/* if cs use as gpio ,pull up at first */
if (spiCtx[spiPort].spiFunCS0 == HAL_IOMUX_FUNC_AS_GPIO) {
@@ -395,8 +415,47 @@ static int32_t InitSpiDevice(struct SpiDevice *spiDevice)
/* get spi config from hcs file */
#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
-static int32_t GetSpiDeviceResource(struct SpiDevice *spiDevice)
+#define SPI_FIND_CONFIG(node, name, resource) \
+ do { \
+ if (strcmp(HCS_PROP(node, match_attr), name) == 0) { \
+ resource->num = HCS_PROP(node, busNum); \
+ resource->speed = HCS_PROP(node, speed); \
+ resource->transmode = HCS_PROP(node, transmode); \
+ resource->spiCsSoft = HCS_PROP(node, spiCsSoft); \
+ resource->mode = HCS_PROP(node, mode); \
+ resource->dataSize = HCS_PROP(node, dataSize); \
+ resource->csNum = HCS_PROP(node, csNum); \
+ tempPin = HCS_PROP(node, spiClkPin); \
+ resource->spiClkPin = ((tempPin / DEC_NUM) * GROUP_PIN_NUM) + (tempPin % DEC_NUM); \
+ tempPin = HCS_PROP(node, spiMosiPin); \
+ resource->spiMosiPin = ((tempPin / DEC_NUM) * GROUP_PIN_NUM) + (tempPin % DEC_NUM); \
+ tempPin = HCS_PROP(node, spiMisoPin); \
+ resource->spiMisoPin = ((tempPin / DEC_NUM) * GROUP_PIN_NUM) + (tempPin % DEC_NUM); \
+ tempPin = HCS_PROP(node, spiCsPin); \
+ resource->spiCsPin = ((tempPin / DEC_NUM) * GROUP_PIN_NUM) + (tempPin % DEC_NUM); \
+ result = HDF_SUCCESS; \
+ break; \
+ } \
+ } while (0)
+
+#define PLATFORM_SPI_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), spi_config)
+static int32_t GetSpiDeviceResource(struct SpiDevice *spiDevice, const char *deviceMatchAttr)
{
+ uint32_t tempPin;
+ int32_t result = HDF_FAILURE;
+ struct SpiResource *resource = NULL;
+ if (spiDevice == NULL || deviceMatchAttr == NULL) {
+ HDF_LOGE("device or deviceMatchAttr is NULL\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+ resource = &spiDevice->resource;
+#if HCS_NODE_EXISTS(PLATFORM_SPI_CONFIG)
+ HCS_FOREACH_CHILD_VARGS(PLATFORM_SPI_CONFIG, SPI_FIND_CONFIG, deviceMatchAttr, resource);
+#endif
+ if (result != HDF_SUCCESS) {
+ HDF_LOGE("resourceNode %s is NULL\r\n", deviceMatchAttr);
+ }
+ return result;
}
#else
static int32_t GetSpiDeviceResource(struct SpiDevice *spiDevice, const struct DeviceResourceNode *resourceNode)
@@ -489,6 +548,7 @@ static int32_t GetSpiDeviceResource(struct SpiDevice *spiDevice, const struct De
return HDF_SUCCESS;
}
#endif
+
int32_t AttachSpiDevice(struct SpiCntlr *spiCntlr, struct HdfDeviceObject *device)
{
int32_t ret;
@@ -508,7 +568,7 @@ int32_t AttachSpiDevice(struct SpiCntlr *spiCntlr, struct HdfDeviceObject *devic
return HDF_ERR_MALLOC_FAIL;
}
#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
- ret = GetSpiDeviceResource(spiDevice);
+ ret = GetSpiDeviceResource(spiDevice, device->deviceMatchAttr);
#else
ret = GetSpiDeviceResource(spiDevice, device->property);
#endif
@@ -693,6 +753,7 @@ static int32_t SpiDevGetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg)
return HDF_SUCCESS;
}
+
static int32_t SpiDevSetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg)
{
struct SpiDevice *spiDevice = NULL;
@@ -723,11 +784,11 @@ static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg,
struct SpiDevice *spiDevice = NULL;
struct HAL_SPI_CFG_T *spiDevCfg = NULL;
struct SpiMsg *msg = NULL;
+ int32_t ret;
if (spiCntlr == NULL || spiCntlr->priv == NULL) {
HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__);
return HDF_ERR_INVALID_PARAM;
}
- HDF_LOGI("%s: %u Enter\r\n", __func__, spiId);
spiDevice = (struct SpiDevice *)spiCntlr->priv;
spiId = spiDevice->spiId;
for (size_t i = 0; i < count; i++) {
@@ -738,20 +799,23 @@ static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg,
}
if ((msg->wbuf != NULL) && (msg->rbuf == NULL)) {
- HalSpiSend(spiDevice, msg->wbuf, msg->len, TIMEOUT);
+ ret = HalSpiSend(spiDevice, msg->wbuf, msg->len, TIMEOUT);
}
if ((msg->rbuf != NULL) && (msg->wbuf == NULL)) {
- HalSpiRecv(spiDevice, msg->rbuf, msg->len, TIMEOUT);
+ ret = HalSpiRecv(spiDevice, msg->rbuf, msg->len, TIMEOUT);
}
if ((msg->wbuf != NULL) && (msg->rbuf != NULL)) {
- HalSpiSendRecv(spiDevice, msg->wbuf, msg->len, msg->rbuf, msg->len, TIMEOUT);
+ ret = HalSpiSendRecv(spiDevice, msg->wbuf, msg->len, msg->rbuf, msg->len);
}
/* pull pull up cs at the end */
- if (msg->csChange) {
+ if (msg->keepCs == 0) {
hal_gpio_pin_set_dir(spiCtx[spiId].spiPinCS0, HAL_GPIO_DIR_OUT, 1);
}
+ if (ret < 0) {
+ HDF_LOGE("%s send error!\r\n", __func__);
+ }
DelayUs(msg->delayUs);
}
return HDF_SUCCESS;
-}
\ No newline at end of file
+}
diff --git a/platform/spi/spi_bes.h b/platform/spi/spi_bes.h
old mode 100755
new mode 100644
index c274f10444b5349c9416b6c12d268264567b2af1..8cdf91633c0b2fd00a2b863791852121d4c7c5cd
--- a/platform/spi/spi_bes.h
+++ b/platform/spi/spi_bes.h
@@ -1,24 +1,20 @@
/*
- * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * This file is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
+
#ifndef __SPI_BES_H__
#define __SPI_BES_H__
#include "hal_spi.h"
#include "hal_gpio.h"
#include "hal_iomux.h"
+#ifdef CHIP_BEST2003
#include "hal_iomux_best2003.h"
+#endif
#include "osal_mutex.h"
#include "osal_sem.h"
@@ -79,4 +75,4 @@ struct SpiDevice {
}
#endif
-#endif
\ No newline at end of file
+#endif
diff --git a/platform/spi/spi_stm32f4xx.c b/platform/spi/spi_stm32f4xx.c
new file mode 100644
index 0000000000000000000000000000000000000000..f630a1f5e69ce987ba9e73ea432e11b797e194cb
--- /dev/null
+++ b/platform/spi/spi_stm32f4xx.c
@@ -0,0 +1,756 @@
+/*
+ * Copyright (c) 2022 Talkweb Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include
+#include
+#include "hal_gpio.h"
+#include "hal_spi.h"
+#include "osal_mutex.h"
+#include "osal_sem.h"
+#include "spi_core.h"
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+#include "hcs_macro.h"
+#include "hdf_config_macro.h"
+#else
+#include "device_resource_if.h"
+#include "hdf_log.h"
+#endif
+#include "hdf_base_hal.h"
+
+#define BITWORD_EIGHT 8
+#define BITWORD_SIXTEEN 16
+#define GPIO_STR_MAX 32
+#define PER_MS_IN_SEC 1000
+typedef enum {
+ SPI_WORK_MODE_0, // CPOL = 0; CPHA = 0
+ SPI_WORK_MODE_2, // CPOL = 1; CPHA = 0
+ SPI_WORK_MODE_1, // CPOL = 0; CPHA = 1
+ SPI_WORK_MODE_3, // CPOL = 1; CPHA = 1
+ SPI_WORD_MODE_MAX,
+} SPI_CLK_MODE;
+
+typedef enum {
+ SPI_TRANSFER_DMA,
+ SPI_TRANSFER_NORMAL,
+ SPI_TRANSFER_MAX,
+} SPI_TRANS_MODE;
+
+typedef enum {
+ FULL_DUPLEX = 0,
+ SIMPLE_RX,
+ HALF_RX,
+ HALF_TX,
+ SPI_TRANS_DIR_MAX,
+} SPI_TRANS_DIR;
+
+typedef enum {
+ SPI_SLAVE_MODE = 0,
+ SPI_MASTER_MODE,
+ SPI_MASTER_SLAVE_MAX,
+} SPI_SLAVE_MASTER;
+
+typedef enum {
+ SPI_DATA_WIDTH_8 = 0,
+ SPI_DATA_WIDTH_16,
+ SPI_DATA_WIDTH_MAX,
+} SPI_DATA_WIDTH;
+
+typedef enum {
+ SPI_NSS_SOFT_MODE = 0,
+ SPI_NSS_HARD_INPUT_MODE,
+ SPI_NSS_HARD_OUTPUT_MODE,
+ SPI_NSS_MODE_MAX,
+} SPI_NSS;
+
+typedef enum {
+ BAUD_RATE_DIV2 = 0,
+ BAUD_RATE_DIV4,
+ BAUD_RATE_DIV8,
+ BAUD_RATE_DIV16,
+ BAUD_RATE_DIV32,
+ BAUD_RATE_DIV64,
+ BAUD_RATE_DIV128,
+ BAUD_RATE_DIV256,
+ BAUD_RATE_DIV_MAX,
+} SPI_BAUD_RATE;
+
+typedef enum {
+ SPI_MSB_FIRST = 0,
+ SPI_LSB_FIRST,
+ SPI_MLSB_MAX,
+} SPI_BYTE_ORDER;
+
+typedef enum {
+ CRC_DISABLE = 0,
+ CRC_ENABLE,
+ CRC_STATE_MAX,
+} CRC_CALULATION;
+
+typedef enum {
+ SPI_PORT1 = 1,
+ SPI_PORT2,
+ SPI_PORT3,
+} SPI_GROUPS;
+
+typedef enum {
+ SPI_PROTO_MOTOROLA = 0,
+ SPI_PROTO_TI,
+ SPI_PROTO_MAX,
+} SPI_PROTO_STANDARD;
+
+typedef struct {
+ uint8_t busNum;
+ uint8_t csNum;
+ SPI_TRANS_DIR transDir;
+ SPI_TRANS_MODE transMode;
+
+ SPI_SLAVE_MASTER smMode;
+ SPI_CLK_MODE clkMode;
+ SPI_DATA_WIDTH dataWidth;
+ SPI_NSS nss;
+
+ SPI_BAUD_RATE baudRate;
+ SPI_BYTE_ORDER bitOrder;
+ CRC_CALULATION crcEnable;
+ SPI_GROUPS spix;
+
+ STM32_GPIO_PIN csPin;
+ STM32_GPIO_GROUP csGroup;
+ SPI_PROTO_STANDARD standard;
+ uint8_t dummyByte;
+
+ uint16_t crcPoly;
+} SpiResource;
+
+#define HCS_UINT8_PARSE_NUM 16
+static const char *g_parseHcsMap[HCS_UINT8_PARSE_NUM] = {
+ "busNum",
+ "csNum",
+ "transDir",
+ "transMode",
+ "smMode",
+ "clkMode",
+ "dataWidth",
+ "nss",
+ "baudRate",
+ "bitOrder",
+ "crcEnable",
+ "spix",
+ "csPin",
+ "csGpiox",
+ "standard",
+ "dummyByte",
+};
+
+typedef struct {
+ struct OsalSem* sem;
+ struct OsalMutex* mutex;
+ SPI_TypeDef* spix;
+} SPI_CONTEXT_T;
+
+typedef struct {
+ uint32_t spiId;
+ SpiResource resource;
+} SpiDevice;
+
+static uint32_t g_transDirMaps[SPI_TRANS_DIR_MAX] = {
+ LL_SPI_FULL_DUPLEX,
+ LL_SPI_SIMPLEX_RX,
+ LL_SPI_HALF_DUPLEX_RX,
+ LL_SPI_HALF_DUPLEX_TX,
+};
+
+static uint32_t g_nssMaps[SPI_NSS_MODE_MAX] = {
+ LL_SPI_NSS_SOFT,
+ LL_SPI_NSS_HARD_INPUT,
+ LL_SPI_NSS_HARD_OUTPUT,
+};
+
+static uint32_t g_baudMaps[BAUD_RATE_DIV_MAX] = {
+ LL_SPI_BAUDRATEPRESCALER_DIV2,
+ LL_SPI_BAUDRATEPRESCALER_DIV4,
+ LL_SPI_BAUDRATEPRESCALER_DIV8,
+ LL_SPI_BAUDRATEPRESCALER_DIV16,
+ LL_SPI_BAUDRATEPRESCALER_DIV32,
+ LL_SPI_BAUDRATEPRESCALER_DIV64,
+ LL_SPI_BAUDRATEPRESCALER_DIV128,
+ LL_SPI_BAUDRATEPRESCALER_DIV256,
+};
+
+static SPI_TypeDef* g_spiGroupMaps[SPI_PORT3] = {
+ SPI1,
+ SPI2,
+ SPI3,
+};
+
+static void EnableSpiClock(uint32_t spiNum)
+{
+ switch (spiNum) {
+ case SPI_PORT1:
+ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1);
+ break;
+ case SPI_PORT2:
+ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI2);
+ break;
+ case SPI_PORT3:
+ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI3);
+ break;
+ default:
+ break;
+ }
+}
+
+static SPI_CONTEXT_T spiContext[SPI_PORT3] = {
+ {
+ .sem = {NULL},
+ .mutex = {NULL},
+ .spix = {NULL},
+ },
+ {
+ .sem = {NULL},
+ .mutex = {NULL},
+ .spix = {NULL},
+ },
+ {
+ .sem = {NULL},
+ .mutex = {NULL},
+ .spix = {NULL},
+ },
+};
+
+int32_t HalSpiSend(SpiDevice *spiDevice, const uint8_t *data, uint16_t size)
+{
+ uint32_t spiId;
+ SpiResource *resource = NULL;
+
+ if (spiDevice == NULL || data == NULL || size == 0) {
+ HDF_LOGE("spi input para err\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ spiId = spiDevice->spiId;
+ resource = &spiDevice->resource;
+ if (resource == NULL) {
+ HDF_LOGE("resource is null\r\n");
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ if (resource->transMode == SPI_TRANSFER_DMA) {
+ return HDF_ERR_INVALID_PARAM; // unsupport now
+ } else {
+ uint8_t readData;
+ while (size--) {
+ readData = LL_SPI_Transmit(spiContext[spiId].spix, *data);
+ data++;
+ }
+ }
+
+ return HDF_SUCCESS;
+}
+
+int32_t HalSpiRecv(SpiDevice *spiDevice, uint8_t *data, uint16_t size)
+{
+ uint32_t len = size;
+ uint8_t *cmd = NULL;
+ uint32_t spiId;
+ SpiResource *resource = NULL;
+ if (spiDevice == NULL || data == NULL || size == 0) {
+ HDF_LOGE("spi input para err\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ spiId = spiDevice->spiId;
+ resource = &spiDevice->resource;
+ if (resource == NULL) {
+ HDF_LOGE("resource is null\r\n");
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ cmd = (uint8_t *)OsalMemAlloc(len);
+ if (cmd == NULL) {
+ HDF_LOGE("%s OsalMemAlloc size %ld error\r\n", __FUNCTION__, len);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ memset_s(cmd, len, resource->dummyByte, len);
+
+ if (resource->transMode == SPI_TRANSFER_DMA) {
+ return HDF_ERR_INVALID_PARAM; // unsupport now
+ } else {
+ while (len--) {
+ *data = LL_SPI_Transmit(spiContext[spiId].spix, *cmd);
+ data++;
+ cmd++;
+ }
+ }
+
+ OsalMemFree(cmd);
+ return HDF_SUCCESS;
+}
+
+int32_t HalSpiSendRecv(SpiDevice *spiDevice, uint8_t *txData,
+ uint16_t txSize, uint8_t *rxData, uint16_t rxSize)
+{
+ uint32_t spiId;
+ SpiResource *resource = NULL;
+ if (spiDevice == NULL || txData == NULL || txSize == 0 || rxData == NULL || rxSize == 0) {
+ HDF_LOGE("spi input para err\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+ spiId = spiDevice->spiId;
+ resource = &spiDevice->resource;
+
+ if (resource->transMode == SPI_TRANSFER_DMA) {
+ return HDF_ERR_INVALID_PARAM; // unsupport now
+ } else {
+ while (rxSize--) {
+ *rxData = LL_SPI_Transmit(spiContext[spiId].spix, *txData);
+ rxData++;
+ txData++;
+ }
+ }
+
+ return HDF_SUCCESS;
+}
+
+static void InitSpiInitStruct(LL_SPI_InitTypeDef *spiInitStruct, const SpiResource *resource)
+{
+ spiInitStruct->TransferDirection = g_transDirMaps[resource->transDir];
+ if (resource->smMode == SPI_SLAVE_MODE) {
+ spiInitStruct->Mode = LL_SPI_MODE_SLAVE;
+ } else {
+ spiInitStruct->Mode = LL_SPI_MODE_MASTER;
+ }
+
+ if (resource->dataWidth == SPI_DATA_WIDTH_8) {
+ spiInitStruct->DataWidth = LL_SPI_DATAWIDTH_8BIT;
+ } else {
+ spiInitStruct->DataWidth = LL_SPI_DATAWIDTH_16BIT;
+ }
+
+ switch (resource->clkMode) {
+ case SPI_WORK_MODE_0:
+ spiInitStruct->ClockPolarity = LL_SPI_POLARITY_LOW;
+ spiInitStruct->ClockPhase = LL_SPI_PHASE_1EDGE;
+ break;
+ case SPI_WORK_MODE_1:
+ spiInitStruct->ClockPolarity = LL_SPI_POLARITY_HIGH;
+ spiInitStruct->ClockPhase = LL_SPI_PHASE_1EDGE;
+ break;
+ case SPI_WORK_MODE_2:
+ spiInitStruct->ClockPolarity = LL_SPI_POLARITY_LOW;
+ spiInitStruct->ClockPhase = LL_SPI_PHASE_2EDGE;
+ break;
+ case SPI_WORK_MODE_3:
+ spiInitStruct->ClockPolarity = LL_SPI_POLARITY_HIGH;
+ spiInitStruct->ClockPhase = LL_SPI_PHASE_2EDGE;
+ break;
+ default:
+ spiInitStruct->ClockPolarity = LL_SPI_POLARITY_LOW;
+ spiInitStruct->ClockPhase = LL_SPI_PHASE_1EDGE;
+ }
+
+ spiInitStruct->NSS = g_nssMaps[resource->nss];
+ spiInitStruct->BaudRate = g_baudMaps[resource->baudRate];
+
+ if (resource->bitOrder == SPI_MSB_FIRST) {
+ spiInitStruct->BitOrder = LL_SPI_MSB_FIRST;
+ } else {
+ spiInitStruct->BitOrder = LL_SPI_LSB_FIRST;
+ }
+
+ if (resource->crcEnable == CRC_DISABLE) {
+ spiInitStruct->CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
+ } else {
+ spiInitStruct->CRCCalculation = LL_SPI_CRCCALCULATION_ENABLE;
+ }
+ spiInitStruct->CRCPoly = resource->crcPoly;
+
+ return;
+}
+
+static int32_t InitSpiDevice(SpiDevice *spiDevice)
+{
+ uint32_t spiPort;
+ SpiResource *resource = NULL;
+ if (spiDevice == NULL) {
+ HDF_LOGE("%s: invalid parameter\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ LL_SPI_InitTypeDef spiInitStruct = {0};
+ resource = &spiDevice->resource;
+ spiPort = spiDevice->spiId;
+ EnableSpiClock(spiPort + 1);
+ InitSpiInitStruct(&spiInitStruct, resource);
+ SPI_TypeDef* spix = g_spiGroupMaps[resource->spix];
+
+ spiContext[spiPort].spix = spix;
+ LL_SPI_Disable(spix);
+ uint8_t ret = LL_SPI_Init(spix, &spiInitStruct);
+ if (ret != 0) {
+ HDF_LOGE("HAL INIT SPI FAILED\r\n");
+ return HDF_FAILURE;
+ }
+ if (resource->standard == SPI_PROTO_MOTOROLA) {
+ LL_SPI_SetStandard(spix, LL_SPI_PROTOCOL_MOTOROLA);
+ } else {
+ LL_SPI_SetStandard(spix, LL_SPI_PROTOCOL_TI);
+ }
+
+ return HDF_SUCCESS;
+}
+
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+#define SPI_FIND_CONFIG(node, name, resource, spiDevice) \
+ do { \
+ if (strcmp(HCS_PROP(node, match_attr), name) == 0) { \
+ resource->busNum = HCS_PROP(node, busNum); \
+ spiDevice->spiId = resource->busNum; \
+ resource->csNum = HCS_PROP(node, csNum); \
+ resource->transDir = HCS_PROP(node, transDir); \
+ resource->transMode = HCS_PROP(node, transMode); \
+ resource->smMode = HCS_PROP(node, smMode); \
+ resource->dataWidth = HCS_PROP(node, dataWidth); \
+ resource->clkMode = HCS_PROP(node, clkMode); \
+ resource->csNum = HCS_PROP(node, csNum); \
+ resource->nss = HCS_PROP(node, nss); \
+ resource->baudRate = HCS_PROP(node, baudRate); \
+ resource->bitOrder = HCS_PROP(node, bitOrder); \
+ resource->crcEnable = HCS_PROP(node, crcEnable); \
+ resource->crcPoly = HCS_PROP(node, crcPoly); \
+ resource->spix = HCS_PROP(node, spix); \
+ resource->csPin = HCS_PROP(node, csPin); \
+ resource->csGroup = HCS_PROP(node, csGpiox); \
+ resource->standard = HCS_PROP(node, standard); \
+ resource->dummyByte = HCS_PROP(node, dummyByte); \
+ result = HDF_SUCCESS; \
+ } \
+ } while (0)
+
+#define PLATFORM_CONFIG HCS_NODE(HCS_ROOT, platform)
+#define PLATFORM_SPI_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), spi_config)
+static int32_t GetSpiDeviceResource(SpiDevice *spiDevice, const char *deviceMatchAttr)
+{
+ int32_t result = HDF_FAILURE;
+ SpiResource *resource = NULL;
+ if (spiDevice == NULL || deviceMatchAttr == NULL) {
+ HDF_LOGE("device or deviceMatchAttr is NULL\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+ resource = &spiDevice->resource;
+#if HCS_NODE_HAS_PROP(PLATFORM_CONFIG, spi_config)
+ HCS_FOREACH_CHILD_VARGS(PLATFORM_SPI_CONFIG, SPI_FIND_CONFIG, deviceMatchAttr, resource, spiDevice);
+#endif
+ if (result != HDF_SUCCESS) {
+ HDF_LOGE("resourceNode %s is NULL\r\n", deviceMatchAttr);
+ }
+ return result;
+}
+#else
+static int32_t GetSpiDeviceResource(SpiDevice *spiDevice, const struct DeviceResourceNode *resourceNode)
+{
+ struct DeviceResourceIface *dri = NULL;
+ if (spiDevice == NULL || resourceNode == NULL) {
+ HDF_LOGE("%s: PARAM is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ SpiResource *resource = NULL;
+ resource = &spiDevice->resource;
+ if (resource == NULL) {
+ HDF_LOGE("%s: resource is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); // open HDF
+ if (dri == NULL || dri->GetUint16 == NULL || dri->GetUint8 == NULL || dri->GetUint32 == NULL) {
+ HDF_LOGE("DeviceResourceIface is invalid\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+ uint8_t temp[HCS_UINT8_PARSE_NUM] = {0};
+ for (int i = 0; i < HCS_UINT8_PARSE_NUM; i++) {
+ if (dri->GetUint8(resourceNode, g_parseHcsMap[i], &temp[i], 0) != HDF_SUCCESS) {
+ HDF_LOGE("get config %s failed\r\n", g_parseHcsMap[i]);
+ return HDF_FAILURE;
+ }
+ }
+ int ret = memcpy_s(resource, HCS_UINT8_PARSE_NUM, temp, HCS_UINT8_PARSE_NUM);
+ if (ret != 0) {
+ HDF_LOGE("memcpy failed\r\n");
+ return HDF_FAILURE;
+ }
+ if (dri->GetUint16(resourceNode, "crcPoly", &resource->crcPoly, 0) != HDF_SUCCESS) {
+ HDF_LOGE("get config %s failed\r\n", "crcPoly");
+ return HDF_FAILURE;
+ }
+ spiDevice->spiId = resource->busNum;
+
+ return HDF_SUCCESS;
+}
+#endif
+
+int32_t AttachSpiDevice(struct SpiCntlr *spiCntlr, struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ SpiDevice *spiDevice = NULL;
+
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+ if (spiCntlr == NULL || device == NULL) {
+#else
+ if (spiCntlr == NULL || device == NULL || device->property == NULL) {
+#endif
+ HDF_LOGE("%s: property is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ spiDevice = (SpiDevice *)OsalMemAlloc(sizeof(SpiDevice));
+ if (spiDevice == NULL) {
+ HDF_LOGE("%s: OsalMemAlloc spiDevice error\r\n", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+ ret = GetSpiDeviceResource(spiDevice, device->deviceMatchAttr);
+#else
+ ret = GetSpiDeviceResource(spiDevice, device->property);
+#endif
+ if (ret != HDF_SUCCESS) {
+ (void)OsalMemFree(spiDevice);
+ return HDF_FAILURE;
+ }
+
+ spiCntlr->priv = spiDevice;
+ spiCntlr->busNum = spiDevice->spiId;
+ InitSpiDevice(spiDevice);
+
+ return HDF_SUCCESS;
+}
+/* SPI Method */
+static int32_t SpiDevGetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg);
+static int32_t SpiDevSetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg);
+static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg, uint32_t count);
+static int32_t SpiDevOpen(struct SpiCntlr *spiCntlr);
+static int32_t SpiDevClose(struct SpiCntlr *spiCntlr);
+
+struct SpiCntlrMethod g_twSpiCntlrMethod = {
+ .GetCfg = SpiDevGetCfg,
+ .SetCfg = SpiDevSetCfg,
+ .Transfer = SpiDevTransfer,
+ .Open = SpiDevOpen,
+ .Close = SpiDevClose,
+};
+
+/* HdfDriverEntry method definitions */
+static int32_t SpiDriverBind(struct HdfDeviceObject *device);
+static int32_t SpiDriverInit(struct HdfDeviceObject *device);
+static void SpiDriverRelease(struct HdfDeviceObject *device);
+
+/* HdfDriverEntry definitions */
+struct HdfDriverEntry g_SpiDriverEntry = {
+ .moduleVersion = 1,
+ .moduleName = "ST_SPI_MODULE_HDF",
+ .Bind = SpiDriverBind,
+ .Init = SpiDriverInit,
+ .Release = SpiDriverRelease,
+};
+
+HDF_INIT(g_SpiDriverEntry);
+
+static int32_t SpiDriverBind(struct HdfDeviceObject *device)
+{
+ struct SpiCntlr *spiCntlr = NULL;
+ if (device == NULL) {
+ HDF_LOGE("Sample device object is null!\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+ HDF_LOGI("Enter %s:\r\n", __func__);
+ spiCntlr = SpiCntlrCreate(device);
+ if (spiCntlr == NULL) {
+ HDF_LOGE("SpiCntlrCreate object is null!\r\n");
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SpiDriverInit(struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct SpiCntlr *spiCntlr = NULL;
+
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ HDF_LOGI("Enter %s:", __func__);
+ spiCntlr = SpiCntlrFromDevice(device);
+ if (spiCntlr == NULL) {
+ HDF_LOGE("%s: spiCntlr is NULL", __func__);
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+
+ ret = AttachSpiDevice(spiCntlr, device); // SpiCntlr add TWSpiDevice to priv
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: attach error\r\n", __func__);
+ return HDF_DEV_ERR_ATTACHDEV_FAIL;
+ }
+
+ spiCntlr->method = &g_twSpiCntlrMethod; // register callback
+
+ return ret;
+}
+
+static void SpiDriverRelease(struct HdfDeviceObject *device)
+{
+ struct SpiCntlr *spiCntlr = NULL;
+ SpiDevice *spiDevice = NULL;
+
+ HDF_LOGI("Enter %s\r\n", __func__);
+
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL\r\n", __func__);
+ return;
+ }
+
+ spiCntlr = SpiCntlrFromDevice(device);
+ if (spiCntlr == NULL || spiCntlr->priv == NULL) {
+ HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__);
+ return;
+ }
+
+ spiDevice = (SpiDevice *)spiCntlr->priv;
+ OsalMemFree(spiDevice);
+
+ return;
+}
+
+static int32_t SpiDevOpen(struct SpiCntlr *spiCntlr)
+{
+ HDF_LOGI("Enter %s\r\n", __func__);
+ SpiDevice *spiDevice = NULL;
+
+ spiDevice = (SpiDevice*)spiCntlr->priv;
+ SPI_TypeDef* spix = g_spiGroupMaps[spiDevice->resource.spix];
+ LL_SPI_Enable(spix);
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SpiDevClose(struct SpiCntlr *spiCntlr)
+{
+ SpiDevice *spiDevice = NULL;
+
+ spiDevice = (SpiDevice*)spiCntlr->priv;
+ SPI_TypeDef* spix = g_spiGroupMaps[spiDevice->resource.spix];
+ LL_SPI_Disable(spix);
+
+ return HDF_SUCCESS;
+}
+
+static int32_t SpiDevGetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg)
+{
+ SpiDevice *spiDevice = NULL;
+ if (spiCntlr == NULL || spiCfg == NULL || spiCntlr->priv == NULL) {
+ HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ spiDevice = (SpiDevice *)spiCntlr->priv;
+ if (spiDevice == NULL) {
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+ spiCfg->maxSpeedHz = spiDevice->resource.baudRate;
+ spiCfg->mode = spiDevice->resource.clkMode;
+ spiCfg->transferMode = spiDevice->resource.transMode;
+ spiCfg->bitsPerWord = spiDevice->resource.dataWidth;
+
+ if (spiDevice->resource.dataWidth) {
+ spiCfg->bitsPerWord = BITWORD_SIXTEEN;
+ } else {
+ spiCfg->bitsPerWord = BITWORD_EIGHT;
+ }
+
+ return HDF_SUCCESS;
+}
+static int32_t SpiDevSetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg)
+{
+ SpiDevice *spiDevice = NULL;
+ if (spiCntlr == NULL || spiCfg == NULL || spiCntlr->priv == NULL) {
+ HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ spiDevice = (SpiDevice *)spiCntlr->priv;
+ if (spiDevice == NULL) {
+ HDF_LOGE("%s: spiDevice is NULL\r\n", __func__);
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+
+ spiDevice->resource.baudRate = spiCfg->maxSpeedHz;
+ spiDevice->resource.clkMode = spiCfg->mode;
+ spiDevice->resource.transMode = spiCfg->transferMode;
+ if (spiCfg->bitsPerWord == BITWORD_EIGHT) {
+ spiDevice->resource.dataWidth = SPI_DATA_WIDTH_8;
+ } else {
+ spiDevice->resource.dataWidth = SPI_DATA_WIDTH_16;
+ }
+
+ return InitSpiDevice(spiDevice);
+}
+
+static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg, uint32_t count)
+{
+ SpiDevice *spiDevice = NULL;
+ uint32_t ticks = 0;
+ uint8_t singleCsChange = 0;
+ struct SpiMsg *msg = NULL;
+ if (spiCntlr == NULL || spiCntlr->priv == NULL) {
+ HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ spiDevice = (SpiDevice *)spiCntlr->priv;
+ for (size_t i = 0; i < count; i++) {
+ msg = &spiMsg[i];
+ LL_GPIO_ResetOutputPin(LL_GET_GPIOX(spiDevice->resource.csGroup), LL_GET_HAL_PIN(spiDevice->resource.csPin));
+
+ if ((msg->rbuf == NULL) && (msg->wbuf != NULL)) {
+ singleCsChange = msg->wbuf[0];
+
+ if (msg->len == 1) {
+ goto CS_DOWN;
+ }
+ HalSpiSend(spiDevice, msg->wbuf + 1, msg->len - 1);
+ }
+
+ if ((msg->rbuf != NULL) && (msg->wbuf == NULL)) {
+ singleCsChange = msg->rbuf[0];
+
+ if (msg->len == 1) {
+ goto CS_DOWN;
+ }
+ HalSpiRecv(spiDevice, msg->rbuf + 1, msg->len - 1);
+ }
+
+ if ((msg->wbuf != NULL) && (msg->rbuf != NULL)) {
+ HalSpiSendRecv(spiDevice, msg->wbuf, msg->len, msg->rbuf, msg->len);
+ }
+
+ if (msg->keepCs == 0|| singleCsChange) {
+ LL_GPIO_SetOutputPin(LL_GET_GPIOX(spiDevice->resource.csGroup), LL_GET_HAL_PIN(spiDevice->resource.csPin));
+ }
+ if (msg->delayUs > 0) {
+ ticks = (msg->delayUs / PER_MS_IN_SEC);
+ osDelay(ticks);
+ }
+ }
+ return HDF_SUCCESS;
+CS_DOWN:
+ if (msg->keepCs == 0 || singleCsChange) {
+ LL_GPIO_SetOutputPin(LL_GET_GPIOX(spiDevice->resource.csGroup), LL_GET_HAL_PIN(spiDevice->resource.csPin));
+ }
+ return HDF_SUCCESS;
+}
+
diff --git a/platform/spi/spi_wm.c b/platform/spi/spi_wm.c
new file mode 100755
index 0000000000000000000000000000000000000000..61cd9d943e0e9124ef87a0637533d590c50ab3bb
--- /dev/null
+++ b/platform/spi/spi_wm.c
@@ -0,0 +1,508 @@
+/*
+ * Copyright (c) 2022 Jiangsu Hoperun Software Co., Ltd.
+ *
+ * This file is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include
+#include
+#include "hdf_log.h"
+#include "spi_core.h"
+#include "spi_if.h"
+#include "device_resource_if.h"
+#include "wm_gpio_afsel.h"
+#include "osal_mutex.h"
+#include "osal_sem.h"
+#include "wm_hostspi.h"
+
+#define SPI_DMA_MAX 4095
+#define MAX_SPI_NUMBER 1
+#define TIMEOUT 1000
+
+struct SpiResource {
+ uint32_t num;
+ uint32_t speed;
+ enum SpiTransferMode transmode;
+ uint32_t mode; // TLS_SPI_MODE_x
+ uint32_t dataSize;
+ uint32_t spiCsSoft;
+ uint32_t spiClkPin;
+ uint32_t spiMosiPin;
+ uint32_t spiMisoPin;
+ uint32_t spiCsPin;
+};
+
+struct SpiDevice {
+ uint32_t spiId;
+ struct SpiResource resource;
+ struct OsalMutex mutex;
+};
+
+static void SpiIomuxInit(struct SpiDevice *spiDevice)
+{
+ struct SpiResource *resource = NULL;
+ uint32_t spiPort;
+ HDF_LOGI("%s: Enter\r\n", __func__);
+
+ if (spiDevice == NULL) {
+ HDF_LOGE("%s: invalid parameter\r\n", __func__);
+ return;
+ }
+
+ resource = &spiDevice->resource;
+ if (resource == NULL) {
+ HDF_LOGE("resource is null\r\n");
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ spiPort = spiDevice->spiId;
+
+ if (resource->spiCsSoft) {
+ tls_gpio_cfg(WM_IO_PB_00 + resource->spiCsPin, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH);
+ }
+ wm_spi_cs_config(WM_IO_PB_04);
+ wm_spi_ck_config(WM_IO_PB_02);
+ wm_spi_di_config(WM_IO_PB_03);
+ wm_spi_do_config(WM_IO_PB_05);
+}
+
+/**
+ * Spi send
+ *
+ * @param[in] spiId the spi bus id
+ * @param[in] data spi send data
+ * @param[in] size spi send data size
+ * @param[in] timeOut timeOut in milisecond, set this value to HAL_WAIT_FOREVER
+ * if you want to wait forever
+ *
+ * @return 0 : on success, EIO : if the SPI device could not be initialised
+ */
+int32_t HalSpiSend(struct SpiDevice *spiDevice, const uint8_t *data, uint16_t size, uint32_t timeOut)
+{
+ int32_t ret = 0;
+ uint32_t spiId;
+ uint32_t len = size;
+ struct SpiResource *resource = NULL;
+ int32_t status = HDF_FAILURE;
+
+ if (spiDevice == NULL || data == NULL || size == 0) {
+ HDF_LOGE("spi input para err\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ spiId = spiDevice->spiId;
+ resource = &spiDevice->resource;
+ if (resource == NULL) {
+ HDF_LOGE("resource is null\r\n");
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ status = OsalMutexLock(&spiDevice->mutex);
+ if (HDF_SUCCESS != status) {
+ HDF_LOGE("%s spi_mutex wait error = 0x%X!\r\n", __func__, status);
+ return HDF_ERR_TIMEOUT;
+ }
+ ret = tls_spi_write(data, (uint32_t)size);
+ if (ret) {
+ HDF_LOGE("spi tail send fail %ld, size %ld\r\n", ret, len);
+ }
+ OsalMutexUnlock(&spiDevice->mutex);
+ return ret;
+}
+
+/**
+ * SpiRecv
+ *
+ * @param[in] spiId the spi bus id
+ * @param[out] data spi recv data
+ * @param[in] size spi recv data size
+ * @param[in] timeOut timeOut in milisecond, set this value to HAL_WAIT_FOREVER
+ * if you want to wait forever
+ *
+ * @return 0 : on success, EIO : if the SPI device could not be initialised
+ */
+int32_t HalSpiRecv(struct SpiDevice *spiDevice, uint8_t *data, uint16_t size, uint32_t timeOut)
+{
+ int32_t ret = 0;
+ uint32_t len = size;
+ uint32_t remainder = 0;
+ int32_t status = HDF_FAILURE;
+ uint8_t *cmd = NULL;
+ uint32_t spiId;
+ struct SpiResource *resource = NULL;
+ if (spiDevice == NULL || data == NULL || size == 0) {
+ HDF_LOGE("spi input para err\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ spiId = spiDevice->spiId;
+ resource = &spiDevice->resource;
+ if (resource == NULL) {
+ HDF_LOGE("resource is null\r\n");
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ cmd = (uint8_t *)OsalMemAlloc(len);
+ if (cmd == NULL) {
+ HDF_LOGE("%s OsalMemAlloc size %ld error\r\n", __FUNCTION__, len);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ memset_s(cmd, len, 0, len);
+
+ status = OsalMutexLock(&spiDevice->mutex);
+ if (HDF_SUCCESS != status) {
+ HDF_LOGE("%s spi_mutex wait error = 0x%X!\r\n", __func__, status);
+ OsalMemFree(cmd);
+ return HDF_ERR_TIMEOUT;
+ }
+ remainder = len <= SPI_DMA_MAX ? len : SPI_DMA_MAX;
+
+ ret = tls_spi_read(data, remainder);
+
+ len -= remainder;
+ data += remainder;
+
+ if (ret) {
+ HDF_LOGE("spi tail fail %ld, size %ld\r\n", ret, len);
+ }
+ OsalMutexUnlock(&spiDevice->mutex);
+ OsalMemFree(cmd);
+ return ret;
+}
+
+int32_t HalSpiSendRecv(struct SpiDevice *spiDevice, uint8_t *txData, uint16_t txSize, uint8_t *rxData,
+ uint16_t rxSize)
+{
+ int32_t ret;
+ int32_t status;
+ uint32_t spiId;
+ struct SpiResource *resource = NULL;
+ if (spiDevice == NULL || txData == NULL || txSize == 0 || rxData == NULL || rxSize == 0) {
+ HDF_LOGE("spi input para err\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+ spiId = spiDevice->spiId;
+ resource = &spiDevice->resource;
+ status = OsalMutexLock(&spiDevice->mutex);
+ if (HDF_SUCCESS != status) {
+ HDF_LOGE("%s spi_mutex wait error = 0x%X!\r\n", __func__, status);
+ return HDF_ERR_TIMEOUT;
+ }
+ ret = tls_spi_xfer(txData, rxData, txSize, rxSize);
+ if (ret) {
+ HDF_LOGE("spi dma tail fail %d\r\n", ret);
+ }
+ OsalMutexUnlock(&spiDevice->mutex);
+ return ret;
+}
+
+static int32_t InitSpiDevice(struct SpiDevice *spiDevice)
+{
+ uint32_t spiPort;
+ struct SpiResource *resource = NULL;
+ if (spiDevice == NULL) {
+ HDF_LOGE("%s: invalid parameter\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ resource = &spiDevice->resource;
+ spiPort = spiDevice->spiId;
+
+ SpiIomuxInit(spiDevice);
+
+ if (spiDevice->mutex.realMutex == NULL) {
+ if (OsalMutexInit(&spiDevice->mutex) != HDF_SUCCESS) {
+ HDF_LOGE("spi Mutex create failed!\r\n");
+ return HDF_FAILURE;
+ }
+ }
+ tls_spi_init();
+ return HDF_SUCCESS;
+}
+
+/* get spi config from hcs file */
+static int32_t GetSpiDeviceResource(struct SpiDevice *spiDevice, const struct DeviceResourceNode *resourceNode)
+{
+ uint32_t relPin;
+ struct SpiResource *resource = NULL;
+ struct DeviceResourceIface *dri = NULL;
+ if (spiDevice == NULL || resourceNode == NULL) {
+ HDF_LOGE("%s: PARAM is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ resource = &spiDevice->resource;
+ if (resource == NULL) {
+ HDF_LOGE("%s: resource is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); // open HDF
+ if (dri == NULL || dri->GetUint32 == NULL) {
+ HDF_LOGE("DeviceResourceIface is invalid\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ if (dri->GetUint32(resourceNode, "num", &resource->num, 0) != HDF_SUCCESS) {
+ HDF_LOGE("spi config read num fail\r\n");
+ return HDF_FAILURE;
+ }
+ spiDevice->spiId = resource->num;
+
+ if (dri->GetUint32(resourceNode, "speed", &resource->speed, 0) != HDF_SUCCESS) {
+ HDF_LOGE("spi config read base fail\r\n");
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint32(resourceNode, "transmode", &resource->transmode, 0) != HDF_SUCCESS) {
+ HDF_LOGE("spi config read transmode fail\r\n");
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+int32_t AttachSpiDevice(struct SpiCntlr *spiCntlr, struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct SpiDevice *spiDevice = NULL;
+
+ if (spiCntlr == NULL || device == NULL || device->property == NULL) {
+ HDF_LOGE("%s: property is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ spiDevice = (struct SpiDevice *)OsalMemAlloc(sizeof(struct SpiDevice));
+ if (spiDevice == NULL) {
+ HDF_LOGE("%s: OsalMemAlloc spiDevice error\r\n", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+ spiDevice->mutex.realMutex = NULL;
+
+ ret = GetSpiDeviceResource(spiDevice, device->property);
+ if (ret != HDF_SUCCESS) {
+ (void)OsalMemFree(spiDevice);
+ return HDF_FAILURE;
+ }
+
+ spiCntlr->priv = spiDevice;
+ spiCntlr->busNum = spiDevice->spiId;
+ return InitSpiDevice(spiDevice);
+}
+/* SPI Method */
+static int32_t SpiDevGetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg);
+static int32_t SpiDevSetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg);
+static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg, uint32_t count);
+static int32_t SpiDevOpen(struct SpiCntlr *spiCntlr);
+static int32_t SpiDevClose(struct SpiCntlr *spiCntlr);
+
+struct SpiCntlrMethod g_SpiCntlrMethod = {
+ .GetCfg = SpiDevGetCfg,
+ .SetCfg = SpiDevSetCfg,
+ .Transfer = SpiDevTransfer,
+ .Open = SpiDevOpen,
+ .Close = SpiDevClose,
+};
+
+/* HdfDriverEntry method definitions */
+static int32_t SpiDriverBind(struct HdfDeviceObject *device);
+static int32_t SpiDriverInit(struct HdfDeviceObject *device);
+static void SpiDriverRelease(struct HdfDeviceObject *device);
+
+/* HdfDriverEntry definitions */
+struct HdfDriverEntry g_SpiDriverEntry = {
+ .moduleVersion = 1,
+ .moduleName = "W800_SPI_MODULE_HDF",
+ .Bind = SpiDriverBind,
+ .Init = SpiDriverInit,
+ .Release = SpiDriverRelease,
+};
+
+HDF_INIT(g_SpiDriverEntry);
+
+static int32_t SpiDriverBind(struct HdfDeviceObject *device)
+{
+ struct SpiCntlr *spiCntlr = NULL;
+ if (device == NULL) {
+ HDF_LOGE("Sample device object is null!\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+ HDF_LOGI("Enter %s:\r\n", __func__);
+ spiCntlr = (struct SpiCntlr *)OsalMemAlloc(sizeof(struct SpiCntlr));
+ if (spiCntlr == NULL) {
+ HDF_LOGE("%s: host is NULL\r\n", __func__);
+ return HDF_FAILURE;
+ }
+ device->service = &spiCntlr->service;
+ spiCntlr->device = device;
+ spiCntlr->priv = NULL;
+ return HDF_SUCCESS;
+}
+
+static int32_t SpiDriverInit(struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct SpiCntlr *spiCntlr = NULL;
+
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ HDF_LOGI("Enter %s:", __func__);
+ spiCntlr = SpiCntlrFromDevice(device);
+ if (spiCntlr == NULL) {
+ HDF_LOGE("%s: spiCntlr is NULL", __func__);
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+
+ ret = AttachSpiDevice(spiCntlr, device); // SpiCntlr add SpiDevice to priv
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: attach error\r\n", __func__);
+ return HDF_DEV_ERR_ATTACHDEV_FAIL;
+ }
+
+ spiCntlr->method = &g_SpiCntlrMethod; // register callback
+
+ return ret;
+}
+
+static void SpiDriverRelease(struct HdfDeviceObject *device)
+{
+ struct SpiCntlr *spiCntlr = NULL;
+ struct SpiDevice *spiDevice = NULL;
+
+ HDF_LOGI("Enter %s\r\n", __func__);
+
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL\r\n", __func__);
+ return;
+ }
+
+ spiCntlr = SpiCntlrFromDevice(device);
+ if (spiCntlr == NULL || spiCntlr->priv == NULL) {
+ HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__);
+ return;
+ }
+
+ spiDevice = (struct SpiDevice *)spiCntlr->priv;
+ if (spiDevice != NULL) {
+ OsalMemFree(spiDevice);
+ }
+ return;
+}
+
+static int32_t SpiDevOpen(struct SpiCntlr *spiCntlr)
+{
+ HDF_LOGI("Enter %s\r\n", __func__);
+ int ret;
+ struct SpiDevice *spiDevice = NULL;
+ struct SpiResource *resource = NULL;
+ if (spiCntlr == NULL || spiCntlr->priv == NULL) {
+ HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ spiDevice = (struct SpiDevice *)spiCntlr->priv;
+ if (spiDevice == NULL) {
+ HDF_LOGE("spi device is NULL\r\n");
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+ resource = &spiDevice->resource;
+
+ if (resource->transmode == SPI_DMA_TRANSFER) {
+ tls_spi_trans_type(SPI_USE_DMA_TRANSFER);
+ }
+ if (resource->dataSize == SPI_MASTER_FIFO_SIZE) {
+ tls_spi_trans_type(SPI_WORD_TRANSFER);
+ }
+ tls_spi_setup(resource->mode, TLS_SPI_CS_LOW, resource->speed);
+ return HDF_SUCCESS;
+}
+
+static int32_t SpiDevClose(struct SpiCntlr *spiCntlr)
+{
+ int ret;
+ struct SpiDevice *spiDevice = NULL;
+ if (spiCntlr == NULL || spiCntlr->priv == NULL) {
+ HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ spiDevice = (struct SpiDevice *)spiCntlr->priv;
+ if (spiDevice == NULL) {
+ HDF_LOGE("spi device is NULL\r\n");
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t SpiDevGetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg)
+{
+ struct SpiDevice *spiDevice = NULL;
+ if (spiCntlr == NULL || spiCfg == NULL || spiCntlr->priv == NULL) {
+ HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ spiDevice = (struct SpiDevice *)spiCntlr->priv;
+ if (spiDevice == NULL) {
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+ spiCfg->maxSpeedHz = spiDevice->resource.speed;
+ spiCfg->mode = spiDevice->resource.mode;
+ spiCfg->transferMode = spiDevice->resource.transmode;
+ spiCfg->bitsPerWord = spiDevice->resource.dataSize;
+
+ return HDF_SUCCESS;
+}
+static int32_t SpiDevSetCfg(struct SpiCntlr *spiCntlr, struct SpiCfg *spiCfg)
+{
+ struct SpiDevice *spiDevice = NULL;
+ if (spiCntlr == NULL || spiCfg == NULL || spiCntlr->priv == NULL) {
+ HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ spiDevice = (struct SpiDevice *)spiCntlr->priv;
+ if (spiDevice == NULL) {
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+ spiDevice->resource.speed = spiCfg->maxSpeedHz;
+ spiDevice->resource.mode = spiCfg->mode;
+ spiDevice->resource.transmode = spiCfg->transferMode;
+ spiDevice->resource.dataSize = spiCfg->bitsPerWord;
+ return SpiDevOpen(spiCntlr);
+}
+
+static int32_t SpiDevTransfer(struct SpiCntlr *spiCntlr, struct SpiMsg *spiMsg, uint32_t count)
+{
+ uint32_t spiId;
+ struct SpiDevice *spiDevice = NULL;
+ struct SpiMsg *msg = NULL;
+ if (spiCntlr == NULL || spiCntlr->priv == NULL) {
+ HDF_LOGE("%s: spiCntlr is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ HDF_LOGI("%s: %u Enter\r\n", __func__, spiId);
+ spiDevice = (struct SpiDevice *)spiCntlr->priv;
+ spiId = spiDevice->spiId;
+ for (size_t i = 0; i < count; i++) {
+ msg = &spiMsg[i];
+ /* pull down cs at first */
+ if (spiDevice->resource.spiCsSoft) {
+ tls_gpio_write(WM_IO_PB_00 + spiDevice->resource.spiCsPin, 0);
+ }
+
+ if ((msg->wbuf != NULL) && (msg->rbuf == NULL)) {
+ HalSpiSend(spiDevice, msg->wbuf, msg->len, TIMEOUT);
+ }
+ if ((msg->rbuf != NULL) && (msg->wbuf == NULL)) {
+ HalSpiRecv(spiDevice, msg->rbuf, msg->len, TIMEOUT);
+ }
+ if ((msg->wbuf != NULL) && (msg->rbuf != NULL)) {
+ HalSpiSendRecv(spiDevice, msg->wbuf, msg->len, msg->rbuf, msg->len);
+ }
+
+ /* pull pull up cs at the end */
+ if (msg->keepCs == 0 && spiDevice->resource.spiCsSoft) {
+ tls_gpio_write(WM_IO_PB_00 + spiDevice->resource.spiCsPin, 1);
+ }
+ }
+ return HDF_SUCCESS;
+}
diff --git a/platform/uart/BUILD.gn b/platform/uart/BUILD.gn
index e7558566a37370544fc6282c2f13eceb951fc9ae..4d4b3711f5a7d757fa20291a40240a2ab306c0ff 100644
--- a/platform/uart/BUILD.gn
+++ b/platform/uart/BUILD.gn
@@ -1,31 +1,10 @@
#
-# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved.
+# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
#
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
+# This file is dual licensed: you can use it either under the terms of
+# the GPL, or the BSD license, at your option.
+# See the LICENSE file in the root of this repository for complete details.
#
-# 1. Redistributions of source code must retain the above copyright notice, this list of
-# conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice, this list
-# of conditions and the following disclaimer in the documentation and/or other materials
-# provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its contributors may be used
-# to endorse or promote products derived from this software without specific prior written
-# permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
@@ -40,6 +19,29 @@ hdf_driver(module_name) {
if (defined(LOSCFG_SOC_COMPANY_GOODIX)) {
sources += [ "uart_gr5xx.c" ]
}
+ if (defined(LOSCFG_SOC_COMPANY_ASRMICRO)) {
+ sources += [ "uart_asr.c" ]
+ }
+ if (defined(LOSCFG_SOC_COMPANY_WINNERMICRO)) {
+ sources += [ "uart_wm.c" ]
+ }
+ if (defined(LOSCFG_SOC_SERIES_STM32F4xx)) {
+ sources += [ "uart_stm32f4xx.c" ]
+ }
include_dirs = [ "." ]
+ if (defined(LOSCFG_SHIELD_V200ZR_EVB_T1) &&
+ defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) {
+ deps = [ "//device/board/fnlink/shields" ]
+ }
+ if (defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) {
+ HDF_HCS_BUILD_PATH = rebase_path(
+ "//device/board/$device_company/$device_name/liteos_m/hdf_config")
+ cmd = "if [ -f ${HDF_HCS_BUILD_PATH}/BUILD.gn ]; then echo true; else echo false; fi"
+ HAVE_HCS_BUILD_PATH =
+ exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
+ if (HAVE_HCS_BUILD_PATH) {
+ deps = [ "${HDF_HCS_BUILD_PATH}" ]
+ }
+ }
}
diff --git a/platform/uart/uart_asr.c b/platform/uart/uart_asr.c
new file mode 100644
index 0000000000000000000000000000000000000000..d97ec440e6ae4984dcbde13fbb739d7e1a85479e
--- /dev/null
+++ b/platform/uart/uart_asr.c
@@ -0,0 +1,695 @@
+/*
+ * Copyright (c) 2022 ASR Microelectronics (Shanghai) Co., Ltd. All rights reserved.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include "uart/uart_core.h"
+#include "device_resource_if.h"
+#include "hdf_base.h"
+#include "hdf_log.h"
+#include "los_sem.h"
+#include "osal_mem.h"
+#include "duet_pinmux.h"
+#include "duet_uart.h"
+
+#define ASR_UART_NUM DUET_UART_NUM
+#define asr_uart_config_t duet_uart_config_t
+#define asr_uart_dev_t duet_uart_dev_t
+#define asr_uart_struct_init duet_uart_struct_init
+#define asr_uart_dma_config duet_uart_dma_config
+#define asr_uart_init duet_uart_init
+#define asr_uart_send duet_uart_send
+#define asr_uart_finalize duet_uart_finalize
+#define asr_uart_start duet_uart_start
+#define asr_uart_stop duet_uart_stop
+#define asr_uart_set_callback duet_uart_set_callback
+#define asr_uart_calc_baud duet_uart_calc_baud
+#define asr_uart_interrupt_config duet_uart_interrupt_config
+#define asr_uart_clear_interrupt duet_uart_clear_interrupt
+#define asr_uart_get_raw_interrupt_status duet_uart_get_raw_interrupt_status
+#define asr_uart_get_interrupt_status duet_uart_get_interrupt_status
+#define asr_uart_get_flag_status duet_uart_get_flag_status
+#define asr_uart_callback_func duet_uart_callback_func
+#define asr_pinmux_config duet_pinmux_config
+
+#define HDF_LOG_TAG uart_asr
+
+#define DEFAULT_BAUDRATE 115200
+#define DEFAULT_DATABITS UART_ATTR_DATABIT_8
+#define DEFAULT_STOPBITS UART_ATTR_STOPBIT_1
+#define DEFAULT_PARITY UART_ATTR_PARITY_NONE
+#define CONFIG_MAX_BAUDRATE 921600
+#define UART_STATE_NOT_OPENED 0
+#define UART_STATE_OPENING 1
+#define UART_STATE_USEABLE 2
+#define UART_STATE_SUSPENED 3
+#define UART_FLG_DMA_RX (1 << 0)
+#define UART_FLG_DMA_TX (1 << 1)
+#define UART_FLG_RD_BLOCK (1 << 2)
+#define UART_TRANS_TIMEOUT 1000
+#define UART_RX_BUF_LEN 512
+
+typedef int32_t (*app_uart_cfg_handler_t)(struct UartDriverData *udd);
+struct UartResource {
+ uint32_t port;
+ uint32_t pin_tx_pin;
+ uint32_t pin_tx_mux;
+ uint32_t pin_rx_pin;
+ uint32_t pin_rx_mux;
+ uint32_t tx_rx;
+};
+
+struct UartDriverData {
+ asr_uart_dev_t params;
+ struct UartAttribute attr;
+ struct UartResource resource;
+ app_uart_cfg_handler_t config;
+ int32_t count;
+ int32_t state;
+ uint32_t flags;
+};
+
+static uint32_t g_uartTxMutex[ASR_UART_NUM];
+static uint32_t g_uartRxMutex[ASR_UART_NUM];
+static uint8_t *rx_buf[ASR_UART_NUM];
+static uint16_t rx_head[ASR_UART_NUM];
+static uint16_t rx_tail[ASR_UART_NUM];
+
+static void Uart0Callback(char data);
+static void Uart1Callback(char data);
+static void Uart2Callback(char data);
+
+static const asr_uart_callback_func g_evtHandler[ASR_UART_NUM] = {
+ Uart0Callback,
+ Uart1Callback,
+ Uart2Callback
+};
+
+static void Uart0Callback(char data)
+{
+ uint8_t *dst = rx_buf[UART0_INDEX];
+ if (dst) {
+ dst[rx_head[UART0_INDEX]++] = (uint8_t)data;
+ rx_head[UART0_INDEX] %= UART_RX_BUF_LEN;
+ }
+}
+
+static void Uart1Callback(char data)
+{
+ uint8_t *dst = rx_buf[UART1_INDEX];
+ if (dst) {
+ dst[rx_head[UART1_INDEX]++] = (uint8_t)data;
+ rx_head[UART1_INDEX] %= UART_RX_BUF_LEN;
+ }
+}
+static void Uart2Callback(char data)
+{
+ uint8_t *dst = rx_buf[UART2_INDEX];
+ if (dst) {
+ dst[rx_head[UART2_INDEX]++] = (uint8_t)data;
+ rx_head[UART2_INDEX] %= UART_RX_BUF_LEN;
+ }
+}
+
+static uint32_t GetUartDataBits(uint32_t attrDataBits)
+{
+ uint32_t dataBits;
+
+ switch (attrDataBits) {
+ case UART_ATTR_DATABIT_5:
+ dataBits = DATA_5BIT;
+ break;
+ case UART_ATTR_DATABIT_6:
+ dataBits = DATA_6BIT;
+ break;
+ case UART_ATTR_DATABIT_7:
+ dataBits = DATA_7BIT;
+ break;
+ case UART_ATTR_DATABIT_8:
+ dataBits = DATA_8BIT;
+ break;
+ default:
+ dataBits = DATA_8BIT;
+ break;
+ }
+
+ return dataBits;
+}
+
+static uint32_t GetUartStopBits(uint32_t attrStopBits)
+{
+ uint32_t stopBits;
+
+ switch (attrStopBits) {
+ case UART_ATTR_STOPBIT_1:
+ stopBits = STOP_1BIT;
+ break;
+ case UART_ATTR_STOPBIT_2:
+ stopBits = STOP_2BITS;
+ break;
+ default:
+ stopBits = STOP_1BIT;
+ break;
+ }
+
+ return stopBits;
+}
+
+static uint32_t GetUartParity(uint32_t attrParity)
+{
+ uint32_t parity;
+
+ switch (attrParity) {
+ case UART_ATTR_PARITY_NONE:
+ parity = PARITY_NO;
+ break;
+ case UART_ATTR_PARITY_ODD:
+ parity = PARITY_ODD;
+ break;
+ case UART_ATTR_PARITY_EVEN:
+ parity = PARITY_EVEN;
+ break;
+ default:
+ parity = PARITY_NO;
+ break;
+ }
+
+ return parity;
+}
+
+static uint32_t GetUartFlowControl(uint32_t rts, uint32_t cts)
+{
+ uint32_t flow_control;
+
+ if (!rts && !cts) {
+ flow_control = FLOW_CTRL_DISABLED;
+ } else if (rts && cts) {
+ flow_control = FLOW_CTRL_CTS_RTS;
+ } else if (rts) {
+ flow_control = FLOW_CTRL_RTS;
+ } else {
+ flow_control = FLOW_CTRL_CTS;
+ }
+
+ return flow_control;
+}
+
+static int32_t Asr582xUartConfig(struct UartDriverData *udd)
+{
+ uint32_t ret;
+ asr_uart_dev_t *params = NULL;
+
+ if (udd == NULL) {
+ return HDF_FAILURE;
+ }
+ asr_pinmux_config(udd->resource.pin_tx_pin, udd->resource.pin_tx_mux);
+ asr_pinmux_config(udd->resource.pin_rx_pin, udd->resource.pin_rx_mux);
+ params = &udd->params;
+ params->port = udd->resource.port;
+ params->config.data_width = GetUartDataBits(udd->attr.dataBits);
+ params->config.stop_bits = GetUartStopBits(udd->attr.stopBits);
+ params->config.parity = GetUartParity(udd->attr.parity);
+ params->config.flow_control = GetUartFlowControl(udd->attr.rts, udd->attr.cts);
+ params->config.mode = udd->resource.tx_rx;
+ params->priv = (void *)g_evtHandler[udd->resource.port];
+
+ ret = asr_uart_init(params);
+ if (ret != 0) {
+ HDF_LOGE("%s , app uart init failed\r\n", __func__);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t UartHostDevRead(struct UartHost *host, uint8_t *data, uint32_t size)
+{
+ int32_t ret;
+ uint32_t uwRet = 0;
+ uint32_t recv_len = 0;
+ struct UartDriverData *udd = NULL;
+ uint8_t port = 0;
+ uint8_t *src = NULL;
+
+ if ((host == NULL) || (host->priv == NULL) || (data == NULL)) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ udd = (struct UartDriverData *)host->priv;
+ port = udd->resource.port;
+ src = rx_buf[port];
+ if (udd->state != UART_STATE_USEABLE) {
+ HDF_LOGE("%s: uart_%d not useable", __func__, port);
+ return HDF_FAILURE;
+ }
+
+ LOS_MuxPend(g_uartRxMutex[port], LOS_WAIT_FOREVER);
+ if (udd->flags & UART_FLG_RD_BLOCK) {
+ while (recv_len != size) {
+ if (rx_head[port] != rx_tail[port]) {
+ data[recv_len++] = src[rx_tail[port]++];
+ rx_tail[port] %= UART_RX_BUF_LEN;
+ }
+ }
+ } else {
+ while ((recv_len != size) && (rx_head[port] != rx_tail[port])) {
+ data[recv_len++] = src[rx_tail[port]++];
+ rx_tail[port] %= UART_RX_BUF_LEN;
+ }
+ }
+ LOS_MuxPost(g_uartRxMutex[port]);
+
+ return recv_len;
+}
+
+static int32_t UartHostDevWrite(struct UartHost *host, uint8_t *data, uint32_t size)
+{
+ int32_t ret;
+ struct UartDriverData *udd = NULL;
+
+ if ((host == NULL) || (host->priv == NULL) || (data == NULL)) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ udd = (struct UartDriverData *)host->priv;
+ if (udd->state != UART_STATE_USEABLE) {
+ HDF_LOGE("%s: uart_%d not useable", __func__, udd->resource.port);
+ return HDF_FAILURE;
+ }
+
+ LOS_MuxPend(g_uartTxMutex[udd->resource.port], LOS_WAIT_FOREVER);
+ ret = asr_uart_send(&udd->params, data, size, UART_TRANS_TIMEOUT);
+ if (ret != 0) {
+ LOS_MuxPost(g_uartTxMutex[udd->resource.port]);
+ HDF_LOGE("%s: uart_%d send %d data failed", __func__, udd->resource.port, size);
+ return HDF_FAILURE;
+ }
+ LOS_MuxPost(g_uartTxMutex[udd->resource.port]);
+
+ return HDF_SUCCESS;
+}
+
+static int32_t UartHostDevGetBaud(struct UartHost *host, uint32_t *baudRate)
+{
+ struct UartDriverData *udd = NULL;
+
+ if (host == NULL || host->priv == NULL || baudRate == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ udd = (struct UartDriverData *)host->priv;
+ if (udd->state != UART_STATE_USEABLE) {
+ HDF_LOGE("%s: uart_%d not useable", __func__, udd->resource.port);
+ return HDF_FAILURE;
+ }
+ *baudRate = udd->params.config.baud_rate;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t UartHostDevSetBaud(struct UartHost *host, uint32_t baudRate)
+{
+ struct UartDriverData *udd = NULL;
+
+ if (host == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ udd = (struct UartDriverData *)host->priv;
+ if (udd->state != UART_STATE_USEABLE) {
+ HDF_LOGE("%s: uart_%d not useable", __func__, udd->resource.port);
+ return HDF_FAILURE;
+ }
+ if ((baudRate > 0) && (baudRate <= CONFIG_MAX_BAUDRATE)) {
+ udd->params.config.baud_rate = baudRate;
+ if (udd->config == NULL) {
+ HDF_LOGE("%s: not support", __func__);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+ if (udd->config(udd) != HDF_SUCCESS) {
+ HDF_LOGE("%s: config baudrate %d failed", __func__, baudRate);
+ return HDF_FAILURE;
+ }
+ } else {
+ HDF_LOGE("%s: invalid baudrate, which is:%d", __func__, baudRate);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribute *attribute)
+{
+ struct UartDriverData *udd = NULL;
+
+ if (host == NULL || host->priv == NULL || attribute == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ udd = (struct UartDriverData *)host->priv;
+ if (udd->state != UART_STATE_USEABLE) {
+ return HDF_FAILURE;
+ }
+
+ *attribute = udd->attr;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribute *attribute)
+{
+ struct UartDriverData *udd = NULL;
+
+ if (host == NULL || host->priv == NULL || attribute == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ udd = (struct UartDriverData *)host->priv;
+ if (udd->state != UART_STATE_USEABLE) {
+ HDF_LOGE("%s: uart_%d not useable", __func__, udd->resource.port);
+ return HDF_FAILURE;
+ }
+
+ udd->attr = *attribute;
+ if (udd->config == NULL) {
+ HDF_LOGE("%s: not support", __func__);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+ if (udd->config(udd) != HDF_SUCCESS) {
+ HDF_LOGE("%s: config failed", __func__);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t UartHostDevSetTransMode(struct UartHost *host, enum UartTransMode mode)
+{
+ struct UartDriverData *udd = NULL;
+
+ if (host == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ udd = (struct UartDriverData *)host->priv;
+ if (udd->state != UART_STATE_USEABLE) {
+ HDF_LOGE("%s: uart_%d not useable", __func__, udd->resource.port);
+ return HDF_FAILURE;
+ }
+ if (UART_MODE_RD_BLOCK == mode) {
+ udd->flags |= UART_FLG_RD_BLOCK;
+ } else if (UART_MODE_RD_NONBLOCK == mode) {
+ udd->flags &= (~UART_FLG_RD_BLOCK);
+ } else {
+ HDF_LOGE("%s: uart_%d not support mode:%d", __func__, udd->resource.port, mode);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t UartDevSemInit(uint32_t id)
+{
+ uint32_t uwRet = 0;
+
+ uwRet = LOS_MuxCreate(&g_uartTxMutex[id]);
+ if (uwRet != LOS_OK) {
+ return HDF_FAILURE;
+ }
+
+ uwRet = LOS_MuxCreate(&g_uartRxMutex[id]);
+ if (uwRet != LOS_OK) {
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static void UartDevSemDeinit(uint32_t id)
+{
+ if (g_uartTxMutex[id] != 0) {
+ LOS_MuxDelete(g_uartTxMutex[id]);
+ }
+
+ if (g_uartRxMutex[id] != 0) {
+ LOS_MuxDelete(g_uartRxMutex[id]);
+ }
+
+ g_uartTxMutex[id] = 0;
+ g_uartRxMutex[id] = 0;
+}
+
+static int32_t UartHostDevInit(struct UartHost *host)
+{
+ struct UartDriverData *udd = NULL;
+ uint32_t ret = 0;
+ uint8_t *ptxBuf = NULL;
+
+ if (host == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ udd = (struct UartDriverData *)host->priv;
+ if (udd->resource.port >= ASR_UART_NUM) {
+ HDF_LOGE("%s: uart id is greater than the maximum", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ if (udd->state == UART_STATE_NOT_OPENED) {
+ udd->state = UART_STATE_OPENING;
+
+ ptxBuf = (uint8_t *)OsalMemCalloc(UART_RX_BUF_LEN);
+ if (ptxBuf == NULL) {
+ HDF_LOGE("%s: alloc tx buffer failed", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ ret = UartDevSemInit(udd->resource.port);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: uart semaphor init failed", __func__);
+ UartDevSemDeinit(udd->resource.port);
+ return HDF_FAILURE;
+ }
+
+ rx_buf[udd->resource.port] = ptxBuf;
+ udd->config = Asr582xUartConfig;
+
+ if (udd->config(udd) != HDF_SUCCESS) {
+ UartDevSemDeinit(udd->resource.port);
+ (void)OsalMemFree(rx_buf[udd->resource.port]);
+ rx_buf[udd->resource.port] = NULL;
+ return HDF_FAILURE;
+ }
+ }
+
+ udd->state = UART_STATE_USEABLE;
+ udd->count++;
+ return HDF_SUCCESS;
+}
+
+static int32_t UartHostDevDeinit(struct UartHost *host)
+{
+ struct UartDriverData *udd = NULL;
+ if (host == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ udd = (struct UartDriverData *)host->priv;
+ if ((--udd->count) != 0) {
+ return HDF_SUCCESS;
+ }
+ asr_uart_finalize(&udd->params);
+ UartDevSemDeinit(udd->resource.port);
+ if (rx_buf[udd->resource.port] != NULL) {
+ (void)OsalMemFree(rx_buf[udd->resource.port]);
+ rx_buf[udd->resource.port] = NULL;
+ }
+
+ udd->state = UART_STATE_NOT_OPENED;
+ return HDF_SUCCESS;
+}
+
+struct UartHostMethod g_uartHostMethod = {
+ .Init = UartHostDevInit,
+ .Deinit = UartHostDevDeinit,
+ .Read = UartHostDevRead,
+ .Write = UartHostDevWrite,
+ .SetBaud = UartHostDevSetBaud,
+ .GetBaud = UartHostDevGetBaud,
+ .SetAttribute = UartHostDevSetAttribute,
+ .GetAttribute = UartHostDevGetAttribute,
+ .SetTransMode = UartHostDevSetTransMode,
+};
+
+static int32_t UartGetPinConfigFromHcs(struct UartDriverData *udd, const struct DeviceResourceNode *node)
+{
+ uint32_t resourceData;
+ struct DeviceResourceIface *iface = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+
+ if (iface == NULL || iface->GetUint32 == NULL) {
+ HDF_LOGE("%s: face is invalid", __func__);
+ return HDF_FAILURE;
+ }
+
+ if (iface->GetUint32(node, "port", &resourceData, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s: read port fail", __func__);
+ return HDF_FAILURE;
+ }
+ udd->resource.port = resourceData;
+
+ if (iface->GetUint32(node, "pin_tx_pin", &resourceData, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s: read pin_tx_pin fail", __func__);
+ return HDF_FAILURE;
+ }
+ udd->resource.pin_tx_pin = resourceData;
+
+ if (iface->GetUint32(node, "pin_tx_mux", &resourceData, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s: read pin_tx_pin fail", __func__);
+ return HDF_FAILURE;
+ }
+ udd->resource.pin_tx_mux = resourceData;
+
+ if (iface->GetUint32(node, "pin_rx_pin", &resourceData, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s: read pin_rx_pin fail", __func__);
+ return HDF_FAILURE;
+ }
+ udd->resource.pin_rx_pin = resourceData;
+
+ if (iface->GetUint32(node, "pin_rx_mux", &resourceData, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s: read pin_rx_pin fail", __func__);
+ return HDF_FAILURE;
+ }
+ udd->resource.pin_rx_mux = resourceData;
+
+ if (iface->GetUint32(node, "tx_rx", &resourceData, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s: read tx_rx fail", __func__);
+ return HDF_FAILURE;
+ }
+ udd->resource.tx_rx = resourceData;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t UartDevAttach(struct UartHost *host, struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct UartDriverData *udd = NULL;
+
+ if (device->property == NULL) {
+ HDF_LOGE("%s: property is null", __func__);
+ return HDF_FAILURE;
+ }
+ udd = (struct UartDriverData *)OsalMemCalloc(sizeof(*udd));
+ if (udd == NULL) {
+ HDF_LOGE("%s: OsalMemCalloc udd error", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ ret = UartGetPinConfigFromHcs(udd, device->property);
+ if (ret != HDF_SUCCESS) {
+ (void)OsalMemFree(udd);
+ return HDF_FAILURE;
+ }
+
+ udd->state = UART_STATE_NOT_OPENED;
+ udd->config = NULL;
+ udd->count = 0;
+
+ asr_uart_struct_init(&udd->params);
+ udd->params.port = udd->resource.port;
+ udd->params.config.baud_rate = DEFAULT_BAUDRATE;
+ udd->attr.dataBits = DEFAULT_DATABITS;
+ udd->attr.stopBits = DEFAULT_STOPBITS;
+ udd->attr.parity = DEFAULT_PARITY;
+
+ host->priv = udd;
+ host->num = udd->resource.port;
+
+ return HDF_SUCCESS;
+}
+
+static void UartDevDetach(struct UartHost *host)
+{
+ struct UartDriverData *udd = NULL;
+
+ if (host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return;
+ }
+ udd = (struct UartDriverData *)host->priv;
+ if (udd->state != UART_STATE_NOT_OPENED) {
+ HDF_LOGE("%s: uart driver data state invalid", __func__);
+ return;
+ }
+
+ (void)OsalMemFree(udd);
+ host->priv = NULL;
+}
+
+static int32_t HdfUartDeviceBind(struct HdfDeviceObject *device)
+{
+ if (device == NULL) {
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ return (UartHostCreate(device) == NULL) ? HDF_FAILURE : HDF_SUCCESS;
+}
+
+int32_t HdfUartDeviceInit(struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct UartHost *host = NULL;
+
+ if (device == NULL) {
+ HDF_LOGE("%s: device is null", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ host = UartHostFromDevice(device);
+ if (host == NULL) {
+ HDF_LOGE("%s: host is null", __func__);
+ return HDF_FAILURE;
+ }
+ ret = UartDevAttach(host, device);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: attach error", __func__);
+ return HDF_FAILURE;
+ }
+ host->method = &g_uartHostMethod;
+ return ret;
+}
+
+void HdfUartDeviceRelease(struct HdfDeviceObject *device)
+{
+ struct UartHost *host = NULL;
+
+ if (device == NULL) {
+ HDF_LOGE("%s: device is null", __func__);
+ return;
+ }
+ host = UartHostFromDevice(device);
+ if (host == NULL) {
+ HDF_LOGE("%s: host is null", __func__);
+ return;
+ }
+ if (host->priv != NULL) {
+ UartDevDetach(host);
+ }
+ UartHostDestroy(host);
+}
+
+struct HdfDriverEntry g_hdfUartDevice = {
+ .moduleVersion = 1,
+ .moduleName = "HDF_PLATFORM_UART",
+ .Bind = HdfUartDeviceBind,
+ .Init = HdfUartDeviceInit,
+ .Release = HdfUartDeviceRelease,
+};
+
+HDF_INIT(g_hdfUartDevice);
diff --git a/platform/uart/uart_bes.c b/platform/uart/uart_bes.c
index b17ad54861489384b52187fed2f3cb18d82fca1d..cc2a26af89f26276b20d7833aceb75787c4fbbec 100755
--- a/platform/uart/uart_bes.c
+++ b/platform/uart/uart_bes.c
@@ -1,39 +1,49 @@
/*
- * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * This file is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
+
#include "uart_bes.h"
#include
#include
#include "hal_iomux.h"
#include "hal_timer.h"
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+#include "hcs_macro.h"
+#include "hdf_config_macro.h"
+#else
#include "device_resource_if.h"
+#endif
#include "hal_trace.h"
#include "hal_cache.h"
#include "hdf_log.h"
-#define HDF_UART_TMO 1000
+
+#define HDF_UART_TMO OSAL_WAIT_FOREVER
#define HDF_LOG_TAG uartDev
#define UART_FIFO_MAX_BUFFER 2048
#define UART_DMA_RING_BUFFER_SIZE 256 // mast be 2^n
-
+#ifdef LOSCFG_SOC_SERIES_BES2700
+#include "hal_location.h"
+#define MAX_UART_NUMBER 2
+#define MAX_UART_ID HAL_UART_ID_1
+static SRAM_BSS_LOC unsigned char g_halUartBuf[UART_DMA_RING_BUFFER_SIZE];
+static SRAM_BSS_LOC unsigned char g_halUart1Buf[UART_DMA_RING_BUFFER_SIZE];
+static unsigned char *g_uartKfifoBuffer[MAX_UART_NUMBER] = { NULL, NULL };
+#elif defined (LOSCFG_SOC_SERIES_BES2600)
+#define MAX_UART_NUMBER 3
+#define MAX_UART_ID HAL_UART_ID_2
static __SRAMBSS unsigned char g_halUartBuf[UART_DMA_RING_BUFFER_SIZE];
static __SRAMBSS unsigned char g_halUart1Buf[UART_DMA_RING_BUFFER_SIZE];
static __SRAMBSS unsigned char g_halUart2Buf[UART_DMA_RING_BUFFER_SIZE];
+static unsigned char *g_uartKfifoBuffer[MAX_UART_NUMBER] = {NULL, NULL, NULL};
+#endif
-static struct UART_CTX_OBJ g_uartCtx[4] = {0};
-static unsigned char *g_uartKfifoBuffer[4] = {NULL, NULL, NULL, NULL};
+static struct UART_CTX_OBJ g_uartCtx[MAX_UART_NUMBER] = {0};
struct HAL_UART_CFG_T g_lowUartCfg = {
// used for tgdb cli console
.parity = HAL_UART_PARITY_NONE,
@@ -50,21 +60,31 @@ struct HAL_UART_CFG_T g_lowUartCfg = {
static void HalSetUartIomux(enum HAL_UART_ID_T uartId)
{
+ if (uartId > MAX_UART_ID) {
+ HDF_LOGE("%s %d not support!\r\n", __func__, uartId);
+ return;
+ }
if (uartId == HAL_UART_ID_0) {
hal_iomux_set_uart0();
- } else if (uartId == HAL_UART_ID_1) {
+ }
+ if (uartId == HAL_UART_ID_1) {
hal_iomux_set_uart1();
- } else if (uartId == HAL_UART_ID_2) {
+ }
+#ifdef LOSCFG_SOC_SERIES_BES2600
+ if (uartId == HAL_UART_ID_2) {
hal_iomux_set_uart2();
- } else {
- hal_iomux_set_uart3();
}
+#endif
}
-static void HalUartRxStart(uint32_t uartId)
+static void HalUartStartDmaRx(uint32_t uartId)
{
+ if (uartId > MAX_UART_ID) {
+ HDF_LOGE("%s %d not support!\r\n", __func__, uartId);
+ return;
+ }
struct HAL_DMA_DESC_T dmaDescRx;
- unsigned int descCnt = 1;
+ uint32_t descCnt;
union HAL_UART_IRQ_T mask;
mask.reg = 0;
@@ -73,58 +93,61 @@ static void HalUartRxStart(uint32_t uartId)
mask.OE = 0;
mask.PE = 0;
mask.RT = 1;
-
+ descCnt = 1;
hal_uart_dma_recv_mask(uartId, g_uartCtx[uartId].buffer, UART_DMA_RING_BUFFER_SIZE, &dmaDescRx, &descCnt, &mask);
}
-static void UartRxHandler(enum HAL_UART_ID_T id, union HAL_UART_IRQ_T status)
+static void UartRxHandler(enum HAL_UART_ID_T uartId, union HAL_UART_IRQ_T status)
{
- int32_t ret;
-
+ if (uartId > MAX_UART_ID) {
+ HDF_LOGE("%s %d not support!\r\n", __func__, uartId);
+ return;
+ }
if (status.TX) {
- ret = OsalSemPost(&g_uartCtx[id].txSem);
- ASSERT(ret == HDF_SUCCESS, "%s: Failed to release write_sem: %d", __func__, ret);
+ if (OsalSemPost(&g_uartCtx[uartId].txSem) != HDF_SUCCESS) {
+ HDF_LOGE("%s OsalSemPost txSem failed!\r\n", __func__);
+ return;
+ }
}
if (status.RX || status.RT) {
- ret = OsalSemPost(&g_uartCtx[id].rxSem);
- ASSERT(ret == HDF_SUCCESS, "%s: Failed to release read_sem: %d", __func__, ret);
+ if (OsalSemPost(&g_uartCtx[uartId].rxSem) != HDF_SUCCESS) {
+ HDF_LOGE("%s OsalSemPost rxSem failed!\r\n", __func__);
+ return;
+ }
}
}
static void UartDmaRxHandler(uint32_t xferSize, int dmaError, union HAL_UART_IRQ_T status)
{
- uint32_t len = 0;
- uint32_t uartid = 0;
-
- len = kfifo_put(&g_uartCtx[uartid].fifo, g_uartCtx[uartid].buffer, xferSize);
+ uint32_t len;
+ len = kfifo_put(&g_uartCtx[HAL_UART_ID_0].fifo, g_uartCtx[HAL_UART_ID_0].buffer, xferSize);
if (len < xferSize) {
HDF_LOGE("%s ringbuf is full have %d need %d\r", __FUNCTION__, (int)len, (int)xferSize);
return;
}
- memset_s(g_uartCtx[uartid].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE);
- OsalSemPost(&g_uartCtx[uartid].rxSem);
- HalUartRxStart(uartid);
+ (void)memset_s(g_uartCtx[HAL_UART_ID_0].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE);
+ OsalSemPost(&g_uartCtx[HAL_UART_ID_0].rxSem);
+ HalUartStartDmaRx(HAL_UART_ID_0);
}
static void UartDmaTxHandler(uint32_t xferSize, int dmaError)
{
- OsalSemPost(&g_uartCtx[0].txSem);
+ OsalSemPost(&g_uartCtx[HAL_UART_ID_0].txSem);
}
static void Uart1DmaRxHandler(uint32_t xferSize, int dmaError, union HAL_UART_IRQ_T status)
{
- uint32_t len = 0;
- uint32_t uartid = HAL_UART_ID_1;
- len = kfifo_put(&g_uartCtx[uartid].fifo, g_uartCtx[uartid].buffer, xferSize);
+ uint32_t len;
+ len = kfifo_put(&g_uartCtx[HAL_UART_ID_1].fifo, g_uartCtx[HAL_UART_ID_1].buffer, xferSize);
if (len < xferSize) {
HDF_LOGE("%s ringbuf is full have %d need %d\r", __FUNCTION__, (int)len, (int)xferSize);
return;
}
- memset_s(g_uartCtx[uartid].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE);
- OsalSemPost(&g_uartCtx[uartid].rxSem);
- HalUartRxStart(uartid);
+ memset_s(g_uartCtx[HAL_UART_ID_1].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE);
+ OsalSemPost(&g_uartCtx[HAL_UART_ID_1].rxSem);
+ HalUartStartDmaRx(HAL_UART_ID_1);
}
static void Uart1DmaTxHandler(uint32_t xferSize, int dmaError)
@@ -132,29 +155,34 @@ static void Uart1DmaTxHandler(uint32_t xferSize, int dmaError)
OsalSemPost(&g_uartCtx[HAL_UART_ID_1].txSem);
}
+#ifdef LOSCFG_SOC_SERIES_BES2600
/* uart2 */
static void Uart2DmaRxHandler(uint32_t xferSize, int dmaError, union HAL_UART_IRQ_T status)
{
- uint32_t len = 0;
- uint32_t uartid = HAL_UART_ID_2;
- len = kfifo_put(&g_uartCtx[uartid].fifo, g_uartCtx[uartid].buffer, xferSize);
+ uint32_t len ;
+ len = kfifo_put(&g_uartCtx[HAL_UART_ID_2].fifo, g_uartCtx[HAL_UART_ID_2].buffer, xferSize);
if (len < xferSize) {
HDF_LOGE("%s ringbuf is full have %d need %d\r", __FUNCTION__, (int)len, (int)xferSize);
return;
}
- memset_s(g_uartCtx[uartid].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE);
- OsalSemPost(&g_uartCtx[uartid].rxSem);
- HalUartRxStart(uartid);
+ memset_s(g_uartCtx[HAL_UART_ID_2].buffer, UART_DMA_RING_BUFFER_SIZE, 0, UART_DMA_RING_BUFFER_SIZE);
+ OsalSemPost(&g_uartCtx[HAL_UART_ID_2].rxSem);
+ HalUartStartDmaRx(HAL_UART_ID_2);
}
static void Uart2DmaTxHandler(uint32_t xferSize, int dmaError)
{
OsalSemPost(&g_uartCtx[HAL_UART_ID_2].txSem);
}
+#endif
static void HalUartStartRx(uint32_t uartId)
{
+ if (uartId > MAX_UART_ID) {
+ HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__);
+ return;
+ }
union HAL_UART_IRQ_T mask;
mask.reg = 0;
mask.RT = 1;
@@ -166,20 +194,22 @@ static void HalUartStartRx(uint32_t uartId)
static int32_t HalUartSend(uint32_t uartId, const void *data, uint32_t size, uint32_t timeOut)
{
- int32_t ret = HDF_FAILURE;
+ int32_t ret;
struct HAL_DMA_DESC_T dmaSescTx;
- unsigned int descCnt = 1;
-
+ uint32_t descCnt;
if (data == NULL || size == 0) {
HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__);
return HDF_ERR_INVALID_PARAM;
}
- if (uartId > HAL_UART_ID_2) {
+ if (uartId > MAX_UART_ID) {
HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__);
return HDF_ERR_NOT_SUPPORT;
}
-
+ descCnt = 1;
+#ifdef LOSCFG_SOC_SERIES_BES2700
+ hal_cache_sync_all(HAL_CACHE_ID_D_CACHE);
+#endif
hal_uart_dma_send(uartId, data, size, &dmaSescTx, &descCnt);
OsalSemWait(&g_uartCtx[uartId].txSem, timeOut);
@@ -189,19 +219,18 @@ static int32_t HalUartSend(uint32_t uartId, const void *data, uint32_t size, uin
static int32_t HalUartRecv(uint8_t uartId, void *data, uint32_t expectSize,
uint32_t *recvSize, uint32_t timeOut)
{
- int32_t ret = HDF_FAILURE;
- uint32_t beginTime = 0;
- uint32_t nowTime = 0;
- uint32_t fifoPopLen = 0;
+ uint32_t beginTime;
+ uint32_t nowTime;
+ uint32_t fifoPopLen;
uint32_t recvedLen = 0;
- uint32_t expectLen = expectSize;
+ int32_t expectLen = (int32_t)expectSize;
- if (data == NULL || expectSize == 0 || recvSize == NULL) {
+ if (data == NULL || expectLen == 0 || recvSize == NULL) {
HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__);
return HDF_ERR_INVALID_PARAM;
}
- if (uartId > HAL_UART_ID_2) {
+ if (uartId > MAX_UART_ID) {
HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__);
return HDF_ERR_NOT_SUPPORT;
}
@@ -229,19 +258,31 @@ static int32_t HalUartRecv(uint8_t uartId, void *data, uint32_t expectSize,
if (recvSize != NULL) {
*recvSize = recvedLen;
}
-
return HDF_SUCCESS;
}
-static void HalUartHandlerInit(struct UartDevice *device)
+static int32_t InitUartCtxCfg(struct UartDevice *device)
{
uint32_t uartId;
+ struct HAL_UART_CFG_T *uartCfg = NULL;
if (device == NULL) {
HDF_LOGE("%s: INVALID PARAM", __func__);
- return HDF_ERR_INVALID_PARAM;
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ uartCfg = &device->config;
+ if (uartCfg == NULL) {
+ HDF_LOGE("%s: INVALID OBJECT", __func__);
+ return HDF_ERR_INVALID_OBJECT;
}
uartId = device->uartId;
- HDF_LOGI("%s %ld\r\n", __func__, uartId);
+ if (uartId > MAX_UART_ID) {
+ HDF_LOGE("%s %d NOT SUPPORT \r\n", __FILE__, __LINE__);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+ memset_s(&g_uartCtx[uartId], sizeof(struct UART_CTX_OBJ), 0, sizeof(struct UART_CTX_OBJ));
+ g_uartCtx[uartId].txDMA = uartCfg->dma_tx;
+ g_uartCtx[uartId].rxDMA = uartCfg->dma_rx;
+
if (uartId == HAL_UART_ID_0) {
g_uartCtx[uartId].UartDmaRxHandler = UartDmaRxHandler;
g_uartCtx[uartId].UartDmaTxHandler = UartDmaTxHandler;
@@ -253,13 +294,36 @@ static void HalUartHandlerInit(struct UartDevice *device)
g_uartCtx[uartId].UartDmaTxHandler = Uart1DmaTxHandler;
g_uartCtx[uartId].buffer = g_halUart1Buf;
}
-
+#ifdef LOSCFG_SOC_SERIES_BES2600
if (uartId == HAL_UART_ID_2) {
g_uartCtx[uartId].UartDmaRxHandler = Uart2DmaRxHandler;
g_uartCtx[uartId].UartDmaTxHandler = Uart2DmaTxHandler;
g_uartCtx[uartId].buffer = g_halUart2Buf;
}
+#endif
+ return HDF_SUCCESS;
+}
+
+static void HalUartHandlerInit(struct UartDevice *device)
+{
+ uint32_t uartId;
+ int32_t ret;
+ struct HAL_UART_CFG_T *uartCfg = NULL;
+ if (device == NULL) {
+ HDF_LOGE("%s: INVALID PARAM!\r\n", __func__);
+ return;
+ }
+ uartId = device->uartId;
+ if (uartId > MAX_UART_ID) {
+ HDF_LOGE("%s %d NOT SUPPORT!\r\n", __FILE__, __LINE__);
+ return;
+ }
+ ret = InitUartCtxCfg(device);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s %d InitUartCtxCfg failed\r\n", __FILE__, __LINE__);
+ return;
+ }
if (!g_uartKfifoBuffer[uartId]) {
g_uartKfifoBuffer[uartId] = (char *)OsalMemAlloc(UART_FIFO_MAX_BUFFER);
if (!g_uartKfifoBuffer[uartId]) {
@@ -269,13 +333,19 @@ static void HalUartHandlerInit(struct UartDevice *device)
kfifo_init(&g_uartCtx[uartId].fifo, g_uartKfifoBuffer[uartId], UART_FIFO_MAX_BUFFER);
}
- OsalSemInit(&g_uartCtx[uartId].rxSem, 0);
- OsalSemInit(&g_uartCtx[uartId].txSem, 0);
+ if (OsalSemInit(&g_uartCtx[uartId].rxSem, 0) != HDF_SUCCESS) {
+ HDF_LOGE("UART rxsem init failed!");
+ return;
+ }
+ if (OsalSemInit(&g_uartCtx[uartId].txSem, 0) != HDF_SUCCESS) {
+ HDF_LOGE("UART txsem init failed!");
+ return;
+ }
- if (g_uartCtx[uartId].rxDMA) {
- HDF_LOGE("uart %ld start dma rx\r\n", uartId);
+ if (g_uartCtx[uartId].rxDMA == true) {
+ HDF_LOGI("uart %ld start dma rx\r\n", uartId);
hal_uart_irq_set_dma_handler(uartId, g_uartCtx[uartId].UartDmaRxHandler, g_uartCtx[uartId].UartDmaTxHandler);
- HalUartRxStart(uartId);
+ HalUartStartDmaRx(uartId);
} else {
HalUartStartRx(uartId);
}
@@ -290,13 +360,16 @@ static void UartStart(struct UartDevice *device)
return;
}
uartId = device->uartId;
+ if (uartId > MAX_UART_ID) {
+ HDF_LOGE("%s %d NOT SUPPORT \r\n", __FILE__, __LINE__);
+ return HDF_ERR_NOT_SUPPORT;
+ }
uartCfg = &device->config;
if (uartCfg == NULL) {
HDF_LOGE("%s: INVALID OBJECT", __func__);
return;
}
hal_uart_open(uartId, uartCfg);
- HDF_LOGI("%s %ld\r\n", __FUNCTION__, uartId);
HalUartHandlerInit(device);
}
@@ -367,20 +440,15 @@ static int InitUartDevice(struct UartHost *host)
HDF_LOGE("%s: INVALID OBJECT", __func__);
return HDF_ERR_INVALID_OBJECT;
}
- uartDevice->uartId = resource->num;
- uartCfg->parity = resource->parity;
- uartCfg->stop = resource->stopBit;
- uartCfg->data = resource->wLen;
+ uint32_t uartId = resource->num;
+ if (uartId > MAX_UART_ID) {
+ HDF_LOGE("%s %d NOT SUPPORT \r\n", __FILE__, __LINE__);
+ return HDF_ERR_NOT_SUPPORT;
+ }
uartCfg->flow = HAL_UART_FLOW_CONTROL_NONE;
- uartCfg->tx_level = HAL_UART_FIFO_LEVEL_1_2;
+ uartCfg->tx_level = HAL_UART_FIFO_LEVEL_1_8;
uartCfg->rx_level = HAL_UART_FIFO_LEVEL_1_2;
- uartCfg->baud = resource->baudRate;
uartCfg->dma_rx_stop_on_err = false;
- uartCfg->dma_rx = resource->rxDMA;
- uartCfg->dma_tx = resource->txDMA;
-
- g_uartCtx[uartDevice->uartId].txDMA = resource->txDMA;
- g_uartCtx[uartDevice->uartId].rxDMA = resource->rxDMA;
if (!uartDevice->initFlag) {
HDF_LOGE("uart %ld device init\r\n", uartDevice->uartId);
@@ -388,10 +456,53 @@ static int InitUartDevice(struct UartHost *host)
UartStart(uartDevice);
uartDevice->initFlag = true;
}
-
return HDF_SUCCESS;
}
-
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+#define UART_FIND_CONFIG(node, name, resource) \
+ do { \
+ if (strcmp(HCS_PROP(node, match_attr), name) == 0) { \
+ resource->num = HCS_PROP(node, num); \
+ resource->baudRate = HCS_PROP(node, baudRate); \
+ resource->parity = HCS_PROP(node, parity); \
+ resource->stopBit = HCS_PROP(node, stopBit); \
+ resource->wLen = HCS_PROP(node, data); \
+ resource->rxDMA = HCS_PROP(node, rxDMA); \
+ resource->txDMA = HCS_PROP(node, txDMA); \
+ result = HDF_SUCCESS; \
+ break; \
+ } \
+ } while (0)
+
+#define PLATFORM_UART_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), uart_config)
+static uint32_t GetUartDeviceResource(struct UartDevice *device, const char *deviceMatchAttr)
+{
+ struct UartResource *resource = NULL;
+ int32_t result = HDF_FAILURE;
+ if (device == NULL || deviceMatchAttr == NULL) {
+ HDF_LOGE("device or deviceMatchAttr is NULL\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+ resource = &device->resource;
+#if HCS_NODE_EXISTS(PLATFORM_UART_CONFIG)
+ HCS_FOREACH_CHILD_VARGS(PLATFORM_UART_CONFIG, UART_FIND_CONFIG, deviceMatchAttr, resource);
+#endif
+ if (result != HDF_SUCCESS) {
+ HDF_LOGE("resourceNode %s is NULL\r\n", deviceMatchAttr);
+ return result;
+ }
+ // copy config
+ device->initFlag = false;
+ device->uartId = resource->num;
+ device->config.baud = resource->baudRate;
+ device->config.parity = resource->parity;
+ device->config.stop = resource->stopBit;
+ device->config.data = resource->wLen;
+ device->config.dma_rx = (resource->rxDMA == true) ? true : false;
+ device->config.dma_tx = (resource->txDMA == true) ? true : false;
+ return HDF_SUCCESS;
+}
+#else
static uint32_t GetUartDeviceResource(
struct UartDevice *device, const struct DeviceResourceNode *resourceNode)
{
@@ -437,6 +548,7 @@ static uint32_t GetUartDeviceResource(
resource->rxDMA = dri->GetBool(resourceNode, "rxDMA");
// copy config
+ device->initFlag = false;
device->uartId = resource->num;
device->config.baud = resource->baudRate;
device->config.parity = resource->parity;
@@ -446,13 +558,16 @@ static uint32_t GetUartDeviceResource(
device->config.dma_tx = resource->txDMA;
return HDF_SUCCESS;
}
-
+#endif
static int32_t AttachUartDevice(struct UartHost *uartHost, struct HdfDeviceObject *device)
{
int32_t ret;
struct UartDevice *uartDevice = NULL;
-
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+ if (device == NULL || uartHost == NULL) {
+#else
if (uartHost == NULL || device == NULL || device->property == NULL) {
+#endif
HDF_LOGE("%s: property is NULL", __func__);
return HDF_ERR_INVALID_PARAM;
}
@@ -462,8 +577,11 @@ static int32_t AttachUartDevice(struct UartHost *uartHost, struct HdfDeviceObjec
HDF_LOGE("%s: OsalMemCalloc uartDevice error", __func__);
return HDF_ERR_MALLOC_FAIL;
}
-
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+ ret = GetUartDeviceResource(uartDevice, device->deviceMatchAttr);
+#else
ret = GetUartDeviceResource(uartDevice, device->property);
+#endif
if (ret != HDF_SUCCESS) {
(void)OsalMemFree(uartDevice);
return HDF_FAILURE;
@@ -476,7 +594,7 @@ static int32_t AttachUartDevice(struct UartHost *uartHost, struct HdfDeviceObjec
static int32_t UartDriverBind(struct HdfDeviceObject *device)
{
- struct UartHost *devService;
+ struct UartHost *devService = NULL;
if (device == NULL) {
HDF_LOGE("%s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
@@ -560,8 +678,8 @@ static int32_t UartHostDevInit(struct UartHost *host)
HDF_LOGE("%s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
- InitUartDevice(host);
- return HDF_SUCCESS;
+
+ return InitUartDevice(host);
}
static int32_t UartHostDevDeinit(struct UartHost *host)
@@ -590,7 +708,7 @@ static int32_t UartHostDevDeinit(struct UartHost *host)
static int32_t UartHostDevWrite(struct UartHost *host, uint8_t *data, uint32_t size)
{
struct UartDevice *device = NULL;
- uint32_t portId;
+ uint32_t uartId;
if (host == NULL || data == NULL || size == 0 || host->priv == NULL) {
HDF_LOGE("%s: invalid parameter", __func__);
@@ -603,15 +721,19 @@ static int32_t UartHostDevWrite(struct UartHost *host, uint8_t *data, uint32_t s
return HDF_ERR_INVALID_OBJECT;
}
- portId = device->uartId;
- if (g_uartCtx[portId].txDMA) {
- HalUartSend(portId, data, size, HDF_UART_TMO);
+ uartId = device->uartId;
+ if (uartId > MAX_UART_ID) {
+ HDF_LOGE("%s %d NOT SUPPORT \r\n", __FILE__, __LINE__);
+ return HDF_ERR_NOT_SUPPORT;
+ }
+ if (g_uartCtx[uartId].txDMA) {
+ HalUartSend(uartId, data, size, HDF_UART_TMO);
} else {
for (uint32_t idx = 0; idx < size; idx++) {
- if (g_uartCtx[portId].isBlock) {
- hal_uart_blocked_putc(portId, data[idx]);
+ if (g_uartCtx[uartId].isBlock) {
+ hal_uart_blocked_putc(uartId, data[idx]);
} else {
- hal_uart_putc(portId, data[idx]);
+ hal_uart_putc(uartId, data[idx]);
}
}
}
@@ -621,7 +743,7 @@ static int32_t UartHostDevWrite(struct UartHost *host, uint8_t *data, uint32_t s
static int32_t UartHostDevRead(struct UartHost *host, uint8_t *data, uint32_t size)
{
- uint32_t recvSize = 0;
+ uint32_t recvSize;
int32_t ret;
uint32_t uartId;
struct UartDevice *uartDevice = NULL;
@@ -648,7 +770,9 @@ static int32_t UartHostDevRead(struct UartHost *host, uint8_t *data, uint32_t si
if (g_uartCtx[uartId].isBlock) {
data[0] = hal_uart_blocked_getc(uartId);
} else {
- data[0] = hal_uart_getc(uartId);
+ if (hal_uart_readable(uartId) > 0) {
+ data[0] = hal_uart_getc(uartId);
+ }
}
ret = 1;
}
@@ -673,7 +797,10 @@ static int32_t UartHostDevSetBaud(struct UartHost *host, uint32_t baudRate)
return HDF_ERR_INVALID_OBJECT;
}
uartId = uartDevice->uartId;
-
+ if (uartId > MAX_UART_ID) {
+ HDF_LOGE("%s %d NOT SUPPORT \r\n", __FILE__, __LINE__);
+ return HDF_ERR_NOT_SUPPORT;
+ }
uartCfg = &uartDevice->config;
if (uartCfg == NULL) {
HDF_LOGE("%s: device config is NULL", __func__);
@@ -681,7 +808,7 @@ static int32_t UartHostDevSetBaud(struct UartHost *host, uint32_t baudRate)
}
uartCfg->baud = baudRate;
- hal_uart_reopen(uartId, uartCfg);
+ hal_uart_open(uartId, uartCfg);
return HDF_SUCCESS;
}
@@ -702,6 +829,10 @@ static int32_t UartHostDevGetBaud(struct UartHost *host, uint32_t *baudRate)
return HDF_ERR_INVALID_OBJECT;
}
uartId = uartDevice->uartId;
+ if (uartId > MAX_UART_ID) {
+ HDF_LOGE("%s %d NOT SUPPORT \r\n", __FILE__, __LINE__);
+ return HDF_ERR_NOT_SUPPORT;
+ }
uartCfg = &uartDevice->config;
if (uartCfg == NULL) {
HDF_LOGE("%s: device is NULL", __func__);
@@ -715,22 +846,14 @@ static int32_t UartHostDevGetBaud(struct UartHost *host, uint32_t *baudRate)
return HDF_SUCCESS;
}
-static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribute *attribute)
+static int32_t SetUartDevConfig(struct UartAttribute *attribute, struct UartDevice *uartDevice)
{
- HDF_LOGI("%s: Enter", __func__);
- struct UartDevice *uartDevice = NULL;
struct HAL_UART_CFG_T *uartCfg = NULL;
uint32_t uartId;
- if (host == NULL || attribute == NULL || host->priv == NULL) {
+ if (attribute == NULL || uartDevice == NULL) {
HDF_LOGE("%s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
-
- uartDevice = (struct UartDevice *)host->priv;
- if (uartDevice == NULL) {
- HDF_LOGE("%s: device is NULL", __func__);
- return HDF_ERR_INVALID_OBJECT;
- }
uartId = uartDevice->uartId;
uartCfg = &uartDevice->config;
if (uartCfg == NULL) {
@@ -777,17 +900,15 @@ static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribu
} else {
uartCfg->flow = HAL_UART_FLOW_CONTROL_NONE;
}
-
- hal_uart_reopen(uartId, uartCfg);
-
+ hal_uart_open(uartId, uartCfg);
return HDF_SUCCESS;
}
-static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribute *attribute)
+static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribute *attribute)
{
HDF_LOGI("%s: Enter", __func__);
struct UartDevice *uartDevice = NULL;
- struct HAL_UART_CFG_T *uartCfg = NULL;
+ int ret;
if (host == NULL || attribute == NULL || host->priv == NULL) {
HDF_LOGE("%s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
@@ -798,12 +919,21 @@ static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribu
HDF_LOGE("%s: device is NULL", __func__);
return HDF_ERR_INVALID_OBJECT;
}
- uartCfg = &uartDevice->config;
- if (uartCfg == NULL) {
- HDF_LOGE("%s: config is NULL", __func__);
- return HDF_ERR_INVALID_OBJECT;
+
+ ret = SetUartDevConfig(attribute, uartDevice);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: SetUartDevConfig error", __func__);
+ return HDF_FAILURE;
}
+ return HDF_SUCCESS;
+}
+static int32_t GetUartDevConfig(struct UartAttribute *attribute, struct HAL_UART_CFG_T *uartCfg)
+{
+ if (attribute == NULL || uartCfg == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
switch (uartCfg->data) {
case HAL_UART_DATA_BITS_8:
attribute->dataBits = UART_ATTR_DATABIT_8;
@@ -847,10 +977,33 @@ static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribu
attribute->cts = 0;
break;
}
-
return HDF_SUCCESS;
}
+static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribute *attribute)
+{
+ HDF_LOGI("%s: Enter", __func__);
+ struct UartDevice *uartDevice = NULL;
+ struct HAL_UART_CFG_T *uartCfg = NULL;
+ if (host == NULL || attribute == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ uartDevice = (struct UartDevice *)host->priv;
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ uartCfg = &uartDevice->config;
+ if (uartCfg == NULL) {
+ HDF_LOGE("%s: config is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ return GetUartDevConfig(attribute, uartCfg);
+}
+
static int32_t UartHostDevSetTransMode(struct UartHost *host, enum UartTransMode mode)
{
HDF_LOGI("%s: Enter", __func__);
@@ -867,7 +1020,10 @@ static int32_t UartHostDevSetTransMode(struct UartHost *host, enum UartTransMode
return HDF_ERR_INVALID_OBJECT;
}
uartId = uartDevice->uartId;
-
+ if (uartId > MAX_UART_ID) {
+ HDF_LOGE("%s %d NOT SUPPORT \r\n", __FILE__, __LINE__);
+ return HDF_ERR_NOT_SUPPORT;
+ }
switch (mode) {
case UART_MODE_RD_BLOCK:
g_uartCtx[uartId].isBlock = true;
diff --git a/platform/uart/uart_bes.h b/platform/uart/uart_bes.h
old mode 100755
new mode 100644
index 454e1015e6d8540df0150f61802dfaaf85d210e9..98a9bfe925cb38b45c1eab304e1574c4f4a1558d
--- a/platform/uart/uart_bes.h
+++ b/platform/uart/uart_bes.h
@@ -1,17 +1,11 @@
/*
- * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * This file is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
+
#ifndef __UART_BES_H__
#define __UART_BES_H__
@@ -74,4 +68,4 @@ int32_t UartDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf
}
#endif
-#endif
\ No newline at end of file
+#endif
diff --git a/platform/uart/uart_gr5xx.c b/platform/uart/uart_gr5xx.c
old mode 100755
new mode 100644
index 89621068553e7ec87114a2d8a84ca5df143ff75e..9c8005ff128ecc43b958145354749143ac001d71
--- a/platform/uart/uart_gr5xx.c
+++ b/platform/uart/uart_gr5xx.c
@@ -1,17 +1,11 @@
/*
- * Copyright (c) 2021 GOODIX.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Copyright (c) 2021-2022 GOODIX.
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * This file is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
+
#include "app_uart.h"
#include "uart/uart_core.h"
#include "uart_if.h"
diff --git a/platform/uart/uart_stm32f4xx.c b/platform/uart/uart_stm32f4xx.c
new file mode 100644
index 0000000000000000000000000000000000000000..e25dbe59ab9f50764307250d3d55492481cab4c7
--- /dev/null
+++ b/platform/uart/uart_stm32f4xx.c
@@ -0,0 +1,1093 @@
+/*
+ * Copyright (c) 2022 Talkweb Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include
+#include
+#include "hal_gpio.h"
+#include "uart_if.h"
+#include "stm32f4xx_ll_bus.h"
+#include "uart_core.h"
+#include "hal_usart.h"
+#include "osal_sem.h"
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+#include "hcs_macro.h"
+#include "hdf_config_macro.h"
+#else
+#include "device_resource_if.h"
+#endif
+#include "hdf_log.h"
+
+#define HDF_UART_TMO 1000
+#define HDF_LOG_TAG uartDev
+#define GPIO_MAX_LENGTH 32
+#define UART_FIFO_MAX_BUFFER 2048
+#define UART_DMA_RING_BUFFER_SIZE 256 // mast be 2^n
+
+#define UART_IRQ_PRO 5
+#define UART_DEV_SERVICE_NAME_PREFIX "HDF_PLATFORM_UART%d"
+#define MAX_DEV_NAME_SIZE 32
+typedef enum {
+ USART_NUM_1 = 1,
+ USART_NUM_2,
+ USART_NUM_3,
+ USART_NUM_4,
+ USART_NUM_5,
+ USART_NUM_6,
+} USART_NUM;
+
+typedef enum {
+ USART_DATAWIDTH_8 = 0,
+ USART_DATAWIDTH_9,
+ USART_DATAWIDTH_MAX,
+} USART_DATAWIDTH;
+
+typedef enum {
+ USART_STOP_BIT_0_5 = 0,
+ USART_STOP_BIT_1,
+ USART_STOP_BIT_1_5,
+ USART_STOP_BIT_2,
+ USART_STOP_BIT_MAX,
+} USART_STOP_BIT;
+
+typedef enum {
+ USART_PARITY_CHECK_NONE = 0,
+ USART_PARITY_CHECK_EVENT,
+ USART_PARITY_CHECK_ODD,
+ USART_PARITY_CHECK_MAX,
+} USART_PARITY_CHECK;
+
+typedef enum {
+ USART_TRANS_DIR_NONE = 0,
+ USART_TRANS_DIR_RX,
+ USART_TRANS_DIR_TX,
+ USART_TRANS_DIR_RX_TX,
+ USART_TRANS_DIR_MAX,
+} USART_TRANS_DIR;
+
+typedef enum {
+ USART_FLOW_CTRL_NONE = 0,
+ USART_FLOW_CTRL_RTS,
+ USART_FLOW_CTRL_CTS,
+ USART_FLOW_CTRL_RTS_CTS,
+ USART_FLOW_CTRL_MAX,
+} USART_FLOW_CTRL;
+
+typedef enum {
+ USART_OVER_SIMPLING_16 = 0,
+ USART_OVER_SIMPLING_8,
+ USART_OVER_SIMPLING_MAX,
+} USART_OVER_SIMPLING;
+
+typedef enum {
+ USART_TRANS_BLOCK = 0, // block
+ USART_TRANS_NOBLOCK,
+ USART_TRANS_TX_DMA, // TX DMA RX NORMAL
+ USART_TRANS_RX_DMA, // TX NORMAL RX DMA
+ USART_TRANS_TX_RX_DMA, // TX DMA RX DMA
+ USART_TRANS_MODE_MAX,
+} USART_TRANS_MODE;
+
+typedef enum {
+ USART_IDLE_IRQ_DISABLE = 0,
+ USART_IDLE_IRQ_ENABLE,
+ USART_IDLE_IRQ_MAX,
+} USART_IDLE_IRQ;
+
+typedef enum {
+ USART_232 = 0,
+ USART_485,
+ USART_TYPE_MAX,
+} USART_TYPE;
+
+typedef struct {
+ USART_NUM num;
+ uint32_t baudRate;
+ USART_DATAWIDTH dataWidth;
+ USART_STOP_BIT stopBit;
+ USART_PARITY_CHECK parity;
+ USART_TRANS_DIR transDir;
+ USART_FLOW_CTRL flowCtrl;
+ USART_OVER_SIMPLING overSimpling;
+ USART_TRANS_MODE transMode;
+ USART_TYPE uartType;
+ STM32_GPIO_PIN dePin;
+ STM32_GPIO_GROUP deGroup;
+} UartResource;
+
+typedef enum {
+ UART_DEVICE_UNINITIALIZED = 0x0u,
+ UART_DEVICE_INITIALIZED = 0x1u,
+} UartDeviceState;
+
+typedef enum {
+ UART_ATTR_HDF_TO_NIOBE = 0,
+ UART_ATTR_NIOBE_TO_HDF,
+} UART_ATTR_TRAN_TYPE;
+
+typedef void (*HWI_UART_IDLE_IRQ)(void);
+
+typedef struct {
+ bool txDMA;
+ bool rxDMA;
+ bool isBlock;
+ uint8_t dePin;
+ uint8_t deGroup;
+ uint8_t uartType;
+} UsartContextObj;
+
+typedef struct {
+ struct IDeviceIoService ioService;
+ UartResource resource;
+ LL_USART_InitTypeDef initTypedef;
+ uint32_t uartId;
+ bool initFlag;
+ USART_TRANS_MODE transMode;
+} UartDevice;
+
+static const uint32_t g_dataWidthMap[USART_DATAWIDTH_MAX] = {
+ LL_USART_DATAWIDTH_8B,
+ LL_USART_DATAWIDTH_9B,
+};
+
+static const uint32_t g_stopBitMap[USART_STOP_BIT_MAX] = {
+ LL_USART_STOPBITS_0_5,
+ LL_USART_STOPBITS_1,
+ LL_USART_STOPBITS_1_5,
+ LL_USART_STOPBITS_2,
+};
+
+static const uint32_t g_flowControlMap[USART_FLOW_CTRL_MAX] = {
+ LL_USART_HWCONTROL_NONE,
+ LL_USART_HWCONTROL_RTS,
+ LL_USART_HWCONTROL_CTS,
+ LL_USART_HWCONTROL_RTS_CTS,
+};
+
+static const uint32_t g_overSimplingMap[USART_OVER_SIMPLING_MAX] = {
+ LL_USART_OVERSAMPLING_16,
+ LL_USART_OVERSAMPLING_8,
+};
+
+static const uint32_t g_transDirMap[USART_TRANS_DIR_MAX] = {
+ LL_USART_DIRECTION_NONE,
+ LL_USART_DIRECTION_RX,
+ LL_USART_DIRECTION_TX,
+ LL_USART_DIRECTION_TX_RX,
+};
+
+static const uint32_t g_parityMap[USART_PARITY_CHECK_MAX] = {
+ LL_USART_PARITY_NONE,
+ LL_USART_PARITY_EVEN,
+ LL_USART_PARITY_ODD,
+};
+
+static const USART_TypeDef* g_usartRegMap[USART_NUM_6] = {
+ USART1,
+ USART2,
+ USART3,
+ UART4,
+ UART5,
+ USART6,
+};
+static UsartContextObj g_uartCtx[USART_NUM_6] = {0};
+
+static void USARTTxMode(STM32_GPIO_PIN gpioPin, STM32_GPIO_GROUP group)
+{
+ uint32_t pinReg = LL_GET_HAL_PIN(gpioPin);
+ GPIO_TypeDef* gpiox = NULL;
+ gpiox = LL_GET_GPIOX(group);
+ if (gpiox == NULL) {
+ return;
+ }
+ LL_GPIO_SetOutputPin(gpiox, pinReg);
+}
+
+static void USARTRxMode(STM32_GPIO_PIN gpioPin, STM32_GPIO_GROUP group)
+{
+ uint32_t pinReg = LL_GET_HAL_PIN(gpioPin);
+ GPIO_TypeDef* gpiox = NULL;
+ gpiox = LL_GET_GPIOX(group);
+ if (gpiox == NULL) {
+ return;
+ }
+ LL_GPIO_ResetOutputPin(gpiox, pinReg);
+}
+
+static const uint32_t g_exitIrqnMap[USART_NUM_6] = {
+ USART1_IRQn,
+ USART2_IRQn,
+ USART3_IRQn,
+ UART4_IRQn,
+ UART5_IRQn,
+ USART6_IRQn,
+};
+
+static void InitUsartClock(USART_NUM num)
+{
+ switch (num) {
+ case USART_NUM_1:
+ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
+ break;
+ case USART_NUM_2:
+ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART2);
+ break;
+ case USART_NUM_3:
+ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART3);
+ break;
+ case USART_NUM_4:
+ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_UART4);
+ break;
+ case USART_NUM_5:
+ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_UART5);
+ break;
+ case USART_NUM_6:
+ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART6);
+ break;
+ default:
+ break;
+ }
+}
+
+static void InitContextTransMode(UsartContextObj* ctx, USART_TRANS_MODE mode)
+{
+ switch (mode) {
+ case USART_TRANS_BLOCK:
+ ctx->isBlock = true;
+ ctx->rxDMA = false;
+ ctx->txDMA = false;
+ break;
+ case USART_TRANS_NOBLOCK:
+ ctx->isBlock = false;
+ ctx->rxDMA = false;
+ ctx->txDMA = false;
+ break;
+ case USART_TRANS_TX_DMA: // TX DMA RX NORMAL
+ ctx->isBlock = false;
+ ctx->rxDMA = false;
+ ctx->txDMA = true;
+ break;
+ case USART_TRANS_RX_DMA: // TX NORMAL RX DMA
+ ctx->isBlock = false;
+ ctx->rxDMA = true;
+ ctx->txDMA = false;
+ break;
+ case USART_TRANS_TX_RX_DMA: // TX DMA RX DMA
+ ctx->isBlock = false;
+ ctx->rxDMA = true;
+ ctx->txDMA = true;
+ break;
+ default:
+ break;
+ }
+}
+
+static int32_t UartDriverBind(struct HdfDeviceObject *device);
+static int32_t UartDriverInit(struct HdfDeviceObject *device);
+static void UartDriverRelease(struct HdfDeviceObject *device);
+
+struct HdfDriverEntry g_UartDriverEntry = {
+ .moduleVersion = 1,
+ .moduleName = "ST_UART_MODULE_HDF",
+ .Bind = UartDriverBind,
+ .Init = UartDriverInit,
+ .Release = UartDriverRelease,
+};
+HDF_INIT(g_UartDriverEntry);
+
+static int32_t UartHostDevInit(struct UartHost *host);
+static int32_t UartHostDevDeinit(struct UartHost *host);
+static int32_t UartHostDevWrite(struct UartHost *host, uint8_t *data, uint32_t size);
+static int32_t UartHostDevSetBaud(struct UartHost *host, uint32_t baudRate);
+static int32_t UartHostDevGetBaud(struct UartHost *host, uint32_t *baudRate);
+static int32_t UartHostDevRead(struct UartHost *host, uint8_t *data, uint32_t size);
+static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribute *attribute);
+static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribute *attribute);
+static int32_t UartHostDevSetTransMode(struct UartHost *host, enum UartTransMode mode);
+
+struct UartHostMethod g_uartHostMethod = {
+ .Init = UartHostDevInit,
+ .Deinit = UartHostDevDeinit,
+ .Read = UartHostDevRead,
+ .Write = UartHostDevWrite,
+ .SetBaud = UartHostDevSetBaud,
+ .GetBaud = UartHostDevGetBaud,
+ .SetAttribute = UartHostDevSetAttribute,
+ .GetAttribute = UartHostDevGetAttribute,
+ .SetTransMode = UartHostDevSetTransMode,
+};
+
+static int InitUartDevice(struct UartHost *host)
+{
+ uint8_t initRet = 0;
+ UartDevice *uartDevice = NULL;
+ LL_USART_InitTypeDef *initTypedef = NULL;
+ UartResource *resource = NULL;
+ if (host == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ uartDevice = (UartDevice *)host->priv;
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: INVALID OBJECT", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ resource = &uartDevice->resource;
+ if (resource == NULL) {
+ HDF_LOGE("%s: INVALID OBJECT", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ initTypedef = &uartDevice->initTypedef;
+ if (initTypedef == NULL) {
+ HDF_LOGE("%s: INVALID OBJECT", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ InitContextTransMode(&g_uartCtx[uartDevice->uartId - 1], resource->transMode);
+ LL_USART_Disable(g_usartRegMap[uartDevice->uartId - 1]);
+ LL_USART_DeInit(g_usartRegMap[uartDevice->uartId - 1]);
+ InitUsartClock(uartDevice->uartId);
+
+ if (!uartDevice->initFlag) {
+ initRet = LL_USART_Init(g_usartRegMap[uartDevice->uartId - 1], initTypedef);
+ if (initRet) {
+ HDF_LOGE("uart %ld device init failed\r\n", uartDevice->uartId);
+ return HDF_FAILURE;
+ }
+ LL_USART_ConfigAsyncMode(g_usartRegMap[uartDevice->uartId - 1]);
+ LL_USART_Enable(g_usartRegMap[uartDevice->uartId - 1]);
+ UART_IRQ_INIT(g_usartRegMap[uartDevice->uartId - 1], uartDevice->uartId,
+ g_exitIrqnMap[uartDevice->uartId - 1], g_uartCtx[uartDevice->uartId - 1].isBlock);
+
+ uartDevice->initFlag = true;
+ }
+
+ return HDF_SUCCESS;
+}
+
+#ifndef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+static int32_t GetUartHcs(struct DeviceResourceIface *dri,
+ const struct DeviceResourceNode *resourceNode, UartResource *resource)
+{
+ if (dri->GetUint8(resourceNode, "num", &resource->num, 0) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint32(resourceNode, "baudRate", &resource->baudRate, 0) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint8(resourceNode, "dataWidth", &resource->dataWidth, 0) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint8(resourceNode, "stopBit", &resource->stopBit, 0) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint8(resourceNode, "parity", &resource->parity, 0) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint8(resourceNode, "transDir", &resource->transDir, 0) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint8(resourceNode, "flowCtrl", &resource->flowCtrl, 0) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint8(resourceNode, "overSimpling", &resource->overSimpling, 0) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint8(resourceNode, "transMode", &resource->transMode, 0) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint8(resourceNode, "uartType", &resource->uartType, 0) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint8(resourceNode, "uartDePin", &resource->dePin, 0) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ if (dri->GetUint8(resourceNode, "uartDeGroup", &resource->deGroup, 0) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+#endif
+
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+#define UART_FIND_CONFIG(node, name, resource) \
+ do { \
+ if (strcmp(HCS_PROP(node, match_attr), name) == 0) { \
+ resource->num = HCS_PROP(node, num); \
+ resource->baudRate = HCS_PROP(node, baudRate); \
+ resource->dataWidth = HCS_PROP(node, dataWidth); \
+ resource->stopBit = HCS_PROP(node, stopBit); \
+ resource->parity = HCS_PROP(node, parity); \
+ resource->transDir = HCS_PROP(node, transDir); \
+ resource->flowCtrl = HCS_PROP(node, flowCtrl); \
+ resource->overSimpling = HCS_PROP(node, overSimpling); \
+ resource->transMode = HCS_PROP(node, transMode); \
+ resource->uartType = HCS_PROP(node, uartType); \
+ resource->dePin = HCS_PROP(node, uartDePin); \
+ resource->deGroup = HCS_PROP(node, uartDeGroup); \
+ result = HDF_SUCCESS; \
+ } \
+ } while (0)
+#define PLATFORM_CONFIG HCS_NODE(HCS_ROOT, platform)
+#define PLATFORM_UART_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), uart_config)
+static uint32_t GetUartDeviceResource(UartDevice *device, const char *deviceMatchAttr)
+{
+ UartResource *resource = NULL;
+ int32_t result = HDF_FAILURE;
+ if (device == NULL || deviceMatchAttr == NULL) {
+ HDF_LOGE("device or deviceMatchAttr is NULL\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+ resource = &device->resource;
+#if HCS_NODE_HAS_PROP(PLATFORM_CONFIG, uart_config)
+ HCS_FOREACH_CHILD_VARGS(PLATFORM_UART_CONFIG, UART_FIND_CONFIG, deviceMatchAttr, resource);
+#endif
+ if (result != HDF_SUCCESS) {
+ HDF_LOGE("resourceNode %s is NULL\r\n", deviceMatchAttr);
+ return result;
+ }
+ device->uartId = resource->num;
+ g_uartCtx[device->uartId - 1].dePin = resource->dePin;
+ g_uartCtx[device->uartId - 1].deGroup = resource->deGroup;
+ g_uartCtx[device->uartId - 1].uartType = resource->uartType;
+ device->initFlag = false;
+ device->initTypedef.BaudRate = resource->baudRate;
+ device->initTypedef.DataWidth = g_dataWidthMap[resource->dataWidth];
+ device->initTypedef.HardwareFlowControl = g_flowControlMap[resource->flowCtrl];
+ device->initTypedef.StopBits = g_stopBitMap[resource->stopBit];
+ device->initTypedef.OverSampling = g_overSimplingMap[resource->overSimpling];
+ device->initTypedef.TransferDirection = g_transDirMap[resource->transDir];
+ device->initTypedef.Parity = g_parityMap[resource->parity];
+ return HDF_SUCCESS;
+}
+#else
+static int32_t GetUartDeviceResource(UartDevice *device, const struct DeviceResourceNode *resourceNode)
+{
+ struct DeviceResourceIface *dri = NULL;
+ UartResource *resource = NULL;
+ if (device == NULL || resourceNode == NULL) {
+ HDF_LOGE("%s: INVALID PARAM", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ resource = &device->resource;
+ if (resource == NULL) {
+ HDF_LOGE("%s: INVALID OBJECT", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ if (dri == NULL || dri->GetUint32 == NULL || dri->GetUint8 == NULL) {
+ HDF_LOGE("DeviceResourceIface is invalid");
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ if (GetUartHcs(dri, resourceNode, resource) != HDF_SUCCESS) {
+ HDF_LOGE("Get uart hcs failed\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ device->uartId = resource->num;
+ g_uartCtx[device->uartId - 1].dePin = resource->dePin;
+ g_uartCtx[device->uartId - 1].deGroup = resource->deGroup;
+ g_uartCtx[device->uartId - 1].uartType = resource->uartType;
+ device->initFlag = false;
+ device->initTypedef.BaudRate = resource->baudRate;
+ device->initTypedef.DataWidth = g_dataWidthMap[resource->dataWidth];
+ device->initTypedef.HardwareFlowControl = g_flowControlMap[resource->flowCtrl];
+ device->initTypedef.StopBits = g_stopBitMap[resource->stopBit];
+ device->initTypedef.OverSampling = g_overSimplingMap[resource->overSimpling];
+ device->initTypedef.TransferDirection = g_transDirMap[resource->transDir];
+ device->initTypedef.Parity = g_parityMap[resource->parity];
+
+ return HDF_SUCCESS;
+}
+#endif
+
+static int32_t AttachUartDevice(struct UartHost *uartHost, struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ UartDevice *uartDevice = NULL;
+
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+ if (device == NULL || uartHost == NULL) {
+#else
+ if (uartHost == NULL || device == NULL || device->property == NULL) {
+#endif
+ HDF_LOGE("%s: property is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ uartDevice = (UartDevice *)OsalMemAlloc(sizeof(UartDevice));
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: OsalMemCalloc uartDevice error", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+ ret = GetUartDeviceResource(uartDevice, device->deviceMatchAttr);
+#else
+ ret = GetUartDeviceResource(uartDevice, device->property);
+#endif
+ if (ret != HDF_SUCCESS) {
+ (void)OsalMemFree(uartDevice);
+ return HDF_FAILURE;
+ }
+
+ uartHost->priv = uartDevice;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t UartDriverBind(struct HdfDeviceObject *device)
+{
+ struct UartHost *devService;
+ if (device == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ return (UartHostCreate(device) == NULL) ? HDF_FAILURE : HDF_SUCCESS;
+}
+
+static void UartDriverRelease(struct HdfDeviceObject *device)
+{
+ HDF_LOGI("Enter %s:", __func__);
+ uint32_t uartId;
+ struct UartHost *host = NULL;
+ UartDevice *uartDevice = NULL;
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return;
+ }
+
+ host = UartHostFromDevice(device);
+ if (host == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: host is NULL", __func__);
+ return;
+ }
+
+ uartDevice = (UartDevice *)host->priv;
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: INVALID OBJECT", __func__);
+ return;
+ }
+ uartId = uartDevice->uartId;
+ host->method = NULL;
+
+ OsalMemFree(uartDevice);
+}
+
+static int32_t UartDriverInit(struct HdfDeviceObject *device)
+{
+ HDF_LOGI("Enter %s:", __func__);
+ int32_t ret;
+ struct UartHost *host = NULL;
+
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ host = UartHostFromDevice(device);
+ if (host == NULL) {
+ HDF_LOGE("%s: host is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ ret = AttachUartDevice(host, device);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: attach error", __func__);
+ return HDF_FAILURE;
+ }
+
+ host->method = &g_uartHostMethod;
+
+ return ret;
+}
+
+/* UartHostMethod implementations */
+static int32_t UartHostDevInit(struct UartHost *host)
+{
+ HDF_LOGI("%s: Enter\r\n", __func__);
+ if (host == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ return InitUartDevice(host);
+}
+
+static int32_t UartHostDevDeinit(struct UartHost *host)
+{
+ HDF_LOGI("%s: Enter", __func__);
+ uint32_t uartId;
+ UartDevice *uartDevice = NULL;
+ if (host == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ uartDevice = (UartDevice *)host->priv;
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: INVALID OBJECT", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ uartId = uartDevice->uartId;
+ uartDevice->initFlag = false;
+ UART_IRQ_DEINIT(g_usartRegMap[uartDevice->uartId - 1], g_exitIrqnMap[uartId -1]);
+ LL_USART_Disable(g_usartRegMap[uartDevice->uartId - 1]);
+
+ return LL_USART_DeInit(g_usartRegMap[uartId - 1]);
+}
+
+static int32_t UartHostDevWrite(struct UartHost *host, uint8_t *data, uint32_t size)
+{
+ UartDevice *device = NULL;
+ uint32_t portId;
+
+ if (host == NULL || data == NULL || size == 0 || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ device = (UartDevice*)host->priv;
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ portId = device->uartId;
+ USART_TypeDef* usartx = g_usartRegMap[portId - 1];
+ if (g_uartCtx[portId - 1].uartType == USART_485) {
+ USARTTxMode(g_uartCtx[portId - 1].dePin, g_uartCtx[portId - 1].deGroup);
+ }
+ if (g_uartCtx[portId - 1].txDMA) {
+ HDF_LOGE("unsupport dma now\n");
+ return HDF_ERR_INVALID_PARAM;
+ } else {
+ USART_TxData(usartx, data, size);
+ }
+ if (g_uartCtx[portId - 1].uartType == USART_485) {
+ USARTRxMode(g_uartCtx[portId - 1].dePin, g_uartCtx[portId - 1].deGroup);
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t UartHostDevRead(struct UartHost *host, uint8_t *data, uint32_t size)
+{
+ uint32_t recvSize = 0;
+ int32_t ret;
+ uint32_t uartId;
+ UartDevice *uartDevice = NULL;
+ if (host == NULL || data == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ uartDevice = (UartDevice *)host->priv;
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ uartId = uartDevice->uartId;
+ USART_TypeDef* usartx = g_usartRegMap[uartId - 1];
+ if (g_uartCtx[uartId - 1].uartType == USART_485) {
+ USARTRxMode(g_uartCtx[uartId - 1].dePin, g_uartCtx[uartId - 1].deGroup);
+ }
+
+ if (g_uartCtx[uartId - 1].rxDMA) {
+ HDF_LOGE("unsupport dma now\n");
+ return HDF_ERR_INVALID_PARAM;
+ } else {
+ ret = USART_RxData(uartId, data, size, g_uartCtx[uartId - 1].isBlock);
+ }
+
+ return ret;
+}
+
+static int32_t UartHostDevSetBaud(struct UartHost *host, uint32_t baudRate)
+{
+ HDF_LOGI("%s: Enter", __func__);
+ UartDevice *uartDevice = NULL;
+ LL_USART_InitTypeDef *uartInit = NULL;
+
+ uint32_t uartId;
+ if (host == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ uartDevice = (UartDevice *)host->priv;
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ uartId = uartDevice->uartId;
+
+ uartInit = &uartDevice->initTypedef;
+ if (uartInit == NULL) {
+ HDF_LOGE("%s: device config is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ uartInit->BaudRate = baudRate;
+ UartHostDevDeinit(host);
+ UartHostDevInit(host);
+
+ return HDF_SUCCESS;
+}
+
+static int32_t UartHostDevGetBaud(struct UartHost *host, uint32_t *baudRate)
+{
+ HDF_LOGI("%s: Enter", __func__);
+ UartDevice *uartDevice = NULL;
+ LL_USART_InitTypeDef *uartInit = NULL;
+ uint32_t uartId;
+ if (host == NULL || baudRate == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ uartDevice = (UartDevice *)host->priv;
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ uartId = uartDevice->uartId;
+ uartInit = &uartDevice->initTypedef;
+ if (uartInit == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ *baudRate = uartInit->BaudRate;
+
+ return HDF_SUCCESS;
+}
+static void TransDataWidth(LL_USART_InitTypeDef *uartInit, struct UartAttribute *attribute, UART_ATTR_TRAN_TYPE type)
+{
+ if (uartInit == NULL || attribute == NULL) {
+ HDF_LOGE("null ptr\r\n");
+ return;
+ }
+
+ if (type == UART_ATTR_NIOBE_TO_HDF) {
+ switch (uartInit->DataWidth) { // only support 9bit and 8 bit in niobe407
+ case LL_USART_DATAWIDTH_8B:
+ attribute->dataBits = UART_ATTR_DATABIT_8;
+ break;
+ default:
+ attribute->dataBits = UART_ATTR_DATABIT_8;
+ break;
+ }
+ } else {
+ switch (attribute->dataBits) {
+ case UART_ATTR_DATABIT_8:
+ uartInit->DataWidth = LL_USART_DATAWIDTH_8B;
+ break;
+ default:
+ uartInit->DataWidth = LL_USART_DATAWIDTH_8B;
+ break;
+ }
+ }
+
+ return;
+}
+
+static void TransParity(LL_USART_InitTypeDef *uartInit, struct UartAttribute *attribute, UART_ATTR_TRAN_TYPE type)
+{
+ if (uartInit == NULL || attribute == NULL) {
+ HDF_LOGE("null ptr\r\n");
+ return;
+ }
+
+ if (type == UART_ATTR_NIOBE_TO_HDF) {
+ switch (uartInit->Parity) {
+ case LL_USART_PARITY_NONE:
+ attribute->parity = UART_ATTR_PARITY_NONE;
+ break;
+ case LL_USART_PARITY_EVEN:
+ attribute->parity = UART_ATTR_PARITY_EVEN;
+ break;
+ case LL_USART_PARITY_ODD:
+ attribute->parity = UART_ATTR_PARITY_ODD;
+ break;
+ default:
+ attribute->parity = UART_ATTR_PARITY_NONE;
+ break;
+ }
+ } else {
+ switch (attribute->parity) {
+ case UART_ATTR_PARITY_NONE:
+ uartInit->Parity = LL_USART_PARITY_NONE;
+ break;
+ case UART_ATTR_PARITY_EVEN:
+ uartInit->Parity = LL_USART_PARITY_EVEN;
+ break;
+ case UART_ATTR_PARITY_ODD:
+ uartInit->Parity = LL_USART_PARITY_ODD;
+ break;
+ default:
+ uartInit->Parity = LL_USART_PARITY_NONE;
+ break;
+ }
+ }
+
+ return;
+}
+
+static void TransStopbit(LL_USART_InitTypeDef *uartInit, struct UartAttribute *attribute, UART_ATTR_TRAN_TYPE type)
+{
+ if (uartInit == NULL || attribute == NULL) {
+ HDF_LOGE("null ptr\r\n");
+ return;
+ }
+
+ if (type == UART_ATTR_NIOBE_TO_HDF) {
+ switch (uartInit->StopBits) {
+ case LL_USART_STOPBITS_1:
+ attribute->stopBits = UART_ATTR_STOPBIT_1;
+ break;
+ case LL_USART_STOPBITS_1_5:
+ attribute->stopBits = UART_ATTR_STOPBIT_1P5;
+ break;
+ case LL_USART_STOPBITS_2:
+ attribute->stopBits = UART_ATTR_STOPBIT_2;
+ break;
+ default:
+ attribute->stopBits = UART_ATTR_PARITY_NONE;
+ break;
+ }
+ } else {
+ switch (attribute->stopBits) {
+ case UART_ATTR_STOPBIT_1:
+ uartInit->StopBits = LL_USART_STOPBITS_1;
+ break;
+ case UART_ATTR_STOPBIT_1P5:
+ uartInit->StopBits = LL_USART_STOPBITS_1_5;
+ break;
+ case UART_ATTR_STOPBIT_2:
+ uartInit->StopBits = LL_USART_STOPBITS_2;
+ break;
+ default:
+ uartInit->StopBits = LL_USART_STOPBITS_1;
+ break;
+ }
+ }
+
+ return;
+}
+
+static void TransFlowCtrl(LL_USART_InitTypeDef *uartInit, struct UartAttribute *attribute, UART_ATTR_TRAN_TYPE type)
+{
+ if (uartInit == NULL || attribute == NULL) {
+ HDF_LOGE("null ptr\r\n");
+ return;
+ }
+
+ if (type == UART_ATTR_NIOBE_TO_HDF) {
+ switch (uartInit->HardwareFlowControl) {
+ case LL_USART_HWCONTROL_NONE:
+ attribute->rts = 0;
+ attribute->cts = 0;
+ break;
+ case LL_USART_HWCONTROL_CTS:
+ attribute->rts = 0;
+ attribute->cts = 1;
+ break;
+ case LL_USART_HWCONTROL_RTS:
+ attribute->rts = 1;
+ attribute->cts = 0;
+ break;
+ case LL_USART_HWCONTROL_RTS_CTS:
+ attribute->rts = 1;
+ attribute->cts = 1;
+ break;
+ default:
+ attribute->rts = 0;
+ attribute->cts = 0;
+ break;
+ }
+ } else {
+ if (attribute->rts && attribute->cts) {
+ uartInit->HardwareFlowControl = LL_USART_HWCONTROL_RTS_CTS;
+ } else if (attribute->rts && !attribute->cts) {
+ uartInit->HardwareFlowControl = LL_USART_HWCONTROL_RTS;
+ } else if (!attribute->rts && attribute->cts) {
+ uartInit->HardwareFlowControl = LL_USART_HWCONTROL_CTS;
+ } else {
+ uartInit->HardwareFlowControl = LL_USART_HWCONTROL_NONE;
+ }
+ }
+
+ return;
+}
+
+static void TransDir(LL_USART_InitTypeDef *uartInit, struct UartAttribute *attribute, UART_ATTR_TRAN_TYPE type)
+{
+ if (uartInit == NULL || attribute == NULL) {
+ HDF_LOGE("null ptr\r\n");
+ return;
+ }
+ if (type == UART_ATTR_NIOBE_TO_HDF) {
+ switch (uartInit->TransferDirection) {
+ case LL_USART_DIRECTION_NONE:
+ attribute->fifoRxEn = 0;
+ attribute->fifoTxEn = 0;
+ break;
+ case LL_USART_DIRECTION_RX:
+ attribute->fifoRxEn = 1;
+ attribute->fifoTxEn = 0;
+ break;
+ case LL_USART_DIRECTION_TX:
+ attribute->fifoRxEn = 0;
+ attribute->fifoTxEn = 1;
+ break;
+ case LL_USART_DIRECTION_TX_RX:
+ attribute->fifoRxEn = 1;
+ attribute->fifoTxEn = 1;
+ break;
+ default:
+ attribute->fifoRxEn = 1;
+ attribute->fifoTxEn = 1;
+ break;
+ }
+ } else {
+ if (attribute->fifoRxEn && attribute->fifoTxEn) {
+ uartInit->TransferDirection = LL_USART_DIRECTION_TX_RX;
+ } else if (attribute->fifoRxEn && !attribute->fifoTxEn) {
+ uartInit->TransferDirection = LL_USART_DIRECTION_RX;
+ } else if (!attribute->fifoRxEn && attribute->fifoTxEn) {
+ uartInit->TransferDirection = LL_USART_DIRECTION_TX;
+ } else {
+ uartInit->TransferDirection = LL_USART_DIRECTION_NONE;
+ }
+ }
+
+ return;
+}
+
+static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribute *attribute)
+{
+ HDF_LOGI("%s: Enter", __func__);
+ UartDevice *uartDevice = NULL;
+ LL_USART_InitTypeDef *uartInit = NULL;
+ uint32_t uartId;
+ if (host == NULL || attribute == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ uartDevice = (UartDevice *)host->priv;
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ uartId = uartDevice->uartId;
+ uartInit = &uartDevice->initTypedef;
+ if (uartInit == NULL) {
+ HDF_LOGE("%s: config is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ TransDataWidth(uartInit, attribute, UART_ATTR_HDF_TO_NIOBE);
+ TransParity(uartInit, attribute, UART_ATTR_HDF_TO_NIOBE);
+ TransStopbit(uartInit, attribute, UART_ATTR_HDF_TO_NIOBE);
+ TransFlowCtrl(uartInit, attribute, UART_ATTR_HDF_TO_NIOBE);
+ TransDir(uartInit, attribute, UART_ATTR_HDF_TO_NIOBE);
+
+ UartHostDevDeinit(host);
+ UartHostDevInit(host);
+
+ return HDF_SUCCESS;
+}
+
+static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribute *attribute)
+{
+ HDF_LOGI("%s: Enter", __func__);
+ UartDevice *uartDevice = NULL;
+ LL_USART_InitTypeDef *uartInit = NULL;
+ if (host == NULL || attribute == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ uartDevice = (UartDevice *)host->priv;
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ uartInit = &uartDevice->initTypedef;
+ if (uartInit == NULL) {
+ HDF_LOGE("%s: uartInit is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ TransDataWidth(uartInit, attribute, UART_ATTR_NIOBE_TO_HDF);
+ TransParity(uartInit, attribute, UART_ATTR_NIOBE_TO_HDF);
+ TransStopbit(uartInit, attribute, UART_ATTR_NIOBE_TO_HDF);
+ TransFlowCtrl(uartInit, attribute, UART_ATTR_NIOBE_TO_HDF);
+ TransDir(uartInit, attribute, UART_ATTR_NIOBE_TO_HDF);
+
+ return HDF_SUCCESS;
+}
+
+static int32_t UartHostDevSetTransMode(struct UartHost *host, enum UartTransMode mode)
+{
+ HDF_LOGI("%s: Enter", __func__);
+ UartDevice *uartDevice = NULL;
+ uint32_t uartId;
+ if (host == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ uartDevice = (UartDevice *)host->priv;
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ uartId = uartDevice->uartId;
+
+ switch (mode) {
+ case UART_MODE_RD_BLOCK:
+ g_uartCtx[uartId - 1].isBlock = true;
+ break;
+ case UART_MODE_RD_NONBLOCK:
+ g_uartCtx[uartId - 1].isBlock = false;
+ break;
+ case UART_MODE_DMA_RX_EN:
+ g_uartCtx[uartId - 1].rxDMA = true;
+ break;
+ case UART_MODE_DMA_RX_DIS:
+ g_uartCtx[uartId - 1].rxDMA = false;
+ break;
+ case UART_MODE_DMA_TX_EN:
+ g_uartCtx[uartId - 1].txDMA = true;
+ break;
+ case UART_MODE_DMA_TX_DIS:
+ g_uartCtx[uartId - 1].txDMA = false;
+ break;
+ default:
+ HDF_LOGE("%s: UartTransMode(%d) invalid", __func__, mode);
+ break;
+ }
+
+ return HDF_SUCCESS;
+}
\ No newline at end of file
diff --git a/platform/uart/uart_wm.c b/platform/uart/uart_wm.c
new file mode 100755
index 0000000000000000000000000000000000000000..5a9ce8bf10ac623850816e1dff09a9219135a701
--- /dev/null
+++ b/platform/uart/uart_wm.c
@@ -0,0 +1,704 @@
+/*
+ * Copyright (c) 2022 Jiangsu Hoperun Software Co., Ltd.
+ *
+ * This file is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+#include
+#include
+#include "osal_time.h"
+#include "osal_sem.h"
+#include "device_resource_if.h"
+#include "hdf_log.h"
+#include "wm_gpio_afsel.h"
+#include "uart_if.h"
+#include "uart_core.h"
+#include "wm_uart.h"
+
+#define HDF_UART_TMO 1000
+#define TMO_MS_UNIT_CONV (1000)
+#define HDF_LOG_TAG uartDev
+
+#define UART_DEV_SERVICE_NAME_PREFIX "HDF_PLATFORM_UART%d"
+#define MAX_DEV_NAME_SIZE 32
+
+struct UartResource {
+ uint32_t num; /* UART port num */
+ uint32_t baudRate; /* Default baudrate */
+ uint32_t wLen; /* Default word length */
+ uint32_t parity; /* Default parity */
+ uint32_t stopBit; /* Default stop bits */
+ bool txDMA;
+ bool rxDMA;
+};
+
+enum UartDeviceState {
+ UART_DEVICE_UNINITIALIZED = 0x0u,
+ UART_DEVICE_INITIALIZED = 0x1u,
+};
+
+struct UART_CTX_OBJ {
+ bool txDMA;
+ bool rxDMA;
+ bool isBlock;
+ struct OsalSem rxSem;
+ struct OsalSem txSem;
+};
+
+struct UartDevice {
+ struct IDeviceIoService ioService;
+ struct UartResource resource;
+ tls_uart_options_t config;
+ uint32_t uartId;
+ bool initFlag;
+ uint32_t transMode;
+};
+
+enum {
+ UART_READ = 0,
+ UART_WRITE
+};
+
+static struct UART_CTX_OBJ g_uartCtx[4] = {0};
+static unsigned char *g_uartKfifoBuffer[4] = {NULL, NULL, NULL, NULL};
+
+static void HalSetUartIomux(int uartId)
+{
+ switch (uartId) {
+ case TLS_UART_0:
+ wm_uart0_tx_config(WM_IO_PB_19);
+ wm_uart0_rx_config(WM_IO_PB_20);
+ break;
+ case TLS_UART_1:
+ wm_uart1_tx_config(WM_IO_PB_06);
+ wm_uart1_rx_config(WM_IO_PB_07);
+ break;
+ case TLS_UART_2:
+ wm_uart2_tx_scio_config(WM_IO_PB_02);
+ wm_uart2_rx_config(WM_IO_PB_03);
+ break;
+ case TLS_UART_3:
+ wm_uart3_tx_config(WM_IO_PB_00);
+ wm_uart3_rx_config(WM_IO_PB_01);
+ break;
+ case TLS_UART_4:
+ wm_uart4_tx_config(WM_IO_PB_04);
+ wm_uart4_rx_config(WM_IO_PB_05);
+ break;
+ default:
+ HDF_LOGE("%s: uartId(%d) invalid", __func__, uartId);
+ break;
+ }
+}
+
+static void dma_tx_cmpl_callback(uint32_t arg)
+{
+ uint32_t uartId = arg;
+ OsalSemPost(&g_uartCtx[uartId].txSem);
+}
+
+static int32_t HalUartSend(uint32_t uartId, const uint8_t *data, uint32_t size, uint32_t timeOut)
+{
+ int32_t ret = HDF_FAILURE;
+
+ if (data == NULL || size == 0) {
+ HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ tls_uart_dma_write(data, (uint16_t)size, dma_tx_cmpl_callback, (uint16_t)uartId);
+ ret = OsalSemWait(&g_uartCtx[uartId].txSem, timeOut);
+
+ return ret;
+}
+
+static int32_t HalUartRecv(uint8_t uartId, uint8_t *data, uint32_t expectSize,
+ uint32_t *recvSize, uint32_t timeOut)
+{
+ int32_t ret = HDF_FAILURE;
+ uint32_t fifoPopLen = 0;
+ uint32_t recvedLen = 0;
+ uint32_t expectLen = expectSize;
+ OsalTimespec hdfTs1 = { 0, 0 };
+ OsalTimespec hdfTs2 = { 0, 0 };
+ OsalTimespec hdfTsDiff = { 0, 0 };
+
+ if (data == NULL || expectSize == 0 || recvSize == NULL) {
+ HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ OsalGetTime(&hdfTs1);
+ do {
+ fifoPopLen = tls_uart_read(uartId, (uint8_t *)data + recvedLen, expectLen);
+ recvedLen += fifoPopLen;
+ expectLen -= fifoPopLen;
+ if (recvedLen >= expectSize) {
+ break;
+ }
+ /* haven't get any data from fifo */
+ if (recvedLen == 0) {
+ break;
+ }
+ /* if reaches here, it means need to wait for more data come */
+ OsalMSleep(1);
+ /* time out break */
+ OsalGetTime(&hdfTs2);
+ OsalDiffTime(&hdfTs1, &hdfTs2, &hdfTsDiff);
+ if ((uint32_t)(hdfTsDiff.sec * TMO_MS_UNIT_CONV + hdfTsDiff.usec / TMO_MS_UNIT_CONV) >= timeOut) {
+ break;
+ }
+ } while (1);
+
+ if (recvSize != NULL) {
+ *recvSize = recvedLen;
+ }
+ return HDF_SUCCESS;
+}
+
+static void HalUartHandlerInit(struct UartDevice *device)
+{
+ uint32_t uartId;
+
+ if (device == NULL) {
+ HDF_LOGE("%s: INVALID PARAM", __func__);
+ return;
+ }
+
+ uartId = device->uartId;
+ OsalSemInit(&g_uartCtx[uartId].rxSem, 0);
+ OsalSemInit(&g_uartCtx[uartId].txSem, 0);
+}
+
+static void UartStart(struct UartDevice *device)
+{
+ uint32_t uartId;
+ tls_uart_options_t *uartCfg = NULL;
+ if (device == NULL) {
+ HDF_LOGE("%s: INVALID PARAM", __func__);
+ return;
+ }
+ uartId = device->uartId;
+ uartCfg = &device->config;
+ if (uartCfg == NULL) {
+ HDF_LOGE("%s: INVALID OBJECT", __func__);
+ return;
+ }
+ if (WM_SUCCESS != tls_uart_port_init(uartId, uartCfg, 0)) {
+ HDF_LOGE("uart %d init error", uartId);
+ }
+ HDF_LOGI("%s %ld\r\n", __FUNCTION__, uartId);
+ HalUartHandlerInit(device);
+}
+
+/* HdfDriverEntry method definitions */
+static int32_t UartDriverBind(struct HdfDeviceObject *device);
+static int32_t UartDriverInit(struct HdfDeviceObject *device);
+static void UartDriverRelease(struct HdfDeviceObject *device);
+
+/* HdfDriverEntry definitions */
+struct HdfDriverEntry g_UartDriverEntry = {
+ .moduleVersion = 1,
+ .moduleName = "W800_UART_MODULE_HDF",
+ .Bind = UartDriverBind,
+ .Init = UartDriverInit,
+ .Release = UartDriverRelease,
+};
+
+/* Initialize HdfDriverEntry */
+HDF_INIT(g_UartDriverEntry);
+
+/* UartHostMethod method definitions */
+static int32_t UartHostDevInit(struct UartHost *host);
+static int32_t UartHostDevDeinit(struct UartHost *host);
+static int32_t UartHostDevWrite(struct UartHost *host, uint8_t *data, uint32_t size);
+static int32_t UartHostDevSetBaud(struct UartHost *host, uint32_t baudRate);
+static int32_t UartHostDevGetBaud(struct UartHost *host, uint32_t *baudRate);
+static int32_t UartHostDevRead(struct UartHost *host, uint8_t *data, uint32_t size);
+static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribute *attribute);
+static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribute *attribute);
+static int32_t UartHostDevSetTransMode(struct UartHost *host, enum UartTransMode mode);
+
+/* UartHostMethod definitions */
+struct UartHostMethod g_uartHostMethod = {
+ .Init = UartHostDevInit,
+ .Deinit = UartHostDevDeinit,
+ .Read = UartHostDevRead,
+ .Write = UartHostDevWrite,
+ .SetBaud = UartHostDevSetBaud,
+ .GetBaud = UartHostDevGetBaud,
+ .SetAttribute = UartHostDevSetAttribute,
+ .GetAttribute = UartHostDevGetAttribute,
+ .SetTransMode = UartHostDevSetTransMode,
+};
+
+static int InitUartDevice(struct UartHost *host)
+{
+ HDF_LOGI("%s: Enter", __func__);
+ struct UartDevice *uartDevice = NULL;
+
+ if (host == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ uartDevice = (struct UartDevice *)host->priv;
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: INVALID OBJECT", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ if (!uartDevice->initFlag) {
+ HDF_LOGI("uart %ld device init", uartDevice->uartId);
+ HalSetUartIomux(uartDevice->uartId);
+ UartStart(uartDevice);
+ uartDevice->initFlag = true;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static uint32_t GetUartDeviceResource(struct UartDevice *device, const struct DeviceResourceNode *resourceNode)
+{
+ struct DeviceResourceIface *dri = NULL;
+ struct UartResource *resource = NULL;
+ if (device == NULL || resourceNode == NULL) {
+ HDF_LOGE("%s: INVALID PARAM", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ resource = &device->resource;
+ if (resource == NULL) {
+ HDF_LOGE("%s: INVALID OBJECT", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ if (dri == NULL || dri->GetUint32 == NULL) {
+ HDF_LOGE("DeviceResourceIface is invalid");
+ return HDF_ERR_INVALID_PARAM;
+ }
+ if (dri->GetUint32(resourceNode, "num", &resource->num, 0) != HDF_SUCCESS) {
+ HDF_LOGE("uart config read num fail");
+ return HDF_FAILURE;
+ }
+ if (dri->GetUint32(resourceNode, "baudrate", &resource->baudRate, 0) != HDF_SUCCESS) {
+ HDF_LOGE("uart config read baudrate fail");
+ return HDF_FAILURE;
+ }
+ if (dri->GetUint32(resourceNode, "parity", &resource->parity, 0) != HDF_SUCCESS) {
+ HDF_LOGE("uart config read parity fail");
+ return HDF_FAILURE;
+ }
+ if (dri->GetUint32(resourceNode, "stopBit", &resource->stopBit, 0) != HDF_SUCCESS) {
+ HDF_LOGE("uart config read stopBit fail");
+ return HDF_FAILURE;
+ }
+
+ HDF_LOGI("%d, %d, %d, %d", resource->num, resource->baudRate, resource->parity);
+
+ // copy config
+ device->uartId = resource->num;
+ device->config.baudrate = resource->baudRate;
+ device->config.paritytype = (TLS_UART_PMODE_T)resource->parity;
+ device->config.stopbits = (TLS_UART_STOPBITS_T)resource->stopBit;
+ device->config.charlength = TLS_UART_CHSIZE_8BIT;
+ device->config.flow_ctrl = TLS_UART_FLOW_CTRL_NONE;
+ return HDF_SUCCESS;
+}
+
+static int32_t AttachUartDevice(struct UartHost *uartHost, struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct UartDevice *uartDevice = NULL;
+
+ if (uartHost == NULL || device == NULL || device->property == NULL) {
+ HDF_LOGE("%s: property is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ uartDevice = (struct UartDevice *)OsalMemAlloc(sizeof(struct UartDevice));
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: OsalMemCalloc uartDevice error", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ ret = GetUartDeviceResource(uartDevice, device->property);
+ if (ret != HDF_SUCCESS) {
+ (void)OsalMemFree(uartDevice);
+ return HDF_FAILURE;
+ }
+
+ uartHost->priv = uartDevice;
+
+ return InitUartDevice(uartHost);
+}
+
+static int32_t UartDriverBind(struct HdfDeviceObject *device)
+{
+ struct UartHost *devService;
+ if (device == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ devService = (struct UartHost *)OsalMemAlloc(sizeof(*devService));
+ if (devService == NULL) {
+ HDF_LOGE("%s: OsalMemCalloc error", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ devService->device = device;
+ device->service = &(devService->service);
+ devService->priv = NULL;
+ devService->method = NULL;
+ return HDF_SUCCESS;
+}
+
+static void UartDriverRelease(struct HdfDeviceObject *device)
+{
+ HDF_LOGI("Enter %s:", __func__);
+ uint32_t uartId;
+ struct UartHost *host = NULL;
+ struct UartDevice *uartDevice = NULL;
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return;
+ }
+
+ host = UartHostFromDevice(device);
+ if (host == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: host is NULL", __func__);
+ return;
+ }
+
+ uartDevice = (struct UartDevice *)host->priv;
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: INVALID OBJECT", __func__);
+ return;
+ }
+ uartId = uartDevice->uartId;
+ host->method = NULL;
+
+ OsalSemDestroy(&g_uartCtx[uartId].rxSem);
+ OsalSemDestroy(&g_uartCtx[uartId].txSem);
+ OsalMemFree(uartDevice);
+ OsalMemFree(host);
+}
+
+static int32_t UartDriverInit(struct HdfDeviceObject *device)
+{
+ HDF_LOGI("Enter %s:", __func__);
+ int32_t ret;
+ struct UartHost *host = NULL;
+
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ host = UartHostFromDevice(device);
+ if (host == NULL) {
+ HDF_LOGE("%s: host is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ ret = AttachUartDevice(host, device);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: attach error", __func__);
+ return HDF_FAILURE;
+ }
+
+ host->method = &g_uartHostMethod;
+
+ return ret;
+}
+
+/* UartHostMethod implementations */
+static int32_t UartHostDevInit(struct UartHost *host)
+{
+ HDF_LOGI("%s: Enter\r\n", __func__);
+ if (host == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ InitUartDevice(host);
+ return HDF_SUCCESS;
+}
+
+static int32_t UartHostDevDeinit(struct UartHost *host)
+{
+ HDF_LOGI("%s: Enter", __func__);
+ uint32_t uartId;
+ struct UartDevice *uartDevice = NULL;
+ if (host == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ uartDevice = (struct UartDevice *)host->priv;
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: INVALID OBJECT", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ uartId = uartDevice->uartId;
+ uartDevice->initFlag = false;
+
+ return HDF_SUCCESS;
+}
+static int32_t UartHostDevWrite(struct UartHost *host, uint8_t *data, uint32_t size)
+{
+ struct UartDevice *device = NULL;
+ uint32_t portId;
+
+ if (host == NULL || data == NULL || size == 0 || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ device = (struct UartDevice *)host->priv;
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ portId = device->uartId;
+
+ if (g_uartCtx[portId].txDMA) {
+ return HalUartSend(portId, data, size, HDF_UART_TMO);
+ } else {
+ if (tls_uart_write(portId, data, size) < 0) {
+ return HDF_FAILURE;
+ }
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t UartHostDevRead(struct UartHost *host, uint8_t *data, uint32_t size)
+{
+ uint32_t recvSize = 0;
+ int32_t ret;
+ uint32_t uartId;
+ struct UartDevice *uartDevice = NULL;
+ if (host == NULL || data == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ uartDevice = (struct UartDevice *)host->priv;
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ uartId = uartDevice->uartId;
+ if (g_uartCtx[uartId].rxDMA) {
+ ret = HalUartRecv(uartId, data, size, &recvSize, HDF_UART_TMO);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("uart %ld recev error\r\n", uartId);
+ return ret;
+ }
+ ret = recvSize;
+ } else {
+ if (g_uartCtx[uartId].isBlock) {
+ while (tls_uart_try_read(uartId, 1) == 0);
+ ret = tls_uart_read(uartId, data, 1);
+ } else {
+ ret = tls_uart_read(uartId, data, 1);
+ }
+ ret = 1;
+ }
+ return ret;
+}
+
+static int32_t UartHostDevSetBaud(struct UartHost *host, uint32_t baudRate)
+{
+ HDF_LOGI("%s: Enter", __func__);
+ struct UartDevice *uartDevice = NULL;
+ tls_uart_options_t *uartCfg = NULL;
+ uint32_t uartId;
+ if (host == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ uartDevice = (struct UartDevice *)host->priv;
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ uartId = uartDevice->uartId;
+
+ uartCfg = &uartDevice->config;
+ if (uartCfg == NULL) {
+ HDF_LOGE("%s: device config is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ uartCfg->baudrate = baudRate;
+
+ tls_uart_set_baud_rate(uartId, uartCfg->baudrate);
+
+ return HDF_SUCCESS;
+}
+
+static int32_t UartHostDevGetBaud(struct UartHost *host, uint32_t *baudRate)
+{
+ HDF_LOGI("%s: Enter", __func__);
+ struct UartDevice *uartDevice = NULL;
+ tls_uart_options_t *uartCfg = NULL;
+ uint32_t uartId;
+ if (host == NULL || baudRate == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ uartDevice = (struct UartDevice *)host->priv;
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ uartId = uartDevice->uartId;
+
+ uartCfg = &uartDevice->config;
+ if (uartCfg == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ *baudRate = uartCfg->baudrate;
+ return HDF_SUCCESS;
+}
+
+static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribute *attribute)
+{
+ struct UartDevice *uartDevice = NULL;
+ tls_uart_options_t *uartCfg = NULL;
+ uint32_t uartId;
+ if (host == NULL || attribute == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ uartDevice = (struct UartDevice *)host->priv;
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ uartId = uartDevice->uartId;
+ uartCfg = &uartDevice->config;
+ if (uartCfg == NULL) {
+ HDF_LOGE("%s: config is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ uartCfg->paritytype = attribute->parity;
+ tls_uart_set_parity(uartId, uartCfg->paritytype);
+
+ switch (attribute->stopBits) {
+ case UART_ATTR_STOPBIT_1:
+ uartCfg->stopbits = TLS_UART_ONE_STOPBITS;
+ break;
+ case UART_ATTR_STOPBIT_2:
+ uartCfg->stopbits = TLS_UART_TWO_STOPBITS;
+ break;
+ default:
+ uartCfg->stopbits = TLS_UART_ONE_STOPBITS;
+ break;
+ }
+ tls_uart_set_stop_bits(uartId, uartCfg->stopbits);
+
+ if (attribute->rts && attribute->cts) {
+ uartCfg->flow_ctrl = TLS_UART_FLOW_CTRL_HARDWARE;
+ } else {
+ uartCfg->flow_ctrl = TLS_UART_FLOW_CTRL_NONE;
+ }
+ tls_uart_set_fc_status(uartId, uartCfg->flow_ctrl);
+ return HDF_SUCCESS;
+}
+
+static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribute *attribute)
+{
+ HDF_LOGI("%s: Enter", __func__);
+ struct UartDevice *uartDevice = NULL;
+ tls_uart_options_t *uartCfg = NULL;
+ if (host == NULL || attribute == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ uartDevice = (struct UartDevice *)host->priv;
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ uartCfg = &uartDevice->config;
+ if (uartCfg == NULL) {
+ HDF_LOGE("%s: config is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ attribute->parity = uartCfg->paritytype;
+
+ switch (uartCfg->stopbits) {
+ case TLS_UART_ONE_STOPBITS:
+ attribute->stopBits = UART_ATTR_STOPBIT_1;
+ break;
+ case TLS_UART_TWO_STOPBITS:
+ attribute->stopBits = UART_ATTR_STOPBIT_2;
+ break;
+ default:
+ attribute->stopBits = UART_ATTR_STOPBIT_1;
+ break;
+ }
+
+ switch (uartCfg->flow_ctrl) {
+ case TLS_UART_FLOW_CTRL_HARDWARE:
+ attribute->rts = 1;
+ attribute->cts = 1;
+ break;
+ default:
+ attribute->rts = 0;
+ attribute->cts = 0;
+ break;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t UartHostDevSetTransMode(struct UartHost *host, enum UartTransMode mode)
+{
+ HDF_LOGI("%s: Enter", __func__);
+ struct UartDevice *uartDevice = NULL;
+ uint32_t uartId;
+ if (host == NULL || host->priv == NULL) {
+ HDF_LOGE("%s: invalid parameter", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ uartDevice = (struct UartDevice *)host->priv;
+ if (uartDevice == NULL) {
+ HDF_LOGE("%s: device is NULL", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ uartId = uartDevice->uartId;
+
+ switch (mode) {
+ case UART_MODE_RD_BLOCK:
+ g_uartCtx[uartId].isBlock = true;
+ break;
+ case UART_MODE_RD_NONBLOCK:
+ g_uartCtx[uartId].isBlock = false;
+ break;
+ case UART_MODE_DMA_RX_EN:
+ g_uartCtx[uartId].rxDMA = true;
+ break;
+ case UART_MODE_DMA_RX_DIS:
+ g_uartCtx[uartId].rxDMA = false;
+ break;
+ case UART_MODE_DMA_TX_EN:
+ g_uartCtx[uartId].txDMA = true;
+ break;
+ case UART_MODE_DMA_TX_DIS:
+ g_uartCtx[uartId].txDMA = false;
+ break;
+ default:
+ HDF_LOGE("%s: UartTransMode(%d) invalid", __func__, mode);
+ break;
+ }
+ return HDF_SUCCESS;
+}
diff --git a/platform/watchdog/BUILD.gn b/platform/watchdog/BUILD.gn
index 9dd31cf8608bf913d2d29a6d168b7121f58cf91a..1088512f116f6b94f6663e88f9436ae68cf70045 100644
--- a/platform/watchdog/BUILD.gn
+++ b/platform/watchdog/BUILD.gn
@@ -1,31 +1,10 @@
#
-# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved.
+# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
#
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
+# This file is dual licensed: you can use it either under the terms of
+# the GPL, or the BSD license, at your option.
+# See the LICENSE file in the root of this repository for complete details.
#
-# 1. Redistributions of source code must retain the above copyright notice, this list of
-# conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice, this list
-# of conditions and the following disclaimer in the documentation and/or other materials
-# provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its contributors may be used
-# to endorse or promote products derived from this software without specific prior written
-# permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//drivers/adapter/khdf/liteos_m/hdf.gni")
@@ -38,5 +17,23 @@ hdf_driver(module_name) {
sources += [ "watchdog_bes.c" ]
}
+ if (defined(LOSCFG_SOC_COMPANY_STMICROELECTRONICS)) {
+ sources += [ "watchdog_stm32f4xx.c" ]
+ }
+
+ if (defined(LOSCFG_SOC_COMPANY_WINNERMICRO)) {
+ sources += [ "watchdog_wm.c" ]
+ }
+
include_dirs = [ "." ]
+ if (defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)) {
+ HDF_HCS_BUILD_PATH = rebase_path(
+ "//device/board/$device_company/$device_name/liteos_m/hdf_config")
+ cmd = "if [ -f ${HDF_HCS_BUILD_PATH}/BUILD.gn ]; then echo true; else echo false; fi"
+ HAVE_HCS_BUILD_PATH =
+ exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
+ if (HAVE_HCS_BUILD_PATH) {
+ deps = [ "${HDF_HCS_BUILD_PATH}" ]
+ }
+ }
}
diff --git a/platform/watchdog/watchdog_bes.c b/platform/watchdog/watchdog_bes.c
index d0e22d6ed3bec8093fb5ae46116c487a0a13d2e6..7071f41ca8b0b426d3ed4e4ea34ec19c74caf971 100755
--- a/platform/watchdog/watchdog_bes.c
+++ b/platform/watchdog/watchdog_bes.c
@@ -1,17 +1,11 @@
/*
- * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * This file is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
+
#include "watchdog_bes.h"
#include
#include
@@ -53,7 +47,7 @@ static int InitWatchdogDevice(struct WatchdogDevice *watchdogDevice)
struct WatchdogResource *resource = NULL;
int32_t watchdogId;
if (watchdogDevice == NULL) {
- HDF_LOGE("%s: invaild parameter\r\n", __func__);
+ HDF_LOGE("%s: invalid parameter\r\n", __func__);
return HDF_ERR_INVALID_PARAM;
}
@@ -188,7 +182,7 @@ static int32_t WatchdogDriverInit(struct HdfDeviceObject *device)
}
watchdogCntlr->ops = &g_WatchdogCntlrMethod;
-
+
HDF_LOGE("WatchdogDriverInit success!\r\n");
return ret;
}
@@ -326,4 +320,4 @@ static int32_t WatchdogDevReleasePriv(struct WatchdogCntlr *watchdogCntlr)
{
(void)watchdogCntlr;
return HDF_SUCCESS;
-}
\ No newline at end of file
+}
diff --git a/platform/watchdog/watchdog_bes.h b/platform/watchdog/watchdog_bes.h
old mode 100755
new mode 100644
index 2f08bd2c172f8afd359fca3744bd1f6e048ac494..32dbe98b57b16196e3fde0335dc65afd981f8a05
--- a/platform/watchdog/watchdog_bes.h
+++ b/platform/watchdog/watchdog_bes.h
@@ -1,17 +1,11 @@
/*
- * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * This file is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
+
#ifndef BES_WATCHDOG_H
#define BES_WATCHDOG_H
@@ -33,4 +27,4 @@ struct WatchdogDevice {
#ifdef __cplusplus
}
#endif
-#endif
\ No newline at end of file
+#endif
diff --git a/platform/watchdog/watchdog_stm32f4xx.c b/platform/watchdog/watchdog_stm32f4xx.c
new file mode 100644
index 0000000000000000000000000000000000000000..934d43ccebd23ceae32916ac55ccf80215bbf4ab
--- /dev/null
+++ b/platform/watchdog/watchdog_stm32f4xx.c
@@ -0,0 +1,379 @@
+/*
+ * Copyright (c) 2022 Talkweb Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include
+#include
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+#include "hcs_macro.h"
+#include "hdf_config_macro.h"
+#else
+#include "device_resource_if.h"
+#endif
+#include "hdf_device_desc.h"
+#include "hdf_log.h"
+#include "watchdog_core.h"
+#include "watchdog_if.h"
+
+#define WATCHDOG_MIN_TIMEOUT 1
+#define WATCHDOG_MAX_TIMEOUT 4096
+#define WATCHDOG_UPDATE_TIME (((6UL * 256UL * 1000UL) / LSI_VALUE) + ((LSI_STARTUP_TIME / 1000UL) + 1UL))
+
+typedef struct {
+ int watchdogId;
+ int timeout; // Maximum interval between watchdog feeding, unit: ms
+} WatchdogDeviceInfo;
+
+static IWDG_TypeDef *hdf_iwdg = NULL;
+static int g_watchdogStart = 0;
+static int g_watchdogTimeout = 0;
+
+static int32_t WatchdogDevStart(struct WatchdogCntlr *watchdogCntlr);
+static int32_t WatchdogDevStop(struct WatchdogCntlr *watchdogCntlr);
+static int32_t WatchdogDevSetTimeout(struct WatchdogCntlr *watchdogCntlr, uint32_t seconds);
+static int32_t WatchdogDevGetTimeout(struct WatchdogCntlr *watchdogCntlr, uint32_t *seconds);
+static int32_t WatchdogDevGetStatus(struct WatchdogCntlr *watchdogCntlr, uint32_t *status);
+static int32_t WatchdogDevFeed(struct WatchdogCntlr *watchdogCntlr);
+
+struct WatchdogMethod g_WatchdogCntlrMethod = {
+ .getStatus = WatchdogDevGetStatus,
+ .setTimeout = WatchdogDevSetTimeout,
+ .getTimeout = WatchdogDevGetTimeout,
+ .start = WatchdogDevStart,
+ .stop = WatchdogDevStop,
+ .feed = WatchdogDevFeed,
+ .getPriv = NULL,
+ .releasePriv = NULL,
+};
+
+static int InitWatchdogDeviceInfo(WatchdogDeviceInfo *watchdogdeviceinfo)
+{
+ if (watchdogdeviceinfo == NULL) {
+ HDF_LOGE("%s: invaild parameter\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ return HDF_SUCCESS;
+}
+
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+#define WATCHDOG_FIND_CONFIG(node, name, device) \
+ do { \
+ if (strcmp(HCS_PROP(node, match_attr), name) == 0) { \
+ device->watchdogId = HCS_PROP(node, id); \
+ device->timeout = HCS_PROP(node, timeout); \
+ result = HDF_SUCCESS; \
+ } \
+ } while (0)
+#define PLATFORM_CONFIG HCS_NODE(HCS_ROOT, platform)
+#define PLATFORM_WATCHDOG_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), watchdog_config)
+static uint32_t GetWatchdogDeviceInfoResource(WatchdogDeviceInfo *device, const char *deviceMatchAttr)
+{
+ int32_t result = HDF_FAILURE;
+ if (device == NULL || deviceMatchAttr == NULL) {
+ HDF_LOGE("device or deviceMatchAttr is NULL\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+#if HCS_NODE_HAS_PROP(PLATFORM_CONFIG, watchdog_config)
+ HCS_FOREACH_CHILD_VARGS(PLATFORM_WATCHDOG_CONFIG, WATCHDOG_FIND_CONFIG, deviceMatchAttr, device);
+#endif
+ if (result != HDF_SUCCESS) {
+ HDF_LOGE("resourceNode %s is NULL\r\n", deviceMatchAttr);
+ return result;
+ }
+
+ return HDF_SUCCESS;
+}
+#else
+static uint32_t GetWatchdogDeviceInfoResource(WatchdogDeviceInfo *device, const struct DeviceResourceNode *resourceNode)
+{
+ struct DeviceResourceIface *dri = NULL;
+ if (device == NULL || resourceNode == NULL) {
+ HDF_LOGE("resource or device is NULL\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ if (dri == NULL || dri->GetUint32 == NULL) {
+ HDF_LOGE("DeviceResourceIface is invalid\r\n");
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ if (dri->GetUint32(resourceNode, "id", &device->watchdogId, 0) != HDF_SUCCESS) {
+ HDF_LOGE("read watchdogId fail\r\n");
+ return HDF_FAILURE;
+ }
+ if (dri->GetUint32(resourceNode, "timeout", &device->timeout, 0) != HDF_SUCCESS) {
+ HDF_LOGE("read watchdogId fail\r\n");
+ return HDF_FAILURE;
+ }
+
+ HDF_LOGI("watchdogId = %d\n", device->watchdogId);
+ HDF_LOGI("timeout = %dms\n", device->timeout);
+
+ return HDF_SUCCESS;
+}
+#endif
+
+static int32_t AttachWatchdogDeviceInfo(struct WatchdogCntlr *watchdogCntlr, struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ WatchdogDeviceInfo *watchdogdeviceinfo = NULL;
+
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+ if (device == NULL || device->deviceMatchAttr == NULL) {
+#else
+ if (device == NULL || device->property == NULL) {
+#endif
+ HDF_LOGE("%s: param is NULL\r\n", __func__);
+ return HDF_FAILURE;
+ }
+
+ watchdogdeviceinfo = (WatchdogDeviceInfo *)OsalMemAlloc(sizeof(WatchdogDeviceInfo));
+ if (watchdogdeviceinfo == NULL) {
+ HDF_LOGE("%s: OsalMemAlloc WatchdogDeviceInfo error\r\n", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+#ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
+ ret = GetWatchdogDeviceInfoResource(watchdogdeviceinfo, device->deviceMatchAttr);
+#else
+ ret = GetWatchdogDeviceInfoResource(watchdogdeviceinfo, device->property);
+#endif
+ if (ret != HDF_SUCCESS) {
+ (void)OsalMemFree(watchdogdeviceinfo);
+ return HDF_FAILURE;
+ }
+
+ (void)OsalMutexInit(&watchdogCntlr->lock);
+
+ watchdogCntlr->priv = watchdogdeviceinfo;
+ watchdogCntlr->wdtId = watchdogdeviceinfo->watchdogId;
+
+ return InitWatchdogDeviceInfo(watchdogdeviceinfo);
+}
+/* HdfDriverEntry method definitions */
+static int32_t WatchdogDriverBind(struct HdfDeviceObject *device);
+static int32_t WatchdogDriverInit(struct HdfDeviceObject *device);
+static void WatchdogDriverRelease(struct HdfDeviceObject *device);
+
+/* HdfDriverEntry definitions */
+struct HdfDriverEntry g_watchdogDriverEntry = {
+ .moduleVersion = 1,
+ .moduleName = "ST_WATCHDOG_MODULE_HDF",
+ .Bind = WatchdogDriverBind,
+ .Init = WatchdogDriverInit,
+ .Release = WatchdogDriverRelease,
+};
+
+// Initialize HdfDriverEntry
+HDF_INIT(g_watchdogDriverEntry);
+
+static int32_t WatchdogDriverBind(struct HdfDeviceObject *device)
+{
+ struct WatchdogCntlr *watchdogCntlr = NULL;
+
+ if (device == NULL) {
+ HDF_LOGE("hdfDevice object is null!\r\n");
+ return HDF_FAILURE;
+ }
+
+ watchdogCntlr = (struct WatchdogCntlr *)OsalMemAlloc(sizeof(struct WatchdogCntlr));
+ if (watchdogCntlr == NULL) {
+ HDF_LOGE("%s: OsalMemAlloc watchdogCntlr error\r\n", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ HDF_LOGI("Enter %s\r\n", __func__);
+ device->service = &watchdogCntlr->service;
+ watchdogCntlr->device = device;
+ watchdogCntlr->priv = NULL;
+ return HDF_SUCCESS;
+}
+
+static int32_t WatchdogDriverInit(struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct WatchdogCntlr *watchdogCntlr = NULL;
+
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ HDF_LOGI("Enter %s:\r\n", __func__);
+
+ watchdogCntlr = WatchdogCntlrFromDevice(device);
+ if (watchdogCntlr == NULL) {
+ HDF_LOGE("%s: watchdogCntlr is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ ret = AttachWatchdogDeviceInfo(watchdogCntlr, device);
+ if (ret != HDF_SUCCESS) {
+ OsalMemFree(watchdogCntlr);
+ HDF_LOGE("%s:attach error\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ watchdogCntlr->ops = &g_WatchdogCntlrMethod;
+
+ HDF_LOGI("WatchdogDriverInit success!\r\n");
+ return ret;
+}
+
+static void WatchdogDriverRelease(struct HdfDeviceObject *device)
+{
+ struct WatchdogCntlr *watchdogCntlr = NULL;
+ WatchdogDeviceInfo *watchdogdeviceinfo = NULL;
+
+ if (device == NULL) {
+ HDF_LOGE("device is null\r\n");
+ return;
+ }
+
+ watchdogCntlr = WatchdogCntlrFromDevice(device);
+ if (watchdogCntlr == NULL || watchdogCntlr->priv == NULL) {
+ HDF_LOGE("%s: watchdogCntlr is NULL\r\n", __func__);
+ return;
+ }
+
+ watchdogdeviceinfo = (WatchdogDeviceInfo *)watchdogCntlr->priv;
+ if (watchdogdeviceinfo != NULL) {
+ OsalMemFree(watchdogdeviceinfo);
+ }
+ return;
+}
+
+static int32_t WatchdogDevStart(struct WatchdogCntlr *watchdogCntlr)
+{
+ WatchdogDeviceInfo *watchdogdeviceinfo = NULL;
+ int32_t watchdogId = 0;
+ int32_t timeout = 0;
+ unsigned long long tickstart = 0;
+
+ if (watchdogCntlr == NULL || watchdogCntlr->priv == NULL) {
+ HDF_LOGE("%s: watchdogCntlr is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ watchdogdeviceinfo = (WatchdogDeviceInfo *)watchdogCntlr->priv;
+ if (watchdogdeviceinfo == NULL) {
+ HDF_LOGE("%s: OBJECT is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ watchdogId = watchdogdeviceinfo->watchdogId;
+ timeout = watchdogdeviceinfo->timeout;
+
+ if (timeout < WATCHDOG_MIN_TIMEOUT) {
+ HDF_LOGW("%s: watchdog timeout must >= 1, set the timeout to 1ms\r\n", __func__);
+ timeout = WATCHDOG_MIN_TIMEOUT;
+ }
+ if (timeout > WATCHDOG_MAX_TIMEOUT) {
+ HDF_LOGW("%s: watchdog timeout must <= 1, set the timeout to 4096ms\r\n", __func__);
+ timeout = WATCHDOG_MAX_TIMEOUT;
+ }
+
+ HDF_LOGI("%s: watchdog Started! timeout: %dms\r\n", __func__, timeout);
+
+ hdf_iwdg = IWDG; // Point to watchdog register
+ hdf_iwdg->KR = IWDG_KEY_ENABLE;
+ hdf_iwdg->KR = IWDG_KEY_WRITE_ACCESS_ENABLE;
+ hdf_iwdg->PR = IWDG_PRESCALER_32; // 32 frequency division
+ hdf_iwdg->RLR = timeout - 1; // 32K crystal oscillator corresponds to 1-4096ms under 32 prescaled frequency
+
+ tickstart = LOS_TickCountGet();
+ // Wait for the register value to be updated and confirm that the watchdog is started successfully
+ while ((hdf_iwdg->SR & (IWDG_SR_RVU | IWDG_SR_PVU)) != 0x00u) {
+ if ((LOS_TickCountGet() - tickstart) > WATCHDOG_UPDATE_TIME) {
+ if ((hdf_iwdg->SR & (IWDG_SR_RVU | IWDG_SR_PVU)) != 0x00u) {
+ return HDF_FAILURE;
+ }
+ }
+ }
+ hdf_iwdg->KR = IWDG_KEY_RELOAD; // Reload initial value
+
+ g_watchdogStart = 1;
+ return HDF_SUCCESS;
+}
+
+static int32_t WatchdogDevStop(struct WatchdogCntlr *watchdogCntlr)
+{
+ HDF_LOGW("%s: WatchdogDevStop fail,because of soc not support!!\r\n", __func__);
+ return HDF_FAILURE;
+}
+
+static int32_t WatchdogDevSetTimeout(struct WatchdogCntlr *watchdogCntlr, uint32_t seconds)
+{
+ WatchdogDeviceInfo *watchdogdeviceinfo = NULL;
+ if (watchdogCntlr == NULL || watchdogCntlr->priv == NULL) {
+ HDF_LOGE("%s: watchdogCntlr is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ watchdogdeviceinfo = (WatchdogDeviceInfo *)watchdogCntlr->priv;
+ if (watchdogdeviceinfo == NULL) {
+ HDF_LOGE("%s: OBJECT is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ watchdogdeviceinfo->timeout = seconds;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t WatchdogDevGetTimeout(struct WatchdogCntlr *watchdogCntlr, uint32_t *seconds)
+{
+ WatchdogDeviceInfo *watchdogdeviceinfo = NULL;
+ if (watchdogCntlr == NULL || seconds == NULL) {
+ HDF_LOGE("%s: PARAM is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ watchdogdeviceinfo = (WatchdogDeviceInfo *)watchdogCntlr->priv;
+ if (watchdogdeviceinfo == NULL) {
+ HDF_LOGE("%s: OBJECT is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ *seconds = watchdogdeviceinfo->timeout;
+ return HDF_SUCCESS;
+}
+
+static int32_t WatchdogDevGetStatus(struct WatchdogCntlr *watchdogCntlr, uint32_t *status)
+{
+ if (watchdogCntlr == NULL || status == NULL) {
+ HDF_LOGE("%s: PARAM is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ if (g_watchdogStart == 1) {
+ *status = WATCHDOG_START;
+ } else {
+ *status = WATCHDOG_STOP;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t WatchdogDevFeed(struct WatchdogCntlr *watchdogCntlr)
+{
+ (void)watchdogCntlr;
+ if (hdf_iwdg != NULL)
+ hdf_iwdg->KR = IWDG_KEY_RELOAD; // Reload initial value
+ return HDF_SUCCESS;
+}
+
+static int32_t WatchdogDevGetPriv(struct WatchdogCntlr *watchdogCntlr)
+{
+ (void)watchdogCntlr;
+ return HDF_SUCCESS;
+}
+
+static int32_t WatchdogDevReleasePriv(struct WatchdogCntlr *watchdogCntlr)
+{
+ (void)watchdogCntlr;
+ return HDF_SUCCESS;
+}
\ No newline at end of file
diff --git a/platform/watchdog/watchdog_wm.c b/platform/watchdog/watchdog_wm.c
new file mode 100755
index 0000000000000000000000000000000000000000..6a381a23234083932068471d547ff247a3ced896
--- /dev/null
+++ b/platform/watchdog/watchdog_wm.c
@@ -0,0 +1,259 @@
+/*
+ * Copyright (c) 2022 Jiangsu Hoperun Software Co., Ltd.
+ *
+ * This file is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include
+#include
+#include "device_resource_if.h"
+#include "hdf_device_desc.h"
+#include "hdf_log.h"
+#include "watchdog_if.h"
+#include "watchdog_core.h"
+#include "wm_regs.h"
+#include "wm_cpu.h"
+
+struct WatchdogResource {
+ int32_t watchdogId;
+};
+
+struct WatchdogDevice {
+ struct WatchdogResource resource;
+};
+
+static int g_watchdogStart;
+static int g_watchdogTimeout;
+
+static int32_t WatchdogDevStart(struct WatchdogCntlr *watchdogCntlr);
+static int32_t WatchdogDevSetTimeout(struct WatchdogCntlr *watchdogCntlr, uint32_t seconds);
+static int32_t WatchdogDevGetTimeout(struct WatchdogCntlr *watchdogCntlr, uint32_t *seconds);
+static int32_t WatchdogDevGetStatus(struct WatchdogCntlr *watchdogCntlr, uint32_t *status);
+static int32_t WatchdogDevFeed(struct WatchdogCntlr *watchdogCntlr);
+
+struct WatchdogMethod g_WatchdogCntlrMethod = {
+ .getStatus = WatchdogDevGetStatus,
+ .setTimeout = WatchdogDevSetTimeout,
+ .getTimeout = WatchdogDevGetTimeout,
+ .start = WatchdogDevStart,
+ .stop = NULL, // WatchdogDevStop
+ .feed = WatchdogDevFeed,
+ .getPriv = NULL, // WatchdogDevGetPriv
+ .releasePriv = NULL, // WatchdogDevReleasePriv
+};
+
+static int32_t WatchdogDevStart(struct WatchdogCntlr *watchdogCntlr)
+{
+ tls_watchdog_start_cal_elapsed_time();
+ g_watchdogStart = 1;
+ return HDF_SUCCESS;
+}
+
+static int32_t WatchdogDevSetTimeout(struct WatchdogCntlr *watchdogCntlr, uint32_t seconds)
+{
+ g_watchdogTimeout = seconds;
+ tls_watchdog_init(seconds);
+ return HDF_SUCCESS;
+}
+
+static int32_t WatchdogDevGetTimeout(struct WatchdogCntlr *watchdogCntlr, uint32_t *seconds)
+{
+ if (watchdogCntlr == NULL || seconds == NULL) {
+ HDF_LOGE("%s: PARAM is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ g_watchdogTimeout = tls_watchdog_stop_cal_elapsed_time();
+
+ *seconds = g_watchdogTimeout;
+ return HDF_SUCCESS;
+}
+
+static int32_t WatchdogDevGetStatus(struct WatchdogCntlr *watchdogCntlr, uint32_t *status)
+{
+ if (watchdogCntlr == NULL || status == NULL) {
+ HDF_LOGE("%s: PARAM is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ if (g_watchdogStart == 1) {
+ *status = WATCHDOG_START;
+ } else {
+ *status = WATCHDOG_STOP;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t WatchdogDevFeed(struct WatchdogCntlr *watchdogCntlr)
+{
+ tls_sys_clk sysclk;
+
+ tls_sys_clk_get(&sysclk);
+ if (g_watchdogStart == 1) {
+ tls_sys_reset();
+ }
+ return HDF_SUCCESS;
+}
+
+static int InitWatchdogDevice(struct WatchdogDevice *watchdogDevice)
+{
+ struct WatchdogResource *resource = NULL;
+ if (watchdogDevice == NULL) {
+ HDF_LOGE("%s: invaild parameter\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ resource = &watchdogDevice->resource;
+ if (resource == NULL) {
+ HDF_LOGE("resource is NULL\r\n");
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static uint32_t GetWatchdogDeviceResource(
+ struct WatchdogDevice *device, const struct DeviceResourceNode *resourceNode)
+{
+ struct WatchdogResource *resource = NULL;
+ struct DeviceResourceIface *dri = NULL;
+ if (device == NULL || resourceNode == NULL) {
+ HDF_LOGE("resource or device is NULL\r\n");
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ resource = &device->resource;
+ if (resource == NULL) {
+ HDF_LOGE("resource is NULL\r\n");
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ if (dri == NULL || dri->GetUint32 == NULL) {
+ HDF_LOGE("DeviceResourceIface is invalid\r\n");
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t AttachWatchdogDevice(struct WatchdogCntlr *watchdogCntlr, struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct WatchdogDevice *watchdogDevice = NULL;
+
+ if (device == NULL || device->property == NULL) {
+ HDF_LOGE("%s: param is NULL\r\n", __func__);
+ return HDF_FAILURE;
+ }
+
+ watchdogDevice = (struct WatchdogDevice *)OsalMemAlloc(sizeof(struct WatchdogDevice));
+ if (watchdogDevice == NULL) {
+ HDF_LOGE("%s: OsalMemAlloc watchdogDevice error\r\n", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ ret = GetWatchdogDeviceResource(watchdogDevice, device->property);
+ if (ret != HDF_SUCCESS) {
+ (void)OsalMemFree(watchdogDevice);
+ return HDF_FAILURE;
+ }
+
+ watchdogCntlr->priv = watchdogDevice;
+
+ return InitWatchdogDevice(watchdogDevice);
+}
+
+/* HdfDriverEntry method definitions */
+static int32_t WatchdogDriverBind(struct HdfDeviceObject *device);
+static int32_t WatchdogDriverInit(struct HdfDeviceObject *device);
+static void WatchdogDriverRelease(struct HdfDeviceObject *device);
+
+static int32_t WatchdogDriverBind(struct HdfDeviceObject *device)
+{
+ struct WatchdogCntlr *watchdogCntlr = NULL;
+
+ if (device == NULL) {
+ HDF_LOGE("hdfDevice object is null!\r\n");
+ return HDF_FAILURE;
+ }
+
+ watchdogCntlr = (struct WatchdogCntlr *)OsalMemAlloc(sizeof(struct WatchdogCntlr));
+ if (watchdogCntlr == NULL) {
+ HDF_LOGE("%s: OsalMemAlloc watchdogCntlr error\r\n", __func__);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ HDF_LOGI("Enter %s\r\n", __func__);
+ device->service = &watchdogCntlr->service;
+ watchdogCntlr->device = device;
+ watchdogCntlr->priv = NULL;
+ return HDF_SUCCESS;
+}
+
+static int32_t WatchdogDriverInit(struct HdfDeviceObject *device)
+{
+ int32_t ret;
+ struct WatchdogCntlr *watchdogCntlr = NULL;
+
+ if (device == NULL) {
+ HDF_LOGE("%s: device is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ HDF_LOGI("Enter %s:\r\n", __func__);
+
+ watchdogCntlr = WatchdogCntlrFromDevice(device);
+ if (watchdogCntlr == NULL) {
+ HDF_LOGE("%s: watchdogCntlr is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ ret = AttachWatchdogDevice(watchdogCntlr, device);
+ if (ret != HDF_SUCCESS) {
+ OsalMemFree(watchdogCntlr);
+ HDF_LOGE("%s:attach error\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ watchdogCntlr->ops = &g_WatchdogCntlrMethod;
+
+ HDF_LOGE("WatchdogDriverInit success!\r\n");
+ return ret;
+}
+
+static void WatchdogDriverRelease(struct HdfDeviceObject *device)
+{
+ struct WatchdogCntlr *watchdogCntlr = NULL;
+ struct WatchdogDevice *watchdogDevice = NULL;
+
+ if (device == NULL) {
+ HDF_LOGE("device is null\r\n");
+ return;
+ }
+
+ watchdogCntlr = WatchdogCntlrFromDevice(device);
+ if (watchdogCntlr == NULL || watchdogCntlr->priv == NULL) {
+ HDF_LOGE("%s: watchdogCntlr is NULL\r\n", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ watchdogDevice = (struct WatchdogDevice *)watchdogCntlr->priv;
+ if (watchdogDevice != NULL) {
+ OsalMemFree(watchdogDevice);
+ }
+ return;
+}
+
+/* HdfDriverEntry definitions */
+struct HdfDriverEntry g_watchdogDriverEntry = {
+ .moduleVersion = 1,
+ .moduleName = "WM_WATCHDOG_MODULE_HDF",
+ .Bind = WatchdogDriverBind,
+ .Init = WatchdogDriverInit,
+ .Release = WatchdogDriverRelease,
+};
+
+// Initialize HdfDriverEntry
+HDF_INIT(g_watchdogDriverEntry);
diff --git a/uhdf/README.md b/uhdf/README.md
index 7b5c9720e558ee72ea1c5583066013299bead893..3187078a4e6958c90260345140468ab0d1663ba2 100644
--- a/uhdf/README.md
+++ b/uhdf/README.md
@@ -24,9 +24,9 @@ This repository stores the code and compilation scripts for the OpenHarmony driv
[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README.md)
-drivers\_adapter\_uhdf
+[drivers\_adapter\_uhdf](https://gitee.com/openharmony/drivers_adapter/blob/master/uhdf/README_zh.md)
[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README.md)
-[drivers\_adapter\_khdf\_liteos](https://gitee.com/openharmony/drivers_adapter_khdf_liteos/blob/master/README.md)
+[drivers\_adapter\_khdf\_liteos](https://gitee.com/openharmony/drivers_adapter/blob/master/khdf/liteos/README.md)
diff --git a/uhdf/README_zh.md b/uhdf/README_zh.md
index 8e9d52f36e1ef29a97d54ac3e5f290416ede9cc6..3ea6ec1b771ec0fe8cdce0e6dc7b08ba121d8e80 100644
--- a/uhdf/README_zh.md
+++ b/uhdf/README_zh.md
@@ -24,9 +24,9 @@
[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README_zh.md)
-drivers\_adapter\_uhdf
+[drivers\_adapter\_uhdf](https://gitee.com/openharmony/drivers_adapter/blob/master/uhdf/README_zh.md)
[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README_zh.md)
-[drivers\_adapter\_khdf\_liteos](https://gitee.com/openharmony/drivers_adapter_khdf_liteos/blob/master/README_zh.md)
+[drivers\_adapter\_khdf\_liteos](https://gitee.com/openharmony/drivers_adapter/blob/master/khdf/liteos/README_zh.md)
diff --git a/uhdf/platform/BUILD.gn b/uhdf/platform/BUILD.gn
old mode 100755
new mode 100644
index bf7558220752e9bbee7704091bd6785d8997ce75..23ccc94f999d5c915b00788d721d97528620268d
--- a/uhdf/platform/BUILD.gn
+++ b/uhdf/platform/BUILD.gn
@@ -52,6 +52,7 @@ ohos_shared_library("hdf_platform") {
"$HDF_FRAMEWORKS/model/storage/src/mmc/mmc_if.c",
"$HDF_FRAMEWORKS/support/platform/src/adc/adc_if_u.c",
"$HDF_FRAMEWORKS/support/platform/src/dac/dac_if_u.c",
+ "$HDF_FRAMEWORKS/support/platform/src/fwk/platform_listener_u.c",
"$HDF_FRAMEWORKS/support/platform/src/gpio/gpio_if_u.c",
"$HDF_FRAMEWORKS/support/platform/src/hdmi/hdmi_if.c",
"$HDF_FRAMEWORKS/support/platform/src/i2c/i2c_if_u.c",
diff --git a/uhdf/posix/BUILD.gn b/uhdf/posix/BUILD.gn
old mode 100755
new mode 100644
diff --git a/uhdf/test/unittest/platform/BUILD.gn b/uhdf/test/unittest/platform/BUILD.gn
index 487859f9d216aa236cb68eb5eb680966ee293270..c71e01127cb380c09296b2edf8be06efb3f2e687 100644
--- a/uhdf/test/unittest/platform/BUILD.gn
+++ b/uhdf/test/unittest/platform/BUILD.gn
@@ -1,4 +1,4 @@
-# Copyright (c) 2021 Huawei Device Co., Ltd.
+# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@@ -35,28 +35,31 @@ if (board_name == "hi3516dv300" || board_name == "hispark_taurus") {
if (ohos_kernel_type == "liteos_a") {
defines += [ "HDF_LITEOS_TEST" ]
}
+ if (ohos_kernel_type == "linux") {
+ defines += [ "_LINUX_USER_" ]
+ }
sources = [
+ "//drivers/framework/support/platform/test/unittest/common/hdf_adc_test.cpp",
+ "//drivers/framework/support/platform/test/unittest/common/hdf_can_test.cpp",
"//drivers/framework/support/platform/test/unittest/common/hdf_gpio_test.cpp",
"//drivers/framework/support/platform/test/unittest/common/hdf_platform_device_test.cpp",
+ "//drivers/framework/support/platform/test/unittest/common/hdf_platform_dumper_test.cpp",
"//drivers/framework/support/platform/test/unittest/common/hdf_platform_event_test.cpp",
"//drivers/framework/support/platform/test/unittest/common/hdf_platform_manager_test.cpp",
"//drivers/framework/support/platform/test/unittest/common/hdf_platform_queue_test.cpp",
+ "//drivers/framework/support/platform/test/unittest/common/hdf_platform_trace_test.cpp",
"//drivers/framework/support/platform/test/unittest/common/hdf_pwm_test.cpp",
"//drivers/framework/support/platform/test/unittest/common/hdf_regulator_test.cpp",
"//drivers/framework/support/platform/test/unittest/common/hdf_rtc_test.cpp",
"//drivers/framework/support/platform/test/unittest/common/hdf_spi_test.cpp",
- "//drivers/framework/support/platform/test/unittest/common/hdf_uart_test.cpp",
- "//drivers/framework/support/platform/test/unittest/common/hdf_watchdog_test.cpp",
+ "//drivers/framework/test/unittest/platform/common/adc_test.c",
"//drivers/framework/test/unittest/platform/common/gpio_test.c",
"//drivers/framework/test/unittest/platform/common/pwm_test.c",
"//drivers/framework/test/unittest/platform/common/rtc_test.c",
"//drivers/framework/test/unittest/platform/common/spi_test.c",
- "//drivers/framework/test/unittest/platform/common/uart_test.c",
- "//drivers/framework/test/unittest/platform/common/watchdog_test.c",
]
if (ohos_kernel_type == "liteos_a") {
sources += [
- "//drivers/framework/support/platform/test/unittest/common/hdf_adc_test.cpp",
"//drivers/framework/support/platform/test/unittest/common/hdf_dac_test.cpp",
"//drivers/framework/support/platform/test/unittest/common/hdf_i2s_test.cpp",
"//drivers/framework/support/platform/test/unittest/common/hdf_i3c_test.cpp",
@@ -64,9 +67,12 @@ if (board_name == "hi3516dv300" || board_name == "hispark_taurus") {
"//drivers/framework/support/platform/test/unittest/common/hdf_pcie_test.cpp",
"//drivers/framework/support/platform/test/unittest/common/hdf_pin_test.cpp",
"//drivers/framework/support/platform/test/unittest/common/hdf_timer_test.cpp",
- "//drivers/framework/test/unittest/platform/common/adc_test.c",
+ "//drivers/framework/support/platform/test/unittest/common/hdf_uart_test.cpp",
+ "//drivers/framework/support/platform/test/unittest/common/hdf_watchdog_test.cpp",
"//drivers/framework/test/unittest/platform/common/dac_test.c",
"//drivers/framework/test/unittest/platform/common/timer_test.c",
+ "//drivers/framework/test/unittest/platform/common/uart_test.c",
+ "//drivers/framework/test/unittest/platform/common/watchdog_test.c",
]
}
if (storage_type == "emmc") {
@@ -114,6 +120,7 @@ if (board_name == "hi3516dv300" || board_name == "hispark_taurus") {
defines = [ "__USER__" ]
sources = [
"//drivers/framework/support/platform/test/unittest/common/hdf_platform_device_test.cpp",
+ "//drivers/framework/support/platform/test/unittest/common/hdf_platform_dumper_test.cpp",
"//drivers/framework/support/platform/test/unittest/common/hdf_platform_event_test.cpp",
"//drivers/framework/support/platform/test/unittest/common/hdf_platform_manager_test.cpp",
"//drivers/framework/support/platform/test/unittest/common/hdf_platform_queue_test.cpp",
diff --git a/uhdf2/README.md b/uhdf2/README.md
index c8efe7f483dff0ddaf8115d947a69407fc20f466..ce6dca91df297be5aad3969097177582960882cf 100644
--- a/uhdf2/README.md
+++ b/uhdf2/README.md
@@ -29,7 +29,7 @@ This repository stores the code and compilation scripts for the user-mode Hardwa
[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README.md)
-drivers\_adapter
+[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README.md)
[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README.md)
diff --git a/uhdf2/README_zh.md b/uhdf2/README_zh.md
index 67a3d90763ec9d1e8cfc32e3a9544eafc19aceb5..fff6ba756573cfb5bf351a74a877cc00611c01e3 100644
--- a/uhdf2/README_zh.md
+++ b/uhdf2/README_zh.md
@@ -29,7 +29,7 @@
[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README_zh.md)
-drivers\_adapter
+[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README_zh.md)
[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README_zh.md)
diff --git a/uhdf2/hcs/BUILD.gn b/uhdf2/hcs/BUILD.gn
index 077f2c998088a093d4697cdff6e503672a42843e..ff65e837c1422c03da3d25a0085f5987a88f579b 100644
--- a/uhdf2/hcs/BUILD.gn
+++ b/uhdf2/hcs/BUILD.gn
@@ -16,18 +16,7 @@ import("//drivers/adapter/uhdf2/uhdf.gni")
import("$hdf_framework_path/tools/hc-gen/hc_gen.gni")
hc_gen("build_hcs") {
- gadget = "acm"
- if (product_name == "Hi3516DV300" || product_name == "watchos") {
- gadget = "ecm_acm"
- }
hcs_source = "/hdf.hcs"
- if (gadget == "acm") {
- hcs_source = "/hdf.hcs"
- } else if (gadget == "ecm") {
- hcs_source = "/hdf_ecm.hcs"
- } else if (gadget == "ecm_acm") {
- hcs_source = "/hdf_ecm_acm.hcs"
- }
if (product_company == "openharmony") {
hcs_config_path = "default"
@@ -47,3 +36,25 @@ ohos_prebuilt_etc("hdf_default.hcb") {
subsystem_name = "hdf"
part_name = "device_driver_framework"
}
+
+hc_gen_start_cfg("gen_start_cfg") {
+ hcs_source = "/hdf.hcs"
+
+ if (product_company == "openharmony") {
+ hcs_config_path = "default"
+ } else {
+ hcs_config_path = "//vendor/$product_company/$product_name/hdf_config/uhdf/"
+ }
+ sources = [ rebase_path(hcs_config_path + hcs_source) ]
+ outputs = [ "$target_gen_dir/hdf_devhost.cfg" ]
+}
+
+ohos_prebuilt_etc("hdf_devhost.cfg") {
+ deps = [ ":gen_start_cfg" ]
+ outputs = get_target_outputs(":gen_start_cfg")
+ source = outputs[0]
+ relative_install_dir = "init"
+ install_images = [ chipset_base_dir ]
+ subsystem_name = "hdf"
+ part_name = "device_driver_framework"
+}
diff --git a/uhdf2/hcs/camera/hal/mpp/hispark_taurus/driver/mpp_config.hcs b/uhdf2/hcs/camera/hal/mpp/hispark_taurus/driver/mpp_config.hcs
old mode 100755
new mode 100644
diff --git a/uhdf2/hcs/camera/hal/mpp/hispark_taurus/hdi_impl/camera_host_config.hcs b/uhdf2/hcs/camera/hal/mpp/hispark_taurus/hdi_impl/camera_host_config.hcs
old mode 100755
new mode 100644
diff --git a/uhdf2/hcs/camera/hal/mpp/hispark_taurus/hdi_impl/stream_supported_config.hcs b/uhdf2/hcs/camera/hal/mpp/hispark_taurus/hdi_impl/stream_supported_config.hcs
old mode 100755
new mode 100644
diff --git a/uhdf2/hcs/camera/hal/mpp/hispark_taurus/pipeline_core/config.hcs b/uhdf2/hcs/camera/hal/mpp/hispark_taurus/pipeline_core/config.hcs
old mode 100755
new mode 100644
diff --git a/uhdf2/hcs/camera/hal/mpp/hispark_taurus/pipeline_core/ipp_algo_config.hcs b/uhdf2/hcs/camera/hal/mpp/hispark_taurus/pipeline_core/ipp_algo_config.hcs
old mode 100755
new mode 100644
diff --git a/uhdf2/hcs/camera/hal/mpp/hispark_taurus/pipeline_core/params.hcs b/uhdf2/hcs/camera/hal/mpp/hispark_taurus/pipeline_core/params.hcs
old mode 100755
new mode 100644
diff --git a/uhdf2/hcs/camera/hal/v4l2/rpi4b/hdi_impl/camera_host_config.hcs b/uhdf2/hcs/camera/hal/v4l2/rpi4b/hdi_impl/camera_host_config.hcs
old mode 100755
new mode 100644
diff --git a/uhdf2/hcs/camera/hal/v4l2/rpi4b/hdi_impl/stream_supported_config.hcs b/uhdf2/hcs/camera/hal/v4l2/rpi4b/hdi_impl/stream_supported_config.hcs
old mode 100755
new mode 100644
diff --git a/uhdf2/hcs/camera/hal/v4l2/rpi4b/pipeline_core/config.hcs b/uhdf2/hcs/camera/hal/v4l2/rpi4b/pipeline_core/config.hcs
old mode 100755
new mode 100644
diff --git a/uhdf2/hcs/camera/hal/v4l2/rpi4b/pipeline_core/ipp_algo_config.hcs b/uhdf2/hcs/camera/hal/v4l2/rpi4b/pipeline_core/ipp_algo_config.hcs
old mode 100755
new mode 100644
diff --git a/uhdf2/hcs/camera/hal/v4l2/rpi4b/pipeline_core/params.hcs b/uhdf2/hcs/camera/hal/v4l2/rpi4b/pipeline_core/params.hcs
old mode 100755
new mode 100644
diff --git a/uhdf2/hcs/default/device_info.hcs b/uhdf2/hcs/default/device_info.hcs
old mode 100755
new mode 100644
diff --git a/uhdf2/hcs/default/hdf.hcs b/uhdf2/hcs/default/hdf.hcs
old mode 100755
new mode 100644
diff --git a/uhdf2/hdi.gni b/uhdf2/hdi.gni
old mode 100755
new mode 100644
index d664368b15f90ba5d49862fe8f28b961321c73fb..13132badfe295db996ebfc00ec938d1c5f380968
--- a/uhdf2/hdi.gni
+++ b/uhdf2/hdi.gni
@@ -22,12 +22,20 @@ template("hdi") {
assert(defined(invoker.subsystem_name), "subsystem_name are must")
assert(defined(invoker.part_name), "part_name are must")
- root_package_mapping = "ohos.hdi:drivers/interface"
+ root_package = "ohos.hdi"
+ root_path = rebase_path("//drivers/interface")
+ if (defined(invoker.root)) {
+ package_path_map = string_split(invoker.root, ":")
+ root_package = package_path_map[0]
+ root_path = rebase_path(package_path_map[1])
+ }
+ root_package_path = "${root_package}:${root_path}"
+
get_info_args = [
"-i",
invoker.language,
rebase_path(target_gen_dir),
- root_package_mapping,
+ root_package_path,
]
get_info_args += rebase_path(invoker.sources)
files_info = exec_script("$hdf_fwk_path/tools/hdi-gen/build_hdi_files.py",
@@ -50,9 +58,7 @@ template("hdi") {
config("hdi_public_config") {
include_dirs = [
- "$hdf_uhdf_path/include/hdi",
"$hdf_uhdf_path/include/host",
- "$hdf_uhdf_path/ipc/include",
"${files_info.root_package_dir}",
"${files_info.version_dir}",
]
@@ -100,7 +106,7 @@ template("hdi") {
}
args += [
"-r",
- root_package_mapping,
+ root_package_path,
]
}
@@ -121,13 +127,18 @@ template("hdi") {
public_configs = [ ":hdi_public_config" ]
- deps = [
+ deps = [ "$hdi_gen" ]
+
+ public_deps = [
"$hdf_uhdf_path/hdi:libhdi",
- "$hdi_gen",
"//drivers/adapter/uhdf2/ipc:libhdf_ipc_adapter",
"//drivers/adapter/uhdf2/utils:libhdf_utils",
]
+ if (defined(invoker.sequenceable)) {
+ public_deps += invoker.sequenceable
+ }
+
if (is_standard_system) {
external_deps = [
"hiviewdfx_hilog_native:libhilog",
@@ -143,7 +154,7 @@ template("hdi") {
install_images = [ system_base_dir ]
subsystem_name = invoker.subsystem_name
- part_name = invoker.part_name
+ part_name = invoker.part_name + "_interface"
}
}
@@ -164,13 +175,18 @@ template("hdi") {
public_configs = [ ":hdi_public_config" ]
- deps = [
+ deps = [ "$hdi_gen" ]
+
+ public_deps = [
"$hdf_uhdf_path/hdi:libhdi",
- "$hdi_gen",
"//drivers/adapter/uhdf2/ipc:libhdf_ipc_adapter",
"//drivers/adapter/uhdf2/utils:libhdf_utils",
]
+ if (defined(invoker.sequenceable)) {
+ public_deps += invoker.sequenceable
+ }
+
if (is_standard_system) {
external_deps = [
"hiviewdfx_hilog_native:libhilog",
@@ -180,7 +196,9 @@ template("hdi") {
external_deps = [ "hilog:libhilog" ]
}
- if (invoker.language == "cpp") {
+ if (invoker.language == "c") {
+ deps += [ "$hdf_uhdf_path/host:libhdf_host" ]
+ } else if (invoker.language == "cpp") {
external_deps += [ "ipc:ipc_single" ]
}
diff --git a/uhdf2/hdi/BUILD.gn b/uhdf2/hdi/BUILD.gn
index c089d80ff549234763a4b14f8c25b3953c57daa3..1fba60251360eb4d57e6de4cfb5b2d32ae67f364 100644
--- a/uhdf2/hdi/BUILD.gn
+++ b/uhdf2/hdi/BUILD.gn
@@ -57,13 +57,15 @@ if (defined(ohos_lite)) {
sources = [
"$hdf_framework_path/core/shared/src/service_status.c",
"src/devmgr_client.c",
- "src/hdf_load_hdi.c",
"src/hdi_smq_syncer.cpp",
+ "src/hdi_support.cpp",
"src/idevmgr_client.cpp",
"src/iservmgr_client.cpp",
+ "src/object_collector.cpp",
"src/servmgr_client.c",
"src/servstat_listener.c",
"src/servstat_listener_stub.cpp",
+ "src/stub_collector.cpp",
]
deps = [
diff --git a/uhdf2/hdi/src/devmgr_client.c b/uhdf2/hdi/src/devmgr_client.c
index d505a114d3ff0316ef16008eeabbfcb145076fd2..319fefce17fb9d14e7aa6be57beb9ea124ad389c 100644
--- a/uhdf2/hdi/src/devmgr_client.c
+++ b/uhdf2/hdi/src/devmgr_client.c
@@ -94,23 +94,26 @@ static int32_t DevmgrQueryDeviceInfo(struct HDIDeviceManager *iDevMgr, struct De
HdfSbufRecycle(reply);
return HDF_ERR_MALLOC_FAIL;
}
+ do {
+ if (!HdfRemoteServiceWriteInterfaceToken(iDevMgr->remote, data)) {
+ ret = HDF_FAILURE;
+ break;
+ }
+ list->deviceCnt = 0;
+ DListHeadInit(&list->list);
- list->deviceCnt = 0;
- DListHeadInit(&list->list);
-
- HdfSbufWriteInt32(data, type);
- ret = DeviceManagerHdiCall(iDevMgr, DEVMGR_SERVICE_QUERY_DEVICE, data, reply);
- if (ret != HDF_SUCCESS) {
- HDF_LOGE("DevmgrProxyQueryDevice failed");
- goto FINISHED;
- }
+ HdfSbufWriteInt32(data, type);
+ ret = DeviceManagerHdiCall(iDevMgr, DEVMGR_SERVICE_QUERY_DEVICE, data, reply);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("DevmgrProxyQueryDevice failed");
+ break;
+ }
- ret = HdfObtainDeviceInfo(list, reply);
+ ret = HdfObtainDeviceInfo(list, reply);
+ } while (0);
-FINISHED:
HdfSbufRecycle(reply);
HdfSbufRecycle(data);
-
return ret;
}
@@ -165,7 +168,10 @@ int32_t DevmgrLoadDevice(struct HDIDeviceManager *iDevMgr, const char *serviceNa
status = HDF_ERR_MALLOC_FAIL;
break;
}
-
+ if (!HdfRemoteServiceWriteInterfaceToken(iDevMgr->remote, data)) {
+ status = HDF_FAILURE;
+ break;
+ }
if (!HdfSbufWriteString(data, serviceName)) {
HDF_LOGE("%{public}s: writing service name failed!", __func__);
break;
@@ -194,7 +200,10 @@ int32_t DevmgrUnloadDevice(struct HDIDeviceManager *iDevMgr, const char *service
status = HDF_ERR_MALLOC_FAIL;
break;
}
-
+ if (!HdfRemoteServiceWriteInterfaceToken(iDevMgr->remote, data)) {
+ status = HDF_FAILURE;
+ break;
+ }
if (!HdfSbufWriteString(data, serviceName)) {
HDF_LOGE("%{public}s: writing service name failed!", __func__);
break;
@@ -237,7 +246,11 @@ struct HDIDeviceManager *HDIDeviceManagerGet(void)
HdfRemoteServiceRecycle(remote);
return NULL;
}
-
+ if (!HdfRemoteServiceSetInterfaceDesc(remote, "HDI.IDeviceManager.V1_0")) {
+ HDF_LOGE("%{public}s: failed to init interface desc", __func__);
+ HdfRemoteServiceRecycle(remote);
+ return NULL;
+ }
iDevMgr->remote = remote;
HDIDeviceManagerConstruct(iDevMgr);
return iDevMgr;
diff --git a/uhdf2/hdi/src/hdi_support.cpp b/uhdf2/hdi/src/hdi_support.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..df99214ad7ea4da8c4125a7ec20ae0f88f99ffee
--- /dev/null
+++ b/uhdf2/hdi/src/hdi_support.cpp
@@ -0,0 +1,195 @@
+/*
+ * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "hdi_support.h"
+#include
+#include