-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drivers/cpu: add function to get CPU id/serial number #854
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest a comment on this define.