From 5b59c10fc4f7106e95e82930249810fa54dc6e4a Mon Sep 17 00:00:00 2001 From: Alexander Wachter Date: Fri, 21 Dec 2018 11:58:41 +0100 Subject: [PATCH] drivers: Add hwinfo API This commit adds a new hardware info API. With this API it is possible to read out the device ID. Signed-off-by: Alexander Wachter --- drivers/CMakeLists.txt | 1 + drivers/Kconfig | 2 ++ drivers/hwinfo/CMakeLists.txt | 2 ++ drivers/hwinfo/Kconfig | 16 +++++++++ drivers/hwinfo/hwinfo_handlers.c | 15 ++++++++ drivers/hwinfo/hwinfo_weak_impl.c | 12 +++++++ include/hwinfo.h | 57 +++++++++++++++++++++++++++++++ 7 files changed, 105 insertions(+) create mode 100644 drivers/hwinfo/CMakeLists.txt create mode 100644 drivers/hwinfo/Kconfig create mode 100644 drivers/hwinfo/hwinfo_handlers.c create mode 100644 drivers/hwinfo/hwinfo_weak_impl.c create mode 100644 include/hwinfo.h diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index d43eeff9a8a..ee09c765788 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -29,6 +29,7 @@ add_subdirectory_if_kconfig(watchdog) add_subdirectory_if_kconfig(wifi) add_subdirectory_if_kconfig(can) add_subdirectory_if_kconfig(audio) +add_subdirectory_if_kconfig(hwinfo) add_subdirectory_ifdef(CONFIG_FLASH_HAS_DRIVER_ENABLED flash) add_subdirectory_ifdef(CONFIG_SERIAL_HAS_DRIVER serial) diff --git a/drivers/Kconfig b/drivers/Kconfig index 69439adf4ae..94b898722b6 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -85,4 +85,6 @@ source "drivers/audio/Kconfig" source "drivers/neural_net/Kconfig" +source "drivers/hwinfo/Kconfig" + endmenu diff --git a/drivers/hwinfo/CMakeLists.txt b/drivers/hwinfo/CMakeLists.txt new file mode 100644 index 00000000000..f467e7052c2 --- /dev/null +++ b/drivers/hwinfo/CMakeLists.txt @@ -0,0 +1,2 @@ +zephyr_sources_ifdef(CONFIG_USERSPACE hwinfo_handlers.c) +zephyr_sources_ifdef(CONFIG_HWINFO hwinfo_weak_impl.c) diff --git a/drivers/hwinfo/Kconfig b/drivers/hwinfo/Kconfig new file mode 100644 index 00000000000..0b029619a18 --- /dev/null +++ b/drivers/hwinfo/Kconfig @@ -0,0 +1,16 @@ +# Kconfig -HW Info driver configuration options + +# +# Copyright (c) 2019 Alexander Wachter +# +# SPDX-License-Identifier: Apache-2.0 +# + +menuconfig HWINFO + bool "Hardware Information driver" + help + Enable hwinfo driver. + +if HWINFO + +endif diff --git a/drivers/hwinfo/hwinfo_handlers.c b/drivers/hwinfo/hwinfo_handlers.c new file mode 100644 index 00000000000..8dc00ad0d84 --- /dev/null +++ b/drivers/hwinfo/hwinfo_handlers.c @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2018 Alexander Wachter + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +Z_SYSCALL_HANDLER(hwinfo_get_device_id, buffer, length) { + + Z_OOPS(Z_SYSCALL_MEMORY_WRITE(buffer, length)); + + return _impl_hwinfo_get_device_id((u8_t *)buffer, (size_t)length); +} diff --git a/drivers/hwinfo/hwinfo_weak_impl.c b/drivers/hwinfo/hwinfo_weak_impl.c new file mode 100644 index 00000000000..053c1655826 --- /dev/null +++ b/drivers/hwinfo/hwinfo_weak_impl.c @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2018 Alexander Wachter + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +ssize_t __weak _impl_hwinfo_get_device_id(u8_t *buffer, size_t length) +{ + return -ENOTSUP; +} diff --git a/include/hwinfo.h b/include/hwinfo.h new file mode 100644 index 00000000000..f207f5e61e0 --- /dev/null +++ b/include/hwinfo.h @@ -0,0 +1,57 @@ +/** + * @file + * + * @brief Public APIs to get device Information. + */ + +/* + * Copyright (c) 2018 Alexander Wachter + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_HWINFO_H_ +#define ZEPHYR_INCLUDE_HWINFO_H_ + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Device ID + * @{ + */ + + +/** + * @brief Copy the device id to a buffer + * + * This routine copies "length" number of bytes of the device ID to the buffer. + * If the device ID is smaller then length, the rest of the buffer is left unchanged. + * The ID depends on the hardware and is not guaranteed unique. + * + * @param buffer Buffer to write the ID to. + * @param length Max length of the buffer. + * + * @retval size of the device ID copied or negative on error. + */ +__syscall ssize_t hwinfo_get_device_id(u8_t *buffer, size_t length); + +ssize_t _impl_hwinfo_get_device_id(u8_t *buffer, size_t length); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#include + +#endif /* ZEPHYR_INCLUDE_HWINFO_H_ */