-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #854 from authmillenon/cpu-id
drivers/cpu: add function to get CPU id/serial number
- Loading branch information
Showing
5 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,4 +57,6 @@ | |
/* for nativenet */ | ||
#define NATIVE_ETH_PROTO 0x1234 | ||
|
||
#define CPUID_ID_LEN (4) | ||
|
||
#endif /* CPUCONF_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (C) 2014 Martin Lenders <mlenders@inf.fu-berlin.de> | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser General | ||
* Public License. See the file LICENSE in the top level directory for more | ||
* details. | ||
*/ | ||
|
||
/** | ||
* @addtogroup driver_periph | ||
* @{ | ||
* | ||
* @file cpuid.c | ||
* @brief Implementation | ||
* | ||
* @author Martine Lenders <mlenders@inf.fu-berlin.de> | ||
*/ | ||
|
||
#include <string.h> | ||
#include <stdint.h> | ||
|
||
#include "cpu-conf.h" | ||
#include "native_internal.h" | ||
|
||
#include "periph/cpuid.h" | ||
|
||
void cpuid_get(void *id) | ||
{ | ||
memset(id, 0xff, CPUID_ID_LEN); /* Just in case _native_id is shorter | ||
than CPUID_ID_LEN. */ | ||
memcpy(id, &(_native_id), sizeof(_native_id)); | ||
} | ||
|
||
/** | ||
* @} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (C) 2014 Martin Lenders <mlenders@inf.fu-berlin.de> | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser General | ||
* Public License. See the file LICENSE in the top level directory for more | ||
* details. | ||
*/ | ||
|
||
/** | ||
* @addtogroup driver_periph | ||
* @{ | ||
* | ||
* @file periph/cpuid.h | ||
* @brief Provides access the CPU's serial number | ||
* | ||
* @author Martine Lenders <mlenders@inf.fu-berlin.de> | ||
*/ | ||
|
||
#ifndef __PERIPH_CPUID_H_ | ||
#define __PERIPH_CPUID_H_ | ||
|
||
#include "cpu-conf.h" | ||
|
||
#if CPUID_ID_LEN | ||
/** | ||
* @brief Gets the serial number of the CPU. | ||
* | ||
* @param[out] id The serial number of the CPU of length CPU_ID_LEN (must be | ||
* defined in the CPU's cpu-conf.h) | ||
*/ | ||
void cpuid_get(void *id); | ||
#endif /* CPUID_ID_LEN */ | ||
|
||
#endif /* __PERIPH_CPUID_H_ */ | ||
/** | ||
* @} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export APPLICATION = test_cpu_id | ||
include ../Makefile.tests_common | ||
|
||
BOARD_WHITELIST := native | ||
|
||
include $(RIOTBASE)/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (C) 2014 Freie Universität Berlin | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser General | ||
* Public License. See the file LICENSE in the top level directory for more | ||
* details. | ||
*/ | ||
|
||
/** | ||
* @ingroup tests | ||
* @{ | ||
* | ||
* @file | ||
* @brief GET_CPU_ID() test application | ||
* | ||
* @author Martin Lenders <mlenders@inf.fu-berlin.de> | ||
* | ||
* @} | ||
*/ | ||
|
||
#include <stdint.h> | ||
#include <stdio.h> | ||
|
||
#include "cpu-conf.h" | ||
#include "periph/cpuid.h" | ||
|
||
#ifndef CPUID_ID_LEN | ||
#error "cpuid is not defined for the CPU type of this board" | ||
#endif | ||
|
||
int main(void) | ||
{ | ||
uint8_t id[CPUID_ID_LEN]; | ||
|
||
cpuid_get(id); | ||
|
||
for (unsigned int i = 0; i < CPUID_ID_LEN; i++) { | ||
printf("0x%02x ", id[i]); | ||
} | ||
|
||
printf("\n"); | ||
|
||
return 0; | ||
} |