mirror of
https://github.com/openharmony/drivers_adapter.git
synced 2026-07-01 03:23:20 -04:00
add new driver adapter
This commit is contained in:
@@ -0,0 +1 @@
|
||||
khdf/linux
|
||||
Executable
+141
@@ -0,0 +1,141 @@
|
||||
# Copyright (c) 2020-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.
|
||||
|
||||
config DRIVERS_HDF
|
||||
bool "Enable HDF manager"
|
||||
default n
|
||||
depends on DRIVERS
|
||||
help
|
||||
Answer Y to enable LiteOS support HDF.
|
||||
|
||||
config DRIVERS_HDF_PLATFORM
|
||||
bool "Enable HDF platform driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF
|
||||
help
|
||||
Answer Y to enable HDF platform driver.
|
||||
|
||||
config DRIVERS_HDF_PLATFORM_GPIO
|
||||
bool "Enable HDF platform gpio driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF_PLATFORM
|
||||
help
|
||||
Answer Y to enable HDF platform gpio driver.
|
||||
|
||||
config DRIVERS_HDF_PLATFORM_I2C
|
||||
bool "Enable HDF platform i2c driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF_PLATFORM
|
||||
help
|
||||
Answer Y to enable HDF platform i2c driver.
|
||||
|
||||
config DRIVERS_HDF_PLATFORM_EMMC
|
||||
bool "Enable HDF platform emmc driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF_PLATFORM
|
||||
help
|
||||
Answer Y to enable HDF platform emmc driver.
|
||||
|
||||
config DRIVERS_HDF_PLATFORM_PWM
|
||||
bool "Enable HDF platform pwm driver"
|
||||
depends on DRIVERS_HDF_PLATFORM
|
||||
help
|
||||
Answer Y to enable HDF platform pwm driver.
|
||||
|
||||
config DRIVERS_HDF_PLATFORM_RTC
|
||||
bool "Enable HDF platform rtc driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF_PLATFORM
|
||||
help
|
||||
Answer Y to enable HDF platform rtc driver.
|
||||
|
||||
config DRIVERS_HDF_PLATFORM_SDIO
|
||||
bool "Enable HDF platform sdio driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF_PLATFORM
|
||||
help
|
||||
Answer Y to enable HDF platform sdio driver.
|
||||
|
||||
config DRIVERS_HDF_PLATFORM_DMAC
|
||||
bool "Enable HDF platform dmac driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF_PLATFORM
|
||||
help
|
||||
Answer Y to enable HDF platform dmac driver.
|
||||
|
||||
config DRIVERS_HDF_PLATFORM_MIPI_DSI
|
||||
bool "Enable HDF platform mipi dsi driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF_PLATFORM
|
||||
help
|
||||
Answer Y to enable HDF platform mipi dsi driver.
|
||||
|
||||
config DRIVERS_HIEDMAC
|
||||
bool "Enable HIEDMAC"
|
||||
default n
|
||||
depends on DRIVERS && PLATFORM_HI3559AV100
|
||||
help
|
||||
Answer Y to enable LiteOS support hiedmac.
|
||||
|
||||
|
||||
config DRIVERS_HDF_PLATFORM_HISI_SDK
|
||||
bool "Enable HDF hisi sdk driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF_PLATFORM
|
||||
help
|
||||
Answer Y to enable HDF hisi sdk driver.
|
||||
|
||||
config DRIVERS_HDF_PLATFORM_SPI
|
||||
bool "Enable HDF platform spi driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF_PLATFORM
|
||||
help
|
||||
Answer Y to enable HDF platform spi driver.
|
||||
|
||||
config DRIVERS_HDF_PLATFORM_WATCHDOG
|
||||
bool "Enable HDF platform watchdog driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF_PLATFORM
|
||||
help
|
||||
Answer Y to enable HDF platform watchdog driver.
|
||||
|
||||
config DRIVERS_HDF_WIFI
|
||||
bool "Enable HDF WiFi Host driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF && NET_LWIP_SACK
|
||||
help
|
||||
Answer Y to enable HDF WiFi Host driver.
|
||||
|
||||
source "../../drivers/adapter/khdf/liteos/model/bus/usb/Kconfig"
|
||||
source "../../drivers/adapter/khdf/liteos/test/Kconfig"
|
||||
source "../../drivers/adapter/khdf/liteos/model/display/Kconfig"
|
||||
source "../../drivers/adapter/khdf/liteos/model/input/Kconfig"
|
||||
source "../../drivers/adapter/khdf/liteos/model/sensor/Kconfig"
|
||||
|
||||
# hisilicon Kconfig import
|
||||
source "../../device/hisilicon/drivers/Kconfig"
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
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.
|
||||
@@ -0,0 +1,154 @@
|
||||
# Copyright (c) 2020-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.
|
||||
|
||||
include $(LITEOSTOPDIR)/config.mk
|
||||
include ./lite.mk
|
||||
|
||||
MODULE_NAME := hdf
|
||||
|
||||
HDF_FRAMEWORKS = ../../../framework
|
||||
|
||||
LOCAL_SRCS := ./osal/src/osal_timer.c \
|
||||
./osal/src/osal_time.c \
|
||||
./osal/src/osal_thread.c \
|
||||
./osal/src/osal_spinlock.c \
|
||||
./osal/src/osal_irq.c \
|
||||
./osal/src/osal_firmware.c \
|
||||
./osal/src/osal_file.c \
|
||||
./osal/src/osal_workqueue.c \
|
||||
./osal/src/osal_cdev.c \
|
||||
$(HDF_FRAMEWORKS)/utils/src/hdf_cstring.c \
|
||||
$(HDF_FRAMEWORKS)/utils/src/hdf_slist.c \
|
||||
$(HDF_FRAMEWORKS)/utils/src/hdf_sref.c \
|
||||
$(HDF_FRAMEWORKS)/ability/sbuf/src/hdf_sbuf.c \
|
||||
./osal/src/osal_mem.c \
|
||||
./osal/src/osal_mutex.c \
|
||||
./osal/src/osal_sem.c \
|
||||
$(HDF_FRAMEWORKS)/core/host/src/devhost_service.c \
|
||||
$(HDF_FRAMEWORKS)/core/host/src/devmgr_service_clnt.c \
|
||||
$(HDF_FRAMEWORKS)/core/host/src/devsvc_manager_clnt.c \
|
||||
$(HDF_FRAMEWORKS)/core/host/src/hdf_device.c \
|
||||
$(HDF_FRAMEWORKS)/core/host/src/hdf_device_node.c \
|
||||
$(HDF_FRAMEWORKS)/core/host/src/hdf_device_token.c \
|
||||
$(HDF_FRAMEWORKS)/core/host/src/hdf_driver_loader.c \
|
||||
$(HDF_FRAMEWORKS)/core/host/src/hdf_observer_record.c \
|
||||
$(HDF_FRAMEWORKS)/core/host/src/hdf_service_subscriber.c \
|
||||
$(HDF_FRAMEWORKS)/core/host/src/hdf_device_object.c \
|
||||
$(HDF_FRAMEWORKS)/core/host/src/hdf_service_observer.c \
|
||||
$(HDF_FRAMEWORKS)/core/host/src/power_state_token.c \
|
||||
$(HDF_FRAMEWORKS)/core/manager/src/devhost_service_clnt.c \
|
||||
$(HDF_FRAMEWORKS)/core/manager/src/device_token_clnt.c \
|
||||
$(HDF_FRAMEWORKS)/core/manager/src/devmgr_service.c \
|
||||
$(HDF_FRAMEWORKS)/core/manager/src/devsvc_manager.c \
|
||||
$(HDF_FRAMEWORKS)/core/manager/src/hdf_driver_installer.c \
|
||||
$(HDF_FRAMEWORKS)/core/manager/src/hdf_host_info.c \
|
||||
$(HDF_FRAMEWORKS)/core/manager/src/power_state_manager.c \
|
||||
$(HDF_FRAMEWORKS)/core/manager/src/power_state_token_clnt.c \
|
||||
$(HDF_FRAMEWORKS)/core/shared/src/hdf_service_record.c \
|
||||
$(HDF_FRAMEWORKS)/core/shared/src/hdf_device_info.c \
|
||||
$(HDF_FRAMEWORKS)/core/shared/src/hdf_object_manager.c \
|
||||
$(HDF_FRAMEWORKS)/core/shared/src/hdf_io_service.c \
|
||||
$(HDF_FRAMEWORKS)/core/adapter/vnode/src/hdf_vnode_adapter.c \
|
||||
$(HDF_FRAMEWORKS)/core/common/src/devlite_object_config.c \
|
||||
$(HDF_FRAMEWORKS)/core/common/src/hdf_attribute.c \
|
||||
$(HDF_FRAMEWORKS)/core/common/src/load_driver_entry.c \
|
||||
$(HDF_FRAMEWORKS)/core/common/src/devmgr_service_start.c \
|
||||
$(HDF_FRAMEWORKS)/core/common/src/hdf_device_node_ext.c \
|
||||
$(HDF_FRAMEWORKS)/ability/config/hcs_parser/src/hcs_blob_if.c \
|
||||
$(HDF_FRAMEWORKS)/ability/config/hcs_parser/src/hcs_parser.c \
|
||||
$(HDF_FRAMEWORKS)/ability/config/hcs_parser/src/hcs_generate_tree.c \
|
||||
$(HDF_FRAMEWORKS)/ability/config/hcs_parser/src/hcs_tree_if.c \
|
||||
$(HDF_FRAMEWORKS)/ability/config/device_resource_if.c
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM), y)
|
||||
LOCAL_SRCS += ./platform/plat_common.c
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_I2C), y)
|
||||
LOCAL_SRCS += $(HDF_FRAMEWORKS)/support/platform/src/i2c_if.c \
|
||||
$(HDF_FRAMEWORKS)/support/platform/src/i2c_core.c
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_GPIO), y)
|
||||
LOCAL_SRCS += $(HDF_FRAMEWORKS)/support/platform/src/gpio_if.c \
|
||||
$(HDF_FRAMEWORKS)/support/platform/src/gpio_core.c
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG), y)
|
||||
LOCAL_SRCS += $(HDF_FRAMEWORKS)/support/platform/src/watchdog_if.c \
|
||||
$(HDF_FRAMEWORKS)/support/platform/src/watchdog_core.c
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_SPI), y)
|
||||
LOCAL_SRCS += $(HDF_FRAMEWORKS)/support/platform/src/spi_if.c \
|
||||
$(HDF_FRAMEWORKS)/support/platform/src/spi_core.c
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_PWM), y)
|
||||
LOCAL_SRCS += $(HDF_FRAMEWORKS)/support/platform/src/pwm_core.c
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_SDIO), y)
|
||||
LOCAL_SRCS += $(HDF_FRAMEWORKS)/support/platform/src/sdio_if.c \
|
||||
$(HDF_FRAMEWORKS)/support/platform/src/sdio_core.c
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_EMMC), y)
|
||||
LOCAL_SRCS += $(HDF_FRAMEWORKS)/support/platform/src/emmc_if.c \
|
||||
$(HDF_FRAMEWORKS)/support/platform/src/emmc_core.c
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_RTC), y)
|
||||
LOCAL_SRCS += $(HDF_FRAMEWORKS)/support/platform/src/rtc_if.c \
|
||||
$(HDF_FRAMEWORKS)/support/platform/src/rtc_core.c \
|
||||
$(HDF_FRAMEWORKS)/support/platform/src/rtc_base.c
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI), y)
|
||||
LOCAL_SRCS += $(HDF_FRAMEWORKS)/support/platform/src/mipi_dsi_core.c
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_DMAC), y)
|
||||
LOCAL_SRCS += $(HDF_FRAMEWORKS)/support/platform/src/dmac_core.c
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_UART), y)
|
||||
LOCAL_SRCS += $(HDF_FRAMEWORKS)/support/platform/src/uart_if.c \
|
||||
$(HDF_FRAMEWORKS)/support/platform/src/uart_core.c
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_NET_LWIP_SACK), y)
|
||||
LOCAL_SRCS += ./network/src/netbuf_adapter.c
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_WIFI), y)
|
||||
LOCAL_SRCS += ./network/src/net_device_adapter.c
|
||||
endif
|
||||
endif
|
||||
|
||||
LOCAL_FLAGS += $(LITEOS_GCOV_OPTS)
|
||||
|
||||
include $(HDF_DRIVER)
|
||||
@@ -0,0 +1,38 @@
|
||||
# lite\_khdf<a name="EN-US_TOPIC_0000001078489610"></a>
|
||||
|
||||
- [Introduction](#section11660541593)
|
||||
- [Directory Structure](#section161941989596)
|
||||
- [Repositories Involved](#section1371113476307)
|
||||
|
||||
## Introduction<a name="section11660541593"></a>
|
||||
|
||||
This repository stores the code and compilation scripts for the OpenHarmony driver subsystem to adapt to the LiteOS kernel and to deploy the hardware driver foundation \(HDF\).
|
||||
|
||||
## Directory Structure<a name="section161941989596"></a>
|
||||
|
||||
```
|
||||
/drivers/adapter/khdf/liteos
|
||||
├── model # Code for adapting to the LiteOS
|
||||
│ ├── bus # Bus driver model
|
||||
│ ├── display # Display driver model
|
||||
│ ├── input # Input driver model
|
||||
│ ├── network # WLAN driver model
|
||||
│ ├── sensor # Sensor driver model
|
||||
├── ndk # Compilation scripts for adapting to the NDK
|
||||
├── network # Code for adapting to the LiteOS kernel network
|
||||
├── osal # System APIs for adapting to the LiteOS kernel
|
||||
├── test # Test code for the LiteOS kernel driver framework
|
||||
└── tools # Development tools for the LiteOS kernel
|
||||
```
|
||||
|
||||
## Repositories Involved<a name="section1371113476307"></a>
|
||||
|
||||
[Driver subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/driver-subsystem.md)
|
||||
|
||||
[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\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_uhdf/blob/master/README.md)
|
||||
|
||||
drivers\_adapter\_khdf\_liteos
|
||||
@@ -0,0 +1,38 @@
|
||||
# lite\_khdf<a name="ZH-CN_TOPIC_0000001078489610"></a>
|
||||
|
||||
- [简介](#section11660541593)
|
||||
- [目录](#section161941989596)
|
||||
- [相关仓](#section1371113476307)
|
||||
|
||||
## 简介<a name="section11660541593"></a>
|
||||
|
||||
该仓主要存放OpenHarmony驱动子系统适配liteos内核的代码和编译脚本,在liteos内核中部署OpenHarmony驱动框架。
|
||||
|
||||
## 目录<a name="section161941989596"></a>
|
||||
|
||||
```
|
||||
/drivers/adapter/khdf/liteos
|
||||
├── model #驱动模型适配liteos代码
|
||||
│ ├── bus #总线驱动模型
|
||||
│ ├── display #显示驱动模型
|
||||
│ ├── input #输入驱动模型
|
||||
│ ├── network #wifi驱动模型
|
||||
│ └── sensor #传感器驱动模型
|
||||
├── ndk #适配NDK的编译脚本
|
||||
├── network #适配liteos内核网络代码
|
||||
├── osal #适配liteos内核的系统接口
|
||||
├── test #liteos内核驱动框架测试代码
|
||||
└── tools #liteos内核驱动开发工具
|
||||
```
|
||||
|
||||
## 相关仓<a name="section1371113476307"></a>
|
||||
|
||||
[驱动子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E9%A9%B1%E5%8A%A8%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
|
||||
|
||||
[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\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README_zh.md)
|
||||
|
||||
drivers\_adapter\_khdf\_liteos
|
||||
Executable
+143
@@ -0,0 +1,143 @@
|
||||
# Copyright (c) 2020-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.
|
||||
|
||||
PWD := $(abspath $(shell pwd))
|
||||
UNAME := $(shell uname)
|
||||
ifneq ($(findstring $(UNAME),Linux),)
|
||||
HCGEN_PATH := linux-x86/bin/hc-gen
|
||||
else
|
||||
HCGEN_PATH := win-x86/bin/hc-gen.exe
|
||||
endif
|
||||
|
||||
HAVE_VENDOR_CONFIG := $(shell if [ -d $(LITEOS_SOURCE_ROOT)/vendor/$(patsubst "%",%,$(LOSCFG_DEVICE_COMPANY))/$(patsubst "%",%,$(LOSCFG_PRODUCT_NAME))/config ]; then echo y; else echo n; fi)
|
||||
|
||||
ifeq ($(LOCAL_HCS_ROOT),)
|
||||
ifeq ($(HAVE_VENDOR_CONFIG), y)
|
||||
LOCAL_HCS_ROOT := $(abspath $(LITEOSTOPDIR)/../../vendor/$(patsubst "%",%,$(LOSCFG_DEVICE_COMPANY))/$(patsubst "%",%,$(LOSCFG_PRODUCT_NAME))/config)
|
||||
else
|
||||
LOCAL_HCS_ROOT := $(abspath $(LITEOSTOPDIR)/../../device/$(patsubst "%",%,$(LOSCFG_DEVICE_COMPANY))/$(patsubst "%",%,$(LOSCFG_PRODUCT_NAME))/config)
|
||||
endif
|
||||
endif
|
||||
|
||||
HC_GEN := hc-gen
|
||||
BUILD_IN_HC_GEN := $(LITEOSTOPDIR)/../../prebuilts/build-tools/$(HCGEN_PATH)
|
||||
ifneq ($(wildcard $(BUILD_IN_HC_GEN)),)
|
||||
HC_GEN := $(BUILD_IN_HC_GEN)
|
||||
endif
|
||||
|
||||
SOURCE_ROOT := $(abspath $(LITEOSTOPDIR)/../../)
|
||||
HDF_CONFIG_DIR := $(LOCAL_HCS_ROOT)
|
||||
OBJOUT := $(BUILD)$(dir $(subst $(SOURCE_ROOT),,$(shell pwd)))$(MODULE_NAME)
|
||||
LOCAL_CFLAGS += $(LITEOS_GCOV_OPTS)
|
||||
LOCAL_CFLAGS += $(addprefix -I ,$(LOCAL_INCLUDE))
|
||||
|
||||
HCS_SRCS:= $(addprefix $(HDF_CONFIG_DIR)/,$(LOCAL_HCS_SRCS))
|
||||
CONFIG_OUT_DIR := $(OBJOUT)/config/
|
||||
CONFIG_GEN_SRCS := $(addsuffix .c,$(addprefix $(CONFIG_OUT_DIR),$(basename $(LOCAL_HCS_SRCS))))
|
||||
CONFIG_OUT_SUBDIRS := $(dir $(CONFIG_GEN_SRCS))
|
||||
DEPENDS_CONFIG_SRCS := $(addsuffix .c,$(addprefix $(CONFIG_OUT_DIR),$(basename $(LOCAL_DEPENDS_HCS_SRCS))))
|
||||
DEPENDS_CONFIG_OUT_SUBDIRS := $(dir $(DEPENDS_CONFIG_SRCS))
|
||||
LOCAL_INCLUDE += $(CONFIG_OUT_SUBDIRS) $(DEPENDS_CONFIG_OUT_SUBDIRS)
|
||||
|
||||
PLATFORM_HCS_SRC := $(wildcard $(LOCAL_PLATFORM_HCS_SRC))
|
||||
CONFIG_GEN_HEX_SRC := $(addsuffix _hex.c,$(addprefix $(CONFIG_OUT_DIR),$(basename $(PLATFORM_HCS_SRC))))
|
||||
|
||||
LOCAL_CFG_OBJS := $(patsubst %.c, %.o,$(CONFIG_GEN_SRCS))
|
||||
LOCAL_CFG_OBJS += $(patsubst %.c, %.o,$(CONFIG_GEN_HEX_SRC))
|
||||
|
||||
LOCAL_CSRCS := $(filter %.c,$(LOCAL_SRCS))
|
||||
LOCAL_CPPSRCS := $(filter %.cpp,$(LOCAL_SRCS))
|
||||
LOCAL_COBJS := $(patsubst %.c,$(OBJOUT)/%.o,$(LOCAL_CSRCS))
|
||||
LOCAL_CPPOBJS := $(patsubst %.cpp,$(OBJOUT)/%.o,$(LOCAL_CPPSRCS))
|
||||
LOCAL_OBJS := $(LOCAL_CFG_OBJS) $(LOCAL_COBJS) $(LOCAL_CPPOBJS)
|
||||
|
||||
HCB_FLAGS := -b -i -a
|
||||
|
||||
ifeq ($(LOCAL_SO), y)
|
||||
LIBSO := $(OUT)/lib/lib$(MODULE_NAME).so
|
||||
LIBA := $(OUT)/lib/lib$(MODULE_NAME).a
|
||||
else
|
||||
LIBSO :=
|
||||
LIBA := $(OUT)/lib/lib$(MODULE_NAME).a
|
||||
endif
|
||||
LIB := $(LIBA) $(LIBSO)
|
||||
|
||||
all: $(LIB)
|
||||
|
||||
$(CONFIG_GEN_HEX_SRC): $(CONFIG_OUT_DIR)%_hex.c: $(HDF_CONFIG_DIR)/%.hcs
|
||||
$(HIDE)echo gen hdf built-in config
|
||||
$(HIDE)if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi
|
||||
$(HIDE)$(HC_GEN) $(HCB_FLAGS) -o $(subst _hex.c,,$(@)) $<
|
||||
|
||||
$(CONFIG_GEN_SRCS): $(CONFIG_OUT_DIR)%.c: $(HDF_CONFIG_DIR)/%.hcs
|
||||
$(HIDE)echo gen hdf driver config
|
||||
$(HIDE)if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi
|
||||
$(HIDE)$(HC_GEN) -t -o $@ $<
|
||||
|
||||
$(DEPENDS_CONFIG_SRCS): $(CONFIG_OUT_DIR)%.c: $(HDF_CONFIG_DIR)/%.hcs
|
||||
$(HIDE)if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi
|
||||
$(HIDE)$(HC_GEN) -t -o $@ $<
|
||||
$(HIDE)rm $@
|
||||
|
||||
$(LOCAL_CFG_OBJS): %.o: %.c
|
||||
$(HIDE)$(CC) $(LITEOS_CFLAGS) $(LOCAL_FLAGS) $(LOCAL_CFLAGS) -c $< -o $@
|
||||
$(HIDE)rm $<
|
||||
|
||||
$(LOCAL_COBJS): $(OBJOUT)/%.o: %.c | $(LOCAL_CFG_OBJS) $(DEPENDS_CONFIG_SRCS)
|
||||
$(HIDE)$(OBJ_MKDIR)
|
||||
$(HIDE)$(CC) $(LITEOS_CFLAGS) $(LOCAL_FLAGS) $(LOCAL_CFLAGS) -c $< -o $@
|
||||
|
||||
$(LOCAL_CPPOBJS): $(OBJOUT)/%.o: %.cpp
|
||||
$(HIDE)$(OBJ_MKDIR)
|
||||
$(HIDE)$(GPP) $(LITEOS_CXXFLAGS) $(LOCAL_FLAGS) $(LOCAL_CPPFLAGS) -c $< -o $@
|
||||
|
||||
$(LIBA): $(LOCAL_OBJS)
|
||||
ifeq ($(OS), Linux)
|
||||
$(HIDE)$(AR) $(ARFLAGS) $@ $(LOCAL_OBJS)
|
||||
else
|
||||
ifeq ($(LOCAL_MODULES),)
|
||||
$(HIDE)$(AR) $(ARFLAGS) $@ $(LOCAL_OBJS)
|
||||
else
|
||||
$(HIDE)for i in $(LOCAL_MODULES); do \
|
||||
pushd $(OBJOUT)/$$i 1>/dev/null; \
|
||||
$(AR) $(ARFLAGS) $@ *.o;\
|
||||
popd 1>/dev/null;\
|
||||
done
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(LOCAL_SO), y)
|
||||
$(LIBSO): $(LOCAL_CFG_OBJS) $(LOCAL_ALL_OBJS)
|
||||
$(HIDE)$(CC) $(LITEOS_CFLAGS) -fPIC -shared $^ -o $@
|
||||
endif
|
||||
|
||||
clean:
|
||||
$(HIDE)$(RM) $(LIB) $(OBJOUT) $(LOCAL_GCH) *.bak *~
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
# Copyright (c) 2020-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.
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF), y)
|
||||
LITEOS_BASELIB += --whole-archive
|
||||
LITEOS_DRIVERS_HDF := $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos
|
||||
LITEOS_SOURCE_ROOT := $(LITEOSTOPDIR)/../..
|
||||
LIB_SUBDIRS += $(LITEOS_DRIVERS_HDF)
|
||||
HDF_FRAMEWORKS_PATH:= $(LITEOSTOPDIR)/../../drivers/framework
|
||||
LITEOS_BASELIB += -lhdf
|
||||
LITEOS_DRIVERS_HDF_INCLUDE += -I $(HDF_FRAMEWORKS_PATH)/core/common/include/manager
|
||||
LITEOS_DRIVERS_HDF_INCLUDE += -I $(HDF_FRAMEWORKS_PATH)/support/platform/include
|
||||
LITEOS_DRIVERS_HDF_INCLUDE += -I $(HDF_FRAMEWORKS_PATH)/include/platform
|
||||
LITEOS_DRIVERS_HDF_INCLUDE += -I $(HDF_FRAMEWORKS_PATH)/include/utils
|
||||
|
||||
# models
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_WIFI), y)
|
||||
LITEOS_BASELIB += -lhdf_wifi_model
|
||||
LIB_SUBDIRS += $(LITEOS_DRIVERS_HDF)/model/network/wifi
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_USB), y)
|
||||
LITEOS_DRIVERS_HDF_INCLUDE += -I $(LITEOS_DRIVERS_HDF)/model/bus/usb/include
|
||||
LITEOS_BASELIB += -lhdf_usb
|
||||
LIB_SUBDIRS += $(LITEOS_DRIVERS_HDF)/model/bus/usb
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_DISP), y)
|
||||
LITEOS_BASELIB += -lhdf_display
|
||||
LIB_SUBDIRS += $(LITEOS_DRIVERS_HDF)/model/display
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_INPUT), y)
|
||||
LITEOS_BASELIB += -lhdf_input_driver
|
||||
LIB_SUBDIRS += $(LITEOS_DRIVERS_HDF)/model/input
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_SENSOR), y)
|
||||
LITEOS_BASELIB += -lhdf_sensor_driver
|
||||
LIB_SUBDIRS += $(LITEOS_DRIVERS_HDF)/model/sensor
|
||||
endif
|
||||
|
||||
HAVE_VENDOR_CONFIG := $(shell if [ -d $(LITEOS_SOURCE_ROOT)/vendor/$(patsubst "%",%,$(LOSCFG_DEVICE_COMPANY))/$(patsubst "%",%,$(LOSCFG_PRODUCT_NAME))/config ]; then echo y; else echo n; fi)
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_TEST), y)
|
||||
include $(LITEOS_DRIVERS_HDF)/test/test_lite.mk
|
||||
# test
|
||||
LITEOS_BASELIB += -lhdf_test
|
||||
LIB_SUBDIRS += $(LITEOS_DRIVERS_HDF)/test
|
||||
|
||||
LITEOS_BASELIB += -lhdf_test_config
|
||||
LIB_SUBDIRS += $(LITEOS_SOURCE_ROOT)/vendor/$(LOSCFG_DEVICE_COMPANY)/$(LOSCFG_PRODUCT_NAME)/config/hdf_test
|
||||
else
|
||||
# config
|
||||
LITEOS_BASELIB += -lhdf_config
|
||||
ifeq ($(HAVE_VENDOR_CONFIG), y)
|
||||
LIB_SUBDIRS += $(LITEOS_SOURCE_ROOT)/vendor/$(LOSCFG_DEVICE_COMPANY)/$(LOSCFG_PRODUCT_NAME)/config
|
||||
else
|
||||
LIB_SUBDIRS += $(LITEOS_SOURCE_ROOT)/device/$(LOSCFG_DEVICE_COMPANY)/$(LOSCFG_PRODUCT_NAME)/config
|
||||
endif
|
||||
endif
|
||||
|
||||
# vendor lib
|
||||
COMPANY_OF_SOC := $(subst $\",,$(LOSCFG_DEVICE_COMPANY))
|
||||
include $(LITEOSTOPDIR)/../../device/$(COMPANY_OF_SOC)/drivers/lite.mk
|
||||
LITEOS_BASELIB += --no-whole-archive
|
||||
endif
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
# Copyright (c) 2020-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.
|
||||
|
||||
include $(LITEOSTOPDIR)/config.mk
|
||||
|
||||
HDF_ROOT_DIR = $(LITEOSTOPDIR)/../../drivers
|
||||
|
||||
HDF_CFLAGS := -fstack-protector-strong -fno-common -fsigned-char -fno-strict-aliasing -Wno-format -Wno-format-extra-args
|
||||
|
||||
HDF_INCLUDE += -I $(HDF_ROOT_DIR)/framework/include
|
||||
HDF_INCLUDE += -I $(HDF_ROOT_DIR)/framework/include/osal
|
||||
HDF_INCLUDE += -I $(HDF_ROOT_DIR)/framework/include/utils
|
||||
HDF_INCLUDE += -I $(HDF_ROOT_DIR)/framework/utils/include
|
||||
HDF_INCLUDE += -I $(HDF_ROOT_DIR)/framework/include/platform
|
||||
HDF_INCLUDE += -I $(HDF_ROOT_DIR)/framework/include/core
|
||||
HDF_INCLUDE += -I $(HDF_ROOT_DIR)/framework/include/net
|
||||
HDF_INCLUDE += -I $(HDF_ROOT_DIR)/framework/include/wifi
|
||||
HDF_INCLUDE += -I $(HDF_ROOT_DIR)/framework/model/network/common/netdevice
|
||||
HDF_INCLUDE += -I $(HDF_ROOT_DIR)/framework/ability/sbuf/include
|
||||
HDF_INCLUDE += -I $(HDF_ROOT_DIR)/framework/support/platform/include
|
||||
HDF_INCLUDE += -I $(HDF_ROOT_DIR)/framework/core/host/include
|
||||
HDF_INCLUDE += -I $(HDF_ROOT_DIR)/framework/core/manager/include
|
||||
HDF_INCLUDE += -I $(HDF_ROOT_DIR)/framework/core/shared/include
|
||||
HDF_INCLUDE += -I $(HDF_ROOT_DIR)/framework/core/common/include/manager
|
||||
HDF_INCLUDE += -I $(HDF_ROOT_DIR)/framework/core/common/include/host
|
||||
HDF_INCLUDE += -I $(HDF_ROOT_DIR)/adapter/khdf/liteos/network/include
|
||||
HDF_INCLUDE += -I $(HDF_ROOT_DIR)/adapter/khdf/liteos/osal/include
|
||||
HDF_INCLUDE += -I $(HDF_ROOT_DIR)/framework/core/adapter/vnode/include
|
||||
HDF_INCLUDE += -I $(HDF_ROOT_DIR)/framework/core/adapter/syscall/include
|
||||
HDF_INCLUDE += -I $(LITEOSTOPDIR)/bsd/compat/linuxkpi/include
|
||||
HDF_INCLUDE += -I $(HDF_ROOT_DIR)/framework/include/config
|
||||
HDF_INCLUDE += -I $(HDF_ROOT_DIR)/framework/ability/config/hcs_parser/include
|
||||
LOCAL_CFLAGS += $(HDF_INCLUDE)
|
||||
LOCAL_CFLAGS += $(HDF_CFLAGS)
|
||||
|
||||
HDF_DRIVER = $(HDF_ROOT_DIR)/adapter/khdf/liteos/hdf_driver.mk
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
# Copyright (c) 2020-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.
|
||||
|
||||
config DRIVERS_HDF_USB
|
||||
bool "Enable HDF Usb driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF
|
||||
help
|
||||
Answer Y to enable HDF Usb driver.
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) 2020-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.
|
||||
|
||||
include $(LITEOSTOPDIR)/config.mk
|
||||
include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk
|
||||
|
||||
MODULE_NAME := hdf_usb
|
||||
|
||||
LOCAL_SRCS += ./hdf_usb.c
|
||||
|
||||
LOCAL_INCLUDE := $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/model/bus/usb/include
|
||||
|
||||
LOCAL_CFLAGS += -fstack-protector-strong -Wextra -Wall -Werror -fsigned-char -fno-strict-aliasing -fno-common
|
||||
|
||||
include $(HDF_DRIVER)
|
||||
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#include "hdf_log.h"
|
||||
#include "device_resource_if.h"
|
||||
#include "hdf_usb.h"
|
||||
|
||||
#define USB_CONTROLLER_LIST_NAME "controller_list"
|
||||
#define USB_NODE_MATCH_ATTR "hisilicon,hi35xx-xhci"
|
||||
#define USB_MAX_CFG_LEN 8
|
||||
#define USB_CONTROL_NAME_LEN 32
|
||||
#define USB_CFG_UNIT 2
|
||||
|
||||
struct UsbConfig {
|
||||
uint32_t type;
|
||||
uint32_t unit;
|
||||
uint32_t start;
|
||||
uint32_t end;
|
||||
uint32_t count;
|
||||
};
|
||||
|
||||
struct UsbInfo {
|
||||
struct UsbConfig cfg[USB_MAX_CFG_LEN];
|
||||
uint32_t len;
|
||||
};
|
||||
|
||||
static const struct DeviceResourceNode *GetHdfUsbNode(const struct DeviceResourceIface *instance)
|
||||
{
|
||||
const struct DeviceResourceNode *root = instance->GetRootNode();
|
||||
|
||||
if (root == NULL) {
|
||||
HDF_LOGE("%s get root node is null\n", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return instance->GetNodeByMatchAttr(root, USB_NODE_MATCH_ATTR);
|
||||
}
|
||||
|
||||
static int GetUsbControllerParam(const struct DeviceResourceIface *instance, const struct DeviceResourceNode *node,
|
||||
struct UsbConfig *cfg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = instance->GetUint32(node, "res_type", &cfg->type, 0);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: read res_type fail", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
ret = instance->GetUint32(node, "res_unit", &cfg->unit, 0);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: read res unit fail", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
ret = instance->GetUint32(node, "res_start", &cfg->start, 0);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: read res type fail", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
ret = instance->GetUint32(node, "res_end", &cfg->end, 0);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: read res end fail", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
ret = instance->GetUint32(node, "res_count", &cfg->count, 0);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: read res count fail", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int ProcControllorParam(const struct DeviceResourceIface *instance, const struct DeviceResourceNode *node,
|
||||
const char *name, add_res_callback_t callback, struct UsbInfo *info)
|
||||
{
|
||||
int32_t ret;
|
||||
const struct DeviceResourceNode *subNode = NULL;
|
||||
const char *ctrlName = NULL;
|
||||
uint32_t index = 0;
|
||||
struct UsbConfig *cfg = NULL;
|
||||
|
||||
subNode = node->child;
|
||||
if (subNode == NULL) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
DEV_RES_NODE_FOR_EACH_CHILD_NODE(node, subNode) {
|
||||
if (index >= info->len) {
|
||||
break;
|
||||
}
|
||||
|
||||
cfg = &(info->cfg[index]);
|
||||
ret = instance->GetString(subNode, "controller", &ctrlName, NULL);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: read res_type fail", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(name, ctrlName) != 0) {
|
||||
HDF_LOGI("%s: no match name", __func__);
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = GetUsbControllerParam(instance, subNode, cfg);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: read controller param fail", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
callback(name, cfg->type, cfg->unit, cfg->start, cfg->end, cfg->count);
|
||||
index++;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static void HdfUsbInitParam(device_t dev, add_res_callback_t callback)
|
||||
{
|
||||
const struct DeviceResourceIface *devResInstance = NULL;
|
||||
const struct DeviceResourceNode *hdfUsbNode = NULL;
|
||||
const char *ctrlName = NULL;
|
||||
int32_t ret;
|
||||
int32_t count;
|
||||
int32_t i;
|
||||
struct UsbInfo info = {0};
|
||||
|
||||
devResInstance = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
|
||||
if (devResInstance == NULL) {
|
||||
HDF_LOGE("%s get devResInstance node is null", __func__);
|
||||
return;
|
||||
}
|
||||
hdfUsbNode = GetHdfUsbNode(devResInstance);
|
||||
if (hdfUsbNode == NULL) {
|
||||
HDF_LOGE("%s get hdf usb node is null", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
count = devResInstance->GetElemNum(hdfUsbNode, USB_CONTROLLER_LIST_NAME);
|
||||
if ((count <= 0) || (count > USB_MAX_CFG_LEN / USB_CFG_UNIT)) {
|
||||
HDF_LOGE("%s get elemnum failed", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
info.len = USB_MAX_CFG_LEN;
|
||||
for (i = 0; i < count; i++) {
|
||||
ret = devResInstance->GetStringArrayElem(hdfUsbNode, USB_CONTROLLER_LIST_NAME, i, &ctrlName, NULL);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s get hdf usb list name fail", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
device_add_child(dev, ctrlName, 0);
|
||||
ret = ProcControllorParam(devResInstance, hdfUsbNode, ctrlName, callback, &info);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGI("%s proc usb controllor not match, goto next", __func__);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UsbResourceInit(device_t dev, add_res_callback_t callback)
|
||||
{
|
||||
if (callback == NULL) {
|
||||
HDF_LOGE("usb resource init failed");
|
||||
return;
|
||||
}
|
||||
|
||||
HdfUsbInitParam(dev, callback);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#ifndef HDF_USB_H
|
||||
#define HDF_USB_H
|
||||
|
||||
#include "sys/bus.h"
|
||||
|
||||
void UsbResourceInit(device_t dev, add_res_callback_t callback);
|
||||
|
||||
#endif /* HDF_USB_H */
|
||||
|
||||
Executable
+52
@@ -0,0 +1,52 @@
|
||||
# Copyright (c) 2020-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.
|
||||
|
||||
config DRIVERS_HDF_DISP
|
||||
bool "Enable HDF Display driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF
|
||||
help
|
||||
Answer Y to choice HDF Display driver.
|
||||
config DRIVERS_HDF_LCDKIT
|
||||
bool "Enable HDF Lcdkit driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF_DISP
|
||||
help
|
||||
Answer Y to enable HDF Lcdkit driver.
|
||||
config DRIVERS_HDF_LCD_ICN9700
|
||||
bool "Enable HDF Icn9700 driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF_DISP
|
||||
help
|
||||
Answer Y to enable HDF Icn9700 driver.
|
||||
config DRIVERS_HDF_LCD_ST7789
|
||||
bool "Enable HDF St7789 driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF_DISP
|
||||
help
|
||||
Answer Y to enable HDF St7789 driver.
|
||||
Executable
+55
@@ -0,0 +1,55 @@
|
||||
# Copyright (c) 2020-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.
|
||||
|
||||
include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk
|
||||
|
||||
MODULE_NAME := hdf_display
|
||||
|
||||
LOCAL_INCLUDE := $(LITEOSTOPDIR)/../../base/hiviewdfx/hilog_lite/interfaces/native/kits \
|
||||
$(LITEOSTOPDIR)/../../drivers/framework/model/display/driver
|
||||
|
||||
LOCAL_SRCS += $(LITEOSTOPDIR)/../../drivers/framework/model/display/driver/hdf_disp.c
|
||||
LOCAL_SRCS += $(LITEOSTOPDIR)/../../drivers/framework/model/display/driver/lcd_abs_if.c
|
||||
|
||||
ifeq ($(LOSCFG_PLATFORM_HI3516DV300), y)
|
||||
LOCAL_SRCS += $(LITEOSTOPDIR)/../../drivers/framework/model/display/driver/hi35xx_disp.c
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_LCDKIT), y)
|
||||
LOCAL_SRCS += $(LITEOSTOPDIR)/../../drivers/framework/model/display/driver/lcdkit/lite_lcdkit.c
|
||||
LOCAL_SRCS += $(LITEOSTOPDIR)/../../drivers/framework/model/display/driver/lcdkit/lcdkit_parse_config.c
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_LCD_ICN9700), y)
|
||||
LOCAL_SRCS += $(LITEOSTOPDIR)/../../drivers/framework/model/display/driver/panel/mipi_icn9700.c
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_LCD_ST7789), y)
|
||||
LOCAL_SRCS += $(LITEOSTOPDIR)/../../drivers/framework/model/display/driver/panel/ssp_st7789.c
|
||||
endif
|
||||
include $(HDF_DRIVER)
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
# Copyright (c) 2020-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.
|
||||
|
||||
config DRIVERS_HDF_INPUT
|
||||
bool "Enable HDF input driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF
|
||||
help
|
||||
Answer Y to enable HDF input driver.
|
||||
|
||||
config DRIVERS_HDF_TP_5P5_GT911
|
||||
bool "Enable HDF tp 5P5 GT911 driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF_INPUT
|
||||
help
|
||||
Answer Y to enable HDF TP 5P5 GT911 driver.
|
||||
|
||||
config DRIVERS_HDF_TP_2P35_FT6236
|
||||
bool "Enable HDF tp 2P35 FT6236 driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF_INPUT
|
||||
help
|
||||
Answer Y to enable HDF TP 2P35 FT6236 driver.
|
||||
Executable
+55
@@ -0,0 +1,55 @@
|
||||
# Copyright (c) 2020-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.
|
||||
|
||||
include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk
|
||||
|
||||
INPUT_ROOT_DIR = $(LITEOSTOPDIR)/../../drivers/framework/model/input/driver
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_INPUT), y)
|
||||
MODULE_NAME := hdf_input_driver
|
||||
LOCAL_INCLUDE := $(INPUT_ROOT_DIR) \
|
||||
$(INPUT_ROOT_DIR)/input_bus_ops \
|
||||
$(INPUT_ROOT_DIR)/../../../../../third_party/FreeBSD/sys/dev/evdev
|
||||
LOCAL_SRCS += $(INPUT_ROOT_DIR)/input_bus_ops/input_i2c_ops.c \
|
||||
$(INPUT_ROOT_DIR)/hdf_input_device_manager.c \
|
||||
$(INPUT_ROOT_DIR)/input_config_parser.c \
|
||||
$(INPUT_ROOT_DIR)/event_hub.c \
|
||||
$(INPUT_ROOT_DIR)/hdf_touch.c \
|
||||
$(INPUT_ROOT_DIR)/hdf_key.c \
|
||||
$(INPUT_ROOT_DIR)/hdf_hid.c
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_TP_5P5_GT911), y)
|
||||
LOCAL_SRCS += $(INPUT_ROOT_DIR)/touchscreen/touch_gt911.c
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_TP_2P35_FT6236), y)
|
||||
LOCAL_SRCS += $(INPUT_ROOT_DIR)/touchscreen/touch_ft6336.c
|
||||
endif
|
||||
|
||||
include $(HDF_DRIVER)
|
||||
Executable
+94
@@ -0,0 +1,94 @@
|
||||
# Copyright (c) 2020-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.
|
||||
|
||||
include $(LITEOSTOPDIR)/config.mk
|
||||
include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos//lite.mk
|
||||
|
||||
MODULE_NAME := hdf_wifi_model
|
||||
HDM_WIFI_ROOT = $(LITEOSTOPDIR)/../../drivers/framework/model/network/wifi
|
||||
HDM_WIFI_LITE_ROOT = $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/model/network/wifi
|
||||
|
||||
##################path of compile file :start###############
|
||||
##### hdm #####
|
||||
#WPHY_PATH := $(HDM_WIFI_ROOT)/compoments/wphy
|
||||
#WMAC_PATH := $(HDM_WIFI_ROOT)/compoments/wmac
|
||||
WAP_PATH := $(HDM_WIFI_ROOT)/core/compoments/softap
|
||||
WSTA_PATH := $(HDM_WIFI_ROOT)/core/compoments/sta
|
||||
WEAPOL_PATH := $(HDM_WIFI_ROOT)/core/compoments/eapol
|
||||
NETDEV_PATH := $(HDM_WIFI_ROOT)/../common/netdevice
|
||||
MODULE_PATH := $(HDM_WIFI_ROOT)/core/module
|
||||
PLATFORM_PATH := $(HDM_WIFI_ROOT)/platform
|
||||
QOS_PATH := $(PLATFORM_PATH)/src/qos
|
||||
INC_PATH := $(HDM_WIFI_ROOT)/include
|
||||
INC_WIFI_PATH := $(LITEOSTOPDIR)/../../drivers/framework/include/wifi
|
||||
##################path of compile file :end###############
|
||||
|
||||
|
||||
WIFI_CFLAGS += -I $(INC_PATH) \
|
||||
-I $(WSTA_PATH) \
|
||||
-I $(WAP_PATH) \
|
||||
-I $(WEAPOL_PATH) \
|
||||
-I $(NETDEV_PATH) \
|
||||
-I $(MODULE_PATH) \
|
||||
-I $(INC_WIFI_PATH)
|
||||
|
||||
|
||||
LOCAL_SRCS += $(WAP_PATH)/ap.c \
|
||||
$(WEAPOL_PATH)/eapol.c \
|
||||
$(WSTA_PATH)/sta.c \
|
||||
$(NETDEV_PATH)/net_device.c \
|
||||
$(MODULE_PATH)/wifi_module.c \
|
||||
$(MODULE_PATH)/wifi_base.c \
|
||||
$(MODULE_PATH)/wifi_feature.c \
|
||||
$(HDM_WIFI_ROOT)/core/hdf_wifi_core.c
|
||||
|
||||
MESSAGE_INCLUDE += -I $(PLATFORM_PATH)/include/message \
|
||||
-I $(PLATFORM_PATH)/include
|
||||
|
||||
LOCAL_SRCS += $(PLATFORM_PATH)/src/message/nodes/local_node.c \
|
||||
$(PLATFORM_PATH)/src/message/message_dispatcher.c \
|
||||
$(PLATFORM_PATH)/src/message/message_router.c \
|
||||
$(PLATFORM_PATH)/src/message/sidecar.c \
|
||||
$(PLATFORM_PATH)/src/hdf_wlan_priority_queue.c \
|
||||
$(HDM_WIFI_LITE_ROOT)/platform/src/hdf_wlan_queue.c \
|
||||
$(QOS_PATH)/flow_control.c \
|
||||
$(QOS_PATH)/flow_control_task.c \
|
||||
$(PLATFORM_PATH)/src/hdf_wifi_event.c \
|
||||
$(PLATFORM_PATH)/src/hdf_wlan_utils.c \
|
||||
$(PLATFORM_PATH)/src/hdf_wlan_chipdriver_manager.c \
|
||||
$(PLATFORM_PATH)/src/hdf_wlan_power_manager.c \
|
||||
$(PLATFORM_PATH)/src/hdf_wlan_reset_manager.c \
|
||||
$(PLATFORM_PATH)/src/hdf_wlan_product.c \
|
||||
$(PLATFORM_PATH)/src/hdf_wlan_config_parser.c
|
||||
|
||||
LOCAL_CFLAGS += $(WIFI_CFLAGS) $(MESSAGE_INCLUDE)
|
||||
|
||||
LOCAL_CFLAGS += -fstack-protector-strong -fno-common -fsigned-char -fno-strict-aliasing
|
||||
|
||||
include $(HDF_DRIVER)
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#include "hdf_wlan_queue.h"
|
||||
#include "los_queue.h"
|
||||
#include "osal/osal_mem.h"
|
||||
#include "utils/hdf_log.h"
|
||||
|
||||
typedef struct HdfWlanQueueImpl {
|
||||
HdfWlanQueue queue;
|
||||
uint32_t queueID;
|
||||
} HdfWlanQueueImpl;
|
||||
|
||||
HdfWlanQueue *CreateQueue(uint16_t maxQueueSize)
|
||||
{
|
||||
HdfWlanQueueImpl *queue = (HdfWlanQueueImpl *)OsalMemCalloc(sizeof(HdfWlanQueueImpl));
|
||||
if (queue == NULL) {
|
||||
HDF_LOGE("%s:oom", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint32_t ret = LOS_QueueCreate("", maxQueueSize, &(queue->queueID), 0, sizeof(void *));
|
||||
if (ret != LOS_OK) {
|
||||
OsalMemFree(queue);
|
||||
return NULL;
|
||||
}
|
||||
return (HdfWlanQueue *)queue;
|
||||
}
|
||||
void DestroyQueue(HdfWlanQueue *queue)
|
||||
{
|
||||
if (queue == NULL) {
|
||||
return;
|
||||
}
|
||||
HdfWlanQueueImpl *queueImpl = (HdfWlanQueueImpl *)queue;
|
||||
uint32_t status = LOS_QueueDelete(queueImpl->queueID);
|
||||
if (status != LOS_OK) {
|
||||
HDF_LOGE("Destroy message queue failed!err=%d", status);
|
||||
}
|
||||
OsalMemFree(queue);
|
||||
}
|
||||
|
||||
void *PopQueue(HdfWlanQueue *queue)
|
||||
{
|
||||
if (queue == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
void *context = NULL;
|
||||
HdfWlanQueueImpl *queueImpl = (HdfWlanQueueImpl *)queue;
|
||||
|
||||
uint32_t bufferSize = sizeof(void *);
|
||||
uint32_t status = LOS_QueueReadCopy(queueImpl->queueID, &context, &bufferSize, 0);
|
||||
if (status == LOS_OK && bufferSize == sizeof(void *)) {
|
||||
return context;
|
||||
} else if (bufferSize != sizeof(void *)) {
|
||||
HDF_LOGE("Bad pointer size detected! size=%d", bufferSize);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
int32_t PushQueue(HdfWlanQueue *queue, void *context)
|
||||
{
|
||||
if (queue == NULL) {
|
||||
HDF_LOGE("%s:oom", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HdfWlanQueueImpl *queueImpl = (HdfWlanQueueImpl *)queue;
|
||||
|
||||
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);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
Executable
+47
@@ -0,0 +1,47 @@
|
||||
# Copyright (c) 2020-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.
|
||||
|
||||
config DRIVERS_HDF_SENSOR
|
||||
bool "Enable HDF sensor driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF
|
||||
help
|
||||
Answer Y to enable HDF sensor driver.
|
||||
|
||||
config DRIVERS_HDF_SENSOR_ACCEL
|
||||
bool "Enable HDF accel sensor driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF_SENSOR
|
||||
help
|
||||
Answer Y to enable HDF accel sensor driver.
|
||||
config DRIVERS_HDF_SENSOR_GYRO
|
||||
bool "Enable HDF gyro sensor driver"
|
||||
default n
|
||||
depends on DRIVERS_HDF_SENSOR
|
||||
help
|
||||
Answer Y to enable HDF gyro sensor driver.
|
||||
@@ -0,0 +1,50 @@
|
||||
# Copyright (c) 2020-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.
|
||||
|
||||
include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk
|
||||
|
||||
MODULE_NAME := hdf_sensor_driver
|
||||
|
||||
FRAMEWORKS_SENSOR_ROOT = $(LITEOSTOPDIR)/../../drivers/framework/model/sensor/driver
|
||||
|
||||
LOCAL_INCLUDE := $(FRAMEWORKS_SENSOR_ROOT)/include \
|
||||
$(FRAMEWORKS_SENSOR_ROOT)/common/include \
|
||||
$(FRAMEWORKS_SENSOR_ROOT)/accel \
|
||||
$(FRAMEWORKS_SENSOR_ROOT)/chipset/accel
|
||||
|
||||
LOCAL_SRCS += $(FRAMEWORKS_SENSOR_ROOT)/common/src/sensor_common.c \
|
||||
$(FRAMEWORKS_SENSOR_ROOT)/common/src/sensor_device_common.c \
|
||||
$(FRAMEWORKS_SENSOR_ROOT)/common/src/sensor_device_manager.c \
|
||||
$(FRAMEWORKS_SENSOR_ROOT)/common/src/sensor_parser.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
|
||||
endif
|
||||
|
||||
include $(HDF_DRIVER)
|
||||
Executable
+117
@@ -0,0 +1,117 @@
|
||||
# Copyright (c) 2020-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("//build/lite/ndk/ndk.gni")
|
||||
|
||||
group("hdf_api") {
|
||||
deps = []
|
||||
if (ohos_kernel_type == "liteos_a") {
|
||||
deps += [ ":platform_notes" ]
|
||||
deps += [ ":driver_framework_notes" ]
|
||||
deps += [ ":driver_config_notes" ]
|
||||
deps += [ ":hdi_display_notes" ]
|
||||
deps += [ ":hdi_input_notes" ]
|
||||
deps += [ ":hdi_audio_notes" ]
|
||||
deps += [ ":driver_wlan_notes" ]
|
||||
deps += [ ":osal_notes" ]
|
||||
deps += [ ":hdi_codec_notes" ]
|
||||
deps += [ ":hdi_format_notes" ]
|
||||
deps += [ ":hdi_sensor_notes" ]
|
||||
deps += [ ":hdi_wlan_notes" ]
|
||||
}
|
||||
}
|
||||
|
||||
ndk_lib("platform_notes") {
|
||||
deps = []
|
||||
head_files = [ "//drivers/framework/include/platform" ]
|
||||
}
|
||||
|
||||
ndk_lib("driver_framework_notes") {
|
||||
deps = []
|
||||
head_files = [
|
||||
"//drivers/framework/include/core",
|
||||
"//drivers/framework/ability/sbuf/include",
|
||||
]
|
||||
}
|
||||
|
||||
ndk_lib("driver_config_notes") {
|
||||
deps = []
|
||||
head_files = [ "//drivers/framework/include/config" ]
|
||||
}
|
||||
|
||||
ndk_lib("hdi_display_notes") {
|
||||
deps = []
|
||||
head_files = [ "//drivers/peripheral/display/interfaces/include" ]
|
||||
}
|
||||
|
||||
ndk_lib("hdi_input_notes") {
|
||||
deps = []
|
||||
head_files = [ "//drivers/peripheral/input/interfaces/include" ]
|
||||
}
|
||||
|
||||
ndk_lib("hdi_audio_notes") {
|
||||
deps = []
|
||||
head_files = [ "//drivers/peripheral/audio/interfaces/include" ]
|
||||
}
|
||||
|
||||
ndk_lib("driver_wlan_notes") {
|
||||
deps = []
|
||||
head_files = [
|
||||
"//drivers/framework/include/wifi",
|
||||
"//drivers/framework/include/net",
|
||||
"//drivers/framework/model/network/wifi/platform/include",
|
||||
]
|
||||
}
|
||||
|
||||
ndk_lib("osal_notes") {
|
||||
deps = []
|
||||
head_files = [
|
||||
"//drivers/framework/include/osal",
|
||||
"//drivers/framework/include/utils",
|
||||
]
|
||||
}
|
||||
|
||||
ndk_lib("hdi_codec_notes") {
|
||||
deps = []
|
||||
head_files = [ "//drivers/peripheral/codec/interfaces/include/" ]
|
||||
}
|
||||
|
||||
ndk_lib("hdi_format_notes") {
|
||||
deps = []
|
||||
head_files = [ "//drivers/peripheral/format/interfaces/include" ]
|
||||
}
|
||||
|
||||
ndk_lib("hdi_sensor_notes") {
|
||||
deps = []
|
||||
head_files = [ "//drivers/peripheral/sensor/interfaces/include" ]
|
||||
}
|
||||
|
||||
ndk_lib("hdi_wlan_notes") {
|
||||
deps = []
|
||||
head_files = [ "//drivers/peripheral/wlan/interfaces/include" ]
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#ifndef HDF_NET_DEVICE_ADAPTER_LITE_H
|
||||
#define HDF_NET_DEVICE_ADAPTER_LITE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <netinet/in.h>
|
||||
#include "net_device_impl.h"
|
||||
|
||||
#define LWIP_REF_COUNT 1
|
||||
// API
|
||||
int32_t RegisterNetDeviceImpl(struct NetDeviceImpl *ndImpl);
|
||||
int32_t UnRegisterNetDeviceImpl(struct NetDeviceImpl *ndImpl);
|
||||
|
||||
struct NetDeviceAdapterLite {
|
||||
struct netif *lwipNetif;
|
||||
};
|
||||
|
||||
#endif /* HDF_NET_DEVICE_ADAPTER_LITE_H */
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#ifndef HDF_NET_DEVICE_TYPTES_ADAPTER_LITE_H
|
||||
#define HDF_NET_DEVICE_TYPTES_ADAPTER_LITE_H
|
||||
|
||||
#include <net/if.h>
|
||||
|
||||
/**
|
||||
* @brief Enumerates data sending results, including sending succeeded, other data being sent at the link layer,
|
||||
* and data link layer being locked.
|
||||
*/
|
||||
typedef enum {
|
||||
NETDEV_TX_OK = 0x00, /**< Sending succeeded */
|
||||
NETDEV_TX_BUSY = 0x10, /**< Other data being sent at the link layer */
|
||||
NETDEV_TX_LOCKED = 0x20, /**< Data link layer being locked */
|
||||
} NetDevTxResult;
|
||||
|
||||
#endif /* HDF_NET_DEVICE_TYPTES_ADAPTER_LITE_H */
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup WLAN
|
||||
* @{
|
||||
*
|
||||
* @brief Provides cross-OS migration, component adaptation, and modular assembly and compilation.
|
||||
*
|
||||
* Based on the unified APIs provided by the WLAN module, developers of the Hardware Driver Interface
|
||||
* (HDI) are capable of creating, disabling, scanning for, and connecting to WLAN hotspots, managing WLAN chips,
|
||||
* network devices, and power, and applying for, releasing, and moving network data buffers.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef _HDF_NETBUF_ADAPTER_H
|
||||
#define _HDF_NETBUF_ADAPTER_H
|
||||
|
||||
#include "los_spinlock.h"
|
||||
#include "hdf_dlist.h"
|
||||
#include "lwip/pbuf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Enumerates the segments of a network data buffer.
|
||||
*
|
||||
* The entire network data buffer is divided into three segments: a header, data, and a tail.
|
||||
* The header and tail are used to extend both ends of the data segment.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
enum {
|
||||
E_HEAD_BUF, /**< Header buffer segment */
|
||||
E_DATA_BUF, /**< Data segment */
|
||||
E_TAIL_BUF, /**< Tail buffer segment */
|
||||
MAX_BUF_NUM /**< Maximum number of buffer segments */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines the data buffer field.
|
||||
*
|
||||
* The data buffer field records the offset (based on the memory buffer address) and length of each buffer segment.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct BufField {
|
||||
uint32_t offset; /**< Offset of the buffer segment */
|
||||
uint32_t len; /**< Length of the buffer segment */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines the reserved field of a network data buffer used to store private information.
|
||||
*
|
||||
* The length of the reserved field is <b>68</b> bytes.
|
||||
*/
|
||||
#define MAX_NETBUF_RESEVER_SIZE 68
|
||||
|
||||
/**
|
||||
* @brief Records and saves a network data buffer.
|
||||
*
|
||||
* This structure is used to transmit network data between the protocol stack and network driver.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
typedef struct NetBuf {
|
||||
struct DListHead dlist; /**< Doubly linked list. Generally, multiple network data buffers are
|
||||
linked by using a doubly linked list. */
|
||||
struct BufField bufs[MAX_BUF_NUM]; /**< Defines buffer segments used to record the offset address
|
||||
(based on the memory buffer address) and length of each buffer segment,
|
||||
including the header buffer segment, data segment, and tail buffer segment.
|
||||
For details, see {@link MAX_BUF_NUM}. */
|
||||
uint8_t *mem; /**< Memory buffer address */
|
||||
uint32_t len; /**< Length of the memory buffer */
|
||||
uint32_t dataLen; /**< Actual data length of the network data buffer */
|
||||
void *dev; /**< Network device that receives the network data */
|
||||
uint32_t qmap; /**< Queue mappings of the network data buffer */
|
||||
uint8_t rsv[MAX_NETBUF_RESEVER_SIZE]; /**< Reserved field. For details, see {@link MAX_NETBUF_RESEVER_SIZE}. */
|
||||
} NetBuf;
|
||||
|
||||
/**
|
||||
* @brief Indicates the queues for storing network data.
|
||||
*
|
||||
* Queues can be used to process multiple pieces of network data in a centralized manner, improving efficiency.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
typedef struct NetBufQueue {
|
||||
struct DListHead dlist; /**< Doubly linked list. Generally, multiple network data buffers are linked
|
||||
by using a doubly linked list. */
|
||||
uint32_t size; /**< Number of network data buffers in the queue */
|
||||
struct Spinlock lock; /**< Queue operation lock */
|
||||
} NetBufQueue;
|
||||
|
||||
struct NetDevice;
|
||||
|
||||
/**
|
||||
* @brief Converts the <b>pbuf</b> structure of Lightweight TCP/IP Stack (lwIP) to a network data buffer.
|
||||
*
|
||||
* When a network device is specified, the reserved space of the network device will be added to
|
||||
* the size of the converted network data buffer.
|
||||
*
|
||||
* @param netdev Indicates the pointer to the network device.
|
||||
* @param lwip_buf Indicates the pointer to the data buffer of lwIP.
|
||||
*
|
||||
* @return Returns the pointer to the network data buffer if the operation is successful;
|
||||
* returns <b>NULL</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
NetBuf *Pbuf2NetBuf(const struct NetDevice *netdev, struct pbuf *lwipBuf);
|
||||
|
||||
/**
|
||||
* @brief Converts a network data buffer to the <b>pbuf</b> structure of Lightweight TCP/IP Stack (lwIP).
|
||||
*
|
||||
* @param nb Indicates the pointer to the network data buffer.
|
||||
*
|
||||
* @return Returns the pointer to the <b>pbuf</b> structure if the operation is successful;
|
||||
* returns <b>NULL</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct pbuf *NetBuf2Pbuf(const NetBuf *nb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
/** @} */
|
||||
@@ -0,0 +1,542 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#include "net_device_adapter.h"
|
||||
|
||||
#include <lwip/netif.h>
|
||||
#include <lwip/pbuf.h>
|
||||
#include <lwip/opt.h>
|
||||
#include <lwip/netifapi.h>
|
||||
#include "net_device.h"
|
||||
#include "osal_mem.h"
|
||||
#include "securec.h"
|
||||
|
||||
#define HDF_LOG_TAG NetDeviceLite
|
||||
#define FREE_SPACE_SIZE 2
|
||||
|
||||
static int32_t LiteNetDevInit(struct NetDeviceImpl *netDeviceImpl)
|
||||
{
|
||||
struct NetDeviceAdapterLite *liteNdPri = NULL;
|
||||
if (netDeviceImpl == NULL) {
|
||||
HDF_LOGE("%s fail : netdeviceImpl NULL!", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
liteNdPri = (struct NetDeviceAdapterLite *)OsalMemCalloc(sizeof(struct NetDeviceAdapterLite));
|
||||
if (liteNdPri == NULL) {
|
||||
HDF_LOGE("%s fail : malloc fail!", __func__);
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
(void)memset_s(liteNdPri, sizeof(struct NetDeviceAdapterLite), 0, sizeof(struct NetDeviceAdapterLite));
|
||||
netDeviceImpl->osPrivate = (void *)liteNdPri;
|
||||
HDF_LOGI("%s Success!", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
static int32_t LiteNetDevDeInit(struct NetDeviceImpl *netDeviceImpl)
|
||||
{
|
||||
if (netDeviceImpl == NULL) {
|
||||
HDF_LOGE("netdevice lite deinit already free.");
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
if (netDeviceImpl->osPrivate != NULL) {
|
||||
OsalMemFree(netDeviceImpl->osPrivate);
|
||||
netDeviceImpl->osPrivate = NULL;
|
||||
}
|
||||
HDF_LOGI("net device lite deinit success!");
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
static struct NetBuf *ConverPbuffToNetBuf(const NetDevice *netDev, struct pbuf *lwipBuf)
|
||||
{
|
||||
if (netDev == NULL || lwipBuf == NULL) {
|
||||
HDF_LOGE("Convert tot net buff fail : netdev = NULL or lwipBuf = NULL!");
|
||||
return NULL;
|
||||
}
|
||||
return Pbuf2NetBuf(netDev, lwipBuf);
|
||||
}
|
||||
|
||||
static struct pbuf *ConverNetBufToPBuf(const struct NetBuf *netBuff)
|
||||
{
|
||||
if (netBuff == NULL) {
|
||||
HDF_LOGE("Conver to pbufff fail : netBuff = NULL!");
|
||||
return NULL;
|
||||
}
|
||||
return NetBuf2Pbuf(netBuff);
|
||||
}
|
||||
|
||||
static int32_t LwipSendCheck(struct netif *netif, struct pbuf *lwipBuf)
|
||||
{
|
||||
if (netif == NULL || lwipBuf == NULL) {
|
||||
HDF_LOGE("%s : netif = NUll or lwipBuf = NULL!", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
struct NetDeviceImpl *ndImpl = (struct NetDeviceImpl *)netif->state;
|
||||
if (ndImpl == NULL || ndImpl->netDevice == NULL) {
|
||||
HDF_LOGE("%s fail : state = NUll or netdevice = NULL!", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
void LwipSend(struct netif *netif, struct pbuf *lwipBuf)
|
||||
{
|
||||
if (LwipSendCheck(netif, lwipBuf) != HDF_SUCCESS) {
|
||||
return;
|
||||
}
|
||||
struct NetDeviceImpl *ndImpl = (struct NetDeviceImpl *)netif->state;
|
||||
struct NetDevice *netDev = ndImpl->netDevice;
|
||||
struct NetDeviceInterFace *netDevIf = NULL;
|
||||
|
||||
struct NetBuf *netBuff = ConverPbuffToNetBuf(netDev, lwipBuf);
|
||||
if (netBuff == NULL) {
|
||||
return;
|
||||
}
|
||||
netDevIf = netDev->netDeviceIf;
|
||||
if (netDevIf != NULL && netDevIf->xmit != NULL) {
|
||||
netDevIf->xmit(netDev, netBuff);
|
||||
} else {
|
||||
HDF_LOGE("%s fail : netdevIf = null or xmit = null!", __func__);
|
||||
NetBufFree(netBuff);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t LwipSetHwaddr(struct netif *netif, uint8_t *addr, uint8_t len)
|
||||
{
|
||||
if (netif == NULL || addr == NULL) {
|
||||
HDF_LOGE("%s fail : netif = null or addr = null!", __func__);
|
||||
return (uint8_t)COMMON_ERROR;
|
||||
}
|
||||
if (len != MAC_ADDR_SIZE) {
|
||||
HDF_LOGE("%s fail : len not right", __func__);
|
||||
return (uint8_t)COMMON_ERROR;
|
||||
}
|
||||
struct NetDeviceImpl *ndImpl = (struct NetDeviceImpl *)netif->state;
|
||||
struct NetDevice *netDev = NULL;
|
||||
struct NetDeviceInterFace *netDevIf = NULL;
|
||||
if (ndImpl == NULL || ndImpl->netDevice == NULL) {
|
||||
HDF_LOGE("%s fail : state = null or netdevice = null!", __func__);
|
||||
return (uint8_t)COMMON_ERROR;
|
||||
}
|
||||
netDev = ndImpl->netDevice;
|
||||
netDevIf = netDev->netDeviceIf;
|
||||
if (netDevIf == NULL || netDevIf->setMacAddr == NULL) {
|
||||
HDF_LOGE("%s fail : netdevice if = null or setMacAddr = null!", __func__);
|
||||
return (uint8_t)COMMON_ERROR;
|
||||
}
|
||||
return netDevIf->setMacAddr(netDev, addr);
|
||||
}
|
||||
|
||||
void LwipDrvConfig(struct netif *netif, uint32_t conFlags, uint8_t bit)
|
||||
{
|
||||
(void)netif;
|
||||
(void)conFlags;
|
||||
(void)bit;
|
||||
return;
|
||||
}
|
||||
|
||||
static struct netif *CreateLwipNetIf(const struct NetDeviceImpl *netDeviceImpl, const struct NetDevice *netDev)
|
||||
{
|
||||
if (netDev == NULL) {
|
||||
HDF_LOGE("%s : netDev = null!", __func__);
|
||||
return NULL;
|
||||
}
|
||||
struct netif *lwipNf = NULL;
|
||||
lwipNf = (struct netif *)OsalMemCalloc(sizeof(struct netif));
|
||||
if (lwipNf == NULL) {
|
||||
HDF_LOGE("%s fail : netif malloc fail!", __func__);
|
||||
return NULL;
|
||||
}
|
||||
(void)memset_s(lwipNf, sizeof(struct netif), 0, sizeof(struct netif));
|
||||
|
||||
/* register netif to lwip */
|
||||
lwipNf->state = (void *)netDeviceImpl;
|
||||
lwipNf->drv_send = LwipSend;
|
||||
lwipNf->drv_set_hwaddr = LwipSetHwaddr;
|
||||
lwipNf->link_layer_type = WIFI_DRIVER_IF;
|
||||
lwipNf->hwaddr_len = MAC_ADDR_SIZE;
|
||||
lwipNf->drv_config = LwipDrvConfig;
|
||||
#if LOSCFG_NET_LWIP_SACK_2_0
|
||||
if (strncpy_s(lwipNf->name, IFNAMSIZ, netDev->name, IFNAMSIZ - FREE_SPACE_SIZE) != EOK) {
|
||||
HDF_LOGE("lite netif add fail : strncpy_s fail!");
|
||||
OsalMemFree(lwipNf);
|
||||
return NULL;
|
||||
}
|
||||
lwipNf->name[IFNAMSIZ - FREE_SPACE_SIZE] = '\0';
|
||||
#endif
|
||||
return lwipNf;
|
||||
}
|
||||
static void DestroyLwipNetIf(struct netif *lwipNf)
|
||||
{
|
||||
if (lwipNf != NULL) {
|
||||
OsalMemFree(lwipNf);
|
||||
}
|
||||
}
|
||||
|
||||
static void IpV6SpecialProc(struct netif *lwipNf, Protocol80211IfType ifType)
|
||||
{
|
||||
if (lwipNf == NULL) {
|
||||
return;
|
||||
}
|
||||
if ((ifType == PROTOCOL_80211_IFTYPE_AP) || (ifType == PROTOCOL_80211_IFTYPE_MESH_POINT)) {
|
||||
#ifdef _PRE_WLAN_FEATURE_LWIP_IPV6_AUTOCONFIG
|
||||
(hi_void)netifapi_set_ip6_autoconfig_disabled(lwipNf);
|
||||
(hi_void)netifapi_set_accept_ra(lwipNf, false);
|
||||
(hi_void)netifapi_set_ipv6_forwarding(lwipNf, true);
|
||||
(hi_void)netifapi_set_ra_enable(lwipNf, true);
|
||||
#endif
|
||||
}
|
||||
return;
|
||||
}
|
||||
static int32_t LiteNetDevAdd(struct NetDeviceImpl *netDeviceImpl, Protocol80211IfType ifType)
|
||||
{
|
||||
if (netDeviceImpl == NULL || netDeviceImpl->osPrivate == NULL || netDeviceImpl->netDevice == NULL) {
|
||||
HDF_LOGE("Lite netif add fail : impl = null , osPrivate = null, or netdevice = null!");
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
struct NetDeviceAdapterLite *liteNdPri = (struct NetDeviceAdapterLite *)netDeviceImpl->osPrivate;
|
||||
struct NetDevice *lwipNd = netDeviceImpl->netDevice;
|
||||
struct netif *lwipNf = NULL;
|
||||
ip4_addr_t gw, ipaddr, netmask;
|
||||
IP4_ADDR(&gw, 0, 0, 0, 0);
|
||||
IP4_ADDR(&ipaddr, 0, 0, 0, 0);
|
||||
IP4_ADDR(&netmask, 0, 0, 0, 0);
|
||||
int ret = 0;
|
||||
lwipNf = CreateLwipNetIf(netDeviceImpl, lwipNd);
|
||||
if (lwipNf == NULL) {
|
||||
HDF_LOGE("%s fail : CreateLwipNetIf fail!", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if ((ret = netifapi_netif_add(lwipNf, &ipaddr, &netmask, &gw)) != ERR_OK) {
|
||||
HDF_LOGE("%s : netifapi_netif_add fail!,ret=%d", __func__, ret);
|
||||
DestroyLwipNetIf(lwipNf);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HDF_LOGI("netifapi_netif_add success!");
|
||||
#if LOSCFG_NET_LWIP_SACK_2_0
|
||||
/* update netdevice name - wipNf->name + lwipNf->num */
|
||||
int32_t num = snprintf_s(lwipNd->name, IFNAMSIZ, (IFNAMSIZ - 1), "%s%" U16_F, lwipNf->name, lwipNf->num);
|
||||
if (num < 0) {
|
||||
HDF_LOGI("Lite netif add fail : snprintf_s fail!");
|
||||
netifapi_netif_remove(lwipNf);
|
||||
DestroyLwipNetIf(lwipNf);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
#endif
|
||||
/* copy MAC ADDR TO LWIP */
|
||||
if (memcpy_s(lwipNf->hwaddr, NETIF_MAX_HWADDR_LEN, lwipNd->macAddr, MAC_ADDR_SIZE) != EOK) {
|
||||
HDF_LOGI("%s fail : memcpy_s fail!", __func__);
|
||||
netifapi_netif_remove(lwipNf);
|
||||
DestroyLwipNetIf(lwipNf);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
liteNdPri->lwipNetif = lwipNf;
|
||||
IpV6SpecialProc(lwipNf, ifType);
|
||||
/* set netif default status */
|
||||
netifapi_netif_set_default(lwipNf);
|
||||
HDF_LOGI("%s success!!", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static struct netif *GetNetIfFromDevImpl(const struct NetDeviceImpl *netDeviceImpl)
|
||||
{
|
||||
if (netDeviceImpl == NULL || netDeviceImpl->osPrivate == NULL) {
|
||||
HDF_LOGE("%s fail : impl = null or osPrivate = null!", __func__);
|
||||
return NULL;
|
||||
}
|
||||
struct NetDeviceAdapterLite *liteNdPri = (struct NetDeviceAdapterLite *)netDeviceImpl->osPrivate;
|
||||
return liteNdPri->lwipNetif;
|
||||
}
|
||||
|
||||
static int32_t LiteNetDevDelete(struct NetDeviceImpl *netDeviceImpl)
|
||||
{
|
||||
if (netDeviceImpl == NULL || netDeviceImpl->osPrivate == NULL) {
|
||||
HDF_LOGE("%s fail : impl = null or osPrivate = null!", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
struct NetDeviceAdapterLite *liteNdPri = (struct NetDeviceAdapterLite *)netDeviceImpl->osPrivate;
|
||||
struct netif *lwipNf = liteNdPri->lwipNetif;
|
||||
if (lwipNf != NULL) {
|
||||
netifapi_netif_remove(lwipNf);
|
||||
OsalMemFree(lwipNf);
|
||||
liteNdPri->lwipNetif = NULL;
|
||||
}
|
||||
HDF_LOGI("%s success!", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t LiteNetDevSetStatus(struct NetDeviceImpl *netDeviceImpl, NetIfStatus status)
|
||||
{
|
||||
struct netif *lwipNf = GetNetIfFromDevImpl(netDeviceImpl);
|
||||
if (lwipNf == NULL) {
|
||||
HDF_LOGE("%s fail : netif = null!", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
int32_t ret = 0;
|
||||
if (status == NETIF_DOWN) {
|
||||
ret = netifapi_netif_set_down(lwipNf);
|
||||
} else if (status == NETIF_UP) {
|
||||
ret = netifapi_netif_set_up(lwipNf);
|
||||
} else {
|
||||
HDF_LOGE("%s fail : status error!", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
if (ret == ERR_OK) {
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
HDF_LOGE("%s fail ret = %d!", __func__, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
static int32_t LiteNetDevSetLinkStatus(struct NetDeviceImpl *netDeviceImpl, NetIfLinkStatus status)
|
||||
{
|
||||
struct netif *lwipNf = GetNetIfFromDevImpl(netDeviceImpl);
|
||||
if (lwipNf == NULL) {
|
||||
HDF_LOGE("%s fail : netif = null!", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
int32_t ret = 0;
|
||||
if (status == NETIF_LINK_DOWN) {
|
||||
ret = netifapi_netif_set_link_down(lwipNf);
|
||||
} else if (status == NETIF_LINK_UP) {
|
||||
ret = netifapi_netif_set_link_up(lwipNf);
|
||||
} else {
|
||||
HDF_LOGE("%s fail : status error!", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
if (ret == ERR_OK) {
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
HDF_LOGE("%s fail ret = %d!", __func__, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
static ProcessingResult LiteNetDevDataFilter(struct NetBuf *buff)
|
||||
{
|
||||
if (buff == NULL) {
|
||||
HDF_LOGE("%s fail : buff = null!", __func__);
|
||||
return PROCESSING_ERROR;
|
||||
}
|
||||
struct EtherHeader *header = (struct EtherHeader *)NetBufGetAddress(buff, E_DATA_BUF);
|
||||
uint16_t etherType = ntohs(header->etherType);
|
||||
if ((etherType == ETHER_TYPE_IP) || (etherType == ETHER_TYPE_ARP) || (etherType == ETHER_TYPE_RARP) ||
|
||||
(etherType == ETHER_TYPE_IPV6) || (etherType == ETHER_TYPE_6LO) || (etherType == ETHER_TYPE_PAE)) {
|
||||
return PROCESSING_CONTINUE;
|
||||
} else {
|
||||
NetBufFree(buff);
|
||||
return PROCESSING_COMPLETE;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t LiteNetDevDataReceive(struct NetDeviceImpl *netDeviceImpl, struct NetBuf *buff)
|
||||
{
|
||||
struct netif *lwipNf = GetNetIfFromDevImpl(netDeviceImpl);
|
||||
if (lwipNf == NULL) {
|
||||
HDF_LOGE("%s fail : lwipnf = null!", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
struct pbuf *pBuff = ConverNetBufToPBuf(buff);
|
||||
if (pBuff == NULL) {
|
||||
HDF_LOGE("%s fail : pBuff = null!", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
driverif_input(lwipNf, pBuff);
|
||||
NetBufFree(buff);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t LiteNetDevReceive(struct NetDeviceImpl *netDeviceImpl, struct NetBuf *buff, ReceiveFlag flag)
|
||||
{
|
||||
if (flag >= MAX_RECEIVE_FLAG) {
|
||||
HDF_LOGE("%s fail : flag = %d.", __func__, flag);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
struct netif *lwipNf = GetNetIfFromDevImpl(netDeviceImpl);
|
||||
if (lwipNf == NULL || buff == NULL) {
|
||||
HDF_LOGE("%s fail : lwipnf = null or buff = null!", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
ProcessingResult ret = LiteNetDevDataFilter(buff);
|
||||
if (ret == PROCESSING_CONTINUE) {
|
||||
return LiteNetDevDataReceive(netDeviceImpl, buff);
|
||||
} else if (ret == PROCESSING_COMPLETE) {
|
||||
return HDF_SUCCESS;
|
||||
} else {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t LiteNetSetIpAddr(struct NetDeviceImpl *netDeviceImpl, const IpV4Addr *ipAddr, const IpV4Addr *netMask,
|
||||
const IpV4Addr *gw)
|
||||
{
|
||||
struct netif *lwipNf = GetNetIfFromDevImpl(netDeviceImpl);
|
||||
if (lwipNf == NULL) {
|
||||
HDF_LOGE("%s fail : lwipNf = null!", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
netifapi_netif_set_addr(lwipNf, (ip4_addr_t *)ipAddr, (ip4_addr_t *)netMask, (ip4_addr_t *)gw);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t LiteNetDhcpsStart(struct NetDeviceImpl *netDeviceImpl, char *ip, uint16_t ipNum)
|
||||
{
|
||||
struct netif *lwipNf = GetNetIfFromDevImpl(netDeviceImpl);
|
||||
if (lwipNf == NULL) {
|
||||
HDF_LOGE("%s fail : lwipNf = null!", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
int32_t ret = 0;
|
||||
if ((ret = netifapi_dhcps_start(lwipNf, ip, ipNum)) == ERR_OK) {
|
||||
HDF_LOGI("%s success!", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
HDF_LOGE("%s fail, ret = %d!", __func__, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
int32_t LiteNetDhcpsStop(struct NetDeviceImpl *netDeviceImpl)
|
||||
{
|
||||
struct netif *lwipNf = GetNetIfFromDevImpl(netDeviceImpl);
|
||||
if (lwipNf == NULL) {
|
||||
HDF_LOGE("%s fail : lwipNf = null!", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
int32_t ret = 0;
|
||||
if (ERR_OK == (ret = netifapi_dhcps_stop(lwipNf))) {
|
||||
HDF_LOGI("%s success!", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
HDF_LOGE("%s fail, ret = %d!", __func__, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
int32_t LiteNetDhcpStart(struct NetDeviceImpl *netDeviceImpl)
|
||||
{
|
||||
struct netif *lwipNf = GetNetIfFromDevImpl(netDeviceImpl);
|
||||
if (lwipNf == NULL) {
|
||||
HDF_LOGE("%s fail : lwipNf = null!", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
int32_t ret = 0;
|
||||
if ((ret = netifapi_dhcp_start(lwipNf)) == ERR_OK) {
|
||||
HDF_LOGI("%s success!", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
HDF_LOGE("%s fail, ret = %d!", __func__, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
int32_t LiteNetDhcpStop(struct NetDeviceImpl *netDeviceImpl)
|
||||
{
|
||||
struct netif *lwipNf = GetNetIfFromDevImpl(netDeviceImpl);
|
||||
if (lwipNf == NULL) {
|
||||
HDF_LOGE("%s fail : lwipNf = null!", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
int32_t ret = 0;
|
||||
if ((ret = netifapi_dhcp_stop(lwipNf)) == ERR_OK) {
|
||||
dhcp_cleanup(lwipNf);
|
||||
HDF_LOGI("%s success!", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
HDF_LOGE("%s fail, ret = %d!", __func__, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
int32_t LiteNetDhcpIsBound(struct NetDeviceImpl *netDeviceImpl)
|
||||
{
|
||||
struct netif *lwipNf = GetNetIfFromDevImpl(netDeviceImpl);
|
||||
if (lwipNf == NULL) {
|
||||
HDF_LOGE("%s fail : lwipNf = null!", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (dhcp_is_bound(lwipNf) == ERR_OK) {
|
||||
HDF_LOGI("%s success!", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
int32_t LiteNetChangeMacAddr(struct NetDeviceImpl *netDeviceImpl)
|
||||
{
|
||||
struct NetDevice *lwipNd = NULL;
|
||||
struct netif *lwipNf = GetNetIfFromDevImpl(netDeviceImpl);
|
||||
if (lwipNf == NULL) {
|
||||
HDF_LOGE("%s fail : lwipNf = null!", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
lwipNd = netDeviceImpl->netDevice;
|
||||
if (memcpy_s(lwipNf->hwaddr, NETIF_MAX_HWADDR_LEN, lwipNd->macAddr, MAC_ADDR_SIZE) != EOK) {
|
||||
HDF_LOGE("%s fail : memcpy_s fail!", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static struct NetDeviceImplOp g_liteNdImplOps = {
|
||||
.init = LiteNetDevInit,
|
||||
.deInit = LiteNetDevDeInit,
|
||||
.add = LiteNetDevAdd,
|
||||
.delete = LiteNetDevDelete,
|
||||
.setStatus = LiteNetDevSetStatus,
|
||||
.setLinkStatus = LiteNetDevSetLinkStatus,
|
||||
.receive = LiteNetDevReceive,
|
||||
.setIpAddr = LiteNetSetIpAddr,
|
||||
.dhcpsStart = LiteNetDhcpsStart,
|
||||
.dhcpsStop = LiteNetDhcpsStop,
|
||||
.dhcpStart = LiteNetDhcpStart,
|
||||
.dhcpStop = LiteNetDhcpStop,
|
||||
.dhcpIsBound = LiteNetDhcpIsBound,
|
||||
.changeMacAddr = LiteNetChangeMacAddr,
|
||||
};
|
||||
|
||||
int32_t RegisterNetDeviceImpl(struct NetDeviceImpl *ndImpl)
|
||||
{
|
||||
if (ndImpl == NULL) {
|
||||
HDF_LOGE("%s fail : impl = null!", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
ndImpl->interFace = &g_liteNdImplOps;
|
||||
HDF_LOGI("register lite netdevice impl success.");
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
int32_t UnRegisterNetDeviceImpl(struct NetDeviceImpl *ndImpl)
|
||||
{
|
||||
if (ndImpl == NULL) {
|
||||
HDF_LOGI("%s already unregister.", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
ndImpl->interFace = NULL;
|
||||
HDF_LOGI("%s success.", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,684 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#include "hdf_netbuf.h"
|
||||
#include "los_memory.h"
|
||||
#include "lwip/prot/ethernet.h"
|
||||
#include "net_device.h"
|
||||
#include "osal.h"
|
||||
|
||||
#define HDF_LOG_TAG NetBuf
|
||||
|
||||
/**
|
||||
* @brief Initializes a network data buffer queue.
|
||||
*
|
||||
* @param q Indicates the pointer to the network data buffer queue.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void NetBufQueueInit(NetBufQueue *q)
|
||||
{
|
||||
if (q == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
DListHeadInit(&q->dlist);
|
||||
LOS_SpinInit(&q->lock);
|
||||
q->size = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the size of a network data buffer queue.
|
||||
*
|
||||
* @param q Indicates the pointer to the network data buffer queue.
|
||||
*
|
||||
* @return Returns the size of the network data buffer queue.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
uint32_t NetBufQueueSize(const NetBufQueue *q)
|
||||
{
|
||||
if (q == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return q->size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks whether the network data buffer queue is empty.
|
||||
*
|
||||
* @param q Indicates the pointer to the network data buffer queue.
|
||||
*
|
||||
* @return Returns <b>true</b> if the queue is empty; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool NetBufQueueIsEmpty(const NetBufQueue *q)
|
||||
{
|
||||
if (q == NULL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return DListIsEmpty(&q->dlist);
|
||||
}
|
||||
|
||||
/*
|
||||
* Net buffer is a continuous memory which consists of three parts: head buffer, data buffer and tail buffer.
|
||||
*
|
||||
* -----------------------------------------------------
|
||||
* | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||
* ^ ^ ^ ^
|
||||
* | | | |
|
||||
* |<--head buff-->|<----data buff---->|<--tail buff-->|
|
||||
* |<----data len----->|
|
||||
* |<---------------------len------------------------->|
|
||||
*/
|
||||
|
||||
/*
|
||||
* Enqueue the new net buffer to the tail of buffer queue.
|
||||
*
|
||||
* @param : q The pointer to the net buffer queue
|
||||
* nb The new net buffer
|
||||
* @return : void
|
||||
*/
|
||||
void NetBufQueueEnqueue(NetBufQueue *q, NetBuf *nb)
|
||||
{
|
||||
if (q == NULL || nb == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t intSave;
|
||||
LOS_SpinLockSave(&q->lock, &intSave);
|
||||
DListInsertTail(&nb->dlist, &q->dlist);
|
||||
q->size++;
|
||||
LOS_SpinUnlockRestore(&q->lock, intSave);
|
||||
}
|
||||
|
||||
/*
|
||||
* Enqueue the new net buffer to the head of buffer queue.
|
||||
*
|
||||
* @param : q The pointer to the net buffer queue
|
||||
* nb The new net buffer
|
||||
* @return : void
|
||||
*/
|
||||
void NetBufQueueEnqueueHead(NetBufQueue *q, NetBuf *nb)
|
||||
{
|
||||
if (q == NULL || nb == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t intSave;
|
||||
LOS_SpinLockSave(&q->lock, &intSave);
|
||||
DListInsertHead(&nb->dlist, &q->dlist);
|
||||
q->size++;
|
||||
LOS_SpinUnlockRestore(&q->lock, intSave);
|
||||
}
|
||||
|
||||
/*
|
||||
* Dequeue the first net buffer from net buffer queue.
|
||||
*
|
||||
* @param : q The pointer to the net buffer queue
|
||||
* @return : The first net buffer in net buffer queue
|
||||
*/
|
||||
NetBuf *NetBufQueueDequeue(NetBufQueue *q)
|
||||
{
|
||||
NetBuf *nb = NULL;
|
||||
|
||||
if (q == NULL) {
|
||||
return nb;
|
||||
}
|
||||
|
||||
uint32_t intSave;
|
||||
LOS_SpinLockSave(&q->lock, &intSave);
|
||||
if (!DListIsEmpty(&q->dlist)) {
|
||||
nb = DLIST_FIRST_ENTRY(&q->dlist, NetBuf, dlist);
|
||||
DListRemove(&nb->dlist);
|
||||
q->size--;
|
||||
}
|
||||
LOS_SpinUnlockRestore(&q->lock, intSave);
|
||||
|
||||
return nb;
|
||||
}
|
||||
|
||||
/*
|
||||
* Dequeue the last net buffer from net buffer queue.
|
||||
*
|
||||
* @param : q The pointer to the net buffer queue
|
||||
* @return : The last net buffer in net buffer queue
|
||||
*/
|
||||
NetBuf *NetBufQueueDequeueTail(NetBufQueue *q)
|
||||
{
|
||||
NetBuf *nb = NULL;
|
||||
|
||||
if (q == NULL) {
|
||||
return nb;
|
||||
}
|
||||
|
||||
uint32_t intSave;
|
||||
LOS_SpinLockSave(&q->lock, &intSave);
|
||||
if (!DListIsEmpty(&q->dlist)) {
|
||||
nb = DLIST_LAST_ENTRY(&q->dlist, NetBuf, dlist);
|
||||
DListRemove(&nb->dlist);
|
||||
q->size--;
|
||||
}
|
||||
LOS_SpinUnlockRestore(&q->lock, intSave);
|
||||
|
||||
return nb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the network data buffer from the header of a queue, without deleting it from the queue.
|
||||
*
|
||||
* @param q Indicates the pointer to the network data buffer queue.
|
||||
*
|
||||
* @return Returns the pointer to the first network data buffer if the queue is not empty;
|
||||
* returns <b>NULL</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
NetBuf *NetBufQueueAtHead(const NetBufQueue *q)
|
||||
{
|
||||
if (q == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (DListIsEmpty(&q->dlist)) ? NULL : DLIST_FIRST_ENTRY(&q->dlist, NetBuf, dlist);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the network data buffer from the tail of a queue, without deleting it from the queue.
|
||||
*
|
||||
* @param q Indicates the pointer to the network data buffer queue.
|
||||
*
|
||||
* @return Returns the pointer to the last network data buffer if the queue is not empty;
|
||||
* returns <b>NULL</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
NetBuf *NetBufQueueAtTail(const NetBufQueue *q)
|
||||
{
|
||||
if (q == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (DListIsEmpty(&q->dlist)) ? NULL : DLIST_LAST_ENTRY(&q->dlist, NetBuf, dlist);
|
||||
}
|
||||
|
||||
/*
|
||||
* Clear the net buffer queue and free all net buffer in net buffer queue.
|
||||
*
|
||||
* @param : q The pointer to the net buffer queue
|
||||
* @return : void
|
||||
*/
|
||||
void NetBufQueueClear(NetBufQueue *q)
|
||||
{
|
||||
NetBuf *nb = NULL;
|
||||
|
||||
if (q == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
while ((nb = NetBufQueueDequeue(q)) != NULL) {
|
||||
NetBufFree(nb);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Merge two net buffer queues.
|
||||
*
|
||||
* @param : q The pointer to the net buffer queue for added.
|
||||
* add The pointer to the net buffer queue to add.
|
||||
* @return : void
|
||||
*/
|
||||
void NetBufQueueConcat(NetBufQueue *q, NetBufQueue *add)
|
||||
{
|
||||
if (q == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!NetBufQueueIsEmpty(add)) {
|
||||
DListMerge(&add->dlist, &q->dlist);
|
||||
q->size += add->size;
|
||||
add->size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Alloc a net buffer.
|
||||
*
|
||||
* @param : size The net buffer size
|
||||
* @return : A new net buffer or NULL on fail
|
||||
*/
|
||||
NetBuf *NetBufAlloc(uint32_t size)
|
||||
{
|
||||
NetBuf *nb = NULL;
|
||||
uint8_t *data = NULL;
|
||||
|
||||
nb = (NetBuf *)LOS_MemAllocAlign(m_aucSysMem0, sizeof(*nb), CACHE_ALIGNED_SIZE);
|
||||
if (nb == NULL) {
|
||||
HDF_LOGE("%s alloc net buf fail", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data = (uint8_t *)LOS_MemAllocAlign(m_aucSysMem0, size, CACHE_ALIGNED_SIZE);
|
||||
if (data == NULL) {
|
||||
HDF_LOGE("%s alloc data fail, size:%u", __func__, size);
|
||||
LOS_MemFree(m_aucSysMem0, nb);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
(void)memset_s(nb, sizeof(NetBuf), 0, sizeof(NetBuf));
|
||||
(void)memset_s(data, sizeof(uint8_t), 0, sizeof(uint8_t));
|
||||
|
||||
nb->mem = data;
|
||||
nb->len = size;
|
||||
nb->dataLen = 0;
|
||||
nb->bufs[E_HEAD_BUF].offset = 0;
|
||||
nb->bufs[E_HEAD_BUF].len = 0;
|
||||
nb->bufs[E_DATA_BUF].offset = 0;
|
||||
nb->bufs[E_DATA_BUF].len = 0;
|
||||
nb->bufs[E_TAIL_BUF].offset = 0;
|
||||
nb->bufs[E_TAIL_BUF].len = size;
|
||||
|
||||
return nb;
|
||||
}
|
||||
|
||||
/*
|
||||
* Free a net buffer.
|
||||
*
|
||||
* @param : nb A net buffer
|
||||
* @return : void
|
||||
*/
|
||||
void NetBufFree(NetBuf *nb)
|
||||
{
|
||||
if (nb == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (nb->mem != NULL) {
|
||||
LOS_MemFree(m_aucSysMem0, nb->mem);
|
||||
nb->mem = NULL;
|
||||
}
|
||||
|
||||
LOS_MemFree(m_aucSysMem0, nb);
|
||||
}
|
||||
|
||||
/*
|
||||
* Pop head room and add to data buffer
|
||||
*
|
||||
* @param : nb A net buffer
|
||||
* len The length of remove data
|
||||
* @return : The new start address of net buffer data on success or NULL on fail.
|
||||
*/
|
||||
void *NetBufPush(NetBuf *nb, uint32_t id, uint32_t len)
|
||||
{
|
||||
struct BufField *headBuf = NULL;
|
||||
struct BufField *dataBuf = NULL;
|
||||
struct BufField *tailBuf = NULL;
|
||||
|
||||
if (nb == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
headBuf = &nb->bufs[E_HEAD_BUF];
|
||||
dataBuf = &nb->bufs[E_DATA_BUF];
|
||||
tailBuf = &nb->bufs[E_TAIL_BUF];
|
||||
|
||||
switch (id) {
|
||||
case E_HEAD_BUF:
|
||||
if (dataBuf->len < len || nb->dataLen < len) {
|
||||
HDF_LOGE("%s fail, datasize[%u], dataroom[%u], len[%u]", __func__, nb->dataLen, dataBuf->len, len);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
headBuf->len += len;
|
||||
dataBuf->offset += len;
|
||||
dataBuf->len -= len;
|
||||
nb->dataLen -= len;
|
||||
break;
|
||||
case E_DATA_BUF:
|
||||
if (tailBuf->len < len) {
|
||||
HDF_LOGE("%s fail, tailroom[%u], len[%u]", __func__, tailBuf->len, len);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nb->dataLen += len;
|
||||
dataBuf->len += len;
|
||||
tailBuf->offset += len;
|
||||
tailBuf->len -= len;
|
||||
break;
|
||||
case E_TAIL_BUF:
|
||||
if (dataBuf->len < len || nb->dataLen < len || tailBuf->offset < len) {
|
||||
HDF_LOGE("%s fail, datasize[%u], netbuflen[%u], tailbufOffset[%u], len[%u]", __func__,
|
||||
dataBuf->len, nb->dataLen, tailBuf->offset, len);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dataBuf->len -= len;
|
||||
nb->dataLen -= len;
|
||||
tailBuf->offset -= len;
|
||||
tailBuf->len += len;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (nb->mem + dataBuf->offset);
|
||||
}
|
||||
|
||||
/*
|
||||
* reduce data buffer and push to head room.
|
||||
*
|
||||
* @param : nb A net buffer
|
||||
* len The length of add data
|
||||
* @return : The new start address of net buffer data on success or NULL on fail.
|
||||
*/
|
||||
void *NetBufPop(NetBuf *nb, uint32_t id, uint32_t len)
|
||||
{
|
||||
struct BufField *headBuf = NULL;
|
||||
struct BufField *dataBuf = NULL;
|
||||
struct BufField *tailBuf = NULL;
|
||||
|
||||
if (nb == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
headBuf = &nb->bufs[E_HEAD_BUF];
|
||||
dataBuf = &nb->bufs[E_DATA_BUF];
|
||||
tailBuf = &nb->bufs[E_TAIL_BUF];
|
||||
|
||||
switch (id) {
|
||||
case E_HEAD_BUF:
|
||||
if (headBuf->len < len || dataBuf->offset < len) {
|
||||
HDF_LOGE("%s fail, headroom[%u], len[%u]", __func__, headBuf->len, len);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
headBuf->len -= len;
|
||||
dataBuf->offset -= len;
|
||||
dataBuf->len += len;
|
||||
nb->dataLen += len;
|
||||
break;
|
||||
case E_DATA_BUF:
|
||||
if (nb->dataLen < len || dataBuf->len < len) {
|
||||
HDF_LOGE("%s fail, datasize[%u], dataroom[%u], len[%u]",
|
||||
__func__, nb->dataLen, dataBuf->len, len);
|
||||
return NULL;
|
||||
}
|
||||
headBuf->len += len;
|
||||
dataBuf->offset += len;
|
||||
dataBuf->len -= len;
|
||||
nb->dataLen -= len;
|
||||
break;
|
||||
case E_TAIL_BUF:
|
||||
if (tailBuf->len < len) {
|
||||
HDF_LOGE("%s fail, tailroom[%u], len[%u]", __func__, tailBuf->len, len);
|
||||
return NULL;
|
||||
}
|
||||
tailBuf->len -= len;
|
||||
tailBuf->offset += len;
|
||||
dataBuf->len += len;
|
||||
nb->dataLen += len;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (nb->mem + dataBuf->offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the address of a specified buffer segment in a network data buffer.
|
||||
*
|
||||
* @param nb Indicates the pointer to the network data buffer.
|
||||
* @param id Indicates the buffer segment ID.
|
||||
*
|
||||
* @return Returns the address of the specified buffer segment if the operation is successful;
|
||||
* returns <b>NULL</b> if the buffer segment ID is invalid.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
uint8_t *NetBufGetAddress(const NetBuf *nb, uint32_t id)
|
||||
{
|
||||
if (nb == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (id < MAX_BUF_NUM) {
|
||||
return (nb->mem + nb->bufs[id].offset);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the size of a specified buffer segment space in a network data buffer.
|
||||
*
|
||||
* @param nb Indicates the pointer to the network data buffer.
|
||||
* @param id Indicates the buffer segment ID.
|
||||
*
|
||||
* @return Returns the size of the specified buffer segment space if the operation is successful;
|
||||
* returns <b>NULL</b> if the buffer segment ID is invalid.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
uint32_t NetBufGetRoom(const NetBuf *nb, uint32_t id)
|
||||
{
|
||||
if (nb == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (id < MAX_BUF_NUM) {
|
||||
return nb->bufs[id].len;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the actual data length of the data segment of a network data buffer.
|
||||
*
|
||||
* @param nb Indicates the pointer to the network data buffer.
|
||||
*
|
||||
* @return Returns the actual data length of the data segment.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
uint32_t NetBufGetDataLen(const NetBuf *nb)
|
||||
{
|
||||
if (nb == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return nb->dataLen;
|
||||
}
|
||||
|
||||
/*
|
||||
* Expand a net buffer
|
||||
*
|
||||
* @param : nb A net buffer
|
||||
* head The reserved size at head room
|
||||
* tail The reserved size at tail room
|
||||
* @return : 0 for success and others for failure
|
||||
*/
|
||||
int32_t NetBufResizeRoom(NetBuf *nb, uint32_t head, uint32_t tail)
|
||||
{
|
||||
uint8_t *data = NULL;
|
||||
uint32_t size;
|
||||
uint32_t offset;
|
||||
|
||||
if (nb == NULL) {
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
size = head + nb->len + tail;
|
||||
size = ALIGN(size, CACHE_ALIGNED_SIZE);
|
||||
data = (uint8_t *)LOS_MemAllocAlign(m_aucSysMem0, size, CACHE_ALIGNED_SIZE);
|
||||
if (data == NULL) {
|
||||
HDF_LOGE("%s mem alloc fail, size:%u", __func__, size);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
(void)memset_s(data, size, 0, size);
|
||||
if (memcpy_s(data + head, size - head, nb->mem, nb->bufs[E_TAIL_BUF].offset) != EOK) {
|
||||
HDF_LOGE("%s memcopy failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
offset = nb->bufs[E_HEAD_BUF].len;
|
||||
|
||||
LOS_MemFree(m_aucSysMem0, nb->mem);
|
||||
nb->mem = data;
|
||||
nb->len = size;
|
||||
nb->bufs[E_HEAD_BUF].offset = 0;
|
||||
nb->bufs[E_HEAD_BUF].len = offset + head;
|
||||
nb->bufs[E_DATA_BUF].offset = offset + head;
|
||||
nb->bufs[E_DATA_BUF].len = nb->dataLen;
|
||||
nb->bufs[E_TAIL_BUF].offset += head;
|
||||
nb->bufs[E_TAIL_BUF].len += tail;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* Concat a net buffer to another net buffer and free the net buffer for concatted.
|
||||
*
|
||||
* @param : nb A net buffer
|
||||
* cnb The concat net buffer
|
||||
* @return : 0 for success and others for failure
|
||||
*/
|
||||
int32_t NetBufConcat(NetBuf *nb, NetBuf *cnb)
|
||||
{
|
||||
uint32_t tailroom;
|
||||
|
||||
if (nb == NULL || cnb == NULL) {
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
tailroom = NetBufGetRoom(nb, E_TAIL_BUF);
|
||||
if (tailroom < cnb->dataLen) {
|
||||
HDF_LOGE("%s can not concat, tailroom[%u], len[%u]", __func__, tailroom, cnb->len);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
if (nb->mem != NULL) {
|
||||
uint8_t *src = cnb->mem + cnb->bufs[E_DATA_BUF].offset;
|
||||
uint8_t *dst = nb->mem + nb->bufs[E_TAIL_BUF].offset;
|
||||
|
||||
if (memcpy_s(dst, tailroom, src, cnb->dataLen) != EOK) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
NetBufPush(nb, E_DATA_BUF, cnb->dataLen);
|
||||
}
|
||||
|
||||
NetBufFree(cnb);
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert net buffer to LWIP pbuf.
|
||||
*
|
||||
* @param : nb The net buffer
|
||||
* @return : pbuf for lwip
|
||||
*/
|
||||
struct pbuf *NetBuf2Pbuf(const NetBuf *nb)
|
||||
{
|
||||
struct pbuf *p = NULL;
|
||||
struct eth_hdr *hdr = NULL;
|
||||
uint32_t len = NetBufGetDataLen(nb);
|
||||
|
||||
p = pbuf_alloc(PBUF_RAW, (uint16_t)(len + ETH_PAD_SIZE), PBUF_RAM);
|
||||
if (p == NULL) {
|
||||
HDF_LOGE("%s pbuf_alloc failed! len = %d", __func__, len);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hdr = (struct eth_hdr *)p->payload;
|
||||
if (memcpy_s(&hdr->dest, len, NetBufGetAddress(nb, E_DATA_BUF), len) != EOK) {
|
||||
pbuf_free(p);
|
||||
HDF_LOGE("%s memcpy err!", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert LWIP pbuf to net buffer.
|
||||
*
|
||||
* @param : netdev The net device object
|
||||
* lwip_buf The LWIP net buffer
|
||||
* @return : The net buffer
|
||||
*/
|
||||
NetBuf *Pbuf2NetBuf(const NetDevice *netdev, struct pbuf *lwipBuf)
|
||||
{
|
||||
NetBuf *nb = NULL;
|
||||
struct pbuf *tmp = NULL;
|
||||
uint32_t index = 0;
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (lwipBuf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nb = NetBufDevAlloc(netdev, lwipBuf->tot_len);
|
||||
if (nb == NULL) {
|
||||
HDF_LOGE("%s alloc net buffer failed! len = %d", __func__, lwipBuf->tot_len);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
offset = nb->bufs[E_DATA_BUF].offset;
|
||||
|
||||
for (tmp = lwipBuf; tmp != NULL; tmp = tmp->next, index++) {
|
||||
if (tmp->len == 0 || tmp->payload == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (NetBufGetRoom(nb, E_TAIL_BUF) < tmp->len) {
|
||||
HDF_LOGE("%s fail, tailroom[%d], len[%d], idx[%d]",
|
||||
__func__, NetBufGetRoom(nb, E_TAIL_BUF), tmp->len, index);
|
||||
NetBufFree(nb);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (memcpy_s(nb->mem + offset, tmp->len, tmp->payload, tmp->len) != EOK) {
|
||||
HDF_LOGE("%s memcpy_s err!", __func__);
|
||||
NetBufFree(nb);
|
||||
return NULL;
|
||||
}
|
||||
NetBufPush(nb, E_DATA_BUF, tmp->len);
|
||||
|
||||
offset += tmp->len;
|
||||
}
|
||||
|
||||
return nb;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#ifndef HDF_LOG_ADAPTER_H
|
||||
#define HDF_LOG_ADAPTER_H
|
||||
|
||||
#ifdef LOSCFG_BASE_CORE_HILOG
|
||||
#include "hilog/log.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef LOSCFG_BASE_CORE_HILOG
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN 0xD002500
|
||||
|
||||
#define HDF_LOGV_WRAPPER(fmt, arg...) HILOG_DEBUG(LOG_DOMAIN, fmt, ##arg)
|
||||
|
||||
#define HDF_LOGD_WRAPPER(fmt, arg...) HILOG_DEBUG(LOG_DOMAIN, fmt, ##arg)
|
||||
|
||||
#define HDF_LOGI_WRAPPER(fmt, arg...) HILOG_INFO(LOG_DOMAIN, fmt, ##arg)
|
||||
|
||||
#define HDF_LOGW_WRAPPER(fmt, arg...) HILOG_WARN(LOG_DOMAIN, fmt, ##arg)
|
||||
|
||||
#define HDF_LOGE_WRAPPER(fmt, arg...) HILOG_ERROR(LOG_DOMAIN, fmt, ##arg)
|
||||
#else
|
||||
static inline void hdf_print_none(const char *format, ...)
|
||||
{
|
||||
(void)format;
|
||||
}
|
||||
|
||||
#define HDF_LOGV_WRAPPER(fmt, arg...) hdf_print_none("[HDF:V/" LOG_TAG "]" fmt "\r\n", ##arg)
|
||||
|
||||
#define HDF_LOGD_WRAPPER(fmt, arg...) hdf_print_none("[HDF:D/" LOG_TAG "]" fmt "\r\n", ##arg)
|
||||
|
||||
#define HDF_LOGI_WRAPPER(fmt, arg...) hdf_print_none("[HDF:I/" LOG_TAG "]" fmt "\r\n", ##arg)
|
||||
|
||||
#define HDF_LOGW_WRAPPER(fmt, arg...) hdf_print_none("[HDF:W/" LOG_TAG "]" fmt "\r\n", ##arg)
|
||||
|
||||
#define HDF_LOGE_WRAPPER(fmt, arg...) hdf_print_none("[HDF:E/" LOG_TAG "]" fmt "\r\n", ##arg)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* HDF_LOG_ADAPTER_H */
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#ifndef HDF_TYPE_H
|
||||
#define HDF_TYPE_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#endif /* HDF_TYPE_H */
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#ifndef OSAL_ATOMIC_DEF_H
|
||||
#define OSAL_ATOMIC_DEF_H
|
||||
|
||||
#include <los_atomic.h>
|
||||
#include <los_hwi.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define OsalAtomicReadWrapper(v) LOS_AtomicRead((const Atomic *)&(v)->counter)
|
||||
#define OsalAtomicSetWrapper(v, value) LOS_AtomicSet((Atomic *)&(v)->counter, value)
|
||||
#define OsalAtomicIncWrapper(v) LOS_AtomicInc((Atomic *)&(v)->counter)
|
||||
#define OsalAtomicIncRetWrapper(v) LOS_AtomicIncRet((Atomic *)&(v)->counter)
|
||||
#define OsalAtomicDecWrapper(v) LOS_AtomicDec((Atomic *)&(v)->counter)
|
||||
#define OsalAtomicDecRetWrapper(v) LOS_AtomicDecRet((Atomic *)&(v)->counter)
|
||||
|
||||
#define OSAL_BITS_PER_LONG 32
|
||||
#define OSAL_BIT_MASK(nr) (1UL << ((nr) % OSAL_BITS_PER_LONG))
|
||||
#define OSAL_BIT_WORD(nr) ((nr) / OSAL_BITS_PER_LONG)
|
||||
#define OSAL_BITOP_WORD(nr) ((nr) / OSAL_BITS_PER_LONG)
|
||||
|
||||
static inline int32_t OsalTestBitWrapper(unsigned long nr, const volatile unsigned long *addr)
|
||||
{
|
||||
return (1UL & (addr[OSAL_BIT_WORD(nr)] >> (nr & (OSAL_BITS_PER_LONG - 1))));
|
||||
}
|
||||
|
||||
static inline int32_t OsalTestSetBitWrapper(unsigned long nr, volatile unsigned long *addr)
|
||||
{
|
||||
uint32_t intSave = LOS_IntLock();
|
||||
|
||||
const unsigned long mask = OSAL_BIT_MASK(nr);
|
||||
unsigned long *p = ((unsigned long *)addr) + OSAL_BIT_WORD(nr);
|
||||
unsigned long old = *p;
|
||||
*p = old | mask;
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
return ((old & mask) != 0);
|
||||
}
|
||||
|
||||
static inline int32_t OsalTestClearBitWrapper(unsigned long nr, volatile unsigned long *addr)
|
||||
{
|
||||
uint32_t intSave = LOS_IntLock();
|
||||
|
||||
const unsigned long mask = OSAL_BIT_MASK(nr);
|
||||
unsigned long *p = ((unsigned long *)addr) + OSAL_BIT_WORD(nr);
|
||||
unsigned long old = *p;
|
||||
*p = old & ~mask;
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
return ((old & mask) != 0);
|
||||
}
|
||||
|
||||
static inline void OsalClearBitWrapper(unsigned long nr, volatile unsigned long *addr)
|
||||
{
|
||||
uint32_t intSave = LOS_IntLock();
|
||||
|
||||
const unsigned long mask = OSAL_BIT_MASK(nr);
|
||||
unsigned long *p = ((unsigned long *)addr) + OSAL_BIT_WORD(nr);
|
||||
*p &= ~mask;
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OSAL_ATOMIC_DEF_H */
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#ifndef OSAL_CDEV_ADAPTER_DEF_H
|
||||
#define OSAL_CDEV_ADAPTER_DEF_H
|
||||
|
||||
#include <fs/fs.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fs_poll_pri.h>
|
||||
#include <user_copy.h>
|
||||
|
||||
#endif /* OSAL_CDEV_ADAPTER_DEF_H */
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#ifndef OSAL_LINUX_IO_ADAPTER_H
|
||||
#define OSAL_LINUX_IO_ADAPTER_H
|
||||
|
||||
#include <linux/io.h>
|
||||
#include <linux/kernel.h>
|
||||
|
||||
#endif /* OSAL_LINUX_IO_ADAPTER_H */
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef OSAL_MATH_H
|
||||
#define OSAL_MATH_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
static inline int64_t OsalDivS64(int64_t dividend, int32_t divisor)
|
||||
{
|
||||
return ((divisor != 0) ? (dividend / divisor) : 0);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OSAL_MATH_H */
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OSAL_UACCESS_DEF_H
|
||||
#define OSAL_UACCESS_DEF_H
|
||||
|
||||
#include <user_copy.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
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)
|
||||
{
|
||||
return LOS_ArchCopyFromUser(to, from, len);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OSAL_UACCESS_DEF_H */
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#include <linux/fs.h>
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_io_service.h"
|
||||
#include "osal_cdev.h"
|
||||
#include "osal_file.h"
|
||||
#include "osal_mem.h"
|
||||
#include "osal_uaccess.h"
|
||||
|
||||
#define HDF_LOG_TAG osal_cdev
|
||||
|
||||
struct OsalCdev {
|
||||
struct file_operations_vfs fops;
|
||||
const struct OsalCdevOps* opsImpl;
|
||||
const char* path;
|
||||
void* priv;
|
||||
};
|
||||
|
||||
int OsalCdevOpen(FAR struct file* filep)
|
||||
{
|
||||
struct OsalCdev* dev = (struct OsalCdev*)((struct drv_data *)filep->f_vnode->data)->priv;
|
||||
return dev->opsImpl->open(dev, filep);
|
||||
}
|
||||
|
||||
int OsalCdevRelease(FAR struct file* filep)
|
||||
{
|
||||
struct OsalCdev* dev = (struct OsalCdev*)((struct drv_data *)filep->f_vnode->data)->priv;
|
||||
return dev->opsImpl->release(dev, filep);
|
||||
}
|
||||
|
||||
ssize_t OsalCdevRead(FAR struct file* filep, FAR char* buffer, size_t buflen)
|
||||
{
|
||||
struct OsalCdev* dev = (struct OsalCdev*)((struct drv_data *)filep->f_vnode->data)->priv;
|
||||
return dev->opsImpl->read(filep, buffer, buflen, 0);
|
||||
}
|
||||
|
||||
ssize_t OsalCdevWrite(FAR struct file* filep, FAR const char* buffer, size_t buflen)
|
||||
{
|
||||
struct OsalCdev* dev = (struct OsalCdev*)((struct drv_data *)filep->f_vnode->data)->priv;
|
||||
return dev->opsImpl->write(filep, buffer, buflen, 0);
|
||||
}
|
||||
|
||||
off_t OsalCdevSeek(FAR struct file* filep, off_t offset, int whence)
|
||||
{
|
||||
struct OsalCdev* dev = (struct OsalCdev*)((struct drv_data *)filep->f_vnode->data)->priv;
|
||||
return dev->opsImpl->seek(filep, offset, whence);
|
||||
}
|
||||
|
||||
int OsalCdevIoctl(FAR struct file* filep, int cmd, unsigned long arg)
|
||||
{
|
||||
struct OsalCdev* dev = (struct OsalCdev*)((struct drv_data *)filep->f_vnode->data)->priv;
|
||||
return dev->opsImpl->ioctl(filep, cmd, arg);
|
||||
}
|
||||
|
||||
int OsalCdevPoll(FAR struct file* filep, poll_table* fds)
|
||||
{
|
||||
struct OsalCdev* dev = (struct OsalCdev*)((struct drv_data *)filep->f_vnode->data)->priv;
|
||||
return dev->opsImpl->poll(filep, fds);
|
||||
}
|
||||
|
||||
static void AssignFileOps(struct file_operations_vfs* fops, const struct OsalCdevOps* src)
|
||||
{
|
||||
fops->seek = src->seek != NULL ? OsalCdevSeek : NULL;
|
||||
fops->read = src->read != NULL ? OsalCdevRead : NULL;
|
||||
fops->write = src->write != NULL ? OsalCdevWrite : NULL;
|
||||
fops->poll = src->poll != NULL ? OsalCdevPoll : NULL;
|
||||
fops->ioctl = src->ioctl != NULL ? OsalCdevIoctl : NULL;
|
||||
fops->open = src->open != NULL ? OsalCdevOpen : NULL;
|
||||
fops->close = src->release != NULL ? OsalCdevRelease : NULL;
|
||||
}
|
||||
|
||||
struct OsalCdev* OsalAllocCdev(const struct OsalCdevOps* fops)
|
||||
{
|
||||
struct OsalCdev* cdev = OsalMemCalloc(sizeof(struct OsalCdev));
|
||||
if (cdev == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
AssignFileOps(&cdev->fops, fops);
|
||||
cdev->opsImpl = fops;
|
||||
|
||||
return cdev;
|
||||
}
|
||||
|
||||
int OsalRegisterCdev(struct OsalCdev* cdev, const char* name, unsigned int mode, void* priv)
|
||||
{
|
||||
if (cdev == NULL || name == NULL) {
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
HDF_LOGI("%s:register %s", __func__, name);
|
||||
static bool devPathInitted = false;
|
||||
if (!devPathInitted && mkdir(DEV_NODE_PATH, DEV_NODE_PATH_MODE) == 0) {
|
||||
devPathInitted = true;
|
||||
}
|
||||
int ret = register_driver(name, &cdev->fops, mode, cdev);
|
||||
if (ret == HDF_SUCCESS) {
|
||||
cdev->priv = priv;
|
||||
cdev->path = name;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void OsalUnregisterCdev(struct OsalCdev* cdev)
|
||||
{
|
||||
if (cdev != NULL) {
|
||||
unregister_driver(cdev->path);
|
||||
}
|
||||
}
|
||||
|
||||
void OsalFreeCdev(struct OsalCdev* cdev)
|
||||
{
|
||||
if (cdev != NULL) {
|
||||
OsalMemFree(cdev);
|
||||
}
|
||||
}
|
||||
|
||||
void* OsalGetCdevPriv(struct OsalCdev* cdev)
|
||||
{
|
||||
return cdev != NULL ? cdev->priv : NULL;
|
||||
}
|
||||
|
||||
void OsalSetFilePriv(struct file* filep, void* priv)
|
||||
{
|
||||
if (filep != NULL) {
|
||||
filep->f_priv = priv;
|
||||
}
|
||||
}
|
||||
|
||||
void* OsalGetFilePriv(struct file* filep)
|
||||
{
|
||||
return filep != NULL ? filep->f_priv : NULL;
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#include "osal_file.h"
|
||||
#include "fs/file.h"
|
||||
#include "unistd.h"
|
||||
#include "limits.h"
|
||||
#include "sys/stat.h"
|
||||
#include "hdf_log.h"
|
||||
|
||||
#define HDF_LOG_TAG osal_file
|
||||
|
||||
int32_t OsalFileOpen(OsalFile *file, const char *path, int flags, uint32_t rights)
|
||||
{
|
||||
int32_t fd = -1;
|
||||
char pathName[PATH_MAX + 1] = {0};
|
||||
|
||||
if (file == NULL || path == NULL) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
file->realFile = (void *)(uintptr_t)fd;
|
||||
|
||||
if (realpath(path, pathName) == NULL) {
|
||||
HDF_LOGE("%s file name is invalid\n", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
fd = open(pathName, flags, rights);
|
||||
if (fd < 0) {
|
||||
HDF_LOGE("%s open file fail %d %d %d", __func__, flags, rights, errno);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
file->realFile = (void *)(uintptr_t)fd;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
ssize_t OsalFileWrite(OsalFile *file, const void *string, uint32_t length)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
if (file == NULL || (int32_t)(uintptr_t)file->realFile == -1 || string == NULL) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
ret = write((int32_t)(uintptr_t)file->realFile, string, length);
|
||||
if (ret < 0) {
|
||||
HDF_LOGE("%s write file fail %d %d", __func__, length, errno);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void OsalFileClose(OsalFile *file)
|
||||
{
|
||||
if (file == NULL || (int32_t)(uintptr_t)file->realFile == -1) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
close((int32_t)(uintptr_t)file->realFile);
|
||||
file->realFile = (void *)(uintptr_t)-1;
|
||||
}
|
||||
|
||||
ssize_t OsalFileRead(OsalFile *file, void *buf, uint32_t length)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
if (file == NULL || (int32_t)(uintptr_t)file->realFile == -1 || buf == NULL) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
ret = read((int32_t)(uintptr_t)file->realFile, buf, length);
|
||||
if (ret < 0) {
|
||||
HDF_LOGE("%s read file fail %d %d", __func__, length, errno);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
off_t OsalFileLseek(OsalFile *file, off_t offset, int32_t whence)
|
||||
{
|
||||
off_t ret;
|
||||
|
||||
if (file == NULL || (int32_t)(uintptr_t)file->realFile == -1) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
ret = lseek((int32_t)(uintptr_t)file->realFile, offset, whence);
|
||||
if (ret < 0) {
|
||||
HDF_LOGE("%s lseek file fail %lld %d %d", __func__, offset, whence, errno);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#include "osal_firmware.h"
|
||||
#include <limits.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include "fs/file.h"
|
||||
#include "hdf_log.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
#define HDF_LOG_TAG osal_fw
|
||||
#define HDF_FW_BLOCK_SIZE 64
|
||||
|
||||
struct OsalFwDesc {
|
||||
int32_t fd;
|
||||
uint8_t *buff;
|
||||
uint32_t offset;
|
||||
bool openFlag;
|
||||
};
|
||||
|
||||
int32_t OsalRequestFirmware(struct OsalFirmware *fwPara, const char *fwName, void *device)
|
||||
{
|
||||
struct OsalFwDesc *fw = NULL;
|
||||
uint8_t *base = NULL;
|
||||
struct stat fwStat;
|
||||
char path[PATH_MAX + 1] = {0};
|
||||
int32_t fd = -1;
|
||||
|
||||
(void)device;
|
||||
if (fwPara == NULL || fwName == NULL) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
fwPara->fwSize = 0;
|
||||
fwPara->para = NULL;
|
||||
|
||||
if (realpath(fwName, path) == NULL) {
|
||||
HDF_LOGE("%s file name is invalid\n", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
fd = open(path, O_RDONLY, S_IREAD);
|
||||
if (fd == -1) {
|
||||
HDF_LOGE("%s open file fail %d", __func__, errno);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
if (fstat(fd, &fwStat) == -1) {
|
||||
HDF_LOGE("%s fstat file fail %d", __func__, errno);
|
||||
close(fd);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
base = (uint8_t *)OsalMemCalloc(sizeof(*fw) + HDF_FW_BLOCK_SIZE);
|
||||
if (base == NULL) {
|
||||
HDF_LOGE("%s malloc fail", __func__);
|
||||
close(fd);
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
|
||||
fw = (struct OsalFwDesc *)base;
|
||||
fw->fd = fd;
|
||||
fwPara->fwSize = (uint32_t)fwStat.st_size;
|
||||
|
||||
fw->openFlag = true;
|
||||
fw->buff = base + sizeof(*fw);
|
||||
fw->offset = 0;
|
||||
|
||||
fwPara->para = (void *)fw;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalSeekFirmware(struct OsalFirmware *fwPara, uint32_t offset)
|
||||
{
|
||||
struct OsalFwDesc *fw = NULL;
|
||||
|
||||
if (fwPara == NULL || offset >= fwPara->fwSize || fwPara->para == NULL) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
fw = (struct OsalFwDesc *)fwPara->para;
|
||||
fw->offset = offset;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalReadFirmware(struct OsalFirmware *fwPara, struct OsalFwBlock *block)
|
||||
{
|
||||
int32_t readOffset;
|
||||
int32_t readSize;
|
||||
struct OsalFwDesc *fw = NULL;
|
||||
|
||||
if (fwPara == NULL || fwPara->para == NULL || block == NULL) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
fw = (struct OsalFwDesc *)fwPara->para;
|
||||
if (fw->openFlag == false) {
|
||||
HDF_LOGE("%s file do not open", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
block->data = fw->buff;
|
||||
block->endFlag = false;
|
||||
block->dataSize = HDF_FW_BLOCK_SIZE;
|
||||
|
||||
if (fw->offset >= fwPara->fwSize) {
|
||||
HDF_LOGE("%s file offset invalid %d %d", __func__, fw->offset, fwPara->fwSize);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (fw->offset + block->dataSize >= fwPara->fwSize) {
|
||||
block->dataSize = fwPara->fwSize - fw->offset;
|
||||
block->endFlag = true;
|
||||
}
|
||||
|
||||
if (fw->fd == -1) {
|
||||
HDF_LOGE("%s invalid file id", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
readOffset = (int32_t)lseek(fw->fd, fw->offset, SEEK_SET);
|
||||
if (readOffset != fw->offset) {
|
||||
HDF_LOGE("%s seek offset fail %d %d", __func__, readOffset, fw->offset);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
readSize = read(fw->fd, block->data, block->dataSize);
|
||||
if (readSize != block->dataSize) {
|
||||
HDF_LOGE("%s read file fail %d %d", __func__, readSize, block->dataSize);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
block->curOffset = fw->offset;
|
||||
fw->offset += block->dataSize;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalReleaseFirmware(struct OsalFirmware *fwPara)
|
||||
{
|
||||
struct OsalFwDesc *fw = NULL;
|
||||
|
||||
if (fwPara == NULL || fwPara->para == NULL) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
fw = (struct OsalFwDesc *)fwPara->para;
|
||||
if (fw->fd == -1) {
|
||||
HDF_LOGE("%s invalid file id", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (close(fw->fd) != 0) {
|
||||
HDF_LOGE("%s close fail %d", __func__, errno);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
OsalMemFree(fwPara->para);
|
||||
fwPara->para = NULL;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#include "osal_irq.h"
|
||||
#include "los_hwi.h"
|
||||
#include "hdf_log.h"
|
||||
|
||||
#define OSAL_LOG_TAG osal_irq
|
||||
|
||||
int32_t OsalRegisterIrq(uint32_t irqId, uint32_t config, OsalIRQHandle handle, const char *name, void *dev)
|
||||
{
|
||||
uint32_t ret;
|
||||
HwiIrqParam irqParam;
|
||||
|
||||
if (irqId >= OS_HWI_MAX_NUM) {
|
||||
HDF_LOGE("invalid irq number %d\n", irqId);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
irqParam.swIrq = (INT32)irqId;
|
||||
irqParam.pDevId = dev;
|
||||
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);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HalIrqUnmask(irqId);
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalUnregisterIrq(uint32_t irqId, void *dev)
|
||||
{
|
||||
uint32_t ret;
|
||||
HwiIrqParam irqParam;
|
||||
|
||||
if (irqId >= OS_HWI_MAX_NUM) {
|
||||
HDF_LOGE("invalid irq number %d\n", irqId);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
irqParam.swIrq = (INT32)irqId;
|
||||
irqParam.pDevId = dev;
|
||||
ret = LOS_HwiDelete(irqId, &irqParam);
|
||||
if (ret != LOS_OK) {
|
||||
HDF_LOGE("irq %d unregister fail %d\n", irqId, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalEnableIrq(uint32_t irqId)
|
||||
{
|
||||
if (irqId >= OS_HWI_MAX_NUM) {
|
||||
HDF_LOGE("invalid irq number %d\n", irqId);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
HalIrqUnmask(irqId);
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalDisableIrq(uint32_t irqId)
|
||||
{
|
||||
if (irqId >= OS_HWI_MAX_NUM) {
|
||||
HDF_LOGE("invalid irq number %d\n", irqId);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
HalIrqMask(irqId);
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#include "osal_mem.h"
|
||||
#include "los_memory.h"
|
||||
#include "securec.h"
|
||||
#include "hdf_log.h"
|
||||
|
||||
#define HDF_LOG_TAG osal_mem
|
||||
|
||||
void *OsalMemAlloc(size_t size)
|
||||
{
|
||||
void *buf = NULL;
|
||||
|
||||
if (size == 0) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buf = LOS_MemAlloc((VOID *)OS_SYS_MEM_ADDR, size);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
void *OsalMemCalloc(size_t size)
|
||||
{
|
||||
void *buf = NULL;
|
||||
|
||||
if (size == 0) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buf = OsalMemAlloc(size);
|
||||
if (buf != NULL) {
|
||||
(void)memset_s(buf, size, 0, size);
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
void *OsalMemAllocAlign(size_t alignment, size_t size)
|
||||
{
|
||||
void *buf = NULL;
|
||||
|
||||
if (size == 0) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buf = LOS_MemAllocAlign((VOID *)OS_SYS_MEM_ADDR, size, alignment);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
void OsalMemFree(void *mem)
|
||||
{
|
||||
if (mem != NULL) {
|
||||
LOS_MemFree((VOID *)OS_SYS_MEM_ADDR, mem);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#include "osal_mutex.h"
|
||||
#include "los_mux.h"
|
||||
#include "los_sys.h"
|
||||
#include "hdf_log.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
#define HDF_LOG_TAG osal_mutex
|
||||
|
||||
int32_t OsalMutexInit(struct OsalMutex *mutex)
|
||||
{
|
||||
uint32_t ret;
|
||||
LosMux *mux = NULL;
|
||||
|
||||
if (mutex == NULL) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
mux = (LosMux *)OsalMemCalloc(sizeof(LosMux));
|
||||
if (mux == NULL) {
|
||||
HDF_LOGE("%s malloc fail", __func__);
|
||||
mutex->realMutex = NULL;
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
ret = LOS_MuxInit(mux, NULL);
|
||||
if (ret == LOS_OK) {
|
||||
mutex->realMutex = (void *)mux;
|
||||
} else {
|
||||
mutex->realMutex = NULL;
|
||||
OsalMemFree(mux);
|
||||
HDF_LOGE("%s create fail %d %d", __func__, ret, __LINE__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalMutexDestroy(struct OsalMutex *mutex)
|
||||
{
|
||||
uint32_t ret;
|
||||
|
||||
if (mutex == NULL || mutex->realMutex == NULL) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
ret = LOS_MuxDestroy((LosMux *)mutex->realMutex);
|
||||
if (ret != LOS_OK) {
|
||||
HDF_LOGE("%s fail %d %d", __func__, ret, __LINE__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
OsalMemFree(mutex->realMutex);
|
||||
mutex->realMutex = NULL;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalMutexLock(struct OsalMutex *mutex)
|
||||
{
|
||||
uint32_t ret;
|
||||
|
||||
if (mutex == NULL || mutex->realMutex == NULL) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
ret = LOS_MuxLock((LosMux *)mutex->realMutex, LOS_MS2Tick(HDF_WAIT_FOREVER));
|
||||
if (ret != LOS_OK) {
|
||||
HDF_LOGE("%s fail %d %d", __func__, ret, __LINE__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalMutexTimedLock(struct OsalMutex *mutex, uint32_t ms)
|
||||
{
|
||||
uint32_t ret;
|
||||
|
||||
if (mutex == NULL || mutex->realMutex == NULL) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
ret = LOS_MuxLock((LosMux *)mutex->realMutex, LOS_MS2Tick(ms));
|
||||
if (ret != LOS_OK) {
|
||||
if (ret == LOS_ETIMEDOUT) {
|
||||
return HDF_ERR_TIMEOUT;
|
||||
}
|
||||
HDF_LOGE("%s fail %d %d", __func__, ret, __LINE__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalMutexUnlock(struct OsalMutex *mutex)
|
||||
{
|
||||
uint32_t ret;
|
||||
|
||||
if (mutex == NULL || mutex->realMutex == NULL) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
ret = LOS_MuxUnlock((LosMux *)mutex->realMutex);
|
||||
if (ret != LOS_OK) {
|
||||
HDF_LOGE("%s fail %d %d", __func__, ret, __LINE__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#include "osal_sem.h"
|
||||
#include "los_hwi.h"
|
||||
#include "los_sem.h"
|
||||
#include "los_typedef.h"
|
||||
#include "hdf_log.h"
|
||||
|
||||
#define HDF_LOG_TAG osal_sem
|
||||
#define HDF_INVALID_SEM_ID UINT32_MAX
|
||||
|
||||
int32_t OsalSemInit(struct OsalSem *sem, uint32_t value)
|
||||
{
|
||||
uint32_t semId;
|
||||
uint32_t ret;
|
||||
|
||||
if (sem == NULL) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
ret = LOS_SemCreate((uint16_t)value, &semId);
|
||||
if (ret == LOS_OK) {
|
||||
sem->realSemaphore = (void *)(uintptr_t)semId;
|
||||
return HDF_SUCCESS;
|
||||
} else {
|
||||
sem->realSemaphore = (void *)(uintptr_t)HDF_INVALID_SEM_ID;
|
||||
HDF_LOGE("%s create fail %d", __func__, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t OsalSemWait(struct OsalSem *sem, uint32_t ms)
|
||||
{
|
||||
uint32_t ret;
|
||||
|
||||
if (sem == NULL || sem->realSemaphore == (void *)(uintptr_t)HDF_INVALID_SEM_ID) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
ret = LOS_SemPend((uint32_t)(uintptr_t)sem->realSemaphore, LOS_MS2Tick(ms));
|
||||
if (ret == LOS_OK) {
|
||||
return HDF_SUCCESS;
|
||||
} else {
|
||||
if (ret == LOS_ERRNO_SEM_TIMEOUT) {
|
||||
return HDF_ERR_TIMEOUT;
|
||||
}
|
||||
HDF_LOGE("%s LOS_SemPend fail %d", __func__, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t OsalSemPost(struct OsalSem *sem)
|
||||
{
|
||||
uint32_t ret;
|
||||
|
||||
if (sem == NULL || sem->realSemaphore == (void *)(uintptr_t)HDF_INVALID_SEM_ID) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
ret = LOS_SemPost((uint32_t)(uintptr_t)sem->realSemaphore);
|
||||
if (ret == LOS_OK) {
|
||||
return HDF_SUCCESS;
|
||||
} else {
|
||||
HDF_LOGE("%s LOS_SemPost fail %d", __func__, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t OsalSemDestroy(struct OsalSem *sem)
|
||||
{
|
||||
uint32_t ret;
|
||||
|
||||
if (sem == NULL || sem->realSemaphore == (void *)(uintptr_t)HDF_INVALID_SEM_ID) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
ret = LOS_SemDelete((uint32_t)(uintptr_t)sem->realSemaphore);
|
||||
if (ret != LOS_OK) {
|
||||
HDF_LOGE("%s LOS_SemDelete fail %d", __func__, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
sem->realSemaphore = (void *)(uintptr_t)HDF_INVALID_SEM_ID;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#include "osal_spinlock.h"
|
||||
#include "linux/spinlock.h"
|
||||
#include "hdf_log.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
#define HDF_LOG_TAG osal_spinlock
|
||||
|
||||
int32_t OsalSpinInit(OsalSpinlock *spinlock)
|
||||
{
|
||||
spinlock_t *spin = NULL;
|
||||
|
||||
if (spinlock == NULL) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
spin = (spinlock_t *)OsalMemCalloc(sizeof(*spin));
|
||||
if (spin == NULL) {
|
||||
HDF_LOGE("%s malloc fail", __func__);
|
||||
spinlock->realSpinlock = NULL;
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
|
||||
spin_lock_init(spin);
|
||||
spinlock->realSpinlock = spin;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalSpinDestroy(OsalSpinlock *spinlock)
|
||||
{
|
||||
if (spinlock == NULL || spinlock->realSpinlock == NULL) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
OsalMemFree(spinlock->realSpinlock);
|
||||
spinlock->realSpinlock = NULL;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalSpinLock(OsalSpinlock *spinlock)
|
||||
{
|
||||
if (spinlock == NULL || spinlock->realSpinlock == NULL) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
spin_lock((spinlock_t *)spinlock->realSpinlock);
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalSpinUnlock(OsalSpinlock *spinlock)
|
||||
{
|
||||
if (spinlock == NULL || spinlock->realSpinlock == NULL) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
spin_unlock((spinlock_t *)spinlock->realSpinlock);
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalSpinLockIrq(OsalSpinlock *spinlock)
|
||||
{
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
if (spinlock == NULL || spinlock->realSpinlock == NULL) {
|
||||
HDF_LOGE("%s invalid param %d", __func__, __LINE__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
LOS_IntLock();
|
||||
LOS_SpinLock((spinlock_t *)spinlock->realSpinlock);
|
||||
#else
|
||||
(void)spinlock;
|
||||
LOS_IntLock();
|
||||
#endif
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalSpinUnlockIrq(OsalSpinlock *spinlock)
|
||||
{
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
if (spinlock == NULL || spinlock->realSpinlock == NULL) {
|
||||
HDF_LOGE("%s invalid param %d", __func__, __LINE__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
LOS_SpinUnlock((spinlock_t *)spinlock->realSpinlock);
|
||||
LOS_IntUnLock();
|
||||
#else
|
||||
(void)spinlock;
|
||||
LOS_IntUnLock();
|
||||
#endif
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalSpinLockIrqSave(OsalSpinlock *spinlock, uint32_t *flags)
|
||||
{
|
||||
uint32_t temp = 0;
|
||||
if (spinlock == NULL || spinlock->realSpinlock == NULL || flags == NULL) {
|
||||
HDF_LOGE("%s invalid param %d", __func__, __LINE__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
spin_lock_irqsave((spinlock_t *)spinlock->realSpinlock, temp);
|
||||
*flags = temp;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalSpinUnlockIrqRestore(OsalSpinlock *spinlock, uint32_t *flags)
|
||||
{
|
||||
if (spinlock == NULL || spinlock->realSpinlock == NULL || flags == NULL) {
|
||||
HDF_LOGE("%s invalid param %d", __func__, __LINE__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
spin_unlock_irqrestore((spinlock_t *)spinlock->realSpinlock, *flags);
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#include "osal_thread.h"
|
||||
#include "los_hwi.h"
|
||||
#include "los_task.h"
|
||||
#include "securec.h"
|
||||
#include "hdf_log.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
#define HDF_LOG_TAG osal_thread
|
||||
|
||||
#define LOS_PRIORITY_WIN 3
|
||||
#define OS_TASK_PRIORITY_LOWEST 31
|
||||
#define OSAL_THREAD_NAME "hdf_thread"
|
||||
#define OSAL_INVALID_THREAD_ID UINT32_MAX
|
||||
#define OSAL_INVALID_CPU_ID UINT32_MAX
|
||||
|
||||
struct ThreadWrapper {
|
||||
OsalThreadEntry threadEntry;
|
||||
void *entryPara;
|
||||
uint32_t cpuID;
|
||||
uint32_t tid;
|
||||
};
|
||||
|
||||
enum {
|
||||
OSAL_PRIORITY_LOW = 15,
|
||||
OSAL_PRIORITY_MIDDLE = 16,
|
||||
OSAL_PRIORITY_HIGH = 24,
|
||||
OSAL_PRIORITY_HIGHEST = 31,
|
||||
};
|
||||
int32_t OsalThreadCreate(struct OsalThread *thread, OsalThreadEntry threadEntry, void *entryPara)
|
||||
{
|
||||
struct ThreadWrapper *para = NULL;
|
||||
|
||||
if (thread == NULL || threadEntry == NULL) {
|
||||
HDF_LOGE("%s invalid param", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
thread->realThread = NULL;
|
||||
para = (struct ThreadWrapper *)OsalMemCalloc(sizeof(*para));
|
||||
if (para == NULL) {
|
||||
HDF_LOGE("%s malloc fail", __func__);
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
|
||||
para->entryPara = entryPara;
|
||||
para->threadEntry = threadEntry;
|
||||
para->tid = OSAL_INVALID_THREAD_ID;
|
||||
para->cpuID = OSAL_INVALID_CPU_ID;
|
||||
thread->realThread = para;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalThreadBind(struct OsalThread *thread, unsigned int cpuID)
|
||||
{
|
||||
struct ThreadWrapper *para = NULL;
|
||||
|
||||
if (thread == NULL || thread->realThread == NULL) {
|
||||
HDF_LOGE("%s invalid parameter %d\n", __func__, __LINE__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
para = (struct ThreadWrapper *)thread->realThread;
|
||||
para->cpuID = cpuID;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalThreadStart(struct OsalThread *thread, const struct OsalThreadParam *param)
|
||||
{
|
||||
uint32_t ret;
|
||||
TSK_INIT_PARAM_S stTskInitParam;
|
||||
uint16_t priority;
|
||||
struct ThreadWrapper *para = NULL;
|
||||
|
||||
if (OS_INT_ACTIVE) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
if (thread == NULL || thread->realThread == NULL || param == NULL ||
|
||||
param->priority > OSAL_THREAD_PRI_HIGHEST) {
|
||||
HDF_LOGE("%s invalid parameter %d\n", __func__, __LINE__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
para = (struct ThreadWrapper *)thread->realThread;
|
||||
(void)memset_s(&stTskInitParam, sizeof(TSK_INIT_PARAM_S), 0, sizeof(TSK_INIT_PARAM_S));
|
||||
stTskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)para->threadEntry;
|
||||
if (param->stackSize != 0) {
|
||||
stTskInitParam.uwStackSize = param->stackSize;
|
||||
}
|
||||
stTskInitParam.pcName = param->name;
|
||||
stTskInitParam.uwResved = LOS_TASK_STATUS_DETACHED;
|
||||
|
||||
if (param->priority == OSAL_THREAD_PRI_HIGHEST) {
|
||||
priority = OSAL_PRIORITY_HIGHEST;
|
||||
} else if (param->priority == OSAL_THREAD_PRI_HIGH) {
|
||||
priority = OSAL_PRIORITY_HIGH;
|
||||
} else if (param->priority == OSAL_THREAD_PRI_DEFAULT) {
|
||||
priority = OSAL_PRIORITY_MIDDLE;
|
||||
} else {
|
||||
priority = OSAL_PRIORITY_LOW;
|
||||
}
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
if (para->cpuID != OSAL_INVALID_CPU_ID) {
|
||||
stTskInitParam.usCpuAffiMask = CPUID_TO_AFFI_MASK(para->cpuID);
|
||||
}
|
||||
#endif
|
||||
stTskInitParam.usTaskPrio = OS_TASK_PRIORITY_LOWEST - (priority - LOS_PRIORITY_WIN);
|
||||
stTskInitParam.auwArgs[0] = (uintptr_t)para->entryPara;
|
||||
ret = LOS_TaskCreate(¶->tid, &stTskInitParam);
|
||||
if (ret != LOS_OK) {
|
||||
para->tid = OSAL_INVALID_THREAD_ID;
|
||||
HDF_LOGE("%s LOS_TaskCreate fail %d %d", __func__, ret, priority);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static bool OsalCheckPara(struct OsalThread *thread)
|
||||
{
|
||||
struct ThreadWrapper *para = NULL;
|
||||
|
||||
if (OS_INT_ACTIVE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (thread == NULL || thread->realThread == NULL) {
|
||||
HDF_LOGE("%s invalid parameter %d\n", __func__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
para = (struct ThreadWrapper *)thread->realThread;
|
||||
if (para->tid == OSAL_INVALID_THREAD_ID) {
|
||||
HDF_LOGE("%s invalid parameter %d\n", __func__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t OsalThreadSuspend(struct OsalThread *thread)
|
||||
{
|
||||
uint32_t ret;
|
||||
bool flag = false;
|
||||
|
||||
flag = OsalCheckPara(thread);
|
||||
if (flag == false) {
|
||||
HDF_LOGE("%s invalid parameter %d\n", __func__, __LINE__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
ret = LOS_TaskSuspend(((struct ThreadWrapper *)thread->realThread)->tid);
|
||||
if (ret != LOS_OK) {
|
||||
HDF_LOGE("%s LOS_TaskSuspend failed %d\n", __func__, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalThreadDestroy(struct OsalThread *thread)
|
||||
{
|
||||
bool flag = false;
|
||||
|
||||
flag = OsalCheckPara(thread);
|
||||
if (flag == false) {
|
||||
HDF_LOGE("%s invalid parameter %d\n", __func__, __LINE__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
OsalMemFree(thread->realThread);
|
||||
thread->realThread = NULL;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalThreadResume(struct OsalThread *thread)
|
||||
{
|
||||
uint32_t ret;
|
||||
bool flag = false;
|
||||
|
||||
flag = OsalCheckPara(thread);
|
||||
if (flag == false) {
|
||||
HDF_LOGE("%s invalid parameter %d\n", __func__, __LINE__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
ret = LOS_TaskResume(((struct ThreadWrapper *)thread->realThread)->tid);
|
||||
if (ret != LOS_OK) {
|
||||
HDF_LOGE("%s failed %d %d\n", __func__, ret, __LINE__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#include "osal_time.h"
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include "los_sys.h"
|
||||
#include "los_task.h"
|
||||
#include "hdf_log.h"
|
||||
|
||||
#define HDF_LOG_TAG osal_time
|
||||
#define TM_SINCE_YEAR 1900
|
||||
|
||||
int32_t OsalGetTime(OsalTimespec *time)
|
||||
{
|
||||
uint64_t ms;
|
||||
|
||||
if (time == NULL) {
|
||||
HDF_LOGE("%s invalid para", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
ms = LOS_TickCountGet() * (HDF_KILO_UNIT / LOSCFG_BASE_CORE_TICK_PER_SECOND);
|
||||
|
||||
time->sec = ms / HDF_KILO_UNIT;
|
||||
time->usec = (ms % HDF_KILO_UNIT) * HDF_KILO_UNIT;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OsalDiffTime(const OsalTimespec *start, const OsalTimespec *end, OsalTimespec *diff)
|
||||
{
|
||||
uint32_t usec = 0;
|
||||
uint32_t sec = 0;
|
||||
|
||||
if (start == NULL || end == NULL || diff == NULL) {
|
||||
HDF_LOGE("%s invalid para", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (start->sec > end->sec) {
|
||||
HDF_LOGE("%s start time later then end time", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (end->usec < start->usec) {
|
||||
usec = (HDF_KILO_UNIT * HDF_KILO_UNIT);
|
||||
sec = 1;
|
||||
}
|
||||
diff->usec = usec + end->usec - start->usec;
|
||||
diff->sec = end->sec - start->sec - sec;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
uint64_t OsalGetSysTimeMs(void)
|
||||
{
|
||||
return LOS_TickCountGet() * (HDF_KILO_UNIT / LOSCFG_BASE_CORE_TICK_PER_SECOND);
|
||||
}
|
||||
|
||||
void OsalSleep(uint32_t sec)
|
||||
{
|
||||
LOS_Msleep(sec * HDF_KILO_UNIT);
|
||||
}
|
||||
|
||||
void OsalMSleep(uint32_t ms)
|
||||
{
|
||||
LOS_Msleep(ms);
|
||||
}
|
||||
|
||||
void OsalUDelay(uint32_t us)
|
||||
{
|
||||
LOS_Udelay(us);
|
||||
}
|
||||
|
||||
void OsalMDelay(uint32_t ms)
|
||||
{
|
||||
LOS_Mdelay(ms);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#include "osal_timer.h"
|
||||
#include "los_hwi.h"
|
||||
#include "los_swtmr.h"
|
||||
#include "los_swtmr_pri.h"
|
||||
#include "hdf_log.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
#define HDF_LOG_TAG osal_timer
|
||||
|
||||
struct OsalLitetimer {
|
||||
uintptr_t arg;
|
||||
uint16_t timerID;
|
||||
OsalTimerFunc func;
|
||||
uint32_t interval;
|
||||
};
|
||||
|
||||
int32_t OsalTimerCreate(OsalTimer *timer, uint32_t interval, OsalTimerFunc func, uintptr_t arg)
|
||||
{
|
||||
struct OsalLitetimer *liteTimer = NULL;
|
||||
|
||||
if (func == NULL || timer == NULL || interval == 0) {
|
||||
HDF_LOGE("%s invalid para", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
timer->realTimer = NULL;
|
||||
|
||||
liteTimer = (struct OsalLitetimer *)OsalMemCalloc(sizeof(*liteTimer));
|
||||
if (liteTimer == NULL) {
|
||||
HDF_LOGE("%s malloc fail", __func__);
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
liteTimer->timerID = MAX_INVALID_TIMER_VID;
|
||||
liteTimer->arg = arg;
|
||||
liteTimer->func = func;
|
||||
liteTimer->interval = interval;
|
||||
timer->realTimer = (void *)liteTimer;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t OsalStartTimer(OsalTimer *timer, UINT8 mode)
|
||||
{
|
||||
uint32_t ret;
|
||||
uint32_t intSave;
|
||||
uint32_t interval;
|
||||
uint16_t timerID = 0;
|
||||
struct OsalLitetimer *liteTimer = NULL;
|
||||
|
||||
if (timer == NULL || timer->realTimer == NULL) {
|
||||
HDF_LOGE("%s invalid para %d", __func__, __LINE__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
liteTimer = (struct OsalLitetimer *)timer->realTimer;
|
||||
if (liteTimer->interval == 0 || liteTimer->func == NULL) {
|
||||
HDF_LOGE("%s invalid para %d", __func__, __LINE__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
interval = liteTimer->interval;
|
||||
intSave = LOS_IntLock();
|
||||
ret = LOS_SwtmrCreate(LOS_MS2Tick(interval), mode, (SWTMR_PROC_FUNC)liteTimer->func, &timerID, liteTimer->arg);
|
||||
if (ret != LOS_OK) {
|
||||
LOS_IntRestore(intSave);
|
||||
HDF_LOGE("%s LOS_SwtmrCreate fail %d", __func__, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
ret = LOS_SwtmrStart(timerID);
|
||||
if (ret != LOS_OK) {
|
||||
LOS_SwtmrDelete(timerID);
|
||||
LOS_IntRestore(intSave);
|
||||
HDF_LOGE("%s LOS_SwtmrStart fail %d", __func__, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
liteTimer->timerID = timerID;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
int32_t OsalTimerStartLoop(OsalTimer *timer)
|
||||
{
|
||||
return OsalStartTimer(timer, LOS_SWTMR_MODE_PERIOD);
|
||||
}
|
||||
|
||||
int32_t OsalTimerStartOnce(OsalTimer *timer)
|
||||
{
|
||||
return OsalStartTimer(timer, LOS_SWTMR_MODE_ONCE);
|
||||
}
|
||||
|
||||
int32_t OsalTimerSetTimeout(OsalTimer *timer, uint32_t interval)
|
||||
{
|
||||
struct OsalLitetimer *liteTimer = NULL;
|
||||
uint32_t intSave;
|
||||
uint32_t ret;
|
||||
|
||||
if (timer == NULL || timer->realTimer == NULL || interval == 0) {
|
||||
HDF_LOGE("%s invalid para", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
liteTimer = (struct OsalLitetimer *)timer->realTimer;
|
||||
if (liteTimer->timerID == MAX_INVALID_TIMER_VID) {
|
||||
HDF_LOGE("%s timer id invalid %d", __func__, liteTimer->timerID);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
if (liteTimer->interval == interval) {
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
liteTimer->interval = interval;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
ret = LOS_SwtmrDelete(liteTimer->timerID);
|
||||
if (ret != LOS_OK) {
|
||||
LOS_IntRestore(intSave);
|
||||
HDF_LOGE("%s LOS_SwtmrDelete fail %d", __func__, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return OsalTimerStartLoop(timer);
|
||||
}
|
||||
|
||||
int32_t OsalTimerDelete(OsalTimer *timer)
|
||||
{
|
||||
uint32_t intSave;
|
||||
uint32_t ret;
|
||||
struct OsalLitetimer *liteTimer = NULL;
|
||||
|
||||
if (timer == NULL || timer->realTimer == NULL) {
|
||||
HDF_LOGE("%s invalid para", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
liteTimer = (struct OsalLitetimer *)timer->realTimer;
|
||||
if (liteTimer->timerID == MAX_INVALID_TIMER_VID) {
|
||||
HDF_LOGE("%s timer id invalid %d", __func__, liteTimer->timerID);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
ret = LOS_SwtmrDelete(liteTimer->timerID);
|
||||
if (ret == LOS_OK) {
|
||||
LOS_IntRestore(intSave);
|
||||
OsalMemFree(timer->realTimer);
|
||||
timer->realTimer = NULL;
|
||||
return HDF_SUCCESS;
|
||||
} else {
|
||||
LOS_IntRestore(intSave);
|
||||
HDF_LOGE("%s LOS_SwtmrDelete fail %d", __func__, ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#include "hdf_workqueue.h"
|
||||
#include "linux/workqueue.h"
|
||||
#include "hdf_log.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
#define HDF_LOG_TAG hdf_workqueue
|
||||
|
||||
struct WorkWrapper {
|
||||
struct delayed_work work;
|
||||
HdfWorkFunc workFunc;
|
||||
void *para;
|
||||
};
|
||||
|
||||
int32_t HdfWorkQueueInit(HdfWorkQueue *queue, char *name)
|
||||
{
|
||||
if (queue == NULL || name == NULL) {
|
||||
HDF_LOGE("%s invalid para", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
queue->realWorkQueue = create_singlethread_workqueue(name);
|
||||
if (queue->realWorkQueue == NULL) {
|
||||
HDF_LOGE("%s create queue fail", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static void WorkEntry(struct work_struct *work)
|
||||
{
|
||||
struct WorkWrapper *wrapper = NULL;
|
||||
if (work != NULL) {
|
||||
wrapper = (struct WorkWrapper *)work;
|
||||
if (wrapper->workFunc != NULL) {
|
||||
wrapper->workFunc(wrapper->para);
|
||||
} else {
|
||||
HDF_LOGE("%s routine null", __func__);
|
||||
}
|
||||
} else {
|
||||
HDF_LOGE("%s work null", __func__);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t HdfWorkInit(HdfWork *work, HdfWorkFunc func, void *para)
|
||||
{
|
||||
struct work_struct *realWork = NULL;
|
||||
struct WorkWrapper *wrapper = NULL;
|
||||
|
||||
if (work == NULL || func == NULL) {
|
||||
HDF_LOGE("%s invalid para", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
work->realWork = NULL;
|
||||
|
||||
wrapper = (struct WorkWrapper *)OsalMemCalloc(sizeof(*wrapper));
|
||||
if (wrapper == NULL) {
|
||||
HDF_LOGE("%s malloc fail", __func__);
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
realWork = &(wrapper->work.work);
|
||||
wrapper->workFunc = func;
|
||||
wrapper->para = para;
|
||||
|
||||
INIT_WORK(realWork, WorkEntry);
|
||||
work->realWork = wrapper;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t HdfDelayedWorkInit(HdfWork *work, HdfWorkFunc func, void *para)
|
||||
{
|
||||
struct delayed_work *realWork = NULL;
|
||||
struct WorkWrapper *wrapper = NULL;
|
||||
|
||||
if (work == NULL || func == NULL) {
|
||||
HDF_LOGE("%s invalid para", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
work->realWork = NULL;
|
||||
|
||||
wrapper = (struct WorkWrapper *)OsalMemCalloc(sizeof(*wrapper));
|
||||
if (wrapper == NULL) {
|
||||
HDF_LOGE("%s malloc fail", __func__);
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
realWork = &(wrapper->work);
|
||||
wrapper->workFunc = func;
|
||||
wrapper->para = para;
|
||||
|
||||
INIT_DELAYED_WORK(realWork, WorkEntry);
|
||||
work->realWork = wrapper;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
void HdfWorkDestroy(HdfWork *work)
|
||||
{
|
||||
if (work == NULL || work->realWork == NULL) {
|
||||
HDF_LOGE("%s invalid para", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
OsalMemFree(work->realWork);
|
||||
work->realWork = NULL;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void HdfDelayedWorkDestroy(HdfWork *work)
|
||||
{
|
||||
if (work == NULL || work->realWork == NULL) {
|
||||
HDF_LOGE("%s invalid para", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
return HdfWorkDestroy(work);
|
||||
}
|
||||
|
||||
void HdfWorkQueueDestroy(HdfWorkQueue *queue)
|
||||
{
|
||||
if (queue == NULL || queue->realWorkQueue == NULL) {
|
||||
HDF_LOGE("%s invalid para", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
destroy_workqueue(queue->realWorkQueue);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool HdfAddWork(HdfWorkQueue *queue, HdfWork *work)
|
||||
{
|
||||
if (queue == NULL || queue->realWorkQueue == NULL || work == NULL || work->realWork == NULL) {
|
||||
HDF_LOGE("%s invalid para", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
return queue_work(queue->realWorkQueue, &((struct WorkWrapper *)work->realWork)->work.work);
|
||||
}
|
||||
|
||||
bool HdfAddDelayedWork(HdfWorkQueue *queue, HdfWork *work, unsigned long ms)
|
||||
{
|
||||
if (queue == NULL || queue->realWorkQueue == NULL || work == NULL || work->realWork == NULL) {
|
||||
HDF_LOGE("%s invalid para", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
return queue_delayed_work(queue->realWorkQueue, &((struct WorkWrapper *)work->realWork)->work, LOS_MS2Tick(ms));
|
||||
}
|
||||
|
||||
unsigned int HdfWorkBusy(HdfWork *work)
|
||||
{
|
||||
if (work == NULL || work->realWork == NULL) {
|
||||
HDF_LOGE("%s invalid para", __func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return work_busy(&((struct WorkWrapper *)work->realWork)->work.work);
|
||||
}
|
||||
|
||||
bool HdfCancelWorkSync(HdfWork *work)
|
||||
{
|
||||
if (work == NULL || work->realWork == NULL) {
|
||||
HDF_LOGE("%s invalid para", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
return cancel_work_sync(&((struct WorkWrapper *)work->realWork)->work.work);
|
||||
}
|
||||
|
||||
bool HdfCancelDelayedWorkSync(HdfWork *work)
|
||||
{
|
||||
if (work == NULL || work->realWork == NULL) {
|
||||
HDF_LOGE("%s invalid para", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
return cancel_delayed_work_sync(&((struct WorkWrapper *)work->realWork)->work);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#include "plat_common.h"
|
||||
#include "los_hwi.h"
|
||||
|
||||
bool PlatInIrqContext(void)
|
||||
{
|
||||
return (OS_INT_ACTIVE > 0);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
# Copyright (c) 2020-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.
|
||||
|
||||
config DRIVERS_HDF_TEST
|
||||
bool "Enable HDF test"
|
||||
default n
|
||||
depends on DRIVERS_HDF
|
||||
help
|
||||
Answer Y to enable LiteOS support HDF test.
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
# Copyright (c) 2020-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.
|
||||
|
||||
include $(LITEOSTOPDIR)/config.mk
|
||||
include ./test_lite.mk
|
||||
|
||||
MODULE_NAME := hdf_test
|
||||
HDF_TEST_FRAMWORK_ROOT = $(LITEOSTOPDIR)/../../drivers/framework/test/unittest
|
||||
|
||||
LOCAL_SRCS := $(HDF_TEST_FRAMWORK_ROOT)/common/hdf_main_test.c \
|
||||
$(HDF_TEST_FRAMWORK_ROOT)/manager/sample_driver_test.c \
|
||||
$(HDF_TEST_FRAMWORK_ROOT)/osal/osal_test_entry.c \
|
||||
$(HDF_TEST_FRAMWORK_ROOT)/config/hdf_config_test.c \
|
||||
$(HDF_TEST_FRAMWORK_ROOT)/osal/osal_all_test.c \
|
||||
$(HDF_TEST_FRAMWORK_ROOT)/osal/osal_file_test.c \
|
||||
$(HDF_TEST_FRAMWORK_ROOT)/osal/osal_list_test.c \
|
||||
$(HDF_TEST_FRAMWORK_ROOT)/osal/osal_work_test.c \
|
||||
$(HDF_TEST_FRAMWORK_ROOT)/osal/osal_get_case_test.c \
|
||||
$(HDF_TEST_FRAMWORK_ROOT)/ability/config/hcs_parser/unittest/hcs_config_test.c
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_WIFI), y)
|
||||
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/wifi/hdf_wifi_test.c \
|
||||
$(HDF_TEST_FRAMWORK_ROOT)/model/network/wifi/unittest/netdevice/net_device_test.c \
|
||||
$(HDF_TEST_FRAMWORK_ROOT)/model/network/wifi/unittest/module/hdf_module_test.c \
|
||||
$(HDF_TEST_FRAMWORK_ROOT)/model/network/wifi/unittest/net/hdf_netbuf_test.c \
|
||||
$(HDF_TEST_FRAMWORK_ROOT)/model/network/wifi/unittest/qos/flow_control_test.c \
|
||||
$(HDF_TEST_FRAMWORK_ROOT)/model/network/wifi/unittest/message/hdf_queue_test.c \
|
||||
$(HDF_TEST_FRAMWORK_ROOT)/model/network/wifi/unittest/message/hdf_single_node_message_test.c
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM), y)
|
||||
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/platform_driver_test.c
|
||||
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/hdf_gpio_entry_test.c
|
||||
endif
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_I2C), y)
|
||||
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/i2c_test.c
|
||||
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/i2c_driver_test.c
|
||||
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/hdf_i2c_entry_test.c
|
||||
endif
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG), y)
|
||||
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/watchdog_test.c
|
||||
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/hdf_watchdog_entry_test.c
|
||||
endif
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_SPI), y)
|
||||
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/spi_test.c
|
||||
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/hdf_spi_entry_test.c
|
||||
endif
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_UART), y)
|
||||
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/uart_test.c
|
||||
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/hdf_uart_entry_test.c
|
||||
endif
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_RTC), y)
|
||||
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/hdf_rtc_entry_test.c
|
||||
endif
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_SDIO), y)
|
||||
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/sdio_test.c
|
||||
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/hdf_sdio_entry_test.c
|
||||
endif
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI), y)
|
||||
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/mipi_dsi_test.c
|
||||
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/hdf_mipi_dsi_entry_test.c
|
||||
endif
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_EMMC), y)
|
||||
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/emmc_test.c
|
||||
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/hdf_emmc_entry_test.c
|
||||
endif
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_PWM), y)
|
||||
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/common/pwm_test.c
|
||||
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/platform/hdf_pwm_entry_test.c
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_SENSOR), y)
|
||||
LOCAL_SRCS += $(HDF_TEST_FRAMWORK_ROOT)/sensor/hdf_sensor_test.c
|
||||
endif
|
||||
|
||||
LOCAL_FLAGS += $(LITEOS_GCOV_OPTS)
|
||||
LOCAL_CFLAGS += -fstack-protector-strong
|
||||
|
||||
include $(HDF_DRIVER_TEST)
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2020-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.
|
||||
*/
|
||||
|
||||
#ifndef OSAL_TEST_TYPE_H
|
||||
#define OSAL_TEST_TYPE_H
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include "fs/file.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include "los_hwi.h"
|
||||
|
||||
#endif /* OSAL_TEST_TYPE_H */
|
||||
@@ -0,0 +1,94 @@
|
||||
# Copyright (c) 2020-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.
|
||||
|
||||
HDF_CFLAGS := -Wno-format -Wno-format-extra-args
|
||||
HDF_ROOT_TEST_DIR = $(LITEOSTOPDIR)/../../drivers
|
||||
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/include
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/include/osal
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/include/utils
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/utils/include
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/include/platform
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/include/core
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/include/config
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/support/platform/include
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/ability/sbuf/include
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/core/host/include
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/core/master/include
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/core/shared/include
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/core/manager/include
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/core/common/include/host
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/adapter/khdf/liteos/osal/include
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/adapter/khdf/liteos/test/osal/include
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/core/adapter/vnode/include
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/core/adapter/syscall/include
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/adapter/khdf/liteos/network/include
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/test/unittest/common
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/test/unittest/manager
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/test/unittest/config
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/test/unittest/platform
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/test/unittest/hdfframe
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/test/unittest/platform/common
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/test/unittest/osal
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/test/unittest/adapter/osal/unittest
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/test/unittest/adapter/osal/include
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/test/unittest/ability/config/hcs_parser/unittest
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/test/unittest
|
||||
HDF_TEST_INCLUDE += -I $(LITEOSTOPDIR)/bsd/compat/linuxkpi/include
|
||||
HDF_TEST_INCLUDE += -I $(LITEOSTOPDIR)/../../base/hiviewdfx/hilog_lite/interfaces/native/innerkits
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_WIFI), y)
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/test/unittest/model/network/wifi/unittest/netdevice
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/test/unittest/model/network/wifi/unittest/module
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/test/unittest/model/network/wifi/unittest/net
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/test/unittest/model/network/wifi/unittest/qos
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/model/network/wifi/include
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/model/network/common/netdevice
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/model/network/wifi/platform/src/qos
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/test/unittest/model/network/wifi/unittest/message
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/model/network/wifi/include
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/model/network/wifi/core/module
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/model/network/wifi/platform/include
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/model/network/wifi/platform/include/message
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/model/network/wifi/platform/src
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/model/network/wifi/core/compoments/softap
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/model/network/wifi/core/compoments/sta
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/include/wifi
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/include/net
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/test/unittest/wifi
|
||||
endif
|
||||
ifeq ($(LOSCFG_DRIVERS_HDF_SENSOR), y)
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/test/unittest/sensor
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/peripheral/sensor/interfaces/include
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/peripheral/sensor/hal/include
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/model/sensor/driver/include
|
||||
HDF_TEST_INCLUDE += -I $(HDF_ROOT_TEST_DIR)/framework/model/sensor/driver/common/include
|
||||
endif
|
||||
LOCAL_CFLAGS += $(HDF_TEST_INCLUDE)
|
||||
LOCAL_CFLAGS += $(HDF_CFLAGS)
|
||||
HDF_DRIVER_TEST = $(HDF_ROOT_TEST_DIR)/adapter/khdf/liteos/hdf_driver.mk
|
||||
Executable
+4
@@ -0,0 +1,4 @@
|
||||
[compile exit status]:1
|
||||
[compile console output]:
|
||||
Error: ./01_empty_file_ei/case.hcs:1
|
||||
miss 'module' attribute under root node
|
||||
Executable
+4
@@ -0,0 +1,4 @@
|
||||
[compile exit status]:1
|
||||
[compile console output]:
|
||||
Error: ./01_empty_file_ei/case.hcs:1
|
||||
miss 'module' attribute under root node
|
||||
@@ -0,0 +1,3 @@
|
||||
root {
|
||||
|
||||
}
|
||||
Executable
+4
@@ -0,0 +1,4 @@
|
||||
[compile exit status]:1
|
||||
[compile console output]:
|
||||
Error: ./02_empty_root_ei/case.hcs:1
|
||||
miss 'module' attribute under root node
|
||||
Executable
+4
@@ -0,0 +1,4 @@
|
||||
[compile exit status]:1
|
||||
[compile console output]:
|
||||
Error: ./02_empty_root_ei/case.hcs:1
|
||||
miss 'module' attribute under root node
|
||||
@@ -0,0 +1,6 @@
|
||||
root {
|
||||
module = "test";
|
||||
foo {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* It's HDF config auto-gen file, do not modify it manually
|
||||
*/
|
||||
|
||||
#include "golden.h"
|
||||
|
||||
static const struct HdfConfigTestRoot g_hdfConfigTestModuleRoot = {
|
||||
.module = "test",
|
||||
.foo = {},
|
||||
};
|
||||
|
||||
const struct HdfConfigTestRoot* HdfGetTestModuleConfigRoot(void)
|
||||
{
|
||||
return &g_hdfConfigTestModuleRoot;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* HDF decompile hcs file
|
||||
*/
|
||||
|
||||
root {
|
||||
module = "test";
|
||||
foo {}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* It's HDF config auto-gen file, do not modify it manually
|
||||
*/
|
||||
|
||||
#ifndef HCS_CONFIG_GOLDEN_HEADER_H
|
||||
#define HCS_CONFIG_GOLDEN_HEADER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct HdfConfigTestFoo {
|
||||
};
|
||||
|
||||
struct HdfConfigTestRoot {
|
||||
const char* module;
|
||||
struct HdfConfigTestFoo foo;
|
||||
};
|
||||
|
||||
const struct HdfConfigTestRoot* HdfGetTestModuleConfigRoot(void);
|
||||
|
||||
#endif // HCS_CONFIG_GOLDEN_HEADER_H
|
||||
@@ -0,0 +1 @@
|
||||
CqAKoAAAAABBAAAAAAAAACEAAAABcm9vdAAXAAAAAm1vZHVsZQAUdGVzdAABZm9vAAAAAAA=
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
[compile exit status]:0
|
||||
[compile console output]:
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
[compile exit status]:0
|
||||
[compile console output]:
|
||||
@@ -0,0 +1,9 @@
|
||||
root {
|
||||
module = "test";
|
||||
term1 = 1;
|
||||
term2 = 0x2;
|
||||
term3 = 0b11;
|
||||
term_uint16 = 0xffff;
|
||||
term_uint32 = 0xffffffff;
|
||||
term_uint64 = 0xffffffffff;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* It's HDF config auto-gen file, do not modify it manually
|
||||
*/
|
||||
|
||||
#include "golden.h"
|
||||
|
||||
static const struct HdfConfigTestRoot g_hdfConfigTestModuleRoot = {
|
||||
.module = "test",
|
||||
.term1 = 0x1,
|
||||
.term2 = 0x2,
|
||||
.term3 = 0x3,
|
||||
.term_uint16 = 0xffff,
|
||||
.term_uint32 = 0xffffffff,
|
||||
.term_uint64 = 0xffffffffff,
|
||||
};
|
||||
|
||||
const struct HdfConfigTestRoot* HdfGetTestModuleConfigRoot(void)
|
||||
{
|
||||
return &g_hdfConfigTestModuleRoot;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* HDF decompile hcs file
|
||||
*/
|
||||
|
||||
root {
|
||||
module = "test";
|
||||
term1 = 0x1;
|
||||
term2 = 0x2;
|
||||
term3 = 0x3;
|
||||
term_uint16 = 0xffff;
|
||||
term_uint32 = 0xffffffff;
|
||||
term_uint64 = 0xffffffffff;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* It's HDF config auto-gen file, do not modify it manually
|
||||
*/
|
||||
|
||||
#ifndef HCS_CONFIG_GOLDEN_HEADER_H
|
||||
#define HCS_CONFIG_GOLDEN_HEADER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct HdfConfigTestRoot {
|
||||
const char* module;
|
||||
uint8_t term1;
|
||||
uint8_t term2;
|
||||
uint8_t term3;
|
||||
uint16_t term_uint16;
|
||||
uint32_t term_uint32;
|
||||
uint64_t term_uint64;
|
||||
};
|
||||
|
||||
const struct HdfConfigTestRoot* HdfGetTestModuleConfigRoot(void);
|
||||
|
||||
#endif // HCS_CONFIG_GOLDEN_HEADER_H
|
||||
@@ -0,0 +1 @@
|
||||
CqAKoAAAAABBAAAAAAAAAGsAAAABcm9vdABhAAAAAm1vZHVsZQAUdGVzdAACdGVybTEAEAECdGVybTIAEAICdGVybTMAEAMCdGVybV91aW50MTYAEf//AnRlcm1fdWludDMyABL/////AnRlcm1fdWludDY0ABP//////wAAAA==
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
[compile exit status]:0
|
||||
[compile console output]:
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
[compile exit status]:0
|
||||
[compile console output]:
|
||||
@@ -0,0 +1,4 @@
|
||||
root {
|
||||
module = "test";
|
||||
term1 = "hello";
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* It's HDF config auto-gen file, do not modify it manually
|
||||
*/
|
||||
|
||||
#include "golden.h"
|
||||
|
||||
static const struct HdfConfigTestRoot g_hdfConfigTestModuleRoot = {
|
||||
.module = "test",
|
||||
.term1 = "hello",
|
||||
};
|
||||
|
||||
const struct HdfConfigTestRoot* HdfGetTestModuleConfigRoot(void)
|
||||
{
|
||||
return &g_hdfConfigTestModuleRoot;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* HDF decompile hcs file
|
||||
*/
|
||||
|
||||
root {
|
||||
module = "test";
|
||||
term1 = "hello";
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* It's HDF config auto-gen file, do not modify it manually
|
||||
*/
|
||||
|
||||
#ifndef HCS_CONFIG_GOLDEN_HEADER_H
|
||||
#define HCS_CONFIG_GOLDEN_HEADER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct HdfConfigTestRoot {
|
||||
const char* module;
|
||||
const char* term1;
|
||||
};
|
||||
|
||||
const struct HdfConfigTestRoot* HdfGetTestModuleConfigRoot(void);
|
||||
|
||||
#endif // HCS_CONFIG_GOLDEN_HEADER_H
|
||||
@@ -0,0 +1 @@
|
||||
CqAKoAAAAABBAAAAAAAAACYAAAABcm9vdAAcAAAAAm1vZHVsZQAUdGVzdAACdGVybTEAFGhlbGxvAA==
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
[compile exit status]:0
|
||||
[compile console output]:
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
[compile exit status]:0
|
||||
[compile console output]:
|
||||
@@ -0,0 +1,4 @@
|
||||
root {
|
||||
module = "test";
|
||||
term1 = [0x1,0x2,0xffffffffff];
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* It's HDF config auto-gen file, do not modify it manually
|
||||
*/
|
||||
|
||||
#include "golden.h"
|
||||
|
||||
static const struct HdfConfigTestRoot g_hdfConfigTestModuleRoot = {
|
||||
.module = "test",
|
||||
.term1 = { 0x1, 0x2, 0xffffffffff },
|
||||
};
|
||||
|
||||
const struct HdfConfigTestRoot* HdfGetTestModuleConfigRoot(void)
|
||||
{
|
||||
return &g_hdfConfigTestModuleRoot;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* HDF decompile hcs file
|
||||
*/
|
||||
|
||||
root {
|
||||
module = "test";
|
||||
term1 = [0x1, 0x2, 0xffffffffff];
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* It's HDF config auto-gen file, do not modify it manually
|
||||
*/
|
||||
|
||||
#ifndef HCS_CONFIG_GOLDEN_HEADER_H
|
||||
#define HCS_CONFIG_GOLDEN_HEADER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct HdfConfigTestRoot {
|
||||
const char* module;
|
||||
uint64_t term1[3];
|
||||
};
|
||||
|
||||
const struct HdfConfigTestRoot* HdfGetTestModuleConfigRoot(void);
|
||||
|
||||
#endif // HCS_CONFIG_GOLDEN_HEADER_H
|
||||
@@ -0,0 +1 @@
|
||||
CqAKoAAAAABBAAAAAAAAAC8AAAABcm9vdAAlAAAAAm1vZHVsZQAUdGVzdAACdGVybTEABAMAEAEQAhP//////wAAAA==
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
[compile exit status]:0
|
||||
[compile console output]:
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
[compile exit status]:0
|
||||
[compile console output]:
|
||||
@@ -0,0 +1,4 @@
|
||||
root {
|
||||
module = "test";
|
||||
term1 = ["hello", "world"];
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* It's HDF config auto-gen file, do not modify it manually
|
||||
*/
|
||||
|
||||
#include "golden.h"
|
||||
|
||||
static const struct HdfConfigTestRoot g_hdfConfigTestModuleRoot = {
|
||||
.module = "test",
|
||||
.term1 = { "hello", "world" },
|
||||
};
|
||||
|
||||
const struct HdfConfigTestRoot* HdfGetTestModuleConfigRoot(void)
|
||||
{
|
||||
return &g_hdfConfigTestModuleRoot;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* HDF decompile hcs file
|
||||
*/
|
||||
|
||||
root {
|
||||
module = "test";
|
||||
term1 = ["hello", "world"];
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* It's HDF config auto-gen file, do not modify it manually
|
||||
*/
|
||||
|
||||
#ifndef HCS_CONFIG_GOLDEN_HEADER_H
|
||||
#define HCS_CONFIG_GOLDEN_HEADER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct HdfConfigTestRoot {
|
||||
const char* module;
|
||||
const char* term1[2];
|
||||
};
|
||||
|
||||
const struct HdfConfigTestRoot* HdfGetTestModuleConfigRoot(void);
|
||||
|
||||
#endif // HCS_CONFIG_GOLDEN_HEADER_H
|
||||
@@ -0,0 +1 @@
|
||||
CqAKoAAAAABBAAAAAAAAADAAAAABcm9vdAAmAAAAAm1vZHVsZQAUdGVzdAACdGVybTEABAIAFGhlbGxvABR3b3JsZAA=
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
[compile exit status]:0
|
||||
[compile console output]:
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
[compile exit status]:0
|
||||
[compile console output]:
|
||||
@@ -0,0 +1,12 @@
|
||||
root {
|
||||
module = "test";
|
||||
foo {
|
||||
term1 = 1;
|
||||
term2 = 0x2;
|
||||
term3 = 0b11;
|
||||
}
|
||||
|
||||
bar {
|
||||
term1 = &root.bar;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* It's HDF config auto-gen file, do not modify it manually
|
||||
*/
|
||||
|
||||
#include "golden.h"
|
||||
|
||||
static const struct HdfConfigTestRoot g_hdfConfigTestModuleRoot = {
|
||||
.module = "test",
|
||||
.foo = {
|
||||
.term1 = 0x1,
|
||||
.term2 = 0x2,
|
||||
.term3 = 0x3,
|
||||
},
|
||||
.bar = {
|
||||
.term1 = &g_hdfConfigTestModuleRoot.bar,
|
||||
},
|
||||
};
|
||||
|
||||
const struct HdfConfigTestRoot* HdfGetTestModuleConfigRoot(void)
|
||||
{
|
||||
return &g_hdfConfigTestModuleRoot;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* HDF decompile hcs file
|
||||
*/
|
||||
|
||||
root {
|
||||
module = "test";
|
||||
foo {
|
||||
term1 = 0x1;
|
||||
term2 = 0x2;
|
||||
term3 = 0x3;
|
||||
}
|
||||
bar {
|
||||
term1 = &root.bar;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* It's HDF config auto-gen file, do not modify it manually
|
||||
*/
|
||||
|
||||
#ifndef HCS_CONFIG_GOLDEN_HEADER_H
|
||||
#define HCS_CONFIG_GOLDEN_HEADER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct HdfConfigTestFoo {
|
||||
uint8_t term1;
|
||||
uint8_t term2;
|
||||
uint8_t term3;
|
||||
};
|
||||
|
||||
struct HdfConfigTestBar {
|
||||
const struct HdfConfigTestBar* term1;
|
||||
};
|
||||
|
||||
struct HdfConfigTestRoot {
|
||||
const char* module;
|
||||
struct HdfConfigTestFoo foo;
|
||||
struct HdfConfigTestBar bar;
|
||||
};
|
||||
|
||||
const struct HdfConfigTestRoot* HdfGetTestModuleConfigRoot(void);
|
||||
|
||||
#endif // HCS_CONFIG_GOLDEN_HEADER_H
|
||||
@@ -0,0 +1 @@
|
||||
CqAKoAAAAABBAAAAAAAAAFEAAAABcm9vdABHAAAAAm1vZHVsZQAUdGVzdAABZm9vABsAAAACdGVybTEAEAECdGVybTIAEAICdGVybTMAEAMBYmFyAAwAAAACdGVybTEAA1AAAAA=
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
[compile exit status]:0
|
||||
[compile console output]:
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
[compile exit status]:0
|
||||
[compile console output]:
|
||||
@@ -0,0 +1,11 @@
|
||||
root {
|
||||
module = "test";
|
||||
foo {
|
||||
foo1 {
|
||||
term1 = "hello";
|
||||
bar {
|
||||
term1 = "world";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user