diff --git a/cpu/cc2538/include/cpu_conf.h b/cpu/cc2538/include/cpu_conf.h index e415ccdf91..088cdb4eff 100644 --- a/cpu/cc2538/include/cpu_conf.h +++ b/cpu/cc2538/include/cpu_conf.h @@ -41,13 +41,6 @@ extern "C" { #define CPU_FLASH_BASE FLASH_BASE /** @} */ -/** - * @brief length of CPU ID for @ref cpuid_get() in @ref periph/cpuid.h - */ -#ifndef CPUID_ID_LEN -#define CPUID_ID_LEN 8 -#endif - #ifdef __cplusplus } /* end extern "C" */ #endif diff --git a/cpu/cc2538/include/periph_cpu.h b/cpu/cc2538/include/periph_cpu.h index 51264b5d42..e867555b6f 100644 --- a/cpu/cc2538/include/periph_cpu.h +++ b/cpu/cc2538/include/periph_cpu.h @@ -25,7 +25,10 @@ extern "C" { #endif -/* nothing to do here, yet */ +/** + * @brief Length of the CPU_ID in octets + */ +#define CPUID_LEN (8U) #ifdef __cplusplus } diff --git a/cpu/cc2538/periph/cpuid.c b/cpu/cc2538/periph/cpuid.c index efc4cb3828..5005812978 100644 --- a/cpu/cc2538/periph/cpuid.c +++ b/cpu/cc2538/periph/cpuid.c @@ -20,13 +20,12 @@ * @} */ +#include #include #include "cpu.h" #include "periph/cpuid.h" -#define BITS_PER_BYTE 8 - void cpuid_get(void *id) { uint8_t *dest = (uint8_t *)id; @@ -35,13 +34,12 @@ void cpuid_get(void *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 * BITS_PER_BYTE); - dest[1] = IEEE_ADDR_MSWORD >> (2 * BITS_PER_BYTE); - dest[2] = IEEE_ADDR_MSWORD >> (1 * BITS_PER_BYTE); - dest[3] = IEEE_ADDR_MSWORD >> (0 * BITS_PER_BYTE); - dest[4] = IEEE_ADDR_LSWORD >> (3 * BITS_PER_BYTE); - dest[5] = IEEE_ADDR_LSWORD >> (2 * BITS_PER_BYTE); - dest[6] = IEEE_ADDR_LSWORD >> (1 * BITS_PER_BYTE); - dest[7] = IEEE_ADDR_LSWORD >> (0 * BITS_PER_BYTE); + 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/ezr32wg/include/cpu_conf.h b/cpu/ezr32wg/include/cpu_conf.h index 479ecb1a99..c65a2712b3 100644 --- a/cpu/ezr32wg/include/cpu_conf.h +++ b/cpu/ezr32wg/include/cpu_conf.h @@ -40,11 +40,6 @@ extern "C" { #define CPU_FLASH_BASE FLASH_BASE /** @} */ -/** - * @brief CPUID_ID_LEN length of cpuid in bytes - */ -#define CPUID_ID_LEN (8U) /* 64-bit unique ID */ - #ifdef __cplusplus } #endif diff --git a/cpu/ezr32wg/include/periph_cpu.h b/cpu/ezr32wg/include/periph_cpu.h index d45876dc5d..51f4484bde 100644 --- a/cpu/ezr32wg/include/periph_cpu.h +++ b/cpu/ezr32wg/include/periph_cpu.h @@ -38,6 +38,11 @@ extern "C" { typedef uint32_t tim_t; /** @} */ +/** + * @brief Length of the CPU_ID in octets + */ +#define CPUID_LEN (8U) + /** * @brief Define timer configuration values * diff --git a/cpu/ezr32wg/periph/cpuid.c b/cpu/ezr32wg/periph/cpuid.c index 231cadb6b3..25c17a669c 100644 --- a/cpu/ezr32wg/periph/cpuid.c +++ b/cpu/ezr32wg/periph/cpuid.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 Freie Universität Berlin + * 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 @@ -7,15 +7,18 @@ */ /** - * @addtogroup driver_periph + * @addtogroup cpu_ezr32wg * @{ * * @file * @brief Low-level CPUID driver implementation * * @author Hauke Petersen + * + * @} */ +#include #include #include "periph/cpuid.h" diff --git a/cpu/k60/include/cpu_conf.h b/cpu/k60/include/cpu_conf.h index a0731e5c2c..34fd5893f1 100644 --- a/cpu/k60/include/cpu_conf.h +++ b/cpu/k60/include/cpu_conf.h @@ -70,14 +70,6 @@ extern "C" #define CPU_FLASH_BASE (0x00000000) /** @} */ -/** - * @name Length and address for reading CPU_ID (named UID in Freescale documents) - * @{ - */ -#define CPUID_ID_LEN (16) -#define CPUID_ID_PTR ((void *)(&(SIM->UIDH))) -/** @} */ - /** * @name GPIO pin mux function numbers */ diff --git a/cpu/k64f/include/cpu_conf.h b/cpu/k64f/include/cpu_conf.h index 49c11ed116..9d38392ceb 100644 --- a/cpu/k64f/include/cpu_conf.h +++ b/cpu/k64f/include/cpu_conf.h @@ -46,16 +46,6 @@ extern "C" #define CPU_FLASH_BASE (0x00000000) /** @} */ -/** - * @brief Length for reading CPU_ID in octets - */ -#define CPUID_ID_LEN (16) - -/** - * @brief Pointer to CPU_ID - */ -#define CPUID_ID_PTR ((void *)(&(SIM_UIDH))) - /** * @name GPIO pin mux function numbers */ diff --git a/cpu/kinetis_common/cpuid.c b/cpu/kinetis_common/cpuid.c index 85851505f1..f34fd9e62d 100644 --- a/cpu/kinetis_common/cpuid.c +++ b/cpu/kinetis_common/cpuid.c @@ -20,11 +20,11 @@ */ #include -#include "cpu_conf.h" +#include "cpu.h" #include "periph/cpuid.h" void cpuid_get(void *id) { - memcpy(id, CPUID_ID_PTR, CPUID_ID_LEN); + memcpy(id, (void *)&(SIM_UIDH), CPUID_LEN); } diff --git a/cpu/kinetis_common/include/periph_cpu.h b/cpu/kinetis_common/include/periph_cpu.h index 0e6029f513..d9d529bf31 100644 --- a/cpu/kinetis_common/include/periph_cpu.h +++ b/cpu/kinetis_common/include/periph_cpu.h @@ -19,6 +19,8 @@ #ifndef PERIPH_CPU_H_ #define PERIPH_CPU_H_ +#include + #include "periph/dev_enums.h" #ifdef __cplusplus @@ -53,6 +55,11 @@ typedef uint16_t gpio_t; */ #define GPIO_PIN(port, pin) ((port << GPIO_PORT_SHIFT) | pin) +/** + * @brief Length of the CPU_ID in octets + */ +#define CPUID_LEN (16U) + /** * @brief Override values for pull register configuration * @{ diff --git a/cpu/kw2x/include/cpu_conf.h b/cpu/kw2x/include/cpu_conf.h index a16f6f55dc..3ec3c1e00e 100644 --- a/cpu/kw2x/include/cpu_conf.h +++ b/cpu/kw2x/include/cpu_conf.h @@ -51,16 +51,6 @@ extern "C" #define CPU_FLASH_BASE (0x00000000) /** @} */ -/** - * @brief Length for reading CPU_ID in octets - */ -#define CPUID_ID_LEN (16) - -/** - * @brief Pointer to CPU_ID - */ -#define CPUID_ID_PTR ((void *)(&(SIM_UIDH))) - /** * @name GPIO pin mux function numbers */ diff --git a/cpu/lm4f120/include/cpu_conf.h b/cpu/lm4f120/include/cpu_conf.h index b68c366e01..4fe073ecfd 100644 --- a/cpu/lm4f120/include/cpu_conf.h +++ b/cpu/lm4f120/include/cpu_conf.h @@ -59,14 +59,6 @@ extern "C" { #define CPU_FLASH_BASE FLASH_BASE /** @} */ -/** - * @brief Length for reading CPU_ID - * @{ - */ -#define CPUID_ID_LEN (12) -#define CPUID_ADDR NVIC_CPUID -/** @} */ - /** * @name cpu functions * @{ diff --git a/cpu/lm4f120/include/periph_cpu.h b/cpu/lm4f120/include/periph_cpu.h index dc365bf078..de4e0bbc5a 100644 --- a/cpu/lm4f120/include/periph_cpu.h +++ b/cpu/lm4f120/include/periph_cpu.h @@ -25,7 +25,11 @@ extern "C" { #endif -/* nothing to do here, yet */ +/** + * @brief Length of the CPU_ID in octets + */ +#define CPUID_LEN (12U) + #ifdef __cplusplus } diff --git a/cpu/lm4f120/periph/cpuid.c b/cpu/lm4f120/periph/cpuid.c index fe055aa6fd..b00bca0403 100644 --- a/cpu/lm4f120/periph/cpuid.c +++ b/cpu/lm4f120/periph/cpuid.c @@ -7,22 +7,23 @@ */ /** - * @addtogroup driver_periph - * @ingroup cpu_lm4f120 + * @addtogroup cpu_lm4f120 * @{ * - * @file cpuid.c + * @file * @brief Low-level CPUID driver implementation * * @author Rakendra Thapa + * + * @} */ #include -#include "cpu_conf.h" + +#include "cpu.h" #include "periph/cpuid.h" void cpuid_get(void *id) { - memcpy(id, (void *)(CPUID_ADDR), CPUID_ID_LEN); + memcpy(id, (void *)(NVIC_CPUID), CPUID_LEN); } -/** @} */ diff --git a/cpu/lpc11u34/include/cpu_conf.h b/cpu/lpc11u34/include/cpu_conf.h index f5d9fbeae1..e5a276b0c0 100644 --- a/cpu/lpc11u34/include/cpu_conf.h +++ b/cpu/lpc11u34/include/cpu_conf.h @@ -36,13 +36,6 @@ extern "C" { #define CPU_FLASH_BASE LPC_FLASH_BASE /** @} */ -/** - * @brief CPU ID configuration - * @{ - */ -#define CPUID_ID_LEN (16U) -/* @} */ - #ifdef __cplusplus } #endif diff --git a/cpu/lpc11u34/include/periph_cpu.h b/cpu/lpc11u34/include/periph_cpu.h index cb0791596a..84c6864fae 100644 --- a/cpu/lpc11u34/include/periph_cpu.h +++ b/cpu/lpc11u34/include/periph_cpu.h @@ -34,6 +34,11 @@ extern "C" { #define PERIPH_SPI_NEEDS_TRANSFER_REGS /** @} */ +/** + * @brief Length of the CPU_ID in octets + */ +#define CPUID_LEN (16U) + #ifdef __cplusplus } #endif diff --git a/cpu/lpc11u34/periph/cpuid.c b/cpu/lpc11u34/periph/cpuid.c index b759ebcf1c..2805c2a53f 100644 --- a/cpu/lpc11u34/periph/cpuid.c +++ b/cpu/lpc11u34/periph/cpuid.c @@ -1,9 +1,9 @@ /* - * Copyright (C) 2015 Freie Universität Berlin + * Copyright (C) 2015-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. + * 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. */ /** @@ -14,9 +14,13 @@ * @brief Low-level CPUID driver implementation * * @author Paul RATHGEB + * + * @} */ +#include #include + #include "periph/cpuid.h" /* IAP base address */ @@ -33,6 +37,5 @@ void cpuid_get(void *id) iap = (void (*)(uint32_t[], uint32_t[])) IAP_ADDRESS; /* Read UUID */ iap(&command, result); - memcpy(id, &result[1], CPUID_ID_LEN); + memcpy(id, &result[1], CPUID_LEN); } -/** @} */ diff --git a/cpu/native/include/cpu_conf.h b/cpu/native/include/cpu_conf.h index ad6678c881..7aa0641094 100644 --- a/cpu/native/include/cpu_conf.h +++ b/cpu/native/include/cpu_conf.h @@ -55,13 +55,6 @@ extern "C" { */ #define NATIVE_ETH_PROTO 0x1234 -/** - * @brief Length of CPU ID for @ref cpu_id_get() in @ref periph/cpuid.h - */ -#ifndef CPUID_ID_LEN -#define CPUID_ID_LEN (4) -#endif - #ifdef __cplusplus } #endif diff --git a/cpu/native/include/periph_cpu.h b/cpu/native/include/periph_cpu.h index 4e831a234f..64e47da35a 100644 --- a/cpu/native/include/periph_cpu.h +++ b/cpu/native/include/periph_cpu.h @@ -25,7 +25,12 @@ extern "C" { #endif -/* nothing defined here so far... */ +/** + * @brief Length of the CPU_ID in octets + */ +#ifndef CPUID_LEN +#define CPUID_LEN (4U) +#endif #ifdef __cplusplus } diff --git a/cpu/native/periph/cpuid.c b/cpu/native/periph/cpuid.c index 86a9b4940a..97835dde61 100644 --- a/cpu/native/periph/cpuid.c +++ b/cpu/native/periph/cpuid.c @@ -7,13 +7,15 @@ */ /** - * @addtogroup driver_periph + * @addtogroup cpu_native * @{ * * @file * @brief Implementation * * @author Martine Lenders + * + * @} */ #include @@ -26,16 +28,12 @@ void cpuid_get(void *id) { - /* Just in case _native_id is shorter than CPUID_ID_LEN: */ - size_t len = CPUID_ID_LEN; - if (sizeof(_native_id) < CPUID_ID_LEN) { + /* Just in case _native_id is shorter than CPUID_LEN: */ + size_t len = CPUID_LEN; + if (sizeof(_native_id) < CPUID_LEN) { memset(((char*)id) + sizeof(_native_id), 0xff, - CPUID_ID_LEN - sizeof(_native_id)); + CPUID_LEN - sizeof(_native_id)); len = sizeof(_native_id); } memcpy(id, &(_native_id), len); } - -/** - * @} - */ diff --git a/cpu/nrf51/include/cpu_conf.h b/cpu/nrf51/include/cpu_conf.h index 6ac737870d..93b93e0402 100644 --- a/cpu/nrf51/include/cpu_conf.h +++ b/cpu/nrf51/include/cpu_conf.h @@ -34,11 +34,6 @@ extern "C" { #define CPU_IRQ_NUMOF (26U) /** @} */ -/** - * @name Length in bytes for reading CPU_ID - */ -#define CPUID_ID_LEN (8) - #ifdef __cplusplus } #endif diff --git a/cpu/nrf51/include/periph_cpu.h b/cpu/nrf51/include/periph_cpu.h index 2b3fffe910..21d2e60205 100644 --- a/cpu/nrf51/include/periph_cpu.h +++ b/cpu/nrf51/include/periph_cpu.h @@ -25,6 +25,18 @@ extern "C" { #endif +/** + * @brief Mandatory macro for defining GPIO pins + * + * The port definition is used (and zeroed) to suppress compiler warnings + */ +#define GPIO_PIN(x,y) ((x & 0) | y) + +/** + * @brief Length of the CPU_ID in octets + */ +#define CPUID_LEN (8U) + /** * @brief Override GPIO pull register select values * @{ @@ -49,13 +61,6 @@ typedef enum { } gpio_flank_t; /** @} */ -/** - * @brief Mandatory macro for defining GPIO pins - * - * The port definition is used (and zeroed) to suppress compiler warnings - */ -#define GPIO_PIN(x,y) ((x & 0) | y) - #ifdef __cplusplus } #endif diff --git a/cpu/nrf51/periph/cpuid.c b/cpu/nrf51/periph/cpuid.c index 747ead30d5..a65227c526 100644 --- a/cpu/nrf51/periph/cpuid.c +++ b/cpu/nrf51/periph/cpuid.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 Freie Universität Berlin + * 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 @@ -7,13 +7,14 @@ */ /** - * @ingroup cpu_nrf51822 + * @ingroup cpu_nrf51 * @{ * * @file * @brief CPU-ID driver implementation * - * The NRF51822 provides a 64-bit unique identifier, that is unique for each shipped unit. + * The NRF51822 provides a 64-bit unique identifier, that is unique for each + * shipped unit. * * @author Hauke Petersen * @@ -27,5 +28,5 @@ void cpuid_get(void *id) { - memcpy(id, (void*)NRF_FICR->DEVICEID, CPUID_ID_LEN); + memcpy(id, (void*)NRF_FICR->DEVICEID, CPUID_LEN); } diff --git a/cpu/nrf51/radio/nrfmin/nrfmin.c b/cpu/nrf51/radio/nrfmin/nrfmin.c index 75498c2c68..9b1edd3fb4 100644 --- a/cpu/nrf51/radio/nrfmin/nrfmin.c +++ b/cpu/nrf51/radio/nrfmin/nrfmin.c @@ -510,7 +510,7 @@ static void _receive_data(void) */ int nrfmin_init(gnrc_netdev_t *dev) { - uint8_t cpuid[CPUID_ID_LEN]; + uint8_t cpuid[CPUID_LEN]; uint8_t tmp; int i; @@ -535,12 +535,12 @@ int nrfmin_init(gnrc_netdev_t *dev) /* get default address from CPU ID */ cpuid_get(cpuid); tmp = 0; - for (i = 0; i < (CPUID_ID_LEN / 2); i++) { + for (i = 0; i < (CPUID_LEN / 2); i++) { tmp ^= cpuid[i]; } _addr = ((uint16_t)tmp) << 8; tmp = 0; - for (; i < CPUID_ID_LEN; i++) { + for (; i < CPUID_LEN; i++) { tmp ^= cpuid[i]; } _addr |= tmp; diff --git a/cpu/nrf52/include/cpu_conf.h b/cpu/nrf52/include/cpu_conf.h index ff7e6a454f..413ce54932 100644 --- a/cpu/nrf52/include/cpu_conf.h +++ b/cpu/nrf52/include/cpu_conf.h @@ -36,11 +36,6 @@ extern "C" { #define CPU_FLASH_BASE (0x00000000) /** @} */ -/** - * @brief CPU_ID length in octets - */ -#define CPUID_ID_LEN (8) - #ifdef __cplusplus } #endif diff --git a/cpu/nrf52/include/periph_cpu.h b/cpu/nrf52/include/periph_cpu.h index db8110e8cb..31e3728565 100644 --- a/cpu/nrf52/include/periph_cpu.h +++ b/cpu/nrf52/include/periph_cpu.h @@ -56,6 +56,11 @@ typedef enum { */ #define GPIO_PIN(x,y) ((x & 0) | y) +/** + * @brief Length of the CPU_ID in octets + */ +#define CPUID_LEN (8U) + #ifdef __cplusplus } #endif diff --git a/cpu/nrf52/periph/cpuid.c b/cpu/nrf52/periph/cpuid.c index 3329a3fe95..8cf45a550d 100644 --- a/cpu/nrf52/periph/cpuid.c +++ b/cpu/nrf52/periph/cpuid.c @@ -26,9 +26,9 @@ #include #include "cpu.h" -#include "cpu_conf.h" +#include "periph/cpuid.h" void cpuid_get(void *id) { - memcpy(id, (void *)NRF_FICR->DEVICEID, CPUID_ID_LEN); + memcpy(id, (void *)NRF_FICR->DEVICEID, CPUID_LEN); } diff --git a/cpu/sam3/include/cpu_conf.h b/cpu/sam3/include/cpu_conf.h index 276fee53cc..0debff6c02 100644 --- a/cpu/sam3/include/cpu_conf.h +++ b/cpu/sam3/include/cpu_conf.h @@ -36,11 +36,6 @@ extern "C" { #define CPU_FLASH_BASE IFLASH0_ADDR /** @} */ -/** - * @brief CPUID_ID_LEN length of cpuid in bytes - */ -#define CPUID_ID_LEN (16) /* 128 bits long, 16 bytes long */ - #ifdef __cplusplus } #endif diff --git a/cpu/sam3/include/periph_cpu.h b/cpu/sam3/include/periph_cpu.h index b666f60600..6a2d26edb2 100644 --- a/cpu/sam3/include/periph_cpu.h +++ b/cpu/sam3/include/periph_cpu.h @@ -55,6 +55,11 @@ typedef uint32_t gpio_t; #define PERIPH_SPI_NEEDS_TRANSFER_REGS /** @} */ +/** + * @brief Length of the CPU_ID in octets + */ +#define CPUID_LEN (16U) + /** * @brief Override values for pull register configuration * @{ diff --git a/cpu/sam3/periph/cpuid.c b/cpu/sam3/periph/cpuid.c index 97bd98c69e..98e84b502c 100644 --- a/cpu/sam3/periph/cpuid.c +++ b/cpu/sam3/periph/cpuid.c @@ -7,10 +7,10 @@ */ /** - * @addtogroup driver_periph + * @addtogroup cpu_sam3 * @{ * - * @file cpuid.c + * @file * @brief Low-level CPUID driver implementation * * @author Dinh Nguyen @@ -18,9 +18,9 @@ * @} */ +#include #include -#include "cpu_conf.h" #include "periph/cpuid.h" #define EFC_FCMD_STUI 0x0E /* Start unique ID */ @@ -67,5 +67,5 @@ void cpuid_get(void *id) /* Wait for FRDY bit rises. */ while (0 == (EFC1->EEFC_FSR & EEFC_FSR_FRDY)); - memcpy(id, (void*)cpuid, CPUID_ID_LEN); + memcpy(id, (void*)cpuid, CPUID_LEN); } diff --git a/cpu/samd21/include/cpu_conf.h b/cpu/samd21/include/cpu_conf.h index edece7b3b5..1b7324fa01 100644 --- a/cpu/samd21/include/cpu_conf.h +++ b/cpu/samd21/include/cpu_conf.h @@ -33,11 +33,6 @@ extern "C" { #define CPU_FLASH_BASE FLASH_ADDR /** @} */ -/** - * @brief CPUID_ID_LEN length of cpuid in bytes - */ -#define CPUID_ID_LEN (16) /* 128 bits long, 16 bytes long */ - #ifdef __cplusplus } #endif diff --git a/cpu/samd21/include/periph_cpu.h b/cpu/samd21/include/periph_cpu.h index 8628712308..5861294ebb 100644 --- a/cpu/samd21/include/periph_cpu.h +++ b/cpu/samd21/include/periph_cpu.h @@ -44,6 +44,11 @@ typedef uint32_t gpio_t; */ #define GPIO_PIN(x, y) (((gpio_t)(&PORT->Group[x])) | y) +/** + * @brief Length of the CPU_ID in octets + */ +#define CPUID_LEN (16U) + /** * @brief Available ports on the SAMD21 */ diff --git a/cpu/samd21/periph/cpuid.c b/cpu/samd21/periph/cpuid.c index 35bec44ea1..b52d77ad44 100644 --- a/cpu/samd21/periph/cpuid.c +++ b/cpu/samd21/periph/cpuid.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 Freie Universität Berlin + * 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 @@ -7,15 +7,18 @@ */ /** - * @addtogroup driver_periph + * @addtogroup cpu_samd21 * @{ * * @file * @brief Low-level CPUID driver implementation * * @author Troels Hoffmeyer + * + * @} */ +#include #include #include "periph/cpuid.h" @@ -32,5 +35,5 @@ void cpuid_get(void *id) SAMD21_CPUID_WORD1, SAMD21_CPUID_WORD2, SAMD21_CPUID_WORD3}; - memcpy(id, (void*) source_address, CPUID_ID_LEN); + memcpy(id, (void*) source_address, CPUID_LEN); } diff --git a/cpu/saml21/include/cpu_conf.h b/cpu/saml21/include/cpu_conf.h index e35eac3d42..d76423f100 100644 --- a/cpu/saml21/include/cpu_conf.h +++ b/cpu/saml21/include/cpu_conf.h @@ -33,11 +33,6 @@ extern "C" { #define CPU_FLASH_BASE FLASH_ADDR /** @} */ -/** - * @brief CPUID_ID_LEN length of cpuid in bytes - */ -#define CPUID_ID_LEN (16) /* 128 bits long, 16 bytes long */ - #ifdef __cplusplus } #endif diff --git a/cpu/saml21/include/periph_cpu.h b/cpu/saml21/include/periph_cpu.h index d6384ca654..5c111208fc 100644 --- a/cpu/saml21/include/periph_cpu.h +++ b/cpu/saml21/include/periph_cpu.h @@ -45,6 +45,11 @@ typedef uint32_t gpio_t; */ #define GPIO_PIN(x, y) (((gpio_t)(&PORT->Group[x])) | y) +/** + * @brief Length of the CPU_ID in octets + */ +#define CPUID_LEN (16U) + /** * @brief Available ports on the SAML21 for convenient access */ diff --git a/cpu/saml21/periph/cpuid.c b/cpu/saml21/periph/cpuid.c index aa5a356501..c69b99cbff 100644 --- a/cpu/saml21/periph/cpuid.c +++ b/cpu/saml21/periph/cpuid.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 Freie Universität Berlin + * 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 @@ -7,18 +7,20 @@ */ /** - * @addtogroup driver_periph + * @addtogroup cpu_saml21 * @{ * - * @file cpuid.c + * @file * @brief Low-level CPUID driver implementation * * @author Troels Hoffmeyer + * + * @} */ +#include #include -#include "cpu_conf.h" #include "periph/cpuid.h" #define SAML21_CPUID_WORD0 (*(volatile uint32_t *)0x0080A00C) @@ -33,5 +35,5 @@ void cpuid_get(void *id) SAML21_CPUID_WORD1, SAML21_CPUID_WORD2, SAML21_CPUID_WORD3}; - memcpy(id, (void*) source_address, CPUID_ID_LEN); + memcpy(id, (void*) source_address, CPUID_LEN); } diff --git a/cpu/stm32f0/include/cpu_conf.h b/cpu/stm32f0/include/cpu_conf.h index 1f6309761b..d99e8b5211 100644 --- a/cpu/stm32f0/include/cpu_conf.h +++ b/cpu/stm32f0/include/cpu_conf.h @@ -40,11 +40,6 @@ extern "C" { #define CPU_IRQ_NUMOF (31U) /** @} */ -/** - * @brief Length for reading CPU_ID - */ -#define CPUID_ID_LEN (12) - #ifdef __cplusplus } #endif diff --git a/cpu/stm32f0/include/periph_cpu.h b/cpu/stm32f0/include/periph_cpu.h index 1cff6e2cca..2a6512fa02 100644 --- a/cpu/stm32f0/include/periph_cpu.h +++ b/cpu/stm32f0/include/periph_cpu.h @@ -25,6 +25,11 @@ extern "C" { #endif +/** + * @brief Length of the CPU_ID in octets + */ +#define CPUID_LEN (12U) + /** * @brief declare needed generic SPI functions * @{ diff --git a/cpu/stm32f0/periph/cpuid.c b/cpu/stm32f0/periph/cpuid.c index f987c53b4c..aea2cfd9d4 100644 --- a/cpu/stm32f0/periph/cpuid.c +++ b/cpu/stm32f0/periph/cpuid.c @@ -7,24 +7,24 @@ */ /** - * @addtogroup driver_periph + * @addtogroup cpu_stm32f0 * @{ * * @file * @brief Low-level CPUID driver implementation * * @author James Hollister + * + * @} */ #include #include "periph/cpuid.h" -#define STM32F0_CPUID_ADDR (0x1ffff7ac) +#define STM32F0_CPUID_ADDR (0x1ffff7ac) void cpuid_get(void *id) { - memcpy(id, (void *)(STM32F0_CPUID_ADDR), CPUID_ID_LEN); + memcpy(id, (void *)(STM32F0_CPUID_ADDR), CPUID_LEN); } - -/** @} */ diff --git a/cpu/stm32f1/include/cpu_conf.h b/cpu/stm32f1/include/cpu_conf.h index 033ebd804b..02ae4a9da8 100644 --- a/cpu/stm32f1/include/cpu_conf.h +++ b/cpu/stm32f1/include/cpu_conf.h @@ -42,11 +42,6 @@ extern "C" { #define CPU_FLASH_BASE FLASH_BASE /** @} */ -/** - * @brief Length for reading CPU_ID - */ -#define CPUID_ID_LEN (12) - /** * @brief Configure the CPU's clock system * diff --git a/cpu/stm32f1/include/periph_cpu.h b/cpu/stm32f1/include/periph_cpu.h index 1a8e7e6151..d290e248a0 100644 --- a/cpu/stm32f1/include/periph_cpu.h +++ b/cpu/stm32f1/include/periph_cpu.h @@ -44,6 +44,11 @@ typedef uint32_t gpio_t; */ #define GPIO_PIN(x, y) ((GPIOA_BASE + (x << 10)) | y) +/** + * @brief Length of the CPU_ID in octets + */ +#define CPUID_LEN (12U) + /** * @brief Override values for pull register configuration * @{ diff --git a/cpu/stm32f1/periph/cpuid.c b/cpu/stm32f1/periph/cpuid.c index 12641a6471..9e5ebfb9e8 100644 --- a/cpu/stm32f1/periph/cpuid.c +++ b/cpu/stm32f1/periph/cpuid.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 FU Berlin + * 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 @@ -7,13 +7,15 @@ */ /** - * @addtogroup driver_periph + * @addtogroup cpu_stm32f1 * @{ * * @file * @brief Low-level CPUID driver implementation * * @author Thomas Eichinger + * + * @} */ #include @@ -22,7 +24,5 @@ void cpuid_get(void *id) { - memcpy(id, (void *)(0x1ffff7e8), CPUID_ID_LEN); + memcpy(id, (void *)(0x1ffff7e8), CPUID_LEN); } - -/** @} */ diff --git a/cpu/stm32f3/include/cpu_conf.h b/cpu/stm32f3/include/cpu_conf.h index 1a87ba968c..59b05070eb 100644 --- a/cpu/stm32f3/include/cpu_conf.h +++ b/cpu/stm32f3/include/cpu_conf.h @@ -45,11 +45,6 @@ extern "C" { #define CPU_FLASH_BASE FLASH_BASE /** @} */ -/** - * @brief Length for reading CPU_ID - */ -#define CPUID_ID_LEN (12) - #ifdef __cplusplus } diff --git a/cpu/stm32f3/include/periph_cpu.h b/cpu/stm32f3/include/periph_cpu.h index 0060c1f0e7..e1aecbf780 100644 --- a/cpu/stm32f3/include/periph_cpu.h +++ b/cpu/stm32f3/include/periph_cpu.h @@ -44,6 +44,11 @@ typedef uint32_t gpio_t; */ #define GPIO_PIN(x, y) ((GPIOA_BASE + (x << 10)) | y) +/** + * @brief Length of the CPU_ID in octets + */ +#define CPUID_LEN (12U) + /** * @brief Available ports on the STM32F3 family */ diff --git a/cpu/stm32f3/periph/cpuid.c b/cpu/stm32f3/periph/cpuid.c index 6f03911158..8ebad6568e 100644 --- a/cpu/stm32f3/periph/cpuid.c +++ b/cpu/stm32f3/periph/cpuid.c @@ -7,13 +7,15 @@ */ /** - * @addtogroup driver_periph + * @addtogroup cpu_stm32f3 * @{ * * @file * @brief Low-level CPUID driver implementation * * @author James Hollister + * + * @} */ #include @@ -24,7 +26,5 @@ void cpuid_get(void *id) { - memcpy(id, (void *)(STM32F3_CPUID_ADDR), CPUID_ID_LEN); + memcpy(id, (void *)(STM32F3_CPUID_ADDR), CPUID_LEN); } - -/** @} */ diff --git a/cpu/stm32f4/include/cpu_conf.h b/cpu/stm32f4/include/cpu_conf.h index 25d0cf2d72..ab99da295e 100644 --- a/cpu/stm32f4/include/cpu_conf.h +++ b/cpu/stm32f4/include/cpu_conf.h @@ -42,11 +42,6 @@ extern "C" { #define CPU_FLASH_BASE FLASH_BASE /** @} */ -/** - * @brief Length for reading CPU_ID - */ -#define CPUID_ID_LEN (12) - #ifdef __cplusplus } #endif diff --git a/cpu/stm32f4/include/periph_cpu.h b/cpu/stm32f4/include/periph_cpu.h index 39de8e4f33..ea7d710a67 100644 --- a/cpu/stm32f4/include/periph_cpu.h +++ b/cpu/stm32f4/include/periph_cpu.h @@ -52,6 +52,11 @@ typedef uint32_t gpio_t; #define PERIPH_SPI_NEEDS_TRANSFER_REGS /** @} */ +/** + * @brief Length of the CPU_ID in octets + */ +#define CPUID_LEN (12U) + /** * @brief Available ports on the STM32F4 family */ diff --git a/cpu/stm32f4/periph/cpuid.c b/cpu/stm32f4/periph/cpuid.c index 179358d639..90249869c6 100644 --- a/cpu/stm32f4/periph/cpuid.c +++ b/cpu/stm32f4/periph/cpuid.c @@ -7,13 +7,15 @@ */ /** - * @addtogroup driver_periph + * @addtogroup cpu_stm32f4 * @{ * * @file * @brief Low-level CPUID driver implementation * * @author James Hollister + * + * @} */ #include @@ -24,7 +26,5 @@ void cpuid_get(void *id) { - memcpy(id, (void *)(STM32F4_CPUID_ADDR), CPUID_ID_LEN); + memcpy(id, (void *)(STM32F4_CPUID_ADDR), CPUID_LEN); } - -/** @} */ diff --git a/cpu/stm32l1/include/cpu_conf.h b/cpu/stm32l1/include/cpu_conf.h index 8a63964b8d..1520a9b259 100644 --- a/cpu/stm32l1/include/cpu_conf.h +++ b/cpu/stm32l1/include/cpu_conf.h @@ -36,11 +36,6 @@ extern "C" { #define CPU_FLASH_BASE FLASH_BASE /** @} */ -/** - * @name Length for reading CPU_ID - */ -#define CPUID_ID_LEN (12) - #ifdef __cplusplus } #endif diff --git a/cpu/stm32l1/include/periph_cpu.h b/cpu/stm32l1/include/periph_cpu.h index a20ef4586e..9675e09ba7 100644 --- a/cpu/stm32l1/include/periph_cpu.h +++ b/cpu/stm32l1/include/periph_cpu.h @@ -45,6 +45,11 @@ typedef uint32_t gpio_t; */ #define GPIO_PIN(x, y) ((GPIOA_BASE + (x << 10)) | y) +/** + * @brief Length of the CPU_ID in octets + */ +#define CPUID_LEN (12U) + /** * @brief Available ports on the STM32L1 family */ diff --git a/cpu/stm32l1/periph/cpuid.c b/cpu/stm32l1/periph/cpuid.c index 6d3b096ab1..beae57016b 100644 --- a/cpu/stm32l1/periph/cpuid.c +++ b/cpu/stm32l1/periph/cpuid.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 FU Berlin + * 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 @@ -7,13 +7,15 @@ */ /** - * @addtogroup driver_periph + * @addtogroup cpu_stm32l1 * @{ * * @file * @brief Low-level CPUID driver implementation * * @author Thomas Eichinger + * + * @} */ #include @@ -24,7 +26,5 @@ extern volatile uint32_t _cpuid_address[3]; void cpuid_get(void *id) { - memcpy(id, (void *)(&_cpuid_address), CPUID_ID_LEN); + memcpy(id, (void *)(&_cpuid_address), CPUID_LEN); } - -/** @} */ diff --git a/doc/doxygen/riot.doxyfile b/doc/doxygen/riot.doxyfile index b17b45c2d6..64d4561e96 100644 --- a/doc/doxygen/riot.doxyfile +++ b/doc/doxygen/riot.doxyfile @@ -1997,7 +1997,7 @@ INCLUDE_FILE_PATTERNS = PREDEFINED = DOXYGEN \ __attribute__(x)= \ ADC_NUMOF \ - CPUID_ID_LEN \ + CPUID_LEN \ DAC_NUMOF \ GPIO_NUMOF \ I2C_NUMOF \ diff --git a/drivers/at86rf2xx/at86rf2xx.c b/drivers/at86rf2xx/at86rf2xx.c index b194a1df32..1327cbcd7e 100644 --- a/drivers/at86rf2xx/at86rf2xx.c +++ b/drivers/at86rf2xx/at86rf2xx.c @@ -89,8 +89,8 @@ int at86rf2xx_init(at86rf2xx_t *dev, spi_t spi, spi_speed_t spi_speed, void at86rf2xx_reset(at86rf2xx_t *dev) { -#if CPUID_ID_LEN - uint8_t cpuid[CPUID_ID_LEN]; +#if CPUID_LEN + uint8_t cpuid[CPUID_LEN]; eui64_t addr_long; #endif @@ -103,16 +103,16 @@ void at86rf2xx_reset(at86rf2xx_t *dev) dev->seq_nr = 0; dev->options = 0; /* set short and long address */ -#if CPUID_ID_LEN +#if CPUID_LEN cpuid_get(cpuid); -#if CPUID_ID_LEN < 8 - /* in case CPUID_ID_LEN < 8, fill missing bytes with zeros */ - for (int i = CPUID_ID_LEN; i < 8; i++) { +#if CPUID_LEN < 8 + /* in case CPUID_LEN < 8, fill missing bytes with zeros */ + for (int i = CPUID_LEN; i < 8; i++) { cpuid[i] = 0; } #else - for (int i = 8; i < CPUID_ID_LEN; i++) { + for (int i = 8; i < CPUID_LEN; i++) { cpuid[i & 0x07] ^= cpuid[i]; } #endif diff --git a/drivers/cc110x/cc110x-netdev2.c b/drivers/cc110x/cc110x-netdev2.c index 25c6aba647..676d67a5c6 100644 --- a/drivers/cc110x/cc110x-netdev2.c +++ b/drivers/cc110x/cc110x-netdev2.c @@ -69,12 +69,12 @@ static inline int _get_iid(netdev2_t *netdev, eui64_t *value, size_t max_len) } uint8_t *eui64 = (uint8_t*) value; -#ifdef CPUID_ID_LEN - int n = (CPUID_ID_LEN < sizeof(eui64_t)) - ? CPUID_ID_LEN +#ifdef CPUID_LEN + int n = (CPUID_LEN < sizeof(eui64_t)) + ? CPUID_LEN : sizeof(eui64_t); - char cpuid[CPUID_ID_LEN]; + char cpuid[CPUID_LEN]; cpuid_get(cpuid); memcpy(eui64 + 8 - n, cpuid, n); diff --git a/drivers/cc110x/cc110x.c b/drivers/cc110x/cc110x.c index 3fc9cf505c..0f2c2aee53 100644 --- a/drivers/cc110x/cc110x.c +++ b/drivers/cc110x/cc110x.c @@ -87,11 +87,11 @@ int cc110x_setup(cc110x_t *dev, const cc110x_params_t *params) cc110x_set_channel(dev, CC110X_DEFAULT_CHANNEL); /* set default node id */ -#ifdef CPUID_ID_LEN - if (CPUID_ID_LEN>0) { - char cpuid[CPUID_ID_LEN]; +#ifdef CPUID_LEN + if (CPUID_LEN>0) { + char cpuid[CPUID_LEN]; cpuid_get(cpuid); - cc110x_set_address(dev, (uint8_t) cpuid[CPUID_ID_LEN-1]); + cc110x_set_address(dev, (uint8_t) cpuid[CPUID_LEN-1]); } #endif diff --git a/drivers/enc28j60/enc28j60.c b/drivers/enc28j60/enc28j60.c index 8f82491852..b6d74c7431 100644 --- a/drivers/enc28j60/enc28j60.c +++ b/drivers/enc28j60/enc28j60.c @@ -29,7 +29,7 @@ #include "enc28j60.h" #include "enc28j60_regs.h" -#if CPUID_ID_LEN +#if CPUID_LEN #include "periph/cpuid.h" #endif @@ -344,8 +344,8 @@ static int nd_init(netdev2_t *netdev) /* set non-back-to-back inter packet gap -> 0x12 is default */ cmd_wcr(dev, REG_B2_MAIPGL, 2, MAIPGL_FD); /* set default MAC address */ -#if CPUID_ID_LEN - uint8_t macbuf[CPUID_ID_LEN]; +#if CPUID_LEN + uint8_t macbuf[CPUID_LEN]; cpuid_get(&macbuf); /* we get the full ID but use only parts of it */ macbuf[0] |= 0x02; /* locally administered address */ macbuf[0] &= ~0x01; /* unicast address */ diff --git a/drivers/include/periph/cpuid.h b/drivers/include/periph/cpuid.h index fabcd011cc..e673c30bcb 100644 --- a/drivers/include/periph/cpuid.h +++ b/drivers/include/periph/cpuid.h @@ -23,21 +23,21 @@ #ifndef PERIPH_CPUID_H_ #define PERIPH_CPUID_H_ -#include "cpu_conf.h" +#include "periph_cpu.h" #ifdef __cplusplus extern "C" { #endif /** - * @def CPUID_ID_LEN + * @def CPUID_LEN * * @brief The length in byte of the CPU's serial number. * * @note Must be defined in the CPU's @ref cpu_conf.h */ +#if CPUID_LEN -#if CPUID_ID_LEN /** * @brief Gets the serial number of the CPU. * @@ -45,7 +45,7 @@ extern "C" { * defined in the CPU's cpu_conf.h) */ void cpuid_get(void *id); -#endif /* CPUID_ID_LEN */ +#endif /* CPUID_LEN */ #ifdef __cplusplus } diff --git a/drivers/kw2xrf/kw2xrf.c b/drivers/kw2xrf/kw2xrf.c index e4c0038e00..a6c9667b10 100644 --- a/drivers/kw2xrf/kw2xrf.c +++ b/drivers/kw2xrf/kw2xrf.c @@ -392,8 +392,8 @@ int kw2xrf_init(kw2xrf_t *dev, spi_t spi, spi_speed_t spi_speed, uint8_t reg = 0; uint8_t tmp[2]; kw2xrf_gpio_int = int_pin; -#if CPUID_ID_LEN - uint8_t cpuid[CPUID_ID_LEN]; +#if CPUID_LEN + uint8_t cpuid[CPUID_LEN]; eui64_t addr_long; #endif @@ -419,19 +419,19 @@ int kw2xrf_init(kw2xrf_t *dev, spi_t spi, spi_speed_t spi_speed, dev->proto = KW2XRF_DEFAULT_PROTOCOL; dev->option = 0; -#if CPUID_ID_LEN +#if CPUID_LEN cpuid_get(cpuid); -#if CPUID_ID_LEN < 8 +#if CPUID_LEN < 8 - /* in case CPUID_ID_LEN < 8, fill missing bytes with zeros */ - for (int i = CPUID_ID_LEN; i < 8; i++) { + /* in case CPUID_LEN < 8, fill missing bytes with zeros */ + for (int i = CPUID_LEN; i < 8; i++) { cpuid[i] = 0; } #else - for (int i = 8; i < CPUID_ID_LEN; i++) { + for (int i = 8; i < CPUID_LEN; i++) { cpuid[i & 0x07] ^= cpuid[i]; } diff --git a/sys/net/gnrc/application_layer/zep/gnrc_zep.c b/sys/net/gnrc/application_layer/zep/gnrc_zep.c index 24b042f5a2..c1d9558add 100644 --- a/sys/net/gnrc/application_layer/zep/gnrc_zep.c +++ b/sys/net/gnrc/application_layer/zep/gnrc_zep.c @@ -91,8 +91,8 @@ static uint16_t _calc_fcs(uint16_t fcs, const uint8_t *frame, uint8_t frame_len) kernel_pid_t gnrc_zep_init(gnrc_zep_t *dev, uint16_t src_port, ipv6_addr_t *dst, uint16_t dst_port) { -#if CPUID_ID_LEN - uint8_t cpuid[CPUID_ID_LEN]; +#if CPUID_LEN + uint8_t cpuid[CPUID_LEN]; uint32_t hash1, hash2; #endif @@ -120,18 +120,18 @@ kernel_pid_t gnrc_zep_init(gnrc_zep_t *dev, uint16_t src_port, ipv6_addr_t *dst, dev->chan = GNRC_ZEP_DEFAULT_CHANNEL; dev->pan = byteorder_btols(byteorder_htons(GNRC_ZEP_DEFAULT_PANID)); dev->flags = GNRC_ZEP_FLAGS_USE_SRC_PAN; -#if CPUID_ID_LEN +#if CPUID_LEN /* initialize dev->addr and dev->eui64 from cpuid if available */ cpuid_get(cpuid); - hash1 = djb2_hash(cpuid, CPUID_ID_LEN / 2); + hash1 = djb2_hash(cpuid, CPUID_LEN / 2); dev->addr.u16 = (uint16_t)((hash1 >> 16) ^ (hash1 & 0xffff)); - if (CPUID_ID_LEN % 2) { - hash2 = djb2_hash(cpuid + (CPUID_ID_LEN / 2), (CPUID_ID_LEN / 2) - 1); + if (CPUID_LEN % 2) { + hash2 = djb2_hash(cpuid + (CPUID_LEN / 2), (CPUID_LEN / 2) - 1); } else { - hash2 = djb2_hash(cpuid + (CPUID_ID_LEN / 2), CPUID_ID_LEN / 2); + hash2 = djb2_hash(cpuid + (CPUID_LEN / 2), CPUID_LEN / 2); } dev->eui64.u32[0] = hash1; diff --git a/tests/periph_cpuid/main.c b/tests/periph_cpuid/main.c index 146fc630b7..e6ad447714 100644 --- a/tests/periph_cpuid/main.c +++ b/tests/periph_cpuid/main.c @@ -27,7 +27,7 @@ int main(void) { - uint8_t id[CPUID_ID_LEN]; + uint8_t id[CPUID_LEN]; puts("Test for the CPUID driver"); puts("This test is reading out the CPUID of the platforms CPU\n"); @@ -37,7 +37,7 @@ int main(void) /* print the CPUID */ printf("CPUID:"); - for (unsigned int i = 0; i < CPUID_ID_LEN; i++) { + for (unsigned int i = 0; i < CPUID_LEN; i++) { printf(" 0x%02x", id[i]); } printf("\n");