diff --git a/boards/ek-lm4f120xl/Makefile.features b/boards/ek-lm4f120xl/Makefile.features index aacc4f47a..0ce7768d2 100644 --- a/boards/ek-lm4f120xl/Makefile.features +++ b/boards/ek-lm4f120xl/Makefile.features @@ -1,6 +1,5 @@ # Put defined MCU peripherals here (in alphabetical order) FEATURES_PROVIDED += periph_adc -FEATURES_PROVIDED += periph_cpuid FEATURES_PROVIDED += periph_gpio FEATURES_PROVIDED += periph_timer FEATURES_PROVIDED += periph_uart diff --git a/cpu/cc2538/include/periph_cpu.h b/cpu/cc2538/include/periph_cpu.h index 2fbe199bb..1c57a63be 100644 --- a/cpu/cc2538/include/periph_cpu.h +++ b/cpu/cc2538/include/periph_cpu.h @@ -27,6 +27,10 @@ extern "C" { #endif +/** + * @brief Starting offset of CPU_ID + */ +#define CPUID_ADDR (&IEEE_ADDR_MSWORD) /** * @brief Length of the CPU_ID in octets */ diff --git a/cpu/cc2538/periph/cpuid.c b/cpu/cc2538/periph/cpuid.c deleted file mode 100644 index 500581297..000000000 --- a/cpu/cc2538/periph/cpuid.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2014 Loci Controls Inc. - * - * This file is subject to the terms and conditions of the GNU Lesser General - * Public License v2.1. See the file LICENSE in the top level directory for more - * details. - */ - -/** - * @ingroup cpu_cc2538 - * @{ - * - * @file - * @brief CPU-ID driver implementation - * - * The CC2538 provides a 64-bit unique identifier, that is unique for each shipped unit. - * - * @author Ian Martin - * - * @} - */ - -#include -#include - -#include "cpu.h" -#include "periph/cpuid.h" - -void cpuid_get(void *id) -{ - uint8_t *dest = (uint8_t *)id; - - /** - * The byte-order is big-endian but the word order is little endian. - * Make some sense of it: - */ - dest[0] = IEEE_ADDR_MSWORD >> (3 * sizeof(uint8_t)); - dest[1] = IEEE_ADDR_MSWORD >> (2 * sizeof(uint8_t)); - dest[2] = IEEE_ADDR_MSWORD >> (1 * sizeof(uint8_t)); - dest[3] = IEEE_ADDR_MSWORD >> (0 * sizeof(uint8_t)); - dest[4] = IEEE_ADDR_LSWORD >> (3 * sizeof(uint8_t)); - dest[5] = IEEE_ADDR_LSWORD >> (2 * sizeof(uint8_t)); - dest[6] = IEEE_ADDR_LSWORD >> (1 * sizeof(uint8_t)); - dest[7] = IEEE_ADDR_LSWORD >> (0 * sizeof(uint8_t)); -} diff --git a/cpu/cc26x0/include/periph_cpu.h b/cpu/cc26x0/include/periph_cpu.h index 705434bc1..e1f337217 100644 --- a/cpu/cc26x0/include/periph_cpu.h +++ b/cpu/cc26x0/include/periph_cpu.h @@ -25,6 +25,10 @@ extern "C" { #endif +/** + * @brief Starting offset of CPU_ID + */ +#define CPUID_ADDR (&FCFG->MAC_BLE_0) /** * @brief Length of the CPU_ID in octets */ diff --git a/cpu/cc26x0/periph/cpuid.c b/cpu/cc26x0/periph/cpuid.c deleted file mode 100644 index 343c661bf..000000000 --- a/cpu/cc26x0/periph/cpuid.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2016 Leon George - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @ingroup cpu_cc26x0 - * @{ - * - * @file - * @brief cpuid implementation for the CC26x0 - * - * @author Leon M. George - * - * @} - */ - -#include - -#include "periph/cpuid.h" - -void cpuid_get(void *id) -{ - memcpy(id, (void *) &FCFG->MAC_BLE_0, CPUID_LEN); -} diff --git a/cpu/ezr32wg/include/periph_cpu.h b/cpu/ezr32wg/include/periph_cpu.h index f8a783de3..f1ad2aad9 100644 --- a/cpu/ezr32wg/include/periph_cpu.h +++ b/cpu/ezr32wg/include/periph_cpu.h @@ -38,6 +38,10 @@ extern "C" { typedef uint32_t tim_t; /** @} */ +/** + * @brief Starting offset of CPU_ID + */ +#define CPUID_ADDR (&DEVINFO->UNIQUEL) /** * @brief Length of the CPU_ID in octets */ diff --git a/cpu/ezr32wg/periph/cpuid.c b/cpu/ezr32wg/periph/cpuid.c deleted file mode 100644 index 25c17a669..000000000 --- a/cpu/ezr32wg/periph/cpuid.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2014-2016 Freie Universität Berlin - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @addtogroup cpu_ezr32wg - * @{ - * - * @file - * @brief Low-level CPUID driver implementation - * - * @author Hauke Petersen - * - * @} - */ - -#include -#include - -#include "periph/cpuid.h" - -void cpuid_get(void *id) -{ - uint32_t tmp; - uint8_t *res = (uint8_t *)id; - - tmp = DEVINFO->UNIQUEL; - memcpy((res + 4), &tmp, sizeof(uint32_t)); - tmp = DEVINFO->UNIQUEH; - memcpy(res, &tmp, sizeof(uint32_t)); -} diff --git a/cpu/kinetis_common/include/periph_cpu.h b/cpu/kinetis_common/include/periph_cpu.h index e79b51ef4..76c513098 100644 --- a/cpu/kinetis_common/include/periph_cpu.h +++ b/cpu/kinetis_common/include/periph_cpu.h @@ -45,6 +45,10 @@ typedef uint16_t gpio_t; */ #define GPIO_PIN(x, y) (((x + 1) << 12) | (x << 6) | y) +/** + * @brief Starting offset of CPU_ID + */ +#define CPUID_ADDR (&SIM->UIDH) /** * @brief Length of the CPU_ID in octets */ diff --git a/cpu/kinetis_common/periph/cpuid.c b/cpu/kinetis_common/periph/cpuid.c deleted file mode 100644 index f34fd9e62..000000000 --- a/cpu/kinetis_common/periph/cpuid.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2014 PHYTEC Messtechnik GmbH - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @ingroup cpu_kinetis_common_cpuid - * - * @{ - * - * @file - * @brief Low-level CPUID driver implementation - * - * @author Johann Fischer - * - * @} - */ - -#include - -#include "cpu.h" -#include "periph/cpuid.h" - -void cpuid_get(void *id) -{ - memcpy(id, (void *)&(SIM_UIDH), CPUID_LEN); -} diff --git a/cpu/lm4f120/periph/cpuid.c b/cpu/lm4f120/periph/cpuid.c deleted file mode 100644 index b00bca040..000000000 --- a/cpu/lm4f120/periph/cpuid.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2015 Rakendra Thapa - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @addtogroup cpu_lm4f120 - * @{ - * - * @file - * @brief Low-level CPUID driver implementation - * - * @author Rakendra Thapa - * - * @} - */ - -#include - -#include "cpu.h" -#include "periph/cpuid.h" - -void cpuid_get(void *id) -{ - memcpy(id, (void *)(NVIC_CPUID), CPUID_LEN); -} diff --git a/cpu/nrf5x_common/include/periph_cpu_common.h b/cpu/nrf5x_common/include/periph_cpu_common.h index dbb681aa8..fb9f3cc28 100644 --- a/cpu/nrf5x_common/include/periph_cpu_common.h +++ b/cpu/nrf5x_common/include/periph_cpu_common.h @@ -25,6 +25,10 @@ extern "C" { #endif +/** + * @brief Starting offset of CPU_ID + */ +#define CPUID_ADDR (&NRF_FICR->DEVICEID[0]) /** * @brief Length of the CPU_ID in octets */ diff --git a/cpu/nrf5x_common/periph/cpuid.c b/cpu/nrf5x_common/periph/cpuid.c deleted file mode 100644 index 8e51e2c37..000000000 --- a/cpu/nrf5x_common/periph/cpuid.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2014-2016 Freie Universität Berlin - * 2015 Jan Wagner - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @ingroup cpu_nrf5x_common - * @{ - * - * @file - * @brief CPUID interface implementation - * - * The NRF52832 provides a 64-bit unique identifier that is unique for each - * shipped unit. - * - * @author Hauke Petersen - * @author Jan Wagner - * - * @} - */ - -#include - -#include "cpu.h" -#include "periph/cpuid.h" - -void cpuid_get(void *id) -{ - memcpy(id, (void *)NRF_FICR->DEVICEID, CPUID_LEN); -} diff --git a/cpu/sam0_common/periph/cpuid.c b/cpu/sam0_common/periph/cpuid.c index a124d6f64..8359fe1cc 100644 --- a/cpu/sam0_common/periph/cpuid.c +++ b/cpu/sam0_common/periph/cpuid.c @@ -33,5 +33,5 @@ void cpuid_get(void *id) { uint32_t addr[] = { WORD0, WORD1, WORD2, WORD3 }; - memcpy(id, (void *)addr, CPUID_LEN); + memcpy(id, &addr[0], CPUID_LEN); } diff --git a/cpu/stm32_common/include/periph_cpu_common.h b/cpu/stm32_common/include/periph_cpu_common.h index 659f4d4c7..9a884e942 100644 --- a/cpu/stm32_common/include/periph_cpu_common.h +++ b/cpu/stm32_common/include/periph_cpu_common.h @@ -27,6 +27,14 @@ extern "C" { #endif +/** + * @brief Linker script provided symbol for CPUID location + */ +extern uint32_t _cpuid_address; +/** + * @brief Starting offset of CPU_ID + */ +#define CPUID_ADDR (&_cpuid_address) /** * @brief Length of the CPU_ID in octets */ diff --git a/cpu/stm32_common/periph/cpuid.c b/drivers/periph_common/cpuid.c similarity index 69% rename from cpu/stm32_common/periph/cpuid.c rename to drivers/periph_common/cpuid.c index 46500cd0c..5f3dbf8fd 100644 --- a/cpu/stm32_common/periph/cpuid.c +++ b/drivers/periph_common/cpuid.c @@ -1,4 +1,5 @@ /* + * Copyright (C) 2017 Eistec AB * Copyright (C) 2014-2016 Freie Universität Berlin * Copyright (C) 2015 James Hollister * @@ -8,15 +9,16 @@ */ /** - * @addtogroup cpu_stm32_common + * @addtogroup drivers * @{ * * @file - * @brief Implementation of the CPUID driver interface + * @brief Generic implementation of the CPUID driver interface * * @author Thomas Eichinger * @author James Hollister * @author Hauke Petersen + * @author Joakim Nohlgård * * @} */ @@ -26,9 +28,9 @@ #include "periph/cpuid.h" -extern uint32_t _cpuid_address; - +#ifdef CPUID_ADDR void cpuid_get(void *id) { - memcpy(id, &_cpuid_address, CPUID_LEN); + memcpy(id, (void *)CPUID_ADDR, CPUID_LEN); } +#endif