Apply next HAL architecture (hal api + backend) 73/251473/5 accepted/tizen/unified/20210118.141053 submit/tizen/20210118.015732
authorWootak Jung <wootak.jung@samsung.com>
Thu, 14 Jan 2021 06:12:07 +0000 (15:12 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Fri, 15 Jan 2021 04:07:30 +0000 (13:07 +0900)
Change-Id: Ifa74b617c1f5f03bb24c20dc0746682e810f8d84
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
CMakeLists.txt
packaging/bluetooth-firmware-sprd.spec
src/CMakeLists.txt [new file with mode: 0644]
src/hal-backend-bluetooth.c [new file with mode: 0644]

index d5a4426..c43c9dc 100644 (file)
@@ -7,3 +7,4 @@ ENDFOREACH(flag)
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 
 ADD_SUBDIRECTORY(scripts)
+ADD_SUBDIRECTORY(src)
index 3225d6a..1caa623 100644 (file)
@@ -9,6 +9,9 @@ Source1:    bluetooth-hciattach@.service
 Source2:    bluetooth-hci-device.service
 
 BuildRequires:  cmake
+BuildRequires:  pkgconfig(dlog)
+BuildRequires:  pkgconfig(hal-api-common)
+BuildRequires:  pkgconfig(hal-api-bluetooth)
 
 %description
 firmware and tools for bluetooth
@@ -51,3 +54,4 @@ ln -s %{_prefix}/etc/bluetooth/bt-dev-start-TM1.sh %{_prefix}/etc/bluetooth/bt-d
 %attr(755,-,-) %{_prefix}/etc/bluetooth/bt-dev-start-TM1.sh
 %{_unitdir}/bluetooth-hciattach@.service
 %{_unitdir}/bluetooth-hci-device.service
+/hal/lib/*.so*
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644 (file)
index 0000000..ca1fc73
--- /dev/null
@@ -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 (file)
index 0000000..4eb220f
--- /dev/null
@@ -0,0 +1,75 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <errno.h>
+#include <dlog.h>
+
+#include <hal/hal-bluetooth-interface.h>
+
+#undef LOG_TAG
+#define LOG_TAG "HALAPI_BLUETOOTH"
+
+#define EXPORT __attribute__ ((visibility("default")))
+
+static int bluetooth_tm1_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_tm1_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_tm1_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_tm1_start;
+       bluetooth_funcs->stop = bluetooth_tm1_stop;
+
+       *data = (void *)bluetooth_funcs;
+
+       return 0;
+}
+
+static int bluetooth_tm1_exit(void *data)
+{
+       if (!data)
+               return -EINVAL;
+       free(data);
+
+       return 0;
+}
+
+hal_backend EXPORT hal_backend_bluetooth_data = {
+       .name = "bluetooth-spreadtrum",
+       .vendor = "Spreadtrum",
+       .abi_version = HAL_ABI_VERSION_TIZEN_6_5,
+       .init = bluetooth_tm1_init,
+       .exit = bluetooth_tm1_exit,
+};