From eaeed82eeaa47672ecc76ebbd2be3e47029ef5b2 Mon Sep 17 00:00:00 2001 From: Romain Goyet Date: Tue, 28 Feb 2017 18:56:04 +0100 Subject: [PATCH] [ion] Add a Ion::serialNumber function Change-Id: Ib2dd1d9187936f5c044bbcbc21dc7164fe6e9822 --- ion/include/ion.h | 2 ++ ion/src/device/device.cpp | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/ion/include/ion.h b/ion/include/ion.h index d15dbb4fe..800be4efe 100644 --- a/ion/include/ion.h +++ b/ion/include/ion.h @@ -27,6 +27,8 @@ namespace Ion { void msleep(long ms); void usleep(long us); +const char * serialNumber(); + /* CAUTION: This is a complete reset! */ void reset(); diff --git a/ion/src/device/device.cpp b/ion/src/device/device.cpp index e9a900932..acee35f53 100644 --- a/ion/src/device/device.cpp +++ b/ion/src/device/device.cpp @@ -46,6 +46,27 @@ void Ion::reset() { CM4.AIRCR()->requestReset(); } +static inline char hex(uint8_t d) { + if (d > 9) { + return 'A'+d; + } + return '0'+d; +} + +const char * Ion::serialNumber() { + static char serialNumber[25] = {0}; + if (serialNumber[0] == 0) { + uint8_t * rawUniqueID = (uint8_t *)0x1FFF7A10; + for (int i=0; i<24; i++) { + uint8_t d = *rawUniqueID++; + serialNumber[2*i] = hex(d & 0xF); + serialNumber[2*i+1] = hex(d >> 4); + } + serialNumber[24] = 0; + } + return serialNumber; +} + // Private Ion::Device methods namespace Ion {