Merge pull request #4761 from haukepetersen/opt_cpuid

drivers/cpuid: fixed and unified CPUID driver implementations
This commit is contained in:
Hauke Petersen 2016-02-08 18:18:53 +01:00
commit d80a661486
60 changed files with 217 additions and 241 deletions

View File

@ -41,13 +41,6 @@ extern "C" {
#define CPU_FLASH_BASE FLASH_BASE #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 #ifdef __cplusplus
} /* end extern "C" */ } /* end extern "C" */
#endif #endif

View File

@ -25,7 +25,10 @@
extern "C" { extern "C" {
#endif #endif
/* nothing to do here, yet */ /**
* @brief Length of the CPU_ID in octets
*/
#define CPUID_LEN (8U)
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -20,13 +20,12 @@
* @} * @}
*/ */
#include <stdint.h>
#include <string.h> #include <string.h>
#include "cpu.h" #include "cpu.h"
#include "periph/cpuid.h" #include "periph/cpuid.h"
#define BITS_PER_BYTE 8
void cpuid_get(void *id) void cpuid_get(void *id)
{ {
uint8_t *dest = (uint8_t *)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. * The byte-order is big-endian but the word order is little endian.
* Make some sense of it: * Make some sense of it:
*/ */
dest[0] = IEEE_ADDR_MSWORD >> (3 * BITS_PER_BYTE); dest[0] = IEEE_ADDR_MSWORD >> (3 * sizeof(uint8_t));
dest[1] = IEEE_ADDR_MSWORD >> (2 * BITS_PER_BYTE); dest[1] = IEEE_ADDR_MSWORD >> (2 * sizeof(uint8_t));
dest[2] = IEEE_ADDR_MSWORD >> (1 * BITS_PER_BYTE); dest[2] = IEEE_ADDR_MSWORD >> (1 * sizeof(uint8_t));
dest[3] = IEEE_ADDR_MSWORD >> (0 * BITS_PER_BYTE); dest[3] = IEEE_ADDR_MSWORD >> (0 * sizeof(uint8_t));
dest[4] = IEEE_ADDR_LSWORD >> (3 * BITS_PER_BYTE); dest[4] = IEEE_ADDR_LSWORD >> (3 * sizeof(uint8_t));
dest[5] = IEEE_ADDR_LSWORD >> (2 * BITS_PER_BYTE); dest[5] = IEEE_ADDR_LSWORD >> (2 * sizeof(uint8_t));
dest[6] = IEEE_ADDR_LSWORD >> (1 * BITS_PER_BYTE); dest[6] = IEEE_ADDR_LSWORD >> (1 * sizeof(uint8_t));
dest[7] = IEEE_ADDR_LSWORD >> (0 * BITS_PER_BYTE); dest[7] = IEEE_ADDR_LSWORD >> (0 * sizeof(uint8_t));
} }
/** @} */

View File

