Add a desig_get_unique_id_as_string

This commit adds desig_get_unique_id_as_string which is useful if one
wants to use device ID as USB serial number(iSerialNumber), for example.
This commit is contained in:
Andrey Smirnov 2012-11-06 16:48:40 -08:00
parent 7a5da60e26
commit 12e1786863
2 changed files with 31 additions and 0 deletions

View File

@ -51,6 +51,15 @@ u16 desig_get_flash_size(void);
*/
void desig_get_unique_id(u32 result[]);
/**
* Read the full 96 bit unique identifier and return it as a
* zero-terminated string
* @param string memory region to write the result to
8 @param string_len the size of string in bytes
*/
void desig_get_unique_id_as_string(char *string,
unsigned int string_len);
END_DECLS
#endif

View File

@ -35,3 +35,25 @@ void desig_get_unique_id(u32 result[])
result[1] = bits63_32;
result[2] = bits31_16 << 16 | bits15_0;
}
void desig_get_unique_id_as_string(char *string,
unsigned int string_len)
{
int i, len;
u8 device_id[12];
static const char chars[] = "0123456789ABCDEF";
desig_get_unique_id((u32 *)device_id);
/* Each byte produces two characters */
len = (2 * sizeof(device_id) < string_len) ?
2 * sizeof(device_id) : string_len - 1;
for (i = 0; i < len; i += 2) {
string[i] = chars[(device_id[i / 2] >> 0) & 0x0F];
string[i + 1] = chars[(device_id[i / 2] >> 4) & 0x0F];
}
string[len] = '\0';
}