From 394fdf4dec4bd4687cd707cc8b2809f49b2976cd Mon Sep 17 00:00:00 2001 From: Wootak Jung Date: Mon, 18 Jan 2021 10:24:37 +0900 Subject: [PATCH] Apply next HAL architecture (hal api + backend) Change-Id: I9144058b44622f46b3054b83ab39e75d471e8bce Signed-off-by: Wootak Jung --- CMakeLists.txt | 1 + packaging/bluetooth-firmware-bcm.spec | 4 ++ src/CMakeLists.txt | 25 ++++++++++++ src/hal-backend-bluetooth.c | 75 +++++++++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 src/CMakeLists.txt create mode 100644 src/hal-backend-bluetooth.c diff --git a/CMakeLists.txt b/CMakeLists.txt index ff2d9b6..a196a1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,3 +14,4 @@ ADD_SUBDIRECTORY(set-address) ADD_SUBDIRECTORY(tools) ADD_SUBDIRECTORY(firmware) ADD_SUBDIRECTORY(scripts) +ADD_SUBDIRECTORY(src) diff --git a/packaging/bluetooth-firmware-bcm.spec b/packaging/bluetooth-firmware-bcm.spec index 2212b4a..5a4d44d 100644 --- a/packaging/bluetooth-firmware-bcm.spec +++ b/packaging/bluetooth-firmware-bcm.spec @@ -12,6 +12,9 @@ Source2: bluetooth-hci-device.service Provides: bluetooth-scripts BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(hal-api-common) +BuildRequires: pkgconfig(hal-api-bluetooth) BuildRequires: cmake %description @@ -156,3 +159,4 @@ ln -s %{_prefix}/etc/bluetooth/BCM4345C0.hcd /lib/firmware/brcm/ %attr(755,-,-) %{_prefix}/etc/bluetooth/bt-dev-end-rpi3.sh %attr(755,-,-) %{_prefix}/etc/bluetooth/bt-dev-start-rpi3.sh %manifest %{name}.manifest +/hal/lib/*.so* diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..ca1fc73 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,25 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(hal-backend-bluetooth C) + +INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include) + +INCLUDE(FindPkgConfig) +pkg_check_modules(hal-backend-bluetooth_pkgs REQUIRED + dlog + hal-api-common + hal-api-bluetooth +) + +SET(SRCS + ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}.c) + +FOREACH(flag ${hal-backend-bluetooth_pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${hal-backend-bluetooth_pkgs_LDFLAGS}) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /hal/lib COMPONENT RuntimeLibraries) diff --git a/src/hal-backend-bluetooth.c b/src/hal-backend-bluetooth.c new file mode 100644 index 0000000..cd71c84 --- /dev/null +++ b/src/hal-backend-bluetooth.c @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#include + +#include + +#undef LOG_TAG +#define LOG_TAG "HALAPI_BLUETOOTH" + +#define EXPORT __attribute__ ((visibility("default"))) + +static int bluetooth_bcm_start(void) +{ + int ret; + ret = system("/usr/etc/bluetooth/bt-stack-up.sh"); + if (ret == 0x100) { + LOGE("script internal failed"); + return HAL_BACKEND_ERROR_INTERNAL; + } else if (ret == 0x200) { + LOGE("script timeout failed"); + return HAL_BACKEND_ERROR_TIMEOUT; + } + LOGD("script started successfully"); + return HAL_BACKEND_ERROR_NONE; +} + +static int bluetooth_bcm_stop(void) +{ + int ret; + ret = system("/usr/etc/bluetooth/bt-stack-down.sh"); + if (ret == 0x100) { + LOGE("script internal failed"); + return HAL_BACKEND_ERROR_INTERNAL; + } else if (ret == 0x200) { + LOGE("script timeout failed"); + return HAL_BACKEND_ERROR_TIMEOUT; + } + LOGD("script started successfully"); + return HAL_BACKEND_ERROR_NONE; +} + +static int bluetooth_bcm_init(void **data) +{ + hal_backend_bluetooth_funcs *bluetooth_funcs; + + bluetooth_funcs = calloc(1, sizeof(hal_backend_bluetooth_funcs)); + if (!bluetooth_funcs) + return -ENOMEM; + + bluetooth_funcs->start = bluetooth_bcm_start; + bluetooth_funcs->stop = bluetooth_bcm_stop; + + *data = (void *)bluetooth_funcs; + + return 0; +} + +static int bluetooth_bcm_exit(void *data) +{ + if (!data) + return -EINVAL; + free(data); + + return 0; +} + +hal_backend EXPORT hal_backend_bluetooth_data = { + .name = "bluetooth", + .vendor = "broadcom", + .abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .init = bluetooth_bcm_init, + .exit = bluetooth_bcm_exit, +}; -- 2.7.4