@ -40,11 +40,6 @@ extern "C" {
#define CPU_FLASH_BASE FLASH_BASE #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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -38,6 +38,11 @@ extern "C" {
typedef uint32_t tim_t; typedef uint32_t tim_t;
/** @} */ /** @} */
/**
* @brief Length of the CPU_ID in octets
*/
#define CPUID_LEN (8U)
/** /**
* @brief Define timer configuration values * @brief Define timer configuration values
* *

View File

@ -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 * 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 * General Public License v2.1. See the file LICENSE in the top level
@ -7,15 +7,18 @@
*/ */
/** /**
* @addtogroup driver_periph * @addtogroup cpu_ezr32wg
* @{ * @{
* *
* @file * @file
* @brief Low-level CPUID driver implementation * @brief Low-level CPUID driver implementation
* *
* @author Hauke Petersen <hauke.petersen@fu-berlin.de> * @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/ */
#include <stdint.h>
#include <string.h> #include <string.h>
#include "periph/cpuid.h" #include "periph/cpuid.h"

View File

@ -70,14 +70,6 @@ extern "C"
#define CPU_FLASH_BASE (0x00000000) #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 * @name GPIO pin mux function numbers
*/ */

View File

@ -46,16 +46,6 @@ extern "C"
#define CPU_FLASH_BASE (0x00000000) #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 * @name GPIO pin mux function numbers
*/ */

View File

@ -20,11 +20,11 @@
*/ */
#include <string.h> #include <string.h>
#include "cpu_conf.h"
#include "cpu.h"
#include "periph/cpuid.h" #include "periph/cpuid.h"
void cpuid_get(void *id) void cpuid_get(void *id)
{ {
memcpy(id, CPUID_ID_PTR, CPUID_ID_LEN); memcpy(id, (void *)&(SIM_UIDH), CPUID_LEN);
} }

View File

@ -19,6 +19,8 @@
#ifndef PERIPH_CPU_H_ #ifndef PERIPH_CPU_H_
#define PERIPH_CPU_H_ #define PERIPH_CPU_H_
#include <stdint.h>
#include "periph/dev_enums.h" #include "periph/dev_enums.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -53,6 +55,11 @@ typedef uint16_t gpio_t;
*/ */
#define GPIO_PIN(port, pin) ((port << GPIO_PORT_SHIFT) | pin) #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 * @brief Override values for pull register configuration
* @{ * @{

View File

@ -51,16 +51,6 @@ extern "C"
#define CPU_FLASH_BASE (0x00000000) #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 * @name GPIO pin mux function numbers
*/ */

View File

@ -59,14 +59,6 @@ extern "C" {
#define CPU_FLASH_BASE FLASH_BASE #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 * @name cpu functions
* @{ * @{

View File

@ -25,7 +25,11 @@
extern "C" { extern "C" {
#endif #endif
/* nothing to do here, yet */ /**
* @brief Length of the CPU_ID in octets
*/
#define CPUID_LEN (12U)
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -7,22 +7,23 @@
*/ */
/** /**
* @addtogroup driver_periph * @addtogroup cpu_lm4f120
* @ingroup cpu_lm4f120
* @{ * @{
* *
* @file cpuid.c * @file
* @brief Low-level CPUID driver implementation * @brief Low-level CPUID driver implementation
* *
* @author Rakendra Thapa <rakendrathapa@gmail.com> * @author Rakendra Thapa <rakendrathapa@gmail.com>
*
* @}
*/ */
#include <string.h> #include <string.h>
#include "cpu_conf.h"
#include "cpu.h"
#include "periph/cpuid.h" #include "periph/cpuid.h"
void cpuid_get(void *id) void cpuid_get(void *id)
{ {
memcpy(id, (void *)(CPUID_ADDR), CPUID_ID_LEN); memcpy(id, (void *)(NVIC_CPUID), CPUID_LEN);
} }
/** @} */

View File

@ -36,13 +36,6 @@ extern "C" {
#define CPU_FLASH_BASE LPC_FLASH_BASE #define CPU_FLASH_BASE LPC_FLASH_BASE
/** @} */ /** @} */
/**
* @brief CPU ID configuration
* @{
*/
#define CPUID_ID_LEN (16U)
/* @} */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -34,6 +34,11 @@ extern "C" {
#define PERIPH_SPI_NEEDS_TRANSFER_REGS #define PERIPH_SPI_NEEDS_TRANSFER_REGS
/** @} */ /** @} */
/**
* @brief Length of the CPU_ID in octets
*/
#define CPUID_LEN (16U)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -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 * This file is subject to the terms and conditions of the GNU Lesser
* Public License v2.1. See the file LICENSE in the top level directory for more * General Public License v2.1. See the file LICENSE in the top level
* details. * directory for more details.
*/ */
/** /**
@ -14,9 +14,13 @@
* @brief Low-level CPUID driver implementation * @brief Low-level CPUID driver implementation
* *
* @author Paul RATHGEB <paul.rathgeb@skynet.be> * @author Paul RATHGEB <paul.rathgeb@skynet.be>
*
* @}
*/ */
#include <stdint.h>
#include <string.h> #include <string.h>
#include "periph/cpuid.h" #include "periph/cpuid.h"
/* IAP base address */ /* IAP base address */
@ -33,6 +37,5 @@ void cpuid_get(void *id)
iap = (void (*)(uint32_t[], uint32_t[])) IAP_ADDRESS; iap = (void (*)(uint32_t[], uint32_t[])) IAP_ADDRESS;
/* Read UUID */ /* Read UUID */
iap(&command, result); iap(&command, result);
memcpy(id, &result[1], CPUID_ID_LEN); memcpy(id, &result[1], CPUID_LEN);
} }
/** @} */

View File

@ -55,13 +55,6 @@ extern "C" {
*/ */
#define NATIVE_ETH_PROTO 0x1234 #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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -25,7 +25,12 @@
extern "C" { extern "C" {
#endif #endif
/* nothing defined here so far... */ /**
* @brief Length of the CPU_ID in octets
*/
#ifndef CPUID_LEN
#define CPUID_LEN (4U)
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -7,13 +7,15 @@
*/ */
/** /**
* @addtogroup driver_periph * @addtogroup cpu_native
* @{ * @{
* *
* @file * @file
* @brief Implementation * @brief Implementation
* *
* @author Martine Lenders <mlenders@inf.fu-berlin.de> * @author Martine Lenders <mlenders@inf.fu-berlin.de>
*
* @}
*/ */
#include <string.h> #include <string.h>
@ -26,16 +28,12 @@
void cpuid_get(void *id) void cpuid_get(void *id)
{ {
/* Just in case _native_id is shorter than CPUID_ID_LEN: */ /* Just in case _native_id is shorter than CPUID_LEN: */
size_t len = CPUID_ID_LEN; size_t len = CPUID_LEN;
if (sizeof(_native_id) < CPUID_ID_LEN) { if (sizeof(_native_id) < CPUID_LEN) {
memset(((char*)id) + sizeof(_native_id), 0xff, memset(((char*)id) + sizeof(_native_id), 0xff,
CPUID_ID_LEN - sizeof(_native_id)); CPUID_LEN - sizeof(_native_id));
len = sizeof(_native_id); len = sizeof(_native_id);
} }
memcpy(id, &(_native_id), len); memcpy(id, &(_native_id), len);
} }
/**
* @}
*/

View File

@ -34,11 +34,6 @@ extern "C" {
#define CPU_IRQ_NUMOF (26U) #define CPU_IRQ_NUMOF (26U)
/** @} */ /** @} */
/**
* @name Length in bytes for reading CPU_ID
*/
#define CPUID_ID_LEN (8)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -25,6 +25,18 @@
extern "C" { extern "C" {
#endif #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 * @brief Override GPIO pull register select values
* @{ * @{
@ -49,13 +61,6 @@ typedef enum {
} gpio_flank_t; } 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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -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 * 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 * 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 * @file
* @brief CPU-ID driver implementation * @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 <hauke.petersen@fu-berlin.de> * @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* *
@ -27,5 +28,5 @@
void cpuid_get(void *id) void cpuid_get(void *id)
{ {
memcpy(id, (void*)NRF_FICR->DEVICEID, CPUID_ID_LEN); memcpy(id, (void*)NRF_FICR->DEVICEID, CPUID_LEN);
} }

View File

@ -510,7 +510,7 @@ static void _receive_data(void)
*/ */
int nrfmin_init(gnrc_netdev_t *dev) int nrfmin_init(gnrc_netdev_t *dev)
{ {
uint8_t cpuid[CPUID_ID_LEN]; uint8_t cpuid[CPUID_LEN];
uint8_t tmp; uint8_t tmp;
int i; int i;
@ -535,12 +535,12 @@ int nrfmin_init(gnrc_netdev_t *dev)
/* get default address from CPU ID */ /* get default address from CPU ID */
cpuid_get(cpuid); cpuid_get(cpuid);
tmp = 0; tmp = 0;
for (i = 0; i < (CPUID_ID_LEN / 2); i++) { for (i = 0; i < (CPUID_LEN / 2); i++) {
tmp ^= cpuid[i]; tmp ^= cpuid[i];
} }
_addr = ((uint16_t)tmp) << 8; _addr = ((uint16_t)tmp) << 8;
tmp = 0; tmp = 0;
for (; i < CPUID_ID_LEN; i++) { for (; i < CPUID_LEN; i++) {
tmp ^= cpuid[i]; tmp ^= cpuid[i];
} }
_addr |= tmp; _addr |= tmp;

View File

@ -36,11 +36,6 @@ extern "C" {
#define CPU_FLASH_BASE (0x00000000) #define CPU_FLASH_BASE (0x00000000)
/** @} */ /** @} */
/**
* @brief CPU_ID length in octets
*/
#define CPUID_ID_LEN (8)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -56,6 +56,11 @@ typedef enum {
*/ */
#define GPIO_PIN(x,y) ((x & 0) | y) #define GPIO_PIN(x,y) ((x & 0) | y)
/**
* @brief Length of the CPU_ID in octets
*/
#define CPUID_LEN (8U)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -26,9 +26,9 @@
#include <string.h> #include <string.h>
#include "cpu.h" #include "cpu.h"
#include "cpu_conf.h" #include "periph/cpuid.h"
void cpuid_get(void *id) void cpuid_get(void *id)
{ {
memcpy(id, (void *)NRF_FICR->DEVICEID, CPUID_ID_LEN); memcpy(id, (void *)NRF_FICR->DEVICEID, CPUID_LEN);
} }

View File

@ -36,11 +36,6 @@ extern "C" {
#define CPU_FLASH_BASE IFLASH0_ADDR #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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -55,6 +55,11 @@ typedef uint32_t gpio_t;
#define PERIPH_SPI_NEEDS_TRANSFER_REGS #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 * @brief Override values for pull register configuration
* @{ * @{

View File

@ -7,10 +7,10 @@
*/ */
/** /**
* @addtogroup driver_periph * @addtogroup cpu_sam3
* @{ * @{
* *
* @file cpuid.c * @file
* @brief Low-level CPUID driver implementation * @brief Low-level CPUID driver implementation
* *
* @author Dinh Nguyen <nqdinhddt@gmail.com> * @author Dinh Nguyen <nqdinhddt@gmail.com>
@ -18,9 +18,9 @@
* @} * @}
*/ */
#include <stdint.h>
#include <string.h> #include <string.h>
#include "cpu_conf.h"
#include "periph/cpuid.h" #include "periph/cpuid.h"
#define EFC_FCMD_STUI 0x0E /* Start unique ID */ #define EFC_FCMD_STUI 0x0E /* Start unique ID */
@ -67,5 +67,5 @@ void cpuid_get(void *id)
/* Wait for FRDY bit rises. */ /* Wait for FRDY bit rises. */
while (0 == (EFC1->EEFC_FSR & EEFC_FSR_FRDY)); while (0 == (EFC1->EEFC_FSR & EEFC_FSR_FRDY));
memcpy(id, (void*)cpuid, CPUID_ID_LEN); memcpy(id, (void*)cpuid, CPUID_LEN);
} }

View File

@ -33,11 +33,6 @@ extern "C" {
#define CPU_FLASH_BASE FLASH_ADDR #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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -44,6 +44,11 @@ typedef uint32_t gpio_t;
*/ */
#define GPIO_PIN(x, y) (((gpio_t)(&PORT->Group[x])) | y) #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 * @brief Available ports on the SAMD21
*/ */

View File

@ -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 * 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 * General Public License v2.1. See the file LICENSE in the top level
@ -7,15 +7,18 @@
*/ */
/** /**
* @addtogroup driver_periph * @addtogroup cpu_samd21
* @{ * @{
* *
* @file * @file
* @brief Low-level CPUID driver implementation * @brief Low-level CPUID driver implementation
* *
* @author Troels Hoffmeyer <troels.d.hoffmeyer@gmail.com> * @author Troels Hoffmeyer <troels.d.hoffmeyer@gmail.com>
*
* @}
*/ */
#include <stdint.h>
#include <string.h> #include <string.h>
#include "periph/cpuid.h" #include "periph/cpuid.h"
@ -32,5 +35,5 @@ void cpuid_get(void *id)
SAMD21_CPUID_WORD1, SAMD21_CPUID_WORD1,
SAMD21_CPUID_WORD2, SAMD21_CPUID_WORD2,
SAMD21_CPUID_WORD3}; SAMD21_CPUID_WORD3};
memcpy(id, (void*) source_address, CPUID_ID_LEN); memcpy(id, (void*) source_address, CPUID_LEN);
} }

View File

@ -33,11 +33,6 @@ extern "C" {
#define CPU_FLASH_BASE FLASH_ADDR #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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -45,6 +45,11 @@ typedef uint32_t gpio_t;
*/ */
#define GPIO_PIN(x, y) (((gpio_t)(&PORT->Group[x])) | y) #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 * @brief Available ports on the SAML21 for convenient access
*/ */

View File

@ -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 * 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 * 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 * @brief Low-level CPUID driver implementation
* *
* @author Troels Hoffmeyer <troels.d.hoffmeyer@gmail.com> * @author Troels Hoffmeyer <troels.d.hoffmeyer@gmail.com>
*
* @}
*/ */
#include <stdint.h>
#include <string.h> #include <string.h>
#include "cpu_conf.h"
#include "periph/cpuid.h" #include "periph/cpuid.h"
#define SAML21_CPUID_WORD0 (*(volatile uint32_t *)0x0080A00C) #define SAML21_CPUID_WORD0 (*(volatile uint32_t *)0x0080A00C)
@ -33,5 +35,5 @@ void cpuid_get(void *id)
SAML21_CPUID_WORD1, SAML21_CPUID_WORD1,
SAML21_CPUID_WORD2, SAML21_CPUID_WORD2,
SAML21_CPUID_WORD3}; SAML21_CPUID_WORD3};
memcpy(id, (void*) source_address, CPUID_ID_LEN); memcpy(id, (void*) source_address, CPUID_LEN);
} }

View File

@ -40,11 +40,6 @@ extern "C" {
#define CPU_IRQ_NUMOF (31U) #define CPU_IRQ_NUMOF (31U)
/** @} */ /** @} */
/**
* @brief Length for reading CPU_ID
*/
#define CPUID_ID_LEN (12)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -25,6 +25,11 @@
extern "C" { extern "C" {
#endif #endif
/**
* @brief Length of the CPU_ID in octets
*/
#define CPUID_LEN (12U)
/** /**
* @brief declare needed generic SPI functions * @brief declare needed generic SPI functions
* @{ * @{

View File

@ -7,13 +7,15 @@
*/ */
/** /**
* @addtogroup driver_periph * @addtogroup cpu_stm32f0
* @{ * @{
* *
* @file * @file
* @brief Low-level CPUID driver implementation * @brief Low-level CPUID driver implementation
* *
* @author James Hollister <jhollisterjr@gmail.com> * @author James Hollister <jhollisterjr@gmail.com>
*
* @}
*/ */
#include <string.h> #include <string.h>
@ -24,7 +26,5 @@
void cpuid_get(void *id) void cpuid_get(void *id)
{ {
memcpy(id, (void *)(STM32F0_CPUID_ADDR), CPUID_ID_LEN); memcpy(id, (void *)(STM32F0_CPUID_ADDR), CPUID_LEN);
} }
/** @} */

View File

@ -42,11 +42,6 @@ extern "C" {
#define CPU_FLASH_BASE FLASH_BASE #define CPU_FLASH_BASE FLASH_BASE
/** @} */ /** @} */
/**
* @brief Length for reading CPU_ID
*/
#define CPUID_ID_LEN (12)
/** /**
* @brief Configure the CPU's clock system * @brief Configure the CPU's clock system
* *

View File

@ -44,6 +44,11 @@ typedef uint32_t gpio_t;
*/ */
#define GPIO_PIN(x, y) ((GPIOA_BASE + (x << 10)) | y) #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 * @brief Override values for pull register configuration
* @{ * @{

View File

@ -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 * 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 * General Public License v2.1. See the file LICENSE in the top level
@ -7,13 +7,15 @@
*/ */
/** /**
* @addtogroup driver_periph * @addtogroup cpu_stm32f1
* @{ * @{
* *
* @file * @file
* @brief Low-level CPUID driver implementation * @brief Low-level CPUID driver implementation
* *
* @author Thomas Eichinger <thomas.eichinger@fu-berlin.de> * @author Thomas Eichinger <thomas.eichinger@fu-berlin.de>
*
* @}
*/ */
#include <string.h> #include <string.h>
@ -22,7 +24,5 @@
void cpuid_get(void *id) void cpuid_get(void *id)
{ {
memcpy(id, (void *)(0x1ffff7e8), CPUID_ID_LEN); memcpy(id, (void *)(0x1ffff7e8), CPUID_LEN);
} }
/** @} */

View File

@ -45,11 +45,6 @@ extern "C" {
#define CPU_FLASH_BASE FLASH_BASE #define CPU_FLASH_BASE FLASH_BASE
/** @} */ /** @} */
/**
* @brief Length for reading CPU_ID
*/
#define CPUID_ID_LEN (12)
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -44,6 +44,11 @@ typedef uint32_t gpio_t;
*/ */
#define GPIO_PIN(x, y) ((GPIOA_BASE + (x << 10)) | y) #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 * @brief Available ports on the STM32F3 family
*/ */

View File

@ -7,13 +7,15 @@
*/ */
/** /**
* @addtogroup driver_periph * @addtogroup cpu_stm32f3
* @{ * @{
* *
* @file * @file
* @brief Low-level CPUID driver implementation * @brief Low-level CPUID driver implementation
* *
* @author James Hollister <jhollisterjr@gmail.com> * @author James Hollister <jhollisterjr@gmail.com>
*
* @}
*/ */
#include <string.h> #include <string.h>
@ -24,7 +26,5 @@
void cpuid_get(void *id) void cpuid_get(void *id)
{ {
memcpy(id, (void *)(STM32F3_CPUID_ADDR), CPUID_ID_LEN); memcpy(id, (void *)(STM32F3_CPUID_ADDR), CPUID_LEN);
} }
/** @} */

View File

@ -42,11 +42,6 @@ extern "C" {
#define CPU_FLASH_BASE FLASH_BASE #define CPU_FLASH_BASE FLASH_BASE
/** @} */ /** @} */
/**
* @brief Length for reading CPU_ID
*/
#define CPUID_ID_LEN (12)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -52,6 +52,11 @@ typedef uint32_t gpio_t;
#define PERIPH_SPI_NEEDS_TRANSFER_REGS #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 * @brief Available ports on the STM32F4 family
*/ */

View File

@ -7,13 +7,15 @@
*/ */
/** /**
* @addtogroup driver_periph * @addtogroup cpu_stm32f4
* @{ * @{
* *
* @file * @file
* @brief Low-level CPUID driver implementation * @brief Low-level CPUID driver implementation
* *
* @author James Hollister <jhollisterjr@gmail.com> * @author James Hollister <jhollisterjr@gmail.com>
*
* @}
*/ */
#include <string.h> #include <string.h>
@ -24,7 +26,5 @@
void cpuid_get(void *id) void cpuid_get(void *id)
{ {
memcpy(id, (void *)(STM32F4_CPUID_ADDR), CPUID_ID_LEN); memcpy(id, (void *)(STM32F4_CPUID_ADDR), CPUID_LEN);
} }
/** @} */

View File

@ -36,11 +36,6 @@ extern "C" {
#define CPU_FLASH_BASE FLASH_BASE #define CPU_FLASH_BASE FLASH_BASE
/** @} */ /** @} */
/**
* @name Length for reading CPU_ID
*/
#define CPUID_ID_LEN (12)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -45,6 +45,11 @@ typedef uint32_t gpio_t;
*/ */
#define GPIO_PIN(x, y) ((GPIOA_BASE + (x << 10)) | y) #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 * @brief Available ports on the STM32L1 family
*/ */

View File

@ -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 * 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 * General Public License v2.1. See the file LICENSE in the top level
@ -7,13 +7,15 @@
*/ */
/** /**
* @addtogroup driver_periph * @addtogroup cpu_stm32l1
* @{ * @{
* *
* @file * @file
* @brief Low-level CPUID driver implementation * @brief Low-level CPUID driver implementation
* *
* @author Thomas Eichinger <thomas.eichinger@fu-berlin.de> * @author Thomas Eichinger <thomas.eichinger@fu-berlin.de>
*
* @}
*/ */
#include <string.h> #include <string.h>
@ -24,7 +26,5 @@ extern volatile uint32_t _cpuid_address[3];
void cpuid_get(void *id) void cpuid_get(void *id)
{ {
memcpy(id, (void *)(&_cpuid_address), CPUID_ID_LEN); memcpy(id, (void *)(&_cpuid_address), CPUID_LEN);
} }
/** @} */

View File

@ -1997,7 +1997,7 @@ INCLUDE_FILE_PATTERNS =
PREDEFINED = DOXYGEN \ PREDEFINED = DOXYGEN \
__attribute__(x)= \ __attribute__(x)= \
ADC_NUMOF \ ADC_NUMOF \
CPUID_ID_LEN \ CPUID_LEN \
DAC_NUMOF \ DAC_NUMOF \
GPIO_NUMOF \ GPIO_NUMOF \
I2C_NUMOF \ I2C_NUMOF \

View File

@ -89,8 +89,8 @@ int at86rf2xx_init(at86rf2xx_t *dev, spi_t spi, spi_speed_t spi_speed,
void at86rf2xx_reset(at86rf2xx_t *dev) void at86rf2xx_reset(at86rf2xx_t *dev)
{ {
#if CPUID_ID_LEN #if CPUID_LEN
uint8_t cpuid[CPUID_ID_LEN]; uint8_t cpuid[CPUID_LEN];
eui64_t addr_long; eui64_t addr_long;
#endif #endif
@ -103,16 +103,16 @@ void at86rf2xx_reset(at86rf2xx_t *dev)
dev->seq_nr = 0; dev->seq_nr = 0;
dev->options = 0; dev->options = 0;
/* set short and long address */ /* set short and long address */
#if CPUID_ID_LEN #if CPUID_LEN
cpuid_get(cpuid); cpuid_get(cpuid);
#if CPUID_ID_LEN < 8 #if CPUID_LEN < 8
/* in case CPUID_ID_LEN < 8, fill missing bytes with zeros */ /* in case CPUID_LEN < 8, fill missing bytes with zeros */
for (int i = CPUID_ID_LEN; i < 8; i++) { for (int i = CPUID_LEN; i < 8; i++) {
cpuid[i] = 0; cpuid[i] = 0;
} }
#else #else
for (int i = 8; i < CPUID_ID_LEN; i++) { for (int i = 8; i < CPUID_LEN; i++) {
cpuid[i & 0x07] ^= cpuid[i]; cpuid[i & 0x07] ^= cpuid[i];
} }
#endif #endif

View File

@ -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; uint8_t *eui64 = (uint8_t*) value;
#ifdef CPUID_ID_LEN #ifdef CPUID_LEN
int n = (CPUID_ID_LEN < sizeof(eui64_t)) int n = (CPUID_LEN < sizeof(eui64_t))
? CPUID_ID_LEN ? CPUID_LEN
: sizeof(eui64_t); : sizeof(eui64_t);
char cpuid[CPUID_ID_LEN]; char cpuid[CPUID_LEN];
cpuid_get(cpuid); cpuid_get(cpuid);
memcpy(eui64 + 8 - n, cpuid, n); memcpy(eui64 + 8 - n, cpuid, n);

View File

@ -87,11 +87,11 @@ int cc110x_setup(cc110x_t *dev, const cc110x_params_t *params)
cc110x_set_channel(dev, CC110X_DEFAULT_CHANNEL); cc110x_set_channel(dev, CC110X_DEFAULT_CHANNEL);
/* set default node id */ /* set default node id */
#ifdef CPUID_ID_LEN #ifdef CPUID_LEN
if (CPUID_ID_LEN>0) { if (CPUID_LEN>0) {
char cpuid[CPUID_ID_LEN]; char cpuid[CPUID_LEN];
cpuid_get(cpuid); 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 #endif

View File

@ -29,7 +29,7 @@
#include "enc28j60.h" #include "enc28j60.h"
#include "enc28j60_regs.h" #include "enc28j60_regs.h"
#if CPUID_ID_LEN #if CPUID_LEN
#include "periph/cpuid.h" #include "periph/cpuid.h"
#endif #endif
@ -344,8 +344,8 @@ static int nd_init(netdev2_t *netdev)
/* set non-back-to-back inter packet gap -> 0x12 is default */ /* set non-back-to-back inter packet gap -> 0x12 is default */
cmd_wcr(dev, REG_B2_MAIPGL, 2, MAIPGL_FD); cmd_wcr(dev, REG_B2_MAIPGL, 2, MAIPGL_FD);
/* set default MAC address */ /* set default MAC address */
#if CPUID_ID_LEN #if CPUID_LEN
uint8_t macbuf[CPUID_ID_LEN]; uint8_t macbuf[CPUID_LEN];
cpuid_get(&macbuf); /* we get the full ID but use only parts of it */ cpuid_get(&macbuf); /* we get the full ID but use only parts of it */
macbuf[0] |= 0x02; /* locally administered address */ macbuf[0] |= 0x02; /* locally administered address */
macbuf[0] &= ~0x01; /* unicast address */ macbuf[0] &= ~0x01; /* unicast address */

View File

@ -23,21 +23,21 @@
#ifndef PERIPH_CPUID_H_ #ifndef PERIPH_CPUID_H_
#define PERIPH_CPUID_H_ #define PERIPH_CPUID_H_
#include "cpu_conf.h" #include "periph_cpu.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/** /**
* @def CPUID_ID_LEN * @def CPUID_LEN
* *
* @brief The length in byte of the CPU's serial number. * @brief The length in byte of the CPU's serial number.
* *
* @note Must be defined in the CPU's @ref cpu_conf.h * @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. * @brief Gets the serial number of the CPU.
* *
@ -45,7 +45,7 @@ extern "C" {
* defined in the CPU's cpu_conf.h) * defined in the CPU's cpu_conf.h)
*/ */
void cpuid_get(void *id); void cpuid_get(void *id);
#endif /* CPUID_ID_LEN */ #endif /* CPUID_LEN */
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -392,8 +392,8 @@ int kw2xrf_init(kw2xrf_t *dev, spi_t spi, spi_speed_t spi_speed,
uint8_t reg = 0; uint8_t reg = 0;
uint8_t tmp[2]; uint8_t tmp[2];
kw2xrf_gpio_int = int_pin; kw2xrf_gpio_int = int_pin;
#if CPUID_ID_LEN #if CPUID_LEN
uint8_t cpuid[CPUID_ID_LEN]; uint8_t cpuid[CPUID_LEN];
eui64_t addr_long; eui64_t addr_long;
#endif #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->proto = KW2XRF_DEFAULT_PROTOCOL;
dev->option = 0; dev->option = 0;
#if CPUID_ID_LEN #if CPUID_LEN
cpuid_get(cpuid); cpuid_get(cpuid);
#if CPUID_ID_LEN < 8 #if CPUID_LEN < 8
/* in case CPUID_ID_LEN < 8, fill missing bytes with zeros */ /* in case CPUID_LEN < 8, fill missing bytes with zeros */
for (int i = CPUID_ID_LEN; i < 8; i++) { for (int i = CPUID_LEN; i < 8; i++) {
cpuid[i] = 0; cpuid[i] = 0;
} }
#else #else
for (int i = 8; i < CPUID_ID_LEN; i++) { for (int i = 8; i < CPUID_LEN; i++) {
cpuid[i & 0x07] ^= cpuid[i]; cpuid[i & 0x07] ^= cpuid[i];
} }

View File

@ -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, kernel_pid_t gnrc_zep_init(gnrc_zep_t *dev, uint16_t src_port, ipv6_addr_t *dst,
uint16_t dst_port) uint16_t dst_port)
{ {
#if CPUID_ID_LEN #if CPUID_LEN
uint8_t cpuid[CPUID_ID_LEN]; uint8_t cpuid[CPUID_LEN];
uint32_t hash1, hash2; uint32_t hash1, hash2;
#endif #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->chan = GNRC_ZEP_DEFAULT_CHANNEL;
dev->pan = byteorder_btols(byteorder_htons(GNRC_ZEP_DEFAULT_PANID)); dev->pan = byteorder_btols(byteorder_htons(GNRC_ZEP_DEFAULT_PANID));
dev->flags = GNRC_ZEP_FLAGS_USE_SRC_PAN; 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 */ /* initialize dev->addr and dev->eui64 from cpuid if available */
cpuid_get(cpuid); 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)); dev->addr.u16 = (uint16_t)((hash1 >> 16) ^ (hash1 & 0xffff));
if (CPUID_ID_LEN % 2) { if (CPUID_LEN % 2) {
hash2 = djb2_hash(cpuid + (CPUID_ID_LEN / 2), (CPUID_ID_LEN / 2) - 1); hash2 = djb2_hash(cpuid + (CPUID_LEN / 2), (CPUID_LEN / 2) - 1);
} }
else { 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; dev->eui64.u32[0] = hash1;

View File

@ -27,7 +27,7 @@
int main(void) int main(void)
{ {
uint8_t id[CPUID_ID_LEN]; uint8_t id[CPUID_LEN];
puts("Test for the CPUID driver"); puts("Test for the CPUID driver");
puts("This test is reading out the CPUID of the platforms CPU\n"); puts("This test is reading out the CPUID of the platforms CPU\n");
@ -37,7 +37,7 @@ int main(void)
/* print the CPUID */ /* print the CPUID */
printf("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(" 0x%02x", id[i]);
} }
printf("\n"); printf("\n");