From 29b0e73350073bd3f1a142d6f0e9f9f9c20ef7b0 Mon Sep 17 00:00:00 2001 From: Troels Hoffmeyer Date: Tue, 11 Nov 2014 16:36:09 +0100 Subject: [PATCH] samr21: cpuid implemented by reading 128 bits from flash --- boards/samr21-xpro/Makefile.features | 2 +- cpu/samd21/include/cpu-conf.h | 4 +++ cpu/samd21/periph/cpuid.c | 37 ++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 cpu/samd21/periph/cpuid.c diff --git a/boards/samr21-xpro/Makefile.features b/boards/samr21-xpro/Makefile.features index e32153a0c7..fc8df2c708 100644 --- a/boards/samr21-xpro/Makefile.features +++ b/boards/samr21-xpro/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED += transceiver periph_gpio periph_spi cpp periph_timer periph_uart periph_i2c cpp periph_rtc +FEATURES_PROVIDED += transceiver periph_gpio periph_spi cpp periph_timer periph_uart periph_i2c cpp periph_rtc periph_cpuid diff --git a/cpu/samd21/include/cpu-conf.h b/cpu/samd21/include/cpu-conf.h index 6868d7c470..f78e6e6c35 100644 --- a/cpu/samd21/include/cpu-conf.h +++ b/cpu/samd21/include/cpu-conf.h @@ -55,5 +55,9 @@ extern "C" { } #endif +/** + * @brief CPUID_ID_LEN length of cpuid in bytes + */ +#define CPUID_ID_LEN (16) /* 128 bits long, 16 bytes long */ #endif /* __CPU_CONF_H */ /** @} */ diff --git a/cpu/samd21/periph/cpuid.c b/cpu/samd21/periph/cpuid.c new file mode 100644 index 0000000000..c32ea92623 --- /dev/null +++ b/cpu/samd21/periph/cpuid.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 driver_periph + * @{ + * + * @file cpuid.c + * @brief Low-level CPUID driver implementation + * + * @author Troels Hoffmeyer + */ + +#include + +#include "cpu-conf.h" +#include "periph/cpuid.h" + +#define SAMD21_CPUID_WORD0 (*(volatile uint32_t *)0x0080A00C) +#define SAMD21_CPUID_WORD1 (*(volatile uint32_t *)0x0080A040) +#define SAMD21_CPUID_WORD2 (*(volatile uint32_t *)0x0080A044) +#define SAMD21_CPUID_WORD3 (*(volatile uint32_t *)0x0080A048) + + +void cpuid_get(void *id) +{ + uint32_t source_address[] = { SAMD21_CPUID_WORD0, + SAMD21_CPUID_WORD1, + SAMD21_CPUID_WORD2, + SAMD21_CPUID_WORD3}; + memcpy(id, (void*) source_address, CPUID_ID_LEN); +}