update openharmony 1.0.1

This commit is contained in:
mamingshuai
2021-03-11 18:45:42 +08:00
parent 99298aed87
commit c11131d591
73 changed files with 2437 additions and 328 deletions
Executable → Regular
View File
-6
View File
@@ -1,6 +0,0 @@
# Copyright (c) 2020 Huawei Device Co., Ltd. All rights reserved.
source "../../vendor/hisi/hi35xx/platform/Kconfig"
source "../../vendor/huawei/hdf/wifi/driver/Kconfig"
source "../../vendor/huawei/hdf/input/driver/Kconfig"
source "../../vendor/huawei/hdf/display/driver/Kconfig"
Executable → Regular
View File
+34
View File
@@ -0,0 +1,34 @@
# vendor driver<a name="EN-US_TOPIC_0000001124650043"></a>
- [Introduction](#section11660541533)
- [Directory Structure](#section161941989586)
- [Repositories Involved](#section1371113476308)
## Introduction<a name="section11660541533"></a>
This repository shows some HDF sample drivers.
## Directory Structure<a name="section161941989586"></a>
The source code directory structure is as follows:
```
/vendor/huawei/hdf
└── sample # sample driver
├── config # configuration
└── platform # platform sample driver code
```
## Repositories Involved<a name="section1371113476308"></a>
Driver subsystem
hmf/drivers/framework
hmf/drivers/adapter\_lite\_khdf
hmf/drivers/adapter\_lite\_uhdf
hmf/drivers/adapter\_linux\_khdf
hmf/drivers/adapter\_linux\_uhdf
+34
View File
@@ -0,0 +1,34 @@
# vendor driver<a name="ZH-CN_TOPIC_0000001124650043"></a>
- [简介](#section11660541533)
- [目录](#section161941989586)
- [相关仓](#section1371113476308)
## 简介<a name="section11660541533"></a>
该仓下主要展示了一些驱动示例。
## 目录<a name="section161941989586"></a>
该仓下源代码目录结构如下所示
```
/vendor/huawei/hdf
└── sample # 示例驱动
├── config # 驱动配置
└── platform # 平台示例驱动代码
```
## 相关仓<a name="section1371113476308"></a>
驱动子系统
hmf/drivers/framework
hmf/drivers/adapter\_lite\_khdf
hmf/drivers/adapter\_lite\_uhdf
hmf/drivers/adapter\_linux\_khdf
hmf/drivers/adapter\_linux\_uhdf
-13
View File
@@ -1,13 +0,0 @@
config DRIVERS_HDF_LCD
bool "Enable HDF Lcd driver"
default n
depends on DRIVERS_HDF
help
Answer Y to enable HDF Lcd driver.
config DRIVERS_HDF_LCD_ICN9700
bool "Enable HDF Lcd Icn9700 driver"
default n
depends on DRIVERS_HDF_LCD
help
Answer Y to enable HDF Lcd Icn9700 driver.
-44
View File
@@ -1,44 +0,0 @@
# Copyright (c) 2020 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/lite/config/component/lite_component.gni")
copy("display_layer") {
sources = [
"../../../libs/${board_name}/libdisplay_layer.so",
]
outputs = [ "$root_out_dir/libdisplay_layer.so" ]
}
copy("display_gfx") {
sources = [
"../../../libs/${board_name}/libdisplay_gfx.so",
]
outputs = [ "$root_out_dir/libdisplay_gfx.so" ]
}
copy("display_gralloc") {
sources = [
"../../../libs/${board_name}/libdisplay_gralloc.so",
]
outputs = [ "$root_out_dir/libdisplay_gralloc.so" ]
}
group("hi35xx_display") {
deps = [
":display_layer",
":display_gfx",
":display_gralloc",
]
}
-82
View File
@@ -1,82 +0,0 @@
# Copyright (c) 2020 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
LITEOS_BASELIB += -lhdf_config
ifeq ($(findstring y, $(LOSCFG_PLATFORM_HI3518EV300)$(LOSCFG_PLATFORM_HI3516DV300)), y)
LIB_SUBDIRS += $(LITEOS_SOURCE_ROOT)/vendor/hisi/hi35xx/$(LITEOS_PLATFORM)/config
VENDOR_HDF_DRIVERS_PLATFORM_ROOT := $(LITEOSTOPDIR)/../../vendor/hisi/hi35xx/platform
else ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
LIB_SUBDIRS += $(LITEOS_SOURCE_ROOT)/device/qemu/arm/$(LITEOS_PLATFORM)/config
VENDOR_HDF_DRIVERS_PLATFORM_ROOT := $(LITEOSTOPDIR)/../../device/qemu/arm/platform
LITEOS_BASELIB += -lcfiflash
LIB_SUBDIRS += $(LITEOS_SOURCE_ROOT)/device/qemu/arm/$(LITEOS_PLATFORM)/config/cfiflash
else
$(error "No valid vendor paths added to LIB_SUBDIRS")
endif
VENDOR_HDF_DRIVERS_ROOT := $(LITEOSTOPDIR)/../../vendor/huawei/hdf
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_I2C), y)
LITEOS_BASELIB += -lhdf_i2c
endif
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_SPI), y)
LITEOS_BASELIB += -lhdf_spi
endif
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_GPIO), y)
LITEOS_BASELIB += -lhdf_gpio
endif
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG), y)
LITEOS_BASELIB += -lhdf_watchdog
endif
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_SDIO), y)
LITEOS_BASELIB += -lhdf_sdio
endif
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_RTC), y)
LITEOS_BASELIB += -lhdf_rtc
endif
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_UART), y)
LITEOS_BASELIB += -lhdf_uart
endif
ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK), y)
LITEOS_BASELIB += -lhdf_hisi_sdk
endif
ifeq ($(LOSCFG_DRIVERS_HDF_WIFI), y)
LITEOS_BASELIB += -lhdf_vendor_wifi
ifeq ($(LOSCFG_DRIVERS_HI3881), y)
LITEOS_BASELIB += -lhi3881
endif
endif
ifeq ($(LOSCFG_DRIVERS_HDF_INPUT), y)
LITEOS_BASELIB += -lhdf_input_driver
endif
ifeq ($(LOSCFG_DRIVERS_HDF_LCD), y)
LITEOS_BASELIB += -lhdf_lcd_driver
endif
# lib path
LITEOS_LD_PATH += -L$(VENDOR_HDF_DRIVERS_PLATFORM_ROOT)/libs/$(LITEOS_PLATFORM)
LITEOS_LD_PATH += -L$(VENDOR_HDF_DRIVERS_ROOT)/libs/$(LITEOS_PLATFORM)
-14
View File
@@ -1,14 +0,0 @@
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.
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+20
View File
@@ -17,6 +17,16 @@ root {
platform :: host {
hostName = "platform_host";
priority = 50;
device_gpio :: device {
device1 :: deviceNode {
policy = 2;
priority = 10;
permission = 0660;
moduleName = "GPIO_SAMPLE";
serviceName = "GPIO_SAMPLE";
deviceMatchAttr = "sample_gpio";
}
}
device_uart :: device {
device5 :: deviceNode {
policy = 2;
@@ -27,6 +37,16 @@ root {
deviceMatchAttr = "sample_uart_5";
}
}
device_spi :: device {
device3 :: deviceNode {
policy = 2;
priority = 60;
permission = 0660;
moduleName = "SPI_SAMPLE";
serviceName = "HDF_PLATFORM_SPI_3";
deviceMatchAttr = "sample_spi_3";
}
}
}
}
}
+29
View File
@@ -0,0 +1,29 @@
// Copyright 2020 Huawei Device Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
root {
platform {
gpio_config {
gpio_sample {
match_attr = "sample_gpio";
groupNum = 12;
bitNum = 8;
regBase = 0x120d0000;
regStep = 0x1000;
irqStart = 48;
irqShare = 0;
}
}
}
}
+33
View File
@@ -0,0 +1,33 @@
// Copyright 2020 Huawei Device Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
root {
platform {
spi_config {
spi_sample {
serviceName = "SPI_SAMPLE";
match_attr = "sample_spi_3";
transferMode = 0;
busNum = 0;
clkRate = 100000000;
bitsPerWord = 8;
mode = 19;
speed = 2000000;
fifoSize = 256;
numCs = 1;
regBase = 0x120c0000;
}
}
}
}
View File
+2 -5
View File
@@ -13,9 +13,6 @@
import("//build/lite/config/component/lite_component.gni")
copy("hdi_input") {
sources = [
"../../libs/${board_name}/libhdi_input.so",
]
outputs = [ "$root_out_dir/libhdi_input.so" ]
lite_component("hello_gpio_sample") {
features = [ "dispatch:hello_gpio_dispatch" ]
}
+16 -15
View File
@@ -11,18 +11,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/lite/config/component/lite_component.gni")
if (board_name == "hi3516dv300" || board_name == "hi3518ev300") {
group("hdi_display") {
public_deps = [
"//vendor/huawei/hdf/display/hdi/hi35xx:hi35xx_display",
]
}
}
if (board_name == "sun8i") {
group("hdi_display") {
public_deps = [
"//vendor/allwinner/sun8i/hdi:v3s_display",
]
}
}
include $(LITEOSTOPDIR)/config.mk
include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk
MODULE_NAME := hdf_gpio_sample
LOCAL_CFLAGS += $(HDF_INCLUDE)
LOCAL_SRCS += src/gpio_sample.c \
src/gpio_pl061_sample.c \
src/gpio_dispatch_sample.c \
LOCAL_INCLUDE := ./include
LOCAL_CFLAGS += -fstack-protector-strong
include $(HDF_DRIVER)
+51
View File
@@ -0,0 +1,51 @@
# Copyright (c) 2020 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
HDF_FRAMEWORKS = "//drivers/framework"
executable("hello_gpio_dispatch") {
sources = [
"gpio_if.c",
"hello_gpio_dispatch.c",
]
include_dirs = [
"$HDF_FRAMEWORKS/ability/sbuf/include",
"$HDF_FRAMEWORKS/core/shared/include",
"$HDF_FRAMEWORKS/core/host/include",
"$HDF_FRAMEWORKS/core/master/include",
"$HDF_FRAMEWORKS/include/core",
"$HDF_FRAMEWORKS/include/utils",
"$HDF_FRAMEWORKS/utils/include",
"$HDF_FRAMEWORKS/include/osal",
"//drivers/adapter/uhdf/posix/include",
"//third_party/bounds_checking_function/include",
"//base/hiviewdfx/hilog_lite/interfaces/native/innerkits",
]
deps = [
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
"//drivers/adapter/uhdf/manager:hdf_core",
"//drivers/adapter/uhdf/posix:hdf_posix_osal",
]
public_deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
defines = [ "__USER__" ]
cflags = [
"-Wall",
"-Wextra",
"-Wno-format",
"-Wno-format-extra-args",
]
}
+135
View File
@@ -0,0 +1,135 @@
/* Copyright 2020 Huawei Device Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gpio_if.h"
#include "hdf_log.h"
#include "hdf_io_service_if.h"
#define HDF_LOG_TAG gpio_if
static struct HdfIoService *GetIoService()
{
static struct HdfIoService *ioService = NULL;
if (ioService != NULL) {
return ioService;
}
ioService = HdfIoServiceBind(GPIO_SERVICE_NAME);
if (ioService == NULL) {
HDF_LOGE("Failed to get service %{public}s", GPIO_SERVICE_NAME);
}
return ioService;
}
static int32_t GpioOperate(enum GpioOps ops, uint16_t gpio, uint16_t val)
{
int ret = HDF_FAILURE;
struct HdfIoService *service = GetIoService();
if (service == NULL) {
return ret;
}
struct HdfSBuf *data = HdfSBufObtainDefaultSize();
if (data == NULL) {
HDF_LOGE("Failed to obtain sBuf");
return ret;
}
if (!HdfSbufWriteUint16(data, gpio) || !HdfSbufWriteUint16(data, val)) {
HDF_LOGE("Failed to write sBuf");
HdfSBufRecycle(data);
return HDF_FAILURE;
}
ret = service->dispatcher->Dispatch(&service->object, ops, data, NULL);
if (ret != HDF_SUCCESS) {
HDF_LOGE("Failed to send service call, ret: %{public}d", ret);
}
HdfSBufRecycle(data);
return ret;
}
static int32_t GpioQuery(enum GpioOps ops, uint16_t gpio, uint16_t *val)
{
int ret = HDF_FAILURE;
struct HdfIoService *service = GetIoService();
if (service == NULL) {
return ret;
}
struct HdfSBuf *data = HdfSBufObtainDefaultSize();
struct HdfSBuf *reply = HdfSBufObtainDefaultSize();
if (data == NULL || reply == NULL) {
HDF_LOGE("Failed to obtain sBuf");
return ret;
}
if (!HdfSbufWriteUint16(data, gpio)) {
HDF_LOGE("Failed to write data sBuf");
goto __ERR__;
}
ret = service->dispatcher->Dispatch(&service->object, ops, data, reply);
if (ret != HDF_SUCCESS) {
HDF_LOGE("Failed to send service call");
goto __ERR__;
}
if (!HdfSbufReadUint16(reply, val)) {
HDF_LOGE("Failed to read reply sBuf");
goto __ERR__;
}
goto __ERR__;
__ERR__:
HdfSBufRecycle(data);
HdfSBufRecycle(reply);
return ret;
}
int32_t GpioOpen()
{
struct HdfIoService *ioService = GetIoService();
if (ioService == NULL) {
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
int32_t GpioSetDir(uint16_t gpio, uint16_t dir)
{
return GpioOperate(GPIO_OPS_SET_DIR, gpio, dir);
}
int32_t GpioGetDir(uint16_t gpio, uint16_t *dir)
{
return GpioQuery(GPIO_OPS_GET_DIR, gpio, dir);
}
int32_t GpioWrite(uint16_t gpio, uint16_t val)
{
return GpioOperate(GPIO_OPS_WRITE, gpio, val);
}
int32_t GpioRead(uint16_t gpio, uint16_t *val)
{
return GpioQuery(GPIO_OPS_READ, gpio, val);
}
int32_t GpioClose()
{
struct HdfIoService *ioService = GetIoService();
if (ioService == NULL) {
return HDF_FAILURE;
}
HdfIoServiceRecycle(ioService);
return HDF_SUCCESS;
}
+49
View File
@@ -0,0 +1,49 @@
/* Copyright 2020 Huawei Device Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GPIO_IF_H
#define GPIO_IF_H
#include <stdint.h>
#define GPIO_SERVICE_NAME "GPIO_SAMPLE"
enum GpioValue {
GPIO_VAL_LOW = 0,
GPIO_VAL_HIGH = 1,
GPIO_VAL_ERR,
};
enum GpioDirType {
GPIO_DIR_IN = 0,
GPIO_DIR_OUT = 1,
GPIO_DIR_ERR,
};
enum GpioOps {
GPIO_OPS_SET_DIR = 1,
GPIO_OPS_GET_DIR,
GPIO_OPS_WRITE,
GPIO_OPS_READ
};
int32_t GpioOpen();
int32_t GpioClose();
int32_t GpioSetDir(uint16_t gpio, uint16_t dir);
int32_t GpioGetDir(uint16_t gpio, uint16_t *dir);
int32_t GpioWrite(uint16_t gpio, uint16_t val);
int32_t GpioRead(uint16_t gpio, uint16_t *val);
#endif // GPIO_IF_H
@@ -0,0 +1,53 @@
/* Copyright 2020 Huawei Device Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gpio_if.h"
#include "hdf_log.h"
#include "hdf_base.h"
#define HDF_LOG_TAG hello_gpio_dispatch
#define GPIO_PIN 11
int main()
{
uint16_t dir;
uint16_t val;
if (GpioOpen() != HDF_SUCCESS) {
HDF_LOGE("%{public}s: GpioOpen failed", __func__);
return HDF_FAILURE;
}
if (GpioSetDir(GPIO_PIN, GPIO_DIR_IN) != HDF_SUCCESS) {
HDF_LOGE("%{public}s: GpioSetDir failed, gpio %{public}u, dir %{public}u", __func__, GPIO_PIN, GPIO_DIR_IN);
return HDF_FAILURE;
}
if (GpioWrite(GPIO_PIN, GPIO_VAL_HIGH) != HDF_SUCCESS) {
HDF_LOGE("%{public}s: GpioWrite failed, gpio %{public}u, val %{public}u", __func__, GPIO_PIN, GPIO_VAL_HIGH);
return HDF_FAILURE;
}
if (GpioGetDir(GPIO_PIN, &dir) != HDF_SUCCESS) {
HDF_LOGE("%{public}s: GpioGetDir failed, gpio %{public}u", __func__, GPIO_PIN);
return HDF_FAILURE;
}
if (GpioRead(GPIO_PIN, &val) != HDF_SUCCESS) {
HDF_LOGE("%{public}s: GpioRead failed, gpio %{public}u", __func__, GPIO_PIN);
return HDF_FAILURE;
}
if (GpioClose() != HDF_SUCCESS) {
HDF_LOGE("%{public}s: GpioClose failed", __func__);
return HDF_FAILURE;
}
HDF_LOGD("GPIO %{public}u direction is set to %{public}u, value is set to %{public}u", GPIO_PIN, dir, val);
return HDF_SUCCESS;
}
@@ -0,0 +1,30 @@
/* Copyright 2020 Huawei Device Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GPIO_DISPATCH_SAMPLE_H
#define GPIO_DISPATCH_SAMPLE_H
#include "gpio_pl061_sample.h"
enum GpioOps {
GPIO_OPS_SET_DIR = 1,
GPIO_OPS_GET_DIR,
GPIO_OPS_WRITE,
GPIO_OPS_READ
};
int32_t SampleGpioDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply);
#endif // GPIO_DISPATCH_SAMPLE_H
@@ -0,0 +1,82 @@
/* Copyright 2020 Huawei Device Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GPIO_PL061_SAMPLE_H
#define GPIO_PL061_SAMPLE_H
#include "gpio_core.h"
#include "gpio_if.h"
#include "osal.h"
#define GROUP_MAX 32
#define BIT_MAX 16
#define GPIO_DATA(base, bit) ((base) + 0x000 + (1 << ((bit) + 2)))
#define GPIO_DIR(base) ((base) + 0x400)
#define GPIO_IS(base) ((base) + 0x404)
#define GPIO_IBE(base) ((base) + 0x408)
#define GPIO_IEV(base) ((base) + 0x40C)
#define GPIO_IE(base) ((base) + 0x410)
#define GPIO_RIS(base) ((base) + 0x414)
#define GPIO_MIS(base) ((base) + 0x418)
#define GPIO_IC(base) ((base) + 0x41C)
struct GpioGroup {
volatile unsigned char *regBase;
unsigned int index;
OsalSpinlock lock;
};
struct Pl061GpioCntlr {
struct GpioCntlr cntlr;
volatile unsigned char *regBase;
uint32_t phyBase;
uint32_t regStep;
uint32_t irqStart;
uint16_t groupNum;
uint16_t bitNum;
uint8_t irqShare;
struct GpioGroup *groups;
};
static struct Pl061GpioCntlr g_samplePl061GpioCntlr = {
.groups = NULL,
.groupNum = GROUP_MAX,
.bitNum = BIT_MAX,
};
static inline struct Pl061GpioCntlr *ToPl061GpioCntlr(struct GpioCntlr *cntlr)
{
return (struct Pl061GpioCntlr *)cntlr;
}
static inline uint16_t Pl061ToGroupNum(uint16_t gpio)
{
return (uint16_t)(gpio / g_samplePl061GpioCntlr.bitNum);
}
static inline uint16_t Pl061ToBitNum(uint16_t gpio)
{
return (uint16_t)(gpio % g_samplePl061GpioCntlr.bitNum);
}
static inline uint16_t Pl061ToGpioNum(uint16_t group, uint16_t bit)
{
return (uint16_t)(group * g_samplePl061GpioCntlr.bitNum + bit);
}
int32_t Pl061GetGroupByGpioNum(struct GpioCntlr *cntlr, uint16_t gpio,
struct GpioGroup **group);
#endif // GPIO_PL061_SAMPLE_H
@@ -0,0 +1,126 @@
/* Copyright 2020 Huawei Device Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gpio_dispatch_sample.h"
#define HDF_LOG_TAG gpio_dispatch_sample
static int32_t SampleGpioSetDir(struct GpioCntlr *cntlr, struct HdfSBuf *data)
{
uint16_t gpio;
uint16_t dir;
if (!HdfSbufReadUint16(data, &gpio) || !HdfSbufReadUint16(data, &dir)) {
HDF_LOGE("%{public}s: HdfSbufReadUint16 failed", __func__);
return HDF_ERR_INVALID_PARAM;
}
if (cntlr->ops->setDir == NULL) {
HDF_LOGE("%{public}s: cntlr->ops->setDir is NULL", __func__);
return HDF_DEV_ERR_OP;
}
return cntlr->ops->setDir(cntlr, gpio, dir);
}
static int32_t SampleGpioGetDir(struct GpioCntlr *cntlr, struct HdfSBuf *data, struct HdfSBuf *reply)
{
int32_t ret;
uint16_t gpio;
uint16_t dir;
if (!HdfSbufReadUint16(data, &gpio)) {
HDF_LOGE("%{public}s: HdfSbufReadUint16 failed", __func__);
return HDF_ERR_INVALID_PARAM;
}
if (cntlr->ops->getDir == NULL) {
HDF_LOGE("%{public}s: cntlr->ops->getDir is NULL", __func__);
return HDF_DEV_ERR_OP;
}
ret = cntlr->ops->getDir(cntlr, gpio, &dir);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: cntlr->ops->getDir failed, ret: %{public}d", __func__, ret);
return ret;
}
if (!HdfSbufWriteUint16(reply, dir)) {
HDF_LOGE("%{public}s: HdfSbufWriteUint16 failed", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t SampleGpioWrite(struct GpioCntlr *cntlr, struct HdfSBuf *data)
{
uint16_t gpio;
uint16_t val;
if (!HdfSbufReadUint16(data, &gpio) || !HdfSbufReadUint16(data, &val)) {
HDF_LOGE("%{public}s: HdfSbufReadUint16 failed", __func__);
return HDF_ERR_INVALID_PARAM;
}
if (cntlr->ops->write == NULL) {
HDF_LOGE("%{public}s: cntlr->ops->read is NULL", __func__);
return HDF_DEV_ERR_OP;
}
return cntlr->ops->write(cntlr, gpio, val);
}
static int32_t SampleGpioRead(struct GpioCntlr *cntlr, struct HdfSBuf *data, struct HdfSBuf *reply)
{
int32_t ret;
uint16_t gpio;
uint16_t val;
if (!HdfSbufReadUint16(data, &gpio)) {
HDF_LOGE("%{public}s: HdfSbufReadUint16 failed", __func__);
return HDF_ERR_INVALID_PARAM;
}
if (cntlr->ops->read == NULL) {
HDF_LOGE("%{public}s: cntlr->ops->read is NULL", __func__);
return HDF_DEV_ERR_OP;
}
ret = cntlr->ops->read(cntlr, gpio, &val);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: cntlr->ops->read failed, ret: %{public}d", __func__, ret);
return ret;
}
if (!HdfSbufWriteUint16(reply, val)) {
HDF_LOGE("%{public}s: HdfSbufWriteUint16 failed", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
int32_t SampleGpioDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply)
{
if (client == NULL || client->device == NULL) {
HDF_LOGE("%{public}s: client or client->device is NULL", __func__);
return HDF_ERR_INVALID_PARAM;
}
struct GpioCntlr *cntlr = (struct GpioCntlr *)client->device->service;
if (cntlr == NULL || cntlr->ops == NULL) {
HDF_LOGE("%{public}s: cntlr or cntlr->ops is NULL", __func__);
return HDF_ERR_INVALID_PARAM;
}
switch (cmdId) {
case GPIO_OPS_SET_DIR:
return SampleGpioSetDir(cntlr, data);
case GPIO_OPS_GET_DIR:
return SampleGpioGetDir(cntlr, data, reply);
case GPIO_OPS_WRITE:
return SampleGpioWrite(cntlr, data);
case GPIO_OPS_READ:
return SampleGpioRead(cntlr, data, reply);
default:
HDF_LOGE("%{public}s: invalid cmdId %{public}d", __func__, cmdId);
return HDF_FAILURE;
}
}
@@ -0,0 +1,37 @@
/* Copyright 2020 Huawei Device Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gpio_pl061_sample.h"
#include "osal_irq.h"
#define HDF_LOG_TAG gpio_pl061_sample
int32_t Pl061GetGroupByGpioNum(struct GpioCntlr *cntlr, uint16_t gpio, struct GpioGroup **group)
{
struct Pl061GpioCntlr *pl061 = NULL;
uint16_t groupIndex = Pl061ToGroupNum(gpio);
if (cntlr == NULL) {
HDF_LOGE("%{public}s: cntlr is NULL", __func__);
return HDF_ERR_INVALID_OBJECT;
}
pl061 = ToPl061GpioCntlr(cntlr);
if (groupIndex >= pl061->groupNum) {
HDF_LOGE("%{public}s: err group index:%{public}u", __func__, groupIndex);
return HDF_ERR_INVALID_PARAM;
}
*group = &pl061->groups[groupIndex];
return HDF_SUCCESS;
}
+366
View File
@@ -0,0 +1,366 @@
/* Copyright 2020 Huawei Device Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gpio_dispatch_sample.h"
#include "gpio_pl061_sample.h"
#include "device_resource_if.h"
#include "hdf_device_desc.h"
#include "gpio_if.h"
#include "osal.h"
#include "osal_io.h"
#include "gpio_core.h"
#define HDF_LOG_TAG gpio_sample
/* HdfDriverEntry hook function prototypes */
static int32_t SampleGpioDriverBind(struct HdfDeviceObject *device);
static int32_t SampleGpioDriverInit(struct HdfDeviceObject *device);
static void SampleGpioDriverRelease(struct HdfDeviceObject *device);
/* HdfDriverEntry definition */
struct HdfDriverEntry g_sampleGpioDriverEntry = {
.moduleVersion = 1,
.moduleName = "GPIO_SAMPLE",
.Bind = SampleGpioDriverBind,
.Init = SampleGpioDriverInit,
.Release = SampleGpioDriverRelease,
};
/* Init HdfDriverEntry */
HDF_INIT(g_sampleGpioDriverEntry);
/* GPIO function prototypes */
static int32_t SampleGpioWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val);
static int32_t SampleGpioRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val);
static int32_t SampleGpioSetDirection(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t dir);
static int32_t SampleGpioGetDirection(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *dir);
/* GpioMethod definition */
struct GpioMethod g_sampleGpioMethod = {
.request = NULL,
.release = NULL,
.write = SampleGpioWrite,
.read = SampleGpioRead,
.setDir = SampleGpioSetDirection,
.getDir = SampleGpioGetDirection,
.toIrq = NULL,
.setIrq = NULL,
.unsetIrq = NULL,
.enableIrq = NULL,
.disableIrq = NULL,
};
/* Private function prototypes */
/* Read GPIO device resource */
static int32_t GetGpioDeviceResource(struct Pl061GpioCntlr *cntlr, const struct DeviceResourceNode *node);
/* Init GPIO controller memory */
static int32_t InitGpioCntlrMem(struct Pl061GpioCntlr *cntlr);
/* Release GPIO controller memory */
static void ReleaseGpioCntlrMem(struct Pl061GpioCntlr *cntlr);
/* HdfDriverEntry hook function implementations */
static int32_t SampleGpioDriverBind(struct HdfDeviceObject *device)
{
HDF_LOGD("%{public}s: Enter", __func__);
struct Pl061GpioCntlr *pl061Cntlr = &g_samplePl061GpioCntlr;
pl061Cntlr->cntlr.device = device;
device->service = &(pl061Cntlr->cntlr.service);
pl061Cntlr->cntlr.device->service->Dispatch = SampleGpioDispatch;
return HDF_SUCCESS;
}
static int32_t SampleGpioDriverInit(struct HdfDeviceObject *device)
{
int32_t ret;
struct Pl061GpioCntlr *pl061Cntlr = &g_samplePl061GpioCntlr;
HDF_LOGD("%{public}s: Enter", __func__);
if (device == NULL || device->property == NULL) {
HDF_LOGE("%{public}s: device or property NULL!", __func__);
return HDF_ERR_INVALID_OBJECT;
}
ret = GetGpioDeviceResource(pl061Cntlr, device->property);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: get gpio device resource fail:%{public}d", __func__, ret);
return ret;
}
if (pl061Cntlr->groupNum > GROUP_MAX || pl061Cntlr->groupNum <= 0 || pl061Cntlr->bitNum > BIT_MAX ||
pl061Cntlr->bitNum <= 0) {
HDF_LOGE("%{public}s: invalid groupNum:%{public}u or bitNum:%{public}u", __func__, pl061Cntlr->groupNum,
pl061Cntlr->bitNum);
return HDF_ERR_INVALID_PARAM;
}
pl061Cntlr->regBase = OsalIoRemap(pl061Cntlr->phyBase, pl061Cntlr->groupNum * pl061Cntlr->regStep);
if (pl061Cntlr->regBase == NULL) {
HDF_LOGE("%{public}s: err remap phy:0x%{public}x", __func__, pl061Cntlr->phyBase);
return HDF_ERR_IO;
}
ret = InitGpioCntlrMem(pl061Cntlr);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: err init cntlr mem:%{public}d", __func__, ret);
OsalIoUnmap((void *)pl061Cntlr->regBase);
pl061Cntlr->regBase = NULL;
return ret;
}
pl061Cntlr->cntlr.count = pl061Cntlr->groupNum * pl061Cntlr->bitNum;
pl061Cntlr->cntlr.priv = (void *)device->property;
pl061Cntlr->cntlr.ops = &g_sampleGpioMethod;
ret = GpioCntlrAdd(&pl061Cntlr->cntlr);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: err add controller: %{public}d", __func__, ret);
return ret;
}
HDF_LOGI("%{public}s: dev service:%{public}s init success!", __func__, HdfDeviceGetServiceName(device));
return ret;
}
static void SampleGpioDriverRelease(struct HdfDeviceObject *device)
{
struct GpioCntlr *gpioCntlr = NULL;
struct Pl061GpioCntlr *pl061GpioCntlr = NULL;
HDF_LOGD("%{public}s: Enter", __func__);
if (device == NULL) {
HDF_LOGE("%{public}s: device is null!", __func__);
return;
}
gpioCntlr = GpioCntlrFromDevice(device);
if (gpioCntlr == NULL) {
HDF_LOGE("%{public}s: no service bound!", __func__);
return;
}
GpioCntlrRemove(gpioCntlr);
pl061GpioCntlr = (struct Pl061GpioCntlr *)gpioCntlr;
ReleaseGpioCntlrMem(pl061GpioCntlr);
OsalIoUnmap((void *)pl061GpioCntlr->regBase);
pl061GpioCntlr->regBase = NULL;
}
/* Private function implementations */
static int32_t GetGpioDeviceResource(struct Pl061GpioCntlr *cntlr, const struct DeviceResourceNode *node)
{
int32_t ret;
struct DeviceResourceIface *dri = NULL;
dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
if (dri == NULL || dri->GetUint8 == NULL || dri->GetUint16 == NULL || dri->GetUint32 == NULL) {
HDF_LOGE("%{public}s: invalid dri ops fail!", __func__);
return HDF_FAILURE;
}
ret = dri->GetUint32(node, "regBase", &cntlr->phyBase, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: read regBase fail!", __func__);
return ret;
}
ret = dri->GetUint32(node, "regStep", &cntlr->regStep, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: read regStep fail!", __func__);
return ret;
}
ret = dri->GetUint16(node, "groupNum", &cntlr->groupNum, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: read groupNum fail!", __func__);
return ret;
}
ret = dri->GetUint16(node, "bitNum", &cntlr->bitNum, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: read bitNum fail!", __func__);
return ret;
}
ret = dri->GetUint32(node, "irqStart", &cntlr->irqStart, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: read irqStart fail!", __func__);
return ret;
}
ret = dri->GetUint8(node, "irqShare", &cntlr->irqShare, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: read irqShare fail!", __func__);
return ret;
}
return HDF_SUCCESS;
}
static int32_t InitGpioCntlrMem(struct Pl061GpioCntlr *cntlr)
{
size_t groupMemSize;
struct GpioGroup *groups = NULL;
if (cntlr == NULL) {
return HDF_ERR_INVALID_PARAM;
}
groupMemSize = sizeof(struct GpioGroup) * cntlr->groupNum;
groups = (struct GpioGroup *)OsalMemCalloc(groupMemSize);
if (groups == NULL) {
return HDF_ERR_MALLOC_FAIL;
}
cntlr->groups = groups;
for (uint16_t i = 0; i < cntlr->groupNum; i++) {
groups[i].index = i;
groups[i].regBase = cntlr->regBase + (i * cntlr->regStep);
if (OsalSpinInit(&groups[i].lock) != HDF_SUCCESS) {
for (; i > 0; i--) {
(void)OsalSpinDestroy(&groups[i - 1].lock);
}
OsalMemFree(groups);
return HDF_FAILURE;
}
}
return HDF_SUCCESS;
}
static void ReleaseGpioCntlrMem(struct Pl061GpioCntlr *cntlr)
{
if (cntlr == NULL) {
return;
}
if (cntlr->groups != NULL) {
for (uint16_t i = 0; i < cntlr->groupNum; i++) {
(void)OsalSpinDestroy(&cntlr->groups[i].lock);
}
OsalMemFree(cntlr->groups);
cntlr->groups = NULL;
}
}
/* GPIO function implementations */
static int32_t SampleGpioWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val)
{
HDF_LOGD("%{public}s: Enter", __func__);
int32_t ret;
uint32_t irqSave;
unsigned int valCur;
unsigned int bitNum = Pl061ToBitNum(gpio);
volatile unsigned char *addr = NULL;
struct GpioGroup *group = NULL;
ret = Pl061GetGroupByGpioNum(cntlr, gpio, &group);
if (ret != HDF_SUCCESS) {
return ret;
}
addr = GPIO_DATA(group->regBase, bitNum);
if (OsalSpinLockIrqSave(&group->lock, &irqSave) != HDF_SUCCESS) {
return HDF_ERR_DEVICE_BUSY;
}
valCur = OSAL_READL(addr);
if (val == GPIO_VAL_LOW) {
valCur &= ~(1 << bitNum);
} else {
valCur |= (1 << bitNum);
}
OSAL_WRITEL(valCur, addr);
(void)OsalSpinUnlockIrqRestore(&group->lock, &irqSave);
HDF_LOGD("%{public}s: gpio:%{public}u, val:%{public}u", __func__, gpio, val);
return HDF_SUCCESS;
}
static int32_t SampleGpioRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val)
{
HDF_LOGD("%{public}s: Enter", __func__);
int32_t ret;
unsigned int valCur;
volatile unsigned char *addr = NULL;
unsigned int bitNum = Pl061ToBitNum(gpio);
struct GpioGroup *group = NULL;
ret = Pl061GetGroupByGpioNum(cntlr, gpio, &group);
if (ret != HDF_SUCCESS) {
return ret;
}
addr = GPIO_DATA(group->regBase, bitNum);
valCur = OSAL_READL(addr);
if (valCur & (1 << bitNum)) {
*val = GPIO_VAL_HIGH;
} else {
*val = GPIO_VAL_LOW;
}
HDF_LOGD("%{public}s: gpio:%{public}u, val:%{public}u", __func__, gpio, *val);
return HDF_SUCCESS;
}
static int32_t SampleGpioSetDirection(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t dir)
{
HDF_LOGD("%{public}s: Enter", __func__);
int32_t ret;
uint32_t irqSave;
unsigned int val;
volatile unsigned char *addr = NULL;
unsigned int bitNum = Pl061ToBitNum(gpio);
struct GpioGroup *group = NULL;
HDF_LOGD("%{public}s: gpio:%{public}u, dir:%{public}d", __func__, gpio, dir);
ret = Pl061GetGroupByGpioNum(cntlr, gpio, &group);
if (ret != HDF_SUCCESS) {
return ret;
}
addr = GPIO_DIR(group->regBase);
if (OsalSpinLockIrqSave(&group->lock, &irqSave) != HDF_SUCCESS) {
return HDF_ERR_DEVICE_BUSY;
}
val = OSAL_READL(addr);
if (dir == GPIO_DIR_IN) {
val &= ~(1 << bitNum);
} else if (dir == GPIO_DIR_OUT) {
val |= 1 << bitNum;
}
OSAL_WRITEL(val, addr);
(void)OsalSpinUnlockIrqRestore(&group->lock, &irqSave);
return HDF_SUCCESS;
}
static int32_t SampleGpioGetDirection(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *dir)
{
HDF_LOGD("%{public}s: Enter", __func__);
int32_t ret;
unsigned int val;
volatile unsigned char *addr = NULL;
unsigned int bitNum = Pl061ToBitNum(gpio);
struct GpioGroup *group = NULL;
HDF_LOGD("%{public}s: gpio:%{public}u, dir:%{public}d", __func__, gpio, dir);
ret = Pl061GetGroupByGpioNum(cntlr, gpio, &group);
if (ret != HDF_SUCCESS) {
return ret;
}
addr = GPIO_DIR(group->regBase);
val = OSAL_READL(addr);
if (val & (1 << bitNum)) {
*dir = GPIO_DIR_OUT;
} else {
*dir = GPIO_DIR_IN;
}
return HDF_SUCCESS;
}
+2 -8
View File
@@ -13,12 +13,6 @@
import("//build/lite/config/component/lite_component.gni")
copy("wifi_firmware") {
sources = [
"driver/firmware"
]
outputs = [
"$root_out_dir/vendor/{{source_file_part}}"
]
lite_component("hello_spi_sample") {
features = [ "dispatch:hello_spi_dispatch" ]
}
+29
View File
@@ -0,0 +1,29 @@
# Copyright (c) 2020 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
include $(LITEOSTOPDIR)/config.mk
include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk
MODULE_NAME := hdf_spi_sample
LOCAL_CFLAGS += $(HDF_INCLUDE)
LOCAL_SRCS += src/spi_sample.c \
src/spi_pl022_sample.c \
src/spi_dispatch_sample.c \
LOCAL_INCLUDE := ./include
LOCAL_CFLAGS += -fstack-protector-strong
include $(HDF_DRIVER)
+52
View File
@@ -0,0 +1,52 @@
# Copyright (c) 2020 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
HDF_FRAMEWORKS = "//drivers/framework"
executable("hello_spi_dispatch") {
sources = [
"hello_spi_dispatch.c",
"spi_if.c",
]
include_dirs = [
"$HDF_FRAMEWORKS/ability/sbuf/include",
"$HDF_FRAMEWORKS/core/shared/include",
"$HDF_FRAMEWORKS/core/host/include",
"$HDF_FRAMEWORKS/core/master/include",
"$HDF_FRAMEWORKS/include/core",
"$HDF_FRAMEWORKS/include/platform",
"$HDF_FRAMEWORKS/include/utils",
"$HDF_FRAMEWORKS/utils/include",
"$HDF_FRAMEWORKS/include/osal",
"//drivers/adapter/uhdf/posix/include",
"//third_party/bounds_checking_function/include",
"//base/hiviewdfx/hilog_lite/interfaces/native/innerkits",
]
deps = [
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
"//drivers/adapter/uhdf/manager:hdf_core",
"//drivers/adapter/uhdf/posix:hdf_posix_osal",
]
public_deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
defines = [ "__USER__" ]
cflags = [
"-Wall",
"-Wextra",
"-Wno-format",
"-Wno-format-extra-args",
]
}
@@ -0,0 +1,50 @@
/* Copyright 2020 Huawei Device Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "spi_if.h"
#include "hdf_log.h"
#define HDF_LOG_TAG hello_spi_dispatch
int main()
{
int32_t ret;
struct SpiDevInfo spiDevInfo; /* SPI device descriptor */
struct DevHandle *spiHandle = NULL; /* SPI device handle */
spiDevInfo.busNum = 3; /* SPI device bus number */
spiDevInfo.csNum = 0; /* SPI device CS number */
spiHandle = SpiOpen(&spiDevInfo);
if (spiHandle == NULL) {
HDF_LOGE("SpiOpen failed");
return HDF_FAILURE;
}
uint8_t wbuff[1] = {0x12};
uint8_t rbuff[1] = {0};
struct SpiMsg msg; /* Custom message to be transferred */
msg.wbuf = wbuff; /* Pointer to the data to write */
msg.rbuf = rbuff; /* Pointer to the data to read */
msg.len = 1; /* The length of the data to be read or written is 1 bits. */
msg.csChange = 1; /* Disable the CS before the next transfer. */
msg.delayUs = 0; /* No delay before the next transfer */
msg.speed = 115200; /* Speed of this transfer */
ret = SpiTransfer(spiHandle, &msg);
if (ret != HDF_SUCCESS) {
HDF_LOGE("SpiTransfer failed, ret %{public}d", ret);
return ret;
}
SpiClose(spiHandle);
return ret;
}
+94
View File
@@ -0,0 +1,94 @@
/* Copyright 2020 Huawei Device Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "spi_if.h"
#include "osal_mem.h"
#include "hdf_io_service_if.h"
#include "hdf_log.h"
#include "securec.h"
#define HDF_LOG_TAG spi_if
DevHandle SpiOpen(const struct SpiDevInfo *info)
{
int32_t ret;
void *devHandle = NULL;
uint32_t port;
char *serviceName = NULL;
if (info == NULL) {
HDF_LOGW("info is NULL");
return NULL;
}
port = info->busNum;
serviceName = (char *)OsalMemCalloc(MAX_DEV_NAME_SIZE + 1);
if (serviceName == NULL) {
HDF_LOGE("Failed to OsalMemCalloc serviceName");
return NULL;
}
ret = snprintf_s(serviceName, MAX_DEV_NAME_SIZE + 1, MAX_DEV_NAME_SIZE, SPI_DEV_SERVICE_NAME_PREFIX, port);
if (ret < 0) {
HDF_LOGE("Failed to snprintf_s");
OsalMemFree(serviceName);
return NULL;
}
devHandle = (void *)HdfIoServiceBind(serviceName);
OsalMemFree(serviceName);
return devHandle;
}
void SpiClose(DevHandle handle)
{
if (handle == NULL) {
HDF_LOGW("handle is NULL");
return;
}
struct HdfIoService *service = (struct HdfIoService *)handle;
HdfIoServiceRecycle(service);
OsalMemFree(handle);
}
int32_t SpiTransfer(DevHandle handle, struct SpiMsg *msgs)
{
int32_t ret;
if (handle == NULL || msgs == NULL) {
HDF_LOGW("handle or msgs is NULL");
return HDF_ERR_INVALID_PARAM;
}
struct HdfIoService *service = (struct HdfIoService *)handle;
if (service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
HDF_LOGE("service->dispatcher or service->dispatcher->Dispatch is NULL");
return HDF_FAILURE;
}
struct HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
if (sBuf == NULL) {
HDF_LOGE("Failed to obtain sBuf");
return HDF_FAILURE;
}
if (!HdfSbufWriteBuffer(sBuf, msgs, sizeof(struct SpiMsg))) {
HDF_LOGE("Failed to write sbuf");
HdfSBufRecycle(sBuf);
return HDF_FAILURE;
}
ret = service->dispatcher->Dispatch(&service->object, SPI_TRANSFER, sBuf, NULL);
if (ret != HDF_SUCCESS) {
HDF_LOGE("Failed to send service call");
}
HdfSBufRecycle(sBuf);
return ret;
}
+46
View File
@@ -0,0 +1,46 @@
/* Copyright 2020 Huawei Device Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SPI_IF_H
#define SPI_IF_H
#include "hdf_platform.h"
#define SPI_DEV_SERVICE_NAME_PREFIX "HDF_PLATFORM_SPI_%u"
#define MAX_DEV_NAME_SIZE 32
struct SpiDevInfo {
uint32_t busNum;
uint32_t csNum;
};
struct SpiMsg {
uint8_t *wbuf;
uint8_t *rbuf;
uint32_t len;
uint32_t speed;
uint16_t delayUs;
uint8_t csChange;
};
enum {
SPI_TRANSFER = 1
};
DevHandle SpiOpen(const struct SpiDevInfo *info);
void SpiClose(DevHandle handle);
int32_t SpiTransfer(DevHandle handle, struct SpiMsg *msgs);
#endif // SPI_IF_H
@@ -0,0 +1,28 @@
/* Copyright 2020 Huawei Device Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SPI_DISPATCH_SAMPLE_H
#define SPI_DISPATCH_SAMPLE_H
#include "spi_pl022_sample.h"
#include "spi_core.h"
enum {
SPI_TRANSFER = 1
};
int32_t SampleSpiDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply);
#endif // SPI_DISPATCH_SAMPLE_H
@@ -0,0 +1,125 @@
/* Copyright 2020 Huawei Device Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SPI_PL022_SAMPLE_H
#define SPI_PL022_SAMPLE_H
#include "spi_if.h"
#include "osal.h"
/* ********** spi reg offset define start *************** */
#define REG_SPI_PL022_CR0 0x00
#define SPI_PL022_CR0_SCR_SHIFT 8
#define SPI_PL022_CR0_SPH_SHIFT 7
#define SPI_PL022_CR0_SPO_SHIFT 6
#define SPI_PL022_CR0_FRF_SHIFT 4
#define SPI_PL022_CR0_DSS_SHIFT 0
#define SPI_PL022_CR0_SCR (0xff << 8) /* clkout=clk/(cpsdvsr*(scr+1)) */
#define SPI_PL022_CR0_SPH (0x1 << 7) /* spi phase */
#define SPI_PL022_CR0_SPO (0x1 << 6) /* spi clk polarity */
#define SPI_PL022_CR0_FRF (0x3 << 4) /* frame format set */
#define SPI_PL022_CR0_DSS (0xf << 0) /* data bits width */
#define REG_SPI_PL022_CR1 0x04
#define SPI_PL022_CR1_WAIT_EN_SHIFT 15
#define SPI_PL022_CR1_WAIT_VAL_SHIFT 8
#define SPI_PL022_CR1_ALT_SHIFT 6
#define SPI_PL022_CR1_BIG_END_SHIFT 4
#define SPI_PL022_CR1_MS_SHIFT 2
#define SPI_PL022_CR1_SSE_SHIFT 1
#define SPI_PL022_CR1_LBN_SHIFT 0
#define SPI_PL022_CR1_WAIT_EN (0x1 << 15)
#define SPI_PL022_CR1_WAIT_VAL (0x7f << 8)
/* alt mode:spi enable csn is select; spi disable csn is cancel */
#define SPI_PL022_CR1_ALT (0x1 << 6)
#define SPI_PL022_CR1_BIG_END (0x1 << 4) /* big end or little */
#define SPI_PL022_CR1_MS (0x1 << 2) /* cntlr-device mode */
#define SPI_PL022_CR1_SSE (0x1 << 1) /* spi enable set */
#define SPI_PL022_CR1_LBM (0x1 << 0) /* loopback mode */
#define REG_SPI_PL022_DR 0x08
#define REG_SPI_PL022_SR 0x0c
#define SPI_PL022_SR_BSY_SHIFT 4
#define SPI_PL022_SR_RFF_SHIFT 3
#define SPI_PL022_SR_RNE_SHIFT 2
#define SPI_PL022_SR_TNF_SHIFT 1
#define SPI_PL022_SR_TFE_SHIFT 0
#define SPI_PL022_SR_BSY (0x1 << 4) /* spi busy flag */
#define SPI_PL022_SR_RFF (0x1 << 3) /* Whether to send fifo is full */
#define SPI_PL022_SR_RNE (0x1 << 2) /* Whether to send fifo is no empty */
#define SPI_PL022_SR_TNF (0x1 << 1) /* Whether to send fifo is no full */
#define SPI_PL022_SR_TFE (0x1 << 0) /* Whether to send fifo is empty */
#define REG_SPI_PL022_CPSR 0x10
#define SPI_PL022_CPSR_CPSDVSR_SHIFT 0
#define SPI_PL022_CPSR_CPSDVSR (0xff << 0) /* even 2~254 */
#define REG_SPI_PL022_IMSC 0x14
#define REG_SPI_PL022_RIS 0x18
#define REG_SPI_PL022_MIS 0x1c
#define REG_SPI_PL022_ICR 0x20
#define REG_SPI_CRG 0x120100e4 /* CRG_REG_BASE(0x12010000) + 0x0e4 */
#define SPI_CRG_CLK_EN 0
#define SPI_CRG_CLK_RST 0
#define REG_SPI_MISC_CTRL 0x12030024 /* MISC_REG_BASE(0x12030000) + 0x24 */
#define SPI_MISC_CTRL_CS 0
#define SPI_MISC_CTRL_CS_SHIFT 0
/* ********** spi reg offset define end *************** */
#define MAX_WAIT 5000
#define DEFAULT_SPEED 2000000
#define SCR_MAX 255
#define SCR_MIN 0
#define CPSDVSR_MAX 254
#define CPSDVSR_MIN 2
#define SPI_CS_ACTIVE 0
#define SPI_CS_INACTIVE 1
#define TWO_BYTES 2
#define BITS_PER_WORD_MIN 4
#define BITS_PER_WORD_DEFAULT 8
#define BITS_PER_WORD_MAX 16
struct Pl022SpiCntlr {
struct SpiCntlr *cntlr;
struct DListHead deviceList;
volatile unsigned char *regBase;
uint32_t busNum;
uint32_t numCs;
uint32_t curCs;
uint32_t speed;
uint32_t fifoSize;
uint32_t clkRate;
uint32_t maxSpeedHz;
uint32_t minSpeedHz;
uint32_t regCrg;
uint32_t clkEnBit;
uint32_t clkRstBit;
uint32_t regMiscCtrl;
uint32_t miscCtrlCsShift;
uint32_t miscCtrlCs;
uint16_t mode;
uint8_t bitsPerWord;
uint8_t transferMode;
};
int ConfigPl022SpiCntlr(struct Pl022SpiCntlr *cntlr);
int32_t TransferOneMessage(struct Pl022SpiCntlr *cntlr, struct SpiMsg *msg);
#endif // SPI_PL022_SAMPLE_H
+25
View File
@@ -0,0 +1,25 @@
/* Copyright 2020 Huawei Device Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SPI_SAMPLE_H
#define SPI_SAMPLE_H
#include "spi_core.h"
int32_t SampleSpiCntlrTransfer(struct SpiCntlr *cntlr, struct SpiMsg *msg, uint32_t count);
int32_t SampleSpiCntlrSetCfg(struct SpiCntlr *cntlr, struct SpiCfg *cfg);
int32_t SampleSpiCntlrGetCfg(struct SpiCntlr *cntlr, struct SpiCfg *cfg);
#endif // SPI_SAMPLE_H
@@ -0,0 +1,65 @@
/* Copyright 2020 Huawei Device Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "spi_dispatch_sample.h"
#include "spi_sample.h"
#include "hdf_log.h"
#include "hdf_sbuf.h"
#define HDF_LOG_TAG spi_dispatch_sample
static int32_t SampleSpiTransfer(struct SpiCntlr *cntlr, struct HdfSBuf *txBuf)
{
HDF_LOGD("%{public}s: Enter", __func__);
uint32_t readSize = sizeof(struct SpiMsg);
struct SpiMsg *msg = NULL;
if (cntlr == NULL || cntlr->priv == NULL || txBuf == NULL) {
HDF_LOGE("%{public}s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
if (!HdfSbufReadBuffer(txBuf, (const void **)&msg, &readSize)) {
HDF_LOGE("%{public}s: Failed to read sbuf", __func__);
return HDF_DEV_ERR_NO_MEMORY;
}
if (SampleSpiCntlrTransfer(cntlr, msg, msg->len) != HDF_SUCCESS) {
HDF_LOGE("%{public}s: SampleSpiCntlrTransfer error", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
int32_t SampleSpiDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply)
{
if (client == NULL || client->device == NULL) {
HDF_LOGE("%{public}s: client or client->device is NULL", __func__);
return HDF_FAILURE;
}
struct SpiCntlr *cntlr = (struct SpiCntlr *)client->device->service;
if (cntlr == NULL || cntlr->method == NULL) {
HDF_LOGE("%{public}s: cntlr or cntlr->method is NULL", __func__);
return HDF_FAILURE;
}
switch (cmdId) {
case SPI_TRANSFER:
return SampleSpiTransfer(cntlr, data);
default:
HDF_LOGE("%{public}s: invalid cmdId %{public}d", __func__, cmdId);
return HDF_FAILURE;
}
}
+344
View File
@@ -0,0 +1,344 @@
/* Copyright 2020 Huawei Device Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "spi_pl022_sample.h"
#include "osal_io.h"
#define HDF_LOG_TAG spi_pl022_sample
/* Private function prototypes */
static int Pl022SampleSetCs(struct Pl022SpiCntlr *cntlr, uint32_t cs, uint32_t flag);
static int Pl022SampleFlushFifo(const struct Pl022SpiCntlr *cntlr);
static int Pl022SampleTxRx8(const struct Pl022SpiCntlr *cntlr, const struct SpiMsg *msg);
static int Pl022SampleTxRx16(const struct Pl022SpiCntlr *cntlr, const struct SpiMsg *msg);
static void Pl022SampleEnableCntlr(const struct Pl022SpiCntlr *cntlr);
static void Pl022SampleConfigCPSR(const struct Pl022SpiCntlr *cntlr, uint32_t cpsdvsr);
static void Pl022SampleConfigCR0(const struct Pl022SpiCntlr *cntlr, uint32_t scr);
static void Pl022SampleConfigCR1(const struct Pl022SpiCntlr *cntlr);
static int32_t Pl022SampleCfgCs(struct Pl022SpiCntlr *cntlr, uint32_t cs);
static void Pl022SampleDisableCntlr(const struct Pl022SpiCntlr *cntlr);
static int Pl022SampleCheckTimeout(const struct Pl022SpiCntlr *cntlr);
int ConfigPl022SpiCntlr(struct Pl022SpiCntlr *cntlr)
{
uint32_t tmp;
uint32_t scr;
uint32_t cpsdvsr;
Pl022SampleEnableCntlr(cntlr);
/* Check if we can provide the requested rate */
if (cntlr->speed > cntlr->maxSpeedHz) {
cntlr->speed = cntlr->maxSpeedHz;
}
/* Min possible */
if ((cntlr->speed < cntlr->minSpeedHz) || (cntlr->speed == 0)) {
HDF_LOGE("%{public}s: cntlr->speed is %{public}u not support, max %{public}u, min %{public}u", __func__,
cntlr->speed, cntlr->maxSpeedHz, cntlr->minSpeedHz);
return HDF_FAILURE;
}
/* Check if we can provide the requested bits_per_word */
if ((cntlr->bitsPerWord < BITS_PER_WORD_MIN) || (cntlr->bitsPerWord > BITS_PER_WORD_MAX)) {
HDF_LOGE("%{public}s: cntlr->bitsPerWord is %{public}u not support", __func__, cntlr->bitsPerWord);
return HDF_FAILURE;
}
/* compute spi speed, speed=clk/(cpsdvsr*(scr+1)) */
tmp = (cntlr->clkRate) / (cntlr->speed);
if (tmp < CPSDVSR_MIN) {
cpsdvsr = CPSDVSR_MIN;
scr = 0;
} else if (tmp <= CPSDVSR_MAX) {
cpsdvsr = tmp & (~0x1);
scr = (tmp / cpsdvsr) - 1;
} else {
cpsdvsr = CPSDVSR_MAX;
scr = (tmp / cpsdvsr) - 1;
}
/* config SPICPSR register */
Pl022SampleConfigCPSR(cntlr, cpsdvsr);
/* config SPICR0 register */
Pl022SampleConfigCR0(cntlr, scr);
/* config SPICR1 register */
Pl022SampleConfigCR1(cntlr);
return HDF_SUCCESS;
}
int32_t TransferOneMessage(struct Pl022SpiCntlr *cntlr, struct SpiMsg *msg)
{
int32_t ret;
if (msg->speed != 0) {
cntlr->speed = msg->speed;
}
ret = ConfigPl022SpiCntlr(cntlr);
if (ret != HDF_SUCCESS) {
return ret;
}
ret = Pl022SampleSetCs(cntlr, cntlr->curCs, SPI_CS_ACTIVE);
if (ret != HDF_SUCCESS) {
return ret;
}
ret = Pl022SampleFlushFifo(cntlr);
if (ret != HDF_SUCCESS) {
return ret;
}
if (cntlr->bitsPerWord <= BITS_PER_WORD_DEFAULT) {
ret = Pl022SampleTxRx8(cntlr, msg);
} else {
ret = Pl022SampleTxRx16(cntlr, msg);
}
if (ret || msg->csChange) {
Pl022SampleSetCs(cntlr, cntlr->curCs, SPI_CS_INACTIVE);
}
return ret;
}
/* Private function implementations */
static int Pl022SampleSetCs(struct Pl022SpiCntlr *cntlr, uint32_t cs, uint32_t flag)
{
if (Pl022SampleCfgCs(cntlr, cs) != HDF_SUCCESS) {
return HDF_FAILURE;
}
if (flag == SPI_CS_ACTIVE) {
Pl022SampleEnableCntlr(cntlr);
} else {
Pl022SampleDisableCntlr(cntlr);
}
return HDF_SUCCESS;
}
static int Pl022SampleFlushFifo(const struct Pl022SpiCntlr *cntlr)
{
uint32_t value;
uint32_t ret;
uint32_t tmp = 0;
ret = Pl022SampleCheckTimeout(cntlr);
if (ret != HDF_SUCCESS) {
return ret;
}
while (true) {
value = OSAL_READL((UINTPTR)(cntlr->regBase) + REG_SPI_PL022_SR);
if (!(value & SPI_PL022_SR_RNE)) {
break;
}
if (tmp++ > cntlr->fifoSize) {
HDF_LOGE("%{public}s: spi transfer check rx fifo wait timeout", __func__);
return HDF_ERR_TIMEOUT;
}
OSAL_READL((UINTPTR)(cntlr->regBase) + REG_SPI_PL022_DR);
}
return HDF_SUCCESS;
}
static int Pl022SampleTxRx8(const struct Pl022SpiCntlr *cntlr, const struct SpiMsg *msg)
{
uint32_t len = msg->len;
uint32_t tmpLen;
uint32_t count;
const uint8_t *tx = (const uint8_t *)(msg->wbuf);
uint8_t *rx = (uint8_t *)(msg->rbuf);
uint8_t value;
uint32_t ret;
if (tx == NULL && rx == NULL) {
return HDF_ERR_INVALID_PARAM;
}
while (len > 0) {
if (len > cntlr->fifoSize) {
tmpLen = cntlr->fifoSize;
} else {
tmpLen = len;
}
len -= tmpLen;
/* write fifo */
count = tmpLen;
value = 0;
while (count > 0) {
if (tx != NULL) {
value = *tx++;
}
OSAL_WRITEL(value, (UINTPTR)(cntlr->regBase) + REG_SPI_PL022_DR);
count -= 1;
OSAL_READL((UINTPTR)(cntlr->regBase) + REG_SPI_PL022_SR);
}
ret = Pl022SampleCheckTimeout(cntlr);
if (ret != HDF_SUCCESS) {
return ret;
}
/* read fifo */
count = tmpLen;
while (count > 0) {
value = OSAL_READL((UINTPTR)(cntlr->regBase) + REG_SPI_PL022_DR);
if (rx != NULL) {
*rx++ = value;
}
count -= 1;
OSAL_READL((UINTPTR)(cntlr->regBase) + REG_SPI_PL022_SR);
}
}
return HDF_SUCCESS;
}
static int Pl022SampleTxRx16(const struct Pl022SpiCntlr *cntlr, const struct SpiMsg *msg)
{
uint32_t len = msg->len;
uint32_t tmpLen;
uint32_t count;
const uint16_t *tx = (const uint16_t *)(msg->wbuf);
uint16_t *rx = (uint16_t *)(msg->rbuf);
uint16_t value;
uint32_t ret;
if (tx == NULL && rx == NULL) {
return HDF_ERR_INVALID_PARAM;
}
while (len > 0) {
ret = cntlr->fifoSize * TWO_BYTES;
if (len > ret) {
tmpLen = ret;
} else {
tmpLen = len;
}
len -= tmpLen;
/* write fifo */
count = tmpLen;
value = 0;
while (count >= TWO_BYTES) {
if (tx != NULL) {
value = *tx++;
}
OSAL_WRITEL(value, (UINTPTR)(cntlr->regBase) + REG_SPI_PL022_DR);
count -= TWO_BYTES;
}
ret = Pl022SampleCheckTimeout(cntlr);
if (ret != 0) {
return ret;
}
/* read fifo */
count = tmpLen;
while (count >= TWO_BYTES) {
value = OSAL_READL((UINTPTR)(cntlr->regBase) + REG_SPI_PL022_DR);
if (rx != NULL) {
*rx++ = value;
}
count -= TWO_BYTES;
}
}
return 0;
}
static void Pl022SampleEnableCntlr(const struct Pl022SpiCntlr *cntlr)
{
uint32_t value;
value = OSAL_READL((UINTPTR)(cntlr->regBase) + REG_SPI_PL022_CR1);
value |= SPI_PL022_CR1_SSE;
OSAL_WRITEL(value, (UINTPTR)(cntlr->regBase) + REG_SPI_PL022_CR1);
}
static void Pl022SampleConfigCPSR(const struct Pl022SpiCntlr *cntlr, uint32_t cpsdvsr)
{
uint32_t value;
value = OSAL_READL((UINTPTR)(cntlr->regBase) + REG_SPI_PL022_CPSR);
value &= ~SPI_PL022_CPSR_CPSDVSR;
value |= cpsdvsr << SPI_PL022_CPSR_CPSDVSR_SHIFT;
OSAL_WRITEL(value, (UINTPTR)(cntlr->regBase) + REG_SPI_PL022_CPSR);
}
static void Pl022SampleConfigCR0(const struct Pl022SpiCntlr *cntlr, uint32_t scr)
{
uint32_t tmp;
uint32_t value;
value = OSAL_READL((UINTPTR)(cntlr->regBase) + REG_SPI_PL022_CR0);
value &= ~SPI_PL022_CR0_DSS;
value |= (cntlr->bitsPerWord - 1) << SPI_PL022_CR0_DSS_SHIFT;
value &= ~SPI_PL022_CR0_FRF;
value &= ~SPI_PL022_CR0_SPO;
tmp = (!!(cntlr->mode & SPI_CLK_POLARITY)) ? (1 << SPI_PL022_CR0_SPO_SHIFT) : 0;
value |= tmp;
value &= ~SPI_PL022_CR0_SPH;
tmp = (!!(cntlr->mode & SPI_CLK_PHASE)) ? (1 << SPI_PL022_CR0_SPH_SHIFT) : 0;
value |= tmp;
value &= ~SPI_PL022_CR0_SCR;
value |= (scr << SPI_PL022_CR0_SCR_SHIFT);
OSAL_WRITEL(value, (UINTPTR)(cntlr->regBase) + REG_SPI_PL022_CR0);
}
static void Pl022SampleConfigCR1(const struct Pl022SpiCntlr *cntlr)
{
uint32_t tmp;
uint32_t value;
value = OSAL_READL((UINTPTR)(cntlr->regBase) + REG_SPI_PL022_CR1);
value &= ~SPI_PL022_CR1_LBM;
tmp = (!!(cntlr->mode & SPI_MODE_LOOP)) ? (1 << SPI_PL022_CR1_LBN_SHIFT) : 0;
value |= tmp;
value &= ~SPI_PL022_CR1_MS;
value &= ~SPI_PL022_CR1_BIG_END;
tmp = (!!(cntlr->mode & SPI_MODE_LSBFE)) ? (1 << SPI_PL022_CR1_BIG_END_SHIFT) : 0;
value |= tmp;
value &= ~SPI_PL022_CR1_ALT;
value |= 0x1 << SPI_PL022_CR1_ALT_SHIFT;
OSAL_WRITEL(value, (UINTPTR)(cntlr->regBase) + REG_SPI_PL022_CR1);
}
static int32_t Pl022SampleCfgCs(struct Pl022SpiCntlr *cntlr, uint32_t cs)
{
uint32_t value;
uint32_t miscCtrlCs;
if ((cs + 1) > cntlr->numCs) {
HDF_LOGE("%{public}s: cs %{public}u is big than cntlr csNum %{public}u", __func__, cs, cntlr->numCs);
return HDF_FAILURE;
}
if (cntlr->numCs == 1) {
return HDF_SUCCESS;
}
miscCtrlCs = (UINTPTR)(cntlr->regBase) + REG_SPI_MISC_CTRL;
value = OSAL_READL(miscCtrlCs);
value &= ~miscCtrlCs;
value |= (cs << cntlr->miscCtrlCsShift);
OSAL_WRITEL(value, miscCtrlCs);
return HDF_SUCCESS;
}
static void Pl022SampleDisableCntlr(const struct Pl022SpiCntlr *cntlr)
{
uint32_t value;
value = OSAL_READL((UINTPTR)(cntlr->regBase) + REG_SPI_PL022_CR1);
value &= ~SPI_PL022_CR1_SSE;
OSAL_WRITEL(value, (UINTPTR)(cntlr->regBase) + REG_SPI_PL022_CR1);
}
static int Pl022SampleCheckTimeout(const struct Pl022SpiCntlr *cntlr)
{
uint32_t value;
uint32_t tmp = 0;
while (true) {
value = OSAL_READL((UINTPTR)(cntlr->regBase) + REG_SPI_PL022_SR);
if ((value & SPI_PL022_SR_TFE) && (!(value & SPI_PL022_SR_BSY))) {
break;
}
if (tmp++ > MAX_WAIT) {
HDF_LOGE("%{public}s: spi transfer wait timeout", __func__);
return HDF_ERR_TIMEOUT;
}
OsalUDelay(1);
}
return HDF_SUCCESS;
}
+362
View File
@@ -0,0 +1,362 @@
/* Copyright 2020 Huawei Device Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "spi_sample.h"
#include "spi_pl022_sample.h"
#include "spi_dispatch_sample.h"
#include "device_resource_if.h"
#include "hdf_base.h"
#include "osal_mem.h"
#include "hdf_log.h"
#include "spi_core.h"
#include "los_vm_zone.h"
#define HDF_LOG_TAG spi_sample
/* HdfDriverEntry hook function prototypes */
static int32_t SampleSpiDriverBind(struct HdfDeviceObject *device);
static int32_t SampleSpiDriverInit(struct HdfDeviceObject *device);
static void SampleSpiDriverRelease(struct HdfDeviceObject *device);
/* SpiCntlrMethod definition */
struct SpiCntlrMethod g_sampleSpiMethod = {
.Transfer = SampleSpiCntlrTransfer,
.SetCfg = SampleSpiCntlrSetCfg,
.GetCfg = SampleSpiCntlrGetCfg,
};
/* HdfDriverEntry definition */
struct HdfDriverEntry g_sampleSpiDriverEntry = {
.moduleVersion = 1,
.moduleName = "SPI_SAMPLE",
.Bind = SampleSpiDriverBind,
.Init = SampleSpiDriverInit,
.Release = SampleSpiDriverRelease,
};
/* Init HdfDriverEntry */
HDF_INIT(g_sampleSpiDriverEntry);
/* Private function prototypes */
static int InitSpiDevice(struct SpiCntlr *cntlr, const struct DeviceResourceNode *property);
static int ConfigSpiDevice(struct Pl022SpiCntlr *pl022Cntlr);
static int32_t InitSpiDeviceResource(struct Pl022SpiCntlr *pl022Cntlr, const struct DeviceResourceNode *node);
static int32_t CreateSpiDev(struct Pl022SpiCntlr *pl022Cntlr);
static void ReleaseSpiDev(struct Pl022SpiCntlr *pl022Cntlr);
static struct SpiDev *FindDeviceByCsNum(const struct Pl022SpiCntlr *pl022Cntlr, uint32_t cs);
/* HdfDriverEntry hook function implementations */
static int32_t SampleSpiDriverBind(struct HdfDeviceObject *device)
{
HDF_LOGD("%{public}s: Enter", __func__);
struct SpiCntlr *cntlr = NULL;
if (device == NULL) {
HDF_LOGE("%{public}s: device is NULL", __func__);
return HDF_ERR_INVALID_OBJECT;
}
cntlr = SpiCntlrCreate(device);
if (cntlr == NULL) {
HDF_LOGE("%{public}s: cntlr is NULL", __func__);
return HDF_FAILURE;
}
cntlr->service.Dispatch = SampleSpiDispatch;
return HDF_SUCCESS;
}
static int32_t SampleSpiDriverInit(struct HdfDeviceObject *device)
{
HDF_LOGD("%{public}s: Enter", __func__);
int ret;
struct SpiCntlr *cntlr = NULL;
if (device == NULL || device->property == NULL) {
HDF_LOGE("%{public}s: device or device->property is null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
cntlr = SpiCntlrFromDevice(device);
if (cntlr == NULL) {
HDF_LOGE("%{public}s: cntlr is null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
ret = InitSpiDevice(cntlr, device->property);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: InitSpiDevice failed", __func__);
return ret;
}
ret = ConfigSpiDevice(cntlr->priv);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: ConfigSpiDevice failed", __func__);
return ret;
}
return ret;
}
static void SampleSpiDriverRelease(struct HdfDeviceObject *device)
{
HDF_LOGD("%{public}s: Enter", __func__);
struct SpiCntlr *cntlr = NULL;
if (device == NULL) {
HDF_LOGE("%{public}s: device is null", __func__);
return;
}
cntlr = SpiCntlrFromDevice(device);
if (cntlr == NULL) {
HDF_LOGE("%{public}s: cntlr is null", __func__);
return;
}
if (cntlr->priv != NULL) {
ReleaseSpiDev((struct Pl022SpiCntlr *)cntlr->priv);
}
SpiCntlrDestroy(cntlr);
}
/* SPI function implementations */
int32_t SampleSpiCntlrTransfer(struct SpiCntlr *cntlr, struct SpiMsg *msg, uint32_t count)
{
HDF_LOGD("%{public}s: Enter", __func__);
int ret;
struct Pl022SpiCntlr *pl022Cntlr = NULL;
struct SpiDev *spiDev = NULL;
if (cntlr == NULL || cntlr->priv == NULL || msg == NULL || count == 0) {
HDF_LOGE("%{public}s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
pl022Cntlr = (struct Pl022SpiCntlr *)cntlr->priv;
spiDev = FindDeviceByCsNum(pl022Cntlr, cntlr->curCs);
if (spiDev == NULL) {
HDF_LOGE("%{public}s: spiDev is null, curCs %{public}u", __func__, cntlr->curCs);
return HDF_FAILURE;
}
pl022Cntlr->mode = spiDev->mode;
pl022Cntlr->transferMode = spiDev->transferMode;
pl022Cntlr->bitsPerWord = spiDev->bitsPerWord;
pl022Cntlr->maxSpeedHz = spiDev->maxSpeedHz;
pl022Cntlr->curCs = spiDev->csNum;
for (uint32_t i = 0; i < count; i++) {
ret = TransferOneMessage(pl022Cntlr, &(msg[i]));
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: transfer error", __func__);
return ret;
}
}
return ret;
}
int32_t SampleSpiCntlrSetCfg(struct SpiCntlr *cntlr, struct SpiCfg *cfg)
{
HDF_LOGD("%{public}s: Enter", __func__);
struct Pl022SpiCntlr *pl022Cntlr = NULL;
struct SpiDev *spiDev = NULL;
if (cntlr == NULL || cntlr->priv == NULL || cfg == NULL) {
HDF_LOGE("%{public}s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
pl022Cntlr = (struct Pl022SpiCntlr *)cntlr->priv;
spiDev = FindDeviceByCsNum(pl022Cntlr, cntlr->curCs);
if (spiDev == NULL) {
HDF_LOGE("%{public}s: spiDev is null, curCs %{public}u", __func__, cntlr->curCs);
return HDF_FAILURE;
}
spiDev->mode = cfg->mode;
spiDev->transferMode = cfg->transferMode;
spiDev->bitsPerWord = cfg->bitsPerWord;
if ((cfg->bitsPerWord < BITS_PER_WORD_MIN) || (cfg->bitsPerWord > BITS_PER_WORD_MAX)) {
HDF_LOGE("%{public}s: bitsPerWord %{public}u not support, use default bitsPerWord %{public}u",
__func__, cfg->bitsPerWord, BITS_PER_WORD_DEFAULT);
spiDev->bitsPerWord = BITS_PER_WORD_DEFAULT;
}
if (cfg->maxSpeedHz != 0) {
spiDev->maxSpeedHz = cfg->maxSpeedHz;
}
return HDF_SUCCESS;
}
int32_t SampleSpiCntlrGetCfg(struct SpiCntlr *cntlr, struct SpiCfg *cfg)
{
HDF_LOGD("%{public}s: Enter", __func__);
struct Pl022SpiCntlr *pl022Cntlr = NULL;
struct SpiDev *spiDev = NULL;
if (cntlr == NULL || cntlr->priv == NULL || cfg == NULL) {
HDF_LOGE("%{public}s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
pl022Cntlr = (struct Pl022SpiCntlr *)cntlr->priv;
spiDev = FindDeviceByCsNum(pl022Cntlr, cntlr->curCs);
if (spiDev == NULL) {
HDF_LOGE("%{public}s: spiDev is null, curCs %{public}u", __func__, cntlr->curCs);
return HDF_FAILURE;
}
cfg->mode = spiDev->mode;
cfg->transferMode = spiDev->transferMode;
cfg->bitsPerWord = spiDev->bitsPerWord;
cfg->maxSpeedHz = spiDev->maxSpeedHz;
return HDF_SUCCESS;
}
/* Private function implementations */
static int InitSpiDevice(struct SpiCntlr *cntlr, const struct DeviceResourceNode *property)
{
int ret;
struct Pl022SpiCntlr *pl022Cntlr = NULL;
pl022Cntlr = (struct Pl022SpiCntlr *)OsalMemCalloc(sizeof(*pl022Cntlr));
if (pl022Cntlr == NULL) {
HDF_LOGE("%{public}s: OsalMemCalloc error", __func__);
return HDF_FAILURE;
}
ret = InitSpiDeviceResource(pl022Cntlr, property);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: InitSpiDeviceResource error", __func__);
OsalMemFree(pl022Cntlr);
return HDF_FAILURE;
}
pl022Cntlr->maxSpeedHz = (pl022Cntlr->clkRate) / ((SCR_MIN + 1) * CPSDVSR_MIN);
pl022Cntlr->minSpeedHz = (pl022Cntlr->clkRate) / ((SCR_MAX + 1) * CPSDVSR_MAX);
DListHeadInit(&pl022Cntlr->deviceList);
pl022Cntlr->cntlr = cntlr;
cntlr->priv = pl022Cntlr;
cntlr->busNum = pl022Cntlr->busNum;
cntlr->method = &g_sampleSpiMethod;
ret = CreateSpiDev(pl022Cntlr);
if (ret != HDF_SUCCESS) {
ReleaseSpiDev(pl022Cntlr);
return ret;
}
return HDF_SUCCESS;
}
static int ConfigSpiDevice(struct Pl022SpiCntlr *pl022Cntlr)
{
int ret;
ret = ConfigPl022SpiCntlr(pl022Cntlr);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%{public}s: HiPl022Config error", __func__);
}
return ret;
}
static int32_t InitSpiDeviceResource(struct Pl022SpiCntlr *pl022Cntlr, const struct DeviceResourceNode *node)
{
uint32_t tmp;
struct DeviceResourceIface *resIf = NULL;
resIf = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
if (resIf == NULL || resIf->GetUint8 == NULL || resIf->GetUint16 == NULL || resIf->GetUint32 == NULL) {
HDF_LOGE("%{public}s: resource is invalid", __func__);
return HDF_FAILURE;
}
if (resIf->GetUint32(node, "regBase", &tmp, 0) != HDF_SUCCESS) {
HDF_LOGE("%{public}s: read regBase fail", __func__);
return HDF_FAILURE;
}
pl022Cntlr->regBase = (void *)(uintptr_t)(IO_DEVICE_ADDR(tmp));
if (resIf->GetUint32(node, "busNum", &pl022Cntlr->busNum, 0) != HDF_SUCCESS) {
HDF_LOGE("%{public}s: read busNum fail", __func__);
return HDF_FAILURE;
}
if (resIf->GetUint32(node, "numCs", &pl022Cntlr->numCs, 0) != HDF_SUCCESS) {
HDF_LOGE("%{public}s: read numCs fail", __func__);
return HDF_FAILURE;
}
if (resIf->GetUint32(node, "speed", &pl022Cntlr->speed, DEFAULT_SPEED) != HDF_SUCCESS) {
HDF_LOGE("%{public}s: read speed fail", __func__);
return HDF_FAILURE;
}
if (resIf->GetUint32(node, "fifoSize", &pl022Cntlr->fifoSize, 0) != HDF_SUCCESS) {
HDF_LOGE("%{public}s: read fifoSize fail", __func__);
return HDF_FAILURE;
}
if (resIf->GetUint32(node, "clkRate", &pl022Cntlr->clkRate, 0) != HDF_SUCCESS) {
HDF_LOGE("%{public}s: read clkRate fail", __func__);
return HDF_FAILURE;
}
if (resIf->GetUint16(node, "mode", &pl022Cntlr->mode, 0) != HDF_SUCCESS) {
HDF_LOGE("%{public}s: read mode fail", __func__);
return HDF_FAILURE;
}
if (resIf->GetUint8(node, "bitsPerWord", &pl022Cntlr->bitsPerWord, 0) != HDF_SUCCESS) {
HDF_LOGE("%{public}s: read bitsPerWord fail", __func__);
return HDF_FAILURE;
}
if (resIf->GetUint8(node, "transferMode", &pl022Cntlr->transferMode, 0) != HDF_SUCCESS) {
HDF_LOGE("%{public}s: read comMode fail", __func__);
return HDF_FAILURE;
}
pl022Cntlr->regCrg = REG_SPI_CRG;
pl022Cntlr->clkEnBit = SPI_CRG_CLK_EN;
pl022Cntlr->clkRstBit = SPI_CRG_CLK_RST;
pl022Cntlr->regMiscCtrl = REG_SPI_MISC_CTRL;
pl022Cntlr->miscCtrlCs = SPI_MISC_CTRL_CS;
pl022Cntlr->miscCtrlCsShift = SPI_MISC_CTRL_CS_SHIFT;
return HDF_SUCCESS;
}
static int32_t CreateSpiDev(struct Pl022SpiCntlr *pl022Cntlr)
{
uint32_t i;
struct SpiDev *device = NULL;
for (i = 0; i < pl022Cntlr->numCs; i++) {
device = (struct SpiDev *)OsalMemCalloc(sizeof(*device));
if (device == NULL) {
HDF_LOGE("%{public}s: OsalMemCalloc error", __func__);
return HDF_FAILURE;
}
device->cntlr = pl022Cntlr->cntlr;
device->csNum = i;
device->bitsPerWord = pl022Cntlr->bitsPerWord;
device->transferMode = pl022Cntlr->transferMode;
device->maxSpeedHz = pl022Cntlr->maxSpeedHz;
device->mode = pl022Cntlr->mode;
DListHeadInit(&device->list);
DListInsertTail(&device->list, &pl022Cntlr->deviceList);
}
return HDF_SUCCESS;
}
static void ReleaseSpiDev(struct Pl022SpiCntlr *pl022Cntlr)
{
struct SpiDev *dev = NULL;
struct SpiDev *tmpDev = NULL;
DLIST_FOR_EACH_ENTRY_SAFE(dev, tmpDev, &(pl022Cntlr->deviceList), struct SpiDev, list) {
if (dev != NULL) {
DListRemove(&(dev->list));
OsalMemFree(dev);
}
}
OsalMemFree(pl022Cntlr);
}
static struct SpiDev *FindDeviceByCsNum(const struct Pl022SpiCntlr *pl022Cntlr, uint32_t cs)
{
struct SpiDev *dev = NULL;
struct SpiDev *tmpDev = NULL;
if (pl022Cntlr == NULL || pl022Cntlr->numCs <= cs) {
return NULL;
}
DLIST_FOR_EACH_ENTRY_SAFE(dev, tmpDev, &(pl022Cntlr->deviceList), struct SpiDev, list) {
if (dev->csNum == cs) {
break;
}
}
return dev;
}
Executable → Regular
View File
Executable → Regular
View File
+1 -1
View File
@@ -12,7 +12,7 @@
# limitations under the License.
include $(LITEOSTOPDIR)/config.mk
include $(LITEOSTOPDIR)/../../drivers/hdf/lite/lite.mk
include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk
MODULE_NAME := hdf_uart_sample
+29 -30
View File
@@ -11,39 +11,38 @@
# See the License for the specific language governing permissions and
# limitations under the License.
HDF_FRAMEWORKS = "//drivers/hdf/frameworks"
HDF_FRAMEWORKS = "//drivers/framework"
executable("hello_uart") {
sources = [
"hello_uart_dev.c"
]
sources = [ "hello_uart_dev.c" ]
include_dirs = [
"$HDF_FRAMEWORKS/ability/sbuf/include",
"$HDF_FRAMEWORKS/core/shared/include",
"$HDF_FRAMEWORKS/core/host/include",
"$HDF_FRAMEWORKS/core/master/include",
"$HDF_FRAMEWORKS/include/core",
"$HDF_FRAMEWORKS/include/utils",
"$HDF_FRAMEWORKS/utils/include",
"$HDF_FRAMEWORKS/include/osal",
"//third_party/bounds_checking_function/include",
]
include_dirs = [
"$HDF_FRAMEWORKS/ability/sbuf/include",
"$HDF_FRAMEWORKS/core/shared/include",
"$HDF_FRAMEWORKS/core/host/include",
"$HDF_FRAMEWORKS/core/master/include",
"$HDF_FRAMEWORKS/include/core",
"$HDF_FRAMEWORKS/include/utils",
"$HDF_FRAMEWORKS/utils/include",
"$HDF_FRAMEWORKS/include/osal",
"//drivers/adapter/uhdf/posix/include",
"//third_party/bounds_checking_function/include",
"//base/hiviewdfx/hilog_lite/interfaces/native/innerkits",
]
deps = [
"//drivers/hdf/lite/manager:hdf_core",
"//drivers/hdf/lite/adapter/osal/posix:hdf_posix_osal",
]
deps = [
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
"//drivers/adapter/uhdf/manager:hdf_core",
"//drivers/adapter/uhdf/posix:hdf_posix_osal",
]
public_deps = [
"//third_party/bounds_checking_function:libsec_shared",
]
defines = [
"__USER__",
]
public_deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
defines = [ "__USER__" ]
cflags = [
"-Wall",
"-Wextra",
]
}
cflags = [
"-Wall",
"-Wextra",
"-Wno-format",
"-Wno-format-extra-args",
]
}
+4 -4
View File
@@ -18,7 +18,7 @@
#include <fcntl.h>
#include "hdf_log.h"
#define HDF_LOG_TAG "hello_uart"
#define HDF_LOG_TAG hello_uart
#define INFO_SIZE 16
int main(void)
@@ -29,16 +29,16 @@ int main(void)
fd = open("/dev/uartdev-5", O_RDWR);
if (fd < 0) {
HDF_LOGE("hello_uart uartdev-5 open failed %d", fd);
HDF_LOGE("uartdev-5 open failed %{public}d", fd);
return -1;
}
ret = write(fd, info, INFO_SIZE);
if (ret != 0) {
HDF_LOGE("hello_uart write uartdev-5 ret is %d", ret);
HDF_LOGE("write uartdev-5 ret is %{public}d", ret);
}
ret = close(fd);
if (ret != 0) {
HDF_LOGE("hello_uart uartdev-5 close failed %d", fd);
HDF_LOGE("uartdev-5 close failed %{public}d", fd);
return -1;
}
return ret;
+32 -32
View File
@@ -11,41 +11,41 @@
# See the License for the specific language governing permissions and
# limitations under the License.
HDF_FRAMEWORKS = "//drivers/hdf/frameworks"
HDF_FRAMEWORKS = "//drivers/framework"
executable("hello_uart_dispatch") {
sources = [
"hello_uart_dispatch.c",
"uart_if.c",
]
sources = [
"hello_uart_dispatch.c",
"uart_if.c",
]
include_dirs = [
"$HDF_FRAMEWORKS/ability/sbuf/include",
"$HDF_FRAMEWORKS/core/shared/include",
"$HDF_FRAMEWORKS/core/host/include",
"$HDF_FRAMEWORKS/core/master/include",
"$HDF_FRAMEWORKS/include/core",
"$HDF_FRAMEWORKS/include/utils",
"$HDF_FRAMEWORKS/utils/include",
"$HDF_FRAMEWORKS/include/osal",
"//drivers/hdf/lite/include/host",
"//third_party/bounds_checking_function/include",
]
include_dirs = [
"$HDF_FRAMEWORKS/ability/sbuf/include",
"$HDF_FRAMEWORKS/core/shared/include",
"$HDF_FRAMEWORKS/core/host/include",
"$HDF_FRAMEWORKS/core/master/include",
"$HDF_FRAMEWORKS/include/core",
"$HDF_FRAMEWORKS/include/utils",
"$HDF_FRAMEWORKS/utils/include",
"$HDF_FRAMEWORKS/include/osal",
"//drivers/adapter/uhdf/posix/include",
"//third_party/bounds_checking_function/include",
"//base/hiviewdfx/hilog_lite/interfaces/native/innerkits",
]
deps = [
"//drivers/hdf/lite/manager:hdf_core",
"//drivers/hdf/lite/adapter/osal/posix:hdf_posix_osal",
]
deps = [
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
"//drivers/adapter/uhdf/manager:hdf_core",
"//drivers/adapter/uhdf/posix:hdf_posix_osal",
]
public_deps = [
"//third_party/bounds_checking_function:libsec_shared",
]
defines = [
"__USER__",
]
public_deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
defines = [ "__USER__" ]
cflags = [
"-Wall",
"-Wextra",
]
}
cflags = [
"-Wall",
"-Wextra",
"-Wno-format",
"-Wno-format-extra-args",
]
}
+2 -2
View File
@@ -18,7 +18,7 @@
#include "osal_mem.h"
#include "uart_if.h"
#define HDF_LOG_TAG "hello_uart_dispatch"
#define HDF_LOG_TAG hello_uart_dispatch
#define UART_PORT 5
int main()
@@ -27,7 +27,7 @@ int main()
struct DevHandle *handle = UartOpen(UART_PORT);
if (handle == NULL) {
HDF_LOGE("Failed to open uart %d", UART_PORT);
HDF_LOGE("Failed to open uart %{public}d", UART_PORT);
return HDF_FAILURE;
}
+5 -3
View File
@@ -19,6 +19,8 @@
#include "osal_mem.h"
#include "hdf_io_service_if.h"
#define HDF_LOG_TAG uart_if
struct DevHandle *UartOpen(uint32_t port)
{
int32_t ret;
@@ -45,9 +47,9 @@ struct DevHandle *UartOpen(uint32_t port)
return NULL;
}
struct HdfIoService *service = HdfIoServiceBind(serviceName, 0);
struct HdfIoService *service = HdfIoServiceBind(serviceName);
if (service == NULL) {
HDF_LOGE("Failed to get service %s", serviceName);
HDF_LOGE("Failed to get service %{public}s", serviceName);
OsalMemFree(handle);
OsalMemFree(serviceName);
return NULL;
@@ -99,4 +101,4 @@ void UartClose(struct DevHandle *handle)
service = (struct HdfIoService *)handle->object;
HdfIoServiceRecycle(service);
OsalMemFree(handle);
}
}
View File
View File
View File
View File
View File
View File
+14 -14
View File
@@ -21,7 +21,7 @@
#include "osal_mem.h"
#include "uart_pl011_sample.h"
#define HDF_LOG_TAG hdf_uart_dev
#define HDF_LOG_TAG uart_dev_sample
#define HDF_UART_FS_MODE 0660
static int32_t UartSampleDevOpen(FAR struct file *filep)
@@ -35,10 +35,10 @@ static int32_t UartSampleDevOpen(FAR struct file *filep)
inode = (struct inode *)filep->f_inode;
host = (struct UartHost *)inode->i_private;
if (host == NULL) {
HDF_LOGE("%s: host is NULL", __func__);
HDF_LOGE("%{public}s: host is NULL", __func__);
return HDF_ERR_INVALID_PARAM;
}
HDF_LOGI("%s: open uart%d success", __func__, host->num);
HDF_LOGI("%{public}s: open uart%{public}d success", __func__, host->num);
return HDF_SUCCESS;
}
static int32_t UartSampleRelease(FAR struct file *filep)
@@ -52,10 +52,10 @@ static int32_t UartSampleRelease(FAR struct file *filep)
inode = (struct inode *)filep->f_inode;
host = (struct UartHost *)inode->i_private;
if (host == NULL) {
HDF_LOGE("%s: host is NULL", __func__);
HDF_LOGE("%{public}s: host is NULL", __func__);
return HDF_ERR_INVALID_PARAM;
}
HDF_LOGI("%s: close uart%d success", __func__, host->num);
HDF_LOGI("%{public}s: close uart%{public}d success", __func__, host->num);
return HDF_SUCCESS;
}
@@ -74,7 +74,7 @@ static ssize_t UartSampleRead(FAR struct file *filep, FAR char *buf, size_t coun
if (LOS_IsUserAddressRange((vaddr_t)buf, count)) {
tmpBuf = (uint8_t *)OsalMemCalloc(count);
if (tmpBuf == NULL) {
HDF_LOGE("%s: OsalMemCalloc error", __func__);
HDF_LOGE("%{public}s: OsalMemCalloc error", __func__);
return HDF_ERR_MALLOC_FAIL;
}
ret = UartHostRead(host, tmpBuf, count);
@@ -103,7 +103,7 @@ static ssize_t UartSampleWrite(struct file *filep, const char *buf, size_t count
if (LOS_IsUserAddressRange((vaddr_t)buf, count)) {
tmpBuf = (uint8_t *)OsalMemCalloc(count);
if (tmpBuf == NULL) {
HDF_LOGE("%s: OsalMemCalloc error", __func__);
HDF_LOGE("%{public}s: OsalMemCalloc error", __func__);
return HDF_ERR_MALLOC_FAIL;
}
ret = LOS_ArchCopyFromUser(tmpBuf, buf, count);
@@ -135,13 +135,13 @@ static int32_t UartSampleDevIoctl(FAR struct file *filep, int32_t cmd, unsigned
if (host->priv == NULL) {
return HDF_ERR_INVALID_PARAM;
}
HDF_LOGE("%s: num %d", __func__, host->num);
HDF_LOGD("%{public}s: num %{public}d", __func__, host->num);
switch (cmd) {
case UART_CFG_BAUDRATE:
ret = UartHostSetBaud(host, arg);
break;
default:
HDF_LOGE("%s cmd %d not support", __func__, cmd);
HDF_LOGE("%{public}s: cmd %{public}d not support", __func__, cmd);
ret = HDF_ERR_NOT_SUPPORT;
break;
}
@@ -163,29 +163,29 @@ static void AddRemoveUartDev(struct UartHost *host, bool add)
char *devName = NULL;
if (host == NULL || host->priv == NULL) {
HDF_LOGE("%s invalid parameter", __func__);
HDF_LOGW("%{public}s: invalid parameter", __func__);
return;
}
devName = (char *)OsalMemCalloc(sizeof(char) * (MAX_DEV_NAME_SIZE + 1));
if (devName == NULL) {
HDF_LOGE("%s: OsalMemCalloc error", __func__);
HDF_LOGE("%{public}s: OsalMemCalloc error", __func__);
return;
}
ret = snprintf_s(devName, MAX_DEV_NAME_SIZE + 1, MAX_DEV_NAME_SIZE, "/dev/uartdev-%d", host->num);
if (ret < 0) {
HDF_LOGE("%s snprintf_s failed", __func__);
HDF_LOGE("%{public}s: snprintf_s failed", __func__);
OsalMemFree(devName);
return;
}
if (add) {
if (register_driver(devName, &g_uartSampleDevFops, HDF_UART_FS_MODE, host)) {
HDF_LOGE("%s: gen /dev/uartdev-%d fail!", __func__, host->num);
HDF_LOGE("%{public}s: gen /dev/uartdev-%{public}d fail!", __func__, host->num);
OsalMemFree(devName);
return;
}
} else {
if (unregister_driver(devName)) {
HDF_LOGE("%s: remove /dev/uartdev-%d fail!", __func__, host->num);
HDF_LOGE("%{public}s: remove /dev/uartdev-%{public}d fail!", __func__, host->num);
OsalMemFree(devName);
return;
}
+6 -6
View File
@@ -20,7 +20,7 @@
#include "osal_mem.h"
#include "uart_pl011_sample.h"
#define HDF_LOG_TAG "uart_dispatch_sample"
#define HDF_LOG_TAG uart_dispatch_sample
static int32_t SampleDispatchWrite(struct UartDevice *device, struct HdfSBuf *txBuf)
{
@@ -30,12 +30,12 @@ static int32_t SampleDispatchWrite(struct UartDevice *device, struct HdfSBuf *tx
struct UartRegisterMap *regMap = (struct UartRegisterMap *)device->resource.physBase;
if (regMap == NULL) {
HDF_LOGE("%s: regMap is NULL", __func__);
HDF_LOGE("%{public}s: regMap is NULL", __func__);
return HDF_FAILURE;
}
if (!HdfSbufReadBuffer(txBuf, (const void **)&data, &dataSize)) {
HDF_LOGE("%s: Failed to read sbuf", __func__);
HDF_LOGE("%{public}s: Failed to read sbuf", __func__);
return HDF_FAILURE;
}
regMap = (struct UartRegisterMap *)device->resource.physBase;
@@ -49,17 +49,17 @@ int32_t SampleDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSB
{
int32_t result = HDF_FAILURE;
if (client == NULL || client->device == NULL) {
HDF_LOGE("%s: client or client->device is NULL", __func__);
HDF_LOGE("%{public}s: client or client->device is NULL", __func__);
return result;
}
struct UartHost *uartHost = (struct UartHost *)client->device->service;
if (uartHost == NULL) {
HDF_LOGE("%s: uartHost is NULL", __func__);
HDF_LOGE("%{public}s: uartHost is NULL", __func__);
return result;
}
struct UartDevice *uartDevice = (struct UartDevice *)uartHost->priv;
if (uartDevice == NULL) {
HDF_LOGE("%s: uartDevice is NULL", __func__);
HDF_LOGE("%{public}s: uartDevice is NULL", __func__);
return result;
}
switch (cmdId) {
View File
+25 -25
View File
@@ -70,9 +70,9 @@ struct UartHostMethod g_sampleUartHostMethod = {
/* UartHostMethod implementations */
static int32_t SampleUartHostInit(struct UartHost *host)
{
HDF_LOGI("%s: Enter", __func__);
HDF_LOGD("%{public}s: Enter", __func__);
if (host == NULL) {
HDF_LOGE("%s: invalid parameter", __func__);
HDF_LOGW("%{public}s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
return HDF_SUCCESS;
@@ -80,9 +80,9 @@ static int32_t SampleUartHostInit(struct UartHost *host)
static int32_t SampleUartHostDeinit(struct UartHost *host)
{
HDF_LOGI("%s: Enter", __func__);
HDF_LOGD("%{public}s: Enter", __func__);
if (host == NULL) {
HDF_LOGE("%s: invalid parameter", __func__);
HDF_LOGW("%{public}s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
return HDF_SUCCESS;
@@ -90,18 +90,18 @@ static int32_t SampleUartHostDeinit(struct UartHost *host)
static int32_t SampleUartHostWrite(struct UartHost *host, uint8_t *data, uint32_t size)
{
HDF_LOGI("%s: Enter", __func__);
uint32_t idx;
struct UartRegisterMap *regMap = NULL;
struct UartDevice *device = NULL;
HDF_LOGD("%{public}s: Enter", __func__);
if (host == NULL || data == NULL || size == 0) {
HDF_LOGE("%s: invalid parameter", __func__);
HDF_LOGW("%{public}s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
device = (struct UartDevice *)host->priv;
if (device == NULL) {
HDF_LOGE("%s: device is NULL", __func__);
HDF_LOGW("%{public}s: device is NULL", __func__);
return HDF_ERR_INVALID_PARAM;
}
regMap = (struct UartRegisterMap *)device->resource.physBase;
@@ -113,18 +113,18 @@ static int32_t SampleUartHostWrite(struct UartHost *host, uint8_t *data, uint32_
static int32_t SampleUartHostSetBaud(struct UartHost *host, uint32_t baudRate)
{
HDF_LOGI("%s: Enter", __func__);
struct UartDevice *device = NULL;
struct UartRegisterMap *regMap = NULL;
UartPl011Error err;
HDF_LOGD("%{public}s: Enter", __func__);
if (host == NULL) {
HDF_LOGE("%s: invalid parameter", __func__);
HDF_LOGW("%{public}s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
device = (struct UartDevice *)host->priv;
if (device == NULL) {
HDF_LOGE("%s: device is NULL", __func__);
HDF_LOGW("%{public}s: device is NULL", __func__);
return HDF_ERR_INVALID_PARAM;
}
regMap = (struct UartRegisterMap *)device->resource.physBase;
@@ -143,16 +143,16 @@ static int32_t SampleUartHostSetBaud(struct UartHost *host, uint32_t baudRate)
static int32_t SampleUartHostGetBaud(struct UartHost *host, uint32_t *baudRate)
{
HDF_LOGI("%s: Enter", __func__);
struct UartDevice *device = NULL;
HDF_LOGD("%{public}s: Enter", __func__);
if (host == NULL) {
HDF_LOGE("%s: invalid parameter", __func__);
HDF_LOGW("%{public}s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
device = (struct UartDevice *)host->priv;
if (device == NULL) {
HDF_LOGE("%s: device is NULL", __func__);
HDF_LOGW("%{public}s: device is NULL", __func__);
return HDF_ERR_INVALID_PARAM;
}
*baudRate = device->baudrate;
@@ -243,12 +243,12 @@ static int32_t AttachUartDevice(struct UartHost *host, struct HdfDeviceObject *d
int32_t ret;
struct UartDevice *uartDevice = NULL;
if (device->property == NULL) {
HDF_LOGE("%s: property is NULL", __func__);
HDF_LOGW("%{public}s: property is NULL", __func__);
return HDF_FAILURE;
}
uartDevice = (struct UartDevice *)OsalMemCalloc(sizeof(struct UartDevice));
if (uartDevice == NULL) {
HDF_LOGE("%s: OsalMemCalloc uartDevice error", __func__);
HDF_LOGE("%{public}s: OsalMemCalloc uartDevice error", __func__);
return HDF_ERR_MALLOC_FAIL;
}
ret = GetUartDeviceResource(uartDevice, device->property);
@@ -278,7 +278,7 @@ static void DetachUartDevice(struct UartHost *host)
struct UartDevice *uartDevice = NULL;
if (host->priv == NULL) {
HDF_LOGE("%s: invalid parameter", __func__);
HDF_LOGW("%{public}s: invalid parameter", __func__);
return;
}
uartDevice = host->priv;
@@ -291,15 +291,15 @@ static void DetachUartDevice(struct UartHost *host)
static int32_t SampleUartDriverBind(struct HdfDeviceObject *device)
{
struct UartHost *uartHost = NULL;
HDF_LOGD("%{public}s: Enter", __func__);
if (device == NULL) {
return HDF_ERR_INVALID_OBJECT;
}
HDF_LOGI("Enter %s:", __func__);
uartHost = UartHostCreate(device);
if (uartHost == NULL) {
HDF_LOGE("%s: UartHostCreate failed", __func__);
HDF_LOGE("%{public}s: UartHostCreate failed", __func__);
return HDF_FAILURE;
}
uartHost->service.Dispatch = SampleDispatch;
@@ -310,20 +310,20 @@ static int32_t SampleUartDriverInit(struct HdfDeviceObject *device)
{
int32_t ret;
struct UartHost *host = NULL;
HDF_LOGD("%{public}s: Enter", __func__);
if (device == NULL) {
HDF_LOGE("%s: device is NULL", __func__);
HDF_LOGE("%{public}s: device is NULL", __func__);
return HDF_ERR_INVALID_OBJECT;
}
HDF_LOGI("Enter %s:", __func__);
host = UartHostFromDevice(device);
if (host == NULL) {
HDF_LOGE("%s: host is NULL", __func__);
HDF_LOGE("%{public}s: host is NULL", __func__);
return HDF_FAILURE;
}
ret = AttachUartDevice(host, device);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: attach error", __func__);
HDF_LOGE("%{public}s: attach error", __func__);
return HDF_FAILURE;
}
host->method = &g_sampleUartHostMethod;
@@ -333,15 +333,15 @@ static int32_t SampleUartDriverInit(struct HdfDeviceObject *device)
static void SampleUartDriverRelease(struct HdfDeviceObject *device)
{
struct UartHost *host = NULL;
HDF_LOGI("Enter %s:", __func__);
HDF_LOGD("%{public}s: Enter", __func__);
if (device == NULL) {
HDF_LOGE("%s: device is NULL", __func__);
HDF_LOGE("%{public}s: device is NULL", __func__);
return;
}
host = UartHostFromDevice(device);
if (host == NULL) {
HDF_LOGE("%s: host is NULL", __func__);
HDF_LOGE("%{public}s: host is NULL", __func__);
return;
}
if (host->priv != NULL) {
-13
View File
@@ -1,13 +0,0 @@
config DRIVERS_HDF_WIFI
bool "Enable HDF WiFi Host driver"
default n
depends on DRIVERS_HDF
help
Answer Y to enable HDF WiFi Host driver.
config DRIVERS_HI3881
bool "Enable Hi3881 Host driver"
default n
depends on DRIVERS_HDF_WIFI
help
Answer Y to enable Hi3881 Host driver.
Binary file not shown.
-11
View File
@@ -1,11 +0,0 @@
@WiFi patch info
CFG_COUNTRY_CODE=CN;
CFG_RSSI_OFFSET=0;
CFG_MAC=00:00:00:00:00:00;
CFG_DBB_PARAMS=0x6B6B6D6E,0x67676767,0x50545F60,0x565E5E5E,0x4F4F5656,0x00000000,0x01000000;
CFG_FREQ_COMP=105,100,-30;
CFG_CH_TXPWR_OFFSET=0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff;
PARA_VERSION=Hi3881V100;
ADDR_FILE_FILES=1,0xe4800,/vendor/firmware/hisilicon/hi3881_fw.bin;
PARA_CONFIG=0xe4800,4;
QUIT;