From: Paweł Szewczyk
Date: Thu, 28 Jun 2018 10:58:30 +0000 (+0200)
Subject: Add board HAL
X-Git-Tag: accepted/tizen/5.0/unified/20181102.012640~3
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6f13e9d8a1587ce155f57094ff282d0c8bfe0c54;p=platform%2Fadaptation%2Fsamsung_exynos%2Fdevice-manager-plugin-artik.git
Add board HAL
Change-Id: Ifcc9256bb722b32f8c3db3bdb873a4e6c88c8ef8
Signed-off-by: Paweł Szewczyk
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7fab672..3653bc0 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,6 +4,7 @@ PROJECT(device-manager-artik C)
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
#ADD_SUBDIRECTORY(hw/battery)
+ADD_SUBDIRECTORY(hw/board)
ADD_SUBDIRECTORY(hw/display)
#ADD_SUBDIRECTORY(hw/external_connection)
ADD_SUBDIRECTORY(hw/led)
diff --git a/hw/board/CMakeLists.txt b/hw/board/CMakeLists.txt
new file mode 100644
index 0000000..5b8b5b4
--- /dev/null
+++ b/hw/board/CMakeLists.txt
@@ -0,0 +1,19 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(board C)
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(usb_gadget_pkgs REQUIRED hwcommon)
+
+FOREACH(flag ${usb_gadget_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} MODULE board.c)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${usb_gadget_pkgs_LDFLAGS})
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "")
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}/hw COMPONENT RuntimeLibraries)
diff --git a/hw/board/board.c b/hw/board/board.c
new file mode 100755
index 0000000..3c6b42d
--- /dev/null
+++ b/hw/board/board.c
@@ -0,0 +1,91 @@
+/*
+ * libdevice-node
+ *
+ * Copyright (c) 2016 Samsung Electronics 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.
+ */
+
+#define _GNU_SOURCE
+#include
+
+#include
+#include
+#include
+#include
+
+#define SERIAL_FILE_PATH "/sys/firmware/devicetree/base/serial-number"
+#define LINE_LEN 64
+
+static int get_device_serial(char **out)
+{
+ FILE *fp;
+ char *line, *p;
+
+ fp = fopen(SERIAL_FILE_PATH, "r");
+ if (!fp)
+ return -1;
+
+ line = malloc(LINE_LEN);
+ p = fgets(line, LINE_LEN, fp);
+ fclose(fp);
+ if (p == NULL) {
+ free(line);
+ return -1;
+ }
+
+ *out = p;
+ return 0;
+}
+
+static int board_open(struct hw_info *info,
+ const char *id, struct hw_common **common)
+{
+ struct hw_board *b;
+
+ if (!info || !common)
+ return -EINVAL;
+
+ b = calloc(1, sizeof(*b));
+ if (!b)
+ return -ENOMEM;
+
+ b->common.info = info;
+ b->get_device_serial = get_device_serial;
+
+ *common = &b->common;
+ return 0;
+}
+
+static int board_close(struct hw_common *common)
+{
+ struct hw_board *b;
+
+ if (!common)
+ return -EINVAL;
+
+ b = container_of(common, struct hw_board, common);
+ free(b);
+
+ return 0;
+}
+
+HARDWARE_MODULE_STRUCTURE = {
+ .magic = HARDWARE_INFO_TAG,
+ .hal_version = HARDWARE_INFO_VERSION,
+ .device_version = BOARD_HARDWARE_DEVICE_VERSION,
+ .id = BOARD_HARDWARE_DEVICE_ID,
+ .name = "device",
+ .open = board_open,
+ .close = board_close,
+};