Browse Source

periph/cpuid: Unify implementations to a common driver for several platforms

pr/rotary
Joakim Nohlgård 6 years ago
parent
commit
6cda6a6560
  1. 4
      cpu/cc2538/include/periph_cpu.h
  2. 45
      cpu/cc2538/periph/cpuid.c
  3. 4
      cpu/cc26x0/include/periph_cpu.h
  4. 28
      cpu/cc26x0/periph/cpuid.c
  5. 4
      cpu/ezr32wg/include/periph_cpu.h
  6. 35
      cpu/ezr32wg/periph/cpuid.c
  7. 4
      cpu/kinetis_common/include/periph_cpu.h
  8. 30
      cpu/kinetis_common/periph/cpuid.c
  9. 4
      cpu/nrf5x_common/include/periph_cpu_common.h
  10. 34
      cpu/nrf5x_common/periph/cpuid.c
  11. 8
      cpu/stm32_common/include/periph_cpu_common.h
  12. 12
      drivers/periph_common/cpuid.c

4
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
*/

45
cpu/cc2538/periph/cpuid.c

@ -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 <ian@locicontrols.com>
*
* @}
*/
#include <stdint.h>
#include <string.h>
#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));
}

4
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
*/

28
cpu/cc26x0/periph/cpuid.c

@ -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 <leon@georgemail.eu>
*
* @}
*/
#include <string.h>
#include "periph/cpuid.h"
void cpuid_get(void *id)
{
memcpy(id, (void *) &FCFG->MAC_BLE_0, CPUID_LEN);
}

4
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
*/

35
cpu/ezr32wg/periph/cpuid.c

@ -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 <hauke.petersen@fu-berlin.de>
*
* @}
*/
#include <stdint.h>
#include <string.h>
#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));
}

4
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
*/

30
cpu/kinetis_common/periph/cpuid.c

@ -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 <j.fischer@phytec.de>
*
* @}
*/
#include <string.h>
#include "cpu.h"
#include "periph/cpuid.h"
void cpuid_get(void *id)
{
memcpy(id, (void *)&(SIM_UIDH), CPUID_LEN);
}

4
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
*/

34
cpu/nrf5x_common/periph/cpuid.c

@ -1,34 +0,0 @@
/*
* Copyright (C) 2014-2016 Freie Universität Berlin
* 2015 Jan Wagner <mail@jwagner.eu>
*
* 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 <hauke.petersen@fu-berlin.de>
* @author Jan Wagner <mail@jwagner.eu>
*
* @}
*/
#include <string.h>
#include "cpu.h"
#include "periph/cpuid.h"
void cpuid_get(void *id)
{
memcpy(id, (void *)NRF_FICR->DEVICEID, CPUID_LEN);
}

8
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
*/

12
cpu/stm32_common/periph/cpuid.c → 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 <thomas.eichinger@fu-berlin.de>
* @author James Hollister <jhollisterjr@gmail.com>
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Joakim Nohlgård <joakim.nohlgard@eistec.se>
*
* @}
*/
@ -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
Loading…
Cancel
Save