Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@2:60427d02ca93, 2015-03-10 (annotated)
- Committer:
- sam_grove
- Date:
- Tue Mar 10 16:32:46 2015 +0000
- Revision:
- 2:60427d02ca93
- Parent:
- 1:28e9d3ed6106
Update library to maintainers URL
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| sam_grove | 0:f82a1ca216d4 | 1 | #include "mbed.h" |
| sam_grove | 0:f82a1ca216d4 | 2 | #include "IAP.h" |
| sam_grove | 0:f82a1ca216d4 | 3 | |
| sam_grove | 0:f82a1ca216d4 | 4 | DigitalOut led(LED1); |
| sam_grove | 0:f82a1ca216d4 | 5 | |
| sam_grove | 0:f82a1ca216d4 | 6 | char *readUUID(void) |
| sam_grove | 0:f82a1ca216d4 | 7 | { |
| sam_grove | 0:f82a1ca216d4 | 8 | static char buf[64] = {0}; |
| sam_grove | 0:f82a1ca216d4 | 9 | IAP iap; |
| sam_grove | 0:f82a1ca216d4 | 10 | int32_t *block = iap.read_serial(); |
| sam_grove | 0:f82a1ca216d4 | 11 | uint32_t serial_number[5] = {0}; |
| sam_grove | 0:f82a1ca216d4 | 12 | |
| sam_grove | 0:f82a1ca216d4 | 13 | memset(buf, 0, sizeof(buf)); |
| sam_grove | 0:f82a1ca216d4 | 14 | serial_number[0] = *(block); |
| sam_grove | 0:f82a1ca216d4 | 15 | serial_number[1] = *(block+1); |
| sam_grove | 0:f82a1ca216d4 | 16 | // we only want bottom 16 bits of word1 (MAC bits 32-47) |
| sam_grove | 0:f82a1ca216d4 | 17 | // and bit 9 forced to 1, bit 8 forced to 0 |
| sam_grove | 0:f82a1ca216d4 | 18 | // Locally administered MAC, reduced conflicts |
| sam_grove | 0:f82a1ca216d4 | 19 | // http://en.wikipedia.org/wiki/MAC_address |
| sam_grove | 1:28e9d3ed6106 | 20 | serial_number[0] |= 0x00000002; |
| sam_grove | 1:28e9d3ed6106 | 21 | serial_number[0] &= 0x0000FFFE; |
| sam_grove | 0:f82a1ca216d4 | 22 | |
| sam_grove | 0:f82a1ca216d4 | 23 | snprintf(buf, 16, "%4X%08X", serial_number[0], serial_number[1]); |
| sam_grove | 0:f82a1ca216d4 | 24 | |
| sam_grove | 0:f82a1ca216d4 | 25 | return buf; |
| sam_grove | 0:f82a1ca216d4 | 26 | } |
| sam_grove | 0:f82a1ca216d4 | 27 | |
| sam_grove | 0:f82a1ca216d4 | 28 | int main(void) |
| sam_grove | 0:f82a1ca216d4 | 29 | { |
| sam_grove | 0:f82a1ca216d4 | 30 | printf("%s\n", readUUID()); |
| sam_grove | 0:f82a1ca216d4 | 31 | |
| sam_grove | 0:f82a1ca216d4 | 32 | while(1) { |
| sam_grove | 0:f82a1ca216d4 | 33 | led = !led; |
| sam_grove | 0:f82a1ca216d4 | 34 | wait(0.5f); |
| sam_grove | 0:f82a1ca216d4 | 35 | } |
| sam_grove | 0:f82a1ca216d4 | 36 | } |